@workos-inc/node 7.30.0 → 7.30.1
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/net/node-client.js +1 -0
- package/lib/organizations/fixtures/clear-stripe-customer-id.json +13 -0
- package/lib/organizations/fixtures/get-stripe-customer-id.json +17 -0
- package/lib/organizations/fixtures/set-stripe-customer-id-disabled.json +4 -0
- package/lib/organizations/fixtures/set-stripe-customer-id.json +14 -0
- package/lib/organizations/interfaces/organization.interface.d.ts +2 -0
- package/lib/organizations/interfaces/set-stripe-customer-id-options.interface.d.ts +4 -0
- package/lib/organizations/interfaces/set-stripe-customer-id-options.interface.js +2 -0
- package/lib/organizations/interfaces/update-organization-options.interface.d.ts +2 -0
- package/lib/organizations/organizations.d.ts +3 -0
- package/lib/organizations/organizations.js +12 -0
- package/lib/organizations/organizations.spec.js +77 -0
- package/lib/organizations/serializers/organization.serializer.js +3 -9
- package/lib/organizations/serializers/update-organization-options.serializer.js +1 -0
- package/lib/user-management/interfaces/authenticate-with-session-cookie.interface.d.ts +2 -0
- package/lib/user-management/session.js +2 -1
- package/lib/user-management/session.spec.js +2 -1
- package/lib/user-management/user-management.js +2 -1
- package/lib/user-management/user-management.spec.js +2 -1
- package/lib/widgets/fixtures/get-token-error.json +5 -0
- package/lib/widgets/fixtures/token.json +3 -0
- package/lib/widgets/interfaces/get-token.d.ts +19 -0
- package/lib/widgets/interfaces/get-token.js +13 -0
- package/lib/widgets/widgets.d.ts +7 -0
- package/lib/widgets/widgets.js +25 -0
- package/lib/widgets/widgets.spec.d.ts +1 -0
- package/lib/widgets/widgets.spec.js +49 -0
- package/lib/workos.d.ts +2 -0
- package/lib/workos.js +4 -2
- package/package.json +1 -1
|
@@ -187,6 +187,7 @@ class NodeHttpClient extends http_client_1.HttpClient {
|
|
|
187
187
|
yield this.sleep(retryAttempts);
|
|
188
188
|
return makeRequest().then(resolve).catch(reject);
|
|
189
189
|
}
|
|
190
|
+
reject(new Error(err.message));
|
|
190
191
|
}));
|
|
191
192
|
if (body) {
|
|
192
193
|
req.setHeader('Content-Length', Buffer.byteLength(body));
|
|
@@ -0,0 +1,13 @@
|
|
|
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
|
+
}
|
|
12
|
+
]
|
|
13
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
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
|
+
}
|
|
12
|
+
],
|
|
13
|
+
"stripe_customer_id": "cus_MX8J9nfK4lP2Yw"
|
|
14
|
+
}
|
|
@@ -5,6 +5,7 @@ export interface Organization {
|
|
|
5
5
|
name: string;
|
|
6
6
|
allowProfilesOutsideOrganization: boolean;
|
|
7
7
|
domains: OrganizationDomain[];
|
|
8
|
+
stripeCustomerId?: string;
|
|
8
9
|
createdAt: string;
|
|
9
10
|
updatedAt: string;
|
|
10
11
|
}
|
|
@@ -14,6 +15,7 @@ export interface OrganizationResponse {
|
|
|
14
15
|
name: string;
|
|
15
16
|
allow_profiles_outside_organization: boolean;
|
|
16
17
|
domains: OrganizationDomainResponse[];
|
|
18
|
+
stripe_customer_id?: string;
|
|
17
19
|
created_at: string;
|
|
18
20
|
updated_at: string;
|
|
19
21
|
}
|
|
@@ -3,6 +3,7 @@ export interface UpdateOrganizationOptions {
|
|
|
3
3
|
organization: string;
|
|
4
4
|
name?: string;
|
|
5
5
|
domainData?: DomainData[];
|
|
6
|
+
stripeCustomerId?: string | null;
|
|
6
7
|
/**
|
|
7
8
|
* @deprecated If you need to allow sign-ins from any email domain, contact support@workos.com.
|
|
8
9
|
*/
|
|
@@ -15,6 +16,7 @@ export interface UpdateOrganizationOptions {
|
|
|
15
16
|
export interface SerializedUpdateOrganizationOptions {
|
|
16
17
|
name?: string;
|
|
17
18
|
domain_data?: DomainData[];
|
|
19
|
+
stripe_customer_id?: string | null;
|
|
18
20
|
/**
|
|
19
21
|
* @deprecated If you need to allow sign-ins from any email domain, contact support@workos.com.
|
|
20
22
|
*/
|
|
@@ -1,6 +1,7 @@
|
|
|
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';
|
|
4
5
|
export declare class Organizations {
|
|
5
6
|
private readonly workos;
|
|
6
7
|
constructor(workos: WorkOS);
|
|
@@ -9,4 +10,6 @@ export declare class Organizations {
|
|
|
9
10
|
deleteOrganization(id: string): Promise<void>;
|
|
10
11
|
getOrganization(id: string): Promise<Organization>;
|
|
11
12
|
updateOrganization(options: UpdateOrganizationOptions): Promise<Organization>;
|
|
13
|
+
setStripeCustomerId(options: SetStripeCustomerIdOptions): Promise<string | undefined>;
|
|
14
|
+
getStripeCustomerId(id: string): Promise<string | undefined>;
|
|
12
15
|
}
|
|
@@ -57,5 +57,17 @@ 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
|
+
}
|
|
60
72
|
}
|
|
61
73
|
exports.Organizations = Organizations;
|
|
@@ -15,11 +15,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
15
15
|
const jest_fetch_mock_1 = __importDefault(require("jest-fetch-mock"));
|
|
16
16
|
const test_utils_1 = require("../common/utils/test-utils");
|
|
17
17
|
const workos_1 = require("../workos");
|
|
18
|
+
const clear_stripe_customer_id_json_1 = __importDefault(require("./fixtures/clear-stripe-customer-id.json"));
|
|
18
19
|
const create_organization_invalid_json_1 = __importDefault(require("./fixtures/create-organization-invalid.json"));
|
|
19
20
|
const create_organization_json_1 = __importDefault(require("./fixtures/create-organization.json"));
|
|
20
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"));
|
|
21
23
|
const list_organizations_json_1 = __importDefault(require("./fixtures/list-organizations.json"));
|
|
22
24
|
const update_organization_json_1 = __importDefault(require("./fixtures/update-organization.json"));
|
|
25
|
+
const set_stripe_customer_id_json_1 = __importDefault(require("./fixtures/set-stripe-customer-id.json"));
|
|
26
|
+
const set_stripe_customer_id_disabled_json_1 = __importDefault(require("./fixtures/set-stripe-customer-id-disabled.json"));
|
|
23
27
|
const interfaces_1 = require("./interfaces");
|
|
24
28
|
const workos = new workos_1.WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU');
|
|
25
29
|
describe('Organizations', () => {
|
|
@@ -236,4 +240,77 @@ describe('Organizations', () => {
|
|
|
236
240
|
});
|
|
237
241
|
});
|
|
238
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`', () => {
|
|
269
|
+
it('updates the organization’s Stripe customer ID', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
270
|
+
(0, test_utils_1.fetchOnce)(set_stripe_customer_id_json_1.default);
|
|
271
|
+
const subject = yield workos.organizations.updateOrganization({
|
|
272
|
+
organization: 'org_01EHT88Z8J8795GZNQ4ZP1J81T',
|
|
273
|
+
stripeCustomerId: 'cus_MX8J9nfK4lP2Yw',
|
|
274
|
+
});
|
|
275
|
+
expect((0, test_utils_1.fetchBody)()).toMatchObject({
|
|
276
|
+
stripe_customer_id: 'cus_MX8J9nfK4lP2Yw',
|
|
277
|
+
});
|
|
278
|
+
expect(subject.stripeCustomerId).toBe('cus_MX8J9nfK4lP2Yw');
|
|
279
|
+
}));
|
|
280
|
+
it('clears the organization’s Stripe customer ID with a `null` value', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
281
|
+
(0, test_utils_1.fetchOnce)(clear_stripe_customer_id_json_1.default);
|
|
282
|
+
const subject = yield workos.organizations.updateOrganization({
|
|
283
|
+
organization: 'org_01EHT88Z8J8795GZNQ4ZP1J81T',
|
|
284
|
+
stripeCustomerId: null,
|
|
285
|
+
});
|
|
286
|
+
expect((0, test_utils_1.fetchBody)()).toEqual({
|
|
287
|
+
stripe_customer_id: null,
|
|
288
|
+
});
|
|
289
|
+
expect(subject.stripeCustomerId).toBeUndefined();
|
|
290
|
+
}));
|
|
291
|
+
});
|
|
292
|
+
describe('when the feature is not enabled', () => {
|
|
293
|
+
it('returns an error', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
294
|
+
(0, test_utils_1.fetchOnce)(set_stripe_customer_id_disabled_json_1.default, { status: 422 });
|
|
295
|
+
yield expect(workos.organizations.setStripeCustomerId({
|
|
296
|
+
organization: 'org_01EHT88Z8J8795GZNQ4ZP1J81T',
|
|
297
|
+
stripeCustomerId: 'cus_MX8J9nfK4lP2Yw',
|
|
298
|
+
})).rejects.toThrowError('stripe_customer_id is not enabled for this environment');
|
|
299
|
+
expect((0, test_utils_1.fetchBody)()).toEqual({
|
|
300
|
+
stripe_customer_id: 'cus_MX8J9nfK4lP2Yw',
|
|
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,
|
|
311
|
+
});
|
|
312
|
+
expect((0, test_utils_1.fetchURL)()).toContain('/organizations/org_01EHT88Z8J8795GZNQ4ZP1J81T');
|
|
313
|
+
expect(subject).toEqual('cus_MX8J9nfK4lP2Yw');
|
|
314
|
+
}));
|
|
315
|
+
});
|
|
239
316
|
});
|
|
@@ -2,13 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.deserializeOrganization = void 0;
|
|
4
4
|
const organization_domain_serializer_1 = require("../../organization-domains/serializers/organization-domain.serializer");
|
|
5
|
-
const deserializeOrganization = (organization) => ({
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
name: organization.name,
|
|
9
|
-
allowProfilesOutsideOrganization: organization.allow_profiles_outside_organization,
|
|
10
|
-
domains: organization.domains.map(organization_domain_serializer_1.deserializeOrganizationDomain),
|
|
11
|
-
createdAt: organization.created_at,
|
|
12
|
-
updatedAt: organization.updated_at,
|
|
13
|
-
});
|
|
5
|
+
const deserializeOrganization = (organization) => (Object.assign(Object.assign({ object: organization.object, id: organization.id, name: organization.name, allowProfilesOutsideOrganization: organization.allow_profiles_outside_organization, domains: organization.domains.map(organization_domain_serializer_1.deserializeOrganizationDomain) }, (typeof organization.stripe_customer_id === 'undefined'
|
|
6
|
+
? undefined
|
|
7
|
+
: { stripeCustomerId: organization.stripe_customer_id })), { createdAt: organization.created_at, updatedAt: organization.updated_at }));
|
|
14
8
|
exports.deserializeOrganization = deserializeOrganization;
|
|
@@ -6,5 +6,6 @@ const serializeUpdateOrganizationOptions = (options) => ({
|
|
|
6
6
|
allow_profiles_outside_organization: options.allowProfilesOutsideOrganization,
|
|
7
7
|
domain_data: options.domainData,
|
|
8
8
|
domains: options.domains,
|
|
9
|
+
stripe_customer_id: options.stripeCustomerId,
|
|
9
10
|
});
|
|
10
11
|
exports.serializeUpdateOrganizationOptions = serializeUpdateOrganizationOptions;
|
|
@@ -10,6 +10,7 @@ export interface AccessToken {
|
|
|
10
10
|
org_id?: string;
|
|
11
11
|
role?: string;
|
|
12
12
|
permissions?: string[];
|
|
13
|
+
entitlements?: string[];
|
|
13
14
|
}
|
|
14
15
|
export type SessionCookieData = Pick<AuthenticationResponse, 'accessToken' | 'impersonator' | 'organizationId' | 'refreshToken' | 'user'>;
|
|
15
16
|
export declare enum AuthenticateWithSessionCookieFailureReason {
|
|
@@ -27,6 +28,7 @@ export type AuthenticateWithSessionCookieSuccessResponse = {
|
|
|
27
28
|
organizationId?: string;
|
|
28
29
|
role?: string;
|
|
29
30
|
permissions?: string[];
|
|
31
|
+
entitlements?: string[];
|
|
30
32
|
user: User;
|
|
31
33
|
impersonator?: Impersonator;
|
|
32
34
|
};
|
|
@@ -64,13 +64,14 @@ class Session {
|
|
|
64
64
|
reason: interfaces_1.AuthenticateWithSessionCookieFailureReason.INVALID_JWT,
|
|
65
65
|
};
|
|
66
66
|
}
|
|
67
|
-
const { sid: sessionId, org_id: organizationId, role, permissions, } = (0, jose_1.decodeJwt)(session.accessToken);
|
|
67
|
+
const { sid: sessionId, org_id: organizationId, role, permissions, entitlements, } = (0, jose_1.decodeJwt)(session.accessToken);
|
|
68
68
|
return {
|
|
69
69
|
authenticated: true,
|
|
70
70
|
sessionId,
|
|
71
71
|
organizationId,
|
|
72
72
|
role,
|
|
73
73
|
permissions,
|
|
74
|
+
entitlements,
|
|
74
75
|
user: session.user,
|
|
75
76
|
impersonator: session.impersonator,
|
|
76
77
|
};
|
|
@@ -120,7 +120,7 @@ describe('Session', () => {
|
|
|
120
120
|
.mockResolvedValue({});
|
|
121
121
|
const cookiePassword = 'alongcookiesecretmadefortestingsessions';
|
|
122
122
|
const sessionData = yield (0, iron_session_1.sealData)({
|
|
123
|
-
accessToken: '
|
|
123
|
+
accessToken: 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhdXRoZW50aWNhdGVkIjp0cnVlLCJpbXBlcnNvbmF0b3IiOnsiZW1haWwiOiJhZG1pbkBleGFtcGxlLmNvbSIsInJlYXNvbiI6InRlc3QifSwic2lkIjoic2Vzc2lvbl8xMjMiLCJvcmdfaWQiOiJvcmdfMTIzIiwicm9sZSI6Im1lbWJlciIsInBlcm1pc3Npb25zIjpbInBvc3RzOmNyZWF0ZSIsInBvc3RzOmRlbGV0ZSJdLCJlbnRpdGxlbWVudHMiOlsiYXVkaXQtbG9ncyJdLCJ1c2VyIjp7Im9iamVjdCI6InVzZXIiLCJpZCI6InVzZXJfMDFINUpRRFY3UjdBVEVZWkRFRzBXNVBSWVMiLCJlbWFpbCI6InRlc3RAZXhhbXBsZS5jb20ifX0.A8mDST4wtq_0vId6ALg7k2Ukr7FXrszZtdJ_6dfXeAc',
|
|
124
124
|
refreshToken: 'def456',
|
|
125
125
|
impersonator: {
|
|
126
126
|
email: 'admin@example.com',
|
|
@@ -146,6 +146,7 @@ describe('Session', () => {
|
|
|
146
146
|
organizationId: 'org_123',
|
|
147
147
|
role: 'member',
|
|
148
148
|
permissions: ['posts:create', 'posts:delete'],
|
|
149
|
+
entitlements: ['audit-logs'],
|
|
149
150
|
user: {
|
|
150
151
|
object: 'user',
|
|
151
152
|
id: 'user_01H5JQDV7R7ATEYZDEG0W5PRYS',
|
|
@@ -192,7 +192,7 @@ class UserManagement {
|
|
|
192
192
|
reason: authenticate_with_session_cookie_interface_1.AuthenticateWithSessionCookieFailureReason.INVALID_JWT,
|
|
193
193
|
};
|
|
194
194
|
}
|
|
195
|
-
const { sid: sessionId, org_id: organizationId, role, permissions, } = (0, jose_1.decodeJwt)(session.accessToken);
|
|
195
|
+
const { sid: sessionId, org_id: organizationId, role, permissions, entitlements, } = (0, jose_1.decodeJwt)(session.accessToken);
|
|
196
196
|
return {
|
|
197
197
|
authenticated: true,
|
|
198
198
|
sessionId,
|
|
@@ -200,6 +200,7 @@ class UserManagement {
|
|
|
200
200
|
role,
|
|
201
201
|
user: session.user,
|
|
202
202
|
permissions,
|
|
203
|
+
entitlements,
|
|
203
204
|
};
|
|
204
205
|
});
|
|
205
206
|
}
|
|
@@ -720,7 +720,7 @@ describe('UserManagement', () => {
|
|
|
720
720
|
.mockResolvedValue({});
|
|
721
721
|
const cookiePassword = 'alongcookiesecretmadefortestingsessions';
|
|
722
722
|
const sessionData = yield (0, iron_session_1.sealData)({
|
|
723
|
-
accessToken: '
|
|
723
|
+
accessToken: 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhdXRoZW50aWNhdGVkIjp0cnVlLCJpbXBlcnNvbmF0b3IiOnsiZW1haWwiOiJhZG1pbkBleGFtcGxlLmNvbSIsInJlYXNvbiI6InRlc3QifSwic2lkIjoic2Vzc2lvbl8xMjMiLCJvcmdfaWQiOiJvcmdfMTIzIiwicm9sZSI6Im1lbWJlciIsInBlcm1pc3Npb25zIjpbInBvc3RzOmNyZWF0ZSIsInBvc3RzOmRlbGV0ZSJdLCJlbnRpdGxlbWVudHMiOlsiYXVkaXQtbG9ncyJdLCJ1c2VyIjp7Im9iamVjdCI6InVzZXIiLCJpZCI6InVzZXJfMDFINUpRRFY3UjdBVEVZWkRFRzBXNVBSWVMiLCJlbWFpbCI6InRlc3RAZXhhbXBsZS5jb20ifX0.A8mDST4wtq_0vId6ALg7k2Ukr7FXrszZtdJ_6dfXeAc',
|
|
724
724
|
refreshToken: 'def456',
|
|
725
725
|
user: {
|
|
726
726
|
object: 'user',
|
|
@@ -737,6 +737,7 @@ describe('UserManagement', () => {
|
|
|
737
737
|
organizationId: 'org_123',
|
|
738
738
|
role: 'member',
|
|
739
739
|
permissions: ['posts:create', 'posts:delete'],
|
|
740
|
+
entitlements: ['audit-logs'],
|
|
740
741
|
user: expect.objectContaining({
|
|
741
742
|
email: 'test@example.com',
|
|
742
743
|
}),
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export type WidgetScope = 'widgets:users-table:manage';
|
|
2
|
+
export interface GetTokenOptions {
|
|
3
|
+
organizationId: string;
|
|
4
|
+
userId: string;
|
|
5
|
+
scopes: [WidgetScope];
|
|
6
|
+
}
|
|
7
|
+
export interface SerializedGetTokenOptions {
|
|
8
|
+
organization_id: string;
|
|
9
|
+
user_id: string;
|
|
10
|
+
scopes: [WidgetScope];
|
|
11
|
+
}
|
|
12
|
+
export declare const serializeGetTokenOptions: (options: GetTokenOptions) => SerializedGetTokenOptions;
|
|
13
|
+
export interface GetTokenResponse {
|
|
14
|
+
token: string;
|
|
15
|
+
}
|
|
16
|
+
export interface GetTokenResponseResponse {
|
|
17
|
+
token: string;
|
|
18
|
+
}
|
|
19
|
+
export declare const deserializeGetTokenResponse: (data: GetTokenResponseResponse) => GetTokenResponse;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.deserializeGetTokenResponse = exports.serializeGetTokenOptions = void 0;
|
|
4
|
+
const serializeGetTokenOptions = (options) => ({
|
|
5
|
+
organization_id: options.organizationId,
|
|
6
|
+
user_id: options.userId,
|
|
7
|
+
scopes: options.scopes,
|
|
8
|
+
});
|
|
9
|
+
exports.serializeGetTokenOptions = serializeGetTokenOptions;
|
|
10
|
+
const deserializeGetTokenResponse = (data) => ({
|
|
11
|
+
token: data.token,
|
|
12
|
+
});
|
|
13
|
+
exports.deserializeGetTokenResponse = deserializeGetTokenResponse;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.Widgets = void 0;
|
|
13
|
+
const get_token_1 = require("./interfaces/get-token");
|
|
14
|
+
class Widgets {
|
|
15
|
+
constructor(workos) {
|
|
16
|
+
this.workos = workos;
|
|
17
|
+
}
|
|
18
|
+
getToken(payload) {
|
|
19
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
20
|
+
const { data } = yield this.workos.post('/widgets/token', (0, get_token_1.serializeGetTokenOptions)(payload));
|
|
21
|
+
return (0, get_token_1.deserializeGetTokenResponse)(data).token;
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.Widgets = Widgets;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const jest_fetch_mock_1 = __importDefault(require("jest-fetch-mock"));
|
|
16
|
+
const workos_1 = require("../workos");
|
|
17
|
+
const test_utils_1 = require("../common/utils/test-utils");
|
|
18
|
+
const token_json_1 = __importDefault(require("./fixtures/token.json"));
|
|
19
|
+
const get_token_error_json_1 = __importDefault(require("./fixtures/get-token-error.json"));
|
|
20
|
+
describe('Widgets', () => {
|
|
21
|
+
let workos;
|
|
22
|
+
beforeAll(() => {
|
|
23
|
+
workos = new workos_1.WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU', {
|
|
24
|
+
apiHostname: 'api.workos.test',
|
|
25
|
+
clientId: 'proj_123',
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
beforeEach(() => jest_fetch_mock_1.default.resetMocks());
|
|
29
|
+
describe('getToken', () => {
|
|
30
|
+
it('sends a Get Token request', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
31
|
+
(0, test_utils_1.fetchOnce)(token_json_1.default);
|
|
32
|
+
const token = yield workos.widgets.getToken({
|
|
33
|
+
organizationId: 'org_123',
|
|
34
|
+
userId: 'user_123',
|
|
35
|
+
scopes: ['widgets:users-table:manage'],
|
|
36
|
+
});
|
|
37
|
+
expect((0, test_utils_1.fetchURL)()).toContain('/widgets/token');
|
|
38
|
+
expect(token).toEqual('this.is.a.token');
|
|
39
|
+
}));
|
|
40
|
+
it('returns an error if the API returns an error', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
41
|
+
(0, test_utils_1.fetchOnce)(get_token_error_json_1.default, { status: 404 });
|
|
42
|
+
yield expect(workos.widgets.getToken({
|
|
43
|
+
organizationId: 'org_123',
|
|
44
|
+
userId: 'user_123',
|
|
45
|
+
scopes: ['widgets:users-table:manage'],
|
|
46
|
+
})).rejects.toThrow("User not found 'user_123'");
|
|
47
|
+
}));
|
|
48
|
+
});
|
|
49
|
+
});
|
package/lib/workos.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ import { UserManagement } from './user-management/user-management';
|
|
|
13
13
|
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
|
+
import { Widgets } from './widgets/widgets';
|
|
16
17
|
export declare class WorkOS {
|
|
17
18
|
readonly key?: string | undefined;
|
|
18
19
|
readonly options: WorkOSOptions;
|
|
@@ -31,6 +32,7 @@ export declare class WorkOS {
|
|
|
31
32
|
readonly events: Events;
|
|
32
33
|
readonly userManagement: UserManagement;
|
|
33
34
|
readonly fga: FGA;
|
|
35
|
+
readonly widgets: Widgets;
|
|
34
36
|
constructor(key?: string | undefined, options?: WorkOSOptions);
|
|
35
37
|
createWebhookClient(): Webhooks;
|
|
36
38
|
createHttpClient(options: WorkOSOptions, userAgent: string): HttpClient;
|
package/lib/workos.js
CHANGED
|
@@ -27,7 +27,8 @@ const bad_request_exception_1 = require("./common/exceptions/bad-request.excepti
|
|
|
27
27
|
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
|
-
const
|
|
30
|
+
const widgets_1 = require("./widgets/widgets");
|
|
31
|
+
const VERSION = '7.30.1';
|
|
31
32
|
const DEFAULT_HOSTNAME = 'api.workos.com';
|
|
32
33
|
const HEADER_AUTHORIZATION = 'Authorization';
|
|
33
34
|
const HEADER_IDEMPOTENCY_KEY = 'Idempotency-Key';
|
|
@@ -46,6 +47,7 @@ class WorkOS {
|
|
|
46
47
|
this.mfa = new mfa_1.Mfa(this);
|
|
47
48
|
this.events = new events_1.Events(this);
|
|
48
49
|
this.fga = new fga_1.FGA(this);
|
|
50
|
+
this.widgets = new widgets_1.Widgets(this);
|
|
49
51
|
if (!key) {
|
|
50
52
|
// process might be undefined in some environments
|
|
51
53
|
this.key =
|
|
@@ -176,7 +178,7 @@ class WorkOS {
|
|
|
176
178
|
handleHttpError({ path, error }) {
|
|
177
179
|
var _a;
|
|
178
180
|
if (!(error instanceof http_client_1.HttpClientError)) {
|
|
179
|
-
throw new Error(`Unexpected error: ${error}
|
|
181
|
+
throw new Error(`Unexpected error: ${error}`, { cause: error });
|
|
180
182
|
}
|
|
181
183
|
const { response } = error;
|
|
182
184
|
if (response) {
|
package/package.json
CHANGED