Repository navigation
v6.1.2
Changes
- fix(ids): 🐛 Generate identifiers across Node and browsers
Release details
- npm: https://www.npmjs.com/package/@haskou/value-objects/v/6.1.2
- Pull request: #61
- Source branch:
fix/identifier-generation - Version bump:
patch
Pull request notes
Problem
After crypto extraction, UUID and ShortId generation directly called globalThis.crypto.getRandomValues. This failed in Node environments where the global Web Crypto API was unavailable, despite the platform providing native randomness.
Change
- Add
uuid11.1.1, whose maintained legacy exports support Node, browsers, CommonJS, and ESM. This line uses native Node crypto without requiring a global object. - Delegate UUID v4 generation to the dependency and remove custom UUID formatting.
- Preserve ShortId's 24-character hex format, 32-bit timestamp prefix, and 64 random bits, selecting bytes outside UUID version/variant fields.
- Keep randomness secure; do not fall back to Math.random or require consumer configuration.
- Add regressions for Node generation without global crypto and the ShortId timestamp prefix.
This PR contains only identifier generation. ESM/CommonJS packaging remains in #59.
Validation
- 565 unit tests passed; the new no-global-crypto regressions failed before the fix.
- ESLint and TypeScript build passed.
- A fresh Node process loaded the built package with global crypto removed and generated 1,000 UUIDs and 1,000 ShortIds, all unique.
- A browser bundle ran in the actual Chromium in-app browser with no consumer setup and generated 1,000 UUID v4 values and 1,000 ShortIds, with valid formats and no duplicates.