@workos-inc/node 2.20.0 → 3.0.0-alpha.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.js +5 -4
- package/lib/audit-logs/audit-logs.spec.js +87 -87
- package/lib/audit-logs/interfaces/audit-log-export-options.interface.d.ts +13 -3
- package/lib/audit-logs/interfaces/audit-log-export.interface.d.ts +8 -0
- package/lib/audit-logs/interfaces/create-audit-log-event-options.interface.d.ts +13 -1
- package/lib/audit-logs/serializers/audit-log-export-options.serializer.d.ts +2 -0
- package/lib/audit-logs/serializers/audit-log-export-options.serializer.js +14 -0
- package/lib/audit-logs/serializers/audit-log-export.serializer.d.ts +2 -0
- package/lib/audit-logs/serializers/audit-log-export.serializer.js +12 -0
- package/lib/audit-logs/serializers/create-audit-log-event-options.serializer.d.ts +2 -0
- package/lib/audit-logs/serializers/create-audit-log-event-options.serializer.js +16 -0
- package/lib/audit-logs/serializers/index.d.ts +3 -0
- package/lib/audit-logs/serializers/index.js +19 -0
- package/lib/audit-trail/audit-trail.spec.js +2 -1
- package/lib/common/interfaces/index.d.ts +2 -0
- package/lib/common/interfaces/index.js +2 -0
- package/lib/common/interfaces/list.interface.d.ts +8 -0
- package/lib/common/interfaces/workos-response-error.interface.d.ts +8 -0
- package/lib/common/serializers/index.d.ts +1 -0
- package/lib/common/serializers/index.js +17 -0
- package/lib/common/serializers/list.serializer.d.ts +2 -0
- package/lib/common/serializers/list.serializer.js +9 -0
- package/lib/common/utils/workos-mock-response.d.ts +7 -0
- package/lib/common/utils/workos-mock-response.js +11 -0
- package/lib/directory-sync/directory-sync.d.ts +7 -12
- package/lib/directory-sync/directory-sync.js +8 -6
- package/lib/directory-sync/directory-sync.spec.js +95 -20
- package/lib/directory-sync/interfaces/directory-group.interface.d.ts +20 -0
- package/lib/directory-sync/interfaces/directory-user.interface.d.ts +48 -0
- package/lib/directory-sync/interfaces/directory.interface.d.ts +12 -0
- package/lib/directory-sync/interfaces/index.d.ts +6 -6
- package/lib/directory-sync/interfaces/index.js +20 -0
- package/lib/directory-sync/interfaces/list-directories-options.interface.d.ts +1 -1
- package/lib/directory-sync/interfaces/{list-users-options.interface.d.ts → list-directory-users-options.interface.d.ts} +1 -1
- package/lib/directory-sync/interfaces/list-directory-users-options.interface.js +2 -0
- package/lib/directory-sync/serializers/directory-group.serializer.d.ts +2 -0
- package/lib/directory-sync/serializers/directory-group.serializer.js +14 -0
- package/lib/directory-sync/serializers/directory-user.serializer.d.ts +3 -0
- package/lib/directory-sync/serializers/directory-user.serializer.js +23 -0
- package/lib/directory-sync/serializers/directory.serializer.d.ts +2 -0
- package/lib/directory-sync/serializers/directory.serializer.js +16 -0
- package/lib/directory-sync/serializers/index.d.ts +3 -0
- package/lib/directory-sync/serializers/index.js +19 -0
- package/lib/directory-sync/utils/get-primary-email.d.ts +2 -2
- package/lib/directory-sync/utils/get-primary-email.spec.js +10 -8
- package/lib/events/events.d.ts +3 -3
- package/lib/events/events.js +3 -1
- package/lib/events/events.spec.js +19 -3
- package/lib/events/interfaces/event.interface.d.ts +4 -1
- package/lib/events/interfaces/list-events-options.interface.d.ts +2 -2
- package/lib/events/serializers/event.serializer.d.ts +2 -0
- package/lib/events/serializers/event.serializer.js +10 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/mfa/interfaces/challenge.interface.d.ts +9 -0
- package/lib/mfa/interfaces/factor.interface.d.ts +13 -4
- package/lib/mfa/interfaces/index.d.ts +9 -0
- package/lib/mfa/interfaces/index.js +25 -0
- package/lib/mfa/interfaces/sms.interface.d.ts +3 -0
- package/lib/mfa/interfaces/totp.interface.d.ts +7 -0
- package/lib/mfa/interfaces/verify-challenge-response.d.ts +5 -1
- package/lib/mfa/mfa.d.ts +2 -8
- package/lib/mfa/mfa.js +5 -4
- package/lib/mfa/mfa.spec.js +134 -115
- package/lib/mfa/serializers/challenge.serializer.d.ts +2 -0
- package/lib/mfa/serializers/challenge.serializer.js +13 -0
- package/lib/mfa/serializers/factor.serializer.d.ts +2 -0
- package/lib/mfa/serializers/factor.serializer.js +7 -0
- package/lib/mfa/serializers/index.d.ts +3 -0
- package/lib/mfa/serializers/index.js +19 -0
- package/lib/mfa/serializers/sms.serializer.d.ts +2 -0
- package/lib/mfa/serializers/sms.serializer.js +7 -0
- package/lib/mfa/serializers/totp.serializer.d.ts +2 -0
- package/lib/mfa/serializers/totp.serializer.js +11 -0
- package/lib/mfa/serializers/verify-response.serializer.d.ts +2 -0
- package/lib/mfa/serializers/verify-response.serializer.js +9 -0
- package/lib/organizations/interfaces/create-organization-options.interface.d.ts +5 -0
- package/lib/organizations/interfaces/organization.interface.d.ts +9 -0
- package/lib/organizations/interfaces/update-organization-options.interface.d.ts +5 -0
- package/lib/organizations/organizations.d.ts +2 -2
- package/lib/organizations/organizations.js +8 -6
- package/lib/organizations/organizations.spec.js +4 -3
- package/lib/organizations/serializers/create-organization-options.serializer.d.ts +2 -0
- package/lib/organizations/serializers/create-organization-options.serializer.js +9 -0
- package/lib/organizations/serializers/index.d.ts +3 -0
- package/lib/organizations/serializers/index.js +19 -0
- package/lib/organizations/serializers/organization.serializer.d.ts +2 -0
- package/lib/organizations/serializers/organization.serializer.js +13 -0
- package/lib/organizations/serializers/update-organization-options.serializer.d.ts +2 -0
- package/lib/organizations/serializers/update-organization-options.serializer.js +9 -0
- package/lib/passwordless/interfaces/create-passwordless-session-options.interface.d.ts +8 -0
- package/lib/passwordless/interfaces/index.d.ts +3 -3
- package/lib/passwordless/interfaces/index.js +17 -0
- package/lib/passwordless/interfaces/passwordless-session.interface.d.ts +7 -0
- package/lib/passwordless/passwordless.d.ts +1 -3
- package/lib/passwordless/passwordless.js +2 -1
- package/lib/passwordless/serializers/index.d.ts +0 -0
- package/lib/passwordless/serializers/index.js +1 -0
- package/lib/passwordless/serializers/passwordless-session.serializer.d.ts +2 -0
- package/lib/passwordless/serializers/passwordless-session.serializer.js +11 -0
- 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 +20 -1
- package/lib/sso/interfaces/index.d.ts +2 -0
- package/lib/sso/interfaces/index.js +2 -0
- package/lib/sso/interfaces/list-connections-options.interface.d.ts +5 -0
- package/lib/sso/interfaces/profile-and-token.interface.d.ts +6 -2
- package/lib/sso/interfaces/profile.interface.d.ts +14 -0
- package/lib/sso/serializers/connection.serializer.d.ts +2 -0
- package/lib/sso/serializers/connection.serializer.js +17 -0
- package/lib/sso/serializers/index.d.ts +3 -0
- package/lib/sso/serializers/index.js +19 -0
- package/lib/sso/serializers/profile-and-token.serializer.d.ts +2 -0
- package/lib/sso/serializers/profile-and-token.serializer.js +9 -0
- package/lib/sso/serializers/profile.serializer.d.ts +2 -0
- package/lib/sso/serializers/profile.serializer.js +16 -0
- package/lib/sso/sso.d.ts +3 -9
- package/lib/sso/sso.js +18 -9
- package/lib/sso/sso.spec.js +27 -9
- package/lib/users/exceptions/index.d.ts +4 -0
- package/lib/users/exceptions/index.js +10 -0
- 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 +7 -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 +21 -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 +15 -0
- package/lib/users/interfaces/authenticate-user-with-token-options.interface.js +2 -0
- package/lib/users/interfaces/authentication-response.interface.d.ts +10 -0
- package/lib/users/interfaces/authentication-response.interface.js +2 -0
- package/lib/users/interfaces/complete-password-reset-options.interface.d.ts +8 -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 +16 -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 +17 -0
- package/lib/users/interfaces/create-password-reset-challenge-options.interface.js +2 -0
- package/lib/users/interfaces/create-user-options.interface.d.ts +14 -0
- package/lib/users/interfaces/create-user-options.interface.js +2 -0
- package/lib/users/interfaces/index.d.ts +15 -0
- package/lib/users/interfaces/index.js +31 -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 +15 -0
- package/lib/users/interfaces/revoke-session-options.interface.js +2 -0
- package/lib/users/interfaces/session.interface.d.ts +12 -0
- package/lib/users/interfaces/session.interface.js +2 -0
- package/lib/users/interfaces/update-user-options.interface.d.ts +9 -0
- package/lib/users/interfaces/update-user-options.interface.js +2 -0
- package/lib/users/interfaces/update-user-password-options.interface.d.ts +7 -0
- package/lib/users/interfaces/update-user-password-options.interface.js +2 -0
- package/lib/users/interfaces/user.interface.d.ts +59 -0
- package/lib/users/interfaces/user.interface.js +2 -0
- package/lib/users/interfaces/verify-session.interface.d.ts +18 -0
- package/lib/users/interfaces/verify-session.interface.js +2 -0
- package/lib/users/serializers/authenticate-user-with-password-options.serializer.d.ts +2 -0
- package/lib/users/serializers/authenticate-user-with-password-options.serializer.js +14 -0
- package/lib/users/serializers/authenticate-user-with-token-options.serializer.d.ts +2 -0
- package/lib/users/serializers/authenticate-user-with-token-options.serializer.js +11 -0
- package/lib/users/serializers/authentication-response.serializer.d.ts +2 -0
- package/lib/users/serializers/authentication-response.serializer.js +12 -0
- package/lib/users/serializers/complete-password-reset-options.serializer.d.ts +2 -0
- package/lib/users/serializers/complete-password-reset-options.serializer.js +8 -0
- package/lib/users/serializers/create-email-verification-challenge.serializer.d.ts +2 -0
- package/lib/users/serializers/create-email-verification-challenge.serializer.js +9 -0
- package/lib/users/serializers/create-password-reset-challenge.serializer.d.ts +3 -0
- package/lib/users/serializers/create-password-reset-challenge.serializer.js +14 -0
- package/lib/users/serializers/create-user-options.serializer.d.ts +2 -0
- package/lib/users/serializers/create-user-options.serializer.js +11 -0
- package/lib/users/serializers/index.d.ts +13 -0
- package/lib/users/serializers/index.js +29 -0
- package/lib/users/serializers/revoke-session-options.serializer.d.ts +2 -0
- package/lib/users/serializers/revoke-session-options.serializer.js +14 -0
- package/lib/users/serializers/session.serializer.d.ts +2 -0
- package/lib/users/serializers/session.serializer.js +10 -0
- package/lib/users/serializers/update-user-options.serializer.d.ts +2 -0
- package/lib/users/serializers/update-user-options.serializer.js +8 -0
- package/lib/users/serializers/update-user-password-options.serializer.d.ts +2 -0
- package/lib/users/serializers/update-user-password-options.serializer.js +7 -0
- package/lib/users/serializers/user.serializer.d.ts +2 -0
- package/lib/users/serializers/user.serializer.js +31 -0
- package/lib/users/serializers/verify-session.serializer.d.ts +3 -0
- package/lib/users/serializers/verify-session.serializer.js +15 -0
- package/lib/users/users.d.ts +23 -0
- package/lib/users/users.js +124 -0
- package/lib/users/users.spec.d.ts +1 -0
- package/lib/users/users.spec.js +318 -0
- package/lib/webhooks/fixtures/webhook.json +1 -1
- package/lib/webhooks/interfaces/webhook-directory-user.interface.d.ts +2 -2
- package/lib/webhooks/interfaces/webhook.interface.d.ts +1 -0
- package/lib/workos.d.ts +6 -4
- package/lib/workos.js +3 -1
- package/package.json +13 -14
- package/lib/directory-sync/interfaces/group.interface.d.ts +0 -10
- package/lib/directory-sync/interfaces/user.interface.d.ts +0 -23
- /package/lib/{directory-sync/interfaces/group.interface.js → common/interfaces/workos-response-error.interface.js} +0 -0
- /package/lib/directory-sync/interfaces/{list-users-options.interface.js → directory-group.interface.js} +0 -0
- /package/lib/directory-sync/interfaces/{user.interface.js → directory-user.interface.js} +0 -0
|
@@ -0,0 +1,318 @@
|
|
|
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/sessions/token').reply(200, {
|
|
107
|
+
user: user_json_1.default,
|
|
108
|
+
session: session_json_1.default,
|
|
109
|
+
});
|
|
110
|
+
const resp = yield workos.users.authenticateUserWithPassword({
|
|
111
|
+
clientId: 'proj_whatever',
|
|
112
|
+
email: 'test01@example.com',
|
|
113
|
+
password: 'extra-secure',
|
|
114
|
+
});
|
|
115
|
+
expect(mock.history.post[0].url).toEqual('/users/sessions/token');
|
|
116
|
+
expect(resp).toMatchObject({
|
|
117
|
+
user: {
|
|
118
|
+
email: 'test01@example.com',
|
|
119
|
+
},
|
|
120
|
+
session: {
|
|
121
|
+
id: 'session_01H5K05VP5CPCXJA5Z7G191GS4',
|
|
122
|
+
token: 'really-long-token',
|
|
123
|
+
},
|
|
124
|
+
});
|
|
125
|
+
}));
|
|
126
|
+
});
|
|
127
|
+
describe('authenticateUserWithToken', () => {
|
|
128
|
+
it('sends a token authentication request', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
129
|
+
mock
|
|
130
|
+
.onPost('/users/sessions/token')
|
|
131
|
+
.reply(200, { user: user_json_1.default, session: session_json_1.default });
|
|
132
|
+
const resp = yield workos.users.authenticateUserWithToken({
|
|
133
|
+
clientId: 'proj_whatever',
|
|
134
|
+
code: 'or this',
|
|
135
|
+
expiresIn: 15,
|
|
136
|
+
});
|
|
137
|
+
expect(mock.history.post[0].url).toEqual('/users/sessions/token');
|
|
138
|
+
expect(JSON.parse(mock.history.post[0].data)).toMatchObject({
|
|
139
|
+
client_secret: 'sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU',
|
|
140
|
+
grant_type: 'authorization_code',
|
|
141
|
+
});
|
|
142
|
+
expect(resp).toMatchObject({
|
|
143
|
+
user: {
|
|
144
|
+
email: 'test01@example.com',
|
|
145
|
+
},
|
|
146
|
+
session: {
|
|
147
|
+
id: 'session_01H5K05VP5CPCXJA5Z7G191GS4',
|
|
148
|
+
token: 'really-long-token',
|
|
149
|
+
},
|
|
150
|
+
});
|
|
151
|
+
}));
|
|
152
|
+
});
|
|
153
|
+
describe('verifySession', () => {
|
|
154
|
+
it('sends a request to verify the session', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
155
|
+
mock.onPost('/users/sessions/verify').reply(200, {
|
|
156
|
+
user: user_json_1.default,
|
|
157
|
+
session: session_json_1.default,
|
|
158
|
+
});
|
|
159
|
+
const resp = yield workos.users.verifySession({
|
|
160
|
+
clientId: 'proj_something',
|
|
161
|
+
token: 'really-long-token',
|
|
162
|
+
});
|
|
163
|
+
expect(mock.history.post[0].url).toEqual('/users/sessions/verify');
|
|
164
|
+
expect(resp).toMatchObject({
|
|
165
|
+
user: {
|
|
166
|
+
email: 'test01@example.com',
|
|
167
|
+
},
|
|
168
|
+
session: {
|
|
169
|
+
id: 'session_01H5K05VP5CPCXJA5Z7G191GS4',
|
|
170
|
+
token: 'really-long-token',
|
|
171
|
+
},
|
|
172
|
+
});
|
|
173
|
+
}));
|
|
174
|
+
});
|
|
175
|
+
describe('revokeSession', () => {
|
|
176
|
+
it('can revoke with the session_id', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
177
|
+
mock.onPost('/users/sessions/revocations').reply(200, true);
|
|
178
|
+
const revoked = yield workos.users.revokeSession({
|
|
179
|
+
sessionId: 'session_01H5K05VP5CPCXJA5Z7G191GS4',
|
|
180
|
+
});
|
|
181
|
+
expect(mock.history.post[0].url).toEqual('/users/sessions/revocations');
|
|
182
|
+
expect(revoked).toEqual(true);
|
|
183
|
+
}));
|
|
184
|
+
it('can revoke with the session_token', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
185
|
+
mock.onPost('/users/sessions/revocations').reply(200, true);
|
|
186
|
+
const revoked = yield workos.users.revokeSession({
|
|
187
|
+
sessionToken: 'really-long-token',
|
|
188
|
+
});
|
|
189
|
+
expect(mock.history.post[0].url).toEqual('/users/sessions/revocations');
|
|
190
|
+
expect(revoked).toEqual(true);
|
|
191
|
+
}));
|
|
192
|
+
});
|
|
193
|
+
describe('revokeAllSessionsForUser', () => {
|
|
194
|
+
it('sends a revokeAllSessionsForUser request', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
195
|
+
mock.onDelete(`/users/${userId}/sessions`).reply(200, true);
|
|
196
|
+
const revoked = yield workos.users.revokeAllSessionsForUser(userId);
|
|
197
|
+
expect(mock.history.delete[0].url).toEqual(`/users/${userId}/sessions`);
|
|
198
|
+
expect(revoked).toEqual(true);
|
|
199
|
+
}));
|
|
200
|
+
});
|
|
201
|
+
describe('createEmailVerificationChallenge', () => {
|
|
202
|
+
it('sends a Create Email Verification Challenge request', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
203
|
+
mock.onPost(`/users/${userId}/email_verification_challenge`).reply(200, {
|
|
204
|
+
token: 'email-verification-challenge',
|
|
205
|
+
user: user_json_1.default,
|
|
206
|
+
});
|
|
207
|
+
const resp = yield workos.users.createEmailVerificationChallenge({
|
|
208
|
+
userId,
|
|
209
|
+
verificationUrl: 'https://example.com/verify-email',
|
|
210
|
+
});
|
|
211
|
+
expect(mock.history.post[0].url).toEqual(`/users/${userId}/email_verification_challenge`);
|
|
212
|
+
expect(resp).toMatchObject({
|
|
213
|
+
token: 'email-verification-challenge',
|
|
214
|
+
user: {
|
|
215
|
+
email: 'test01@example.com',
|
|
216
|
+
},
|
|
217
|
+
});
|
|
218
|
+
}));
|
|
219
|
+
describe('completeEmailVerification', () => {
|
|
220
|
+
it('sends a Complete Email Verification request', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
221
|
+
mock.onPost(`/users/email_verification`).reply(200, user_json_1.default);
|
|
222
|
+
const resp = yield workos.users.completeEmailVerification('email-verification-token');
|
|
223
|
+
expect(mock.history.post[0].url).toEqual(`/users/email_verification`);
|
|
224
|
+
expect(resp).toMatchObject({
|
|
225
|
+
email: 'test01@example.com',
|
|
226
|
+
});
|
|
227
|
+
}));
|
|
228
|
+
});
|
|
229
|
+
});
|
|
230
|
+
describe('createPasswordResetChallenge', () => {
|
|
231
|
+
it('sends a Create Password Reset Challenge request', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
232
|
+
mock.onPost(`/users/password_reset_challenge`).reply(200, {
|
|
233
|
+
token: 'password-reset-token',
|
|
234
|
+
user: user_json_1.default,
|
|
235
|
+
});
|
|
236
|
+
const resp = yield workos.users.createPasswordResetChallenge({
|
|
237
|
+
email: 'test01@example.com',
|
|
238
|
+
passwordResetUrl: 'https://example.com/forgot-password',
|
|
239
|
+
});
|
|
240
|
+
expect(mock.history.post[0].url).toEqual(`/users/password_reset_challenge`);
|
|
241
|
+
expect(resp).toMatchObject({
|
|
242
|
+
token: 'password-reset-token',
|
|
243
|
+
user: {
|
|
244
|
+
email: 'test01@example.com',
|
|
245
|
+
},
|
|
246
|
+
});
|
|
247
|
+
}));
|
|
248
|
+
});
|
|
249
|
+
describe('completePasswordReset', () => {
|
|
250
|
+
it('sends a completePasswordReset request', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
251
|
+
mock.onPost(`/users/password_reset`).reply(200, user_json_1.default);
|
|
252
|
+
const resp = yield workos.users.completePasswordReset({
|
|
253
|
+
token: '',
|
|
254
|
+
newPassword: 'correct horse battery staple',
|
|
255
|
+
});
|
|
256
|
+
expect(mock.history.post[0].url).toEqual(`/users/password_reset`);
|
|
257
|
+
expect(resp).toMatchObject({
|
|
258
|
+
email: 'test01@example.com',
|
|
259
|
+
});
|
|
260
|
+
}));
|
|
261
|
+
});
|
|
262
|
+
describe('addUserToOrganization', () => {
|
|
263
|
+
it('sends a addUserToOrganization request', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
264
|
+
mock.onPost(`/users/${userId}/organizations`).reply(200, user_json_1.default);
|
|
265
|
+
const resp = yield workos.users.addUserToOrganization({
|
|
266
|
+
userId,
|
|
267
|
+
organizationId: 'org_coolorg',
|
|
268
|
+
});
|
|
269
|
+
expect(mock.history.post[0].url).toEqual(`/users/${userId}/organizations`);
|
|
270
|
+
expect(resp).toMatchObject({
|
|
271
|
+
email: 'test01@example.com',
|
|
272
|
+
});
|
|
273
|
+
}));
|
|
274
|
+
});
|
|
275
|
+
describe('removeUserFromOrganization', () => {
|
|
276
|
+
it('sends a removeUserFromOrganization request', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
277
|
+
const orgId = 'org_coolorg';
|
|
278
|
+
mock
|
|
279
|
+
.onDelete(`/users/${userId}/organizations/${orgId}`)
|
|
280
|
+
.reply(200, user_json_1.default);
|
|
281
|
+
const resp = yield workos.users.removeUserFromOrganization({
|
|
282
|
+
userId,
|
|
283
|
+
organizationId: orgId,
|
|
284
|
+
});
|
|
285
|
+
expect(mock.history.delete[0].url).toEqual(`/users/${userId}/organizations/${orgId}`);
|
|
286
|
+
expect(resp).toMatchObject({
|
|
287
|
+
email: 'test01@example.com',
|
|
288
|
+
});
|
|
289
|
+
}));
|
|
290
|
+
});
|
|
291
|
+
describe('updateUser', () => {
|
|
292
|
+
it('sends a updateUser request', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
293
|
+
mock.onPut(`/users/${userId}`).reply(200, user_json_1.default);
|
|
294
|
+
const resp = yield workos.users.updateUser({
|
|
295
|
+
userId,
|
|
296
|
+
firstName: 'Dane',
|
|
297
|
+
lastName: 'Williams',
|
|
298
|
+
});
|
|
299
|
+
expect(mock.history.put[0].url).toEqual(`/users/${userId}`);
|
|
300
|
+
expect(resp).toMatchObject({
|
|
301
|
+
email: 'test01@example.com',
|
|
302
|
+
});
|
|
303
|
+
}));
|
|
304
|
+
});
|
|
305
|
+
describe('updateUserPassword', () => {
|
|
306
|
+
it('sends a updateUserPassword request', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
307
|
+
mock.onPut(`/users/${userId}/password`).reply(200, user_json_1.default);
|
|
308
|
+
const resp = yield workos.users.updateUserPassword({
|
|
309
|
+
userId,
|
|
310
|
+
password: 'secure',
|
|
311
|
+
});
|
|
312
|
+
expect(mock.history.put[0].url).toEqual(`/users/${userId}/password`);
|
|
313
|
+
expect(resp).toMatchObject({
|
|
314
|
+
email: 'test01@example.com',
|
|
315
|
+
});
|
|
316
|
+
}));
|
|
317
|
+
});
|
|
318
|
+
});
|
|
@@ -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 {
|
|
2
|
-
export interface WebhookDirectoryUser extends
|
|
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:
|
|
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 = '
|
|
30
|
+
const VERSION = '3.0.0-alpha.2';
|
|
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-alpha.2",
|
|
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.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": "
|
|
50
|
+
"typescript": "5.1.6"
|
|
52
51
|
}
|
|
53
52
|
}
|
|
@@ -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
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|