@workos-inc/node 7.30.1 → 7.31.0-beta.actions1
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/actions/actions.d.ts +19 -0
- package/lib/actions/actions.js +53 -0
- package/lib/actions/actions.spec.d.ts +1 -0
- package/lib/actions/actions.spec.js +78 -0
- package/lib/actions/fixtures/action-context.json +39 -0
- package/lib/actions/interfaces/response-payload.d.ts +23 -0
- package/lib/common/crypto/CryptoProvider.d.ts +32 -0
- package/lib/common/crypto/CryptoProvider.js +13 -0
- package/lib/common/crypto/CryptoProvider.spec.d.ts +1 -0
- package/lib/common/crypto/CryptoProvider.spec.js +57 -0
- package/lib/common/crypto/NodeCryptoProvider.d.ts +12 -0
- package/lib/common/crypto/NodeCryptoProvider.js +73 -0
- package/lib/common/crypto/SignatureProvider.d.ts +13 -0
- package/lib/common/crypto/SignatureProvider.js +53 -0
- package/lib/common/crypto/SignatureProvider.spec.d.ts +1 -0
- package/lib/common/crypto/SignatureProvider.spec.js +66 -0
- package/lib/common/crypto/SubtleCryptoProvider.d.ts +15 -0
- package/lib/common/crypto/SubtleCryptoProvider.js +75 -0
- package/lib/common/crypto/index.d.ts +4 -0
- package/lib/common/crypto/index.js +20 -0
- package/lib/common/net/fetch-client.spec.d.ts +1 -0
- package/lib/common/net/fetch-client.spec.js +140 -0
- package/lib/common/net/index.d.ts +5 -0
- package/lib/common/net/index.js +31 -0
- package/lib/common/net/node-client.spec.d.ts +1 -0
- package/lib/common/net/node-client.spec.js +140 -0
- package/lib/common/utils/unreachable.d.ts +10 -0
- package/lib/common/utils/unreachable.js +18 -0
- package/lib/fga/fga.spec.js +0 -609
- package/lib/index.d.ts +3 -0
- package/lib/index.js +12 -0
- package/lib/index.worker.d.ts +3 -0
- package/lib/index.worker.js +6 -0
- package/lib/organizations/organizations.d.ts +0 -3
- package/lib/organizations/organizations.js +0 -12
- package/lib/organizations/organizations.spec.js +13 -51
- package/lib/webhooks/webhooks.d.ts +9 -9
- package/lib/webhooks/webhooks.js +11 -36
- package/lib/webhooks/webhooks.spec.js +23 -46
- package/lib/workos.d.ts +3 -0
- package/lib/workos.js +5 -0
- package/lib/workos.spec.js +5 -1
- package/package.json +2 -1
- package/lib/organizations/fixtures/get-stripe-customer-id.json +0 -17
- package/lib/organizations/interfaces/set-stripe-customer-id-options.interface.d.ts +0 -4
- /package/lib/{organizations/interfaces/set-stripe-customer-id-options.interface.js → actions/interfaces/response-payload.js} +0 -0
package/lib/index.js
CHANGED
|
@@ -19,6 +19,7 @@ const node_crypto_provider_1 = require("./common/crypto/node-crypto-provider");
|
|
|
19
19
|
const subtle_crypto_provider_1 = require("./common/crypto/subtle-crypto-provider");
|
|
20
20
|
const fetch_client_1 = require("./common/net/fetch-client");
|
|
21
21
|
const node_client_1 = require("./common/net/node-client");
|
|
22
|
+
const actions_1 = require("./actions/actions");
|
|
22
23
|
const webhooks_1 = require("./webhooks/webhooks");
|
|
23
24
|
const workos_1 = require("./workos");
|
|
24
25
|
const web_iron_session_provider_1 = require("./common/iron-session/web-iron-session-provider");
|
|
@@ -61,6 +62,17 @@ class WorkOSNode extends workos_1.WorkOS {
|
|
|
61
62
|
return new webhooks_1.Webhooks(cryptoProvider);
|
|
62
63
|
}
|
|
63
64
|
/** @override */
|
|
65
|
+
createActionsClient() {
|
|
66
|
+
let cryptoProvider;
|
|
67
|
+
if (typeof crypto !== 'undefined' && typeof crypto.subtle !== 'undefined') {
|
|
68
|
+
cryptoProvider = new subtle_crypto_provider_1.SubtleCryptoProvider();
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
cryptoProvider = new node_crypto_provider_1.NodeCryptoProvider();
|
|
72
|
+
}
|
|
73
|
+
return new actions_1.Actions(cryptoProvider);
|
|
74
|
+
}
|
|
75
|
+
/** @override */
|
|
64
76
|
createIronSessionProvider() {
|
|
65
77
|
return new web_iron_session_provider_1.WebIronSessionProvider();
|
|
66
78
|
}
|
package/lib/index.worker.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Actions } from './actions/actions';
|
|
1
2
|
import { IronSessionProvider } from './common/iron-session/iron-session-provider';
|
|
2
3
|
import { HttpClient } from './common/net/http-client';
|
|
3
4
|
import { WorkOSOptions } from './index.worker';
|
|
@@ -21,6 +22,8 @@ declare class WorkOSWorker extends WorkOS {
|
|
|
21
22
|
/** @override */
|
|
22
23
|
createWebhookClient(): Webhooks;
|
|
23
24
|
/** @override */
|
|
25
|
+
createActionsClient(): Actions;
|
|
26
|
+
/** @override */
|
|
24
27
|
createIronSessionProvider(): IronSessionProvider;
|
|
25
28
|
/** @override */
|
|
26
29
|
emitWarning(warning: string): void;
|
package/lib/index.worker.js
CHANGED
|
@@ -15,6 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
exports.WorkOS = void 0;
|
|
18
|
+
const actions_1 = require("./actions/actions");
|
|
18
19
|
const subtle_crypto_provider_1 = require("./common/crypto/subtle-crypto-provider");
|
|
19
20
|
const edge_iron_session_provider_1 = require("./common/iron-session/edge-iron-session-provider");
|
|
20
21
|
const fetch_client_1 = require("./common/net/fetch-client");
|
|
@@ -44,6 +45,11 @@ class WorkOSWorker extends workos_1.WorkOS {
|
|
|
44
45
|
return new webhooks_1.Webhooks(cryptoProvider);
|
|
45
46
|
}
|
|
46
47
|
/** @override */
|
|
48
|
+
createActionsClient() {
|
|
49
|
+
const cryptoProvider = new subtle_crypto_provider_1.SubtleCryptoProvider();
|
|
50
|
+
return new actions_1.Actions(cryptoProvider);
|
|
51
|
+
}
|
|
52
|
+
/** @override */
|
|
47
53
|
createIronSessionProvider() {
|
|
48
54
|
return new edge_iron_session_provider_1.EdgeIronSessionProvider();
|
|
49
55
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { AutoPaginatable } from '../common/utils/pagination';
|
|
2
2
|
import { WorkOS } from '../workos';
|
|
3
3
|
import { CreateOrganizationOptions, CreateOrganizationRequestOptions, ListOrganizationsOptions, Organization, UpdateOrganizationOptions } from './interfaces';
|
|
4
|
-
import { SetStripeCustomerIdOptions } from './interfaces/set-stripe-customer-id-options.interface';
|
|
5
4
|
export declare class Organizations {
|
|
6
5
|
private readonly workos;
|
|
7
6
|
constructor(workos: WorkOS);
|
|
@@ -10,6 +9,4 @@ export declare class Organizations {
|
|
|
10
9
|
deleteOrganization(id: string): Promise<void>;
|
|
11
10
|
getOrganization(id: string): Promise<Organization>;
|
|
12
11
|
updateOrganization(options: UpdateOrganizationOptions): Promise<Organization>;
|
|
13
|
-
setStripeCustomerId(options: SetStripeCustomerIdOptions): Promise<string | undefined>;
|
|
14
|
-
getStripeCustomerId(id: string): Promise<string | undefined>;
|
|
15
12
|
}
|
|
@@ -57,17 +57,5 @@ class Organizations {
|
|
|
57
57
|
return (0, serializers_1.deserializeOrganization)(data);
|
|
58
58
|
});
|
|
59
59
|
}
|
|
60
|
-
setStripeCustomerId(options) {
|
|
61
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
62
|
-
const updatedOrganization = yield this.updateOrganization(options);
|
|
63
|
-
return updatedOrganization.stripeCustomerId;
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
getStripeCustomerId(id) {
|
|
67
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
68
|
-
const organization = yield this.getOrganization(id);
|
|
69
|
-
return organization.stripeCustomerId;
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
60
|
}
|
|
73
61
|
exports.Organizations = Organizations;
|
|
@@ -19,7 +19,6 @@ const clear_stripe_customer_id_json_1 = __importDefault(require("./fixtures/clea
|
|
|
19
19
|
const create_organization_invalid_json_1 = __importDefault(require("./fixtures/create-organization-invalid.json"));
|
|
20
20
|
const create_organization_json_1 = __importDefault(require("./fixtures/create-organization.json"));
|
|
21
21
|
const get_organization_json_1 = __importDefault(require("./fixtures/get-organization.json"));
|
|
22
|
-
const get_stripe_customer_id_json_1 = __importDefault(require("./fixtures/get-stripe-customer-id.json"));
|
|
23
22
|
const list_organizations_json_1 = __importDefault(require("./fixtures/list-organizations.json"));
|
|
24
23
|
const update_organization_json_1 = __importDefault(require("./fixtures/update-organization.json"));
|
|
25
24
|
const set_stripe_customer_id_json_1 = __importDefault(require("./fixtures/set-stripe-customer-id.json"));
|
|
@@ -239,33 +238,7 @@ describe('Organizations', () => {
|
|
|
239
238
|
}));
|
|
240
239
|
});
|
|
241
240
|
});
|
|
242
|
-
|
|
243
|
-
describe('setStripeCustomerId', () => {
|
|
244
|
-
describe('with a valid payload', () => {
|
|
245
|
-
it('updates the organization’s Stripe customer ID', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
246
|
-
(0, test_utils_1.fetchOnce)(set_stripe_customer_id_json_1.default);
|
|
247
|
-
const subject = yield workos.organizations.setStripeCustomerId({
|
|
248
|
-
organization: 'org_01EHT88Z8J8795GZNQ4ZP1J81T',
|
|
249
|
-
stripeCustomerId: 'cus_MX8J9nfK4lP2Yw',
|
|
250
|
-
});
|
|
251
|
-
expect((0, test_utils_1.fetchBody)()).toEqual({
|
|
252
|
-
stripe_customer_id: 'cus_MX8J9nfK4lP2Yw',
|
|
253
|
-
});
|
|
254
|
-
expect(subject).toBe('cus_MX8J9nfK4lP2Yw');
|
|
255
|
-
}));
|
|
256
|
-
it('clears the organization’s Stripe customer ID with a `null` value', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
257
|
-
(0, test_utils_1.fetchOnce)(clear_stripe_customer_id_json_1.default);
|
|
258
|
-
const subject = yield workos.organizations.setStripeCustomerId({
|
|
259
|
-
organization: 'org_01EHT88Z8J8795GZNQ4ZP1J81T',
|
|
260
|
-
stripeCustomerId: null,
|
|
261
|
-
});
|
|
262
|
-
expect((0, test_utils_1.fetchBody)()).toEqual({
|
|
263
|
-
stripe_customer_id: null,
|
|
264
|
-
});
|
|
265
|
-
expect(subject).toBeUndefined();
|
|
266
|
-
}));
|
|
267
|
-
});
|
|
268
|
-
describe('when set via `updateOrganization`', () => {
|
|
241
|
+
describe('when given `stripeCustomerId`', () => {
|
|
269
242
|
it('updates the organization’s Stripe customer ID', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
270
243
|
(0, test_utils_1.fetchOnce)(set_stripe_customer_id_json_1.default);
|
|
271
244
|
const subject = yield workos.organizations.updateOrganization({
|
|
@@ -288,29 +261,18 @@ describe('Organizations', () => {
|
|
|
288
261
|
});
|
|
289
262
|
expect(subject.stripeCustomerId).toBeUndefined();
|
|
290
263
|
}));
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
});
|
|
302
|
-
}));
|
|
303
|
-
});
|
|
304
|
-
});
|
|
305
|
-
describe('getStripeCustomerId', () => {
|
|
306
|
-
it('returns the organization’s Stripe customer ID', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
307
|
-
(0, test_utils_1.fetchOnce)(get_stripe_customer_id_json_1.default);
|
|
308
|
-
const subject = yield workos.organizations.setStripeCustomerId({
|
|
309
|
-
organization: 'org_01EHT88Z8J8795GZNQ4ZP1J81T',
|
|
310
|
-
stripeCustomerId: null,
|
|
264
|
+
describe('when the feature is not enabled', () => {
|
|
265
|
+
it('returns an error', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
266
|
+
(0, test_utils_1.fetchOnce)(set_stripe_customer_id_disabled_json_1.default, { status: 422 });
|
|
267
|
+
yield expect(workos.organizations.updateOrganization({
|
|
268
|
+
organization: 'org_01EHT88Z8J8795GZNQ4ZP1J81T',
|
|
269
|
+
stripeCustomerId: 'cus_MX8J9nfK4lP2Yw',
|
|
270
|
+
})).rejects.toThrowError('stripe_customer_id is not enabled for this environment');
|
|
271
|
+
expect((0, test_utils_1.fetchBody)()).toEqual({
|
|
272
|
+
stripe_customer_id: 'cus_MX8J9nfK4lP2Yw',
|
|
273
|
+
});
|
|
274
|
+
}));
|
|
311
275
|
});
|
|
312
|
-
|
|
313
|
-
expect(subject).toEqual('cus_MX8J9nfK4lP2Yw');
|
|
314
|
-
}));
|
|
276
|
+
});
|
|
315
277
|
});
|
|
316
278
|
});
|
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
import { Event } from '../common/interfaces';
|
|
2
2
|
import { CryptoProvider } from '../common/crypto/crypto-provider';
|
|
3
3
|
export declare class Webhooks {
|
|
4
|
-
private
|
|
4
|
+
private signatureProvider;
|
|
5
5
|
constructor(cryptoProvider: CryptoProvider);
|
|
6
|
+
get verifyHeader(): ({ payload, sigHeader, secret, tolerance, }: {
|
|
7
|
+
payload: any;
|
|
8
|
+
sigHeader: string;
|
|
9
|
+
secret: string;
|
|
10
|
+
tolerance?: number | undefined;
|
|
11
|
+
}) => Promise<boolean>;
|
|
12
|
+
get computeSignature(): (timestamp: any, payload: any, secret: string) => Promise<string>;
|
|
13
|
+
get getTimestampAndSignatureHash(): (sigHeader: string) => [string, string];
|
|
6
14
|
constructEvent({ payload, sigHeader, secret, tolerance, }: {
|
|
7
15
|
payload: unknown;
|
|
8
16
|
sigHeader: string;
|
|
9
17
|
secret: string;
|
|
10
18
|
tolerance?: number;
|
|
11
19
|
}): Promise<Event>;
|
|
12
|
-
verifyHeader({ payload, sigHeader, secret, tolerance, }: {
|
|
13
|
-
payload: any;
|
|
14
|
-
sigHeader: string;
|
|
15
|
-
secret: string;
|
|
16
|
-
tolerance?: number;
|
|
17
|
-
}): Promise<boolean>;
|
|
18
|
-
getTimestampAndSignatureHash(sigHeader: string): [string, string];
|
|
19
|
-
computeSignature(timestamp: any, payload: any, secret: string): Promise<string>;
|
|
20
20
|
}
|
package/lib/webhooks/webhooks.js
CHANGED
|
@@ -10,11 +10,20 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.Webhooks = void 0;
|
|
13
|
-
const exceptions_1 = require("../common/exceptions");
|
|
14
13
|
const serializers_1 = require("../common/serializers");
|
|
14
|
+
const SignatureProvider_1 = require("../common/crypto/SignatureProvider");
|
|
15
15
|
class Webhooks {
|
|
16
16
|
constructor(cryptoProvider) {
|
|
17
|
-
this.
|
|
17
|
+
this.signatureProvider = new SignatureProvider_1.SignatureProvider(cryptoProvider);
|
|
18
|
+
}
|
|
19
|
+
get verifyHeader() {
|
|
20
|
+
return this.signatureProvider.verifyHeader.bind(this.signatureProvider);
|
|
21
|
+
}
|
|
22
|
+
get computeSignature() {
|
|
23
|
+
return this.signatureProvider.computeSignature.bind(this.signatureProvider);
|
|
24
|
+
}
|
|
25
|
+
get getTimestampAndSignatureHash() {
|
|
26
|
+
return this.signatureProvider.getTimestampAndSignatureHash.bind(this.signatureProvider);
|
|
18
27
|
}
|
|
19
28
|
constructEvent({ payload, sigHeader, secret, tolerance = 180000, }) {
|
|
20
29
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -24,39 +33,5 @@ class Webhooks {
|
|
|
24
33
|
return (0, serializers_1.deserializeEvent)(webhookPayload);
|
|
25
34
|
});
|
|
26
35
|
}
|
|
27
|
-
verifyHeader({ payload, sigHeader, secret, tolerance = 180000, }) {
|
|
28
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
29
|
-
const [timestamp, signatureHash] = this.getTimestampAndSignatureHash(sigHeader);
|
|
30
|
-
if (!signatureHash || Object.keys(signatureHash).length === 0) {
|
|
31
|
-
throw new exceptions_1.SignatureVerificationException('No signature hash found with expected scheme v1');
|
|
32
|
-
}
|
|
33
|
-
if (parseInt(timestamp, 10) < Date.now() - tolerance) {
|
|
34
|
-
throw new exceptions_1.SignatureVerificationException('Timestamp outside the tolerance zone');
|
|
35
|
-
}
|
|
36
|
-
const expectedSig = yield this.computeSignature(timestamp, payload, secret);
|
|
37
|
-
if ((yield this.cryptoProvider.secureCompare(expectedSig, signatureHash)) ===
|
|
38
|
-
false) {
|
|
39
|
-
throw new exceptions_1.SignatureVerificationException('Signature hash does not match the expected signature hash for payload');
|
|
40
|
-
}
|
|
41
|
-
return true;
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
getTimestampAndSignatureHash(sigHeader) {
|
|
45
|
-
const signature = sigHeader;
|
|
46
|
-
const [t, v1] = signature.split(',');
|
|
47
|
-
if (typeof t === 'undefined' || typeof v1 === 'undefined') {
|
|
48
|
-
throw new exceptions_1.SignatureVerificationException('Signature or timestamp missing');
|
|
49
|
-
}
|
|
50
|
-
const { 1: timestamp } = t.split('=');
|
|
51
|
-
const { 1: signatureHash } = v1.split('=');
|
|
52
|
-
return [timestamp, signatureHash];
|
|
53
|
-
}
|
|
54
|
-
computeSignature(timestamp, payload, secret) {
|
|
55
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
56
|
-
payload = JSON.stringify(payload);
|
|
57
|
-
const signedPayload = `${timestamp}.${payload}`;
|
|
58
|
-
return yield this.cryptoProvider.computeHMACSignatureAsync(signedPayload, secret);
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
36
|
}
|
|
62
37
|
exports.Webhooks = Webhooks;
|
|
@@ -17,8 +17,6 @@ const workos_1 = require("../workos");
|
|
|
17
17
|
const webhook_json_1 = __importDefault(require("./fixtures/webhook.json"));
|
|
18
18
|
const workos = new workos_1.WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU');
|
|
19
19
|
const exceptions_1 = require("../common/exceptions");
|
|
20
|
-
const node_crypto_provider_1 = require("../common/crypto/node-crypto-provider");
|
|
21
|
-
const subtle_crypto_provider_1 = require("../common/crypto/subtle-crypto-provider");
|
|
22
20
|
describe('Webhooks', () => {
|
|
23
21
|
let payload;
|
|
24
22
|
let secret;
|
|
@@ -166,55 +164,34 @@ describe('Webhooks', () => {
|
|
|
166
164
|
});
|
|
167
165
|
});
|
|
168
166
|
describe('verifyHeader', () => {
|
|
169
|
-
it('
|
|
170
|
-
const
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
167
|
+
it('aliases to the signature provider', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
168
|
+
const spy = jest.spyOn(
|
|
169
|
+
// tslint:disable-next-line
|
|
170
|
+
workos.webhooks['signatureProvider'], 'verifyHeader');
|
|
171
|
+
yield workos.webhooks.verifyHeader({
|
|
172
|
+
payload,
|
|
173
|
+
sigHeader: `t=${timestamp}, v1=${signatureHash}`,
|
|
174
|
+
secret,
|
|
175
|
+
});
|
|
176
|
+
expect(spy).toHaveBeenCalled();
|
|
174
177
|
}));
|
|
175
178
|
});
|
|
176
|
-
describe('getTimestampAndSignatureHash', () => {
|
|
177
|
-
it('returns the timestamp and signature when the signature is valid', () => {
|
|
178
|
-
const sigHeader = `t=${timestamp}, v1=${signatureHash}`;
|
|
179
|
-
const timestampAndSignature = workos.webhooks.getTimestampAndSignatureHash(sigHeader);
|
|
180
|
-
expect(timestampAndSignature).toEqual([
|
|
181
|
-
timestamp.toString(),
|
|
182
|
-
signatureHash,
|
|
183
|
-
]);
|
|
184
|
-
});
|
|
185
|
-
});
|
|
186
179
|
describe('computeSignature', () => {
|
|
187
|
-
it('
|
|
188
|
-
const
|
|
189
|
-
|
|
180
|
+
it('aliases to the signature provider', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
181
|
+
const spy = jest.spyOn(
|
|
182
|
+
// tslint:disable-next-line
|
|
183
|
+
workos.webhooks['signatureProvider'], 'computeSignature');
|
|
184
|
+
yield workos.webhooks.computeSignature(timestamp, payload, secret);
|
|
185
|
+
expect(spy).toHaveBeenCalled();
|
|
190
186
|
}));
|
|
191
187
|
});
|
|
192
|
-
describe('
|
|
193
|
-
it('
|
|
188
|
+
describe('getTimestampAndSignatureHash', () => {
|
|
189
|
+
it('aliases to the signature provider', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
190
|
+
const spy = jest.spyOn(
|
|
194
191
|
// tslint:disable-next-line
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
describe('when computing HMAC signature', () => {
|
|
200
|
-
it('returns the same for the Node crypto and Web Crypto versions', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
201
|
-
const nodeCryptoProvider = new node_crypto_provider_1.NodeCryptoProvider();
|
|
202
|
-
const subtleCryptoProvider = new subtle_crypto_provider_1.SubtleCryptoProvider();
|
|
203
|
-
const stringifiedPayload = JSON.stringify(payload);
|
|
204
|
-
const payloadHMAC = `${timestamp}.${stringifiedPayload}`;
|
|
205
|
-
const nodeCompare = yield nodeCryptoProvider.computeHMACSignatureAsync(payloadHMAC, secret);
|
|
206
|
-
const subtleCompare = yield subtleCryptoProvider.computeHMACSignatureAsync(payloadHMAC, secret);
|
|
207
|
-
expect(nodeCompare).toEqual(subtleCompare);
|
|
208
|
-
}));
|
|
209
|
-
});
|
|
210
|
-
describe('when securely comparing', () => {
|
|
211
|
-
it('returns the same for the Node crypto and Web Crypto versions', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
212
|
-
const nodeCryptoProvider = new node_crypto_provider_1.NodeCryptoProvider();
|
|
213
|
-
const subtleCryptoProvider = new subtle_crypto_provider_1.SubtleCryptoProvider();
|
|
214
|
-
const signature = yield workos.webhooks.computeSignature(timestamp, payload, secret);
|
|
215
|
-
expect(nodeCryptoProvider.secureCompare(signature, signatureHash)).toEqual(subtleCryptoProvider.secureCompare(signature, signatureHash));
|
|
216
|
-
expect(nodeCryptoProvider.secureCompare(signature, 'foo')).toEqual(subtleCryptoProvider.secureCompare(signature, 'foo'));
|
|
217
|
-
}));
|
|
218
|
-
});
|
|
192
|
+
workos.webhooks['signatureProvider'], 'getTimestampAndSignatureHash');
|
|
193
|
+
workos.webhooks.getTimestampAndSignatureHash(`t=${timestamp}, v1=${signatureHash}`);
|
|
194
|
+
expect(spy).toHaveBeenCalled();
|
|
195
|
+
}));
|
|
219
196
|
});
|
|
220
197
|
});
|
package/lib/workos.d.ts
CHANGED
|
@@ -14,12 +14,14 @@ import { FGA } from './fga/fga';
|
|
|
14
14
|
import { HttpClient } from './common/net/http-client';
|
|
15
15
|
import { IronSessionProvider } from './common/iron-session/iron-session-provider';
|
|
16
16
|
import { Widgets } from './widgets/widgets';
|
|
17
|
+
import { Actions } from './actions/actions';
|
|
17
18
|
export declare class WorkOS {
|
|
18
19
|
readonly key?: string | undefined;
|
|
19
20
|
readonly options: WorkOSOptions;
|
|
20
21
|
readonly baseURL: string;
|
|
21
22
|
readonly client: HttpClient;
|
|
22
23
|
readonly clientId?: string;
|
|
24
|
+
readonly actions: Actions;
|
|
23
25
|
readonly auditLogs: AuditLogs;
|
|
24
26
|
readonly directorySync: DirectorySync;
|
|
25
27
|
readonly organizations: Organizations;
|
|
@@ -35,6 +37,7 @@ export declare class WorkOS {
|
|
|
35
37
|
readonly widgets: Widgets;
|
|
36
38
|
constructor(key?: string | undefined, options?: WorkOSOptions);
|
|
37
39
|
createWebhookClient(): Webhooks;
|
|
40
|
+
createActionsClient(): Actions;
|
|
38
41
|
createHttpClient(options: WorkOSOptions, userAgent: string): HttpClient;
|
|
39
42
|
createIronSessionProvider(): IronSessionProvider;
|
|
40
43
|
get version(): string;
|
package/lib/workos.js
CHANGED
|
@@ -28,6 +28,7 @@ const http_client_1 = require("./common/net/http-client");
|
|
|
28
28
|
const subtle_crypto_provider_1 = require("./common/crypto/subtle-crypto-provider");
|
|
29
29
|
const fetch_client_1 = require("./common/net/fetch-client");
|
|
30
30
|
const widgets_1 = require("./widgets/widgets");
|
|
31
|
+
const actions_1 = require("./actions/actions");
|
|
31
32
|
const VERSION = '7.30.1';
|
|
32
33
|
const DEFAULT_HOSTNAME = 'api.workos.com';
|
|
33
34
|
const HEADER_AUTHORIZATION = 'Authorization';
|
|
@@ -78,6 +79,7 @@ class WorkOS {
|
|
|
78
79
|
userAgent += ` ${name}: ${version}`;
|
|
79
80
|
}
|
|
80
81
|
this.webhooks = this.createWebhookClient();
|
|
82
|
+
this.actions = this.createActionsClient();
|
|
81
83
|
// Must initialize UserManagement after baseURL is configured
|
|
82
84
|
this.userManagement = new user_management_1.UserManagement(this, this.createIronSessionProvider());
|
|
83
85
|
this.client = this.createHttpClient(options, userAgent);
|
|
@@ -85,6 +87,9 @@ class WorkOS {
|
|
|
85
87
|
createWebhookClient() {
|
|
86
88
|
return new webhooks_1.Webhooks(new subtle_crypto_provider_1.SubtleCryptoProvider());
|
|
87
89
|
}
|
|
90
|
+
createActionsClient() {
|
|
91
|
+
return new actions_1.Actions(new subtle_crypto_provider_1.SubtleCryptoProvider());
|
|
92
|
+
}
|
|
88
93
|
createHttpClient(options, userAgent) {
|
|
89
94
|
var _a;
|
|
90
95
|
return new fetch_client_1.FetchHttpClient(this.baseURL, Object.assign(Object.assign({}, options.config), { headers: Object.assign(Object.assign({}, (_a = options.config) === null || _a === void 0 ? void 0 : _a.headers), { Authorization: `Bearer ${this.key}`, 'User-Agent': userAgent }) }));
|
package/lib/workos.spec.js
CHANGED
|
@@ -246,8 +246,12 @@ describe('WorkOS', () => {
|
|
|
246
246
|
const workos = new index_worker_1.WorkOS('sk_test_key');
|
|
247
247
|
// tslint:disable-next-line
|
|
248
248
|
expect(workos['client']).toBeInstanceOf(fetch_client_1.FetchHttpClient);
|
|
249
|
+
expect(
|
|
249
250
|
// tslint:disable-next-line
|
|
250
|
-
|
|
251
|
+
workos.webhooks['signatureProvider']['cryptoProvider']).toBeInstanceOf(subtle_crypto_provider_1.SubtleCryptoProvider);
|
|
252
|
+
expect(
|
|
253
|
+
// tslint:disable-next-line
|
|
254
|
+
workos.actions['signatureProvider']['cryptoProvider']).toBeInstanceOf(subtle_crypto_provider_1.SubtleCryptoProvider);
|
|
251
255
|
});
|
|
252
256
|
it('uses console.warn to emit warnings', () => {
|
|
253
257
|
const workos = new index_worker_1.WorkOS('sk_test_key');
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "7.
|
|
2
|
+
"version": "7.31.0-beta.actions1",
|
|
3
3
|
"name": "@workos-inc/node",
|
|
4
4
|
"author": "WorkOS",
|
|
5
5
|
"description": "A Node wrapper for the WorkOS API",
|
|
@@ -50,6 +50,7 @@
|
|
|
50
50
|
"jest": "29.6.2",
|
|
51
51
|
"jest-environment-miniflare": "^2.14.2",
|
|
52
52
|
"jest-fetch-mock": "^3.0.3",
|
|
53
|
+
"nock": "^13.5.5",
|
|
53
54
|
"prettier": "2.8.8",
|
|
54
55
|
"supertest": "6.3.3",
|
|
55
56
|
"ts-jest": "29.1.3",
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "Test Organization 3",
|
|
3
|
-
"object": "organization",
|
|
4
|
-
"id": "org_01EHT88Z8J8795GZNQ4ZP1J81T",
|
|
5
|
-
"allow_profiles_outside_organization": false,
|
|
6
|
-
"domains": [
|
|
7
|
-
{
|
|
8
|
-
"domain": "example.com",
|
|
9
|
-
"object": "organization_domain",
|
|
10
|
-
"id": "org_domain_01EHT88Z8WZEFWYPM6EC9BX2R8",
|
|
11
|
-
"state": "verified",
|
|
12
|
-
"verification_strategy": "dns",
|
|
13
|
-
"verification_token": "xB8SeACdKJQP9DP4CahU4YuQZ"
|
|
14
|
-
}
|
|
15
|
-
],
|
|
16
|
-
"stripe_customer_id": "cus_MX8J9nfK4lP2Yw"
|
|
17
|
-
}
|