@workos-inc/node 5.2.0 → 6.0.0-rc.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/audit-logs/audit-logs.spec.js +18 -4
- package/lib/common/interfaces/workos-options.interface.d.ts +1 -2
- package/lib/common/utils/fetch-client.d.ts +29 -0
- package/lib/common/utils/fetch-client.js +97 -0
- package/lib/common/utils/fetch-error.d.ts +13 -0
- package/lib/common/utils/fetch-error.js +13 -0
- package/lib/common/utils/test-utils.d.ts +8 -0
- package/lib/common/utils/test-utils.js +45 -0
- package/lib/directory-sync/directory-sync.spec.js +34 -45
- package/lib/events/events.spec.js +5 -6
- package/lib/mfa/mfa.spec.js +39 -42
- package/lib/organization-domains/organization-domains.spec.js +12 -24
- package/lib/organizations/organizations.spec.js +49 -74
- package/lib/passwordless/passwordless.spec.js +9 -16
- package/lib/portal/portal.spec.js +41 -47
- package/lib/sso/sso.spec.js +56 -100
- package/lib/user-management/user-management.spec.js +90 -123
- package/lib/webhooks/webhooks.d.ts +5 -5
- package/lib/webhooks/webhooks.js +64 -42
- package/lib/webhooks/webhooks.spec.js +40 -30
- package/lib/workos.d.ts +11 -6
- package/lib/workos.js +16 -19
- package/lib/workos.spec.js +17 -22
- package/package.json +3 -2
|
@@ -12,8 +12,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
const
|
|
16
|
-
const
|
|
15
|
+
const jest_fetch_mock_1 = __importDefault(require("jest-fetch-mock"));
|
|
16
|
+
const test_utils_1 = require("../common/utils/test-utils");
|
|
17
17
|
const workos_1 = require("../workos");
|
|
18
18
|
const user_json_1 = __importDefault(require("./fixtures/user.json"));
|
|
19
19
|
const list_users_json_1 = __importDefault(require("./fixtures/list-users.json"));
|
|
@@ -22,18 +22,17 @@ const organization_membership_json_1 = __importDefault(require("./fixtures/organ
|
|
|
22
22
|
const list_organization_memberships_json_1 = __importDefault(require("./fixtures/list-organization-memberships.json"));
|
|
23
23
|
const invitation_json_1 = __importDefault(require("./fixtures/invitation.json"));
|
|
24
24
|
const list_invitations_json_1 = __importDefault(require("./fixtures/list-invitations.json"));
|
|
25
|
-
const mock = new axios_mock_adapter_1.default(axios_1.default);
|
|
26
25
|
const workos = new workos_1.WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU');
|
|
27
26
|
const userId = 'user_01H5JQDV7R7ATEYZDEG0W5PRYS';
|
|
28
27
|
const organizationMembershipId = 'om_01H5JQDV7R7ATEYZDEG0W5PRYS';
|
|
29
28
|
const invitationId = 'invitation_01H5JQDV7R7ATEYZDEG0W5PRYS';
|
|
30
29
|
describe('UserManagement', () => {
|
|
31
|
-
|
|
30
|
+
beforeEach(() => jest_fetch_mock_1.default.resetMocks());
|
|
32
31
|
describe('getUser', () => {
|
|
33
32
|
it('sends a Get User request', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
34
|
-
|
|
33
|
+
(0, test_utils_1.fetchOnce)(user_json_1.default);
|
|
35
34
|
const user = yield workos.userManagement.getUser(userId);
|
|
36
|
-
expect(
|
|
35
|
+
expect((0, test_utils_1.fetchURL)()).toContain(`/user_management/users/${userId}`);
|
|
37
36
|
expect(user).toMatchObject({
|
|
38
37
|
object: 'user',
|
|
39
38
|
id: 'user_01H5JQDV7R7ATEYZDEG0W5PRYS',
|
|
@@ -47,9 +46,9 @@ describe('UserManagement', () => {
|
|
|
47
46
|
});
|
|
48
47
|
describe('listUsers', () => {
|
|
49
48
|
it('lists users', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
50
|
-
|
|
49
|
+
(0, test_utils_1.fetchOnce)(list_users_json_1.default);
|
|
51
50
|
const userList = yield workos.userManagement.listUsers();
|
|
52
|
-
expect(
|
|
51
|
+
expect((0, test_utils_1.fetchURL)()).toContain('/user_management/users');
|
|
53
52
|
expect(userList).toMatchObject({
|
|
54
53
|
object: 'list',
|
|
55
54
|
data: [
|
|
@@ -65,25 +64,25 @@ describe('UserManagement', () => {
|
|
|
65
64
|
});
|
|
66
65
|
}));
|
|
67
66
|
it('sends the correct params when filtering', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
68
|
-
|
|
67
|
+
(0, test_utils_1.fetchOnce)(list_users_json_1.default);
|
|
69
68
|
yield workos.userManagement.listUsers({
|
|
70
69
|
email: 'foo@example.com',
|
|
71
70
|
organizationId: 'org_someorg',
|
|
72
71
|
after: 'user_01H5JQDV7R7ATEYZDEG0W5PRYS',
|
|
73
72
|
limit: 10,
|
|
74
73
|
});
|
|
75
|
-
expect(
|
|
74
|
+
expect((0, test_utils_1.fetchSearchParams)()).toEqual({
|
|
76
75
|
email: 'foo@example.com',
|
|
77
76
|
organization_id: 'org_someorg',
|
|
78
77
|
after: 'user_01H5JQDV7R7ATEYZDEG0W5PRYS',
|
|
79
|
-
limit: 10,
|
|
78
|
+
limit: '10',
|
|
80
79
|
order: 'desc',
|
|
81
80
|
});
|
|
82
81
|
}));
|
|
83
82
|
});
|
|
84
83
|
describe('createUser', () => {
|
|
85
84
|
it('sends a Create User request', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
86
|
-
|
|
85
|
+
(0, test_utils_1.fetchOnce)(user_json_1.default);
|
|
87
86
|
const user = yield workos.userManagement.createUser({
|
|
88
87
|
email: 'test01@example.com',
|
|
89
88
|
password: 'extra-secure',
|
|
@@ -91,7 +90,7 @@ describe('UserManagement', () => {
|
|
|
91
90
|
lastName: 'User',
|
|
92
91
|
emailVerified: true,
|
|
93
92
|
});
|
|
94
|
-
expect(
|
|
93
|
+
expect((0, test_utils_1.fetchURL)()).toContain('/user_management/users');
|
|
95
94
|
expect(user).toMatchObject({
|
|
96
95
|
object: 'user',
|
|
97
96
|
email: 'test01@example.com',
|
|
@@ -106,15 +105,13 @@ describe('UserManagement', () => {
|
|
|
106
105
|
});
|
|
107
106
|
describe('authenticateUserWithMagicAuth', () => {
|
|
108
107
|
it('sends a magic auth authentication request', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
109
|
-
|
|
110
|
-
user: user_json_1.default,
|
|
111
|
-
});
|
|
108
|
+
(0, test_utils_1.fetchOnce)({ user: user_json_1.default });
|
|
112
109
|
const resp = yield workos.userManagement.authenticateWithMagicAuth({
|
|
113
110
|
clientId: 'proj_whatever',
|
|
114
111
|
code: '123456',
|
|
115
112
|
email: user_json_1.default.email,
|
|
116
113
|
});
|
|
117
|
-
expect(
|
|
114
|
+
expect((0, test_utils_1.fetchURL)()).toContain('/user_management/authenticate');
|
|
118
115
|
expect(resp).toMatchObject({
|
|
119
116
|
user: {
|
|
120
117
|
email: 'test01@example.com',
|
|
@@ -124,15 +121,13 @@ describe('UserManagement', () => {
|
|
|
124
121
|
});
|
|
125
122
|
describe('authenticateUserWithPassword', () => {
|
|
126
123
|
it('sends an password authentication request', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
127
|
-
|
|
128
|
-
user: user_json_1.default,
|
|
129
|
-
});
|
|
124
|
+
(0, test_utils_1.fetchOnce)({ user: user_json_1.default });
|
|
130
125
|
const resp = yield workos.userManagement.authenticateWithPassword({
|
|
131
126
|
clientId: 'proj_whatever',
|
|
132
127
|
email: 'test01@example.com',
|
|
133
128
|
password: 'extra-secure',
|
|
134
129
|
});
|
|
135
|
-
expect(
|
|
130
|
+
expect((0, test_utils_1.fetchURL)()).toContain('/user_management/authenticate');
|
|
136
131
|
expect(resp).toMatchObject({
|
|
137
132
|
user: {
|
|
138
133
|
email: 'test01@example.com',
|
|
@@ -142,16 +137,16 @@ describe('UserManagement', () => {
|
|
|
142
137
|
});
|
|
143
138
|
describe('authenticateUserWithCode', () => {
|
|
144
139
|
it('sends a token authentication request', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
145
|
-
|
|
146
|
-
.onPost('/user_management/authenticate')
|
|
147
|
-
.reply(200, { user: user_json_1.default });
|
|
140
|
+
(0, test_utils_1.fetchOnce)({ user: user_json_1.default });
|
|
148
141
|
const resp = yield workos.userManagement.authenticateWithCode({
|
|
149
142
|
clientId: 'proj_whatever',
|
|
150
143
|
code: 'or this',
|
|
151
144
|
});
|
|
152
|
-
expect(
|
|
153
|
-
expect(
|
|
145
|
+
expect((0, test_utils_1.fetchURL)()).toContain('/user_management/authenticate');
|
|
146
|
+
expect((0, test_utils_1.fetchBody)()).toEqual({
|
|
147
|
+
client_id: 'proj_whatever',
|
|
154
148
|
client_secret: 'sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU',
|
|
149
|
+
code: 'or this',
|
|
155
150
|
grant_type: 'authorization_code',
|
|
156
151
|
});
|
|
157
152
|
expect(resp).toMatchObject({
|
|
@@ -163,17 +158,15 @@ describe('UserManagement', () => {
|
|
|
163
158
|
});
|
|
164
159
|
describe('authenticateUserWithTotp', () => {
|
|
165
160
|
it('sends a token authentication request', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
166
|
-
|
|
167
|
-
.onPost('/user_management/authenticate')
|
|
168
|
-
.reply(200, { user: user_json_1.default });
|
|
161
|
+
(0, test_utils_1.fetchOnce)({ user: user_json_1.default });
|
|
169
162
|
const resp = yield workos.userManagement.authenticateWithTotp({
|
|
170
163
|
clientId: 'proj_whatever',
|
|
171
164
|
code: 'or this',
|
|
172
165
|
authenticationChallengeId: 'auth_challenge_01H96FETXGTW1QMBSBT2T36PW0',
|
|
173
166
|
pendingAuthenticationToken: 'cTDQJTTkTkkVYxQUlKBIxEsFs',
|
|
174
167
|
});
|
|
175
|
-
expect(
|
|
176
|
-
expect(
|
|
168
|
+
expect((0, test_utils_1.fetchURL)()).toContain('/user_management/authenticate');
|
|
169
|
+
expect((0, test_utils_1.fetchBody)()).toEqual({
|
|
177
170
|
client_id: 'proj_whatever',
|
|
178
171
|
code: 'or this',
|
|
179
172
|
client_secret: 'sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU',
|
|
@@ -190,16 +183,14 @@ describe('UserManagement', () => {
|
|
|
190
183
|
});
|
|
191
184
|
describe('authenticateUserWithEmailVerification', () => {
|
|
192
185
|
it('sends an email verification authentication request', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
193
|
-
|
|
194
|
-
.onPost('/user_management/authenticate')
|
|
195
|
-
.reply(200, { user: user_json_1.default });
|
|
186
|
+
(0, test_utils_1.fetchOnce)({ user: user_json_1.default });
|
|
196
187
|
const resp = yield workos.userManagement.authenticateWithEmailVerification({
|
|
197
188
|
clientId: 'proj_whatever',
|
|
198
189
|
code: 'or this',
|
|
199
190
|
pendingAuthenticationToken: 'cTDQJTTkTkkVYxQUlKBIxEsFs',
|
|
200
191
|
});
|
|
201
|
-
expect(
|
|
202
|
-
expect(
|
|
192
|
+
expect((0, test_utils_1.fetchURL)()).toContain('/user_management/authenticate');
|
|
193
|
+
expect((0, test_utils_1.fetchBody)()).toEqual({
|
|
203
194
|
client_id: 'proj_whatever',
|
|
204
195
|
code: 'or this',
|
|
205
196
|
client_secret: 'sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU',
|
|
@@ -215,16 +206,14 @@ describe('UserManagement', () => {
|
|
|
215
206
|
});
|
|
216
207
|
describe('authenticateWithOrganizationSelection', () => {
|
|
217
208
|
it('sends an Organization Selection Authentication request', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
218
|
-
|
|
219
|
-
.onPost('/user_management/authenticate')
|
|
220
|
-
.reply(200, { user: user_json_1.default });
|
|
209
|
+
(0, test_utils_1.fetchOnce)({ user: user_json_1.default });
|
|
221
210
|
const resp = yield workos.userManagement.authenticateWithOrganizationSelection({
|
|
222
211
|
clientId: 'proj_whatever',
|
|
223
212
|
pendingAuthenticationToken: 'cTDQJTTkTkkVYxQUlKBIxEsFs',
|
|
224
213
|
organizationId: 'org_01H5JQDV7R7ATEYZDEG0W5PRYS',
|
|
225
214
|
});
|
|
226
|
-
expect(
|
|
227
|
-
expect(
|
|
215
|
+
expect((0, test_utils_1.fetchURL)()).toContain('/user_management/authenticate');
|
|
216
|
+
expect((0, test_utils_1.fetchBody)()).toEqual({
|
|
228
217
|
client_id: 'proj_whatever',
|
|
229
218
|
client_secret: 'sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU',
|
|
230
219
|
grant_type: 'urn:workos:oauth:grant-type:organization-selection',
|
|
@@ -240,13 +229,11 @@ describe('UserManagement', () => {
|
|
|
240
229
|
});
|
|
241
230
|
describe('sendVerificationEmail', () => {
|
|
242
231
|
it('sends a Create Email Verification Challenge request', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
243
|
-
|
|
244
|
-
.onPost(`/user_management/users/${userId}/email_verification/send`)
|
|
245
|
-
.reply(200, { user: user_json_1.default });
|
|
232
|
+
(0, test_utils_1.fetchOnce)({ user: user_json_1.default });
|
|
246
233
|
const resp = yield workos.userManagement.sendVerificationEmail({
|
|
247
234
|
userId,
|
|
248
235
|
});
|
|
249
|
-
expect(
|
|
236
|
+
expect((0, test_utils_1.fetchURL)()).toContain(`/user_management/users/${userId}/email_verification/send`);
|
|
250
237
|
expect(resp).toMatchObject({
|
|
251
238
|
user: {
|
|
252
239
|
createdAt: '2023-07-18T02:07:19.911Z',
|
|
@@ -262,14 +249,12 @@ describe('UserManagement', () => {
|
|
|
262
249
|
}));
|
|
263
250
|
describe('verifyEmail', () => {
|
|
264
251
|
it('sends a Complete Email Verification request', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
265
|
-
|
|
266
|
-
.onPost(`/user_management/users/${userId}/email_verification/confirm`)
|
|
267
|
-
.reply(200, { user: user_json_1.default });
|
|
252
|
+
(0, test_utils_1.fetchOnce)({ user: user_json_1.default });
|
|
268
253
|
const resp = yield workos.userManagement.verifyEmail({
|
|
269
254
|
userId,
|
|
270
255
|
code: '123456',
|
|
271
256
|
});
|
|
272
|
-
expect(
|
|
257
|
+
expect((0, test_utils_1.fetchURL)()).toContain(`/user_management/users/${userId}/email_verification/confirm`);
|
|
273
258
|
expect(resp.user).toMatchObject({
|
|
274
259
|
email: 'test01@example.com',
|
|
275
260
|
});
|
|
@@ -278,39 +263,36 @@ describe('UserManagement', () => {
|
|
|
278
263
|
});
|
|
279
264
|
describe('sendMagicAuthCode', () => {
|
|
280
265
|
it('sends a Send Magic Auth Code request', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
281
|
-
|
|
282
|
-
.onPost('/user_management/magic_auth/send', {
|
|
283
|
-
email: 'bob.loblaw@example.com',
|
|
284
|
-
})
|
|
285
|
-
.reply(200);
|
|
266
|
+
(0, test_utils_1.fetchOnce)();
|
|
286
267
|
const response = yield workos.userManagement.sendMagicAuthCode({
|
|
287
268
|
email: 'bob.loblaw@example.com',
|
|
288
269
|
});
|
|
289
|
-
expect(
|
|
270
|
+
expect((0, test_utils_1.fetchURL)()).toContain('/user_management/magic_auth/send');
|
|
271
|
+
expect((0, test_utils_1.fetchBody)()).toEqual({
|
|
272
|
+
email: 'bob.loblaw@example.com',
|
|
273
|
+
});
|
|
290
274
|
expect(response).toBeUndefined();
|
|
291
275
|
}));
|
|
292
276
|
});
|
|
293
277
|
describe('sendPasswordResetEmail', () => {
|
|
294
278
|
it('sends a Send Password Reset Email request', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
295
|
-
|
|
279
|
+
(0, test_utils_1.fetchOnce)();
|
|
296
280
|
const resp = yield workos.userManagement.sendPasswordResetEmail({
|
|
297
281
|
email: 'test01@example.com',
|
|
298
282
|
passwordResetUrl: 'https://example.com/forgot-password',
|
|
299
283
|
});
|
|
300
|
-
expect(
|
|
284
|
+
expect((0, test_utils_1.fetchURL)()).toContain(`/user_management/password_reset/send`);
|
|
301
285
|
expect(resp).toBeUndefined();
|
|
302
286
|
}));
|
|
303
287
|
});
|
|
304
288
|
describe('resetPassword', () => {
|
|
305
289
|
it('sends a Reset Password request', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
306
|
-
|
|
307
|
-
.onPost(`/user_management/password_reset/confirm`)
|
|
308
|
-
.reply(200, { user: user_json_1.default });
|
|
290
|
+
(0, test_utils_1.fetchOnce)({ user: user_json_1.default });
|
|
309
291
|
const resp = yield workos.userManagement.resetPassword({
|
|
310
292
|
token: '',
|
|
311
293
|
newPassword: 'correct horse battery staple',
|
|
312
294
|
});
|
|
313
|
-
expect(
|
|
295
|
+
expect((0, test_utils_1.fetchURL)()).toContain(`/user_management/password_reset/confirm`);
|
|
314
296
|
expect(resp.user).toMatchObject({
|
|
315
297
|
email: 'test01@example.com',
|
|
316
298
|
});
|
|
@@ -318,15 +300,15 @@ describe('UserManagement', () => {
|
|
|
318
300
|
});
|
|
319
301
|
describe('updateUser', () => {
|
|
320
302
|
it('sends a updateUser request', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
321
|
-
|
|
303
|
+
(0, test_utils_1.fetchOnce)(user_json_1.default);
|
|
322
304
|
const resp = yield workos.userManagement.updateUser({
|
|
323
305
|
userId,
|
|
324
306
|
firstName: 'Dane',
|
|
325
307
|
lastName: 'Williams',
|
|
326
308
|
emailVerified: true,
|
|
327
309
|
});
|
|
328
|
-
expect(
|
|
329
|
-
expect(
|
|
310
|
+
expect((0, test_utils_1.fetchURL)()).toContain(`/user_management/users/${userId}`);
|
|
311
|
+
expect((0, test_utils_1.fetchBody)()).toEqual({
|
|
330
312
|
first_name: 'Dane',
|
|
331
313
|
last_name: 'Williams',
|
|
332
314
|
email_verified: true,
|
|
@@ -338,13 +320,13 @@ describe('UserManagement', () => {
|
|
|
338
320
|
}));
|
|
339
321
|
describe('when only one property is provided', () => {
|
|
340
322
|
it('sends a updateUser request', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
341
|
-
|
|
323
|
+
(0, test_utils_1.fetchOnce)(user_json_1.default);
|
|
342
324
|
const resp = yield workos.userManagement.updateUser({
|
|
343
325
|
userId,
|
|
344
326
|
firstName: 'Dane',
|
|
345
327
|
});
|
|
346
|
-
expect(
|
|
347
|
-
expect(
|
|
328
|
+
expect((0, test_utils_1.fetchURL)()).toContain(`/user_management/users/${userId}`);
|
|
329
|
+
expect((0, test_utils_1.fetchBody)()).toEqual({
|
|
348
330
|
first_name: 'Dane',
|
|
349
331
|
});
|
|
350
332
|
expect(resp).toMatchObject({
|
|
@@ -356,7 +338,7 @@ describe('UserManagement', () => {
|
|
|
356
338
|
});
|
|
357
339
|
describe('enrollAuthFactor', () => {
|
|
358
340
|
it('sends an enrollAuthFactor request', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
359
|
-
|
|
341
|
+
(0, test_utils_1.fetchOnce)({
|
|
360
342
|
authentication_factor: {
|
|
361
343
|
object: 'authentication_factor',
|
|
362
344
|
id: 'auth_factor_1234',
|
|
@@ -387,7 +369,7 @@ describe('UserManagement', () => {
|
|
|
387
369
|
totpIssuer: 'WorkOS',
|
|
388
370
|
totpUser: 'some_user',
|
|
389
371
|
});
|
|
390
|
-
expect(
|
|
372
|
+
expect((0, test_utils_1.fetchURL)()).toContain(`/user_management/users/${userId}/auth_factors`);
|
|
391
373
|
expect(resp).toMatchObject({
|
|
392
374
|
authenticationFactor: {
|
|
393
375
|
object: 'authentication_factor',
|
|
@@ -417,11 +399,9 @@ describe('UserManagement', () => {
|
|
|
417
399
|
});
|
|
418
400
|
describe('listAuthFactors', () => {
|
|
419
401
|
it('sends a listAuthFactors request', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
420
|
-
|
|
421
|
-
.onGet(`/user_management/users/${userId}/auth_factors`)
|
|
422
|
-
.reply(200, list_factors_json_1.default);
|
|
402
|
+
(0, test_utils_1.fetchOnce)(list_factors_json_1.default);
|
|
423
403
|
const resp = yield workos.userManagement.listAuthFactors({ userId });
|
|
424
|
-
expect(
|
|
404
|
+
expect((0, test_utils_1.fetchURL)()).toContain(`/user_management/users/${userId}/auth_factors`);
|
|
425
405
|
expect(resp).toMatchObject({
|
|
426
406
|
object: 'list',
|
|
427
407
|
data: [
|
|
@@ -446,19 +426,19 @@ describe('UserManagement', () => {
|
|
|
446
426
|
});
|
|
447
427
|
describe('deleteUser', () => {
|
|
448
428
|
it('sends a deleteUser request', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
449
|
-
|
|
429
|
+
(0, test_utils_1.fetchOnce)();
|
|
450
430
|
const resp = yield workos.userManagement.deleteUser(userId);
|
|
451
|
-
expect(
|
|
431
|
+
expect((0, test_utils_1.fetchURL)()).toContain(`/user_management/users/${userId}`);
|
|
452
432
|
expect(resp).toBeUndefined();
|
|
453
433
|
}));
|
|
454
434
|
});
|
|
455
435
|
describe('getOrganizationMembership', () => {
|
|
456
436
|
it('sends a Get OrganizationMembership request', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
437
|
+
(0, test_utils_1.fetchOnce)(organization_membership_json_1.default, {
|
|
438
|
+
status: 200,
|
|
439
|
+
});
|
|
460
440
|
const organizationMembership = yield workos.userManagement.getOrganizationMembership(organizationMembershipId);
|
|
461
|
-
expect(
|
|
441
|
+
expect((0, test_utils_1.fetchURL)()).toContain(`/user_management/organization_memberships/${organizationMembershipId}`);
|
|
462
442
|
expect(organizationMembership).toMatchObject({
|
|
463
443
|
object: 'organization_membership',
|
|
464
444
|
id: 'om_01H5JQDV7R7ATEYZDEG0W5PRYS',
|
|
@@ -469,14 +449,14 @@ describe('UserManagement', () => {
|
|
|
469
449
|
});
|
|
470
450
|
describe('listOrganizationMemberships', () => {
|
|
471
451
|
it('lists organization memberships', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
452
|
+
(0, test_utils_1.fetchOnce)(list_organization_memberships_json_1.default, {
|
|
453
|
+
status: 200,
|
|
454
|
+
});
|
|
475
455
|
const organizationMembershipsList = yield workos.userManagement.listOrganizationMemberships({
|
|
476
456
|
organizationId: 'organization_01H5JQDV7R7ATEYZDEG0W5PRYS',
|
|
477
457
|
userId: 'user_01H5JQDV7R7ATEYZDEG0W5PRYS',
|
|
478
458
|
});
|
|
479
|
-
expect(
|
|
459
|
+
expect((0, test_utils_1.fetchURL)()).toContain('/user_management/organization_memberships');
|
|
480
460
|
expect(organizationMembershipsList).toMatchObject({
|
|
481
461
|
object: 'list',
|
|
482
462
|
data: [
|
|
@@ -493,35 +473,34 @@ describe('UserManagement', () => {
|
|
|
493
473
|
});
|
|
494
474
|
}));
|
|
495
475
|
it('sends the correct params when filtering', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
476
|
+
(0, test_utils_1.fetchOnce)(list_organization_memberships_json_1.default, {
|
|
477
|
+
status: 200,
|
|
478
|
+
});
|
|
499
479
|
yield workos.userManagement.listOrganizationMemberships({
|
|
500
480
|
userId: 'user_someuser',
|
|
501
481
|
organizationId: 'org_someorg',
|
|
502
482
|
after: 'user_01H5JQDV7R7ATEYZDEG0W5PRYS',
|
|
503
483
|
limit: 10,
|
|
504
484
|
});
|
|
505
|
-
expect(
|
|
485
|
+
expect((0, test_utils_1.fetchSearchParams)()).toEqual({
|
|
506
486
|
user_id: 'user_someuser',
|
|
507
487
|
organization_id: 'org_someorg',
|
|
508
|
-
before: undefined,
|
|
509
488
|
after: 'user_01H5JQDV7R7ATEYZDEG0W5PRYS',
|
|
510
|
-
limit: 10,
|
|
489
|
+
limit: '10',
|
|
511
490
|
order: 'desc',
|
|
512
491
|
});
|
|
513
492
|
}));
|
|
514
493
|
});
|
|
515
494
|
describe('createOrganizationMembership', () => {
|
|
516
495
|
it('sends a create organization membership request', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
496
|
+
(0, test_utils_1.fetchOnce)(organization_membership_json_1.default, {
|
|
497
|
+
status: 200,
|
|
498
|
+
});
|
|
520
499
|
const organizationMembership = yield workos.userManagement.createOrganizationMembership({
|
|
521
500
|
organizationId: 'org_01H5JQDV7R7ATEYZDEG0W5PRYS',
|
|
522
501
|
userId: 'user_01H5JQDV7R7ATEYZDEG0W5PRYS',
|
|
523
502
|
});
|
|
524
|
-
expect(
|
|
503
|
+
expect((0, test_utils_1.fetchURL)()).toContain('/user_management/organization_memberships');
|
|
525
504
|
expect(organizationMembership).toMatchObject({
|
|
526
505
|
object: 'organization_membership',
|
|
527
506
|
organizationId: 'organization_01H5JQDV7R7ATEYZDEG0W5PRYS',
|
|
@@ -531,34 +510,28 @@ describe('UserManagement', () => {
|
|
|
531
510
|
});
|
|
532
511
|
describe('deleteOrganizationMembership', () => {
|
|
533
512
|
it('sends a deleteOrganizationMembership request', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
534
|
-
|
|
535
|
-
.onDelete(`/user_management/organization_memberships/${organizationMembershipId}`)
|
|
536
|
-
.reply(200);
|
|
513
|
+
(0, test_utils_1.fetchOnce)();
|
|
537
514
|
const resp = yield workos.userManagement.deleteOrganizationMembership(organizationMembershipId);
|
|
538
|
-
expect(
|
|
515
|
+
expect((0, test_utils_1.fetchURL)()).toContain(`/user_management/organization_memberships/${organizationMembershipId}`);
|
|
539
516
|
expect(resp).toBeUndefined();
|
|
540
517
|
}));
|
|
541
518
|
});
|
|
542
519
|
describe('getInvitation', () => {
|
|
543
520
|
it('sends a Get Invitation request', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
544
|
-
|
|
545
|
-
.onGet(`/user_management/invitations/${invitationId}`)
|
|
546
|
-
.reply(200, invitation_json_1.default);
|
|
521
|
+
(0, test_utils_1.fetchOnce)(invitation_json_1.default);
|
|
547
522
|
const invitation = yield workos.userManagement.getInvitation(invitationId);
|
|
548
|
-
expect(
|
|
523
|
+
expect((0, test_utils_1.fetchURL)()).toContain(`/user_management/invitations/${invitationId}`);
|
|
549
524
|
expect(invitation).toMatchObject({});
|
|
550
525
|
}));
|
|
551
526
|
});
|
|
552
527
|
describe('listInvitations', () => {
|
|
553
528
|
it('lists invitations', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
554
|
-
|
|
555
|
-
.onGet('/user_management/invitations')
|
|
556
|
-
.reply(200, list_invitations_json_1.default);
|
|
529
|
+
(0, test_utils_1.fetchOnce)(list_invitations_json_1.default);
|
|
557
530
|
const invitationsList = yield workos.userManagement.listInvitations({
|
|
558
531
|
organizationId: 'org_01H5JQDV7R7ATEYZDEG0W5PRYS',
|
|
559
532
|
email: 'dane@workos.com',
|
|
560
533
|
});
|
|
561
|
-
expect(
|
|
534
|
+
expect((0, test_utils_1.fetchURL)()).toContain('/user_management/invitations');
|
|
562
535
|
expect(invitationsList).toMatchObject({
|
|
563
536
|
object: 'list',
|
|
564
537
|
data: [
|
|
@@ -576,48 +549,44 @@ describe('UserManagement', () => {
|
|
|
576
549
|
});
|
|
577
550
|
}));
|
|
578
551
|
it('sends the correct params when filtering', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
579
|
-
|
|
580
|
-
.onGet('/user_management/invitations')
|
|
581
|
-
.reply(200, list_invitations_json_1.default);
|
|
552
|
+
(0, test_utils_1.fetchOnce)(list_invitations_json_1.default);
|
|
582
553
|
yield workos.userManagement.listInvitations({
|
|
583
554
|
organizationId: 'org_someorg',
|
|
584
555
|
after: 'user_01H5JQDV7R7ATEYZDEG0W5PRYS',
|
|
585
556
|
limit: 10,
|
|
586
557
|
});
|
|
587
|
-
expect(
|
|
558
|
+
expect((0, test_utils_1.fetchSearchParams)()).toEqual({
|
|
588
559
|
organization_id: 'org_someorg',
|
|
589
|
-
before: undefined,
|
|
590
560
|
after: 'user_01H5JQDV7R7ATEYZDEG0W5PRYS',
|
|
591
|
-
limit: 10,
|
|
561
|
+
limit: '10',
|
|
592
562
|
order: 'desc',
|
|
593
563
|
});
|
|
594
564
|
}));
|
|
595
565
|
});
|
|
596
566
|
describe('sendInvitation', () => {
|
|
597
567
|
it('sends a Send Invitation request', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
598
|
-
|
|
599
|
-
.onPost('/user_management/invitations', {
|
|
600
|
-
email: 'dane@workos.com',
|
|
601
|
-
})
|
|
602
|
-
.reply(200, invitation_json_1.default);
|
|
568
|
+
(0, test_utils_1.fetchOnce)(invitation_json_1.default);
|
|
603
569
|
const response = yield workos.userManagement.sendInvitation({
|
|
604
570
|
email: 'dane@workos.com',
|
|
605
571
|
});
|
|
606
|
-
expect(
|
|
572
|
+
expect((0, test_utils_1.fetchURL)()).toContain('/user_management/invitations');
|
|
573
|
+
expect((0, test_utils_1.fetchBody)()).toEqual({
|
|
574
|
+
email: 'dane@workos.com',
|
|
575
|
+
});
|
|
607
576
|
expect(response).toMatchObject({
|
|
608
577
|
object: 'invitation',
|
|
609
578
|
email: 'dane@workos.com',
|
|
610
579
|
});
|
|
611
580
|
}));
|
|
612
581
|
it('sends the correct params when provided', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
613
|
-
|
|
582
|
+
(0, test_utils_1.fetchOnce)(invitation_json_1.default);
|
|
614
583
|
yield workos.userManagement.sendInvitation({
|
|
615
584
|
email: 'dane@workos.com',
|
|
616
585
|
organizationId: 'org_someorg',
|
|
617
586
|
expiresInDays: 4,
|
|
618
587
|
inviterUserId: 'user_someuser',
|
|
619
588
|
});
|
|
620
|
-
expect(
|
|
589
|
+
expect((0, test_utils_1.fetchBody)()).toEqual({
|
|
621
590
|
email: 'dane@workos.com',
|
|
622
591
|
organization_id: 'org_someorg',
|
|
623
592
|
expires_in_days: 4,
|
|
@@ -628,11 +597,9 @@ describe('UserManagement', () => {
|
|
|
628
597
|
describe('revokeInvitation', () => {
|
|
629
598
|
it('send a Revoke Invitation request', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
630
599
|
const invitationId = 'invitation_01H5JQDV7R7ATEYZDEG0W5PRYS';
|
|
631
|
-
|
|
632
|
-
.onPost(`/user_management/invitations/${invitationId}/revoke`)
|
|
633
|
-
.reply(200, invitation_json_1.default);
|
|
600
|
+
(0, test_utils_1.fetchOnce)(invitation_json_1.default);
|
|
634
601
|
const response = yield workos.userManagement.revokeInvitation(invitationId);
|
|
635
|
-
expect(
|
|
602
|
+
expect((0, test_utils_1.fetchURL)()).toContain(`/user_management/invitations/${invitationId}/revoke`);
|
|
636
603
|
expect(response).toMatchObject({
|
|
637
604
|
object: 'invitation',
|
|
638
605
|
email: 'dane@workos.com',
|
|
@@ -5,14 +5,14 @@ export declare class Webhooks {
|
|
|
5
5
|
sigHeader: string;
|
|
6
6
|
secret: string;
|
|
7
7
|
tolerance?: number;
|
|
8
|
-
}): Event
|
|
8
|
+
}): Promise<Event>;
|
|
9
9
|
verifyHeader({ payload, sigHeader, secret, tolerance, }: {
|
|
10
10
|
payload: any;
|
|
11
11
|
sigHeader: string;
|
|
12
12
|
secret: string;
|
|
13
13
|
tolerance?: number;
|
|
14
|
-
}): boolean
|
|
15
|
-
getTimestampAndSignatureHash(sigHeader: string): string
|
|
16
|
-
computeSignature(timestamp: any, payload: any, secret: string): string
|
|
17
|
-
secureCompare(stringA: string, stringB: string): boolean
|
|
14
|
+
}): Promise<boolean>;
|
|
15
|
+
getTimestampAndSignatureHash(sigHeader: string): [string, string];
|
|
16
|
+
computeSignature(timestamp: any, payload: any, secret: string): Promise<string>;
|
|
17
|
+
secureCompare(stringA: string, stringB: string): Promise<boolean>;
|
|
18
18
|
}
|