@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
@@ -32,11 +32,10 @@ describe('UserManagement', () => {
32
32
  object: 'user',
33
33
  id: 'user_01H5JQDV7R7ATEYZDEG0W5PRYS',
34
34
  email: 'test01@example.com',
35
- first_name: 'Test 01',
36
- last_name: 'User',
37
- organization_memberships: [],
38
- user_type: 'unmanaged',
39
- email_verified_at: '2023-07-17T20:07:20.055Z',
35
+ firstName: 'Test 01',
36
+ lastName: 'User',
37
+ userType: 'unmanaged',
38
+ emailVerifiedAt: '2023-07-17T20:07:20.055Z',
40
39
  });
41
40
  }));
42
41
  });
@@ -53,7 +52,7 @@ describe('UserManagement', () => {
53
52
  email: 'test01@example.com',
54
53
  },
55
54
  ],
56
- list_metadata: {
55
+ listMetadata: {
57
56
  before: null,
58
57
  after: null,
59
58
  },
@@ -74,6 +73,7 @@ describe('UserManagement', () => {
74
73
  type: 'managed',
75
74
  after: 'user_01H5JQDV7R7ATEYZDEG0W5PRYS',
76
75
  limit: 10,
76
+ order: 'desc',
77
77
  });
78
78
  }));
79
79
  });
@@ -83,25 +83,58 @@ describe('UserManagement', () => {
83
83
  const user = yield workos.users.createUser({
84
84
  email: 'test01@example.com',
85
85
  password: 'extra-secure',
86
- first_name: 'Test 01',
87
- last_name: 'User',
88
- email_verified: true,
86
+ firstName: 'Test 01',
87
+ lastName: 'User',
88
+ emailVerified: true,
89
89
  });
90
90
  expect(mock.history.post[0].url).toEqual('/users');
91
- expect(user).toMatchObject(user_json_1.default);
91
+ expect(user).toMatchObject({
92
+ object: 'user',
93
+ email: 'test01@example.com',
94
+ firstName: 'Test 01',
95
+ lastName: 'User',
96
+ userType: 'unmanaged',
97
+ emailVerifiedAt: '2023-07-17T20:07:20.055Z',
98
+ createdAt: '2023-07-18T02:07:19.911Z',
99
+ updatedAt: '2023-07-18T02:07:19.911Z',
100
+ });
101
+ }));
102
+ });
103
+ describe('authenticateUserWithMagicAuth', () => {
104
+ it('sends a magic auth authentication request', () => __awaiter(void 0, void 0, void 0, function* () {
105
+ mock.onPost('/users/sessions/token').reply(200, {
106
+ user: user_json_1.default,
107
+ session: session_json_1.default,
108
+ });
109
+ const resp = yield workos.users.authenticateUserWithMagicAuth({
110
+ clientId: 'proj_whatever',
111
+ code: '123456',
112
+ magicAuthChallengeId: 'auth_challenge_123',
113
+ });
114
+ expect(mock.history.post[0].url).toEqual('/users/sessions/token');
115
+ expect(resp).toMatchObject({
116
+ user: {
117
+ email: 'test01@example.com',
118
+ },
119
+ session: {
120
+ id: 'session_01H5K05VP5CPCXJA5Z7G191GS4',
121
+ token: 'really-long-token',
122
+ },
123
+ });
92
124
  }));
93
125
  });
94
126
  describe('authenticateUserWithPassword', () => {
95
127
  it('sends an password authentication request', () => __awaiter(void 0, void 0, void 0, function* () {
96
- mock.onPost('/users/authentications').reply(200, {
128
+ mock.onPost('/users/sessions/token').reply(200, {
97
129
  user: user_json_1.default,
98
130
  session: session_json_1.default,
99
131
  });
100
132
  const resp = yield workos.users.authenticateUserWithPassword({
133
+ clientId: 'proj_whatever',
101
134
  email: 'test01@example.com',
102
135
  password: 'extra-secure',
103
136
  });
104
- expect(mock.history.post[0].url).toEqual('/users/authentications');
137
+ expect(mock.history.post[0].url).toEqual('/users/sessions/token');
105
138
  expect(resp).toMatchObject({
106
139
  user: {
107
140
  email: 'test01@example.com',
@@ -119,9 +152,9 @@ describe('UserManagement', () => {
119
152
  .onPost('/users/sessions/token')
120
153
  .reply(200, { user: user_json_1.default, session: session_json_1.default });
121
154
  const resp = yield workos.users.authenticateUserWithToken({
122
- client_id: 'proj_whatever',
155
+ clientId: 'proj_whatever',
123
156
  code: 'or this',
124
- expires_in: 15,
157
+ expiresIn: 15,
125
158
  });
126
159
  expect(mock.history.post[0].url).toEqual('/users/sessions/token');
127
160
  expect(JSON.parse(mock.history.post[0].data)).toMatchObject({
@@ -146,7 +179,7 @@ describe('UserManagement', () => {
146
179
  session: session_json_1.default,
147
180
  });
148
181
  const resp = yield workos.users.verifySession({
149
- client_id: 'proj_something',
182
+ clientId: 'proj_something',
150
183
  token: 'really-long-token',
151
184
  });
152
185
  expect(mock.history.post[0].url).toEqual('/users/sessions/verify');
@@ -165,7 +198,7 @@ describe('UserManagement', () => {
165
198
  it('can revoke with the session_id', () => __awaiter(void 0, void 0, void 0, function* () {
166
199
  mock.onPost('/users/sessions/revocations').reply(200, true);
167
200
  const revoked = yield workos.users.revokeSession({
168
- session_id: 'session_01H5K05VP5CPCXJA5Z7G191GS4',
201
+ sessionId: 'session_01H5K05VP5CPCXJA5Z7G191GS4',
169
202
  });
170
203
  expect(mock.history.post[0].url).toEqual('/users/sessions/revocations');
171
204
  expect(revoked).toEqual(true);
@@ -173,7 +206,7 @@ describe('UserManagement', () => {
173
206
  it('can revoke with the session_token', () => __awaiter(void 0, void 0, void 0, function* () {
174
207
  mock.onPost('/users/sessions/revocations').reply(200, true);
175
208
  const revoked = yield workos.users.revokeSession({
176
- session_token: 'really-long-token',
209
+ sessionToken: 'really-long-token',
177
210
  });
178
211
  expect(mock.history.post[0].url).toEqual('/users/sessions/revocations');
179
212
  expect(revoked).toEqual(true);
@@ -182,7 +215,7 @@ describe('UserManagement', () => {
182
215
  describe('revokeAllSessionsForUser', () => {
183
216
  it('sends a revokeAllSessionsForUser request', () => __awaiter(void 0, void 0, void 0, function* () {
184
217
  mock.onDelete(`/users/${userId}/sessions`).reply(200, true);
185
- const revoked = yield workos.users.revokeAllSessionsForUser(userId);
218
+ const revoked = yield workos.users.revokeAllSessionsForUser({ userId });
186
219
  expect(mock.history.delete[0].url).toEqual(`/users/${userId}/sessions`);
187
220
  expect(revoked).toEqual(true);
188
221
  }));
@@ -194,8 +227,8 @@ describe('UserManagement', () => {
194
227
  user: user_json_1.default,
195
228
  });
196
229
  const resp = yield workos.users.createEmailVerificationChallenge({
197
- user_id: userId,
198
- verification_url: 'https://example.com/verify-email',
230
+ userId,
231
+ verificationUrl: 'https://example.com/verify-email',
199
232
  });
200
233
  expect(mock.history.post[0].url).toEqual(`/users/${userId}/email_verification_challenge`);
201
234
  expect(resp).toMatchObject({
@@ -207,19 +240,33 @@ describe('UserManagement', () => {
207
240
  }));
208
241
  describe('completeEmailVerification', () => {
209
242
  it('sends a Complete Email Verification request', () => __awaiter(void 0, void 0, void 0, function* () {
210
- mock
211
- .onPost(`/users/email_verification`)
212
- .reply(200, { user: user_json_1.default });
243
+ mock.onPost(`/users/email_verification`).reply(200, user_json_1.default);
213
244
  const resp = yield workos.users.completeEmailVerification('email-verification-token');
214
245
  expect(mock.history.post[0].url).toEqual(`/users/email_verification`);
215
246
  expect(resp).toMatchObject({
216
- user: {
217
- email: 'test01@example.com',
218
- },
247
+ email: 'test01@example.com',
219
248
  });
220
249
  }));
221
250
  });
222
251
  });
252
+ describe('sendMagicAuthCode', () => {
253
+ it('sends a Send Magic Auth Code request', () => __awaiter(void 0, void 0, void 0, function* () {
254
+ mock
255
+ .onPost('/users/magic_auth/send', {
256
+ email_address: 'bob.loblaw@example.com',
257
+ })
258
+ .reply(200, {
259
+ id: 'auth_challenge_01E4ZCR3C56J083X43JQXF3JK5',
260
+ });
261
+ const response = yield workos.users.sendMagicAuthCode({
262
+ emailAddress: 'bob.loblaw@example.com',
263
+ });
264
+ expect(mock.history.post[0].url).toEqual('/users/magic_auth/send');
265
+ expect(response).toMatchObject({
266
+ id: 'auth_challenge_01E4ZCR3C56J083X43JQXF3JK5',
267
+ });
268
+ }));
269
+ });
223
270
  describe('createPasswordResetChallenge', () => {
224
271
  it('sends a Create Password Reset Challenge request', () => __awaiter(void 0, void 0, void 0, function* () {
225
272
  mock.onPost(`/users/password_reset_challenge`).reply(200, {
@@ -228,7 +275,7 @@ describe('UserManagement', () => {
228
275
  });
229
276
  const resp = yield workos.users.createPasswordResetChallenge({
230
277
  email: 'test01@example.com',
231
- password_reset_url: 'https://example.com/forgot-password',
278
+ passwordResetUrl: 'https://example.com/forgot-password',
232
279
  });
233
280
  expect(mock.history.post[0].url).toEqual(`/users/password_reset_challenge`);
234
281
  expect(resp).toMatchObject({
@@ -241,53 +288,90 @@ describe('UserManagement', () => {
241
288
  });
242
289
  describe('completePasswordReset', () => {
243
290
  it('sends a completePasswordReset request', () => __awaiter(void 0, void 0, void 0, function* () {
244
- mock.onPost(`/users/password_reset`).reply(200, {
245
- user: user_json_1.default,
246
- });
291
+ mock.onPost(`/users/password_reset`).reply(200, user_json_1.default);
247
292
  const resp = yield workos.users.completePasswordReset({
248
293
  token: '',
249
- new_password: 'correct horse battery staple',
294
+ newPassword: 'correct horse battery staple',
250
295
  });
251
296
  expect(mock.history.post[0].url).toEqual(`/users/password_reset`);
252
297
  expect(resp).toMatchObject({
253
- user: {
254
- email: 'test01@example.com',
255
- },
298
+ email: 'test01@example.com',
256
299
  });
257
300
  }));
258
301
  });
259
302
  describe('addUserToOrganization', () => {
260
303
  it('sends a addUserToOrganization request', () => __awaiter(void 0, void 0, void 0, function* () {
261
- mock.onPost(`/users/${userId}/organizations`).reply(200, {
262
- user: user_json_1.default,
263
- });
304
+ mock.onPost(`/users/${userId}/organizations`).reply(200, user_json_1.default);
264
305
  const resp = yield workos.users.addUserToOrganization({
265
- user_id: userId,
266
- organization_id: 'org_coolorg',
306
+ userId,
307
+ organizationId: 'org_coolorg',
267
308
  });
268
309
  expect(mock.history.post[0].url).toEqual(`/users/${userId}/organizations`);
269
310
  expect(resp).toMatchObject({
270
- user: {
271
- email: 'test01@example.com',
272
- },
311
+ email: 'test01@example.com',
273
312
  });
274
313
  }));
275
314
  });
276
315
  describe('removeUserFromOrganization', () => {
277
316
  it('sends a removeUserFromOrganization request', () => __awaiter(void 0, void 0, void 0, function* () {
278
317
  const orgId = 'org_coolorg';
279
- mock.onDelete(`/users/${userId}/organizations/${orgId}`).reply(200, {
280
- user: user_json_1.default,
281
- });
318
+ mock
319
+ .onDelete(`/users/${userId}/organizations/${orgId}`)
320
+ .reply(200, user_json_1.default);
282
321
  const resp = yield workos.users.removeUserFromOrganization({
283
- user_id: userId,
284
- organization_id: orgId,
322
+ userId,
323
+ organizationId: orgId,
285
324
  });
286
325
  expect(mock.history.delete[0].url).toEqual(`/users/${userId}/organizations/${orgId}`);
287
326
  expect(resp).toMatchObject({
288
- user: {
327
+ email: 'test01@example.com',
328
+ });
329
+ }));
330
+ });
331
+ describe('updateUser', () => {
332
+ it('sends a updateUser request', () => __awaiter(void 0, void 0, void 0, function* () {
333
+ mock.onPut(`/users/${userId}`).reply(200, user_json_1.default);
334
+ const resp = yield workos.users.updateUser({
335
+ userId,
336
+ firstName: 'Dane',
337
+ lastName: 'Williams',
338
+ });
339
+ expect(mock.history.put[0].url).toEqual(`/users/${userId}`);
340
+ expect(JSON.parse(mock.history.put[0].data)).toEqual({
341
+ first_name: 'Dane',
342
+ last_name: 'Williams',
343
+ });
344
+ expect(resp).toMatchObject({
345
+ email: 'test01@example.com',
346
+ });
347
+ }));
348
+ describe('when only one property is provided', () => {
349
+ it('sends a updateUser request', () => __awaiter(void 0, void 0, void 0, function* () {
350
+ mock.onPut(`/users/${userId}`).reply(200, user_json_1.default);
351
+ const resp = yield workos.users.updateUser({
352
+ userId,
353
+ firstName: 'Dane',
354
+ });
355
+ expect(mock.history.put[0].url).toEqual(`/users/${userId}`);
356
+ expect(JSON.parse(mock.history.put[0].data)).toEqual({
357
+ first_name: 'Dane',
358
+ });
359
+ expect(resp).toMatchObject({
289
360
  email: 'test01@example.com',
290
- },
361
+ });
362
+ }));
363
+ });
364
+ });
365
+ describe('updateUserPassword', () => {
366
+ it('sends a updateUserPassword request', () => __awaiter(void 0, void 0, void 0, function* () {
367
+ mock.onPut(`/users/${userId}/password`).reply(200, user_json_1.default);
368
+ const resp = yield workos.users.updateUserPassword({
369
+ userId,
370
+ password: 'secure',
371
+ });
372
+ expect(mock.history.put[0].url).toEqual(`/users/${userId}/password`);
373
+ expect(resp).toMatchObject({
374
+ email: 'test01@example.com',
291
375
  });
292
376
  }));
293
377
  });
@@ -1 +1,67 @@
1
- { "id": "wh_123", "data": { "id": "directory_user_01FAEAJCR3ZBZ30D8BD1924TVG", "state": "active", "emails": [{ "type": "work", "value": "blair@foo-corp.com", "primary": true }], "idp_id": "00u1e8mutl6wlH3lL4x7", "object": "directory_user", "username": "blair@foo-corp.com", "last_name": "Lunchford", "first_name": "Blair", "job_title": "Software Engineer", "directory_id": "directory_01F9M7F68PZP8QXP8G7X5QRHS7", "raw_attributes": { "name": { "givenName": "Blair", "familyName": "Lunchford", "middleName": "Elizabeth", "honorificPrefix": "Ms." }, "title": "Software Engineer", "active": true, "emails": [{ "type": "work", "value": "blair@foo-corp.com", "primary": true }], "groups": [], "locale": "en-US", "schemas": ["urn:ietf:params:scim:schemas:core:2.0:User", "urn:ietf:params:scim:schemas:extension:enterprise:2.0:User"], "userName": "blair@foo-corp.com", "addresses": [{ "region": "CA", "primary": true, "locality": "San Francisco", "postalCode": "94016" }], "externalId": "00u1e8mutl6wlH3lL4x7", "displayName": "Blair Lunchford", "urn:ietf:params:scim:schemas:extension:enterprise:2.0:User": { "manager": { "value": "2", "displayName": "Kate Chapman" }, "division": "Engineering", "department": "Customer Success" } } }, "event": "dsync.user.created" }
1
+ {
2
+ "id": "wh_123",
3
+ "data": {
4
+ "id": "directory_user_01FAEAJCR3ZBZ30D8BD1924TVG",
5
+ "state": "active",
6
+ "emails": [
7
+ {
8
+ "type": "work",
9
+ "value": "blair@foo-corp.com",
10
+ "primary": true
11
+ }
12
+ ],
13
+ "idp_id": "00u1e8mutl6wlH3lL4x7",
14
+ "object": "directory_user",
15
+ "username": "blair@foo-corp.com",
16
+ "last_name": "Lunchford",
17
+ "first_name": "Blair",
18
+ "job_title": "Software Engineer",
19
+ "directory_id": "directory_01F9M7F68PZP8QXP8G7X5QRHS7",
20
+ "created_at": "2021-06-25T19:07:33.155Z",
21
+ "updated_at": "2021-06-25T19:07:33.155Z",
22
+ "raw_attributes": {
23
+ "name": {
24
+ "givenName": "Blair",
25
+ "familyName": "Lunchford",
26
+ "middleName": "Elizabeth",
27
+ "honorificPrefix": "Ms."
28
+ },
29
+ "title": "Software Engineer",
30
+ "active": true,
31
+ "emails": [
32
+ {
33
+ "type": "work",
34
+ "value": "blair@foo-corp.com",
35
+ "primary": true
36
+ }
37
+ ],
38
+ "groups": [],
39
+ "locale": "en-US",
40
+ "schemas": [
41
+ "urn:ietf:params:scim:schemas:core:2.0:User",
42
+ "urn:ietf:params:scim:schemas:extension:enterprise:2.0:User"
43
+ ],
44
+ "userName": "blair@foo-corp.com",
45
+ "addresses": [
46
+ {
47
+ "region": "CA",
48
+ "primary": true,
49
+ "locality": "San Francisco",
50
+ "postalCode": "94016"
51
+ }
52
+ ],
53
+ "externalId": "00u1e8mutl6wlH3lL4x7",
54
+ "displayName": "Blair Lunchford",
55
+ "urn:ietf:params:scim:schemas:extension:enterprise:2.0:User": {
56
+ "manager": {
57
+ "value": "2",
58
+ "displayName": "Kate Chapman"
59
+ },
60
+ "division": "Engineering",
61
+ "department": "Customer Success"
62
+ }
63
+ }
64
+ },
65
+ "event": "dsync.user.created",
66
+ "created_at": "2021-06-25T19:07:33.155Z"
67
+ }
@@ -1,11 +1,11 @@
1
- import { Webhook } from './interfaces/webhook.interface';
1
+ import { Event } from '../common/interfaces';
2
2
  export declare class Webhooks {
3
3
  constructEvent({ payload, sigHeader, secret, tolerance, }: {
4
4
  payload: unknown;
5
5
  sigHeader: string;
6
6
  secret: string;
7
7
  tolerance?: number;
8
- }): Webhook;
8
+ }): Event;
9
9
  verifyHeader({ payload, sigHeader, secret, tolerance, }: {
10
10
  payload: any;
11
11
  sigHeader: string;
@@ -6,12 +6,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.Webhooks = void 0;
7
7
  const crypto_1 = __importDefault(require("crypto"));
8
8
  const exceptions_1 = require("../common/exceptions");
9
+ const serializers_1 = require("../common/serializers");
9
10
  class Webhooks {
10
11
  constructEvent({ payload, sigHeader, secret, tolerance = 180000, }) {
11
12
  const options = { payload, sigHeader, secret, tolerance };
12
13
  this.verifyHeader(options);
13
14
  const webhookPayload = payload;
14
- return webhookPayload;
15
+ return (0, serializers_1.deserializeEvent)(webhookPayload);
15
16
  }
16
17
  verifyHeader({ payload, sigHeader, secret, tolerance = 180000, }) {
17
18
  const [timestamp, signatureHash] = this.getTimestampAndSignatureHash(sigHeader);
@@ -35,14 +35,16 @@ describe('Webhooks', () => {
35
35
  primary: true,
36
36
  },
37
37
  ],
38
- idp_id: '00u1e8mutl6wlH3lL4x7',
38
+ idpId: '00u1e8mutl6wlH3lL4x7',
39
39
  object: 'directory_user',
40
40
  username: 'blair@foo-corp.com',
41
- last_name: 'Lunchford',
42
- first_name: 'Blair',
43
- job_title: 'Software Engineer',
44
- directory_id: 'directory_01F9M7F68PZP8QXP8G7X5QRHS7',
45
- raw_attributes: {
41
+ lastName: 'Lunchford',
42
+ firstName: 'Blair',
43
+ jobTitle: 'Software Engineer',
44
+ directoryId: 'directory_01F9M7F68PZP8QXP8G7X5QRHS7',
45
+ createdAt: '2021-06-25T19:07:33.155Z',
46
+ updatedAt: '2021-06-25T19:07:33.155Z',
47
+ rawAttributes: {
46
48
  name: {
47
49
  givenName: 'Blair',
48
50
  familyName: 'Lunchford',
package/lib/workos.d.ts CHANGED
@@ -28,10 +28,11 @@ export declare class WorkOS {
28
28
  readonly events: Events;
29
29
  readonly users: Users;
30
30
  constructor(key?: string | undefined, options?: WorkOSOptions);
31
- post(path: string, entity: any, options?: PostOptions): Promise<AxiosResponse>;
32
- get(path: string, options?: GetOptions): Promise<AxiosResponse>;
33
- put(path: string, entity: any, options?: PutOptions): Promise<AxiosResponse>;
34
- delete(path: string, query?: any): Promise<AxiosResponse>;
31
+ get version(): string;
32
+ post<T = any, D = any, P = any>(path: string, entity: P, options?: PostOptions): Promise<AxiosResponse<T, D>>;
33
+ get<T = any, D = any>(path: string, options?: GetOptions): Promise<AxiosResponse<T, D>>;
34
+ put<T = any, D = any>(path: string, entity: any, options?: PutOptions): Promise<AxiosResponse<T, D>>;
35
+ delete<T = any, D = any>(path: string, query?: any): Promise<AxiosResponse<T, D>>;
35
36
  emitWarning(warning: string): void;
36
37
  private handleAxiosError;
37
38
  }
package/lib/workos.js CHANGED
@@ -27,7 +27,7 @@ const mfa_1 = require("./mfa/mfa");
27
27
  const audit_logs_1 = require("./audit-logs/audit-logs");
28
28
  const users_1 = require("./users/users");
29
29
  const bad_request_exception_1 = require("./common/exceptions/bad-request.exception");
30
- const VERSION = '3.0.0-user-management.2';
30
+ const VERSION = '3.0.0';
31
31
  const DEFAULT_HOSTNAME = 'api.workos.com';
32
32
  class WorkOS {
33
33
  constructor(key, options = {}) {
@@ -63,6 +63,9 @@ class WorkOS {
63
63
  }
64
64
  this.client = axios_1.default.create(Object.assign(Object.assign({}, options.axios), { baseURL: this.baseURL, headers: Object.assign(Object.assign({}, (_a = options.axios) === null || _a === void 0 ? void 0 : _a.headers), { Authorization: `Bearer ${this.key}`, 'User-Agent': `workos-node/${VERSION}` }) }));
65
65
  }
66
+ get version() {
67
+ return VERSION;
68
+ }
66
69
  post(path, entity, options = {}) {
67
70
  return __awaiter(this, void 0, void 0, function* () {
68
71
  const requestHeaders = {};
@@ -14,8 +14,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  const axios_1 = __importDefault(require("axios"));
16
16
  const axios_mock_adapter_1 = __importDefault(require("axios-mock-adapter"));
17
- const workos_1 = require("./workos");
17
+ const promises_1 = __importDefault(require("fs/promises"));
18
18
  const exceptions_1 = require("./common/exceptions");
19
+ const workos_1 = require("./workos");
19
20
  const mock = new axios_mock_adapter_1.default(axios_1.default);
20
21
  describe('WorkOS', () => {
21
22
  describe('constructor', () => {
@@ -82,6 +83,15 @@ describe('WorkOS', () => {
82
83
  }));
83
84
  });
84
85
  });
86
+ describe('version', () => {
87
+ it('matches the version in `package.json`', () => __awaiter(void 0, void 0, void 0, function* () {
88
+ const workos = new workos_1.WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU');
89
+ // Read `package.json` using file I/O instead of `require` so we don't run
90
+ // into issues with the `require` cache.
91
+ const packageJson = JSON.parse(yield promises_1.default.readFile('package.json', 'utf8'));
92
+ expect(workos.version).toBe(packageJson.version);
93
+ }));
94
+ });
85
95
  describe('post', () => {
86
96
  describe('when the api responds with a 404', () => {
87
97
  it('throws a NotFoundException', () => __awaiter(void 0, void 0, void 0, function* () {
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "3.0.0-user-management.2",
2
+ "version": "3.0.0",
3
3
  "name": "@workos-inc/node",
4
4
  "author": "WorkOS",
5
5
  "description": "A Node wrapper for the WorkOS API",
@@ -9,7 +9,7 @@
9
9
  "workos"
10
10
  ],
11
11
  "volta": {
12
- "node": "14.21.2",
12
+ "node": "14.21.3",
13
13
  "yarn": "1.22.19"
14
14
  },
15
15
  "main": "lib/index.js",
@@ -34,20 +34,19 @@
34
34
  "prepublishOnly": "yarn run build"
35
35
  },
36
36
  "dependencies": {
37
- "axios": "0.21.4",
38
- "pluralize": "8.0.0",
39
- "query-string": "7.1.3"
37
+ "axios": "1.4.0",
38
+ "pluralize": "8.0.0"
40
39
  },
41
40
  "devDependencies": {
42
- "@types/jest": "27.5.2",
43
- "@types/node": "14.18.36",
44
- "@types/pluralize": "0.0.29",
45
- "axios-mock-adapter": "1.21.2",
46
- "jest": "27.5.1",
47
- "prettier": "2.8.3",
48
- "supertest": "6.2.3",
49
- "ts-jest": "27.1.5",
41
+ "@types/jest": "29.5.3",
42
+ "@types/node": "14.18.54",
43
+ "@types/pluralize": "0.0.30",
44
+ "axios-mock-adapter": "1.21.5",
45
+ "jest": "29.6.2",
46
+ "prettier": "2.8.8",
47
+ "supertest": "6.3.3",
48
+ "ts-jest": "29.1.1",
50
49
  "tslint": "6.1.3",
51
- "typescript": "4.9.5"
50
+ "typescript": "5.1.6"
52
51
  }
53
- }
52
+ }
@@ -1,10 +0,0 @@
1
- export interface Group {
2
- id: string;
3
- idp_id: string;
4
- directory_id: string;
5
- organization_id: string | null;
6
- name: string;
7
- created_at: string;
8
- updated_at: string;
9
- raw_attributes: any;
10
- }
@@ -1,23 +0,0 @@
1
- import { Group } from './group.interface';
2
- export type DefaultCustomAttributes = Record<string, unknown>;
3
- export interface User<TCustomAttributes extends object = DefaultCustomAttributes, TRawAttributes = any> {
4
- id: string;
5
- directory_id: string;
6
- organization_id: string | null;
7
- raw_attributes: TRawAttributes;
8
- custom_attributes: TCustomAttributes;
9
- idp_id: string;
10
- first_name: string;
11
- emails: {
12
- type: string;
13
- value: string;
14
- primary: boolean;
15
- }[];
16
- username: string;
17
- last_name: string;
18
- job_title: string | null;
19
- state: 'active' | 'inactive' | 'suspended';
20
- }
21
- export interface UserWithGroups<TCustomAttributes extends object = DefaultCustomAttributes> extends User<TCustomAttributes> {
22
- groups: Group[];
23
- }
@@ -1,63 +0,0 @@
1
- interface EventBase {
2
- id: string;
3
- created_at: string;
4
- }
5
- export interface ConnectionActivatedEvent extends EventBase {
6
- event: 'connection.activated';
7
- data: Record<string, unknown>;
8
- }
9
- export interface ConnectionDeactivatedEvent extends EventBase {
10
- event: 'connection.deactivated';
11
- data: Record<string, unknown>;
12
- }
13
- export interface ConnectionDeletedEvent extends EventBase {
14
- event: 'connection.deleted';
15
- data: Record<string, unknown>;
16
- }
17
- export interface DsyncActivatedEvent extends EventBase {
18
- event: 'dsync.activated';
19
- data: Record<string, unknown>;
20
- }
21
- export interface DsyncDeactivatedEvent extends EventBase {
22
- event: 'dsync.deactivated';
23
- data: Record<string, unknown>;
24
- }
25
- export interface DsyncDeletedEvent extends EventBase {
26
- event: 'dsync.deleted';
27
- data: Record<string, unknown>;
28
- }
29
- export interface DsyncGroupCreatedEvent extends EventBase {
30
- event: 'dsync.group.created';
31
- data: Record<string, unknown>;
32
- }
33
- export interface DsyncGroupDeletedEvent extends EventBase {
34
- event: 'dsync.group.deleted';
35
- data: Record<string, unknown>;
36
- }
37
- export interface DsyncGroupUpdatedEvent extends EventBase {
38
- event: 'dsync.group.updated';
39
- data: Record<string, unknown>;
40
- }
41
- export interface DsyncGroupUserAddedEvent extends EventBase {
42
- event: 'dsync.group.user_added';
43
- data: Record<string, unknown>;
44
- }
45
- export interface DsyncGroupUserRemovedEvent extends EventBase {
46
- event: 'dsync.group.user_removed';
47
- data: Record<string, unknown>;
48
- }
49
- export interface DsyncUserCreatedEvent extends EventBase {
50
- event: 'dsync.user.created';
51
- data: Record<string, unknown>;
52
- }
53
- export interface DsyncUserDeletedEvent extends EventBase {
54
- event: 'dsync.user.deleted';
55
- data: Record<string, unknown>;
56
- }
57
- export interface DsyncUserUpdatedEvent extends EventBase {
58
- event: 'dsync.user.updated';
59
- data: Record<string, unknown>;
60
- }
61
- export type Event = ConnectionActivatedEvent | ConnectionDeactivatedEvent | ConnectionDeletedEvent | DsyncActivatedEvent | DsyncDeactivatedEvent | DsyncDeletedEvent | DsyncGroupCreatedEvent | DsyncGroupUpdatedEvent | DsyncGroupDeletedEvent | DsyncGroupUserAddedEvent | DsyncGroupUserRemovedEvent | DsyncUserCreatedEvent | DsyncUserUpdatedEvent | DsyncUserDeletedEvent;
62
- export type EventNames = 'connection.activated' | 'connection.deactivated' | 'connection.deleted' | 'dsync.activated' | 'dsync.deactivated' | 'dsync.deleted' | 'dsync.group.created' | 'dsync.group.deleted' | 'dsync.group.updated' | 'dsync.group.user_added' | 'dsync.group.user_removed' | 'dsync.user.created' | 'dsync.user.deleted' | 'dsync.user.updated';
63
- export {};