@workos-inc/node 7.11.4 → 7.13.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/user-management/fixtures/identity.json +12 -0
- package/lib/user-management/interfaces/authentication-response.interface.d.ts +0 -8
- package/lib/user-management/interfaces/identity.interface.d.ts +10 -0
- package/lib/user-management/interfaces/identity.interface.js +2 -0
- package/lib/user-management/serializers/authentication-response.serializer.d.ts +1 -2
- package/lib/user-management/serializers/authentication-response.serializer.js +1 -6
- package/lib/user-management/serializers/identity.serializer.d.ts +2 -0
- package/lib/user-management/serializers/identity.serializer.js +13 -0
- package/lib/user-management/user-management.d.ts +4 -2
- package/lib/user-management/user-management.js +11 -1
- package/lib/user-management/user-management.spec.js +21 -0
- package/lib/workos.js +1 -1
- package/package.json +1 -1
|
@@ -17,12 +17,4 @@ export interface AuthenticationResponseResponse {
|
|
|
17
17
|
impersonator?: ImpersonatorResponse;
|
|
18
18
|
authentication_method?: AuthenticationMethod;
|
|
19
19
|
}
|
|
20
|
-
export interface RefreshAuthenticationResponse {
|
|
21
|
-
accessToken: string;
|
|
22
|
-
refreshToken: string;
|
|
23
|
-
}
|
|
24
|
-
export interface RefreshAuthenticationResponseResponse {
|
|
25
|
-
access_token: string;
|
|
26
|
-
refresh_token: string;
|
|
27
|
-
}
|
|
28
20
|
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export interface Identity {
|
|
2
|
+
idpId: string;
|
|
3
|
+
type: 'OAuth';
|
|
4
|
+
provider: 'AppleOAuth' | 'GoogleOAuth' | 'GitHubOAuth' | 'MicrosoftOAuth';
|
|
5
|
+
}
|
|
6
|
+
export interface IdentityResponse {
|
|
7
|
+
idp_id: string;
|
|
8
|
+
type: 'OAuth';
|
|
9
|
+
provider: 'AppleOAuth' | 'GoogleOAuth' | 'GitHubOAuth' | 'MicrosoftOAuth';
|
|
10
|
+
}
|
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
import { AuthenticationResponse, AuthenticationResponseResponse
|
|
1
|
+
import { AuthenticationResponse, AuthenticationResponseResponse } from '../interfaces';
|
|
2
2
|
export declare const deserializeAuthenticationResponse: (authenticationResponse: AuthenticationResponseResponse) => AuthenticationResponse;
|
|
3
|
-
export declare const deserializeRefreshAuthenticationResponse: (refreshAuthenticationResponse: RefreshAuthenticationResponseResponse) => RefreshAuthenticationResponse;
|
|
@@ -11,15 +11,10 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
11
11
|
return t;
|
|
12
12
|
};
|
|
13
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
-
exports.
|
|
14
|
+
exports.deserializeAuthenticationResponse = void 0;
|
|
15
15
|
const user_serializer_1 = require("./user.serializer");
|
|
16
16
|
const deserializeAuthenticationResponse = (authenticationResponse) => {
|
|
17
17
|
const { user, organization_id, access_token, refresh_token, authentication_method, impersonator } = authenticationResponse, rest = __rest(authenticationResponse, ["user", "organization_id", "access_token", "refresh_token", "authentication_method", "impersonator"]);
|
|
18
18
|
return Object.assign({ user: (0, user_serializer_1.deserializeUser)(user), organizationId: organization_id, accessToken: access_token, refreshToken: refresh_token, impersonator, authenticationMethod: authentication_method }, 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;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.deserializeIdentities = void 0;
|
|
4
|
+
const deserializeIdentities = (identities) => {
|
|
5
|
+
return identities.map((identity) => {
|
|
6
|
+
return {
|
|
7
|
+
idpId: identity.idp_id,
|
|
8
|
+
type: identity.type,
|
|
9
|
+
provider: identity.provider,
|
|
10
|
+
};
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
exports.deserializeIdentities = deserializeIdentities;
|
|
@@ -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, AuthenticateWithRefreshTokenOptions,
|
|
3
|
+
import { AuthenticateWithCodeOptions, AuthenticateWithMagicAuthOptions, AuthenticateWithPasswordOptions, AuthenticateWithTotpOptions, AuthenticationResponse, ResetPasswordOptions, SendPasswordResetEmailOptions, CreateUserOptions, EnrollAuthFactorOptions, ListAuthFactorsOptions, ListUsersOptions, SendMagicAuthCodeOptions, SendVerificationEmailOptions, UpdateUserOptions, User, VerifyEmailOptions, AuthenticateWithRefreshTokenOptions, MagicAuth, CreateMagicAuthOptions, EmailVerification, PasswordReset, CreatePasswordResetOptions } 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';
|
|
@@ -14,6 +14,7 @@ import { AuthenticateWithOrganizationSelectionOptions } from './interfaces/authe
|
|
|
14
14
|
import { Factor, FactorWithSecrets } from './interfaces/factor.interface';
|
|
15
15
|
import { RevokeSessionOptions } from './interfaces/revoke-session-options.interface';
|
|
16
16
|
import { UpdateOrganizationMembershipOptions } from './interfaces/update-organization-membership-options.interface';
|
|
17
|
+
import { Identity } from './interfaces/identity.interface';
|
|
17
18
|
export declare class UserManagement {
|
|
18
19
|
private readonly workos;
|
|
19
20
|
constructor(workos: WorkOS);
|
|
@@ -23,7 +24,7 @@ export declare class UserManagement {
|
|
|
23
24
|
authenticateWithMagicAuth(payload: AuthenticateWithMagicAuthOptions): Promise<AuthenticationResponse>;
|
|
24
25
|
authenticateWithPassword(payload: AuthenticateWithPasswordOptions): Promise<AuthenticationResponse>;
|
|
25
26
|
authenticateWithCode(payload: AuthenticateWithCodeOptions): Promise<AuthenticationResponse>;
|
|
26
|
-
authenticateWithRefreshToken(payload: AuthenticateWithRefreshTokenOptions): Promise<
|
|
27
|
+
authenticateWithRefreshToken(payload: AuthenticateWithRefreshTokenOptions): Promise<AuthenticationResponse>;
|
|
27
28
|
authenticateWithTotp(payload: AuthenticateWithTotpOptions): Promise<AuthenticationResponse>;
|
|
28
29
|
authenticateWithEmailVerification(payload: AuthenticateWithEmailVerificationOptions): Promise<AuthenticationResponse>;
|
|
29
30
|
authenticateWithOrganizationSelection(payload: AuthenticateWithOrganizationSelectionOptions): Promise<AuthenticationResponse>;
|
|
@@ -56,6 +57,7 @@ export declare class UserManagement {
|
|
|
56
57
|
}>;
|
|
57
58
|
listAuthFactors(options: ListAuthFactorsOptions): Promise<AutoPaginatable<Factor>>;
|
|
58
59
|
deleteUser(userId: string): Promise<void>;
|
|
60
|
+
getUserIdentities(userId: string): Promise<Identity[]>;
|
|
59
61
|
getOrganizationMembership(organizationMembershipId: string): Promise<OrganizationMembership>;
|
|
60
62
|
listOrganizationMemberships(options: ListOrganizationMembershipsOptions): Promise<AutoPaginatable<OrganizationMembership>>;
|
|
61
63
|
createOrganizationMembership(options: CreateOrganizationMembershipOptions): Promise<OrganizationMembership>;
|
|
@@ -37,6 +37,7 @@ const authenticate_with_organization_selection_options_serializer_1 = require(".
|
|
|
37
37
|
const factor_serializer_1 = require("./serializers/factor.serializer");
|
|
38
38
|
const revoke_session_options_interface_1 = require("./interfaces/revoke-session-options.interface");
|
|
39
39
|
const update_organization_membership_options_serializer_1 = require("./serializers/update-organization-membership-options.serializer");
|
|
40
|
+
const identity_serializer_1 = require("./serializers/identity.serializer");
|
|
40
41
|
const toQueryString = (options) => {
|
|
41
42
|
const searchParams = new URLSearchParams();
|
|
42
43
|
const keys = Object.keys(options).sort();
|
|
@@ -90,7 +91,7 @@ class UserManagement {
|
|
|
90
91
|
authenticateWithRefreshToken(payload) {
|
|
91
92
|
return __awaiter(this, void 0, void 0, function* () {
|
|
92
93
|
const { data } = yield this.workos.post('/user_management/authenticate', (0, serializers_1.serializeAuthenticateWithRefreshTokenOptions)(Object.assign(Object.assign({}, payload), { clientSecret: this.workos.key })));
|
|
93
|
-
return (0, serializers_1.
|
|
94
|
+
return (0, serializers_1.deserializeAuthenticationResponse)(data);
|
|
94
95
|
});
|
|
95
96
|
}
|
|
96
97
|
authenticateWithTotp(payload) {
|
|
@@ -203,6 +204,15 @@ class UserManagement {
|
|
|
203
204
|
yield this.workos.delete(`/user_management/users/${userId}`);
|
|
204
205
|
});
|
|
205
206
|
}
|
|
207
|
+
getUserIdentities(userId) {
|
|
208
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
209
|
+
if (!userId) {
|
|
210
|
+
throw new TypeError(`Incomplete arguments. Need to specify 'userId'.`);
|
|
211
|
+
}
|
|
212
|
+
const { data } = yield this.workos.get(`/user_management/users/${userId}/identities`);
|
|
213
|
+
return (0, identity_serializer_1.deserializeIdentities)(data);
|
|
214
|
+
});
|
|
215
|
+
}
|
|
206
216
|
getOrganizationMembership(organizationMembershipId) {
|
|
207
217
|
return __awaiter(this, void 0, void 0, function* () {
|
|
208
218
|
const { data } = yield this.workos.get(`/user_management/organization_memberships/${organizationMembershipId}`);
|
|
@@ -26,6 +26,7 @@ const magic_auth_json_1 = __importDefault(require("./fixtures/magic_auth.json"))
|
|
|
26
26
|
const organization_membership_json_1 = __importDefault(require("./fixtures/organization-membership.json"));
|
|
27
27
|
const password_reset_json_1 = __importDefault(require("./fixtures/password_reset.json"));
|
|
28
28
|
const user_json_1 = __importDefault(require("./fixtures/user.json"));
|
|
29
|
+
const identity_json_1 = __importDefault(require("./fixtures/identity.json"));
|
|
29
30
|
const workos = new workos_1.WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU');
|
|
30
31
|
const userId = 'user_01H5JQDV7R7ATEYZDEG0W5PRYS';
|
|
31
32
|
const organizationMembershipId = 'om_01H5JQDV7R7ATEYZDEG0W5PRYS';
|
|
@@ -228,6 +229,7 @@ describe('UserManagement', () => {
|
|
|
228
229
|
describe('authenticateWithRefreshToken', () => {
|
|
229
230
|
it('sends a refresh_token authentication request', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
230
231
|
(0, test_utils_1.fetchOnce)({
|
|
232
|
+
user: user_json_1.default,
|
|
231
233
|
access_token: 'access_token',
|
|
232
234
|
refresh_token: 'refreshToken2',
|
|
233
235
|
});
|
|
@@ -615,6 +617,25 @@ describe('UserManagement', () => {
|
|
|
615
617
|
expect(resp).toBeUndefined();
|
|
616
618
|
}));
|
|
617
619
|
});
|
|
620
|
+
describe('getUserIdentities', () => {
|
|
621
|
+
it('sends a Get User Identities request', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
622
|
+
(0, test_utils_1.fetchOnce)(identity_json_1.default);
|
|
623
|
+
const resp = yield workos.userManagement.getUserIdentities(userId);
|
|
624
|
+
expect((0, test_utils_1.fetchURL)()).toContain(`/user_management/users/${userId}/identities`);
|
|
625
|
+
expect(resp).toMatchObject([
|
|
626
|
+
{
|
|
627
|
+
idpId: '108872335',
|
|
628
|
+
type: 'OAuth',
|
|
629
|
+
provider: 'GithubOAuth',
|
|
630
|
+
},
|
|
631
|
+
{
|
|
632
|
+
idpId: '111966195055680542408',
|
|
633
|
+
type: 'OAuth',
|
|
634
|
+
provider: 'GoogleOAuth',
|
|
635
|
+
},
|
|
636
|
+
]);
|
|
637
|
+
}));
|
|
638
|
+
});
|
|
618
639
|
describe('getOrganizationMembership', () => {
|
|
619
640
|
it('sends a Get OrganizationMembership request', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
620
641
|
(0, test_utils_1.fetchOnce)(organization_membership_json_1.default, {
|
package/lib/workos.js
CHANGED
|
@@ -26,7 +26,7 @@ const bad_request_exception_1 = require("./common/exceptions/bad-request.excepti
|
|
|
26
26
|
const http_client_1 = require("./common/net/http-client");
|
|
27
27
|
const subtle_crypto_provider_1 = require("./common/crypto/subtle-crypto-provider");
|
|
28
28
|
const fetch_client_1 = require("./common/net/fetch-client");
|
|
29
|
-
const VERSION = '7.
|
|
29
|
+
const VERSION = '7.13.0';
|
|
30
30
|
const DEFAULT_HOSTNAME = 'api.workos.com';
|
|
31
31
|
class WorkOS {
|
|
32
32
|
constructor(key, options = {}) {
|
package/package.json
CHANGED