@workos-inc/node 7.33.0 → 7.34.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/audit-logs/audit-logs.spec.js +58 -0
- package/lib/audit-logs/interfaces/create-audit-log-schema-options.interface.d.ts +1 -1
- package/lib/audit-logs/serializers/create-audit-log-schema-options.serializer.js +6 -4
- package/lib/audit-logs/serializers/create-audit-log-schema.serializer.js +3 -1
- package/lib/user-management/interfaces/authenticate-with-session-cookie.interface.d.ts +1 -0
- package/lib/user-management/session.js +3 -1
- package/lib/user-management/session.spec.js +3 -1
- package/lib/user-management/user-management.js +1 -0
- package/lib/user-management/user-management.spec.js +3 -1
- package/lib/workos.js +1 -1
- package/package.json +1 -1
|
@@ -61,6 +61,7 @@ const schema = {
|
|
|
61
61
|
baz: 'boolean',
|
|
62
62
|
},
|
|
63
63
|
};
|
|
64
|
+
const schemaWithoutMetadata = Object.assign(Object.assign({}, schema), { metadata: undefined });
|
|
64
65
|
describe('AuditLogs', () => {
|
|
65
66
|
beforeEach(() => jest_fetch_mock_1.default.resetMocks());
|
|
66
67
|
describe('createEvent', () => {
|
|
@@ -328,6 +329,63 @@ describe('AuditLogs', () => {
|
|
|
328
329
|
expect(workosSpy).toHaveBeenCalledWith('/audit_logs/actions/user.logged_in/schemas', (0, serializers_1.serializeCreateAuditLogSchemaOptions)(schema), { idempotencyKey: 'the-idempotency-key' });
|
|
329
330
|
}));
|
|
330
331
|
});
|
|
332
|
+
describe('without metadata', () => {
|
|
333
|
+
it('does not include metadata with the request', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
334
|
+
const workosSpy = jest.spyOn(workos_1.WorkOS.prototype, 'post');
|
|
335
|
+
const time = new Date().toISOString();
|
|
336
|
+
const createSchemaResult = {
|
|
337
|
+
object: 'audit_log_schema',
|
|
338
|
+
version: 1,
|
|
339
|
+
targets: [
|
|
340
|
+
{
|
|
341
|
+
type: 'user',
|
|
342
|
+
metadata: {
|
|
343
|
+
user_id: 'string',
|
|
344
|
+
},
|
|
345
|
+
},
|
|
346
|
+
],
|
|
347
|
+
actor: {
|
|
348
|
+
metadata: {
|
|
349
|
+
actor_id: 'string',
|
|
350
|
+
},
|
|
351
|
+
},
|
|
352
|
+
metadata: undefined,
|
|
353
|
+
createdAt: time,
|
|
354
|
+
};
|
|
355
|
+
const createSchemaResponse = {
|
|
356
|
+
object: 'audit_log_schema',
|
|
357
|
+
version: 1,
|
|
358
|
+
targets: [
|
|
359
|
+
{
|
|
360
|
+
type: 'user',
|
|
361
|
+
metadata: {
|
|
362
|
+
type: 'object',
|
|
363
|
+
properties: {
|
|
364
|
+
user_id: {
|
|
365
|
+
type: 'string',
|
|
366
|
+
},
|
|
367
|
+
},
|
|
368
|
+
},
|
|
369
|
+
},
|
|
370
|
+
],
|
|
371
|
+
actor: {
|
|
372
|
+
metadata: {
|
|
373
|
+
type: 'object',
|
|
374
|
+
properties: {
|
|
375
|
+
actor_id: {
|
|
376
|
+
type: 'string',
|
|
377
|
+
},
|
|
378
|
+
},
|
|
379
|
+
},
|
|
380
|
+
},
|
|
381
|
+
created_at: time,
|
|
382
|
+
};
|
|
383
|
+
workosSpy.mockResolvedValueOnce((0, workos_mock_response_1.mockWorkOsResponse)(201, createSchemaResponse));
|
|
384
|
+
const workos = new workos_1.WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU');
|
|
385
|
+
yield expect(workos.auditLogs.createSchema(schemaWithoutMetadata)).resolves.toEqual(createSchemaResult);
|
|
386
|
+
expect(workosSpy).toHaveBeenCalledWith('/audit_logs/actions/user.logged_in/schemas', (0, serializers_1.serializeCreateAuditLogSchemaOptions)(schemaWithoutMetadata), {});
|
|
387
|
+
}));
|
|
388
|
+
});
|
|
331
389
|
describe('when the api responds with a 201', () => {
|
|
332
390
|
it('returns `audit_log_schema`', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
333
391
|
const workosSpy = jest.spyOn(workos_1.WorkOS.prototype, 'post');
|
|
@@ -33,10 +33,12 @@ const serializeCreateAuditLogSchemaOptions = (schema) => {
|
|
|
33
33
|
: undefined,
|
|
34
34
|
};
|
|
35
35
|
}),
|
|
36
|
-
metadata:
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
36
|
+
metadata: schema.metadata
|
|
37
|
+
? {
|
|
38
|
+
type: 'object',
|
|
39
|
+
properties: serializeMetadata(schema.metadata),
|
|
40
|
+
}
|
|
41
|
+
: undefined,
|
|
40
42
|
});
|
|
41
43
|
};
|
|
42
44
|
exports.serializeCreateAuditLogSchemaOptions = serializeCreateAuditLogSchemaOptions;
|
|
@@ -29,7 +29,9 @@ const deserializeAuditLogSchema = (auditLogSchema) => {
|
|
|
29
29
|
actor: {
|
|
30
30
|
metadata: deserializeMetadata((_a = auditLogSchema.actor) === null || _a === void 0 ? void 0 : _a.metadata),
|
|
31
31
|
},
|
|
32
|
-
metadata:
|
|
32
|
+
metadata: auditLogSchema.metadata
|
|
33
|
+
? deserializeMetadata(auditLogSchema.metadata)
|
|
34
|
+
: undefined,
|
|
33
35
|
createdAt: auditLogSchema.created_at,
|
|
34
36
|
});
|
|
35
37
|
};
|
|
@@ -74,6 +74,7 @@ class Session {
|
|
|
74
74
|
entitlements,
|
|
75
75
|
user: session.user,
|
|
76
76
|
impersonator: session.impersonator,
|
|
77
|
+
accessToken: session.accessToken,
|
|
77
78
|
};
|
|
78
79
|
});
|
|
79
80
|
}
|
|
@@ -97,12 +98,13 @@ class Session {
|
|
|
97
98
|
reason: interfaces_1.RefreshAndSealSessionDataFailureReason.INVALID_SESSION_COOKIE,
|
|
98
99
|
};
|
|
99
100
|
}
|
|
101
|
+
const { org_id: organizationIdFromAccessToken } = (0, jose_1.decodeJwt)(session.accessToken);
|
|
100
102
|
try {
|
|
101
103
|
const cookiePassword = (_a = options.cookiePassword) !== null && _a !== void 0 ? _a : this.cookiePassword;
|
|
102
104
|
const authenticationResponse = yield this.userManagement.authenticateWithRefreshToken({
|
|
103
105
|
clientId: this.userManagement.clientId,
|
|
104
106
|
refreshToken: session.refreshToken,
|
|
105
|
-
organizationId: (_b = options.organizationId) !== null && _b !== void 0 ? _b :
|
|
107
|
+
organizationId: (_b = options.organizationId) !== null && _b !== void 0 ? _b : organizationIdFromAccessToken,
|
|
106
108
|
session: {
|
|
107
109
|
// We want to store the new sealed session in this class instance, so this always needs to be true
|
|
108
110
|
sealSession: true,
|
|
@@ -119,8 +119,9 @@ describe('Session', () => {
|
|
|
119
119
|
.spyOn(jose, 'jwtVerify')
|
|
120
120
|
.mockResolvedValue({});
|
|
121
121
|
const cookiePassword = 'alongcookiesecretmadefortestingsessions';
|
|
122
|
+
const accessToken = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhdXRoZW50aWNhdGVkIjp0cnVlLCJpbXBlcnNvbmF0b3IiOnsiZW1haWwiOiJhZG1pbkBleGFtcGxlLmNvbSIsInJlYXNvbiI6InRlc3QifSwic2lkIjoic2Vzc2lvbl8xMjMiLCJvcmdfaWQiOiJvcmdfMTIzIiwicm9sZSI6Im1lbWJlciIsInBlcm1pc3Npb25zIjpbInBvc3RzOmNyZWF0ZSIsInBvc3RzOmRlbGV0ZSJdLCJlbnRpdGxlbWVudHMiOlsiYXVkaXQtbG9ncyJdLCJ1c2VyIjp7Im9iamVjdCI6InVzZXIiLCJpZCI6InVzZXJfMDFINUpRRFY3UjdBVEVZWkRFRzBXNVBSWVMiLCJlbWFpbCI6InRlc3RAZXhhbXBsZS5jb20ifX0.A8mDST4wtq_0vId6ALg7k2Ukr7FXrszZtdJ_6dfXeAc';
|
|
122
123
|
const sessionData = yield (0, iron_session_1.sealData)({
|
|
123
|
-
accessToken
|
|
124
|
+
accessToken,
|
|
124
125
|
refreshToken: 'def456',
|
|
125
126
|
impersonator: {
|
|
126
127
|
email: 'admin@example.com',
|
|
@@ -152,6 +153,7 @@ describe('Session', () => {
|
|
|
152
153
|
id: 'user_01H5JQDV7R7ATEYZDEG0W5PRYS',
|
|
153
154
|
email: 'test@example.com',
|
|
154
155
|
},
|
|
156
|
+
accessToken,
|
|
155
157
|
});
|
|
156
158
|
}));
|
|
157
159
|
});
|
|
@@ -747,8 +747,9 @@ describe('UserManagement', () => {
|
|
|
747
747
|
.spyOn(jose, 'jwtVerify')
|
|
748
748
|
.mockResolvedValue({});
|
|
749
749
|
const cookiePassword = 'alongcookiesecretmadefortestingsessions';
|
|
750
|
+
const accessToken = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhdXRoZW50aWNhdGVkIjp0cnVlLCJpbXBlcnNvbmF0b3IiOnsiZW1haWwiOiJhZG1pbkBleGFtcGxlLmNvbSIsInJlYXNvbiI6InRlc3QifSwic2lkIjoic2Vzc2lvbl8xMjMiLCJvcmdfaWQiOiJvcmdfMTIzIiwicm9sZSI6Im1lbWJlciIsInBlcm1pc3Npb25zIjpbInBvc3RzOmNyZWF0ZSIsInBvc3RzOmRlbGV0ZSJdLCJlbnRpdGxlbWVudHMiOlsiYXVkaXQtbG9ncyJdLCJ1c2VyIjp7Im9iamVjdCI6InVzZXIiLCJpZCI6InVzZXJfMDFINUpRRFY3UjdBVEVZWkRFRzBXNVBSWVMiLCJlbWFpbCI6InRlc3RAZXhhbXBsZS5jb20ifX0.A8mDST4wtq_0vId6ALg7k2Ukr7FXrszZtdJ_6dfXeAc';
|
|
750
751
|
const sessionData = yield (0, iron_session_1.sealData)({
|
|
751
|
-
accessToken
|
|
752
|
+
accessToken,
|
|
752
753
|
refreshToken: 'def456',
|
|
753
754
|
user: {
|
|
754
755
|
object: 'user',
|
|
@@ -769,6 +770,7 @@ describe('UserManagement', () => {
|
|
|
769
770
|
user: expect.objectContaining({
|
|
770
771
|
email: 'test@example.com',
|
|
771
772
|
}),
|
|
773
|
+
accessToken,
|
|
772
774
|
});
|
|
773
775
|
}));
|
|
774
776
|
});
|
package/lib/workos.js
CHANGED
|
@@ -29,7 +29,7 @@ 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
31
|
const actions_1 = require("./actions/actions");
|
|
32
|
-
const VERSION = '7.
|
|
32
|
+
const VERSION = '7.34.0';
|
|
33
33
|
const DEFAULT_HOSTNAME = 'api.workos.com';
|
|
34
34
|
const HEADER_AUTHORIZATION = 'Authorization';
|
|
35
35
|
const HEADER_IDEMPOTENCY_KEY = 'Idempotency-Key';
|
package/package.json
CHANGED