From 681e8ebed3395add4670ac70d88628919881b292 Mon Sep 17 00:00:00 2001 From: Logan Gore <119902778+logan-stytch@users.noreply.github.com> Date: Wed, 3 Apr 2024 17:08:45 -0700 Subject: [PATCH] Release organization metrics API (#310) --- dist/b2b/client.js | 2 ++ dist/b2b/organizations.js | 17 ++++++++++ dist/b2c/client.js | 2 ++ dist/b2c/project.js | 36 ++++++++++++++++++++ lib/b2b/client.ts | 3 ++ lib/b2b/index.ts | 2 ++ lib/b2b/organizations.ts | 29 ++++++++++++++++ lib/b2b/scim_connections.ts | 11 ++++++- lib/b2c/client.ts | 3 ++ lib/b2c/index.ts | 2 ++ lib/b2c/project.ts | 51 +++++++++++++++++++++++++++++ package-lock.json | 4 +-- package.json | 2 +- types/lib/b2b/client.d.ts | 2 ++ types/lib/b2b/index.d.ts | 2 +- types/lib/b2b/organizations.d.ts | 16 +++++++++ types/lib/b2b/scim_connections.d.ts | 2 +- types/lib/b2c/client.d.ts | 2 ++ types/lib/b2c/index.d.ts | 1 + types/lib/b2c/project.d.ts | 23 +++++++++++++ 20 files changed, 206 insertions(+), 6 deletions(-) create mode 100644 dist/b2c/project.js create mode 100644 lib/b2c/project.ts create mode 100644 types/lib/b2c/project.d.ts diff --git a/dist/b2b/client.js b/dist/b2b/client.js index 8148f0ab..a5e37f97 100644 --- a/dist/b2b/client.js +++ b/dist/b2b/client.js @@ -14,6 +14,7 @@ var _organizations = require("./organizations"); var _otp = require("./otp"); var _passwords = require("./passwords"); var _rbac_local = require("./rbac_local"); +var _project = require("../b2c/project"); var _rbac = require("./rbac"); var _recovery_codes = require("./recovery_codes"); var _scim = require("./scim"); @@ -39,6 +40,7 @@ class B2BClient extends _client.BaseClient { this.otps = new _otp.OTPs(this.fetchConfig); this.organizations = new _organizations.Organizations(this.fetchConfig); this.passwords = new _passwords.Passwords(this.fetchConfig); + this.project = new _project.Project(this.fetchConfig); this.rbac = new _rbac.RBAC(this.fetchConfig); this.recoveryCodes = new _recovery_codes.RecoveryCodes(this.fetchConfig); this.scim = new _scim.SCIM(this.fetchConfig); diff --git a/dist/b2b/organizations.js b/dist/b2b/organizations.js index c5190f5b..50c98767 100644 --- a/dist/b2b/organizations.js +++ b/dist/b2b/organizations.js @@ -192,5 +192,22 @@ class Organizations { data }); } + + /** + * @param params {@link B2BOrganizationsMetricsRequest} + * @returns {@link B2BOrganizationsMetricsResponse} + * @async + * @throws A {@link StytchError} on a non-2xx response from the Stytch API + * @throws A {@link RequestError} when the Stytch API cannot be reached + */ + metrics(params) { + const headers = {}; + return (0, _shared.request)(this.fetchConfig, { + method: "GET", + url: `/v1/b2b/organizations/${params.organization_id}/metrics`, + headers, + params: {} + }); + } } exports.Organizations = Organizations; \ No newline at end of file diff --git a/dist/b2c/client.js b/dist/b2c/client.js index d5115236..3ddf680b 100644 --- a/dist/b2c/client.js +++ b/dist/b2c/client.js @@ -12,6 +12,7 @@ var _magic_links = require("./magic_links"); var _oauth = require("./oauth"); var _otps = require("./otps"); var _passwords = require("./passwords"); +var _project = require("./project"); var _sessions = require("./sessions"); var _totps = require("./totps"); var _users = require("./users"); @@ -33,6 +34,7 @@ class Client extends _client.BaseClient { this.oauth = new _oauth.OAuth(this.fetchConfig); this.otps = new _otps.OTPs(this.fetchConfig); this.passwords = new _passwords.Passwords(this.fetchConfig); + this.project = new _project.Project(this.fetchConfig); this.sessions = new _sessions.Sessions(this.fetchConfig, this.jwtConfig); this.totps = new _totps.TOTPs(this.fetchConfig); this.users = new _users.Users(this.fetchConfig); diff --git a/dist/b2c/project.js b/dist/b2c/project.js new file mode 100644 index 00000000..264ada44 --- /dev/null +++ b/dist/b2c/project.js @@ -0,0 +1,36 @@ +"use strict"; + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.Project = void 0; +require("../shared/method_options"); +var _shared = require("../shared"); +// !!! +// WARNING: This file is autogenerated +// Only modify code within MANUAL() sections +// or your changes may be overwritten later! +// !!! + +class Project { + constructor(fetchConfig) { + this.fetchConfig = fetchConfig; + } + + /** + * @param params {@link ProjectMetricsRequest} + * @returns {@link ProjectMetricsResponse} + * @async + * @throws A {@link StytchError} on a non-2xx response from the Stytch API + * @throws A {@link RequestError} when the Stytch API cannot be reached + */ + metrics() { + const headers = {}; + return (0, _shared.request)(this.fetchConfig, { + method: "GET", + url: `/v1/projects/metrics`, + headers + }); + } +} +exports.Project = Project; \ No newline at end of file diff --git a/lib/b2b/client.ts b/lib/b2b/client.ts index 9966040e..4ca632b1 100644 --- a/lib/b2b/client.ts +++ b/lib/b2b/client.ts @@ -9,6 +9,7 @@ import { Organizations } from "./organizations"; import { OTPs } from "./otp"; import { Passwords } from "./passwords"; import { PolicyCache } from "./rbac_local"; +import { Project } from "../b2c/project"; import { RBAC } from "./rbac"; import { RecoveryCodes } from "./recovery_codes"; import { SCIM } from "./scim"; @@ -25,6 +26,7 @@ export class B2BClient extends BaseClient { otps: OTPs; organizations: Organizations; passwords: Passwords; + project: Project; rbac: RBAC; recoveryCodes: RecoveryCodes; scim: SCIM; @@ -56,6 +58,7 @@ export class B2BClient extends BaseClient { this.otps = new OTPs(this.fetchConfig); this.organizations = new Organizations(this.fetchConfig); this.passwords = new Passwords(this.fetchConfig); + this.project = new Project(this.fetchConfig); this.rbac = new RBAC(this.fetchConfig); this.recoveryCodes = new RecoveryCodes(this.fetchConfig); this.scim = new SCIM(this.fetchConfig); diff --git a/lib/b2b/index.ts b/lib/b2b/index.ts index 895e8740..a913469c 100644 --- a/lib/b2b/index.ts +++ b/lib/b2b/index.ts @@ -41,6 +41,8 @@ export type { B2BOrganizationsDeleteResponse, B2BOrganizationsGetRequest, B2BOrganizationsGetResponse, + B2BOrganizationsMetricsRequest, + B2BOrganizationsMetricsResponse, B2BOrganizationsSearchRequest, B2BOrganizationsSearchResponse, B2BOrganizationsUpdateRequest, diff --git a/lib/b2b/organizations.ts b/lib/b2b/organizations.ts index 376f9227..c9ae3f41 100644 --- a/lib/b2b/organizations.ts +++ b/lib/b2b/organizations.ts @@ -589,6 +589,16 @@ export interface B2BOrganizationsGetResponse { status_code: number; } +export interface B2BOrganizationsMetricsRequest { + organization_id: string; +} + +export interface B2BOrganizationsMetricsResponse { + request_id: string; + member_count: number; + status_code: number; +} + // Request type for `organizations.search`. export interface B2BOrganizationsSearchRequest { /** @@ -1093,4 +1103,23 @@ export class Organizations { data, }); } + + /** + * @param params {@link B2BOrganizationsMetricsRequest} + * @returns {@link B2BOrganizationsMetricsResponse} + * @async + * @throws A {@link StytchError} on a non-2xx response from the Stytch API + * @throws A {@link RequestError} when the Stytch API cannot be reached + */ + metrics( + params: B2BOrganizationsMetricsRequest + ): Promise { + const headers: Record = {}; + return request(this.fetchConfig, { + method: "GET", + url: `/v1/b2b/organizations/${params.organization_id}/metrics`, + headers, + params: {}, + }); + } } diff --git a/lib/b2b/scim_connections.ts b/lib/b2b/scim_connections.ts index 13a4e01e..61bc64a7 100644 --- a/lib/b2b/scim_connections.ts +++ b/lib/b2b/scim_connections.ts @@ -23,7 +23,16 @@ export interface B2BSCIMConnectionsCreateRequest { organization_id: string; // A human-readable display name for the connection. display_name?: string; - identity_provider?: "unknown" | "okta" | "microsoft-entra" | string; + identity_provider?: + | "unknown" + | "okta" + | "microsoft-entra" + | "cyberark" + | "jumpcloud" + | "onelogin" + | "pingfederate" + | "rippling" + | string; } // Response type for `scim.connections.create`. diff --git a/lib/b2c/client.ts b/lib/b2c/client.ts index 1c072273..9a297ca4 100644 --- a/lib/b2c/client.ts +++ b/lib/b2c/client.ts @@ -7,6 +7,7 @@ import { MagicLinks } from "./magic_links"; import { OAuth } from "./oauth"; import { OTPs } from "./otps"; import { Passwords } from "./passwords"; +import { Project } from "./project"; import { Sessions } from "./sessions"; import { TOTPs } from "./totps"; import { Users } from "./users"; @@ -20,6 +21,7 @@ export class Client extends BaseClient { oauth: OAuth; otps: OTPs; passwords: Passwords; + project: Project; sessions: Sessions; totps: TOTPs; users: Users; @@ -46,6 +48,7 @@ export class Client extends BaseClient { this.oauth = new OAuth(this.fetchConfig); this.otps = new OTPs(this.fetchConfig); this.passwords = new Passwords(this.fetchConfig); + this.project = new Project(this.fetchConfig); this.sessions = new Sessions(this.fetchConfig, this.jwtConfig); this.totps = new TOTPs(this.fetchConfig); this.users = new Users(this.fetchConfig); diff --git a/lib/b2c/index.ts b/lib/b2c/index.ts index 8c2cf181..c85e701c 100644 --- a/lib/b2c/index.ts +++ b/lib/b2c/index.ts @@ -238,6 +238,8 @@ export type { OTPsEmailSendResponse, } from "./otps_email"; +export type { ProjectMetric, ProjectMetricsResponse } from "./project"; + export type { TOTPWithRecoveryCodes, TOTPsAuthenticateRequest, diff --git a/lib/b2c/project.ts b/lib/b2c/project.ts new file mode 100644 index 00000000..2c3ef44e --- /dev/null +++ b/lib/b2c/project.ts @@ -0,0 +1,51 @@ +// !!! +// WARNING: This file is autogenerated +// Only modify code within MANUAL() sections +// or your changes may be overwritten later! +// !!! + +import {} from "../shared/method_options"; +import { fetchConfig } from "../shared"; +import { request } from "../shared"; + +export interface ProjectMetric { + count: number; + metric_type?: + | "UNKNOWN" + | "USER_COUNT" + | "ORGANIZATION_COUNT" + | "MEMBER_COUNT" + | "M2M_CLIENT_COUNT" + | string; +} + +export interface ProjectMetricsResponse { + request_id: string; + project_id: string; + metrics: ProjectMetric[]; + status_code: number; +} + +export class Project { + private fetchConfig: fetchConfig; + + constructor(fetchConfig: fetchConfig) { + this.fetchConfig = fetchConfig; + } + + /** + * @param params {@link ProjectMetricsRequest} + * @returns {@link ProjectMetricsResponse} + * @async + * @throws A {@link StytchError} on a non-2xx response from the Stytch API + * @throws A {@link RequestError} when the Stytch API cannot be reached + */ + metrics(): Promise { + const headers: Record = {}; + return request(this.fetchConfig, { + method: "GET", + url: `/v1/projects/metrics`, + headers, + }); + } +} diff --git a/package-lock.json b/package-lock.json index 4192685d..cfeaa60d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "stytch", - "version": "10.12.0", + "version": "10.13.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "stytch", - "version": "10.12.0", + "version": "10.13.0", "license": "MIT", "dependencies": { "jose": "^4.14.6", diff --git a/package.json b/package.json index 38da6d5d..6c80ae03 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "stytch", - "version": "10.12.0", + "version": "10.13.0", "description": "A wrapper for the Stytch API", "types": "./types/lib/index.d.ts", "main": "./dist/index.js", diff --git a/types/lib/b2b/client.d.ts b/types/lib/b2b/client.d.ts index 7797150c..04c09668 100644 --- a/types/lib/b2b/client.d.ts +++ b/types/lib/b2b/client.d.ts @@ -7,6 +7,7 @@ import { OAuth } from "./oauth"; import { Organizations } from "./organizations"; import { OTPs } from "./otp"; import { Passwords } from "./passwords"; +import { Project } from "../b2c/project"; import { RBAC } from "./rbac"; import { RecoveryCodes } from "./recovery_codes"; import { SCIM } from "./scim"; @@ -22,6 +23,7 @@ export declare class B2BClient extends BaseClient { otps: OTPs; organizations: Organizations; passwords: Passwords; + project: Project; rbac: RBAC; recoveryCodes: RecoveryCodes; scim: SCIM; diff --git a/types/lib/b2b/index.d.ts b/types/lib/b2b/index.d.ts index c550a0cb..c477c04c 100644 --- a/types/lib/b2b/index.d.ts +++ b/types/lib/b2b/index.d.ts @@ -4,7 +4,7 @@ export type { B2BSessionsAuthenticateJwtRequest, B2BSessionsAuthenticateJwtLocal export type { PolicyCache, performAuthorizationCheck } from "./rbac_local"; export type { Policy, PolicyResource, PolicyRole, PolicyRolePermission, B2BRBACPolicyResponse, } from "./rbac"; export type { MemberOptions, MfaRequired } from "./mfa"; -export type { ActiveSSOConnection, EmailImplicitRoleAssignment, Member, MemberRole, MemberRoleSource, OAuthRegistration, Organization, B2BOrganizationsResultsMetadata, SSORegistration, SearchQuery, B2BOrganizationsCreateRequest, B2BOrganizationsCreateResponse, B2BOrganizationsDeleteRequest, B2BOrganizationsDeleteResponse, B2BOrganizationsGetRequest, B2BOrganizationsGetResponse, B2BOrganizationsSearchRequest, B2BOrganizationsSearchResponse, B2BOrganizationsUpdateRequest, B2BOrganizationsUpdateResponse, B2BOrganizationsUpdateRequestOptions, B2BOrganizationsDeleteRequestOptions, } from "./organizations"; +export type { ActiveSSOConnection, EmailImplicitRoleAssignment, Member, MemberRole, MemberRoleSource, OAuthRegistration, Organization, B2BOrganizationsResultsMetadata, SSORegistration, SearchQuery, B2BOrganizationsCreateRequest, B2BOrganizationsCreateResponse, B2BOrganizationsDeleteRequest, B2BOrganizationsDeleteResponse, B2BOrganizationsGetRequest, B2BOrganizationsGetResponse, B2BOrganizationsMetricsRequest, B2BOrganizationsMetricsResponse, B2BOrganizationsSearchRequest, B2BOrganizationsSearchResponse, B2BOrganizationsUpdateRequest, B2BOrganizationsUpdateResponse, B2BOrganizationsUpdateRequestOptions, B2BOrganizationsDeleteRequestOptions, } from "./organizations"; export type { B2BOrganizationsMembersCreateRequest, B2BOrganizationsMembersCreateResponse, B2BOrganizationsMembersDangerouslyGetRequest, B2BOrganizationsMembersDeleteMFAPhoneNumberRequest, B2BOrganizationsMembersDeleteMFAPhoneNumberResponse, B2BOrganizationsMembersDeletePasswordRequest, B2BOrganizationsMembersDeletePasswordResponse, B2BOrganizationsMembersDeleteRequest, B2BOrganizationsMembersDeleteResponse, B2BOrganizationsMembersDeleteTOTPRequest, B2BOrganizationsMembersDeleteTOTPResponse, B2BOrganizationsMembersGetRequest, B2BOrganizationsMembersGetResponse, B2BOrganizationsMembersReactivateRequest, B2BOrganizationsMembersReactivateResponse, B2BOrganizationsMembersSearchRequest, B2BOrganizationsMembersSearchResponse, B2BOrganizationsMembersUpdateRequest, B2BOrganizationsMembersUpdateResponse, B2BOrganizationsMembersUpdateRequestOptions, B2BOrganizationsMembersDeleteRequestOptions, B2BOrganizationsMembersReactivateRequestOptions, B2BOrganizationsMembersDeleteMFAPhoneNumberRequestOptions, B2BOrganizationsMembersDeleteTOTPRequestOptions, B2BOrganizationsMembersSearchRequestOptions, B2BOrganizationsMembersDeletePasswordRequestOptions, B2BOrganizationsMembersCreateRequestOptions, } from "./organizations_members"; export type { B2BOrganizationsMembersOAuthProvidersGoogleResponse, B2BOrganizationsMembersOAuthProvidersMicrosoftResponse, B2BOrganizationsMembersOAuthProvidersProviderInformationRequest, } from "./organizations_members_oauth_providers"; export type { AuthorizationCheck, AuthorizationVerdict, MemberSession, PrimaryRequired, B2BSessionsAuthenticateRequest, B2BSessionsAuthenticateResponse, B2BSessionsExchangeRequest, B2BSessionsExchangeResponse, B2BSessionsGetJWKSRequest, B2BSessionsGetJWKSResponse, B2BSessionsGetRequest, B2BSessionsGetResponse, B2BSessionsRevokeRequest, B2BSessionsRevokeResponse, } from "./sessions"; diff --git a/types/lib/b2b/organizations.d.ts b/types/lib/b2b/organizations.d.ts index df4d54df..4f2b1fff 100644 --- a/types/lib/b2b/organizations.d.ts +++ b/types/lib/b2b/organizations.d.ts @@ -525,6 +525,14 @@ export interface B2BOrganizationsGetResponse { */ status_code: number; } +export interface B2BOrganizationsMetricsRequest { + organization_id: string; +} +export interface B2BOrganizationsMetricsResponse { + request_id: string; + member_count: number; + status_code: number; +} export interface B2BOrganizationsSearchRequest { /** * The `cursor` field allows you to paginate through your results. Each result array is limited to 1000 @@ -910,4 +918,12 @@ export declare class Organizations { * @throws A {@link RequestError} when the Stytch API cannot be reached */ search(data: B2BOrganizationsSearchRequest): Promise; + /** + * @param params {@link B2BOrganizationsMetricsRequest} + * @returns {@link B2BOrganizationsMetricsResponse} + * @async + * @throws A {@link StytchError} on a non-2xx response from the Stytch API + * @throws A {@link RequestError} when the Stytch API cannot be reached + */ + metrics(params: B2BOrganizationsMetricsRequest): Promise; } diff --git a/types/lib/b2b/scim_connections.d.ts b/types/lib/b2b/scim_connections.d.ts index 092fbbef..c5c90e29 100644 --- a/types/lib/b2b/scim_connections.d.ts +++ b/types/lib/b2b/scim_connections.d.ts @@ -7,7 +7,7 @@ export interface B2BSCIMConnectionsCreateRequest { */ organization_id: string; display_name?: string; - identity_provider?: "unknown" | "okta" | "microsoft-entra" | string; + identity_provider?: "unknown" | "okta" | "microsoft-entra" | "cyberark" | "jumpcloud" | "onelogin" | "pingfederate" | "rippling" | string; } export interface B2BSCIMConnectionsCreateResponse { /** diff --git a/types/lib/b2c/client.d.ts b/types/lib/b2c/client.d.ts index 61a66e0e..0ca0d296 100644 --- a/types/lib/b2c/client.d.ts +++ b/types/lib/b2c/client.d.ts @@ -6,6 +6,7 @@ import { MagicLinks } from "./magic_links"; import { OAuth } from "./oauth"; import { OTPs } from "./otps"; import { Passwords } from "./passwords"; +import { Project } from "./project"; import { Sessions } from "./sessions"; import { TOTPs } from "./totps"; import { Users } from "./users"; @@ -18,6 +19,7 @@ export declare class Client extends BaseClient { oauth: OAuth; otps: OTPs; passwords: Passwords; + project: Project; sessions: Sessions; totps: TOTPs; users: Users; diff --git a/types/lib/b2c/index.d.ts b/types/lib/b2c/index.d.ts index 24cc8fd6..e6c33fc1 100644 --- a/types/lib/b2c/index.d.ts +++ b/types/lib/b2c/index.d.ts @@ -19,5 +19,6 @@ export type { OTPsAuthenticateRequest, OTPsAuthenticateResponse } from "./otps"; export type { OTPsSmsLoginOrCreateRequest, OTPsSmsLoginOrCreateResponse, OTPsSmsSendRequest, OTPsSmsSendResponse, } from "./otps_sms"; export type { OTPsWhatsappLoginOrCreateRequest, OTPsWhatsappLoginOrCreateResponse, OTPsWhatsappSendRequest, OTPsWhatsappSendResponse, } from "./otps_whatsapp"; export type { OTPsEmailLoginOrCreateRequest, OTPsEmailLoginOrCreateResponse, OTPsEmailSendRequest, OTPsEmailSendResponse, } from "./otps_email"; +export type { ProjectMetric, ProjectMetricsResponse } from "./project"; export type { TOTPWithRecoveryCodes, TOTPsAuthenticateRequest, TOTPsAuthenticateResponse, TOTPsCreateRequest, TOTPsCreateResponse, TOTPsRecoverRequest, TOTPsRecoverResponse, TOTPsRecoveryCodesRequest, TOTPsRecoveryCodesResponse, } from "./totps"; export type { WebAuthnAuthenticateRequest, WebAuthnAuthenticateResponse, WebAuthnAuthenticateStartRequest, WebAuthnAuthenticateStartResponse, WebAuthnRegisterRequest, WebAuthnRegisterResponse, WebAuthnRegisterStartRequest, WebAuthnRegisterStartResponse, WebAuthnUpdateRequest, WebAuthnUpdateResponse, } from "./webauthn"; diff --git a/types/lib/b2c/project.d.ts b/types/lib/b2c/project.d.ts new file mode 100644 index 00000000..22d02200 --- /dev/null +++ b/types/lib/b2c/project.d.ts @@ -0,0 +1,23 @@ +import { fetchConfig } from "../shared"; +export interface ProjectMetric { + count: number; + metric_type?: "UNKNOWN" | "USER_COUNT" | "ORGANIZATION_COUNT" | "MEMBER_COUNT" | "M2M_CLIENT_COUNT" | string; +} +export interface ProjectMetricsResponse { + request_id: string; + project_id: string; + metrics: ProjectMetric[]; + status_code: number; +} +export declare class Project { + private fetchConfig; + constructor(fetchConfig: fetchConfig); + /** + * @param params {@link ProjectMetricsRequest} + * @returns {@link ProjectMetricsResponse} + * @async + * @throws A {@link StytchError} on a non-2xx response from the Stytch API + * @throws A {@link RequestError} when the Stytch API cannot be reached + */ + metrics(): Promise; +}