@usero/sdk 0.3.4 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/plugins/session-replay.ts"],"names":[],"mappings":";AA0IA,IAAM,QAAA,GAA4B;AAAA,EACjC,YAAA,EAAc,CAAA;AAAA,EACd,UAAA,EAAY,CAAA;AAAA,EACZ,QAAA,EAAU,EAAE,SAAA,EAAW,EAAA,EAAI,QAAQ,GAAA,EAAI;AAAA,EACvC,aAAA,EAAe,IAAA;AAAA,EACf,gBAAA,EAAkB,mBAAA;AAAA,EAClB,gBAAA,EAAkB,IAAA;AAAA,EAClB,aAAA,EAAe,oBAAA;AAAA,EACf,YAAA,EAAc,EAAA;AAAA,EACd,cAAA,EAAgB,GAAA;AAAA,EAChB,gBAAA,EAAkB,CAAA;AAAA,EAClB,MAAA,EAAQ;AACT,CAAA;AAEA,IAAM,uBAAA,GAA0B,qCAAA;AAChC,IAAM,mBAAA,GAAsB,IAAI,IAAA,GAAO,IAAA;AAEvC,SAAS,cAAc,KAAA,EAA2B;AACjD,EAAA,IAAI,MAAA,GAAS,EAAA;AACb,EAAA,MAAM,SAAA,GAAY,KAAA;AAClB,EAAA,KAAA,IAAS,IAAI,CAAA,EAAG,CAAA,GAAI,KAAA,CAAM,MAAA,EAAQ,KAAK,SAAA,EAAW;AACjD,IAAA,MAAM,KAAA,GAAQ,KAAA,CAAM,QAAA,CAAS,CAAA,EAAG,IAAI,SAAS,CAAA;AAC7C,IAAA,MAAA,IAAU,OAAO,YAAA,CAAa,KAAA,CAAM,MAAM,KAAA,CAAM,IAAA,CAAK,KAAK,CAAC,CAAA;AAAA,EAC5D;AACA,EAAA,OAAO,OAAO,IAAA,KAAS,UAAA,GAAa,IAAA,CAAK,MAAM,CAAA,GAAI,EAAA;AACpD;AAEA,eAAe,UAAU,KAAA,EAAoC;AAC5D,EAAA,IAAI,OAAO,sBAAsB,WAA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AACA,MAAA,IAAI,MAAM,mBAAA,EAAqB;AAC9B,QAAA,MAAA,CAAO,mBAAA,CAAoB,qBAAA,EAAuB,KAAA,CAAM,mBAAmB,CAAA;AAC3E,QAAA,KAAA,CAAM,mBAAA,GAAsB,IAAA;AAAA,MAC7B;AAIA,MAAA,IAAI,KAAA,CAAM,eAAA,IAAmB,CAAC,KAAA,CAAM,OAAA,EAAS;AAC5C,QAAA,QAAA,CAAS,KAAA,EAAO,GAAA,EAAK,EAAE,SAAA,EAAW,OAAO,CAAA;AAAA,MAC1C;AACA,MAAA,KAAA,CAAM,OAAA,GAAU,IAAA;AAChB,MAAA,SAAA,CAAU,KAAK,CAAA;AACf,MAAA,KAAA,CAAM,cAAc,MAAA,GAAS,CAAA;AAAA,IAC9B;AAAA,GACD;AACD;AAMO,SAAS,kBAAkB,GAAA,EAAiD;AAClF,EAAA,MAAM,KAAA,GAAQ,IAAI,QAAA,EAAsB;AACxC,EAAA,IAAI,CAAC,SAAS,KAAA,CAAM,SAAA,IAAa,MAAM,OAAA,IAAW,CAAC,KAAA,CAAM,eAAA,EAAiB,OAAO,IAAA;AACjF,EAAA,MAAM,QAAA,GACL,KAAA,CAAM,kBAAA,KAAuB,IAAA,GAC1B,IAAA,CAAK,GAAA,CAAI,CAAA,EAAG,IAAA,CAAK,GAAA,EAAI,GAAI,KAAA,CAAM,kBAAkB,CAAA,GACjD,CAAA;AACJ,EAAA,OAAO,EAAE,EAAA,EAAI,KAAA,CAAM,eAAA,EAAiB,QAAA,EAAS;AAC9C;AAGO,IAAM,QAAA,GAAW;AAAA,EACvB,aAAA;AAAA,EACA,SAAA;AAAA,EACA,gBAAA;AAAA,EACA,WAAA;AAAA,EACA,aAAA;AAAA,EACA,OAAA;AAAA,EACA,mBAAA;AAAA,EACA;AACD","file":"session-replay.js","sourcesContent":["// Session replay plugin for the Usero widget.\n//\n// Streams rrweb events to the SaaS side as gzipped chunks while the user\n// is on the page, instead of buffering in memory and attaching to a\n// feedback submission. This decouples session replay from feedback so we\n// capture every session (subject to bot-gate + sampling + engagement\n// gates), not just the ones that submit feedback.\n//\n// Lifecycle:\n// 1. onInit: dice-roll sample, optional engagement-time gate, mint a\n// stable per-tab `sdkSessionId` in sessionStorage, and POST to\n// /api/replay-sessions to create the row. If the server returns\n// `{accepted:false}` (bot-gated), the plugin no-ops the rest of the\n// session and getCurrentSession() returns null.\n// 2. Recording: lazy-load rrweb, append events to a buffer, flush a\n// chunk every `chunkSeconds` (or sooner if the buffer is large).\n// Each chunk is gzipped via CompressionStream and PUT to\n// /api/replay-sessions/:id/chunks/:seq with raw bytes + the three\n// X-Usero-* headers (Client-Id, Event-Count, Duration-Ms). Retries\n// with exponential backoff. R2 head-check makes retries idempotent\n// server-side. A chunk PUT returning 409 stops the session.\n// 3. onFeedbackSubmit: returns `{sessionReplayId, replayOffsetMs}` so\n// the feedback record can FK at the moment of submit. Does NOT\n// attach `replayEvents` (legacy field) — chunked uploads carry the\n// events out-of-band.\n// 4. onDestroy / pagehide: best-effort flush remaining buffer, then\n// sendBeacon to /api/replay-sessions/:id/finalise with the\n// end-timestamp. Idempotent server-side.\n//\n// Bundle hygiene: rrweb stays lazy via dynamic `import('rrweb')` behind\n// the engagement gate, so consumers who lose the dice roll or navigate\n// away inside the gate window pay zero rrweb bytes.\n\nimport type { UseroPlugin, PluginContext } from '../plugin'\n\nexport interface ReplaySampling {\n\tmousemove?: number\n\tscroll?: number\n\tmedia?: number\n\tinput?: number | 'last'\n}\n\nexport interface SessionReplayOptions {\n\t// Wait this many ms after page load before loading rrweb and creating\n\t// the session row. If the user navigates away first, rrweb is never\n\t// loaded and no session row is created. Default 0 (start immediately).\n\tstartAfterMs?: number\n\t// Probability (0..1) that this session records at all. Decided once\n\t// at init via Math.random(). Default 1.\n\tsampleRate?: number\n\t// rrweb sampling rates per event type.\n\tsampling?: ReplaySampling\n\t// Mask all <input>/<textarea> values in the recording. Default true.\n\tmaskAllInputs?: boolean\n\t// CSS selector for nodes whose text content should be masked. Default\n\t// `[data-usero-mask]`.\n\tmaskTextSelector?: string\n\t// Inline external stylesheets so the replay viewer renders correctly\n\t// without network access. Default true.\n\tinlineStylesheet?: boolean\n\t// Block (entirely skip) DOM subtrees matching this selector. Default\n\t// `[data-usero-block]`.\n\tblockSelector?: string\n\t// Flush a chunk every N seconds. Default 10. Smaller = more PUTs but\n\t// less data lost on tab crash.\n\tchunkSeconds?: number\n\t// Soft cap on buffered events before forcing a flush, regardless of\n\t// time. Default 5000.\n\tchunkMaxEvents?: number\n\t// Max attempts per chunk before giving up. Default 5.\n\tchunkMaxAttempts?: number\n\t// API origin. Override for self-hosted or local dev. Defaults to the\n\t// PluginContext baseUrl threaded through by the widget.\n\tapiUrl?: string\n}\n\ninterface RrwebEvent {\n\ttype: number\n\tdata: unknown\n\ttimestamp: number\n}\n\ninterface RrwebRecordOptions {\n\temit: (event: RrwebEvent) => void\n\tmaskAllInputs?: boolean\n\tmaskTextSelector?: string\n\tinlineStylesheet?: boolean\n\tblockSelector?: string\n\tsampling?: ReplaySampling\n}\n\ninterface RrwebRecordFn {\n\t(opts: RrwebRecordOptions): () => void\n\ttakeFullSnapshot?: (isCheckout?: boolean) => void\n}\n\ntype RrwebRecord = RrwebRecordFn\n\ninterface ResolvedOptions {\n\tstartAfterMs: number\n\tsampleRate: number\n\tsampling: ReplaySampling\n\tmaskAllInputs: boolean\n\tmaskTextSelector: string\n\tinlineStylesheet: boolean\n\tblockSelector: string\n\tchunkSeconds: number\n\tchunkMaxEvents: number\n\tchunkMaxAttempts: number\n\tapiUrl: string\n}\n\ninterface ReplayStore {\n\toptions: ResolvedOptions\n\tclientId: string\n\tsdkSessionId: string\n\tsessionReplayId: string | null\n\t// Wall-clock timestamp (ms) of the first event we ever recorded.\n\t// Used to compute replayOffsetMs at feedback-submit time.\n\trecordingStartedAt: number | null\n\tpendingEvents: RrwebEvent[]\n\tpendingFirstTs: number | null\n\tpendingLastTs: number | null\n\tnextChunkSeq: number\n\tuploadQueue: Promise<void>\n\tpendingUploads: number\n\tchunkFlushTimer: ReturnType<typeof setInterval> | null\n\tstartTimer: ReturnType<typeof setTimeout> | null\n\tpageHideHandler: (() => void) | null\n\tshadowUpdateHandler: ((event: Event) => void) | null\n\trecord: RrwebRecord | null\n\tstopRecording: (() => void) | null\n\tloadInProgress: boolean\n\tcancelled: boolean\n\t// True once the session is \"done\": bot-gated, finalised, or destroyed.\n\tstopped: boolean\n}\n\nconst DEFAULTS: ResolvedOptions = {\n\tstartAfterMs: 0,\n\tsampleRate: 1,\n\tsampling: { mousemove: 50, scroll: 100 },\n\tmaskAllInputs: true,\n\tmaskTextSelector: '[data-usero-mask]',\n\tinlineStylesheet: true,\n\tblockSelector: '[data-usero-block]',\n\tchunkSeconds: 10,\n\tchunkMaxEvents: 5000,\n\tchunkMaxAttempts: 5,\n\tapiUrl: '',\n}\n\nconst SDK_SESSION_STORAGE_KEY = 'usero:session-replay:sdk-session-id'\nconst HARD_CHUNK_BYTE_CAP = 4 * 1024 * 1024\n\nfunction uint8ToBase64(bytes: Uint8Array): string {\n\tlet binary = ''\n\tconst chunkSize = 0x8000\n\tfor (let i = 0; i < bytes.length; i += chunkSize) {\n\t\tconst slice = bytes.subarray(i, i + chunkSize)\n\t\tbinary += String.fromCharCode.apply(null, Array.from(slice))\n\t}\n\treturn typeof btoa === 'function' ? btoa(binary) : ''\n}\n\nasync function gzipBytes(input: string): Promise<Uint8Array> {\n\tif (typeof CompressionStream === 'undefined') {\n\t\t// Old browsers: send uncompressed JSON. Acceptable degradation;\n\t\t// the server endpoint accepts raw application/octet-stream.\n\t\treturn new TextEncoder().encode(input)\n\t}\n\tconst stream = new Blob([input]).stream().pipeThrough(new CompressionStream('gzip'))\n\tconst buf = await new Response(stream).arrayBuffer()\n\treturn new Uint8Array(buf)\n}\n\nfunction generateRandomId(): string {\n\tif (typeof crypto !== 'undefined' && typeof crypto.randomUUID === 'function') {\n\t\treturn crypto.randomUUID()\n\t}\n\tconst bytes = new Uint8Array(16)\n\tif (typeof crypto !== 'undefined' && typeof crypto.getRandomValues === 'function') {\n\t\tcrypto.getRandomValues(bytes)\n\t} else {\n\t\tfor (let i = 0; i < bytes.length; i += 1) bytes[i] = Math.floor(Math.random() * 256)\n\t}\n\tlet out = ''\n\tfor (const b of bytes) out += b.toString(16).padStart(2, '0')\n\treturn out\n}\n\nfunction mintSdkSessionId(): string {\n\ttry {\n\t\tconst existing = window.sessionStorage?.getItem(SDK_SESSION_STORAGE_KEY)\n\t\tif (existing && /^[a-z0-9-]{8,}$/i.test(existing)) return existing\n\t} catch {\n\t\t// sessionStorage can throw in sandboxed iframes — fall through.\n\t}\n\tconst id = generateRandomId()\n\ttry {\n\t\twindow.sessionStorage?.setItem(SDK_SESSION_STORAGE_KEY, id)\n\t} catch {\n\t\t// Ignore: we still return the freshly minted id.\n\t}\n\treturn id\n}\n\nfunction joinUrl(apiUrl: string, path: string): string {\n\treturn `${apiUrl.replace(/\\/$/, '')}${path}`\n}\n\ninterface CreateSessionResult {\n\taccepted: boolean\n\tsessionReplayId?: string\n\tdropReason?: string\n}\n\nasync function createSession(\n\tapiUrl: string,\n\tclientId: string,\n\tsdkSessionId: string,\n): Promise<CreateSessionResult | null> {\n\ttry {\n\t\tconst startUrl =\n\t\t\ttypeof window !== 'undefined' && window.location ? window.location.href : undefined\n\t\tconst userAgent =\n\t\t\ttypeof navigator !== 'undefined' && navigator.userAgent ? navigator.userAgent : undefined\n\t\tconst res = await fetch(joinUrl(apiUrl, '/api/replay-sessions'), {\n\t\t\tmethod: 'POST',\n\t\t\theaders: { 'Content-Type': 'application/json' },\n\t\t\tbody: JSON.stringify({\n\t\t\t\tclientId,\n\t\t\t\tsdkSessionId,\n\t\t\t\tstartUrl,\n\t\t\t\tuserAgent,\n\t\t\t\tstartedAt: new Date().toISOString(),\n\t\t\t}),\n\t\t})\n\t\tif (!res.ok) return null\n\t\tconst json = (await res.json()) as {\n\t\t\taccepted?: unknown\n\t\t\tsessionReplayId?: unknown\n\t\t\tdropReason?: unknown\n\t\t}\n\t\tif (typeof json.accepted !== 'boolean') return null\n\t\tconst result: CreateSessionResult = { accepted: json.accepted }\n\t\tif (typeof json.sessionReplayId === 'string') result.sessionReplayId = json.sessionReplayId\n\t\tif (typeof json.dropReason === 'string') result.dropReason = json.dropReason\n\t\treturn result\n\t} catch {\n\t\treturn null\n\t}\n}\n\ninterface ChunkUploadResult {\n\tok: boolean\n\tstopSession: boolean\n}\n\nasync function uploadChunk(\n\tapiUrl: string,\n\tsessionReplayId: string,\n\tclientId: string,\n\tseq: number,\n\tbytes: Uint8Array,\n\teventCount: number,\n\tdurationMs: number,\n\tlogger: PluginContext['logger'],\n\tmaxAttempts: number,\n): Promise<ChunkUploadResult> {\n\tconst url = joinUrl(\n\t\tapiUrl,\n\t\t`/api/replay-sessions/${encodeURIComponent(sessionReplayId)}/chunks/${seq}`,\n\t)\n\tlet attempt = 0\n\twhile (attempt < maxAttempts) {\n\t\ttry {\n\t\t\t// Wrap in a Blob so the body type is unambiguously BodyInit; some\n\t\t\t// TS lib targets reject raw Uint8Array as fetch body. Slice off\n\t\t\t// the buffer to satisfy the BlobPart ArrayBuffer constraint\n\t\t\t// (Uint8Array<SharedArrayBuffer> is the alternative the lib\n\t\t\t// admits, which we never produce here).\n\t\t\tconst buffer = bytes.buffer.slice(\n\t\t\t\tbytes.byteOffset,\n\t\t\t\tbytes.byteOffset + bytes.byteLength,\n\t\t\t) as ArrayBuffer\n\t\t\tconst blob = new Blob([buffer], { type: 'application/octet-stream' })\n\t\t\tconst res = await fetch(url, {\n\t\t\t\tmethod: 'PUT',\n\t\t\t\tbody: blob,\n\t\t\t\theaders: {\n\t\t\t\t\t'Content-Type': 'application/octet-stream',\n\t\t\t\t\t'X-Usero-Client-Id': clientId,\n\t\t\t\t\t'X-Usero-Event-Count': String(eventCount),\n\t\t\t\t\t'X-Usero-Duration-Ms': String(Math.max(0, Math.round(durationMs))),\n\t\t\t\t},\n\t\t\t})\n\t\t\tif (res.ok) return { ok: true, stopSession: false }\n\t\t\t// 409: server told us to stop (bot-dropped, or session already\n\t\t\t// finalised). Don't retry, don't upload further chunks.\n\t\t\tif (res.status === 409) {\n\t\t\t\tlogger.warn(`chunk ${seq} rejected with 409, stopping session`)\n\t\t\t\treturn { ok: false, stopSession: true }\n\t\t\t}\n\t\t\t// Other 4xx (besides 408/429) won't get better with retry.\n\t\t\tif (res.status >= 400 && res.status < 500 && res.status !== 408 && res.status !== 429) {\n\t\t\t\tlogger.error(`chunk ${seq} rejected with ${res.status}`)\n\t\t\t\treturn { ok: false, stopSession: false }\n\t\t\t}\n\t\t} catch (err) {\n\t\t\tlogger.warn(`chunk ${seq} attempt ${attempt + 1} failed`, err)\n\t\t}\n\t\tattempt += 1\n\t\tconst backoff = Math.min(15_000, 500 * 2 ** attempt) + Math.floor(Math.random() * 250)\n\t\tawait new Promise(resolve => setTimeout(resolve, backoff))\n\t}\n\tlogger.error(`chunk ${seq} dropped after ${maxAttempts} attempts`)\n\treturn { ok: false, stopSession: false }\n}\n\nasync function loadRrwebRecord(): Promise<RrwebRecord | null> {\n\ttry {\n\t\tconst mod: unknown = await import(/* webpackChunkName: \"rrweb\" */ 'rrweb')\n\t\tif (\n\t\t\tmod &&\n\t\t\ttypeof mod === 'object' &&\n\t\t\t'record' in mod &&\n\t\t\ttypeof (mod as { record: unknown }).record === 'function'\n\t\t) {\n\t\t\treturn (mod as { record: RrwebRecord }).record\n\t\t}\n\t\treturn null\n\t} catch {\n\t\treturn null\n\t}\n}\n\nfunction scheduleChunkUpload(store: ReplayStore, ctx: PluginContext): void {\n\tif (!store.sessionReplayId) return\n\tif (store.pendingEvents.length === 0) return\n\tconst events = store.pendingEvents\n\tconst eventCount = events.length\n\tconst firstTs = store.pendingFirstTs ?? 0\n\tconst lastTs = store.pendingLastTs ?? firstTs\n\tconst durationMs = Math.max(0, lastTs - firstTs)\n\tconst seq = store.nextChunkSeq\n\tstore.nextChunkSeq += 1\n\tstore.pendingEvents = []\n\tstore.pendingFirstTs = null\n\tstore.pendingLastTs = null\n\n\tconst sessionReplayId = store.sessionReplayId\n\tconst apiUrl = store.options.apiUrl\n\tconst clientId = store.clientId\n\tconst maxAttempts = store.options.chunkMaxAttempts\n\n\tstore.pendingUploads += 1\n\tstore.uploadQueue = store.uploadQueue.then(async () => {\n\t\ttry {\n\t\t\tif (store.cancelled) return\n\t\t\tconst json = JSON.stringify(events)\n\t\t\tconst bytes = await gzipBytes(json)\n\t\t\tif (bytes.byteLength > HARD_CHUNK_BYTE_CAP) {\n\t\t\t\tctx.logger.error(\n\t\t\t\t\t`chunk ${seq} exceeds 4MB hard cap (${bytes.byteLength} bytes), dropping`,\n\t\t\t\t)\n\t\t\t\treturn\n\t\t\t}\n\t\t\tconst result = await uploadChunk(\n\t\t\t\tapiUrl,\n\t\t\t\tsessionReplayId,\n\t\t\t\tclientId,\n\t\t\t\tseq,\n\t\t\t\tbytes,\n\t\t\t\teventCount,\n\t\t\t\tdurationMs,\n\t\t\t\tctx.logger,\n\t\t\t\tmaxAttempts,\n\t\t\t)\n\t\t\tif (result.stopSession) {\n\t\t\t\tstore.stopped = true\n\t\t\t\tstopRrweb(store)\n\t\t\t}\n\t\t} catch (err) {\n\t\t\tctx.logger.error(`chunk ${seq} encode failed`, err)\n\t\t} finally {\n\t\t\tstore.pendingUploads -= 1\n\t\t}\n\t})\n}\n\nfunction flushPendingChunk(store: ReplayStore, ctx: PluginContext): void {\n\tif (store.stopped || store.cancelled) return\n\tif (store.pendingEvents.length === 0) return\n\tscheduleChunkUpload(store, ctx)\n}\n\nfunction stopRrweb(store: ReplayStore): void {\n\tif (store.stopRecording) {\n\t\ttry {\n\t\t\tstore.stopRecording()\n\t\t} catch {\n\t\t\t// Already stopped.\n\t\t}\n\t\tstore.stopRecording = null\n\t}\n\tif (store.chunkFlushTimer) {\n\t\tclearInterval(store.chunkFlushTimer)\n\t\tstore.chunkFlushTimer = null\n\t}\n}\n\nfunction startRecording(store: ReplayStore, ctx: PluginContext): void {\n\tif (store.cancelled || store.stopped || store.stopRecording || store.loadInProgress) return\n\tstore.loadInProgress = true\n\tvoid loadRrwebRecord().then(record => {\n\t\tstore.loadInProgress = false\n\t\tif (store.cancelled || store.stopped || !record) {\n\t\t\tif (!record) ctx.logger.warn('rrweb failed to load, replay disabled')\n\t\t\treturn\n\t\t}\n\t\ttry {\n\t\t\tconst stop = record({\n\t\t\t\temit: event => {\n\t\t\t\t\tif (store.stopped || store.cancelled) return\n\t\t\t\t\tif (store.recordingStartedAt === null) store.recordingStartedAt = event.timestamp\n\t\t\t\t\tstore.pendingEvents.push(event)\n\t\t\t\t\tif (store.pendingFirstTs === null) store.pendingFirstTs = event.timestamp\n\t\t\t\t\tstore.pendingLastTs = event.timestamp\n\t\t\t\t\tif (store.pendingEvents.length >= store.options.chunkMaxEvents) {\n\t\t\t\t\t\tscheduleChunkUpload(store, ctx)\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\tmaskAllInputs: store.options.maskAllInputs,\n\t\t\t\tmaskTextSelector: store.options.maskTextSelector || undefined,\n\t\t\t\tinlineStylesheet: store.options.inlineStylesheet,\n\t\t\t\tblockSelector: store.options.blockSelector,\n\t\t\t\tsampling: store.options.sampling,\n\t\t\t})\n\t\t\tstore.stopRecording = stop\n\t\t\tstore.record = record\n\t\t\tscheduleShadowSnapshot(store, ctx)\n\n\t\t\tstore.chunkFlushTimer = setInterval(\n\t\t\t\t() => flushPendingChunk(store, ctx),\n\t\t\t\tstore.options.chunkSeconds * 1000,\n\t\t\t)\n\t\t} catch (err) {\n\t\t\tctx.logger.error('rrweb record() threw', err)\n\t\t}\n\t})\n}\n\nfunction scheduleShadowSnapshot(store: ReplayStore, ctx: PluginContext): void {\n\tif (store.cancelled || store.stopped || !store.record || !store.stopRecording) return\n\tconst fn = store.record.takeFullSnapshot\n\tif (typeof fn !== 'function') return\n\ttry {\n\t\tfn(true)\n\t} catch (err) {\n\t\tctx.logger.warn('takeFullSnapshot threw', err)\n\t}\n}\n\nfunction finalise(store: ReplayStore, ctx: PluginContext, opts: { useBeacon: boolean }): void {\n\tif (!store.sessionReplayId) return\n\tif (store.pendingEvents.length > 0) flushPendingChunk(store, ctx)\n\tconst url = joinUrl(\n\t\tstore.options.apiUrl,\n\t\t`/api/replay-sessions/${encodeURIComponent(store.sessionReplayId)}/finalise`,\n\t)\n\tconst body = JSON.stringify({ clientId: store.clientId, endedAt: new Date().toISOString() })\n\tif (opts.useBeacon && typeof navigator !== 'undefined' && navigator.sendBeacon) {\n\t\ttry {\n\t\t\tconst blob = new Blob([body], { type: 'application/json' })\n\t\t\tnavigator.sendBeacon(url, blob)\n\t\t\treturn\n\t\t} catch (err) {\n\t\t\tctx.logger.warn('finalise sendBeacon threw', err)\n\t\t}\n\t}\n\tvoid fetch(url, {\n\t\tmethod: 'POST',\n\t\tbody,\n\t\theaders: { 'Content-Type': 'application/json' },\n\t\tkeepalive: true,\n\t}).catch(err => ctx.logger.warn('finalise fetch failed', err))\n}\n\nexport interface CurrentSessionHandle {\n\tid: string\n\toffsetMs: number\n}\n\nexport function sessionReplay(options: SessionReplayOptions = {}): UseroPlugin {\n\tconst merged: ResolvedOptions = {\n\t\t...DEFAULTS,\n\t\t...options,\n\t\tsampling: { ...DEFAULTS.sampling, ...(options.sampling ?? {}) },\n\t}\n\n\treturn {\n\t\tname: 'session-replay',\n\t\tonInit(ctx) {\n\t\t\tif (typeof window === 'undefined') return\n\t\t\tif (merged.sampleRate < 1 && Math.random() >= merged.sampleRate) {\n\t\t\t\tctx.logger.debug('skipped by sampleRate')\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tconst apiUrl = merged.apiUrl || ctx.baseUrl\n\t\t\tif (!apiUrl) {\n\t\t\t\tctx.logger.error('session-replay needs an apiUrl (via options or PluginContext)')\n\t\t\t\treturn\n\t\t\t}\n\t\t\tconst sdkSessionId = mintSdkSessionId()\n\n\t\t\tconst store: ReplayStore = {\n\t\t\t\toptions: { ...merged, apiUrl },\n\t\t\t\tclientId: ctx.clientId,\n\t\t\t\tsdkSessionId,\n\t\t\t\tsessionReplayId: null,\n\t\t\t\trecordingStartedAt: null,\n\t\t\t\tpendingEvents: [],\n\t\t\t\tpendingFirstTs: null,\n\t\t\t\tpendingLastTs: null,\n\t\t\t\tnextChunkSeq: 0,\n\t\t\t\tuploadQueue: Promise.resolve(),\n\t\t\t\tpendingUploads: 0,\n\t\t\t\tchunkFlushTimer: null,\n\t\t\t\tstartTimer: null,\n\t\t\t\tpageHideHandler: null,\n\t\t\t\tshadowUpdateHandler: null,\n\t\t\t\trecord: null,\n\t\t\t\tstopRecording: null,\n\t\t\t\tloadInProgress: false,\n\t\t\t\tcancelled: false,\n\t\t\t\tstopped: false,\n\t\t\t}\n\t\t\tctx.setStore(store)\n\n\t\t\tconst onShadowUpdate = (): void => scheduleShadowSnapshot(store, ctx)\n\t\t\tstore.shadowUpdateHandler = onShadowUpdate\n\t\t\twindow.addEventListener('usero:shadow-update', onShadowUpdate)\n\n\t\t\tconst onPageHide = (): void => {\n\t\t\t\tfinalise(store, ctx, { useBeacon: true })\n\t\t\t\tstore.stopped = true\n\t\t\t\tstopRrweb(store)\n\t\t\t}\n\t\t\tstore.pageHideHandler = onPageHide\n\t\t\twindow.addEventListener('pagehide', onPageHide)\n\n\t\t\tconst begin = async (): Promise<void> => {\n\t\t\t\tif (store.cancelled) return\n\t\t\t\tconst created = await createSession(apiUrl, ctx.clientId, sdkSessionId)\n\t\t\t\tif (!created) {\n\t\t\t\t\tctx.logger.warn('session create failed, replay disabled')\n\t\t\t\t\tstore.stopped = true\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\tif (!created.accepted) {\n\t\t\t\t\tctx.logger.info(`session-replay declined: ${created.dropReason ?? 'unknown'}`)\n\t\t\t\t\tstore.stopped = true\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\tif (!created.sessionReplayId) {\n\t\t\t\t\tctx.logger.error('server accepted but returned no sessionReplayId')\n\t\t\t\t\tstore.stopped = true\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\tstore.sessionReplayId = created.sessionReplayId\n\t\t\t\tstore.recordingStartedAt = Date.now()\n\t\t\t\tstartRecording(store, ctx)\n\t\t\t}\n\n\t\t\tif (merged.startAfterMs > 0) {\n\t\t\t\tconst cancelOnExit = (): void => {\n\t\t\t\t\tstore.cancelled = true\n\t\t\t\t\tif (store.startTimer) {\n\t\t\t\t\t\tclearTimeout(store.startTimer)\n\t\t\t\t\t\tstore.startTimer = null\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\twindow.addEventListener('pagehide', cancelOnExit, { once: true })\n\t\t\t\twindow.addEventListener('beforeunload', cancelOnExit, { once: true })\n\t\t\t\tstore.startTimer = setTimeout(() => {\n\t\t\t\t\tvoid begin()\n\t\t\t\t}, merged.startAfterMs)\n\t\t\t} else {\n\t\t\t\tvoid begin()\n\t\t\t}\n\t\t},\n\t\tonFeedbackSubmit(ctx) {\n\t\t\tconst store = ctx.getStore<ReplayStore>()\n\t\t\tif (!store || store.cancelled || store.stopped) return undefined\n\t\t\tif (!store.sessionReplayId) return undefined\n\t\t\tconst offsetMs =\n\t\t\t\tstore.recordingStartedAt !== null\n\t\t\t\t\t? Math.max(0, Date.now() - store.recordingStartedAt)\n\t\t\t\t\t: 0\n\t\t\treturn { sessionReplayId: store.sessionReplayId, replayOffsetMs: offsetMs }\n\t\t},\n\t\tonDestroy(ctx) {\n\t\t\tconst store = ctx.getStore<ReplayStore>()\n\t\t\tif (!store) return\n\t\t\tstore.cancelled = true\n\t\t\tif (store.startTimer) {\n\t\t\t\tclearTimeout(store.startTimer)\n\t\t\t\tstore.startTimer = null\n\t\t\t}\n\t\t\tif (store.pageHideHandler) {\n\t\t\t\twindow.removeEventListener('pagehide', store.pageHideHandler)\n\t\t\t\tstore.pageHideHandler = null\n\t\t\t}\n\t\t\tif (store.shadowUpdateHandler) {\n\t\t\t\twindow.removeEventListener('usero:shadow-update', store.shadowUpdateHandler)\n\t\t\t\tstore.shadowUpdateHandler = null\n\t\t\t}\n\t\t\t// SPA route change / React unmount: send a finalise so the\n\t\t\t// server stamps endedAt. fetch+keepalive is fine here since we\n\t\t\t// aren't necessarily in a pagehide path.\n\t\t\tif (store.sessionReplayId && !store.stopped) {\n\t\t\t\tfinalise(store, ctx, { useBeacon: false })\n\t\t\t}\n\t\t\tstore.stopped = true\n\t\t\tstopRrweb(store)\n\t\t\tstore.pendingEvents.length = 0\n\t\t},\n\t}\n}\n\n// Returns the live session-replay handle for a given plugin context, or\n// null if the session was bot-dropped, sample-skipped, or not yet\n// created. Other plugins (e.g. user-test) can call this to attach the\n// replay FK + offset to their own server-side records.\nexport function getCurrentSession(ctx: PluginContext): CurrentSessionHandle | null {\n\tconst store = ctx.getStore<ReplayStore>()\n\tif (!store || store.cancelled || store.stopped || !store.sessionReplayId) return null\n\tconst offsetMs =\n\t\tstore.recordingStartedAt !== null\n\t\t\t? Math.max(0, Date.now() - store.recordingStartedAt)\n\t\t\t: 0\n\treturn { id: store.sessionReplayId, offsetMs }\n}\n\n// Internal helper exports for testing only. Not part of the public API.\nexport const __test__ = {\n\tuint8ToBase64,\n\tgzipBytes,\n\tmintSdkSessionId,\n\tuploadChunk,\n\tcreateSession,\n\tjoinUrl,\n\tHARD_CHUNK_BYTE_CAP,\n\tSDK_SESSION_STORAGE_KEY,\n}\n"]}
1
+ {"version":3,"sources":["../../src/identity.ts","../../src/plugins/session-replay.ts"],"names":["generateRandomId"],"mappings":";AAeA,IAAM,gBAAA,GAAmB,oBAAA;AAEzB,IAAI,iBAAA,GAAmC,IAAA;AAgBvC,SAAS,gBAAA,GAA2B;AACnC,EAAA,IAAI,OAAO,MAAA,KAAW,WAAA,IAAe,OAAO,MAAA,CAAO,eAAe,UAAA,EAAY;AAC7E,IAAA,OAAO,OAAO,UAAA,EAAW;AAAA,EAC1B;AACA,EAAA,MAAM,KAAA,GAAQ,IAAI,UAAA,CAAW,EAAE,CAAA;AAC/B,EAAA,IAAI,OAAO,MAAA,KAAW,WA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AAA,EAAI,GAAI,KAAA,CAAM,kBAAkB,CAAA,GACjD,CAAA;AACJ,EAAA,OAAO,EAAE,EAAA,EAAI,KAAA,CAAM,eAAA,EAAiB,QAAA,EAAS;AAC9C;AAGO,IAAM,QAAA,GAAW;AAAA,EACvB,aAAA;AAAA,EACA,SAAA;AAAA,EACA,gBAAA;AAAA,EACA,WAAA;AAAA,EACA,aAAA;AAAA,EACA,OAAA;AAAA,EACA,mBAAA;AAAA,EACA;AACD","file":"session-replay.js","sourcesContent":["// Identity layer for the Usero SDK.\n//\n// Two responsibilities:\n// 1. Mint and persist a stable per-browser `anonymousId` in localStorage\n// so cross-tab + cross-day replays from the same browser stitch\n// together server-side. Falls back to an in-memory id if storage is\n// blocked (sandboxed iframes, Safari Lockdown, full quota). Replay\n// still works in that case, you just lose stitching.\n// 2. Auto-fire POST /api/identify when the resolved user transitions\n// (null -> id, id -> id'). Deduped by an in-memory fingerprint so\n// re-renders with the same user are no-ops on the network.\n//\n// All storage access is wrapped in try/catch and gated behind a one-shot\n// init read. The hot path (replay chunk flush) never touches localStorage.\n\nconst ANON_STORAGE_KEY = 'usero:anonymous-id'\n\nlet cachedAnonymousId: string | null = null\n// Fingerprint of the last identify we POSTed. Same SDK instance + same\n// resolved user + same traits = no-op. Cleared on logout (anonymousId\n// rotation).\nlet lastIdentifyFingerprint: string | null = null\n\nexport type UserTraitValue = string | number | boolean | null\nexport type UserTraits = Record<string, UserTraitValue>\n\nexport interface UseroUser {\n\tid: string\n\temail?: string\n\tdisplayName?: string\n\ttraits?: UserTraits\n}\n\nfunction generateRandomId(): string {\n\tif (typeof crypto !== 'undefined' && typeof crypto.randomUUID === 'function') {\n\t\treturn crypto.randomUUID()\n\t}\n\tconst bytes = new Uint8Array(16)\n\tif (typeof crypto !== 'undefined' && typeof crypto.getRandomValues === 'function') {\n\t\tcrypto.getRandomValues(bytes)\n\t} else {\n\t\tfor (let i = 0; i < bytes.length; i += 1) bytes[i] = Math.floor(Math.random() * 256)\n\t}\n\tlet out = ''\n\tfor (const b of bytes) out += b.toString(16).padStart(2, '0')\n\treturn out\n}\n\nfunction safeReadLocalStorage(key: string): string | null {\n\tif (typeof window === 'undefined') return null\n\ttry {\n\t\treturn window.localStorage?.getItem(key) ?? null\n\t} catch {\n\t\treturn null\n\t}\n}\n\nfunction safeWriteLocalStorage(key: string, value: string): void {\n\tif (typeof window === 'undefined') return\n\ttry {\n\t\twindow.localStorage?.setItem(key, value)\n\t} catch {\n\t\t// Sandboxed iframe / Safari Lockdown / quota. Fall back to memory.\n\t}\n}\n\n/**\n * Returns the stable per-browser anonymousId. Reads localStorage at most\n * once per SDK instance. Subsequent calls hit the in-memory cache, so\n * even hot paths (per-event in replay) are safe to call this.\n */\nexport function getOrMintAnonymousId(): string {\n\tif (cachedAnonymousId) return cachedAnonymousId\n\tconst existing = safeReadLocalStorage(ANON_STORAGE_KEY)\n\t// Sanity filter, not strict validation. We accept anything that looks\n\t// plausibly like an id (>=8 alphanumeric-or-hyphen) so older SDK\n\t// versions that wrote a slightly different shape still stitch. Fresh\n\t// mint is cheap, so we only reject obvious garbage; tightening this\n\t// would force rotation in customer browsers and split otherwise-good\n\t// sibling-session attribution.\n\tif (existing && /^[a-z0-9-]{8,}$/i.test(existing)) {\n\t\tcachedAnonymousId = existing\n\t\treturn existing\n\t}\n\tconst id = generateRandomId()\n\tsafeWriteLocalStorage(ANON_STORAGE_KEY, id)\n\tcachedAnonymousId = id\n\treturn id\n}\n\n/**\n * Rotate the anonymousId. Called on logout (user transitions from a\n * known id to null) so the next anonymous trail does not get auto-merged\n * into the previous person on the next identify().\n */\nexport function rotateAnonymousId(): string {\n\tconst id = generateRandomId()\n\tcachedAnonymousId = id\n\tsafeWriteLocalStorage(ANON_STORAGE_KEY, id)\n\tlastIdentifyFingerprint = null\n\treturn id\n}\n\nfunction fingerprintUser(anonymousId: string, user: UseroUser): string {\n\t// Stable across re-renders: keys sorted, traits canonicalised. Cheap\n\t// enough on the hot path (only runs when the SDK thinks the user might\n\t// have changed, never per-event).\n\tconst traits = user.traits ?? {}\n\tconst keys = Object.keys(traits).sort()\n\tconst canonical: Array<[string, UserTraitValue]> = keys.map(k => [k, traits[k] ?? null])\n\treturn JSON.stringify([anonymousId, user.id, user.email ?? null, user.displayName ?? null, canonical])\n}\n\nexport interface IdentifyTransport {\n\tapiUrl: string\n\tclientId: string\n}\n\n/**\n * POST to /api/identify if the (anonymousId, user) fingerprint differs\n * from the last call. Returns true if a network request actually fired.\n * Never throws; failures are best-effort and the caller (the widget /\n * provider) should not treat them as errors.\n *\n * Tab-unload safety: if the page is hidden when this fires (visibility\n * 'hidden' or a pagehide handler), we route the payload through\n * `navigator.sendBeacon` so the request survives unload. Otherwise we\n * use a normal fetch and only cache the fingerprint when the server\n * confirms `accepted: true`. A 200 `{ accepted: false }` (e.g.\n * `unknown_client` for a clientId that becomes valid mid-session) is\n * treated as retryable so the next call re-fires.\n */\nexport async function identifyIfChanged(transport: IdentifyTransport, user: UseroUser): Promise<boolean> {\n\tconst anonymousId = getOrMintAnonymousId()\n\tconst fp = fingerprintUser(anonymousId, user)\n\tif (fp === lastIdentifyFingerprint) return false\n\n\tconst url = `${transport.apiUrl.replace(/\\/$/, '')}/api/identify`\n\t// Body must stay under the browser's keepalive / sendBeacon cap\n\t// (~64KB across most engines) when this fires on pagehide. That\n\t// transitively caps trait payload size; in practice traits should be\n\t// small typed scalars, not blobs.\n\tconst body = JSON.stringify({\n\t\tclientId: transport.clientId,\n\t\tanonymousId,\n\t\texternalUserId: user.id,\n\t\temail: user.email,\n\t\tdisplayName: user.displayName,\n\t\ttraits: user.traits,\n\t})\n\n\t// If the document is hidden (pagehide / tab close in flight), best-effort\n\t// hand off to sendBeacon. We don't get a response back, so we optimistically\n\t// cache the fingerprint to avoid re-firing on the next page; the server is\n\t// idempotent if the page reload re-runs identify with the same payload.\n\tif (\n\t\ttypeof document !== 'undefined' &&\n\t\tdocument.visibilityState === 'hidden' &&\n\t\ttypeof navigator !== 'undefined' &&\n\t\ttypeof navigator.sendBeacon === 'function'\n\t) {\n\t\ttry {\n\t\t\tconst blob = new Blob([body], { type: 'application/json' })\n\t\t\t// sendBeacon returns false when the user agent refuses to queue\n\t\t\t// the request (size cap, or historically Safari rejecting\n\t\t\t// non-CORS-simple content types). Modern Safari accepts\n\t\t\t// application/json, but we keep a keepalive-fetch fallback so an\n\t\t\t// older WebKit that rejects the beacon still ships the identify.\n\t\t\tif (navigator.sendBeacon(url, blob)) {\n\t\t\t\tlastIdentifyFingerprint = fp\n\t\t\t\treturn true\n\t\t\t}\n\t\t} catch {\n\t\t\t// fall through to keepalive fetch below\n\t\t}\n\t}\n\n\ttry {\n\t\tconst res = await fetch(url, {\n\t\t\tmethod: 'POST',\n\t\t\theaders: { 'Content-Type': 'application/json' },\n\t\t\tbody,\n\t\t\t// keepalive lets the request survive a tab-close mid-flight on\n\t\t\t// browsers that support it; sendBeacon above is the primary path.\n\t\t\tkeepalive: true,\n\t\t})\n\t\tif (!res.ok) return true\n\t\t// Parse the response: a 200 with `accepted: false` (e.g. unknown\n\t\t// client) is retryable. Only cache the fingerprint when the server\n\t\t// confirmed it actually stored the identity.\n\t\ttry {\n\t\t\tconst json = (await res.json()) as { accepted?: unknown }\n\t\t\tif (json && json.accepted === true) lastIdentifyFingerprint = fp\n\t\t} catch {\n\t\t\t// Server returned 2xx but unparseable body: don't cache, let the\n\t\t\t// next call retry.\n\t\t}\n\t\treturn true\n\t} catch {\n\t\treturn false\n\t}\n}\n\n/**\n * Clear identify state and rotate anonymousId. Called when the resolved\n * user transitions from a known id to null (logout). The next anonymous\n * trail will get a fresh anonymousId so it does not merge into the\n * previous person.\n */\nexport function handleLogout(): void {\n\trotateAnonymousId()\n}\n\n// Test hooks (not exported from the package public surface).\nexport const __test__ = {\n\tANON_STORAGE_KEY,\n\tresetIdentityState: (): void => {\n\t\tcachedAnonymousId = null\n\t\tlastIdentifyFingerprint = null\n\t},\n}\n","// Session replay plugin for the Usero widget.\n//\n// Streams rrweb events to the SaaS side as gzipped chunks while the user\n// is on the page, instead of buffering in memory and attaching to a\n// feedback submission. This decouples session replay from feedback so we\n// capture every session (subject to bot-gate + sampling + engagement\n// gates), not just the ones that submit feedback.\n//\n// Lifecycle:\n// 1. onInit: dice-roll sample, optional engagement-time gate, mint a\n// stable per-tab `sdkSessionId` in sessionStorage, and POST to\n// /api/replay-sessions to create the row. If the server returns\n// `{accepted:false}` (bot-gated), the plugin no-ops the rest of the\n// session and getCurrentSession() returns null.\n// 2. Recording: lazy-load rrweb, append events to a buffer, flush a\n// chunk every `chunkSeconds` (or sooner if the buffer is large).\n// Each chunk is gzipped via CompressionStream and PUT to\n// /api/replay-sessions/:id/chunks/:seq with raw bytes + the three\n// X-Usero-* headers (Client-Id, Event-Count, Duration-Ms). Retries\n// with exponential backoff. R2 head-check makes retries idempotent\n// server-side. A chunk PUT returning 409 stops the session.\n// 3. onFeedbackSubmit: returns `{sessionReplayId, replayOffsetMs}` so\n// the feedback record can FK at the moment of submit. Does NOT\n// attach `replayEvents` (legacy field) — chunked uploads carry the\n// events out-of-band.\n// 4. onDestroy / pagehide: best-effort flush remaining buffer, then\n// sendBeacon to /api/replay-sessions/:id/finalise with the\n// end-timestamp. Idempotent server-side.\n//\n// Bundle hygiene: rrweb stays lazy via dynamic `import('rrweb')` behind\n// the engagement gate, so consumers who lose the dice roll or navigate\n// away inside the gate window pay zero rrweb bytes.\n\nimport { getOrMintAnonymousId } from '../identity'\nimport type { UseroPlugin, PluginContext } from '../plugin'\n\nexport interface ReplaySampling {\n\tmousemove?: number\n\tscroll?: number\n\tmedia?: number\n\tinput?: number | 'last'\n}\n\nexport interface SessionReplayOptions {\n\t// Wait this many ms after page load before loading rrweb and creating\n\t// the session row. If the user navigates away first, rrweb is never\n\t// loaded and no session row is created. Default 0 (start immediately).\n\tstartAfterMs?: number\n\t// Probability (0..1) that this session records at all. Decided once\n\t// at init via Math.random(). Default 1.\n\tsampleRate?: number\n\t// rrweb sampling rates per event type.\n\tsampling?: ReplaySampling\n\t// Mask all <input>/<textarea> values in the recording. Default true.\n\tmaskAllInputs?: boolean\n\t// CSS selector for nodes whose text content should be masked. Default\n\t// `[data-usero-mask]`.\n\tmaskTextSelector?: string\n\t// Inline external stylesheets so the replay viewer renders correctly\n\t// without network access. Default true.\n\tinlineStylesheet?: boolean\n\t// Block (entirely skip) DOM subtrees matching this selector. Default\n\t// `[data-usero-block]`.\n\tblockSelector?: string\n\t// Flush a chunk every N seconds. Default 10. Smaller = more PUTs but\n\t// less data lost on tab crash.\n\tchunkSeconds?: number\n\t// Soft cap on buffered events before forcing a flush, regardless of\n\t// time. Default 5000.\n\tchunkMaxEvents?: number\n\t// Max attempts per chunk before giving up. Default 5.\n\tchunkMaxAttempts?: number\n\t// API origin. Override for self-hosted or local dev. Defaults to the\n\t// PluginContext baseUrl threaded through by the widget.\n\tapiUrl?: string\n}\n\ninterface RrwebEvent {\n\ttype: number\n\tdata: unknown\n\ttimestamp: number\n}\n\ninterface RrwebRecordOptions {\n\temit: (event: RrwebEvent) => void\n\tmaskAllInputs?: boolean\n\tmaskTextSelector?: string\n\tinlineStylesheet?: boolean\n\tblockSelector?: string\n\tsampling?: ReplaySampling\n}\n\ninterface RrwebRecordFn {\n\t(opts: RrwebRecordOptions): () => void\n\ttakeFullSnapshot?: (isCheckout?: boolean) => void\n}\n\ntype RrwebRecord = RrwebRecordFn\n\ninterface ResolvedOptions {\n\tstartAfterMs: number\n\tsampleRate: number\n\tsampling: ReplaySampling\n\tmaskAllInputs: boolean\n\tmaskTextSelector: string\n\tinlineStylesheet: boolean\n\tblockSelector: string\n\tchunkSeconds: number\n\tchunkMaxEvents: number\n\tchunkMaxAttempts: number\n\tapiUrl: string\n}\n\ninterface ReplayStore {\n\toptions: ResolvedOptions\n\tclientId: string\n\tsdkSessionId: string\n\tsessionReplayId: string | null\n\t// Wall-clock timestamp (ms) of the first event we ever recorded.\n\t// Used to compute replayOffsetMs at feedback-submit time.\n\trecordingStartedAt: number | null\n\tpendingEvents: RrwebEvent[]\n\tpendingFirstTs: number | null\n\tpendingLastTs: number | null\n\tnextChunkSeq: number\n\tuploadQueue: Promise<void>\n\tpendingUploads: number\n\tchunkFlushTimer: ReturnType<typeof setInterval> | null\n\tstartTimer: ReturnType<typeof setTimeout> | null\n\tpageHideHandler: (() => void) | null\n\tshadowUpdateHandler: ((event: Event) => void) | null\n\trecord: RrwebRecord | null\n\tstopRecording: (() => void) | null\n\tloadInProgress: boolean\n\tcancelled: boolean\n\t// True once the session is \"done\": bot-gated, finalised, or destroyed.\n\tstopped: boolean\n}\n\nconst DEFAULTS: ResolvedOptions = {\n\tstartAfterMs: 0,\n\tsampleRate: 1,\n\tsampling: { mousemove: 50, scroll: 100 },\n\tmaskAllInputs: true,\n\tmaskTextSelector: '[data-usero-mask]',\n\tinlineStylesheet: true,\n\tblockSelector: '[data-usero-block]',\n\tchunkSeconds: 10,\n\tchunkMaxEvents: 5000,\n\tchunkMaxAttempts: 5,\n\tapiUrl: '',\n}\n\nconst SDK_SESSION_STORAGE_KEY = 'usero:session-replay:sdk-session-id'\nconst HARD_CHUNK_BYTE_CAP = 4 * 1024 * 1024\n\nfunction uint8ToBase64(bytes: Uint8Array): string {\n\tlet binary = ''\n\tconst chunkSize = 0x8000\n\tfor (let i = 0; i < bytes.length; i += chunkSize) {\n\t\tconst slice = bytes.subarray(i, i + chunkSize)\n\t\tbinary += String.fromCharCode.apply(null, Array.from(slice))\n\t}\n\treturn typeof btoa === 'function' ? btoa(binary) : ''\n}\n\nasync function gzipBytes(input: string): Promise<Uint8Array> {\n\tif (typeof CompressionStream === 'undefined') {\n\t\t// Old browsers: send uncompressed JSON. Acceptable degradation;\n\t\t// the server endpoint accepts raw application/octet-stream.\n\t\treturn new TextEncoder().encode(input)\n\t}\n\tconst stream = new Blob([input]).stream().pipeThrough(new CompressionStream('gzip'))\n\tconst buf = await new Response(stream).arrayBuffer()\n\treturn new Uint8Array(buf)\n}\n\nfunction generateRandomId(): string {\n\tif (typeof crypto !== 'undefined' && typeof crypto.randomUUID === 'function') {\n\t\treturn crypto.randomUUID()\n\t}\n\tconst bytes = new Uint8Array(16)\n\tif (typeof crypto !== 'undefined' && typeof crypto.getRandomValues === 'function') {\n\t\tcrypto.getRandomValues(bytes)\n\t} else {\n\t\tfor (let i = 0; i < bytes.length; i += 1) bytes[i] = Math.floor(Math.random() * 256)\n\t}\n\tlet out = ''\n\tfor (const b of bytes) out += b.toString(16).padStart(2, '0')\n\treturn out\n}\n\nfunction mintSdkSessionId(): string {\n\ttry {\n\t\tconst existing = window.sessionStorage?.getItem(SDK_SESSION_STORAGE_KEY)\n\t\tif (existing && /^[a-z0-9-]{8,}$/i.test(existing)) return existing\n\t} catch {\n\t\t// sessionStorage can throw in sandboxed iframes — fall through.\n\t}\n\tconst id = generateRandomId()\n\ttry {\n\t\twindow.sessionStorage?.setItem(SDK_SESSION_STORAGE_KEY, id)\n\t} catch {\n\t\t// Ignore: we still return the freshly minted id.\n\t}\n\treturn id\n}\n\nfunction joinUrl(apiUrl: string, path: string): string {\n\treturn `${apiUrl.replace(/\\/$/, '')}${path}`\n}\n\ninterface CreateSessionResult {\n\taccepted: boolean\n\tsessionReplayId?: string\n\tdropReason?: string\n}\n\nasync function createSession(\n\tapiUrl: string,\n\tclientId: string,\n\tsdkSessionId: string,\n\tanonymousId: string,\n): Promise<CreateSessionResult | null> {\n\ttry {\n\t\tconst startUrl =\n\t\t\ttypeof window !== 'undefined' && window.location ? window.location.href : undefined\n\t\tconst userAgent =\n\t\t\ttypeof navigator !== 'undefined' && navigator.userAgent ? navigator.userAgent : undefined\n\t\tconst res = await fetch(joinUrl(apiUrl, '/api/replay-sessions'), {\n\t\t\tmethod: 'POST',\n\t\t\theaders: { 'Content-Type': 'application/json' },\n\t\t\tbody: JSON.stringify({\n\t\t\t\tclientId,\n\t\t\t\tsdkSessionId,\n\t\t\t\tanonymousId,\n\t\t\t\tstartUrl,\n\t\t\t\tuserAgent,\n\t\t\t\tstartedAt: new Date().toISOString(),\n\t\t\t}),\n\t\t})\n\t\tif (!res.ok) return null\n\t\tconst json = (await res.json()) as {\n\t\t\taccepted?: unknown\n\t\t\tsessionReplayId?: unknown\n\t\t\tdropReason?: unknown\n\t\t}\n\t\tif (typeof json.accepted !== 'boolean') return null\n\t\tconst result: CreateSessionResult = { accepted: json.accepted }\n\t\tif (typeof json.sessionReplayId === 'string') result.sessionReplayId = json.sessionReplayId\n\t\tif (typeof json.dropReason === 'string') result.dropReason = json.dropReason\n\t\treturn result\n\t} catch {\n\t\treturn null\n\t}\n}\n\ninterface ChunkUploadResult {\n\tok: boolean\n\tstopSession: boolean\n}\n\nasync function uploadChunk(\n\tapiUrl: string,\n\tsessionReplayId: string,\n\tclientId: string,\n\tseq: number,\n\tbytes: Uint8Array,\n\teventCount: number,\n\tdurationMs: number,\n\tlogger: PluginContext['logger'],\n\tmaxAttempts: number,\n): Promise<ChunkUploadResult> {\n\tconst url = joinUrl(\n\t\tapiUrl,\n\t\t`/api/replay-sessions/${encodeURIComponent(sessionReplayId)}/chunks/${seq}`,\n\t)\n\tlet attempt = 0\n\twhile (attempt < maxAttempts) {\n\t\ttry {\n\t\t\t// Wrap in a Blob so the body type is unambiguously BodyInit; some\n\t\t\t// TS lib targets reject raw Uint8Array as fetch body. Slice off\n\t\t\t// the buffer to satisfy the BlobPart ArrayBuffer constraint\n\t\t\t// (Uint8Array<SharedArrayBuffer> is the alternative the lib\n\t\t\t// admits, which we never produce here).\n\t\t\tconst buffer = bytes.buffer.slice(\n\t\t\t\tbytes.byteOffset,\n\t\t\t\tbytes.byteOffset + bytes.byteLength,\n\t\t\t) as ArrayBuffer\n\t\t\tconst blob = new Blob([buffer], { type: 'application/octet-stream' })\n\t\t\tconst res = await fetch(url, {\n\t\t\t\tmethod: 'PUT',\n\t\t\t\tbody: blob,\n\t\t\t\theaders: {\n\t\t\t\t\t'Content-Type': 'application/octet-stream',\n\t\t\t\t\t'X-Usero-Client-Id': clientId,\n\t\t\t\t\t'X-Usero-Event-Count': String(eventCount),\n\t\t\t\t\t'X-Usero-Duration-Ms': String(Math.max(0, Math.round(durationMs))),\n\t\t\t\t},\n\t\t\t})\n\t\t\tif (res.ok) return { ok: true, stopSession: false }\n\t\t\t// 409: server told us to stop (bot-dropped, or session already\n\t\t\t// finalised). Don't retry, don't upload further chunks.\n\t\t\tif (res.status === 409) {\n\t\t\t\tlogger.warn(`chunk ${seq} rejected with 409, stopping session`)\n\t\t\t\treturn { ok: false, stopSession: true }\n\t\t\t}\n\t\t\t// Other 4xx (besides 408/429) won't get better with retry.\n\t\t\tif (res.status >= 400 && res.status < 500 && res.status !== 408 && res.status !== 429) {\n\t\t\t\tlogger.error(`chunk ${seq} rejected with ${res.status}`)\n\t\t\t\treturn { ok: false, stopSession: false }\n\t\t\t}\n\t\t} catch (err) {\n\t\t\tlogger.warn(`chunk ${seq} attempt ${attempt + 1} failed`, err)\n\t\t}\n\t\tattempt += 1\n\t\tconst backoff = Math.min(15_000, 500 * 2 ** attempt) + Math.floor(Math.random() * 250)\n\t\tawait new Promise(resolve => setTimeout(resolve, backoff))\n\t}\n\tlogger.error(`chunk ${seq} dropped after ${maxAttempts} attempts`)\n\treturn { ok: false, stopSession: false }\n}\n\nasync function loadRrwebRecord(): Promise<RrwebRecord | null> {\n\ttry {\n\t\tconst mod: unknown = await import(/* webpackChunkName: \"rrweb\" */ 'rrweb')\n\t\tif (\n\t\t\tmod &&\n\t\t\ttypeof mod === 'object' &&\n\t\t\t'record' in mod &&\n\t\t\ttypeof (mod as { record: unknown }).record === 'function'\n\t\t) {\n\t\t\treturn (mod as { record: RrwebRecord }).record\n\t\t}\n\t\treturn null\n\t} catch {\n\t\treturn null\n\t}\n}\n\nfunction scheduleChunkUpload(store: ReplayStore, ctx: PluginContext): void {\n\tif (!store.sessionReplayId) return\n\tif (store.pendingEvents.length === 0) return\n\t// Chunk boundary: re-resolve the user. Captures mid-session login on\n\t// replay-only installs that never open the widget. No-op via fingerprint\n\t// dedupe if nothing changed.\n\ttry {\n\t\tctx.resolveUser?.()\n\t} catch (err) {\n\t\tctx.logger.warn('resolveUser threw at chunk boundary', err)\n\t}\n\tconst events = store.pendingEvents\n\tconst eventCount = events.length\n\tconst firstTs = store.pendingFirstTs ?? 0\n\tconst lastTs = store.pendingLastTs ?? firstTs\n\tconst durationMs = Math.max(0, lastTs - firstTs)\n\tconst seq = store.nextChunkSeq\n\tstore.nextChunkSeq += 1\n\tstore.pendingEvents = []\n\tstore.pendingFirstTs = null\n\tstore.pendingLastTs = null\n\n\tconst sessionReplayId = store.sessionReplayId\n\tconst apiUrl = store.options.apiUrl\n\tconst clientId = store.clientId\n\tconst maxAttempts = store.options.chunkMaxAttempts\n\n\tstore.pendingUploads += 1\n\tstore.uploadQueue = store.uploadQueue.then(async () => {\n\t\ttry {\n\t\t\tif (store.cancelled) return\n\t\t\tconst json = JSON.stringify(events)\n\t\t\tconst bytes = await gzipBytes(json)\n\t\t\tif (bytes.byteLength > HARD_CHUNK_BYTE_CAP) {\n\t\t\t\tctx.logger.error(\n\t\t\t\t\t`chunk ${seq} exceeds 4MB hard cap (${bytes.byteLength} bytes), dropping`,\n\t\t\t\t)\n\t\t\t\treturn\n\t\t\t}\n\t\t\tconst result = await uploadChunk(\n\t\t\t\tapiUrl,\n\t\t\t\tsessionReplayId,\n\t\t\t\tclientId,\n\t\t\t\tseq,\n\t\t\t\tbytes,\n\t\t\t\teventCount,\n\t\t\t\tdurationMs,\n\t\t\t\tctx.logger,\n\t\t\t\tmaxAttempts,\n\t\t\t)\n\t\t\tif (result.stopSession) {\n\t\t\t\tstore.stopped = true\n\t\t\t\tstopRrweb(store)\n\t\t\t}\n\t\t} catch (err) {\n\t\t\tctx.logger.error(`chunk ${seq} encode failed`, err)\n\t\t} finally {\n\t\t\tstore.pendingUploads -= 1\n\t\t}\n\t})\n}\n\nfunction flushPendingChunk(store: ReplayStore, ctx: PluginContext): void {\n\tif (store.stopped || store.cancelled) return\n\tif (store.pendingEvents.length === 0) return\n\tscheduleChunkUpload(store, ctx)\n}\n\nfunction stopRrweb(store: ReplayStore): void {\n\tif (store.stopRecording) {\n\t\ttry {\n\t\t\tstore.stopRecording()\n\t\t} catch {\n\t\t\t// Already stopped.\n\t\t}\n\t\tstore.stopRecording = null\n\t}\n\tif (store.chunkFlushTimer) {\n\t\tclearInterval(store.chunkFlushTimer)\n\t\tstore.chunkFlushTimer = null\n\t}\n}\n\nfunction startRecording(store: ReplayStore, ctx: PluginContext): void {\n\tif (store.cancelled || store.stopped || store.stopRecording || store.loadInProgress) return\n\tstore.loadInProgress = true\n\tvoid loadRrwebRecord().then(record => {\n\t\tstore.loadInProgress = false\n\t\tif (store.cancelled || store.stopped || !record) {\n\t\t\tif (!record) ctx.logger.warn('rrweb failed to load, replay disabled')\n\t\t\treturn\n\t\t}\n\t\ttry {\n\t\t\tconst stop = record({\n\t\t\t\temit: event => {\n\t\t\t\t\tif (store.stopped || store.cancelled) return\n\t\t\t\t\tif (store.recordingStartedAt === null) store.recordingStartedAt = event.timestamp\n\t\t\t\t\tstore.pendingEvents.push(event)\n\t\t\t\t\tif (store.pendingFirstTs === null) store.pendingFirstTs = event.timestamp\n\t\t\t\t\tstore.pendingLastTs = event.timestamp\n\t\t\t\t\tif (store.pendingEvents.length >= store.options.chunkMaxEvents) {\n\t\t\t\t\t\tscheduleChunkUpload(store, ctx)\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\tmaskAllInputs: store.options.maskAllInputs,\n\t\t\t\tmaskTextSelector: store.options.maskTextSelector || undefined,\n\t\t\t\tinlineStylesheet: store.options.inlineStylesheet,\n\t\t\t\tblockSelector: store.options.blockSelector,\n\t\t\t\tsampling: store.options.sampling,\n\t\t\t})\n\t\t\tstore.stopRecording = stop\n\t\t\tstore.record = record\n\t\t\tscheduleShadowSnapshot(store, ctx)\n\n\t\t\tstore.chunkFlushTimer = setInterval(\n\t\t\t\t() => flushPendingChunk(store, ctx),\n\t\t\t\tstore.options.chunkSeconds * 1000,\n\t\t\t)\n\t\t} catch (err) {\n\t\t\tctx.logger.error('rrweb record() threw', err)\n\t\t}\n\t})\n}\n\nfunction scheduleShadowSnapshot(store: ReplayStore, ctx: PluginContext): void {\n\tif (store.cancelled || store.stopped || !store.record || !store.stopRecording) return\n\tconst fn = store.record.takeFullSnapshot\n\tif (typeof fn !== 'function') return\n\ttry {\n\t\tfn(true)\n\t} catch (err) {\n\t\tctx.logger.warn('takeFullSnapshot threw', err)\n\t}\n}\n\nfunction finalise(store: ReplayStore, ctx: PluginContext, opts: { useBeacon: boolean }): void {\n\tif (!store.sessionReplayId) return\n\tif (store.pendingEvents.length > 0) flushPendingChunk(store, ctx)\n\tconst url = joinUrl(\n\t\tstore.options.apiUrl,\n\t\t`/api/replay-sessions/${encodeURIComponent(store.sessionReplayId)}/finalise`,\n\t)\n\tconst body = JSON.stringify({ clientId: store.clientId, endedAt: new Date().toISOString() })\n\tif (opts.useBeacon && typeof navigator !== 'undefined' && navigator.sendBeacon) {\n\t\ttry {\n\t\t\tconst blob = new Blob([body], { type: 'application/json' })\n\t\t\tnavigator.sendBeacon(url, blob)\n\t\t\treturn\n\t\t} catch (err) {\n\t\t\tctx.logger.warn('finalise sendBeacon threw', err)\n\t\t}\n\t}\n\tvoid fetch(url, {\n\t\tmethod: 'POST',\n\t\tbody,\n\t\theaders: { 'Content-Type': 'application/json' },\n\t\tkeepalive: true,\n\t}).catch(err => ctx.logger.warn('finalise fetch failed', err))\n}\n\nexport interface CurrentSessionHandle {\n\tid: string\n\toffsetMs: number\n}\n\nexport function sessionReplay(options: SessionReplayOptions = {}): UseroPlugin {\n\tconst merged: ResolvedOptions = {\n\t\t...DEFAULTS,\n\t\t...options,\n\t\tsampling: { ...DEFAULTS.sampling, ...(options.sampling ?? {}) },\n\t}\n\n\treturn {\n\t\tname: 'session-replay',\n\t\tonInit(ctx) {\n\t\t\tif (typeof window === 'undefined') return\n\t\t\tif (merged.sampleRate < 1 && Math.random() >= merged.sampleRate) {\n\t\t\t\tctx.logger.debug('skipped by sampleRate')\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tconst apiUrl = merged.apiUrl || ctx.baseUrl\n\t\t\tif (!apiUrl) {\n\t\t\t\tctx.logger.error('session-replay needs an apiUrl (via options or PluginContext)')\n\t\t\t\treturn\n\t\t\t}\n\t\t\tconst sdkSessionId = mintSdkSessionId()\n\t\t\t// Mint or read the cross-session anonymousId. Cached in module\n\t\t\t// scope after the first call, so this stays O(1) on hot paths.\n\t\t\tconst anonymousId = getOrMintAnonymousId()\n\n\t\t\tconst store: ReplayStore = {\n\t\t\t\toptions: { ...merged, apiUrl },\n\t\t\t\tclientId: ctx.clientId,\n\t\t\t\tsdkSessionId,\n\t\t\t\tsessionReplayId: null,\n\t\t\t\trecordingStartedAt: null,\n\t\t\t\tpendingEvents: [],\n\t\t\t\tpendingFirstTs: null,\n\t\t\t\tpendingLastTs: null,\n\t\t\t\tnextChunkSeq: 0,\n\t\t\t\tuploadQueue: Promise.resolve(),\n\t\t\t\tpendingUploads: 0,\n\t\t\t\tchunkFlushTimer: null,\n\t\t\t\tstartTimer: null,\n\t\t\t\tpageHideHandler: null,\n\t\t\t\tshadowUpdateHandler: null,\n\t\t\t\trecord: null,\n\t\t\t\tstopRecording: null,\n\t\t\t\tloadInProgress: false,\n\t\t\t\tcancelled: false,\n\t\t\t\tstopped: false,\n\t\t\t}\n\t\t\tctx.setStore(store)\n\n\t\t\tconst onShadowUpdate = (): void => scheduleShadowSnapshot(store, ctx)\n\t\t\tstore.shadowUpdateHandler = onShadowUpdate\n\t\t\twindow.addEventListener('usero:shadow-update', onShadowUpdate)\n\n\t\t\tconst onPageHide = (): void => {\n\t\t\t\tfinalise(store, ctx, { useBeacon: true })\n\t\t\t\tstore.stopped = true\n\t\t\t\tstopRrweb(store)\n\t\t\t}\n\t\t\tstore.pageHideHandler = onPageHide\n\t\t\twindow.addEventListener('pagehide', onPageHide)\n\n\t\t\tconst begin = async (): Promise<void> => {\n\t\t\t\tif (store.cancelled) return\n\t\t\t\t// Replay-only customers may never open the widget, so the host's\n\t\t\t\t// user state never gets polled by the widget's interaction\n\t\t\t\t// boundaries. Re-resolve here so a mid-session login that\n\t\t\t\t// happened before session start is visible server-side before\n\t\t\t\t// the first chunk lands. Fingerprint dedupe inside\n\t\t\t\t// identifyIfChanged makes this effectively free when nothing\n\t\t\t\t// changed.\n\t\t\t\ttry {\n\t\t\t\t\tctx.resolveUser?.()\n\t\t\t\t} catch (err) {\n\t\t\t\t\tctx.logger.warn('resolveUser threw at session start', err)\n\t\t\t\t}\n\t\t\t\tconst created = await createSession(apiUrl, ctx.clientId, sdkSessionId, anonymousId)\n\t\t\t\tif (!created) {\n\t\t\t\t\tctx.logger.warn('session create failed, replay disabled')\n\t\t\t\t\tstore.stopped = true\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\tif (!created.accepted) {\n\t\t\t\t\tctx.logger.info(`session-replay declined: ${created.dropReason ?? 'unknown'}`)\n\t\t\t\t\tstore.stopped = true\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\tif (!created.sessionReplayId) {\n\t\t\t\t\tctx.logger.error('server accepted but returned no sessionReplayId')\n\t\t\t\t\tstore.stopped = true\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\tstore.sessionReplayId = created.sessionReplayId\n\t\t\t\tstore.recordingStartedAt = Date.now()\n\t\t\t\tstartRecording(store, ctx)\n\t\t\t}\n\n\t\t\tif (merged.startAfterMs > 0) {\n\t\t\t\tconst cancelOnExit = (): void => {\n\t\t\t\t\tstore.cancelled = true\n\t\t\t\t\tif (store.startTimer) {\n\t\t\t\t\t\tclearTimeout(store.startTimer)\n\t\t\t\t\t\tstore.startTimer = null\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\twindow.addEventListener('pagehide', cancelOnExit, { once: true })\n\t\t\t\twindow.addEventListener('beforeunload', cancelOnExit, { once: true })\n\t\t\t\tstore.startTimer = setTimeout(() => {\n\t\t\t\t\tvoid begin()\n\t\t\t\t}, merged.startAfterMs)\n\t\t\t} else {\n\t\t\t\tvoid begin()\n\t\t\t}\n\t\t},\n\t\tonFeedbackSubmit(ctx) {\n\t\t\tconst store = ctx.getStore<ReplayStore>()\n\t\t\tif (!store || store.cancelled || store.stopped) return undefined\n\t\t\tif (!store.sessionReplayId) return undefined\n\t\t\tconst offsetMs =\n\t\t\t\tstore.recordingStartedAt !== null\n\t\t\t\t\t? Math.max(0, Date.now() - store.recordingStartedAt)\n\t\t\t\t\t: 0\n\t\t\treturn { sessionReplayId: store.sessionReplayId, replayOffsetMs: offsetMs }\n\t\t},\n\t\tonDestroy(ctx) {\n\t\t\tconst store = ctx.getStore<ReplayStore>()\n\t\t\tif (!store) return\n\t\t\tstore.cancelled = true\n\t\t\tif (store.startTimer) {\n\t\t\t\tclearTimeout(store.startTimer)\n\t\t\t\tstore.startTimer = null\n\t\t\t}\n\t\t\tif (store.pageHideHandler) {\n\t\t\t\twindow.removeEventListener('pagehide', store.pageHideHandler)\n\t\t\t\tstore.pageHideHandler = null\n\t\t\t}\n\t\t\tif (store.shadowUpdateHandler) {\n\t\t\t\twindow.removeEventListener('usero:shadow-update', store.shadowUpdateHandler)\n\t\t\t\tstore.shadowUpdateHandler = null\n\t\t\t}\n\t\t\t// SPA route change / React unmount: send a finalise so the\n\t\t\t// server stamps endedAt. fetch+keepalive is fine here since we\n\t\t\t// aren't necessarily in a pagehide path.\n\t\t\tif (store.sessionReplayId && !store.stopped) {\n\t\t\t\tfinalise(store, ctx, { useBeacon: false })\n\t\t\t}\n\t\t\tstore.stopped = true\n\t\t\tstopRrweb(store)\n\t\t\tstore.pendingEvents.length = 0\n\t\t},\n\t}\n}\n\n// Returns the live session-replay handle for a given plugin context, or\n// null if the session was bot-dropped, sample-skipped, or not yet\n// created. Other plugins (e.g. user-test) can call this to attach the\n// replay FK + offset to their own server-side records.\nexport function getCurrentSession(ctx: PluginContext): CurrentSessionHandle | null {\n\tconst store = ctx.getStore<ReplayStore>()\n\tif (!store || store.cancelled || store.stopped || !store.sessionReplayId) return null\n\tconst offsetMs =\n\t\tstore.recordingStartedAt !== null\n\t\t\t? Math.max(0, Date.now() - store.recordingStartedAt)\n\t\t\t: 0\n\treturn { id: store.sessionReplayId, offsetMs }\n}\n\n// Internal helper exports for testing only. Not part of the public API.\nexport const __test__ = {\n\tuint8ToBase64,\n\tgzipBytes,\n\tmintSdkSessionId,\n\tuploadChunk,\n\tcreateSession,\n\tjoinUrl,\n\tHARD_CHUNK_BYTE_CAP,\n\tSDK_SESSION_STORAGE_KEY,\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/types.ts","../../src/plugins/user-test.ts"],"names":[],"mappings":";;;AAoHO,IAAM,eAAA,GAAkB,kBAAA;;;AChD/B,IAAM,eAAA,GAGF;AAAA,EACH,UAAA,EAAY,YAAA;AAAA,EACZ,YAAA,EAAc,EAAA;AAAA,EACd,MAAA,EAAQ,eAAA;AAAA,EACR,UAAA,EAAY,EAAA;AAAA,EACZ,aAAA,EAAe;AAChB,CAAA;AAEA,IAAM,uBAAA,GAA0B,6BAAA;AAChC,IAAM,QAAA,GAAW,iBAAA;AACjB,IAAM,SAAA,GAAY,gBAAA;AAWlB,SAAS,eAAe,QAAA,EAAsC;AAC7D,EAAA,IAAI,UAAU,OAAO,QAAA;AACrB,EAAA,IAAI;AACH,IAAA,MAAM,MAAA,GAAS,MAAA,CAAO,YAAA,EAAc,OAAA,CAAQ,uBAAuB,CAAA;AACnE,IAAA,IAAI,MAAA,IAAU,MAAA,CAAO,IAAA,EAAK,EAAG,OAAO,OAAO,IAAA,EAAK,CAAE,KAAA,CAAM,CAAA,EAAG,GAAG,CAAA;AAAA,EAC/D,CAAA,CAAA,MAAQ;AAAA,EAER;AACA,EAAA,OAAO,MAAA;AACR;AAEA,SAAS,YAAY,UAAA,EAAmC;AACvD,EAAA,IAAI,OAAO,MAAA,KAAW,WAAA,IAAe,OAAO,MAAA,CAAO,QAAA,KAAa,aAAa,OAAO,IAAA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vB;AAAA,GACD;AACD;AAGO,IAAM,QAAA,GAAW,EAAE,WAAA,EAAa,YAAA,EAAc,wBAAA","file":"user-test.cjs","sourcesContent":["// Shared types used by both the vanilla and React entry points.\n// Keep this file framework-free so the vanilla bundle never pulls react.\n\nexport type FeedbackRating = 1 | 2 | 3 | 4\n\nexport interface FeedbackMetadata {\n\tpageUrl: string\n\tpageTitle: string\n\treferrer?: string\n\ttimestamp: number\n}\n\nexport interface ScreenshotData {\n\tfileName: string\n\turl: string\n\tfileSize: number\n\twidth?: number\n\theight?: number\n\tmimeType: string\n}\n\nexport interface FeedbackSubmission {\n\tclientId: string\n\trating?: FeedbackRating\n\tcomment?: string\n\tuserEmail?: string\n\tpageUrl: string\n\tpageTitle: string\n\treferrer?: string\n\tenvironment?: string\n\tscreenshots?: ScreenshotData[]\n\tmetadata?: Record<string, unknown>\n\t// Legacy gzipped + base64-encoded rrweb event stream. The pre-chunked\n\t// session-replay plugin attached this on submit. The chunked-upload\n\t// plugin (>= 0.4.0) does NOT set this — it ships events out-of-band\n\t// via the chunk endpoints and points at the resulting session replay\n\t// via `sessionReplayId` + `replayOffsetMs`. Kept on the wire one\n\t// release for backward compat with old SaaS deployments that only\n\t// know how to ingest the legacy field.\n\treplayEvents?: string\n\t// Pointer to a SessionReplay row created by the session-replay\n\t// plugin's chunked-upload pipeline, plus the offset within that\n\t// recording at submit time so the dashboard can deep-link.\n\tsessionReplayId?: string\n\treplayOffsetMs?: number\n}\n\nexport interface FeedbackData {\n\trating?: FeedbackRating\n\tcomment?: string\n\tuserEmail?: string\n\tscreenshots?: ScreenshotData[]\n\tmetadata: FeedbackMetadata\n}\n\nexport type WidgetPosition = 'right' | 'left'\n\nexport interface WidgetTheme {\n\tprimary: string\n\tbackground: string\n\ttext: string\n\tborder: string\n\tshadow: string\n}\n\n// Forward-declared to avoid a circular import. The plugin module imports\n// FeedbackSubmission from this file, so we can't import UseroPlugin back\n// up here without a cycle. Keeping the prop typed as an opaque object with\n// the minimal shape the widget actually inspects works fine for consumers.\nexport interface FeedbackWidgetProps {\n\tclientId: string\n\tposition?: WidgetPosition\n\ttheme?: Partial<WidgetTheme>\n\ttitle?: string\n\tplaceholder?: string\n\tshowEmailOption?: boolean\n\tshowScreenshotOption?: boolean\n\tenvironment?: string\n\tbaseUrl?: string\n\tmetadata?: Record<string, unknown>\n\tplugins?: ReadonlyArray<import('./plugin').UseroPlugin>\n\tonSubmit?: (feedback: FeedbackData) => void\n\tonError?: (error: Error) => void\n\tonOpen?: () => void\n\tonClose?: () => void\n}\n\nexport interface SubmissionResponse {\n\tsuccess: boolean\n\terror?: string\n\tid?: string\n\tmessage?: string\n\tdata?: unknown\n}\n\nexport const EMOJI_MAP: Record<FeedbackRating, string> = {\n\t1: '😞',\n\t2: '😐',\n\t3: '😊',\n\t4: '🤩',\n}\n\nexport const RATING_LABELS: Record<FeedbackRating, string> = {\n\t1: 'Needs work',\n\t2: \"It's okay\",\n\t3: 'Pretty good',\n\t4: 'Amazing!',\n}\n\nexport const EMOJI_BACKGROUNDS: Record<FeedbackRating, string> = {\n\t1: 'linear-gradient(135deg,#ff6b6b14,#ff6b6b1f)',\n\t2: 'linear-gradient(135deg,#9ca3af0f,#9ca3af1a)',\n\t3: 'linear-gradient(135deg,#3b82f614,#3b82f61f)',\n\t4: 'linear-gradient(135deg,#f59e0b14,#f59e0b1f)',\n}\n\nexport const DEFAULT_API_URL = 'https://usero.io'\n\nexport const DEFAULT_THEME: WidgetTheme = {\n\tprimary: '#2563eb',\n\tbackground: '#ffffff',\n\ttext: '#374151',\n\tborder: '#e5e7eb',\n\tshadow:\n\t\t'0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05)',\n}\n\nexport const DARK_THEME: WidgetTheme = {\n\tprimary: '#2563eb',\n\tbackground: '#1f2937',\n\ttext: '#f9fafb',\n\tborder: '#374151',\n\tshadow:\n\t\t'0 10px 15px -3px rgba(0, 0, 0, 0.3), 0 4px 6px -2px rgba(0, 0, 0, 0.2)',\n}\n\nexport function mergeTheme(customTheme: Partial<WidgetTheme> = {}): WidgetTheme {\n\treturn { ...DEFAULT_THEME, ...customTheme }\n}\n","// User-testing-mode plugin for the Usero widget.\n//\n// Activates ONLY when the host page URL carries `?usero_test=<slug>`. When\n// active, it:\n// 1. Creates a UserTestSession on the SaaS side via\n// POST /api/user-test-sessions\n// 2. Starts a MediaRecorder on the user's microphone (Opus in WebM) and\n// ships chunks every `chunkSeconds` to\n// PUT /api/user-test-sessions/:id/chunk?index=N\n// 3. Renders a small floating \"recording\" indicator with a Finish button\n// bottom-center so the tester can stop on their own.\n// 4. On Finish (or `pagehide`), flushes any buffered chunks and calls\n// POST /api/user-test-sessions/:id/finalise.\n//\n// Mic-permission denied is non-fatal: the session is still created (the\n// session-replay plugin keeps recording in parallel) and the indicator\n// shows a \"no audio\" hint. The SaaS side detects audio presence from the\n// first chunk; if no chunks land, hasAudio stays false there too.\n//\n// Bundle hygiene: this module is a subpath export and does NOT depend on\n// rrweb or any other heavy dep — just the native MediaRecorder API. The\n// floating UI is shadow-DOM scoped so host page CSS can't leak in.\n//\n// Privacy: only the microphone is recorded. We never read DOM text, never\n// touch the camera, and never persist audio in the browser past the\n// IndexedDB fallback (cleared on successful upload).\n\nimport type { UseroPlugin, PluginContext } from '../plugin'\nimport { DEFAULT_API_URL } from '../types'\n\nexport interface UserTestOptions {\n\t// URL query param the welcome page appends to redirect testers back.\n\t// Default `usero_test`. Match SaaS side if you ever change it.\n\tqueryParam?: string\n\t// Audio chunk length in seconds. Smaller = more partial-data resilience\n\t// but more requests. Default 30.\n\tchunkSeconds?: number\n\t// API origin. Override for self-hosted or local dev. Defaults to the\n\t// shared SDK constant (https://usero.io).\n\tapiUrl?: string\n\t// Override the tester-name shown on the SaaS side. Normally the welcome\n\t// page collects this and stores it in localStorage; the plugin reads it\n\t// from there. This option lets a host site bypass that.\n\ttesterName?: string\n\t// Hide the floating indicator. The plugin still records and finalises\n\t// on `pagehide`, but the tester gets no on-page UI. Useful if the host\n\t// page wants to render its own.\n\thideIndicator?: boolean\n}\n\ninterface RecorderStore {\n\tcancelled: boolean\n\tslug: string\n\tsessionId: string | null\n\tclientId: string | null\n\trecorder: MediaRecorder | null\n\tstream: MediaStream | null\n\tchunkIndex: number\n\tuploadQueue: Promise<void>\n\tpendingUploads: number\n\tstartedAt: number\n\tindicator: HTMLElement | null\n\tindicatorRoot: ShadowRoot | null\n\tindicatorState: 'recording' | 'finishing' | 'done' | 'no-audio' | 'error'\n\tpageHideHandler: (() => void) | null\n\toptions: Required<UserTestOptions>\n}\n\nconst DEFAULT_OPTIONS: Required<Omit<UserTestOptions, 'testerName' | 'apiUrl'>> & {\n\ttesterName: string\n\tapiUrl: string\n} = {\n\tqueryParam: 'usero_test',\n\tchunkSeconds: 30,\n\tapiUrl: DEFAULT_API_URL,\n\ttesterName: '',\n\thideIndicator: false,\n}\n\nconst TESTER_NAME_STORAGE_KEY = 'usero:user-test:tester-name'\nconst IDB_NAME = 'usero-user-test'\nconst IDB_STORE = 'pending-chunks'\n\ninterface PendingChunk {\n\tid: string\n\tsessionId: string\n\tapiUrl: string\n\tchunkIndex: number\n\tblob: Blob\n\tcreatedAt: number\n}\n\nfunction readTesterName(override: string): string | undefined {\n\tif (override) return override\n\ttry {\n\t\tconst stored = window.localStorage?.getItem(TESTER_NAME_STORAGE_KEY)\n\t\tif (stored && stored.trim()) return stored.trim().slice(0, 120)\n\t} catch {\n\t\t// Storage access can throw in some sandboxed iframes — ignore.\n\t}\n\treturn undefined\n}\n\nfunction getTestSlug(queryParam: string): string | null {\n\tif (typeof window === 'undefined' || typeof window.location === 'undefined') return null\n\ttry {\n\t\tconst params = new URLSearchParams(window.location.search)\n\t\tconst slug = params.get(queryParam)\n\t\tif (!slug) return null\n\t\tconst cleaned = slug.trim().slice(0, 64)\n\t\tif (!/^[a-z0-9-]+$/i.test(cleaned)) return null\n\t\treturn cleaned\n\t} catch {\n\t\treturn null\n\t}\n}\n\nfunction isMediaRecorderSupported(): boolean {\n\treturn typeof window !== 'undefined' && typeof window.MediaRecorder !== 'undefined' && typeof navigator !== 'undefined' && !!navigator.mediaDevices?.getUserMedia\n}\n\nfunction pickMimeType(): string | undefined {\n\tconst candidates = ['audio/webm;codecs=opus', 'audio/webm', 'audio/ogg;codecs=opus', 'audio/mp4']\n\tfor (const candidate of candidates) {\n\t\tif (typeof MediaRecorder !== 'undefined' && MediaRecorder.isTypeSupported?.(candidate)) {\n\t\t\treturn candidate\n\t\t}\n\t}\n\treturn undefined\n}\n\n// IndexedDB helpers. Best-effort, never throw upstream — if IDB is missing\n// or quota-blown we just lose offline resilience but the live upload path\n// still runs.\nfunction idbOpen(): Promise<IDBDatabase | null> {\n\treturn new Promise(resolve => {\n\t\tif (typeof indexedDB === 'undefined') {\n\t\t\tresolve(null)\n\t\t\treturn\n\t\t}\n\t\ttry {\n\t\t\tconst req = indexedDB.open(IDB_NAME, 1)\n\t\t\treq.onupgradeneeded = (): void => {\n\t\t\t\tconst db = req.result\n\t\t\t\tif (!db.objectStoreNames.contains(IDB_STORE)) {\n\t\t\t\t\tdb.createObjectStore(IDB_STORE, { keyPath: 'id' })\n\t\t\t\t}\n\t\t\t}\n\t\t\treq.onsuccess = (): void => resolve(req.result)\n\t\t\treq.onerror = (): void => resolve(null)\n\t\t} catch {\n\t\t\tresolve(null)\n\t\t}\n\t})\n}\n\nasync function idbStashChunk(chunk: PendingChunk): Promise<void> {\n\tconst db = await idbOpen()\n\tif (!db) return\n\tawait new Promise<void>(resolve => {\n\t\ttry {\n\t\t\tconst tx = db.transaction(IDB_STORE, 'readwrite')\n\t\t\ttx.objectStore(IDB_STORE).put(chunk)\n\t\t\ttx.oncomplete = (): void => resolve()\n\t\t\ttx.onerror = (): void => resolve()\n\t\t\ttx.onabort = (): void => resolve()\n\t\t} catch {\n\t\t\tresolve()\n\t\t}\n\t})\n\tdb.close()\n}\n\nasync function idbDeleteChunk(id: string): Promise<void> {\n\tconst db = await idbOpen()\n\tif (!db) return\n\tawait new Promise<void>(resolve => {\n\t\ttry {\n\t\t\tconst tx = db.transaction(IDB_STORE, 'readwrite')\n\t\t\ttx.objectStore(IDB_STORE).delete(id)\n\t\t\ttx.oncomplete = (): void => resolve()\n\t\t\ttx.onerror = (): void => resolve()\n\t\t\ttx.onabort = (): void => resolve()\n\t\t} catch {\n\t\t\tresolve()\n\t\t}\n\t})\n\tdb.close()\n}\n\nasync function idbListChunks(sessionId: string): Promise<PendingChunk[]> {\n\tconst db = await idbOpen()\n\tif (!db) return []\n\tconst items = await new Promise<PendingChunk[]>(resolve => {\n\t\ttry {\n\t\t\tconst tx = db.transaction(IDB_STORE, 'readonly')\n\t\t\tconst req = tx.objectStore(IDB_STORE).getAll()\n\t\t\treq.onsuccess = (): void => {\n\t\t\t\tconst all = (req.result as PendingChunk[]) ?? []\n\t\t\t\tresolve(all.filter(c => c.sessionId === sessionId))\n\t\t\t}\n\t\t\treq.onerror = (): void => resolve([])\n\t\t} catch {\n\t\t\tresolve([])\n\t\t}\n\t})\n\tdb.close()\n\treturn items\n}\n\nasync function uploadChunkWithRetry(\n\tapiUrl: string,\n\tsessionId: string,\n\tindex: number,\n\tblob: Blob,\n\tlogger: PluginContext['logger'],\n\tmaxAttempts = 5,\n): Promise<boolean> {\n\tconst url = `${apiUrl.replace(/\\/$/, '')}/api/user-test-sessions/${encodeURIComponent(sessionId)}/chunk?index=${index}`\n\tlet attempt = 0\n\twhile (attempt < maxAttempts) {\n\t\ttry {\n\t\t\tconst res = await fetch(url, {\n\t\t\t\tmethod: 'PUT',\n\t\t\t\tbody: blob,\n\t\t\t\theaders: { 'Content-Type': blob.type || 'audio/webm' },\n\t\t\t\tkeepalive: blob.size <= 60 * 1024, // browsers cap keepalive bodies\n\t\t\t})\n\t\t\tif (res.ok) return true\n\t\t\t// 4xx (other than 413) won't get better with retries; bail early.\n\t\t\tif (res.status >= 400 && res.status < 500 && res.status !== 408 && res.status !== 429) {\n\t\t\t\tlogger.error(`chunk ${index} rejected with ${res.status}`)\n\t\t\t\treturn false\n\t\t\t}\n\t\t} catch (err) {\n\t\t\tlogger.warn(`chunk ${index} upload attempt ${attempt + 1} failed`, err)\n\t\t}\n\t\tattempt += 1\n\t\tconst backoff = Math.min(15000, 500 * 2 ** attempt) + Math.floor(Math.random() * 250)\n\t\tawait new Promise(resolve => setTimeout(resolve, backoff))\n\t}\n\treturn false\n}\n\nfunction buildIndicator(host: HTMLElement, store: RecorderStore, onFinish: () => void): ShadowRoot {\n\tconst root = host.attachShadow({ mode: 'closed' })\n\tconst style = document.createElement('style')\n\t// Keep this CSS small. Pulse is the only animation. Bottom-center,\n\t// safe-area aware, semi-transparent so it doesn't block the page.\n\tstyle.textContent = `\n\t\t:host { all: initial; }\n\t\t.bar {\n\t\t\tposition: fixed;\n\t\t\tbottom: calc(env(safe-area-inset-bottom, 0px) + 16px);\n\t\t\tleft: 50%;\n\t\t\ttransform: translateX(-50%);\n\t\t\tdisplay: inline-flex;\n\t\t\talign-items: center;\n\t\t\tgap: 10px;\n\t\t\tpadding: 8px 14px 8px 12px;\n\t\t\tbackground: rgba(17, 17, 17, 0.78);\n\t\t\tcolor: #fff;\n\t\t\tborder-radius: 999px;\n\t\t\tfont-family: -apple-system, BlinkMacSystemFont, \"Segoe UI\", system-ui, sans-serif;\n\t\t\tfont-size: 13px;\n\t\t\tline-height: 1;\n\t\t\tbox-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);\n\t\t\tbackdrop-filter: blur(8px);\n\t\t\t-webkit-backdrop-filter: blur(8px);\n\t\t\tz-index: 2147483646;\n\t\t\tmax-width: calc(100vw - 32px);\n\t\t}\n\t\t.dot {\n\t\t\twidth: 8px; height: 8px; border-radius: 50%;\n\t\t\tbackground: #ef4444;\n\t\t\tbox-shadow: 0 0 0 0 rgba(239, 68, 68, 0.6);\n\t\t\tanimation: pulse 1.6s ease-out infinite;\n\t\t}\n\t\t.dot[data-state=\"no-audio\"] { background: #fbbf24; animation: none; }\n\t\t.dot[data-state=\"finishing\"] { background: #fbbf24; animation: none; }\n\t\t.dot[data-state=\"done\"] { background: #10b981; animation: none; }\n\t\t.dot[data-state=\"error\"] { background: #ef4444; animation: none; }\n\t\t.label { font-weight: 500; letter-spacing: 0.01em; }\n\t\t.spacer { width: 1px; height: 16px; background: rgba(255,255,255,0.18); margin: 0 2px; }\n\t\t.btn {\n\t\t\tappearance: none; border: 0; background: rgba(255,255,255,0.12);\n\t\t\tcolor: #fff; font: inherit; font-weight: 600;\n\t\t\tpadding: 6px 12px; border-radius: 999px; cursor: pointer;\n\t\t\ttransition: background 0.15s ease;\n\t\t}\n\t\t.btn:hover { background: rgba(255,255,255,0.22); }\n\t\t.btn:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }\n\t\t.btn[disabled] { opacity: 0.5; cursor: progress; }\n\t\t.thanks {\n\t\t\tposition: fixed; inset: 0;\n\t\t\tdisplay: grid; place-items: center;\n\t\t\tbackground: rgba(15, 15, 17, 0.78);\n\t\t\tbackdrop-filter: blur(6px);\n\t\t\t-webkit-backdrop-filter: blur(6px);\n\t\t\tcolor: #fff;\n\t\t\tfont-family: -apple-system, BlinkMacSystemFont, \"Segoe UI\", system-ui, sans-serif;\n\t\t\tz-index: 2147483647;\n\t\t\tpadding: 24px;\n\t\t\ttext-align: center;\n\t\t}\n\t\t.thanks-card {\n\t\t\tbackground: #fff; color: #111;\n\t\t\tborder-radius: 16px; padding: 28px 24px;\n\t\t\tmax-width: 360px; width: 100%;\n\t\t\tbox-shadow: 0 20px 50px rgba(0,0,0,0.25);\n\t\t}\n\t\t.thanks h2 { margin: 0 0 8px; font-size: 20px; }\n\t\t.thanks p { margin: 0; font-size: 14px; line-height: 1.45; color: #4b5563; }\n\t\t.thanks .check {\n\t\t\twidth: 44px; height: 44px; border-radius: 50%;\n\t\t\tbackground: #10b981; color: #fff;\n\t\t\tdisplay: grid; place-items: center;\n\t\t\tmargin: 0 auto 12px;\n\t\t\tfont-size: 22px;\n\t\t}\n\t\t@keyframes pulse {\n\t\t\t0% { box-shadow: 0 0 0 0 rgba(239,68,68,0.55); }\n\t\t\t70% { box-shadow: 0 0 0 10px rgba(239,68,68,0); }\n\t\t\t100% { box-shadow: 0 0 0 0 rgba(239,68,68,0); }\n\t\t}\n\t\t@media (prefers-reduced-motion: reduce) {\n\t\t\t.dot { animation: none; }\n\t\t}\n\t`\n\tconst bar = document.createElement('div')\n\tbar.className = 'bar'\n\tbar.setAttribute('role', 'status')\n\tbar.setAttribute('aria-live', 'polite')\n\n\tconst dot = document.createElement('span')\n\tdot.className = 'dot'\n\tdot.setAttribute('data-state', store.indicatorState)\n\n\tconst label = document.createElement('span')\n\tlabel.className = 'label'\n\tlabel.textContent = 'Recording'\n\n\tconst spacer = document.createElement('span')\n\tspacer.className = 'spacer'\n\n\tconst btn = document.createElement('button')\n\tbtn.type = 'button'\n\tbtn.className = 'btn'\n\tbtn.textContent = 'Finish'\n\tbtn.addEventListener('click', onFinish)\n\n\tbar.appendChild(dot)\n\tbar.appendChild(label)\n\tbar.appendChild(spacer)\n\tbar.appendChild(btn)\n\n\troot.appendChild(style)\n\troot.appendChild(bar)\n\treturn root\n}\n\nfunction renderIndicatorState(store: RecorderStore): void {\n\tconst root = store.indicatorRoot\n\tif (!root) return\n\tconst dot = root.querySelector('.dot')\n\tconst label = root.querySelector('.label')\n\tconst btn = root.querySelector<HTMLButtonElement>('.btn')\n\tif (!(dot instanceof HTMLElement) || !(label instanceof HTMLElement) || !btn) return\n\tdot.setAttribute('data-state', store.indicatorState)\n\tswitch (store.indicatorState) {\n\t\tcase 'recording':\n\t\t\tlabel.textContent = 'Recording'\n\t\t\tbtn.textContent = 'Finish'\n\t\t\tbtn.disabled = false\n\t\t\tbreak\n\t\tcase 'no-audio':\n\t\t\tlabel.textContent = 'No mic, replay only'\n\t\t\tbtn.textContent = 'Finish'\n\t\t\tbtn.disabled = false\n\t\t\tbreak\n\t\tcase 'finishing':\n\t\t\tlabel.textContent = 'Saving'\n\t\t\tbtn.textContent = 'Saving'\n\t\t\tbtn.disabled = true\n\t\t\tbreak\n\t\tcase 'done':\n\t\t\tlabel.textContent = 'Saved'\n\t\t\tbtn.textContent = 'Done'\n\t\t\tbtn.disabled = true\n\t\t\tbreak\n\t\tcase 'error':\n\t\t\tlabel.textContent = 'Save failed'\n\t\t\tbtn.textContent = 'Retry'\n\t\t\tbtn.disabled = false\n\t\t\tbreak\n\t}\n}\n\nfunction showThanksScreen(root: ShadowRoot): void {\n\tconst overlay = document.createElement('div')\n\toverlay.className = 'thanks'\n\toverlay.innerHTML = `\n\t\t<div class=\"thanks-card\">\n\t\t\t<div class=\"check\" aria-hidden=\"true\">&#10003;</div>\n\t\t\t<h2>Thanks for testing</h2>\n\t\t\t<p>Your session was saved. You can close this tab.</p>\n\t\t</div>\n\t`\n\troot.appendChild(overlay)\n}\n\nasync function createSession(\n\tapiUrl: string,\n\tslug: string,\n\ttesterName: string | undefined,\n): Promise<{ sessionId: string; clientId: string } | null> {\n\ttry {\n\t\tconst res = await fetch(`${apiUrl.replace(/\\/$/, '')}/api/user-test-sessions`, {\n\t\t\tmethod: 'POST',\n\t\t\theaders: { 'Content-Type': 'application/json' },\n\t\t\tbody: JSON.stringify({ slug, ...(testerName ? { testerName } : {}) }),\n\t\t})\n\t\tif (!res.ok) return null\n\t\tconst json = (await res.json()) as { sessionId?: unknown; clientId?: unknown }\n\t\tif (typeof json.sessionId !== 'string' || typeof json.clientId !== 'string') return null\n\t\treturn { sessionId: json.sessionId, clientId: json.clientId }\n\t} catch {\n\t\treturn null\n\t}\n}\n\nasync function finaliseSession(\n\tapiUrl: string,\n\tsessionId: string,\n\tdurationSeconds: number,\n): Promise<boolean> {\n\ttry {\n\t\tconst res = await fetch(`${apiUrl.replace(/\\/$/, '')}/api/user-test-sessions/${encodeURIComponent(sessionId)}/finalise`, {\n\t\t\tmethod: 'POST',\n\t\t\theaders: { 'Content-Type': 'application/json' },\n\t\t\tbody: JSON.stringify({ durationSeconds: Math.max(0, Math.round(durationSeconds)) }),\n\t\t\tkeepalive: true,\n\t\t})\n\t\treturn res.ok\n\t} catch {\n\t\treturn false\n\t}\n}\n\nasync function flushPendingFromIdb(store: RecorderStore, ctx: PluginContext): Promise<void> {\n\tif (!store.sessionId) return\n\tconst pending = await idbListChunks(store.sessionId)\n\tfor (const chunk of pending) {\n\t\tconst ok = await uploadChunkWithRetry(chunk.apiUrl, chunk.sessionId, chunk.chunkIndex, chunk.blob, ctx.logger, 3)\n\t\tif (ok) await idbDeleteChunk(chunk.id)\n\t}\n}\n\nfunction enqueueChunk(store: RecorderStore, ctx: PluginContext, blob: Blob): void {\n\tif (store.cancelled || !store.sessionId || blob.size === 0) return\n\tconst index = store.chunkIndex\n\tstore.chunkIndex += 1\n\tstore.pendingUploads += 1\n\tconst sessionId = store.sessionId\n\tconst apiUrl = store.options.apiUrl\n\n\tstore.uploadQueue = store.uploadQueue.then(async () => {\n\t\tconst ok = await uploadChunkWithRetry(apiUrl, sessionId, index, blob, ctx.logger)\n\t\tif (!ok) {\n\t\t\tctx.logger.warn(`chunk ${index} stashed for offline retry`)\n\t\t\tawait idbStashChunk({\n\t\t\t\tid: `${sessionId}:${index}:${Date.now()}`,\n\t\t\t\tsessionId,\n\t\t\t\tapiUrl,\n\t\t\t\tchunkIndex: index,\n\t\t\t\tblob,\n\t\t\t\tcreatedAt: Date.now(),\n\t\t\t})\n\t\t}\n\t\tstore.pendingUploads -= 1\n\t})\n}\n\nasync function startRecording(store: RecorderStore, ctx: PluginContext): Promise<void> {\n\tif (!isMediaRecorderSupported()) {\n\t\tctx.logger.warn('MediaRecorder not supported, continuing without audio')\n\t\tstore.indicatorState = 'no-audio'\n\t\trenderIndicatorState(store)\n\t\treturn\n\t}\n\tlet stream: MediaStream\n\ttry {\n\t\tstream = await navigator.mediaDevices.getUserMedia({ audio: true })\n\t} catch (err) {\n\t\tctx.logger.warn('mic permission denied or unavailable', err)\n\t\tstore.indicatorState = 'no-audio'\n\t\trenderIndicatorState(store)\n\t\treturn\n\t}\n\tstore.stream = stream\n\tconst mimeType = pickMimeType()\n\tlet recorder: MediaRecorder\n\ttry {\n\t\trecorder = mimeType ? new MediaRecorder(stream, { mimeType }) : new MediaRecorder(stream)\n\t} catch (err) {\n\t\tctx.logger.error('MediaRecorder construction failed', err)\n\t\tstream.getTracks().forEach(t => t.stop())\n\t\tstore.stream = null\n\t\tstore.indicatorState = 'no-audio'\n\t\trenderIndicatorState(store)\n\t\treturn\n\t}\n\tstore.recorder = recorder\n\trecorder.addEventListener('dataavailable', event => {\n\t\tif (event.data && event.data.size > 0) {\n\t\t\tenqueueChunk(store, ctx, event.data)\n\t\t}\n\t})\n\trecorder.addEventListener('error', event => {\n\t\tctx.logger.error('MediaRecorder error', event)\n\t})\n\t// `timeslice` makes the recorder emit a self-contained chunk every N ms.\n\trecorder.start(store.options.chunkSeconds * 1000)\n}\n\nfunction stopRecording(store: RecorderStore): void {\n\tconst recorder = store.recorder\n\tif (recorder && recorder.state !== 'inactive') {\n\t\ttry {\n\t\t\trecorder.requestData()\n\t\t} catch {\n\t\t\t// requestData throws if state is invalid; ignore.\n\t\t}\n\t\ttry {\n\t\t\trecorder.stop()\n\t\t} catch {\n\t\t\t// already stopped\n\t\t}\n\t}\n\tstore.recorder = null\n\tif (store.stream) {\n\t\tstore.stream.getTracks().forEach(t => t.stop())\n\t\tstore.stream = null\n\t}\n}\n\nasync function finishFlow(store: RecorderStore, ctx: PluginContext, opts: { showThanks: boolean }): Promise<void> {\n\tif (store.cancelled) return\n\tif (store.indicatorState === 'finishing' || store.indicatorState === 'done') return\n\tstore.indicatorState = 'finishing'\n\trenderIndicatorState(store)\n\n\tstopRecording(store)\n\t// Wait for the queued uploads to drain. Each upload already has its own\n\t// retry/backoff; this just lets them finish before finalise fires.\n\tawait store.uploadQueue\n\tawait flushPendingFromIdb(store, ctx)\n\n\tconst durationSeconds = (Date.now() - store.startedAt) / 1000\n\tif (store.sessionId) {\n\t\tconst ok = await finaliseSession(store.options.apiUrl, store.sessionId, durationSeconds)\n\t\tstore.indicatorState = ok ? 'done' : 'error'\n\t} else {\n\t\tstore.indicatorState = 'error'\n\t}\n\trenderIndicatorState(store)\n\n\tif (opts.showThanks && store.indicatorRoot && store.indicatorState === 'done') {\n\t\tshowThanksScreen(store.indicatorRoot)\n\t}\n}\n\nexport function userTest(options: UserTestOptions = {}): UseroPlugin {\n\tconst merged: Required<UserTestOptions> = {\n\t\tqueryParam: options.queryParam ?? DEFAULT_OPTIONS.queryParam,\n\t\tchunkSeconds: options.chunkSeconds ?? DEFAULT_OPTIONS.chunkSeconds,\n\t\tapiUrl: options.apiUrl ?? DEFAULT_OPTIONS.apiUrl,\n\t\ttesterName: options.testerName ?? DEFAULT_OPTIONS.testerName,\n\t\thideIndicator: options.hideIndicator ?? DEFAULT_OPTIONS.hideIndicator,\n\t}\n\n\treturn {\n\t\tname: 'user-test',\n\t\tonInit(ctx) {\n\t\t\tif (typeof window === 'undefined' || typeof document === 'undefined') return\n\t\t\tconst slug = getTestSlug(merged.queryParam)\n\t\t\tif (!slug) return\n\n\t\t\tconst apiUrl = merged.apiUrl || ctx.baseUrl || DEFAULT_API_URL\n\t\t\tconst store: RecorderStore = {\n\t\t\t\tcancelled: false,\n\t\t\t\tslug,\n\t\t\t\tsessionId: null,\n\t\t\t\tclientId: null,\n\t\t\t\trecorder: null,\n\t\t\t\tstream: null,\n\t\t\t\tchunkIndex: 0,\n\t\t\t\tuploadQueue: Promise.resolve(),\n\t\t\t\tpendingUploads: 0,\n\t\t\t\tstartedAt: Date.now(),\n\t\t\t\tindicator: null,\n\t\t\t\tindicatorRoot: null,\n\t\t\t\tindicatorState: 'recording',\n\t\t\t\tpageHideHandler: null,\n\t\t\t\toptions: { ...merged, apiUrl },\n\t\t\t}\n\t\t\tctx.setStore(store)\n\n\t\t\tconst onFinish = (): void => {\n\t\t\t\tvoid finishFlow(store, ctx, { showThanks: true })\n\t\t\t}\n\n\t\t\tif (!merged.hideIndicator) {\n\t\t\t\tconst host = document.createElement('div')\n\t\t\t\thost.setAttribute('data-usero-user-test', 'true')\n\t\t\t\tdocument.body.appendChild(host)\n\t\t\t\tstore.indicator = host\n\t\t\t\tstore.indicatorRoot = buildIndicator(host, store, onFinish)\n\t\t\t\trenderIndicatorState(store)\n\t\t\t}\n\n\t\t\tconst pageHide = (): void => {\n\t\t\t\t// Best-effort flush + finalise. We don't await here; the browser\n\t\t\t\t// is shutting the page down. `keepalive: true` on finalise lets\n\t\t\t\t// the request race the unload.\n\t\t\t\tvoid finishFlow(store, ctx, { showThanks: false })\n\t\t\t}\n\t\t\tstore.pageHideHandler = pageHide\n\t\t\twindow.addEventListener('pagehide', pageHide)\n\n\t\t\tvoid (async (): Promise<void> => {\n\t\t\t\tconst created = await createSession(apiUrl, slug, readTesterName(merged.testerName))\n\t\t\t\tif (store.cancelled) return\n\t\t\t\tif (!created) {\n\t\t\t\t\tctx.logger.error('failed to create user-test session')\n\t\t\t\t\tstore.indicatorState = 'error'\n\t\t\t\t\trenderIndicatorState(store)\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\tstore.sessionId = created.sessionId\n\t\t\t\tstore.clientId = created.clientId\n\t\t\t\tawait startRecording(store, ctx)\n\t\t\t\trenderIndicatorState(store)\n\t\t\t})()\n\t\t},\n\t\tonDestroy(ctx) {\n\t\t\tconst store = ctx.getStore<RecorderStore>()\n\t\t\tif (!store) return\n\t\t\tstore.cancelled = true\n\t\t\tif (store.pageHideHandler) {\n\t\t\t\twindow.removeEventListener('pagehide', store.pageHideHandler)\n\t\t\t\tstore.pageHideHandler = null\n\t\t\t}\n\t\t\tstopRecording(store)\n\t\t\tif (store.indicator && store.indicator.parentNode) {\n\t\t\t\tstore.indicator.parentNode.removeChild(store.indicator)\n\t\t\t}\n\t\t\tstore.indicator = null\n\t\t\tstore.indicatorRoot = null\n\t\t},\n\t}\n}\n\n// Internal helpers exposed for tests only. Not part of the public API.\nexport const __test__ = { getTestSlug, pickMimeType, isMediaRecorderSupported }\n"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A;AAAA,QACD;AACA,QAAA,KAAA,CAAM,YAAY,OAAA,CAAQ,SAAA;AAC1B,QAAA,KAAA,CAAM,WAAW,OAAA,CAAQ,QAAA;AACzB,QAAA,MAAM,cAAA,CAAe,OAAO,GAAG,CAAA;AAC/B,QAAA,oBAAA,CAAqB,KAAK,CAAA;AAAA,MAC3B,CAAA,GAAG;AAAA,IACJ,CAAA;AAAA,IACA,UAAU,GAAA,EAAK;AACd,MAAA,MAAM,KAAA,GAAQ,IAAI,QAAA,EAAwB;AAC1C,MAAA,IAAI,CAAC,KAAA,EAAO;AACZ,MAAA,KAAA,CAAM,SAAA,GAAY,IAAA;AAClB,MAAA,IAAI,MAAM,eAAA,EAAiB;AAC1B,QAAA,MAAA,CAAO,mBAAA,CAAoB,UAAA,EAAY,KAAA,CAAM,eAAe,CAAA;AAC5D,QAAA,KAAA,CAAM,eAAA,GAAkB,IAAA;AAAA,MACzB;AACA,MAAA,aAAA,CAAc,KAAK,CAAA;AACnB,MAAA,IAAI,KAAA,CAAM,SAAA,IAAa,KAAA,CAAM,SAAA,CAAU,UAAA,EAAY;AAClD,QAAA,KAAA,CAAM,SAAA,CAAU,UAAA,CAAW,WAAA,CAAY,KAAA,CAAM,SAAS,CAAA;AAAA,MACvD;AACA,MAAA,KAAA,CAAM,SAAA,GAAY,IAAA;AAClB,MAAA,KAAA,CAAM,aAAA,GAAgB,IAAA;AAAA,IACvB;AAAA,GACD;AACD;AAGO,IAAM,QAAA,GAAW,EAAE,WAAA,EAAa,YAAA,EAAc,wBAAA","file":"user-test.cjs","sourcesContent":["// Shared types used by both the vanilla and React entry points.\n// Keep this file framework-free so the vanilla bundle never pulls react.\n\nexport type FeedbackRating = 1 | 2 | 3 | 4\n\nexport interface FeedbackMetadata {\n\tpageUrl: string\n\tpageTitle: string\n\treferrer?: string\n\ttimestamp: number\n}\n\nexport interface ScreenshotData {\n\tfileName: string\n\turl: string\n\tfileSize: number\n\twidth?: number\n\theight?: number\n\tmimeType: string\n}\n\nexport interface FeedbackSubmission {\n\tclientId: string\n\trating?: FeedbackRating\n\tcomment?: string\n\tuserEmail?: string\n\tpageUrl: string\n\tpageTitle: string\n\treferrer?: string\n\tenvironment?: string\n\tscreenshots?: ScreenshotData[]\n\tmetadata?: Record<string, unknown>\n\t// Legacy gzipped + base64-encoded rrweb event stream. The pre-chunked\n\t// session-replay plugin attached this on submit. The chunked-upload\n\t// plugin (>= 0.4.0) does NOT set this — it ships events out-of-band\n\t// via the chunk endpoints and points at the resulting session replay\n\t// via `sessionReplayId` + `replayOffsetMs`. Kept on the wire one\n\t// release for backward compat with old SaaS deployments that only\n\t// know how to ingest the legacy field.\n\treplayEvents?: string\n\t// Pointer to a SessionReplay row created by the session-replay\n\t// plugin's chunked-upload pipeline, plus the offset within that\n\t// recording at submit time so the dashboard can deep-link.\n\tsessionReplayId?: string\n\treplayOffsetMs?: number\n}\n\nexport interface FeedbackData {\n\trating?: FeedbackRating\n\tcomment?: string\n\tuserEmail?: string\n\tscreenshots?: ScreenshotData[]\n\tmetadata: FeedbackMetadata\n}\n\n// Customer-supplied identity for the session-replay / identify pipeline.\n// Use the declarative form: pass `user` on the React widget (the SDK\n// diffs and auto-fires identify), or supply `getUser` on the vanilla\n// init (the SDK polls it at session start). An imperative `identify()`\n// call exists as an escape hatch only and is intentionally not\n// documented as the headline API.\nexport type UseroUserTraitValue = string | number | boolean | null\nexport type UseroUserTraits = Record<string, UseroUserTraitValue>\nexport interface UseroUser {\n\tid: string\n\temail?: string\n\tdisplayName?: string\n\ttraits?: UseroUserTraits\n}\n\nexport type WidgetPosition = 'right' | 'left'\n\nexport interface WidgetTheme {\n\tprimary: string\n\tbackground: string\n\ttext: string\n\tborder: string\n\tshadow: string\n}\n\n// Forward-declared to avoid a circular import. The plugin module imports\n// FeedbackSubmission from this file, so we can't import UseroPlugin back\n// up here without a cycle. Keeping the prop typed as an opaque object with\n// the minimal shape the widget actually inspects works fine for consumers.\nexport interface FeedbackWidgetProps {\n\tclientId: string\n\tposition?: WidgetPosition\n\ttheme?: Partial<WidgetTheme>\n\ttitle?: string\n\tplaceholder?: string\n\tshowEmailOption?: boolean\n\tshowScreenshotOption?: boolean\n\tenvironment?: string\n\tbaseUrl?: string\n\tmetadata?: Record<string, unknown>\n\tplugins?: ReadonlyArray<import('./plugin').UseroPlugin>\n\t// Declarative identity. React: pass the current user (or null on\n\t// logout) and the SDK auto-fires identify when the resolved id\n\t// transitions. Vanilla: pass a getter so the SDK can resolve user at\n\t// session start / chunk boundaries. Pass at most one. The SDK never\n\t// invokes both.\n\tuser?: UseroUser | null\n\tgetUser?: () => UseroUser | null | undefined\n\tonSubmit?: (feedback: FeedbackData) => void\n\tonError?: (error: Error) => void\n\tonOpen?: () => void\n\tonClose?: () => void\n}\n\nexport interface SubmissionResponse {\n\tsuccess: boolean\n\terror?: string\n\tid?: string\n\tmessage?: string\n\tdata?: unknown\n}\n\nexport const EMOJI_MAP: Record<FeedbackRating, string> = {\n\t1: '😞',\n\t2: '😐',\n\t3: '😊',\n\t4: '🤩',\n}\n\nexport const RATING_LABELS: Record<FeedbackRating, string> = {\n\t1: 'Needs work',\n\t2: \"It's okay\",\n\t3: 'Pretty good',\n\t4: 'Amazing!',\n}\n\nexport const EMOJI_BACKGROUNDS: Record<FeedbackRating, string> = {\n\t1: 'linear-gradient(135deg,#ff6b6b14,#ff6b6b1f)',\n\t2: 'linear-gradient(135deg,#9ca3af0f,#9ca3af1a)',\n\t3: 'linear-gradient(135deg,#3b82f614,#3b82f61f)',\n\t4: 'linear-gradient(135deg,#f59e0b14,#f59e0b1f)',\n}\n\nexport const DEFAULT_API_URL = 'https://usero.io'\n\nexport const DEFAULT_THEME: WidgetTheme = {\n\tprimary: '#2563eb',\n\tbackground: '#ffffff',\n\ttext: '#374151',\n\tborder: '#e5e7eb',\n\tshadow:\n\t\t'0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05)',\n}\n\nexport const DARK_THEME: WidgetTheme = {\n\tprimary: '#2563eb',\n\tbackground: '#1f2937',\n\ttext: '#f9fafb',\n\tborder: '#374151',\n\tshadow:\n\t\t'0 10px 15px -3px rgba(0, 0, 0, 0.3), 0 4px 6px -2px rgba(0, 0, 0, 0.2)',\n}\n\nexport function mergeTheme(customTheme: Partial<WidgetTheme> = {}): WidgetTheme {\n\treturn { ...DEFAULT_THEME, ...customTheme }\n}\n","// User-testing-mode plugin for the Usero widget.\n//\n// Activates ONLY when the host page URL carries `?usero_test=<slug>`. When\n// active, it:\n// 1. Creates a UserTestSession on the SaaS side via\n// POST /api/user-test-sessions\n// 2. Starts a MediaRecorder on the user's microphone (Opus in WebM) and\n// ships chunks every `chunkSeconds` to\n// PUT /api/user-test-sessions/:id/chunk?index=N\n// 3. Renders a small floating \"recording\" indicator with a Finish button\n// bottom-center so the tester can stop on their own.\n// 4. On Finish (or `pagehide`), flushes any buffered chunks and calls\n// POST /api/user-test-sessions/:id/finalise.\n//\n// Mic-permission denied is non-fatal: the session is still created (the\n// session-replay plugin keeps recording in parallel) and the indicator\n// shows a \"no audio\" hint. The SaaS side detects audio presence from the\n// first chunk; if no chunks land, hasAudio stays false there too.\n//\n// Bundle hygiene: this module is a subpath export and does NOT depend on\n// rrweb or any other heavy dep — just the native MediaRecorder API. The\n// floating UI is shadow-DOM scoped so host page CSS can't leak in.\n//\n// Privacy: only the microphone is recorded. We never read DOM text, never\n// touch the camera, and never persist audio in the browser past the\n// IndexedDB fallback (cleared on successful upload).\n\nimport type { UseroPlugin, PluginContext } from '../plugin'\nimport { DEFAULT_API_URL } from '../types'\n\nexport interface UserTestOptions {\n\t// URL query param the welcome page appends to redirect testers back.\n\t// Default `usero_test`. Match SaaS side if you ever change it.\n\tqueryParam?: string\n\t// Audio chunk length in seconds. Smaller = more partial-data resilience\n\t// but more requests. Default 30.\n\tchunkSeconds?: number\n\t// API origin. Override for self-hosted or local dev. Defaults to the\n\t// shared SDK constant (https://usero.io).\n\tapiUrl?: string\n\t// Override the tester-name shown on the SaaS side. Normally the welcome\n\t// page collects this and stores it in localStorage; the plugin reads it\n\t// from there. This option lets a host site bypass that.\n\ttesterName?: string\n\t// Hide the floating indicator. The plugin still records and finalises\n\t// on `pagehide`, but the tester gets no on-page UI. Useful if the host\n\t// page wants to render its own.\n\thideIndicator?: boolean\n}\n\ninterface RecorderStore {\n\tcancelled: boolean\n\tslug: string\n\tsessionId: string | null\n\tclientId: string | null\n\trecorder: MediaRecorder | null\n\tstream: MediaStream | null\n\tchunkIndex: number\n\tuploadQueue: Promise<void>\n\tpendingUploads: number\n\tstartedAt: number\n\tindicator: HTMLElement | null\n\tindicatorRoot: ShadowRoot | null\n\tindicatorState: 'recording' | 'finishing' | 'done' | 'no-audio' | 'error'\n\tpageHideHandler: (() => void) | null\n\toptions: Required<UserTestOptions>\n}\n\nconst DEFAULT_OPTIONS: Required<Omit<UserTestOptions, 'testerName' | 'apiUrl'>> & {\n\ttesterName: string\n\tapiUrl: string\n} = {\n\tqueryParam: 'usero_test',\n\tchunkSeconds: 30,\n\tapiUrl: DEFAULT_API_URL,\n\ttesterName: '',\n\thideIndicator: false,\n}\n\nconst TESTER_NAME_STORAGE_KEY = 'usero:user-test:tester-name'\nconst IDB_NAME = 'usero-user-test'\nconst IDB_STORE = 'pending-chunks'\n\ninterface PendingChunk {\n\tid: string\n\tsessionId: string\n\tapiUrl: string\n\tchunkIndex: number\n\tblob: Blob\n\tcreatedAt: number\n}\n\nfunction readTesterName(override: string): string | undefined {\n\tif (override) return override\n\ttry {\n\t\tconst stored = window.localStorage?.getItem(TESTER_NAME_STORAGE_KEY)\n\t\tif (stored && stored.trim()) return stored.trim().slice(0, 120)\n\t} catch {\n\t\t// Storage access can throw in some sandboxed iframes — ignore.\n\t}\n\treturn undefined\n}\n\nfunction getTestSlug(queryParam: string): string | null {\n\tif (typeof window === 'undefined' || typeof window.location === 'undefined') return null\n\ttry {\n\t\tconst params = new URLSearchParams(window.location.search)\n\t\tconst slug = params.get(queryParam)\n\t\tif (!slug) return null\n\t\tconst cleaned = slug.trim().slice(0, 64)\n\t\tif (!/^[a-z0-9-]+$/i.test(cleaned)) return null\n\t\treturn cleaned\n\t} catch {\n\t\treturn null\n\t}\n}\n\nfunction isMediaRecorderSupported(): boolean {\n\treturn typeof window !== 'undefined' && typeof window.MediaRecorder !== 'undefined' && typeof navigator !== 'undefined' && !!navigator.mediaDevices?.getUserMedia\n}\n\nfunction pickMimeType(): string | undefined {\n\tconst candidates = ['audio/webm;codecs=opus', 'audio/webm', 'audio/ogg;codecs=opus', 'audio/mp4']\n\tfor (const candidate of candidates) {\n\t\tif (typeof MediaRecorder !== 'undefined' && MediaRecorder.isTypeSupported?.(candidate)) {\n\t\t\treturn candidate\n\t\t}\n\t}\n\treturn undefined\n}\n\n// IndexedDB helpers. Best-effort, never throw upstream — if IDB is missing\n// or quota-blown we just lose offline resilience but the live upload path\n// still runs.\nfunction idbOpen(): Promise<IDBDatabase | null> {\n\treturn new Promise(resolve => {\n\t\tif (typeof indexedDB === 'undefined') {\n\t\t\tresolve(null)\n\t\t\treturn\n\t\t}\n\t\ttry {\n\t\t\tconst req = indexedDB.open(IDB_NAME, 1)\n\t\t\treq.onupgradeneeded = (): void => {\n\t\t\t\tconst db = req.result\n\t\t\t\tif (!db.objectStoreNames.contains(IDB_STORE)) {\n\t\t\t\t\tdb.createObjectStore(IDB_STORE, { keyPath: 'id' })\n\t\t\t\t}\n\t\t\t}\n\t\t\treq.onsuccess = (): void => resolve(req.result)\n\t\t\treq.onerror = (): void => resolve(null)\n\t\t} catch {\n\t\t\tresolve(null)\n\t\t}\n\t})\n}\n\nasync function idbStashChunk(chunk: PendingChunk): Promise<void> {\n\tconst db = await idbOpen()\n\tif (!db) return\n\tawait new Promise<void>(resolve => {\n\t\ttry {\n\t\t\tconst tx = db.transaction(IDB_STORE, 'readwrite')\n\t\t\ttx.objectStore(IDB_STORE).put(chunk)\n\t\t\ttx.oncomplete = (): void => resolve()\n\t\t\ttx.onerror = (): void => resolve()\n\t\t\ttx.onabort = (): void => resolve()\n\t\t} catch {\n\t\t\tresolve()\n\t\t}\n\t})\n\tdb.close()\n}\n\nasync function idbDeleteChunk(id: string): Promise<void> {\n\tconst db = await idbOpen()\n\tif (!db) return\n\tawait new Promise<void>(resolve => {\n\t\ttry {\n\t\t\tconst tx = db.transaction(IDB_STORE, 'readwrite')\n\t\t\ttx.objectStore(IDB_STORE).delete(id)\n\t\t\ttx.oncomplete = (): void => resolve()\n\t\t\ttx.onerror = (): void => resolve()\n\t\t\ttx.onabort = (): void => resolve()\n\t\t} catch {\n\t\t\tresolve()\n\t\t}\n\t})\n\tdb.close()\n}\n\nasync function idbListChunks(sessionId: string): Promise<PendingChunk[]> {\n\tconst db = await idbOpen()\n\tif (!db) return []\n\tconst items = await new Promise<PendingChunk[]>(resolve => {\n\t\ttry {\n\t\t\tconst tx = db.transaction(IDB_STORE, 'readonly')\n\t\t\tconst req = tx.objectStore(IDB_STORE).getAll()\n\t\t\treq.onsuccess = (): void => {\n\t\t\t\tconst all = (req.result as PendingChunk[]) ?? []\n\t\t\t\tresolve(all.filter(c => c.sessionId === sessionId))\n\t\t\t}\n\t\t\treq.onerror = (): void => resolve([])\n\t\t} catch {\n\t\t\tresolve([])\n\t\t}\n\t})\n\tdb.close()\n\treturn items\n}\n\nasync function uploadChunkWithRetry(\n\tapiUrl: string,\n\tsessionId: string,\n\tindex: number,\n\tblob: Blob,\n\tlogger: PluginContext['logger'],\n\tmaxAttempts = 5,\n): Promise<boolean> {\n\tconst url = `${apiUrl.replace(/\\/$/, '')}/api/user-test-sessions/${encodeURIComponent(sessionId)}/chunk?index=${index}`\n\tlet attempt = 0\n\twhile (attempt < maxAttempts) {\n\t\ttry {\n\t\t\tconst res = await fetch(url, {\n\t\t\t\tmethod: 'PUT',\n\t\t\t\tbody: blob,\n\t\t\t\theaders: { 'Content-Type': blob.type || 'audio/webm' },\n\t\t\t\tkeepalive: blob.size <= 60 * 1024, // browsers cap keepalive bodies\n\t\t\t})\n\t\t\tif (res.ok) return true\n\t\t\t// 4xx (other than 413) won't get better with retries; bail early.\n\t\t\tif (res.status >= 400 && res.status < 500 && res.status !== 408 && res.status !== 429) {\n\t\t\t\tlogger.error(`chunk ${index} rejected with ${res.status}`)\n\t\t\t\treturn false\n\t\t\t}\n\t\t} catch (err) {\n\t\t\tlogger.warn(`chunk ${index} upload attempt ${attempt + 1} failed`, err)\n\t\t}\n\t\tattempt += 1\n\t\tconst backoff = Math.min(15000, 500 * 2 ** attempt) + Math.floor(Math.random() * 250)\n\t\tawait new Promise(resolve => setTimeout(resolve, backoff))\n\t}\n\treturn false\n}\n\nfunction buildIndicator(host: HTMLElement, store: RecorderStore, onFinish: () => void): ShadowRoot {\n\tconst root = host.attachShadow({ mode: 'closed' })\n\tconst style = document.createElement('style')\n\t// Keep this CSS small. Pulse is the only animation. Bottom-center,\n\t// safe-area aware, semi-transparent so it doesn't block the page.\n\tstyle.textContent = `\n\t\t:host { all: initial; }\n\t\t.bar {\n\t\t\tposition: fixed;\n\t\t\tbottom: calc(env(safe-area-inset-bottom, 0px) + 16px);\n\t\t\tleft: 50%;\n\t\t\ttransform: translateX(-50%);\n\t\t\tdisplay: inline-flex;\n\t\t\talign-items: center;\n\t\t\tgap: 10px;\n\t\t\tpadding: 8px 14px 8px 12px;\n\t\t\tbackground: rgba(17, 17, 17, 0.78);\n\t\t\tcolor: #fff;\n\t\t\tborder-radius: 999px;\n\t\t\tfont-family: -apple-system, BlinkMacSystemFont, \"Segoe UI\", system-ui, sans-serif;\n\t\t\tfont-size: 13px;\n\t\t\tline-height: 1;\n\t\t\tbox-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);\n\t\t\tbackdrop-filter: blur(8px);\n\t\t\t-webkit-backdrop-filter: blur(8px);\n\t\t\tz-index: 2147483646;\n\t\t\tmax-width: calc(100vw - 32px);\n\t\t}\n\t\t.dot {\n\t\t\twidth: 8px; height: 8px; border-radius: 50%;\n\t\t\tbackground: #ef4444;\n\t\t\tbox-shadow: 0 0 0 0 rgba(239, 68, 68, 0.6);\n\t\t\tanimation: pulse 1.6s ease-out infinite;\n\t\t}\n\t\t.dot[data-state=\"no-audio\"] { background: #fbbf24; animation: none; }\n\t\t.dot[data-state=\"finishing\"] { background: #fbbf24; animation: none; }\n\t\t.dot[data-state=\"done\"] { background: #10b981; animation: none; }\n\t\t.dot[data-state=\"error\"] { background: #ef4444; animation: none; }\n\t\t.label { font-weight: 500; letter-spacing: 0.01em; }\n\t\t.spacer { width: 1px; height: 16px; background: rgba(255,255,255,0.18); margin: 0 2px; }\n\t\t.btn {\n\t\t\tappearance: none; border: 0; background: rgba(255,255,255,0.12);\n\t\t\tcolor: #fff; font: inherit; font-weight: 600;\n\t\t\tpadding: 6px 12px; border-radius: 999px; cursor: pointer;\n\t\t\ttransition: background 0.15s ease;\n\t\t}\n\t\t.btn:hover { background: rgba(255,255,255,0.22); }\n\t\t.btn:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }\n\t\t.btn[disabled] { opacity: 0.5; cursor: progress; }\n\t\t.thanks {\n\t\t\tposition: fixed; inset: 0;\n\t\t\tdisplay: grid; place-items: center;\n\t\t\tbackground: rgba(15, 15, 17, 0.78);\n\t\t\tbackdrop-filter: blur(6px);\n\t\t\t-webkit-backdrop-filter: blur(6px);\n\t\t\tcolor: #fff;\n\t\t\tfont-family: -apple-system, BlinkMacSystemFont, \"Segoe UI\", system-ui, sans-serif;\n\t\t\tz-index: 2147483647;\n\t\t\tpadding: 24px;\n\t\t\ttext-align: center;\n\t\t}\n\t\t.thanks-card {\n\t\t\tbackground: #fff; color: #111;\n\t\t\tborder-radius: 16px; padding: 28px 24px;\n\t\t\tmax-width: 360px; width: 100%;\n\t\t\tbox-shadow: 0 20px 50px rgba(0,0,0,0.25);\n\t\t}\n\t\t.thanks h2 { margin: 0 0 8px; font-size: 20px; }\n\t\t.thanks p { margin: 0; font-size: 14px; line-height: 1.45; color: #4b5563; }\n\t\t.thanks .check {\n\t\t\twidth: 44px; height: 44px; border-radius: 50%;\n\t\t\tbackground: #10b981; color: #fff;\n\t\t\tdisplay: grid; place-items: center;\n\t\t\tmargin: 0 auto 12px;\n\t\t\tfont-size: 22px;\n\t\t}\n\t\t@keyframes pulse {\n\t\t\t0% { box-shadow: 0 0 0 0 rgba(239,68,68,0.55); }\n\t\t\t70% { box-shadow: 0 0 0 10px rgba(239,68,68,0); }\n\t\t\t100% { box-shadow: 0 0 0 0 rgba(239,68,68,0); }\n\t\t}\n\t\t@media (prefers-reduced-motion: reduce) {\n\t\t\t.dot { animation: none; }\n\t\t}\n\t`\n\tconst bar = document.createElement('div')\n\tbar.className = 'bar'\n\tbar.setAttribute('role', 'status')\n\tbar.setAttribute('aria-live', 'polite')\n\n\tconst dot = document.createElement('span')\n\tdot.className = 'dot'\n\tdot.setAttribute('data-state', store.indicatorState)\n\n\tconst label = document.createElement('span')\n\tlabel.className = 'label'\n\tlabel.textContent = 'Recording'\n\n\tconst spacer = document.createElement('span')\n\tspacer.className = 'spacer'\n\n\tconst btn = document.createElement('button')\n\tbtn.type = 'button'\n\tbtn.className = 'btn'\n\tbtn.textContent = 'Finish'\n\tbtn.addEventListener('click', onFinish)\n\n\tbar.appendChild(dot)\n\tbar.appendChild(label)\n\tbar.appendChild(spacer)\n\tbar.appendChild(btn)\n\n\troot.appendChild(style)\n\troot.appendChild(bar)\n\treturn root\n}\n\nfunction renderIndicatorState(store: RecorderStore): void {\n\tconst root = store.indicatorRoot\n\tif (!root) return\n\tconst dot = root.querySelector('.dot')\n\tconst label = root.querySelector('.label')\n\tconst btn = root.querySelector<HTMLButtonElement>('.btn')\n\tif (!(dot instanceof HTMLElement) || !(label instanceof HTMLElement) || !btn) return\n\tdot.setAttribute('data-state', store.indicatorState)\n\tswitch (store.indicatorState) {\n\t\tcase 'recording':\n\t\t\tlabel.textContent = 'Recording'\n\t\t\tbtn.textContent = 'Finish'\n\t\t\tbtn.disabled = false\n\t\t\tbreak\n\t\tcase 'no-audio':\n\t\t\tlabel.textContent = 'No mic, replay only'\n\t\t\tbtn.textContent = 'Finish'\n\t\t\tbtn.disabled = false\n\t\t\tbreak\n\t\tcase 'finishing':\n\t\t\tlabel.textContent = 'Saving'\n\t\t\tbtn.textContent = 'Saving'\n\t\t\tbtn.disabled = true\n\t\t\tbreak\n\t\tcase 'done':\n\t\t\tlabel.textContent = 'Saved'\n\t\t\tbtn.textContent = 'Done'\n\t\t\tbtn.disabled = true\n\t\t\tbreak\n\t\tcase 'error':\n\t\t\tlabel.textContent = 'Save failed'\n\t\t\tbtn.textContent = 'Retry'\n\t\t\tbtn.disabled = false\n\t\t\tbreak\n\t}\n}\n\nfunction showThanksScreen(root: ShadowRoot): void {\n\tconst overlay = document.createElement('div')\n\toverlay.className = 'thanks'\n\toverlay.innerHTML = `\n\t\t<div class=\"thanks-card\">\n\t\t\t<div class=\"check\" aria-hidden=\"true\">&#10003;</div>\n\t\t\t<h2>Thanks for testing</h2>\n\t\t\t<p>Your session was saved. You can close this tab.</p>\n\t\t</div>\n\t`\n\troot.appendChild(overlay)\n}\n\nasync function createSession(\n\tapiUrl: string,\n\tslug: string,\n\ttesterName: string | undefined,\n): Promise<{ sessionId: string; clientId: string } | null> {\n\ttry {\n\t\tconst res = await fetch(`${apiUrl.replace(/\\/$/, '')}/api/user-test-sessions`, {\n\t\t\tmethod: 'POST',\n\t\t\theaders: { 'Content-Type': 'application/json' },\n\t\t\tbody: JSON.stringify({ slug, ...(testerName ? { testerName } : {}) }),\n\t\t})\n\t\tif (!res.ok) return null\n\t\tconst json = (await res.json()) as { sessionId?: unknown; clientId?: unknown }\n\t\tif (typeof json.sessionId !== 'string' || typeof json.clientId !== 'string') return null\n\t\treturn { sessionId: json.sessionId, clientId: json.clientId }\n\t} catch {\n\t\treturn null\n\t}\n}\n\nasync function finaliseSession(\n\tapiUrl: string,\n\tsessionId: string,\n\tdurationSeconds: number,\n): Promise<boolean> {\n\ttry {\n\t\tconst res = await fetch(`${apiUrl.replace(/\\/$/, '')}/api/user-test-sessions/${encodeURIComponent(sessionId)}/finalise`, {\n\t\t\tmethod: 'POST',\n\t\t\theaders: { 'Content-Type': 'application/json' },\n\t\t\tbody: JSON.stringify({ durationSeconds: Math.max(0, Math.round(durationSeconds)) }),\n\t\t\tkeepalive: true,\n\t\t})\n\t\treturn res.ok\n\t} catch {\n\t\treturn false\n\t}\n}\n\nasync function flushPendingFromIdb(store: RecorderStore, ctx: PluginContext): Promise<void> {\n\tif (!store.sessionId) return\n\tconst pending = await idbListChunks(store.sessionId)\n\tfor (const chunk of pending) {\n\t\tconst ok = await uploadChunkWithRetry(chunk.apiUrl, chunk.sessionId, chunk.chunkIndex, chunk.blob, ctx.logger, 3)\n\t\tif (ok) await idbDeleteChunk(chunk.id)\n\t}\n}\n\nfunction enqueueChunk(store: RecorderStore, ctx: PluginContext, blob: Blob): void {\n\tif (store.cancelled || !store.sessionId || blob.size === 0) return\n\tconst index = store.chunkIndex\n\tstore.chunkIndex += 1\n\tstore.pendingUploads += 1\n\tconst sessionId = store.sessionId\n\tconst apiUrl = store.options.apiUrl\n\n\tstore.uploadQueue = store.uploadQueue.then(async () => {\n\t\tconst ok = await uploadChunkWithRetry(apiUrl, sessionId, index, blob, ctx.logger)\n\t\tif (!ok) {\n\t\t\tctx.logger.warn(`chunk ${index} stashed for offline retry`)\n\t\t\tawait idbStashChunk({\n\t\t\t\tid: `${sessionId}:${index}:${Date.now()}`,\n\t\t\t\tsessionId,\n\t\t\t\tapiUrl,\n\t\t\t\tchunkIndex: index,\n\t\t\t\tblob,\n\t\t\t\tcreatedAt: Date.now(),\n\t\t\t})\n\t\t}\n\t\tstore.pendingUploads -= 1\n\t})\n}\n\nasync function startRecording(store: RecorderStore, ctx: PluginContext): Promise<void> {\n\tif (!isMediaRecorderSupported()) {\n\t\tctx.logger.warn('MediaRecorder not supported, continuing without audio')\n\t\tstore.indicatorState = 'no-audio'\n\t\trenderIndicatorState(store)\n\t\treturn\n\t}\n\tlet stream: MediaStream\n\ttry {\n\t\tstream = await navigator.mediaDevices.getUserMedia({ audio: true })\n\t} catch (err) {\n\t\tctx.logger.warn('mic permission denied or unavailable', err)\n\t\tstore.indicatorState = 'no-audio'\n\t\trenderIndicatorState(store)\n\t\treturn\n\t}\n\tstore.stream = stream\n\tconst mimeType = pickMimeType()\n\tlet recorder: MediaRecorder\n\ttry {\n\t\trecorder = mimeType ? new MediaRecorder(stream, { mimeType }) : new MediaRecorder(stream)\n\t} catch (err) {\n\t\tctx.logger.error('MediaRecorder construction failed', err)\n\t\tstream.getTracks().forEach(t => t.stop())\n\t\tstore.stream = null\n\t\tstore.indicatorState = 'no-audio'\n\t\trenderIndicatorState(store)\n\t\treturn\n\t}\n\tstore.recorder = recorder\n\trecorder.addEventListener('dataavailable', event => {\n\t\tif (event.data && event.data.size > 0) {\n\t\t\tenqueueChunk(store, ctx, event.data)\n\t\t}\n\t})\n\trecorder.addEventListener('error', event => {\n\t\tctx.logger.error('MediaRecorder error', event)\n\t})\n\t// `timeslice` makes the recorder emit a self-contained chunk every N ms.\n\trecorder.start(store.options.chunkSeconds * 1000)\n}\n\nfunction stopRecording(store: RecorderStore): void {\n\tconst recorder = store.recorder\n\tif (recorder && recorder.state !== 'inactive') {\n\t\ttry {\n\t\t\trecorder.requestData()\n\t\t} catch {\n\t\t\t// requestData throws if state is invalid; ignore.\n\t\t}\n\t\ttry {\n\t\t\trecorder.stop()\n\t\t} catch {\n\t\t\t// already stopped\n\t\t}\n\t}\n\tstore.recorder = null\n\tif (store.stream) {\n\t\tstore.stream.getTracks().forEach(t => t.stop())\n\t\tstore.stream = null\n\t}\n}\n\nasync function finishFlow(store: RecorderStore, ctx: PluginContext, opts: { showThanks: boolean }): Promise<void> {\n\tif (store.cancelled) return\n\tif (store.indicatorState === 'finishing' || store.indicatorState === 'done') return\n\tstore.indicatorState = 'finishing'\n\trenderIndicatorState(store)\n\n\tstopRecording(store)\n\t// Wait for the queued uploads to drain. Each upload already has its own\n\t// retry/backoff; this just lets them finish before finalise fires.\n\tawait store.uploadQueue\n\tawait flushPendingFromIdb(store, ctx)\n\n\tconst durationSeconds = (Date.now() - store.startedAt) / 1000\n\tif (store.sessionId) {\n\t\tconst ok = await finaliseSession(store.options.apiUrl, store.sessionId, durationSeconds)\n\t\tstore.indicatorState = ok ? 'done' : 'error'\n\t} else {\n\t\tstore.indicatorState = 'error'\n\t}\n\trenderIndicatorState(store)\n\n\tif (opts.showThanks && store.indicatorRoot && store.indicatorState === 'done') {\n\t\tshowThanksScreen(store.indicatorRoot)\n\t}\n}\n\nexport function userTest(options: UserTestOptions = {}): UseroPlugin {\n\tconst merged: Required<UserTestOptions> = {\n\t\tqueryParam: options.queryParam ?? DEFAULT_OPTIONS.queryParam,\n\t\tchunkSeconds: options.chunkSeconds ?? DEFAULT_OPTIONS.chunkSeconds,\n\t\tapiUrl: options.apiUrl ?? DEFAULT_OPTIONS.apiUrl,\n\t\ttesterName: options.testerName ?? DEFAULT_OPTIONS.testerName,\n\t\thideIndicator: options.hideIndicator ?? DEFAULT_OPTIONS.hideIndicator,\n\t}\n\n\treturn {\n\t\tname: 'user-test',\n\t\tonInit(ctx) {\n\t\t\tif (typeof window === 'undefined' || typeof document === 'undefined') return\n\t\t\tconst slug = getTestSlug(merged.queryParam)\n\t\t\tif (!slug) return\n\n\t\t\tconst apiUrl = merged.apiUrl || ctx.baseUrl || DEFAULT_API_URL\n\t\t\tconst store: RecorderStore = {\n\t\t\t\tcancelled: false,\n\t\t\t\tslug,\n\t\t\t\tsessionId: null,\n\t\t\t\tclientId: null,\n\t\t\t\trecorder: null,\n\t\t\t\tstream: null,\n\t\t\t\tchunkIndex: 0,\n\t\t\t\tuploadQueue: Promise.resolve(),\n\t\t\t\tpendingUploads: 0,\n\t\t\t\tstartedAt: Date.now(),\n\t\t\t\tindicator: null,\n\t\t\t\tindicatorRoot: null,\n\t\t\t\tindicatorState: 'recording',\n\t\t\t\tpageHideHandler: null,\n\t\t\t\toptions: { ...merged, apiUrl },\n\t\t\t}\n\t\t\tctx.setStore(store)\n\n\t\t\tconst onFinish = (): void => {\n\t\t\t\tvoid finishFlow(store, ctx, { showThanks: true })\n\t\t\t}\n\n\t\t\tif (!merged.hideIndicator) {\n\t\t\t\tconst host = document.createElement('div')\n\t\t\t\thost.setAttribute('data-usero-user-test', 'true')\n\t\t\t\tdocument.body.appendChild(host)\n\t\t\t\tstore.indicator = host\n\t\t\t\tstore.indicatorRoot = buildIndicator(host, store, onFinish)\n\t\t\t\trenderIndicatorState(store)\n\t\t\t}\n\n\t\t\tconst pageHide = (): void => {\n\t\t\t\t// Best-effort flush + finalise. We don't await here; the browser\n\t\t\t\t// is shutting the page down. `keepalive: true` on finalise lets\n\t\t\t\t// the request race the unload.\n\t\t\t\tvoid finishFlow(store, ctx, { showThanks: false })\n\t\t\t}\n\t\t\tstore.pageHideHandler = pageHide\n\t\t\twindow.addEventListener('pagehide', pageHide)\n\n\t\t\tvoid (async (): Promise<void> => {\n\t\t\t\tconst created = await createSession(apiUrl, slug, readTesterName(merged.testerName))\n\t\t\t\tif (store.cancelled) return\n\t\t\t\tif (!created) {\n\t\t\t\t\tctx.logger.error('failed to create user-test session')\n\t\t\t\t\tstore.indicatorState = 'error'\n\t\t\t\t\trenderIndicatorState(store)\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\tstore.sessionId = created.sessionId\n\t\t\t\tstore.clientId = created.clientId\n\t\t\t\tawait startRecording(store, ctx)\n\t\t\t\trenderIndicatorState(store)\n\t\t\t})()\n\t\t},\n\t\tonDestroy(ctx) {\n\t\t\tconst store = ctx.getStore<RecorderStore>()\n\t\t\tif (!store) return\n\t\t\tstore.cancelled = true\n\t\t\tif (store.pageHideHandler) {\n\t\t\t\twindow.removeEventListener('pagehide', store.pageHideHandler)\n\t\t\t\tstore.pageHideHandler = null\n\t\t\t}\n\t\t\tstopRecording(store)\n\t\t\tif (store.indicator && store.indicator.parentNode) {\n\t\t\t\tstore.indicator.parentNode.removeChild(store.indicator)\n\t\t\t}\n\t\t\tstore.indicator = null\n\t\t\tstore.indicatorRoot = null\n\t\t},\n\t}\n}\n\n// Internal helpers exposed for tests only. Not part of the public API.\nexport const __test__ = { getTestSlug, pickMimeType, isMediaRecorderSupported }\n"]}
@@ -35,6 +35,7 @@ interface PluginContext {
35
35
  getStore: <T>() => T | undefined;
36
36
  setStore: <T>(value: T) => void;
37
37
  logger: PluginLogger;
38
+ resolveUser?: () => void;
38
39
  }
39
40
  interface UseroPlugin {
40
41
  name: string;
@@ -35,6 +35,7 @@ interface PluginContext {
35
35
  getStore: <T>() => T | undefined;
36
36
  setStore: <T>(value: T) => void;
37
37
  logger: PluginLogger;
38
+ resolveUser?: () => void;
38
39
  }
39
40
  interface UseroPlugin {
40
41
  name: string;