Skip to content

feat!: Port AuditLogs to oagen#1627

Open
gjtorikian wants to merge 2 commits into
mainfrom
oagen/own-audit-logs
Open

feat!: Port AuditLogs to oagen#1627
gjtorikian wants to merge 2 commits into
mainfrom
oagen/own-audit-logs

Conversation

@gjtorikian

@gjtorikian gjtorikian commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Description

This PR generates the AuditLogs category in the Node SDK from the OpenAPI spec.

Almost every existing method changed its input signature, its output, or both. Callers cannot expect the same input/output format.

┌──────────────┬─────────────────────────────────────────────────┬────────────────────────────────────────────────────────────┐
│    Method    │                     Before                      │                           After                            │
├──────────────┼─────────────────────────────────────────────────┼────────────────────────────────────────────────────────────┤
│ createEvent  │ createEvent(organization: string, event,        │ createEvent(options: CreateEventOptions) →                 │
│              │ options?) → Promise<void>                       │ Promise<AuditLogEventCreateResponse>                       │
├──────────────┼─────────────────────────────────────────────────┼────────────────────────────────────────────────────────────┤
│ createSchema │ createSchema(schema: {action, ...}, options?)   │ createSchema(options: {actionName, ...})                   │
├──────────────┼─────────────────────────────────────────────────┼────────────────────────────────────────────────────────────┤
│ listSchemas  │ listSchemas(action: string, options?)           │ renamed → listActionSchemas(options: {actionName, ...})    │
├──────────────┼─────────────────────────────────────────────────┼────────────────────────────────────────────────────────────┤
│ getExport    │ getExport(auditLogExportId: string)             │ getExport(options: {auditLogExportId})                     │
├──────────────┼─────────────────────────────────────────────────┼────────────────────────────────────────────────────────────┤
│ createExport │ createExport(options: AuditLogExportOptions)    │ same signature                                             │
└──────────────┴─────────────────────────────────────────────────┴────────────────────────────────────────────────────────────┘

As well:

  • AuditLogExport.createdAt / updatedAt change: string → Date
  • AuditLogSchema.createdAt also changed string → Date

The following new methods were added:

  • getOrganizationAuditLogsRetention(options)
  • updateOrganizationAuditLogsRetention(options)
  • listActions(options?)

Because of these changes, this is a major breaking change to the SDK.

@gjtorikian gjtorikian requested review from a team as code owners June 17, 2026 00:25
@gjtorikian gjtorikian requested a review from tribble June 17, 2026 00:25
@greptile-apps

greptile-apps Bot commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR ports the AuditLogs module from hand-written code to oagen-generated code, aligning the Node SDK with the OpenAPI spec. Every existing method changes its signature or return type (or both), and three new methods are added.

  • Breaking signature changes: createEvent now accepts a single options object (dropping the positional organization/event args), createSchema/listSchemas are renamed and restructured, and getExport wraps its argument in an options object; rangeStart/rangeEnd in AuditLogExportOptions change from Date to string.
  • New methods: getOrganizationAuditLogsRetention, updateOrganizationAuditLogsRetention, and listActions are introduced with corresponding interfaces, serializers, and fixtures.
  • Date handling updated: AuditLogExport.createdAt/updatedAt and AuditLogSchema.createdAt are now deserialized as Date objects; a new serializers.spec.ts validates all new serializers and deserializers with fixture-based tests.

Confidence Score: 5/5

The change is a clean oagen-generated port; all existing behaviour (idempotency key, URL encoding, date deserialization) is preserved, and the new methods are straightforward API wrappers.

The core logic is correct: idempotency keys are still auto-generated for createEvent, URL parameters are now properly encodeURIComponent-wrapped, and date fields are properly deserialized. The only gap is that the auto-generated test file drops the detailed idempotency-key assertions that previously guarded createEvent; the behaviour is still implemented correctly but has lost test coverage.

src/audit-logs/audit-logs.spec.ts — idempotency-key test coverage for createEvent was not regenerated.

Important Files Changed

Filename Overview
src/audit-logs/audit-logs.ts Core implementation ported from hand-written to oagen-generated; new methods added (getOrganizationAuditLogsRetention, updateOrganizationAuditLogsRetention, listActions, listActionSchemas), createSchema/createEvent/createExport/getExport signatures updated; idempotency key logic is preserved, encodeURIComponent added to URL segments
src/audit-logs/audit-logs.spec.ts Test suite replaced wholesale by auto-generated tests; new tests cover happy path and error path for each method, but detailed idempotency-key and retry-specific assertions for createEvent are no longer present
src/audit-logs/interfaces/audit-log-export-options.interface.ts rangeStart/rangeEnd changed from Date to string (breaking); SerializedAuditLogExportOptions removed; actors deprecated field absent from public type but present in AuditLogExportCreation used by the serializer
src/audit-logs/interfaces/index.ts Barrel export updated to expose all new interfaces; internal wire types (AuditLogEventIngestionResponse, AuditLogExportCreationResponse, AuditLogSchemaInputResponse, etc.) are now part of the public surface
src/audit-logs/serializers/audit-log-export-creation.serializer.ts New serializer for AuditLogExportCreation; correctly maps all camelCase fields to snake_case wire format including deprecated actors field
src/audit-logs/serializers/audit-log-event-ingestion.serializer.ts New serializer that wraps serializeAuditLogEvent and serializes the organizationId field; straightforward and correct
src/audit-logs/serializers.spec.ts New serializer-level unit tests for all new serializers and deserializers; fixture-driven and clean

Sequence Diagram

%%{init: {'theme': 'neutral'}}%%
sequenceDiagram
    participant Caller
    participant AuditLogs
    participant WorkOS HTTP

    Caller->>AuditLogs: createEvent(options: CreateEventOptions, requestOptions?)
    AuditLogs->>AuditLogs: serializeAuditLogEventIngestion(options)
    AuditLogs->>AuditLogs: auto-generate idempotencyKey if absent
    AuditLogs->>WorkOS HTTP: POST /audit_logs/events
    WorkOS HTTP-->>AuditLogs: AuditLogEventCreateResponseWire
    AuditLogs-->>Caller: AuditLogEventCreateResponse

    Caller->>AuditLogs: createExport(options: AuditLogExportOptions)
    AuditLogs->>AuditLogs: serializeAuditLogExportCreation(options)
    AuditLogs->>WorkOS HTTP: POST /audit_logs/exports
    WorkOS HTTP-->>AuditLogs: AuditLogExportResponse
    AuditLogs->>AuditLogs: deserializeAuditLogExport (createdAt/updatedAt to Date)
    AuditLogs-->>Caller: AuditLogExport

    Caller->>AuditLogs: "getOrganizationAuditLogsRetention({id})"
    AuditLogs->>WorkOS HTTP: GET /organizations/:id/audit_logs_retention
    WorkOS HTTP-->>AuditLogs: AuditLogsRetentionResponse
    AuditLogs-->>Caller: AuditLogsRetention

    Caller->>AuditLogs: "listActionSchemas({actionName, ...pagination})"
    AuditLogs->>WorkOS HTTP: GET /audit_logs/actions/:name/schemas
    WorkOS HTTP-->>AuditLogs: list of AuditLogSchemaResponse
    AuditLogs-->>Caller: AutoPaginatable[AuditLogSchema]
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
sequenceDiagram
    participant Caller
    participant AuditLogs
    participant WorkOS HTTP

    Caller->>AuditLogs: createEvent(options: CreateEventOptions, requestOptions?)
    AuditLogs->>AuditLogs: serializeAuditLogEventIngestion(options)
    AuditLogs->>AuditLogs: auto-generate idempotencyKey if absent
    AuditLogs->>WorkOS HTTP: POST /audit_logs/events
    WorkOS HTTP-->>AuditLogs: AuditLogEventCreateResponseWire
    AuditLogs-->>Caller: AuditLogEventCreateResponse

    Caller->>AuditLogs: createExport(options: AuditLogExportOptions)
    AuditLogs->>AuditLogs: serializeAuditLogExportCreation(options)
    AuditLogs->>WorkOS HTTP: POST /audit_logs/exports
    WorkOS HTTP-->>AuditLogs: AuditLogExportResponse
    AuditLogs->>AuditLogs: deserializeAuditLogExport (createdAt/updatedAt to Date)
    AuditLogs-->>Caller: AuditLogExport

    Caller->>AuditLogs: "getOrganizationAuditLogsRetention({id})"
    AuditLogs->>WorkOS HTTP: GET /organizations/:id/audit_logs_retention
    WorkOS HTTP-->>AuditLogs: AuditLogsRetentionResponse
    AuditLogs-->>Caller: AuditLogsRetention

    Caller->>AuditLogs: "listActionSchemas({actionName, ...pagination})"
    AuditLogs->>WorkOS HTTP: GET /audit_logs/actions/:name/schemas
    WorkOS HTTP-->>AuditLogs: list of AuditLogSchemaResponse
    AuditLogs-->>Caller: AutoPaginatable[AuditLogSchema]
Loading

Reviews (2): Last reviewed commit: "fix(audit-logs): restore idempotency, fi..." | Re-trigger Greptile

Comment thread src/audit-logs/audit-logs.ts
Comment thread src/audit-logs/audit-logs.ts
@gjtorikian gjtorikian marked this pull request as draft June 18, 2026 19:06
@gjtorikian gjtorikian changed the title feat! Port AuditLogs to oagen feat!: Port AuditLogs to oagen Jun 18, 2026
@gjtorikian gjtorikian added the autogenerated Autogenerated code or content label Jun 18, 2026
…zer test

Regenerate AuditLogs with the fixed node emitter and fold in the review findings
from #1627:

- createEvent regains idempotency: a `requestOptions: PostOptions = {}` param and
  an auto-generated `workos-node-${uuid}` Idempotency-Key, so a 5xx retry no
  longer silently duplicates an audit event (the options-object emitter path
  previously dropped it entirely).
- createExport JSDoc no longer documents `options.actors` — the curated
  AuditLogExportOptions doesn't expose that deprecated field.
- Drop the dead `SerializedAuditLogExportOptions` interface (its only consumer,
  the old serializeAuditLogExportOptions, was removed in the port).
- serializers.spec.ts now reconstructs the camelCase domain model from the wire
  fixture instead of feeding the serializer a snake_case object (which threw
  `model.occurredAt.toISOString()` on undefined).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@gjtorikian gjtorikian marked this pull request as ready for review July 2, 2026 18:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

autogenerated Autogenerated code or content

Development

Successfully merging this pull request may close these issues.

1 participant