// Cross-platform unique ID generator for correlation IDs // Works in browsers, Node.js, and React Native let counter = 0 export const generateCorrelationId = (): string => { // Try crypto.randomUUID() first (modern browsers, Node 19+) if (typeof crypto !== 'undefined' && typeof crypto.randomUUID === 'function') { return crypto.randomUUID() } // Fallback: crypto.getRandomValues (browsers, React Native with crypto polyfill) if (typeof crypto !== 'undefined' && typeof crypto.getRandomValues === 'function') { const array = new Uint8Array(16) crypto.getRandomValues(array) return Array.from(array, (byte) => byte.toString(16).padStart(2, '0')).join('') } // Last resort fallback: timestamp + counter + random // More entropy than original: includes incrementing counter counter = (counter + 1) % 1000000 return `${Date.now()}-${counter}-${Math.random().toString(36).substring(2, 15)}` }