@workos-inc/node 6.0.3 → 6.2.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/common/interfaces/event.interface.d.ts +11 -3
- package/lib/common/serializers/event.serializer.js +1 -0
- package/lib/events/events.spec.js +29 -1
- package/lib/sso/sso.spec.js +19 -0
- package/lib/user-management/fixtures/list-organization-memberships.json +1 -0
- package/lib/user-management/fixtures/organization-membership.json +1 -0
- package/lib/user-management/interfaces/authenticate-with-refresh-token-options.interface.d.ts +11 -0
- package/lib/user-management/interfaces/authenticate-with-refresh-token-options.interface.js +2 -0
- package/lib/user-management/interfaces/authentication-response.interface.d.ts +12 -0
- package/lib/user-management/interfaces/index.d.ts +1 -0
- package/lib/user-management/interfaces/index.js +1 -0
- package/lib/user-management/interfaces/organization-membership.interface.d.ts +2 -0
- package/lib/user-management/interfaces/revoke-session-options.interface.d.ts +7 -0
- package/lib/user-management/interfaces/revoke-session-options.interface.js +7 -0
- package/lib/user-management/interfaces/update-user-options.interface.d.ts +2 -2
- package/lib/user-management/serializers/authenticate-with-refresh-token.options.serializer.d.ts +2 -0
- package/lib/user-management/serializers/authenticate-with-refresh-token.options.serializer.js +12 -0
- package/lib/user-management/serializers/authentication-response.serializer.d.ts +2 -1
- package/lib/user-management/serializers/authentication-response.serializer.js +8 -3
- package/lib/user-management/serializers/index.d.ts +1 -0
- package/lib/user-management/serializers/index.js +1 -0
- package/lib/user-management/serializers/organization-membership.serializer.js +1 -0
- package/lib/user-management/user-management.d.ts +8 -1
- package/lib/user-management/user-management.js +25 -1
- package/lib/user-management/user-management.spec.js +61 -0
- package/lib/workos.js +1 -1
- package/package.json +1 -1
|
@@ -170,6 +170,14 @@ export interface OrganizationMembershipAddedResponse extends EventResponseBase {
|
|
|
170
170
|
event: 'organization_membership.added';
|
|
171
171
|
data: OrganizationMembershipResponse;
|
|
172
172
|
}
|
|
173
|
+
export interface OrganizationMembershipUpdated extends EventBase {
|
|
174
|
+
event: 'organization_membership.updated';
|
|
175
|
+
data: OrganizationMembership;
|
|
176
|
+
}
|
|
177
|
+
export interface OrganizationMembershipUpdatedResponse extends EventResponseBase {
|
|
178
|
+
event: 'organization_membership.updated';
|
|
179
|
+
data: OrganizationMembershipResponse;
|
|
180
|
+
}
|
|
173
181
|
export interface OrganizationMembershipRemoved extends EventBase {
|
|
174
182
|
event: 'organization_membership.removed';
|
|
175
183
|
data: OrganizationMembership;
|
|
@@ -178,7 +186,7 @@ export interface OrganizationMembershipRemovedResponse extends EventResponseBase
|
|
|
178
186
|
event: 'organization_membership.removed';
|
|
179
187
|
data: OrganizationMembershipResponse;
|
|
180
188
|
}
|
|
181
|
-
export type Event = ConnectionActivatedEvent | ConnectionDeactivatedEvent | ConnectionDeletedEvent | DsyncActivatedEvent | DsyncDeactivatedEvent | DsyncDeletedEvent | DsyncGroupCreatedEvent | DsyncGroupUpdatedEvent | DsyncGroupDeletedEvent | DsyncGroupUserAddedEvent | DsyncGroupUserRemovedEvent | DsyncUserCreatedEvent | DsyncUserUpdatedEvent | DsyncUserDeletedEvent | UserCreatedEvent | UserUpdatedEvent | UserDeletedEvent | OrganizationMembershipAdded | OrganizationMembershipRemoved;
|
|
182
|
-
export type EventResponse = ConnectionActivatedEventResponse | ConnectionDeactivatedEventResponse | ConnectionDeletedEventResponse | DsyncActivatedEventResponse | DsyncDeactivatedEventResponse | DsyncDeletedEventResponse | DsyncGroupCreatedEventResponse | DsyncGroupUpdatedEventResponse | DsyncGroupDeletedEventResponse | DsyncGroupUserAddedEventResponse | DsyncGroupUserRemovedEventResponse | DsyncUserCreatedEventResponse | DsyncUserUpdatedEventResponse | DsyncUserDeletedEventResponse | UserCreatedEventResponse | UserUpdatedEventResponse | UserDeletedEventResponse | OrganizationMembershipAddedResponse | OrganizationMembershipRemovedResponse;
|
|
183
|
-
export type EventName = 'connection.activated' | 'connection.deactivated' | 'connection.deleted' | 'dsync.activated' | 'dsync.deactivated' | 'dsync.deleted' | 'dsync.group.created' | 'dsync.group.deleted' | 'dsync.group.updated' | 'dsync.group.user_added' | 'dsync.group.user_removed' | 'dsync.user.created' | 'dsync.user.deleted' | 'dsync.user.updated' | 'user.created' | 'user.updated' | 'user.deleted' | 'organization_membership.added' | 'organization_membership.removed';
|
|
189
|
+
export type Event = ConnectionActivatedEvent | ConnectionDeactivatedEvent | ConnectionDeletedEvent | DsyncActivatedEvent | DsyncDeactivatedEvent | DsyncDeletedEvent | DsyncGroupCreatedEvent | DsyncGroupUpdatedEvent | DsyncGroupDeletedEvent | DsyncGroupUserAddedEvent | DsyncGroupUserRemovedEvent | DsyncUserCreatedEvent | DsyncUserUpdatedEvent | DsyncUserDeletedEvent | UserCreatedEvent | UserUpdatedEvent | UserDeletedEvent | OrganizationMembershipAdded | OrganizationMembershipUpdated | OrganizationMembershipRemoved;
|
|
190
|
+
export type EventResponse = ConnectionActivatedEventResponse | ConnectionDeactivatedEventResponse | ConnectionDeletedEventResponse | DsyncActivatedEventResponse | DsyncDeactivatedEventResponse | DsyncDeletedEventResponse | DsyncGroupCreatedEventResponse | DsyncGroupUpdatedEventResponse | DsyncGroupDeletedEventResponse | DsyncGroupUserAddedEventResponse | DsyncGroupUserRemovedEventResponse | DsyncUserCreatedEventResponse | DsyncUserUpdatedEventResponse | DsyncUserDeletedEventResponse | UserCreatedEventResponse | UserUpdatedEventResponse | UserDeletedEventResponse | OrganizationMembershipAddedResponse | OrganizationMembershipUpdatedResponse | OrganizationMembershipRemovedResponse;
|
|
191
|
+
export type EventName = 'connection.activated' | 'connection.deactivated' | 'connection.deleted' | 'dsync.activated' | 'dsync.deactivated' | 'dsync.deleted' | 'dsync.group.created' | 'dsync.group.deleted' | 'dsync.group.updated' | 'dsync.group.user_added' | 'dsync.group.user_removed' | 'dsync.user.created' | 'dsync.user.deleted' | 'dsync.user.updated' | 'user.created' | 'user.updated' | 'user.deleted' | 'organization_membership.added' | 'organization_membership.updated' | 'organization_membership.removed';
|
|
184
192
|
export {};
|
|
@@ -42,6 +42,7 @@ const deserializeEvent = (event) => {
|
|
|
42
42
|
case 'user.deleted':
|
|
43
43
|
return Object.assign(Object.assign({}, eventBase), { event: event.event, data: (0, serializers_3.deserializeUser)(event.data) });
|
|
44
44
|
case 'organization_membership.added':
|
|
45
|
+
case 'organization_membership.updated':
|
|
45
46
|
case 'organization_membership.removed':
|
|
46
47
|
return Object.assign(Object.assign({}, eventBase), { event: event.event, data: (0, organization_membership_serializer_1.deserializeOrganizationMembership)(event.data) });
|
|
47
48
|
}
|
|
@@ -58,9 +58,37 @@ describe('Event', () => {
|
|
|
58
58
|
data: [eventResponse],
|
|
59
59
|
list_metadata: {},
|
|
60
60
|
};
|
|
61
|
+
describe('with options', () => {
|
|
62
|
+
it('requests Events with query parameters', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
63
|
+
const eventsResponse = {
|
|
64
|
+
object: 'list',
|
|
65
|
+
data: [eventResponse],
|
|
66
|
+
list_metadata: {},
|
|
67
|
+
};
|
|
68
|
+
(0, test_utils_1.fetchOnce)(eventsResponse);
|
|
69
|
+
const list = yield workos.events.listEvents({
|
|
70
|
+
events: ['connection.activated'],
|
|
71
|
+
rangeStart: '2020-05-04',
|
|
72
|
+
rangeEnd: '2020-05-07',
|
|
73
|
+
});
|
|
74
|
+
expect((0, test_utils_1.fetchSearchParams)()).toMatchObject({
|
|
75
|
+
events: 'connection.activated',
|
|
76
|
+
range_start: '2020-05-04',
|
|
77
|
+
range_end: '2020-05-07',
|
|
78
|
+
});
|
|
79
|
+
expect(list).toEqual({
|
|
80
|
+
object: 'list',
|
|
81
|
+
data: [event],
|
|
82
|
+
listMetadata: {},
|
|
83
|
+
});
|
|
84
|
+
}));
|
|
85
|
+
});
|
|
61
86
|
it(`requests Events`, () => __awaiter(void 0, void 0, void 0, function* () {
|
|
62
87
|
(0, test_utils_1.fetchOnce)(eventsListResponse);
|
|
63
|
-
const subject = yield workos.events.listEvents({
|
|
88
|
+
const subject = yield workos.events.listEvents({
|
|
89
|
+
rangeStart: '2020-05-05',
|
|
90
|
+
rangeEnd: '2020-05-07',
|
|
91
|
+
});
|
|
64
92
|
expect(subject).toEqual({
|
|
65
93
|
object: 'list',
|
|
66
94
|
data: [event],
|
package/lib/sso/sso.spec.js
CHANGED
|
@@ -30,6 +30,25 @@ describe('SSO', () => {
|
|
|
30
30
|
updated_at: '2023-07-17T20:07:20.055Z',
|
|
31
31
|
};
|
|
32
32
|
describe('SSO', () => {
|
|
33
|
+
describe('with options', () => {
|
|
34
|
+
it('requests Connections with query parameters', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
35
|
+
const workos = new workos_1.WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU');
|
|
36
|
+
const listConnectionsResponse = {
|
|
37
|
+
object: 'list',
|
|
38
|
+
data: [connectionResponse],
|
|
39
|
+
list_metadata: {},
|
|
40
|
+
};
|
|
41
|
+
(0, test_utils_1.fetchOnce)(listConnectionsResponse);
|
|
42
|
+
yield workos.sso.listConnections({
|
|
43
|
+
connectionType: interfaces_1.ConnectionType.OktaSAML,
|
|
44
|
+
organizationId: 'org_123',
|
|
45
|
+
});
|
|
46
|
+
expect((0, test_utils_1.fetchSearchParams)()).toMatchObject({
|
|
47
|
+
connection_type: interfaces_1.ConnectionType.OktaSAML,
|
|
48
|
+
organization_id: 'org_123',
|
|
49
|
+
});
|
|
50
|
+
}));
|
|
51
|
+
});
|
|
33
52
|
describe('getAuthorizationUrl', () => {
|
|
34
53
|
describe('with no custom api hostname', () => {
|
|
35
54
|
it('generates an authorize url with the default api hostname', () => {
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
"id": "om_01H5JQDV7R7ATEYZDEG0W5PRYS",
|
|
7
7
|
"user_id": "user_01H5JQDV7R7ATEYZDEG0W5PRYS",
|
|
8
8
|
"organization_id": "organization_01H5JQDV7R7ATEYZDEG0W5PRYS",
|
|
9
|
+
"status": "active",
|
|
9
10
|
"created_at": "2023-07-18T02:07:19.911Z",
|
|
10
11
|
"updated_at": "2023-07-18T02:07:19.911Z"
|
|
11
12
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { AuthenticateWithOptionsBase, SerializedAuthenticateWithOptionsBase } from './authenticate-with-options-base.interface';
|
|
2
|
+
export interface AuthenticateWithRefreshTokenOptions extends AuthenticateWithOptionsBase {
|
|
3
|
+
refreshToken: string;
|
|
4
|
+
}
|
|
5
|
+
export interface AuthenticateUserWithRefreshTokenCredentials {
|
|
6
|
+
clientSecret: string | undefined;
|
|
7
|
+
}
|
|
8
|
+
export interface SerializedAuthenticateWithRefreshTokenOptions extends SerializedAuthenticateWithOptionsBase {
|
|
9
|
+
grant_type: 'refresh_token';
|
|
10
|
+
refresh_token: string;
|
|
11
|
+
}
|
|
@@ -2,8 +2,20 @@ import { User, UserResponse } from './user.interface';
|
|
|
2
2
|
export interface AuthenticationResponse {
|
|
3
3
|
user: User;
|
|
4
4
|
organizationId?: string;
|
|
5
|
+
accessToken?: string;
|
|
6
|
+
refreshToken?: string;
|
|
5
7
|
}
|
|
6
8
|
export interface AuthenticationResponseResponse {
|
|
7
9
|
user: UserResponse;
|
|
8
10
|
organization_id?: string;
|
|
11
|
+
access_token?: string;
|
|
12
|
+
refresh_token?: string;
|
|
13
|
+
}
|
|
14
|
+
export interface RefreshAuthenticationResponse {
|
|
15
|
+
accessToken: string;
|
|
16
|
+
refreshToken: string;
|
|
17
|
+
}
|
|
18
|
+
export interface RefreshAuthenticationResponseResponse {
|
|
19
|
+
access_token: string;
|
|
20
|
+
refresh_token: string;
|
|
9
21
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export * from './authenticate-with-magic-auth-options.interface';
|
|
2
2
|
export * from './authenticate-with-password-options.interface';
|
|
3
3
|
export * from './authenticate-with-code-options.interface';
|
|
4
|
+
export * from './authenticate-with-refresh-token-options.interface';
|
|
4
5
|
export * from './authenticate-with-totp-options.interface';
|
|
5
6
|
export * from './authentication-response.interface';
|
|
6
7
|
export * from './reset-password-options.interface';
|
|
@@ -17,6 +17,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
__exportStar(require("./authenticate-with-magic-auth-options.interface"), exports);
|
|
18
18
|
__exportStar(require("./authenticate-with-password-options.interface"), exports);
|
|
19
19
|
__exportStar(require("./authenticate-with-code-options.interface"), exports);
|
|
20
|
+
__exportStar(require("./authenticate-with-refresh-token-options.interface"), exports);
|
|
20
21
|
__exportStar(require("./authenticate-with-totp-options.interface"), exports);
|
|
21
22
|
__exportStar(require("./authentication-response.interface"), exports);
|
|
22
23
|
__exportStar(require("./reset-password-options.interface"), exports);
|
|
@@ -2,6 +2,7 @@ export interface OrganizationMembership {
|
|
|
2
2
|
object: 'organization_membership';
|
|
3
3
|
id: string;
|
|
4
4
|
organizationId: string;
|
|
5
|
+
status: 'active' | 'pending';
|
|
5
6
|
userId: string;
|
|
6
7
|
createdAt: string;
|
|
7
8
|
updatedAt: string;
|
|
@@ -10,6 +11,7 @@ export interface OrganizationMembershipResponse {
|
|
|
10
11
|
object: 'organization_membership';
|
|
11
12
|
id: string;
|
|
12
13
|
organization_id: string;
|
|
14
|
+
status: 'active' | 'pending';
|
|
13
15
|
user_id: string;
|
|
14
16
|
created_at: string;
|
|
15
17
|
updated_at: string;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.serializeRevokeSessionOptions = void 0;
|
|
4
|
+
const serializeRevokeSessionOptions = (options) => ({
|
|
5
|
+
session_id: options.sessionId,
|
|
6
|
+
});
|
|
7
|
+
exports.serializeRevokeSessionOptions = serializeRevokeSessionOptions;
|
|
@@ -5,7 +5,7 @@ export interface UpdateUserOptions {
|
|
|
5
5
|
emailVerified?: boolean;
|
|
6
6
|
password?: string;
|
|
7
7
|
passwordHash?: string;
|
|
8
|
-
passwordHashType?: 'bcrypt' | 'firebase-scrypt';
|
|
8
|
+
passwordHashType?: 'bcrypt' | 'firebase-scrypt' | 'ssha';
|
|
9
9
|
}
|
|
10
10
|
export interface SerializedUpdateUserOptions {
|
|
11
11
|
first_name?: string;
|
|
@@ -13,5 +13,5 @@ export interface SerializedUpdateUserOptions {
|
|
|
13
13
|
email_verified?: boolean;
|
|
14
14
|
password?: string;
|
|
15
15
|
password_hash?: string;
|
|
16
|
-
password_hash_type?: 'bcrypt' | 'firebase-scrypt';
|
|
16
|
+
password_hash_type?: 'bcrypt' | 'firebase-scrypt' | 'ssha';
|
|
17
17
|
}
|
package/lib/user-management/serializers/authenticate-with-refresh-token.options.serializer.d.ts
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { AuthenticateUserWithCodeCredentials, AuthenticateWithRefreshTokenOptions, SerializedAuthenticateWithRefreshTokenOptions } from '../interfaces';
|
|
2
|
+
export declare const serializeAuthenticateWithRefreshTokenOptions: (options: AuthenticateWithRefreshTokenOptions & AuthenticateUserWithCodeCredentials) => SerializedAuthenticateWithRefreshTokenOptions;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.serializeAuthenticateWithRefreshTokenOptions = void 0;
|
|
4
|
+
const serializeAuthenticateWithRefreshTokenOptions = (options) => ({
|
|
5
|
+
grant_type: 'refresh_token',
|
|
6
|
+
client_id: options.clientId,
|
|
7
|
+
client_secret: options.clientSecret,
|
|
8
|
+
refresh_token: options.refreshToken,
|
|
9
|
+
ip_address: options.ipAddress,
|
|
10
|
+
user_agent: options.userAgent,
|
|
11
|
+
});
|
|
12
|
+
exports.serializeAuthenticateWithRefreshTokenOptions = serializeAuthenticateWithRefreshTokenOptions;
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
import { AuthenticationResponse, AuthenticationResponseResponse } from '../interfaces';
|
|
1
|
+
import { AuthenticationResponse, AuthenticationResponseResponse, RefreshAuthenticationResponse, RefreshAuthenticationResponseResponse } from '../interfaces';
|
|
2
2
|
export declare const deserializeAuthenticationResponse: (authenticationResponse: AuthenticationResponseResponse) => AuthenticationResponse;
|
|
3
|
+
export declare const deserializeRefreshAuthenticationResponse: (refreshAuthenticationResponse: RefreshAuthenticationResponseResponse) => RefreshAuthenticationResponse;
|
|
@@ -11,10 +11,15 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
11
11
|
return t;
|
|
12
12
|
};
|
|
13
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
-
exports.deserializeAuthenticationResponse = void 0;
|
|
14
|
+
exports.deserializeRefreshAuthenticationResponse = exports.deserializeAuthenticationResponse = void 0;
|
|
15
15
|
const user_serializer_1 = require("./user.serializer");
|
|
16
16
|
const deserializeAuthenticationResponse = (authenticationResponse) => {
|
|
17
|
-
const { user, organization_id } = authenticationResponse, rest = __rest(authenticationResponse, ["user", "organization_id"]);
|
|
18
|
-
return Object.assign({ user: (0, user_serializer_1.deserializeUser)(user), organizationId: organization_id }, rest);
|
|
17
|
+
const { user, organization_id, access_token, refresh_token } = authenticationResponse, rest = __rest(authenticationResponse, ["user", "organization_id", "access_token", "refresh_token"]);
|
|
18
|
+
return Object.assign({ user: (0, user_serializer_1.deserializeUser)(user), organizationId: organization_id, accessToken: access_token, refreshToken: refresh_token }, rest);
|
|
19
19
|
};
|
|
20
20
|
exports.deserializeAuthenticationResponse = deserializeAuthenticationResponse;
|
|
21
|
+
const deserializeRefreshAuthenticationResponse = (refreshAuthenticationResponse) => {
|
|
22
|
+
const { access_token, refresh_token } = refreshAuthenticationResponse, rest = __rest(refreshAuthenticationResponse, ["access_token", "refresh_token"]);
|
|
23
|
+
return Object.assign({ accessToken: access_token, refreshToken: refresh_token }, rest);
|
|
24
|
+
};
|
|
25
|
+
exports.deserializeRefreshAuthenticationResponse = deserializeRefreshAuthenticationResponse;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export * from './authenticate-with-code-options.serializer';
|
|
2
2
|
export * from './authenticate-with-magic-auth-options.serializer';
|
|
3
3
|
export * from './authenticate-with-password-options.serializer';
|
|
4
|
+
export * from './authenticate-with-refresh-token.options.serializer';
|
|
4
5
|
export * from './authenticate-with-totp-options.serializer';
|
|
5
6
|
export * from './authentication-response.serializer';
|
|
6
7
|
export * from './enroll-auth-factor-options.serializer';
|
|
@@ -17,6 +17,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
__exportStar(require("./authenticate-with-code-options.serializer"), exports);
|
|
18
18
|
__exportStar(require("./authenticate-with-magic-auth-options.serializer"), exports);
|
|
19
19
|
__exportStar(require("./authenticate-with-password-options.serializer"), exports);
|
|
20
|
+
__exportStar(require("./authenticate-with-refresh-token.options.serializer"), exports);
|
|
20
21
|
__exportStar(require("./authenticate-with-totp-options.serializer"), exports);
|
|
21
22
|
__exportStar(require("./authentication-response.serializer"), exports);
|
|
22
23
|
__exportStar(require("./enroll-auth-factor-options.serializer"), exports);
|
|
@@ -6,6 +6,7 @@ const deserializeOrganizationMembership = (organizationMembership) => ({
|
|
|
6
6
|
id: organizationMembership.id,
|
|
7
7
|
userId: organizationMembership.user_id,
|
|
8
8
|
organizationId: organizationMembership.organization_id,
|
|
9
|
+
status: organizationMembership.status,
|
|
9
10
|
createdAt: organizationMembership.created_at,
|
|
10
11
|
updatedAt: organizationMembership.updated_at,
|
|
11
12
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { WorkOS } from '../workos';
|
|
2
2
|
import { AutoPaginatable } from '../common/utils/pagination';
|
|
3
|
-
import { AuthenticateWithCodeOptions, AuthenticateWithMagicAuthOptions, AuthenticateWithPasswordOptions, AuthenticateWithTotpOptions, AuthenticationResponse, ResetPasswordOptions, SendPasswordResetEmailOptions, CreateUserOptions, EnrollAuthFactorOptions, ListAuthFactorsOptions, ListUsersOptions, SendMagicAuthCodeOptions, SendVerificationEmailOptions, UpdateUserOptions, User, VerifyEmailOptions } from './interfaces';
|
|
3
|
+
import { AuthenticateWithCodeOptions, AuthenticateWithMagicAuthOptions, AuthenticateWithPasswordOptions, AuthenticateWithTotpOptions, AuthenticationResponse, ResetPasswordOptions, SendPasswordResetEmailOptions, CreateUserOptions, EnrollAuthFactorOptions, ListAuthFactorsOptions, ListUsersOptions, SendMagicAuthCodeOptions, SendVerificationEmailOptions, UpdateUserOptions, User, VerifyEmailOptions, AuthenticateWithRefreshTokenOptions, RefreshAuthenticationResponse } from './interfaces';
|
|
4
4
|
import { Challenge } from '../mfa/interfaces';
|
|
5
5
|
import { OrganizationMembership } from './interfaces/organization-membership.interface';
|
|
6
6
|
import { ListOrganizationMembershipsOptions } from './interfaces/list-organization-memberships-options.interface';
|
|
@@ -12,6 +12,7 @@ import { AuthorizationURLOptions } from './interfaces/authorization-url-options.
|
|
|
12
12
|
import { AuthenticateWithEmailVerificationOptions } from './interfaces/authenticate-with-email-verification-options.interface';
|
|
13
13
|
import { AuthenticateWithOrganizationSelectionOptions } from './interfaces/authenticate-with-organization-selection.interface';
|
|
14
14
|
import { Factor, FactorWithSecrets } from './interfaces/factor.interface';
|
|
15
|
+
import { RevokeSessionOptions } from './interfaces/revoke-session-options.interface';
|
|
15
16
|
export declare class UserManagement {
|
|
16
17
|
private readonly workos;
|
|
17
18
|
constructor(workos: WorkOS);
|
|
@@ -21,6 +22,7 @@ export declare class UserManagement {
|
|
|
21
22
|
authenticateWithMagicAuth(payload: AuthenticateWithMagicAuthOptions): Promise<AuthenticationResponse>;
|
|
22
23
|
authenticateWithPassword(payload: AuthenticateWithPasswordOptions): Promise<AuthenticationResponse>;
|
|
23
24
|
authenticateWithCode(payload: AuthenticateWithCodeOptions): Promise<AuthenticationResponse>;
|
|
25
|
+
authenticateWithRefreshToken(payload: AuthenticateWithRefreshTokenOptions): Promise<RefreshAuthenticationResponse>;
|
|
24
26
|
authenticateWithTotp(payload: AuthenticateWithTotpOptions): Promise<AuthenticationResponse>;
|
|
25
27
|
authenticateWithEmailVerification(payload: AuthenticateWithEmailVerificationOptions): Promise<AuthenticationResponse>;
|
|
26
28
|
authenticateWithOrganizationSelection(payload: AuthenticateWithOrganizationSelectionOptions): Promise<AuthenticationResponse>;
|
|
@@ -50,5 +52,10 @@ export declare class UserManagement {
|
|
|
50
52
|
listInvitations(options: ListInvitationsOptions): Promise<AutoPaginatable<Invitation>>;
|
|
51
53
|
sendInvitation(payload: SendInvitationOptions): Promise<Invitation>;
|
|
52
54
|
revokeInvitation(invitationId: string): Promise<Invitation>;
|
|
55
|
+
revokeSession(payload: RevokeSessionOptions): Promise<void>;
|
|
53
56
|
getAuthorizationUrl({ connectionId, clientId, domainHint, loginHint, organizationId, provider, redirectUri, state, }: AuthorizationURLOptions): string;
|
|
57
|
+
getLogoutUrl({ sessionId }: {
|
|
58
|
+
sessionId: string;
|
|
59
|
+
}): string;
|
|
60
|
+
getJwksUrl(clientId: string): string;
|
|
54
61
|
}
|
|
@@ -24,6 +24,7 @@ const list_users_options_serializer_1 = require("./serializers/list-users-option
|
|
|
24
24
|
const authenticate_with_email_verification_serializer_1 = require("./serializers/authenticate-with-email-verification.serializer");
|
|
25
25
|
const authenticate_with_organization_selection_options_serializer_1 = require("./serializers/authenticate-with-organization-selection-options.serializer");
|
|
26
26
|
const factor_serializer_1 = require("./serializers/factor.serializer");
|
|
27
|
+
const revoke_session_options_interface_1 = require("./interfaces/revoke-session-options.interface");
|
|
27
28
|
const toQueryString = (options) => {
|
|
28
29
|
const searchParams = new URLSearchParams();
|
|
29
30
|
const keys = Object.keys(options).sort();
|
|
@@ -74,6 +75,12 @@ class UserManagement {
|
|
|
74
75
|
return (0, serializers_1.deserializeAuthenticationResponse)(data);
|
|
75
76
|
});
|
|
76
77
|
}
|
|
78
|
+
authenticateWithRefreshToken(payload) {
|
|
79
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
80
|
+
const { data } = yield this.workos.post('/user_management/authenticate', (0, serializers_1.serializeAuthenticateWithRefreshTokenOptions)(Object.assign(Object.assign({}, payload), { clientSecret: this.workos.key })));
|
|
81
|
+
return (0, serializers_1.deserializeRefreshAuthenticationResponse)(data);
|
|
82
|
+
});
|
|
83
|
+
}
|
|
77
84
|
authenticateWithTotp(payload) {
|
|
78
85
|
return __awaiter(this, void 0, void 0, function* () {
|
|
79
86
|
const { data } = yield this.workos.post('/user_management/authenticate', (0, serializers_1.serializeAuthenticateWithTotpOptions)(Object.assign(Object.assign({}, payload), { clientSecret: this.workos.key })));
|
|
@@ -196,9 +203,14 @@ class UserManagement {
|
|
|
196
203
|
return (0, invitation_serializer_1.deserializeInvitation)(data);
|
|
197
204
|
});
|
|
198
205
|
}
|
|
206
|
+
revokeSession(payload) {
|
|
207
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
208
|
+
yield this.workos.post('/user_management/sessions/revoke', (0, revoke_session_options_interface_1.serializeRevokeSessionOptions)(payload));
|
|
209
|
+
});
|
|
210
|
+
}
|
|
199
211
|
getAuthorizationUrl({ connectionId, clientId, domainHint, loginHint, organizationId, provider, redirectUri, state, }) {
|
|
200
212
|
if (!provider && !connectionId && !organizationId) {
|
|
201
|
-
throw new
|
|
213
|
+
throw new TypeError(`Incomplete arguments. Need to specify either a 'connectionId', 'organizationId', or 'provider'.`);
|
|
202
214
|
}
|
|
203
215
|
const query = toQueryString({
|
|
204
216
|
connection_id: connectionId,
|
|
@@ -213,5 +225,17 @@ class UserManagement {
|
|
|
213
225
|
});
|
|
214
226
|
return `${this.workos.baseURL}/user_management/authorize?${query}`;
|
|
215
227
|
}
|
|
228
|
+
getLogoutUrl({ sessionId }) {
|
|
229
|
+
if (!sessionId) {
|
|
230
|
+
throw new TypeError(`Incomplete arguments. Need to specify 'sessionId'.`);
|
|
231
|
+
}
|
|
232
|
+
return `${this.workos.baseURL}/user_management/sessions/logout?session_id=${sessionId}`;
|
|
233
|
+
}
|
|
234
|
+
getJwksUrl(clientId) {
|
|
235
|
+
if (!clientId) {
|
|
236
|
+
throw TypeError('clientId must be a valid clientId');
|
|
237
|
+
}
|
|
238
|
+
return `${this.workos.baseURL}/sso/jwks/${clientId}`;
|
|
239
|
+
}
|
|
216
240
|
}
|
|
217
241
|
exports.UserManagement = UserManagement;
|
|
@@ -156,6 +156,29 @@ describe('UserManagement', () => {
|
|
|
156
156
|
});
|
|
157
157
|
}));
|
|
158
158
|
});
|
|
159
|
+
describe('authenticateWithRefreshToken', () => {
|
|
160
|
+
it('sends a refresh_token authentication request', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
161
|
+
(0, test_utils_1.fetchOnce)({
|
|
162
|
+
access_token: 'access_token',
|
|
163
|
+
refresh_token: 'refreshToken2',
|
|
164
|
+
});
|
|
165
|
+
const resp = yield workos.userManagement.authenticateWithRefreshToken({
|
|
166
|
+
clientId: 'proj_whatever',
|
|
167
|
+
refreshToken: 'refresh_token1',
|
|
168
|
+
});
|
|
169
|
+
expect((0, test_utils_1.fetchURL)()).toContain('/user_management/authenticate');
|
|
170
|
+
expect((0, test_utils_1.fetchBody)()).toEqual({
|
|
171
|
+
client_id: 'proj_whatever',
|
|
172
|
+
client_secret: 'sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU',
|
|
173
|
+
refresh_token: 'refresh_token1',
|
|
174
|
+
grant_type: 'refresh_token',
|
|
175
|
+
});
|
|
176
|
+
expect(resp).toMatchObject({
|
|
177
|
+
accessToken: 'access_token',
|
|
178
|
+
refreshToken: 'refreshToken2',
|
|
179
|
+
});
|
|
180
|
+
}));
|
|
181
|
+
});
|
|
159
182
|
describe('authenticateUserWithTotp', () => {
|
|
160
183
|
it('sends a token authentication request', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
161
184
|
(0, test_utils_1.fetchOnce)({ user: user_json_1.default });
|
|
@@ -444,6 +467,7 @@ describe('UserManagement', () => {
|
|
|
444
467
|
id: 'om_01H5JQDV7R7ATEYZDEG0W5PRYS',
|
|
445
468
|
userId: 'user_01H5JQDV7R7ATEYZDEG0W5PRYS',
|
|
446
469
|
organizationId: 'organization_01H5JQDV7R7ATEYZDEG0W5PRYS',
|
|
470
|
+
status: 'active',
|
|
447
471
|
});
|
|
448
472
|
}));
|
|
449
473
|
});
|
|
@@ -464,6 +488,7 @@ describe('UserManagement', () => {
|
|
|
464
488
|
object: 'organization_membership',
|
|
465
489
|
organizationId: 'organization_01H5JQDV7R7ATEYZDEG0W5PRYS',
|
|
466
490
|
userId: 'user_01H5JQDV7R7ATEYZDEG0W5PRYS',
|
|
491
|
+
status: 'active',
|
|
467
492
|
},
|
|
468
493
|
],
|
|
469
494
|
listMetadata: {
|
|
@@ -505,6 +530,7 @@ describe('UserManagement', () => {
|
|
|
505
530
|
object: 'organization_membership',
|
|
506
531
|
organizationId: 'organization_01H5JQDV7R7ATEYZDEG0W5PRYS',
|
|
507
532
|
userId: 'user_01H5JQDV7R7ATEYZDEG0W5PRYS',
|
|
533
|
+
status: 'active',
|
|
508
534
|
});
|
|
509
535
|
}));
|
|
510
536
|
});
|
|
@@ -606,6 +632,19 @@ describe('UserManagement', () => {
|
|
|
606
632
|
});
|
|
607
633
|
}));
|
|
608
634
|
});
|
|
635
|
+
describe('revokeSession', () => {
|
|
636
|
+
it('sends a Revoke Session request', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
637
|
+
const sessionId = 'session_12345';
|
|
638
|
+
(0, test_utils_1.fetchOnce)({});
|
|
639
|
+
yield workos.userManagement.revokeSession({
|
|
640
|
+
sessionId,
|
|
641
|
+
});
|
|
642
|
+
expect((0, test_utils_1.fetchURL)()).toContain('/user_management/sessions/revoke');
|
|
643
|
+
expect((0, test_utils_1.fetchBody)()).toEqual({
|
|
644
|
+
session_id: 'session_12345',
|
|
645
|
+
});
|
|
646
|
+
}));
|
|
647
|
+
});
|
|
609
648
|
describe('getAuthorizationUrl', () => {
|
|
610
649
|
describe('with no custom api hostname', () => {
|
|
611
650
|
it('generates an authorize url with the default api hostname', () => {
|
|
@@ -713,4 +752,26 @@ describe('UserManagement', () => {
|
|
|
713
752
|
});
|
|
714
753
|
});
|
|
715
754
|
});
|
|
755
|
+
describe('getLogoutUrl', () => {
|
|
756
|
+
it('returns a logout url', () => {
|
|
757
|
+
const workos = new workos_1.WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU');
|
|
758
|
+
const url = workos.userManagement.getLogoutUrl({
|
|
759
|
+
sessionId: '123456',
|
|
760
|
+
});
|
|
761
|
+
expect(url).toBe('https://api.workos.com/user_management/sessions/logout?session_id=123456');
|
|
762
|
+
});
|
|
763
|
+
});
|
|
764
|
+
describe('getJwksUrl', () => {
|
|
765
|
+
it('returns the jwks url', () => {
|
|
766
|
+
const workos = new workos_1.WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU');
|
|
767
|
+
const url = workos.userManagement.getJwksUrl('client_whatever');
|
|
768
|
+
expect(url).toBe('https://api.workos.com/sso/jwks/client_whatever');
|
|
769
|
+
});
|
|
770
|
+
it('throws an error if the clientId is blank', () => {
|
|
771
|
+
const workos = new workos_1.WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU');
|
|
772
|
+
expect(() => {
|
|
773
|
+
workos.userManagement.getJwksUrl('');
|
|
774
|
+
}).toThrowError(TypeError);
|
|
775
|
+
});
|
|
776
|
+
});
|
|
716
777
|
});
|
package/lib/workos.js
CHANGED
|
@@ -24,7 +24,7 @@ const audit_logs_1 = require("./audit-logs/audit-logs");
|
|
|
24
24
|
const user_management_1 = require("./user-management/user-management");
|
|
25
25
|
const bad_request_exception_1 = require("./common/exceptions/bad-request.exception");
|
|
26
26
|
const fetch_client_1 = require("./common/utils/fetch-client");
|
|
27
|
-
const VERSION = '6.0
|
|
27
|
+
const VERSION = '6.2.0';
|
|
28
28
|
const DEFAULT_HOSTNAME = 'api.workos.com';
|
|
29
29
|
class WorkOS {
|
|
30
30
|
constructor(key, options = {}) {
|
package/package.json
CHANGED