@workos-inc/node 2.20.0 → 3.0.0-user-management.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.
- package/lib/audit-logs/audit-logs.spec.js +2 -1
- package/lib/audit-trail/audit-trail.spec.js +2 -1
- package/lib/common/interfaces/index.d.ts +1 -0
- package/lib/common/interfaces/index.js +1 -0
- package/lib/common/interfaces/workos-response-error.interface.d.ts +8 -0
- package/lib/common/interfaces/workos-response-error.interface.js +2 -0
- package/lib/mfa/mfa.spec.js +10 -10
- package/lib/organizations/organizations.spec.js +2 -1
- package/lib/portal/interfaces/generate-portal-link-intent.interface.js +1 -1
- package/lib/sso/interfaces/connection-type.enum.d.ts +1 -0
- package/lib/sso/interfaces/connection-type.enum.js +2 -1
- package/lib/sso/interfaces/connection.interface.d.ts +1 -1
- package/lib/sso/sso.js +12 -5
- package/lib/sso/sso.spec.js +3 -3
- package/lib/users/fixtures/list-users.json +21 -0
- package/lib/users/fixtures/session.json +6 -0
- package/lib/users/fixtures/user.json +12 -0
- package/lib/users/interfaces/add-user-to-organization-options.interface.d.ts +4 -0
- package/lib/users/interfaces/add-user-to-organization-options.interface.js +2 -0
- package/lib/users/interfaces/authenticate-user-with-password-options.interface.d.ts +8 -0
- package/lib/users/interfaces/authenticate-user-with-password-options.interface.js +2 -0
- package/lib/users/interfaces/authenticate-user-with-token-options.interface.d.ts +6 -0
- package/lib/users/interfaces/authenticate-user-with-token-options.interface.js +2 -0
- package/lib/users/interfaces/authentication-response.interface.d.ts +6 -0
- package/lib/users/interfaces/authentication-response.interface.js +2 -0
- package/lib/users/interfaces/complete-password-reset-options.interface.d.ts +4 -0
- package/lib/users/interfaces/complete-password-reset-options.interface.js +2 -0
- package/lib/users/interfaces/create-email-verification-challenge-options.interface.d.ts +9 -0
- package/lib/users/interfaces/create-email-verification-challenge-options.interface.js +2 -0
- package/lib/users/interfaces/create-password-reset-challenge-options.interface.d.ts +9 -0
- package/lib/users/interfaces/create-password-reset-challenge-options.interface.js +2 -0
- package/lib/users/interfaces/create-user-options.interface.d.ts +7 -0
- package/lib/users/interfaces/create-user-options.interface.js +2 -0
- package/lib/users/interfaces/index.d.ts +13 -0
- package/lib/users/interfaces/index.js +29 -0
- package/lib/users/interfaces/list-users-options.interface.d.ts +6 -0
- package/lib/users/interfaces/list-users-options.interface.js +2 -0
- package/lib/users/interfaces/remove-user-from-organization-options.interface.d.ts +4 -0
- package/lib/users/interfaces/remove-user-from-organization-options.interface.js +2 -0
- package/lib/users/interfaces/revoke-session-options.interface.d.ts +8 -0
- package/lib/users/interfaces/revoke-session-options.interface.js +2 -0
- package/lib/users/interfaces/session.interface.d.ts +6 -0
- package/lib/users/interfaces/session.interface.js +2 -0
- package/lib/users/interfaces/user.interface.d.ts +31 -0
- package/lib/users/interfaces/user.interface.js +2 -0
- package/lib/users/interfaces/verify-session.interface.d.ts +10 -0
- package/lib/users/interfaces/verify-session.interface.js +2 -0
- package/lib/users/users.d.ts +21 -0
- package/lib/users/users.js +110 -0
- package/lib/users/users.spec.d.ts +1 -0
- package/lib/users/users.spec.js +294 -0
- package/lib/webhooks/fixtures/webhook.json +1 -1
- package/lib/webhooks/interfaces/webhook.interface.d.ts +1 -0
- package/lib/workos.d.ts +2 -0
- package/lib/workos.js +3 -1
- package/package.json +13 -14
|
@@ -56,6 +56,7 @@ describe('AuditLogs', () => {
|
|
|
56
56
|
describe('createEvent', () => {
|
|
57
57
|
describe('with an idempotency key', () => {
|
|
58
58
|
it('includes an idempotency key with request', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
59
|
+
var _a;
|
|
59
60
|
mock
|
|
60
61
|
.onPost('/audit_logs/events', {
|
|
61
62
|
event: serializeEventOptions(event),
|
|
@@ -66,7 +67,7 @@ describe('AuditLogs', () => {
|
|
|
66
67
|
yield expect(workos.auditLogs.createEvent('org_123', event, {
|
|
67
68
|
idempotencyKey: 'the-idempotency-key',
|
|
68
69
|
})).resolves.toBeUndefined();
|
|
69
|
-
expect(mock.history.post[0].headers['Idempotency-Key']).toEqual('the-idempotency-key');
|
|
70
|
+
expect((_a = mock.history.post[0].headers) === null || _a === void 0 ? void 0 : _a['Idempotency-Key']).toEqual('the-idempotency-key');
|
|
70
71
|
}));
|
|
71
72
|
});
|
|
72
73
|
describe('when the api responds with a 200', () => {
|
|
@@ -34,6 +34,7 @@ describe('AuditTrail', () => {
|
|
|
34
34
|
describe('when the api responds with a 201 CREATED', () => {
|
|
35
35
|
describe('with an idempotency key', () => {
|
|
36
36
|
it('includes an idempotency key with request', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
37
|
+
var _a;
|
|
37
38
|
mock
|
|
38
39
|
.onPost('/events', serializeEventOptions(event))
|
|
39
40
|
.replyOnce(201, { success: true });
|
|
@@ -41,7 +42,7 @@ describe('AuditTrail', () => {
|
|
|
41
42
|
yield expect(workos.auditTrail.createEvent(event, {
|
|
42
43
|
idempotencyKey: 'the-idempotency-key',
|
|
43
44
|
})).resolves.toBeUndefined();
|
|
44
|
-
expect(mock.history.post[0].headers['Idempotency-Key']).toEqual('the-idempotency-key');
|
|
45
|
+
expect((_a = mock.history.post[0].headers) === null || _a === void 0 ? void 0 : _a['Idempotency-Key']).toEqual('the-idempotency-key');
|
|
45
46
|
}));
|
|
46
47
|
});
|
|
47
48
|
it('posts Event successfully', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -19,3 +19,4 @@ __exportStar(require("./post-options.interface"), exports);
|
|
|
19
19
|
__exportStar(require("./put-options.interface"), exports);
|
|
20
20
|
__exportStar(require("./unprocessable-entity-error.interface"), exports);
|
|
21
21
|
__exportStar(require("./workos-options.interface"), exports);
|
|
22
|
+
__exportStar(require("./workos-response-error.interface"), exports);
|
package/lib/mfa/mfa.spec.js
CHANGED
|
@@ -23,7 +23,7 @@ describe('MFA', () => {
|
|
|
23
23
|
mock.onGet().reply(200, {});
|
|
24
24
|
const workos = new workos_1.WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU');
|
|
25
25
|
const factor = yield workos.mfa.getFactor('test_123');
|
|
26
|
-
expect(factor).toMatchInlineSnapshot(`
|
|
26
|
+
expect(factor).toMatchInlineSnapshot(`{}`);
|
|
27
27
|
}));
|
|
28
28
|
});
|
|
29
29
|
describe('deleteFactor', () => {
|
|
@@ -53,7 +53,7 @@ describe('MFA', () => {
|
|
|
53
53
|
type: 'generic_otp',
|
|
54
54
|
});
|
|
55
55
|
expect(enrollResponse).toMatchInlineSnapshot(`
|
|
56
|
-
|
|
56
|
+
{
|
|
57
57
|
"created_at": "2022-03-15T20:39:19.892Z",
|
|
58
58
|
"id": "auth_factor_1234",
|
|
59
59
|
"object": "authentication_factor",
|
|
@@ -89,11 +89,11 @@ describe('MFA', () => {
|
|
|
89
89
|
user: 'some_user',
|
|
90
90
|
});
|
|
91
91
|
expect(enrollResponse).toMatchInlineSnapshot(`
|
|
92
|
-
|
|
92
|
+
{
|
|
93
93
|
"created_at": "2022-03-15T20:39:19.892Z",
|
|
94
94
|
"id": "auth_factor_1234",
|
|
95
95
|
"object": "authentication_factor",
|
|
96
|
-
"totp":
|
|
96
|
+
"totp": {
|
|
97
97
|
"issuer": "WorkOS",
|
|
98
98
|
"qr_code": "qr-code-test",
|
|
99
99
|
"secret": "secret-test",
|
|
@@ -127,11 +127,11 @@ describe('MFA', () => {
|
|
|
127
127
|
phoneNumber: '+1555555555',
|
|
128
128
|
});
|
|
129
129
|
expect(enrollResponse).toMatchInlineSnapshot(`
|
|
130
|
-
|
|
130
|
+
{
|
|
131
131
|
"created_at": "2022-03-15T20:39:19.892Z",
|
|
132
132
|
"id": "auth_factor_1234",
|
|
133
133
|
"object": "authentication_factor",
|
|
134
|
-
"sms":
|
|
134
|
+
"sms": {
|
|
135
135
|
"phone_number": "+15555555555",
|
|
136
136
|
},
|
|
137
137
|
"type": "sms",
|
|
@@ -179,7 +179,7 @@ describe('MFA', () => {
|
|
|
179
179
|
authenticationFactorId: 'auth_factor_1234',
|
|
180
180
|
});
|
|
181
181
|
expect(challengeResponse).toMatchInlineSnapshot(`
|
|
182
|
-
|
|
182
|
+
{
|
|
183
183
|
"authentication_factor_id": "auth_factor_1234",
|
|
184
184
|
"code": "12345",
|
|
185
185
|
"created_at": "2022-03-15T20:39:19.892Z",
|
|
@@ -215,7 +215,7 @@ describe('MFA', () => {
|
|
|
215
215
|
smsTemplate: 'This is your code: 12345',
|
|
216
216
|
});
|
|
217
217
|
expect(challengeResponse).toMatchInlineSnapshot(`
|
|
218
|
-
|
|
218
|
+
{
|
|
219
219
|
"authentication_factor_id": "auth_factor_1234",
|
|
220
220
|
"code": "12345",
|
|
221
221
|
"created_at": "2022-03-15T20:39:19.892Z",
|
|
@@ -256,8 +256,8 @@ describe('MFA', () => {
|
|
|
256
256
|
code: '12345',
|
|
257
257
|
});
|
|
258
258
|
expect(verifyResponse).toMatchInlineSnapshot(`
|
|
259
|
-
|
|
260
|
-
"challenge":
|
|
259
|
+
{
|
|
260
|
+
"challenge": {
|
|
261
261
|
"authentication_factor_id": "auth_factor_1234",
|
|
262
262
|
"code": "12345",
|
|
263
263
|
"created_at": "2022-03-15T20:39:19.892Z",
|
|
@@ -110,6 +110,7 @@ describe('Organizations', () => {
|
|
|
110
110
|
describe('createOrganization', () => {
|
|
111
111
|
describe('with an idempotency key', () => {
|
|
112
112
|
it('includes an idempotency key with request', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
113
|
+
var _a;
|
|
113
114
|
mock
|
|
114
115
|
.onPost('/organizations', {
|
|
115
116
|
domains: ['example.com'],
|
|
@@ -122,7 +123,7 @@ describe('Organizations', () => {
|
|
|
122
123
|
}, {
|
|
123
124
|
idempotencyKey: 'the-idempotency-key',
|
|
124
125
|
});
|
|
125
|
-
expect(mock.history.post[0].headers['Idempotency-Key']).toEqual('the-idempotency-key');
|
|
126
|
+
expect((_a = mock.history.post[0].headers) === null || _a === void 0 ? void 0 : _a['Idempotency-Key']).toEqual('the-idempotency-key');
|
|
126
127
|
}));
|
|
127
128
|
});
|
|
128
129
|
describe('with a valid payload', () => {
|
|
@@ -7,4 +7,4 @@ var GeneratePortalLinkIntent;
|
|
|
7
7
|
GeneratePortalLinkIntent["DSync"] = "dsync";
|
|
8
8
|
GeneratePortalLinkIntent["LogStreams"] = "log_streams";
|
|
9
9
|
GeneratePortalLinkIntent["SSO"] = "sso";
|
|
10
|
-
})(GeneratePortalLinkIntent
|
|
10
|
+
})(GeneratePortalLinkIntent || (exports.GeneratePortalLinkIntent = GeneratePortalLinkIntent = {}));
|
|
@@ -15,6 +15,7 @@ export declare enum ConnectionType {
|
|
|
15
15
|
JumpCloudSAML = "JumpCloudSAML",
|
|
16
16
|
KeycloakSAML = "KeycloakSAML",
|
|
17
17
|
LastPassSAML = "LastPassSAML",
|
|
18
|
+
LoginGovOidc = "LoginGovOidc",
|
|
18
19
|
MagicLink = "MagicLink",
|
|
19
20
|
MicrosoftOAuth = "MicrosoftOAuth",
|
|
20
21
|
MiniOrangeSAML = "MiniOrangeSAML",
|
|
@@ -19,6 +19,7 @@ var ConnectionType;
|
|
|
19
19
|
ConnectionType["JumpCloudSAML"] = "JumpCloudSAML";
|
|
20
20
|
ConnectionType["KeycloakSAML"] = "KeycloakSAML";
|
|
21
21
|
ConnectionType["LastPassSAML"] = "LastPassSAML";
|
|
22
|
+
ConnectionType["LoginGovOidc"] = "LoginGovOidc";
|
|
22
23
|
ConnectionType["MagicLink"] = "MagicLink";
|
|
23
24
|
ConnectionType["MicrosoftOAuth"] = "MicrosoftOAuth";
|
|
24
25
|
ConnectionType["MiniOrangeSAML"] = "MiniOrangeSAML";
|
|
@@ -34,4 +35,4 @@ var ConnectionType;
|
|
|
34
35
|
ConnectionType["ShibbolethSAML"] = "ShibbolethSAML";
|
|
35
36
|
ConnectionType["SimpleSamlPhpSAML"] = "SimpleSamlPhpSAML";
|
|
36
37
|
ConnectionType["VMwareSAML"] = "VMwareSAML";
|
|
37
|
-
})(ConnectionType
|
|
38
|
+
})(ConnectionType || (exports.ConnectionType = ConnectionType = {}));
|
|
@@ -10,7 +10,7 @@ export interface Connection {
|
|
|
10
10
|
organization_id?: string;
|
|
11
11
|
name: string;
|
|
12
12
|
connection_type: ConnectionType;
|
|
13
|
-
state: 'draft' | 'active' | 'inactive';
|
|
13
|
+
state: 'draft' | 'active' | 'inactive' | 'validating';
|
|
14
14
|
/**
|
|
15
15
|
* @deprecated The status parameter has been deprecated. Please use state.
|
|
16
16
|
*/
|
package/lib/sso/sso.js
CHANGED
|
@@ -8,12 +8,19 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
12
|
exports.SSO = void 0;
|
|
16
|
-
const
|
|
13
|
+
const toQueryString = (options) => {
|
|
14
|
+
const searchParams = new URLSearchParams();
|
|
15
|
+
const keys = Object.keys(options).sort();
|
|
16
|
+
for (const key of keys) {
|
|
17
|
+
const value = options[key];
|
|
18
|
+
if (value) {
|
|
19
|
+
searchParams.append(key, value);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return searchParams.toString();
|
|
23
|
+
};
|
|
17
24
|
class SSO {
|
|
18
25
|
constructor(workos) {
|
|
19
26
|
this.workos = workos;
|
|
@@ -30,7 +37,7 @@ class SSO {
|
|
|
30
37
|
if (domain) {
|
|
31
38
|
this.workos.emitWarning('The `domain` parameter for `getAuthorizationURL` is deprecated. Please use `organization` instead.');
|
|
32
39
|
}
|
|
33
|
-
const query =
|
|
40
|
+
const query = toQueryString({
|
|
34
41
|
connection,
|
|
35
42
|
organization,
|
|
36
43
|
domain,
|
package/lib/sso/sso.spec.js
CHANGED
|
@@ -113,7 +113,7 @@ describe('SSO', () => {
|
|
|
113
113
|
redirectURI: 'example.com/sso/workos/callback',
|
|
114
114
|
state: 'custom state',
|
|
115
115
|
});
|
|
116
|
-
expect(url).toMatchInlineSnapshot(`"https://api.workos.com/sso/authorize?client_id=proj_123&connection=connection_123&domain_hint=lyft.com&redirect_uri=example.com%2Fsso%2Fworkos%2Fcallback&response_type=code&state=custom
|
|
116
|
+
expect(url).toMatchInlineSnapshot(`"https://api.workos.com/sso/authorize?client_id=proj_123&connection=connection_123&domain_hint=lyft.com&redirect_uri=example.com%2Fsso%2Fworkos%2Fcallback&response_type=code&state=custom+state"`);
|
|
117
117
|
});
|
|
118
118
|
});
|
|
119
119
|
describe('with loginHint', () => {
|
|
@@ -126,7 +126,7 @@ describe('SSO', () => {
|
|
|
126
126
|
redirectURI: 'example.com/sso/workos/callback',
|
|
127
127
|
state: 'custom state',
|
|
128
128
|
});
|
|
129
|
-
expect(url).toMatchInlineSnapshot(`"https://api.workos.com/sso/authorize?client_id=proj_123&connection=connection_123&login_hint=foo%40workos.com&redirect_uri=example.com%2Fsso%2Fworkos%2Fcallback&response_type=code&state=custom
|
|
129
|
+
expect(url).toMatchInlineSnapshot(`"https://api.workos.com/sso/authorize?client_id=proj_123&connection=connection_123&login_hint=foo%40workos.com&redirect_uri=example.com%2Fsso%2Fworkos%2Fcallback&response_type=code&state=custom+state"`);
|
|
130
130
|
});
|
|
131
131
|
});
|
|
132
132
|
});
|
|
@@ -266,7 +266,7 @@ describe('SSO', () => {
|
|
|
266
266
|
});
|
|
267
267
|
expect(mock.history.get.length).toBe(1);
|
|
268
268
|
const { headers } = mock.history.get[0];
|
|
269
|
-
expect(headers.Authorization).toBe(`Bearer access_token`);
|
|
269
|
+
expect(headers === null || headers === void 0 ? void 0 : headers.Authorization).toBe(`Bearer access_token`);
|
|
270
270
|
expect(profile.id).toBe('prof_123');
|
|
271
271
|
}));
|
|
272
272
|
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"object": "list",
|
|
3
|
+
"data": [
|
|
4
|
+
{
|
|
5
|
+
"object": "user",
|
|
6
|
+
"id": "user_01H5JQDV7R7ATEYZDEG0W5PRYS",
|
|
7
|
+
"email": "test01@example.com",
|
|
8
|
+
"first_name": "Test 01",
|
|
9
|
+
"last_name": "User",
|
|
10
|
+
"organization_memberships": [],
|
|
11
|
+
"created_at": "2023-07-18T02:07:19.911Z",
|
|
12
|
+
"updated_at": "2023-07-18T02:07:19.911Z",
|
|
13
|
+
"user_type": "unmanaged",
|
|
14
|
+
"email_verified_at": "2023-07-17T20:07:20.055Z"
|
|
15
|
+
}
|
|
16
|
+
],
|
|
17
|
+
"list_metadata": {
|
|
18
|
+
"before": null,
|
|
19
|
+
"after": null
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"object": "user",
|
|
3
|
+
"id": "user_01H5JQDV7R7ATEYZDEG0W5PRYS",
|
|
4
|
+
"email": "test01@example.com",
|
|
5
|
+
"first_name": "Test 01",
|
|
6
|
+
"last_name": "User",
|
|
7
|
+
"organization_memberships": [],
|
|
8
|
+
"created_at": "2023-07-18T02:07:19.911Z",
|
|
9
|
+
"updated_at": "2023-07-18T02:07:19.911Z",
|
|
10
|
+
"user_type": "unmanaged",
|
|
11
|
+
"email_verified_at": "2023-07-17T20:07:20.055Z"
|
|
12
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export * from './add-user-to-organization-options.interface';
|
|
2
|
+
export * from './authenticate-user-with-password-options.interface';
|
|
3
|
+
export * from './authenticate-user-with-token-options.interface';
|
|
4
|
+
export * from './authentication-response.interface';
|
|
5
|
+
export * from './complete-password-reset-options.interface';
|
|
6
|
+
export * from './create-email-verification-challenge-options.interface';
|
|
7
|
+
export * from './create-password-reset-challenge-options.interface';
|
|
8
|
+
export * from './create-user-options.interface';
|
|
9
|
+
export * from './list-users-options.interface';
|
|
10
|
+
export * from './remove-user-from-organization-options.interface';
|
|
11
|
+
export * from './revoke-session-options.interface';
|
|
12
|
+
export * from './user.interface';
|
|
13
|
+
export * from './verify-session.interface';
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./add-user-to-organization-options.interface"), exports);
|
|
18
|
+
__exportStar(require("./authenticate-user-with-password-options.interface"), exports);
|
|
19
|
+
__exportStar(require("./authenticate-user-with-token-options.interface"), exports);
|
|
20
|
+
__exportStar(require("./authentication-response.interface"), exports);
|
|
21
|
+
__exportStar(require("./complete-password-reset-options.interface"), exports);
|
|
22
|
+
__exportStar(require("./create-email-verification-challenge-options.interface"), exports);
|
|
23
|
+
__exportStar(require("./create-password-reset-challenge-options.interface"), exports);
|
|
24
|
+
__exportStar(require("./create-user-options.interface"), exports);
|
|
25
|
+
__exportStar(require("./list-users-options.interface"), exports);
|
|
26
|
+
__exportStar(require("./remove-user-from-organization-options.interface"), exports);
|
|
27
|
+
__exportStar(require("./revoke-session-options.interface"), exports);
|
|
28
|
+
__exportStar(require("./user.interface"), exports);
|
|
29
|
+
__exportStar(require("./verify-session.interface"), exports);
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export type User = ManagedUser | UnmanangedUser;
|
|
2
|
+
interface ManagedUser extends BaseUser {
|
|
3
|
+
user_type: 'managed';
|
|
4
|
+
organization_memberships: [OrganizationMembership];
|
|
5
|
+
sso_profile_id: string;
|
|
6
|
+
}
|
|
7
|
+
interface UnmanangedUser extends BaseUser {
|
|
8
|
+
user_type: 'unmanaged';
|
|
9
|
+
organization_memberships: OrganizationMembership[];
|
|
10
|
+
email_verified_at?: string;
|
|
11
|
+
google_oauth_profile_id?: string;
|
|
12
|
+
}
|
|
13
|
+
interface BaseUser {
|
|
14
|
+
object: 'user';
|
|
15
|
+
id: string;
|
|
16
|
+
email: string;
|
|
17
|
+
first_name?: string;
|
|
18
|
+
last_name?: string;
|
|
19
|
+
created_at: string;
|
|
20
|
+
updated_at: string;
|
|
21
|
+
}
|
|
22
|
+
interface OrganizationMembership {
|
|
23
|
+
organization: OrganizationSummary;
|
|
24
|
+
created_at: string;
|
|
25
|
+
updated_at: string;
|
|
26
|
+
}
|
|
27
|
+
interface OrganizationSummary {
|
|
28
|
+
id: string;
|
|
29
|
+
name: string;
|
|
30
|
+
}
|
|
31
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { WorkOS } from '../workos';
|
|
2
|
+
import { AddUserToOrganizationOptions, AuthenticateUserWithPasswordOptions, AuthenticateUserWithTokenOptions, AuthenticationResponse, CompletePasswordResetOptions, CreateEmailVerificationChallengeOptions, CreateEmailVerificationChallengeResponse, CreatePasswordResetChallengeOptions, CreatePasswordResetChallengeResponse, CreateUserOptions, ListUsersOptions, RemoveUserFromOrganizationOptions, RevokeSessionOptions, User, VerifySessionOptions, VerifySessionResponse } from './interfaces';
|
|
3
|
+
import { List } from '../common/interfaces/list.interface';
|
|
4
|
+
export declare class Users {
|
|
5
|
+
private readonly workos;
|
|
6
|
+
constructor(workos: WorkOS);
|
|
7
|
+
getUser(userId: string): Promise<User>;
|
|
8
|
+
listUsers(options?: ListUsersOptions): Promise<List<User>>;
|
|
9
|
+
createUser(payload: CreateUserOptions): Promise<User>;
|
|
10
|
+
authenticateUserWithPassword(payload: AuthenticateUserWithPasswordOptions): Promise<AuthenticationResponse>;
|
|
11
|
+
authenticateUserWithToken(payload: AuthenticateUserWithTokenOptions): Promise<AuthenticationResponse>;
|
|
12
|
+
verifySession(payload: VerifySessionOptions): Promise<VerifySessionResponse>;
|
|
13
|
+
revokeSession(payload: RevokeSessionOptions): Promise<boolean>;
|
|
14
|
+
revokeAllSessionsForUser(userId: string): Promise<boolean>;
|
|
15
|
+
createEmailVerificationChallenge({ user_id, verification_url, }: CreateEmailVerificationChallengeOptions): Promise<CreateEmailVerificationChallengeResponse>;
|
|
16
|
+
completeEmailVerification(token: string): Promise<User>;
|
|
17
|
+
createPasswordResetChallenge(payload: CreatePasswordResetChallengeOptions): Promise<CreatePasswordResetChallengeResponse>;
|
|
18
|
+
completePasswordReset(payload: CompletePasswordResetOptions): Promise<User>;
|
|
19
|
+
addUserToOrganization({ user_id, organization_id, }: AddUserToOrganizationOptions): Promise<User>;
|
|
20
|
+
removeUserFromOrganization({ user_id, organization_id, }: RemoveUserFromOrganizationOptions): Promise<User>;
|
|
21
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.Users = void 0;
|
|
13
|
+
class Users {
|
|
14
|
+
constructor(workos) {
|
|
15
|
+
this.workos = workos;
|
|
16
|
+
}
|
|
17
|
+
getUser(userId) {
|
|
18
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
19
|
+
const { data } = yield this.workos.get(`/users/${userId}`);
|
|
20
|
+
return data;
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
listUsers(options) {
|
|
24
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
25
|
+
const { data } = yield this.workos.get('/users', {
|
|
26
|
+
query: options,
|
|
27
|
+
});
|
|
28
|
+
return data;
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
createUser(payload) {
|
|
32
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
33
|
+
const { data } = yield this.workos.post('/users', payload);
|
|
34
|
+
return data;
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
authenticateUserWithPassword(payload) {
|
|
38
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
39
|
+
const { data } = yield this.workos.post('/users/authentications', payload);
|
|
40
|
+
return data;
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
authenticateUserWithToken(payload) {
|
|
44
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
45
|
+
const { data } = yield this.workos.post('/users/sessions/token', Object.assign(Object.assign({}, payload), { client_secret: this.workos.key, grant_type: 'authorization_code' }));
|
|
46
|
+
return data;
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
verifySession(payload) {
|
|
50
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
51
|
+
const { data } = yield this.workos.post('/users/sessions/verify', payload);
|
|
52
|
+
return data;
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
revokeSession(payload) {
|
|
56
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
57
|
+
const { data } = yield this.workos.post('/users/sessions/revocations', payload);
|
|
58
|
+
return data;
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
revokeAllSessionsForUser(userId) {
|
|
62
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
63
|
+
const { data } = yield this.workos.delete(`/users/${userId}/sessions`);
|
|
64
|
+
return data;
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
createEmailVerificationChallenge({ user_id, verification_url, }) {
|
|
68
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
69
|
+
const { data } = yield this.workos.post(`/users/${user_id}/email_verification_challenge`, {
|
|
70
|
+
verification_url,
|
|
71
|
+
});
|
|
72
|
+
return data;
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
completeEmailVerification(token) {
|
|
76
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
77
|
+
const { data } = yield this.workos.post('/users/email_verification', {
|
|
78
|
+
token,
|
|
79
|
+
});
|
|
80
|
+
return data;
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
createPasswordResetChallenge(payload) {
|
|
84
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
85
|
+
const { data } = yield this.workos.post('/users/password_reset_challenge', payload);
|
|
86
|
+
return data;
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
completePasswordReset(payload) {
|
|
90
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
91
|
+
const { data } = yield this.workos.post('/users/password_reset', payload);
|
|
92
|
+
return data;
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
addUserToOrganization({ user_id, organization_id, }) {
|
|
96
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
97
|
+
const { data } = yield this.workos.post(`/users/${user_id}/organizations`, {
|
|
98
|
+
organization_id,
|
|
99
|
+
});
|
|
100
|
+
return data;
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
removeUserFromOrganization({ user_id, organization_id, }) {
|
|
104
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
105
|
+
const { data } = yield this.workos.delete(`/users/${user_id}/organizations/${organization_id}`);
|
|
106
|
+
return data;
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
exports.Users = Users;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,294 @@
|
|
|
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
|
+
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',
|
|
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
|
+
list_metadata: {
|
|
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
|
+
first_name: 'Test 01',
|
|
87
|
+
last_name: 'User',
|
|
88
|
+
email_verified: true,
|
|
89
|
+
});
|
|
90
|
+
expect(mock.history.post[0].url).toEqual('/users');
|
|
91
|
+
expect(user).toMatchObject(user_json_1.default);
|
|
92
|
+
}));
|
|
93
|
+
});
|
|
94
|
+
describe('authenticateUserWithPassword', () => {
|
|
95
|
+
it('sends an password authentication request', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
96
|
+
mock.onPost('/users/authentications').reply(200, {
|
|
97
|
+
user: user_json_1.default,
|
|
98
|
+
session: session_json_1.default,
|
|
99
|
+
});
|
|
100
|
+
const resp = yield workos.users.authenticateUserWithPassword({
|
|
101
|
+
email: 'test01@example.com',
|
|
102
|
+
password: 'extra-secure',
|
|
103
|
+
});
|
|
104
|
+
expect(mock.history.post[0].url).toEqual('/users/authentications');
|
|
105
|
+
expect(resp).toMatchObject({
|
|
106
|
+
user: {
|
|
107
|
+
email: 'test01@example.com',
|
|
108
|
+
},
|
|
109
|
+
session: {
|
|
110
|
+
id: 'session_01H5K05VP5CPCXJA5Z7G191GS4',
|
|
111
|
+
token: 'really-long-token',
|
|
112
|
+
},
|
|
113
|
+
});
|
|
114
|
+
}));
|
|
115
|
+
});
|
|
116
|
+
describe('authenticateUserWithToken', () => {
|
|
117
|
+
it('sends a token authentication request', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
118
|
+
mock
|
|
119
|
+
.onPost('/users/sessions/token')
|
|
120
|
+
.reply(200, { user: user_json_1.default, session: session_json_1.default });
|
|
121
|
+
const resp = yield workos.users.authenticateUserWithToken({
|
|
122
|
+
client_id: 'proj_whatever',
|
|
123
|
+
code: 'or this',
|
|
124
|
+
expires_in: 15,
|
|
125
|
+
});
|
|
126
|
+
expect(mock.history.post[0].url).toEqual('/users/sessions/token');
|
|
127
|
+
expect(JSON.parse(mock.history.post[0].data)).toMatchObject({
|
|
128
|
+
client_secret: 'sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU',
|
|
129
|
+
grant_type: 'authorization_code',
|
|
130
|
+
});
|
|
131
|
+
expect(resp).toMatchObject({
|
|
132
|
+
user: {
|
|
133
|
+
email: 'test01@example.com',
|
|
134
|
+
},
|
|
135
|
+
session: {
|
|
136
|
+
id: 'session_01H5K05VP5CPCXJA5Z7G191GS4',
|
|
137
|
+
token: 'really-long-token',
|
|
138
|
+
},
|
|
139
|
+
});
|
|
140
|
+
}));
|
|
141
|
+
});
|
|
142
|
+
describe('verifySession', () => {
|
|
143
|
+
it('sends a request to verify the session', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
144
|
+
mock.onPost('/users/sessions/verify').reply(200, {
|
|
145
|
+
user: user_json_1.default,
|
|
146
|
+
session: session_json_1.default,
|
|
147
|
+
});
|
|
148
|
+
const resp = yield workos.users.verifySession({
|
|
149
|
+
client_id: 'proj_something',
|
|
150
|
+
token: 'really-long-token',
|
|
151
|
+
});
|
|
152
|
+
expect(mock.history.post[0].url).toEqual('/users/sessions/verify');
|
|
153
|
+
expect(resp).toMatchObject({
|
|
154
|
+
user: {
|
|
155
|
+
email: 'test01@example.com',
|
|
156
|
+
},
|
|
157
|
+
session: {
|
|
158
|
+
id: 'session_01H5K05VP5CPCXJA5Z7G191GS4',
|
|
159
|
+
token: 'really-long-token',
|
|
160
|
+
},
|
|
161
|
+
});
|
|
162
|
+
}));
|
|
163
|
+
});
|
|
164
|
+
describe('revokeSession', () => {
|
|
165
|
+
it('can revoke with the session_id', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
166
|
+
mock.onPost('/users/sessions/revocations').reply(200, true);
|
|
167
|
+
const revoked = yield workos.users.revokeSession({
|
|
168
|
+
session_id: 'session_01H5K05VP5CPCXJA5Z7G191GS4',
|
|
169
|
+
});
|
|
170
|
+
expect(mock.history.post[0].url).toEqual('/users/sessions/revocations');
|
|
171
|
+
expect(revoked).toEqual(true);
|
|
172
|
+
}));
|
|
173
|
+
it('can revoke with the session_token', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
174
|
+
mock.onPost('/users/sessions/revocations').reply(200, true);
|
|
175
|
+
const revoked = yield workos.users.revokeSession({
|
|
176
|
+
session_token: 'really-long-token',
|
|
177
|
+
});
|
|
178
|
+
expect(mock.history.post[0].url).toEqual('/users/sessions/revocations');
|
|
179
|
+
expect(revoked).toEqual(true);
|
|
180
|
+
}));
|
|
181
|
+
});
|
|
182
|
+
describe('revokeAllSessionsForUser', () => {
|
|
183
|
+
it('sends a revokeAllSessionsForUser request', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
184
|
+
mock.onDelete(`/users/${userId}/sessions`).reply(200, true);
|
|
185
|
+
const revoked = yield workos.users.revokeAllSessionsForUser(userId);
|
|
186
|
+
expect(mock.history.delete[0].url).toEqual(`/users/${userId}/sessions`);
|
|
187
|
+
expect(revoked).toEqual(true);
|
|
188
|
+
}));
|
|
189
|
+
});
|
|
190
|
+
describe('createEmailVerificationChallenge', () => {
|
|
191
|
+
it('sends a Create Email Verification Challenge request', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
192
|
+
mock.onPost(`/users/${userId}/email_verification_challenge`).reply(200, {
|
|
193
|
+
token: 'email-verification-challenge',
|
|
194
|
+
user: user_json_1.default,
|
|
195
|
+
});
|
|
196
|
+
const resp = yield workos.users.createEmailVerificationChallenge({
|
|
197
|
+
user_id: userId,
|
|
198
|
+
verification_url: 'https://example.com/verify-email',
|
|
199
|
+
});
|
|
200
|
+
expect(mock.history.post[0].url).toEqual(`/users/${userId}/email_verification_challenge`);
|
|
201
|
+
expect(resp).toMatchObject({
|
|
202
|
+
token: 'email-verification-challenge',
|
|
203
|
+
user: {
|
|
204
|
+
email: 'test01@example.com',
|
|
205
|
+
},
|
|
206
|
+
});
|
|
207
|
+
}));
|
|
208
|
+
describe('completeEmailVerification', () => {
|
|
209
|
+
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 });
|
|
213
|
+
const resp = yield workos.users.completeEmailVerification('email-verification-token');
|
|
214
|
+
expect(mock.history.post[0].url).toEqual(`/users/email_verification`);
|
|
215
|
+
expect(resp).toMatchObject({
|
|
216
|
+
user: {
|
|
217
|
+
email: 'test01@example.com',
|
|
218
|
+
},
|
|
219
|
+
});
|
|
220
|
+
}));
|
|
221
|
+
});
|
|
222
|
+
});
|
|
223
|
+
describe('createPasswordResetChallenge', () => {
|
|
224
|
+
it('sends a Create Password Reset Challenge request', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
225
|
+
mock.onPost(`/users/password_reset_challenge`).reply(200, {
|
|
226
|
+
token: 'password-reset-token',
|
|
227
|
+
user: user_json_1.default,
|
|
228
|
+
});
|
|
229
|
+
const resp = yield workos.users.createPasswordResetChallenge({
|
|
230
|
+
email: 'test01@example.com',
|
|
231
|
+
password_reset_url: 'https://example.com/forgot-password',
|
|
232
|
+
});
|
|
233
|
+
expect(mock.history.post[0].url).toEqual(`/users/password_reset_challenge`);
|
|
234
|
+
expect(resp).toMatchObject({
|
|
235
|
+
token: 'password-reset-token',
|
|
236
|
+
user: {
|
|
237
|
+
email: 'test01@example.com',
|
|
238
|
+
},
|
|
239
|
+
});
|
|
240
|
+
}));
|
|
241
|
+
});
|
|
242
|
+
describe('completePasswordReset', () => {
|
|
243
|
+
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
|
+
});
|
|
247
|
+
const resp = yield workos.users.completePasswordReset({
|
|
248
|
+
token: '',
|
|
249
|
+
new_password: 'correct horse battery staple',
|
|
250
|
+
});
|
|
251
|
+
expect(mock.history.post[0].url).toEqual(`/users/password_reset`);
|
|
252
|
+
expect(resp).toMatchObject({
|
|
253
|
+
user: {
|
|
254
|
+
email: 'test01@example.com',
|
|
255
|
+
},
|
|
256
|
+
});
|
|
257
|
+
}));
|
|
258
|
+
});
|
|
259
|
+
describe('addUserToOrganization', () => {
|
|
260
|
+
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
|
+
});
|
|
264
|
+
const resp = yield workos.users.addUserToOrganization({
|
|
265
|
+
user_id: userId,
|
|
266
|
+
organization_id: 'org_coolorg',
|
|
267
|
+
});
|
|
268
|
+
expect(mock.history.post[0].url).toEqual(`/users/${userId}/organizations`);
|
|
269
|
+
expect(resp).toMatchObject({
|
|
270
|
+
user: {
|
|
271
|
+
email: 'test01@example.com',
|
|
272
|
+
},
|
|
273
|
+
});
|
|
274
|
+
}));
|
|
275
|
+
});
|
|
276
|
+
describe('removeUserFromOrganization', () => {
|
|
277
|
+
it('sends a removeUserFromOrganization request', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
278
|
+
const orgId = 'org_coolorg';
|
|
279
|
+
mock.onDelete(`/users/${userId}/organizations/${orgId}`).reply(200, {
|
|
280
|
+
user: user_json_1.default,
|
|
281
|
+
});
|
|
282
|
+
const resp = yield workos.users.removeUserFromOrganization({
|
|
283
|
+
user_id: userId,
|
|
284
|
+
organization_id: orgId,
|
|
285
|
+
});
|
|
286
|
+
expect(mock.history.delete[0].url).toEqual(`/users/${userId}/organizations/${orgId}`);
|
|
287
|
+
expect(resp).toMatchObject({
|
|
288
|
+
user: {
|
|
289
|
+
email: 'test01@example.com',
|
|
290
|
+
},
|
|
291
|
+
});
|
|
292
|
+
}));
|
|
293
|
+
});
|
|
294
|
+
});
|
|
@@ -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" }
|
|
@@ -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,6 +26,7 @@ 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
31
|
post(path: string, entity: any, options?: PostOptions): Promise<AxiosResponse>;
|
|
30
32
|
get(path: string, options?: GetOptions): Promise<AxiosResponse>;
|
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.
|
|
30
|
+
const VERSION = '2.17.0';
|
|
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
|
+
"version": "3.0.0-user-management.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.
|
|
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": "
|
|
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": "
|
|
43
|
-
"@types/node": "14.18.
|
|
44
|
-
"@types/pluralize": "0.0.
|
|
45
|
-
"axios-mock-adapter": "1.21.
|
|
46
|
-
"jest": "
|
|
47
|
-
"prettier": "2.8.
|
|
48
|
-
"supertest": "6.
|
|
49
|
-
"ts-jest": "
|
|
41
|
+
"@types/jest": "29.5.3",
|
|
42
|
+
"@types/node": "14.18.53",
|
|
43
|
+
"@types/pluralize": "0.0.30",
|
|
44
|
+
"axios-mock-adapter": "1.21.5",
|
|
45
|
+
"jest": "29.6.1",
|
|
46
|
+
"prettier": "2.8.8",
|
|
47
|
+
"supertest": "6.3.3",
|
|
48
|
+
"ts-jest": "29.1.1",
|
|
50
49
|
"tslint": "6.1.3",
|
|
51
|
-
"typescript": "
|
|
50
|
+
"typescript": "5.1.6"
|
|
52
51
|
}
|
|
53
52
|
}
|