UNPKG

@dudousxd/nestjs-telescope

Version:

Laravel Telescope-style observability console for NestJS — core: watchers, recorder, correlation, SQLite store, headless API.

42 lines 1.53 kB
// packages/core/src/auth/auth-response.ts function isRecord(value) { return typeof value === 'object' && value !== null; } function isRawNodeResponse(value) { return (isRecord(value) && typeof value.getHeader === 'function' && typeof value.setHeader === 'function'); } /** * Resolve the writable Node `ServerResponse` from a platform response. Express' * response IS the Node response; Fastify's reply wraps it on `.raw`. Returns the * outer response when it already exposes get/setHeader (Express), otherwise the * unwrapped `.raw` (Fastify) — so a single `setHeader` path serves both. */ function resolveRawResponse(response) { if (isRawNodeResponse(response)) return response; if (isRecord(response) && isRawNodeResponse(response.raw)) return response.raw; return null; } function existingSetCookies(response) { const current = response.getHeader('set-cookie'); if (Array.isArray(current)) return current; if (typeof current === 'string') return [current]; return []; } /** * Append a `Set-Cookie` header to the response WITHOUT clobbering any cookies * already queued by the host (auth or otherwise). Platform-agnostic raw write — * no-ops gracefully if the response can't be unwrapped. */ export function appendSetCookie(response, cookie) { const raw = resolveRawResponse(response); if (!raw) return; raw.setHeader('set-cookie', [...existingSetCookies(raw), cookie]); } //# sourceMappingURL=auth-response.js.map