@workos-inc/node 7.28.0 → 7.29.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.d.ts +2 -0
- package/lib/audit-logs/audit-logs.js +6 -0
- package/lib/audit-logs/audit-logs.spec.js +188 -0
- package/lib/audit-logs/interfaces/create-audit-log-schema-options.interface.d.ts +63 -0
- package/lib/audit-logs/interfaces/create-audit-log-schema-options.interface.js +2 -0
- package/lib/audit-logs/interfaces/index.d.ts +1 -0
- package/lib/audit-logs/interfaces/index.js +1 -0
- package/lib/audit-logs/serializers/create-audit-log-schema-options.serializer.d.ts +2 -0
- package/lib/audit-logs/serializers/create-audit-log-schema-options.serializer.js +42 -0
- package/lib/audit-logs/serializers/create-audit-log-schema.serializer.d.ts +2 -0
- package/lib/audit-logs/serializers/create-audit-log-schema.serializer.js +36 -0
- package/lib/audit-logs/serializers/index.d.ts +2 -0
- package/lib/audit-logs/serializers/index.js +2 -0
- package/lib/workos.js +1 -1
- package/package.json +1 -1
|
@@ -2,10 +2,12 @@ import { WorkOS } from '../workos';
|
|
|
2
2
|
import { CreateAuditLogEventOptions, CreateAuditLogEventRequestOptions } from './interfaces';
|
|
3
3
|
import { AuditLogExportOptions } from './interfaces/audit-log-export-options.interface';
|
|
4
4
|
import { AuditLogExport } from './interfaces/audit-log-export.interface';
|
|
5
|
+
import { AuditLogSchema, CreateAuditLogSchemaOptions, CreateAuditLogSchemaRequestOptions } from './interfaces/create-audit-log-schema-options.interface';
|
|
5
6
|
export declare class AuditLogs {
|
|
6
7
|
private readonly workos;
|
|
7
8
|
constructor(workos: WorkOS);
|
|
8
9
|
createEvent(organization: string, event: CreateAuditLogEventOptions, options?: CreateAuditLogEventRequestOptions): Promise<void>;
|
|
9
10
|
createExport(options: AuditLogExportOptions): Promise<AuditLogExport>;
|
|
10
11
|
getExport(auditLogExportId: string): Promise<AuditLogExport>;
|
|
12
|
+
createSchema(schema: CreateAuditLogSchemaOptions, options?: CreateAuditLogSchemaRequestOptions): Promise<AuditLogSchema>;
|
|
11
13
|
}
|
|
@@ -35,5 +35,11 @@ class AuditLogs {
|
|
|
35
35
|
return (0, serializers_1.deserializeAuditLogExport)(data);
|
|
36
36
|
});
|
|
37
37
|
}
|
|
38
|
+
createSchema(schema, options = {}) {
|
|
39
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
40
|
+
const { data } = yield this.workos.post(`/audit_logs/actions/${schema.action}/schemas`, (0, serializers_1.serializeCreateAuditLogSchemaOptions)(schema), options);
|
|
41
|
+
return (0, serializers_1.deserializeAuditLogSchema)(data);
|
|
42
|
+
});
|
|
43
|
+
}
|
|
38
44
|
}
|
|
39
45
|
exports.AuditLogs = AuditLogs;
|
|
@@ -41,6 +41,26 @@ const event = {
|
|
|
41
41
|
successful: true,
|
|
42
42
|
},
|
|
43
43
|
};
|
|
44
|
+
const schema = {
|
|
45
|
+
action: 'user.logged_in',
|
|
46
|
+
actor: {
|
|
47
|
+
metadata: {
|
|
48
|
+
actor_id: 'string',
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
targets: [
|
|
52
|
+
{
|
|
53
|
+
type: 'user',
|
|
54
|
+
metadata: {
|
|
55
|
+
user_id: 'string',
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
],
|
|
59
|
+
metadata: {
|
|
60
|
+
foo: 'number',
|
|
61
|
+
baz: 'boolean',
|
|
62
|
+
},
|
|
63
|
+
};
|
|
44
64
|
describe('AuditLogs', () => {
|
|
45
65
|
beforeEach(() => jest_fetch_mock_1.default.resetMocks());
|
|
46
66
|
describe('createEvent', () => {
|
|
@@ -234,4 +254,172 @@ describe('AuditLogs', () => {
|
|
|
234
254
|
}));
|
|
235
255
|
});
|
|
236
256
|
});
|
|
257
|
+
describe('createSchema', () => {
|
|
258
|
+
describe('with an idempotency key', () => {
|
|
259
|
+
it('includes an idempotency key with request', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
260
|
+
const workosSpy = jest.spyOn(workos_1.WorkOS.prototype, 'post');
|
|
261
|
+
const time = new Date().toISOString();
|
|
262
|
+
const createSchemaResult = {
|
|
263
|
+
object: 'audit_log_schema',
|
|
264
|
+
version: 1,
|
|
265
|
+
targets: [
|
|
266
|
+
{
|
|
267
|
+
type: 'user',
|
|
268
|
+
metadata: {
|
|
269
|
+
user_id: 'string',
|
|
270
|
+
},
|
|
271
|
+
},
|
|
272
|
+
],
|
|
273
|
+
actor: {
|
|
274
|
+
metadata: {
|
|
275
|
+
actor_id: 'string',
|
|
276
|
+
},
|
|
277
|
+
},
|
|
278
|
+
metadata: {
|
|
279
|
+
foo: 'number',
|
|
280
|
+
baz: 'boolean',
|
|
281
|
+
},
|
|
282
|
+
createdAt: time,
|
|
283
|
+
};
|
|
284
|
+
const createSchemaResponse = {
|
|
285
|
+
object: 'audit_log_schema',
|
|
286
|
+
version: 1,
|
|
287
|
+
targets: [
|
|
288
|
+
{
|
|
289
|
+
type: 'user',
|
|
290
|
+
metadata: {
|
|
291
|
+
type: 'object',
|
|
292
|
+
properties: {
|
|
293
|
+
user_id: {
|
|
294
|
+
type: 'string',
|
|
295
|
+
},
|
|
296
|
+
},
|
|
297
|
+
},
|
|
298
|
+
},
|
|
299
|
+
],
|
|
300
|
+
actor: {
|
|
301
|
+
metadata: {
|
|
302
|
+
type: 'object',
|
|
303
|
+
properties: {
|
|
304
|
+
actor_id: {
|
|
305
|
+
type: 'string',
|
|
306
|
+
},
|
|
307
|
+
},
|
|
308
|
+
},
|
|
309
|
+
},
|
|
310
|
+
metadata: {
|
|
311
|
+
type: 'object',
|
|
312
|
+
properties: {
|
|
313
|
+
foo: {
|
|
314
|
+
type: 'number',
|
|
315
|
+
},
|
|
316
|
+
baz: {
|
|
317
|
+
type: 'boolean',
|
|
318
|
+
},
|
|
319
|
+
},
|
|
320
|
+
},
|
|
321
|
+
created_at: time,
|
|
322
|
+
};
|
|
323
|
+
workosSpy.mockResolvedValueOnce((0, workos_mock_response_1.mockWorkOsResponse)(201, createSchemaResponse));
|
|
324
|
+
const workos = new workos_1.WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU');
|
|
325
|
+
yield expect(workos.auditLogs.createSchema(schema, {
|
|
326
|
+
idempotencyKey: 'the-idempotency-key',
|
|
327
|
+
})).resolves.toEqual(createSchemaResult);
|
|
328
|
+
expect(workosSpy).toHaveBeenCalledWith('/audit_logs/actions/user.logged_in/schemas', (0, serializers_1.serializeCreateAuditLogSchemaOptions)(schema), { idempotencyKey: 'the-idempotency-key' });
|
|
329
|
+
}));
|
|
330
|
+
});
|
|
331
|
+
describe('when the api responds with a 201', () => {
|
|
332
|
+
it('returns `audit_log_schema`', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
333
|
+
const workosSpy = jest.spyOn(workos_1.WorkOS.prototype, 'post');
|
|
334
|
+
const time = new Date().toISOString();
|
|
335
|
+
const createSchemaResult = {
|
|
336
|
+
object: 'audit_log_schema',
|
|
337
|
+
version: 1,
|
|
338
|
+
targets: [
|
|
339
|
+
{
|
|
340
|
+
type: 'user',
|
|
341
|
+
metadata: {
|
|
342
|
+
user_id: 'string',
|
|
343
|
+
},
|
|
344
|
+
},
|
|
345
|
+
],
|
|
346
|
+
actor: {
|
|
347
|
+
metadata: {
|
|
348
|
+
actor_id: 'string',
|
|
349
|
+
},
|
|
350
|
+
},
|
|
351
|
+
metadata: {
|
|
352
|
+
foo: 'number',
|
|
353
|
+
baz: 'boolean',
|
|
354
|
+
},
|
|
355
|
+
createdAt: time,
|
|
356
|
+
};
|
|
357
|
+
const createSchemaResponse = {
|
|
358
|
+
object: 'audit_log_schema',
|
|
359
|
+
version: 1,
|
|
360
|
+
targets: [
|
|
361
|
+
{
|
|
362
|
+
type: 'user',
|
|
363
|
+
metadata: {
|
|
364
|
+
type: 'object',
|
|
365
|
+
properties: {
|
|
366
|
+
user_id: {
|
|
367
|
+
type: 'string',
|
|
368
|
+
},
|
|
369
|
+
},
|
|
370
|
+
},
|
|
371
|
+
},
|
|
372
|
+
],
|
|
373
|
+
actor: {
|
|
374
|
+
metadata: {
|
|
375
|
+
type: 'object',
|
|
376
|
+
properties: {
|
|
377
|
+
actor_id: {
|
|
378
|
+
type: 'string',
|
|
379
|
+
},
|
|
380
|
+
},
|
|
381
|
+
},
|
|
382
|
+
},
|
|
383
|
+
metadata: {
|
|
384
|
+
type: 'object',
|
|
385
|
+
properties: {
|
|
386
|
+
foo: {
|
|
387
|
+
type: 'number',
|
|
388
|
+
},
|
|
389
|
+
baz: {
|
|
390
|
+
type: 'boolean',
|
|
391
|
+
},
|
|
392
|
+
},
|
|
393
|
+
},
|
|
394
|
+
created_at: time,
|
|
395
|
+
};
|
|
396
|
+
workosSpy.mockResolvedValueOnce((0, workos_mock_response_1.mockWorkOsResponse)(201, createSchemaResponse));
|
|
397
|
+
const workos = new workos_1.WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU');
|
|
398
|
+
yield expect(workos.auditLogs.createSchema(schema, {
|
|
399
|
+
idempotencyKey: 'the-idempotency-key',
|
|
400
|
+
})).resolves.toEqual(createSchemaResult);
|
|
401
|
+
}));
|
|
402
|
+
});
|
|
403
|
+
describe('when the api responds with a 400', () => {
|
|
404
|
+
it('throws a BadRequestException', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
405
|
+
const workosSpy = jest.spyOn(workos_1.WorkOS.prototype, 'post');
|
|
406
|
+
const errors = [
|
|
407
|
+
{
|
|
408
|
+
field: 'actor.metadata',
|
|
409
|
+
code: 'actor.metadata must be an object',
|
|
410
|
+
},
|
|
411
|
+
];
|
|
412
|
+
workosSpy.mockImplementationOnce(() => {
|
|
413
|
+
throw new bad_request_exception_1.BadRequestException({
|
|
414
|
+
code: '400',
|
|
415
|
+
errors,
|
|
416
|
+
message: 'Audit Log Schema could not be processed due to missing or incorrect data.',
|
|
417
|
+
requestID: 'a-request-id',
|
|
418
|
+
});
|
|
419
|
+
});
|
|
420
|
+
const workos = new workos_1.WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU');
|
|
421
|
+
yield expect(workos.auditLogs.createSchema(schema)).rejects.toThrow(bad_request_exception_1.BadRequestException);
|
|
422
|
+
}));
|
|
423
|
+
});
|
|
424
|
+
});
|
|
237
425
|
});
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { PostOptions } from '../../common/interfaces';
|
|
2
|
+
export type AuditLogSchemaMetadata = Record<string, {
|
|
3
|
+
type: 'string' | 'boolean' | 'number';
|
|
4
|
+
}> | undefined;
|
|
5
|
+
export interface AuditLogSchema {
|
|
6
|
+
object: 'audit_log_schema';
|
|
7
|
+
version: number;
|
|
8
|
+
targets: AuditLogTargetSchema[];
|
|
9
|
+
actor: AuditLogActorSchema;
|
|
10
|
+
metadata: Record<string, string | boolean | number> | undefined;
|
|
11
|
+
createdAt: string;
|
|
12
|
+
}
|
|
13
|
+
export interface AuditLogActorSchema {
|
|
14
|
+
metadata: Record<string, string | boolean | number>;
|
|
15
|
+
}
|
|
16
|
+
export interface AuditLogTargetSchema {
|
|
17
|
+
type: string;
|
|
18
|
+
metadata?: Record<string, string | boolean | number> | undefined;
|
|
19
|
+
}
|
|
20
|
+
export interface CreateAuditLogSchemaOptions {
|
|
21
|
+
action: string;
|
|
22
|
+
targets: AuditLogTargetSchema[];
|
|
23
|
+
actor?: AuditLogActorSchema;
|
|
24
|
+
metadata?: Record<string, string | boolean | number>;
|
|
25
|
+
}
|
|
26
|
+
interface SerializedAuditLogTargetSchema {
|
|
27
|
+
type: string;
|
|
28
|
+
metadata?: {
|
|
29
|
+
type: 'object';
|
|
30
|
+
properties: AuditLogSchemaMetadata;
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
export interface SerializedCreateAuditLogSchemaOptions {
|
|
34
|
+
targets: SerializedAuditLogTargetSchema[];
|
|
35
|
+
actor?: {
|
|
36
|
+
metadata: {
|
|
37
|
+
type: 'object';
|
|
38
|
+
properties: AuditLogSchemaMetadata;
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
metadata?: {
|
|
42
|
+
type: 'object';
|
|
43
|
+
properties: AuditLogSchemaMetadata;
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
export interface CreateAuditLogSchemaResponse {
|
|
47
|
+
object: 'audit_log_schema';
|
|
48
|
+
version: number;
|
|
49
|
+
targets: SerializedAuditLogTargetSchema[];
|
|
50
|
+
actor: {
|
|
51
|
+
metadata: {
|
|
52
|
+
type: 'object';
|
|
53
|
+
properties: AuditLogSchemaMetadata;
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
metadata: {
|
|
57
|
+
type: 'object';
|
|
58
|
+
properties: AuditLogSchemaMetadata;
|
|
59
|
+
};
|
|
60
|
+
created_at: string;
|
|
61
|
+
}
|
|
62
|
+
export type CreateAuditLogSchemaRequestOptions = Pick<PostOptions, 'idempotencyKey'>;
|
|
63
|
+
export {};
|
|
@@ -17,3 +17,4 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
__exportStar(require("./audit-log-export-options.interface"), exports);
|
|
18
18
|
__exportStar(require("./audit-log-export.interface"), exports);
|
|
19
19
|
__exportStar(require("./create-audit-log-event-options.interface"), exports);
|
|
20
|
+
__exportStar(require("./create-audit-log-schema-options.interface"), exports);
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.serializeCreateAuditLogSchemaOptions = void 0;
|
|
4
|
+
function serializeMetadata(metadata) {
|
|
5
|
+
if (!metadata) {
|
|
6
|
+
return {};
|
|
7
|
+
}
|
|
8
|
+
const serializedMetadata = {};
|
|
9
|
+
Object.keys(metadata).forEach((key) => {
|
|
10
|
+
serializedMetadata[key] = {
|
|
11
|
+
type: metadata[key],
|
|
12
|
+
};
|
|
13
|
+
});
|
|
14
|
+
return serializedMetadata;
|
|
15
|
+
}
|
|
16
|
+
const serializeCreateAuditLogSchemaOptions = (schema) => {
|
|
17
|
+
var _a;
|
|
18
|
+
return ({
|
|
19
|
+
actor: {
|
|
20
|
+
metadata: {
|
|
21
|
+
type: 'object',
|
|
22
|
+
properties: serializeMetadata((_a = schema.actor) === null || _a === void 0 ? void 0 : _a.metadata),
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
targets: schema.targets.map((target) => {
|
|
26
|
+
return {
|
|
27
|
+
type: target.type,
|
|
28
|
+
metadata: target.metadata
|
|
29
|
+
? {
|
|
30
|
+
type: 'object',
|
|
31
|
+
properties: serializeMetadata(target.metadata),
|
|
32
|
+
}
|
|
33
|
+
: undefined,
|
|
34
|
+
};
|
|
35
|
+
}),
|
|
36
|
+
metadata: {
|
|
37
|
+
type: 'object',
|
|
38
|
+
properties: serializeMetadata(schema.metadata),
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
exports.serializeCreateAuditLogSchemaOptions = serializeCreateAuditLogSchemaOptions;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.deserializeAuditLogSchema = void 0;
|
|
4
|
+
function deserializeMetadata(metadata) {
|
|
5
|
+
if (!metadata || !metadata.properties) {
|
|
6
|
+
return {};
|
|
7
|
+
}
|
|
8
|
+
const deserializedMetadata = {};
|
|
9
|
+
Object.keys(metadata.properties).forEach((key) => {
|
|
10
|
+
if (metadata.properties) {
|
|
11
|
+
deserializedMetadata[key] = metadata.properties[key].type;
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
return deserializedMetadata;
|
|
15
|
+
}
|
|
16
|
+
const deserializeAuditLogSchema = (auditLogSchema) => {
|
|
17
|
+
var _a;
|
|
18
|
+
return ({
|
|
19
|
+
object: auditLogSchema.object,
|
|
20
|
+
version: auditLogSchema.version,
|
|
21
|
+
targets: auditLogSchema.targets.map((target) => {
|
|
22
|
+
return {
|
|
23
|
+
type: target.type,
|
|
24
|
+
metadata: target.metadata
|
|
25
|
+
? deserializeMetadata(target.metadata)
|
|
26
|
+
: undefined,
|
|
27
|
+
};
|
|
28
|
+
}),
|
|
29
|
+
actor: {
|
|
30
|
+
metadata: deserializeMetadata((_a = auditLogSchema.actor) === null || _a === void 0 ? void 0 : _a.metadata),
|
|
31
|
+
},
|
|
32
|
+
metadata: deserializeMetadata(auditLogSchema.metadata),
|
|
33
|
+
createdAt: auditLogSchema.created_at,
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
exports.deserializeAuditLogSchema = deserializeAuditLogSchema;
|
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
export * from './audit-log-export.serializer';
|
|
2
2
|
export * from './audit-log-export-options.serializer';
|
|
3
3
|
export * from './create-audit-log-event-options.serializer';
|
|
4
|
+
export * from './create-audit-log-schema-options.serializer';
|
|
5
|
+
export * from './create-audit-log-schema.serializer';
|
|
@@ -17,3 +17,5 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
__exportStar(require("./audit-log-export.serializer"), exports);
|
|
18
18
|
__exportStar(require("./audit-log-export-options.serializer"), exports);
|
|
19
19
|
__exportStar(require("./create-audit-log-event-options.serializer"), exports);
|
|
20
|
+
__exportStar(require("./create-audit-log-schema-options.serializer"), exports);
|
|
21
|
+
__exportStar(require("./create-audit-log-schema.serializer"), exports);
|
package/lib/workos.js
CHANGED
|
@@ -27,7 +27,7 @@ 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 VERSION = '7.
|
|
30
|
+
const VERSION = '7.29.0';
|
|
31
31
|
const DEFAULT_HOSTNAME = 'api.workos.com';
|
|
32
32
|
const HEADER_AUTHORIZATION = 'Authorization';
|
|
33
33
|
const HEADER_IDEMPOTENCY_KEY = 'Idempotency-Key';
|
package/package.json
CHANGED