@workos-inc/node 2.12.0 → 2.14.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/directory-sync/directory-sync.spec.js +3 -0
- package/lib/directory-sync/interfaces/user.interface.d.ts +1 -0
- package/lib/directory-sync/utils/get-primary-email.d.ts +2 -0
- package/lib/directory-sync/utils/get-primary-email.js +9 -0
- package/lib/directory-sync/utils/get-primary-email.spec.d.ts +1 -0
- package/lib/directory-sync/utils/get-primary-email.spec.js +31 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/portal/interfaces/generate-portal-link-intent.interface.d.ts +3 -2
- package/lib/portal/interfaces/generate-portal-link-intent.interface.js +2 -1
- package/lib/portal/portal.spec.js +17 -0
- package/lib/webhooks/fixtures/webhook.json +1 -1
- package/lib/webhooks/webhooks.d.ts +9 -4
- package/lib/webhooks/webhooks.spec.js +32 -8
- package/lib/workos.js +1 -1
- package/package.json +4 -4
|
@@ -61,6 +61,7 @@ describe('DirectorySync', () => {
|
|
|
61
61
|
groups: [groupResponse],
|
|
62
62
|
idp_id: 'idp_foo',
|
|
63
63
|
last_name: 'Snow',
|
|
64
|
+
job_title: 'Knight of the Watch',
|
|
64
65
|
raw_attributes: {},
|
|
65
66
|
state: 'active',
|
|
66
67
|
username: 'jonsnow',
|
|
@@ -176,6 +177,7 @@ describe('DirectorySync', () => {
|
|
|
176
177
|
emails: [],
|
|
177
178
|
first_name: 'Virginia',
|
|
178
179
|
last_name: 'Stoltenberg',
|
|
180
|
+
job_title: 'Software Engineer',
|
|
179
181
|
state: 'active',
|
|
180
182
|
raw_attributes: {},
|
|
181
183
|
custom_attributes: {
|
|
@@ -200,6 +202,7 @@ describe('DirectorySync', () => {
|
|
|
200
202
|
emails: [],
|
|
201
203
|
first_name: 'Eli',
|
|
202
204
|
last_name: 'Leffler',
|
|
205
|
+
job_title: 'Software Engineer',
|
|
203
206
|
state: 'active',
|
|
204
207
|
raw_attributes: {},
|
|
205
208
|
custom_attributes: {
|
|
@@ -15,6 +15,7 @@ export interface User<TCustomAttributes extends object = DefaultCustomAttributes
|
|
|
15
15
|
}[];
|
|
16
16
|
username: string;
|
|
17
17
|
last_name: string;
|
|
18
|
+
job_title: string | null;
|
|
18
19
|
state: 'active' | 'inactive' | 'suspended';
|
|
19
20
|
}
|
|
20
21
|
export interface UserWithGroups<TCustomAttributes extends object = DefaultCustomAttributes> extends User<TCustomAttributes> {
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getPrimaryEmail = void 0;
|
|
4
|
+
function getPrimaryEmail(user) {
|
|
5
|
+
var _a;
|
|
6
|
+
const primaryEmail = (_a = user.emails) === null || _a === void 0 ? void 0 : _a.find((email) => email.primary);
|
|
7
|
+
return primaryEmail === null || primaryEmail === void 0 ? void 0 : primaryEmail.value;
|
|
8
|
+
}
|
|
9
|
+
exports.getPrimaryEmail = getPrimaryEmail;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const get_primary_email_1 = require("./get-primary-email");
|
|
4
|
+
describe('getPrimaryEmail', () => {
|
|
5
|
+
const user = {
|
|
6
|
+
id: 'user_123',
|
|
7
|
+
custom_attributes: {
|
|
8
|
+
custom: true,
|
|
9
|
+
},
|
|
10
|
+
directory_id: 'dir_123',
|
|
11
|
+
organization_id: 'org_123',
|
|
12
|
+
emails: [
|
|
13
|
+
{
|
|
14
|
+
primary: true,
|
|
15
|
+
type: 'type',
|
|
16
|
+
value: 'jonsnow@workos.com',
|
|
17
|
+
},
|
|
18
|
+
],
|
|
19
|
+
first_name: 'Jon',
|
|
20
|
+
idp_id: 'idp_foo',
|
|
21
|
+
last_name: 'Snow',
|
|
22
|
+
raw_attributes: {},
|
|
23
|
+
state: 'active',
|
|
24
|
+
username: 'jonsnow',
|
|
25
|
+
job_title: 'Knight of the Watch',
|
|
26
|
+
};
|
|
27
|
+
it(`returns primary email value`, () => {
|
|
28
|
+
const primaryEmail = (0, get_primary_email_1.getPrimaryEmail)(user);
|
|
29
|
+
expect(primaryEmail).toEqual('jonsnow@workos.com');
|
|
30
|
+
});
|
|
31
|
+
});
|
package/lib/index.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export * from './audit-trail/interfaces';
|
|
|
4
4
|
export * from './common/exceptions';
|
|
5
5
|
export * from './common/interfaces';
|
|
6
6
|
export * from './directory-sync/interfaces';
|
|
7
|
+
export * from './directory-sync/utils/get-primary-email';
|
|
7
8
|
export * from './organizations/interfaces';
|
|
8
9
|
export * from './passwordless/interfaces';
|
|
9
10
|
export * from './portal/interfaces';
|
package/lib/index.js
CHANGED
|
@@ -22,6 +22,7 @@ __exportStar(require("./audit-trail/interfaces"), exports);
|
|
|
22
22
|
__exportStar(require("./common/exceptions"), exports);
|
|
23
23
|
__exportStar(require("./common/interfaces"), exports);
|
|
24
24
|
__exportStar(require("./directory-sync/interfaces"), exports);
|
|
25
|
+
__exportStar(require("./directory-sync/utils/get-primary-email"), exports);
|
|
25
26
|
__exportStar(require("./organizations/interfaces"), exports);
|
|
26
27
|
__exportStar(require("./passwordless/interfaces"), exports);
|
|
27
28
|
__exportStar(require("./portal/interfaces"), exports);
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.GeneratePortalLinkIntent = void 0;
|
|
4
4
|
var GeneratePortalLinkIntent;
|
|
5
5
|
(function (GeneratePortalLinkIntent) {
|
|
6
|
-
GeneratePortalLinkIntent["
|
|
6
|
+
GeneratePortalLinkIntent["AuditLogs"] = "audit_logs";
|
|
7
7
|
GeneratePortalLinkIntent["DSync"] = "dsync";
|
|
8
|
+
GeneratePortalLinkIntent["SSO"] = "sso";
|
|
8
9
|
})(GeneratePortalLinkIntent = exports.GeneratePortalLinkIntent || (exports.GeneratePortalLinkIntent = {}));
|
|
@@ -58,6 +58,23 @@ describe('Portal', () => {
|
|
|
58
58
|
expect(link).toEqual('https://id.workos.com/portal/launch?secret=secret');
|
|
59
59
|
}));
|
|
60
60
|
});
|
|
61
|
+
describe('with the `audit_logs` intent', () => {
|
|
62
|
+
it('returns an Admin Portal link', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
63
|
+
mock
|
|
64
|
+
.onPost('/portal/generate_link', {
|
|
65
|
+
intent: generate_portal_link_intent_interface_1.GeneratePortalLinkIntent.AuditLogs,
|
|
66
|
+
organization: 'org_01EHQMYV6MBK39QC5PZXHY59C3',
|
|
67
|
+
return_url: 'https://www.example.com',
|
|
68
|
+
})
|
|
69
|
+
.reply(201, generate_link_json_1.default);
|
|
70
|
+
const { link } = yield workos.portal.generateLink({
|
|
71
|
+
intent: generate_portal_link_intent_interface_1.GeneratePortalLinkIntent.AuditLogs,
|
|
72
|
+
organization: 'org_01EHQMYV6MBK39QC5PZXHY59C3',
|
|
73
|
+
returnUrl: 'https://www.example.com',
|
|
74
|
+
});
|
|
75
|
+
expect(link).toEqual('https://id.workos.com/portal/launch?secret=secret');
|
|
76
|
+
}));
|
|
77
|
+
});
|
|
61
78
|
});
|
|
62
79
|
describe('with an invalid organization', () => {
|
|
63
80
|
it('throws an error', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{ "id": "wh_123", "data": { "id": "directory_user_01FAEAJCR3ZBZ30D8BD1924TVG", "state": "active", "emails": [{ "type": "work", "value": "blair@foo-corp.com", "primary": true }], "idp_id": "00u1e8mutl6wlH3lL4x7", "object": "directory_user", "username": "blair@foo-corp.com", "last_name": "
|
|
1
|
+
{ "id": "wh_123", "data": { "id": "directory_user_01FAEAJCR3ZBZ30D8BD1924TVG", "state": "active", "emails": [{ "type": "work", "value": "blair@foo-corp.com", "primary": true }], "idp_id": "00u1e8mutl6wlH3lL4x7", "object": "directory_user", "username": "blair@foo-corp.com", "last_name": "Lunchford", "first_name": "Blair", "job_title": "Software Engineer", "directory_id": "directory_01F9M7F68PZP8QXP8G7X5QRHS7", "raw_attributes": { "name": { "givenName": "Blair", "familyName": "Lunchford", "middleName": "Elizabeth", "honorificPrefix": "Ms." }, "title": "Software Engineer", "active": true, "emails": [{ "type": "work", "value": "blair@foo-corp.com", "primary": true }], "groups": [], "locale": "en-US", "schemas": ["urn:ietf:params:scim:schemas:core:2.0:User", "urn:ietf:params:scim:schemas:extension:enterprise:2.0:User"], "userName": "blair@foo-corp.com", "addresses": [{ "region": "CA", "primary": true, "locality": "San Francisco", "postalCode": "94016" }], "externalId": "00u1e8mutl6wlH3lL4x7", "displayName": "Blair Lunchford", "urn:ietf:params:scim:schemas:extension:enterprise:2.0:User": { "manager": { "value": "2", "displayName": "Kate Chapman" }, "division": "Engineering", "department": "Customer Success" } } }, "event": "dsync.user.created" }
|
|
@@ -6,8 +6,13 @@ export declare class Webhooks {
|
|
|
6
6
|
secret: string;
|
|
7
7
|
tolerance?: number;
|
|
8
8
|
}): Webhook;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
verifyHeader({ payload, sigHeader, secret, tolerance, }: {
|
|
10
|
+
payload: any;
|
|
11
|
+
sigHeader: string;
|
|
12
|
+
secret: string;
|
|
13
|
+
tolerance?: number;
|
|
14
|
+
}): boolean;
|
|
15
|
+
getTimestampAndSignatureHash(sigHeader: string): string[];
|
|
16
|
+
computeSignature(timestamp: any, payload: any, secret: string): string;
|
|
17
|
+
secureCompare(stringA: string, stringB: string): boolean;
|
|
13
18
|
}
|
|
@@ -38,17 +38,18 @@ describe('Webhooks', () => {
|
|
|
38
38
|
idp_id: '00u1e8mutl6wlH3lL4x7',
|
|
39
39
|
object: 'directory_user',
|
|
40
40
|
username: 'blair@foo-corp.com',
|
|
41
|
-
last_name: '
|
|
41
|
+
last_name: 'Lunchford',
|
|
42
42
|
first_name: 'Blair',
|
|
43
|
+
job_title: 'Software Engineer',
|
|
43
44
|
directory_id: 'directory_01F9M7F68PZP8QXP8G7X5QRHS7',
|
|
44
45
|
raw_attributes: {
|
|
45
46
|
name: {
|
|
46
47
|
givenName: 'Blair',
|
|
47
|
-
familyName: '
|
|
48
|
+
familyName: 'Lunchford',
|
|
48
49
|
middleName: 'Elizabeth',
|
|
49
50
|
honorificPrefix: 'Ms.',
|
|
50
51
|
},
|
|
51
|
-
title: '
|
|
52
|
+
title: 'Software Engineer',
|
|
52
53
|
active: true,
|
|
53
54
|
emails: [
|
|
54
55
|
{
|
|
@@ -66,18 +67,18 @@ describe('Webhooks', () => {
|
|
|
66
67
|
userName: 'blair@foo-corp.com',
|
|
67
68
|
addresses: [
|
|
68
69
|
{
|
|
69
|
-
region: '
|
|
70
|
+
region: 'CA',
|
|
70
71
|
primary: true,
|
|
71
|
-
locality: '
|
|
72
|
-
postalCode: '
|
|
72
|
+
locality: 'San Francisco',
|
|
73
|
+
postalCode: '94016',
|
|
73
74
|
},
|
|
74
75
|
],
|
|
75
76
|
externalId: '00u1e8mutl6wlH3lL4x7',
|
|
76
|
-
displayName: 'Blair
|
|
77
|
+
displayName: 'Blair Lunchford',
|
|
77
78
|
'urn:ietf:params:scim:schemas:extension:enterprise:2.0:User': {
|
|
78
79
|
manager: {
|
|
79
80
|
value: '2',
|
|
80
|
-
displayName: '
|
|
81
|
+
displayName: 'Kate Chapman',
|
|
81
82
|
},
|
|
82
83
|
division: 'Engineering',
|
|
83
84
|
department: 'Customer Success',
|
|
@@ -151,4 +152,27 @@ describe('Webhooks', () => {
|
|
|
151
152
|
});
|
|
152
153
|
});
|
|
153
154
|
});
|
|
155
|
+
describe('verifyHeader', () => {
|
|
156
|
+
it('returns true when the signature is valid', () => {
|
|
157
|
+
const sigHeader = `t=${timestamp}, v1=${signatureHash}`;
|
|
158
|
+
const options = { payload, sigHeader, secret };
|
|
159
|
+
expect(() => workos.webhooks.verifyHeader(options)).toBeTruthy();
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
describe('getTimestampAndSignatureHash', () => {
|
|
163
|
+
it('returns the timestamp and signature when the signature is valid', () => {
|
|
164
|
+
const sigHeader = `t=${timestamp}, v1=${signatureHash}`;
|
|
165
|
+
const timestampAndSignature = workos.webhooks.getTimestampAndSignatureHash(sigHeader);
|
|
166
|
+
expect(timestampAndSignature).toEqual([
|
|
167
|
+
timestamp.toString(),
|
|
168
|
+
signatureHash,
|
|
169
|
+
]);
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
describe('computeSignature', () => {
|
|
173
|
+
it('returns the computed signature', () => {
|
|
174
|
+
const signature = workos.webhooks.computeSignature(timestamp, payload, secret);
|
|
175
|
+
expect(signature).toEqual(signatureHash);
|
|
176
|
+
});
|
|
177
|
+
});
|
|
154
178
|
});
|
package/lib/workos.js
CHANGED
|
@@ -25,7 +25,7 @@ const webhooks_1 = require("./webhooks/webhooks");
|
|
|
25
25
|
const mfa_1 = require("./mfa/mfa");
|
|
26
26
|
const audit_logs_1 = require("./audit-logs/audit-logs");
|
|
27
27
|
const bad_request_exception_1 = require("./common/exceptions/bad-request.exception");
|
|
28
|
-
const VERSION = '2.
|
|
28
|
+
const VERSION = '2.14.0';
|
|
29
29
|
const DEFAULT_HOSTNAME = 'api.workos.com';
|
|
30
30
|
class WorkOS {
|
|
31
31
|
constructor(key, options = {}) {
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "2.
|
|
2
|
+
"version": "2.14.0",
|
|
3
3
|
"name": "@workos-inc/node",
|
|
4
4
|
"author": "WorkOS",
|
|
5
5
|
"description": "A Node wrapper for the WorkOS API",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"workos"
|
|
10
10
|
],
|
|
11
11
|
"volta": {
|
|
12
|
-
"node": "14.20.
|
|
12
|
+
"node": "14.20.1",
|
|
13
13
|
"yarn": "1.22.19"
|
|
14
14
|
},
|
|
15
15
|
"main": "lib/index.js",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@types/jest": "27.5.2",
|
|
43
|
-
"@types/node": "14.18.
|
|
43
|
+
"@types/node": "14.18.32",
|
|
44
44
|
"@types/pluralize": "0.0.29",
|
|
45
45
|
"axios-mock-adapter": "1.21.2",
|
|
46
46
|
"jest": "27.5.1",
|
|
@@ -48,6 +48,6 @@
|
|
|
48
48
|
"supertest": "6.2.3",
|
|
49
49
|
"ts-jest": "27.1.5",
|
|
50
50
|
"tslint": "6.1.3",
|
|
51
|
-
"typescript": "4.
|
|
51
|
+
"typescript": "4.8.4"
|
|
52
52
|
}
|
|
53
53
|
}
|