( requestId: string | undefined, fallbackSeed?: unknown, )
| 6 | const REQUEST_CANCELED_MESSAGE = 'request canceled'; |
| 7 | |
| 8 | export function resolveRequestTrackingId( |
| 9 | requestId: string | undefined, |
| 10 | fallbackSeed?: unknown, |
| 11 | ): string { |
| 12 | if (typeof requestId === 'string' && requestId.length > 0) return requestId; |
| 13 | const rawSeed = |
| 14 | typeof fallbackSeed === 'string' |
| 15 | ? fallbackSeed |
| 16 | : typeof fallbackSeed === 'number' && Number.isFinite(fallbackSeed) |
| 17 | ? String(fallbackSeed) |
| 18 | : 'generated'; |
| 19 | const normalizedSeed = |
| 20 | rawSeed |
| 21 | .trim() |
| 22 | .replace(/[^a-zA-Z0-9_-]/g, '_') |
| 23 | .slice(0, 32) || 'generated'; |
| 24 | const nonce = Math.random().toString(36).slice(2, 10); |
| 25 | return `req:${normalizedSeed}:${process.pid}:${Date.now()}:${nonce}`; |
| 26 | } |
| 27 | |
| 28 | const COLLECTION_HIGH_WATERMARK = 50_000; |
| 29 | const COLLECTION_EVICT_COUNT = 10_000; |
no test coverage detected