@workos-inc/node 2.20.0 → 3.0.0-alpha.2

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 (202) 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/interfaces/list-events-options.interface.d.ts +2 -2
  51. package/lib/events/serializers/event.serializer.d.ts +2 -0
  52. package/lib/events/serializers/event.serializer.js +10 -0
  53. package/lib/index.d.ts +1 -0
  54. package/lib/index.js +1 -0
  55. package/lib/mfa/interfaces/challenge.interface.d.ts +9 -0
  56. package/lib/mfa/interfaces/factor.interface.d.ts +13 -4
  57. package/lib/mfa/interfaces/index.d.ts +9 -0
  58. package/lib/mfa/interfaces/index.js +25 -0
  59. package/lib/mfa/interfaces/sms.interface.d.ts +3 -0
  60. package/lib/mfa/interfaces/totp.interface.d.ts +7 -0
  61. package/lib/mfa/interfaces/verify-challenge-response.d.ts +5 -1
  62. package/lib/mfa/mfa.d.ts +2 -8
  63. package/lib/mfa/mfa.js +5 -4
  64. package/lib/mfa/mfa.spec.js +134 -115
  65. package/lib/mfa/serializers/challenge.serializer.d.ts +2 -0
  66. package/lib/mfa/serializers/challenge.serializer.js +13 -0
  67. package/lib/mfa/serializers/factor.serializer.d.ts +2 -0
  68. package/lib/mfa/serializers/factor.serializer.js +7 -0
  69. package/lib/mfa/serializers/index.d.ts +3 -0
  70. package/lib/mfa/serializers/index.js +19 -0
  71. package/lib/mfa/serializers/sms.serializer.d.ts +2 -0
  72. package/lib/mfa/serializers/sms.serializer.js +7 -0
  73. package/lib/mfa/serializers/totp.serializer.d.ts +2 -0
  74. package/lib/mfa/serializers/totp.serializer.js +11 -0
  75. package/lib/mfa/serializers/verify-response.serializer.d.ts +2 -0
  76. package/lib/mfa/serializers/verify-response.serializer.js +9 -0
  77. package/lib/organizations/interfaces/create-organization-options.interface.d.ts +5 -0
  78. package/lib/organizations/interfaces/organization.interface.d.ts +9 -0
  79. package/lib/organizations/interfaces/update-organization-options.interface.d.ts +5 -0
  80. package/lib/organizations/organizations.d.ts +2 -2
  81. package/lib/organizations/organizations.js +8 -6
  82. package/lib/organizations/organizations.spec.js +4 -3
  83. package/lib/organizations/serializers/create-organization-options.serializer.d.ts +2 -0
  84. package/lib/organizations/serializers/create-organization-options.serializer.js +9 -0
  85. package/lib/organizations/serializers/index.d.ts +3 -0
  86. package/lib/organizations/serializers/index.js +19 -0
  87. package/lib/organizations/serializers/organization.serializer.d.ts +2 -0
  88. package/lib/organizations/serializers/organization.serializer.js +13 -0
  89. package/lib/organizations/serializers/update-organization-options.serializer.d.ts +2 -0
  90. package/lib/organizations/serializers/update-organization-options.serializer.js +9 -0
  91. package/lib/passwordless/interfaces/create-passwordless-session-options.interface.d.ts +8 -0
  92. package/lib/passwordless/interfaces/index.d.ts +3 -3
  93. package/lib/passwordless/interfaces/index.js +17 -0
  94. package/lib/passwordless/interfaces/passwordless-session.interface.d.ts +7 -0
  95. package/lib/passwordless/passwordless.d.ts +1 -3
  96. package/lib/passwordless/passwordless.js +2 -1
  97. package/lib/passwordless/serializers/index.d.ts +0 -0
  98. package/lib/passwordless/serializers/index.js +1 -0
  99. package/lib/passwordless/serializers/passwordless-session.serializer.d.ts +2 -0
  100. package/lib/passwordless/serializers/passwordless-session.serializer.js +11 -0
  101. package/lib/portal/interfaces/generate-portal-link-intent.interface.js +1 -1
  102. package/lib/sso/interfaces/connection-type.enum.d.ts +1 -0
  103. package/lib/sso/interfaces/connection-type.enum.js +2 -1
  104. package/lib/sso/interfaces/connection.interface.d.ts +20 -1
  105. package/lib/sso/interfaces/index.d.ts +2 -0
  106. package/lib/sso/interfaces/index.js +2 -0
  107. package/lib/sso/interfaces/list-connections-options.interface.d.ts +5 -0
  108. package/lib/sso/interfaces/profile-and-token.interface.d.ts +6 -2
  109. package/lib/sso/interfaces/profile.interface.d.ts +14 -0
  110. package/lib/sso/serializers/connection.serializer.d.ts +2 -0
  111. package/lib/sso/serializers/connection.serializer.js +17 -0
  112. package/lib/sso/serializers/index.d.ts +3 -0
  113. package/lib/sso/serializers/index.js +19 -0
  114. package/lib/sso/serializers/profile-and-token.serializer.d.ts +2 -0
  115. package/lib/sso/serializers/profile-and-token.serializer.js +9 -0
  116. package/lib/sso/serializers/profile.serializer.d.ts +2 -0
  117. package/lib/sso/serializers/profile.serializer.js +16 -0
  118. package/lib/sso/sso.d.ts +3 -9
  119. package/lib/sso/sso.js +18 -9
  120. package/lib/sso/sso.spec.js +27 -9
  121. package/lib/users/exceptions/index.d.ts +4 -0
  122. package/lib/users/exceptions/index.js +10 -0
  123. package/lib/users/fixtures/list-users.json +21 -0
  124. package/lib/users/fixtures/session.json +6 -0
  125. package/lib/users/fixtures/user.json +12 -0
  126. package/lib/users/interfaces/add-user-to-organization-options.interface.d.ts +7 -0
  127. package/lib/users/interfaces/add-user-to-organization-options.interface.js +2 -0
  128. package/lib/users/interfaces/authenticate-user-with-password-options.interface.d.ts +21 -0
  129. package/lib/users/interfaces/authenticate-user-with-password-options.interface.js +2 -0
  130. package/lib/users/interfaces/authenticate-user-with-token-options.interface.d.ts +15 -0
  131. package/lib/users/interfaces/authenticate-user-with-token-options.interface.js +2 -0
  132. package/lib/users/interfaces/authentication-response.interface.d.ts +10 -0
  133. package/lib/users/interfaces/authentication-response.interface.js +2 -0
  134. package/lib/users/interfaces/complete-password-reset-options.interface.d.ts +8 -0
  135. package/lib/users/interfaces/complete-password-reset-options.interface.js +2 -0
  136. package/lib/users/interfaces/create-email-verification-challenge-options.interface.d.ts +16 -0
  137. package/lib/users/interfaces/create-email-verification-challenge-options.interface.js +2 -0
  138. package/lib/users/interfaces/create-password-reset-challenge-options.interface.d.ts +17 -0
  139. package/lib/users/interfaces/create-password-reset-challenge-options.interface.js +2 -0
  140. package/lib/users/interfaces/create-user-options.interface.d.ts +14 -0
  141. package/lib/users/interfaces/create-user-options.interface.js +2 -0
  142. package/lib/users/interfaces/index.d.ts +15 -0
  143. package/lib/users/interfaces/index.js +31 -0
  144. package/lib/users/interfaces/list-users-options.interface.d.ts +6 -0
  145. package/lib/users/interfaces/list-users-options.interface.js +2 -0
  146. package/lib/users/interfaces/remove-user-from-organization-options.interface.d.ts +4 -0
  147. package/lib/users/interfaces/remove-user-from-organization-options.interface.js +2 -0
  148. package/lib/users/interfaces/revoke-session-options.interface.d.ts +15 -0
  149. package/lib/users/interfaces/revoke-session-options.interface.js +2 -0
  150. package/lib/users/interfaces/session.interface.d.ts +12 -0
  151. package/lib/users/interfaces/session.interface.js +2 -0
  152. package/lib/users/interfaces/update-user-options.interface.d.ts +9 -0
  153. package/lib/users/interfaces/update-user-options.interface.js +2 -0
  154. package/lib/users/interfaces/update-user-password-options.interface.d.ts +7 -0
  155. package/lib/users/interfaces/update-user-password-options.interface.js +2 -0
  156. package/lib/users/interfaces/user.interface.d.ts +59 -0
  157. package/lib/users/interfaces/user.interface.js +2 -0
  158. package/lib/users/interfaces/verify-session.interface.d.ts +18 -0
  159. package/lib/users/interfaces/verify-session.interface.js +2 -0
  160. package/lib/users/serializers/authenticate-user-with-password-options.serializer.d.ts +2 -0
  161. package/lib/users/serializers/authenticate-user-with-password-options.serializer.js +14 -0
  162. package/lib/users/serializers/authenticate-user-with-token-options.serializer.d.ts +2 -0
  163. package/lib/users/serializers/authenticate-user-with-token-options.serializer.js +11 -0
  164. package/lib/users/serializers/authentication-response.serializer.d.ts +2 -0
  165. package/lib/users/serializers/authentication-response.serializer.js +12 -0
  166. package/lib/users/serializers/complete-password-reset-options.serializer.d.ts +2 -0
  167. package/lib/users/serializers/complete-password-reset-options.serializer.js +8 -0
  168. package/lib/users/serializers/create-email-verification-challenge.serializer.d.ts +2 -0
  169. package/lib/users/serializers/create-email-verification-challenge.serializer.js +9 -0
  170. package/lib/users/serializers/create-password-reset-challenge.serializer.d.ts +3 -0
  171. package/lib/users/serializers/create-password-reset-challenge.serializer.js +14 -0
  172. package/lib/users/serializers/create-user-options.serializer.d.ts +2 -0
  173. package/lib/users/serializers/create-user-options.serializer.js +11 -0
  174. package/lib/users/serializers/index.d.ts +13 -0
  175. package/lib/users/serializers/index.js +29 -0
  176. package/lib/users/serializers/revoke-session-options.serializer.d.ts +2 -0
  177. package/lib/users/serializers/revoke-session-options.serializer.js +14 -0
  178. package/lib/users/serializers/session.serializer.d.ts +2 -0
  179. package/lib/users/serializers/session.serializer.js +10 -0
  180. package/lib/users/serializers/update-user-options.serializer.d.ts +2 -0
  181. package/lib/users/serializers/update-user-options.serializer.js +8 -0
  182. package/lib/users/serializers/update-user-password-options.serializer.d.ts +2 -0
  183. package/lib/users/serializers/update-user-password-options.serializer.js +7 -0
  184. package/lib/users/serializers/user.serializer.d.ts +2 -0
  185. package/lib/users/serializers/user.serializer.js +31 -0
  186. package/lib/users/serializers/verify-session.serializer.d.ts +3 -0
  187. package/lib/users/serializers/verify-session.serializer.js +15 -0
  188. package/lib/users/users.d.ts +23 -0
  189. package/lib/users/users.js +124 -0
  190. package/lib/users/users.spec.d.ts +1 -0
  191. package/lib/users/users.spec.js +318 -0
  192. package/lib/webhooks/fixtures/webhook.json +1 -1
  193. package/lib/webhooks/interfaces/webhook-directory-user.interface.d.ts +2 -2
  194. package/lib/webhooks/interfaces/webhook.interface.d.ts +1 -0
  195. package/lib/workos.d.ts +6 -4
  196. package/lib/workos.js +3 -1
  197. package/package.json +13 -14
  198. package/lib/directory-sync/interfaces/group.interface.d.ts +0 -10
  199. package/lib/directory-sync/interfaces/user.interface.d.ts +0 -23
  200. /package/lib/{directory-sync/interfaces/group.interface.js → common/interfaces/workos-response-error.interface.js} +0 -0
  201. /package/lib/directory-sync/interfaces/{list-users-options.interface.js → directory-group.interface.js} +0 -0
  202. /package/lib/directory-sync/interfaces/{user.interface.js → directory-user.interface.js} +0 -0
@@ -10,6 +10,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.DirectorySync = void 0;
13
+ const serializers_1 = require("../common/serializers");
14
+ const serializers_2 = require("./serializers");
13
15
  class DirectorySync {
14
16
  constructor(workos) {
15
17
  this.workos = workos;
@@ -19,13 +21,13 @@ class DirectorySync {
19
21
  const { data } = yield this.workos.get('/directories', {
20
22
  query: options,
21
23
  });
22
- return data;
24
+ return (0, serializers_1.deserializeList)(data, serializers_2.deserializeDirectory);
23
25
  });
24
26
  }
25
27
  getDirectory(id) {
26
28
  return __awaiter(this, void 0, void 0, function* () {
27
29
  const { data } = yield this.workos.get(`/directories/${id}`);
28
- return data;
30
+ return (0, serializers_2.deserializeDirectory)(data);
29
31
  });
30
32
  }
31
33
  deleteDirectory(id) {
@@ -38,7 +40,7 @@ class DirectorySync {
38
40
  const { data } = yield this.workos.get(`/directory_groups`, {
39
41
  query: options,
40
42
  });
41
- return data;
43
+ return (0, serializers_1.deserializeList)(data, serializers_2.deserializeDirectoryGroup);
42
44
  });
43
45
  }
44
46
  listUsers(options) {
@@ -46,19 +48,19 @@ class DirectorySync {
46
48
  const { data } = yield this.workos.get(`/directory_users`, {
47
49
  query: options,
48
50
  });
49
- return data;
51
+ return (0, serializers_1.deserializeList)(data, serializers_2.deserializeDirectoryUserWithGroups);
50
52
  });
51
53
  }
52
54
  getUser(user) {
53
55
  return __awaiter(this, void 0, void 0, function* () {
54
56
  const { data } = yield this.workos.get(`/directory_users/${user}`);
55
- return data;
57
+ return (0, serializers_2.deserializeDirectoryUserWithGroups)(data);
56
58
  });
57
59
  }
58
60
  getGroup(group) {
59
61
  return __awaiter(this, void 0, void 0, function* () {
60
62
  const { data } = yield this.workos.get(`/directory_groups/${group}`);
61
- return data;
63
+ return (0, serializers_2.deserializeDirectoryGroup)(data);
62
64
  });
63
65
  }
64
66
  }
@@ -19,6 +19,18 @@ const mock = new axios_mock_adapter_1.default(axios_1.default);
19
19
  describe('DirectorySync', () => {
20
20
  afterEach(() => mock.resetHistory());
21
21
  const workos = new workos_1.WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU');
22
+ const directory = {
23
+ id: 'directory_123',
24
+ createdAt: '2020-05-06 04:21:48.649164',
25
+ domain: 'foo-corp.com',
26
+ externalKey: '9asBRBVHz2ASEkgg',
27
+ name: 'Foo',
28
+ object: 'directory',
29
+ organizationId: 'org_01EXSR7M9QTKCC5D531SMCWMYG',
30
+ state: 'linked',
31
+ type: 'okta scim v1.1',
32
+ updatedAt: '2021-12-13 12:15:45.531847',
33
+ };
22
34
  const directoryResponse = {
23
35
  id: 'directory_123',
24
36
  created_at: '2020-05-06 04:21:48.649164',
@@ -29,7 +41,19 @@ describe('DirectorySync', () => {
29
41
  organization_id: 'org_01EXSR7M9QTKCC5D531SMCWMYG',
30
42
  state: 'linked',
31
43
  type: 'okta scim v1.1',
32
- updated_at: '2021-10-27 15:21:50.640958',
44
+ updated_at: '2021-12-13 12:15:45.531847',
45
+ };
46
+ const group = {
47
+ id: 'dir_grp_123',
48
+ idpId: '123',
49
+ directoryId: 'dir_123',
50
+ organizationId: 'org_123',
51
+ name: 'Foo Group',
52
+ createdAt: '2021-10-27 15:21:50.640958',
53
+ updatedAt: '2021-12-13 12:15:45.531847',
54
+ rawAttributes: {
55
+ foo: 'bar',
56
+ },
33
57
  };
34
58
  const groupResponse = {
35
59
  id: 'dir_grp_123',
@@ -37,12 +61,37 @@ describe('DirectorySync', () => {
37
61
  directory_id: 'dir_123',
38
62
  organization_id: 'org_123',
39
63
  name: 'Foo Group',
40
- created_at: `2021-10-27 15:21:50.640958`,
41
- updated_at: '2021-10-27 15:21:50.640959',
64
+ created_at: '2021-10-27 15:21:50.640958',
65
+ updated_at: '2021-12-13 12:15:45.531847',
42
66
  raw_attributes: {
43
67
  foo: 'bar',
44
68
  },
45
69
  };
70
+ const userWithGroup = {
71
+ id: 'user_123',
72
+ customAttributes: {
73
+ custom: true,
74
+ },
75
+ directoryId: 'dir_123',
76
+ organizationId: 'org_123',
77
+ emails: [
78
+ {
79
+ primary: true,
80
+ type: 'type',
81
+ value: 'jonsnow@workos.com',
82
+ },
83
+ ],
84
+ firstName: 'Jon',
85
+ groups: [group],
86
+ idpId: 'idp_foo',
87
+ lastName: 'Snow',
88
+ jobTitle: 'Knight of the Watch',
89
+ rawAttributes: {},
90
+ state: 'active',
91
+ username: 'jonsnow',
92
+ createdAt: '2021-10-27 15:21:50.640959',
93
+ updatedAt: '2021-12-13 12:15:45.531847',
94
+ };
46
95
  const userWithGroupResponse = {
47
96
  id: 'user_123',
48
97
  custom_attributes: {
@@ -65,6 +114,8 @@ describe('DirectorySync', () => {
65
114
  raw_attributes: {},
66
115
  state: 'active',
67
116
  username: 'jonsnow',
117
+ created_at: '2021-10-27 15:21:50.640959',
118
+ updated_at: '2021-12-13 12:15:45.531847',
68
119
  };
69
120
  describe('listDirectories', () => {
70
121
  describe('with options', () => {
@@ -79,10 +130,14 @@ describe('DirectorySync', () => {
79
130
  domain: 'google.com',
80
131
  })
81
132
  .replyOnce(200, directoryListResponse);
82
- const directories = yield workos.directorySync.listDirectories({
133
+ const subject = yield workos.directorySync.listDirectories({
83
134
  domain: 'google.com',
84
135
  });
85
- expect(directories).toEqual(directoryListResponse);
136
+ expect(subject).toEqual({
137
+ object: 'list',
138
+ data: [directory],
139
+ listMetadata: {},
140
+ });
86
141
  }));
87
142
  });
88
143
  });
@@ -91,8 +146,8 @@ describe('DirectorySync', () => {
91
146
  mock
92
147
  .onGet('/directories/directory_123')
93
148
  .replyOnce(200, directoryResponse);
94
- const directory = yield workos.directorySync.getDirectory('directory_123');
95
- expect(directory).toEqual(directoryResponse);
149
+ const subject = yield workos.directorySync.getDirectory('directory_123');
150
+ expect(subject).toEqual(directory);
96
151
  }));
97
152
  });
98
153
  describe('deleteDirectory', () => {
@@ -105,8 +160,8 @@ describe('DirectorySync', () => {
105
160
  describe('getGroup', () => {
106
161
  it(`requests a Directory Group`, () => __awaiter(void 0, void 0, void 0, function* () {
107
162
  mock.onGet('/directory_groups/dir_grp_123').replyOnce(200, groupResponse);
108
- const group = yield workos.directorySync.getGroup('dir_grp_123');
109
- expect(group).toEqual(groupResponse);
163
+ const subject = yield workos.directorySync.getGroup('dir_grp_123');
164
+ expect(subject).toEqual(group);
110
165
  }));
111
166
  });
112
167
  describe('listGroups', () => {
@@ -122,10 +177,14 @@ describe('DirectorySync', () => {
122
177
  directory: 'directory_123',
123
178
  })
124
179
  .replyOnce(200, groupListResponse);
125
- const list = yield workos.directorySync.listGroups({
180
+ const subject = yield workos.directorySync.listGroups({
126
181
  directory: 'directory_123',
127
182
  });
128
- expect(list).toEqual(groupListResponse);
183
+ expect(subject).toEqual({
184
+ object: 'list',
185
+ data: [group],
186
+ listMetadata: {},
187
+ });
129
188
  }));
130
189
  });
131
190
  describe('with a User', () => {
@@ -135,10 +194,14 @@ describe('DirectorySync', () => {
135
194
  user: 'directory_usr_123',
136
195
  })
137
196
  .replyOnce(200, groupListResponse);
138
- const list = yield workos.directorySync.listGroups({
197
+ const subject = yield workos.directorySync.listGroups({
139
198
  user: 'directory_usr_123',
140
199
  });
141
- expect(list).toEqual(groupListResponse);
200
+ expect(subject).toEqual({
201
+ object: 'list',
202
+ data: [group],
203
+ listMetadata: {},
204
+ });
142
205
  }));
143
206
  });
144
207
  });
@@ -155,10 +218,14 @@ describe('DirectorySync', () => {
155
218
  directory: 'directory_123',
156
219
  })
157
220
  .replyOnce(200, userWithGroupListResponse);
158
- const list = yield workos.directorySync.listUsers({
221
+ const subject = yield workos.directorySync.listUsers({
159
222
  directory: 'directory_123',
160
223
  });
161
- expect(list).toEqual(userWithGroupListResponse);
224
+ expect(subject).toEqual({
225
+ object: 'list',
226
+ data: [userWithGroup],
227
+ listMetadata: {},
228
+ });
162
229
  }));
163
230
  describe('with custom attributes', () => {
164
231
  it('returns the custom attributes, using the provided type', () => __awaiter(void 0, void 0, void 0, function* () {
@@ -179,6 +246,8 @@ describe('DirectorySync', () => {
179
246
  last_name: 'Stoltenberg',
180
247
  job_title: 'Software Engineer',
181
248
  state: 'active',
249
+ created_at: '2021-10-27 15:21:50.640959',
250
+ updated_at: '2021-12-13 12:15:45.531847',
182
251
  raw_attributes: {},
183
252
  custom_attributes: {
184
253
  managerId: '99f1817b-149c-4438-b80f-a272c3406109',
@@ -204,6 +273,8 @@ describe('DirectorySync', () => {
204
273
  last_name: 'Leffler',
205
274
  job_title: 'Software Engineer',
206
275
  state: 'active',
276
+ created_at: '2021-10-27 15:21:50.640959',
277
+ updated_at: '2021-12-13 12:15:45.531847',
207
278
  raw_attributes: {},
208
279
  custom_attributes: {
209
280
  managerId: '263c7472-4d3f-4ab4-8162-e768af103065',
@@ -223,7 +294,7 @@ describe('DirectorySync', () => {
223
294
  const users = yield workos.directorySync.listUsers({
224
295
  directory: 'directory_123',
225
296
  });
226
- const managerIds = users.data.map((user) => user.custom_attributes.managerId);
297
+ const managerIds = users.data.map((user) => user.customAttributes.managerId);
227
298
  expect(managerIds).toEqual([
228
299
  '99f1817b-149c-4438-b80f-a272c3406109',
229
300
  '263c7472-4d3f-4ab4-8162-e768af103065',
@@ -238,10 +309,14 @@ describe('DirectorySync', () => {
238
309
  group: 'directory_grp_123',
239
310
  })
240
311
  .replyOnce(200, userWithGroupListResponse);
241
- const list = yield workos.directorySync.listUsers({
312
+ const subject = yield workos.directorySync.listUsers({
242
313
  group: 'directory_grp_123',
243
314
  });
244
- expect(list).toEqual(userWithGroupListResponse);
315
+ expect(subject).toEqual({
316
+ object: 'list',
317
+ data: [userWithGroup],
318
+ listMetadata: {},
319
+ });
245
320
  }));
246
321
  });
247
322
  });
@@ -250,8 +325,8 @@ describe('DirectorySync', () => {
250
325
  mock
251
326
  .onGet('/directory_users/dir_usr_123')
252
327
  .replyOnce(200, userWithGroupResponse);
253
- const user = yield workos.directorySync.getUser('dir_usr_123');
254
- expect(user).toEqual(userWithGroupResponse);
328
+ const subject = yield workos.directorySync.getUser('dir_usr_123');
329
+ expect(subject).toEqual(userWithGroup);
255
330
  }));
256
331
  });
257
332
  });
@@ -0,0 +1,20 @@
1
+ export interface DirectoryGroup {
2
+ id: string;
3
+ idpId: string;
4
+ directoryId: string;
5
+ organizationId: string | null;
6
+ name: string;
7
+ createdAt: string;
8
+ updatedAt: string;
9
+ rawAttributes: any;
10
+ }
11
+ export interface DirectoryGroupResponse {
12
+ id: string;
13
+ idp_id: string;
14
+ directory_id: string;
15
+ organization_id: string | null;
16
+ name: string;
17
+ created_at: string;
18
+ updated_at: string;
19
+ raw_attributes: any;
20
+ }
@@ -0,0 +1,48 @@
1
+ import { DirectoryGroup, DirectoryGroupResponse } from './directory-group.interface';
2
+ export type DefaultCustomAttributes = Record<string, unknown>;
3
+ export interface DirectoryUser<TCustomAttributes extends object = DefaultCustomAttributes, TRawAttributes = any> {
4
+ id: string;
5
+ directoryId: string;
6
+ organizationId: string | null;
7
+ rawAttributes: TRawAttributes;
8
+ customAttributes: TCustomAttributes;
9
+ idpId: string;
10
+ firstName: string;
11
+ emails: {
12
+ type: string;
13
+ value: string;
14
+ primary: boolean;
15
+ }[];
16
+ username: string;
17
+ lastName: string;
18
+ jobTitle: string | null;
19
+ state: 'active' | 'inactive' | 'suspended';
20
+ createdAt: string;
21
+ updatedAt: string;
22
+ }
23
+ export interface DirectoryUserResponse<TCustomAttributes extends object = DefaultCustomAttributes, TRawAttributes = any> {
24
+ id: string;
25
+ directory_id: string;
26
+ organization_id: string | null;
27
+ raw_attributes: TRawAttributes;
28
+ custom_attributes: TCustomAttributes;
29
+ idp_id: string;
30
+ first_name: string;
31
+ emails: {
32
+ type: string;
33
+ value: string;
34
+ primary: boolean;
35
+ }[];
36
+ username: string;
37
+ last_name: string;
38
+ job_title: string | null;
39
+ state: 'active' | 'inactive' | 'suspended';
40
+ created_at: string;
41
+ updated_at: string;
42
+ }
43
+ export interface DirectoryUserWithGroups<TCustomAttributes extends object = DefaultCustomAttributes> extends DirectoryUser<TCustomAttributes> {
44
+ groups: DirectoryGroup[];
45
+ }
46
+ export interface DirectoryUserWithGroupsResponse<TCustomAttributes extends object = DefaultCustomAttributes> extends DirectoryUserResponse<TCustomAttributes> {
47
+ groups: DirectoryGroupResponse[];
48
+ }
@@ -1,4 +1,16 @@
1
1
  export interface Directory {
2
+ object: 'directory';
3
+ id: string;
4
+ domain: string;
5
+ externalKey: string;
6
+ name: string;
7
+ organizationId?: string;
8
+ state: 'unlinked' | 'linked' | 'invalid_credentials';
9
+ type: string;
10
+ createdAt: string;
11
+ updatedAt: string;
12
+ }
13
+ export interface DirectoryResponse {
2
14
  object: 'directory';
3
15
  id: string;
4
16
  domain: string;
@@ -1,6 +1,6 @@
1
- export { Directory } from './directory.interface';
2
- export { Group } from './group.interface';
3
- export { ListDirectoriesOptions } from './list-directories-options.interface';
4
- export { ListGroupsOptions } from './list-groups-options.interface';
5
- export { ListUsersOptions } from './list-users-options.interface';
6
- export { User, UserWithGroups } from './user.interface';
1
+ export * from './directory.interface';
2
+ export * from './directory-group.interface';
3
+ export * from './list-directories-options.interface';
4
+ export * from './list-groups-options.interface';
5
+ export * from './list-directory-users-options.interface';
6
+ export * from './directory-user.interface';
@@ -1,2 +1,22 @@
1
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
+ };
2
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./directory.interface"), exports);
18
+ __exportStar(require("./directory-group.interface"), exports);
19
+ __exportStar(require("./list-directories-options.interface"), exports);
20
+ __exportStar(require("./list-groups-options.interface"), exports);
21
+ __exportStar(require("./list-directory-users-options.interface"), exports);
22
+ __exportStar(require("./directory-user.interface"), exports);
@@ -1,6 +1,6 @@
1
1
  import { PaginationOptions } from '../../common/interfaces/pagination-options.interface';
2
2
  export interface ListDirectoriesOptions extends PaginationOptions {
3
3
  domain?: string;
4
- organization_id?: string;
4
+ organizationId?: string;
5
5
  search?: string;
6
6
  }
@@ -1,5 +1,5 @@
1
1
  import { PaginationOptions } from '../../common/interfaces/pagination-options.interface';
2
- export interface ListUsersOptions extends PaginationOptions {
2
+ export interface ListDirectoryUsersOptions extends PaginationOptions {
3
3
  directory?: string;
4
4
  group?: string;
5
5
  }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ import { DirectoryGroup, DirectoryGroupResponse } from '../interfaces';
2
+ export declare const deserializeDirectoryGroup: (directoryGroup: DirectoryGroupResponse) => DirectoryGroup;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.deserializeDirectoryGroup = void 0;
4
+ const deserializeDirectoryGroup = (directoryGroup) => ({
5
+ id: directoryGroup.id,
6
+ idpId: directoryGroup.idp_id,
7
+ directoryId: directoryGroup.directory_id,
8
+ organizationId: directoryGroup.organization_id,
9
+ name: directoryGroup.name,
10
+ createdAt: directoryGroup.created_at,
11
+ updatedAt: directoryGroup.updated_at,
12
+ rawAttributes: directoryGroup.raw_attributes,
13
+ });
14
+ exports.deserializeDirectoryGroup = deserializeDirectoryGroup;
@@ -0,0 +1,3 @@
1
+ import { DefaultCustomAttributes, DirectoryUser, DirectoryUserResponse, DirectoryUserWithGroups, DirectoryUserWithGroupsResponse } from '../interfaces';
2
+ export declare const deserializeDirectoryUser: <TCustomAttributes extends object = DefaultCustomAttributes>(directoryUser: DirectoryUserResponse<TCustomAttributes, any> | DirectoryUserWithGroupsResponse<TCustomAttributes>) => DirectoryUser<TCustomAttributes, any>;
3
+ export declare const deserializeDirectoryUserWithGroups: <TCustomAttributes extends object = DefaultCustomAttributes>(directoryUserWithGroups: DirectoryUserWithGroupsResponse<TCustomAttributes>) => DirectoryUserWithGroups<TCustomAttributes>;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.deserializeDirectoryUserWithGroups = exports.deserializeDirectoryUser = void 0;
4
+ const directory_group_serializer_1 = require("./directory-group.serializer");
5
+ const deserializeDirectoryUser = (directoryUser) => ({
6
+ id: directoryUser.id,
7
+ directoryId: directoryUser.directory_id,
8
+ organizationId: directoryUser.organization_id,
9
+ rawAttributes: directoryUser.raw_attributes,
10
+ customAttributes: directoryUser.custom_attributes,
11
+ idpId: directoryUser.idp_id,
12
+ firstName: directoryUser.first_name,
13
+ emails: directoryUser.emails,
14
+ username: directoryUser.username,
15
+ lastName: directoryUser.last_name,
16
+ jobTitle: directoryUser.job_title,
17
+ state: directoryUser.state,
18
+ createdAt: directoryUser.created_at,
19
+ updatedAt: directoryUser.updated_at,
20
+ });
21
+ exports.deserializeDirectoryUser = deserializeDirectoryUser;
22
+ const deserializeDirectoryUserWithGroups = (directoryUserWithGroups) => (Object.assign(Object.assign({}, (0, exports.deserializeDirectoryUser)(directoryUserWithGroups)), { groups: directoryUserWithGroups.groups.map(directory_group_serializer_1.deserializeDirectoryGroup) }));
23
+ exports.deserializeDirectoryUserWithGroups = deserializeDirectoryUserWithGroups;
@@ -0,0 +1,2 @@
1
+ import { Directory, DirectoryResponse } from '../interfaces';
2
+ export declare const deserializeDirectory: (directory: DirectoryResponse) => Directory;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.deserializeDirectory = void 0;
4
+ const deserializeDirectory = (directory) => ({
5
+ object: directory.object,
6
+ id: directory.id,
7
+ domain: directory.domain,
8
+ externalKey: directory.external_key,
9
+ name: directory.name,
10
+ organizationId: directory.organization_id,
11
+ state: directory.state,
12
+ type: directory.type,
13
+ createdAt: directory.created_at,
14
+ updatedAt: directory.updated_at,
15
+ });
16
+ exports.deserializeDirectory = deserializeDirectory;
@@ -0,0 +1,3 @@
1
+ export * from './directory-group.serializer';
2
+ export * from './directory-user.serializer';
3
+ export * from './directory.serializer';
@@ -0,0 +1,19 @@
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("./directory-group.serializer"), exports);
18
+ __exportStar(require("./directory-user.serializer"), exports);
19
+ __exportStar(require("./directory.serializer"), exports);
@@ -1,2 +1,2 @@
1
- import { User } from '../interfaces/user.interface';
2
- export declare function getPrimaryEmail(user: User): string | undefined;
1
+ import { DirectoryUser } from '../interfaces/directory-user.interface';
2
+ export declare function getPrimaryEmail(user: DirectoryUser): string | undefined;
@@ -4,11 +4,11 @@ const get_primary_email_1 = require("./get-primary-email");
4
4
  describe('getPrimaryEmail', () => {
5
5
  const user = {
6
6
  id: 'user_123',
7
- custom_attributes: {
7
+ customAttributes: {
8
8
  custom: true,
9
9
  },
10
- directory_id: 'dir_123',
11
- organization_id: 'org_123',
10
+ directoryId: 'dir_123',
11
+ organizationId: 'org_123',
12
12
  emails: [
13
13
  {
14
14
  primary: true,
@@ -16,13 +16,15 @@ describe('getPrimaryEmail', () => {
16
16
  value: 'jonsnow@workos.com',
17
17
  },
18
18
  ],
19
- first_name: 'Jon',
20
- idp_id: 'idp_foo',
21
- last_name: 'Snow',
22
- raw_attributes: {},
19
+ firstName: 'Jon',
20
+ idpId: 'idp_foo',
21
+ lastName: 'Snow',
22
+ rawAttributes: {},
23
23
  state: 'active',
24
24
  username: 'jonsnow',
25
- job_title: 'Knight of the Watch',
25
+ jobTitle: 'Knight of the Watch',
26
+ createdAt: '2021-10-27 15:21:50.640958',
27
+ updatedAt: '2021-12-13 12:15:45.531847',
26
28
  };
27
29
  it(`returns primary email value`, () => {
28
30
  const primaryEmail = (0, get_primary_email_1.getPrimaryEmail)(user);
@@ -1,9 +1,9 @@
1
1
  import { WorkOS } from '../workos';
2
- import { Event } from './interfaces/event.interface';
3
- import { List } from '../common/interfaces/list.interface';
2
+ import { Event } from './interfaces';
4
3
  import { ListEventOptions } from './interfaces';
4
+ import { DeserializedList } from '../common/interfaces';
5
5
  export declare class Events {
6
6
  private readonly workos;
7
7
  constructor(workos: WorkOS);
8
- listEvents(options: ListEventOptions): Promise<List<Event>>;
8
+ listEvents(options: ListEventOptions): Promise<DeserializedList<Event>>;
9
9
  }
@@ -10,6 +10,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.Events = void 0;
13
+ const serializers_1 = require("../common/serializers");
14
+ const event_serializer_1 = require("./serializers/event.serializer");
13
15
  class Events {
14
16
  constructor(workos) {
15
17
  this.workos = workos;
@@ -19,7 +21,7 @@ class Events {
19
21
  const { data } = yield this.workos.get(`/events`, {
20
22
  query: options,
21
23
  });
22
- return data;
24
+ return (0, serializers_1.deserializeList)(data, event_serializer_1.deserializeEvent);
23
25
  });
24
26
  }
25
27
  }
@@ -19,6 +19,14 @@ const mock = new axios_mock_adapter_1.default(axios_1.default);
19
19
  describe('Event', () => {
20
20
  afterEach(() => mock.resetHistory());
21
21
  const workos = new workos_1.WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU');
22
+ const event = {
23
+ id: 'event_01234ABCD',
24
+ createdAt: '2020-05-06 04:21:48.649164',
25
+ event: 'dsync.user.created',
26
+ data: {
27
+ id: 'event_01234ABCD',
28
+ },
29
+ };
22
30
  const eventResponse = {
23
31
  id: 'event_01234ABCD',
24
32
  created_at: '2020-05-06 04:21:48.649164',
@@ -35,15 +43,23 @@ describe('Event', () => {
35
43
  };
36
44
  it(`requests Events`, () => __awaiter(void 0, void 0, void 0, function* () {
37
45
  mock.onGet('/events', {}).replyOnce(200, eventsListResponse);
38
- const list = yield workos.events.listEvents({});
39
- expect(list).toEqual(eventsListResponse);
46
+ const subject = yield workos.events.listEvents({});
47
+ expect(subject).toEqual({
48
+ object: 'list',
49
+ data: [event],
50
+ listMetadata: {},
51
+ });
40
52
  }));
41
53
  it(`requests Events with a valid event name`, () => __awaiter(void 0, void 0, void 0, function* () {
42
54
  mock.onGet('/events').replyOnce(200, eventsListResponse);
43
55
  const list = yield workos.events.listEvents({
44
56
  events: ['connection.activated'],
45
57
  });
46
- expect(list).toEqual(eventsListResponse);
58
+ expect(list).toEqual({
59
+ object: 'list',
60
+ data: [event],
61
+ listMetadata: {},
62
+ });
47
63
  }));
48
64
  });
49
65
  });