{"version":3,"sources":["../src/stream/session-ref.ts","../src/stream/types.ts"],"sourcesContent":["// Copyright 2026 Bitech.id. Licensed under the MIT License.\n\nimport type { StreamEndReason } from './types.js';\n\n// Deliberately tiny and free of any rrweb import — this file is always\n// bundled (statically imported by index.ts) so Trace correlation and the\n// promote-on-error hook work even before the heavy recorder module has been\n// dynamically imported, without paying for rrweb's bytes up front.\n\nlet currentSessionId: string | undefined;\n\n/** Read by beforeSend to stamp tags.session_id on every Trace event, when a Stream session is active. */\nexport function getReplaySessionId(): string | undefined {\n  return currentSessionId;\n}\n\nexport function setReplaySessionId(sessionId: string | undefined): void {\n  currentSessionId = sessionId;\n}\n\ntype ErrorCapturedHook = () => void;\n\nlet onErrorCaptured: ErrorCapturedHook | undefined;\n\n/** Called by beforeSend whenever an exception is about to be sent — a no-op until the stream module registers a hook. */\nexport function notifyErrorCaptured(): void {\n  onErrorCaptured?.();\n}\n\nexport function setErrorCapturedHook(hook: ErrorCapturedHook | undefined): void {\n  onErrorCaptured = hook;\n}\n\ntype StopRequestedHook = (reason: StreamEndReason) => void;\n\nlet onStopRequested: StopRequestedHook | undefined;\n\n/** Ends the active Stream session early, e.g. on user consent withdrawal. A no-op if Stream isn't active. */\nexport function requestStreamStop(reason: StreamEndReason = 'user_optout'): void {\n  onStopRequested?.(reason);\n}\n\nexport function setStopRequestedHook(hook: StopRequestedHook | undefined): void {\n  onStopRequested = hook;\n}\n","// Copyright 2026 Bitech.id. Licensed under the MIT License.\n\n/**\n * Biwave Stream (session replay) config, passed via `init({ stream: {...} })`.\n * `platform`/`capture_mode` are fixed to 'web'/'dom' for @biwave/browser —\n * 'wireframe'/'screenshot' are mobile-SDK capture modes, out of scope here.\n */\nexport interface StreamOptions {\n  enabled?: boolean;\n  /** 0-1, probability a session is actively recorded+uploaded. Default 0.1. */\n  sessionSampleRate?: number;\n  /** 0-1, probability a non-sampled session is kept in a ring buffer for error-triggered promotion. Default 1.0. */\n  errorSampleRate?: number;\n  /** Ring buffer retention window, in seconds. Default 60. */\n  bufferSeconds?: number;\n  /** Default false — text is recorded as-is (LogRocket-style; only passwords are masked). Set true to mask all text nodes (per-element opt-out via the 'biwave-unmask' class). */\n  maskAllText?: boolean;\n  /** Default true — captures console/network/click/navigation as discrete, countable session events (LogRocket-style timeline). */\n  captureEvents?: boolean;\n}\n\nexport interface ResolvedStreamOptions {\n  sessionSampleRate: number;\n  errorSampleRate: number;\n  bufferSeconds: number;\n  maskAllText: boolean;\n  captureEvents: boolean;\n}\n\nexport const DEFAULT_STREAM_OPTIONS: ResolvedStreamOptions = {\n  sessionSampleRate: 0.1,\n  errorSampleRate: 1.0,\n  bufferSeconds: 60,\n  maskAllText: false,\n  captureEvents: true,\n};\n\n/** Returned by POST /api/stream/sessions — must be obeyed, never hardcoded. */\nexport interface StreamLimits {\n  max_chunk_bytes: number;\n  max_session_duration_ms: number;\n  max_chunks: number;\n}\n\nexport type StreamEndReason = 'normal' | 'crash' | 'user_optout';\n\nexport type StreamMode = 'recording' | 'buffered';\n\nexport interface StreamSessionState {\n  session_id: string;\n  mode: StreamMode;\n  started_at: number;\n  /** Next seq to assign — monotonic, never reused for different content. */\n  next_seq: number;\n  /** Set once the init response is known; recording mode assumes defaults until then. */\n  limits: StreamLimits | null;\n  /** True once POST /api/stream/sessions has been called (successfully or not — init is fire-and-forget-ish, chunks don't wait for it). */\n  init_sent: boolean;\n}\n\nexport const DEFAULT_LIMITS: StreamLimits = {\n  max_chunk_bytes: 1_048_576,\n  max_session_duration_ms: 3_600_000,\n  max_chunks: 2000,\n};\n"],"mappings":";AASA,IAAI;AAGG,SAAS,qBAAyC;AACvD,SAAO;AACT;AAEO,SAAS,mBAAmB,WAAqC;AACtE,qBAAmB;AACrB;AAIA,IAAI;AAGG,SAAS,sBAA4B;AAC1C,oBAAkB;AACpB;AAEO,SAAS,qBAAqB,MAA2C;AAC9E,oBAAkB;AACpB;AAIA,IAAI;AAGG,SAAS,kBAAkB,SAA0B,eAAqB;AAC/E,oBAAkB,MAAM;AAC1B;AAEO,SAAS,qBAAqB,MAA2C;AAC9E,oBAAkB;AACpB;;;ACfO,IAAM,yBAAgD;AAAA,EAC3D,mBAAmB;AAAA,EACnB,iBAAiB;AAAA,EACjB,eAAe;AAAA,EACf,aAAa;AAAA,EACb,eAAe;AACjB;AAyBO,IAAM,iBAA+B;AAAA,EAC1C,iBAAiB;AAAA,EACjB,yBAAyB;AAAA,EACzB,YAAY;AACd;","names":[]}