/** * Generates a unique string ID. Uses crypto.randomUUID when available, * otherwise falls back to a timestamp + random string. * * @param prefix - Optional prefix for the fallback format (e.g. "req", "err"). * Only affects fallback; UUIDs have no prefix. */ export function createUniqueId(prefix?: string): string { if ( typeof globalThis.crypto !== "undefined" && typeof globalThis.crypto.randomUUID === "function" ) { return globalThis.crypto.randomUUID(); } const fallback = `${Date.now()}_${Math.random().toString(36).slice(2)}`; return prefix ? `${prefix}_${fallback}` : fallback; }