@workos-inc/node 3.9.1 → 4.0.0

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 (162) hide show
  1. package/lib/common/interfaces/event.interface.d.ts +45 -3
  2. package/lib/common/serializers/event.serializer.js +9 -0
  3. package/lib/directory-sync/interfaces/directory-user.interface.d.ts +12 -12
  4. package/lib/index.d.ts +1 -2
  5. package/lib/index.js +1 -2
  6. package/lib/mfa/interfaces/challenge.interface.d.ts +2 -2
  7. package/lib/mfa/interfaces/factor.interface.d.ts +23 -3
  8. package/lib/mfa/interfaces/totp.interface.d.ts +4 -0
  9. package/lib/mfa/mfa.d.ts +2 -2
  10. package/lib/mfa/mfa.js +1 -1
  11. package/lib/mfa/mfa.spec.js +0 -6
  12. package/lib/mfa/serializers/factor.serializer.d.ts +2 -1
  13. package/lib/mfa/serializers/factor.serializer.js +3 -1
  14. package/lib/mfa/serializers/totp.serializer.d.ts +2 -1
  15. package/lib/mfa/serializers/totp.serializer.js +17 -8
  16. package/lib/sso/interfaces/authorization-url-options.interface.d.ts +2 -2
  17. package/lib/sso/interfaces/get-profile-and-token-options.interface.d.ts +1 -1
  18. package/lib/sso/sso.d.ts +2 -2
  19. package/lib/sso/sso.js +5 -5
  20. package/lib/sso/sso.spec.js +30 -30
  21. package/lib/user-management/fixtures/invitation.json +13 -0
  22. package/lib/{users → user-management}/fixtures/list-factors.json +0 -3
  23. package/lib/user-management/fixtures/list-invitations.json +22 -0
  24. package/lib/user-management/fixtures/list-organization-memberships.json +17 -0
  25. package/lib/user-management/fixtures/organization-membership.json +8 -0
  26. package/lib/user-management/interfaces/authenticate-with-code-options.interface.d.ts +11 -0
  27. package/lib/user-management/interfaces/authenticate-with-email-verification-options.interface.d.ts +13 -0
  28. package/lib/user-management/interfaces/authenticate-with-magic-auth-options.interface.d.ts +15 -0
  29. package/lib/user-management/interfaces/authenticate-with-options-base.interface.d.ts +11 -0
  30. package/lib/user-management/interfaces/authenticate-with-organization-selection.interface.d.ts +13 -0
  31. package/lib/user-management/interfaces/authenticate-with-password-options.interface.d.ts +13 -0
  32. package/lib/{users → user-management}/interfaces/authenticate-with-totp-options.interface.d.ts +3 -9
  33. package/lib/{users → user-management}/interfaces/authentication-response.interface.d.ts +2 -0
  34. package/lib/user-management/interfaces/authorization-url-options.interface.d.ts +10 -0
  35. package/lib/user-management/interfaces/create-organization-membership-options.interface.d.ts +8 -0
  36. package/lib/{users → user-management}/interfaces/enroll-auth-factor.interface.d.ts +4 -4
  37. package/lib/user-management/interfaces/factor.interface.d.ts +37 -0
  38. package/lib/{users → user-management}/interfaces/index.d.ts +2 -5
  39. package/lib/{users → user-management}/interfaces/index.js +2 -5
  40. package/lib/user-management/interfaces/invitation.interface.d.ts +26 -0
  41. package/lib/user-management/interfaces/list-invitations-options.interface.d.ts +9 -0
  42. package/lib/user-management/interfaces/list-organization-memberships-options.interface.d.ts +9 -0
  43. package/lib/{users → user-management}/interfaces/list-users-options.interface.d.ts +5 -1
  44. package/lib/user-management/interfaces/organization-membership.interface.d.ts +16 -0
  45. package/lib/user-management/interfaces/send-invitation-options.interface.d.ts +12 -0
  46. package/lib/user-management/interfaces/send-password-reset-email-options.interface.d.ts +8 -0
  47. package/lib/{users → user-management}/interfaces/update-user-options.interface.d.ts +6 -0
  48. package/lib/user-management/interfaces/update-user-password-options.interface.js +2 -0
  49. package/lib/user-management/interfaces/user.interface.js +2 -0
  50. package/lib/user-management/interfaces/verify-email-options.interface.d.ts +7 -0
  51. package/lib/user-management/interfaces/verify-email-options.interface.js +2 -0
  52. package/lib/user-management/serializers/authenticate-with-email-verification.serializer.d.ts +2 -0
  53. package/lib/user-management/serializers/authenticate-with-email-verification.serializer.js +13 -0
  54. package/lib/{users → user-management}/serializers/authenticate-with-magic-auth-options.serializer.js +2 -1
  55. package/lib/user-management/serializers/authenticate-with-organization-selection-options.serializer.d.ts +2 -0
  56. package/lib/user-management/serializers/authenticate-with-organization-selection-options.serializer.js +13 -0
  57. package/lib/{users → user-management}/serializers/authentication-response.serializer.js +1 -0
  58. package/lib/user-management/serializers/create-organization-membership-options.serializer.d.ts +2 -0
  59. package/lib/user-management/serializers/create-organization-membership-options.serializer.js +8 -0
  60. package/lib/user-management/serializers/factor.serializer.d.ts +3 -0
  61. package/lib/user-management/serializers/factor.serializer.js +24 -0
  62. package/lib/{users → user-management}/serializers/index.d.ts +1 -0
  63. package/lib/{users → user-management}/serializers/index.js +1 -0
  64. package/lib/user-management/serializers/invitation.serializer.d.ts +2 -0
  65. package/lib/user-management/serializers/invitation.serializer.js +17 -0
  66. package/lib/user-management/serializers/list-invitations-options.serializer.d.ts +2 -0
  67. package/lib/user-management/serializers/list-invitations-options.serializer.js +12 -0
  68. package/lib/user-management/serializers/list-organization-memberships-options.serializer.d.ts +2 -0
  69. package/lib/user-management/serializers/list-organization-memberships-options.serializer.js +12 -0
  70. package/lib/user-management/serializers/list-users-options.serializer.d.ts +2 -0
  71. package/lib/user-management/serializers/list-users-options.serializer.js +12 -0
  72. package/lib/user-management/serializers/organization-membership.serializer.d.ts +2 -0
  73. package/lib/user-management/serializers/organization-membership.serializer.js +12 -0
  74. package/lib/user-management/serializers/send-invitation-options.serializer.d.ts +2 -0
  75. package/lib/user-management/serializers/send-invitation-options.serializer.js +10 -0
  76. package/lib/user-management/serializers/send-password-reset-email.serializer.d.ts +2 -0
  77. package/lib/user-management/serializers/send-password-reset-email.serializer.js +8 -0
  78. package/lib/{users → user-management}/serializers/update-user-options.serializer.js +3 -0
  79. package/lib/user-management/user-management.d.ts +54 -0
  80. package/lib/user-management/user-management.js +215 -0
  81. package/lib/user-management/user-management.spec.js +745 -0
  82. package/lib/workos.d.ts +2 -4
  83. package/lib/workos.js +3 -5
  84. package/package.json +1 -1
  85. package/lib/audit-trail/audit-trail.d.ts +0 -12
  86. package/lib/audit-trail/audit-trail.js +0 -31
  87. package/lib/audit-trail/audit-trail.spec.js +0 -183
  88. package/lib/audit-trail/interfaces/create-event-options.interface.d.ts +0 -3
  89. package/lib/audit-trail/interfaces/event-options.interface.d.ts +0 -14
  90. package/lib/audit-trail/interfaces/event.interface.d.ts +0 -23
  91. package/lib/audit-trail/interfaces/index.d.ts +0 -4
  92. package/lib/audit-trail/interfaces/list-events-options.interface.d.ts +0 -16
  93. package/lib/users/interfaces/add-user-to-organization-options.interface.d.ts +0 -7
  94. package/lib/users/interfaces/authenticate-with-code-options.interface.d.ts +0 -17
  95. package/lib/users/interfaces/authenticate-with-magic-auth-options.interface.d.ts +0 -19
  96. package/lib/users/interfaces/authenticate-with-password-options.interface.d.ts +0 -19
  97. package/lib/users/interfaces/delete-user-options.interface.d.ts +0 -3
  98. package/lib/users/interfaces/remove-user-from-organization-options.interface.d.ts +0 -4
  99. package/lib/users/interfaces/send-password-reset-options.interface.d.ts +0 -17
  100. package/lib/users/interfaces/verify-email-code-options.interface.d.ts +0 -7
  101. package/lib/users/serializers/send-password-reset-email.serializer.d.ts +0 -3
  102. package/lib/users/serializers/send-password-reset-email.serializer.js +0 -14
  103. package/lib/users/users.d.ts +0 -38
  104. package/lib/users/users.js +0 -140
  105. package/lib/users/users.spec.d.ts +0 -1
  106. package/lib/users/users.spec.js +0 -462
  107. /package/lib/{users → user-management}/fixtures/list-users.json +0 -0
  108. /package/lib/{users → user-management}/fixtures/user.json +0 -0
  109. /package/lib/{users → user-management}/interfaces/authenticate-with-code-options.interface.js +0 -0
  110. /package/lib/{audit-trail/interfaces/create-event-options.interface.js → user-management/interfaces/authenticate-with-email-verification-options.interface.js} +0 -0
  111. /package/lib/{users → user-management}/interfaces/authenticate-with-magic-auth-options.interface.js +0 -0
  112. /package/lib/{audit-trail/interfaces/event-options.interface.js → user-management/interfaces/authenticate-with-options-base.interface.js} +0 -0
  113. /package/lib/{audit-trail/interfaces/event.interface.js → user-management/interfaces/authenticate-with-organization-selection.interface.js} +0 -0
  114. /package/lib/{users → user-management}/interfaces/authenticate-with-password-options.interface.js +0 -0
  115. /package/lib/{users → user-management}/interfaces/authenticate-with-totp-options.interface.js +0 -0
  116. /package/lib/{users → user-management}/interfaces/authentication-response.interface.js +0 -0
  117. /package/lib/{audit-trail/interfaces/index.js → user-management/interfaces/authorization-url-options.interface.js} +0 -0
  118. /package/lib/{audit-trail/interfaces/list-events-options.interface.js → user-management/interfaces/create-organization-membership-options.interface.js} +0 -0
  119. /package/lib/{users → user-management}/interfaces/create-user-options.interface.d.ts +0 -0
  120. /package/lib/{users → user-management}/interfaces/create-user-options.interface.js +0 -0
  121. /package/lib/{users → user-management}/interfaces/enroll-auth-factor.interface.js +0 -0
  122. /package/lib/{users/interfaces/add-user-to-organization-options.interface.js → user-management/interfaces/factor.interface.js} +0 -0
  123. /package/lib/{users/interfaces/delete-user-options.interface.js → user-management/interfaces/invitation.interface.js} +0 -0
  124. /package/lib/{users → user-management}/interfaces/list-auth-factors-options.interface.d.ts +0 -0
  125. /package/lib/{users → user-management}/interfaces/list-auth-factors-options.interface.js +0 -0
  126. /package/lib/{users/interfaces/list-users-options.interface.js → user-management/interfaces/list-invitations-options.interface.js} +0 -0
  127. /package/lib/{users/interfaces/remove-user-from-organization-options.interface.js → user-management/interfaces/list-organization-memberships-options.interface.js} +0 -0
  128. /package/lib/{users/interfaces/reset-password-options.interface.js → user-management/interfaces/list-users-options.interface.js} +0 -0
  129. /package/lib/{users/interfaces/send-magic-auth-code-options.interface.js → user-management/interfaces/organization-membership.interface.js} +0 -0
  130. /package/lib/{users → user-management}/interfaces/reset-password-options.interface.d.ts +0 -0
  131. /package/lib/{users/interfaces/send-password-reset-options.interface.js → user-management/interfaces/reset-password-options.interface.js} +0 -0
  132. /package/lib/{users/interfaces/send-verification-email-options.js → user-management/interfaces/send-invitation-options.interface.js} +0 -0
  133. /package/lib/{users → user-management}/interfaces/send-magic-auth-code-options.interface.d.ts +0 -0
  134. /package/lib/{users/interfaces/update-user-options.interface.js → user-management/interfaces/send-magic-auth-code-options.interface.js} +0 -0
  135. /package/lib/{users/interfaces/update-user-password-options.interface.js → user-management/interfaces/send-password-reset-email-options.interface.js} +0 -0
  136. /package/lib/{users → user-management}/interfaces/send-verification-email-options.d.ts +0 -0
  137. /package/lib/{users/interfaces/user.interface.js → user-management/interfaces/send-verification-email-options.js} +0 -0
  138. /package/lib/{users/interfaces/verify-email-code-options.interface.js → user-management/interfaces/update-user-options.interface.js} +0 -0
  139. /package/lib/{users → user-management}/interfaces/update-user-password-options.interface.d.ts +0 -0
  140. /package/lib/{users → user-management}/interfaces/user.interface.d.ts +0 -0
  141. /package/lib/{users → user-management}/serializers/authenticate-with-code-options.serializer.d.ts +0 -0
  142. /package/lib/{users → user-management}/serializers/authenticate-with-code-options.serializer.js +0 -0
  143. /package/lib/{users → user-management}/serializers/authenticate-with-magic-auth-options.serializer.d.ts +0 -0
  144. /package/lib/{users → user-management}/serializers/authenticate-with-password-options.serializer.d.ts +0 -0
  145. /package/lib/{users → user-management}/serializers/authenticate-with-password-options.serializer.js +0 -0
  146. /package/lib/{users → user-management}/serializers/authenticate-with-totp-options.serializer.d.ts +0 -0
  147. /package/lib/{users → user-management}/serializers/authenticate-with-totp-options.serializer.js +0 -0
  148. /package/lib/{users → user-management}/serializers/authentication-response.serializer.d.ts +0 -0
  149. /package/lib/{users → user-management}/serializers/create-user-options.serializer.d.ts +0 -0
  150. /package/lib/{users → user-management}/serializers/create-user-options.serializer.js +0 -0
  151. /package/lib/{users → user-management}/serializers/enroll-auth-factor-options.serializer.d.ts +0 -0
  152. /package/lib/{users → user-management}/serializers/enroll-auth-factor-options.serializer.js +0 -0
  153. /package/lib/{users → user-management}/serializers/reset-password-options.serializer.d.ts +0 -0
  154. /package/lib/{users → user-management}/serializers/reset-password-options.serializer.js +0 -0
  155. /package/lib/{users → user-management}/serializers/send-magic-auth-code-options.serializer.d.ts +0 -0
  156. /package/lib/{users → user-management}/serializers/send-magic-auth-code-options.serializer.js +0 -0
  157. /package/lib/{users → user-management}/serializers/update-user-options.serializer.d.ts +0 -0
  158. /package/lib/{users → user-management}/serializers/update-user-password-options.serializer.d.ts +0 -0
  159. /package/lib/{users → user-management}/serializers/update-user-password-options.serializer.js +0 -0
  160. /package/lib/{users → user-management}/serializers/user.serializer.d.ts +0 -0
  161. /package/lib/{users → user-management}/serializers/user.serializer.js +0 -0
  162. /package/lib/{audit-trail/audit-trail.spec.d.ts → user-management/user-management.spec.d.ts} +0 -0
package/lib/workos.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import { AxiosResponse } from 'axios';
2
- import { AuditTrail } from './audit-trail/audit-trail';
3
2
  import { GetOptions, PostOptions, PutOptions, WorkOSOptions } from './common/interfaces';
4
3
  import { DirectorySync } from './directory-sync/directory-sync';
5
4
  import { Events } from './events/events';
@@ -11,14 +10,13 @@ import { SSO } from './sso/sso';
11
10
  import { Webhooks } from './webhooks/webhooks';
12
11
  import { Mfa } from './mfa/mfa';
13
12
  import { AuditLogs } from './audit-logs/audit-logs';
14
- import { Users } from './users/users';
13
+ import { UserManagement } from './user-management/user-management';
15
14
  export declare class WorkOS {
16
15
  readonly key?: string | undefined;
17
16
  readonly options: WorkOSOptions;
18
17
  readonly baseURL: string;
19
18
  private readonly client;
20
19
  readonly auditLogs: AuditLogs;
21
- readonly auditTrail: AuditTrail;
22
20
  readonly directorySync: DirectorySync;
23
21
  readonly organizations: Organizations;
24
22
  readonly organizationDomains: OrganizationDomains;
@@ -28,7 +26,7 @@ export declare class WorkOS {
28
26
  readonly webhooks: Webhooks;
29
27
  readonly mfa: Mfa;
30
28
  readonly events: Events;
31
- readonly users: Users;
29
+ readonly userManagement: UserManagement;
32
30
  constructor(key?: string | undefined, options?: WorkOSOptions);
33
31
  get version(): string;
34
32
  post<T = any, D = any, P = any>(path: string, entity: P, options?: PostOptions): Promise<AxiosResponse<T, D>>;
package/lib/workos.js CHANGED
@@ -14,7 +14,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.WorkOS = void 0;
16
16
  const axios_1 = __importDefault(require("axios"));
17
- const audit_trail_1 = require("./audit-trail/audit-trail");
18
17
  const exceptions_1 = require("./common/exceptions");
19
18
  const directory_sync_1 = require("./directory-sync/directory-sync");
20
19
  const events_1 = require("./events/events");
@@ -26,9 +25,9 @@ const sso_1 = require("./sso/sso");
26
25
  const webhooks_1 = require("./webhooks/webhooks");
27
26
  const mfa_1 = require("./mfa/mfa");
28
27
  const audit_logs_1 = require("./audit-logs/audit-logs");
29
- const users_1 = require("./users/users");
28
+ const user_management_1 = require("./user-management/user-management");
30
29
  const bad_request_exception_1 = require("./common/exceptions/bad-request.exception");
31
- const VERSION = '3.9.1';
30
+ const VERSION = '4.0.0';
32
31
  const DEFAULT_HOSTNAME = 'api.workos.com';
33
32
  class WorkOS {
34
33
  constructor(key, options = {}) {
@@ -36,7 +35,6 @@ class WorkOS {
36
35
  this.key = key;
37
36
  this.options = options;
38
37
  this.auditLogs = new audit_logs_1.AuditLogs(this);
39
- this.auditTrail = new audit_trail_1.AuditTrail(this);
40
38
  this.directorySync = new directory_sync_1.DirectorySync(this);
41
39
  this.organizations = new organizations_1.Organizations(this);
42
40
  this.organizationDomains = new organization_domains_1.OrganizationDomains(this);
@@ -46,7 +44,7 @@ class WorkOS {
46
44
  this.webhooks = new webhooks_1.Webhooks();
47
45
  this.mfa = new mfa_1.Mfa(this);
48
46
  this.events = new events_1.Events(this);
49
- this.users = new users_1.Users(this);
47
+ this.userManagement = new user_management_1.UserManagement(this);
50
48
  if (!key) {
51
49
  this.key = process.env.WORKOS_API_KEY;
52
50
  if (!this.key) {
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "3.9.1",
2
+ "version": "4.0.0",
3
3
  "name": "@workos-inc/node",
4
4
  "author": "WorkOS",
5
5
  "description": "A Node wrapper for the WorkOS API",
@@ -1,12 +0,0 @@
1
- import { CreateEventOptions } from './interfaces/create-event-options.interface';
2
- import { AuditTrailEvent } from './interfaces/event.interface';
3
- import { EventOptions } from './interfaces/event-options.interface';
4
- import { ListResponse } from '../common/interfaces';
5
- import { ListEventsOptions } from './interfaces/list-events-options.interface';
6
- import { WorkOS } from '../workos';
7
- export declare class AuditTrail {
8
- private readonly workos;
9
- constructor(workos: WorkOS);
10
- createEvent(event: EventOptions, { idempotencyKey }?: CreateEventOptions): Promise<void>;
11
- listEvents(options?: ListEventsOptions): Promise<ListResponse<AuditTrailEvent>>;
12
- }
@@ -1,31 +0,0 @@
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.AuditTrail = void 0;
13
- class AuditTrail {
14
- constructor(workos) {
15
- this.workos = workos;
16
- }
17
- createEvent(event, { idempotencyKey } = {}) {
18
- return __awaiter(this, void 0, void 0, function* () {
19
- yield this.workos.post('/events', event, { idempotencyKey });
20
- });
21
- }
22
- listEvents(options) {
23
- return __awaiter(this, void 0, void 0, function* () {
24
- const { data } = yield this.workos.get('/events', {
25
- query: options,
26
- });
27
- return data;
28
- });
29
- }
30
- }
31
- exports.AuditTrail = AuditTrail;
@@ -1,183 +0,0 @@
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
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- const axios_1 = __importDefault(require("axios"));
16
- const axios_mock_adapter_1 = __importDefault(require("axios-mock-adapter"));
17
- const exceptions_1 = require("../common/exceptions");
18
- const workos_1 = require("../workos");
19
- const mock = new axios_mock_adapter_1.default(axios_1.default);
20
- const event = {
21
- group: 'WorkOS',
22
- actor_name: 'WorkOS@example.com',
23
- actor_id: 'user_1',
24
- location: ' 192.0.0.8',
25
- occurred_at: new Date(0),
26
- target_name: 'Security Audit 2018',
27
- target_id: 'document_39127',
28
- action_type: 'U',
29
- action: 'document.updated',
30
- };
31
- const serializeEventOptions = (options) => (Object.assign(Object.assign({}, options), { occurred_at: options.occurred_at.toISOString() }));
32
- describe('AuditTrail', () => {
33
- describe('createEvent', () => {
34
- describe('when the api responds with a 201 CREATED', () => {
35
- describe('with an idempotency key', () => {
36
- it('includes an idempotency key with request', () => __awaiter(void 0, void 0, void 0, function* () {
37
- var _a;
38
- mock
39
- .onPost('/events', serializeEventOptions(event))
40
- .replyOnce(201, { success: true });
41
- const workos = new workos_1.WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU');
42
- yield expect(workos.auditTrail.createEvent(event, {
43
- idempotencyKey: 'the-idempotency-key',
44
- })).resolves.toBeUndefined();
45
- expect((_a = mock.history.post[0].headers) === null || _a === void 0 ? void 0 : _a['Idempotency-Key']).toEqual('the-idempotency-key');
46
- }));
47
- });
48
- it('posts Event successfully', () => __awaiter(void 0, void 0, void 0, function* () {
49
- mock
50
- .onPost('/events', serializeEventOptions(event))
51
- .replyOnce(201, { success: true });
52
- const workos = new workos_1.WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU');
53
- yield expect(workos.auditTrail.createEvent(event)).resolves.toBeUndefined();
54
- }));
55
- });
56
- describe('when the api responds with a 401', () => {
57
- it('throws an UnauthorizedException', () => __awaiter(void 0, void 0, void 0, function* () {
58
- mock.onPost('/events', serializeEventOptions(event)).replyOnce(401, {
59
- message: 'Unauthorized',
60
- }, { 'X-Request-ID': 'a-request-id' });
61
- const workos = new workos_1.WorkOS('invalid apikey');
62
- yield expect(workos.auditTrail.createEvent(event)).rejects.toStrictEqual(new exceptions_1.UnauthorizedException('a-request-id'));
63
- }));
64
- });
65
- describe('when the api responds with a 422', () => {
66
- it('throws an UnprocessableEntity', () => __awaiter(void 0, void 0, void 0, function* () {
67
- const errors = [
68
- {
69
- field: 'target_id',
70
- code: 'target_id must be a string',
71
- },
72
- {
73
- field: 'occurred_at',
74
- code: 'occurred_at must be an ISO 8601 date string',
75
- },
76
- ];
77
- mock.onPost('/events', serializeEventOptions(event)).replyOnce(422, {
78
- message: 'Validation failed',
79
- errors,
80
- }, { 'X-Request-ID': 'a-request-id' });
81
- const workos = new workos_1.WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU');
82
- yield expect(workos.auditTrail.createEvent(event)).rejects.toMatchSnapshot();
83
- }));
84
- });
85
- });
86
- describe('listEvents', () => {
87
- describe('With no filters', () => {
88
- it('Returns all events', () => __awaiter(void 0, void 0, void 0, function* () {
89
- mock.onGet('/events').replyOnce(200, {
90
- data: [
91
- {
92
- object: 'event',
93
- id: 'evt_0',
94
- group: 'foo-corp.com',
95
- latitude: null,
96
- longitude: null,
97
- location: '::1',
98
- type: 'r',
99
- actor_name: 'demo@foo-corp.com',
100
- actor_id: 'user_0',
101
- target_name: 'http_request',
102
- target_id: '',
103
- metadata: {},
104
- occurred_at: new Date(),
105
- action: {
106
- object: 'event_action',
107
- id: 'evt_action_0',
108
- name: 'user.searched_directories',
109
- },
110
- },
111
- {
112
- object: 'event',
113
- id: 'evt_1',
114
- group: 'workos.com',
115
- location: '::1',
116
- latitude: null,
117
- longitude: null,
118
- type: 'r',
119
- actor_name: 'foo@example.com',
120
- actor_id: 'user_1',
121
- target_name: 'api_key_query',
122
- target_id: 'key_0',
123
- metadata: {
124
- description: 'User viewed API key.',
125
- x_request_id: '',
126
- },
127
- occurred_at: new Date('2020-07-31T14:27:00.384Z'),
128
- action: {
129
- object: 'event_action',
130
- id: 'evt_action_1',
131
- name: 'user.viewed_api_key',
132
- project_id: 'project_0',
133
- },
134
- },
135
- ],
136
- list_metadata: { before: null, after: null },
137
- });
138
- const workos = new workos_1.WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU');
139
- const events = yield workos.auditTrail.listEvents();
140
- expect(events.data).toHaveLength(2);
141
- }));
142
- });
143
- describe('With a filter', () => {
144
- it('Returns events that match the filter', () => __awaiter(void 0, void 0, void 0, function* () {
145
- mock
146
- .onGet('/events', {
147
- action: ['user.searched_directories'],
148
- })
149
- .replyOnce(200, {
150
- data: [
151
- {
152
- object: 'event',
153
- id: 'evt_0',
154
- group: 'foo-corp.com',
155
- latitude: null,
156
- longitude: null,
157
- location: '::1',
158
- type: 'r',
159
- actor_name: 'demo@foo-corp.com',
160
- actor_id: 'user_0',
161
- target_name: 'http_request',
162
- target_id: '',
163
- metadata: {},
164
- occurred_at: new Date(),
165
- action: {
166
- object: 'event_action',
167
- id: 'evt_action_0',
168
- name: 'user.searched_directories',
169
- },
170
- },
171
- ],
172
- list_metadata: { before: null, after: null },
173
- });
174
- const workos = new workos_1.WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU');
175
- const events = yield workos.auditTrail.listEvents({
176
- action: ['user.searched_directories'],
177
- });
178
- expect(events.data).toHaveLength(1);
179
- expect(events.data[0].action.name).toEqual('user.searched_directories');
180
- }));
181
- });
182
- });
183
- });
@@ -1,3 +0,0 @@
1
- export interface CreateEventOptions {
2
- idempotencyKey?: string;
3
- }
@@ -1,14 +0,0 @@
1
- export interface EventOptions {
2
- group: string;
3
- actor_name: string;
4
- actor_id: string;
5
- location: string;
6
- occurred_at: Date;
7
- target_name: string;
8
- target_id: string;
9
- action: string;
10
- action_type: string;
11
- metadata?: {
12
- [key: string]: string;
13
- };
14
- }
@@ -1,23 +0,0 @@
1
- export interface AuditTrailEventAction {
2
- object: 'event_action';
3
- id: string;
4
- name: string;
5
- }
6
- export interface AuditTrailEvent {
7
- object: 'event';
8
- id: string;
9
- group: string;
10
- location: string;
11
- latitude: string;
12
- longitude: string;
13
- type: string;
14
- actor_name: string;
15
- actor_id: string;
16
- target_name: string;
17
- target_id: string;
18
- occurred_at: Date;
19
- action: AuditTrailEventAction;
20
- metadata?: {
21
- [key: string]: string;
22
- };
23
- }
@@ -1,4 +0,0 @@
1
- export { CreateEventOptions } from './create-event-options.interface';
2
- export { EventOptions } from './event-options.interface';
3
- export { AuditTrailEvent } from './event.interface';
4
- export { ListEventsOptions } from './list-events-options.interface';
@@ -1,16 +0,0 @@
1
- import { PaginationOptions } from '../../common/interfaces/pagination-options.interface';
2
- export interface ListEventsOptions extends PaginationOptions {
3
- group?: string[];
4
- action?: string[];
5
- action_type?: string[];
6
- actor_name?: string[];
7
- actor_id?: string[];
8
- target_name?: string[];
9
- target_id?: string[];
10
- occurred_at?: string;
11
- occurred_at_gt?: string;
12
- occurred_at_gte?: string;
13
- occurred_at_lt?: string;
14
- occurred_at_lte?: string;
15
- search?: string;
16
- }
@@ -1,7 +0,0 @@
1
- export interface AddUserToOrganizationOptions {
2
- userId: string;
3
- organizationId: string;
4
- }
5
- export interface SerializedAddUserToOrganizationOptions {
6
- organization_id: string;
7
- }
@@ -1,17 +0,0 @@
1
- export interface AuthenticateWithCodeOptions {
2
- clientId: string;
3
- code: string;
4
- ipAddress?: string;
5
- userAgent?: string;
6
- }
7
- export interface AuthenticateUserWithCodeCredentials {
8
- clientSecret: string | undefined;
9
- }
10
- export interface SerializedAuthenticateWithCodeOptions {
11
- grant_type: 'authorization_code';
12
- client_id: string;
13
- client_secret: string | undefined;
14
- code: string;
15
- ip_address?: string;
16
- user_agent?: string;
17
- }
@@ -1,19 +0,0 @@
1
- export interface AuthenticateWithMagicAuthOptions {
2
- clientId: string;
3
- code: string;
4
- userId: string;
5
- ipAddress?: string;
6
- userAgent?: string;
7
- }
8
- export interface AuthenticateUserWithMagicAuthCredentials {
9
- clientSecret: string | undefined;
10
- }
11
- export interface SerializedAuthenticateWithMagicAuthOptions {
12
- grant_type: 'urn:workos:oauth:grant-type:magic-auth:code';
13
- client_id: string;
14
- client_secret: string | undefined;
15
- code: string;
16
- user_id: string;
17
- ip_address?: string;
18
- user_agent?: string;
19
- }
@@ -1,19 +0,0 @@
1
- export interface AuthenticateWithPasswordOptions {
2
- clientId: string;
3
- email: string;
4
- password: string;
5
- ipAddress?: string;
6
- userAgent?: string;
7
- }
8
- export interface AuthenticateUserWithPasswordCredentials {
9
- clientSecret: string | undefined;
10
- }
11
- export interface SerializedAuthenticateWithPasswordOptions {
12
- grant_type: 'password';
13
- client_id: string;
14
- client_secret: string | undefined;
15
- email: string;
16
- password: string;
17
- ip_address?: string;
18
- user_agent?: string;
19
- }
@@ -1,3 +0,0 @@
1
- export interface DeleteUserOptions {
2
- userId: string;
3
- }
@@ -1,4 +0,0 @@
1
- export interface RemoveUserFromOrganizationOptions {
2
- userId: string;
3
- organizationId: string;
4
- }
@@ -1,17 +0,0 @@
1
- import { User, UserResponse } from './user.interface';
2
- export interface SendPasswordResetEmailOptions {
3
- email: string;
4
- passwordResetUrl: string;
5
- }
6
- export interface SerializedSendPasswordResetEmailOptions {
7
- email: string;
8
- password_reset_url: string;
9
- }
10
- export interface SendPasswordResetEmailResponse {
11
- token: string;
12
- user: User;
13
- }
14
- export interface SendPasswordResetEmailResponseResponse {
15
- token: string;
16
- user: UserResponse;
17
- }
@@ -1,7 +0,0 @@
1
- export interface VerifyEmailCodeOptions {
2
- code: string;
3
- userId: string;
4
- }
5
- export interface SerializedVerifyEmailCodeOptions {
6
- code: string;
7
- }
@@ -1,3 +0,0 @@
1
- import { SendPasswordResetEmailOptions, SendPasswordResetEmailResponse, SendPasswordResetEmailResponseResponse, SerializedSendPasswordResetEmailOptions } from '../interfaces';
2
- export declare const deserializeSendPasswordResetEmailResponse: (sendPasswordResetEmailResponse: SendPasswordResetEmailResponseResponse) => SendPasswordResetEmailResponse;
3
- export declare const serializeSendPasswordResetEmailOptions: (options: SendPasswordResetEmailOptions) => SerializedSendPasswordResetEmailOptions;
@@ -1,14 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.serializeSendPasswordResetEmailOptions = exports.deserializeSendPasswordResetEmailResponse = void 0;
4
- const user_serializer_1 = require("./user.serializer");
5
- const deserializeSendPasswordResetEmailResponse = (sendPasswordResetEmailResponse) => ({
6
- token: sendPasswordResetEmailResponse.token,
7
- user: (0, user_serializer_1.deserializeUser)(sendPasswordResetEmailResponse.user),
8
- });
9
- exports.deserializeSendPasswordResetEmailResponse = deserializeSendPasswordResetEmailResponse;
10
- const serializeSendPasswordResetEmailOptions = (options) => ({
11
- email: options.email,
12
- password_reset_url: options.passwordResetUrl,
13
- });
14
- exports.serializeSendPasswordResetEmailOptions = serializeSendPasswordResetEmailOptions;
@@ -1,38 +0,0 @@
1
- import { WorkOS } from '../workos';
2
- import { AutoPaginatable } from '../common/utils/pagination';
3
- import { AddUserToOrganizationOptions, AuthenticateWithCodeOptions, AuthenticateWithMagicAuthOptions, AuthenticateWithPasswordOptions, AuthenticateWithTotpOptions, AuthenticationResponse, ResetPasswordOptions, SendPasswordResetEmailOptions, SendPasswordResetEmailResponse, CreateUserOptions, DeleteUserOptions, EnrollAuthFactorOptions, ListAuthFactorsOptions, ListUsersOptions, RemoveUserFromOrganizationOptions, SendMagicAuthCodeOptions, SendVerificationEmailOptions, UpdateUserOptions, UpdateUserPasswordOptions, User, VerifyEmailCodeOptions } from './interfaces';
4
- import { Challenge, Factor } from '../mfa/interfaces';
5
- export declare class Users {
6
- private readonly workos;
7
- constructor(workos: WorkOS);
8
- getUser(userId: string): Promise<User>;
9
- listUsers(options?: ListUsersOptions): Promise<AutoPaginatable<User>>;
10
- createUser(payload: CreateUserOptions): Promise<User>;
11
- authenticateWithMagicAuth(payload: AuthenticateWithMagicAuthOptions): Promise<AuthenticationResponse>;
12
- authenticateWithPassword(payload: AuthenticateWithPasswordOptions): Promise<AuthenticationResponse>;
13
- authenticateWithCode(payload: AuthenticateWithCodeOptions): Promise<AuthenticationResponse>;
14
- authenticateWithTotp(payload: AuthenticateWithTotpOptions): Promise<AuthenticationResponse>;
15
- sendVerificationEmail({ userId, }: SendVerificationEmailOptions): Promise<{
16
- user: User;
17
- }>;
18
- sendMagicAuthCode(options: SendMagicAuthCodeOptions): Promise<{
19
- user: User;
20
- }>;
21
- verifyEmailCode({ code, userId, }: VerifyEmailCodeOptions): Promise<{
22
- user: User;
23
- }>;
24
- sendPasswordResetEmail(payload: SendPasswordResetEmailOptions): Promise<SendPasswordResetEmailResponse>;
25
- resetPassword(payload: ResetPasswordOptions): Promise<{
26
- user: User;
27
- }>;
28
- addUserToOrganization({ userId, organizationId, }: AddUserToOrganizationOptions): Promise<User>;
29
- removeUserFromOrganization({ userId, organizationId, }: RemoveUserFromOrganizationOptions): Promise<User>;
30
- updateUser(payload: UpdateUserOptions): Promise<User>;
31
- updateUserPassword(payload: UpdateUserPasswordOptions): Promise<User>;
32
- enrollAuthFactor(payload: EnrollAuthFactorOptions): Promise<{
33
- authenticationFactor: Factor;
34
- authenticationChallenge: Challenge;
35
- }>;
36
- listAuthFactors(options: ListAuthFactorsOptions): Promise<AutoPaginatable<Factor>>;
37
- deleteUser(payload: DeleteUserOptions): Promise<void>;
38
- }