@workos-inc/node 7.28.0 → 7.29.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.
@@ -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 {};
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,3 +1,4 @@
1
1
  export * from './audit-log-export-options.interface';
2
2
  export * from './audit-log-export.interface';
3
3
  export * from './create-audit-log-event-options.interface';
4
+ export * from './create-audit-log-schema-options.interface';
@@ -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,2 @@
1
+ import { CreateAuditLogSchemaOptions, SerializedCreateAuditLogSchemaOptions } from '../interfaces';
2
+ export declare const serializeCreateAuditLogSchemaOptions: (schema: CreateAuditLogSchemaOptions) => SerializedCreateAuditLogSchemaOptions;
@@ -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,2 @@
1
+ import { AuditLogSchema, CreateAuditLogSchemaResponse } from '../interfaces';
2
+ export declare const deserializeAuditLogSchema: (auditLogSchema: CreateAuditLogSchemaResponse) => AuditLogSchema;
@@ -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);
@@ -16,7 +16,7 @@ export interface OrganizationDomain {
16
16
  id: string;
17
17
  domain: string;
18
18
  state: OrganizationDomainState;
19
- verificationToken: string;
19
+ verificationToken?: string;
20
20
  verificationStrategy: OrganizationDomainVerificationStrategy;
21
21
  }
22
22
  export interface OrganizationDomainResponse {
@@ -24,6 +24,6 @@ export interface OrganizationDomainResponse {
24
24
  id: string;
25
25
  domain: string;
26
26
  state: OrganizationDomainState;
27
- verification_token: string;
27
+ verification_token?: string;
28
28
  verification_strategy: OrganizationDomainVerificationStrategy;
29
29
  }
@@ -7,7 +7,10 @@
7
7
  {
8
8
  "domain": "example.com",
9
9
  "object": "organization_domain",
10
- "id": "org_domain_01EHT88Z8WZEFWYPM6EC9BX2R8"
10
+ "id": "org_domain_01EHT88Z8WZEFWYPM6EC9BX2R8",
11
+ "state": "verified",
12
+ "verification_strategy": "dns",
13
+ "verification_token": "xB8SeACdKJQP9DP4CahU4YuQZ"
11
14
  }
12
15
  ]
13
16
  }
@@ -1,4 +1,4 @@
1
- import { OrganizationDomain } from '../../organization-domains/interfaces/organization-domain.interface';
1
+ import { OrganizationDomain, OrganizationDomainResponse } from '../../organization-domains/interfaces/organization-domain.interface';
2
2
  export interface Organization {
3
3
  object: 'organization';
4
4
  id: string;
@@ -13,7 +13,7 @@ export interface OrganizationResponse {
13
13
  id: string;
14
14
  name: string;
15
15
  allow_profiles_outside_organization: boolean;
16
- domains: OrganizationDomain[];
16
+ domains: OrganizationDomainResponse[];
17
17
  created_at: string;
18
18
  updated_at: string;
19
19
  }
@@ -178,7 +178,16 @@ describe('Organizations', () => {
178
178
  expect(subject.id).toEqual('org_01EHT88Z8J8795GZNQ4ZP1J81T');
179
179
  expect(subject.name).toEqual('Test Organization 3');
180
180
  expect(subject.allowProfilesOutsideOrganization).toEqual(false);
181
- expect(subject.domains).toHaveLength(1);
181
+ expect(subject.domains).toEqual([
182
+ {
183
+ object: 'organization_domain',
184
+ id: 'org_domain_01EHT88Z8WZEFWYPM6EC9BX2R8',
185
+ domain: 'example.com',
186
+ state: 'verified',
187
+ verificationStrategy: 'dns',
188
+ verificationToken: 'xB8SeACdKJQP9DP4CahU4YuQZ',
189
+ },
190
+ ]);
182
191
  }));
183
192
  });
184
193
  describe('deleteOrganization', () => {
@@ -1,12 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.deserializeOrganization = void 0;
4
+ const organization_domain_serializer_1 = require("../../organization-domains/serializers/organization-domain.serializer");
4
5
  const deserializeOrganization = (organization) => ({
5
6
  object: organization.object,
6
7
  id: organization.id,
7
8
  name: organization.name,
8
9
  allowProfilesOutsideOrganization: organization.allow_profiles_outside_organization,
9
- domains: organization.domains,
10
+ domains: organization.domains.map(organization_domain_serializer_1.deserializeOrganizationDomain),
10
11
  createdAt: organization.created_at,
11
12
  updatedAt: organization.updated_at,
12
13
  });
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.28.0';
30
+ const VERSION = '7.29.1';
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
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "7.28.0",
2
+ "version": "7.29.1",
3
3
  "name": "@workos-inc/node",
4
4
  "author": "WorkOS",
5
5
  "description": "A Node wrapper for the WorkOS API",