@amplitude/session-replay-browser 1.43.0 → 1.44.1

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.
Files changed (75) hide show
  1. package/lib/cjs/config/local-config.d.ts +3 -1
  2. package/lib/cjs/config/local-config.d.ts.map +1 -1
  3. package/lib/cjs/config/local-config.js +60 -2
  4. package/lib/cjs/config/local-config.js.map +1 -1
  5. package/lib/cjs/config/types.d.ts +43 -0
  6. package/lib/cjs/config/types.d.ts.map +1 -1
  7. package/lib/cjs/config/types.js.map +1 -1
  8. package/lib/cjs/constants.d.ts +1 -0
  9. package/lib/cjs/constants.d.ts.map +1 -1
  10. package/lib/cjs/constants.js +7 -1
  11. package/lib/cjs/constants.js.map +1 -1
  12. package/lib/cjs/events/base-events-store.d.ts.map +1 -1
  13. package/lib/cjs/events/base-events-store.js +1 -1
  14. package/lib/cjs/events/base-events-store.js.map +1 -1
  15. package/lib/cjs/events/events-idb-store.d.ts +2 -0
  16. package/lib/cjs/events/events-idb-store.d.ts.map +1 -1
  17. package/lib/cjs/events/events-idb-store.js +44 -15
  18. package/lib/cjs/events/events-idb-store.js.map +1 -1
  19. package/lib/cjs/events/events-memory-store.d.ts +2 -0
  20. package/lib/cjs/events/events-memory-store.d.ts.map +1 -1
  21. package/lib/cjs/events/events-memory-store.js +60 -11
  22. package/lib/cjs/events/events-memory-store.js.map +1 -1
  23. package/lib/cjs/session-replay.d.ts.map +1 -1
  24. package/lib/cjs/session-replay.js +27 -25
  25. package/lib/cjs/session-replay.js.map +1 -1
  26. package/lib/cjs/track-destination.d.ts +19 -1
  27. package/lib/cjs/track-destination.d.ts.map +1 -1
  28. package/lib/cjs/track-destination.js +188 -11
  29. package/lib/cjs/track-destination.js.map +1 -1
  30. package/lib/cjs/version.d.ts +1 -1
  31. package/lib/cjs/version.js +1 -1
  32. package/lib/cjs/version.js.map +1 -1
  33. package/lib/cjs/worker/index.js +1 -1
  34. package/lib/esm/config/local-config.d.ts +3 -1
  35. package/lib/esm/config/local-config.d.ts.map +1 -1
  36. package/lib/esm/config/local-config.js +61 -3
  37. package/lib/esm/config/local-config.js.map +1 -1
  38. package/lib/esm/config/types.d.ts +43 -0
  39. package/lib/esm/config/types.d.ts.map +1 -1
  40. package/lib/esm/config/types.js.map +1 -1
  41. package/lib/esm/constants.d.ts +1 -0
  42. package/lib/esm/constants.d.ts.map +1 -1
  43. package/lib/esm/constants.js +6 -0
  44. package/lib/esm/constants.js.map +1 -1
  45. package/lib/esm/events/base-events-store.d.ts.map +1 -1
  46. package/lib/esm/events/base-events-store.js +1 -1
  47. package/lib/esm/events/base-events-store.js.map +1 -1
  48. package/lib/esm/events/events-idb-store.d.ts +2 -0
  49. package/lib/esm/events/events-idb-store.d.ts.map +1 -1
  50. package/lib/esm/events/events-idb-store.js +44 -15
  51. package/lib/esm/events/events-idb-store.js.map +1 -1
  52. package/lib/esm/events/events-memory-store.d.ts +2 -0
  53. package/lib/esm/events/events-memory-store.d.ts.map +1 -1
  54. package/lib/esm/events/events-memory-store.js +61 -12
  55. package/lib/esm/events/events-memory-store.js.map +1 -1
  56. package/lib/esm/session-replay.d.ts.map +1 -1
  57. package/lib/esm/session-replay.js +27 -25
  58. package/lib/esm/session-replay.js.map +1 -1
  59. package/lib/esm/track-destination.d.ts +19 -1
  60. package/lib/esm/track-destination.d.ts.map +1 -1
  61. package/lib/esm/track-destination.js +190 -13
  62. package/lib/esm/track-destination.js.map +1 -1
  63. package/lib/esm/version.d.ts +1 -1
  64. package/lib/esm/version.js +1 -1
  65. package/lib/esm/version.js.map +1 -1
  66. package/lib/esm/worker/index.js +1 -1
  67. package/lib/scripts/index-min.js +1 -1
  68. package/lib/scripts/index-min.js.gz +0 -0
  69. package/lib/scripts/index-min.js.map +1 -1
  70. package/lib/scripts/session-replay-browser-min.js +1 -1
  71. package/lib/scripts/session-replay-browser-min.js.gz +0 -0
  72. package/lib/scripts/session-replay-browser-min.js.map +1 -1
  73. package/lib/scripts/worker-min.js +1 -1
  74. package/lib/scripts/worker-min.js.gz +0 -0
  75. package/package.json +3 -3
@@ -1 +1 @@
1
- {"version":3,"file":"events-idb-store.js","sourceRoot":"","sources":["../../../src/events/events-idb-store.ts"],"names":[],"mappings":";AAAA,OAAO,EAA0B,MAAM,EAAE,MAAM,KAAK,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE9C,OAAO,EAAE,eAAe,EAAoC,MAAM,qBAAqB,CAAC;AACxF,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAEtD,wEAAwE;AACxE,4EAA4E;AAC5E,qEAAqE;AACrE,MAAM,UAAU,YAAY;IAC1B,IAAI;QACF,OAAO,MAAM,CAAC,UAAU,EAAE,CAAC;KAC5B;IAAC,WAAM;QACN,OAAO,sCAAsC,CAAC,OAAO,CAAC,OAAO,EAAE,UAAC,CAAC;YAC/D,IAAM,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC;YACnC,OAAO,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;QACxD,CAAC,CAAC,CAAC;KACJ;AACH,CAAC;AAED,MAAM,CAAC,IAAM,kBAAkB,GAAG,wBAAwB,CAAC;AAC3D,MAAM,CAAC,IAAM,kBAAkB,GAAG,iBAAiB,CAAC;AACpD,MAAM,CAAC,IAAM,eAAe,GAAG,cAAc,CAAC;AAE9C,4EAA4E;AAC5E,4EAA4E;AAC5E,4EAA4E;AAC5E,4EAA4E;AAC5E,0BAA0B;AAC1B,MAAM,CAAC,IAAM,kBAAkB,GAAG,IAAI,CAAC;AAEvC,2EAA2E;AAC3E,6EAA6E;AAC7E,wEAAwE;AACxE,2EAA2E;AAC3E,oEAAoE;AACpE,MAAM,CAAC,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BAAS;yBACV;wBACc,MAAM,GAAc,MAAM,MAApB,EAAK,IAAI,UAAK,MAAM,EAAnC,SAA0B,CAAF,CAAY;wBAC1C,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;;;;;;;;;;;;;;;;6BAGvB,sBAAO,SAAS,EAAC;;;;KAClB;IAiQH,kCAAC;AAAD,CAAC,AAnVD,CAAiD,eAAe,GAmV/D","sourcesContent":["import { DBSchema, IDBPDatabase, openDB } from 'idb';\nimport { STORAGE_FAILURE } from '../messages';\nimport { EventType, Events, SendingSequencesReturn } from '../typings/session-replay';\nimport { BaseEventsStore, InstanceArgs as BaseInstanceArgs } from './base-events-store';\nimport { logIdbError } from '../utils/is-abort-error';\n\n// crypto.randomUUID() requires a secure context (https). Fall back to a\n// Math.random-based UUID for http origins or older browsers — tab IDs don't\n// need to be cryptographically secure, just unique within a session.\nexport function generateUUID(): string {\n try {\n return crypto.randomUUID();\n } catch {\n return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {\n const r = (Math.random() * 16) | 0;\n return (c === 'x' ? r : (r & 0x3) | 0x8).toString(16);\n });\n }\n}\n\nexport const currentSequenceKey = 'sessionCurrentSequence';\nexport const sequencesToSendKey = 'sequencesToSend';\nexport const remoteConfigKey = 'remoteConfig';\n\n// Timeout for openDB at init. IDB openDB can hang forever when another tab\n// holds an open connection during a version upgrade, or when the DB is in a\n// \"closing\" state (documented Chrome behaviour). When that happens we want\n// SessionReplayEventsIDBStore.new() to bail out so the caller can fall back\n// to the in-memory store.\nexport const OPEN_DB_TIMEOUT_MS = 2000;\n\n// Timeout for per-operation tx.done settlement. Mid-recording a readwrite\n// transaction can stall (storage pressure in some browsers stalls instead of\n// throwing); without a timeout, recordFailure() is never called and the\n// memory fallback never triggers. The transaction may still settle later;\n// the timedOut flag prevents double-counting alongside errorLogged.\nexport const TX_DONE_TIMEOUT_MS = 5000;\n\n/**\n * Race a promise against a timeout. Resolves/rejects with the original\n * promise's value when it settles first; rejects with a timeout error if\n * `ms` elapses first. Either way the timer is cleared so we don't leak\n * pending setTimeouts.\n */\nexport function withTimeout<T>(promise: Promise<T>, ms: number, message = 'IDB operation timed out'): Promise<T> {\n return new Promise<T>((resolve, reject) => {\n const timer = setTimeout(() => reject(new Error(`${message} after ${ms}ms`)), ms);\n promise.then(\n (v) => {\n clearTimeout(timer);\n resolve(v);\n },\n (e) => {\n clearTimeout(timer);\n reject(e);\n },\n );\n });\n}\n\n/**\n * Arms a watchdog that fires `onTimeout` only if `tx.done` hasn't settled\n * within `ms`. A \"soft cancel\" returned to the caller suppresses the timeout\n * if the synchronous operation body completes without exception — important\n * because in test environments fake timers can fire ahead of tx.done's commit\n * microtask. Production behaviour is preserved: a genuinely stalled\n * transaction (no commit, no error, individual op promises never resolved)\n * cannot reach the soft-cancel call and the timeout fires as designed.\n *\n * Soft-cancel is only invoked once the awaits inside the operation's outer\n * try block have all returned — i.e. the IDB driver acknowledged each\n * individual put/get. If the driver accepts a put but the underlying\n * transaction silently fails to commit (the production stall scenario),\n * tx.done still hasn't settled, and recordFailure must NOT have been\n * suppressed. The fix for that scenario in production is the tx.done.catch\n * handler attached separately by callers, which catches the eventual abort.\n *\n * The soft-cancel pattern only suppresses the timeout for the \"all puts\n * resolved successfully\" case — a case where tx.done is overwhelmingly\n * likely to settle imminently in production. If it doesn't, callers can\n * still detect the failure on the NEXT operation (which will fail to open\n * a transaction or hit the same pressure), because all three methods use\n * readwrite transactions on the same two stores, which IDB serializes:\n * if T1's tx.done never settles, T2 is blocked waiting for T1 to commit or\n * abort — T2's put/get requests never resolve, T2 never reaches its\n * soft-cancel, and T2's watchdog fires, calling recordFailure().\n */\nfunction armTxDoneTimeout(txDone: Promise<unknown>, ms: number, onTimeout: () => void): () => void {\n const timer = setTimeout(onTimeout, ms);\n // Belt-and-braces: clear the timer when tx.done settles, even though the\n // primary cancel path is the caller's success-path cancel(). This covers\n // the case where tx.done settles with no caller cancellation (shouldn't\n // happen in current code paths, but cheap insurance).\n txDone.then(\n () => clearTimeout(timer),\n () => clearTimeout(timer),\n );\n return () => clearTimeout(timer);\n}\n\nexport interface SessionReplayDB extends DBSchema {\n sessionCurrentSequence: {\n key: number;\n value: Omit<SendingSequencesReturn<number>, 'sequenceId'> & { tabId?: string };\n };\n sequencesToSend: {\n key: number;\n value: Omit<SendingSequencesReturn<number>, 'sequenceId'> & { tabId?: string };\n indexes: { sessionId: string | number };\n };\n}\n\nexport const defineObjectStores = (db: IDBPDatabase<SessionReplayDB>) => {\n let sequencesStore;\n let currentSequenceStore;\n if (!db.objectStoreNames.contains(currentSequenceKey)) {\n currentSequenceStore = db.createObjectStore(currentSequenceKey, {\n keyPath: 'sessionId',\n });\n }\n if (!db.objectStoreNames.contains(sequencesToSendKey)) {\n sequencesStore = db.createObjectStore(sequencesToSendKey, {\n keyPath: 'sequenceId',\n autoIncrement: true,\n });\n sequencesStore.createIndex('sessionId', 'sessionId');\n }\n return {\n sequencesStore,\n currentSequenceStore,\n };\n};\n\nexport const createStore = async (dbName: string) => {\n // Wrap openDB with a timeout so a hung connection (foreign tab holding an\n // open handle during version upgrade, or \"closing\" DB) doesn't block the\n // SDK from initialising. On timeout this rejects, which propagates up to\n // SessionReplayEventsIDBStore.new()'s catch block, returning undefined and\n // triggering the memory fallback.\n return await withTimeout(\n openDB<SessionReplayDB>(dbName, 1, {\n upgrade: defineObjectStores,\n }),\n OPEN_DB_TIMEOUT_MS,\n 'IDB openDB timed out',\n );\n};\n\ntype InstanceArgs = {\n apiKey: string;\n db: IDBPDatabase<SessionReplayDB>;\n tabId: string;\n onPersistentFailure?: () => void;\n consecutiveFailureThreshold?: number;\n} & BaseInstanceArgs;\n\nexport class SessionReplayEventsIDBStore extends BaseEventsStore<number> {\n private readonly db: IDBPDatabase<SessionReplayDB>;\n private readonly tabId: string;\n private readonly onPersistentFailure?: () => void;\n private readonly consecutiveFailureThreshold: number;\n private consecutiveFailures = 0;\n private hasTriggeredFallback = false;\n\n constructor(args: InstanceArgs) {\n super(args);\n this.db = args.db;\n this.tabId = args.tabId;\n this.onPersistentFailure = args.onPersistentFailure;\n // Default threshold of 1: fall back to memory immediately on the first IDB failure.\n // Session replay correctness is far more important than persistence, and IDB errors\n // are typically the symptom of a deeper problem (storage pressure, locked DB, broken\n // browser implementation) that won't recover within a single session. Memory store\n // is always safe — fall back early.\n this.consecutiveFailureThreshold = args.consecutiveFailureThreshold ?? 1;\n }\n\n private recordFailure() {\n this.consecutiveFailures++;\n if (!this.hasTriggeredFallback && this.consecutiveFailures >= this.consecutiveFailureThreshold) {\n this.hasTriggeredFallback = true;\n this.onPersistentFailure?.();\n }\n }\n\n private recordSuccess() {\n this.consecutiveFailures = 0;\n }\n\n static async new(\n type: EventType,\n args: Omit<InstanceArgs, 'db' | 'tabId'> & { tabId?: string },\n ): Promise<SessionReplayEventsIDBStore | undefined> {\n try {\n const dbSuffix = type === 'replay' ? '' : `_${type}`;\n const dbName = `${args.apiKey.substring(0, 10)}_amp_session_replay_events${dbSuffix}`;\n const db = await createStore(dbName);\n // Generate a fresh in-memory UUID per store instance. sessionStorage is\n // intentionally avoided: standalone session-replay customers (without the\n // analytics-browser SDK) would be exposed to a new storage surface they\n // did not consent to, and persistence across page reloads is not needed —\n // completed sequences in sequencesToSend are flushed by any tab/instance.\n const tabId = args.tabId ?? generateUUID();\n return new SessionReplayEventsIDBStore({\n ...args,\n db,\n tabId,\n });\n } catch (e) {\n logIdbError(args.loggerProvider, `${STORAGE_FAILURE}: ${e as string}`, e);\n }\n return;\n }\n\n async getCurrentSequenceEvents(sessionId?: number) {\n if (sessionId) {\n const record = await this.db.get('sessionCurrentSequence', sessionId);\n if (!record) {\n return undefined;\n }\n // Only return our own tab's record (or legacy untagged records).\n if (record.tabId && record.tabId !== this.tabId) {\n return undefined;\n }\n const { tabId: _tabId, ...rest } = record;\n return [rest];\n }\n\n const allEvents = [];\n for (const record of await this.db.getAll('sessionCurrentSequence')) {\n if (record.tabId && record.tabId !== this.tabId) {\n continue;\n }\n const { tabId: _tabId, ...rest } = record;\n allEvents.push(rest);\n }\n\n return allEvents;\n }\n\n getSequencesToSend = async (): Promise<SendingSequencesReturn<number>[] | undefined> => {\n let errorLogged = false;\n let timedOut = false;\n try {\n const sequences: SendingSequencesReturn<number>[] = [];\n const tx = this.db.transaction('sequencesToSend');\n // Attach a catch handler immediately so tx.done rejections (e.g. AbortError after\n // cursor traversal completes) are always handled without blocking the return path.\n // The errorLogged / timedOut flags prevent double-logging and double-recording\n // when the outer catch (or the timeout race) already fired for the same abort.\n tx.done.catch((e: unknown) => {\n if (!errorLogged && !timedOut) {\n logIdbError(this.loggerProvider, `${STORAGE_FAILURE}: ${e as string}`, e);\n this.recordFailure();\n }\n });\n // Arm a watchdog so a stalled transaction (no error, no commit, e.g.\n // storage pressure on some browsers) still trips the failure counter.\n // The watchdog fires only when tx.done genuinely never settles AND the\n // operation's success path didn't run; if tx.done rejects (abort), the\n // tx.done.catch handler above is the sole recorder of failure.\n const cancelTimeout = armTxDoneTimeout(tx.done, TX_DONE_TIMEOUT_MS, () => {\n if (!errorLogged && !timedOut) {\n timedOut = true;\n logIdbError(this.loggerProvider, `${STORAGE_FAILURE}: transaction timed out`);\n this.recordFailure();\n }\n });\n let cursor = await tx.store.openCursor();\n while (cursor) {\n const { sessionId, events } = cursor.value;\n // Return all completed sequences regardless of tabId. Filtering by tab\n // would cause event loss on page reload: a new store instance gets a\n // fresh in-memory UUID and would never see sequences written by the\n // previous instance. Completed sequences are safe to flush by any\n // tab/instance; the server deduplicates, and cleanUpSessionEventsStore\n // on an already-deleted key is a no-op.\n sequences.push({\n events,\n sequenceId: cursor.key,\n sessionId,\n });\n cursor = await cursor.continue();\n }\n\n this.recordSuccess();\n cancelTimeout();\n return sequences;\n } catch (e) {\n if (!timedOut) {\n errorLogged = true;\n logIdbError(this.loggerProvider, `${STORAGE_FAILURE}: ${e as string}`, e);\n this.recordFailure();\n }\n }\n return undefined;\n };\n\n storeCurrentSequence = async (sessionId: number) => {\n let errorLogged = false;\n let timedOut = false;\n try {\n // Wrap the read of sessionCurrentSequence and the writes to sequencesToSend +\n // sessionCurrentSequence in a single readwrite transaction so the three operations\n // commit or roll back atomically. Without this, a concurrent addEventToCurrentSequence\n // call could interleave and either lose the events being promoted or duplicate them\n // (storeCurrentSequence reads N events, addEvent appends an N+1th, storeCurrentSequence\n // writes only the first N back to sequencesToSend, then resets the slot — losing N+1).\n const tx = this.db.transaction([currentSequenceKey, sequencesToSendKey], 'readwrite');\n tx.done.catch((e: unknown) => {\n if (!errorLogged && !timedOut) {\n logIdbError(this.loggerProvider, `${STORAGE_FAILURE}: ${e as string}`, e);\n this.recordFailure();\n }\n });\n // Stalled-transaction protection: see armTxDoneTimeout in getSequencesToSend.\n const cancelTimeout = armTxDoneTimeout(tx.done, TX_DONE_TIMEOUT_MS, () => {\n if (!errorLogged && !timedOut) {\n timedOut = true;\n logIdbError(this.loggerProvider, `${STORAGE_FAILURE}: transaction timed out`);\n this.recordFailure();\n }\n });\n\n const currentSequenceData = await tx.objectStore(currentSequenceKey).get(sessionId);\n // Skip promotion if the slot is empty or owned by another tab — let the owning\n // tab promote its own events on its next addEventToCurrentSequence/storeCurrentSequence\n // call (via Bug 1's foreign-tab promotion path).\n // Don't call recordSuccess() here: no write was performed, so this is not\n // evidence the storage layer is healthy — leave the failure counter unchanged.\n if (!currentSequenceData || (currentSequenceData.tabId && currentSequenceData.tabId !== this.tabId)) {\n cancelTimeout();\n return undefined;\n }\n\n // Skip empty sequences — no point writing a zero-event row to sequencesToSend.\n if (currentSequenceData.events.length === 0) {\n cancelTimeout();\n return undefined;\n }\n\n const sequenceId = await tx.objectStore(sequencesToSendKey).put({\n sessionId,\n events: currentSequenceData.events,\n tabId: this.tabId,\n });\n\n await tx.objectStore(currentSequenceKey).put({\n sessionId,\n events: [],\n tabId: this.tabId,\n });\n\n this.recordSuccess();\n cancelTimeout();\n const { tabId: _tabId, ...rest } = currentSequenceData;\n return {\n ...rest,\n sessionId,\n sequenceId,\n };\n } catch (e) {\n if (!timedOut) {\n errorLogged = true;\n logIdbError(this.loggerProvider, `${STORAGE_FAILURE}: ${e as string}`, e);\n this.recordFailure();\n }\n }\n return undefined;\n };\n\n addEventToCurrentSequence = async (sessionId: number, event: string) => {\n let errorLogged = false;\n let timedOut = false;\n try {\n // Always open a readwrite transaction over both stores so that the read and\n // any subsequent write are atomic. IDB serializes readwrite transactions on\n // overlapping stores, so concurrent fire-and-forget callers (events-manager\n // does not await this method) are queued by the engine rather than interleaving\n // — eliminating the TOCTOU race that a narrow-read + separate-write approach\n // would introduce on the split path.\n const tx = this.db.transaction([currentSequenceKey, sequencesToSendKey], 'readwrite');\n // Attach a catch handler immediately so tx.done rejections (e.g. AbortError after\n // put succeeds but before auto-commit) are always handled without blocking.\n // The errorLogged / timedOut flags prevent double-logging when the outer catch\n // (or the timeout) already fired for the same transaction.\n tx.done.catch((e: unknown) => {\n if (!errorLogged && !timedOut) {\n logIdbError(this.loggerProvider, `${STORAGE_FAILURE}: ${e as string}`, e);\n this.recordFailure();\n }\n });\n // Stalled-transaction protection: see armTxDoneTimeout in getSequencesToSend.\n const cancelTimeout = armTxDoneTimeout(tx.done, TX_DONE_TIMEOUT_MS, () => {\n if (!errorLogged && !timedOut) {\n timedOut = true;\n logIdbError(this.loggerProvider, `${STORAGE_FAILURE}: transaction timed out`);\n this.recordFailure();\n }\n });\n const sequenceEvents = await tx.objectStore(currentSequenceKey).get(sessionId);\n\n // Foreign-tab record path: another tab owns the current-sequence slot for this\n // sessionId. Don't silently overwrite — that would drop the foreign tab's\n // in-progress events. Promote them to sequencesToSend (tabId kept for forensics)\n // before claiming the slot for ourselves. getSequencesToSend no longer filters\n // by tabId, so either tab may flush the promoted sequence; server deduplicates.\n if (sequenceEvents?.tabId && sequenceEvents.tabId !== this.tabId) {\n if (sequenceEvents.events.length > 0) {\n await tx.objectStore(sequencesToSendKey).put({\n sessionId,\n events: sequenceEvents.events,\n tabId: sequenceEvents.tabId,\n });\n }\n await tx.objectStore(currentSequenceKey).put({ sessionId, events: [event], tabId: this.tabId });\n this.recordSuccess();\n cancelTimeout();\n return undefined;\n }\n\n // ownedSequence is either undefined (no record yet) or this tab's record.\n const ownedSequence = sequenceEvents;\n\n if (!ownedSequence) {\n await tx.objectStore(currentSequenceKey).put({ sessionId, events: [event], tabId: this.tabId });\n this.recordSuccess();\n cancelTimeout();\n return undefined;\n }\n\n if (!this.shouldSplitEventsList(ownedSequence.events, event)) {\n await tx\n .objectStore(currentSequenceKey)\n .put({ sessionId, events: ownedSequence.events.concat(event), tabId: this.tabId });\n this.recordSuccess();\n cancelTimeout();\n return undefined;\n }\n\n // Split path: reset sessionCurrentSequence and write the old events to\n // sequencesToSend atomically within the same transaction.\n const eventsToSend = ownedSequence.events;\n await tx.objectStore(currentSequenceKey).put({ sessionId, events: [event], tabId: this.tabId });\n const sequenceId = await tx.objectStore(sequencesToSendKey).put({\n sessionId,\n events: eventsToSend,\n tabId: this.tabId,\n });\n\n this.recordSuccess();\n cancelTimeout();\n return {\n events: eventsToSend,\n sessionId,\n sequenceId,\n };\n } catch (e) {\n if (!timedOut) {\n errorLogged = true;\n logIdbError(this.loggerProvider, `${STORAGE_FAILURE}: ${e as string}`, e);\n this.recordFailure();\n }\n }\n return undefined;\n };\n\n storeSendingEvents = async (sessionId: number, events: Events) => {\n try {\n const sequenceId = await this.db.put<'sequencesToSend'>(sequencesToSendKey, {\n sessionId: sessionId,\n events: events,\n tabId: this.tabId,\n });\n this.recordSuccess();\n return sequenceId;\n } catch (e) {\n logIdbError(this.loggerProvider, `${STORAGE_FAILURE}: ${e as string}`, e);\n this.recordFailure();\n }\n return undefined;\n };\n\n cleanUpSessionEventsStore = async (_sessionId: number, sequenceId?: number) => {\n if (!sequenceId) {\n return;\n }\n try {\n await this.db.delete<'sequencesToSend'>(sequencesToSendKey, sequenceId);\n this.recordSuccess();\n } catch (e) {\n logIdbError(this.loggerProvider, `${STORAGE_FAILURE}: ${e as string}`, e);\n this.recordFailure();\n }\n };\n}\n"]}
1
+ {"version":3,"file":"events-idb-store.js","sourceRoot":"","sources":["../../../src/events/events-idb-store.ts"],"names":[],"mappings":";AAAA,OAAO,EAA0B,MAAM,EAAE,MAAM,KAAK,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE9C,OAAO,EAAE,eAAe,EAAoC,MAAM,qBAAqB,CAAC;AACxF,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAEtD,wEAAwE;AACxE,4EAA4E;AAC5E,qEAAqE;AACrE,MAAM,UAAU,YAAY;IAC1B,IAAI;QACF,OAAO,MAAM,CAAC,UAAU,EAAE,CAAC;KAC5B;IAAC,WAAM;QACN,OAAO,sCAAsC,CAAC,OAAO,CAAC,OAAO,EAAE,UAAC,CAAC;YAC/D,IAAM,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC;YACnC,OAAO,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;QACxD,CAAC,CAAC,CAAC;KACJ;AACH,CAAC;AAED,MAAM,CAAC,IAAM,kBAAkB,GAAG,wBAAwB,CAAC;AAC3D,MAAM,CAAC,IAAM,kBAAkB,GAAG,iBAAiB,CAAC;AACpD,MAAM,CAAC,IAAM,eAAe,GAAG,cAAc,CAAC;AAE9C,4EAA4E;AAC5E,4EAA4E;AAC5E,4EAA4E;AAC5E,4EAA4E;AAC5E,0BAA0B;AAC1B,MAAM,CAAC,IAAM,kBAAkB,GAAG,IAAI,CAAC;AAEvC,2EAA2E;AAC3E,6EAA6E;AAC7E,wEAAwE;AACxE,2EAA2E;AAC3E,oEAAoE;AACpE,MAAM,CAAC,IAAM,kBAAkB,GAAG,IAAI,CAAC;AAEv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ema, IDBPDatabase, openDB } from 'idb';\nimport { STORAGE_FAILURE } from '../messages';\nimport { EventType, Events, SendingSequencesReturn } from '../typings/session-replay';\nimport { BaseEventsStore, InstanceArgs as BaseInstanceArgs } from './base-events-store';\nimport { logIdbError } from '../utils/is-abort-error';\n\n// crypto.randomUUID() requires a secure context (https). Fall back to a\n// Math.random-based UUID for http origins or older browsers — tab IDs don't\n// need to be cryptographically secure, just unique within a session.\nexport function generateUUID(): string {\n try {\n return crypto.randomUUID();\n } catch {\n return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {\n const r = (Math.random() * 16) | 0;\n return (c === 'x' ? r : (r & 0x3) | 0x8).toString(16);\n });\n }\n}\n\nexport const currentSequenceKey = 'sessionCurrentSequence';\nexport const sequencesToSendKey = 'sequencesToSend';\nexport const remoteConfigKey = 'remoteConfig';\n\n// Timeout for openDB at init. IDB openDB can hang forever when another tab\n// holds an open connection during a version upgrade, or when the DB is in a\n// \"closing\" state (documented Chrome behaviour). When that happens we want\n// SessionReplayEventsIDBStore.new() to bail out so the caller can fall back\n// to the in-memory store.\nexport const OPEN_DB_TIMEOUT_MS = 2000;\n\n// Timeout for per-operation tx.done settlement. Mid-recording a readwrite\n// transaction can stall (storage pressure in some browsers stalls instead of\n// throwing); without a timeout, recordFailure() is never called and the\n// memory fallback never triggers. The transaction may still settle later;\n// the timedOut flag prevents double-counting alongside errorLogged.\nexport const TX_DONE_TIMEOUT_MS = 5000;\n\n/**\n * Race a promise against a timeout. Resolves/rejects with the original\n * promise's value when it settles first; rejects with a timeout error if\n * `ms` elapses first. Either way the timer is cleared so we don't leak\n * pending setTimeouts.\n */\nexport function withTimeout<T>(promise: Promise<T>, ms: number, message = 'IDB operation timed out'): Promise<T> {\n return new Promise<T>((resolve, reject) => {\n const timer = setTimeout(() => reject(new Error(`${message} after ${ms}ms`)), ms);\n promise.then(\n (v) => {\n clearTimeout(timer);\n resolve(v);\n },\n (e) => {\n clearTimeout(timer);\n reject(e);\n },\n );\n });\n}\n\n/**\n * Arms a watchdog that fires `onTimeout` only if `tx.done` hasn't settled\n * within `ms`. A \"soft cancel\" returned to the caller suppresses the timeout\n * if the synchronous operation body completes without exception — important\n * because in test environments fake timers can fire ahead of tx.done's commit\n * microtask. Production behaviour is preserved: a genuinely stalled\n * transaction (no commit, no error, individual op promises never resolved)\n * cannot reach the soft-cancel call and the timeout fires as designed.\n *\n * Soft-cancel is only invoked once the awaits inside the operation's outer\n * try block have all returned — i.e. the IDB driver acknowledged each\n * individual put/get. If the driver accepts a put but the underlying\n * transaction silently fails to commit (the production stall scenario),\n * tx.done still hasn't settled, and recordFailure must NOT have been\n * suppressed. The fix for that scenario in production is the tx.done.catch\n * handler attached separately by callers, which catches the eventual abort.\n *\n * The soft-cancel pattern only suppresses the timeout for the \"all puts\n * resolved successfully\" case — a case where tx.done is overwhelmingly\n * likely to settle imminently in production. If it doesn't, callers can\n * still detect the failure on the NEXT operation (which will fail to open\n * a transaction or hit the same pressure), because all three methods use\n * readwrite transactions on the same two stores, which IDB serializes:\n * if T1's tx.done never settles, T2 is blocked waiting for T1 to commit or\n * abort — T2's put/get requests never resolve, T2 never reaches its\n * soft-cancel, and T2's watchdog fires, calling recordFailure().\n */\nfunction armTxDoneTimeout(txDone: Promise<unknown>, ms: number, onTimeout: () => void): () => void {\n const timer = setTimeout(onTimeout, ms);\n // Belt-and-braces: clear the timer when tx.done settles, even though the\n // primary cancel path is the caller's success-path cancel(). This covers\n // the case where tx.done settles with no caller cancellation (shouldn't\n // happen in current code paths, but cheap insurance).\n txDone.then(\n () => clearTimeout(timer),\n () => clearTimeout(timer),\n );\n return () => clearTimeout(timer);\n}\n\nexport interface SessionReplayDB extends DBSchema {\n sessionCurrentSequence: {\n key: number;\n value: Omit<SendingSequencesReturn<number>, 'sequenceId'> & { tabId?: string };\n };\n sequencesToSend: {\n key: number;\n value: Omit<SendingSequencesReturn<number>, 'sequenceId'> & { tabId?: string };\n indexes: { sessionId: string | number };\n };\n}\n\nexport const defineObjectStores = (db: IDBPDatabase<SessionReplayDB>) => {\n let sequencesStore;\n let currentSequenceStore;\n if (!db.objectStoreNames.contains(currentSequenceKey)) {\n currentSequenceStore = db.createObjectStore(currentSequenceKey, {\n keyPath: 'sessionId',\n });\n }\n if (!db.objectStoreNames.contains(sequencesToSendKey)) {\n sequencesStore = db.createObjectStore(sequencesToSendKey, {\n keyPath: 'sequenceId',\n autoIncrement: true,\n });\n sequencesStore.createIndex('sessionId', 'sessionId');\n }\n return {\n sequencesStore,\n currentSequenceStore,\n };\n};\n\nexport const createStore = async (dbName: string) => {\n // Wrap openDB with a timeout so a hung connection (foreign tab holding an\n // open handle during version upgrade, or \"closing\" DB) doesn't block the\n // SDK from initialising. On timeout this rejects, which propagates up to\n // SessionReplayEventsIDBStore.new()'s catch block, returning undefined and\n // triggering the memory fallback.\n return await withTimeout(\n openDB<SessionReplayDB>(dbName, 1, {\n upgrade: defineObjectStores,\n }),\n OPEN_DB_TIMEOUT_MS,\n 'IDB openDB timed out',\n );\n};\n\ntype InstanceArgs = {\n apiKey: string;\n db: IDBPDatabase<SessionReplayDB>;\n tabId: string;\n onPersistentFailure?: () => void;\n consecutiveFailureThreshold?: number;\n} & BaseInstanceArgs;\n\nexport class SessionReplayEventsIDBStore extends BaseEventsStore<number> {\n private readonly db: IDBPDatabase<SessionReplayDB>;\n private readonly tabId: string;\n private readonly onPersistentFailure?: () => void;\n private readonly consecutiveFailureThreshold: number;\n private consecutiveFailures = 0;\n private hasTriggeredFallback = false;\n private emptyFilteredCount = 0;\n\n // Sampled (1 in 100) debug log so we can observe whether the store-layer guards\n // are catching empty-batch cases that would otherwise hit the empty-body 400 path\n // on the server. Logged at debug, not warn — this is operational telemetry for\n // post-deploy verification, not a customer-actionable warning. Per-store-instance\n // counter (rather than Math.random) keeps the first hit deterministic for tests.\n private maybeLogEmptyFiltered(source: string) {\n if (this.emptyFilteredCount++ % 100 === 0) {\n this.loggerProvider.debug(`Filtered empty session replay sequence at ${source} (idb store)`);\n }\n }\n\n constructor(args: InstanceArgs) {\n super(args);\n this.db = args.db;\n this.tabId = args.tabId;\n this.onPersistentFailure = args.onPersistentFailure;\n // Default threshold of 1: fall back to memory immediately on the first IDB failure.\n // Session replay correctness is far more important than persistence, and IDB errors\n // are typically the symptom of a deeper problem (storage pressure, locked DB, broken\n // browser implementation) that won't recover within a single session. Memory store\n // is always safe — fall back early.\n this.consecutiveFailureThreshold = args.consecutiveFailureThreshold ?? 1;\n }\n\n private recordFailure() {\n this.consecutiveFailures++;\n if (!this.hasTriggeredFallback && this.consecutiveFailures >= this.consecutiveFailureThreshold) {\n this.hasTriggeredFallback = true;\n this.onPersistentFailure?.();\n }\n }\n\n private recordSuccess() {\n this.consecutiveFailures = 0;\n }\n\n static async new(\n type: EventType,\n args: Omit<InstanceArgs, 'db' | 'tabId'> & { tabId?: string },\n ): Promise<SessionReplayEventsIDBStore | undefined> {\n try {\n const dbSuffix = type === 'replay' ? '' : `_${type}`;\n const dbName = `${args.apiKey.substring(0, 10)}_amp_session_replay_events${dbSuffix}`;\n const db = await createStore(dbName);\n // Generate a fresh in-memory UUID per store instance. sessionStorage is\n // intentionally avoided: standalone session-replay customers (without the\n // analytics-browser SDK) would be exposed to a new storage surface they\n // did not consent to, and persistence across page reloads is not needed —\n // completed sequences in sequencesToSend are flushed by any tab/instance.\n const tabId = args.tabId ?? generateUUID();\n return new SessionReplayEventsIDBStore({\n ...args,\n db,\n tabId,\n });\n } catch (e) {\n logIdbError(args.loggerProvider, `${STORAGE_FAILURE}: ${e as string}`, e);\n }\n return;\n }\n\n async getCurrentSequenceEvents(sessionId?: number) {\n if (sessionId) {\n const record = await this.db.get('sessionCurrentSequence', sessionId);\n if (!record) {\n return undefined;\n }\n // Only return our own tab's record (or legacy untagged records).\n if (record.tabId && record.tabId !== this.tabId) {\n return undefined;\n }\n const { tabId: _tabId, ...rest } = record;\n return [rest];\n }\n\n const allEvents = [];\n for (const record of await this.db.getAll('sessionCurrentSequence')) {\n if (record.tabId && record.tabId !== this.tabId) {\n continue;\n }\n const { tabId: _tabId, ...rest } = record;\n allEvents.push(rest);\n }\n\n return allEvents;\n }\n\n getSequencesToSend = async (): Promise<SendingSequencesReturn<number>[] | undefined> => {\n let errorLogged = false;\n let timedOut = false;\n try {\n const sequences: SendingSequencesReturn<number>[] = [];\n // readwrite mode so we can prune stale empty rows in-place. Without that,\n // older-SDK-persisted events:[] rows sit in IDB indefinitely and re-fire the\n // sampled log on every flush cycle, creating Datadog noise indistinguishable\n // from active bug occurrences.\n const tx = this.db.transaction('sequencesToSend', 'readwrite');\n // Attach a catch handler immediately so tx.done rejections (e.g. AbortError after\n // cursor traversal completes) are always handled without blocking the return path.\n // The errorLogged / timedOut flags prevent double-logging and double-recording\n // when the outer catch (or the timeout race) already fired for the same abort.\n tx.done.catch((e: unknown) => {\n if (!errorLogged && !timedOut) {\n logIdbError(this.loggerProvider, `${STORAGE_FAILURE}: ${e as string}`, e);\n this.recordFailure();\n }\n });\n // Arm a watchdog so a stalled transaction (no error, no commit, e.g.\n // storage pressure on some browsers) still trips the failure counter.\n // The watchdog fires only when tx.done genuinely never settles AND the\n // operation's success path didn't run; if tx.done rejects (abort), the\n // tx.done.catch handler above is the sole recorder of failure.\n const cancelTimeout = armTxDoneTimeout(tx.done, TX_DONE_TIMEOUT_MS, () => {\n if (!errorLogged && !timedOut) {\n timedOut = true;\n logIdbError(this.loggerProvider, `${STORAGE_FAILURE}: transaction timed out`);\n this.recordFailure();\n }\n });\n let cursor = await tx.store.openCursor();\n while (cursor) {\n const { sessionId, events } = cursor.value;\n // Skip empty persisted records. These can come from older SDK builds that\n // wrote zero-event sequences via addEventToCurrentSequence's split path\n // (when a single oversized event triggered a split with empty buffer);\n // flushing them produces empty-body POSTs the server rejects with 400.\n // Delete them in-place so they don't re-fire the sampled log on every\n // subsequent flush — by construction (this fix) we never write empty rows\n // anymore, so any empty row is unambiguously stale.\n if (events.length === 0) {\n this.maybeLogEmptyFiltered('getSequencesToSend');\n await cursor.delete();\n } else {\n // Return all completed sequences regardless of tabId. Filtering by tab\n // would cause event loss on page reload: a new store instance gets a\n // fresh in-memory UUID and would never see sequences written by the\n // previous instance. Completed sequences are safe to flush by any\n // tab/instance; the server deduplicates, and cleanUpSessionEventsStore\n // on an already-deleted key is a no-op.\n sequences.push({\n events,\n sequenceId: cursor.key,\n sessionId,\n });\n }\n cursor = await cursor.continue();\n }\n\n this.recordSuccess();\n cancelTimeout();\n return sequences;\n } catch (e) {\n if (!timedOut) {\n errorLogged = true;\n logIdbError(this.loggerProvider, `${STORAGE_FAILURE}: ${e as string}`, e);\n this.recordFailure();\n }\n }\n return undefined;\n };\n\n storeCurrentSequence = async (sessionId: number) => {\n let errorLogged = false;\n let timedOut = false;\n try {\n // Wrap the read of sessionCurrentSequence and the writes to sequencesToSend +\n // sessionCurrentSequence in a single readwrite transaction so the three operations\n // commit or roll back atomically. Without this, a concurrent addEventToCurrentSequence\n // call could interleave and either lose the events being promoted or duplicate them\n // (storeCurrentSequence reads N events, addEvent appends an N+1th, storeCurrentSequence\n // writes only the first N back to sequencesToSend, then resets the slot — losing N+1).\n const tx = this.db.transaction([currentSequenceKey, sequencesToSendKey], 'readwrite');\n tx.done.catch((e: unknown) => {\n if (!errorLogged && !timedOut) {\n logIdbError(this.loggerProvider, `${STORAGE_FAILURE}: ${e as string}`, e);\n this.recordFailure();\n }\n });\n // Stalled-transaction protection: see armTxDoneTimeout in getSequencesToSend.\n const cancelTimeout = armTxDoneTimeout(tx.done, TX_DONE_TIMEOUT_MS, () => {\n if (!errorLogged && !timedOut) {\n timedOut = true;\n logIdbError(this.loggerProvider, `${STORAGE_FAILURE}: transaction timed out`);\n this.recordFailure();\n }\n });\n\n const currentSequenceData = await tx.objectStore(currentSequenceKey).get(sessionId);\n // Skip promotion if the slot is empty or owned by another tab — let the owning\n // tab promote its own events on its next addEventToCurrentSequence/storeCurrentSequence\n // call (via Bug 1's foreign-tab promotion path).\n // Don't call recordSuccess() here: no write was performed, so this is not\n // evidence the storage layer is healthy — leave the failure counter unchanged.\n if (!currentSequenceData || (currentSequenceData.tabId && currentSequenceData.tabId !== this.tabId)) {\n cancelTimeout();\n return undefined;\n }\n\n // Skip empty sequences — no point writing a zero-event row to sequencesToSend\n // (would later POST as an empty body and 400 on the server).\n if (currentSequenceData.events.length === 0) {\n this.maybeLogEmptyFiltered('storeCurrentSequence');\n cancelTimeout();\n return undefined;\n }\n\n const sequenceId = await tx.objectStore(sequencesToSendKey).put({\n sessionId,\n events: currentSequenceData.events,\n tabId: this.tabId,\n });\n\n await tx.objectStore(currentSequenceKey).put({\n sessionId,\n events: [],\n tabId: this.tabId,\n });\n\n this.recordSuccess();\n cancelTimeout();\n const { tabId: _tabId, ...rest } = currentSequenceData;\n return {\n ...rest,\n sessionId,\n sequenceId,\n };\n } catch (e) {\n if (!timedOut) {\n errorLogged = true;\n logIdbError(this.loggerProvider, `${STORAGE_FAILURE}: ${e as string}`, e);\n this.recordFailure();\n }\n }\n return undefined;\n };\n\n addEventToCurrentSequence = async (sessionId: number, event: string) => {\n let errorLogged = false;\n let timedOut = false;\n try {\n // Always open a readwrite transaction over both stores so that the read and\n // any subsequent write are atomic. IDB serializes readwrite transactions on\n // overlapping stores, so concurrent fire-and-forget callers (events-manager\n // does not await this method) are queued by the engine rather than interleaving\n // — eliminating the TOCTOU race that a narrow-read + separate-write approach\n // would introduce on the split path.\n const tx = this.db.transaction([currentSequenceKey, sequencesToSendKey], 'readwrite');\n // Attach a catch handler immediately so tx.done rejections (e.g. AbortError after\n // put succeeds but before auto-commit) are always handled without blocking.\n // The errorLogged / timedOut flags prevent double-logging when the outer catch\n // (or the timeout) already fired for the same transaction.\n tx.done.catch((e: unknown) => {\n if (!errorLogged && !timedOut) {\n logIdbError(this.loggerProvider, `${STORAGE_FAILURE}: ${e as string}`, e);\n this.recordFailure();\n }\n });\n // Stalled-transaction protection: see armTxDoneTimeout in getSequencesToSend.\n const cancelTimeout = armTxDoneTimeout(tx.done, TX_DONE_TIMEOUT_MS, () => {\n if (!errorLogged && !timedOut) {\n timedOut = true;\n logIdbError(this.loggerProvider, `${STORAGE_FAILURE}: transaction timed out`);\n this.recordFailure();\n }\n });\n const sequenceEvents = await tx.objectStore(currentSequenceKey).get(sessionId);\n\n // Foreign-tab record path: another tab owns the current-sequence slot for this\n // sessionId. Don't silently overwrite — that would drop the foreign tab's\n // in-progress events. Promote them to sequencesToSend (tabId kept for forensics)\n // before claiming the slot for ourselves. getSequencesToSend no longer filters\n // by tabId, so either tab may flush the promoted sequence; server deduplicates.\n if (sequenceEvents?.tabId && sequenceEvents.tabId !== this.tabId) {\n if (sequenceEvents.events.length > 0) {\n await tx.objectStore(sequencesToSendKey).put({\n sessionId,\n events: sequenceEvents.events,\n tabId: sequenceEvents.tabId,\n });\n }\n await tx.objectStore(currentSequenceKey).put({ sessionId, events: [event], tabId: this.tabId });\n this.recordSuccess();\n cancelTimeout();\n return undefined;\n }\n\n // ownedSequence is either undefined (no record yet) or this tab's record.\n const ownedSequence = sequenceEvents;\n\n if (!ownedSequence) {\n await tx.objectStore(currentSequenceKey).put({ sessionId, events: [event], tabId: this.tabId });\n this.recordSuccess();\n cancelTimeout();\n return undefined;\n }\n\n if (!this.shouldSplitEventsList(ownedSequence.events, event)) {\n await tx\n .objectStore(currentSequenceKey)\n .put({ sessionId, events: ownedSequence.events.concat(event), tabId: this.tabId });\n this.recordSuccess();\n cancelTimeout();\n return undefined;\n }\n\n // Split path: reset sessionCurrentSequence and write the old events to\n // sequencesToSend atomically within the same transaction.\n const eventsToSend = ownedSequence.events;\n\n // shouldSplitEventsList can return true with an empty buffer when a single\n // incoming event is larger than MAX_EVENT_LIST_SIZE (700 KB) — the size-constraint\n // branch fires regardless of current length. Don't write a zero-event row to\n // sequencesToSend (which would later POST as an empty body, the SR-4284 root\n // cause); just claim the slot for the new event without finalizing anything.\n // This is the *primary* root-cause filter site: warn here so post-deploy\n // Datadog can confirm the new SDK is actually preventing the bug at its source\n // (vs. only seeing leftover-state hits at the get/storeCurrentSequence layers).\n if (eventsToSend.length === 0) {\n this.maybeLogEmptyFiltered('addEventToCurrentSequence');\n await tx.objectStore(currentSequenceKey).put({ sessionId, events: [event], tabId: this.tabId });\n this.recordSuccess();\n cancelTimeout();\n return undefined;\n }\n\n await tx.objectStore(currentSequenceKey).put({ sessionId, events: [event], tabId: this.tabId });\n const sequenceId = await tx.objectStore(sequencesToSendKey).put({\n sessionId,\n events: eventsToSend,\n tabId: this.tabId,\n });\n\n this.recordSuccess();\n cancelTimeout();\n return {\n events: eventsToSend,\n sessionId,\n sequenceId,\n };\n } catch (e) {\n if (!timedOut) {\n errorLogged = true;\n logIdbError(this.loggerProvider, `${STORAGE_FAILURE}: ${e as string}`, e);\n this.recordFailure();\n }\n }\n return undefined;\n };\n\n storeSendingEvents = async (sessionId: number, events: Events) => {\n try {\n const sequenceId = await this.db.put<'sequencesToSend'>(sequencesToSendKey, {\n sessionId: sessionId,\n events: events,\n tabId: this.tabId,\n });\n this.recordSuccess();\n return sequenceId;\n } catch (e) {\n logIdbError(this.loggerProvider, `${STORAGE_FAILURE}: ${e as string}`, e);\n this.recordFailure();\n }\n return undefined;\n };\n\n cleanUpSessionEventsStore = async (_sessionId: number, sequenceId?: number) => {\n if (!sequenceId) {\n return;\n }\n try {\n await this.db.delete<'sequencesToSend'>(sequencesToSendKey, sequenceId);\n this.recordSuccess();\n } catch (e) {\n logIdbError(this.loggerProvider, `${STORAGE_FAILURE}: ${e as string}`, e);\n this.recordFailure();\n }\n };\n}\n"]}
@@ -4,8 +4,10 @@ export declare class InMemoryEventsStore extends BaseEventsStore<number> {
4
4
  private finalizedSequences;
5
5
  private sequences;
6
6
  private sequenceId;
7
+ private emptyFilteredCount;
7
8
  private resetCurrentSequence;
8
9
  private addSequence;
10
+ private maybeLogEmptyFiltered;
9
11
  getSequencesToSend(): Promise<SendingSequencesReturn<number>[] | undefined>;
10
12
  storeCurrentSequence(sessionId: string | number): Promise<SendingSequencesReturn<number> | undefined>;
11
13
  addEventToCurrentSequence(sessionId: number, event: string): Promise<SendingSequencesReturn<number> | undefined>;
@@ -1 +1 @@
1
- {"version":3,"file":"events-memory-store.d.ts","sourceRoot":"","sources":["../../../src/events/events-memory-store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AAC3E,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAEtD,qBAAa,mBAAoB,SAAQ,eAAe,CAAC,MAAM,CAAC;IAC9D,OAAO,CAAC,kBAAkB,CAAwE;IAClG,OAAO,CAAC,SAAS,CAAyC;IAC1D,OAAO,CAAC,UAAU,CAAK;IAEvB,OAAO,CAAC,oBAAoB;IAI5B,OAAO,CAAC,WAAW;IAQb,kBAAkB,IAAI,OAAO,CAAC,sBAAsB,CAAC,MAAM,CAAC,EAAE,GAAG,SAAS,CAAC;IAQ3E,oBAAoB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,sBAAsB,CAAC,MAAM,CAAC,GAAG,SAAS,CAAC;IAOrG,yBAAyB,CAC7B,SAAS,EAAE,MAAM,EACjB,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC,sBAAsB,CAAC,MAAM,CAAC,GAAG,SAAS,CAAC;IAehD,kBAAkB,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;IAMlF,yBAAyB,CAAC,UAAU,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAKxF"}
1
+ {"version":3,"file":"events-memory-store.d.ts","sourceRoot":"","sources":["../../../src/events/events-memory-store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AAC3E,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAEtD,qBAAa,mBAAoB,SAAQ,eAAe,CAAC,MAAM,CAAC;IAC9D,OAAO,CAAC,kBAAkB,CAAwE;IAClG,OAAO,CAAC,SAAS,CAAyC;IAC1D,OAAO,CAAC,UAAU,CAAK;IACvB,OAAO,CAAC,kBAAkB,CAAK;IAE/B,OAAO,CAAC,oBAAoB;IAI5B,OAAO,CAAC,WAAW;IAanB,OAAO,CAAC,qBAAqB;IAMvB,kBAAkB,IAAI,OAAO,CAAC,sBAAsB,CAAC,MAAM,CAAC,EAAE,GAAG,SAAS,CAAC;IAkB3E,oBAAoB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,sBAAsB,CAAC,MAAM,CAAC,GAAG,SAAS,CAAC;IAcrG,yBAAyB,CAC7B,SAAS,EAAE,MAAM,EACjB,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC,sBAAsB,CAAC,MAAM,CAAC,GAAG,SAAS,CAAC;IAyBhD,kBAAkB,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;IAMlF,yBAAyB,CAAC,UAAU,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAKxF"}
@@ -1,4 +1,4 @@
1
- import { __awaiter, __extends, __generator, __read, __spreadArray } from "tslib";
1
+ import { __awaiter, __extends, __generator, __read, __spreadArray, __values } from "tslib";
2
2
  import { BaseEventsStore } from './base-events-store';
3
3
  var InMemoryEventsStore = /** @class */ (function (_super) {
4
4
  __extends(InMemoryEventsStore, _super);
@@ -7,6 +7,7 @@ var InMemoryEventsStore = /** @class */ (function (_super) {
7
7
  _this.finalizedSequences = {};
8
8
  _this.sequences = {};
9
9
  _this.sequenceId = 0;
10
+ _this.emptyFilteredCount = 0;
10
11
  return _this;
11
12
  }
12
13
  InMemoryEventsStore.prototype.resetCurrentSequence = function (sessionId) {
@@ -19,24 +20,61 @@ var InMemoryEventsStore = /** @class */ (function (_super) {
19
20
  this.resetCurrentSequence(sessionId);
20
21
  return { sequenceId: sequenceId, events: events, sessionId: sessionId };
21
22
  };
23
+ // Sampled (1 in 100) debug log so we can observe whether the store-layer guards
24
+ // are actually catching cases that would otherwise hit the empty-body 400 path on
25
+ // the server. Logged at debug, not warn — this is operational telemetry for
26
+ // post-deploy verification, not a customer-actionable warning. Per-store-instance
27
+ // counter rather than Math.random keeps the first hit deterministic for tests.
28
+ InMemoryEventsStore.prototype.maybeLogEmptyFiltered = function (source) {
29
+ if (this.emptyFilteredCount++ % 100 === 0) {
30
+ this.loggerProvider.debug("Filtered empty session replay sequence at ".concat(source, " (in-memory store)"));
31
+ }
32
+ };
22
33
  InMemoryEventsStore.prototype.getSequencesToSend = function () {
23
34
  return __awaiter(this, void 0, void 0, function () {
24
- return __generator(this, function (_a) {
25
- return [2 /*return*/, Object.entries(this.finalizedSequences).map(function (_a) {
26
- var _b = __read(_a, 2), sequenceId = _b[0], _c = _b[1], sessionId = _c.sessionId, events = _c.events;
27
- return ({
28
- sequenceId: Number(sequenceId),
29
- sessionId: sessionId,
30
- events: events,
31
- });
32
- })];
35
+ var result, _a, _b, _c, sequenceId, _d, sessionId, events;
36
+ var e_1, _e;
37
+ return __generator(this, function (_f) {
38
+ result = [];
39
+ try {
40
+ for (_a = __values(Object.entries(this.finalizedSequences)), _b = _a.next(); !_b.done; _b = _a.next()) {
41
+ _c = __read(_b.value, 2), sequenceId = _c[0], _d = _c[1], sessionId = _d.sessionId, events = _d.events;
42
+ if (events.length === 0) {
43
+ // Prune in-place for consistency with the IDB store: by construction we
44
+ // never write empty sequences anymore, so any empty entry is unambiguously
45
+ // stale residue. Without the delete, every subsequent getSequencesToSend
46
+ // would re-iterate the empty entry and re-fire the sampled log, producing
47
+ // repeated noise that's indistinguishable from active bug occurrences.
48
+ this.maybeLogEmptyFiltered('getSequencesToSend');
49
+ delete this.finalizedSequences[Number(sequenceId)];
50
+ continue;
51
+ }
52
+ result.push({ sequenceId: Number(sequenceId), sessionId: sessionId, events: events });
53
+ }
54
+ }
55
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
56
+ finally {
57
+ try {
58
+ if (_b && !_b.done && (_e = _a.return)) _e.call(_a);
59
+ }
60
+ finally { if (e_1) throw e_1.error; }
61
+ }
62
+ return [2 /*return*/, result];
33
63
  });
34
64
  });
35
65
  };
36
66
  InMemoryEventsStore.prototype.storeCurrentSequence = function (sessionId) {
37
67
  return __awaiter(this, void 0, void 0, function () {
68
+ var buffered;
38
69
  return __generator(this, function (_a) {
39
- if (!this.sequences[sessionId]) {
70
+ buffered = this.sequences[sessionId];
71
+ if (!buffered) {
72
+ return [2 /*return*/, undefined];
73
+ }
74
+ if (buffered.length === 0) {
75
+ // Slot exists but is empty (e.g. drained by a prior storeCurrentSequence then
76
+ // re-flushed before any new event landed). Don't finalize a zero-event row.
77
+ this.maybeLogEmptyFiltered('storeCurrentSequence');
40
78
  return [2 /*return*/, undefined];
41
79
  }
42
80
  return [2 /*return*/, this.addSequence(sessionId)];
@@ -50,8 +88,19 @@ var InMemoryEventsStore = /** @class */ (function (_super) {
50
88
  if (!this.sequences[sessionId]) {
51
89
  this.resetCurrentSequence(sessionId);
52
90
  }
91
+ // shouldSplitEventsList can return true with an empty buffer when a single
92
+ // incoming event is larger than MAX_EVENT_LIST_SIZE (700 KB) — the size-constraint
93
+ // branch fires regardless of current length. Don't finalize a zero-event sequence
94
+ // (the SR-4284 root cause); just hold the incoming event in the buffer.
95
+ // shouldSplitEventsList's time-elapsed branch only fires when events.length > 0
96
+ // (see base-events-store.ts), so calling it on an empty buffer has no side effects.
53
97
  if (this.shouldSplitEventsList(this.sequences[sessionId], event)) {
54
- sequenceReturn = this.addSequence(sessionId);
98
+ if (this.sequences[sessionId].length === 0) {
99
+ this.maybeLogEmptyFiltered('addEventToCurrentSequence');
100
+ }
101
+ else {
102
+ sequenceReturn = this.addSequence(sessionId);
103
+ }
55
104
  }
56
105
  this.sequences[sessionId].push(event);
57
106
  return [2 /*return*/, sequenceReturn];
@@ -1 +1 @@
1
- {"version":3,"file":"events-memory-store.js","sourceRoot":"","sources":["../../../src/events/events-memory-store.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAEtD;IAAyC,uCAAuB;IAAhE;QAAA,qEA6DC;QA5DS,wBAAkB,GAAqE,EAAE,CAAC;QAC1F,eAAS,GAAsC,EAAE,CAAC;QAClD,gBAAU,GAAG,CAAC,CAAC;;IA0DzB,CAAC;IAxDS,kDAAoB,GAA5B,UAA6B,SAA0B;QACrD,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,GAAG,EAAE,CAAC;IACjC,CAAC;IAEO,yCAAW,GAAnB,UAAoB,SAA0B;QAC5C,IAAM,UAAU,GAAG,IAAI,CAAC,UAAU,EAAE,CAAC;QACrC,IAAM,MAAM,4BAAO,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,SAAC,CAAC;QAC9C,IAAI,CAAC,kBAAkB,CAAC,UAAU,CAAC,GAAG,EAAE,SAAS,WAAA,EAAE,MAAM,QAAA,EAAE,CAAC;QAC5D,IAAI,CAAC,oBAAoB,CAAC,SAAS,CAAC,CAAC;QACrC,OAAO,EAAE,UAAU,YAAA,EAAE,MAAM,QAAA,EAAE,SAAS,WAAA,EAAE,CAAC;IAC3C,CAAC;IAEK,gDAAkB,GAAxB;;;gBACE,sBAAO,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC,GAAG,CAAC,UAAC,EAAmC;4BAAnC,KAAA,aAAmC,EAAlC,UAAU,QAAA,EAAE,UAAqB,EAAnB,SAAS,eAAA,EAAE,MAAM,YAAA;wBAAQ,OAAA,CAAC;4BAC3F,UAAU,EAAE,MAAM,CAAC,UAAU,CAAC;4BAC9B,SAAS,WAAA;4BACT,MAAM,QAAA;yBACP,CAAC;oBAJ0F,CAI1F,CAAC,EAAC;;;KACL;IAEK,kDAAoB,GAA1B,UAA2B,SAA0B;;;gBACnD,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,EAAE;oBAC9B,sBAAO,SAAS,EAAC;iBAClB;gBACD,sBAAO,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,EAAC;;;KACpC;IAEK,uDAAyB,GAA/B,UACE,SAAiB,EACjB,KAAa;;;;gBAEb,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,EAAE;oBAC9B,IAAI,CAAC,oBAAoB,CAAC,SAAS,CAAC,CAAC;iBACtC;gBAGD,IAAI,IAAI,CAAC,qBAAqB,CAAC,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,EAAE,KAAK,CAAC,EAAE;oBAChE,cAAc,GAAG,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC;iBAC9C;gBAED,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;gBAEtC,sBAAO,cAAc,EAAC;;;KACvB;IAEK,gDAAkB,GAAxB,UAAyB,SAAiB,EAAE,MAAc;;;gBACxD,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,EAAE,SAAS,WAAA,EAAE,MAAM,QAAA,EAAE,CAAC;gBAEjE,sBAAO,IAAI,CAAC,UAAU,EAAE,EAAC;;;KAC1B;IAEK,uDAAyB,GAA/B,UAAgC,UAAkB,EAAE,UAAmB;;;gBACrE,IAAI,UAAU,KAAK,SAAS,EAAE;oBAC5B,OAAO,IAAI,CAAC,kBAAkB,CAAC,UAAU,CAAC,CAAC;iBAC5C;;;;KACF;IACH,0BAAC;AAAD,CAAC,AA7DD,CAAyC,eAAe,GA6DvD","sourcesContent":["import { Events, SendingSequencesReturn } from '../typings/session-replay';\nimport { BaseEventsStore } from './base-events-store';\n\nexport class InMemoryEventsStore extends BaseEventsStore<number> {\n private finalizedSequences: Record<number, { sessionId: string | number; events: string[] }> = {};\n private sequences: Record<string | number, string[]> = {};\n private sequenceId = 0;\n\n private resetCurrentSequence(sessionId: string | number) {\n this.sequences[sessionId] = [];\n }\n\n private addSequence(sessionId: string | number): SendingSequencesReturn<number> {\n const sequenceId = this.sequenceId++;\n const events = [...this.sequences[sessionId]];\n this.finalizedSequences[sequenceId] = { sessionId, events };\n this.resetCurrentSequence(sessionId);\n return { sequenceId, events, sessionId };\n }\n\n async getSequencesToSend(): Promise<SendingSequencesReturn<number>[] | undefined> {\n return Object.entries(this.finalizedSequences).map(([sequenceId, { sessionId, events }]) => ({\n sequenceId: Number(sequenceId),\n sessionId,\n events,\n }));\n }\n\n async storeCurrentSequence(sessionId: string | number): Promise<SendingSequencesReturn<number> | undefined> {\n if (!this.sequences[sessionId]) {\n return undefined;\n }\n return this.addSequence(sessionId);\n }\n\n async addEventToCurrentSequence(\n sessionId: number,\n event: string,\n ): Promise<SendingSequencesReturn<number> | undefined> {\n if (!this.sequences[sessionId]) {\n this.resetCurrentSequence(sessionId);\n }\n\n let sequenceReturn: SendingSequencesReturn<number> | undefined;\n if (this.shouldSplitEventsList(this.sequences[sessionId], event)) {\n sequenceReturn = this.addSequence(sessionId);\n }\n\n this.sequences[sessionId].push(event);\n\n return sequenceReturn;\n }\n\n async storeSendingEvents(sessionId: number, events: Events): Promise<number | undefined> {\n this.finalizedSequences[this.sequenceId] = { sessionId, events };\n\n return this.sequenceId++;\n }\n\n async cleanUpSessionEventsStore(_sessionId: number, sequenceId?: number): Promise<void> {\n if (sequenceId !== undefined) {\n delete this.finalizedSequences[sequenceId];\n }\n }\n}\n"]}
1
+ {"version":3,"file":"events-memory-store.js","sourceRoot":"","sources":["../../../src/events/events-memory-store.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAEtD;IAAyC,uCAAuB;IAAhE;QAAA,qEAoGC;QAnGS,wBAAkB,GAAqE,EAAE,CAAC;QAC1F,eAAS,GAAsC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A2B,CAAC,CAAC;qBACzD;yBAAM;wBACL,cAAc,GAAG,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC;qBAC9C;iBACF;gBAED,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;gBAEtC,sBAAO,cAAc,EAAC;;;KACvB;IAEK,gDAAkB,GAAxB,UAAyB,SAAiB,EAAE,MAAc;;;gBACxD,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,EAAE,SAAS,WAAA,EAAE,MAAM,QAAA,EAAE,CAAC;gBAEjE,sBAAO,IAAI,CAAC,UAAU,EAAE,EAAC;;;KAC1B;IAEK,uDAAyB,GAA/B,UAAgC,UAAkB,EAAE,UAAmB;;;gBACrE,IAAI,UAAU,KAAK,SAAS,EAAE;oBAC5B,OAAO,IAAI,CAAC,kBAAkB,CAAC,UAAU,CAAC,CAAC;iBAC5C;;;;KACF;IACH,0BAAC;AAAD,CAAC,AApGD,CAAyC,eAAe,GAoGvD","sourcesContent":["import { Events, SendingSequencesReturn } from '../typings/session-replay';\nimport { BaseEventsStore } from './base-events-store';\n\nexport class InMemoryEventsStore extends BaseEventsStore<number> {\n private finalizedSequences: Record<number, { sessionId: string | number; events: string[] }> = {};\n private sequences: Record<string | number, string[]> = {};\n private sequenceId = 0;\n private emptyFilteredCount = 0;\n\n private resetCurrentSequence(sessionId: string | number) {\n this.sequences[sessionId] = [];\n }\n\n private addSequence(sessionId: string | number): SendingSequencesReturn<number> {\n const sequenceId = this.sequenceId++;\n const events = [...this.sequences[sessionId]];\n this.finalizedSequences[sequenceId] = { sessionId, events };\n this.resetCurrentSequence(sessionId);\n return { sequenceId, events, sessionId };\n }\n\n // Sampled (1 in 100) debug log so we can observe whether the store-layer guards\n // are actually catching cases that would otherwise hit the empty-body 400 path on\n // the server. Logged at debug, not warn — this is operational telemetry for\n // post-deploy verification, not a customer-actionable warning. Per-store-instance\n // counter rather than Math.random keeps the first hit deterministic for tests.\n private maybeLogEmptyFiltered(source: string) {\n if (this.emptyFilteredCount++ % 100 === 0) {\n this.loggerProvider.debug(`Filtered empty session replay sequence at ${source} (in-memory store)`);\n }\n }\n\n async getSequencesToSend(): Promise<SendingSequencesReturn<number>[] | undefined> {\n const result: SendingSequencesReturn<number>[] = [];\n for (const [sequenceId, { sessionId, events }] of Object.entries(this.finalizedSequences)) {\n if (events.length === 0) {\n // Prune in-place for consistency with the IDB store: by construction we\n // never write empty sequences anymore, so any empty entry is unambiguously\n // stale residue. Without the delete, every subsequent getSequencesToSend\n // would re-iterate the empty entry and re-fire the sampled log, producing\n // repeated noise that's indistinguishable from active bug occurrences.\n this.maybeLogEmptyFiltered('getSequencesToSend');\n delete this.finalizedSequences[Number(sequenceId)];\n continue;\n }\n result.push({ sequenceId: Number(sequenceId), sessionId, events });\n }\n return result;\n }\n\n async storeCurrentSequence(sessionId: string | number): Promise<SendingSequencesReturn<number> | undefined> {\n const buffered = this.sequences[sessionId];\n if (!buffered) {\n return undefined;\n }\n if (buffered.length === 0) {\n // Slot exists but is empty (e.g. drained by a prior storeCurrentSequence then\n // re-flushed before any new event landed). Don't finalize a zero-event row.\n this.maybeLogEmptyFiltered('storeCurrentSequence');\n return undefined;\n }\n return this.addSequence(sessionId);\n }\n\n async addEventToCurrentSequence(\n sessionId: number,\n event: string,\n ): Promise<SendingSequencesReturn<number> | undefined> {\n if (!this.sequences[sessionId]) {\n this.resetCurrentSequence(sessionId);\n }\n\n let sequenceReturn: SendingSequencesReturn<number> | undefined;\n // shouldSplitEventsList can return true with an empty buffer when a single\n // incoming event is larger than MAX_EVENT_LIST_SIZE (700 KB) — the size-constraint\n // branch fires regardless of current length. Don't finalize a zero-event sequence\n // (the SR-4284 root cause); just hold the incoming event in the buffer.\n // shouldSplitEventsList's time-elapsed branch only fires when events.length > 0\n // (see base-events-store.ts), so calling it on an empty buffer has no side effects.\n if (this.shouldSplitEventsList(this.sequences[sessionId], event)) {\n if (this.sequences[sessionId].length === 0) {\n this.maybeLogEmptyFiltered('addEventToCurrentSequence');\n } else {\n sequenceReturn = this.addSequence(sessionId);\n }\n }\n\n this.sequences[sessionId].push(event);\n\n return sequenceReturn;\n }\n\n async storeSendingEvents(sessionId: number, events: Events): Promise<number | undefined> {\n this.finalizedSequences[this.sequenceId] = { sessionId, events };\n\n return this.sequenceId++;\n }\n\n async cleanUpSessionEventsStore(_sessionId: number, sequenceId?: number): Promise<void> {\n if (sequenceId !== undefined) {\n delete this.finalizedSequences[sequenceId];\n }\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"session-replay.d.ts","sourceRoot":"","sources":["../../src/session-replay.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,OAAO,EASR,MAAM,2BAA2B,CAAC;AAKnC,OAAO,EACL,aAAa,EACb,yBAAyB,EACzB,kCAAkC,EAInC,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAEL,gBAAgB,EASjB,MAAM,aAAa,CAAC;AAWrB,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,EAAuB,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AAavF,OAAO,EACL,sBAAsB,EACtB,0BAA0B,IAAI,mCAAmC,EAIjE,kBAAkB,IAAI,mBAAmB,EACzC,oBAAoB,EACpB,2BAA2B,EAC5B,MAAM,0BAA0B,CAAC;AAOlC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAGpD,KAAK,WAAW,GAAG,CAAC,CAAC,EAAE,mBAAmB,GAAG,KAAK,KAAK,IAAI,CAAC;AAE5D,qBAAa,aAAc,YAAW,sBAAsB;IAC1D,IAAI,SAAuC;IAC3C,MAAM,EAAE,yBAAyB,GAAG,SAAS,CAAC;IAC9C,qBAAqB,EAAE,kCAAkC,GAAG,SAAS,CAAC;IACtE,WAAW,EAAE,mBAAmB,GAAG,SAAS,CAAC;IAC7C,aAAa,CAAC,EAAE,mCAAmC,CAAC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A2B,mGA6F5C;IAEF,UAAU,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM;IAoDhC,UAAU,CAAC,sBAAsB,UAAQ;IAgB/C,YAAY;IAUZ,eAAe;IA+Df,iBAAiB,IAAI,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS;IAWlD,oBAAoB,IAAI,MAAM,GAAG,SAAS;IAgCpC,mBAAmB,CAAC,aAAa,EAAE,aAAa,GAAG,SAAS;YAyCpD,iBAAiB;IAezB,YAAY,CAAC,iBAAiB,UAAO;YAmB7B,aAAa;IA2H3B,OAAO,CAAC,uBAAuB;IAuD/B,OAAO,CAAC,wBAAwB;IAkChC,mBAAmB,cACN,gBAAgB;;kDAmC3B;IAEF,mBAAmB,aAgBjB;IAEF,WAAW;IAIX,YAAY;IAIN,KAAK,CAAC,QAAQ,UAAQ;IAS5B,QAAQ;IASR,OAAO,CAAC,UAAU;IAYlB,OAAO,CAAC,WAAW;YAyBL,0BAA0B;CAUzC"}
@@ -314,13 +314,13 @@ var SessionReplay = /** @class */ (function () {
314
314
  return currentUrl != null ? { url: currentUrl } : undefined;
315
315
  };
316
316
  SessionReplay.prototype._init = function (apiKey, options) {
317
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
317
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
318
318
  return __awaiter(this, void 0, void 0, function () {
319
- var now, _o, _p, joinedConfig, localConfig, remoteConfig, scrollWatcher, managers, storeType, compressionWorkerScript, trackDestinationWorkerScript, globalScope, _q, compressionScript, trackDestinationScript, rrwebEventManager, error_1, typedError, payloadBatcher, interactionEventManager, error_2, typedError, pending_2, pending_1, pending_1_1, _r, event_1, sessionId, messenger, needsUrlTracking;
320
- var e_2, _s;
319
+ var now, _q, _r, joinedConfig, localConfig, remoteConfig, scrollWatcher, managers, storeType, compressionWorkerScript, trackDestinationWorkerScript, globalScope, _s, compressionScript, trackDestinationScript, rrwebEventManager, error_1, typedError, payloadBatcher, interactionEventManager, error_2, typedError, pending_2, pending_1, pending_1_1, _t, event_1, sessionId, messenger, needsUrlTracking;
320
+ var e_2, _u;
321
321
  var _this = this;
322
- return __generator(this, function (_t) {
323
- switch (_t.label) {
322
+ return __generator(this, function (_v) {
323
+ switch (_v.label) {
324
324
  case 0:
325
325
  // Re-init should always tear down any previous URL-change subscription, even when the
326
326
  // next config has no targeting config and we don't subscribe again.
@@ -336,13 +336,13 @@ var SessionReplay = /** @class */ (function () {
336
336
  options.sessionId !== undefined
337
337
  ? (_b = getOrInitReplayStartTime(apiKey, options.sessionId, now, this.loggerProvider)) !== null && _b !== void 0 ? _b : now
338
338
  : now;
339
- _o = this;
339
+ _q = this;
340
340
  return [4 /*yield*/, createSessionReplayJoinedConfigGenerator(apiKey, options)];
341
341
  case 1:
342
- _o.joinedConfigGenerator = _t.sent();
342
+ _q.joinedConfigGenerator = _v.sent();
343
343
  return [4 /*yield*/, this.joinedConfigGenerator.generateJoinedConfig()];
344
344
  case 2:
345
- _p = _t.sent(), joinedConfig = _p.joinedConfig, localConfig = _p.localConfig, remoteConfig = _p.remoteConfig;
345
+ _r = _v.sent(), joinedConfig = _r.joinedConfig, localConfig = _r.localConfig, remoteConfig = _r.remoteConfig;
346
346
  this.config = joinedConfig;
347
347
  this.setMetadata(options.sessionId, joinedConfig, localConfig, remoteConfig, (_c = options.version) === null || _c === void 0 ? void 0 : _c.version, VERSION, (_d = options.version) === null || _d === void 0 ? void 0 : _d.type);
348
348
  this.pageLeaveFns = [];
@@ -366,50 +366,52 @@ var SessionReplay = /** @class */ (function () {
366
366
  if (!(this.config.useWebWorker && globalScope && globalScope.Worker)) return [3 /*break*/, 4];
367
367
  return [4 /*yield*/, import('./worker')];
368
368
  case 3:
369
- _q = _t.sent(), compressionScript = _q.compressionScript, trackDestinationScript = _q.trackDestinationScript;
369
+ _s = _v.sent(), compressionScript = _s.compressionScript, trackDestinationScript = _s.trackDestinationScript;
370
370
  compressionWorkerScript = compressionScript;
371
371
  trackDestinationWorkerScript = trackDestinationScript;
372
- _t.label = 4;
372
+ _v.label = 4;
373
373
  case 4:
374
- _t.trys.push([4, 6, , 7]);
374
+ _v.trys.push([4, 6, , 7]);
375
375
  return [4 /*yield*/, createEventsManager({
376
376
  config: this.config,
377
377
  type: 'replay',
378
+ minInterval: (_g = this.config.flushIntervalConfig) === null || _g === void 0 ? void 0 : _g.minIntervalMs,
379
+ maxInterval: (_h = this.config.flushIntervalConfig) === null || _h === void 0 ? void 0 : _h.maxIntervalMs,
378
380
  storeType: storeType,
379
381
  trackDestinationWorkerScript: trackDestinationWorkerScript,
380
382
  shouldSend: function () { return !_this.isBelowMinSessionDuration(); },
381
383
  })];
382
384
  case 5:
383
- rrwebEventManager = _t.sent();
385
+ rrwebEventManager = _v.sent();
384
386
  this.rrwebEventManager = rrwebEventManager;
385
387
  managers.push({ name: 'replay', manager: rrwebEventManager });
386
388
  return [3 /*break*/, 7];
387
389
  case 6:
388
- error_1 = _t.sent();
390
+ error_1 = _v.sent();
389
391
  typedError = error_1;
390
392
  this.loggerProvider.warn("Error occurred while creating replay events manager: ".concat(typedError.toString()));
391
393
  return [3 /*break*/, 7];
392
394
  case 7:
393
- if (!((_g = this.config.interactionConfig) === null || _g === void 0 ? void 0 : _g.enabled)) return [3 /*break*/, 11];
395
+ if (!((_j = this.config.interactionConfig) === null || _j === void 0 ? void 0 : _j.enabled)) return [3 /*break*/, 11];
394
396
  payloadBatcher = this.config.interactionConfig.batch ? clickBatcher : clickNonBatcher;
395
- _t.label = 8;
397
+ _v.label = 8;
396
398
  case 8:
397
- _t.trys.push([8, 10, , 11]);
399
+ _v.trys.push([8, 10, , 11]);
398
400
  return [4 /*yield*/, createEventsManager({
399
401
  config: this.config,
400
402
  type: 'interaction',
401
- minInterval: (_h = this.config.interactionConfig.trackEveryNms) !== null && _h !== void 0 ? _h : INTERACTION_MIN_INTERVAL,
403
+ minInterval: (_k = this.config.interactionConfig.trackEveryNms) !== null && _k !== void 0 ? _k : INTERACTION_MIN_INTERVAL,
402
404
  maxInterval: INTERACTION_MAX_INTERVAL,
403
405
  payloadBatcher: payloadBatcher,
404
406
  storeType: storeType,
405
407
  trackDestinationWorkerScript: trackDestinationWorkerScript,
406
408
  })];
407
409
  case 9:
408
- interactionEventManager = _t.sent();
410
+ interactionEventManager = _v.sent();
409
411
  managers.push({ name: 'interaction', manager: interactionEventManager });
410
412
  return [3 /*break*/, 11];
411
413
  case 10:
412
- error_2 = _t.sent();
414
+ error_2 = _v.sent();
413
415
  typedError = error_2;
414
416
  this.loggerProvider.warn("Error occurred while creating interaction events manager: ".concat(typedError.toString()));
415
417
  return [3 /*break*/, 11];
@@ -426,14 +428,14 @@ var SessionReplay = /** @class */ (function () {
426
428
  pending_2 = this.pendingEmitEvents.splice(0);
427
429
  try {
428
430
  for (pending_1 = __values(pending_2), pending_1_1 = pending_1.next(); !pending_1_1.done; pending_1_1 = pending_1.next()) {
429
- _r = pending_1_1.value, event_1 = _r.event, sessionId = _r.sessionId;
431
+ _t = pending_1_1.value, event_1 = _t.event, sessionId = _t.sessionId;
430
432
  this.eventCompressor.enqueueEvent(event_1, sessionId);
431
433
  }
432
434
  }
433
435
  catch (e_2_1) { e_2 = { error: e_2_1 }; }
434
436
  finally {
435
437
  try {
436
- if (pending_1_1 && !pending_1_1.done && (_s = pending_1.return)) _s.call(pending_1);
438
+ if (pending_1_1 && !pending_1_1.done && (_u = pending_1.return)) _u.call(pending_1);
437
439
  }
438
440
  finally { if (e_2) throw e_2.error; }
439
441
  }
@@ -470,11 +472,11 @@ var SessionReplay = /** @class */ (function () {
470
472
  ], false);
471
473
  return [4 /*yield*/, this.initializeNetworkObservers()];
472
474
  case 12:
473
- _t.sent();
475
+ _v.sent();
474
476
  // Enable background capture when this page is opened by the Amplitude app
475
477
  // (window.opener exists). Uses the shared messenger singleton so that if
476
478
  // autocapture is also loaded, both share a single messenger and script load.
477
- if ((_j = getGlobalScope()) === null || _j === void 0 ? void 0 : _j.opener) {
479
+ if ((_l = getGlobalScope()) === null || _l === void 0 ? void 0 : _l.opener) {
478
480
  messenger = getOrCreateWindowMessenger();
479
481
  enableBackgroundCapture(messenger);
480
482
  messenger.setup(__assign({ logger: this.loggerProvider }, (this.config.serverZone && { endpoint: AMPLITUDE_ORIGINS_MAP[this.config.serverZone] })));
@@ -483,8 +485,8 @@ var SessionReplay = /** @class */ (function () {
483
485
  this.teardownEventListeners(false);
484
486
  return [4 /*yield*/, this.evaluateTargetingAndCapture({ userProperties: options.userProperties, page: this.getCurrentPageForTargeting() }, true)];
485
487
  case 13:
486
- _t.sent();
487
- needsUrlTracking = this.config.targetingConfig || ((_m = (_l = (_k = this.config.privacyConfig) === null || _k === void 0 ? void 0 : _k.urlMaskLevels) === null || _l === void 0 ? void 0 : _l.length) !== null && _m !== void 0 ? _m : 0) > 0;
488
+ _v.sent();
489
+ needsUrlTracking = this.config.targetingConfig || ((_p = (_o = (_m = this.config.privacyConfig) === null || _m === void 0 ? void 0 : _m.urlMaskLevels) === null || _o === void 0 ? void 0 : _o.length) !== null && _p !== void 0 ? _p : 0) > 0;
488
490
  if (needsUrlTracking) {
489
491
  this.setupUrlChangeListener();
490
492
  }