Skip to content

[v8] Use globalThis.crypto.randomUUID for runtime-agnostic UUIDs#1398

Merged
nicknisi merged 1 commit intoversion-8from
nicknisi/v8-audit-logs-random-uuid
Nov 24, 2025
Merged

[v8] Use globalThis.crypto.randomUUID for runtime-agnostic UUIDs#1398
nicknisi merged 1 commit intoversion-8from
nicknisi/v8-audit-logs-random-uuid

Conversation

@nicknisi
Copy link
Member

Replaces Node.js-specific crypto import with globalThis.crypto to ensure compatibility across Node.js 20 and other runtimes.

Description

Documentation

Does this require changes to the WorkOS Docs? E.g. the API Reference or code snippets need updates.

[ ] Yes

If yes, link a related docs PR and add a docs maintainer as a reviewer. Their approval is required.

…ation

Replaces Node.js-specific crypto import with globalThis.crypto to ensure
compatibility across Node.js 20+, Cloudflare Workers, and edge runtimes.
@nicknisi nicknisi requested a review from a team as a code owner November 24, 2025 16:24
@nicknisi nicknisi requested review from awolfden and removed request for a team November 24, 2025 16:24
@greptile-apps
Copy link
Contributor

greptile-apps bot commented Nov 24, 2025

Greptile Overview

Greptile Summary

Replaced Node.js-specific crypto import with globalThis.crypto.randomUUID() to ensure UUID generation works across all target runtimes (Node.js 20+, Deno, Bun, Cloudflare Workers, Convex).

Key changes:

  • Removed import { randomUUID } from 'crypto' statement
  • Updated randomUUID() call to globalThis.crypto.randomUUID() in the auto-generated idempotency value on src/audit-logs/audit-logs.ts:38

Compatibility verified:

  • Node.js 20.15+ (minimum supported version): globalThis.crypto.randomUUID() is available
  • Cloudflare Workers, Deno, Bun: All support globalThis.crypto.randomUUID()
  • Existing tests continue to validate auto-generation behavior

This change aligns with the v8 runtime-agnostic approach seen in recent commits that replaced dependencies with vanilla implementations.

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk - it's a straightforward runtime compatibility improvement
  • The change is minimal, well-tested, and improves cross-runtime compatibility. globalThis.crypto.randomUUID() is available in Node.js 20.15+ (the minimum version), and all target runtimes (Deno, Bun, Cloudflare Workers). Existing comprehensive test suite validates the auto-generation behavior remains unchanged.
  • No files require special attention

Important Files Changed

File Analysis

Filename Score Overview
src/audit-logs/audit-logs.ts 5/5 Replaced Node.js-specific crypto.randomUUID() import with globalThis.crypto.randomUUID() for cross-runtime compatibility

Sequence Diagram

sequenceDiagram
    participant Client
    participant AuditLogs
    participant Crypto as globalThis.crypto
    participant API as WorkOS API

    Client->>AuditLogs: createEvent(organization, event, options?)
    
    alt idempotencyKey not provided
        AuditLogs->>Crypto: randomUUID()
        Crypto-->>AuditLogs: UUID string
        AuditLogs->>AuditLogs: Generate: "workos-node-{UUID}"
    else idempotencyKey provided
        AuditLogs->>AuditLogs: Use provided value
    end
    
    AuditLogs->>API: POST /audit_logs/events with idempotency header
    API-->>AuditLogs: 201 Created
    AuditLogs-->>Client: void
Loading

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 file reviewed, no comments

Edit Code Review Agent Settings | Greptile

@nicknisi nicknisi merged commit 733200a into version-8 Nov 24, 2025
6 checks passed
@nicknisi nicknisi deleted the nicknisi/v8-audit-logs-random-uuid branch November 24, 2025 16:54
nicknisi added a commit that referenced this pull request Dec 2, 2025
Replaces Node.js-specific crypto import with globalThis.crypto to ensure
compatibility across Node.js 20 and other runtimes.

Does this require changes to the WorkOS Docs? E.g. the [API
Reference](https://workos.com/docs/reference) or code snippets need
updates.

```
[ ] Yes
```

If yes, link a related docs PR and add a docs maintainer as a reviewer.
Their approval is required.
nicknisi added a commit that referenced this pull request Dec 4, 2025
Replaces Node.js-specific crypto import with globalThis.crypto to ensure
compatibility across Node.js 20 and other runtimes.

Does this require changes to the WorkOS Docs? E.g. the [API
Reference](https://workos.com/docs/reference) or code snippets need
updates.

```
[ ] Yes
```

If yes, link a related docs PR and add a docs maintainer as a reviewer.
Their approval is required.
nicknisi added a commit that referenced this pull request Dec 4, 2025
Replaces Node.js-specific crypto import with globalThis.crypto to ensure
compatibility across Node.js 20 and other runtimes.

Does this require changes to the WorkOS Docs? E.g. the [API
Reference](https://workos.com/docs/reference) or code snippets need
updates.

```
[ ] Yes
```

If yes, link a related docs PR and add a docs maintainer as a reviewer.
Their approval is required.
nicknisi added a commit that referenced this pull request Dec 16, 2025
Replaces Node.js-specific crypto import with globalThis.crypto to ensure
compatibility across Node.js 20 and other runtimes.

Does this require changes to the WorkOS Docs? E.g. the [API
Reference](https://workos.com/docs/reference) or code snippets need
updates.

```
[ ] Yes
```

If yes, link a related docs PR and add a docs maintainer as a reviewer.
Their approval is required.
nicknisi added a commit that referenced this pull request Dec 22, 2025
Replaces Node.js-specific crypto import with globalThis.crypto to ensure
compatibility across Node.js 20 and other runtimes.

Does this require changes to the WorkOS Docs? E.g. the [API
Reference](https://workos.com/docs/reference) or code snippets need
updates.

```
[ ] Yes
```

If yes, link a related docs PR and add a docs maintainer as a reviewer.
Their approval is required.
nicknisi added a commit that referenced this pull request Jan 8, 2026
Replaces Node.js-specific crypto import with globalThis.crypto to ensure
compatibility across Node.js 20 and other runtimes.

Does this require changes to the WorkOS Docs? E.g. the [API
Reference](https://workos.com/docs/reference) or code snippets need
updates.

```
[ ] Yes
```

If yes, link a related docs PR and add a docs maintainer as a reviewer.
Their approval is required.
nicknisi added a commit that referenced this pull request Jan 9, 2026
Replaces Node.js-specific crypto import with globalThis.crypto to ensure
compatibility across Node.js 20 and other runtimes.

Does this require changes to the WorkOS Docs? E.g. the [API
Reference](https://workos.com/docs/reference) or code snippets need
updates.

```
[ ] Yes
```

If yes, link a related docs PR and add a docs maintainer as a reviewer.
Their approval is required.
nicknisi added a commit that referenced this pull request Jan 12, 2026
Replaces Node.js-specific crypto import with globalThis.crypto to ensure
compatibility across Node.js 20 and other runtimes.

Does this require changes to the WorkOS Docs? E.g. the [API
Reference](https://workos.com/docs/reference) or code snippets need
updates.

```
[ ] Yes
```

If yes, link a related docs PR and add a docs maintainer as a reviewer.
Their approval is required.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants