@workos-inc/node 3.0.0-alpha.1 → 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/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/sso/interfaces/connection.interface.d.ts +19 -0
- 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 +6 -4
- package/lib/sso/sso.spec.js +24 -6
- package/lib/users/interfaces/authenticate-user-with-password-options.interface.d.ts +7 -2
- package/lib/users/interfaces/authenticate-user-with-token-options.interface.d.ts +1 -4
- package/lib/users/interfaces/index.d.ts +2 -0
- package/lib/users/interfaces/index.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/serializers/authenticate-user-with-password-options.serializer.d.ts +2 -2
- package/lib/users/serializers/authenticate-user-with-password-options.serializer.js +3 -1
- package/lib/users/serializers/authenticate-user-with-token-options.serializer.js +1 -2
- package/lib/users/serializers/index.d.ts +2 -0
- package/lib/users/serializers/index.js +2 -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/users.d.ts +3 -1
- package/lib/users/users.js +14 -2
- package/lib/users/users.spec.js +30 -2
- package/lib/workos.js +1 -1
- package/package.json +1 -1
|
@@ -6,3 +6,11 @@ export interface CreatePasswordlessSessionOptions {
|
|
|
6
6
|
connection?: string;
|
|
7
7
|
expiresIn?: number;
|
|
8
8
|
}
|
|
9
|
+
export interface SerializedCreatePasswordlessSessionOptions {
|
|
10
|
+
type: 'MagicLink';
|
|
11
|
+
email: string;
|
|
12
|
+
redirect_uri?: string;
|
|
13
|
+
state?: string;
|
|
14
|
+
connection?: string;
|
|
15
|
+
expires_in?: number;
|
|
16
|
+
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export
|
|
1
|
+
export * from './passwordless-session.interface';
|
|
2
|
+
export * from './create-passwordless-session-options.interface';
|
|
3
|
+
export * from './send-session-response.interface';
|
|
@@ -1,2 +1,19 @@
|
|
|
1
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
|
+
};
|
|
2
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./passwordless-session.interface"), exports);
|
|
18
|
+
__exportStar(require("./create-passwordless-session-options.interface"), exports);
|
|
19
|
+
__exportStar(require("./send-session-response.interface"), exports);
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { WorkOS } from '../workos';
|
|
2
|
-
import { PasswordlessSession } from './interfaces
|
|
3
|
-
import { CreatePasswordlessSessionOptions } from './interfaces/create-passwordless-session-options.interface';
|
|
4
|
-
import { SendSessionResponse } from './interfaces/send-session-response.interface';
|
|
2
|
+
import { CreatePasswordlessSessionOptions, PasswordlessSession, SendSessionResponse } from './interfaces';
|
|
5
3
|
export declare class Passwordless {
|
|
6
4
|
private readonly workos;
|
|
7
5
|
constructor(workos: WorkOS);
|
|
@@ -21,6 +21,7 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
21
21
|
};
|
|
22
22
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
23
|
exports.Passwordless = void 0;
|
|
24
|
+
const passwordless_session_serializer_1 = require("./serializers/passwordless-session.serializer");
|
|
24
25
|
class Passwordless {
|
|
25
26
|
constructor(workos) {
|
|
26
27
|
this.workos = workos;
|
|
@@ -29,7 +30,7 @@ class Passwordless {
|
|
|
29
30
|
var { redirectURI, expiresIn } = _a, options = __rest(_a, ["redirectURI", "expiresIn"]);
|
|
30
31
|
return __awaiter(this, void 0, void 0, function* () {
|
|
31
32
|
const { data } = yield this.workos.post('/passwordless/sessions', Object.assign(Object.assign({}, options), { redirect_uri: redirectURI, expires_in: expiresIn }));
|
|
32
|
-
return data;
|
|
33
|
+
return (0, passwordless_session_serializer_1.deserializePasswordlessSession)(data);
|
|
33
34
|
});
|
|
34
35
|
}
|
|
35
36
|
sendSession(sessionId) {
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.deserializePasswordlessSession = void 0;
|
|
4
|
+
const deserializePasswordlessSession = (passwordlessSession) => ({
|
|
5
|
+
id: passwordlessSession.id,
|
|
6
|
+
email: passwordlessSession.email,
|
|
7
|
+
expiresAt: passwordlessSession.expires_at,
|
|
8
|
+
link: passwordlessSession.link,
|
|
9
|
+
object: passwordlessSession.object,
|
|
10
|
+
});
|
|
11
|
+
exports.deserializePasswordlessSession = deserializePasswordlessSession;
|
|
@@ -5,6 +5,25 @@ export interface ConnectionDomain {
|
|
|
5
5
|
domain: string;
|
|
6
6
|
}
|
|
7
7
|
export interface Connection {
|
|
8
|
+
object: 'connection';
|
|
9
|
+
id: string;
|
|
10
|
+
organizationId?: string;
|
|
11
|
+
name: string;
|
|
12
|
+
/**
|
|
13
|
+
* @deprecated The connectionType parameter has been deprecated. Please use type.
|
|
14
|
+
*/
|
|
15
|
+
connectionType: ConnectionType;
|
|
16
|
+
state: 'draft' | 'active' | 'inactive' | 'validating';
|
|
17
|
+
/**
|
|
18
|
+
* @deprecated The status parameter has been deprecated. Please use state.
|
|
19
|
+
*/
|
|
20
|
+
status: 'linked' | 'unlinked';
|
|
21
|
+
domains: ConnectionDomain[];
|
|
22
|
+
type: ConnectionType;
|
|
23
|
+
createdAt: string;
|
|
24
|
+
updatedAt: string;
|
|
25
|
+
}
|
|
26
|
+
export interface ConnectionResponse {
|
|
8
27
|
object: 'connection';
|
|
9
28
|
id: string;
|
|
10
29
|
organization_id?: string;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export * from './authorization-url-options.interface';
|
|
2
2
|
export * from './connection-type.enum';
|
|
3
3
|
export * from './connection.interface';
|
|
4
|
+
export * from './get-profile-options.interface';
|
|
4
5
|
export * from './get-profile-and-token-options.interface';
|
|
6
|
+
export * from './list-connections-options.interface';
|
|
5
7
|
export * from './profile-and-token.interface';
|
|
6
8
|
export * from './profile.interface';
|
|
@@ -17,6 +17,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
__exportStar(require("./authorization-url-options.interface"), exports);
|
|
18
18
|
__exportStar(require("./connection-type.enum"), exports);
|
|
19
19
|
__exportStar(require("./connection.interface"), exports);
|
|
20
|
+
__exportStar(require("./get-profile-options.interface"), exports);
|
|
20
21
|
__exportStar(require("./get-profile-and-token-options.interface"), exports);
|
|
22
|
+
__exportStar(require("./list-connections-options.interface"), exports);
|
|
21
23
|
__exportStar(require("./profile-and-token.interface"), exports);
|
|
22
24
|
__exportStar(require("./profile.interface"), exports);
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { PaginationOptions } from '../../common/interfaces/pagination-options.interface';
|
|
2
2
|
import { ConnectionType } from './connection-type.enum';
|
|
3
3
|
export interface ListConnectionsOptions extends PaginationOptions {
|
|
4
|
+
connectionType?: ConnectionType;
|
|
5
|
+
domain?: string;
|
|
6
|
+
organizationId?: string;
|
|
7
|
+
}
|
|
8
|
+
export interface SerializedListConnectionsOptions extends PaginationOptions {
|
|
4
9
|
connection_type?: ConnectionType;
|
|
5
10
|
domain?: string;
|
|
6
11
|
organization_id?: string;
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
import { Profile } from './profile.interface';
|
|
1
|
+
import { Profile, ProfileResponse } from './profile.interface';
|
|
2
2
|
export interface ProfileAndToken {
|
|
3
|
-
|
|
3
|
+
accessToken: string;
|
|
4
4
|
profile: Profile;
|
|
5
5
|
}
|
|
6
|
+
export interface ProfileAndTokenResponse {
|
|
7
|
+
access_token: string;
|
|
8
|
+
profile: ProfileResponse;
|
|
9
|
+
}
|
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
import { ConnectionType } from './connection-type.enum';
|
|
2
2
|
export interface Profile {
|
|
3
|
+
id: string;
|
|
4
|
+
idpId: string;
|
|
5
|
+
organizationId?: string;
|
|
6
|
+
connectionId: string;
|
|
7
|
+
connectionType: ConnectionType;
|
|
8
|
+
email: string;
|
|
9
|
+
firstName?: string;
|
|
10
|
+
lastName?: string;
|
|
11
|
+
groups?: string[];
|
|
12
|
+
rawAttributes?: {
|
|
13
|
+
[key: string]: any;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
export interface ProfileResponse {
|
|
3
17
|
id: string;
|
|
4
18
|
idp_id: string;
|
|
5
19
|
organization_id?: string;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.deserializeConnection = void 0;
|
|
4
|
+
const deserializeConnection = (connection) => ({
|
|
5
|
+
object: connection.object,
|
|
6
|
+
id: connection.id,
|
|
7
|
+
organizationId: connection.organization_id,
|
|
8
|
+
name: connection.name,
|
|
9
|
+
connectionType: connection.connection_type,
|
|
10
|
+
type: connection.connection_type,
|
|
11
|
+
state: connection.state,
|
|
12
|
+
status: connection.status,
|
|
13
|
+
domains: connection.domains,
|
|
14
|
+
createdAt: connection.created_at,
|
|
15
|
+
updatedAt: connection.updated_at,
|
|
16
|
+
});
|
|
17
|
+
exports.deserializeConnection = deserializeConnection;
|
|
@@ -0,0 +1,19 @@
|
|
|
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("./connection.serializer"), exports);
|
|
18
|
+
__exportStar(require("./profile-and-token.serializer"), exports);
|
|
19
|
+
__exportStar(require("./profile.serializer"), exports);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.deserializeProfileAndToken = void 0;
|
|
4
|
+
const profile_serializer_1 = require("./profile.serializer");
|
|
5
|
+
const deserializeProfileAndToken = (profileAndToken) => ({
|
|
6
|
+
accessToken: profileAndToken.access_token,
|
|
7
|
+
profile: (0, profile_serializer_1.deserializeProfile)(profileAndToken.profile),
|
|
8
|
+
});
|
|
9
|
+
exports.deserializeProfileAndToken = deserializeProfileAndToken;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.deserializeProfile = void 0;
|
|
4
|
+
const deserializeProfile = (profile) => ({
|
|
5
|
+
id: profile.id,
|
|
6
|
+
idpId: profile.idp_id,
|
|
7
|
+
organizationId: profile.organization_id,
|
|
8
|
+
connectionId: profile.connection_id,
|
|
9
|
+
connectionType: profile.connection_type,
|
|
10
|
+
email: profile.email,
|
|
11
|
+
firstName: profile.first_name,
|
|
12
|
+
lastName: profile.last_name,
|
|
13
|
+
groups: profile.groups,
|
|
14
|
+
rawAttributes: profile.raw_attributes,
|
|
15
|
+
});
|
|
16
|
+
exports.deserializeProfile = deserializeProfile;
|
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
|
@@ -10,6 +10,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.SSO = void 0;
|
|
13
|
+
const serializers_1 = require("../common/serializers");
|
|
14
|
+
const serializers_2 = require("./serializers");
|
|
13
15
|
const toQueryString = (options) => {
|
|
14
16
|
const searchParams = new URLSearchParams();
|
|
15
17
|
const keys = Object.keys(options).sort();
|
|
@@ -54,7 +56,7 @@ class SSO {
|
|
|
54
56
|
getConnection(id) {
|
|
55
57
|
return __awaiter(this, void 0, void 0, function* () {
|
|
56
58
|
const { data } = yield this.workos.get(`/connections/${id}`);
|
|
57
|
-
return data;
|
|
59
|
+
return (0, serializers_2.deserializeConnection)(data);
|
|
58
60
|
});
|
|
59
61
|
}
|
|
60
62
|
getProfileAndToken({ code, clientID, }) {
|
|
@@ -66,7 +68,7 @@ class SSO {
|
|
|
66
68
|
code,
|
|
67
69
|
});
|
|
68
70
|
const { data } = yield this.workos.post('/sso/token', form);
|
|
69
|
-
return data;
|
|
71
|
+
return (0, serializers_2.deserializeProfileAndToken)(data);
|
|
70
72
|
});
|
|
71
73
|
}
|
|
72
74
|
getProfile({ accessToken }) {
|
|
@@ -74,7 +76,7 @@ class SSO {
|
|
|
74
76
|
const { data } = yield this.workos.get('/sso/profile', {
|
|
75
77
|
accessToken,
|
|
76
78
|
});
|
|
77
|
-
return data;
|
|
79
|
+
return (0, serializers_2.deserializeProfile)(data);
|
|
78
80
|
});
|
|
79
81
|
}
|
|
80
82
|
listConnections(options) {
|
|
@@ -82,7 +84,7 @@ class SSO {
|
|
|
82
84
|
const { data } = yield this.workos.get(`/connections`, {
|
|
83
85
|
query: options,
|
|
84
86
|
});
|
|
85
|
-
return data;
|
|
87
|
+
return (0, serializers_1.deserializeList)(data, serializers_2.deserializeConnection);
|
|
86
88
|
});
|
|
87
89
|
}
|
|
88
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', () => {
|
|
@@ -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
|
});
|
|
@@ -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
|
});
|
|
@@ -1,16 +1,21 @@
|
|
|
1
1
|
export interface AuthenticateUserWithPasswordOptions {
|
|
2
|
+
clientId: string;
|
|
2
3
|
email: string;
|
|
3
4
|
password: string;
|
|
4
5
|
ipAddress?: string;
|
|
5
6
|
userAgent?: string;
|
|
6
|
-
startSession?: boolean;
|
|
7
7
|
expiresIn?: number;
|
|
8
8
|
}
|
|
9
|
+
export interface AuthenticateUserWithPasswordCredentials {
|
|
10
|
+
clientSecret: string | undefined;
|
|
11
|
+
}
|
|
9
12
|
export interface SerializedAuthenticateUserWithPasswordOptions {
|
|
13
|
+
grant_type: 'password';
|
|
14
|
+
client_id: string;
|
|
15
|
+
client_secret: string | undefined;
|
|
10
16
|
email: string;
|
|
11
17
|
password: string;
|
|
12
18
|
ip_address?: string;
|
|
13
19
|
user_agent?: string;
|
|
14
|
-
start_session?: boolean;
|
|
15
20
|
expires_in?: number;
|
|
16
21
|
}
|
|
@@ -1,18 +1,15 @@
|
|
|
1
1
|
export interface AuthenticateUserWithTokenOptions {
|
|
2
2
|
clientId: string;
|
|
3
3
|
code: string;
|
|
4
|
-
startSession?: boolean;
|
|
5
4
|
expiresIn?: number;
|
|
6
5
|
}
|
|
7
6
|
export interface AuthenticateUserWithTokenCredentials {
|
|
8
7
|
clientSecret: string | undefined;
|
|
9
|
-
grantType: string;
|
|
10
8
|
}
|
|
11
9
|
export interface SerializedAuthenticateUserWithTokenOptions {
|
|
10
|
+
grant_type: 'authorization_code';
|
|
12
11
|
client_id: string;
|
|
13
12
|
client_secret: string | undefined;
|
|
14
13
|
code: string;
|
|
15
|
-
grant_type: string;
|
|
16
|
-
start_session?: boolean;
|
|
17
14
|
expires_in?: number;
|
|
18
15
|
}
|
|
@@ -11,3 +11,5 @@ export * from './remove-user-from-organization-options.interface';
|
|
|
11
11
|
export * from './revoke-session-options.interface';
|
|
12
12
|
export * from './user.interface';
|
|
13
13
|
export * from './verify-session.interface';
|
|
14
|
+
export * from './update-user-password-options.interface';
|
|
15
|
+
export * from './update-user-options.interface';
|
|
@@ -27,3 +27,5 @@ __exportStar(require("./remove-user-from-organization-options.interface"), expor
|
|
|
27
27
|
__exportStar(require("./revoke-session-options.interface"), exports);
|
|
28
28
|
__exportStar(require("./user.interface"), exports);
|
|
29
29
|
__exportStar(require("./verify-session.interface"), exports);
|
|
30
|
+
__exportStar(require("./update-user-password-options.interface"), exports);
|
|
31
|
+
__exportStar(require("./update-user-options.interface"), exports);
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { AuthenticateUserWithPasswordOptions, SerializedAuthenticateUserWithPasswordOptions } from '../interfaces';
|
|
2
|
-
export declare const serializeAuthenticateUserWithPasswordOptions: (options: AuthenticateUserWithPasswordOptions) => SerializedAuthenticateUserWithPasswordOptions;
|
|
1
|
+
import { AuthenticateUserWithPasswordCredentials, AuthenticateUserWithPasswordOptions, SerializedAuthenticateUserWithPasswordOptions } from '../interfaces';
|
|
2
|
+
export declare const serializeAuthenticateUserWithPasswordOptions: (options: AuthenticateUserWithPasswordOptions & AuthenticateUserWithPasswordCredentials) => SerializedAuthenticateUserWithPasswordOptions;
|
|
@@ -2,11 +2,13 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.serializeAuthenticateUserWithPasswordOptions = void 0;
|
|
4
4
|
const serializeAuthenticateUserWithPasswordOptions = (options) => ({
|
|
5
|
+
grant_type: 'password',
|
|
6
|
+
client_id: options.clientId,
|
|
7
|
+
client_secret: options.clientSecret,
|
|
5
8
|
email: options.email,
|
|
6
9
|
password: options.password,
|
|
7
10
|
ip_address: options.ipAddress,
|
|
8
11
|
user_agent: options.userAgent,
|
|
9
|
-
start_session: options.startSession,
|
|
10
12
|
expires_in: options.expiresIn,
|
|
11
13
|
});
|
|
12
14
|
exports.serializeAuthenticateUserWithPasswordOptions = serializeAuthenticateUserWithPasswordOptions;
|
|
@@ -2,11 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.serializeAuthenticateUserWithTokenOptions = void 0;
|
|
4
4
|
const serializeAuthenticateUserWithTokenOptions = (options) => ({
|
|
5
|
+
grant_type: 'authorization_code',
|
|
5
6
|
client_id: options.clientId,
|
|
6
7
|
client_secret: options.clientSecret,
|
|
7
8
|
code: options.code,
|
|
8
|
-
grant_type: options.grantType,
|
|
9
|
-
start_session: options.startSession,
|
|
10
9
|
expires_in: options.expiresIn,
|
|
11
10
|
});
|
|
12
11
|
exports.serializeAuthenticateUserWithTokenOptions = serializeAuthenticateUserWithTokenOptions;
|
|
@@ -7,5 +7,7 @@ export * from './create-password-reset-challenge.serializer';
|
|
|
7
7
|
export * from './create-user-options.serializer';
|
|
8
8
|
export * from './revoke-session-options.serializer';
|
|
9
9
|
export * from './session.serializer';
|
|
10
|
+
export * from './update-user-password-options.serializer';
|
|
11
|
+
export * from './update-user-options.serializer';
|
|
10
12
|
export * from './user.serializer';
|
|
11
13
|
export * from './verify-session.serializer';
|
|
@@ -23,5 +23,7 @@ __exportStar(require("./create-password-reset-challenge.serializer"), exports);
|
|
|
23
23
|
__exportStar(require("./create-user-options.serializer"), exports);
|
|
24
24
|
__exportStar(require("./revoke-session-options.serializer"), exports);
|
|
25
25
|
__exportStar(require("./session.serializer"), exports);
|
|
26
|
+
__exportStar(require("./update-user-password-options.serializer"), exports);
|
|
27
|
+
__exportStar(require("./update-user-options.serializer"), exports);
|
|
26
28
|
__exportStar(require("./user.serializer"), exports);
|
|
27
29
|
__exportStar(require("./verify-session.serializer"), exports);
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.serializeUpdateUserOptions = void 0;
|
|
4
|
+
const serializeUpdateUserOptions = (options) => ({
|
|
5
|
+
first_name: options.firstName,
|
|
6
|
+
last_name: options.lastName,
|
|
7
|
+
});
|
|
8
|
+
exports.serializeUpdateUserOptions = serializeUpdateUserOptions;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.serializeUpdateUserPasswordOptions = void 0;
|
|
4
|
+
const serializeUpdateUserPasswordOptions = (options) => ({
|
|
5
|
+
password: options.password,
|
|
6
|
+
});
|
|
7
|
+
exports.serializeUpdateUserPasswordOptions = serializeUpdateUserPasswordOptions;
|
package/lib/users/users.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { WorkOS } from '../workos';
|
|
2
|
-
import { AddUserToOrganizationOptions, AuthenticateUserWithPasswordOptions, AuthenticateUserWithTokenOptions, AuthenticationResponse, CompletePasswordResetOptions, CreateEmailVerificationChallengeOptions, CreateEmailVerificationChallengeResponse, CreatePasswordResetChallengeOptions, CreatePasswordResetChallengeResponse, CreateUserOptions, ListUsersOptions, RemoveUserFromOrganizationOptions, RevokeSessionOptions, User, VerifySessionOptions, VerifySessionResponse } from './interfaces';
|
|
2
|
+
import { AddUserToOrganizationOptions, AuthenticateUserWithPasswordOptions, AuthenticateUserWithTokenOptions, AuthenticationResponse, CompletePasswordResetOptions, CreateEmailVerificationChallengeOptions, CreateEmailVerificationChallengeResponse, CreatePasswordResetChallengeOptions, CreatePasswordResetChallengeResponse, CreateUserOptions, ListUsersOptions, RemoveUserFromOrganizationOptions, RevokeSessionOptions, UpdateUserOptions, UpdateUserPasswordOptions, User, VerifySessionOptions, VerifySessionResponse } from './interfaces';
|
|
3
3
|
import { DeserializedList } from '../common/interfaces';
|
|
4
4
|
export declare class Users {
|
|
5
5
|
private readonly workos;
|
|
@@ -18,4 +18,6 @@ export declare class Users {
|
|
|
18
18
|
completePasswordReset(payload: CompletePasswordResetOptions): Promise<User>;
|
|
19
19
|
addUserToOrganization({ userId, organizationId, }: AddUserToOrganizationOptions): Promise<User>;
|
|
20
20
|
removeUserFromOrganization({ userId, organizationId, }: RemoveUserFromOrganizationOptions): Promise<User>;
|
|
21
|
+
updateUser(payload: UpdateUserOptions): Promise<User>;
|
|
22
|
+
updateUserPassword(payload: UpdateUserPasswordOptions): Promise<User>;
|
|
21
23
|
}
|
package/lib/users/users.js
CHANGED
|
@@ -38,13 +38,13 @@ class Users {
|
|
|
38
38
|
}
|
|
39
39
|
authenticateUserWithPassword(payload) {
|
|
40
40
|
return __awaiter(this, void 0, void 0, function* () {
|
|
41
|
-
const { data } = yield this.workos.post('/users/
|
|
41
|
+
const { data } = yield this.workos.post('/users/sessions/token', (0, serializers_1.serializeAuthenticateUserWithPasswordOptions)(Object.assign(Object.assign({}, payload), { clientSecret: this.workos.key })));
|
|
42
42
|
return (0, serializers_1.deserializeAuthenticationResponse)(data);
|
|
43
43
|
});
|
|
44
44
|
}
|
|
45
45
|
authenticateUserWithToken(payload) {
|
|
46
46
|
return __awaiter(this, void 0, void 0, function* () {
|
|
47
|
-
const { data } = yield this.workos.post('/users/sessions/token', (0, serializers_1.serializeAuthenticateUserWithTokenOptions)(Object.assign(Object.assign({}, payload), { clientSecret: this.workos.key
|
|
47
|
+
const { data } = yield this.workos.post('/users/sessions/token', (0, serializers_1.serializeAuthenticateUserWithTokenOptions)(Object.assign(Object.assign({}, payload), { clientSecret: this.workos.key })));
|
|
48
48
|
return (0, serializers_1.deserializeAuthenticationResponse)(data);
|
|
49
49
|
});
|
|
50
50
|
}
|
|
@@ -108,5 +108,17 @@ class Users {
|
|
|
108
108
|
return (0, serializers_1.deserializeUser)(data);
|
|
109
109
|
});
|
|
110
110
|
}
|
|
111
|
+
updateUser(payload) {
|
|
112
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
113
|
+
const { data } = yield this.workos.put(`/users/${payload.userId}`, (0, serializers_1.serializeUpdateUserOptions)(payload));
|
|
114
|
+
return (0, serializers_1.deserializeUser)(data);
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
updateUserPassword(payload) {
|
|
118
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
119
|
+
const { data } = yield this.workos.put(`/users/${payload.userId}/password`, (0, serializers_1.serializeUpdateUserPasswordOptions)(payload));
|
|
120
|
+
return (0, serializers_1.deserializeUser)(data);
|
|
121
|
+
});
|
|
122
|
+
}
|
|
111
123
|
}
|
|
112
124
|
exports.Users = Users;
|
package/lib/users/users.spec.js
CHANGED
|
@@ -103,15 +103,16 @@ describe('UserManagement', () => {
|
|
|
103
103
|
});
|
|
104
104
|
describe('authenticateUserWithPassword', () => {
|
|
105
105
|
it('sends an password authentication request', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
106
|
-
mock.onPost('/users/
|
|
106
|
+
mock.onPost('/users/sessions/token').reply(200, {
|
|
107
107
|
user: user_json_1.default,
|
|
108
108
|
session: session_json_1.default,
|
|
109
109
|
});
|
|
110
110
|
const resp = yield workos.users.authenticateUserWithPassword({
|
|
111
|
+
clientId: 'proj_whatever',
|
|
111
112
|
email: 'test01@example.com',
|
|
112
113
|
password: 'extra-secure',
|
|
113
114
|
});
|
|
114
|
-
expect(mock.history.post[0].url).toEqual('/users/
|
|
115
|
+
expect(mock.history.post[0].url).toEqual('/users/sessions/token');
|
|
115
116
|
expect(resp).toMatchObject({
|
|
116
117
|
user: {
|
|
117
118
|
email: 'test01@example.com',
|
|
@@ -287,4 +288,31 @@ describe('UserManagement', () => {
|
|
|
287
288
|
});
|
|
288
289
|
}));
|
|
289
290
|
});
|
|
291
|
+
describe('updateUser', () => {
|
|
292
|
+
it('sends a updateUser request', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
293
|
+
mock.onPut(`/users/${userId}`).reply(200, user_json_1.default);
|
|
294
|
+
const resp = yield workos.users.updateUser({
|
|
295
|
+
userId,
|
|
296
|
+
firstName: 'Dane',
|
|
297
|
+
lastName: 'Williams',
|
|
298
|
+
});
|
|
299
|
+
expect(mock.history.put[0].url).toEqual(`/users/${userId}`);
|
|
300
|
+
expect(resp).toMatchObject({
|
|
301
|
+
email: 'test01@example.com',
|
|
302
|
+
});
|
|
303
|
+
}));
|
|
304
|
+
});
|
|
305
|
+
describe('updateUserPassword', () => {
|
|
306
|
+
it('sends a updateUserPassword request', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
307
|
+
mock.onPut(`/users/${userId}/password`).reply(200, user_json_1.default);
|
|
308
|
+
const resp = yield workos.users.updateUserPassword({
|
|
309
|
+
userId,
|
|
310
|
+
password: 'secure',
|
|
311
|
+
});
|
|
312
|
+
expect(mock.history.put[0].url).toEqual(`/users/${userId}/password`);
|
|
313
|
+
expect(resp).toMatchObject({
|
|
314
|
+
email: 'test01@example.com',
|
|
315
|
+
});
|
|
316
|
+
}));
|
|
317
|
+
});
|
|
290
318
|
});
|
package/lib/workos.js
CHANGED
|
@@ -27,7 +27,7 @@ const mfa_1 = require("./mfa/mfa");
|
|
|
27
27
|
const audit_logs_1 = require("./audit-logs/audit-logs");
|
|
28
28
|
const users_1 = require("./users/users");
|
|
29
29
|
const bad_request_exception_1 = require("./common/exceptions/bad-request.exception");
|
|
30
|
-
const VERSION = '3.0.0-alpha.
|
|
30
|
+
const VERSION = '3.0.0-alpha.2';
|
|
31
31
|
const DEFAULT_HOSTNAME = 'api.workos.com';
|
|
32
32
|
class WorkOS {
|
|
33
33
|
constructor(key, options = {}) {
|
package/package.json
CHANGED