import type { ApiRequestOptions } from './apiClient'; export type RuntimeGuestRequestOptions = Pick< ApiRequestOptions, | 'authImpact' | 'skipAuth' | 'skipRefresh' | 'notifyAuthStateChange' | 'clearAuthOnUnauthorized' > & { runtimeGuestToken?: string; }; export function buildRuntimeGuestHeaders( options: Pick, headers: Record = {}, ) { const runtimeGuestToken = options.runtimeGuestToken?.trim(); if (!runtimeGuestToken) { return headers; } return { ...headers, Authorization: `Bearer ${runtimeGuestToken}`, }; } export function buildRuntimeGuestAuthOptions< TOptions extends RuntimeGuestRequestOptions, >(options: TOptions) { const runtimeGuestToken = options.runtimeGuestToken?.trim(); return { authImpact: options.authImpact, skipAuth: runtimeGuestToken ? true : options.skipAuth, skipRefresh: runtimeGuestToken ? true : options.skipRefresh, notifyAuthStateChange: options.notifyAuthStateChange, clearAuthOnUnauthorized: options.clearAuthOnUnauthorized, } satisfies ApiRequestOptions; }