@workos-inc/node 3.0.0-user-management.2 → 3.0.0
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.d.ts +2 -2
- package/lib/audit-trail/audit-trail.spec.js +2 -1
- package/lib/common/interfaces/at-least-one-property-of.interface.d.ts +7 -0
- package/lib/common/interfaces/event.interface.d.ts +142 -0
- package/lib/common/interfaces/index.d.ts +5 -0
- package/lib/common/interfaces/index.js +5 -0
- package/lib/common/interfaces/list.interface.d.ts +9 -1
- package/lib/common/interfaces/workos-response-error.interface.d.ts +8 -0
- package/lib/common/serializers/event.serializer.d.ts +2 -0
- package/lib/common/serializers/event.serializer.js +40 -0
- package/lib/common/serializers/index.d.ts +2 -0
- package/lib/common/serializers/index.js +18 -0
- package/lib/common/serializers/list.serializer.d.ts +2 -0
- package/lib/common/serializers/list.serializer.js +9 -0
- package/lib/common/utils/fetch-and-deserialize.d.ts +3 -0
- package/lib/common/utils/fetch-and-deserialize.js +23 -0
- package/lib/common/utils/pagination.d.ts +15 -0
- package/lib/common/utils/pagination.js +90 -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 +8 -12
- package/lib/directory-sync/directory-sync.js +9 -15
- package/lib/directory-sync/directory-sync.spec.js +132 -20
- package/lib/directory-sync/interfaces/directory-group.interface.d.ts +40 -0
- package/lib/directory-sync/interfaces/directory-user.interface.d.ts +50 -0
- package/lib/directory-sync/interfaces/directory.interface.d.ts +47 -2
- 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-groups-options.interface.d.ts +1 -1
- package/lib/directory-sync/serializers/directory-group.serializer.d.ts +4 -0
- package/lib/directory-sync/serializers/directory-group.serializer.js +37 -0
- package/lib/directory-sync/serializers/directory-user.serializer.d.ts +4 -0
- package/lib/directory-sync/serializers/directory-user.serializer.js +43 -0
- package/lib/directory-sync/serializers/directory.serializer.d.ts +5 -0
- package/lib/directory-sync/serializers/directory.serializer.js +50 -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 +11 -8
- package/lib/events/events.d.ts +1 -2
- package/lib/events/events.js +2 -1
- package/lib/events/events.spec.js +39 -5
- package/lib/events/interfaces/index.d.ts +0 -1
- package/lib/events/interfaces/index.js +0 -1
- package/lib/events/interfaces/list-events-options.interface.d.ts +4 -4
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -1
- 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/{webhooks/interfaces → mfa/serializers}/index.js +3 -4
- 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 +9 -9
- package/lib/organizations/organizations.spec.js +11 -4
- 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 +16 -5
- 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 +16 -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 +23 -16
- package/lib/sso/sso.spec.js +26 -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 +0 -1
- package/lib/users/fixtures/session.json +2 -0
- package/lib/users/fixtures/user.json +0 -1
- package/lib/users/interfaces/add-user-to-organization-options.interface.d.ts +4 -1
- package/lib/users/interfaces/authenticate-user-with-magic-auth-options.interface.d.ts +21 -0
- package/lib/users/interfaces/authenticate-user-with-password-options.interface.d.ts +14 -1
- package/lib/users/interfaces/authenticate-user-with-token-options.interface.d.ts +10 -1
- package/lib/users/interfaces/authentication-response.interface.d.ts +7 -3
- package/lib/users/interfaces/complete-password-reset-options.interface.d.ts +4 -0
- package/lib/users/interfaces/create-email-verification-challenge-options.interface.d.ts +9 -2
- package/lib/users/interfaces/create-password-reset-challenge-options.interface.d.ts +9 -1
- package/lib/users/interfaces/create-user-options.interface.d.ts +8 -1
- package/lib/users/interfaces/index.d.ts +7 -0
- package/lib/users/interfaces/index.js +7 -0
- package/lib/users/interfaces/magic-auth-challenge.interface.d.ts +3 -0
- package/lib/users/interfaces/remove-user-from-organization-options.interface.d.ts +2 -2
- package/lib/users/interfaces/revoke-all-sessions-for-user-options.interface.d.ts +3 -0
- package/lib/users/interfaces/revoke-all-sessions-for-user-options.interface.js +2 -0
- package/lib/users/interfaces/revoke-session-options.interface.d.ts +7 -0
- package/lib/users/interfaces/send-magic-auth-code-options.interface.d.ts +6 -0
- package/lib/users/interfaces/send-magic-auth-code-options.interface.js +2 -0
- package/lib/users/interfaces/session.interface.d.ts +35 -0
- package/lib/users/interfaces/update-user-options.interface.d.ts +14 -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 +28 -18
- package/lib/users/interfaces/verify-session.interface.d.ts +10 -2
- package/lib/users/serializers/authenticate-user-with-magic-auth-options.serializer.d.ts +2 -0
- package/lib/users/serializers/authenticate-user-with-magic-auth-options.serializer.js +14 -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 +10 -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 +15 -0
- package/lib/users/serializers/index.js +31 -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/send-magic-auth-code-options.serializer.d.ts +2 -0
- package/lib/users/serializers/send-magic-auth-code-options.serializer.js +7 -0
- package/lib/users/serializers/session.serializer.d.ts +4 -0
- package/lib/users/serializers/session.serializer.js +22 -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 +24 -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 +11 -7
- package/lib/users/users.js +54 -30
- package/lib/users/users.spec.js +133 -49
- package/lib/webhooks/fixtures/webhook.json +67 -1
- package/lib/webhooks/webhooks.d.ts +2 -2
- package/lib/webhooks/webhooks.js +2 -1
- package/lib/webhooks/webhooks.spec.js +8 -6
- package/lib/workos.d.ts +5 -4
- package/lib/workos.js +4 -1
- package/lib/workos.spec.js +11 -1
- package/package.json +14 -15
- package/lib/directory-sync/interfaces/group.interface.d.ts +0 -10
- package/lib/directory-sync/interfaces/user.interface.d.ts +0 -23
- package/lib/events/interfaces/event.interface.d.ts +0 -63
- package/lib/webhooks/interfaces/index.d.ts +0 -4
- package/lib/webhooks/interfaces/webhook-directory-group.interface.d.ts +0 -10
- package/lib/webhooks/interfaces/webhook-directory-user.interface.d.ts +0 -5
- package/lib/webhooks/interfaces/webhook-directory.interface.d.ts +0 -20
- package/lib/webhooks/interfaces/webhook.interface.d.ts +0 -73
- /package/lib/{directory-sync/interfaces/group.interface.js → common/interfaces/at-least-one-property-of.interface.js} +0 -0
- /package/lib/{events → common}/interfaces/event.interface.js +0 -0
- /package/lib/{directory-sync/interfaces/list-users-options.interface.js → common/interfaces/workos-response-error.interface.js} +0 -0
- /package/lib/directory-sync/interfaces/{user.interface.js → directory-group.interface.js} +0 -0
- /package/lib/{webhooks/interfaces/webhook-directory-group.interface.js → directory-sync/interfaces/directory-user.interface.js} +0 -0
- /package/lib/{webhooks/interfaces/webhook-directory-user.interface.js → directory-sync/interfaces/list-directory-users-options.interface.js} +0 -0
- /package/lib/{webhooks/interfaces/webhook-directory.interface.js → users/interfaces/authenticate-user-with-magic-auth-options.interface.js} +0 -0
- /package/lib/{webhooks/interfaces/webhook.interface.js → users/interfaces/magic-auth-challenge.interface.js} +0 -0
package/lib/mfa/mfa.spec.js
CHANGED
|
@@ -16,19 +16,46 @@ const axios_1 = __importDefault(require("axios"));
|
|
|
16
16
|
const axios_mock_adapter_1 = __importDefault(require("axios-mock-adapter"));
|
|
17
17
|
const exceptions_1 = require("../common/exceptions");
|
|
18
18
|
const workos_1 = require("../workos");
|
|
19
|
+
const mock = new axios_mock_adapter_1.default(axios_1.default);
|
|
19
20
|
describe('MFA', () => {
|
|
20
21
|
describe('getFactor', () => {
|
|
21
|
-
it('
|
|
22
|
-
const
|
|
23
|
-
|
|
22
|
+
it('returns the requested factor', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
23
|
+
const factor = {
|
|
24
|
+
object: 'authentication_factor',
|
|
25
|
+
id: 'auth_factor_1234',
|
|
26
|
+
createdAt: '2022-03-15T20:39:19.892Z',
|
|
27
|
+
updatedAt: '2022-03-15T20:39:19.892Z',
|
|
28
|
+
type: 'totp',
|
|
29
|
+
totp: {
|
|
30
|
+
issuer: 'WorkOS',
|
|
31
|
+
qrCode: 'qr-code-test',
|
|
32
|
+
secret: 'secret-test',
|
|
33
|
+
uri: 'uri-test',
|
|
34
|
+
user: 'some_user',
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
const factorResponse = {
|
|
38
|
+
object: 'authentication_factor',
|
|
39
|
+
id: 'auth_factor_1234',
|
|
40
|
+
created_at: '2022-03-15T20:39:19.892Z',
|
|
41
|
+
updated_at: '2022-03-15T20:39:19.892Z',
|
|
42
|
+
type: 'totp',
|
|
43
|
+
totp: {
|
|
44
|
+
issuer: 'WorkOS',
|
|
45
|
+
qr_code: 'qr-code-test',
|
|
46
|
+
secret: 'secret-test',
|
|
47
|
+
uri: 'uri-test',
|
|
48
|
+
user: 'some_user',
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
mock.onGet().reply(200, factorResponse);
|
|
24
52
|
const workos = new workos_1.WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU');
|
|
25
|
-
const
|
|
26
|
-
expect(
|
|
53
|
+
const subject = yield workos.mfa.getFactor('test_123');
|
|
54
|
+
expect(subject).toEqual(factor);
|
|
27
55
|
}));
|
|
28
56
|
});
|
|
29
57
|
describe('deleteFactor', () => {
|
|
30
58
|
it('sends request to delete a Factor', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
31
|
-
const mock = new axios_mock_adapter_1.default(axios_1.default);
|
|
32
59
|
mock.onDelete().reply(200, {});
|
|
33
60
|
const workos = new workos_1.WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU');
|
|
34
61
|
yield workos.mfa.deleteFactor('conn_123');
|
|
@@ -38,35 +65,47 @@ describe('MFA', () => {
|
|
|
38
65
|
describe('enrollFactor', () => {
|
|
39
66
|
describe('with generic', () => {
|
|
40
67
|
it('enrolls a factor with generic type', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
41
|
-
const
|
|
42
|
-
|
|
68
|
+
const factor = {
|
|
69
|
+
object: 'authentication_factor',
|
|
70
|
+
id: 'auth_factor_1234',
|
|
71
|
+
createdAt: '2022-03-15T20:39:19.892Z',
|
|
72
|
+
updatedAt: '2022-03-15T20:39:19.892Z',
|
|
73
|
+
type: 'generic_otp',
|
|
74
|
+
};
|
|
75
|
+
const factorResponse = {
|
|
43
76
|
object: 'authentication_factor',
|
|
44
77
|
id: 'auth_factor_1234',
|
|
45
78
|
created_at: '2022-03-15T20:39:19.892Z',
|
|
46
79
|
updated_at: '2022-03-15T20:39:19.892Z',
|
|
47
80
|
type: 'generic_otp',
|
|
48
|
-
}
|
|
81
|
+
};
|
|
82
|
+
mock.onPost('/auth/factors/enroll').reply(200, factorResponse);
|
|
49
83
|
const workos = new workos_1.WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU', {
|
|
50
84
|
apiHostname: 'api.workos.dev',
|
|
51
85
|
});
|
|
52
|
-
const
|
|
86
|
+
const subject = yield workos.mfa.enrollFactor({
|
|
53
87
|
type: 'generic_otp',
|
|
54
88
|
});
|
|
55
|
-
expect(
|
|
56
|
-
Object {
|
|
57
|
-
"created_at": "2022-03-15T20:39:19.892Z",
|
|
58
|
-
"id": "auth_factor_1234",
|
|
59
|
-
"object": "authentication_factor",
|
|
60
|
-
"type": "generic_otp",
|
|
61
|
-
"updated_at": "2022-03-15T20:39:19.892Z",
|
|
62
|
-
}
|
|
63
|
-
`);
|
|
89
|
+
expect(subject).toEqual(factor);
|
|
64
90
|
}));
|
|
65
91
|
});
|
|
66
92
|
describe('with totp', () => {
|
|
67
93
|
it('enrolls a factor with totp type', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
68
|
-
const
|
|
69
|
-
|
|
94
|
+
const factor = {
|
|
95
|
+
object: 'authentication_factor',
|
|
96
|
+
id: 'auth_factor_1234',
|
|
97
|
+
createdAt: '2022-03-15T20:39:19.892Z',
|
|
98
|
+
updatedAt: '2022-03-15T20:39:19.892Z',
|
|
99
|
+
type: 'totp',
|
|
100
|
+
totp: {
|
|
101
|
+
issuer: 'WorkOS',
|
|
102
|
+
qrCode: 'qr-code-test',
|
|
103
|
+
secret: 'secret-test',
|
|
104
|
+
uri: 'uri-test',
|
|
105
|
+
user: 'some_user',
|
|
106
|
+
},
|
|
107
|
+
};
|
|
108
|
+
const factorResponse = {
|
|
70
109
|
object: 'authentication_factor',
|
|
71
110
|
id: 'auth_factor_1234',
|
|
72
111
|
created_at: '2022-03-15T20:39:19.892Z',
|
|
@@ -79,37 +118,32 @@ describe('MFA', () => {
|
|
|
79
118
|
uri: 'uri-test',
|
|
80
119
|
user: 'some_user',
|
|
81
120
|
},
|
|
82
|
-
}
|
|
121
|
+
};
|
|
122
|
+
mock.onPost('/auth/factors/enroll').reply(200, factorResponse);
|
|
83
123
|
const workos = new workos_1.WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU', {
|
|
84
124
|
apiHostname: 'api.workos.dev',
|
|
85
125
|
});
|
|
86
|
-
const
|
|
126
|
+
const subject = yield workos.mfa.enrollFactor({
|
|
87
127
|
type: 'totp',
|
|
88
128
|
issuer: 'WorkOS',
|
|
89
129
|
user: 'some_user',
|
|
90
130
|
});
|
|
91
|
-
expect(
|
|
92
|
-
Object {
|
|
93
|
-
"created_at": "2022-03-15T20:39:19.892Z",
|
|
94
|
-
"id": "auth_factor_1234",
|
|
95
|
-
"object": "authentication_factor",
|
|
96
|
-
"totp": Object {
|
|
97
|
-
"issuer": "WorkOS",
|
|
98
|
-
"qr_code": "qr-code-test",
|
|
99
|
-
"secret": "secret-test",
|
|
100
|
-
"uri": "uri-test",
|
|
101
|
-
"user": "some_user",
|
|
102
|
-
},
|
|
103
|
-
"type": "totp",
|
|
104
|
-
"updated_at": "2022-03-15T20:39:19.892Z",
|
|
105
|
-
}
|
|
106
|
-
`);
|
|
131
|
+
expect(subject).toEqual(factor);
|
|
107
132
|
}));
|
|
108
133
|
});
|
|
109
134
|
describe('with sms', () => {
|
|
110
135
|
it('enrolls a factor with sms type', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
111
|
-
const
|
|
112
|
-
|
|
136
|
+
const factor = {
|
|
137
|
+
object: 'authentication_factor',
|
|
138
|
+
id: 'auth_factor_1234',
|
|
139
|
+
createdAt: '2022-03-15T20:39:19.892Z',
|
|
140
|
+
updatedAt: '2022-03-15T20:39:19.892Z',
|
|
141
|
+
type: 'sms',
|
|
142
|
+
sms: {
|
|
143
|
+
phoneNumber: '+15555555555',
|
|
144
|
+
},
|
|
145
|
+
};
|
|
146
|
+
const factorResponse = {
|
|
113
147
|
object: 'authentication_factor',
|
|
114
148
|
id: 'auth_factor_1234',
|
|
115
149
|
created_at: '2022-03-15T20:39:19.892Z',
|
|
@@ -118,30 +152,19 @@ describe('MFA', () => {
|
|
|
118
152
|
sms: {
|
|
119
153
|
phone_number: '+15555555555',
|
|
120
154
|
},
|
|
121
|
-
}
|
|
155
|
+
};
|
|
156
|
+
mock.onPost('/auth/factors/enroll').reply(200, factorResponse);
|
|
122
157
|
const workos = new workos_1.WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU', {
|
|
123
158
|
apiHostname: 'api.workos.dev',
|
|
124
159
|
});
|
|
125
|
-
const
|
|
160
|
+
const subject = yield workos.mfa.enrollFactor({
|
|
126
161
|
type: 'sms',
|
|
127
162
|
phoneNumber: '+1555555555',
|
|
128
163
|
});
|
|
129
|
-
expect(
|
|
130
|
-
Object {
|
|
131
|
-
"created_at": "2022-03-15T20:39:19.892Z",
|
|
132
|
-
"id": "auth_factor_1234",
|
|
133
|
-
"object": "authentication_factor",
|
|
134
|
-
"sms": Object {
|
|
135
|
-
"phone_number": "+15555555555",
|
|
136
|
-
},
|
|
137
|
-
"type": "sms",
|
|
138
|
-
"updated_at": "2022-03-15T20:39:19.892Z",
|
|
139
|
-
}
|
|
140
|
-
`);
|
|
164
|
+
expect(subject).toEqual(factor);
|
|
141
165
|
}));
|
|
142
166
|
describe('when phone number is invalid', () => {
|
|
143
167
|
it('throws an exception', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
144
|
-
const mock = new axios_mock_adapter_1.default(axios_1.default);
|
|
145
168
|
mock.onPost('/auth/factors/enroll').reply(422, {
|
|
146
169
|
message: `Phone number is invalid: 'foo'`,
|
|
147
170
|
code: 'invalid_phone_number',
|
|
@@ -162,8 +185,16 @@ describe('MFA', () => {
|
|
|
162
185
|
describe('challengeFactor', () => {
|
|
163
186
|
describe('with no sms template', () => {
|
|
164
187
|
it('challenge a factor with no sms template', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
165
|
-
const
|
|
166
|
-
|
|
188
|
+
const challenge = {
|
|
189
|
+
object: 'authentication_challenge',
|
|
190
|
+
id: 'auth_challenge_1234',
|
|
191
|
+
createdAt: '2022-03-15T20:39:19.892Z',
|
|
192
|
+
updatedAt: '2022-03-15T20:39:19.892Z',
|
|
193
|
+
expiresAt: '2022-03-15T21:39:19.892Z',
|
|
194
|
+
code: '12345',
|
|
195
|
+
authenticationFactorId: 'auth_factor_1234',
|
|
196
|
+
};
|
|
197
|
+
const challengeResponse = {
|
|
167
198
|
object: 'authentication_challenge',
|
|
168
199
|
id: 'auth_challenge_1234',
|
|
169
200
|
created_at: '2022-03-15T20:39:19.892Z',
|
|
@@ -171,34 +202,31 @@ describe('MFA', () => {
|
|
|
171
202
|
expires_at: '2022-03-15T21:39:19.892Z',
|
|
172
203
|
code: '12345',
|
|
173
204
|
authentication_factor_id: 'auth_factor_1234',
|
|
174
|
-
}
|
|
205
|
+
};
|
|
206
|
+
mock
|
|
207
|
+
.onPost('/auth/factors/auth_factor_1234/challenge')
|
|
208
|
+
.reply(200, challengeResponse);
|
|
175
209
|
const workos = new workos_1.WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU', {
|
|
176
210
|
apiHostname: 'api.workos.dev',
|
|
177
211
|
});
|
|
178
|
-
const
|
|
212
|
+
const subject = yield workos.mfa.challengeFactor({
|
|
179
213
|
authenticationFactorId: 'auth_factor_1234',
|
|
180
214
|
});
|
|
181
|
-
expect(
|
|
182
|
-
Object {
|
|
183
|
-
"authentication_factor_id": "auth_factor_1234",
|
|
184
|
-
"code": "12345",
|
|
185
|
-
"created_at": "2022-03-15T20:39:19.892Z",
|
|
186
|
-
"expires_at": "2022-03-15T21:39:19.892Z",
|
|
187
|
-
"id": "auth_challenge_1234",
|
|
188
|
-
"object": "authentication_challenge",
|
|
189
|
-
"updated_at": "2022-03-15T20:39:19.892Z",
|
|
190
|
-
}
|
|
191
|
-
`);
|
|
215
|
+
expect(subject).toEqual(challenge);
|
|
192
216
|
}));
|
|
193
217
|
});
|
|
194
218
|
describe('with sms template', () => {
|
|
195
219
|
it('challenge a factor with sms template', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
196
|
-
const
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
.
|
|
220
|
+
const challenge = {
|
|
221
|
+
object: 'authentication_challenge',
|
|
222
|
+
id: 'auth_challenge_1234',
|
|
223
|
+
createdAt: '2022-03-15T20:39:19.892Z',
|
|
224
|
+
updatedAt: '2022-03-15T20:39:19.892Z',
|
|
225
|
+
expiresAt: '2022-03-15T21:39:19.892Z',
|
|
226
|
+
code: '12345',
|
|
227
|
+
authenticationFactorId: 'auth_factor_1234',
|
|
228
|
+
};
|
|
229
|
+
const challengeResponse = {
|
|
202
230
|
object: 'authentication_challenge',
|
|
203
231
|
id: 'auth_challenge_1234',
|
|
204
232
|
created_at: '2022-03-15T20:39:19.892Z',
|
|
@@ -206,37 +234,39 @@ describe('MFA', () => {
|
|
|
206
234
|
expires_at: '2022-03-15T21:39:19.892Z',
|
|
207
235
|
code: '12345',
|
|
208
236
|
authentication_factor_id: 'auth_factor_1234',
|
|
209
|
-
}
|
|
237
|
+
};
|
|
238
|
+
mock
|
|
239
|
+
.onPost('/auth/factors/auth_factor_1234/challenge', {
|
|
240
|
+
sms_template: 'This is your code: 12345',
|
|
241
|
+
})
|
|
242
|
+
.reply(200, challengeResponse);
|
|
210
243
|
const workos = new workos_1.WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU', {
|
|
211
244
|
apiHostname: 'api.workos.dev',
|
|
212
245
|
});
|
|
213
|
-
const
|
|
246
|
+
const subject = yield workos.mfa.challengeFactor({
|
|
214
247
|
authenticationFactorId: 'auth_factor_1234',
|
|
215
248
|
smsTemplate: 'This is your code: 12345',
|
|
216
249
|
});
|
|
217
|
-
expect(
|
|
218
|
-
Object {
|
|
219
|
-
"authentication_factor_id": "auth_factor_1234",
|
|
220
|
-
"code": "12345",
|
|
221
|
-
"created_at": "2022-03-15T20:39:19.892Z",
|
|
222
|
-
"expires_at": "2022-03-15T21:39:19.892Z",
|
|
223
|
-
"id": "auth_challenge_1234",
|
|
224
|
-
"object": "authentication_challenge",
|
|
225
|
-
"updated_at": "2022-03-15T20:39:19.892Z",
|
|
226
|
-
}
|
|
227
|
-
`);
|
|
250
|
+
expect(subject).toEqual(challenge);
|
|
228
251
|
}));
|
|
229
252
|
});
|
|
230
253
|
});
|
|
231
254
|
describe('verifyChallenge', () => {
|
|
232
255
|
describe('verify with successful response', () => {
|
|
233
256
|
it('verifies a successful factor', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
234
|
-
const
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
257
|
+
const verifyResponse = {
|
|
258
|
+
challenge: {
|
|
259
|
+
object: 'authentication_challenge',
|
|
260
|
+
id: 'auth_challenge_1234',
|
|
261
|
+
createdAt: '2022-03-15T20:39:19.892Z',
|
|
262
|
+
updatedAt: '2022-03-15T20:39:19.892Z',
|
|
263
|
+
expiresAt: '2022-03-15T21:39:19.892Z',
|
|
264
|
+
code: '12345',
|
|
265
|
+
authenticationFactorId: 'auth_factor_1234',
|
|
266
|
+
},
|
|
267
|
+
valid: true,
|
|
268
|
+
};
|
|
269
|
+
const verifyResponseResponse = {
|
|
240
270
|
challenge: {
|
|
241
271
|
object: 'authentication_challenge',
|
|
242
272
|
id: 'auth_challenge_1234',
|
|
@@ -247,33 +277,24 @@ describe('MFA', () => {
|
|
|
247
277
|
authentication_factor_id: 'auth_factor_1234',
|
|
248
278
|
},
|
|
249
279
|
valid: true,
|
|
250
|
-
}
|
|
280
|
+
};
|
|
281
|
+
mock
|
|
282
|
+
.onPost('/auth/challenges/auth_challenge_1234/verify', {
|
|
283
|
+
code: '12345',
|
|
284
|
+
})
|
|
285
|
+
.reply(200, verifyResponseResponse);
|
|
251
286
|
const workos = new workos_1.WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU', {
|
|
252
287
|
apiHostname: 'api.workos.dev',
|
|
253
288
|
});
|
|
254
|
-
const
|
|
289
|
+
const subject = yield workos.mfa.verifyChallenge({
|
|
255
290
|
authenticationChallengeId: 'auth_challenge_1234',
|
|
256
291
|
code: '12345',
|
|
257
292
|
});
|
|
258
|
-
expect(
|
|
259
|
-
Object {
|
|
260
|
-
"challenge": Object {
|
|
261
|
-
"authentication_factor_id": "auth_factor_1234",
|
|
262
|
-
"code": "12345",
|
|
263
|
-
"created_at": "2022-03-15T20:39:19.892Z",
|
|
264
|
-
"expires_at": "2022-03-15T21:39:19.892Z",
|
|
265
|
-
"id": "auth_challenge_1234",
|
|
266
|
-
"object": "authentication_challenge",
|
|
267
|
-
"updated_at": "2022-03-15T20:39:19.892Z",
|
|
268
|
-
},
|
|
269
|
-
"valid": true,
|
|
270
|
-
}
|
|
271
|
-
`);
|
|
293
|
+
expect(subject).toEqual(verifyResponse);
|
|
272
294
|
}));
|
|
273
295
|
});
|
|
274
296
|
describe('when the challenge has been previously verified', () => {
|
|
275
297
|
it('throws an exception', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
276
|
-
const mock = new axios_mock_adapter_1.default(axios_1.default);
|
|
277
298
|
mock
|
|
278
299
|
.onPost('/auth/challenges/auth_challenge_1234/verify', {
|
|
279
300
|
code: '12345',
|
|
@@ -295,7 +316,6 @@ describe('MFA', () => {
|
|
|
295
316
|
});
|
|
296
317
|
describe('when the challenge has expired', () => {
|
|
297
318
|
it('throws an exception', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
298
|
-
const mock = new axios_mock_adapter_1.default(axios_1.default);
|
|
299
319
|
mock
|
|
300
320
|
.onPost('/auth/challenges/auth_challenge_1234/verify', {
|
|
301
321
|
code: '12345',
|
|
@@ -315,7 +335,6 @@ describe('MFA', () => {
|
|
|
315
335
|
})).rejects.toThrow(exceptions_1.UnprocessableEntityException);
|
|
316
336
|
}));
|
|
317
337
|
it('exception has code', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
318
|
-
const mock = new axios_mock_adapter_1.default(axios_1.default);
|
|
319
338
|
mock
|
|
320
339
|
.onPost('/auth/challenges/auth_challenge_1234/verify', {
|
|
321
340
|
code: '12345',
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.deserializeChallenge = void 0;
|
|
4
|
+
const deserializeChallenge = (challenge) => ({
|
|
5
|
+
object: challenge.object,
|
|
6
|
+
id: challenge.id,
|
|
7
|
+
createdAt: challenge.created_at,
|
|
8
|
+
updatedAt: challenge.updated_at,
|
|
9
|
+
expiresAt: challenge.expires_at,
|
|
10
|
+
code: challenge.code,
|
|
11
|
+
authenticationFactorId: challenge.authentication_factor_id,
|
|
12
|
+
});
|
|
13
|
+
exports.deserializeChallenge = deserializeChallenge;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.deserializeFactor = void 0;
|
|
4
|
+
const sms_serializer_1 = require("./sms.serializer");
|
|
5
|
+
const totp_serializer_1 = require("./totp.serializer");
|
|
6
|
+
const deserializeFactor = (factor) => (Object.assign(Object.assign({ object: factor.object, id: factor.id, createdAt: factor.created_at, updatedAt: factor.updated_at, type: factor.type }, (factor.sms ? { sms: (0, sms_serializer_1.deserializeSms)(factor.sms) } : {})), (factor.totp ? { totp: (0, totp_serializer_1.deserializeTotp)(factor.totp) } : {})));
|
|
7
|
+
exports.deserializeFactor = deserializeFactor;
|
|
@@ -14,7 +14,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./
|
|
18
|
-
__exportStar(require("./
|
|
19
|
-
__exportStar(require("./
|
|
20
|
-
__exportStar(require("./webhook-directory-user.interface"), exports);
|
|
17
|
+
__exportStar(require("./challenge.serializer"), exports);
|
|
18
|
+
__exportStar(require("./factor.serializer"), exports);
|
|
19
|
+
__exportStar(require("./verify-response.serializer"), exports);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.deserializeTotp = void 0;
|
|
4
|
+
const deserializeTotp = (totp) => ({
|
|
5
|
+
issuer: totp.issuer,
|
|
6
|
+
user: totp.user,
|
|
7
|
+
qrCode: totp.qr_code,
|
|
8
|
+
secret: totp.secret,
|
|
9
|
+
uri: totp.uri,
|
|
10
|
+
});
|
|
11
|
+
exports.deserializeTotp = deserializeTotp;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.deserializeVerifyResponse = void 0;
|
|
4
|
+
const challenge_serializer_1 = require("./challenge.serializer");
|
|
5
|
+
const deserializeVerifyResponse = (verifyResponse) => ({
|
|
6
|
+
challenge: (0, challenge_serializer_1.deserializeChallenge)(verifyResponse.challenge),
|
|
7
|
+
valid: verifyResponse.valid,
|
|
8
|
+
});
|
|
9
|
+
exports.deserializeVerifyResponse = deserializeVerifyResponse;
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import { PostOptions } from '../../common/interfaces';
|
|
2
2
|
export interface CreateOrganizationOptions {
|
|
3
|
+
name: string;
|
|
4
|
+
allowProfilesOutsideOrganization?: boolean;
|
|
5
|
+
domains?: string[];
|
|
6
|
+
}
|
|
7
|
+
export interface SerializedCreateOrganizationOptions {
|
|
3
8
|
name: string;
|
|
4
9
|
allow_profiles_outside_organization?: boolean;
|
|
5
10
|
domains?: string[];
|
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
import { OrganizationDomain } from './organization-domain.interface';
|
|
2
2
|
export interface Organization {
|
|
3
|
+
object: 'organization';
|
|
4
|
+
id: string;
|
|
5
|
+
name: string;
|
|
6
|
+
allowProfilesOutsideOrganization: boolean;
|
|
7
|
+
domains: OrganizationDomain[];
|
|
8
|
+
createdAt: string;
|
|
9
|
+
updatedAt: string;
|
|
10
|
+
}
|
|
11
|
+
export interface OrganizationResponse {
|
|
3
12
|
object: 'organization';
|
|
4
13
|
id: string;
|
|
5
14
|
name: string;
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
export interface UpdateOrganizationOptions {
|
|
2
2
|
organization: string;
|
|
3
|
+
name: string;
|
|
4
|
+
allowProfilesOutsideOrganization?: boolean;
|
|
5
|
+
domains?: string[];
|
|
6
|
+
}
|
|
7
|
+
export interface SerializedUpdateOrganizationOptions {
|
|
3
8
|
name: string;
|
|
4
9
|
allow_profiles_outside_organization?: boolean;
|
|
5
10
|
domains?: string[];
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AutoPaginatable } from '../common/utils/pagination';
|
|
2
2
|
import { WorkOS } from '../workos';
|
|
3
3
|
import { CreateOrganizationOptions, CreateOrganizationRequestOptions, ListOrganizationsOptions, Organization, UpdateOrganizationOptions } from './interfaces';
|
|
4
4
|
export declare class Organizations {
|
|
5
5
|
private readonly workos;
|
|
6
6
|
constructor(workos: WorkOS);
|
|
7
|
-
listOrganizations(options?: ListOrganizationsOptions): Promise<
|
|
7
|
+
listOrganizations(options?: ListOrganizationsOptions): Promise<AutoPaginatable<Organization>>;
|
|
8
8
|
createOrganization(payload: CreateOrganizationOptions, requestOptions?: CreateOrganizationRequestOptions): Promise<Organization>;
|
|
9
9
|
deleteOrganization(id: string): Promise<void>;
|
|
10
10
|
getOrganization(id: string): Promise<Organization>;
|
|
@@ -21,22 +21,22 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
21
21
|
};
|
|
22
22
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
23
|
exports.Organizations = void 0;
|
|
24
|
+
const pagination_1 = require("../common/utils/pagination");
|
|
25
|
+
const serializers_1 = require("./serializers");
|
|
26
|
+
const fetch_and_deserialize_1 = require("../common/utils/fetch-and-deserialize");
|
|
24
27
|
class Organizations {
|
|
25
28
|
constructor(workos) {
|
|
26
29
|
this.workos = workos;
|
|
27
30
|
}
|
|
28
31
|
listOrganizations(options) {
|
|
29
32
|
return __awaiter(this, void 0, void 0, function* () {
|
|
30
|
-
|
|
31
|
-
query: options,
|
|
32
|
-
});
|
|
33
|
-
return data;
|
|
33
|
+
return new pagination_1.AutoPaginatable(yield (0, fetch_and_deserialize_1.fetchAndDeserialize)(this.workos, '/organizations', serializers_1.deserializeOrganization, options), (params) => (0, fetch_and_deserialize_1.fetchAndDeserialize)(this.workos, '/organizations', serializers_1.deserializeOrganization, params), options);
|
|
34
34
|
});
|
|
35
35
|
}
|
|
36
36
|
createOrganization(payload, requestOptions = {}) {
|
|
37
37
|
return __awaiter(this, void 0, void 0, function* () {
|
|
38
|
-
const { data } = yield this.workos.post('/organizations', payload, requestOptions);
|
|
39
|
-
return data;
|
|
38
|
+
const { data } = yield this.workos.post('/organizations', (0, serializers_1.serializeCreateOrganizationOptions)(payload), requestOptions);
|
|
39
|
+
return (0, serializers_1.deserializeOrganization)(data);
|
|
40
40
|
});
|
|
41
41
|
}
|
|
42
42
|
deleteOrganization(id) {
|
|
@@ -47,14 +47,14 @@ class Organizations {
|
|
|
47
47
|
getOrganization(id) {
|
|
48
48
|
return __awaiter(this, void 0, void 0, function* () {
|
|
49
49
|
const { data } = yield this.workos.get(`/organizations/${id}`);
|
|
50
|
-
return data;
|
|
50
|
+
return (0, serializers_1.deserializeOrganization)(data);
|
|
51
51
|
});
|
|
52
52
|
}
|
|
53
53
|
updateOrganization(options) {
|
|
54
54
|
return __awaiter(this, void 0, void 0, function* () {
|
|
55
55
|
const { organization: organizationId } = options, payload = __rest(options, ["organization"]);
|
|
56
|
-
const { data } = yield this.workos.put(`/organizations/${organizationId}`, payload);
|
|
57
|
-
return data;
|
|
56
|
+
const { data } = yield this.workos.put(`/organizations/${organizationId}`, (0, serializers_1.serializeUpdateOrganizationOptions)(payload));
|
|
57
|
+
return (0, serializers_1.deserializeOrganization)(data);
|
|
58
58
|
});
|
|
59
59
|
}
|
|
60
60
|
}
|