diff --git a/.oagen-manifest.json b/.oagen-manifest.json index ba29803e3..dfd4fbe7a 100644 --- a/.oagen-manifest.json +++ b/.oagen-manifest.json @@ -1,10 +1,75 @@ { "version": 2, "language": "node", - "generatedAt": "2026-06-01T17:59:24.986Z", + "generatedAt": "2026-06-17T00:09:39.124Z", "files": [ "src/api-keys/interfaces/create-validation-options.interface.ts", "src/api-keys/interfaces/delete-api-key-options.interface.ts", + "src/audit-logs/audit-logs.spec.ts", + "src/audit-logs/audit-logs.ts", + "src/audit-logs/fixtures/audit-log-action.json", + "src/audit-logs/fixtures/audit-log-event-actor.json", + "src/audit-logs/fixtures/audit-log-event-context.json", + "src/audit-logs/fixtures/audit-log-event-create-response.json", + "src/audit-logs/fixtures/audit-log-event-ingestion.json", + "src/audit-logs/fixtures/audit-log-event-target.json", + "src/audit-logs/fixtures/audit-log-event.json", + "src/audit-logs/fixtures/audit-log-export-creation.json", + "src/audit-logs/fixtures/audit-log-export.json", + "src/audit-logs/fixtures/audit-log-schema-actor-input.json", + "src/audit-logs/fixtures/audit-log-schema-actor.json", + "src/audit-logs/fixtures/audit-log-schema-input.json", + "src/audit-logs/fixtures/audit-log-schema-target-input.json", + "src/audit-logs/fixtures/audit-log-schema-target.json", + "src/audit-logs/fixtures/audit-log-schema.json", + "src/audit-logs/fixtures/audit-logs-retention.json", + "src/audit-logs/fixtures/list-audit-log-action.json", + "src/audit-logs/fixtures/list-audit-log-schema.json", + "src/audit-logs/fixtures/update-audit-logs-retention.json", + "src/audit-logs/interfaces/audit-log-action.interface.ts", + "src/audit-logs/interfaces/audit-log-event-actor.interface.ts", + "src/audit-logs/interfaces/audit-log-event-context.interface.ts", + "src/audit-logs/interfaces/audit-log-event-create-response.interface.ts", + "src/audit-logs/interfaces/audit-log-event-ingestion.interface.ts", + "src/audit-logs/interfaces/audit-log-event-target.interface.ts", + "src/audit-logs/interfaces/audit-log-event.interface.ts", + "src/audit-logs/interfaces/audit-log-export-creation.interface.ts", + "src/audit-logs/interfaces/audit-log-export-state.interface.ts", + "src/audit-logs/interfaces/audit-log-export.interface.ts", + "src/audit-logs/interfaces/audit-log-schema-actor-input.interface.ts", + "src/audit-logs/interfaces/audit-log-schema-actor.interface.ts", + "src/audit-logs/interfaces/audit-log-schema-input.interface.ts", + "src/audit-logs/interfaces/audit-log-schema-target-input.interface.ts", + "src/audit-logs/interfaces/audit-log-schema-target.interface.ts", + "src/audit-logs/interfaces/audit-log-schema.interface.ts", + "src/audit-logs/interfaces/audit-logs-retention.interface.ts", + "src/audit-logs/interfaces/create-event-options.interface.ts", + "src/audit-logs/interfaces/create-schema-options.interface.ts", + "src/audit-logs/interfaces/get-export-options.interface.ts", + "src/audit-logs/interfaces/get-organization-audit-logs-retention-options.interface.ts", + "src/audit-logs/interfaces/index.ts", + "src/audit-logs/interfaces/list-action-schemas-options.interface.ts", + "src/audit-logs/interfaces/list-actions-options.interface.ts", + "src/audit-logs/interfaces/update-audit-logs-retention.interface.ts", + "src/audit-logs/interfaces/update-organization-audit-logs-retention-options.interface.ts", + "src/audit-logs/serializers/audit-log-action.serializer.ts", + "src/audit-logs/serializers/audit-log-event-actor.serializer.ts", + "src/audit-logs/serializers/audit-log-event-context.serializer.ts", + "src/audit-logs/serializers/audit-log-event-create-response.serializer.ts", + "src/audit-logs/serializers/audit-log-event-ingestion.serializer.ts", + "src/audit-logs/serializers/audit-log-event-target.serializer.ts", + "src/audit-logs/serializers/audit-log-event.serializer.ts", + "src/audit-logs/serializers/audit-log-export-creation.serializer.ts", + "src/audit-logs/serializers/audit-log-export.serializer.ts", + "src/audit-logs/serializers/audit-log-schema-actor-input.serializer.ts", + "src/audit-logs/serializers/audit-log-schema-actor.serializer.ts", + "src/audit-logs/serializers/audit-log-schema-input.serializer.ts", + "src/audit-logs/serializers/audit-log-schema-target-input.serializer.ts", + "src/audit-logs/serializers/audit-log-schema-target.serializer.ts", + "src/audit-logs/serializers/audit-log-schema.serializer.ts", + "src/audit-logs/serializers/audit-logs-retention.serializer.ts", + "src/audit-logs/serializers/index.ts", + "src/audit-logs/serializers/update-audit-logs-retention.serializer.ts", "src/connect/connect.spec.ts", "src/connect/connect.ts", "src/connect/fixtures/application-credentials-list-item.json", diff --git a/src/audit-logs/audit-logs.spec.ts b/src/audit-logs/audit-logs.spec.ts index 3c9c99b3e..17b897ce0 100644 --- a/src/audit-logs/audit-logs.spec.ts +++ b/src/audit-logs/audit-logs.spec.ts @@ -1,1075 +1,219 @@ +// This file is auto-generated by oagen. Do not edit. + import fetch from 'jest-fetch-mock'; -import { UnauthorizedException } from '../common/exceptions'; -import { BadRequestException } from '../common/exceptions/bad-request.exception'; -import { ListResponse } from '../common/interfaces'; -import { mockWorkOsResponse } from '../common/utils/workos-mock-response'; -import { WorkOS } from '../workos'; import { - AuditLogExport, - AuditLogExportOptions, - AuditLogExportResponse, - AuditLogSchema, - AuditLogSchemaResponse, - CreateAuditLogEventOptions, - CreateAuditLogSchemaOptions, - CreateAuditLogSchemaResponse, -} from './interfaces'; -import { - serializeAuditLogExportOptions, - serializeCreateAuditLogEventOptions, - serializeCreateAuditLogSchemaOptions, -} from './serializers'; + fetchOnce, + fetchURL, + fetchMethod, + fetchSearchParams, + fetchBody, +} from '../common/utils/test-utils'; +import { WorkOS } from '../workos'; -const event: CreateAuditLogEventOptions = { - action: 'document.updated', - occurredAt: new Date(), - actor: { - id: 'user_1', - name: 'Jon Smith', - type: 'user', - }, - targets: [ - { - id: 'document_39127', - type: 'document', - }, - ], - context: { - location: '192.0.0.8', - userAgent: 'Firefox', - }, - metadata: { - successful: true, - }, -}; +import auditLogsRetentionFixture from './fixtures/audit-logs-retention.json'; +import listAuditLogActionFixture from './fixtures/list-audit-log-action.json'; +import listAuditLogSchemaFixture from './fixtures/list-audit-log-schema.json'; +import auditLogSchemaFixture from './fixtures/audit-log-schema.json'; +import auditLogEventCreateResponseFixture from './fixtures/audit-log-event-create-response.json'; +import auditLogExportFixture from './fixtures/audit-log-export.json'; -const schema: CreateAuditLogSchemaOptions = { - action: 'user.logged_in', - actor: { - metadata: { - actor_id: 'string', - }, - }, - targets: [ +const workos = new WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU'); + +function expectAuditLogsRetention(result: any) { + expect(result.retentionPeriodInDays).toBe(30); +} + +function expectAuditLogSchema(result: any) { + expect(result.object).toBe('audit_log_schema'); + expect(result.version).toBe(1); + expect(result.targets).toEqual([ { - type: 'user', - metadata: { - user_id: 'string', - }, + type: 'invoice', + metadata: { type: 'object', properties: { cost: { type: 'number' } } }, }, - ], - metadata: { - foo: 'number', - baz: 'boolean', - }, -}; - -const schemaWithoutMetadata = { ...schema, metadata: undefined }; + ]); + expect(result.createdAt.toISOString()).toBe('2026-01-15T12:00:00.000Z'); +} + +function expectAuditLogExport(result: any) { + expect(result.object).toBe('audit_log_export'); + expect(result.id).toBe('audit_log_export_01GBZK5MP7TD1YCFQHFR22180V'); + expect(result.state).toBe('ready'); + expect(result.createdAt.toISOString()).toBe('2026-01-15T12:00:00.000Z'); + expect(result.updatedAt.toISOString()).toBe('2026-01-15T12:00:00.000Z'); +} describe('AuditLogs', () => { beforeEach(() => fetch.resetMocks()); - describe('createEvent', () => { - describe('with an idempotency key', () => { - it('includes an idempotency key with request', async () => { - const workosSpy = jest.spyOn(WorkOS.prototype, 'post'); - - workosSpy.mockResolvedValueOnce( - mockWorkOsResponse(201, { success: true }), - ); - - const workos = new WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU'); - - await expect( - workos.auditLogs.createEvent('org_123', event, { - idempotencyKey: 'the-idempotency-key', - }), - ).resolves.toBeUndefined(); - - expect(workosSpy).toHaveBeenCalledWith( - '/audit_logs/events', - { - event: serializeCreateAuditLogEventOptions(event), - organization_id: 'org_123', - }, - { idempotencyKey: 'the-idempotency-key' }, - ); - }); - }); - - describe('without an idempotency key', () => { - it('auto-generates an idempotency key with workos-node prefix', async () => { - const workosSpy = jest.spyOn(WorkOS.prototype, 'post'); - - workosSpy.mockResolvedValueOnce( - mockWorkOsResponse(201, { success: true }), - ); - - const workos = new WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU'); - - await expect( - workos.auditLogs.createEvent('org_123', event), - ).resolves.toBeUndefined(); - - // Verify that an idempotency key was auto-generated - expect(workosSpy).toHaveBeenCalledWith( - '/audit_logs/events', - { - event: serializeCreateAuditLogEventOptions(event), - organization_id: 'org_123', - }, - expect.objectContaining({ - idempotencyKey: expect.stringMatching(/^workos-node\S*/), - }), - ); - }); - - it('generates different idempotency keys for different requests', async () => { - const workosSpy = jest.spyOn(WorkOS.prototype, 'post'); - - workosSpy.mockResolvedValue(mockWorkOsResponse(201, { success: true })); - - const workos = new WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU'); - - await workos.auditLogs.createEvent('org_123', event); - await workos.auditLogs.createEvent('org_123', event); - - const firstCallKey = workosSpy.mock.calls[0][2]?.idempotencyKey; - const secondCallKey = workosSpy.mock.calls[1][2]?.idempotencyKey; + describe('getOrganizationAuditLogsRetention', () => { + it('returns the expected result', async () => { + fetchOnce(auditLogsRetentionFixture); - expect(firstCallKey).toBeDefined(); - expect(secondCallKey).toBeDefined(); - expect(firstCallKey).not.toBe(secondCallKey); + const result = await workos.auditLogs.getOrganizationAuditLogsRetention({ + id: 'test_id', }); - }); - - describe('when the api responds with a 200', () => { - it('returns void', async () => { - const workosSpy = jest.spyOn(WorkOS.prototype, 'post'); - - workosSpy.mockResolvedValueOnce( - mockWorkOsResponse(201, { success: true }), - ); - - const workos = new WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU'); - - await expect( - workos.auditLogs.createEvent('org_123', event), - ).resolves.toBeUndefined(); - - expect(workosSpy).toHaveBeenCalledWith( - '/audit_logs/events', - { - event: serializeCreateAuditLogEventOptions(event), - organization_id: 'org_123', - }, - expect.objectContaining({ - idempotencyKey: expect.stringMatching(/^workos-node\S*/), - }), - ); - }); - }); - - describe('when the api responds with a 401', () => { - it('throws an UnauthorizedException', async () => { - const workosSpy = jest.spyOn(WorkOS.prototype, 'post'); - - workosSpy.mockImplementationOnce(() => { - throw new UnauthorizedException('a-request-id'); - }); - - const workos = new WorkOS('invalid apikey'); - - await expect( - workos.auditLogs.createEvent('org_123', event), - ).rejects.toThrow(UnauthorizedException); - }); - }); - - describe('when the api responds with a 400', () => { - it('throws an BadRequestException', async () => { - const workosSpy = jest.spyOn(WorkOS.prototype, 'post'); - - const errors = [ - { - field: 'occurred_at', - code: 'occurred_at must be an ISO 8601 date string', - }, - ]; - workosSpy.mockImplementationOnce(() => { - throw new BadRequestException({ - code: '400', - errors, - message: - 'Audit Log could not be processed due to missing or incorrect data.', - requestID: 'a-request-id', - }); - }); - - const workos = new WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU'); - - await expect( - workos.auditLogs.createEvent('org_123', event), - ).rejects.toThrow(BadRequestException); - }); + expect(fetchMethod()).toBe('GET'); + expect(new URL(String(fetchURL())).pathname).toBe( + '/organizations/test_id/audit_logs_retention', + ); + expectAuditLogsRetention(result); }); + }); - describe('retry behavior', () => { - beforeEach(() => { - fetch.resetMocks(); - jest.clearAllMocks(); - jest.useFakeTimers(); - }); - - afterEach(() => { - jest.useRealTimers(); - }); - - it('retries on 500 status code and eventually succeeds', async () => { - fetch.mockResponses( - [JSON.stringify({ error: 'Internal Server Error' }), { status: 500 }], - [JSON.stringify({ error: 'Internal Server Error' }), { status: 500 }], - [JSON.stringify({ success: true }), { status: 201 }], - ); - - const workos = new WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU'); - - const promise = workos.auditLogs.createEvent('org_123', event); - await jest.runAllTimersAsync(); - await expect(promise).resolves.toBeUndefined(); - - expect(fetch).toHaveBeenCalledTimes(3); - }); - - it('retries on 502 status code and eventually succeeds', async () => { - fetch.mockResponses( - [JSON.stringify({ error: 'Bad Gateway' }), { status: 502 }], - [JSON.stringify({ error: 'Bad Gateway' }), { status: 502 }], - [JSON.stringify({ success: true }), { status: 201 }], - ); - - const workos = new WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU'); - - const promise = workos.auditLogs.createEvent('org_123', event); - await jest.runAllTimersAsync(); - await expect(promise).resolves.toBeUndefined(); - - expect(fetch).toHaveBeenCalledTimes(3); - }); - - it('retries on 504 status code and eventually succeeds', async () => { - fetch.mockResponses( - [JSON.stringify({ error: 'Gateway Timeout' }), { status: 504 }], - [JSON.stringify({ error: 'Gateway Timeout' }), { status: 504 }], - [JSON.stringify({ success: true }), { status: 201 }], - ); - - const workos = new WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU'); - - const promise = workos.auditLogs.createEvent('org_123', event); - await jest.runAllTimersAsync(); - await expect(promise).resolves.toBeUndefined(); - - expect(fetch).toHaveBeenCalledTimes(3); - }); - - it('retries on 408 status code and eventually succeeds', async () => { - fetch.mockResponses( - [JSON.stringify({ error: 'Request Timeout' }), { status: 408 }], - [JSON.stringify({ error: 'Request Timeout' }), { status: 408 }], - [JSON.stringify({ success: true }), { status: 201 }], - ); - - const workos = new WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU'); - - const promise = workos.auditLogs.createEvent('org_123', event); - await jest.runAllTimersAsync(); - await expect(promise).resolves.toBeUndefined(); - - expect(fetch).toHaveBeenCalledTimes(3); - }); - - it('succeeds on the last retry attempt (4th attempt)', async () => { - fetch.mockResponses( - [JSON.stringify({ error: 'Internal Server Error' }), { status: 500 }], - [JSON.stringify({ error: 'Internal Server Error' }), { status: 500 }], - [JSON.stringify({ error: 'Internal Server Error' }), { status: 500 }], - [JSON.stringify({ success: true }), { status: 201 }], - ); - - const workos = new WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU'); - - const promise = workos.auditLogs.createEvent('org_123', event); - await jest.runAllTimersAsync(); - await expect(promise).resolves.toBeUndefined(); - - expect(fetch).toHaveBeenCalledTimes(4); - }); - - it('retries a maximum of 3 times (4 total attempts)', async () => { - fetch.mockResponse(JSON.stringify({ error: 'Internal Server Error' }), { - status: 500, - }); - - const workos = new WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU'); - - const promise = workos.auditLogs - .createEvent('org_123', event) - .catch((e) => e); - await jest.runAllTimersAsync(); - const result = await promise; - - expect(result).toBeInstanceOf(Error); - - // 1 initial attempt + 3 retries = 4 total attempts - expect(fetch).toHaveBeenCalledTimes(4); - }); - - it('uses the same idempotency key across all retry attempts', async () => { - fetch.mockResponses( - [JSON.stringify({ error: 'Internal Server Error' }), { status: 500 }], - [JSON.stringify({ error: 'Internal Server Error' }), { status: 500 }], - [JSON.stringify({ success: true }), { status: 201 }], - ); - - const workos = new WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU'); - - const promise = workos.auditLogs.createEvent('org_123', event, { - idempotencyKey: 'test-idempotency-key', - }); - await jest.runAllTimersAsync(); - await promise; - - expect(fetch).toHaveBeenCalledTimes(3); - - // Verify all requests have the same idempotency key in headers - const calls = fetch.mock.calls; - for (const call of calls) { - const headers = call[1]?.headers as Record; - expect(headers['Idempotency-Key']).toBe('test-idempotency-key'); - } - }); - - it('maintains auto-generated idempotency key across retry attempts', async () => { - fetch.mockResponses( - [JSON.stringify({ error: 'Internal Server Error' }), { status: 500 }], - [JSON.stringify({ error: 'Internal Server Error' }), { status: 500 }], - [JSON.stringify({ success: true }), { status: 201 }], - ); - - const workos = new WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU'); - - const promise = workos.auditLogs.createEvent('org_123', event); - await jest.runAllTimersAsync(); - await promise; - - expect(fetch).toHaveBeenCalledTimes(3); - - // Verify all requests have the same auto-generated idempotency key - const calls = fetch.mock.calls; - const idempotencyKeys = calls.map( - (call) => - (call[1]?.headers as Record)['Idempotency-Key'], - ); + describe('updateOrganizationAuditLogsRetention', () => { + it('sends the correct request and returns result', async () => { + fetchOnce(auditLogsRetentionFixture); - // All keys should be defined - idempotencyKeys.forEach((key) => { - expect(key).toBeDefined(); - expect(key).toMatch(/\S/); - expect(key.startsWith('workos-node-')).toBe(true); + const result = + await workos.auditLogs.updateOrganizationAuditLogsRetention({ + id: 'test_id', + retentionPeriodInDays: 1, }); - // All keys should be the same - expect(idempotencyKeys[0]).toBe(idempotencyKeys[1]); - expect(idempotencyKeys[1]).toBe(idempotencyKeys[2]); - }); + expect(fetchMethod()).toBe('PUT'); + expect(new URL(String(fetchURL())).pathname).toBe( + '/organizations/test_id/audit_logs_retention', + ); + expect(fetchBody()).toEqual( + expect.objectContaining({ retention_period_in_days: 1 }), + ); + expectAuditLogsRetention(result); }); }); - describe('createExport', () => { - describe('when the api responds with a 201', () => { - it('returns `audit_log_export`', async () => { - const workosSpy = jest.spyOn(WorkOS.prototype, 'post'); - - const options: AuditLogExportOptions = { - organizationId: 'org_123', - rangeStart: new Date(), - rangeEnd: new Date(), - }; - - const timestamp: string = new Date().toISOString(); + describe('listActions', () => { + it('returns paginated results', async () => { + fetchOnce(listAuditLogActionFixture); - const auditLogExport: AuditLogExport = { - object: 'audit_log_export', - id: 'audit_log_export_1234', - state: 'pending', - url: undefined, - createdAt: timestamp, - updatedAt: timestamp, - }; - - const auditLogExportResponse: AuditLogExportResponse = { - object: 'audit_log_export', - id: 'audit_log_export_1234', - state: 'pending', - url: undefined, - created_at: timestamp, - updated_at: timestamp, - }; - - workosSpy.mockResolvedValueOnce( - mockWorkOsResponse(201, auditLogExportResponse), - ); - - const workos = new WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU'); - - await expect(workos.auditLogs.createExport(options)).resolves.toEqual( - auditLogExport, - ); - - expect(workosSpy).toHaveBeenCalledWith( - '/audit_logs/exports', - serializeAuditLogExportOptions(options), - ); + const { data, listMetadata } = await workos.auditLogs.listActions({ + order: 'desc', }); - }); - - describe('when additional filters are defined', () => { - it('returns `audit_log_export`', async () => { - const workosSpy = jest.spyOn(WorkOS.prototype, 'post'); - - const options: AuditLogExportOptions = { - actions: ['foo', 'bar'], - actorNames: ['Jon', 'Smith'], - actorIds: ['user_foo', 'user_bar'], - organizationId: 'org_123', - rangeEnd: new Date(), - rangeStart: new Date(), - targets: ['user', 'team'], - }; - const timestamp: string = new Date().toISOString(); - - const auditLogExport: AuditLogExport = { - object: 'audit_log_export', - id: 'audit_log_export_1234', - state: 'pending', - url: undefined, - createdAt: timestamp, - updatedAt: timestamp, - }; - - const auditLogExportResponse: AuditLogExportResponse = { - object: 'audit_log_export', - id: 'audit_log_export_1234', - state: 'pending', - url: undefined, - created_at: timestamp, - updated_at: timestamp, - }; - - workosSpy.mockResolvedValueOnce( - mockWorkOsResponse(201, auditLogExportResponse), - ); - - const workos = new WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU'); - - await expect(workos.auditLogs.createExport(options)).resolves.toEqual( - auditLogExport, - ); - - expect(workosSpy).toHaveBeenCalledWith( - '/audit_logs/exports', - serializeAuditLogExportOptions(options), - ); - }); - }); - - describe('when the api responds with a 401', () => { - it('throws an UnauthorizedException', async () => { - const workosSpy = jest.spyOn(WorkOS.prototype, 'post'); - - const options: AuditLogExportOptions = { - organizationId: 'org_123', - rangeStart: new Date(), - rangeEnd: new Date(), - }; - - workosSpy.mockImplementationOnce(() => { - throw new UnauthorizedException('a-request-id'); - }); - - const workos = new WorkOS('invalid apikey'); - - await expect(workos.auditLogs.createExport(options)).rejects.toThrow( - UnauthorizedException, - ); - }); + expect(fetchMethod()).toBe('GET'); + expect(new URL(String(fetchURL())).pathname).toBe('/audit_logs/actions'); + expect(fetchSearchParams()).toHaveProperty('order'); + expect(Array.isArray(data)).toBe(true); + expect(listMetadata).toBeDefined(); + expect(data.length).toBeGreaterThan(0); + expect(data[0].object).toBe('audit_log_action'); + expect(data[0].name).toBe('user.viewed_invoice'); + expect(data[0].createdAt.toISOString()).toBe('2026-01-15T12:00:00.000Z'); + expect(data[0].updatedAt.toISOString()).toBe('2026-01-15T12:00:00.000Z'); }); }); - describe('getExport', () => { - describe('when the api responds with a 201', () => { - it('returns `audit_log_export`', async () => { - const workosSpy = jest.spyOn(WorkOS.prototype, 'get'); - - const timestamp: string = new Date().toISOString(); - - const auditLogExport: AuditLogExport = { - object: 'audit_log_export', - id: 'audit_log_export_1234', - state: 'pending', - url: undefined, - createdAt: timestamp, - updatedAt: timestamp, - }; - - const auditLogExportResponse: AuditLogExportResponse = { - object: 'audit_log_export', - id: 'audit_log_export_1234', - state: 'pending', - url: undefined, - created_at: timestamp, - updated_at: timestamp, - }; - - workosSpy.mockResolvedValueOnce( - mockWorkOsResponse(201, auditLogExportResponse), - ); - - const workos = new WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU'); - - await expect( - workos.auditLogs.getExport(auditLogExport.id), - ).resolves.toEqual(auditLogExport); + describe('listActionSchemas', () => { + it('returns paginated results', async () => { + fetchOnce(listAuditLogSchemaFixture); - expect(workosSpy).toHaveBeenCalledWith( - `/audit_logs/exports/${auditLogExport.id}`, - ); + const { data, listMetadata } = await workos.auditLogs.listActionSchemas({ + actionName: 'test_actionName', + order: 'desc', }); - }); - - describe('when the api responds with a 401', () => { - it('throws an UnauthorizedException', async () => { - const workosSpy = jest.spyOn(WorkOS.prototype, 'get'); - - workosSpy.mockImplementationOnce(() => { - throw new UnauthorizedException('a-request-id'); - }); - const workos = new WorkOS('invalid apikey'); - - await expect( - workos.auditLogs.getExport('audit_log_export_1234'), - ).rejects.toThrow(UnauthorizedException); - - expect(workosSpy).toHaveBeenCalledWith( - `/audit_logs/exports/audit_log_export_1234`, - ); - }); + expect(fetchMethod()).toBe('GET'); + expect(new URL(String(fetchURL())).pathname).toBe( + '/audit_logs/actions/test_actionName/schemas', + ); + expect(fetchSearchParams()).toHaveProperty('order'); + expect(Array.isArray(data)).toBe(true); + expect(listMetadata).toBeDefined(); + expect(data.length).toBeGreaterThan(0); + expectAuditLogSchema(data[0]); }); }); describe('createSchema', () => { - describe('with an idempotency key', () => { - it('includes an idempotency key with request', async () => { - const workosSpy = jest.spyOn(WorkOS.prototype, 'post'); - - const time = new Date().toISOString(); - - const createSchemaResult: AuditLogSchema = { - object: 'audit_log_schema', - version: 1, - targets: [ - { - type: 'user', - metadata: { - user_id: 'string', - }, - }, - ], - actor: { - metadata: { - actor_id: 'string', - }, - }, - metadata: { - foo: 'number', - baz: 'boolean', - }, - createdAt: time, - }; - - const createSchemaResponse: CreateAuditLogSchemaResponse = { - object: 'audit_log_schema', - version: 1, - targets: [ - { - type: 'user', - metadata: { - type: 'object', - properties: { - user_id: { - type: 'string', - }, - }, - }, - }, - ], - actor: { - metadata: { - type: 'object', - properties: { - actor_id: { - type: 'string', - }, - }, - }, - }, - metadata: { - type: 'object', - properties: { - foo: { - type: 'number', - }, - baz: { - type: 'boolean', - }, - }, - }, - created_at: time, - }; - - workosSpy.mockResolvedValueOnce( - mockWorkOsResponse(201, createSchemaResponse), - ); + it('sends the correct request and returns result', async () => { + fetchOnce(auditLogSchemaFixture); - const workos = new WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU'); - - await expect( - workos.auditLogs.createSchema(schema, { - idempotencyKey: 'the-idempotency-key', - }), - ).resolves.toEqual(createSchemaResult); - - expect(workosSpy).toHaveBeenCalledWith( - '/audit_logs/actions/user.logged_in/schemas', - serializeCreateAuditLogSchemaOptions(schema), - { idempotencyKey: 'the-idempotency-key' }, - ); + const result = await workos.auditLogs.createSchema({ + actionName: 'test_actionName', + targets: [{ type: 'test_type' }], }); - }); - - describe('without metadata', () => { - it('does not include metadata with the request', async () => { - const workosSpy = jest.spyOn(WorkOS.prototype, 'post'); - - const time = new Date().toISOString(); - - const createSchemaResult: AuditLogSchema = { - object: 'audit_log_schema', - version: 1, - targets: [ - { - type: 'user', - metadata: { - user_id: 'string', - }, - }, - ], - actor: { - metadata: { - actor_id: 'string', - }, - }, - metadata: undefined, - createdAt: time, - }; - - const createSchemaResponse: CreateAuditLogSchemaResponse = { - object: 'audit_log_schema', - version: 1, - targets: [ - { - type: 'user', - metadata: { - type: 'object', - properties: { - user_id: { - type: 'string', - }, - }, - }, - }, - ], - actor: { - metadata: { - type: 'object', - properties: { - actor_id: { - type: 'string', - }, - }, - }, - }, - created_at: time, - }; - - workosSpy.mockResolvedValueOnce( - mockWorkOsResponse(201, createSchemaResponse), - ); - - const workos = new WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU'); - - await expect( - workos.auditLogs.createSchema(schemaWithoutMetadata), - ).resolves.toEqual(createSchemaResult); - - expect(workosSpy).toHaveBeenCalledWith( - '/audit_logs/actions/user.logged_in/schemas', - serializeCreateAuditLogSchemaOptions(schemaWithoutMetadata), - {}, - ); - }); - }); - describe('when the api responds with a 201', () => { - it('returns `audit_log_schema`', async () => { - const workosSpy = jest.spyOn(WorkOS.prototype, 'post'); - - const time = new Date().toISOString(); - - const createSchemaResult: AuditLogSchema = { - object: 'audit_log_schema', - version: 1, - targets: [ - { - type: 'user', - metadata: { - user_id: 'string', - }, - }, - ], - actor: { - metadata: { - actor_id: 'string', - }, - }, - metadata: { - foo: 'number', - baz: 'boolean', - }, - createdAt: time, - }; - - const createSchemaResponse: CreateAuditLogSchemaResponse = { - object: 'audit_log_schema', - version: 1, - targets: [ - { - type: 'user', - metadata: { - type: 'object', - properties: { - user_id: { - type: 'string', - }, - }, - }, - }, - ], - actor: { - metadata: { - type: 'object', - properties: { - actor_id: { - type: 'string', - }, - }, - }, - }, - metadata: { - type: 'object', - properties: { - foo: { - type: 'number', - }, - baz: { - type: 'boolean', - }, - }, - }, - created_at: time, - }; - - workosSpy.mockResolvedValueOnce( - mockWorkOsResponse(201, createSchemaResponse), - ); - - const workos = new WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU'); - - await expect( - workos.auditLogs.createSchema(schema, { - idempotencyKey: 'the-idempotency-key', - }), - ).resolves.toEqual(createSchemaResult); - }); - }); - - describe('when the api responds with a 400', () => { - it('throws a BadRequestException', async () => { - const workosSpy = jest.spyOn(WorkOS.prototype, 'post'); - - const errors = [ - { - field: 'actor.metadata', - code: 'actor.metadata must be an object', - }, - ]; - - workosSpy.mockImplementationOnce(() => { - throw new BadRequestException({ - code: '400', - errors, - message: - 'Audit Log Schema could not be processed due to missing or incorrect data.', - requestID: 'a-request-id', - }); - }); - - const workos = new WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU'); - - await expect(workos.auditLogs.createSchema(schema)).rejects.toThrow( - BadRequestException, - ); - }); + expect(fetchMethod()).toBe('POST'); + expect(new URL(String(fetchURL())).pathname).toBe( + '/audit_logs/actions/test_actionName/schemas', + ); + expect(fetchBody()).toEqual( + expect.objectContaining({ targets: [{ type: 'test_type' }] }), + ); + expectAuditLogSchema(result); }); }); - describe('listSchemas', () => { - describe('when the api responds with a 200', () => { - it('returns a paginated list of schemas', async () => { - const workosSpy = jest.spyOn(WorkOS.prototype, 'get'); - - const time = new Date().toISOString(); - - const schemaResponse: AuditLogSchemaResponse = { - object: 'audit_log_schema', - version: 1, - targets: [ - { - type: 'user', - metadata: { - type: 'object', - properties: { - user_id: { type: 'string' }, - }, - }, - }, - ], - actor: { - metadata: { - type: 'object', - properties: { - actor_id: { type: 'string' }, - }, - }, - }, - metadata: { - type: 'object', - properties: { - foo: { type: 'number' }, - }, - }, - created_at: time, - }; - - const listResponse: ListResponse = { - object: 'list', - data: [schemaResponse], - list_metadata: { - before: undefined, - after: undefined, - }, - }; - - workosSpy.mockResolvedValueOnce(mockWorkOsResponse(200, listResponse)); - - const workos = new WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU'); - - const result = await workos.auditLogs.listSchemas('user.logged_in'); - - expect(result.data).toHaveLength(1); - // Metadata is deserialized to simplified format (same as createSchema) - expect(result.data[0]).toEqual({ - object: 'audit_log_schema', - version: 1, - targets: [ - { - type: 'user', - metadata: { user_id: 'string' }, - }, - ], - actor: { - metadata: { actor_id: 'string' }, - }, - metadata: { foo: 'number' }, - createdAt: time, - }); - - expect(workosSpy).toHaveBeenCalledWith( - '/audit_logs/actions/user.logged_in/schemas', - { query: { order: 'desc' } }, - ); - }); - }); - - describe('with pagination options', () => { - it('passes pagination parameters to the API', async () => { - const workosSpy = jest.spyOn(WorkOS.prototype, 'get'); - - const listResponse: ListResponse = { - object: 'list', - data: [], - list_metadata: { - before: undefined, - after: undefined, - }, - }; - - workosSpy.mockResolvedValueOnce(mockWorkOsResponse(200, listResponse)); - - const workos = new WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU'); - - await workos.auditLogs.listSchemas('user.logged_in', { - limit: 10, - after: 'cursor_123', - order: 'asc', - }); - - expect(workosSpy).toHaveBeenCalledWith( - '/audit_logs/actions/user.logged_in/schemas', - { query: { limit: 10, after: 'cursor_123', order: 'asc' } }, - ); - }); + describe('createEvent', () => { + it('sends the correct request and returns result', async () => { + fetchOnce(auditLogEventCreateResponseFixture); + + const result = await workos.auditLogs.createEvent({ + organizationId: 'organization_id_01234', + event: { + action: 'test_action', + occurredAt: new Date('2023-01-01T00:00:00.000Z'), + actor: { id: '01234', type: 'test_type' }, + targets: [{ id: '01234', type: 'test_type' }], + context: { location: 'test_location' }, + }, + }); + + expect(fetchMethod()).toBe('POST'); + expect(new URL(String(fetchURL())).pathname).toBe('/audit_logs/events'); + expect(fetchBody()).toEqual( + expect.objectContaining({ + organization_id: 'organization_id_01234', + event: { + action: 'test_action', + occurred_at: '2023-01-01T00:00:00.000Z', + actor: { id: '01234', type: 'test_type' }, + targets: [{ id: '01234', type: 'test_type' }], + context: { location: 'test_location' }, + }, + }), + ); + expect(result.success).toBe(true); }); + }); - describe('when the api responds with a 401', () => { - it('throws an UnauthorizedException', async () => { - const workosSpy = jest.spyOn(WorkOS.prototype, 'get'); - - workosSpy.mockImplementationOnce(() => { - throw new UnauthorizedException('a-request-id'); - }); - - const workos = new WorkOS('invalid apikey'); - - await expect( - workos.auditLogs.listSchemas('user.logged_in'), - ).rejects.toThrow(UnauthorizedException); - }); + describe('createExport', () => { + it('sends the correct request and returns result', async () => { + fetchOnce(auditLogExportFixture); + + const result = await workos.auditLogs.createExport({ + organizationId: 'organization_id_01234', + rangeStart: 'test_range_start', + rangeEnd: 'test_range_end', + }); + + expect(fetchMethod()).toBe('POST'); + expect(new URL(String(fetchURL())).pathname).toBe('/audit_logs/exports'); + expect(fetchBody()).toEqual( + expect.objectContaining({ + organization_id: 'organization_id_01234', + range_start: 'test_range_start', + range_end: 'test_range_end', + }), + ); + expectAuditLogExport(result); }); + }); - describe('with schema without optional fields', () => { - it('returns schema with undefined actor and metadata', async () => { - const workosSpy = jest.spyOn(WorkOS.prototype, 'get'); - - const time = new Date().toISOString(); - - const schemaResponse: AuditLogSchemaResponse = { - object: 'audit_log_schema', - version: 1, - targets: [ - { - type: 'document', - }, - ], - created_at: time, - }; - - const listResponse: ListResponse = { - object: 'list', - data: [schemaResponse], - list_metadata: { - before: undefined, - after: undefined, - }, - }; - - workosSpy.mockResolvedValueOnce(mockWorkOsResponse(200, listResponse)); - - const workos = new WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU'); - - const result = await workos.auditLogs.listSchemas('document.created'); + describe('getExport', () => { + it('returns the expected result', async () => { + fetchOnce(auditLogExportFixture); - expect(result.data).toHaveLength(1); - expect(result.data[0]).toEqual({ - object: 'audit_log_schema', - version: 1, - targets: [ - { - type: 'document', - metadata: undefined, - }, - ], - actor: undefined, - metadata: undefined, - createdAt: time, - }); + const result = await workos.auditLogs.getExport({ + auditLogExportId: 'test_auditLogExportId', }); - }); - - describe('with multiple schemas', () => { - it('returns all schemas in the response', async () => { - const workosSpy = jest.spyOn(WorkOS.prototype, 'get'); - - const time1 = new Date().toISOString(); - const time2 = new Date(Date.now() - 1000).toISOString(); - - const schemaResponse1: AuditLogSchemaResponse = { - object: 'audit_log_schema', - version: 2, - targets: [{ type: 'user' }], - created_at: time1, - }; - - const schemaResponse2: AuditLogSchemaResponse = { - object: 'audit_log_schema', - version: 1, - targets: [{ type: 'user' }], - metadata: { - type: 'object', - properties: { - ip_address: { type: 'string' }, - }, - }, - created_at: time2, - }; - - const listResponse: ListResponse = { - object: 'list', - data: [schemaResponse1, schemaResponse2], - list_metadata: { - before: 'cursor_before', - after: 'cursor_after', - }, - }; - - workosSpy.mockResolvedValueOnce(mockWorkOsResponse(200, listResponse)); - const workos = new WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU'); - - const result = await workos.auditLogs.listSchemas('user.logged_in'); - - expect(result.data).toHaveLength(2); - expect(result.data[0].version).toBe(2); - expect(result.data[1].version).toBe(1); - // Metadata is deserialized to simplified format - expect(result.data[1].metadata).toEqual({ ip_address: 'string' }); - expect(result.listMetadata.before).toBe('cursor_before'); - expect(result.listMetadata.after).toBe('cursor_after'); - }); + expect(fetchMethod()).toBe('GET'); + expect(new URL(String(fetchURL())).pathname).toBe( + '/audit_logs/exports/test_auditLogExportId', + ); + expectAuditLogExport(result); }); }); }); diff --git a/src/audit-logs/audit-logs.ts b/src/audit-logs/audit-logs.ts index b4aa4724b..af4254546 100644 --- a/src/audit-logs/audit-logs.ts +++ b/src/audit-logs/audit-logs.ts @@ -1,36 +1,189 @@ -import { PaginationOptions } from '../common/interfaces'; -import { fetchAndDeserialize } from '../common/utils/fetch-and-deserialize'; +// This file is auto-generated by oagen. Do not edit. + +import type { WorkOS } from '../workos'; import { AutoPaginatable } from '../common/utils/pagination'; -import { WorkOS } from '../workos'; -import { - CreateAuditLogEventOptions, - CreateAuditLogEventRequestOptions, -} from './interfaces'; -import { AuditLogExportOptions } from './interfaces/audit-log-export-options.interface'; -import { - AuditLogExport, - AuditLogExportResponse, -} from './interfaces/audit-log-export.interface'; -import { +import { fetchAndDeserialize } from '../common/utils/fetch-and-deserialize'; +import type { GetOrganizationAuditLogsRetentionOptions } from './interfaces/get-organization-audit-logs-retention-options.interface'; +import type { UpdateOrganizationAuditLogsRetentionOptions } from './interfaces/update-organization-audit-logs-retention-options.interface'; +import type { ListActionsOptions } from './interfaces/list-actions-options.interface'; +import type { ListActionSchemasOptions } from './interfaces/list-action-schemas-options.interface'; +import type { CreateSchemaOptions } from './interfaces/create-schema-options.interface'; +import type { CreateEventOptions } from './interfaces/create-event-options.interface'; +import type { AuditLogExportOptions } from './interfaces/audit-log-export-options.interface'; +import type { GetExportOptions } from './interfaces/get-export-options.interface'; +import type { + AuditLogsRetention, + AuditLogsRetentionResponse, +} from './interfaces/audit-logs-retention.interface'; +import type { + AuditLogAction, + AuditLogActionResponse, +} from './interfaces/audit-log-action.interface'; +import type { AuditLogSchema, AuditLogSchemaResponse, } from './interfaces/audit-log-schema.interface'; -import { - CreateAuditLogSchemaResponse, - CreateAuditLogSchemaRequestOptions, - CreateAuditLogSchemaOptions, -} from './interfaces/create-audit-log-schema-options.interface'; -import { - deserializeAuditLogExport, - deserializeAuditLogSchema, - serializeAuditLogExportOptions, - serializeCreateAuditLogEventOptions, - serializeCreateAuditLogSchemaOptions, -} from './serializers'; +import type { + AuditLogEventCreateResponse, + AuditLogEventCreateResponseWire, +} from './interfaces/audit-log-event-create-response.interface'; +import type { + AuditLogExport, + AuditLogExportResponse, +} from './interfaces/audit-log-export.interface'; +import type { UpdateAuditLogsRetentionResponse } from './interfaces/update-audit-logs-retention.interface'; +import type { AuditLogSchemaInputResponse } from './interfaces/audit-log-schema-input.interface'; +import type { AuditLogEventIngestionResponse } from './interfaces/audit-log-event-ingestion.interface'; +import type { AuditLogExportCreationResponse } from './interfaces/audit-log-export-creation.interface'; +import { deserializeAuditLogsRetention } from './serializers/audit-logs-retention.serializer'; +import { deserializeAuditLogAction } from './serializers/audit-log-action.serializer'; +import { deserializeAuditLogSchema } from './serializers/audit-log-schema.serializer'; +import { deserializeAuditLogEventCreateResponse } from './serializers/audit-log-event-create-response.serializer'; +import { deserializeAuditLogExport } from './serializers/audit-log-export.serializer'; +import { serializeUpdateAuditLogsRetention } from './serializers/update-audit-logs-retention.serializer'; +import { serializeAuditLogSchemaInput } from './serializers/audit-log-schema-input.serializer'; +import { serializeAuditLogEventIngestion } from './serializers/audit-log-event-ingestion.serializer'; +import { serializeAuditLogExportCreation } from './serializers/audit-log-export-creation.serializer'; export class AuditLogs { constructor(private readonly workos: WorkOS) {} + /** + * Get Retention + * + * Get the configured event retention period for the given Organization. + * @param options - The request options. + * @param options.id - Unique identifier of the Organization. + * @example "org_01EHZNVPK3SFK441A1RGBFSHRT" + * @returns {Promise} + * @throws {NotFoundException} 404 + */ + async getOrganizationAuditLogsRetention( + options: GetOrganizationAuditLogsRetentionOptions, + ): Promise { + const { id } = options; + const { data } = await this.workos.get( + `/organizations/${encodeURIComponent(id)}/audit_logs_retention`, + ); + return deserializeAuditLogsRetention(data); + } + + /** + * Set Retention + * + * Set the event retention period for the given Organization. + * @param options - The request options. + * @param options.id - Unique identifier of the Organization. + * @example "org_01EHZNVPK3SFK441A1RGBFSHRT" + * @returns {Promise} + * @throws {NotFoundException} 404 + * @throws {UnprocessableEntityException} 422 + */ + async updateOrganizationAuditLogsRetention( + options: UpdateOrganizationAuditLogsRetentionOptions, + ): Promise { + const { id, ...payload } = options; + const { data } = await this.workos.put< + AuditLogsRetentionResponse, + UpdateAuditLogsRetentionResponse + >( + `/organizations/${encodeURIComponent(id)}/audit_logs_retention`, + serializeUpdateAuditLogsRetention(payload), + ); + return deserializeAuditLogsRetention(data); + } + + /** + * List Actions + * + * Get a list of all Audit Log actions in the current environment. + * @param options - Pagination and filter options. + * @returns {Promise>} + * @throws {NotFoundException} 404 + * @throws {UnprocessableEntityException} 422 + */ + async listActions( + options?: ListActionsOptions, + ): Promise> { + const paginationOptions = options; + return new AutoPaginatable( + await fetchAndDeserialize( + this.workos, + '/audit_logs/actions', + deserializeAuditLogAction, + paginationOptions, + ), + (params) => + fetchAndDeserialize( + this.workos, + '/audit_logs/actions', + deserializeAuditLogAction, + params, + ), + paginationOptions, + ); + } + + /** + * List Schemas + * + * Get a list of all schemas for the Audit Logs action identified by `:name`. + * @param options - Pagination and filter options. + * @param options.actionName - The name of the Audit Log action. + * @example "user.logged_in" + * @returns {Promise>} + * @throws {NotFoundException} 404 + * @throws {UnprocessableEntityException} 422 + */ + async listActionSchemas( + options: ListActionSchemasOptions, + ): Promise< + AutoPaginatable< + AuditLogSchema, + Omit + > + > { + const { actionName, ...paginationOptions } = options; + return new AutoPaginatable( + await fetchAndDeserialize( + this.workos, + `/audit_logs/actions/${encodeURIComponent(actionName)}/schemas`, + deserializeAuditLogSchema, + paginationOptions, + ), + (params) => + fetchAndDeserialize( + this.workos, + `/audit_logs/actions/${encodeURIComponent(actionName)}/schemas`, + deserializeAuditLogSchema, + params, + ), + paginationOptions, + ); + } + + /** + * Create Schema + * + * Creates a new Audit Log schema used to validate the payload of incoming Audit Log Events. If the `action` does not exist, it will also be created. + * @param options - The request options. + * @param options.actionName - The name of the Audit Log action. + * @example "user.logged_in" + * @returns {Promise} + * @throws {UnprocessableEntityException} 422 + */ + async createSchema(options: CreateSchemaOptions): Promise { + const { actionName, ...payload } = options; + const { data } = await this.workos.post< + AuditLogSchemaResponse, + AuditLogSchemaInputResponse + >( + `/audit_logs/actions/${encodeURIComponent(actionName)}/schemas`, + serializeAuditLogSchemaInput(payload), + ); + return deserializeAuditLogSchema(data); + } + /** * Create Event * @@ -41,50 +194,55 @@ export class AuditLogs { * To achieve idempotency, you can add `Idempotency-Key` request header to a Create Event request with a unique string as the value. Each subsequent request matching this unique string will return the same response. We suggest using [v4 UUIDs](https://en.wikipedia.org/wiki/Universally_unique_identifier) for idempotency keys to avoid collisions. * * Idempotency keys expire after 24 hours. The API will generate a new response if you submit a request with an expired key. - * @param payload - Object containing organizationId, event. - * @returns {Promise} + * @param event - The audit log event to create. + * @param options - The request options. + * @returns {Promise} * @throws {BadRequestException} 400 * @throws {NotFoundException} 404 * @throws {UnprocessableEntityException} 422 * @throws {RateLimitExceededException} 429 */ async createEvent( - organization: string, - event: CreateAuditLogEventOptions, - options: CreateAuditLogEventRequestOptions = {}, - ): Promise { - // Auto-generate idempotency key if not provided - const optionsWithIdempotency: CreateAuditLogEventRequestOptions = { - ...options, - idempotencyKey: - options.idempotencyKey || - `workos-node-${globalThis.crypto.randomUUID()}`, - }; - - await this.workos.post( - '/audit_logs/events', - { - event: serializeCreateAuditLogEventOptions(event), - organization_id: organization, - }, - optionsWithIdempotency, - ); + options: CreateEventOptions, + ): Promise { + const payload = options; + const { data } = await this.workos.post< + AuditLogEventCreateResponseWire, + AuditLogEventIngestionResponse + >('/audit_logs/events', serializeAuditLogEventIngestion(payload)); + return deserializeAuditLogEventCreateResponse(data); } /** * Create Export * * Create an Audit Log Export. Exports are scoped to a single organization within a specified date range. - * @param payload - Object containing organizationId, rangeStart, rangeEnd. + * @param options - Object containing organizationId, rangeStart, rangeEnd. + * @param options.organizationId - The unique ID of the Organization. + * @example "org_01EHZNVPK3SFK441A1RGBFSHRT" + * @param options.rangeStart - ISO-8601 value for start of the export range. + * @example "2022-07-02T18:09:06.996Z" + * @param options.rangeEnd - ISO-8601 value for end of the export range. + * @example "2022-09-02T18:09:06.996Z" + * @param options.actions - List of actions to filter against. + * @example ["user.signed_in"] + * @param options.actors - (deprecated) Deprecated. Use `actor_names` instead. + * @example ["Jon Smith"] + * @param options.actorNames - List of actor names to filter against. + * @example ["Jon Smith"] + * @param options.actorIds - List of actor IDs to filter against. + * @example ["user_01GBZK5MP7TD1YCFQHFR22180V"] + * @param options.targets - List of target types to filter against. + * @example ["team"] * @returns {Promise} * @throws {BadRequestException} 400 */ async createExport(options: AuditLogExportOptions): Promise { - const { data } = await this.workos.post( - '/audit_logs/exports', - serializeAuditLogExportOptions(options), - ); - + const payload = options; + const { data } = await this.workos.post< + AuditLogExportResponse, + AuditLogExportCreationResponse + >('/audit_logs/exports', serializeAuditLogExportCreation(payload)); return deserializeAuditLogExport(data); } @@ -92,64 +250,17 @@ export class AuditLogs { * Get Export * * Get an Audit Log Export. The URL will expire after 10 minutes. If the export is needed again at a later time, refetching the export will regenerate the URL. - * @param auditLogExportId - The unique ID of the Audit Log Export. - * - * @example - * "audit_log_export_01GBZK5MP7TD1YCFQHFR22180V" - * + * @param options - The request options. + * @param options.auditLogExportId - The unique ID of the Audit Log Export. + * @example "audit_log_export_01GBZK5MP7TD1YCFQHFR22180V" * @returns {Promise} * @throws {NotFoundException} 404 */ - async getExport(auditLogExportId: string): Promise { + async getExport(options: GetExportOptions): Promise { + const { auditLogExportId } = options; const { data } = await this.workos.get( - `/audit_logs/exports/${auditLogExportId}`, + `/audit_logs/exports/${encodeURIComponent(auditLogExportId)}`, ); - return deserializeAuditLogExport(data); } - - /** - * Create Schema - * - * Creates a new Audit Log schema used to validate the payload of incoming Audit Log Events. If the `action` does not exist, it will also be created. - * @param payload - Object containing targets. - * @returns {Promise} - * @throws {UnprocessableEntityException} 422 - */ - async createSchema( - schema: CreateAuditLogSchemaOptions, - options: CreateAuditLogSchemaRequestOptions = {}, - ): Promise { - const { data } = await this.workos.post( - `/audit_logs/actions/${schema.action}/schemas`, - serializeCreateAuditLogSchemaOptions(schema), - options, - ); - - return deserializeAuditLogSchema(data); - } - - async listSchemas( - action: string, - options?: PaginationOptions, - ): Promise> { - const endpoint = `/audit_logs/actions/${action}/schemas`; - - return new AutoPaginatable( - await fetchAndDeserialize( - this.workos, - endpoint, - deserializeAuditLogSchema, - options, - ), - (params: PaginationOptions) => - fetchAndDeserialize( - this.workos, - endpoint, - deserializeAuditLogSchema, - params, - ), - options, - ); - } } diff --git a/src/audit-logs/fixtures/audit-log-action.json b/src/audit-logs/fixtures/audit-log-action.json new file mode 100644 index 000000000..a7212b6c5 --- /dev/null +++ b/src/audit-logs/fixtures/audit-log-action.json @@ -0,0 +1,42 @@ +{ + "object": "audit_log_action", + "name": "user.viewed_invoice", + "schema": { + "object": "audit_log_schema", + "version": 1, + "actor": { + "metadata": { + "type": "object", + "properties": { + "role": { + "type": "string" + } + } + } + }, + "targets": [ + { + "type": "invoice", + "metadata": { + "type": "object", + "properties": { + "cost": { + "type": "number" + } + } + } + } + ], + "metadata": { + "type": "object", + "properties": { + "transactionId": { + "type": "string" + } + } + }, + "created_at": "2026-01-15T12:00:00.000Z" + }, + "created_at": "2026-01-15T12:00:00.000Z", + "updated_at": "2026-01-15T12:00:00.000Z" +} diff --git a/src/audit-logs/fixtures/audit-log-event-actor.json b/src/audit-logs/fixtures/audit-log-event-actor.json new file mode 100644 index 000000000..68894d0d9 --- /dev/null +++ b/src/audit-logs/fixtures/audit-log-event-actor.json @@ -0,0 +1,8 @@ +{ + "id": "user_TF4C5938", + "type": "user", + "name": "Jon Smith", + "metadata": { + "owner": "user_01GBTCQ2" + } +} diff --git a/src/audit-logs/fixtures/audit-log-event-context.json b/src/audit-logs/fixtures/audit-log-event-context.json new file mode 100644 index 000000000..4b61b9176 --- /dev/null +++ b/src/audit-logs/fixtures/audit-log-event-context.json @@ -0,0 +1,4 @@ +{ + "location": "123.123.123.123", + "user_agent": "Chrome/104.0.0.0" +} diff --git a/src/audit-logs/fixtures/audit-log-event-create-response.json b/src/audit-logs/fixtures/audit-log-event-create-response.json new file mode 100644 index 000000000..5550c6db4 --- /dev/null +++ b/src/audit-logs/fixtures/audit-log-event-create-response.json @@ -0,0 +1,3 @@ +{ + "success": true +} diff --git a/src/audit-logs/fixtures/audit-log-event-ingestion.json b/src/audit-logs/fixtures/audit-log-event-ingestion.json new file mode 100644 index 000000000..09c9f4909 --- /dev/null +++ b/src/audit-logs/fixtures/audit-log-event-ingestion.json @@ -0,0 +1,33 @@ +{ + "organization_id": "org_01EHWNCE74X7JSDV0X3SZ3KJNY", + "event": { + "action": "user.signed_in", + "occurred_at": "2026-02-02T16:35:39.317Z", + "actor": { + "id": "user_TF4C5938", + "type": "user", + "name": "Jon Smith", + "metadata": { + "owner": "user_01GBTCQ2" + } + }, + "targets": [ + { + "id": "user_TF4C5938", + "type": "user", + "name": "Jon Smith", + "metadata": { + "owner": "user_01GBTCQ2" + } + } + ], + "context": { + "location": "123.123.123.123", + "user_agent": "Chrome/104.0.0.0" + }, + "metadata": { + "owner": "user_01GBTCQ2" + }, + "version": 1 + } +} diff --git a/src/audit-logs/fixtures/audit-log-event-target.json b/src/audit-logs/fixtures/audit-log-event-target.json new file mode 100644 index 000000000..68894d0d9 --- /dev/null +++ b/src/audit-logs/fixtures/audit-log-event-target.json @@ -0,0 +1,8 @@ +{ + "id": "user_TF4C5938", + "type": "user", + "name": "Jon Smith", + "metadata": { + "owner": "user_01GBTCQ2" + } +} diff --git a/src/audit-logs/fixtures/audit-log-event.json b/src/audit-logs/fixtures/audit-log-event.json new file mode 100644 index 000000000..ab6e39e71 --- /dev/null +++ b/src/audit-logs/fixtures/audit-log-event.json @@ -0,0 +1,30 @@ +{ + "action": "user.signed_in", + "occurred_at": "2026-02-02T16:35:39.317Z", + "actor": { + "id": "user_TF4C5938", + "type": "user", + "name": "Jon Smith", + "metadata": { + "owner": "user_01GBTCQ2" + } + }, + "targets": [ + { + "id": "user_TF4C5938", + "type": "user", + "name": "Jon Smith", + "metadata": { + "owner": "user_01GBTCQ2" + } + } + ], + "context": { + "location": "123.123.123.123", + "user_agent": "Chrome/104.0.0.0" + }, + "metadata": { + "owner": "user_01GBTCQ2" + }, + "version": 1 +} diff --git a/src/audit-logs/fixtures/audit-log-export-creation.json b/src/audit-logs/fixtures/audit-log-export-creation.json new file mode 100644 index 000000000..81e70a608 --- /dev/null +++ b/src/audit-logs/fixtures/audit-log-export-creation.json @@ -0,0 +1,10 @@ +{ + "organization_id": "org_01EHZNVPK3SFK441A1RGBFSHRT", + "range_start": "2022-07-02T18:09:06.996Z", + "range_end": "2022-09-02T18:09:06.996Z", + "actions": ["user.signed_in"], + "actors": ["Jon Smith"], + "actor_names": ["Jon Smith"], + "actor_ids": ["user_01GBZK5MP7TD1YCFQHFR22180V"], + "targets": ["team"] +} diff --git a/src/audit-logs/fixtures/audit-log-export.json b/src/audit-logs/fixtures/audit-log-export.json new file mode 100644 index 000000000..e076643f7 --- /dev/null +++ b/src/audit-logs/fixtures/audit-log-export.json @@ -0,0 +1,8 @@ +{ + "object": "audit_log_export", + "id": "audit_log_export_01GBZK5MP7TD1YCFQHFR22180V", + "state": "ready", + "url": "https://exports.audit-logs.com/audit-log-exports/export.csv", + "created_at": "2026-01-15T12:00:00.000Z", + "updated_at": "2026-01-15T12:00:00.000Z" +} diff --git a/src/audit-logs/fixtures/audit-log-schema-actor-input.json b/src/audit-logs/fixtures/audit-log-schema-actor-input.json new file mode 100644 index 000000000..cea875990 --- /dev/null +++ b/src/audit-logs/fixtures/audit-log-schema-actor-input.json @@ -0,0 +1,10 @@ +{ + "metadata": { + "type": "object", + "properties": { + "role": { + "type": "string" + } + } + } +} diff --git a/src/audit-logs/fixtures/audit-log-schema-actor.json b/src/audit-logs/fixtures/audit-log-schema-actor.json new file mode 100644 index 000000000..319068e72 --- /dev/null +++ b/src/audit-logs/fixtures/audit-log-schema-actor.json @@ -0,0 +1,5 @@ +{ + "metadata": { + "key": {} + } +} diff --git a/src/audit-logs/fixtures/audit-log-schema-input.json b/src/audit-logs/fixtures/audit-log-schema-input.json new file mode 100644 index 000000000..773d6b724 --- /dev/null +++ b/src/audit-logs/fixtures/audit-log-schema-input.json @@ -0,0 +1,33 @@ +{ + "actor": { + "metadata": { + "type": "object", + "properties": { + "role": { + "type": "string" + } + } + } + }, + "targets": [ + { + "type": "invoice", + "metadata": { + "type": "object", + "properties": { + "cost": { + "type": "number" + } + } + } + } + ], + "metadata": { + "type": "object", + "properties": { + "transactionId": { + "type": "string" + } + } + } +} diff --git a/src/audit-logs/fixtures/audit-log-schema-target-input.json b/src/audit-logs/fixtures/audit-log-schema-target-input.json new file mode 100644 index 000000000..328b52566 --- /dev/null +++ b/src/audit-logs/fixtures/audit-log-schema-target-input.json @@ -0,0 +1,11 @@ +{ + "type": "invoice", + "metadata": { + "type": "object", + "properties": { + "cost": { + "type": "number" + } + } + } +} diff --git a/src/audit-logs/fixtures/audit-log-schema-target.json b/src/audit-logs/fixtures/audit-log-schema-target.json new file mode 100644 index 000000000..328b52566 --- /dev/null +++ b/src/audit-logs/fixtures/audit-log-schema-target.json @@ -0,0 +1,11 @@ +{ + "type": "invoice", + "metadata": { + "type": "object", + "properties": { + "cost": { + "type": "number" + } + } + } +} diff --git a/src/audit-logs/fixtures/audit-log-schema.json b/src/audit-logs/fixtures/audit-log-schema.json new file mode 100644 index 000000000..cdf6f0755 --- /dev/null +++ b/src/audit-logs/fixtures/audit-log-schema.json @@ -0,0 +1,36 @@ +{ + "object": "audit_log_schema", + "version": 1, + "actor": { + "metadata": { + "type": "object", + "properties": { + "role": { + "type": "string" + } + } + } + }, + "targets": [ + { + "type": "invoice", + "metadata": { + "type": "object", + "properties": { + "cost": { + "type": "number" + } + } + } + } + ], + "metadata": { + "type": "object", + "properties": { + "transactionId": { + "type": "string" + } + } + }, + "created_at": "2026-01-15T12:00:00.000Z" +} diff --git a/src/audit-logs/fixtures/audit-logs-retention.json b/src/audit-logs/fixtures/audit-logs-retention.json new file mode 100644 index 000000000..0720427e5 --- /dev/null +++ b/src/audit-logs/fixtures/audit-logs-retention.json @@ -0,0 +1,3 @@ +{ + "retention_period_in_days": 30 +} diff --git a/src/audit-logs/fixtures/list-audit-log-action.json b/src/audit-logs/fixtures/list-audit-log-action.json new file mode 100644 index 000000000..f36c55df6 --- /dev/null +++ b/src/audit-logs/fixtures/list-audit-log-action.json @@ -0,0 +1,50 @@ +{ + "data": [ + { + "object": "audit_log_action", + "name": "user.viewed_invoice", + "schema": { + "object": "audit_log_schema", + "version": 1, + "actor": { + "metadata": { + "type": "object", + "properties": { + "role": { + "type": "string" + } + } + } + }, + "targets": [ + { + "type": "invoice", + "metadata": { + "type": "object", + "properties": { + "cost": { + "type": "number" + } + } + } + } + ], + "metadata": { + "type": "object", + "properties": { + "transactionId": { + "type": "string" + } + } + }, + "created_at": "2026-01-15T12:00:00.000Z" + }, + "created_at": "2026-01-15T12:00:00.000Z", + "updated_at": "2026-01-15T12:00:00.000Z" + } + ], + "list_metadata": { + "before": null, + "after": null + } +} diff --git a/src/audit-logs/fixtures/list-audit-log-schema.json b/src/audit-logs/fixtures/list-audit-log-schema.json new file mode 100644 index 000000000..97bd6f5b7 --- /dev/null +++ b/src/audit-logs/fixtures/list-audit-log-schema.json @@ -0,0 +1,44 @@ +{ + "data": [ + { + "object": "audit_log_schema", + "version": 1, + "actor": { + "metadata": { + "type": "object", + "properties": { + "role": { + "type": "string" + } + } + } + }, + "targets": [ + { + "type": "invoice", + "metadata": { + "type": "object", + "properties": { + "cost": { + "type": "number" + } + } + } + } + ], + "metadata": { + "type": "object", + "properties": { + "transactionId": { + "type": "string" + } + } + }, + "created_at": "2026-01-15T12:00:00.000Z" + } + ], + "list_metadata": { + "before": null, + "after": null + } +} diff --git a/src/audit-logs/fixtures/update-audit-logs-retention.json b/src/audit-logs/fixtures/update-audit-logs-retention.json new file mode 100644 index 000000000..0720427e5 --- /dev/null +++ b/src/audit-logs/fixtures/update-audit-logs-retention.json @@ -0,0 +1,3 @@ +{ + "retention_period_in_days": 30 +} diff --git a/src/audit-logs/interfaces/audit-log-action.interface.ts b/src/audit-logs/interfaces/audit-log-action.interface.ts new file mode 100644 index 000000000..2afd8f468 --- /dev/null +++ b/src/audit-logs/interfaces/audit-log-action.interface.ts @@ -0,0 +1,27 @@ +// This file is auto-generated by oagen. Do not edit. + +import type { + AuditLogSchema, + AuditLogSchemaResponse, +} from './audit-log-schema.interface'; + +export interface AuditLogAction { + /** Distinguishes the Audit Log Action object. */ + object: 'audit_log_action'; + /** Identifier of what action was taken. */ + name: string; + /** The schema associated with the action. */ + schema: AuditLogSchema; + /** An ISO 8601 timestamp. */ + createdAt: Date; + /** An ISO 8601 timestamp. */ + updatedAt: Date; +} + +export interface AuditLogActionResponse { + object: 'audit_log_action'; + name: string; + schema: AuditLogSchemaResponse; + created_at: string; + updated_at: string; +} diff --git a/src/audit-logs/interfaces/audit-log-event-actor.interface.ts b/src/audit-logs/interfaces/audit-log-event-actor.interface.ts new file mode 100644 index 000000000..63729822f --- /dev/null +++ b/src/audit-logs/interfaces/audit-log-event-actor.interface.ts @@ -0,0 +1,19 @@ +// This file is auto-generated by oagen. Do not edit. + +export interface AuditLogEventActor { + /** Actor identifier. */ + id: string; + /** Actor type. */ + type: string; + /** Optional actor name. */ + name?: string; + /** Additional data associated with the event or entity. */ + metadata?: Record; +} + +export interface AuditLogEventActorResponse { + id: string; + type: string; + name?: string; + metadata?: Record; +} diff --git a/src/audit-logs/interfaces/audit-log-event-context.interface.ts b/src/audit-logs/interfaces/audit-log-event-context.interface.ts new file mode 100644 index 000000000..bb0607cd1 --- /dev/null +++ b/src/audit-logs/interfaces/audit-log-event-context.interface.ts @@ -0,0 +1,13 @@ +// This file is auto-generated by oagen. Do not edit. + +export interface AuditLogEventContext { + /** IP Address or some other geolocation identifier. */ + location: string; + /** User agent string. */ + userAgent?: string; +} + +export interface AuditLogEventContextResponse { + location: string; + user_agent?: string; +} diff --git a/src/audit-logs/interfaces/audit-log-event-create-response.interface.ts b/src/audit-logs/interfaces/audit-log-event-create-response.interface.ts new file mode 100644 index 000000000..1bfff9f0c --- /dev/null +++ b/src/audit-logs/interfaces/audit-log-event-create-response.interface.ts @@ -0,0 +1,10 @@ +// This file is auto-generated by oagen. Do not edit. + +export interface AuditLogEventCreateResponse { + /** Whether the Audit Log event was created successfully. */ + success: boolean; +} + +export interface AuditLogEventCreateResponseWire { + success: boolean; +} diff --git a/src/audit-logs/interfaces/audit-log-event-ingestion.interface.ts b/src/audit-logs/interfaces/audit-log-event-ingestion.interface.ts new file mode 100644 index 000000000..2f5bb685b --- /dev/null +++ b/src/audit-logs/interfaces/audit-log-event-ingestion.interface.ts @@ -0,0 +1,18 @@ +// This file is auto-generated by oagen. Do not edit. + +import type { + AuditLogEvent, + AuditLogEventResponse, +} from './audit-log-event.interface'; + +export interface AuditLogEventIngestion { + /** The unique ID of the Organization. */ + organizationId: string; + /** The audit log event to create. */ + event: AuditLogEvent; +} + +export interface AuditLogEventIngestionResponse { + organization_id: string; + event: AuditLogEventResponse; +} diff --git a/src/audit-logs/interfaces/audit-log-event-target.interface.ts b/src/audit-logs/interfaces/audit-log-event-target.interface.ts new file mode 100644 index 000000000..ef5689afe --- /dev/null +++ b/src/audit-logs/interfaces/audit-log-event-target.interface.ts @@ -0,0 +1,19 @@ +// This file is auto-generated by oagen. Do not edit. + +export interface AuditLogEventTarget { + /** Target identifier. */ + id: string; + /** Target type. */ + type: string; + /** Optional target name. */ + name?: string; + /** Additional data associated with the event or entity. */ + metadata?: Record; +} + +export interface AuditLogEventTargetResponse { + id: string; + type: string; + name?: string; + metadata?: Record; +} diff --git a/src/audit-logs/interfaces/audit-log-event.interface.ts b/src/audit-logs/interfaces/audit-log-event.interface.ts new file mode 100644 index 000000000..53c74d2fc --- /dev/null +++ b/src/audit-logs/interfaces/audit-log-event.interface.ts @@ -0,0 +1,41 @@ +// This file is auto-generated by oagen. Do not edit. + +import type { + AuditLogEventActor, + AuditLogEventActorResponse, +} from './audit-log-event-actor.interface'; +import type { + AuditLogEventTarget, + AuditLogEventTargetResponse, +} from './audit-log-event-target.interface'; +import type { + AuditLogEventContext, + AuditLogEventContextResponse, +} from './audit-log-event-context.interface'; + +export interface AuditLogEvent { + /** Identifier of what happened. */ + action: string; + /** ISO-8601 value of when the action occurred. */ + occurredAt: Date; + /** The entity that performed the action. */ + actor: AuditLogEventActor; + /** The resources affected by the action. */ + targets: AuditLogEventTarget[]; + /** Additional context about where and how the action occurred. */ + context: AuditLogEventContext; + /** Additional data associated with the event or entity. */ + metadata?: Record; + /** What schema version the event is associated with. */ + version?: number; +} + +export interface AuditLogEventResponse { + action: string; + occurred_at: string; + actor: AuditLogEventActorResponse; + targets: AuditLogEventTargetResponse[]; + context: AuditLogEventContextResponse; + metadata?: Record; + version?: number; +} diff --git a/src/audit-logs/interfaces/audit-log-export-creation.interface.ts b/src/audit-logs/interfaces/audit-log-export-creation.interface.ts new file mode 100644 index 000000000..010deb4d0 --- /dev/null +++ b/src/audit-logs/interfaces/audit-log-export-creation.interface.ts @@ -0,0 +1,34 @@ +// This file is auto-generated by oagen. Do not edit. + +export interface AuditLogExportCreation { + /** The unique ID of the Organization. */ + organizationId: string; + /** ISO-8601 value for start of the export range. */ + rangeStart: string; + /** ISO-8601 value for end of the export range. */ + rangeEnd: string; + /** List of actions to filter against. */ + actions?: string[]; + /** + * Deprecated. Use `actor_names` instead. + * @deprecated + */ + actors?: string[]; + /** List of actor names to filter against. */ + actorNames?: string[]; + /** List of actor IDs to filter against. */ + actorIds?: string[]; + /** List of target types to filter against. */ + targets?: string[]; +} + +export interface AuditLogExportCreationResponse { + organization_id: string; + range_start: string; + range_end: string; + actions?: string[]; + actors?: string[]; + actor_names?: string[]; + actor_ids?: string[]; + targets?: string[]; +} diff --git a/src/audit-logs/interfaces/audit-log-export-options.interface.ts b/src/audit-logs/interfaces/audit-log-export-options.interface.ts index 7c7f22e96..d62a22084 100644 --- a/src/audit-logs/interfaces/audit-log-export-options.interface.ts +++ b/src/audit-logs/interfaces/audit-log-export-options.interface.ts @@ -3,8 +3,8 @@ export interface AuditLogExportOptions { actorNames?: string[]; actorIds?: string[]; organizationId: string; - rangeEnd: Date; - rangeStart: Date; + rangeEnd: string; + rangeStart: string; targets?: string[]; } diff --git a/src/audit-logs/interfaces/audit-log-export-state.interface.ts b/src/audit-logs/interfaces/audit-log-export-state.interface.ts new file mode 100644 index 000000000..e4177c8a7 --- /dev/null +++ b/src/audit-logs/interfaces/audit-log-export-state.interface.ts @@ -0,0 +1,10 @@ +// This file is auto-generated by oagen. Do not edit. + +export const AuditLogExportState = { + Pending: 'pending', + Ready: 'ready', + Error: 'error', +} as const; + +export type AuditLogExportState = + (typeof AuditLogExportState)[keyof typeof AuditLogExportState]; diff --git a/src/audit-logs/interfaces/audit-log-export.interface.ts b/src/audit-logs/interfaces/audit-log-export.interface.ts index c41a97e9d..bd17cbf9f 100644 --- a/src/audit-logs/interfaces/audit-log-export.interface.ts +++ b/src/audit-logs/interfaces/audit-log-export.interface.ts @@ -1,10 +1,18 @@ +// This file is auto-generated by oagen. Do not edit. + export interface AuditLogExport { + /** Distinguishes the Audit Log Export object. */ object: 'audit_log_export'; + /** The unique ID of the Audit Log Export. */ id: string; + /** The state of the export. Possible values: pending, ready, error. */ state: 'pending' | 'ready' | 'error'; + /** A URL to the CSV file. Only defined when the Audit Log Export is ready. */ url?: string; - createdAt: string; - updatedAt: string; + /** An ISO 8601 timestamp. */ + createdAt: Date; + /** An ISO 8601 timestamp. */ + updatedAt: Date; } export interface AuditLogExportResponse { diff --git a/src/audit-logs/interfaces/audit-log-schema-actor-input.interface.ts b/src/audit-logs/interfaces/audit-log-schema-actor-input.interface.ts new file mode 100644 index 000000000..6ac0a0177 --- /dev/null +++ b/src/audit-logs/interfaces/audit-log-schema-actor-input.interface.ts @@ -0,0 +1,10 @@ +// This file is auto-generated by oagen. Do not edit. + +export interface AuditLogSchemaActorInput { + /** JSON schema for actor metadata. */ + metadata: Record; +} + +export interface AuditLogSchemaActorInputResponse { + metadata: Record; +} diff --git a/src/audit-logs/interfaces/audit-log-schema-actor.interface.ts b/src/audit-logs/interfaces/audit-log-schema-actor.interface.ts new file mode 100644 index 000000000..05c78ba30 --- /dev/null +++ b/src/audit-logs/interfaces/audit-log-schema-actor.interface.ts @@ -0,0 +1,11 @@ +// This file is auto-generated by oagen. Do not edit. + +/** The metadata schema for the actor. */ +export interface AuditLogSchemaActor { + /** The JSON Schema definition for actor metadata. */ + metadata: Record; +} + +export interface AuditLogSchemaActorResponse { + metadata: Record; +} diff --git a/src/audit-logs/interfaces/audit-log-schema-input.interface.ts b/src/audit-logs/interfaces/audit-log-schema-input.interface.ts new file mode 100644 index 000000000..33960597b --- /dev/null +++ b/src/audit-logs/interfaces/audit-log-schema-input.interface.ts @@ -0,0 +1,25 @@ +// This file is auto-generated by oagen. Do not edit. + +import type { + AuditLogSchemaActorInput, + AuditLogSchemaActorInputResponse, +} from './audit-log-schema-actor-input.interface'; +import type { + AuditLogSchemaTargetInput, + AuditLogSchemaTargetInputResponse, +} from './audit-log-schema-target-input.interface'; + +export interface AuditLogSchemaInput { + /** The metadata schema for the actor. */ + actor?: AuditLogSchemaActorInput; + /** The list of targets for the schema. */ + targets: AuditLogSchemaTargetInput[]; + /** Optional JSON schema for event metadata. */ + metadata?: Record; +} + +export interface AuditLogSchemaInputResponse { + actor?: AuditLogSchemaActorInputResponse; + targets: AuditLogSchemaTargetInputResponse[]; + metadata?: Record; +} diff --git a/src/audit-logs/interfaces/audit-log-schema-target-input.interface.ts b/src/audit-logs/interfaces/audit-log-schema-target-input.interface.ts new file mode 100644 index 000000000..5a74f6ba8 --- /dev/null +++ b/src/audit-logs/interfaces/audit-log-schema-target-input.interface.ts @@ -0,0 +1,13 @@ +// This file is auto-generated by oagen. Do not edit. + +export interface AuditLogSchemaTargetInput { + /** The type of the target resource. */ + type: string; + /** Optional JSON schema for target metadata. */ + metadata?: Record; +} + +export interface AuditLogSchemaTargetInputResponse { + type: string; + metadata?: Record; +} diff --git a/src/audit-logs/interfaces/audit-log-schema-target.interface.ts b/src/audit-logs/interfaces/audit-log-schema-target.interface.ts new file mode 100644 index 000000000..cf9345f62 --- /dev/null +++ b/src/audit-logs/interfaces/audit-log-schema-target.interface.ts @@ -0,0 +1,13 @@ +// This file is auto-generated by oagen. Do not edit. + +export interface AuditLogSchemaTarget { + /** The type of the target resource. */ + type: string; + /** Additional data associated with the event or entity. */ + metadata?: Record; +} + +export interface AuditLogSchemaTargetResponse { + type: string; + metadata?: Record; +} diff --git a/src/audit-logs/interfaces/audit-log-schema.interface.ts b/src/audit-logs/interfaces/audit-log-schema.interface.ts index ff2b4ac47..f8a5809d4 100644 --- a/src/audit-logs/interfaces/audit-log-schema.interface.ts +++ b/src/audit-logs/interfaces/audit-log-schema.interface.ts @@ -1,46 +1,34 @@ -export type AuditLogSchemaMetadata = - | Record - | undefined; +// This file is auto-generated by oagen. Do not edit. -export interface AuditLogActorSchema { - metadata: Record; -} - -export interface AuditLogTargetSchema { - type: string; - metadata?: Record; -} +import type { + AuditLogSchemaActor, + AuditLogSchemaActorResponse, +} from './audit-log-schema-actor.interface'; +import type { + AuditLogSchemaTarget, + AuditLogSchemaTargetResponse, +} from './audit-log-schema-target.interface'; export interface AuditLogSchema { + /** Distinguishes the Audit Log Schema object. */ object: 'audit_log_schema'; + /** The version of the schema. */ version: number; - targets: AuditLogTargetSchema[]; - actor: AuditLogActorSchema | undefined; - metadata: Record | undefined; - createdAt: string; -} - -interface SerializedAuditLogTargetSchema { - type: string; - metadata?: { - type: 'object'; - properties: AuditLogSchemaMetadata; - }; + /** The metadata schema for the actor. */ + actor?: AuditLogSchemaActor; + /** The list of targets for the schema. */ + targets: AuditLogSchemaTarget[]; + /** Additional data associated with the event or entity. */ + metadata?: Record; + /** The timestamp when the Audit Log Schema was created. */ + createdAt: Date; } export interface AuditLogSchemaResponse { object: 'audit_log_schema'; version: number; - targets: SerializedAuditLogTargetSchema[]; - actor?: { - metadata: { - type: 'object'; - properties: AuditLogSchemaMetadata; - }; - }; - metadata?: { - type: 'object'; - properties: AuditLogSchemaMetadata; - }; + actor?: AuditLogSchemaActorResponse; + targets: AuditLogSchemaTargetResponse[]; + metadata?: Record; created_at: string; } diff --git a/src/audit-logs/interfaces/audit-logs-retention.interface.ts b/src/audit-logs/interfaces/audit-logs-retention.interface.ts new file mode 100644 index 000000000..26cba3ea5 --- /dev/null +++ b/src/audit-logs/interfaces/audit-logs-retention.interface.ts @@ -0,0 +1,10 @@ +// This file is auto-generated by oagen. Do not edit. + +export interface AuditLogsRetention { + /** The number of days Audit Log events will be retained before being permanently deleted. Valid values are 30 and 365. */ + retentionPeriodInDays: number | null; +} + +export interface AuditLogsRetentionResponse { + retention_period_in_days: number | null; +} diff --git a/src/audit-logs/interfaces/create-audit-log-event-options.interface.ts b/src/audit-logs/interfaces/create-audit-log-event-options.interface.ts deleted file mode 100644 index b74649d8f..000000000 --- a/src/audit-logs/interfaces/create-audit-log-event-options.interface.ts +++ /dev/null @@ -1,46 +0,0 @@ -import { PostOptions } from '../../common/interfaces'; - -export interface AuditLogActor { - id: string; - name?: string; - type: string; - metadata?: Record; -} - -export interface AuditLogTarget { - id: string; - name?: string; - type: string; - metadata?: Record; -} - -export interface CreateAuditLogEventOptions { - action: string; - version?: number; - occurredAt: Date; - actor: AuditLogActor; - targets: AuditLogTarget[]; - context: { - location: string; - userAgent?: string; - }; - metadata?: Record; -} - -export interface SerializedCreateAuditLogEventOptions { - action: string; - version?: number; - occurred_at: string; - actor: AuditLogActor; - targets: AuditLogTarget[]; - context: { - location: string; - user_agent?: string; - }; - metadata?: Record; -} - -export type CreateAuditLogEventRequestOptions = Pick< - PostOptions, - 'idempotencyKey' ->; diff --git a/src/audit-logs/interfaces/create-audit-log-schema-options.interface.ts b/src/audit-logs/interfaces/create-audit-log-schema-options.interface.ts deleted file mode 100644 index 451d2a6c6..000000000 --- a/src/audit-logs/interfaces/create-audit-log-schema-options.interface.ts +++ /dev/null @@ -1,45 +0,0 @@ -import { PostOptions } from '../../common/interfaces'; - -import type { - AuditLogSchemaMetadata, - AuditLogSchemaResponse, - AuditLogActorSchema, - AuditLogTargetSchema, -} from './audit-log-schema.interface'; - -export interface CreateAuditLogSchemaOptions { - action: string; - targets: AuditLogTargetSchema[]; - actor?: AuditLogActorSchema; - metadata?: Record; -} - -interface SerializedAuditLogTargetSchema { - type: string; - metadata?: { - type: 'object'; - properties: AuditLogSchemaMetadata; - }; -} - -export interface SerializedCreateAuditLogSchemaOptions { - targets: SerializedAuditLogTargetSchema[]; - actor?: { - metadata: { - type: 'object'; - properties: AuditLogSchemaMetadata; - }; - }; - metadata?: { - type: 'object'; - properties: AuditLogSchemaMetadata; - }; -} - -/** @deprecated Use AuditLogSchemaResponse instead */ -export type CreateAuditLogSchemaResponse = AuditLogSchemaResponse; - -export type CreateAuditLogSchemaRequestOptions = Pick< - PostOptions, - 'idempotencyKey' ->; diff --git a/src/audit-logs/interfaces/create-event-options.interface.ts b/src/audit-logs/interfaces/create-event-options.interface.ts new file mode 100644 index 000000000..fa2183516 --- /dev/null +++ b/src/audit-logs/interfaces/create-event-options.interface.ts @@ -0,0 +1,10 @@ +// This file is auto-generated by oagen. Do not edit. + +import type { AuditLogEvent } from './audit-log-event.interface'; + +export interface CreateEventOptions { + /** The unique ID of the Organization. */ + organizationId: string; + /** The audit log event to create. */ + event: AuditLogEvent; +} diff --git a/src/audit-logs/interfaces/create-schema-options.interface.ts b/src/audit-logs/interfaces/create-schema-options.interface.ts new file mode 100644 index 000000000..6db1dc590 --- /dev/null +++ b/src/audit-logs/interfaces/create-schema-options.interface.ts @@ -0,0 +1,15 @@ +// This file is auto-generated by oagen. Do not edit. + +import type { AuditLogSchemaActorInput } from './audit-log-schema-actor-input.interface'; +import type { AuditLogSchemaTargetInput } from './audit-log-schema-target-input.interface'; + +export interface CreateSchemaOptions { + /** The name of the Audit Log action. */ + actionName: string; + /** The metadata schema for the actor. */ + actor?: AuditLogSchemaActorInput; + /** The list of targets for the schema. */ + targets: AuditLogSchemaTargetInput[]; + /** Optional JSON schema for event metadata. */ + metadata?: Record; +} diff --git a/src/audit-logs/interfaces/get-export-options.interface.ts b/src/audit-logs/interfaces/get-export-options.interface.ts new file mode 100644 index 000000000..9faa877bf --- /dev/null +++ b/src/audit-logs/interfaces/get-export-options.interface.ts @@ -0,0 +1,6 @@ +// This file is auto-generated by oagen. Do not edit. + +export interface GetExportOptions { + /** The unique ID of the Audit Log Export. */ + auditLogExportId: string; +} diff --git a/src/audit-logs/interfaces/get-organization-audit-logs-retention-options.interface.ts b/src/audit-logs/interfaces/get-organization-audit-logs-retention-options.interface.ts new file mode 100644 index 000000000..cf819e625 --- /dev/null +++ b/src/audit-logs/interfaces/get-organization-audit-logs-retention-options.interface.ts @@ -0,0 +1,6 @@ +// This file is auto-generated by oagen. Do not edit. + +export interface GetOrganizationAuditLogsRetentionOptions { + /** Unique identifier of the Organization. */ + id: string; +} diff --git a/src/audit-logs/interfaces/index.ts b/src/audit-logs/interfaces/index.ts index 39e487671..53ad1afb5 100644 --- a/src/audit-logs/interfaces/index.ts +++ b/src/audit-logs/interfaces/index.ts @@ -1,5 +1,28 @@ +// This file is auto-generated by oagen. Do not edit. + +export * from './audit-log-action.interface'; +export * from './audit-log-event-actor.interface'; +export * from './audit-log-event-context.interface'; +export * from './audit-log-event-create-response.interface'; +export * from './audit-log-event-ingestion.interface'; +export * from './audit-log-event-target.interface'; +export * from './audit-log-event.interface'; +export * from './audit-log-export-creation.interface'; export * from './audit-log-export-options.interface'; +export * from './audit-log-export-state.interface'; export * from './audit-log-export.interface'; +export * from './audit-log-schema-actor-input.interface'; +export * from './audit-log-schema-actor.interface'; +export * from './audit-log-schema-input.interface'; +export * from './audit-log-schema-target-input.interface'; +export * from './audit-log-schema-target.interface'; export * from './audit-log-schema.interface'; -export * from './create-audit-log-event-options.interface'; -export * from './create-audit-log-schema-options.interface'; +export * from './audit-logs-retention.interface'; +export * from './create-event-options.interface'; +export * from './create-schema-options.interface'; +export * from './get-export-options.interface'; +export * from './get-organization-audit-logs-retention-options.interface'; +export * from './list-action-schemas-options.interface'; +export * from './list-actions-options.interface'; +export * from './update-audit-logs-retention.interface'; +export * from './update-organization-audit-logs-retention-options.interface'; diff --git a/src/audit-logs/interfaces/list-action-schemas-options.interface.ts b/src/audit-logs/interfaces/list-action-schemas-options.interface.ts new file mode 100644 index 000000000..29a4bdaa4 --- /dev/null +++ b/src/audit-logs/interfaces/list-action-schemas-options.interface.ts @@ -0,0 +1,8 @@ +// This file is auto-generated by oagen. Do not edit. + +import type { PaginationOptions } from '../../common/interfaces/pagination-options.interface'; + +export interface ListActionSchemasOptions extends PaginationOptions { + /** The name of the Audit Log action. */ + actionName: string; +} diff --git a/src/audit-logs/interfaces/list-actions-options.interface.ts b/src/audit-logs/interfaces/list-actions-options.interface.ts new file mode 100644 index 000000000..bc066ca00 --- /dev/null +++ b/src/audit-logs/interfaces/list-actions-options.interface.ts @@ -0,0 +1,5 @@ +// This file is auto-generated by oagen. Do not edit. + +import type { PaginationOptions } from '../../common/interfaces/pagination-options.interface'; + +export type ListActionsOptions = PaginationOptions; diff --git a/src/audit-logs/interfaces/update-audit-logs-retention.interface.ts b/src/audit-logs/interfaces/update-audit-logs-retention.interface.ts new file mode 100644 index 000000000..861ca0636 --- /dev/null +++ b/src/audit-logs/interfaces/update-audit-logs-retention.interface.ts @@ -0,0 +1,10 @@ +// This file is auto-generated by oagen. Do not edit. + +export interface UpdateAuditLogsRetention { + /** The number of days Audit Log events will be retained. Valid values are `30` and `365`. */ + retentionPeriodInDays: number; +} + +export interface UpdateAuditLogsRetentionResponse { + retention_period_in_days: number; +} diff --git a/src/audit-logs/interfaces/update-organization-audit-logs-retention-options.interface.ts b/src/audit-logs/interfaces/update-organization-audit-logs-retention-options.interface.ts new file mode 100644 index 000000000..d64ed5264 --- /dev/null +++ b/src/audit-logs/interfaces/update-organization-audit-logs-retention-options.interface.ts @@ -0,0 +1,8 @@ +// This file is auto-generated by oagen. Do not edit. + +export interface UpdateOrganizationAuditLogsRetentionOptions { + /** Unique identifier of the Organization. */ + id: string; + /** The number of days Audit Log events will be retained. Valid values are `30` and `365`. */ + retentionPeriodInDays: number; +} diff --git a/src/audit-logs/serializers/audit-log-action.serializer.ts b/src/audit-logs/serializers/audit-log-action.serializer.ts new file mode 100644 index 000000000..017ab99c6 --- /dev/null +++ b/src/audit-logs/serializers/audit-log-action.serializer.ts @@ -0,0 +1,17 @@ +// This file is auto-generated by oagen. Do not edit. + +import type { + AuditLogAction, + AuditLogActionResponse, +} from '../interfaces/audit-log-action.interface'; +import { deserializeAuditLogSchema } from './audit-log-schema.serializer'; + +export const deserializeAuditLogAction = ( + response: AuditLogActionResponse, +): AuditLogAction => ({ + object: response.object, + name: response.name, + schema: deserializeAuditLogSchema(response.schema), + createdAt: new Date(response.created_at), + updatedAt: new Date(response.updated_at), +}); diff --git a/src/audit-logs/serializers/audit-log-event-actor.serializer.ts b/src/audit-logs/serializers/audit-log-event-actor.serializer.ts new file mode 100644 index 000000000..8f187926d --- /dev/null +++ b/src/audit-logs/serializers/audit-log-event-actor.serializer.ts @@ -0,0 +1,15 @@ +// This file is auto-generated by oagen. Do not edit. + +import type { + AuditLogEventActor, + AuditLogEventActorResponse, +} from '../interfaces/audit-log-event-actor.interface'; + +export const serializeAuditLogEventActor = ( + model: AuditLogEventActor, +): AuditLogEventActorResponse => ({ + id: model.id, + type: model.type, + name: model.name, + metadata: model.metadata, +}); diff --git a/src/audit-logs/serializers/audit-log-event-context.serializer.ts b/src/audit-logs/serializers/audit-log-event-context.serializer.ts new file mode 100644 index 000000000..0b3021918 --- /dev/null +++ b/src/audit-logs/serializers/audit-log-event-context.serializer.ts @@ -0,0 +1,13 @@ +// This file is auto-generated by oagen. Do not edit. + +import type { + AuditLogEventContext, + AuditLogEventContextResponse, +} from '../interfaces/audit-log-event-context.interface'; + +export const serializeAuditLogEventContext = ( + model: AuditLogEventContext, +): AuditLogEventContextResponse => ({ + location: model.location, + user_agent: model.userAgent, +}); diff --git a/src/audit-logs/serializers/audit-log-event-create-response.serializer.ts b/src/audit-logs/serializers/audit-log-event-create-response.serializer.ts new file mode 100644 index 000000000..7a7b475f8 --- /dev/null +++ b/src/audit-logs/serializers/audit-log-event-create-response.serializer.ts @@ -0,0 +1,12 @@ +// This file is auto-generated by oagen. Do not edit. + +import type { + AuditLogEventCreateResponse, + AuditLogEventCreateResponseWire, +} from '../interfaces/audit-log-event-create-response.interface'; + +export const deserializeAuditLogEventCreateResponse = ( + response: AuditLogEventCreateResponseWire, +): AuditLogEventCreateResponse => ({ + success: response.success, +}); diff --git a/src/audit-logs/serializers/audit-log-event-ingestion.serializer.ts b/src/audit-logs/serializers/audit-log-event-ingestion.serializer.ts new file mode 100644 index 000000000..73e7a4545 --- /dev/null +++ b/src/audit-logs/serializers/audit-log-event-ingestion.serializer.ts @@ -0,0 +1,14 @@ +// This file is auto-generated by oagen. Do not edit. + +import type { + AuditLogEventIngestion, + AuditLogEventIngestionResponse, +} from '../interfaces/audit-log-event-ingestion.interface'; +import { serializeAuditLogEvent } from './audit-log-event.serializer'; + +export const serializeAuditLogEventIngestion = ( + model: AuditLogEventIngestion, +): AuditLogEventIngestionResponse => ({ + organization_id: model.organizationId, + event: serializeAuditLogEvent(model.event), +}); diff --git a/src/audit-logs/serializers/audit-log-event-target.serializer.ts b/src/audit-logs/serializers/audit-log-event-target.serializer.ts new file mode 100644 index 000000000..0b6c48761 --- /dev/null +++ b/src/audit-logs/serializers/audit-log-event-target.serializer.ts @@ -0,0 +1,15 @@ +// This file is auto-generated by oagen. Do not edit. + +import type { + AuditLogEventTarget, + AuditLogEventTargetResponse, +} from '../interfaces/audit-log-event-target.interface'; + +export const serializeAuditLogEventTarget = ( + model: AuditLogEventTarget, +): AuditLogEventTargetResponse => ({ + id: model.id, + type: model.type, + name: model.name, + metadata: model.metadata, +}); diff --git a/src/audit-logs/serializers/audit-log-event.serializer.ts b/src/audit-logs/serializers/audit-log-event.serializer.ts new file mode 100644 index 000000000..9ca5392cd --- /dev/null +++ b/src/audit-logs/serializers/audit-log-event.serializer.ts @@ -0,0 +1,21 @@ +// This file is auto-generated by oagen. Do not edit. + +import type { + AuditLogEvent, + AuditLogEventResponse, +} from '../interfaces/audit-log-event.interface'; +import { serializeAuditLogEventActor } from './audit-log-event-actor.serializer'; +import { serializeAuditLogEventTarget } from './audit-log-event-target.serializer'; +import { serializeAuditLogEventContext } from './audit-log-event-context.serializer'; + +export const serializeAuditLogEvent = ( + model: AuditLogEvent, +): AuditLogEventResponse => ({ + action: model.action, + occurred_at: model.occurredAt.toISOString(), + actor: serializeAuditLogEventActor(model.actor), + targets: model.targets.map(serializeAuditLogEventTarget), + context: serializeAuditLogEventContext(model.context), + metadata: model.metadata, + version: model.version, +}); diff --git a/src/audit-logs/serializers/audit-log-export-creation.serializer.ts b/src/audit-logs/serializers/audit-log-export-creation.serializer.ts new file mode 100644 index 000000000..b37885efe --- /dev/null +++ b/src/audit-logs/serializers/audit-log-export-creation.serializer.ts @@ -0,0 +1,19 @@ +// This file is auto-generated by oagen. Do not edit. + +import type { + AuditLogExportCreation, + AuditLogExportCreationResponse, +} from '../interfaces/audit-log-export-creation.interface'; + +export const serializeAuditLogExportCreation = ( + model: AuditLogExportCreation, +): AuditLogExportCreationResponse => ({ + organization_id: model.organizationId, + range_start: model.rangeStart, + range_end: model.rangeEnd, + actions: model.actions, + actors: model.actors, + actor_names: model.actorNames, + actor_ids: model.actorIds, + targets: model.targets, +}); diff --git a/src/audit-logs/serializers/audit-log-export-options.serializer.ts b/src/audit-logs/serializers/audit-log-export-options.serializer.ts deleted file mode 100644 index 72b011771..000000000 --- a/src/audit-logs/serializers/audit-log-export-options.serializer.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { - AuditLogExportOptions, - SerializedAuditLogExportOptions, -} from '../interfaces'; - -export const serializeAuditLogExportOptions = ( - options: AuditLogExportOptions, -): SerializedAuditLogExportOptions => ({ - actions: options.actions, - actor_names: options.actorNames, - actor_ids: options.actorIds, - organization_id: options.organizationId, - range_end: options.rangeEnd.toISOString(), - range_start: options.rangeStart.toISOString(), - targets: options.targets, -}); diff --git a/src/audit-logs/serializers/audit-log-export.serializer.ts b/src/audit-logs/serializers/audit-log-export.serializer.ts index 0fc5132ef..81ccc8e3a 100644 --- a/src/audit-logs/serializers/audit-log-export.serializer.ts +++ b/src/audit-logs/serializers/audit-log-export.serializer.ts @@ -1,12 +1,17 @@ -import { AuditLogExport, AuditLogExportResponse } from '../interfaces'; +// This file is auto-generated by oagen. Do not edit. + +import type { + AuditLogExport, + AuditLogExportResponse, +} from '../interfaces/audit-log-export.interface'; export const deserializeAuditLogExport = ( - auditLogExport: AuditLogExportResponse, + response: AuditLogExportResponse, ): AuditLogExport => ({ - object: auditLogExport.object, - id: auditLogExport.id, - state: auditLogExport.state, - url: auditLogExport.url, - createdAt: auditLogExport.created_at, - updatedAt: auditLogExport.updated_at, + object: response.object, + id: response.id, + state: response.state, + url: response.url ?? undefined, + createdAt: new Date(response.created_at), + updatedAt: new Date(response.updated_at), }); diff --git a/src/audit-logs/serializers/audit-log-schema-actor-input.serializer.ts b/src/audit-logs/serializers/audit-log-schema-actor-input.serializer.ts new file mode 100644 index 000000000..ab51af723 --- /dev/null +++ b/src/audit-logs/serializers/audit-log-schema-actor-input.serializer.ts @@ -0,0 +1,12 @@ +// This file is auto-generated by oagen. Do not edit. + +import type { + AuditLogSchemaActorInput, + AuditLogSchemaActorInputResponse, +} from '../interfaces/audit-log-schema-actor-input.interface'; + +export const serializeAuditLogSchemaActorInput = ( + model: AuditLogSchemaActorInput, +): AuditLogSchemaActorInputResponse => ({ + metadata: model.metadata, +}); diff --git a/src/audit-logs/serializers/audit-log-schema-actor.serializer.ts b/src/audit-logs/serializers/audit-log-schema-actor.serializer.ts new file mode 100644 index 000000000..8a0eaf5b3 --- /dev/null +++ b/src/audit-logs/serializers/audit-log-schema-actor.serializer.ts @@ -0,0 +1,18 @@ +// This file is auto-generated by oagen. Do not edit. + +import type { + AuditLogSchemaActor, + AuditLogSchemaActorResponse, +} from '../interfaces/audit-log-schema-actor.interface'; + +export const deserializeAuditLogSchemaActor = ( + response: AuditLogSchemaActorResponse, +): AuditLogSchemaActor => ({ + metadata: response.metadata, +}); + +export const serializeAuditLogSchemaActor = ( + model: AuditLogSchemaActor, +): AuditLogSchemaActorResponse => ({ + metadata: model.metadata, +}); diff --git a/src/audit-logs/serializers/audit-log-schema-input.serializer.ts b/src/audit-logs/serializers/audit-log-schema-input.serializer.ts new file mode 100644 index 000000000..389605f3e --- /dev/null +++ b/src/audit-logs/serializers/audit-log-schema-input.serializer.ts @@ -0,0 +1,19 @@ +// This file is auto-generated by oagen. Do not edit. + +import type { + AuditLogSchemaInput, + AuditLogSchemaInputResponse, +} from '../interfaces/audit-log-schema-input.interface'; +import { serializeAuditLogSchemaActorInput } from './audit-log-schema-actor-input.serializer'; +import { serializeAuditLogSchemaTargetInput } from './audit-log-schema-target-input.serializer'; + +export const serializeAuditLogSchemaInput = ( + model: AuditLogSchemaInput, +): AuditLogSchemaInputResponse => ({ + actor: + model.actor != null + ? serializeAuditLogSchemaActorInput(model.actor) + : undefined, + targets: model.targets.map(serializeAuditLogSchemaTargetInput), + metadata: model.metadata, +}); diff --git a/src/audit-logs/serializers/audit-log-schema-target-input.serializer.ts b/src/audit-logs/serializers/audit-log-schema-target-input.serializer.ts new file mode 100644 index 000000000..83aaa4b02 --- /dev/null +++ b/src/audit-logs/serializers/audit-log-schema-target-input.serializer.ts @@ -0,0 +1,13 @@ +// This file is auto-generated by oagen. Do not edit. + +import type { + AuditLogSchemaTargetInput, + AuditLogSchemaTargetInputResponse, +} from '../interfaces/audit-log-schema-target-input.interface'; + +export const serializeAuditLogSchemaTargetInput = ( + model: AuditLogSchemaTargetInput, +): AuditLogSchemaTargetInputResponse => ({ + type: model.type, + metadata: model.metadata, +}); diff --git a/src/audit-logs/serializers/audit-log-schema-target.serializer.ts b/src/audit-logs/serializers/audit-log-schema-target.serializer.ts new file mode 100644 index 000000000..92f7d72e9 --- /dev/null +++ b/src/audit-logs/serializers/audit-log-schema-target.serializer.ts @@ -0,0 +1,20 @@ +// This file is auto-generated by oagen. Do not edit. + +import type { + AuditLogSchemaTarget, + AuditLogSchemaTargetResponse, +} from '../interfaces/audit-log-schema-target.interface'; + +export const deserializeAuditLogSchemaTarget = ( + response: AuditLogSchemaTargetResponse, +): AuditLogSchemaTarget => ({ + type: response.type, + metadata: response.metadata, +}); + +export const serializeAuditLogSchemaTarget = ( + model: AuditLogSchemaTarget, +): AuditLogSchemaTargetResponse => ({ + type: model.type, + metadata: model.metadata, +}); diff --git a/src/audit-logs/serializers/audit-log-schema.serializer.ts b/src/audit-logs/serializers/audit-log-schema.serializer.ts new file mode 100644 index 000000000..8b9e83f80 --- /dev/null +++ b/src/audit-logs/serializers/audit-log-schema.serializer.ts @@ -0,0 +1,22 @@ +// This file is auto-generated by oagen. Do not edit. + +import type { + AuditLogSchema, + AuditLogSchemaResponse, +} from '../interfaces/audit-log-schema.interface'; +import { deserializeAuditLogSchemaActor } from './audit-log-schema-actor.serializer'; +import { deserializeAuditLogSchemaTarget } from './audit-log-schema-target.serializer'; + +export const deserializeAuditLogSchema = ( + response: AuditLogSchemaResponse, +): AuditLogSchema => ({ + object: response.object, + version: response.version, + actor: + response.actor != null + ? deserializeAuditLogSchemaActor(response.actor) + : undefined, + targets: response.targets.map(deserializeAuditLogSchemaTarget), + metadata: response.metadata, + createdAt: new Date(response.created_at), +}); diff --git a/src/audit-logs/serializers/audit-logs-retention.serializer.ts b/src/audit-logs/serializers/audit-logs-retention.serializer.ts new file mode 100644 index 000000000..f459a443e --- /dev/null +++ b/src/audit-logs/serializers/audit-logs-retention.serializer.ts @@ -0,0 +1,12 @@ +// This file is auto-generated by oagen. Do not edit. + +import type { + AuditLogsRetention, + AuditLogsRetentionResponse, +} from '../interfaces/audit-logs-retention.interface'; + +export const deserializeAuditLogsRetention = ( + response: AuditLogsRetentionResponse, +): AuditLogsRetention => ({ + retentionPeriodInDays: response.retention_period_in_days ?? null, +}); diff --git a/src/audit-logs/serializers/create-audit-log-event-options.serializer.ts b/src/audit-logs/serializers/create-audit-log-event-options.serializer.ts deleted file mode 100644 index fc316ac22..000000000 --- a/src/audit-logs/serializers/create-audit-log-event-options.serializer.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { - CreateAuditLogEventOptions, - SerializedCreateAuditLogEventOptions, -} from '../interfaces'; - -export const serializeCreateAuditLogEventOptions = ( - event: CreateAuditLogEventOptions, -): SerializedCreateAuditLogEventOptions => ({ - action: event.action, - version: event.version, - occurred_at: event.occurredAt.toISOString(), - actor: event.actor, - targets: event.targets, - context: { - location: event.context.location, - user_agent: event.context.userAgent, - }, - metadata: event.metadata, -}); diff --git a/src/audit-logs/serializers/create-audit-log-schema-options.serializer.ts b/src/audit-logs/serializers/create-audit-log-schema-options.serializer.ts deleted file mode 100644 index edae6e509..000000000 --- a/src/audit-logs/serializers/create-audit-log-schema-options.serializer.ts +++ /dev/null @@ -1,51 +0,0 @@ -import { - AuditLogSchemaMetadata, - CreateAuditLogSchemaOptions, - SerializedCreateAuditLogSchemaOptions, -} from '../interfaces'; - -function serializeMetadata( - metadata: Record | undefined, -) { - if (!metadata) { - return {}; - } - - const serializedMetadata: AuditLogSchemaMetadata = {}; - - Object.keys(metadata).forEach((key) => { - serializedMetadata[key] = { - type: metadata[key] as 'string' | 'number' | 'boolean', - }; - }); - - return serializedMetadata; -} - -export const serializeCreateAuditLogSchemaOptions = ( - schema: CreateAuditLogSchemaOptions, -): SerializedCreateAuditLogSchemaOptions => ({ - actor: { - metadata: { - type: 'object', - properties: serializeMetadata(schema.actor?.metadata), - }, - }, - targets: schema.targets.map((target) => { - return { - type: target.type, - metadata: target.metadata - ? { - type: 'object', - properties: serializeMetadata(target.metadata), - } - : undefined, - }; - }), - metadata: schema.metadata - ? { - type: 'object', - properties: serializeMetadata(schema.metadata), - } - : undefined, -}); diff --git a/src/audit-logs/serializers/create-audit-log-schema.serializer.ts b/src/audit-logs/serializers/create-audit-log-schema.serializer.ts deleted file mode 100644 index e2950040c..000000000 --- a/src/audit-logs/serializers/create-audit-log-schema.serializer.ts +++ /dev/null @@ -1,39 +0,0 @@ -import { AuditLogSchema, AuditLogSchemaResponse } from '../interfaces'; - -function deserializeMetadata(metadata: { - properties?: Record; -}): Record { - if (!metadata || !metadata.properties) { - return {}; - } - - const deserializedMetadata: Record = {}; - - Object.keys(metadata.properties).forEach((key) => { - if (metadata.properties) { - deserializedMetadata[key] = metadata.properties[key].type; - } - }); - - return deserializedMetadata; -} - -export const deserializeAuditLogSchema = ( - auditLogSchema: AuditLogSchemaResponse, -): AuditLogSchema => ({ - object: auditLogSchema.object, - version: auditLogSchema.version, - targets: auditLogSchema.targets.map((target) => ({ - type: target.type, - metadata: target.metadata - ? deserializeMetadata(target.metadata) - : undefined, - })), - actor: auditLogSchema.actor - ? { metadata: deserializeMetadata(auditLogSchema.actor.metadata) } - : undefined, - metadata: auditLogSchema.metadata - ? deserializeMetadata(auditLogSchema.metadata) - : undefined, - createdAt: auditLogSchema.created_at, -}); diff --git a/src/audit-logs/serializers/index.ts b/src/audit-logs/serializers/index.ts index c208debee..e8a28984a 100644 --- a/src/audit-logs/serializers/index.ts +++ b/src/audit-logs/serializers/index.ts @@ -1,5 +1,19 @@ +// This file is auto-generated by oagen. Do not edit. + +export * from './audit-log-action.serializer'; +export * from './audit-log-event.serializer'; +export * from './audit-log-event-actor.serializer'; +export * from './audit-log-event-context.serializer'; +export * from './audit-log-event-create-response.serializer'; +export * from './audit-log-event-ingestion.serializer'; +export * from './audit-log-event-target.serializer'; export * from './audit-log-export.serializer'; -export * from './audit-log-export-options.serializer'; -export * from './create-audit-log-event-options.serializer'; -export * from './create-audit-log-schema-options.serializer'; -export * from './create-audit-log-schema.serializer'; +export * from './audit-log-export-creation.serializer'; +export * from './audit-log-schema.serializer'; +export * from './audit-log-schema-actor.serializer'; +export * from './audit-log-schema-actor-input.serializer'; +export * from './audit-log-schema-input.serializer'; +export * from './audit-log-schema-target.serializer'; +export * from './audit-log-schema-target-input.serializer'; +export * from './audit-logs-retention.serializer'; +export * from './update-audit-logs-retention.serializer'; diff --git a/src/audit-logs/serializers/update-audit-logs-retention.serializer.ts b/src/audit-logs/serializers/update-audit-logs-retention.serializer.ts new file mode 100644 index 000000000..14faac71c --- /dev/null +++ b/src/audit-logs/serializers/update-audit-logs-retention.serializer.ts @@ -0,0 +1,12 @@ +// This file is auto-generated by oagen. Do not edit. + +import type { + UpdateAuditLogsRetention, + UpdateAuditLogsRetentionResponse, +} from '../interfaces/update-audit-logs-retention.interface'; + +export const serializeUpdateAuditLogsRetention = ( + model: UpdateAuditLogsRetention, +): UpdateAuditLogsRetentionResponse => ({ + retention_period_in_days: model.retentionPeriodInDays, +});