Add randomUUID to CryptoProvider for edge runtime compatibility#1404
Merged
Add randomUUID to CryptoProvider for edge runtime compatibility#1404
Conversation
Contributor
Greptile OverviewGreptile SummaryThis PR fixes edge runtime compatibility by abstracting UUID generation through the Key Changes:
The implementation correctly follows UUID v4 specification with proper version (0x40) and variant (0x80) bits set. Confidence Score: 5/5
Important Files ChangedFile Analysis
Sequence DiagramsequenceDiagram
participant Client
participant AuditLogs
participant WorkOS
participant CryptoProvider
participant NodeCrypto as NodeCryptoProvider
participant SubtleCrypto as SubtleCryptoProvider
Client->>AuditLogs: createEvent(org, event, options)
alt idempotencyKey not provided
AuditLogs->>WorkOS: getCryptoProvider()
WorkOS-->>AuditLogs: CryptoProvider instance
alt Node.js runtime
AuditLogs->>NodeCrypto: randomUUID()
NodeCrypto->>NodeCrypto: crypto.randomUUID()
NodeCrypto-->>AuditLogs: UUID v4 string
else Edge runtime (Convex, Cloudflare)
AuditLogs->>SubtleCrypto: randomUUID()
SubtleCrypto->>SubtleCrypto: randomBytes(16)
SubtleCrypto->>SubtleCrypto: Apply UUID v4 bit masks
SubtleCrypto-->>AuditLogs: UUID v4 string
end
AuditLogs->>AuditLogs: Prefix UUID with workos-node
end
AuditLogs->>WorkOS: post('/audit_logs/events', data, options)
WorkOS-->>Client: Response
|
43a7286 to
43f415e
Compare
Fixes #1403. The audit-logs module was importing randomUUID directly from Node's crypto module, breaking edge-like runtimes (Convex, Cloudflare Workers) that cannot import the "crypto" package. This adds randomUUID() to the CryptoProvider interface with implementations in both NodeCryptoProvider and SubtleCryptoProvider, ensuring the audit-logs idempotency key generation works across all supported runtimes.
43f415e to
c4ae1dc
Compare
Merged
nicknisi
added a commit
that referenced
this pull request
Dec 2, 2025
## Description - #1404 ## Documentation 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #1403
randomUUID()abstract method toCryptoProviderinterfaceNodeCryptoProviderusing Node'scrypto.randomUUID()SubtleCryptoProviderusingrandomBytes(16)with UUID v4 bit manipulationAuditLogsto usegetCryptoProvider().randomUUID()instead of direct Node crypto importThis ensures the audit-logs idempotency key generation works across all supported runtimes including edge environments (Convex, Cloudflare Workers) that cannot import the Node "crypto" package.