/** * Timing metadata stamped onto a request config so the response handler can attribute * and measure the round trip. Intersect with your transport's config type. * * `stamp` is a JourneyStepStamp from `step.stamp()` or ambient instrumentation. */ export interface JourneyTimedMeta { journeyStart?: number; stamp?: unknown; /** Skip attribution for this request (no ambient stamp, no scoring). */ ignore?: boolean; /** Per-request override for aborted/cancelled HTTP policy. */ httpAbortedRequests?: 'continue' | 'bad' | 'exclude'; /** Per-request override for 4xx HTTP policy. */ httpClientErrorRequests?: 'continue' | 'bad' | 'exclude'; } function pageOrigin(): string { try { return globalThis.location?.origin ?? ''; } catch { return ''; } } function resolveHomeOrigin(instanceBaseURL: string | undefined, origin: string): string { try { const homeBase = instanceBaseURL ?? origin; return new URL(homeBase || 'http://localhost').origin; } catch { return origin; } } /** * Endpoint key for timeout / ignore lookup: PATH for same-origin (vs instance baseURL), * or "host/path" for cross-domain. */ export function requestKey( url: string | undefined, configBaseURL: string | undefined, instanceBaseURL: string | undefined ): string { const origin = pageOrigin(); const base = configBaseURL ?? instanceBaseURL ?? origin; let abs: URL; try { abs = new URL(url ?? '', base || undefined); } catch { return url ?? ''; } const homeOrigin = resolveHomeOrigin(instanceBaseURL, origin); return abs.origin === homeOrigin ? abs.pathname : abs.host + abs.pathname; }