UNPKG

@dudousxd/nestjs-telescope

Version:

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

51 lines 1.86 kB
function isRecord(value) { return typeof value === 'object' && value !== null; } function readHeaders(request) { if (!isRecord(request)) return {}; const headers = request.headers; return isRecord(headers) ? headers : {}; } /** Coerce a single header (string or string[]) to a string, else undefined. */ function headerToString(value) { if (typeof value === 'string') return value; if (Array.isArray(value) && value.every((part) => typeof part === 'string')) { return value.join(','); } return undefined; } /** Read the raw `Cookie` request header (Express and Fastify both expose `headers`). */ export function readCookieHeader(request) { return headerToString(readHeaders(request).cookie); } /** * Decide whether the cookie should carry `Secure`. True when the request is * https directly (`request.protocol === 'https'`) OR a proxy forwarded https * (`x-forwarded-proto` includes 'https'). Defensive structural reads — never * throws, defaults to insecure (works on plain http in dev). */ export function isHttpsRequest(request) { if (isRecord(request) && request.protocol === 'https') return true; const forwarded = headerToString(readHeaders(request)['x-forwarded-proto']); if (forwarded === undefined) return false; return forwarded .split(',') .map((proto) => proto.trim().toLowerCase()) .includes('https'); } /** * Attach the verified session onto the raw request so `authorizer` / * `authorizeAction` hooks can read `request.telescopeSession`. Narrow * structural mutation — avoids an `as` cast at the guard call site. */ export function attachSession(request, session) { if (!isRecord(request)) return; const target = request; target.telescopeSession = session; } //# sourceMappingURL=auth-request.js.map