From 4bf85302cf1ed3c2f5548e887feb9ebe0cd3cd88 Mon Sep 17 00:00:00 2001 From: swaroopakkineni Date: Sat, 31 Jan 2026 15:59:30 -1000 Subject: [PATCH 01/17] init --- package-lock.json | 24 ++-- package.json | 1 + src/audit-logs/audit-logs.spec.ts | 121 ++++++++++++++++++ src/audit-logs/audit-logs.ts | 34 +++++ src/audit-logs/interfaces/index.ts | 1 + .../list-schemas-options.interface.ts | 9 ++ .../audit-log-configuration.interface.ts | 60 +++++++++ .../audit-log-retention.interface.ts | 24 ++++ src/organizations/interfaces/index.ts | 2 + src/organizations/organizations.spec.ts | 101 +++++++++++++++ src/organizations/organizations.ts | 59 +++++++++ .../audit-log-configuration.serializer.ts | 44 +++++++ src/organizations/serializers/index.ts | 1 + 13 files changed, 470 insertions(+), 11 deletions(-) create mode 100644 src/audit-logs/interfaces/list-schemas-options.interface.ts create mode 100644 src/organizations/interfaces/audit-log-configuration.interface.ts create mode 100644 src/organizations/interfaces/audit-log-retention.interface.ts create mode 100644 src/organizations/serializers/audit-log-configuration.serializer.ts diff --git a/package-lock.json b/package-lock.json index 080530c53..a7d1c3478 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,6 +9,7 @@ "version": "8.0.0", "license": "MIT", "dependencies": { + "@workos-inc/node": "^8.0.0", "iron-webcrypto": "^2.0.0", "jose": "~6.1.0" }, @@ -133,7 +134,6 @@ "integrity": "sha512-e7jT4DxYvIDLk1ZHmU/m/mB19rex9sv0c2ftBtjSBv+kVM/902eh0fINUzD7UwLLNR+jU585GxUJ8/EBfAM5fw==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "@babel/code-frame": "^7.27.1", "@babel/generator": "^7.28.5", @@ -4508,7 +4508,6 @@ "integrity": "sha512-okqtOgqu2qmZJ5iN4TWlgfF171dZmx2FzdOv2K/ixL2LZWDStL8+JgQerI2sa8eAEfoydG9+0V96m7V+P8yE1Q==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "@eslint-community/regexpp": "^4.12.2", "@typescript-eslint/scope-manager": "8.52.0", @@ -4548,7 +4547,6 @@ "integrity": "sha512-iIACsx8pxRnguSYhHiMn2PvhvfpopO9FXHyn1mG5txZIsAaB6F0KwbFnUQN3KCiG3Jcuad/Cao2FAs1Wp7vAyg==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "@typescript-eslint/scope-manager": "8.52.0", "@typescript-eslint/types": "8.52.0", @@ -5023,13 +5021,24 @@ "win32" ] }, + "node_modules/@workos-inc/node": { + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/@workos-inc/node/-/node-8.0.0.tgz", + "integrity": "sha512-D8VDfx0GXeiVm8vccAl0rElW7taebRnrteKPJzZwehwzI9W/Usa4qKfmwxj+7Lh1Z1deEocDRCpZpV7ml4GpWQ==", + "dependencies": { + "iron-webcrypto": "^2.0.0", + "jose": "~6.1.0" + }, + "engines": { + "node": ">=20.15.0" + } + }, "node_modules/acorn": { "version": "8.15.0", "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.15.0.tgz", "integrity": "sha512-NZyJarBfL7nWwIq+FDL6Zp/yHEhePMNnnJ0y3qfieCrmNvYct8uvtiV41UvlSe6apAfk0fY1FbWx+NwfmpvtTg==", "dev": true, "license": "MIT", - "peer": true, "bin": { "acorn": "bin/acorn" }, @@ -5398,7 +5407,6 @@ } ], "license": "MIT", - "peer": true, "dependencies": { "baseline-browser-mapping": "^2.9.0", "caniuse-lite": "^1.0.30001759", @@ -6152,7 +6160,6 @@ "integrity": "sha512-LEyamqS7W5HB3ujJyvi0HQK/dtVINZvd5mAAp9eT5S/ujByGjiZLCzPcHVzuXbpJDJF/cxwHlfceVUDZ2lnSTw==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "@eslint-community/eslint-utils": "^4.8.0", "@eslint-community/regexpp": "^4.12.1", @@ -7229,7 +7236,6 @@ "integrity": "sha512-F26gjC0yWN8uAA5m5Ss8ZQf5nDHWGlN/xWZIh8S5SRbsEKBovwZhxGd6LJlbZYxBgCYOtreSUyb8hpXyGC5O4A==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "@jest/core": "30.2.0", "@jest/types": "30.2.0", @@ -8088,7 +8094,6 @@ "integrity": "sha512-jcByLnIFkd5gSXZmjNvS1TlmRhCXZjIzHYlaGkPlLIekG55JDR2Z4va9tZwCiP+/RDERiNhMOFu01xd6O5ct1Q==", "dev": true, "license": "MIT", - "peer": true, "bin": { "marked": "bin/marked.js" }, @@ -9101,7 +9106,6 @@ "integrity": "sha512-Qd9c2p0XKZdgT5AYd+KgAMggJ8ZmCs3JnS9PTMWkyUfteKlfmKtxJbWTHkVakxwXs1Ub7jrRYVeFeF7N0sQxyw==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "@oxc-project/types": "=0.101.0", "@rolldown/pluginutils": "1.0.0-beta.53" @@ -9775,7 +9779,6 @@ "integrity": "sha512-5gTmgEY/sqK6gFXLIsQNH19lWb4ebPDLA4SdLP7dsWkIXHWlG66oPuVvXSGFPppYZz8ZDZq0dYYrbHfBCVUb1Q==", "dev": true, "license": "MIT", - "peer": true, "engines": { "node": ">=12" }, @@ -10065,7 +10068,6 @@ "integrity": "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==", "dev": true, "license": "Apache-2.0", - "peer": true, "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" diff --git a/package.json b/package.json index 0f989dd51..7f7a2e34f 100644 --- a/package.json +++ b/package.json @@ -41,6 +41,7 @@ "typecheck": "tsc --noEmit" }, "dependencies": { + "@workos-inc/node": "^8.0.0", "iron-webcrypto": "^2.0.0", "jose": "~6.1.0" }, diff --git a/src/audit-logs/audit-logs.spec.ts b/src/audit-logs/audit-logs.spec.ts index d34aab05e..752419703 100644 --- a/src/audit-logs/audit-logs.spec.ts +++ b/src/audit-logs/audit-logs.spec.ts @@ -1,6 +1,7 @@ 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 { @@ -844,4 +845,124 @@ describe('AuditLogs', () => { }); }); }); + + 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: 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' }, + }, + }, + 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({ + action: 'user.logged_in', + }); + + expect(result.data).toHaveLength(1); + 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({ + action: '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('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({ action: 'user.logged_in' }), + ).rejects.toThrow(UnauthorizedException); + }); + }); + }); }); diff --git a/src/audit-logs/audit-logs.ts b/src/audit-logs/audit-logs.ts index 105d72e4d..ea3b91e89 100644 --- a/src/audit-logs/audit-logs.ts +++ b/src/audit-logs/audit-logs.ts @@ -1,7 +1,11 @@ +import { PaginationOptions } from '../common/interfaces'; +import { fetchAndDeserialize } from '../common/utils/fetch-and-deserialize'; +import { AutoPaginatable } from '../common/utils/pagination'; import { WorkOS } from '../workos'; import { CreateAuditLogEventOptions, CreateAuditLogEventRequestOptions, + ListSchemasOptions, } from './interfaces'; import { AuditLogExportOptions } from './interfaces/audit-log-export-options.interface'; import { @@ -77,4 +81,34 @@ export class AuditLogs { return deserializeAuditLogSchema(data); } + + /** + * Lists all schemas for a specific audit log action. + * + * @param options - Options including the action identifier and pagination parameters + * @returns A paginated list of audit log schemas + */ + async listSchemas( + options: ListSchemasOptions, + ): Promise> { + const { action, ...paginationOptions } = options; + const endpoint = `/audit_logs/actions/${action}/schemas`; + + return new AutoPaginatable( + await fetchAndDeserialize( + this.workos, + endpoint, + deserializeAuditLogSchema, + paginationOptions, + ), + (params: PaginationOptions) => + fetchAndDeserialize( + this.workos, + endpoint, + deserializeAuditLogSchema, + params, + ), + options, + ); + } } diff --git a/src/audit-logs/interfaces/index.ts b/src/audit-logs/interfaces/index.ts index c52752fc2..cce34fc1c 100644 --- a/src/audit-logs/interfaces/index.ts +++ b/src/audit-logs/interfaces/index.ts @@ -2,3 +2,4 @@ export * from './audit-log-export-options.interface'; export * from './audit-log-export.interface'; export * from './create-audit-log-event-options.interface'; export * from './create-audit-log-schema-options.interface'; +export * from './list-schemas-options.interface'; diff --git a/src/audit-logs/interfaces/list-schemas-options.interface.ts b/src/audit-logs/interfaces/list-schemas-options.interface.ts new file mode 100644 index 000000000..27963c89d --- /dev/null +++ b/src/audit-logs/interfaces/list-schemas-options.interface.ts @@ -0,0 +1,9 @@ +import { PaginationOptions } from '../../common/interfaces'; + +/** + * Options for listing audit log schemas for a specific action. + */ +export interface ListSchemasOptions extends PaginationOptions { + /** The action identifier (e.g., 'user.logged_in') */ + action: string; +} diff --git a/src/organizations/interfaces/audit-log-configuration.interface.ts b/src/organizations/interfaces/audit-log-configuration.interface.ts new file mode 100644 index 000000000..309cd8513 --- /dev/null +++ b/src/organizations/interfaces/audit-log-configuration.interface.ts @@ -0,0 +1,60 @@ +/** + * Log stream destination types for audit log forwarding. + */ +export type AuditLogStreamType = + | 'Datadog' + | 'Splunk' + | 'S3' + | 'GoogleCloudStorage' + | 'GenericHttps'; + +/** + * Audit log stream configuration. + */ +export interface AuditLogStream { + /** Unique identifier for the log stream */ + id: string; + /** Type of log stream destination */ + type: AuditLogStreamType; + /** Current state of the log stream */ + state: string; + /** ISO-8601 timestamp of last successful sync */ + lastSyncedAt: string; + /** ISO-8601 timestamp when the stream was created */ + createdAt: string; +} + +/** + * API response format for audit log stream. + */ +export interface AuditLogStreamResponse { + id: string; + type: AuditLogStreamType; + state: string; + last_synced_at: string; + created_at: string; +} + +/** + * Complete audit log configuration for an organization. + */ +export interface AuditLogConfiguration { + /** The organization ID */ + organizationId: string; + /** Number of days audit logs are retained */ + retentionPeriodInDays: number; + /** Current state of audit logging ('active', 'inactive', or 'disabled') */ + state: 'active' | 'inactive' | 'disabled'; + /** Optional log stream configuration if forwarding is enabled */ + logStream?: AuditLogStream; +} + +/** + * API response format for audit log configuration. + */ +export interface AuditLogConfigurationResponse { + organization_id: string; + retention_period_in_days: number; + state: 'active' | 'inactive' | 'disabled'; + log_stream?: AuditLogStreamResponse; +} diff --git a/src/organizations/interfaces/audit-log-retention.interface.ts b/src/organizations/interfaces/audit-log-retention.interface.ts new file mode 100644 index 000000000..f86ff12be --- /dev/null +++ b/src/organizations/interfaces/audit-log-retention.interface.ts @@ -0,0 +1,24 @@ +/** + * Audit log retention configuration for an organization. + */ +export interface AuditLogRetention { + /** Number of days audit logs are retained (30 or 365) */ + retentionPeriodInDays: number; +} + +/** + * API response format for audit log retention. + */ +export interface AuditLogRetentionResponse { + retention_period_in_days: number; +} + +/** + * Options for setting audit log retention for an organization. + */ +export interface SetAuditLogRetentionOptions { + /** The ID of the organization */ + organizationId: string; + /** Number of days to retain audit logs (30 or 365) */ + retentionPeriodInDays: number; +} diff --git a/src/organizations/interfaces/index.ts b/src/organizations/interfaces/index.ts index d44e49367..6ad1cf3c0 100644 --- a/src/organizations/interfaces/index.ts +++ b/src/organizations/interfaces/index.ts @@ -1,3 +1,5 @@ +export * from './audit-log-configuration.interface'; +export * from './audit-log-retention.interface'; export * from './create-organization-options.interface'; export * from './domain-data.interface'; export * from './list-organization-feature-flags-options.interface'; diff --git a/src/organizations/organizations.spec.ts b/src/organizations/organizations.spec.ts index 48b0b794e..b027b4f12 100644 --- a/src/organizations/organizations.spec.ts +++ b/src/organizations/organizations.spec.ts @@ -704,4 +704,105 @@ describe('Organizations', () => { }); }); }); + + describe('getAuditLogRetention', () => { + it('returns the audit log retention for an organization', async () => { + fetchOnce({ retention_period_in_days: 365 }); + + const retention = await workos.organizations.getAuditLogRetention( + 'org_01EHT88Z8J8795GZNQ4ZP1J81T', + ); + + expect(fetchURL()).toContain( + '/organizations/org_01EHT88Z8J8795GZNQ4ZP1J81T/audit_logs_retention', + ); + expect(retention).toEqual({ + retentionPeriodInDays: 365, + }); + }); + }); + + describe('setAuditLogRetention', () => { + it('sets the audit log retention for an organization', async () => { + fetchOnce({ retention_period_in_days: 30 }); + + const retention = await workos.organizations.setAuditLogRetention({ + organizationId: 'org_01EHT88Z8J8795GZNQ4ZP1J81T', + retentionPeriodInDays: 30, + }); + + expect(fetchURL()).toContain( + '/organizations/org_01EHT88Z8J8795GZNQ4ZP1J81T/audit_logs_retention', + ); + expect(fetchBody()).toEqual({ + retention_period_in_days: 30, + }); + expect(retention).toEqual({ + retentionPeriodInDays: 30, + }); + }); + }); + + describe('getAuditLogConfiguration', () => { + describe('without a log stream', () => { + it('returns the audit log configuration for an organization', async () => { + fetchOnce({ + organization_id: 'org_01EHT88Z8J8795GZNQ4ZP1J81T', + retention_period_in_days: 365, + state: 'active', + }); + + const configuration = + await workos.organizations.getAuditLogConfiguration( + 'org_01EHT88Z8J8795GZNQ4ZP1J81T', + ); + + expect(fetchURL()).toContain( + '/organizations/org_01EHT88Z8J8795GZNQ4ZP1J81T/audit_log_configuration', + ); + expect(configuration).toEqual({ + organizationId: 'org_01EHT88Z8J8795GZNQ4ZP1J81T', + retentionPeriodInDays: 365, + state: 'active', + logStream: undefined, + }); + }); + }); + + describe('with a log stream', () => { + it('returns the audit log configuration with log stream details', async () => { + const timestamp = '2024-01-01T00:00:00.000Z'; + fetchOnce({ + organization_id: 'org_01EHT88Z8J8795GZNQ4ZP1J81T', + retention_period_in_days: 365, + state: 'active', + log_stream: { + id: 'log_stream_01ABC', + type: 'Datadog', + state: 'active', + last_synced_at: timestamp, + created_at: timestamp, + }, + }); + + const configuration = + await workos.organizations.getAuditLogConfiguration( + 'org_01EHT88Z8J8795GZNQ4ZP1J81T', + ); + + expect(configuration).toEqual({ + organizationId: 'org_01EHT88Z8J8795GZNQ4ZP1J81T', + retentionPeriodInDays: 365, + state: 'active', + logStream: { + id: 'log_stream_01ABC', + type: 'Datadog', + state: 'active', + lastSyncedAt: timestamp, + createdAt: timestamp, + }, + }); + }); + }); + }); }); diff --git a/src/organizations/organizations.ts b/src/organizations/organizations.ts index 85949a975..95a30ac18 100644 --- a/src/organizations/organizations.ts +++ b/src/organizations/organizations.ts @@ -1,11 +1,16 @@ import { AutoPaginatable } from '../common/utils/pagination'; import { WorkOS } from '../workos'; import { + AuditLogConfiguration, + AuditLogConfigurationResponse, + AuditLogRetention, + AuditLogRetentionResponse, CreateOrganizationOptions, CreateOrganizationRequestOptions, ListOrganizationsOptions, Organization, OrganizationResponse, + SetAuditLogRetentionOptions, UpdateOrganizationOptions, } from './interfaces'; import { @@ -13,6 +18,8 @@ import { FeatureFlagResponse, } from '../feature-flags/interfaces/feature-flag.interface'; import { + deserializeAuditLogConfiguration, + deserializeAuditLogRetention, deserializeOrganization, serializeCreateOrganizationOptions, serializeUpdateOrganizationOptions, @@ -187,4 +194,56 @@ export class Organizations { return deserializeCreatedApiKey(data); } + + /** + * Gets the audit log retention period for an organization. + * + * @param organizationId - The ID of the organization + * @returns The audit log retention configuration + */ + async getAuditLogRetention( + organizationId: string, + ): Promise { + const { data } = await this.workos.get( + `/organizations/${organizationId}/audit_logs_retention`, + ); + + return deserializeAuditLogRetention(data); + } + + /** + * Sets the audit log retention period for an organization. + * + * @param options - Options including organizationId and retentionPeriodInDays (30 or 365) + * @returns The updated audit log retention configuration + */ + async setAuditLogRetention( + options: SetAuditLogRetentionOptions, + ): Promise { + const { organizationId, retentionPeriodInDays } = options; + + const { data } = await this.workos.put( + `/organizations/${organizationId}/audit_logs_retention`, + { retention_period_in_days: retentionPeriodInDays }, + ); + + return deserializeAuditLogRetention(data); + } + + /** + * Gets the complete audit log configuration for an organization. + * Includes retention period, state, and optional log stream configuration. + * + * @param organizationId - The ID of the organization + * @returns The complete audit log configuration + */ + async getAuditLogConfiguration( + organizationId: string, + ): Promise { + const { data } = await this.workos.get( + `/organizations/${organizationId}/audit_log_configuration`, + ); + + return deserializeAuditLogConfiguration(data); + } } diff --git a/src/organizations/serializers/audit-log-configuration.serializer.ts b/src/organizations/serializers/audit-log-configuration.serializer.ts new file mode 100644 index 000000000..bfd63c379 --- /dev/null +++ b/src/organizations/serializers/audit-log-configuration.serializer.ts @@ -0,0 +1,44 @@ +import { + AuditLogConfiguration, + AuditLogConfigurationResponse, + AuditLogRetention, + AuditLogRetentionResponse, + AuditLogStream, + AuditLogStreamResponse, +} from '../interfaces'; + +/** + * Deserializes an audit log stream response from the API. + */ +const deserializeAuditLogStream = ( + stream: AuditLogStreamResponse, +): AuditLogStream => ({ + id: stream.id, + type: stream.type, + state: stream.state, + lastSyncedAt: stream.last_synced_at, + createdAt: stream.created_at, +}); + +/** + * Deserializes an audit log configuration response from the API. + */ +export const deserializeAuditLogConfiguration = ( + response: AuditLogConfigurationResponse, +): AuditLogConfiguration => ({ + organizationId: response.organization_id, + retentionPeriodInDays: response.retention_period_in_days, + state: response.state, + logStream: response.log_stream + ? deserializeAuditLogStream(response.log_stream) + : undefined, +}); + +/** + * Deserializes an audit log retention response from the API. + */ +export const deserializeAuditLogRetention = ( + response: AuditLogRetentionResponse, +): AuditLogRetention => ({ + retentionPeriodInDays: response.retention_period_in_days, +}); diff --git a/src/organizations/serializers/index.ts b/src/organizations/serializers/index.ts index c53e493c4..112204643 100644 --- a/src/organizations/serializers/index.ts +++ b/src/organizations/serializers/index.ts @@ -1,3 +1,4 @@ +export * from './audit-log-configuration.serializer'; export * from './create-organization-options.serializer'; export * from './organization.serializer'; export * from './update-organization-options.serializer'; From 0b3f7d04aaa7dd19710f585119da907242dac5e6 Mon Sep 17 00:00:00 2001 From: swaroopakkineni Date: Sat, 31 Jan 2026 16:39:13 -1000 Subject: [PATCH 02/17] lol --- src/audit-logs/audit-logs.spec.ts | 94 +++++++++++++++++++ src/audit-logs/audit-logs.ts | 31 ++++++ .../interfaces/audit-log-action.interface.ts | 25 +++++ src/audit-logs/interfaces/index.ts | 1 + .../audit-log-action.serializer.ts | 15 +++ src/audit-logs/serializers/index.ts | 1 + 6 files changed, 167 insertions(+) create mode 100644 src/audit-logs/interfaces/audit-log-action.interface.ts create mode 100644 src/audit-logs/serializers/audit-log-action.serializer.ts diff --git a/src/audit-logs/audit-logs.spec.ts b/src/audit-logs/audit-logs.spec.ts index 752419703..1ab4e4291 100644 --- a/src/audit-logs/audit-logs.spec.ts +++ b/src/audit-logs/audit-logs.spec.ts @@ -5,6 +5,7 @@ import { ListResponse } from '../common/interfaces'; import { mockWorkOsResponse } from '../common/utils/workos-mock-response'; import { WorkOS } from '../workos'; import { + AuditLogActionResponse, AuditLogExport, AuditLogExportOptions, AuditLogExportResponse, @@ -965,4 +966,97 @@ describe('AuditLogs', () => { }); }); }); + + describe('listActions', () => { + describe('when the api responds with a 200', () => { + it('returns a paginated list of actions', async () => { + const workosSpy = jest.spyOn(WorkOS.prototype, 'get'); + + const actionResponse: AuditLogActionResponse = { + object: 'audit_log_action', + name: 'user.logged_in', + }; + + const listResponse: ListResponse = { + object: 'list', + data: [ + actionResponse, + { object: 'audit_log_action', name: 'user.signed_out' }, + ], + list_metadata: { + before: undefined, + after: 'cursor_next', + }, + }; + + workosSpy.mockResolvedValueOnce(mockWorkOsResponse(200, listResponse)); + + const workos = new WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU'); + + const result = await workos.auditLogs.listActions(); + + expect(result.data).toHaveLength(2); + expect(result.data[0]).toEqual({ + object: 'audit_log_action', + name: 'user.logged_in', + }); + expect(result.data[1]).toEqual({ + object: 'audit_log_action', + name: 'user.signed_out', + }); + expect(result.listMetadata).toMatchObject({ + after: 'cursor_next', + }); + + expect(workosSpy).toHaveBeenCalledWith('/audit_logs/actions', { + 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.listActions({ + limit: 5, + after: 'cursor_abc', + order: 'asc', + }); + + expect(workosSpy).toHaveBeenCalledWith('/audit_logs/actions', { + query: { limit: 5, after: 'cursor_abc', order: 'asc' }, + }); + }); + }); + + 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.listActions()).rejects.toThrow( + UnauthorizedException, + ); + }); + }); + }); }); diff --git a/src/audit-logs/audit-logs.ts b/src/audit-logs/audit-logs.ts index ea3b91e89..0031948a2 100644 --- a/src/audit-logs/audit-logs.ts +++ b/src/audit-logs/audit-logs.ts @@ -3,8 +3,11 @@ import { fetchAndDeserialize } from '../common/utils/fetch-and-deserialize'; import { AutoPaginatable } from '../common/utils/pagination'; import { WorkOS } from '../workos'; import { + AuditLogAction, + AuditLogActionResponse, CreateAuditLogEventOptions, CreateAuditLogEventRequestOptions, + ListActionsOptions, ListSchemasOptions, } from './interfaces'; import { AuditLogExportOptions } from './interfaces/audit-log-export-options.interface'; @@ -19,6 +22,7 @@ import { CreateAuditLogSchemaResponse, } from './interfaces/create-audit-log-schema-options.interface'; import { + deserializeAuditLogAction, deserializeAuditLogExport, serializeAuditLogExportOptions, serializeCreateAuditLogEventOptions, @@ -111,4 +115,31 @@ export class AuditLogs { options, ); } + + /** + * Lists all audit log actions in the current environment. + * + * @param options - Optional pagination parameters + * @returns A paginated list of audit log actions + */ + async listActions( + options?: ListActionsOptions, + ): Promise> { + return new AutoPaginatable( + await fetchAndDeserialize( + this.workos, + '/audit_logs/actions', + deserializeAuditLogAction, + options, + ), + (params: PaginationOptions) => + fetchAndDeserialize( + this.workos, + '/audit_logs/actions', + deserializeAuditLogAction, + params, + ), + options, + ); + } } 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..ea7d5724b --- /dev/null +++ b/src/audit-logs/interfaces/audit-log-action.interface.ts @@ -0,0 +1,25 @@ +import { PaginationOptions } from '../../common/interfaces'; + +/** + * Represents an Audit Log Action in the WorkOS system. + * Actions define the types of events that can be logged. + */ +export interface AuditLogAction { + /** The object type, always 'audit_log_action' */ + object: 'audit_log_action'; + /** The unique identifier for the action (e.g., 'user.logged_in') */ + name: string; +} + +/** + * API response format for an audit log action. + */ +export interface AuditLogActionResponse { + object: 'audit_log_action'; + name: string; +} + +/** + * Options for listing audit log actions. + */ +export type ListActionsOptions = PaginationOptions; diff --git a/src/audit-logs/interfaces/index.ts b/src/audit-logs/interfaces/index.ts index cce34fc1c..5295767b6 100644 --- a/src/audit-logs/interfaces/index.ts +++ b/src/audit-logs/interfaces/index.ts @@ -1,3 +1,4 @@ +export * from './audit-log-action.interface'; export * from './audit-log-export-options.interface'; export * from './audit-log-export.interface'; export * from './create-audit-log-event-options.interface'; 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..a92b9999f --- /dev/null +++ b/src/audit-logs/serializers/audit-log-action.serializer.ts @@ -0,0 +1,15 @@ +import { + AuditLogAction, + AuditLogActionResponse, +} from '../interfaces/audit-log-action.interface'; + +/** + * Deserializes an audit log action response from the API. + * The API response is already in the correct format, so this is a simple passthrough. + */ +export const deserializeAuditLogAction = ( + response: AuditLogActionResponse, +): AuditLogAction => ({ + object: response.object, + name: response.name, +}); diff --git a/src/audit-logs/serializers/index.ts b/src/audit-logs/serializers/index.ts index c208debee..4e5ec98f3 100644 --- a/src/audit-logs/serializers/index.ts +++ b/src/audit-logs/serializers/index.ts @@ -1,3 +1,4 @@ +export * from './audit-log-action.serializer'; export * from './audit-log-export.serializer'; export * from './audit-log-export-options.serializer'; export * from './create-audit-log-event-options.serializer'; From c155b07bf62ea95397dc671a916b63b3d43a0f9a Mon Sep 17 00:00:00 2001 From: swaroopakkineni Date: Sat, 31 Jan 2026 21:20:23 -1000 Subject: [PATCH 03/17] lol --- package-lock.json | 13 ------------- package.json | 1 - 2 files changed, 14 deletions(-) diff --git a/package-lock.json b/package-lock.json index a7d1c3478..babb4565d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,6 @@ "version": "8.0.0", "license": "MIT", "dependencies": { - "@workos-inc/node": "^8.0.0", "iron-webcrypto": "^2.0.0", "jose": "~6.1.0" }, @@ -5021,18 +5020,6 @@ "win32" ] }, - "node_modules/@workos-inc/node": { - "version": "8.0.0", - "resolved": "https://registry.npmjs.org/@workos-inc/node/-/node-8.0.0.tgz", - "integrity": "sha512-D8VDfx0GXeiVm8vccAl0rElW7taebRnrteKPJzZwehwzI9W/Usa4qKfmwxj+7Lh1Z1deEocDRCpZpV7ml4GpWQ==", - "dependencies": { - "iron-webcrypto": "^2.0.0", - "jose": "~6.1.0" - }, - "engines": { - "node": ">=20.15.0" - } - }, "node_modules/acorn": { "version": "8.15.0", "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.15.0.tgz", diff --git a/package.json b/package.json index 7f7a2e34f..0f989dd51 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,6 @@ "typecheck": "tsc --noEmit" }, "dependencies": { - "@workos-inc/node": "^8.0.0", "iron-webcrypto": "^2.0.0", "jose": "~6.1.0" }, From 64dee8d33c1c8b6de7901783a9be70930c426d40 Mon Sep 17 00:00:00 2001 From: swaroopakkineni Date: Sat, 31 Jan 2026 22:28:23 -1000 Subject: [PATCH 04/17] moar --- src/audit-logs/audit-logs.spec.ts | 257 ++++-------------- src/audit-logs/audit-logs.ts | 57 ++-- .../interfaces/audit-log-action.interface.ts | 25 -- ...eate-audit-log-schema-options.interface.ts | 77 +++--- src/audit-logs/interfaces/index.ts | 2 +- .../list-audit-log-schemas.interface.ts | 30 ++ .../audit-log-action.serializer.ts | 15 - ...ate-audit-log-schema-options.serializer.ts | 45 +-- .../create-audit-log-schema.serializer.ts | 35 +-- src/audit-logs/serializers/index.ts | 2 +- .../list-audit-log-schema.serializer.ts | 15 + .../audit-log-configuration.interface.ts | 60 ---- .../audit-log-retention.interface.ts | 24 -- src/organizations/interfaces/index.ts | 2 - src/organizations/organizations.spec.ts | 101 ------- src/organizations/organizations.ts | 59 ---- .../audit-log-configuration.serializer.ts | 44 --- src/organizations/serializers/index.ts | 1 - 18 files changed, 160 insertions(+), 691 deletions(-) delete mode 100644 src/audit-logs/interfaces/audit-log-action.interface.ts create mode 100644 src/audit-logs/interfaces/list-audit-log-schemas.interface.ts delete mode 100644 src/audit-logs/serializers/audit-log-action.serializer.ts create mode 100644 src/audit-logs/serializers/list-audit-log-schema.serializer.ts delete mode 100644 src/organizations/interfaces/audit-log-configuration.interface.ts delete mode 100644 src/organizations/interfaces/audit-log-retention.interface.ts delete mode 100644 src/organizations/serializers/audit-log-configuration.serializer.ts diff --git a/src/audit-logs/audit-logs.spec.ts b/src/audit-logs/audit-logs.spec.ts index 1ab4e4291..b4c45ac28 100644 --- a/src/audit-logs/audit-logs.spec.ts +++ b/src/audit-logs/audit-logs.spec.ts @@ -5,7 +5,6 @@ import { ListResponse } from '../common/interfaces'; import { mockWorkOsResponse } from '../common/utils/workos-mock-response'; import { WorkOS } from '../workos'; import { - AuditLogActionResponse, AuditLogExport, AuditLogExportOptions, AuditLogExportResponse, @@ -13,6 +12,7 @@ import { CreateAuditLogEventOptions, CreateAuditLogSchemaOptions, CreateAuditLogSchemaResponse, + ListAuditLogSchemaItemResponse, } from './interfaces'; import { serializeAuditLogExportOptions, @@ -47,20 +47,29 @@ const schema: CreateAuditLogSchemaOptions = { action: 'user.logged_in', actor: { metadata: { - actor_id: 'string', + type: 'object', + properties: { + actor_id: { type: 'string' }, + }, }, }, targets: [ { type: 'user', metadata: { - user_id: 'string', + type: 'object', + properties: { + user_id: { type: 'string' }, + }, }, }, ], metadata: { - foo: 'number', - baz: 'boolean', + type: 'object', + properties: { + foo: { type: 'number' }, + baz: { type: 'boolean' }, + }, }, }; @@ -578,29 +587,6 @@ describe('AuditLogs', () => { 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, @@ -610,9 +596,7 @@ describe('AuditLogs', () => { metadata: { type: 'object', properties: { - user_id: { - type: 'string', - }, + user_id: { type: 'string' }, }, }, }, @@ -621,26 +605,29 @@ describe('AuditLogs', () => { metadata: { type: 'object', properties: { - actor_id: { - type: 'string', - }, + actor_id: { type: 'string' }, }, }, }, metadata: { type: 'object', properties: { - foo: { - type: 'number', - }, - baz: { - type: 'boolean', - }, + foo: { type: 'number' }, + baz: { type: 'boolean' }, }, }, created_at: time, }; + const createSchemaResult: AuditLogSchema = { + object: 'audit_log_schema', + version: 1, + targets: createSchemaResponse.targets, + actor: createSchemaResponse.actor, + metadata: createSchemaResponse.metadata, + createdAt: time, + }; + workosSpy.mockResolvedValueOnce( mockWorkOsResponse(201, createSchemaResponse), ); @@ -667,26 +654,6 @@ describe('AuditLogs', () => { 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, @@ -696,9 +663,7 @@ describe('AuditLogs', () => { metadata: { type: 'object', properties: { - user_id: { - type: 'string', - }, + user_id: { type: 'string' }, }, }, }, @@ -707,15 +672,22 @@ describe('AuditLogs', () => { metadata: { type: 'object', properties: { - actor_id: { - type: 'string', - }, + actor_id: { type: 'string' }, }, }, }, created_at: time, }; + const createSchemaResult: AuditLogSchema = { + object: 'audit_log_schema', + version: 1, + targets: createSchemaResponse.targets, + actor: createSchemaResponse.actor, + metadata: undefined, + createdAt: time, + }; + workosSpy.mockResolvedValueOnce( mockWorkOsResponse(201, createSchemaResponse), ); @@ -740,29 +712,6 @@ describe('AuditLogs', () => { 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, @@ -772,9 +721,7 @@ describe('AuditLogs', () => { metadata: { type: 'object', properties: { - user_id: { - type: 'string', - }, + user_id: { type: 'string' }, }, }, }, @@ -783,26 +730,29 @@ describe('AuditLogs', () => { metadata: { type: 'object', properties: { - actor_id: { - type: 'string', - }, + actor_id: { type: 'string' }, }, }, }, metadata: { type: 'object', properties: { - foo: { - type: 'number', - }, - baz: { - type: 'boolean', - }, + foo: { type: 'number' }, + baz: { type: 'boolean' }, }, }, created_at: time, }; + const createSchemaResult: AuditLogSchema = { + object: 'audit_log_schema', + version: 1, + targets: createSchemaResponse.targets, + actor: createSchemaResponse.actor, + metadata: createSchemaResponse.metadata, + createdAt: time, + }; + workosSpy.mockResolvedValueOnce( mockWorkOsResponse(201, createSchemaResponse), ); @@ -854,7 +804,7 @@ describe('AuditLogs', () => { const time = new Date().toISOString(); - const schemaResponse: CreateAuditLogSchemaResponse = { + const schemaResponse: ListAuditLogSchemaItemResponse = { object: 'audit_log_schema', version: 1, targets: [ @@ -885,7 +835,7 @@ describe('AuditLogs', () => { created_at: time, }; - const listResponse: ListResponse = { + const listResponse: ListResponse = { object: 'list', data: [schemaResponse], list_metadata: { @@ -906,9 +856,9 @@ describe('AuditLogs', () => { 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' }, + targets: schemaResponse.targets, + actor: schemaResponse.actor, + metadata: schemaResponse.metadata, createdAt: time, }); @@ -923,7 +873,7 @@ describe('AuditLogs', () => { it('passes pagination parameters to the API', async () => { const workosSpy = jest.spyOn(WorkOS.prototype, 'get'); - const listResponse: ListResponse = { + const listResponse: ListResponse = { object: 'list', data: [], list_metadata: { @@ -966,97 +916,4 @@ describe('AuditLogs', () => { }); }); }); - - describe('listActions', () => { - describe('when the api responds with a 200', () => { - it('returns a paginated list of actions', async () => { - const workosSpy = jest.spyOn(WorkOS.prototype, 'get'); - - const actionResponse: AuditLogActionResponse = { - object: 'audit_log_action', - name: 'user.logged_in', - }; - - const listResponse: ListResponse = { - object: 'list', - data: [ - actionResponse, - { object: 'audit_log_action', name: 'user.signed_out' }, - ], - list_metadata: { - before: undefined, - after: 'cursor_next', - }, - }; - - workosSpy.mockResolvedValueOnce(mockWorkOsResponse(200, listResponse)); - - const workos = new WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU'); - - const result = await workos.auditLogs.listActions(); - - expect(result.data).toHaveLength(2); - expect(result.data[0]).toEqual({ - object: 'audit_log_action', - name: 'user.logged_in', - }); - expect(result.data[1]).toEqual({ - object: 'audit_log_action', - name: 'user.signed_out', - }); - expect(result.listMetadata).toMatchObject({ - after: 'cursor_next', - }); - - expect(workosSpy).toHaveBeenCalledWith('/audit_logs/actions', { - 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.listActions({ - limit: 5, - after: 'cursor_abc', - order: 'asc', - }); - - expect(workosSpy).toHaveBeenCalledWith('/audit_logs/actions', { - query: { limit: 5, after: 'cursor_abc', order: 'asc' }, - }); - }); - }); - - 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.listActions()).rejects.toThrow( - UnauthorizedException, - ); - }); - }); - }); }); diff --git a/src/audit-logs/audit-logs.ts b/src/audit-logs/audit-logs.ts index 0031948a2..2a3bbe47c 100644 --- a/src/audit-logs/audit-logs.ts +++ b/src/audit-logs/audit-logs.ts @@ -3,11 +3,8 @@ import { fetchAndDeserialize } from '../common/utils/fetch-and-deserialize'; import { AutoPaginatable } from '../common/utils/pagination'; import { WorkOS } from '../workos'; import { - AuditLogAction, - AuditLogActionResponse, CreateAuditLogEventOptions, CreateAuditLogEventRequestOptions, - ListActionsOptions, ListSchemasOptions, } from './interfaces'; import { AuditLogExportOptions } from './interfaces/audit-log-export-options.interface'; @@ -22,12 +19,16 @@ import { CreateAuditLogSchemaResponse, } from './interfaces/create-audit-log-schema-options.interface'; import { - deserializeAuditLogAction, + ListAuditLogSchemaItemResponse, + ListedAuditLogSchema, +} from './interfaces/list-audit-log-schemas.interface'; +import { deserializeAuditLogExport, + deserializeAuditLogSchema, + deserializeListedAuditLogSchema, serializeAuditLogExportOptions, serializeCreateAuditLogEventOptions, serializeCreateAuditLogSchemaOptions, - deserializeAuditLogSchema, } from './serializers'; export class AuditLogs { @@ -94,51 +95,25 @@ export class AuditLogs { */ async listSchemas( options: ListSchemasOptions, - ): Promise> { + ): Promise> { const { action, ...paginationOptions } = options; const endpoint = `/audit_logs/actions/${action}/schemas`; return new AutoPaginatable( - await fetchAndDeserialize( + await fetchAndDeserialize< + ListAuditLogSchemaItemResponse, + ListedAuditLogSchema + >( this.workos, endpoint, - deserializeAuditLogSchema, + deserializeListedAuditLogSchema, paginationOptions, ), (params: PaginationOptions) => - fetchAndDeserialize( - this.workos, - endpoint, - deserializeAuditLogSchema, - params, - ), - options, - ); - } - - /** - * Lists all audit log actions in the current environment. - * - * @param options - Optional pagination parameters - * @returns A paginated list of audit log actions - */ - async listActions( - options?: ListActionsOptions, - ): Promise> { - return new AutoPaginatable( - await fetchAndDeserialize( - this.workos, - '/audit_logs/actions', - deserializeAuditLogAction, - options, - ), - (params: PaginationOptions) => - fetchAndDeserialize( - this.workos, - '/audit_logs/actions', - deserializeAuditLogAction, - params, - ), + fetchAndDeserialize< + ListAuditLogSchemaItemResponse, + ListedAuditLogSchema + >(this.workos, endpoint, deserializeListedAuditLogSchema, params), options, ); } diff --git a/src/audit-logs/interfaces/audit-log-action.interface.ts b/src/audit-logs/interfaces/audit-log-action.interface.ts deleted file mode 100644 index ea7d5724b..000000000 --- a/src/audit-logs/interfaces/audit-log-action.interface.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { PaginationOptions } from '../../common/interfaces'; - -/** - * Represents an Audit Log Action in the WorkOS system. - * Actions define the types of events that can be logged. - */ -export interface AuditLogAction { - /** The object type, always 'audit_log_action' */ - object: 'audit_log_action'; - /** The unique identifier for the action (e.g., 'user.logged_in') */ - name: string; -} - -/** - * API response format for an audit log action. - */ -export interface AuditLogActionResponse { - object: 'audit_log_action'; - name: string; -} - -/** - * Options for listing audit log actions. - */ -export type ListActionsOptions = PaginationOptions; 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 index 8f87cc02d..fe49eab8e 100644 --- a/src/audit-logs/interfaces/create-audit-log-schema-options.interface.ts +++ b/src/audit-logs/interfaces/create-audit-log-schema-options.interface.ts @@ -1,70 +1,61 @@ import { PostOptions } from '../../common/interfaces'; -export type AuditLogSchemaMetadata = - | Record - | undefined; +/** + * JSON Schema definition for metadata fields. + * This is the raw JSON schema format expected by the API. + */ +export type JsonSchemaDefinition = Record; +/** + * Audit log schema returned by the API. + */ export interface AuditLogSchema { object: 'audit_log_schema'; version: number; - targets: AuditLogTargetSchema[]; - actor: AuditLogActorSchema; - metadata: Record | undefined; + targets: AuditLogSchemaTarget[]; + actor?: AuditLogSchemaActor; + metadata?: JsonSchemaDefinition; createdAt: string; } -export interface AuditLogActorSchema { - metadata: Record; +export interface AuditLogSchemaActor { + metadata: JsonSchemaDefinition; } -export interface AuditLogTargetSchema { +export interface AuditLogSchemaTarget { type: string; - metadata?: Record | undefined; + metadata?: JsonSchemaDefinition; } +/** + * Options for creating an audit log schema. + * Metadata fields accept raw JSON schema definitions. + */ export interface CreateAuditLogSchemaOptions { action: string; - targets: AuditLogTargetSchema[]; - actor?: AuditLogActorSchema; - metadata?: Record; -} - -interface SerializedAuditLogTargetSchema { - type: string; - metadata?: { - type: 'object'; - properties: AuditLogSchemaMetadata; - }; + targets: AuditLogSchemaTarget[]; + actor?: AuditLogSchemaActor; + metadata?: JsonSchemaDefinition; } +/** + * Serialized request body sent to the API. + */ export interface SerializedCreateAuditLogSchemaOptions { - targets: SerializedAuditLogTargetSchema[]; - actor?: { - metadata: { - type: 'object'; - properties: AuditLogSchemaMetadata; - }; - }; - metadata?: { - type: 'object'; - properties: AuditLogSchemaMetadata; - }; + targets: AuditLogSchemaTarget[]; + actor?: AuditLogSchemaActor; + metadata?: JsonSchemaDefinition; } +/** + * API response for creating an audit log schema. + */ export interface CreateAuditLogSchemaResponse { object: 'audit_log_schema'; version: number; - targets: SerializedAuditLogTargetSchema[]; - actor: { - metadata: { - type: 'object'; - properties: AuditLogSchemaMetadata; - }; - }; - metadata?: { - type: 'object'; - properties: AuditLogSchemaMetadata; - }; + targets: AuditLogSchemaTarget[]; + actor?: AuditLogSchemaActor; + metadata?: JsonSchemaDefinition; created_at: string; } diff --git a/src/audit-logs/interfaces/index.ts b/src/audit-logs/interfaces/index.ts index 5295767b6..d9ef5c223 100644 --- a/src/audit-logs/interfaces/index.ts +++ b/src/audit-logs/interfaces/index.ts @@ -1,6 +1,6 @@ -export * from './audit-log-action.interface'; export * from './audit-log-export-options.interface'; export * from './audit-log-export.interface'; export * from './create-audit-log-event-options.interface'; export * from './create-audit-log-schema-options.interface'; +export * from './list-audit-log-schemas.interface'; export * from './list-schemas-options.interface'; diff --git a/src/audit-logs/interfaces/list-audit-log-schemas.interface.ts b/src/audit-logs/interfaces/list-audit-log-schemas.interface.ts new file mode 100644 index 000000000..6c9749663 --- /dev/null +++ b/src/audit-logs/interfaces/list-audit-log-schemas.interface.ts @@ -0,0 +1,30 @@ +import { + AuditLogSchemaActor, + AuditLogSchemaTarget, + JsonSchemaDefinition, +} from './create-audit-log-schema-options.interface'; + +/** + * API response for a single schema item in the list schemas endpoint. + * Note: List items use `updated_at` instead of `created_at` and don't have an `object` field. + */ +export interface ListAuditLogSchemaItemResponse { + object: 'audit_log_schema'; + version: number; + targets: AuditLogSchemaTarget[]; + actor?: AuditLogSchemaActor; + metadata?: JsonSchemaDefinition; + created_at: string; +} + +/** + * Deserialized audit log schema from the list schemas endpoint. + */ +export interface ListedAuditLogSchema { + object: 'audit_log_schema'; + version: number; + targets: AuditLogSchemaTarget[]; + actor?: AuditLogSchemaActor; + metadata?: JsonSchemaDefinition; + createdAt: string; +} diff --git a/src/audit-logs/serializers/audit-log-action.serializer.ts b/src/audit-logs/serializers/audit-log-action.serializer.ts deleted file mode 100644 index a92b9999f..000000000 --- a/src/audit-logs/serializers/audit-log-action.serializer.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { - AuditLogAction, - AuditLogActionResponse, -} from '../interfaces/audit-log-action.interface'; - -/** - * Deserializes an audit log action response from the API. - * The API response is already in the correct format, so this is a simple passthrough. - */ -export const deserializeAuditLogAction = ( - response: AuditLogActionResponse, -): AuditLogAction => ({ - object: response.object, - name: response.name, -}); 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 index edae6e509..246f154fa 100644 --- a/src/audit-logs/serializers/create-audit-log-schema-options.serializer.ts +++ b/src/audit-logs/serializers/create-audit-log-schema-options.serializer.ts @@ -1,51 +1,12 @@ 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, + targets: schema.targets, + actor: schema.actor, + metadata: schema.metadata, }); diff --git a/src/audit-logs/serializers/create-audit-log-schema.serializer.ts b/src/audit-logs/serializers/create-audit-log-schema.serializer.ts index 9b21e3dda..da7ee615b 100644 --- a/src/audit-logs/serializers/create-audit-log-schema.serializer.ts +++ b/src/audit-logs/serializers/create-audit-log-schema.serializer.ts @@ -1,41 +1,12 @@ import { AuditLogSchema, CreateAuditLogSchemaResponse } 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: CreateAuditLogSchemaResponse, ): AuditLogSchema => ({ object: auditLogSchema.object, version: auditLogSchema.version, - targets: auditLogSchema.targets.map((target) => { - return { - type: target.type, - metadata: target.metadata - ? deserializeMetadata(target.metadata) - : undefined, - }; - }), - actor: { - metadata: deserializeMetadata(auditLogSchema.actor?.metadata), - }, - metadata: auditLogSchema.metadata - ? deserializeMetadata(auditLogSchema.metadata) - : undefined, + targets: auditLogSchema.targets, + actor: auditLogSchema.actor, + metadata: auditLogSchema.metadata, createdAt: auditLogSchema.created_at, }); diff --git a/src/audit-logs/serializers/index.ts b/src/audit-logs/serializers/index.ts index 4e5ec98f3..d4ecd5d14 100644 --- a/src/audit-logs/serializers/index.ts +++ b/src/audit-logs/serializers/index.ts @@ -1,6 +1,6 @@ -export * from './audit-log-action.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 './list-audit-log-schema.serializer'; diff --git a/src/audit-logs/serializers/list-audit-log-schema.serializer.ts b/src/audit-logs/serializers/list-audit-log-schema.serializer.ts new file mode 100644 index 000000000..1a4f232c3 --- /dev/null +++ b/src/audit-logs/serializers/list-audit-log-schema.serializer.ts @@ -0,0 +1,15 @@ +import { + ListAuditLogSchemaItemResponse, + ListedAuditLogSchema, +} from '../interfaces'; + +export const deserializeListedAuditLogSchema = ( + schema: ListAuditLogSchemaItemResponse, +): ListedAuditLogSchema => ({ + object: schema.object, + version: schema.version, + targets: schema.targets, + actor: schema.actor, + metadata: schema.metadata, + createdAt: schema.created_at, +}); diff --git a/src/organizations/interfaces/audit-log-configuration.interface.ts b/src/organizations/interfaces/audit-log-configuration.interface.ts deleted file mode 100644 index 309cd8513..000000000 --- a/src/organizations/interfaces/audit-log-configuration.interface.ts +++ /dev/null @@ -1,60 +0,0 @@ -/** - * Log stream destination types for audit log forwarding. - */ -export type AuditLogStreamType = - | 'Datadog' - | 'Splunk' - | 'S3' - | 'GoogleCloudStorage' - | 'GenericHttps'; - -/** - * Audit log stream configuration. - */ -export interface AuditLogStream { - /** Unique identifier for the log stream */ - id: string; - /** Type of log stream destination */ - type: AuditLogStreamType; - /** Current state of the log stream */ - state: string; - /** ISO-8601 timestamp of last successful sync */ - lastSyncedAt: string; - /** ISO-8601 timestamp when the stream was created */ - createdAt: string; -} - -/** - * API response format for audit log stream. - */ -export interface AuditLogStreamResponse { - id: string; - type: AuditLogStreamType; - state: string; - last_synced_at: string; - created_at: string; -} - -/** - * Complete audit log configuration for an organization. - */ -export interface AuditLogConfiguration { - /** The organization ID */ - organizationId: string; - /** Number of days audit logs are retained */ - retentionPeriodInDays: number; - /** Current state of audit logging ('active', 'inactive', or 'disabled') */ - state: 'active' | 'inactive' | 'disabled'; - /** Optional log stream configuration if forwarding is enabled */ - logStream?: AuditLogStream; -} - -/** - * API response format for audit log configuration. - */ -export interface AuditLogConfigurationResponse { - organization_id: string; - retention_period_in_days: number; - state: 'active' | 'inactive' | 'disabled'; - log_stream?: AuditLogStreamResponse; -} diff --git a/src/organizations/interfaces/audit-log-retention.interface.ts b/src/organizations/interfaces/audit-log-retention.interface.ts deleted file mode 100644 index f86ff12be..000000000 --- a/src/organizations/interfaces/audit-log-retention.interface.ts +++ /dev/null @@ -1,24 +0,0 @@ -/** - * Audit log retention configuration for an organization. - */ -export interface AuditLogRetention { - /** Number of days audit logs are retained (30 or 365) */ - retentionPeriodInDays: number; -} - -/** - * API response format for audit log retention. - */ -export interface AuditLogRetentionResponse { - retention_period_in_days: number; -} - -/** - * Options for setting audit log retention for an organization. - */ -export interface SetAuditLogRetentionOptions { - /** The ID of the organization */ - organizationId: string; - /** Number of days to retain audit logs (30 or 365) */ - retentionPeriodInDays: number; -} diff --git a/src/organizations/interfaces/index.ts b/src/organizations/interfaces/index.ts index 6ad1cf3c0..d44e49367 100644 --- a/src/organizations/interfaces/index.ts +++ b/src/organizations/interfaces/index.ts @@ -1,5 +1,3 @@ -export * from './audit-log-configuration.interface'; -export * from './audit-log-retention.interface'; export * from './create-organization-options.interface'; export * from './domain-data.interface'; export * from './list-organization-feature-flags-options.interface'; diff --git a/src/organizations/organizations.spec.ts b/src/organizations/organizations.spec.ts index b027b4f12..48b0b794e 100644 --- a/src/organizations/organizations.spec.ts +++ b/src/organizations/organizations.spec.ts @@ -704,105 +704,4 @@ describe('Organizations', () => { }); }); }); - - describe('getAuditLogRetention', () => { - it('returns the audit log retention for an organization', async () => { - fetchOnce({ retention_period_in_days: 365 }); - - const retention = await workos.organizations.getAuditLogRetention( - 'org_01EHT88Z8J8795GZNQ4ZP1J81T', - ); - - expect(fetchURL()).toContain( - '/organizations/org_01EHT88Z8J8795GZNQ4ZP1J81T/audit_logs_retention', - ); - expect(retention).toEqual({ - retentionPeriodInDays: 365, - }); - }); - }); - - describe('setAuditLogRetention', () => { - it('sets the audit log retention for an organization', async () => { - fetchOnce({ retention_period_in_days: 30 }); - - const retention = await workos.organizations.setAuditLogRetention({ - organizationId: 'org_01EHT88Z8J8795GZNQ4ZP1J81T', - retentionPeriodInDays: 30, - }); - - expect(fetchURL()).toContain( - '/organizations/org_01EHT88Z8J8795GZNQ4ZP1J81T/audit_logs_retention', - ); - expect(fetchBody()).toEqual({ - retention_period_in_days: 30, - }); - expect(retention).toEqual({ - retentionPeriodInDays: 30, - }); - }); - }); - - describe('getAuditLogConfiguration', () => { - describe('without a log stream', () => { - it('returns the audit log configuration for an organization', async () => { - fetchOnce({ - organization_id: 'org_01EHT88Z8J8795GZNQ4ZP1J81T', - retention_period_in_days: 365, - state: 'active', - }); - - const configuration = - await workos.organizations.getAuditLogConfiguration( - 'org_01EHT88Z8J8795GZNQ4ZP1J81T', - ); - - expect(fetchURL()).toContain( - '/organizations/org_01EHT88Z8J8795GZNQ4ZP1J81T/audit_log_configuration', - ); - expect(configuration).toEqual({ - organizationId: 'org_01EHT88Z8J8795GZNQ4ZP1J81T', - retentionPeriodInDays: 365, - state: 'active', - logStream: undefined, - }); - }); - }); - - describe('with a log stream', () => { - it('returns the audit log configuration with log stream details', async () => { - const timestamp = '2024-01-01T00:00:00.000Z'; - fetchOnce({ - organization_id: 'org_01EHT88Z8J8795GZNQ4ZP1J81T', - retention_period_in_days: 365, - state: 'active', - log_stream: { - id: 'log_stream_01ABC', - type: 'Datadog', - state: 'active', - last_synced_at: timestamp, - created_at: timestamp, - }, - }); - - const configuration = - await workos.organizations.getAuditLogConfiguration( - 'org_01EHT88Z8J8795GZNQ4ZP1J81T', - ); - - expect(configuration).toEqual({ - organizationId: 'org_01EHT88Z8J8795GZNQ4ZP1J81T', - retentionPeriodInDays: 365, - state: 'active', - logStream: { - id: 'log_stream_01ABC', - type: 'Datadog', - state: 'active', - lastSyncedAt: timestamp, - createdAt: timestamp, - }, - }); - }); - }); - }); }); diff --git a/src/organizations/organizations.ts b/src/organizations/organizations.ts index 95a30ac18..85949a975 100644 --- a/src/organizations/organizations.ts +++ b/src/organizations/organizations.ts @@ -1,16 +1,11 @@ import { AutoPaginatable } from '../common/utils/pagination'; import { WorkOS } from '../workos'; import { - AuditLogConfiguration, - AuditLogConfigurationResponse, - AuditLogRetention, - AuditLogRetentionResponse, CreateOrganizationOptions, CreateOrganizationRequestOptions, ListOrganizationsOptions, Organization, OrganizationResponse, - SetAuditLogRetentionOptions, UpdateOrganizationOptions, } from './interfaces'; import { @@ -18,8 +13,6 @@ import { FeatureFlagResponse, } from '../feature-flags/interfaces/feature-flag.interface'; import { - deserializeAuditLogConfiguration, - deserializeAuditLogRetention, deserializeOrganization, serializeCreateOrganizationOptions, serializeUpdateOrganizationOptions, @@ -194,56 +187,4 @@ export class Organizations { return deserializeCreatedApiKey(data); } - - /** - * Gets the audit log retention period for an organization. - * - * @param organizationId - The ID of the organization - * @returns The audit log retention configuration - */ - async getAuditLogRetention( - organizationId: string, - ): Promise { - const { data } = await this.workos.get( - `/organizations/${organizationId}/audit_logs_retention`, - ); - - return deserializeAuditLogRetention(data); - } - - /** - * Sets the audit log retention period for an organization. - * - * @param options - Options including organizationId and retentionPeriodInDays (30 or 365) - * @returns The updated audit log retention configuration - */ - async setAuditLogRetention( - options: SetAuditLogRetentionOptions, - ): Promise { - const { organizationId, retentionPeriodInDays } = options; - - const { data } = await this.workos.put( - `/organizations/${organizationId}/audit_logs_retention`, - { retention_period_in_days: retentionPeriodInDays }, - ); - - return deserializeAuditLogRetention(data); - } - - /** - * Gets the complete audit log configuration for an organization. - * Includes retention period, state, and optional log stream configuration. - * - * @param organizationId - The ID of the organization - * @returns The complete audit log configuration - */ - async getAuditLogConfiguration( - organizationId: string, - ): Promise { - const { data } = await this.workos.get( - `/organizations/${organizationId}/audit_log_configuration`, - ); - - return deserializeAuditLogConfiguration(data); - } } diff --git a/src/organizations/serializers/audit-log-configuration.serializer.ts b/src/organizations/serializers/audit-log-configuration.serializer.ts deleted file mode 100644 index bfd63c379..000000000 --- a/src/organizations/serializers/audit-log-configuration.serializer.ts +++ /dev/null @@ -1,44 +0,0 @@ -import { - AuditLogConfiguration, - AuditLogConfigurationResponse, - AuditLogRetention, - AuditLogRetentionResponse, - AuditLogStream, - AuditLogStreamResponse, -} from '../interfaces'; - -/** - * Deserializes an audit log stream response from the API. - */ -const deserializeAuditLogStream = ( - stream: AuditLogStreamResponse, -): AuditLogStream => ({ - id: stream.id, - type: stream.type, - state: stream.state, - lastSyncedAt: stream.last_synced_at, - createdAt: stream.created_at, -}); - -/** - * Deserializes an audit log configuration response from the API. - */ -export const deserializeAuditLogConfiguration = ( - response: AuditLogConfigurationResponse, -): AuditLogConfiguration => ({ - organizationId: response.organization_id, - retentionPeriodInDays: response.retention_period_in_days, - state: response.state, - logStream: response.log_stream - ? deserializeAuditLogStream(response.log_stream) - : undefined, -}); - -/** - * Deserializes an audit log retention response from the API. - */ -export const deserializeAuditLogRetention = ( - response: AuditLogRetentionResponse, -): AuditLogRetention => ({ - retentionPeriodInDays: response.retention_period_in_days, -}); diff --git a/src/organizations/serializers/index.ts b/src/organizations/serializers/index.ts index 112204643..c53e493c4 100644 --- a/src/organizations/serializers/index.ts +++ b/src/organizations/serializers/index.ts @@ -1,4 +1,3 @@ -export * from './audit-log-configuration.serializer'; export * from './create-organization-options.serializer'; export * from './organization.serializer'; export * from './update-organization-options.serializer'; From 32f9bc3ee4a8f0349a842a33c4e81681d16b3e85 Mon Sep 17 00:00:00 2001 From: swaroopakkineni Date: Sat, 31 Jan 2026 22:42:13 -1000 Subject: [PATCH 05/17] moar --- src/audit-logs/audit-logs.spec.ts | 169 ++++++++++++------ ...eate-audit-log-schema-options.interface.ts | 77 ++++---- .../list-audit-log-schemas.interface.ts | 49 +++-- ...ate-audit-log-schema-options.serializer.ts | 45 ++++- .../create-audit-log-schema.serializer.ts | 35 +++- .../list-audit-log-schema.serializer.ts | 34 +++- 6 files changed, 301 insertions(+), 108 deletions(-) diff --git a/src/audit-logs/audit-logs.spec.ts b/src/audit-logs/audit-logs.spec.ts index b4c45ac28..2a16de56d 100644 --- a/src/audit-logs/audit-logs.spec.ts +++ b/src/audit-logs/audit-logs.spec.ts @@ -47,29 +47,20 @@ const schema: CreateAuditLogSchemaOptions = { action: 'user.logged_in', actor: { metadata: { - type: 'object', - properties: { - actor_id: { type: 'string' }, - }, + actor_id: 'string', }, }, targets: [ { type: 'user', metadata: { - type: 'object', - properties: { - user_id: { type: 'string' }, - }, + user_id: 'string', }, }, ], metadata: { - type: 'object', - properties: { - foo: { type: 'number' }, - baz: { type: 'boolean' }, - }, + foo: 'number', + baz: 'boolean', }, }; @@ -587,6 +578,29 @@ describe('AuditLogs', () => { 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, @@ -596,7 +610,9 @@ describe('AuditLogs', () => { metadata: { type: 'object', properties: { - user_id: { type: 'string' }, + user_id: { + type: 'string', + }, }, }, }, @@ -605,29 +621,26 @@ describe('AuditLogs', () => { metadata: { type: 'object', properties: { - actor_id: { type: 'string' }, + actor_id: { + type: 'string', + }, }, }, }, metadata: { type: 'object', properties: { - foo: { type: 'number' }, - baz: { type: 'boolean' }, + foo: { + type: 'number', + }, + baz: { + type: 'boolean', + }, }, }, created_at: time, }; - const createSchemaResult: AuditLogSchema = { - object: 'audit_log_schema', - version: 1, - targets: createSchemaResponse.targets, - actor: createSchemaResponse.actor, - metadata: createSchemaResponse.metadata, - createdAt: time, - }; - workosSpy.mockResolvedValueOnce( mockWorkOsResponse(201, createSchemaResponse), ); @@ -654,6 +667,26 @@ describe('AuditLogs', () => { 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, @@ -663,7 +696,9 @@ describe('AuditLogs', () => { metadata: { type: 'object', properties: { - user_id: { type: 'string' }, + user_id: { + type: 'string', + }, }, }, }, @@ -672,22 +707,15 @@ describe('AuditLogs', () => { metadata: { type: 'object', properties: { - actor_id: { type: 'string' }, + actor_id: { + type: 'string', + }, }, }, }, created_at: time, }; - const createSchemaResult: AuditLogSchema = { - object: 'audit_log_schema', - version: 1, - targets: createSchemaResponse.targets, - actor: createSchemaResponse.actor, - metadata: undefined, - createdAt: time, - }; - workosSpy.mockResolvedValueOnce( mockWorkOsResponse(201, createSchemaResponse), ); @@ -712,6 +740,29 @@ describe('AuditLogs', () => { 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, @@ -721,7 +772,9 @@ describe('AuditLogs', () => { metadata: { type: 'object', properties: { - user_id: { type: 'string' }, + user_id: { + type: 'string', + }, }, }, }, @@ -730,29 +783,26 @@ describe('AuditLogs', () => { metadata: { type: 'object', properties: { - actor_id: { type: 'string' }, + actor_id: { + type: 'string', + }, }, }, }, metadata: { type: 'object', properties: { - foo: { type: 'number' }, - baz: { type: 'boolean' }, + foo: { + type: 'number', + }, + baz: { + type: 'boolean', + }, }, }, created_at: time, }; - const createSchemaResult: AuditLogSchema = { - object: 'audit_log_schema', - version: 1, - targets: createSchemaResponse.targets, - actor: createSchemaResponse.actor, - metadata: createSchemaResponse.metadata, - createdAt: time, - }; - workosSpy.mockResolvedValueOnce( mockWorkOsResponse(201, createSchemaResponse), ); @@ -856,9 +906,22 @@ describe('AuditLogs', () => { expect(result.data[0]).toEqual({ object: 'audit_log_schema', version: 1, - targets: schemaResponse.targets, - actor: schemaResponse.actor, - metadata: schemaResponse.metadata, + targets: [ + { + type: 'user', + metadata: { + user_id: 'string', + }, + }, + ], + actor: { + metadata: { + actor_id: 'string', + }, + }, + metadata: { + foo: 'number', + }, createdAt: time, }); 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 index fe49eab8e..8f87cc02d 100644 --- a/src/audit-logs/interfaces/create-audit-log-schema-options.interface.ts +++ b/src/audit-logs/interfaces/create-audit-log-schema-options.interface.ts @@ -1,61 +1,70 @@ import { PostOptions } from '../../common/interfaces'; -/** - * JSON Schema definition for metadata fields. - * This is the raw JSON schema format expected by the API. - */ -export type JsonSchemaDefinition = Record; +export type AuditLogSchemaMetadata = + | Record + | undefined; -/** - * Audit log schema returned by the API. - */ export interface AuditLogSchema { object: 'audit_log_schema'; version: number; - targets: AuditLogSchemaTarget[]; - actor?: AuditLogSchemaActor; - metadata?: JsonSchemaDefinition; + targets: AuditLogTargetSchema[]; + actor: AuditLogActorSchema; + metadata: Record | undefined; createdAt: string; } -export interface AuditLogSchemaActor { - metadata: JsonSchemaDefinition; +export interface AuditLogActorSchema { + metadata: Record; } -export interface AuditLogSchemaTarget { +export interface AuditLogTargetSchema { type: string; - metadata?: JsonSchemaDefinition; + metadata?: Record | undefined; } -/** - * Options for creating an audit log schema. - * Metadata fields accept raw JSON schema definitions. - */ export interface CreateAuditLogSchemaOptions { action: string; - targets: AuditLogSchemaTarget[]; - actor?: AuditLogSchemaActor; - metadata?: JsonSchemaDefinition; + targets: AuditLogTargetSchema[]; + actor?: AuditLogActorSchema; + metadata?: Record; +} + +interface SerializedAuditLogTargetSchema { + type: string; + metadata?: { + type: 'object'; + properties: AuditLogSchemaMetadata; + }; } -/** - * Serialized request body sent to the API. - */ export interface SerializedCreateAuditLogSchemaOptions { - targets: AuditLogSchemaTarget[]; - actor?: AuditLogSchemaActor; - metadata?: JsonSchemaDefinition; + targets: SerializedAuditLogTargetSchema[]; + actor?: { + metadata: { + type: 'object'; + properties: AuditLogSchemaMetadata; + }; + }; + metadata?: { + type: 'object'; + properties: AuditLogSchemaMetadata; + }; } -/** - * API response for creating an audit log schema. - */ export interface CreateAuditLogSchemaResponse { object: 'audit_log_schema'; version: number; - targets: AuditLogSchemaTarget[]; - actor?: AuditLogSchemaActor; - metadata?: JsonSchemaDefinition; + targets: SerializedAuditLogTargetSchema[]; + actor: { + metadata: { + type: 'object'; + properties: AuditLogSchemaMetadata; + }; + }; + metadata?: { + type: 'object'; + properties: AuditLogSchemaMetadata; + }; created_at: string; } diff --git a/src/audit-logs/interfaces/list-audit-log-schemas.interface.ts b/src/audit-logs/interfaces/list-audit-log-schemas.interface.ts index 6c9749663..a361dc709 100644 --- a/src/audit-logs/interfaces/list-audit-log-schemas.interface.ts +++ b/src/audit-logs/interfaces/list-audit-log-schemas.interface.ts @@ -1,30 +1,55 @@ -import { - AuditLogSchemaActor, - AuditLogSchemaTarget, - JsonSchemaDefinition, -} from './create-audit-log-schema-options.interface'; +import { AuditLogSchemaMetadata } from './create-audit-log-schema-options.interface'; + +/** + * Target schema in the raw API response format. + */ +interface ListAuditLogSchemaTargetResponse { + type: string; + metadata?: { + type: 'object'; + properties: AuditLogSchemaMetadata; + }; +} + +/** + * Actor schema in the raw API response format. + */ +interface ListAuditLogSchemaActorResponse { + metadata: { + type: 'object'; + properties: AuditLogSchemaMetadata; + }; +} /** * API response for a single schema item in the list schemas endpoint. - * Note: List items use `updated_at` instead of `created_at` and don't have an `object` field. */ export interface ListAuditLogSchemaItemResponse { object: 'audit_log_schema'; version: number; - targets: AuditLogSchemaTarget[]; - actor?: AuditLogSchemaActor; - metadata?: JsonSchemaDefinition; + targets: ListAuditLogSchemaTargetResponse[]; + actor?: ListAuditLogSchemaActorResponse; + metadata?: { + type: 'object'; + properties: AuditLogSchemaMetadata; + }; created_at: string; } /** * Deserialized audit log schema from the list schemas endpoint. + * Uses the same deserialized format as AuditLogSchema for consistency. */ export interface ListedAuditLogSchema { object: 'audit_log_schema'; version: number; - targets: AuditLogSchemaTarget[]; - actor?: AuditLogSchemaActor; - metadata?: JsonSchemaDefinition; + targets: Array<{ + type: string; + metadata?: Record; + }>; + actor?: { + metadata: Record; + }; + metadata?: Record; createdAt: string; } 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 index 246f154fa..edae6e509 100644 --- a/src/audit-logs/serializers/create-audit-log-schema-options.serializer.ts +++ b/src/audit-logs/serializers/create-audit-log-schema-options.serializer.ts @@ -1,12 +1,51 @@ 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 => ({ - targets: schema.targets, - actor: schema.actor, - metadata: schema.metadata, + 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 index da7ee615b..9b21e3dda 100644 --- a/src/audit-logs/serializers/create-audit-log-schema.serializer.ts +++ b/src/audit-logs/serializers/create-audit-log-schema.serializer.ts @@ -1,12 +1,41 @@ import { AuditLogSchema, CreateAuditLogSchemaResponse } 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: CreateAuditLogSchemaResponse, ): AuditLogSchema => ({ object: auditLogSchema.object, version: auditLogSchema.version, - targets: auditLogSchema.targets, - actor: auditLogSchema.actor, - metadata: auditLogSchema.metadata, + targets: auditLogSchema.targets.map((target) => { + return { + type: target.type, + metadata: target.metadata + ? deserializeMetadata(target.metadata) + : undefined, + }; + }), + actor: { + metadata: deserializeMetadata(auditLogSchema.actor?.metadata), + }, + metadata: auditLogSchema.metadata + ? deserializeMetadata(auditLogSchema.metadata) + : undefined, createdAt: auditLogSchema.created_at, }); diff --git a/src/audit-logs/serializers/list-audit-log-schema.serializer.ts b/src/audit-logs/serializers/list-audit-log-schema.serializer.ts index 1a4f232c3..4cf88159e 100644 --- a/src/audit-logs/serializers/list-audit-log-schema.serializer.ts +++ b/src/audit-logs/serializers/list-audit-log-schema.serializer.ts @@ -3,13 +3,41 @@ import { ListedAuditLogSchema, } from '../interfaces'; +function deserializeMetadata(metadata?: { + type: 'object'; + properties?: Record; +}): Record | undefined { + if (!metadata || !metadata.properties) { + return undefined; + } + + const deserializedMetadata: Record = {}; + + Object.keys(metadata.properties).forEach((key) => { + if (metadata.properties) { + deserializedMetadata[key] = metadata.properties[key].type; + } + }); + + return deserializedMetadata; +} + export const deserializeListedAuditLogSchema = ( schema: ListAuditLogSchemaItemResponse, ): ListedAuditLogSchema => ({ object: schema.object, version: schema.version, - targets: schema.targets, - actor: schema.actor, - metadata: schema.metadata, + targets: schema.targets.map((target) => ({ + type: target.type, + metadata: target.metadata + ? deserializeMetadata(target.metadata) + : undefined, + })), + actor: schema.actor + ? { + metadata: deserializeMetadata(schema.actor.metadata) ?? {}, + } + : undefined, + metadata: deserializeMetadata(schema.metadata), createdAt: schema.created_at, }); From d5e63cbb719c9161e80dcba33ab8f2f21f7ce8fd Mon Sep 17 00:00:00 2001 From: swaroopakkineni Date: Mon, 2 Feb 2026 04:17:45 -1000 Subject: [PATCH 06/17] revert package-lock to main --- package-lock.json | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/package-lock.json b/package-lock.json index babb4565d..080530c53 100644 --- a/package-lock.json +++ b/package-lock.json @@ -133,6 +133,7 @@ "integrity": "sha512-e7jT4DxYvIDLk1ZHmU/m/mB19rex9sv0c2ftBtjSBv+kVM/902eh0fINUzD7UwLLNR+jU585GxUJ8/EBfAM5fw==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "@babel/code-frame": "^7.27.1", "@babel/generator": "^7.28.5", @@ -4507,6 +4508,7 @@ "integrity": "sha512-okqtOgqu2qmZJ5iN4TWlgfF171dZmx2FzdOv2K/ixL2LZWDStL8+JgQerI2sa8eAEfoydG9+0V96m7V+P8yE1Q==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "@eslint-community/regexpp": "^4.12.2", "@typescript-eslint/scope-manager": "8.52.0", @@ -4546,6 +4548,7 @@ "integrity": "sha512-iIACsx8pxRnguSYhHiMn2PvhvfpopO9FXHyn1mG5txZIsAaB6F0KwbFnUQN3KCiG3Jcuad/Cao2FAs1Wp7vAyg==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "@typescript-eslint/scope-manager": "8.52.0", "@typescript-eslint/types": "8.52.0", @@ -5026,6 +5029,7 @@ "integrity": "sha512-NZyJarBfL7nWwIq+FDL6Zp/yHEhePMNnnJ0y3qfieCrmNvYct8uvtiV41UvlSe6apAfk0fY1FbWx+NwfmpvtTg==", "dev": true, "license": "MIT", + "peer": true, "bin": { "acorn": "bin/acorn" }, @@ -5394,6 +5398,7 @@ } ], "license": "MIT", + "peer": true, "dependencies": { "baseline-browser-mapping": "^2.9.0", "caniuse-lite": "^1.0.30001759", @@ -6147,6 +6152,7 @@ "integrity": "sha512-LEyamqS7W5HB3ujJyvi0HQK/dtVINZvd5mAAp9eT5S/ujByGjiZLCzPcHVzuXbpJDJF/cxwHlfceVUDZ2lnSTw==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "@eslint-community/eslint-utils": "^4.8.0", "@eslint-community/regexpp": "^4.12.1", @@ -7223,6 +7229,7 @@ "integrity": "sha512-F26gjC0yWN8uAA5m5Ss8ZQf5nDHWGlN/xWZIh8S5SRbsEKBovwZhxGd6LJlbZYxBgCYOtreSUyb8hpXyGC5O4A==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "@jest/core": "30.2.0", "@jest/types": "30.2.0", @@ -8081,6 +8088,7 @@ "integrity": "sha512-jcByLnIFkd5gSXZmjNvS1TlmRhCXZjIzHYlaGkPlLIekG55JDR2Z4va9tZwCiP+/RDERiNhMOFu01xd6O5ct1Q==", "dev": true, "license": "MIT", + "peer": true, "bin": { "marked": "bin/marked.js" }, @@ -9093,6 +9101,7 @@ "integrity": "sha512-Qd9c2p0XKZdgT5AYd+KgAMggJ8ZmCs3JnS9PTMWkyUfteKlfmKtxJbWTHkVakxwXs1Ub7jrRYVeFeF7N0sQxyw==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "@oxc-project/types": "=0.101.0", "@rolldown/pluginutils": "1.0.0-beta.53" @@ -9766,6 +9775,7 @@ "integrity": "sha512-5gTmgEY/sqK6gFXLIsQNH19lWb4ebPDLA4SdLP7dsWkIXHWlG66oPuVvXSGFPppYZz8ZDZq0dYYrbHfBCVUb1Q==", "dev": true, "license": "MIT", + "peer": true, "engines": { "node": ">=12" }, @@ -10055,6 +10065,7 @@ "integrity": "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==", "dev": true, "license": "Apache-2.0", + "peer": true, "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" From a55e9b72214340f757aa6ba1ddaf39cd0b94795c Mon Sep 17 00:00:00 2001 From: swaroopakkineni Date: Mon, 2 Feb 2026 04:35:45 -1000 Subject: [PATCH 07/17] lol --- src/audit-logs/audit-logs.spec.ts | 104 ++++++++++++++++++ src/audit-logs/audit-logs.ts | 6 - .../list-audit-log-schema.serializer.ts | 16 +-- 3 files changed, 112 insertions(+), 14 deletions(-) diff --git a/src/audit-logs/audit-logs.spec.ts b/src/audit-logs/audit-logs.spec.ts index 2a16de56d..74d1af3c1 100644 --- a/src/audit-logs/audit-logs.spec.ts +++ b/src/audit-logs/audit-logs.spec.ts @@ -978,5 +978,109 @@ describe('AuditLogs', () => { ).rejects.toThrow(UnauthorizedException); }); }); + + 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: ListAuditLogSchemaItemResponse = { + 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({ + action: 'document.created', + }); + + 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, + }); + }); + }); + + 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: ListAuditLogSchemaItemResponse = { + object: 'audit_log_schema', + version: 2, + targets: [{ type: 'user' }], + created_at: time1, + }; + + const schemaResponse2: ListAuditLogSchemaItemResponse = { + 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({ + action: 'user.logged_in', + }); + + expect(result.data).toHaveLength(2); + expect(result.data[0].version).toBe(2); + expect(result.data[1].version).toBe(1); + expect(result.data[1].metadata).toEqual({ ip_address: 'string' }); + expect(result.listMetadata.before).toBe('cursor_before'); + expect(result.listMetadata.after).toBe('cursor_after'); + }); + }); }); }); diff --git a/src/audit-logs/audit-logs.ts b/src/audit-logs/audit-logs.ts index 2a3bbe47c..88ed5055c 100644 --- a/src/audit-logs/audit-logs.ts +++ b/src/audit-logs/audit-logs.ts @@ -87,12 +87,6 @@ export class AuditLogs { return deserializeAuditLogSchema(data); } - /** - * Lists all schemas for a specific audit log action. - * - * @param options - Options including the action identifier and pagination parameters - * @returns A paginated list of audit log schemas - */ async listSchemas( options: ListSchemasOptions, ): Promise> { diff --git a/src/audit-logs/serializers/list-audit-log-schema.serializer.ts b/src/audit-logs/serializers/list-audit-log-schema.serializer.ts index 4cf88159e..2926bf76a 100644 --- a/src/audit-logs/serializers/list-audit-log-schema.serializer.ts +++ b/src/audit-logs/serializers/list-audit-log-schema.serializer.ts @@ -23,21 +23,21 @@ function deserializeMetadata(metadata?: { } export const deserializeListedAuditLogSchema = ( - schema: ListAuditLogSchemaItemResponse, + auditLogSchema: ListAuditLogSchemaItemResponse, ): ListedAuditLogSchema => ({ - object: schema.object, - version: schema.version, - targets: schema.targets.map((target) => ({ + object: auditLogSchema.object, + version: auditLogSchema.version, + targets: auditLogSchema.targets.map((target) => ({ type: target.type, metadata: target.metadata ? deserializeMetadata(target.metadata) : undefined, })), - actor: schema.actor + actor: auditLogSchema.actor ? { - metadata: deserializeMetadata(schema.actor.metadata) ?? {}, + metadata: deserializeMetadata(auditLogSchema.actor.metadata) ?? {}, } : undefined, - metadata: deserializeMetadata(schema.metadata), - createdAt: schema.created_at, + metadata: deserializeMetadata(auditLogSchema.metadata), + createdAt: auditLogSchema.created_at, }); From 6d3cf2afeab50347fe27443c06ba915193e6bc7f Mon Sep 17 00:00:00 2001 From: swaroopakkineni Date: Mon, 2 Feb 2026 04:40:30 -1000 Subject: [PATCH 08/17] review --- src/audit-logs/audit-logs.spec.ts | 24 ++++++++++-- .../list-audit-log-schemas.interface.ts | 38 +++++++++---------- .../list-audit-log-schema.serializer.ts | 36 ++++-------------- 3 files changed, 47 insertions(+), 51 deletions(-) diff --git a/src/audit-logs/audit-logs.spec.ts b/src/audit-logs/audit-logs.spec.ts index 74d1af3c1..afb7bb13c 100644 --- a/src/audit-logs/audit-logs.spec.ts +++ b/src/audit-logs/audit-logs.spec.ts @@ -903,6 +903,7 @@ describe('AuditLogs', () => { }); expect(result.data).toHaveLength(1); + // Metadata is passed through in raw JSON Schema format expect(result.data[0]).toEqual({ object: 'audit_log_schema', version: 1, @@ -910,17 +911,26 @@ describe('AuditLogs', () => { { type: 'user', metadata: { - user_id: 'string', + type: 'object', + properties: { + user_id: { type: 'string' }, + }, }, }, ], actor: { metadata: { - actor_id: 'string', + type: 'object', + properties: { + actor_id: { type: 'string' }, + }, }, }, metadata: { - foo: 'number', + type: 'object', + properties: { + foo: { type: 'number' }, + }, }, createdAt: time, }); @@ -1077,7 +1087,13 @@ describe('AuditLogs', () => { expect(result.data).toHaveLength(2); expect(result.data[0].version).toBe(2); expect(result.data[1].version).toBe(1); - expect(result.data[1].metadata).toEqual({ ip_address: 'string' }); + // Metadata is passed through in raw JSON Schema format + expect(result.data[1].metadata).toEqual({ + type: 'object', + properties: { + ip_address: { type: 'string' }, + }, + }); expect(result.listMetadata.before).toBe('cursor_before'); expect(result.listMetadata.after).toBe('cursor_after'); }); diff --git a/src/audit-logs/interfaces/list-audit-log-schemas.interface.ts b/src/audit-logs/interfaces/list-audit-log-schemas.interface.ts index a361dc709..dcb25db9e 100644 --- a/src/audit-logs/interfaces/list-audit-log-schemas.interface.ts +++ b/src/audit-logs/interfaces/list-audit-log-schemas.interface.ts @@ -1,55 +1,55 @@ -import { AuditLogSchemaMetadata } from './create-audit-log-schema-options.interface'; +/** + * JSON Schema definition for audit log metadata fields. + * Matches the API's AuditLogJsonSchemaDefinition (io-ts UnknownRecord). + * This allows arbitrary JSON Schema structures as returned by the API. + */ +export type AuditLogJsonSchemaDefinition = Record; /** - * Target schema in the raw API response format. + * Target schema in the API response format. + * Metadata is an optional raw JSON Schema definition. */ interface ListAuditLogSchemaTargetResponse { type: string; - metadata?: { - type: 'object'; - properties: AuditLogSchemaMetadata; - }; + metadata?: AuditLogJsonSchemaDefinition; } /** - * Actor schema in the raw API response format. + * Actor schema in the API response format. + * Metadata is a required raw JSON Schema definition. */ interface ListAuditLogSchemaActorResponse { - metadata: { - type: 'object'; - properties: AuditLogSchemaMetadata; - }; + metadata: AuditLogJsonSchemaDefinition; } /** * API response for a single schema item in the list schemas endpoint. + * Matches the AuditLogSchema type from api-json-models/rest-api/audit-log-schema.ts */ export interface ListAuditLogSchemaItemResponse { object: 'audit_log_schema'; version: number; targets: ListAuditLogSchemaTargetResponse[]; actor?: ListAuditLogSchemaActorResponse; - metadata?: { - type: 'object'; - properties: AuditLogSchemaMetadata; - }; + metadata?: AuditLogJsonSchemaDefinition; created_at: string; } /** * Deserialized audit log schema from the list schemas endpoint. - * Uses the same deserialized format as AuditLogSchema for consistency. + * Preserves the raw JSON Schema format for metadata fields to maintain + * full fidelity with the API response. */ export interface ListedAuditLogSchema { object: 'audit_log_schema'; version: number; targets: Array<{ type: string; - metadata?: Record; + metadata?: AuditLogJsonSchemaDefinition; }>; actor?: { - metadata: Record; + metadata: AuditLogJsonSchemaDefinition; }; - metadata?: Record; + metadata?: AuditLogJsonSchemaDefinition; createdAt: string; } diff --git a/src/audit-logs/serializers/list-audit-log-schema.serializer.ts b/src/audit-logs/serializers/list-audit-log-schema.serializer.ts index 2926bf76a..9cb45a676 100644 --- a/src/audit-logs/serializers/list-audit-log-schema.serializer.ts +++ b/src/audit-logs/serializers/list-audit-log-schema.serializer.ts @@ -3,25 +3,11 @@ import { ListedAuditLogSchema, } from '../interfaces'; -function deserializeMetadata(metadata?: { - type: 'object'; - properties?: Record; -}): Record | undefined { - if (!metadata || !metadata.properties) { - return undefined; - } - - const deserializedMetadata: Record = {}; - - Object.keys(metadata.properties).forEach((key) => { - if (metadata.properties) { - deserializedMetadata[key] = metadata.properties[key].type; - } - }); - - return deserializedMetadata; -} - +/** + * Deserializes an audit log schema from the list schemas API response. + * Converts snake_case fields to camelCase while preserving metadata + * in its raw JSON Schema format. + */ export const deserializeListedAuditLogSchema = ( auditLogSchema: ListAuditLogSchemaItemResponse, ): ListedAuditLogSchema => ({ @@ -29,15 +15,9 @@ export const deserializeListedAuditLogSchema = ( version: auditLogSchema.version, targets: auditLogSchema.targets.map((target) => ({ type: target.type, - metadata: target.metadata - ? deserializeMetadata(target.metadata) - : undefined, + metadata: target.metadata, })), - actor: auditLogSchema.actor - ? { - metadata: deserializeMetadata(auditLogSchema.actor.metadata) ?? {}, - } - : undefined, - metadata: deserializeMetadata(auditLogSchema.metadata), + actor: auditLogSchema.actor, + metadata: auditLogSchema.metadata, createdAt: auditLogSchema.created_at, }); From e4ae74986f88a9afb4725629d289f5f17a85488b Mon Sep 17 00:00:00 2001 From: swaroopakkineni Date: Mon, 2 Feb 2026 04:55:26 -1000 Subject: [PATCH 09/17] moar --- src/audit-logs/audit-logs.spec.ts | 50 +++++------------ src/audit-logs/audit-logs.ts | 30 ++++------ ...rface.ts => audit-log-schema.interface.ts} | 11 ++-- src/audit-logs/interfaces/index.ts | 3 +- .../list-audit-log-schemas.interface.ts | 55 ------------------- .../create-audit-log-schema.serializer.ts | 24 ++++---- src/audit-logs/serializers/index.ts | 1 - .../list-audit-log-schema.serializer.ts | 23 -------- 8 files changed, 46 insertions(+), 151 deletions(-) rename src/audit-logs/interfaces/{create-audit-log-schema-options.interface.ts => audit-log-schema.interface.ts} (85%) delete mode 100644 src/audit-logs/interfaces/list-audit-log-schemas.interface.ts delete mode 100644 src/audit-logs/serializers/list-audit-log-schema.serializer.ts diff --git a/src/audit-logs/audit-logs.spec.ts b/src/audit-logs/audit-logs.spec.ts index afb7bb13c..c27dc9cc0 100644 --- a/src/audit-logs/audit-logs.spec.ts +++ b/src/audit-logs/audit-logs.spec.ts @@ -9,10 +9,10 @@ import { AuditLogExportOptions, AuditLogExportResponse, AuditLogSchema, + AuditLogSchemaResponse, CreateAuditLogEventOptions, CreateAuditLogSchemaOptions, CreateAuditLogSchemaResponse, - ListAuditLogSchemaItemResponse, } from './interfaces'; import { serializeAuditLogExportOptions, @@ -854,7 +854,7 @@ describe('AuditLogs', () => { const time = new Date().toISOString(); - const schemaResponse: ListAuditLogSchemaItemResponse = { + const schemaResponse: AuditLogSchemaResponse = { object: 'audit_log_schema', version: 1, targets: [ @@ -885,7 +885,7 @@ describe('AuditLogs', () => { created_at: time, }; - const listResponse: ListResponse = { + const listResponse: ListResponse = { object: 'list', data: [schemaResponse], list_metadata: { @@ -903,35 +903,20 @@ describe('AuditLogs', () => { }); expect(result.data).toHaveLength(1); - // Metadata is passed through in raw JSON Schema format + // Metadata is deserialized to simplified format (same as createSchema) expect(result.data[0]).toEqual({ object: 'audit_log_schema', version: 1, targets: [ { type: 'user', - metadata: { - type: 'object', - properties: { - user_id: { type: 'string' }, - }, - }, + metadata: { user_id: 'string' }, }, ], actor: { - metadata: { - type: 'object', - properties: { - actor_id: { type: 'string' }, - }, - }, - }, - metadata: { - type: 'object', - properties: { - foo: { type: 'number' }, - }, + metadata: { actor_id: 'string' }, }, + metadata: { foo: 'number' }, createdAt: time, }); @@ -946,7 +931,7 @@ describe('AuditLogs', () => { it('passes pagination parameters to the API', async () => { const workosSpy = jest.spyOn(WorkOS.prototype, 'get'); - const listResponse: ListResponse = { + const listResponse: ListResponse = { object: 'list', data: [], list_metadata: { @@ -995,7 +980,7 @@ describe('AuditLogs', () => { const time = new Date().toISOString(); - const schemaResponse: ListAuditLogSchemaItemResponse = { + const schemaResponse: AuditLogSchemaResponse = { object: 'audit_log_schema', version: 1, targets: [ @@ -1006,7 +991,7 @@ describe('AuditLogs', () => { created_at: time, }; - const listResponse: ListResponse = { + const listResponse: ListResponse = { object: 'list', data: [schemaResponse], list_metadata: { @@ -1047,14 +1032,14 @@ describe('AuditLogs', () => { const time1 = new Date().toISOString(); const time2 = new Date(Date.now() - 1000).toISOString(); - const schemaResponse1: ListAuditLogSchemaItemResponse = { + const schemaResponse1: AuditLogSchemaResponse = { object: 'audit_log_schema', version: 2, targets: [{ type: 'user' }], created_at: time1, }; - const schemaResponse2: ListAuditLogSchemaItemResponse = { + const schemaResponse2: AuditLogSchemaResponse = { object: 'audit_log_schema', version: 1, targets: [{ type: 'user' }], @@ -1067,7 +1052,7 @@ describe('AuditLogs', () => { created_at: time2, }; - const listResponse: ListResponse = { + const listResponse: ListResponse = { object: 'list', data: [schemaResponse1, schemaResponse2], list_metadata: { @@ -1087,13 +1072,8 @@ describe('AuditLogs', () => { expect(result.data).toHaveLength(2); expect(result.data[0].version).toBe(2); expect(result.data[1].version).toBe(1); - // Metadata is passed through in raw JSON Schema format - expect(result.data[1].metadata).toEqual({ - type: 'object', - properties: { - ip_address: { type: 'string' }, - }, - }); + // 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'); }); diff --git a/src/audit-logs/audit-logs.ts b/src/audit-logs/audit-logs.ts index 88ed5055c..59a33c812 100644 --- a/src/audit-logs/audit-logs.ts +++ b/src/audit-logs/audit-logs.ts @@ -14,18 +14,13 @@ import { } from './interfaces/audit-log-export.interface'; import { AuditLogSchema, + AuditLogSchemaResponse, CreateAuditLogSchemaOptions, CreateAuditLogSchemaRequestOptions, - CreateAuditLogSchemaResponse, -} from './interfaces/create-audit-log-schema-options.interface'; -import { - ListAuditLogSchemaItemResponse, - ListedAuditLogSchema, -} from './interfaces/list-audit-log-schemas.interface'; +} from './interfaces/audit-log-schema.interface'; import { deserializeAuditLogExport, deserializeAuditLogSchema, - deserializeListedAuditLogSchema, serializeAuditLogExportOptions, serializeCreateAuditLogEventOptions, serializeCreateAuditLogSchemaOptions, @@ -78,7 +73,7 @@ export class AuditLogs { schema: CreateAuditLogSchemaOptions, options: CreateAuditLogSchemaRequestOptions = {}, ): Promise { - const { data } = await this.workos.post( + const { data } = await this.workos.post( `/audit_logs/actions/${schema.action}/schemas`, serializeCreateAuditLogSchemaOptions(schema), options, @@ -89,25 +84,24 @@ export class AuditLogs { async listSchemas( options: ListSchemasOptions, - ): Promise> { + ): Promise> { const { action, ...paginationOptions } = options; const endpoint = `/audit_logs/actions/${action}/schemas`; return new AutoPaginatable( - await fetchAndDeserialize< - ListAuditLogSchemaItemResponse, - ListedAuditLogSchema - >( + await fetchAndDeserialize( this.workos, endpoint, - deserializeListedAuditLogSchema, + deserializeAuditLogSchema, paginationOptions, ), (params: PaginationOptions) => - fetchAndDeserialize< - ListAuditLogSchemaItemResponse, - ListedAuditLogSchema - >(this.workos, endpoint, deserializeListedAuditLogSchema, params), + fetchAndDeserialize( + this.workos, + endpoint, + deserializeAuditLogSchema, + params, + ), options, ); } diff --git a/src/audit-logs/interfaces/create-audit-log-schema-options.interface.ts b/src/audit-logs/interfaces/audit-log-schema.interface.ts similarity index 85% rename from src/audit-logs/interfaces/create-audit-log-schema-options.interface.ts rename to src/audit-logs/interfaces/audit-log-schema.interface.ts index 8f87cc02d..63371f0b0 100644 --- a/src/audit-logs/interfaces/create-audit-log-schema-options.interface.ts +++ b/src/audit-logs/interfaces/audit-log-schema.interface.ts @@ -8,8 +8,8 @@ export interface AuditLogSchema { object: 'audit_log_schema'; version: number; targets: AuditLogTargetSchema[]; - actor: AuditLogActorSchema; - metadata: Record | undefined; + actor?: AuditLogActorSchema; + metadata?: Record; createdAt: string; } @@ -51,11 +51,11 @@ export interface SerializedCreateAuditLogSchemaOptions { }; } -export interface CreateAuditLogSchemaResponse { +export interface AuditLogSchemaResponse { object: 'audit_log_schema'; version: number; targets: SerializedAuditLogTargetSchema[]; - actor: { + actor?: { metadata: { type: 'object'; properties: AuditLogSchemaMetadata; @@ -68,6 +68,9 @@ export interface CreateAuditLogSchemaResponse { created_at: string; } +/** @deprecated Use AuditLogSchemaResponse instead */ +export type CreateAuditLogSchemaResponse = AuditLogSchemaResponse; + export type CreateAuditLogSchemaRequestOptions = Pick< PostOptions, 'idempotencyKey' diff --git a/src/audit-logs/interfaces/index.ts b/src/audit-logs/interfaces/index.ts index d9ef5c223..f41b74501 100644 --- a/src/audit-logs/interfaces/index.ts +++ b/src/audit-logs/interfaces/index.ts @@ -1,6 +1,5 @@ export * from './audit-log-export-options.interface'; export * from './audit-log-export.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 './list-audit-log-schemas.interface'; export * from './list-schemas-options.interface'; diff --git a/src/audit-logs/interfaces/list-audit-log-schemas.interface.ts b/src/audit-logs/interfaces/list-audit-log-schemas.interface.ts deleted file mode 100644 index dcb25db9e..000000000 --- a/src/audit-logs/interfaces/list-audit-log-schemas.interface.ts +++ /dev/null @@ -1,55 +0,0 @@ -/** - * JSON Schema definition for audit log metadata fields. - * Matches the API's AuditLogJsonSchemaDefinition (io-ts UnknownRecord). - * This allows arbitrary JSON Schema structures as returned by the API. - */ -export type AuditLogJsonSchemaDefinition = Record; - -/** - * Target schema in the API response format. - * Metadata is an optional raw JSON Schema definition. - */ -interface ListAuditLogSchemaTargetResponse { - type: string; - metadata?: AuditLogJsonSchemaDefinition; -} - -/** - * Actor schema in the API response format. - * Metadata is a required raw JSON Schema definition. - */ -interface ListAuditLogSchemaActorResponse { - metadata: AuditLogJsonSchemaDefinition; -} - -/** - * API response for a single schema item in the list schemas endpoint. - * Matches the AuditLogSchema type from api-json-models/rest-api/audit-log-schema.ts - */ -export interface ListAuditLogSchemaItemResponse { - object: 'audit_log_schema'; - version: number; - targets: ListAuditLogSchemaTargetResponse[]; - actor?: ListAuditLogSchemaActorResponse; - metadata?: AuditLogJsonSchemaDefinition; - created_at: string; -} - -/** - * Deserialized audit log schema from the list schemas endpoint. - * Preserves the raw JSON Schema format for metadata fields to maintain - * full fidelity with the API response. - */ -export interface ListedAuditLogSchema { - object: 'audit_log_schema'; - version: number; - targets: Array<{ - type: string; - metadata?: AuditLogJsonSchemaDefinition; - }>; - actor?: { - metadata: AuditLogJsonSchemaDefinition; - }; - metadata?: AuditLogJsonSchemaDefinition; - createdAt: string; -} diff --git a/src/audit-logs/serializers/create-audit-log-schema.serializer.ts b/src/audit-logs/serializers/create-audit-log-schema.serializer.ts index 9b21e3dda..e2950040c 100644 --- a/src/audit-logs/serializers/create-audit-log-schema.serializer.ts +++ b/src/audit-logs/serializers/create-audit-log-schema.serializer.ts @@ -1,4 +1,4 @@ -import { AuditLogSchema, CreateAuditLogSchemaResponse } from '../interfaces'; +import { AuditLogSchema, AuditLogSchemaResponse } from '../interfaces'; function deserializeMetadata(metadata: { properties?: Record; @@ -19,21 +19,19 @@ function deserializeMetadata(metadata: { } export const deserializeAuditLogSchema = ( - auditLogSchema: CreateAuditLogSchemaResponse, + auditLogSchema: AuditLogSchemaResponse, ): AuditLogSchema => ({ object: auditLogSchema.object, version: auditLogSchema.version, - targets: auditLogSchema.targets.map((target) => { - return { - type: target.type, - metadata: target.metadata - ? deserializeMetadata(target.metadata) - : undefined, - }; - }), - actor: { - metadata: deserializeMetadata(auditLogSchema.actor?.metadata), - }, + 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, diff --git a/src/audit-logs/serializers/index.ts b/src/audit-logs/serializers/index.ts index d4ecd5d14..c208debee 100644 --- a/src/audit-logs/serializers/index.ts +++ b/src/audit-logs/serializers/index.ts @@ -3,4 +3,3 @@ 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 './list-audit-log-schema.serializer'; diff --git a/src/audit-logs/serializers/list-audit-log-schema.serializer.ts b/src/audit-logs/serializers/list-audit-log-schema.serializer.ts deleted file mode 100644 index 9cb45a676..000000000 --- a/src/audit-logs/serializers/list-audit-log-schema.serializer.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { - ListAuditLogSchemaItemResponse, - ListedAuditLogSchema, -} from '../interfaces'; - -/** - * Deserializes an audit log schema from the list schemas API response. - * Converts snake_case fields to camelCase while preserving metadata - * in its raw JSON Schema format. - */ -export const deserializeListedAuditLogSchema = ( - auditLogSchema: ListAuditLogSchemaItemResponse, -): ListedAuditLogSchema => ({ - object: auditLogSchema.object, - version: auditLogSchema.version, - targets: auditLogSchema.targets.map((target) => ({ - type: target.type, - metadata: target.metadata, - })), - actor: auditLogSchema.actor, - metadata: auditLogSchema.metadata, - createdAt: auditLogSchema.created_at, -}); From 276770717d56c904e62c07d93c2d802f5bd7100f Mon Sep 17 00:00:00 2001 From: swaroopakkineni Date: Mon, 2 Feb 2026 05:03:49 -1000 Subject: [PATCH 10/17] lol --- src/audit-logs/audit-logs.spec.ts | 7 +++---- src/audit-logs/interfaces/audit-log-schema.interface.ts | 3 --- .../interfaces/list-schemas-options.interface.ts | 5 ----- 3 files changed, 3 insertions(+), 12 deletions(-) diff --git a/src/audit-logs/audit-logs.spec.ts b/src/audit-logs/audit-logs.spec.ts index c27dc9cc0..f2afddf17 100644 --- a/src/audit-logs/audit-logs.spec.ts +++ b/src/audit-logs/audit-logs.spec.ts @@ -12,7 +12,6 @@ import { AuditLogSchemaResponse, CreateAuditLogEventOptions, CreateAuditLogSchemaOptions, - CreateAuditLogSchemaResponse, } from './interfaces'; import { serializeAuditLogExportOptions, @@ -601,7 +600,7 @@ describe('AuditLogs', () => { createdAt: time, }; - const createSchemaResponse: CreateAuditLogSchemaResponse = { + const createSchemaResponse: AuditLogSchemaResponse = { object: 'audit_log_schema', version: 1, targets: [ @@ -687,7 +686,7 @@ describe('AuditLogs', () => { createdAt: time, }; - const createSchemaResponse: CreateAuditLogSchemaResponse = { + const createSchemaResponse: AuditLogSchemaResponse = { object: 'audit_log_schema', version: 1, targets: [ @@ -763,7 +762,7 @@ describe('AuditLogs', () => { createdAt: time, }; - const createSchemaResponse: CreateAuditLogSchemaResponse = { + const createSchemaResponse: AuditLogSchemaResponse = { object: 'audit_log_schema', version: 1, targets: [ diff --git a/src/audit-logs/interfaces/audit-log-schema.interface.ts b/src/audit-logs/interfaces/audit-log-schema.interface.ts index 63371f0b0..5aa132ba0 100644 --- a/src/audit-logs/interfaces/audit-log-schema.interface.ts +++ b/src/audit-logs/interfaces/audit-log-schema.interface.ts @@ -68,9 +68,6 @@ export interface AuditLogSchemaResponse { created_at: string; } -/** @deprecated Use AuditLogSchemaResponse instead */ -export type CreateAuditLogSchemaResponse = AuditLogSchemaResponse; - export type CreateAuditLogSchemaRequestOptions = Pick< PostOptions, 'idempotencyKey' diff --git a/src/audit-logs/interfaces/list-schemas-options.interface.ts b/src/audit-logs/interfaces/list-schemas-options.interface.ts index 27963c89d..bae771b7f 100644 --- a/src/audit-logs/interfaces/list-schemas-options.interface.ts +++ b/src/audit-logs/interfaces/list-schemas-options.interface.ts @@ -1,9 +1,4 @@ import { PaginationOptions } from '../../common/interfaces'; - -/** - * Options for listing audit log schemas for a specific action. - */ export interface ListSchemasOptions extends PaginationOptions { - /** The action identifier (e.g., 'user.logged_in') */ action: string; } From ddb4337ba17254e49c55db66c1e4a111a7d5a556 Mon Sep 17 00:00:00 2001 From: swaroopakkineni Date: Mon, 2 Feb 2026 05:07:15 -1000 Subject: [PATCH 11/17] lol --- src/audit-logs/interfaces/audit-log-schema.interface.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/audit-logs/interfaces/audit-log-schema.interface.ts b/src/audit-logs/interfaces/audit-log-schema.interface.ts index 5aa132ba0..979b03e5f 100644 --- a/src/audit-logs/interfaces/audit-log-schema.interface.ts +++ b/src/audit-logs/interfaces/audit-log-schema.interface.ts @@ -8,8 +8,8 @@ export interface AuditLogSchema { object: 'audit_log_schema'; version: number; targets: AuditLogTargetSchema[]; - actor?: AuditLogActorSchema; - metadata?: Record; + actor: AuditLogActorSchema | undefined; + metadata: Record | undefined; createdAt: string; } From f325b7ec86f8377dd42b7c284796235b98c86e36 Mon Sep 17 00:00:00 2001 From: swaroopakkineni Date: Mon, 2 Feb 2026 07:56:42 -1000 Subject: [PATCH 12/17] lol --- src/audit-logs/audit-logs.ts | 9 ++- .../interfaces/audit-log-schema.interface.ts | 42 +++---------- ...eate-audit-log-schema-options.interface.ts | 60 +++++++++++++++++++ src/audit-logs/interfaces/index.ts | 1 + 4 files changed, 74 insertions(+), 38 deletions(-) create mode 100644 src/audit-logs/interfaces/create-audit-log-schema-options.interface.ts diff --git a/src/audit-logs/audit-logs.ts b/src/audit-logs/audit-logs.ts index 59a33c812..84121c0bf 100644 --- a/src/audit-logs/audit-logs.ts +++ b/src/audit-logs/audit-logs.ts @@ -15,9 +15,12 @@ import { import { AuditLogSchema, AuditLogSchemaResponse, - CreateAuditLogSchemaOptions, - CreateAuditLogSchemaRequestOptions, } from './interfaces/audit-log-schema.interface'; +import { + CreateAuditLogSchemaResponse, + CreateAuditLogSchemaRequestOptions, + CreateAuditLogSchemaOptions +} from './interfaces/create-audit-log-schema-options.interface'; import { deserializeAuditLogExport, deserializeAuditLogSchema, @@ -73,7 +76,7 @@ export class AuditLogs { schema: CreateAuditLogSchemaOptions, options: CreateAuditLogSchemaRequestOptions = {}, ): Promise { - const { data } = await this.workos.post( + const { data } = await this.workos.post( `/audit_logs/actions/${schema.action}/schemas`, serializeCreateAuditLogSchemaOptions(schema), options, diff --git a/src/audit-logs/interfaces/audit-log-schema.interface.ts b/src/audit-logs/interfaces/audit-log-schema.interface.ts index 979b03e5f..ff2b4ac47 100644 --- a/src/audit-logs/interfaces/audit-log-schema.interface.ts +++ b/src/audit-logs/interfaces/audit-log-schema.interface.ts @@ -1,32 +1,23 @@ -import { PostOptions } from '../../common/interfaces'; - export type AuditLogSchemaMetadata = | Record | undefined; -export interface AuditLogSchema { - object: 'audit_log_schema'; - version: number; - targets: AuditLogTargetSchema[]; - actor: AuditLogActorSchema | undefined; - metadata: Record | undefined; - createdAt: string; -} - export interface AuditLogActorSchema { metadata: Record; } export interface AuditLogTargetSchema { type: string; - metadata?: Record | undefined; + metadata?: Record; } -export interface CreateAuditLogSchemaOptions { - action: string; +export interface AuditLogSchema { + object: 'audit_log_schema'; + version: number; targets: AuditLogTargetSchema[]; - actor?: AuditLogActorSchema; - metadata?: Record; + actor: AuditLogActorSchema | undefined; + metadata: Record | undefined; + createdAt: string; } interface SerializedAuditLogTargetSchema { @@ -37,20 +28,6 @@ interface SerializedAuditLogTargetSchema { }; } -export interface SerializedCreateAuditLogSchemaOptions { - targets: SerializedAuditLogTargetSchema[]; - actor?: { - metadata: { - type: 'object'; - properties: AuditLogSchemaMetadata; - }; - }; - metadata?: { - type: 'object'; - properties: AuditLogSchemaMetadata; - }; -} - export interface AuditLogSchemaResponse { object: 'audit_log_schema'; version: number; @@ -67,8 +44,3 @@ export interface AuditLogSchemaResponse { }; created_at: string; } - -export type CreateAuditLogSchemaRequestOptions = 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 new file mode 100644 index 000000000..7bbab2a89 --- /dev/null +++ b/src/audit-logs/interfaces/create-audit-log-schema-options.interface.ts @@ -0,0 +1,60 @@ +import { PostOptions } from '../../common/interfaces'; + +// Re-export common types for backward compatibility +export { + AuditLogSchema, + AuditLogSchemaResponse, + AuditLogSchemaMetadata, + AuditLogActorSchema, + AuditLogTargetSchema, +} from './audit-log-schema.interface'; + +import type { + AuditLogSchemaMetadata, + AuditLogSchemaResponse, + AuditLogActorSchema, + AuditLogTargetSchema, +} from './audit-log-schema.interface'; + +/** + * Options for creating a new audit log schema. + */ +export interface CreateAuditLogSchemaOptions { + action: string; + targets: AuditLogTargetSchema[]; + actor?: AuditLogActorSchema; + metadata?: Record; +} + +interface SerializedAuditLogTargetSchema { + type: string; + metadata?: { + type: 'object'; + properties: AuditLogSchemaMetadata; + }; +} + +/** + * Serialized format for creating audit log schema (sent to API). + */ +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/index.ts b/src/audit-logs/interfaces/index.ts index f41b74501..274427a46 100644 --- a/src/audit-logs/interfaces/index.ts +++ b/src/audit-logs/interfaces/index.ts @@ -2,4 +2,5 @@ export * from './audit-log-export-options.interface'; export * from './audit-log-export.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 './list-schemas-options.interface'; From 1b36ea28065d2b8d94da09633dea59544a2553c9 Mon Sep 17 00:00:00 2001 From: swaroopakkineni Date: Mon, 2 Feb 2026 08:02:45 -1000 Subject: [PATCH 13/17] moar --- .../create-audit-log-schema-options.interface.ts | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) 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 index 7bbab2a89..c7004e2dd 100644 --- a/src/audit-logs/interfaces/create-audit-log-schema-options.interface.ts +++ b/src/audit-logs/interfaces/create-audit-log-schema-options.interface.ts @@ -1,7 +1,6 @@ import { PostOptions } from '../../common/interfaces'; -// Re-export common types for backward compatibility -export { +export type { AuditLogSchema, AuditLogSchemaResponse, AuditLogSchemaMetadata, @@ -16,9 +15,6 @@ import type { AuditLogTargetSchema, } from './audit-log-schema.interface'; -/** - * Options for creating a new audit log schema. - */ export interface CreateAuditLogSchemaOptions { action: string; targets: AuditLogTargetSchema[]; @@ -34,9 +30,6 @@ interface SerializedAuditLogTargetSchema { }; } -/** - * Serialized format for creating audit log schema (sent to API). - */ export interface SerializedCreateAuditLogSchemaOptions { targets: SerializedAuditLogTargetSchema[]; actor?: { From 34c491f4f8258e92bf95264b0b344e5905e657f5 Mon Sep 17 00:00:00 2001 From: swaroopakkineni Date: Mon, 2 Feb 2026 08:11:27 -1000 Subject: [PATCH 14/17] prettier --- src/audit-logs/audit-logs.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/audit-logs/audit-logs.ts b/src/audit-logs/audit-logs.ts index 84121c0bf..d10df4d86 100644 --- a/src/audit-logs/audit-logs.ts +++ b/src/audit-logs/audit-logs.ts @@ -19,7 +19,7 @@ import { import { CreateAuditLogSchemaResponse, CreateAuditLogSchemaRequestOptions, - CreateAuditLogSchemaOptions + CreateAuditLogSchemaOptions, } from './interfaces/create-audit-log-schema-options.interface'; import { deserializeAuditLogExport, From 1e0672f9a1b59e12b2c49e772a61f23bda168093 Mon Sep 17 00:00:00 2001 From: swaroopakkineni Date: Mon, 2 Feb 2026 08:12:34 -1000 Subject: [PATCH 15/17] prettier --- src/audit-logs/audit-logs.spec.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/audit-logs/audit-logs.spec.ts b/src/audit-logs/audit-logs.spec.ts index f2afddf17..c27dc9cc0 100644 --- a/src/audit-logs/audit-logs.spec.ts +++ b/src/audit-logs/audit-logs.spec.ts @@ -12,6 +12,7 @@ import { AuditLogSchemaResponse, CreateAuditLogEventOptions, CreateAuditLogSchemaOptions, + CreateAuditLogSchemaResponse, } from './interfaces'; import { serializeAuditLogExportOptions, @@ -600,7 +601,7 @@ describe('AuditLogs', () => { createdAt: time, }; - const createSchemaResponse: AuditLogSchemaResponse = { + const createSchemaResponse: CreateAuditLogSchemaResponse = { object: 'audit_log_schema', version: 1, targets: [ @@ -686,7 +687,7 @@ describe('AuditLogs', () => { createdAt: time, }; - const createSchemaResponse: AuditLogSchemaResponse = { + const createSchemaResponse: CreateAuditLogSchemaResponse = { object: 'audit_log_schema', version: 1, targets: [ @@ -762,7 +763,7 @@ describe('AuditLogs', () => { createdAt: time, }; - const createSchemaResponse: AuditLogSchemaResponse = { + const createSchemaResponse: CreateAuditLogSchemaResponse = { object: 'audit_log_schema', version: 1, targets: [ From 3079d1c4ac63ce1085e719a3c46438f5c6a79e86 Mon Sep 17 00:00:00 2001 From: swaroopakkineni Date: Wed, 4 Feb 2026 04:38:12 -1000 Subject: [PATCH 16/17] nit --- .../create-audit-log-schema-options.interface.ts | 7 ------- 1 file changed, 7 deletions(-) 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 index c7004e2dd..2c4bc876b 100644 --- a/src/audit-logs/interfaces/create-audit-log-schema-options.interface.ts +++ b/src/audit-logs/interfaces/create-audit-log-schema-options.interface.ts @@ -8,13 +8,6 @@ export type { AuditLogTargetSchema, } from './audit-log-schema.interface'; -import type { - AuditLogSchemaMetadata, - AuditLogSchemaResponse, - AuditLogActorSchema, - AuditLogTargetSchema, -} from './audit-log-schema.interface'; - export interface CreateAuditLogSchemaOptions { action: string; targets: AuditLogTargetSchema[]; From d120d412ba1d6a9fcd3420588f872c6b3a0b08d6 Mon Sep 17 00:00:00 2001 From: swaroopakkineni Date: Wed, 4 Feb 2026 04:43:03 -1000 Subject: [PATCH 17/17] nit --- .../create-audit-log-schema-options.interface.ts | 7 +++++++ 1 file changed, 7 insertions(+) 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 index 2c4bc876b..c7004e2dd 100644 --- a/src/audit-logs/interfaces/create-audit-log-schema-options.interface.ts +++ b/src/audit-logs/interfaces/create-audit-log-schema-options.interface.ts @@ -8,6 +8,13 @@ export type { AuditLogTargetSchema, } from './audit-log-schema.interface'; +import type { + AuditLogSchemaMetadata, + AuditLogSchemaResponse, + AuditLogActorSchema, + AuditLogTargetSchema, +} from './audit-log-schema.interface'; + export interface CreateAuditLogSchemaOptions { action: string; targets: AuditLogTargetSchema[];