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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (169) hide show
  1. package/lib/audit-logs/audit-logs.js +5 -4
  2. package/lib/audit-logs/audit-logs.spec.js +87 -87
  3. package/lib/audit-logs/interfaces/audit-log-export-options.interface.d.ts +13 -3
  4. package/lib/audit-logs/interfaces/audit-log-export.interface.d.ts +8 -0
  5. package/lib/audit-logs/interfaces/create-audit-log-event-options.interface.d.ts +13 -1
  6. package/lib/audit-logs/serializers/audit-log-export-options.serializer.d.ts +2 -0
  7. package/lib/audit-logs/serializers/audit-log-export-options.serializer.js +14 -0
  8. package/lib/audit-logs/serializers/audit-log-export.serializer.d.ts +2 -0
  9. package/lib/audit-logs/serializers/audit-log-export.serializer.js +12 -0
  10. package/lib/audit-logs/serializers/create-audit-log-event-options.serializer.d.ts +2 -0
  11. package/lib/audit-logs/serializers/create-audit-log-event-options.serializer.js +16 -0
  12. package/lib/audit-logs/serializers/index.d.ts +3 -0
  13. package/lib/audit-logs/serializers/index.js +19 -0
  14. package/lib/audit-trail/audit-trail.spec.js +2 -1
  15. package/lib/common/interfaces/index.d.ts +2 -0
  16. package/lib/common/interfaces/index.js +2 -0
  17. package/lib/common/interfaces/list.interface.d.ts +8 -0
  18. package/lib/common/interfaces/workos-response-error.interface.d.ts +8 -0
  19. package/lib/common/serializers/index.d.ts +1 -0
  20. package/lib/common/serializers/index.js +17 -0
  21. package/lib/common/serializers/list.serializer.d.ts +2 -0
  22. package/lib/common/serializers/list.serializer.js +9 -0
  23. package/lib/common/utils/workos-mock-response.d.ts +7 -0
  24. package/lib/common/utils/workos-mock-response.js +11 -0
  25. package/lib/directory-sync/directory-sync.d.ts +7 -12
  26. package/lib/directory-sync/directory-sync.js +8 -6
  27. package/lib/directory-sync/directory-sync.spec.js +95 -20
  28. package/lib/directory-sync/interfaces/directory-group.interface.d.ts +20 -0
  29. package/lib/directory-sync/interfaces/directory-user.interface.d.ts +48 -0
  30. package/lib/directory-sync/interfaces/directory.interface.d.ts +12 -0
  31. package/lib/directory-sync/interfaces/index.d.ts +6 -6
  32. package/lib/directory-sync/interfaces/index.js +20 -0
  33. package/lib/directory-sync/interfaces/list-directories-options.interface.d.ts +1 -1
  34. package/lib/directory-sync/interfaces/{list-users-options.interface.d.ts → list-directory-users-options.interface.d.ts} +1 -1
  35. package/lib/directory-sync/interfaces/list-directory-users-options.interface.js +2 -0
  36. package/lib/directory-sync/serializers/directory-group.serializer.d.ts +2 -0
  37. package/lib/directory-sync/serializers/directory-group.serializer.js +14 -0
  38. package/lib/directory-sync/serializers/directory-user.serializer.d.ts +3 -0
  39. package/lib/directory-sync/serializers/directory-user.serializer.js +23 -0
  40. package/lib/directory-sync/serializers/directory.serializer.d.ts +2 -0
  41. package/lib/directory-sync/serializers/directory.serializer.js +16 -0
  42. package/lib/directory-sync/serializers/index.d.ts +3 -0
  43. package/lib/directory-sync/serializers/index.js +19 -0
  44. package/lib/directory-sync/utils/get-primary-email.d.ts +2 -2
  45. package/lib/directory-sync/utils/get-primary-email.spec.js +10 -8
  46. package/lib/events/events.d.ts +3 -3
  47. package/lib/events/events.js +3 -1
  48. package/lib/events/events.spec.js +19 -3
  49. package/lib/events/interfaces/event.interface.d.ts +4 -1
  50. package/lib/events/serializers/event.serializer.d.ts +2 -0
  51. package/lib/events/serializers/event.serializer.js +10 -0
  52. package/lib/index.d.ts +1 -0
  53. package/lib/index.js +1 -0
  54. package/lib/mfa/interfaces/challenge.interface.d.ts +9 -0
  55. package/lib/mfa/interfaces/factor.interface.d.ts +13 -4
  56. package/lib/mfa/interfaces/index.d.ts +9 -0
  57. package/lib/mfa/interfaces/index.js +25 -0
  58. package/lib/mfa/interfaces/sms.interface.d.ts +3 -0
  59. package/lib/mfa/interfaces/totp.interface.d.ts +7 -0
  60. package/lib/mfa/interfaces/verify-challenge-response.d.ts +5 -1
  61. package/lib/mfa/mfa.d.ts +2 -8
  62. package/lib/mfa/mfa.js +5 -4
  63. package/lib/mfa/mfa.spec.js +134 -115
  64. package/lib/mfa/serializers/challenge.serializer.d.ts +2 -0
  65. package/lib/mfa/serializers/challenge.serializer.js +13 -0
  66. package/lib/mfa/serializers/factor.serializer.d.ts +2 -0
  67. package/lib/mfa/serializers/factor.serializer.js +7 -0
  68. package/lib/mfa/serializers/index.d.ts +3 -0
  69. package/lib/mfa/serializers/index.js +19 -0
  70. package/lib/mfa/serializers/sms.serializer.d.ts +2 -0
  71. package/lib/mfa/serializers/sms.serializer.js +7 -0
  72. package/lib/mfa/serializers/totp.serializer.d.ts +2 -0
  73. package/lib/mfa/serializers/totp.serializer.js +11 -0
  74. package/lib/mfa/serializers/verify-response.serializer.d.ts +2 -0
  75. package/lib/mfa/serializers/verify-response.serializer.js +9 -0
  76. package/lib/organizations/interfaces/create-organization-options.interface.d.ts +5 -0
  77. package/lib/organizations/interfaces/organization.interface.d.ts +9 -0
  78. package/lib/organizations/interfaces/update-organization-options.interface.d.ts +5 -0
  79. package/lib/organizations/organizations.d.ts +2 -2
  80. package/lib/organizations/organizations.js +8 -6
  81. package/lib/organizations/organizations.spec.js +4 -3
  82. package/lib/organizations/serializers/create-organization-options.serializer.d.ts +2 -0
  83. package/lib/organizations/serializers/create-organization-options.serializer.js +9 -0
  84. package/lib/organizations/serializers/index.d.ts +3 -0
  85. package/lib/organizations/serializers/index.js +19 -0
  86. package/lib/organizations/serializers/organization.serializer.d.ts +2 -0
  87. package/lib/organizations/serializers/organization.serializer.js +13 -0
  88. package/lib/organizations/serializers/update-organization-options.serializer.d.ts +2 -0
  89. package/lib/organizations/serializers/update-organization-options.serializer.js +9 -0
  90. package/lib/portal/interfaces/generate-portal-link-intent.interface.js +1 -1
  91. package/lib/sso/interfaces/connection-type.enum.d.ts +1 -0
  92. package/lib/sso/interfaces/connection-type.enum.js +2 -1
  93. package/lib/sso/interfaces/connection.interface.d.ts +1 -1
  94. package/lib/sso/sso.js +12 -5
  95. package/lib/sso/sso.spec.js +3 -3
  96. package/lib/users/exceptions/index.d.ts +4 -0
  97. package/lib/users/exceptions/index.js +10 -0
  98. package/lib/users/fixtures/list-users.json +21 -0
  99. package/lib/users/fixtures/session.json +6 -0
  100. package/lib/users/fixtures/user.json +12 -0
  101. package/lib/users/interfaces/add-user-to-organization-options.interface.d.ts +7 -0
  102. package/lib/users/interfaces/add-user-to-organization-options.interface.js +2 -0
  103. package/lib/users/interfaces/authenticate-user-with-password-options.interface.d.ts +16 -0
  104. package/lib/users/interfaces/authenticate-user-with-password-options.interface.js +2 -0
  105. package/lib/users/interfaces/authenticate-user-with-token-options.interface.d.ts +18 -0
  106. package/lib/users/interfaces/authenticate-user-with-token-options.interface.js +2 -0
  107. package/lib/users/interfaces/authentication-response.interface.d.ts +10 -0
  108. package/lib/users/interfaces/authentication-response.interface.js +2 -0
  109. package/lib/users/interfaces/complete-password-reset-options.interface.d.ts +8 -0
  110. package/lib/users/interfaces/complete-password-reset-options.interface.js +2 -0
  111. package/lib/users/interfaces/create-email-verification-challenge-options.interface.d.ts +16 -0
  112. package/lib/users/interfaces/create-email-verification-challenge-options.interface.js +2 -0
  113. package/lib/users/interfaces/create-password-reset-challenge-options.interface.d.ts +17 -0
  114. package/lib/users/interfaces/create-password-reset-challenge-options.interface.js +2 -0
  115. package/lib/users/interfaces/create-user-options.interface.d.ts +14 -0
  116. package/lib/users/interfaces/create-user-options.interface.js +2 -0
  117. package/lib/users/interfaces/index.d.ts +13 -0
  118. package/lib/users/interfaces/index.js +29 -0
  119. package/lib/users/interfaces/list-users-options.interface.d.ts +6 -0
  120. package/lib/users/interfaces/list-users-options.interface.js +2 -0
  121. package/lib/users/interfaces/remove-user-from-organization-options.interface.d.ts +4 -0
  122. package/lib/users/interfaces/remove-user-from-organization-options.interface.js +2 -0
  123. package/lib/users/interfaces/revoke-session-options.interface.d.ts +15 -0
  124. package/lib/users/interfaces/revoke-session-options.interface.js +2 -0
  125. package/lib/users/interfaces/session.interface.d.ts +12 -0
  126. package/lib/users/interfaces/session.interface.js +2 -0
  127. package/lib/users/interfaces/user.interface.d.ts +59 -0
  128. package/lib/users/interfaces/user.interface.js +2 -0
  129. package/lib/users/interfaces/verify-session.interface.d.ts +18 -0
  130. package/lib/users/interfaces/verify-session.interface.js +2 -0
  131. package/lib/users/serializers/authenticate-user-with-password-options.serializer.d.ts +2 -0
  132. package/lib/users/serializers/authenticate-user-with-password-options.serializer.js +12 -0
  133. package/lib/users/serializers/authenticate-user-with-token-options.serializer.d.ts +2 -0
  134. package/lib/users/serializers/authenticate-user-with-token-options.serializer.js +12 -0
  135. package/lib/users/serializers/authentication-response.serializer.d.ts +2 -0
  136. package/lib/users/serializers/authentication-response.serializer.js +12 -0
  137. package/lib/users/serializers/complete-password-reset-options.serializer.d.ts +2 -0
  138. package/lib/users/serializers/complete-password-reset-options.serializer.js +8 -0
  139. package/lib/users/serializers/create-email-verification-challenge.serializer.d.ts +2 -0
  140. package/lib/users/serializers/create-email-verification-challenge.serializer.js +9 -0
  141. package/lib/users/serializers/create-password-reset-challenge.serializer.d.ts +3 -0
  142. package/lib/users/serializers/create-password-reset-challenge.serializer.js +14 -0
  143. package/lib/users/serializers/create-user-options.serializer.d.ts +2 -0
  144. package/lib/users/serializers/create-user-options.serializer.js +11 -0
  145. package/lib/users/serializers/index.d.ts +11 -0
  146. package/lib/users/serializers/index.js +27 -0
  147. package/lib/users/serializers/revoke-session-options.serializer.d.ts +2 -0
  148. package/lib/users/serializers/revoke-session-options.serializer.js +14 -0
  149. package/lib/users/serializers/session.serializer.d.ts +2 -0
  150. package/lib/users/serializers/session.serializer.js +10 -0
  151. package/lib/users/serializers/user.serializer.d.ts +2 -0
  152. package/lib/users/serializers/user.serializer.js +31 -0
  153. package/lib/users/serializers/verify-session.serializer.d.ts +3 -0
  154. package/lib/users/serializers/verify-session.serializer.js +15 -0
  155. package/lib/users/users.d.ts +21 -0
  156. package/lib/users/users.js +112 -0
  157. package/lib/users/users.spec.d.ts +1 -0
  158. package/lib/users/users.spec.js +290 -0
  159. package/lib/webhooks/fixtures/webhook.json +1 -1
  160. package/lib/webhooks/interfaces/webhook-directory-user.interface.d.ts +2 -2
  161. package/lib/webhooks/interfaces/webhook.interface.d.ts +1 -0
  162. package/lib/workos.d.ts +6 -4
  163. package/lib/workos.js +3 -1
  164. package/package.json +13 -14
  165. package/lib/directory-sync/interfaces/group.interface.d.ts +0 -10
  166. package/lib/directory-sync/interfaces/user.interface.d.ts +0 -23
  167. /package/lib/{directory-sync/interfaces/group.interface.js → common/interfaces/workos-response-error.interface.js} +0 -0
  168. /package/lib/directory-sync/interfaces/{list-users-options.interface.js → directory-group.interface.js} +0 -0
  169. /package/lib/directory-sync/interfaces/{user.interface.js → directory-user.interface.js} +0 -0
@@ -0,0 +1,290 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ const axios_1 = __importDefault(require("axios"));
16
+ const axios_mock_adapter_1 = __importDefault(require("axios-mock-adapter"));
17
+ const workos_1 = require("../workos");
18
+ const user_json_1 = __importDefault(require("./fixtures/user.json"));
19
+ const list_users_json_1 = __importDefault(require("./fixtures/list-users.json"));
20
+ const session_json_1 = __importDefault(require("./fixtures/session.json"));
21
+ const mock = new axios_mock_adapter_1.default(axios_1.default);
22
+ const workos = new workos_1.WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU');
23
+ const userId = 'user_01H5JQDV7R7ATEYZDEG0W5PRYS';
24
+ describe('UserManagement', () => {
25
+ afterEach(() => mock.resetHistory());
26
+ describe('getUser', () => {
27
+ it('sends a Get User request', () => __awaiter(void 0, void 0, void 0, function* () {
28
+ mock.onGet(`/users/${userId}`).reply(200, user_json_1.default);
29
+ const user = yield workos.users.getUser(userId);
30
+ expect(mock.history.get[0].url).toEqual(`/users/${userId}`);
31
+ expect(user).toMatchObject({
32
+ object: 'user',
33
+ id: 'user_01H5JQDV7R7ATEYZDEG0W5PRYS',
34
+ email: 'test01@example.com',
35
+ firstName: 'Test 01',
36
+ lastName: 'User',
37
+ organizationMemberships: [],
38
+ userType: 'unmanaged',
39
+ emailVerifiedAt: '2023-07-17T20:07:20.055Z',
40
+ });
41
+ }));
42
+ });
43
+ describe('listUsers', () => {
44
+ it('lists users', () => __awaiter(void 0, void 0, void 0, function* () {
45
+ mock.onGet('/users').reply(200, list_users_json_1.default);
46
+ const userList = yield workos.users.listUsers();
47
+ expect(mock.history.get[0].url).toEqual('/users');
48
+ expect(userList).toMatchObject({
49
+ object: 'list',
50
+ data: [
51
+ {
52
+ object: 'user',
53
+ email: 'test01@example.com',
54
+ },
55
+ ],
56
+ listMetadata: {
57
+ before: null,
58
+ after: null,
59
+ },
60
+ });
61
+ }));
62
+ it('sends the correct params when filtering', () => __awaiter(void 0, void 0, void 0, function* () {
63
+ mock.onGet('/users').reply(200, list_users_json_1.default);
64
+ yield workos.users.listUsers({
65
+ email: 'foo@example.com',
66
+ organization: 'org_someorg',
67
+ type: 'managed',
68
+ after: 'user_01H5JQDV7R7ATEYZDEG0W5PRYS',
69
+ limit: 10,
70
+ });
71
+ expect(mock.history.get[0].params).toEqual({
72
+ email: 'foo@example.com',
73
+ organization: 'org_someorg',
74
+ type: 'managed',
75
+ after: 'user_01H5JQDV7R7ATEYZDEG0W5PRYS',
76
+ limit: 10,
77
+ });
78
+ }));
79
+ });
80
+ describe('createUser', () => {
81
+ it('sends a Create User request', () => __awaiter(void 0, void 0, void 0, function* () {
82
+ mock.onPost('/users').reply(200, user_json_1.default);
83
+ const user = yield workos.users.createUser({
84
+ email: 'test01@example.com',
85
+ password: 'extra-secure',
86
+ firstName: 'Test 01',
87
+ lastName: 'User',
88
+ emailVerified: true,
89
+ });
90
+ expect(mock.history.post[0].url).toEqual('/users');
91
+ expect(user).toMatchObject({
92
+ object: 'user',
93
+ email: 'test01@example.com',
94
+ firstName: 'Test 01',
95
+ lastName: 'User',
96
+ organizationMemberships: [],
97
+ userType: 'unmanaged',
98
+ emailVerifiedAt: '2023-07-17T20:07:20.055Z',
99
+ createdAt: '2023-07-18T02:07:19.911Z',
100
+ updatedAt: '2023-07-18T02:07:19.911Z',
101
+ });
102
+ }));
103
+ });
104
+ describe('authenticateUserWithPassword', () => {
105
+ it('sends an password authentication request', () => __awaiter(void 0, void 0, void 0, function* () {
106
+ mock.onPost('/users/authentications').reply(200, {
107
+ user: user_json_1.default,
108
+ session: session_json_1.default,
109
+ });
110
+ const resp = yield workos.users.authenticateUserWithPassword({
111
+ email: 'test01@example.com',
112
+ password: 'extra-secure',
113
+ });
114
+ expect(mock.history.post[0].url).toEqual('/users/authentications');
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
+ });
124
+ }));
125
+ });
126
+ describe('authenticateUserWithToken', () => {
127
+ it('sends a token authentication request', () => __awaiter(void 0, void 0, void 0, function* () {
128
+ mock
129
+ .onPost('/users/sessions/token')
130
+ .reply(200, { user: user_json_1.default, session: session_json_1.default });
131
+ const resp = yield workos.users.authenticateUserWithToken({
132
+ clientId: 'proj_whatever',
133
+ code: 'or this',
134
+ expiresIn: 15,
135
+ });
136
+ expect(mock.history.post[0].url).toEqual('/users/sessions/token');
137
+ expect(JSON.parse(mock.history.post[0].data)).toMatchObject({
138
+ client_secret: 'sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU',
139
+ grant_type: 'authorization_code',
140
+ });
141
+ expect(resp).toMatchObject({
142
+ user: {
143
+ email: 'test01@example.com',
144
+ },
145
+ session: {
146
+ id: 'session_01H5K05VP5CPCXJA5Z7G191GS4',
147
+ token: 'really-long-token',
148
+ },
149
+ });
150
+ }));
151
+ });
152
+ describe('verifySession', () => {
153
+ it('sends a request to verify the session', () => __awaiter(void 0, void 0, void 0, function* () {
154
+ mock.onPost('/users/sessions/verify').reply(200, {
155
+ user: user_json_1.default,
156
+ session: session_json_1.default,
157
+ });
158
+ const resp = yield workos.users.verifySession({
159
+ clientId: 'proj_something',
160
+ token: 'really-long-token',
161
+ });
162
+ expect(mock.history.post[0].url).toEqual('/users/sessions/verify');
163
+ expect(resp).toMatchObject({
164
+ user: {
165
+ email: 'test01@example.com',
166
+ },
167
+ session: {
168
+ id: 'session_01H5K05VP5CPCXJA5Z7G191GS4',
169
+ token: 'really-long-token',
170
+ },
171
+ });
172
+ }));
173
+ });
174
+ describe('revokeSession', () => {
175
+ it('can revoke with the session_id', () => __awaiter(void 0, void 0, void 0, function* () {
176
+ mock.onPost('/users/sessions/revocations').reply(200, true);
177
+ const revoked = yield workos.users.revokeSession({
178
+ sessionId: 'session_01H5K05VP5CPCXJA5Z7G191GS4',
179
+ });
180
+ expect(mock.history.post[0].url).toEqual('/users/sessions/revocations');
181
+ expect(revoked).toEqual(true);
182
+ }));
183
+ it('can revoke with the session_token', () => __awaiter(void 0, void 0, void 0, function* () {
184
+ mock.onPost('/users/sessions/revocations').reply(200, true);
185
+ const revoked = yield workos.users.revokeSession({
186
+ sessionToken: 'really-long-token',
187
+ });
188
+ expect(mock.history.post[0].url).toEqual('/users/sessions/revocations');
189
+ expect(revoked).toEqual(true);
190
+ }));
191
+ });
192
+ describe('revokeAllSessionsForUser', () => {
193
+ it('sends a revokeAllSessionsForUser request', () => __awaiter(void 0, void 0, void 0, function* () {
194
+ mock.onDelete(`/users/${userId}/sessions`).reply(200, true);
195
+ const revoked = yield workos.users.revokeAllSessionsForUser(userId);
196
+ expect(mock.history.delete[0].url).toEqual(`/users/${userId}/sessions`);
197
+ expect(revoked).toEqual(true);
198
+ }));
199
+ });
200
+ describe('createEmailVerificationChallenge', () => {
201
+ it('sends a Create Email Verification Challenge request', () => __awaiter(void 0, void 0, void 0, function* () {
202
+ mock.onPost(`/users/${userId}/email_verification_challenge`).reply(200, {
203
+ token: 'email-verification-challenge',
204
+ user: user_json_1.default,
205
+ });
206
+ const resp = yield workos.users.createEmailVerificationChallenge({
207
+ userId,
208
+ verificationUrl: 'https://example.com/verify-email',
209
+ });
210
+ expect(mock.history.post[0].url).toEqual(`/users/${userId}/email_verification_challenge`);
211
+ expect(resp).toMatchObject({
212
+ token: 'email-verification-challenge',
213
+ user: {
214
+ email: 'test01@example.com',
215
+ },
216
+ });
217
+ }));
218
+ describe('completeEmailVerification', () => {
219
+ it('sends a Complete Email Verification request', () => __awaiter(void 0, void 0, void 0, function* () {
220
+ mock.onPost(`/users/email_verification`).reply(200, user_json_1.default);
221
+ const resp = yield workos.users.completeEmailVerification('email-verification-token');
222
+ expect(mock.history.post[0].url).toEqual(`/users/email_verification`);
223
+ expect(resp).toMatchObject({
224
+ email: 'test01@example.com',
225
+ });
226
+ }));
227
+ });
228
+ });
229
+ describe('createPasswordResetChallenge', () => {
230
+ it('sends a Create Password Reset Challenge request', () => __awaiter(void 0, void 0, void 0, function* () {
231
+ mock.onPost(`/users/password_reset_challenge`).reply(200, {
232
+ token: 'password-reset-token',
233
+ user: user_json_1.default,
234
+ });
235
+ const resp = yield workos.users.createPasswordResetChallenge({
236
+ email: 'test01@example.com',
237
+ passwordResetUrl: 'https://example.com/forgot-password',
238
+ });
239
+ expect(mock.history.post[0].url).toEqual(`/users/password_reset_challenge`);
240
+ expect(resp).toMatchObject({
241
+ token: 'password-reset-token',
242
+ user: {
243
+ email: 'test01@example.com',
244
+ },
245
+ });
246
+ }));
247
+ });
248
+ describe('completePasswordReset', () => {
249
+ it('sends a completePasswordReset request', () => __awaiter(void 0, void 0, void 0, function* () {
250
+ mock.onPost(`/users/password_reset`).reply(200, user_json_1.default);
251
+ const resp = yield workos.users.completePasswordReset({
252
+ token: '',
253
+ newPassword: 'correct horse battery staple',
254
+ });
255
+ expect(mock.history.post[0].url).toEqual(`/users/password_reset`);
256
+ expect(resp).toMatchObject({
257
+ email: 'test01@example.com',
258
+ });
259
+ }));
260
+ });
261
+ describe('addUserToOrganization', () => {
262
+ it('sends a addUserToOrganization request', () => __awaiter(void 0, void 0, void 0, function* () {
263
+ mock.onPost(`/users/${userId}/organizations`).reply(200, user_json_1.default);
264
+ const resp = yield workos.users.addUserToOrganization({
265
+ userId,
266
+ organizationId: 'org_coolorg',
267
+ });
268
+ expect(mock.history.post[0].url).toEqual(`/users/${userId}/organizations`);
269
+ expect(resp).toMatchObject({
270
+ email: 'test01@example.com',
271
+ });
272
+ }));
273
+ });
274
+ describe('removeUserFromOrganization', () => {
275
+ it('sends a removeUserFromOrganization request', () => __awaiter(void 0, void 0, void 0, function* () {
276
+ const orgId = 'org_coolorg';
277
+ mock
278
+ .onDelete(`/users/${userId}/organizations/${orgId}`)
279
+ .reply(200, user_json_1.default);
280
+ const resp = yield workos.users.removeUserFromOrganization({
281
+ userId,
282
+ organizationId: orgId,
283
+ });
284
+ expect(mock.history.delete[0].url).toEqual(`/users/${userId}/organizations/${orgId}`);
285
+ expect(resp).toMatchObject({
286
+ email: 'test01@example.com',
287
+ });
288
+ }));
289
+ });
290
+ });
@@ -1 +1 @@
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
+ { "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", "created_at": "2021-06-25T19:07:33.155Z" }
@@ -1,5 +1,5 @@
1
- import { User } from '../../directory-sync/interfaces';
2
- export interface WebhookDirectoryUser extends User {
1
+ import { DirectoryUser } from '../../directory-sync/interfaces';
2
+ export interface WebhookDirectoryUser extends DirectoryUser {
3
3
  created_at: string;
4
4
  updated_at: string;
5
5
  }
@@ -4,6 +4,7 @@ import { WebhookDirectoryUser as User } from './webhook-directory-user.interface
4
4
  import { WebhookDirectory as Directory } from './webhook-directory.interface';
5
5
  interface WebhookBase {
6
6
  id: string;
7
+ created_at: string;
7
8
  }
8
9
  export interface ConnectionActivatedWebhook extends WebhookBase {
9
10
  event: 'connection.activated';
package/lib/workos.d.ts CHANGED
@@ -10,6 +10,7 @@ import { SSO } from './sso/sso';
10
10
  import { Webhooks } from './webhooks/webhooks';
11
11
  import { Mfa } from './mfa/mfa';
12
12
  import { AuditLogs } from './audit-logs/audit-logs';
13
+ import { Users } from './users/users';
13
14
  export declare class WorkOS {
14
15
  readonly key?: string | undefined;
15
16
  readonly options: WorkOSOptions;
@@ -25,11 +26,12 @@ export declare class WorkOS {
25
26
  readonly webhooks: Webhooks;
26
27
  readonly mfa: Mfa;
27
28
  readonly events: Events;
29
+ readonly users: Users;
28
30
  constructor(key?: string | undefined, options?: WorkOSOptions);
29
- post(path: string, entity: any, options?: PostOptions): Promise<AxiosResponse>;
30
- get(path: string, options?: GetOptions): Promise<AxiosResponse>;
31
- put(path: string, entity: any, options?: PutOptions): Promise<AxiosResponse>;
32
- delete(path: string, query?: any): Promise<AxiosResponse>;
31
+ post<T = any, D = any, P = any>(path: string, entity: P, options?: PostOptions): Promise<AxiosResponse<T, D>>;
32
+ get<T = any, D = any>(path: string, options?: GetOptions): Promise<AxiosResponse<T, D>>;
33
+ put<T = any, D = any>(path: string, entity: any, options?: PutOptions): Promise<AxiosResponse<T, D>>;
34
+ delete<T = any, D = any>(path: string, query?: any): Promise<AxiosResponse<T, D>>;
33
35
  emitWarning(warning: string): void;
34
36
  private handleAxiosError;
35
37
  }
package/lib/workos.js CHANGED
@@ -25,8 +25,9 @@ const sso_1 = require("./sso/sso");
25
25
  const webhooks_1 = require("./webhooks/webhooks");
26
26
  const mfa_1 = require("./mfa/mfa");
27
27
  const audit_logs_1 = require("./audit-logs/audit-logs");
28
+ const users_1 = require("./users/users");
28
29
  const bad_request_exception_1 = require("./common/exceptions/bad-request.exception");
29
- const VERSION = '2.19.0';
30
+ const VERSION = '3.0.0-alpha.1';
30
31
  const DEFAULT_HOSTNAME = 'api.workos.com';
31
32
  class WorkOS {
32
33
  constructor(key, options = {}) {
@@ -43,6 +44,7 @@ class WorkOS {
43
44
  this.webhooks = new webhooks_1.Webhooks();
44
45
  this.mfa = new mfa_1.Mfa(this);
45
46
  this.events = new events_1.Events(this);
47
+ this.users = new users_1.Users(this);
46
48
  if (!key) {
47
49
  this.key = process.env.WORKOS_API_KEY;
48
50
  if (!this.key) {
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "2.19.0",
2
+ "version": "3.0.0-alpha.1",
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
- }