Skip to content

feat!: Port AuditLogs to oagen#1627

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

feat!: Port AuditLogs to oagen#1627
gjtorikian wants to merge 4 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 SDK category to the OpenAPI-driven oagen generator, replacing hand-written serializers, interfaces, and method signatures with auto-generated equivalents. All files are marked "Do not edit."

  • Breaking changes across the board: createEvent gains a return type, createExport/getExport/createSchema change their input shapes, listSchemas is renamed to listActionSchemas, and rangeStart/rangeEnd on AuditLogExportOptions change from Date to string; three new methods (getOrganizationAuditLogsRetention, updateOrganizationAuditLogsRetention, listActions) are added.
  • Idempotency preserved: createEvent still auto-generates a workos-node-{uuid} idempotency key when none is provided and merges requestOptions correctly; the new test-utils-based spec verifies the key format and that an explicit key is forwarded.
  • Date deserialization added: createdAt/updatedAt on AuditLogExport and AuditLogSchema now return Date objects (breaking change from string).

Confidence Score: 5/5

Safe to merge — the implementation is correct, idempotency key generation is preserved, URL parameters are properly encoded, and date deserialization is handled throughout.

The auto-generated code is clean and consistent. Idempotency key handling in createEvent is correct (key generated once per call via requestOptions spread, so retries reuse it). Date fields are properly deserialized with new Date(). URL parameters use encodeURIComponent. The only concern is a test coverage regression where retry/idempotency contract tests were removed, but this does not affect the correctness of the shipped code.

src/audit-logs/audit-logs.spec.ts — the auto-generated spec dropped all retry tests for createEvent; worth reviewing whether the generator can be configured to include them.

Important Files Changed

Filename Overview
src/audit-logs/audit-logs.ts Main implementation: method signatures updated, idempotency key preserved, URL params encoded, new retention/action endpoints added
src/audit-logs/audit-logs.spec.ts Auto-generated spec replacing hand-written tests; retry/idempotency regression tests dropped; single test exercises multiple createEvent calls with only one fetchOnce mock
src/audit-logs/interfaces/audit-log-export-options.interface.ts rangeStart/rangeEnd changed from Date to string; SerializedAuditLogExportOptions removed; actors deprecated field not exposed to callers
src/audit-logs/interfaces/audit-log-export.interface.ts createdAt/updatedAt changed from string to Date; AuditLogExportState const/type added in separate file but not referenced here
src/audit-logs/serializers/audit-log-export.serializer.ts Correctly deserializes dates with new Date(); uses null-coalescing for url field to handle potential null from API
src/audit-logs/serializers/audit-log-export-creation.serializer.ts Replaces deleted serializeAuditLogExportOptions; correctly maps camelCase to snake_case; handles deprecated actors field
src/audit-logs/interfaces/index.ts Re-exports expanded with 15 new interfaces; old create-event/schema options replaced; all new types publicly exposed
src/audit-logs/serializers.spec.ts New auto-generated serializer spec with round-trip tests for all new serializers

Sequence Diagram

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

    Note over AuditLogs: createEvent
    Caller->>AuditLogs: createEvent(CreateEventOptions, PostOptions?)
    AuditLogs->>AuditLogs: serializeAuditLogEventIngestion
    AuditLogs->>AuditLogs: auto-generate idempotencyKey if not provided
    AuditLogs->>WorkOSHTTP: POST /audit_logs/events + Idempotency-Key header
    WorkOSHTTP-->>AuditLogs: AuditLogEventCreateResponseWire
    AuditLogs-->>Caller: AuditLogEventCreateResponse

    Note over AuditLogs: createExport
    Caller->>AuditLogs: createExport(AuditLogExportOptions)
    AuditLogs->>AuditLogs: serializeAuditLogExportCreation
    AuditLogs->>WorkOSHTTP: POST /audit_logs/exports
    WorkOSHTTP-->>AuditLogs: AuditLogExportResponse
    AuditLogs->>AuditLogs: deserializeAuditLogExport - dates to Date objects
    AuditLogs-->>Caller: AuditLogExport

    Note over AuditLogs: getOrganizationAuditLogsRetention new
    Caller->>AuditLogs: getOrganizationAuditLogsRetention id
    AuditLogs->>WorkOSHTTP: GET /organizations/:id/audit_logs_retention
    WorkOSHTTP-->>AuditLogs: AuditLogsRetentionResponse
    AuditLogs-->>Caller: AuditLogsRetention

    Note over AuditLogs: listActions new
    Caller->>AuditLogs: listActions(options?)
    AuditLogs->>WorkOSHTTP: GET /audit_logs/actions
    WorkOSHTTP-->>AuditLogs: ListResponse AuditLogActionResponse
    AuditLogs-->>Caller: AutoPaginatable AuditLogAction
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 WorkOSHTTP

    Note over AuditLogs: createEvent
    Caller->>AuditLogs: createEvent(CreateEventOptions, PostOptions?)
    AuditLogs->>AuditLogs: serializeAuditLogEventIngestion
    AuditLogs->>AuditLogs: auto-generate idempotencyKey if not provided
    AuditLogs->>WorkOSHTTP: POST /audit_logs/events + Idempotency-Key header
    WorkOSHTTP-->>AuditLogs: AuditLogEventCreateResponseWire
    AuditLogs-->>Caller: AuditLogEventCreateResponse

    Note over AuditLogs: createExport
    Caller->>AuditLogs: createExport(AuditLogExportOptions)
    AuditLogs->>AuditLogs: serializeAuditLogExportCreation
    AuditLogs->>WorkOSHTTP: POST /audit_logs/exports
    WorkOSHTTP-->>AuditLogs: AuditLogExportResponse
    AuditLogs->>AuditLogs: deserializeAuditLogExport - dates to Date objects
    AuditLogs-->>Caller: AuditLogExport

    Note over AuditLogs: getOrganizationAuditLogsRetention new
    Caller->>AuditLogs: getOrganizationAuditLogsRetention id
    AuditLogs->>WorkOSHTTP: GET /organizations/:id/audit_logs_retention
    WorkOSHTTP-->>AuditLogs: AuditLogsRetentionResponse
    AuditLogs-->>Caller: AuditLogsRetention

    Note over AuditLogs: listActions new
    Caller->>AuditLogs: listActions(options?)
    AuditLogs->>WorkOSHTTP: GET /audit_logs/actions
    WorkOSHTTP-->>AuditLogs: ListResponse AuditLogActionResponse
    AuditLogs-->>Caller: AutoPaginatable AuditLogAction
Loading

Reviews (4): Last reviewed commit: "Merge branch 'main' into oagen/own-audit..." | 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
Regenerated audit-logs.spec.ts with the node emitter's new idempotency
test emission. Adds assertions that createEvent forwards a caller-supplied
Idempotency-Key header and auto-generates a `workos-node-` prefixed one
when none is given — the coverage the oagen port dropped and that review
flagged. The behavior was already correct; this guards it.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@gjtorikian gjtorikian added the breaking change Contains a breaking change label Jul 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

autogenerated Autogenerated code or content breaking change Contains a breaking change

Development

Successfully merging this pull request may close these issues.

1 participant