@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
package/lib/sso/sso.d.ts
CHANGED
|
@@ -1,12 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DeserializedList } from '../common/interfaces';
|
|
2
2
|
import { WorkOS } from '../workos';
|
|
3
|
-
import { AuthorizationURLOptions } from './interfaces
|
|
4
|
-
import { Connection } from './interfaces/connection.interface';
|
|
5
|
-
import { GetProfileAndTokenOptions } from './interfaces/get-profile-and-token-options.interface';
|
|
6
|
-
import { GetProfileOptions } from './interfaces/get-profile-options.interface';
|
|
7
|
-
import { ListConnectionsOptions } from './interfaces/list-connections-options.interface';
|
|
8
|
-
import { ProfileAndToken } from './interfaces/profile-and-token.interface';
|
|
9
|
-
import { Profile } from './interfaces/profile.interface';
|
|
3
|
+
import { AuthorizationURLOptions, Connection, GetProfileAndTokenOptions, GetProfileOptions, ListConnectionsOptions, Profile, ProfileAndToken } from './interfaces';
|
|
10
4
|
export declare class SSO {
|
|
11
5
|
private readonly workos;
|
|
12
6
|
constructor(workos: WorkOS);
|
|
@@ -15,5 +9,5 @@ export declare class SSO {
|
|
|
15
9
|
getConnection(id: string): Promise<Connection>;
|
|
16
10
|
getProfileAndToken({ code, clientID, }: GetProfileAndTokenOptions): Promise<ProfileAndToken>;
|
|
17
11
|
getProfile({ accessToken }: GetProfileOptions): Promise<Profile>;
|
|
18
|
-
listConnections(options?: ListConnectionsOptions): Promise<
|
|
12
|
+
listConnections(options?: ListConnectionsOptions): Promise<DeserializedList<Connection>>;
|
|
19
13
|
}
|
package/lib/sso/sso.js
CHANGED
|
@@ -8,12 +8,21 @@ 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 serializers_1 = require("../common/serializers");
|
|
14
|
+
const serializers_2 = require("./serializers");
|
|
15
|
+
const toQueryString = (options) => {
|
|
16
|
+
const searchParams = new URLSearchParams();
|
|
17
|
+
const keys = Object.keys(options).sort();
|
|
18
|
+
for (const key of keys) {
|
|
19
|
+
const value = options[key];
|
|
20
|
+
if (value) {
|
|
21
|
+
searchParams.append(key, value);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return searchParams.toString();
|
|
25
|
+
};
|
|
17
26
|
class SSO {
|
|
18
27
|
constructor(workos) {
|
|
19
28
|
this.workos = workos;
|
|
@@ -30,7 +39,7 @@ class SSO {
|
|
|
30
39
|
if (domain) {
|
|
31
40
|
this.workos.emitWarning('The `domain` parameter for `getAuthorizationURL` is deprecated. Please use `organization` instead.');
|
|
32
41
|
}
|
|
33
|
-
const query =
|
|
42
|
+
const query = toQueryString({
|
|
34
43
|
connection,
|
|
35
44
|
organization,
|
|
36
45
|
domain,
|
|
@@ -47,7 +56,7 @@ class SSO {
|
|
|
47
56
|
getConnection(id) {
|
|
48
57
|
return __awaiter(this, void 0, void 0, function* () {
|
|
49
58
|
const { data } = yield this.workos.get(`/connections/${id}`);
|
|
50
|
-
return data;
|
|
59
|
+
return (0, serializers_2.deserializeConnection)(data);
|
|
51
60
|
});
|
|
52
61
|
}
|
|
53
62
|
getProfileAndToken({ code, clientID, }) {
|
|
@@ -59,7 +68,7 @@ class SSO {
|
|
|
59
68
|
code,
|
|
60
69
|
});
|
|
61
70
|
const { data } = yield this.workos.post('/sso/token', form);
|
|
62
|
-
return data;
|
|
71
|
+
return (0, serializers_2.deserializeProfileAndToken)(data);
|
|
63
72
|
});
|
|
64
73
|
}
|
|
65
74
|
getProfile({ accessToken }) {
|
|
@@ -67,7 +76,7 @@ class SSO {
|
|
|
67
76
|
const { data } = yield this.workos.get('/sso/profile', {
|
|
68
77
|
accessToken,
|
|
69
78
|
});
|
|
70
|
-
return data;
|
|
79
|
+
return (0, serializers_2.deserializeProfile)(data);
|
|
71
80
|
});
|
|
72
81
|
}
|
|
73
82
|
listConnections(options) {
|
|
@@ -75,7 +84,7 @@ class SSO {
|
|
|
75
84
|
const { data } = yield this.workos.get(`/connections`, {
|
|
76
85
|
query: options,
|
|
77
86
|
});
|
|
78
|
-
return data;
|
|
87
|
+
return (0, serializers_1.deserializeList)(data, serializers_2.deserializeConnection);
|
|
79
88
|
});
|
|
80
89
|
}
|
|
81
90
|
}
|
package/lib/sso/sso.spec.js
CHANGED
|
@@ -15,7 +15,20 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
15
15
|
const axios_1 = __importDefault(require("axios"));
|
|
16
16
|
const axios_mock_adapter_1 = __importDefault(require("axios-mock-adapter"));
|
|
17
17
|
const workos_1 = require("../workos");
|
|
18
|
+
const interfaces_1 = require("./interfaces");
|
|
18
19
|
describe('SSO', () => {
|
|
20
|
+
const connectionResponse = {
|
|
21
|
+
object: 'connection',
|
|
22
|
+
id: 'conn_123',
|
|
23
|
+
organization_id: 'org_123',
|
|
24
|
+
name: 'Connection',
|
|
25
|
+
connection_type: interfaces_1.ConnectionType.OktaSAML,
|
|
26
|
+
state: 'active',
|
|
27
|
+
status: 'linked',
|
|
28
|
+
domains: [],
|
|
29
|
+
created_at: '2023-07-17T20:07:20.055Z',
|
|
30
|
+
updated_at: '2023-07-17T20:07:20.055Z',
|
|
31
|
+
};
|
|
19
32
|
describe('SSO', () => {
|
|
20
33
|
describe('getAuthorizationURL', () => {
|
|
21
34
|
describe('with no custom api hostname', () => {
|
|
@@ -113,7 +126,7 @@ describe('SSO', () => {
|
|
|
113
126
|
redirectURI: 'example.com/sso/workos/callback',
|
|
114
127
|
state: 'custom state',
|
|
115
128
|
});
|
|
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
|
|
129
|
+
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
130
|
});
|
|
118
131
|
});
|
|
119
132
|
describe('with loginHint', () => {
|
|
@@ -126,7 +139,7 @@ describe('SSO', () => {
|
|
|
126
139
|
redirectURI: 'example.com/sso/workos/callback',
|
|
127
140
|
state: 'custom state',
|
|
128
141
|
});
|
|
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
|
|
142
|
+
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
143
|
});
|
|
131
144
|
});
|
|
132
145
|
});
|
|
@@ -172,7 +185,7 @@ describe('SSO', () => {
|
|
|
172
185
|
return [404];
|
|
173
186
|
});
|
|
174
187
|
const workos = new workos_1.WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU');
|
|
175
|
-
const {
|
|
188
|
+
const { accessToken, profile } = yield workos.sso.getProfileAndToken({
|
|
176
189
|
code: 'authorization_code',
|
|
177
190
|
clientID: 'proj_123',
|
|
178
191
|
});
|
|
@@ -223,7 +236,7 @@ describe('SSO', () => {
|
|
|
223
236
|
return [404];
|
|
224
237
|
});
|
|
225
238
|
const workos = new workos_1.WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU');
|
|
226
|
-
const {
|
|
239
|
+
const { accessToken, profile } = yield workos.sso.getProfileAndToken({
|
|
227
240
|
code: 'authorization_code',
|
|
228
241
|
clientID: 'proj_123',
|
|
229
242
|
});
|
|
@@ -266,7 +279,7 @@ describe('SSO', () => {
|
|
|
266
279
|
});
|
|
267
280
|
expect(mock.history.get.length).toBe(1);
|
|
268
281
|
const { headers } = mock.history.get[0];
|
|
269
|
-
expect(headers.Authorization).toBe(`Bearer access_token`);
|
|
282
|
+
expect(headers === null || headers === void 0 ? void 0 : headers.Authorization).toBe(`Bearer access_token`);
|
|
270
283
|
expect(profile.id).toBe('prof_123');
|
|
271
284
|
}));
|
|
272
285
|
});
|
|
@@ -282,19 +295,24 @@ describe('SSO', () => {
|
|
|
282
295
|
describe('getConnection', () => {
|
|
283
296
|
it(`requests a Connection`, () => __awaiter(void 0, void 0, void 0, function* () {
|
|
284
297
|
const mock = new axios_mock_adapter_1.default(axios_1.default);
|
|
285
|
-
mock.onGet('/connections/conn_123').replyOnce(200,
|
|
298
|
+
mock.onGet('/connections/conn_123').replyOnce(200, connectionResponse);
|
|
286
299
|
const workos = new workos_1.WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU');
|
|
287
|
-
yield workos.sso.getConnection('conn_123');
|
|
300
|
+
const subject = yield workos.sso.getConnection('conn_123');
|
|
288
301
|
expect(mock.history.get[0].url).toEqual('/connections/conn_123');
|
|
302
|
+
expect(subject.connectionType).toEqual('OktaSAML');
|
|
289
303
|
}));
|
|
290
304
|
});
|
|
291
305
|
describe('listConnections', () => {
|
|
292
306
|
it(`requests a list of Connections`, () => __awaiter(void 0, void 0, void 0, function* () {
|
|
293
307
|
const mock = new axios_mock_adapter_1.default(axios_1.default);
|
|
294
|
-
mock.onGet('/connections').replyOnce(200, {
|
|
308
|
+
mock.onGet('/connections').replyOnce(200, {
|
|
309
|
+
data: [connectionResponse],
|
|
310
|
+
list_metadata: {},
|
|
311
|
+
});
|
|
295
312
|
const workos = new workos_1.WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU');
|
|
296
|
-
yield workos.sso.listConnections();
|
|
313
|
+
const subject = yield workos.sso.listConnections();
|
|
297
314
|
expect(mock.history.get[0].url).toEqual('/connections');
|
|
315
|
+
expect(subject.data).toHaveLength(1);
|
|
298
316
|
}));
|
|
299
317
|
});
|
|
300
318
|
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UnexpectedUserTypeException = void 0;
|
|
4
|
+
class UnexpectedUserTypeException extends Error {
|
|
5
|
+
constructor(user) {
|
|
6
|
+
super();
|
|
7
|
+
this.message = `Unsupported user type: ${user.user_type} received from API.`;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
exports.UnexpectedUserTypeException = UnexpectedUserTypeException;
|
|
@@ -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,21 @@
|
|
|
1
|
+
export interface AuthenticateUserWithPasswordOptions {
|
|
2
|
+
clientId: string;
|
|
3
|
+
email: string;
|
|
4
|
+
password: string;
|
|
5
|
+
ipAddress?: string;
|
|
6
|
+
userAgent?: string;
|
|
7
|
+
expiresIn?: number;
|
|
8
|
+
}
|
|
9
|
+
export interface AuthenticateUserWithPasswordCredentials {
|
|
10
|
+
clientSecret: string | undefined;
|
|
11
|
+
}
|
|
12
|
+
export interface SerializedAuthenticateUserWithPasswordOptions {
|
|
13
|
+
grant_type: 'password';
|
|
14
|
+
client_id: string;
|
|
15
|
+
client_secret: string | undefined;
|
|
16
|
+
email: string;
|
|
17
|
+
password: string;
|
|
18
|
+
ip_address?: string;
|
|
19
|
+
user_agent?: string;
|
|
20
|
+
expires_in?: number;
|
|
21
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export interface AuthenticateUserWithTokenOptions {
|
|
2
|
+
clientId: string;
|
|
3
|
+
code: string;
|
|
4
|
+
expiresIn?: number;
|
|
5
|
+
}
|
|
6
|
+
export interface AuthenticateUserWithTokenCredentials {
|
|
7
|
+
clientSecret: string | undefined;
|
|
8
|
+
}
|
|
9
|
+
export interface SerializedAuthenticateUserWithTokenOptions {
|
|
10
|
+
grant_type: 'authorization_code';
|
|
11
|
+
client_id: string;
|
|
12
|
+
client_secret: string | undefined;
|
|
13
|
+
code: string;
|
|
14
|
+
expires_in?: number;
|
|
15
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { User, UserResponse } from './user.interface';
|
|
2
|
+
import { Session, SessionResponse } from './session.interface';
|
|
3
|
+
export interface AuthenticationResponse {
|
|
4
|
+
session?: Session;
|
|
5
|
+
user: User;
|
|
6
|
+
}
|
|
7
|
+
export interface AuthenticationResponseResponse {
|
|
8
|
+
session?: SessionResponse;
|
|
9
|
+
user: UserResponse;
|
|
10
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { User, UserResponse } from './user.interface';
|
|
2
|
+
export interface CreateEmailVerificationChallengeOptions {
|
|
3
|
+
userId: string;
|
|
4
|
+
verificationUrl: string;
|
|
5
|
+
}
|
|
6
|
+
export interface SerializedCreateEmailVerificationChallengeOptions {
|
|
7
|
+
verification_url: string;
|
|
8
|
+
}
|
|
9
|
+
export interface CreateEmailVerificationChallengeResponse {
|
|
10
|
+
token: string;
|
|
11
|
+
user: User;
|
|
12
|
+
}
|
|
13
|
+
export interface CreateEmailVerificationChallengeResponseResponse {
|
|
14
|
+
token: string;
|
|
15
|
+
user: UserResponse;
|
|
16
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { User, UserResponse } from './user.interface';
|
|
2
|
+
export interface CreatePasswordResetChallengeOptions {
|
|
3
|
+
email: string;
|
|
4
|
+
passwordResetUrl: string;
|
|
5
|
+
}
|
|
6
|
+
export interface SerializedCreatePasswordResetChallengeOptions {
|
|
7
|
+
email: string;
|
|
8
|
+
password_reset_url: string;
|
|
9
|
+
}
|
|
10
|
+
export interface CreatePasswordResetChallengeResponse {
|
|
11
|
+
token: string;
|
|
12
|
+
user: User;
|
|
13
|
+
}
|
|
14
|
+
export interface CreatePasswordResetChallengeResponseResponse {
|
|
15
|
+
token: string;
|
|
16
|
+
user: UserResponse;
|
|
17
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface CreateUserOptions {
|
|
2
|
+
email: string;
|
|
3
|
+
password: string;
|
|
4
|
+
firstName?: string;
|
|
5
|
+
lastName?: string;
|
|
6
|
+
emailVerified?: boolean;
|
|
7
|
+
}
|
|
8
|
+
export interface SerializedCreateUserOptions {
|
|
9
|
+
email: string;
|
|
10
|
+
password: string;
|
|
11
|
+
first_name?: string;
|
|
12
|
+
last_name?: string;
|
|
13
|
+
email_verified?: boolean;
|
|
14
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
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';
|
|
14
|
+
export * from './update-user-password-options.interface';
|
|
15
|
+
export * from './update-user-options.interface';
|
|
@@ -0,0 +1,31 @@
|
|
|
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);
|
|
30
|
+
__exportStar(require("./update-user-password-options.interface"), exports);
|
|
31
|
+
__exportStar(require("./update-user-options.interface"), exports);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export type RevokeSessionOptions = SessionId | SessionToken;
|
|
2
|
+
export type SerializedRevokeSessionOptions = SerializedSessionId | SerializedSessionToken;
|
|
3
|
+
interface SessionId {
|
|
4
|
+
sessionId: string;
|
|
5
|
+
}
|
|
6
|
+
interface SerializedSessionId {
|
|
7
|
+
session_id: string;
|
|
8
|
+
}
|
|
9
|
+
interface SessionToken {
|
|
10
|
+
sessionToken: string;
|
|
11
|
+
}
|
|
12
|
+
interface SerializedSessionToken {
|
|
13
|
+
session_token: string;
|
|
14
|
+
}
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
export type User = ManagedUser | UnmanagedUser;
|
|
2
|
+
export type UserResponse = ManagedUserResponse | UnmanagedUserResponse;
|
|
3
|
+
interface ManagedUser extends BaseUser {
|
|
4
|
+
userType: 'managed';
|
|
5
|
+
organizationMemberships: [OrganizationMembership];
|
|
6
|
+
ssoProfileId: string | null;
|
|
7
|
+
}
|
|
8
|
+
interface ManagedUserResponse extends BaseUserResponse {
|
|
9
|
+
user_type: 'managed';
|
|
10
|
+
organization_memberships: [OrganizationMembershipResponse];
|
|
11
|
+
sso_profile_id: string | null;
|
|
12
|
+
}
|
|
13
|
+
interface UnmanagedUser extends BaseUser {
|
|
14
|
+
userType: 'unmanaged';
|
|
15
|
+
organizationMemberships: OrganizationMembership[];
|
|
16
|
+
emailVerifiedAt: string | null;
|
|
17
|
+
googleOauthProfileId: string | null;
|
|
18
|
+
microsoftOauthProfileId: string | null;
|
|
19
|
+
}
|
|
20
|
+
interface UnmanagedUserResponse extends BaseUserResponse {
|
|
21
|
+
user_type: 'unmanaged';
|
|
22
|
+
organization_memberships: OrganizationMembershipResponse[];
|
|
23
|
+
email_verified_at: string | null;
|
|
24
|
+
google_oauth_profile_id: string | null;
|
|
25
|
+
microsoft_oauth_profile_id: string | null;
|
|
26
|
+
}
|
|
27
|
+
export interface BaseUser {
|
|
28
|
+
object: 'user';
|
|
29
|
+
id: string;
|
|
30
|
+
email: string;
|
|
31
|
+
firstName: string | null;
|
|
32
|
+
lastName: string | null;
|
|
33
|
+
createdAt: string;
|
|
34
|
+
updatedAt: string;
|
|
35
|
+
}
|
|
36
|
+
interface BaseUserResponse {
|
|
37
|
+
object: 'user';
|
|
38
|
+
id: string;
|
|
39
|
+
email: string;
|
|
40
|
+
first_name: string | null;
|
|
41
|
+
last_name: string | null;
|
|
42
|
+
created_at: string;
|
|
43
|
+
updated_at: string;
|
|
44
|
+
}
|
|
45
|
+
export interface OrganizationMembership {
|
|
46
|
+
organization: OrganizationSummary;
|
|
47
|
+
createdAt: string;
|
|
48
|
+
updatedAt: string;
|
|
49
|
+
}
|
|
50
|
+
export interface OrganizationMembershipResponse {
|
|
51
|
+
organization: OrganizationSummary;
|
|
52
|
+
created_at: string;
|
|
53
|
+
updated_at: string;
|
|
54
|
+
}
|
|
55
|
+
interface OrganizationSummary {
|
|
56
|
+
id: string;
|
|
57
|
+
name: string;
|
|
58
|
+
}
|
|
59
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { User, UserResponse } from './user.interface';
|
|
2
|
+
import { Session, SessionResponse } from './session.interface';
|
|
3
|
+
export interface VerifySessionOptions {
|
|
4
|
+
token: string;
|
|
5
|
+
clientId: string;
|
|
6
|
+
}
|
|
7
|
+
export interface SerializedVerifySessionOptions {
|
|
8
|
+
token: string;
|
|
9
|
+
client_id: string;
|
|
10
|
+
}
|
|
11
|
+
export interface VerifySessionResponse {
|
|
12
|
+
session: Session;
|
|
13
|
+
user: User;
|
|
14
|
+
}
|
|
15
|
+
export interface VerifySessionResponseResponse {
|
|
16
|
+
session: SessionResponse;
|
|
17
|
+
user: UserResponse;
|
|
18
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { AuthenticateUserWithPasswordCredentials, AuthenticateUserWithPasswordOptions, SerializedAuthenticateUserWithPasswordOptions } from '../interfaces';
|
|
2
|
+
export declare const serializeAuthenticateUserWithPasswordOptions: (options: AuthenticateUserWithPasswordOptions & AuthenticateUserWithPasswordCredentials) => SerializedAuthenticateUserWithPasswordOptions;
|