@workos-inc/node 3.0.0-user-management.2 → 3.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 (217) 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.d.ts +2 -2
  15. package/lib/audit-trail/audit-trail.spec.js +2 -1
  16. package/lib/common/interfaces/at-least-one-property-of.interface.d.ts +7 -0
  17. package/lib/common/interfaces/event.interface.d.ts +142 -0
  18. package/lib/common/interfaces/index.d.ts +5 -0
  19. package/lib/common/interfaces/index.js +5 -0
  20. package/lib/common/interfaces/list.interface.d.ts +9 -1
  21. package/lib/common/interfaces/workos-response-error.interface.d.ts +8 -0
  22. package/lib/common/serializers/event.serializer.d.ts +2 -0
  23. package/lib/common/serializers/event.serializer.js +40 -0
  24. package/lib/common/serializers/index.d.ts +2 -0
  25. package/lib/common/serializers/index.js +18 -0
  26. package/lib/common/serializers/list.serializer.d.ts +2 -0
  27. package/lib/common/serializers/list.serializer.js +9 -0
  28. package/lib/common/utils/fetch-and-deserialize.d.ts +3 -0
  29. package/lib/common/utils/fetch-and-deserialize.js +23 -0
  30. package/lib/common/utils/pagination.d.ts +15 -0
  31. package/lib/common/utils/pagination.js +90 -0
  32. package/lib/common/utils/workos-mock-response.d.ts +7 -0
  33. package/lib/common/utils/workos-mock-response.js +11 -0
  34. package/lib/directory-sync/directory-sync.d.ts +8 -12
  35. package/lib/directory-sync/directory-sync.js +9 -15
  36. package/lib/directory-sync/directory-sync.spec.js +132 -20
  37. package/lib/directory-sync/interfaces/directory-group.interface.d.ts +40 -0
  38. package/lib/directory-sync/interfaces/directory-user.interface.d.ts +50 -0
  39. package/lib/directory-sync/interfaces/directory.interface.d.ts +47 -2
  40. package/lib/directory-sync/interfaces/index.d.ts +6 -6
  41. package/lib/directory-sync/interfaces/index.js +20 -0
  42. package/lib/directory-sync/interfaces/list-directories-options.interface.d.ts +1 -1
  43. package/lib/directory-sync/interfaces/{list-users-options.interface.d.ts → list-directory-users-options.interface.d.ts} +1 -1
  44. package/lib/directory-sync/interfaces/list-groups-options.interface.d.ts +1 -1
  45. package/lib/directory-sync/serializers/directory-group.serializer.d.ts +4 -0
  46. package/lib/directory-sync/serializers/directory-group.serializer.js +37 -0
  47. package/lib/directory-sync/serializers/directory-user.serializer.d.ts +4 -0
  48. package/lib/directory-sync/serializers/directory-user.serializer.js +43 -0
  49. package/lib/directory-sync/serializers/directory.serializer.d.ts +5 -0
  50. package/lib/directory-sync/serializers/directory.serializer.js +50 -0
  51. package/lib/directory-sync/serializers/index.d.ts +3 -0
  52. package/lib/directory-sync/serializers/index.js +19 -0
  53. package/lib/directory-sync/utils/get-primary-email.d.ts +2 -2
  54. package/lib/directory-sync/utils/get-primary-email.spec.js +11 -8
  55. package/lib/events/events.d.ts +1 -2
  56. package/lib/events/events.js +2 -1
  57. package/lib/events/events.spec.js +39 -5
  58. package/lib/events/interfaces/index.d.ts +0 -1
  59. package/lib/events/interfaces/index.js +0 -1
  60. package/lib/events/interfaces/list-events-options.interface.d.ts +4 -4
  61. package/lib/index.d.ts +1 -1
  62. package/lib/index.js +1 -1
  63. package/lib/mfa/interfaces/challenge.interface.d.ts +9 -0
  64. package/lib/mfa/interfaces/factor.interface.d.ts +13 -4
  65. package/lib/mfa/interfaces/index.d.ts +9 -0
  66. package/lib/mfa/interfaces/index.js +25 -0
  67. package/lib/mfa/interfaces/sms.interface.d.ts +3 -0
  68. package/lib/mfa/interfaces/totp.interface.d.ts +7 -0
  69. package/lib/mfa/interfaces/verify-challenge-response.d.ts +5 -1
  70. package/lib/mfa/mfa.d.ts +2 -8
  71. package/lib/mfa/mfa.js +5 -4
  72. package/lib/mfa/mfa.spec.js +134 -115
  73. package/lib/mfa/serializers/challenge.serializer.d.ts +2 -0
  74. package/lib/mfa/serializers/challenge.serializer.js +13 -0
  75. package/lib/mfa/serializers/factor.serializer.d.ts +2 -0
  76. package/lib/mfa/serializers/factor.serializer.js +7 -0
  77. package/lib/mfa/serializers/index.d.ts +3 -0
  78. package/lib/{webhooks/interfaces → mfa/serializers}/index.js +3 -4
  79. package/lib/mfa/serializers/sms.serializer.d.ts +2 -0
  80. package/lib/mfa/serializers/sms.serializer.js +7 -0
  81. package/lib/mfa/serializers/totp.serializer.d.ts +2 -0
  82. package/lib/mfa/serializers/totp.serializer.js +11 -0
  83. package/lib/mfa/serializers/verify-response.serializer.d.ts +2 -0
  84. package/lib/mfa/serializers/verify-response.serializer.js +9 -0
  85. package/lib/organizations/interfaces/create-organization-options.interface.d.ts +5 -0
  86. package/lib/organizations/interfaces/organization.interface.d.ts +9 -0
  87. package/lib/organizations/interfaces/update-organization-options.interface.d.ts +5 -0
  88. package/lib/organizations/organizations.d.ts +2 -2
  89. package/lib/organizations/organizations.js +9 -9
  90. package/lib/organizations/organizations.spec.js +11 -4
  91. package/lib/organizations/serializers/create-organization-options.serializer.d.ts +2 -0
  92. package/lib/organizations/serializers/create-organization-options.serializer.js +9 -0
  93. package/lib/organizations/serializers/index.d.ts +3 -0
  94. package/lib/organizations/serializers/index.js +19 -0
  95. package/lib/organizations/serializers/organization.serializer.d.ts +2 -0
  96. package/lib/organizations/serializers/organization.serializer.js +13 -0
  97. package/lib/organizations/serializers/update-organization-options.serializer.d.ts +2 -0
  98. package/lib/organizations/serializers/update-organization-options.serializer.js +9 -0
  99. package/lib/passwordless/interfaces/create-passwordless-session-options.interface.d.ts +8 -0
  100. package/lib/passwordless/interfaces/index.d.ts +3 -3
  101. package/lib/passwordless/interfaces/index.js +17 -0
  102. package/lib/passwordless/interfaces/passwordless-session.interface.d.ts +7 -0
  103. package/lib/passwordless/passwordless.d.ts +1 -3
  104. package/lib/passwordless/passwordless.js +2 -1
  105. package/lib/passwordless/serializers/index.d.ts +0 -0
  106. package/lib/passwordless/serializers/index.js +1 -0
  107. package/lib/passwordless/serializers/passwordless-session.serializer.d.ts +2 -0
  108. package/lib/passwordless/serializers/passwordless-session.serializer.js +11 -0
  109. package/lib/portal/interfaces/generate-portal-link-intent.interface.js +1 -1
  110. package/lib/sso/interfaces/connection-type.enum.d.ts +1 -0
  111. package/lib/sso/interfaces/connection-type.enum.js +2 -1
  112. package/lib/sso/interfaces/connection.interface.d.ts +16 -5
  113. package/lib/sso/interfaces/index.d.ts +2 -0
  114. package/lib/sso/interfaces/index.js +2 -0
  115. package/lib/sso/interfaces/list-connections-options.interface.d.ts +5 -0
  116. package/lib/sso/interfaces/profile-and-token.interface.d.ts +6 -2
  117. package/lib/sso/interfaces/profile.interface.d.ts +14 -0
  118. package/lib/sso/serializers/connection.serializer.d.ts +2 -0
  119. package/lib/sso/serializers/connection.serializer.js +16 -0
  120. package/lib/sso/serializers/index.d.ts +3 -0
  121. package/lib/sso/serializers/index.js +19 -0
  122. package/lib/sso/serializers/profile-and-token.serializer.d.ts +2 -0
  123. package/lib/sso/serializers/profile-and-token.serializer.js +9 -0
  124. package/lib/sso/serializers/profile.serializer.d.ts +2 -0
  125. package/lib/sso/serializers/profile.serializer.js +16 -0
  126. package/lib/sso/sso.d.ts +3 -9
  127. package/lib/sso/sso.js +23 -16
  128. package/lib/sso/sso.spec.js +26 -9
  129. package/lib/users/exceptions/index.d.ts +4 -0
  130. package/lib/users/exceptions/index.js +10 -0
  131. package/lib/users/fixtures/list-users.json +0 -1
  132. package/lib/users/fixtures/session.json +2 -0
  133. package/lib/users/fixtures/user.json +0 -1
  134. package/lib/users/interfaces/add-user-to-organization-options.interface.d.ts +4 -1
  135. package/lib/users/interfaces/authenticate-user-with-magic-auth-options.interface.d.ts +21 -0
  136. package/lib/users/interfaces/authenticate-user-with-password-options.interface.d.ts +14 -1
  137. package/lib/users/interfaces/authenticate-user-with-token-options.interface.d.ts +10 -1
  138. package/lib/users/interfaces/authentication-response.interface.d.ts +7 -3
  139. package/lib/users/interfaces/complete-password-reset-options.interface.d.ts +4 -0
  140. package/lib/users/interfaces/create-email-verification-challenge-options.interface.d.ts +9 -2
  141. package/lib/users/interfaces/create-password-reset-challenge-options.interface.d.ts +9 -1
  142. package/lib/users/interfaces/create-user-options.interface.d.ts +8 -1
  143. package/lib/users/interfaces/index.d.ts +7 -0
  144. package/lib/users/interfaces/index.js +7 -0
  145. package/lib/users/interfaces/magic-auth-challenge.interface.d.ts +3 -0
  146. package/lib/users/interfaces/remove-user-from-organization-options.interface.d.ts +2 -2
  147. package/lib/users/interfaces/revoke-all-sessions-for-user-options.interface.d.ts +3 -0
  148. package/lib/users/interfaces/revoke-all-sessions-for-user-options.interface.js +2 -0
  149. package/lib/users/interfaces/revoke-session-options.interface.d.ts +7 -0
  150. package/lib/users/interfaces/send-magic-auth-code-options.interface.d.ts +6 -0
  151. package/lib/users/interfaces/send-magic-auth-code-options.interface.js +2 -0
  152. package/lib/users/interfaces/session.interface.d.ts +35 -0
  153. package/lib/users/interfaces/update-user-options.interface.d.ts +14 -0
  154. package/lib/users/interfaces/update-user-options.interface.js +2 -0
  155. package/lib/users/interfaces/update-user-password-options.interface.d.ts +7 -0
  156. package/lib/users/interfaces/update-user-password-options.interface.js +2 -0
  157. package/lib/users/interfaces/user.interface.d.ts +28 -18
  158. package/lib/users/interfaces/verify-session.interface.d.ts +10 -2
  159. package/lib/users/serializers/authenticate-user-with-magic-auth-options.serializer.d.ts +2 -0
  160. package/lib/users/serializers/authenticate-user-with-magic-auth-options.serializer.js +14 -0
  161. package/lib/users/serializers/authenticate-user-with-password-options.serializer.d.ts +2 -0
  162. package/lib/users/serializers/authenticate-user-with-password-options.serializer.js +14 -0
  163. package/lib/users/serializers/authenticate-user-with-token-options.serializer.d.ts +2 -0
  164. package/lib/users/serializers/authenticate-user-with-token-options.serializer.js +11 -0
  165. package/lib/users/serializers/authentication-response.serializer.d.ts +2 -0
  166. package/lib/users/serializers/authentication-response.serializer.js +10 -0
  167. package/lib/users/serializers/complete-password-reset-options.serializer.d.ts +2 -0
  168. package/lib/users/serializers/complete-password-reset-options.serializer.js +8 -0
  169. package/lib/users/serializers/create-email-verification-challenge.serializer.d.ts +2 -0
  170. package/lib/users/serializers/create-email-verification-challenge.serializer.js +9 -0
  171. package/lib/users/serializers/create-password-reset-challenge.serializer.d.ts +3 -0
  172. package/lib/users/serializers/create-password-reset-challenge.serializer.js +14 -0
  173. package/lib/users/serializers/create-user-options.serializer.d.ts +2 -0
  174. package/lib/users/serializers/create-user-options.serializer.js +11 -0
  175. package/lib/users/serializers/index.d.ts +15 -0
  176. package/lib/users/serializers/index.js +31 -0
  177. package/lib/users/serializers/revoke-session-options.serializer.d.ts +2 -0
  178. package/lib/users/serializers/revoke-session-options.serializer.js +14 -0
  179. package/lib/users/serializers/send-magic-auth-code-options.serializer.d.ts +2 -0
  180. package/lib/users/serializers/send-magic-auth-code-options.serializer.js +7 -0
  181. package/lib/users/serializers/session.serializer.d.ts +4 -0
  182. package/lib/users/serializers/session.serializer.js +22 -0
  183. package/lib/users/serializers/update-user-options.serializer.d.ts +2 -0
  184. package/lib/users/serializers/update-user-options.serializer.js +8 -0
  185. package/lib/users/serializers/update-user-password-options.serializer.d.ts +2 -0
  186. package/lib/users/serializers/update-user-password-options.serializer.js +7 -0
  187. package/lib/users/serializers/user.serializer.d.ts +2 -0
  188. package/lib/users/serializers/user.serializer.js +24 -0
  189. package/lib/users/serializers/verify-session.serializer.d.ts +3 -0
  190. package/lib/users/serializers/verify-session.serializer.js +15 -0
  191. package/lib/users/users.d.ts +11 -7
  192. package/lib/users/users.js +54 -30
  193. package/lib/users/users.spec.js +133 -49
  194. package/lib/webhooks/fixtures/webhook.json +67 -1
  195. package/lib/webhooks/webhooks.d.ts +2 -2
  196. package/lib/webhooks/webhooks.js +2 -1
  197. package/lib/webhooks/webhooks.spec.js +8 -6
  198. package/lib/workos.d.ts +5 -4
  199. package/lib/workos.js +4 -1
  200. package/lib/workos.spec.js +11 -1
  201. package/package.json +14 -15
  202. package/lib/directory-sync/interfaces/group.interface.d.ts +0 -10
  203. package/lib/directory-sync/interfaces/user.interface.d.ts +0 -23
  204. package/lib/events/interfaces/event.interface.d.ts +0 -63
  205. package/lib/webhooks/interfaces/index.d.ts +0 -4
  206. package/lib/webhooks/interfaces/webhook-directory-group.interface.d.ts +0 -10
  207. package/lib/webhooks/interfaces/webhook-directory-user.interface.d.ts +0 -5
  208. package/lib/webhooks/interfaces/webhook-directory.interface.d.ts +0 -20
  209. package/lib/webhooks/interfaces/webhook.interface.d.ts +0 -73
  210. /package/lib/{directory-sync/interfaces/group.interface.js → common/interfaces/at-least-one-property-of.interface.js} +0 -0
  211. /package/lib/{events → common}/interfaces/event.interface.js +0 -0
  212. /package/lib/{directory-sync/interfaces/list-users-options.interface.js → common/interfaces/workos-response-error.interface.js} +0 -0
  213. /package/lib/directory-sync/interfaces/{user.interface.js → directory-group.interface.js} +0 -0
  214. /package/lib/{webhooks/interfaces/webhook-directory-group.interface.js → directory-sync/interfaces/directory-user.interface.js} +0 -0
  215. /package/lib/{webhooks/interfaces/webhook-directory-user.interface.js → directory-sync/interfaces/list-directory-users-options.interface.js} +0 -0
  216. /package/lib/{webhooks/interfaces/webhook-directory.interface.js → users/interfaces/authenticate-user-with-magic-auth-options.interface.js} +0 -0
  217. /package/lib/{webhooks/interfaces/webhook.interface.js → users/interfaces/magic-auth-challenge.interface.js} +0 -0
@@ -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: 'active',
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,13 +61,40 @@ 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
+ object: 'directory_user',
72
+ id: 'user_123',
73
+ customAttributes: {
74
+ custom: true,
75
+ },
76
+ directoryId: 'dir_123',
77
+ organizationId: 'org_123',
78
+ emails: [
79
+ {
80
+ primary: true,
81
+ type: 'type',
82
+ value: 'jonsnow@workos.com',
83
+ },
84
+ ],
85
+ firstName: 'Jon',
86
+ groups: [group],
87
+ idpId: 'idp_foo',
88
+ lastName: 'Snow',
89
+ jobTitle: 'Knight of the Watch',
90
+ rawAttributes: {},
91
+ state: 'active',
92
+ username: 'jonsnow',
93
+ createdAt: '2021-10-27 15:21:50.640959',
94
+ updatedAt: '2021-12-13 12:15:45.531847',
95
+ };
46
96
  const userWithGroupResponse = {
97
+ object: 'directory_user',
47
98
  id: 'user_123',
48
99
  custom_attributes: {
49
100
  custom: true,
@@ -65,6 +116,8 @@ describe('DirectorySync', () => {
65
116
  raw_attributes: {},
66
117
  state: 'active',
67
118
  username: 'jonsnow',
119
+ created_at: '2021-10-27 15:21:50.640959',
120
+ updated_at: '2021-12-13 12:15:45.531847',
68
121
  };
69
122
  describe('listDirectories', () => {
70
123
  describe('with options', () => {
@@ -79,10 +132,21 @@ describe('DirectorySync', () => {
79
132
  domain: 'google.com',
80
133
  })
81
134
  .replyOnce(200, directoryListResponse);
82
- const directories = yield workos.directorySync.listDirectories({
135
+ const subject = yield workos.directorySync.listDirectories({
83
136
  domain: 'google.com',
84
137
  });
85
- expect(directories).toEqual(directoryListResponse);
138
+ expect(subject).toMatchObject({
139
+ object: 'list',
140
+ list: {
141
+ object: 'list',
142
+ data: [directory],
143
+ listMetadata: {},
144
+ },
145
+ apiCall: expect.any(Function),
146
+ options: {
147
+ domain: 'google.com',
148
+ },
149
+ });
86
150
  }));
87
151
  });
88
152
  });
@@ -91,8 +155,8 @@ describe('DirectorySync', () => {
91
155
  mock
92
156
  .onGet('/directories/directory_123')
93
157
  .replyOnce(200, directoryResponse);
94
- const directory = yield workos.directorySync.getDirectory('directory_123');
95
- expect(directory).toEqual(directoryResponse);
158
+ const subject = yield workos.directorySync.getDirectory('directory_123');
159
+ expect(subject).toEqual(directory);
96
160
  }));
97
161
  });
98
162
  describe('deleteDirectory', () => {
@@ -105,8 +169,8 @@ describe('DirectorySync', () => {
105
169
  describe('getGroup', () => {
106
170
  it(`requests a Directory Group`, () => __awaiter(void 0, void 0, void 0, function* () {
107
171
  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);
172
+ const subject = yield workos.directorySync.getGroup('dir_grp_123');
173
+ expect(subject).toEqual(group);
110
174
  }));
111
175
  });
112
176
  describe('listGroups', () => {
@@ -122,10 +186,21 @@ describe('DirectorySync', () => {
122
186
  directory: 'directory_123',
123
187
  })
124
188
  .replyOnce(200, groupListResponse);
125
- const list = yield workos.directorySync.listGroups({
189
+ const subject = yield workos.directorySync.listGroups({
126
190
  directory: 'directory_123',
127
191
  });
128
- expect(list).toEqual(groupListResponse);
192
+ expect(subject).toMatchObject({
193
+ object: 'list',
194
+ list: {
195
+ object: 'list',
196
+ data: [group],
197
+ listMetadata: {},
198
+ },
199
+ apiCall: expect.any(Function),
200
+ options: {
201
+ directory: 'directory_123',
202
+ },
203
+ });
129
204
  }));
130
205
  });
131
206
  describe('with a User', () => {
@@ -135,10 +210,21 @@ describe('DirectorySync', () => {
135
210
  user: 'directory_usr_123',
136
211
  })
137
212
  .replyOnce(200, groupListResponse);
138
- const list = yield workos.directorySync.listGroups({
213
+ const subject = yield workos.directorySync.listGroups({
139
214
  user: 'directory_usr_123',
140
215
  });
141
- expect(list).toEqual(groupListResponse);
216
+ expect(subject).toEqual({
217
+ object: 'list',
218
+ list: {
219
+ object: 'list',
220
+ data: [group],
221
+ listMetadata: {},
222
+ },
223
+ apiCall: expect.any(Function),
224
+ options: {
225
+ user: 'directory_usr_123',
226
+ },
227
+ });
142
228
  }));
143
229
  });
144
230
  });
@@ -155,10 +241,21 @@ describe('DirectorySync', () => {
155
241
  directory: 'directory_123',
156
242
  })
157
243
  .replyOnce(200, userWithGroupListResponse);
158
- const list = yield workos.directorySync.listUsers({
244
+ const subject = yield workos.directorySync.listUsers({
159
245
  directory: 'directory_123',
160
246
  });
161
- expect(list).toEqual(userWithGroupListResponse);
247
+ expect(subject).toMatchObject({
248
+ object: 'list',
249
+ list: {
250
+ object: 'list',
251
+ data: [userWithGroup],
252
+ listMetadata: {},
253
+ },
254
+ apiCall: expect.any(Function),
255
+ options: {
256
+ directory: 'directory_123',
257
+ },
258
+ });
162
259
  }));
163
260
  describe('with custom attributes', () => {
164
261
  it('returns the custom attributes, using the provided type', () => __awaiter(void 0, void 0, void 0, function* () {
@@ -179,6 +276,8 @@ describe('DirectorySync', () => {
179
276
  last_name: 'Stoltenberg',
180
277
  job_title: 'Software Engineer',
181
278
  state: 'active',
279
+ created_at: '2021-10-27 15:21:50.640959',
280
+ updated_at: '2021-12-13 12:15:45.531847',
182
281
  raw_attributes: {},
183
282
  custom_attributes: {
184
283
  managerId: '99f1817b-149c-4438-b80f-a272c3406109',
@@ -204,6 +303,8 @@ describe('DirectorySync', () => {
204
303
  last_name: 'Leffler',
205
304
  job_title: 'Software Engineer',
206
305
  state: 'active',
306
+ created_at: '2021-10-27 15:21:50.640959',
307
+ updated_at: '2021-12-13 12:15:45.531847',
207
308
  raw_attributes: {},
208
309
  custom_attributes: {
209
310
  managerId: '263c7472-4d3f-4ab4-8162-e768af103065',
@@ -223,7 +324,7 @@ describe('DirectorySync', () => {
223
324
  const users = yield workos.directorySync.listUsers({
224
325
  directory: 'directory_123',
225
326
  });
226
- const managerIds = users.data.map((user) => user.custom_attributes.managerId);
327
+ const managerIds = users.data.map((user) => user.customAttributes.managerId);
227
328
  expect(managerIds).toEqual([
228
329
  '99f1817b-149c-4438-b80f-a272c3406109',
229
330
  '263c7472-4d3f-4ab4-8162-e768af103065',
@@ -238,10 +339,21 @@ describe('DirectorySync', () => {
238
339
  group: 'directory_grp_123',
239
340
  })
240
341
  .replyOnce(200, userWithGroupListResponse);
241
- const list = yield workos.directorySync.listUsers({
342
+ const subject = yield workos.directorySync.listUsers({
242
343
  group: 'directory_grp_123',
243
344
  });
244
- expect(list).toEqual(userWithGroupListResponse);
345
+ expect(subject).toMatchObject({
346
+ object: 'list',
347
+ list: {
348
+ object: 'list',
349
+ data: [userWithGroup],
350
+ listMetadata: {},
351
+ },
352
+ apiCall: expect.any(Function),
353
+ options: {
354
+ group: 'directory_grp_123',
355
+ },
356
+ });
245
357
  }));
246
358
  });
247
359
  });
@@ -250,8 +362,8 @@ describe('DirectorySync', () => {
250
362
  mock
251
363
  .onGet('/directory_users/dir_usr_123')
252
364
  .replyOnce(200, userWithGroupResponse);
253
- const user = yield workos.directorySync.getUser('dir_usr_123');
254
- expect(user).toEqual(userWithGroupResponse);
365
+ const subject = yield workos.directorySync.getUser('dir_usr_123');
366
+ expect(subject).toEqual(userWithGroup);
255
367
  }));
256
368
  });
257
369
  });
@@ -0,0 +1,40 @@
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
+ }
21
+ export interface EventDirectoryGroup<TRawAttributes = any> {
22
+ id: string;
23
+ idpId: string;
24
+ directoryId: string;
25
+ organizationId: string | null;
26
+ name: string;
27
+ createdAt: string;
28
+ updatedAt: string;
29
+ rawAttributes: TRawAttributes;
30
+ }
31
+ export interface EventDirectoryGroupResponse<TRawAttributes = any> {
32
+ id: string;
33
+ idp_id: string;
34
+ directory_id: string;
35
+ organization_id: string | null;
36
+ name: string;
37
+ created_at: string;
38
+ updated_at: string;
39
+ raw_attributes: TRawAttributes;
40
+ }
@@ -0,0 +1,50 @@
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
+ object: 'directory_user';
5
+ id: string;
6
+ directoryId: string;
7
+ organizationId: string | null;
8
+ rawAttributes: TRawAttributes;
9
+ customAttributes: TCustomAttributes;
10
+ idpId: string;
11
+ firstName: string;
12
+ emails: {
13
+ type: string;
14
+ value: string;
15
+ primary: boolean;
16
+ }[];
17
+ username: string;
18
+ lastName: string;
19
+ jobTitle: string | null;
20
+ state: 'active' | 'inactive' | 'suspended';
21
+ createdAt: string;
22
+ updatedAt: string;
23
+ }
24
+ export interface DirectoryUserResponse<TCustomAttributes extends object = DefaultCustomAttributes, TRawAttributes = any> {
25
+ object: 'directory_user';
26
+ id: string;
27
+ directory_id: string;
28
+ organization_id: string | null;
29
+ raw_attributes: TRawAttributes;
30
+ custom_attributes: TCustomAttributes;
31
+ idp_id: string;
32
+ first_name: string;
33
+ emails: {
34
+ type: string;
35
+ value: string;
36
+ primary: boolean;
37
+ }[];
38
+ username: string;
39
+ last_name: string;
40
+ job_title: string | null;
41
+ state: 'active' | 'inactive' | 'suspended';
42
+ created_at: string;
43
+ updated_at: string;
44
+ }
45
+ export interface DirectoryUserWithGroups<TCustomAttributes extends object = DefaultCustomAttributes> extends DirectoryUser<TCustomAttributes> {
46
+ groups: DirectoryGroup[];
47
+ }
48
+ export interface DirectoryUserWithGroupsResponse<TCustomAttributes extends object = DefaultCustomAttributes> extends DirectoryUserResponse<TCustomAttributes> {
49
+ groups: DirectoryGroupResponse[];
50
+ }
@@ -1,12 +1,57 @@
1
+ export type DirectoryType = 'azure scim v2.0' | 'bamboohr' | 'breathe hr' | 'cezanne hr' | 'cyberark scim v2.0' | 'fourth hr' | 'gsuite directory' | 'generic scim v1.1' | 'generic scim v2.0' | 'gusto' | 'hibob' | 'jump cloud scim v2.0' | 'okta scim v1.1' | 'okta scim v2.0' | 'onelogin scim v2.0' | 'people hr' | 'personio' | 'pingfederate scim v2.0' | 'rippling' | 'rippling scim v2.0' | 'sftp' | 'sftp workday' | 's3' | 'workday';
2
+ export type DirectoryState = 'active' | 'deleting' | 'inactive' | 'invalid_credentials' | 'validating';
3
+ export type DirectoryStateResponse = 'deleting' | 'invalid_credentials' | 'linked' | 'unlinked' | 'validating';
1
4
  export interface Directory {
2
5
  object: 'directory';
3
6
  id: string;
4
7
  domain: string;
8
+ externalKey: string;
9
+ name: string;
10
+ organizationId?: string;
11
+ state: DirectoryState;
12
+ type: DirectoryType;
13
+ createdAt: string;
14
+ updatedAt: string;
15
+ }
16
+ export interface DirectoryResponse {
17
+ object: 'directory';
18
+ id: string;
19
+ domain: string;
20
+ external_key: string;
21
+ name: string;
22
+ organization_id?: string;
23
+ state: DirectoryStateResponse;
24
+ type: DirectoryType;
25
+ created_at: string;
26
+ updated_at: string;
27
+ }
28
+ interface EventDirectoryDomain {
29
+ object: 'organization_domain';
30
+ id: string;
31
+ domain: string;
32
+ }
33
+ export interface EventDirectory {
34
+ object: 'directory';
35
+ id: string;
36
+ externalKey: string;
37
+ type: DirectoryType;
38
+ state: DirectoryState;
39
+ name: string;
40
+ organizationId?: string;
41
+ domains: EventDirectoryDomain[];
42
+ createdAt: string;
43
+ updatedAt: string;
44
+ }
45
+ export interface EventDirectoryResponse {
46
+ object: 'directory';
47
+ id: string;
5
48
  external_key: string;
49
+ type: DirectoryType;
50
+ state: DirectoryState;
6
51
  name: string;
7
52
  organization_id?: string;
8
- state: 'unlinked' | 'linked' | 'invalid_credentials';
9
- type: string;
53
+ domains: EventDirectoryDomain[];
10
54
  created_at: string;
11
55
  updated_at: string;
12
56
  }
57
+ export {};
@@ -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
  }
@@ -1,5 +1,5 @@
1
1
  import { PaginationOptions } from '../../common/interfaces/pagination-options.interface';
2
- export interface ListGroupsOptions extends PaginationOptions {
2
+ export interface ListDirectoryGroupsOptions extends PaginationOptions {
3
3
  directory?: string;
4
4
  user?: string;
5
5
  }
@@ -0,0 +1,4 @@
1
+ import { DirectoryGroup, DirectoryGroupResponse, EventDirectoryGroup, EventDirectoryGroupResponse } from '../interfaces';
2
+ export declare const deserializeDirectoryGroup: (directoryGroup: DirectoryGroupResponse) => DirectoryGroup;
3
+ export declare const deserializeEventDirectoryGroup: (directoryGroup: EventDirectoryGroupResponse) => EventDirectoryGroup;
4
+ export declare const deserializeUpdatedEventDirectoryGroup: (directoryGroup: EventDirectoryGroupResponse & Record<'previous_attributes', any>) => EventDirectoryGroup & Record<'previousAttributes', any>;
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.deserializeUpdatedEventDirectoryGroup = exports.deserializeEventDirectoryGroup = 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;
15
+ const deserializeEventDirectoryGroup = (directoryGroup) => ({
16
+ id: directoryGroup.id,
17
+ idpId: directoryGroup.idp_id,
18
+ directoryId: directoryGroup.directory_id,
19
+ organizationId: directoryGroup.organization_id,
20
+ name: directoryGroup.name,
21
+ createdAt: directoryGroup.created_at,
22
+ updatedAt: directoryGroup.updated_at,
23
+ rawAttributes: directoryGroup.raw_attributes,
24
+ });
25
+ exports.deserializeEventDirectoryGroup = deserializeEventDirectoryGroup;
26
+ const deserializeUpdatedEventDirectoryGroup = (directoryGroup) => ({
27
+ id: directoryGroup.id,
28
+ idpId: directoryGroup.idp_id,
29
+ directoryId: directoryGroup.directory_id,
30
+ organizationId: directoryGroup.organization_id,
31
+ name: directoryGroup.name,
32
+ createdAt: directoryGroup.created_at,
33
+ updatedAt: directoryGroup.updated_at,
34
+ rawAttributes: directoryGroup.raw_attributes,
35
+ previousAttributes: directoryGroup.previous_attributes,
36
+ });
37
+ exports.deserializeUpdatedEventDirectoryGroup = deserializeUpdatedEventDirectoryGroup;
@@ -0,0 +1,4 @@
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>;
4
+ export declare const deserializeUpdatedEventDirectoryUser: (directoryUser: DirectoryUserResponse & Record<'previous_attributes', any>) => DirectoryUser & Record<'previousAttributes', any>;
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.deserializeUpdatedEventDirectoryUser = exports.deserializeDirectoryUserWithGroups = exports.deserializeDirectoryUser = void 0;
4
+ const directory_group_serializer_1 = require("./directory-group.serializer");
5
+ const deserializeDirectoryUser = (directoryUser) => ({
6
+ object: directoryUser.object,
7
+ id: directoryUser.id,
8
+ directoryId: directoryUser.directory_id,
9
+ organizationId: directoryUser.organization_id,
10
+ rawAttributes: directoryUser.raw_attributes,
11
+ customAttributes: directoryUser.custom_attributes,
12
+ idpId: directoryUser.idp_id,
13
+ firstName: directoryUser.first_name,
14
+ emails: directoryUser.emails,
15
+ username: directoryUser.username,
16
+ lastName: directoryUser.last_name,
17
+ jobTitle: directoryUser.job_title,
18
+ state: directoryUser.state,
19
+ createdAt: directoryUser.created_at,
20
+ updatedAt: directoryUser.updated_at,
21
+ });
22
+ exports.deserializeDirectoryUser = deserializeDirectoryUser;
23
+ const deserializeDirectoryUserWithGroups = (directoryUserWithGroups) => (Object.assign(Object.assign({}, (0, exports.deserializeDirectoryUser)(directoryUserWithGroups)), { groups: directoryUserWithGroups.groups.map(directory_group_serializer_1.deserializeDirectoryGroup) }));
24
+ exports.deserializeDirectoryUserWithGroups = deserializeDirectoryUserWithGroups;
25
+ const deserializeUpdatedEventDirectoryUser = (directoryUser) => ({
26
+ object: 'directory_user',
27
+ id: directoryUser.id,
28
+ directoryId: directoryUser.directory_id,
29
+ organizationId: directoryUser.organization_id,
30
+ rawAttributes: directoryUser.raw_attributes,
31
+ customAttributes: directoryUser.custom_attributes,
32
+ idpId: directoryUser.idp_id,
33
+ firstName: directoryUser.first_name,
34
+ emails: directoryUser.emails,
35
+ username: directoryUser.username,
36
+ lastName: directoryUser.last_name,
37
+ jobTitle: directoryUser.job_title,
38
+ state: directoryUser.state,
39
+ createdAt: directoryUser.created_at,
40
+ updatedAt: directoryUser.updated_at,
41
+ previousAttributes: directoryUser.previous_attributes,
42
+ });
43
+ exports.deserializeUpdatedEventDirectoryUser = deserializeUpdatedEventDirectoryUser;
@@ -0,0 +1,5 @@
1
+ import { Directory, DirectoryResponse, DirectoryState, DirectoryStateResponse, EventDirectory, EventDirectoryResponse } from '../interfaces';
2
+ export declare const deserializeDirectory: (directory: DirectoryResponse) => Directory;
3
+ export declare const deserializeDirectoryState: (state: DirectoryStateResponse) => DirectoryState;
4
+ export declare const deserializeEventDirectory: (directory: EventDirectoryResponse) => EventDirectory;
5
+ export declare const deserializeDeletedEventDirectory: (directory: Omit<EventDirectoryResponse, 'domains' | 'external_key'>) => Omit<EventDirectory, 'domains' | 'externalKey'>;
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.deserializeDeletedEventDirectory = exports.deserializeEventDirectory = exports.deserializeDirectoryState = 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: (0, exports.deserializeDirectoryState)(directory.state),
12
+ type: directory.type,
13
+ createdAt: directory.created_at,
14
+ updatedAt: directory.updated_at,
15
+ });
16
+ exports.deserializeDirectory = deserializeDirectory;
17
+ const deserializeDirectoryState = (state) => {
18
+ if (state === 'linked') {
19
+ return 'active';
20
+ }
21
+ if (state === 'unlinked') {
22
+ return 'inactive';
23
+ }
24
+ return state;
25
+ };
26
+ exports.deserializeDirectoryState = deserializeDirectoryState;
27
+ const deserializeEventDirectory = (directory) => ({
28
+ object: directory.object,
29
+ id: directory.id,
30
+ externalKey: directory.external_key,
31
+ type: directory.type,
32
+ state: directory.state,
33
+ name: directory.name,
34
+ organizationId: directory.organization_id,
35
+ domains: directory.domains,
36
+ createdAt: directory.created_at,
37
+ updatedAt: directory.updated_at,
38
+ });
39
+ exports.deserializeEventDirectory = deserializeEventDirectory;
40
+ const deserializeDeletedEventDirectory = (directory) => ({
41
+ object: directory.object,
42
+ id: directory.id,
43
+ type: directory.type,
44
+ state: directory.state,
45
+ name: directory.name,
46
+ organizationId: directory.organization_id,
47
+ createdAt: directory.created_at,
48
+ updatedAt: directory.updated_at,
49
+ });
50
+ exports.deserializeDeletedEventDirectory = deserializeDeletedEventDirectory;
@@ -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);