@workos-inc/node 2.19.0 → 3.0.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (169) hide show
  1. package/lib/audit-logs/audit-logs.js +5 -4
  2. package/lib/audit-logs/audit-logs.spec.js +87 -87
  3. package/lib/audit-logs/interfaces/audit-log-export-options.interface.d.ts +13 -3
  4. package/lib/audit-logs/interfaces/audit-log-export.interface.d.ts +8 -0
  5. package/lib/audit-logs/interfaces/create-audit-log-event-options.interface.d.ts +13 -1
  6. package/lib/audit-logs/serializers/audit-log-export-options.serializer.d.ts +2 -0
  7. package/lib/audit-logs/serializers/audit-log-export-options.serializer.js +14 -0
  8. package/lib/audit-logs/serializers/audit-log-export.serializer.d.ts +2 -0
  9. package/lib/audit-logs/serializers/audit-log-export.serializer.js +12 -0
  10. package/lib/audit-logs/serializers/create-audit-log-event-options.serializer.d.ts +2 -0
  11. package/lib/audit-logs/serializers/create-audit-log-event-options.serializer.js +16 -0
  12. package/lib/audit-logs/serializers/index.d.ts +3 -0
  13. package/lib/audit-logs/serializers/index.js +19 -0
  14. package/lib/audit-trail/audit-trail.spec.js +2 -1
  15. package/lib/common/interfaces/index.d.ts +2 -0
  16. package/lib/common/interfaces/index.js +2 -0
  17. package/lib/common/interfaces/list.interface.d.ts +8 -0
  18. package/lib/common/interfaces/workos-response-error.interface.d.ts +8 -0
  19. package/lib/common/serializers/index.d.ts +1 -0
  20. package/lib/common/serializers/index.js +17 -0
  21. package/lib/common/serializers/list.serializer.d.ts +2 -0
  22. package/lib/common/serializers/list.serializer.js +9 -0
  23. package/lib/common/utils/workos-mock-response.d.ts +7 -0
  24. package/lib/common/utils/workos-mock-response.js +11 -0
  25. package/lib/directory-sync/directory-sync.d.ts +7 -12
  26. package/lib/directory-sync/directory-sync.js +8 -6
  27. package/lib/directory-sync/directory-sync.spec.js +95 -20
  28. package/lib/directory-sync/interfaces/directory-group.interface.d.ts +20 -0
  29. package/lib/directory-sync/interfaces/directory-user.interface.d.ts +48 -0
  30. package/lib/directory-sync/interfaces/directory.interface.d.ts +12 -0
  31. package/lib/directory-sync/interfaces/index.d.ts +6 -6
  32. package/lib/directory-sync/interfaces/index.js +20 -0
  33. package/lib/directory-sync/interfaces/list-directories-options.interface.d.ts +1 -1
  34. package/lib/directory-sync/interfaces/{list-users-options.interface.d.ts → list-directory-users-options.interface.d.ts} +1 -1
  35. package/lib/directory-sync/interfaces/list-directory-users-options.interface.js +2 -0
  36. package/lib/directory-sync/serializers/directory-group.serializer.d.ts +2 -0
  37. package/lib/directory-sync/serializers/directory-group.serializer.js +14 -0
  38. package/lib/directory-sync/serializers/directory-user.serializer.d.ts +3 -0
  39. package/lib/directory-sync/serializers/directory-user.serializer.js +23 -0
  40. package/lib/directory-sync/serializers/directory.serializer.d.ts +2 -0
  41. package/lib/directory-sync/serializers/directory.serializer.js +16 -0
  42. package/lib/directory-sync/serializers/index.d.ts +3 -0
  43. package/lib/directory-sync/serializers/index.js +19 -0
  44. package/lib/directory-sync/utils/get-primary-email.d.ts +2 -2
  45. package/lib/directory-sync/utils/get-primary-email.spec.js +10 -8
  46. package/lib/events/events.d.ts +3 -3
  47. package/lib/events/events.js +3 -1
  48. package/lib/events/events.spec.js +19 -3
  49. package/lib/events/interfaces/event.interface.d.ts +4 -1
  50. package/lib/events/serializers/event.serializer.d.ts +2 -0
  51. package/lib/events/serializers/event.serializer.js +10 -0
  52. package/lib/index.d.ts +1 -0
  53. package/lib/index.js +1 -0
  54. package/lib/mfa/interfaces/challenge.interface.d.ts +9 -0
  55. package/lib/mfa/interfaces/factor.interface.d.ts +13 -4
  56. package/lib/mfa/interfaces/index.d.ts +9 -0
  57. package/lib/mfa/interfaces/index.js +25 -0
  58. package/lib/mfa/interfaces/sms.interface.d.ts +3 -0
  59. package/lib/mfa/interfaces/totp.interface.d.ts +7 -0
  60. package/lib/mfa/interfaces/verify-challenge-response.d.ts +5 -1
  61. package/lib/mfa/mfa.d.ts +2 -8
  62. package/lib/mfa/mfa.js +5 -4
  63. package/lib/mfa/mfa.spec.js +134 -115
  64. package/lib/mfa/serializers/challenge.serializer.d.ts +2 -0
  65. package/lib/mfa/serializers/challenge.serializer.js +13 -0
  66. package/lib/mfa/serializers/factor.serializer.d.ts +2 -0
  67. package/lib/mfa/serializers/factor.serializer.js +7 -0
  68. package/lib/mfa/serializers/index.d.ts +3 -0
  69. package/lib/mfa/serializers/index.js +19 -0
  70. package/lib/mfa/serializers/sms.serializer.d.ts +2 -0
  71. package/lib/mfa/serializers/sms.serializer.js +7 -0
  72. package/lib/mfa/serializers/totp.serializer.d.ts +2 -0
  73. package/lib/mfa/serializers/totp.serializer.js +11 -0
  74. package/lib/mfa/serializers/verify-response.serializer.d.ts +2 -0
  75. package/lib/mfa/serializers/verify-response.serializer.js +9 -0
  76. package/lib/organizations/interfaces/create-organization-options.interface.d.ts +5 -0
  77. package/lib/organizations/interfaces/organization.interface.d.ts +9 -0
  78. package/lib/organizations/interfaces/update-organization-options.interface.d.ts +5 -0
  79. package/lib/organizations/organizations.d.ts +2 -2
  80. package/lib/organizations/organizations.js +8 -6
  81. package/lib/organizations/organizations.spec.js +4 -3
  82. package/lib/organizations/serializers/create-organization-options.serializer.d.ts +2 -0
  83. package/lib/organizations/serializers/create-organization-options.serializer.js +9 -0
  84. package/lib/organizations/serializers/index.d.ts +3 -0
  85. package/lib/organizations/serializers/index.js +19 -0
  86. package/lib/organizations/serializers/organization.serializer.d.ts +2 -0
  87. package/lib/organizations/serializers/organization.serializer.js +13 -0
  88. package/lib/organizations/serializers/update-organization-options.serializer.d.ts +2 -0
  89. package/lib/organizations/serializers/update-organization-options.serializer.js +9 -0
  90. package/lib/portal/interfaces/generate-portal-link-intent.interface.js +1 -1
  91. package/lib/sso/interfaces/connection-type.enum.d.ts +1 -0
  92. package/lib/sso/interfaces/connection-type.enum.js +2 -1
  93. package/lib/sso/interfaces/connection.interface.d.ts +1 -1
  94. package/lib/sso/sso.js +12 -5
  95. package/lib/sso/sso.spec.js +3 -3
  96. package/lib/users/exceptions/index.d.ts +4 -0
  97. package/lib/users/exceptions/index.js +10 -0
  98. package/lib/users/fixtures/list-users.json +21 -0
  99. package/lib/users/fixtures/session.json +6 -0
  100. package/lib/users/fixtures/user.json +12 -0
  101. package/lib/users/interfaces/add-user-to-organization-options.interface.d.ts +7 -0
  102. package/lib/users/interfaces/add-user-to-organization-options.interface.js +2 -0
  103. package/lib/users/interfaces/authenticate-user-with-password-options.interface.d.ts +16 -0
  104. package/lib/users/interfaces/authenticate-user-with-password-options.interface.js +2 -0
  105. package/lib/users/interfaces/authenticate-user-with-token-options.interface.d.ts +18 -0
  106. package/lib/users/interfaces/authenticate-user-with-token-options.interface.js +2 -0
  107. package/lib/users/interfaces/authentication-response.interface.d.ts +10 -0
  108. package/lib/users/interfaces/authentication-response.interface.js +2 -0
  109. package/lib/users/interfaces/complete-password-reset-options.interface.d.ts +8 -0
  110. package/lib/users/interfaces/complete-password-reset-options.interface.js +2 -0
  111. package/lib/users/interfaces/create-email-verification-challenge-options.interface.d.ts +16 -0
  112. package/lib/users/interfaces/create-email-verification-challenge-options.interface.js +2 -0
  113. package/lib/users/interfaces/create-password-reset-challenge-options.interface.d.ts +17 -0
  114. package/lib/users/interfaces/create-password-reset-challenge-options.interface.js +2 -0
  115. package/lib/users/interfaces/create-user-options.interface.d.ts +14 -0
  116. package/lib/users/interfaces/create-user-options.interface.js +2 -0
  117. package/lib/users/interfaces/index.d.ts +13 -0
  118. package/lib/users/interfaces/index.js +29 -0
  119. package/lib/users/interfaces/list-users-options.interface.d.ts +6 -0
  120. package/lib/users/interfaces/list-users-options.interface.js +2 -0
  121. package/lib/users/interfaces/remove-user-from-organization-options.interface.d.ts +4 -0
  122. package/lib/users/interfaces/remove-user-from-organization-options.interface.js +2 -0
  123. package/lib/users/interfaces/revoke-session-options.interface.d.ts +15 -0
  124. package/lib/users/interfaces/revoke-session-options.interface.js +2 -0
  125. package/lib/users/interfaces/session.interface.d.ts +12 -0
  126. package/lib/users/interfaces/session.interface.js +2 -0
  127. package/lib/users/interfaces/user.interface.d.ts +59 -0
  128. package/lib/users/interfaces/user.interface.js +2 -0
  129. package/lib/users/interfaces/verify-session.interface.d.ts +18 -0
  130. package/lib/users/interfaces/verify-session.interface.js +2 -0
  131. package/lib/users/serializers/authenticate-user-with-password-options.serializer.d.ts +2 -0
  132. package/lib/users/serializers/authenticate-user-with-password-options.serializer.js +12 -0
  133. package/lib/users/serializers/authenticate-user-with-token-options.serializer.d.ts +2 -0
  134. package/lib/users/serializers/authenticate-user-with-token-options.serializer.js +12 -0
  135. package/lib/users/serializers/authentication-response.serializer.d.ts +2 -0
  136. package/lib/users/serializers/authentication-response.serializer.js +12 -0
  137. package/lib/users/serializers/complete-password-reset-options.serializer.d.ts +2 -0
  138. package/lib/users/serializers/complete-password-reset-options.serializer.js +8 -0
  139. package/lib/users/serializers/create-email-verification-challenge.serializer.d.ts +2 -0
  140. package/lib/users/serializers/create-email-verification-challenge.serializer.js +9 -0
  141. package/lib/users/serializers/create-password-reset-challenge.serializer.d.ts +3 -0
  142. package/lib/users/serializers/create-password-reset-challenge.serializer.js +14 -0
  143. package/lib/users/serializers/create-user-options.serializer.d.ts +2 -0
  144. package/lib/users/serializers/create-user-options.serializer.js +11 -0
  145. package/lib/users/serializers/index.d.ts +11 -0
  146. package/lib/users/serializers/index.js +27 -0
  147. package/lib/users/serializers/revoke-session-options.serializer.d.ts +2 -0
  148. package/lib/users/serializers/revoke-session-options.serializer.js +14 -0
  149. package/lib/users/serializers/session.serializer.d.ts +2 -0
  150. package/lib/users/serializers/session.serializer.js +10 -0
  151. package/lib/users/serializers/user.serializer.d.ts +2 -0
  152. package/lib/users/serializers/user.serializer.js +31 -0
  153. package/lib/users/serializers/verify-session.serializer.d.ts +3 -0
  154. package/lib/users/serializers/verify-session.serializer.js +15 -0
  155. package/lib/users/users.d.ts +21 -0
  156. package/lib/users/users.js +112 -0
  157. package/lib/users/users.spec.d.ts +1 -0
  158. package/lib/users/users.spec.js +290 -0
  159. package/lib/webhooks/fixtures/webhook.json +1 -1
  160. package/lib/webhooks/interfaces/webhook-directory-user.interface.d.ts +2 -2
  161. package/lib/webhooks/interfaces/webhook.interface.d.ts +1 -0
  162. package/lib/workos.d.ts +6 -4
  163. package/lib/workos.js +3 -1
  164. package/package.json +13 -14
  165. package/lib/directory-sync/interfaces/group.interface.d.ts +0 -10
  166. package/lib/directory-sync/interfaces/user.interface.d.ts +0 -23
  167. /package/lib/{directory-sync/interfaces/group.interface.js → common/interfaces/workos-response-error.interface.js} +0 -0
  168. /package/lib/directory-sync/interfaces/{list-users-options.interface.js → directory-group.interface.js} +0 -0
  169. /package/lib/directory-sync/interfaces/{user.interface.js → directory-user.interface.js} +0 -0
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./add-user-to-organization-options.interface"), exports);
18
+ __exportStar(require("./authenticate-user-with-password-options.interface"), exports);
19
+ __exportStar(require("./authenticate-user-with-token-options.interface"), exports);
20
+ __exportStar(require("./authentication-response.interface"), exports);
21
+ __exportStar(require("./complete-password-reset-options.interface"), exports);
22
+ __exportStar(require("./create-email-verification-challenge-options.interface"), exports);
23
+ __exportStar(require("./create-password-reset-challenge-options.interface"), exports);
24
+ __exportStar(require("./create-user-options.interface"), exports);
25
+ __exportStar(require("./list-users-options.interface"), exports);
26
+ __exportStar(require("./remove-user-from-organization-options.interface"), exports);
27
+ __exportStar(require("./revoke-session-options.interface"), exports);
28
+ __exportStar(require("./user.interface"), exports);
29
+ __exportStar(require("./verify-session.interface"), exports);
@@ -0,0 +1,6 @@
1
+ import { PaginationOptions } from '../../common/interfaces/pagination-options.interface';
2
+ export interface ListUsersOptions extends PaginationOptions {
3
+ type?: 'managed' | 'unmanaged';
4
+ email?: string;
5
+ organization?: string;
6
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,4 @@
1
+ export interface RemoveUserFromOrganizationOptions {
2
+ userId: string;
3
+ organizationId: string;
4
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,15 @@
1
+ export type RevokeSessionOptions = SessionId | SessionToken;
2
+ export type SerializedRevokeSessionOptions = SerializedSessionId | SerializedSessionToken;
3
+ interface SessionId {
4
+ sessionId: string;
5
+ }
6
+ interface SerializedSessionId {
7
+ session_id: string;
8
+ }
9
+ interface SessionToken {
10
+ sessionToken: string;
11
+ }
12
+ interface SerializedSessionToken {
13
+ session_token: string;
14
+ }
15
+ export {};
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,12 @@
1
+ export interface Session {
2
+ id: string;
3
+ createdAt: string;
4
+ expiresAt: string;
5
+ token: string;
6
+ }
7
+ export interface SessionResponse {
8
+ id: string;
9
+ created_at: string;
10
+ expires_at: string;
11
+ token: string;
12
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,59 @@
1
+ export type User = ManagedUser | UnmanagedUser;
2
+ export type UserResponse = ManagedUserResponse | UnmanagedUserResponse;
3
+ interface ManagedUser extends BaseUser {
4
+ userType: 'managed';
5
+ organizationMemberships: [OrganizationMembership];
6
+ ssoProfileId: string | null;
7
+ }
8
+ interface ManagedUserResponse extends BaseUserResponse {
9
+ user_type: 'managed';
10
+ organization_memberships: [OrganizationMembershipResponse];
11
+ sso_profile_id: string | null;
12
+ }
13
+ interface UnmanagedUser extends BaseUser {
14
+ userType: 'unmanaged';
15
+ organizationMemberships: OrganizationMembership[];
16
+ emailVerifiedAt: string | null;
17
+ googleOauthProfileId: string | null;
18
+ microsoftOauthProfileId: string | null;
19
+ }
20
+ interface UnmanagedUserResponse extends BaseUserResponse {
21
+ user_type: 'unmanaged';
22
+ organization_memberships: OrganizationMembershipResponse[];
23
+ email_verified_at: string | null;
24
+ google_oauth_profile_id: string | null;
25
+ microsoft_oauth_profile_id: string | null;
26
+ }
27
+ export interface BaseUser {
28
+ object: 'user';
29
+ id: string;
30
+ email: string;
31
+ firstName: string | null;
32
+ lastName: string | null;
33
+ createdAt: string;
34
+ updatedAt: string;
35
+ }
36
+ interface BaseUserResponse {
37
+ object: 'user';
38
+ id: string;
39
+ email: string;
40
+ first_name: string | null;
41
+ last_name: string | null;
42
+ created_at: string;
43
+ updated_at: string;
44
+ }
45
+ export interface OrganizationMembership {
46
+ organization: OrganizationSummary;
47
+ createdAt: string;
48
+ updatedAt: string;
49
+ }
50
+ export interface OrganizationMembershipResponse {
51
+ organization: OrganizationSummary;
52
+ created_at: string;
53
+ updated_at: string;
54
+ }
55
+ interface OrganizationSummary {
56
+ id: string;
57
+ name: string;
58
+ }
59
+ export {};
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,18 @@
1
+ import { User, UserResponse } from './user.interface';
2
+ import { Session, SessionResponse } from './session.interface';
3
+ export interface VerifySessionOptions {
4
+ token: string;
5
+ clientId: string;
6
+ }
7
+ export interface SerializedVerifySessionOptions {
8
+ token: string;
9
+ client_id: string;
10
+ }
11
+ export interface VerifySessionResponse {
12
+ session: Session;
13
+ user: User;
14
+ }
15
+ export interface VerifySessionResponseResponse {
16
+ session: SessionResponse;
17
+ user: UserResponse;
18
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ import { AuthenticateUserWithPasswordOptions, SerializedAuthenticateUserWithPasswordOptions } from '../interfaces';
2
+ export declare const serializeAuthenticateUserWithPasswordOptions: (options: AuthenticateUserWithPasswordOptions) => SerializedAuthenticateUserWithPasswordOptions;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.serializeAuthenticateUserWithPasswordOptions = void 0;
4
+ const serializeAuthenticateUserWithPasswordOptions = (options) => ({
5
+ email: options.email,
6
+ password: options.password,
7
+ ip_address: options.ipAddress,
8
+ user_agent: options.userAgent,
9
+ start_session: options.startSession,
10
+ expires_in: options.expiresIn,
11
+ });
12
+ exports.serializeAuthenticateUserWithPasswordOptions = serializeAuthenticateUserWithPasswordOptions;
@@ -0,0 +1,2 @@
1
+ import { AuthenticateUserWithTokenCredentials, AuthenticateUserWithTokenOptions, SerializedAuthenticateUserWithTokenOptions } from '../interfaces';
2
+ export declare const serializeAuthenticateUserWithTokenOptions: (options: AuthenticateUserWithTokenOptions & AuthenticateUserWithTokenCredentials) => SerializedAuthenticateUserWithTokenOptions;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.serializeAuthenticateUserWithTokenOptions = void 0;
4
+ const serializeAuthenticateUserWithTokenOptions = (options) => ({
5
+ client_id: options.clientId,
6
+ client_secret: options.clientSecret,
7
+ code: options.code,
8
+ grant_type: options.grantType,
9
+ start_session: options.startSession,
10
+ expires_in: options.expiresIn,
11
+ });
12
+ exports.serializeAuthenticateUserWithTokenOptions = serializeAuthenticateUserWithTokenOptions;
@@ -0,0 +1,2 @@
1
+ import { AuthenticationResponse, AuthenticationResponseResponse } from '../interfaces';
2
+ export declare const deserializeAuthenticationResponse: (authenticationResponse: AuthenticationResponseResponse) => AuthenticationResponse;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.deserializeAuthenticationResponse = void 0;
4
+ const session_serializer_1 = require("./session.serializer");
5
+ const user_serializer_1 = require("./user.serializer");
6
+ const deserializeAuthenticationResponse = (authenticationResponse) => ({
7
+ session: authenticationResponse.session
8
+ ? (0, session_serializer_1.deserializeSession)(authenticationResponse.session)
9
+ : undefined,
10
+ user: (0, user_serializer_1.deserializeUser)(authenticationResponse.user),
11
+ });
12
+ exports.deserializeAuthenticationResponse = deserializeAuthenticationResponse;
@@ -0,0 +1,2 @@
1
+ import { CompletePasswordResetOptions, SerializedCompletePasswordResetOptions } from '../interfaces';
2
+ export declare const serializeCompletePasswordResetOptions: (options: CompletePasswordResetOptions) => SerializedCompletePasswordResetOptions;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.serializeCompletePasswordResetOptions = void 0;
4
+ const serializeCompletePasswordResetOptions = (options) => ({
5
+ token: options.token,
6
+ new_password: options.newPassword,
7
+ });
8
+ exports.serializeCompletePasswordResetOptions = serializeCompletePasswordResetOptions;
@@ -0,0 +1,2 @@
1
+ import { CreateEmailVerificationChallengeResponse, CreateEmailVerificationChallengeResponseResponse } from '../interfaces';
2
+ export declare const deserializeCreateEmailVerificationChallengeResponse: (createEmailVerificationChallengeResponse: CreateEmailVerificationChallengeResponseResponse) => CreateEmailVerificationChallengeResponse;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.deserializeCreateEmailVerificationChallengeResponse = void 0;
4
+ const user_serializer_1 = require("./user.serializer");
5
+ const deserializeCreateEmailVerificationChallengeResponse = (createEmailVerificationChallengeResponse) => ({
6
+ token: createEmailVerificationChallengeResponse.token,
7
+ user: (0, user_serializer_1.deserializeUser)(createEmailVerificationChallengeResponse.user),
8
+ });
9
+ exports.deserializeCreateEmailVerificationChallengeResponse = deserializeCreateEmailVerificationChallengeResponse;
@@ -0,0 +1,3 @@
1
+ import { CreatePasswordResetChallengeOptions, CreatePasswordResetChallengeResponse, CreatePasswordResetChallengeResponseResponse, SerializedCreatePasswordResetChallengeOptions } from '../interfaces';
2
+ export declare const deserializeCreatePasswordResetChallengeResponse: (createPasswordResetChallengeResponse: CreatePasswordResetChallengeResponseResponse) => CreatePasswordResetChallengeResponse;
3
+ export declare const serializeCreatePasswordResetChallengeOptions: (options: CreatePasswordResetChallengeOptions) => SerializedCreatePasswordResetChallengeOptions;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.serializeCreatePasswordResetChallengeOptions = exports.deserializeCreatePasswordResetChallengeResponse = void 0;
4
+ const user_serializer_1 = require("./user.serializer");
5
+ const deserializeCreatePasswordResetChallengeResponse = (createPasswordResetChallengeResponse) => ({
6
+ token: createPasswordResetChallengeResponse.token,
7
+ user: (0, user_serializer_1.deserializeUser)(createPasswordResetChallengeResponse.user),
8
+ });
9
+ exports.deserializeCreatePasswordResetChallengeResponse = deserializeCreatePasswordResetChallengeResponse;
10
+ const serializeCreatePasswordResetChallengeOptions = (options) => ({
11
+ email: options.email,
12
+ password_reset_url: options.passwordResetUrl,
13
+ });
14
+ exports.serializeCreatePasswordResetChallengeOptions = serializeCreatePasswordResetChallengeOptions;
@@ -0,0 +1,2 @@
1
+ import { CreateUserOptions, SerializedCreateUserOptions } from '../interfaces';
2
+ export declare const serializeCreateUserOptions: (options: CreateUserOptions) => SerializedCreateUserOptions;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.serializeCreateUserOptions = void 0;
4
+ const serializeCreateUserOptions = (options) => ({
5
+ email: options.email,
6
+ password: options.password,
7
+ first_name: options.firstName,
8
+ last_name: options.lastName,
9
+ email_verified: options.emailVerified,
10
+ });
11
+ exports.serializeCreateUserOptions = serializeCreateUserOptions;
@@ -0,0 +1,11 @@
1
+ export * from './authenticate-user-with-password-options.serializer';
2
+ export * from './authenticate-user-with-token-options.serializer';
3
+ export * from './authentication-response.serializer';
4
+ export * from './complete-password-reset-options.serializer';
5
+ export * from './create-email-verification-challenge.serializer';
6
+ export * from './create-password-reset-challenge.serializer';
7
+ export * from './create-user-options.serializer';
8
+ export * from './revoke-session-options.serializer';
9
+ export * from './session.serializer';
10
+ export * from './user.serializer';
11
+ export * from './verify-session.serializer';
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./authenticate-user-with-password-options.serializer"), exports);
18
+ __exportStar(require("./authenticate-user-with-token-options.serializer"), exports);
19
+ __exportStar(require("./authentication-response.serializer"), exports);
20
+ __exportStar(require("./complete-password-reset-options.serializer"), exports);
21
+ __exportStar(require("./create-email-verification-challenge.serializer"), exports);
22
+ __exportStar(require("./create-password-reset-challenge.serializer"), exports);
23
+ __exportStar(require("./create-user-options.serializer"), exports);
24
+ __exportStar(require("./revoke-session-options.serializer"), exports);
25
+ __exportStar(require("./session.serializer"), exports);
26
+ __exportStar(require("./user.serializer"), exports);
27
+ __exportStar(require("./verify-session.serializer"), exports);
@@ -0,0 +1,2 @@
1
+ import { RevokeSessionOptions, SerializedRevokeSessionOptions } from '../interfaces';
2
+ export declare const serializeRevokeSessionOptions: (options: RevokeSessionOptions) => SerializedRevokeSessionOptions;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.serializeRevokeSessionOptions = void 0;
4
+ const serializeRevokeSessionOptions = (options) => {
5
+ if ('sessionId' in options) {
6
+ return {
7
+ session_id: options.sessionId,
8
+ };
9
+ }
10
+ return {
11
+ session_token: options.sessionToken,
12
+ };
13
+ };
14
+ exports.serializeRevokeSessionOptions = serializeRevokeSessionOptions;
@@ -0,0 +1,2 @@
1
+ import { Session, SessionResponse } from '../interfaces/session.interface';
2
+ export declare const deserializeSession: (session: SessionResponse) => Session;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.deserializeSession = void 0;
4
+ const deserializeSession = (session) => ({
5
+ id: session.id,
6
+ createdAt: session.created_at,
7
+ expiresAt: session.expires_at,
8
+ token: session.token,
9
+ });
10
+ exports.deserializeSession = deserializeSession;
@@ -0,0 +1,2 @@
1
+ import { User, UserResponse } from '../interfaces';
2
+ export declare const deserializeUser: (user: UserResponse) => User;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.deserializeUser = void 0;
4
+ const exceptions_1 = require("../exceptions");
5
+ const deserializeUser = (user) => {
6
+ const baseUser = {
7
+ object: user.object,
8
+ id: user.id,
9
+ email: user.email,
10
+ firstName: user.first_name,
11
+ lastName: user.last_name,
12
+ createdAt: user.created_at,
13
+ updatedAt: user.updated_at,
14
+ };
15
+ switch (user.user_type) {
16
+ case 'managed':
17
+ return Object.assign(Object.assign({}, baseUser), { userType: user.user_type, organizationMemberships: [
18
+ deserializeOrganizationMembership(user.organization_memberships[0]),
19
+ ], ssoProfileId: user.sso_profile_id });
20
+ case 'unmanaged':
21
+ return Object.assign(Object.assign({}, baseUser), { userType: user.user_type, organizationMemberships: user.organization_memberships.map(deserializeOrganizationMembership), emailVerifiedAt: user.email_verified_at, googleOauthProfileId: user.google_oauth_profile_id, microsoftOauthProfileId: user.microsoft_oauth_profile_id });
22
+ default:
23
+ throw new exceptions_1.UnexpectedUserTypeException(user);
24
+ }
25
+ };
26
+ exports.deserializeUser = deserializeUser;
27
+ const deserializeOrganizationMembership = (organizationMembership) => ({
28
+ organization: organizationMembership.organization,
29
+ createdAt: organizationMembership.created_at,
30
+ updatedAt: organizationMembership.updated_at,
31
+ });
@@ -0,0 +1,3 @@
1
+ import { SerializedVerifySessionOptions, VerifySessionOptions, VerifySessionResponse, VerifySessionResponseResponse } from '../interfaces';
2
+ export declare const deserializeVerifySessionResponse: (verifySessionResponse: VerifySessionResponseResponse) => VerifySessionResponse;
3
+ export declare const serializeVerifySessionOptions: (options: VerifySessionOptions) => SerializedVerifySessionOptions;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.serializeVerifySessionOptions = exports.deserializeVerifySessionResponse = void 0;
4
+ const session_serializer_1 = require("./session.serializer");
5
+ const user_serializer_1 = require("./user.serializer");
6
+ const deserializeVerifySessionResponse = (verifySessionResponse) => ({
7
+ session: (0, session_serializer_1.deserializeSession)(verifySessionResponse.session),
8
+ user: (0, user_serializer_1.deserializeUser)(verifySessionResponse.user),
9
+ });
10
+ exports.deserializeVerifySessionResponse = deserializeVerifySessionResponse;
11
+ const serializeVerifySessionOptions = (options) => ({
12
+ token: options.token,
13
+ client_id: options.clientId,
14
+ });
15
+ exports.serializeVerifySessionOptions = serializeVerifySessionOptions;
@@ -0,0 +1,21 @@
1
+ import { WorkOS } from '../workos';
2
+ import { AddUserToOrganizationOptions, AuthenticateUserWithPasswordOptions, AuthenticateUserWithTokenOptions, AuthenticationResponse, CompletePasswordResetOptions, CreateEmailVerificationChallengeOptions, CreateEmailVerificationChallengeResponse, CreatePasswordResetChallengeOptions, CreatePasswordResetChallengeResponse, CreateUserOptions, ListUsersOptions, RemoveUserFromOrganizationOptions, RevokeSessionOptions, User, VerifySessionOptions, VerifySessionResponse } from './interfaces';
3
+ import { DeserializedList } from '../common/interfaces';
4
+ export declare class Users {
5
+ private readonly workos;
6
+ constructor(workos: WorkOS);
7
+ getUser(userId: string): Promise<User>;
8
+ listUsers(options?: ListUsersOptions): Promise<DeserializedList<User>>;
9
+ createUser(payload: CreateUserOptions): Promise<User>;
10
+ authenticateUserWithPassword(payload: AuthenticateUserWithPasswordOptions): Promise<AuthenticationResponse>;
11
+ authenticateUserWithToken(payload: AuthenticateUserWithTokenOptions): Promise<AuthenticationResponse>;
12
+ verifySession(payload: VerifySessionOptions): Promise<VerifySessionResponse>;
13
+ revokeSession(payload: RevokeSessionOptions): Promise<boolean>;
14
+ revokeAllSessionsForUser(userId: string): Promise<boolean>;
15
+ createEmailVerificationChallenge({ userId, verificationUrl, }: CreateEmailVerificationChallengeOptions): Promise<CreateEmailVerificationChallengeResponse>;
16
+ completeEmailVerification(token: string): Promise<User>;
17
+ createPasswordResetChallenge(payload: CreatePasswordResetChallengeOptions): Promise<CreatePasswordResetChallengeResponse>;
18
+ completePasswordReset(payload: CompletePasswordResetOptions): Promise<User>;
19
+ addUserToOrganization({ userId, organizationId, }: AddUserToOrganizationOptions): Promise<User>;
20
+ removeUserFromOrganization({ userId, organizationId, }: RemoveUserFromOrganizationOptions): Promise<User>;
21
+ }
@@ -0,0 +1,112 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.Users = void 0;
13
+ const serializers_1 = require("./serializers");
14
+ const serializers_2 = require("../common/serializers");
15
+ class Users {
16
+ constructor(workos) {
17
+ this.workos = workos;
18
+ }
19
+ getUser(userId) {
20
+ return __awaiter(this, void 0, void 0, function* () {
21
+ const { data } = yield this.workos.get(`/users/${userId}`);
22
+ return (0, serializers_1.deserializeUser)(data);
23
+ });
24
+ }
25
+ listUsers(options) {
26
+ return __awaiter(this, void 0, void 0, function* () {
27
+ const { data } = yield this.workos.get('/users', {
28
+ query: options,
29
+ });
30
+ return (0, serializers_2.deserializeList)(data, serializers_1.deserializeUser);
31
+ });
32
+ }
33
+ createUser(payload) {
34
+ return __awaiter(this, void 0, void 0, function* () {
35
+ const { data } = yield this.workos.post('/users', (0, serializers_1.serializeCreateUserOptions)(payload));
36
+ return (0, serializers_1.deserializeUser)(data);
37
+ });
38
+ }
39
+ authenticateUserWithPassword(payload) {
40
+ return __awaiter(this, void 0, void 0, function* () {
41
+ const { data } = yield this.workos.post('/users/authentications', (0, serializers_1.serializeAuthenticateUserWithPasswordOptions)(payload));
42
+ return (0, serializers_1.deserializeAuthenticationResponse)(data);
43
+ });
44
+ }
45
+ authenticateUserWithToken(payload) {
46
+ return __awaiter(this, void 0, void 0, function* () {
47
+ const { data } = yield this.workos.post('/users/sessions/token', (0, serializers_1.serializeAuthenticateUserWithTokenOptions)(Object.assign(Object.assign({}, payload), { clientSecret: this.workos.key, grantType: 'authorization_code' })));
48
+ return (0, serializers_1.deserializeAuthenticationResponse)(data);
49
+ });
50
+ }
51
+ verifySession(payload) {
52
+ return __awaiter(this, void 0, void 0, function* () {
53
+ const { data } = yield this.workos.post('/users/sessions/verify', (0, serializers_1.serializeVerifySessionOptions)(payload));
54
+ return (0, serializers_1.deserializeVerifySessionResponse)(data);
55
+ });
56
+ }
57
+ revokeSession(payload) {
58
+ return __awaiter(this, void 0, void 0, function* () {
59
+ const { data } = yield this.workos.post('/users/sessions/revocations', (0, serializers_1.serializeRevokeSessionOptions)(payload));
60
+ return data;
61
+ });
62
+ }
63
+ revokeAllSessionsForUser(userId) {
64
+ return __awaiter(this, void 0, void 0, function* () {
65
+ const { data } = yield this.workos.delete(`/users/${userId}/sessions`);
66
+ return data;
67
+ });
68
+ }
69
+ createEmailVerificationChallenge({ userId, verificationUrl, }) {
70
+ return __awaiter(this, void 0, void 0, function* () {
71
+ const { data } = yield this.workos.post(`/users/${userId}/email_verification_challenge`, {
72
+ verification_url: verificationUrl,
73
+ });
74
+ return (0, serializers_1.deserializeCreateEmailVerificationChallengeResponse)(data);
75
+ });
76
+ }
77
+ completeEmailVerification(token) {
78
+ return __awaiter(this, void 0, void 0, function* () {
79
+ const { data } = yield this.workos.post('/users/email_verification', {
80
+ token,
81
+ });
82
+ return (0, serializers_1.deserializeUser)(data);
83
+ });
84
+ }
85
+ createPasswordResetChallenge(payload) {
86
+ return __awaiter(this, void 0, void 0, function* () {
87
+ const { data } = yield this.workos.post('/users/password_reset_challenge', (0, serializers_1.serializeCreatePasswordResetChallengeOptions)(payload));
88
+ return (0, serializers_1.deserializeCreatePasswordResetChallengeResponse)(data);
89
+ });
90
+ }
91
+ completePasswordReset(payload) {
92
+ return __awaiter(this, void 0, void 0, function* () {
93
+ const { data } = yield this.workos.post('/users/password_reset', (0, serializers_1.serializeCompletePasswordResetOptions)(payload));
94
+ return (0, serializers_1.deserializeUser)(data);
95
+ });
96
+ }
97
+ addUserToOrganization({ userId, organizationId, }) {
98
+ return __awaiter(this, void 0, void 0, function* () {
99
+ const { data } = yield this.workos.post(`/users/${userId}/organizations`, {
100
+ organization_id: organizationId,
101
+ });
102
+ return (0, serializers_1.deserializeUser)(data);
103
+ });
104
+ }
105
+ removeUserFromOrganization({ userId, organizationId, }) {
106
+ return __awaiter(this, void 0, void 0, function* () {
107
+ const { data } = yield this.workos.delete(`/users/${userId}/organizations/${organizationId}`);
108
+ return (0, serializers_1.deserializeUser)(data);
109
+ });
110
+ }
111
+ }
112
+ exports.Users = Users;
@@ -0,0 +1 @@
1
+ export {};