@sprig-technologies/sprig-browser 2.41.2 → 2.42.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.
package/dist/replay.js CHANGED
@@ -1,96 +1,96 @@
1
- var it = Object.defineProperty;
2
- var dt = (e, t, n) => t in e ? it(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
3
- var F = (e, t, n) => dt(e, typeof t != "symbol" ? t + "" : t, n);
4
- import { b as d, s as Q, a as m, v as X, c as ct, g as lt, P as ke, r as Ue, d as ut, e as V, S as Y, f as pt } from "./metricsReporter-CJIq-5XV.js";
5
- import { d as gt } from "./debounce-CMb8f7wh.js";
1
+ var lt = Object.defineProperty;
2
+ var ct = (e, t, a) => t in e ? lt(e, t, { enumerable: !0, configurable: !0, writable: !0, value: a }) : e[t] = a;
3
+ var F = (e, t, a) => ct(e, typeof t != "symbol" ? t + "" : t, a);
4
+ import { b as d, s as Q, a as m, v as X, c as ut, g as pt, P as xe, r as Be, d as gt, e as V, S as Y, f as mt } from "./metricsReporter-DbRyYFfD.js";
5
+ import { d as yt } from "./debounce-CMb8f7wh.js";
6
6
  var B = ((e) => (e[e.DomContentLoaded = 0] = "DomContentLoaded", e[e.Load = 1] = "Load", e[e.FullSnapshot = 2] = "FullSnapshot", e[e.IncrementalSnapshot = 3] = "IncrementalSnapshot", e[e.Meta = 4] = "Meta", e[e.Custom = 5] = "Custom", e[e.Plugin = 6] = "Plugin", e))(B || {}), k = ((e) => (e[e.Mutation = 0] = "Mutation", e[e.MouseMove = 1] = "MouseMove", e[e.MouseInteraction = 2] = "MouseInteraction", e[e.Scroll = 3] = "Scroll", e[e.ViewportResize = 4] = "ViewportResize", e[e.Input = 5] = "Input", e[e.TouchMove = 6] = "TouchMove", e[e.MediaInteraction = 7] = "MediaInteraction", e[e.StyleSheetRule = 8] = "StyleSheetRule", e[e.CanvasMutation = 9] = "CanvasMutation", e[e.Font = 10] = "Font", e[e.Log = 11] = "Log", e[e.Drag = 12] = "Drag", e[e.StyleDeclaration = 13] = "StyleDeclaration", e[e.Selection = 14] = "Selection", e[e.AdoptedStyleSheet = 15] = "AdoptedStyleSheet", e[e.CustomElement = 16] = "CustomElement", e))(k || {});
7
- const re = (e, t) => t.some((n) => e instanceof n);
8
- let Se, De;
9
- const oe = /* @__PURE__ */ new WeakMap(), Z = /* @__PURE__ */ new WeakMap(), K = /* @__PURE__ */ new WeakMap();
10
- let se = { get(e, t, n) {
7
+ const re = (e, t) => t.some((a) => e instanceof a);
8
+ let Se, be;
9
+ const se = /* @__PURE__ */ new WeakMap(), Z = /* @__PURE__ */ new WeakMap(), K = /* @__PURE__ */ new WeakMap();
10
+ let oe = { get(e, t, a) {
11
11
  if (e instanceof IDBTransaction) {
12
- if (t === "done") return oe.get(e);
13
- if (t === "store") return n.objectStoreNames[1] ? void 0 : n.objectStore(n.objectStoreNames[0]);
12
+ if (t === "done") return se.get(e);
13
+ if (t === "store") return a.objectStoreNames[1] ? void 0 : a.objectStore(a.objectStoreNames[0]);
14
14
  }
15
15
  return M(e[t]);
16
- }, set: (e, t, n) => (e[t] = n, !0), has: (e, t) => e instanceof IDBTransaction && (t === "done" || t === "store") || t in e };
17
- function xe(e) {
18
- se = e(se);
16
+ }, set: (e, t, a) => (e[t] = a, !0), has: (e, t) => e instanceof IDBTransaction && (t === "done" || t === "store") || t in e };
17
+ function Me(e) {
18
+ oe = e(oe);
19
19
  }
20
- function mt(e) {
21
- return (De || (De = [IDBCursor.prototype.advance, IDBCursor.prototype.continue, IDBCursor.prototype.continuePrimaryKey])).includes(e) ? function(...t) {
20
+ function wt(e) {
21
+ return (be || (be = [IDBCursor.prototype.advance, IDBCursor.prototype.continue, IDBCursor.prototype.continuePrimaryKey])).includes(e) ? function(...t) {
22
22
  return e.apply(ie(this), t), M(this.request);
23
23
  } : function(...t) {
24
24
  return M(e.apply(ie(this), t));
25
25
  };
26
26
  }
27
- function wt(e) {
28
- return typeof e == "function" ? mt(e) : (e instanceof IDBTransaction && function(t) {
29
- if (oe.has(t)) return;
30
- const n = new Promise((a, r) => {
31
- const o = () => {
27
+ function ft(e) {
28
+ return typeof e == "function" ? wt(e) : (e instanceof IDBTransaction && function(t) {
29
+ if (se.has(t)) return;
30
+ const a = new Promise((n, r) => {
31
+ const s = () => {
32
32
  r(t.error || new DOMException("AbortError", "AbortError"));
33
33
  };
34
34
  t.oncomplete = () => {
35
- a();
36
- }, t.onerror = o, t.onabort = o;
35
+ n();
36
+ }, t.onerror = s, t.onabort = s;
37
37
  });
38
- oe.set(t, n);
39
- }(e), re(e, Se || (Se = [IDBDatabase, IDBObjectStore, IDBIndex, IDBCursor, IDBTransaction])) ? new Proxy(e, se) : e);
38
+ se.set(t, a);
39
+ }(e), re(e, Se || (Se = [IDBDatabase, IDBObjectStore, IDBIndex, IDBCursor, IDBTransaction])) ? new Proxy(e, oe) : e);
40
40
  }
41
41
  function M(e) {
42
- if (e instanceof IDBRequest) return function(n) {
43
- const a = new Promise((r, o) => {
44
- n.onsuccess = () => {
45
- r(M(n.result));
46
- }, n.onerror = () => {
47
- o(n.error);
42
+ if (e instanceof IDBRequest) return function(a) {
43
+ const n = new Promise((r, s) => {
44
+ a.onsuccess = () => {
45
+ r(M(a.result));
46
+ }, a.onerror = () => {
47
+ s(a.error);
48
48
  };
49
49
  });
50
- return K.set(a, n), a;
50
+ return K.set(n, a), n;
51
51
  }(e);
52
52
  if (Z.has(e)) return Z.get(e);
53
- const t = wt(e);
53
+ const t = ft(e);
54
54
  return t !== e && (Z.set(e, t), K.set(t, e)), t;
55
55
  }
56
56
  const ie = (e) => K.get(e);
57
57
  function de(e, { blocked: t } = {}) {
58
- const n = indexedDB.deleteDatabase(e);
59
- return t && (n.onblocked = (a) => t(a.oldVersion, a)), M(n).then(() => {
58
+ const a = indexedDB.deleteDatabase(e);
59
+ return t && (a.onblocked = (n) => t(n.oldVersion, n)), M(a).then(() => {
60
60
  });
61
61
  }
62
- const yt = ["get", "getKey", "getAll", "getAllKeys", "count"], ft = ["put", "add", "delete", "clear"], ee = /* @__PURE__ */ new Map();
63
- function be(e, t) {
62
+ const ht = ["get", "getKey", "getAll", "getAllKeys", "count"], It = ["put", "add", "delete", "clear"], ee = /* @__PURE__ */ new Map();
63
+ function De(e, t) {
64
64
  if (!(e instanceof IDBDatabase) || t in e || typeof t != "string") return;
65
65
  if (ee.get(t)) return ee.get(t);
66
- const n = t.replace(/FromIndex$/, ""), a = t !== n, r = ft.includes(n);
67
- if (!(n in (a ? IDBIndex : IDBObjectStore).prototype) || !r && !yt.includes(n)) return;
68
- const o = async function(s, ...c) {
69
- const i = this.transaction(s, r ? "readwrite" : "readonly");
70
- let l = i.store;
71
- return a && (l = l.index(c.shift())), (await Promise.all([l[n](...c), r && i.done]))[0];
66
+ const a = t.replace(/FromIndex$/, ""), n = t !== a, r = It.includes(a);
67
+ if (!(a in (n ? IDBIndex : IDBObjectStore).prototype) || !r && !ht.includes(a)) return;
68
+ const s = async function(o, ...l) {
69
+ const i = this.transaction(o, r ? "readwrite" : "readonly");
70
+ let c = i.store;
71
+ return n && (c = c.index(l.shift())), (await Promise.all([c[a](...l), r && i.done]))[0];
72
72
  };
73
- return ee.set(t, o), o;
73
+ return ee.set(t, s), s;
74
74
  }
75
- xe((e) => ({ ...e, get: (t, n, a) => be(t, n) || e.get(t, n, a), has: (t, n) => !!be(t, n) || e.has(t, n) }));
76
- const ht = ["continue", "continuePrimaryKey", "advance"], Ee = {}, ce = /* @__PURE__ */ new WeakMap(), Be = /* @__PURE__ */ new WeakMap(), It = { get(e, t) {
77
- if (!ht.includes(t)) return e[t];
78
- let n = Ee[t];
79
- return n || (n = Ee[t] = function(...a) {
80
- ce.set(this, Be.get(this)[t](...a));
81
- }), n;
75
+ Me((e) => ({ ...e, get: (t, a, n) => De(t, a) || e.get(t, a, n), has: (t, a) => !!De(t, a) || e.has(t, a) }));
76
+ const vt = ["continue", "continuePrimaryKey", "advance"], Te = {}, le = /* @__PURE__ */ new WeakMap(), _e = /* @__PURE__ */ new WeakMap(), St = { get(e, t) {
77
+ if (!vt.includes(t)) return e[t];
78
+ let a = Te[t];
79
+ return a || (a = Te[t] = function(...n) {
80
+ le.set(this, _e.get(this)[t](...n));
81
+ }), a;
82
82
  } };
83
- async function* vt(...e) {
83
+ async function* bt(...e) {
84
84
  let t = this;
85
85
  if (t instanceof IDBCursor || (t = await t.openCursor(...e)), !t) return;
86
- const n = new Proxy(t, It);
87
- for (Be.set(n, t), K.set(n, ie(t)); t; ) yield n, t = await (ce.get(n) || t.continue()), ce.delete(n);
86
+ const a = new Proxy(t, St);
87
+ for (_e.set(a, t), K.set(a, ie(t)); t; ) yield a, t = await (le.get(a) || t.continue()), le.delete(a);
88
88
  }
89
- function Re(e, t) {
89
+ function Ee(e, t) {
90
90
  return t === Symbol.asyncIterator && re(e, [IDBIndex, IDBObjectStore, IDBCursor]) || t === "iterate" && re(e, [IDBIndex, IDBObjectStore]);
91
91
  }
92
- xe((e) => ({ ...e, get: (t, n, a) => Re(t, n) ? vt : e.get(t, n, a), has: (t, n) => Re(t, n) || e.has(t, n) }));
93
- const St = "sprigReplayIframeLoaded", Dt = "sprigReplayIframeSettings", bt = "sprigReplayIframeTakeFullSnapshot", Et = "sprigReplayTeardown", fe = [], Me = new class {
92
+ Me((e) => ({ ...e, get: (t, a, n) => Ee(t, a) ? bt : e.get(t, a, n), has: (t, a) => Ee(t, a) || e.has(t, a) }));
93
+ const Dt = "sprigReplayIframeLoaded", Tt = "sprigReplayIframeSettings", Et = "sprigReplayIframeTakeFullSnapshot", Rt = "sprigReplayTeardown", fe = [], Ae = new class {
94
94
  constructor(e) {
95
95
  F(this, "awaitingResolvers", []);
96
96
  F(this, "activeCount", 0);
@@ -116,160 +116,161 @@ const St = "sprigReplayIframeLoaded", Dt = "sprigReplayIframeSettings", bt = "sp
116
116
  setLimit(e) {
117
117
  this.capacity = e;
118
118
  }
119
- }(2), _e = async ({ apiUrl: e, surveyId: t, uploadId: n, etags: a, headers: r, responseGroupUuid: o, replayDuration: s, eventDigest: c }, i = !1) => {
120
- var y;
121
- if (!i && !n && !a) return void d.error("UploadErr", { isMobile: i, uploadId: n, etags: a });
119
+ }(2), Ne = async ({ apiUrl: e, surveyId: t, uploadId: a, etags: n, headers: r, responseGroupUuid: s, replayDuration: o, eventDigest: l }, i = !1) => {
120
+ var w;
121
+ if (!i && !a && !n) return void d.error("UploadErr", { isMobile: i, uploadId: a, etags: n });
122
122
  d.info("MarkUploadComplete", { surveyId: t });
123
- const l = await Q(`${e}/sdk/1/completeSessionReplay`, { method: "POST", body: JSON.stringify({ etags: a, uploadId: n, responseGroupUuid: o, surveyId: t, replayDuration: s, eventDigest: c, userAgent: (y = window == null ? void 0 : window.navigator) == null ? void 0 : y.userAgent }), headers: r, shouldRetryRequest: !0 });
124
- return d.info("MarkUploadDone", { surveyId: t }), l;
125
- }, Rt = (e) => {
123
+ const c = await Q(`${e}/sdk/1/completeSessionReplay`, { method: "POST", body: JSON.stringify({ etags: n, uploadId: a, responseGroupUuid: s, surveyId: t, replayDuration: o, eventDigest: l, userAgent: (w = window == null ? void 0 : window.navigator) == null ? void 0 : w.userAgent }), headers: r, shouldRetryRequest: !0 });
124
+ return d.info("MarkUploadDone", { surveyId: t }), c;
125
+ }, Ct = (e) => {
126
126
  if (e instanceof Attr) return null;
127
127
  let t = 1;
128
- for (let n = e.previousSibling; n; n = n.previousSibling) n.nodeName === e.nodeName && ++t;
128
+ for (let a = e.previousSibling; a; a = a.previousSibling) a.nodeName === e.nodeName && ++t;
129
129
  return t;
130
- }, Ae = (e) => {
130
+ }, Le = (e) => {
131
131
  if (e === null) return "";
132
132
  const t = [];
133
133
  if (e instanceof Document) return "/";
134
- for (let n = e; n && !(n instanceof Document) && n !== null; n = n instanceof Attr ? n.ownerElement : n.parentElement) {
135
- const a = t[t.length] = { name: void 0, position: null };
136
- switch (n.nodeType) {
134
+ for (let a = e; a && !(a instanceof Document) && a !== null; a = a instanceof Attr ? a.ownerElement : a.parentElement) {
135
+ const n = t[t.length] = { name: void 0, position: null };
136
+ switch (a.nodeType) {
137
137
  case Node.TEXT_NODE:
138
- a.name = "text()";
138
+ n.name = "text()";
139
139
  break;
140
140
  case Node.ATTRIBUTE_NODE:
141
- a.name = "@" + n.nodeName;
141
+ n.name = "@" + a.nodeName;
142
142
  break;
143
143
  case Node.PROCESSING_INSTRUCTION_NODE:
144
- a.name = "processing-instruction()";
144
+ n.name = "processing-instruction()";
145
145
  break;
146
146
  case Node.COMMENT_NODE:
147
- a.name = "comment()";
147
+ n.name = "comment()";
148
148
  break;
149
149
  case Node.ELEMENT_NODE:
150
- a.name = n.nodeName;
150
+ n.name = a.nodeName;
151
151
  }
152
- a.position = Rt(n);
152
+ n.position = Ct(a);
153
153
  }
154
- return "/" + t.reverse().map((n) => n.position !== null ? `/${n.name}[${n.position}]` : `/${n.name}`).join("");
155
- }, he = (e) => e && e.trim().substring(0, 500).replace(/\s\s+/g, " ").replace(/\r?\n|\r/g, " ").substring(0, 250), C = { capture: !0, passive: !0 }, Ct = ["a", "button", "input", "option", "li", "link"], Pt = ["Escape", "Enter", "Backspace", "F5", "Tab"];
156
- let J = !1, b = null, G = null;
157
- const Ce = (e) => {
158
- var n;
159
- if (((n = e.tagName) == null ? void 0 : n.toLowerCase()) === "html") return { element: "html" };
154
+ return "/" + t.reverse().map((a) => a.position !== null ? `/${a.name}[${a.position}]` : `/${a.name}`).join("");
155
+ }, he = (e) => e && e.trim().substring(0, 500).replace(/\s\s+/g, " ").replace(/\r?\n|\r/g, " ").substring(0, 250), R = { capture: !0, passive: !0 }, Pt = ["a", "button", "input", "option", "li", "link"], kt = ["Escape", "Enter", "Backspace", "F5", "Tab"];
156
+ let J = !1, D = null, G = null;
157
+ const Re = (e) => {
158
+ var a;
159
+ if (((a = e.tagName) == null ? void 0 : a.toLowerCase()) === "html") return { element: "html" };
160
160
  const t = {};
161
- return t.element = ((a) => {
162
- if (!a.tagName) return "No tagName";
163
- const r = a.getAttribute("type");
164
- return r ? `${r} ${a.tagName.toLowerCase()}` : a.tagName.toLowerCase();
161
+ return t.element = ((n) => {
162
+ if (!n.tagName) return "No tagName";
163
+ const r = n.getAttribute("type");
164
+ return r ? `${r} ${n.tagName.toLowerCase()}` : n.tagName.toLowerCase();
165
165
  })(e), t;
166
- }, Tt = (e) => {
167
- var a;
166
+ }, Ut = (e) => {
167
+ var n;
168
168
  if (!e) return {};
169
- const t = { ...Ce(e) }, n = e.parentElement;
170
- if (n && Ct.includes((a = n.tagName) == null ? void 0 : a.toLowerCase())) {
171
- const r = Ce(n);
169
+ const t = { ...Re(e) }, a = e.parentElement;
170
+ if (a && Pt.includes((n = a.tagName) == null ? void 0 : n.toLowerCase())) {
171
+ const r = Re(a);
172
172
  Object.assign(t, r);
173
173
  }
174
174
  return t;
175
- }, Ne = (e, t) => {
176
- var r, o;
177
- let n = t.target;
178
- var a;
179
- t.target === ((r = window.document) == null ? void 0 : r.body) && window.Sprig.pointerDownTarget && (n = window.Sprig.pointerDownTarget), a = { x: t.x, y: t.y, type: e, elementAttributes: Tt(n), windowHeight: window.innerHeight, windowWidth: window.innerWidth, ...n instanceof HTMLElement || n instanceof SVGElement || n instanceof MathMLElement ? { rect: n == null ? void 0 : n.getBoundingClientRect(), xPath: Ae(n) } : {} }, (o = a == null ? void 0 : a.elementAttributes) != null && o.text && (a.elementAttributes.text = he(a.elementAttributes.text)), b == null || b("Sprig_Click", a);
180
- }, Le = (e) => {
175
+ }, Oe = (e, t) => {
176
+ var r, s;
177
+ let a = t.target;
178
+ var n;
179
+ t.target === ((r = window.document) == null ? void 0 : r.body) && window.Sprig.pointerDownTarget && (a = window.Sprig.pointerDownTarget), n = { x: t.x, y: t.y, type: e, elementAttributes: Ut(a), windowHeight: window.innerHeight, windowWidth: window.innerWidth, ...a instanceof HTMLElement || a instanceof SVGElement || a instanceof MathMLElement ? { rect: a == null ? void 0 : a.getBoundingClientRect(), xPath: Le(a) } : {} }, (s = n == null ? void 0 : n.elementAttributes) != null && s.text && (n.elementAttributes.text = he(n.elementAttributes.text)), D == null || D("Sprig_Click", n);
180
+ }, Fe = (e) => {
181
181
  var t;
182
- Pt.includes(e.key) && (t = { key: e.key }, b == null || b("Sprig_Keystroke", t));
183
- }, kt = () => {
182
+ kt.includes(e.key) && (t = { key: e.key }, D == null || D("Sprig_Keystroke", t));
183
+ }, xt = () => {
184
184
  var e;
185
- window.performance.getEntriesByType("navigation").map((t) => t.type).includes("reload") && (e = { url: window.location.href, currentPageTitle: document.title }, b == null || b("Sprig_Refresh", e));
186
- }, Ut = () => {
185
+ window.performance.getEntriesByType("navigation").map((t) => t.type).includes("reload") && (e = { url: window.location.href, currentPageTitle: document.title }, D == null || D("Sprig_Refresh", e));
186
+ }, Bt = () => {
187
187
  var e;
188
- window.performance.getEntriesByType("navigation").map((t) => t.type).includes("back_forward") && ((e = { curUrl: window.location.href, fromUrl: document.referrer, currentPageTitle: document.title }).currentPageTitle && (e.currentPageTitle = he(e.currentPageTitle)), b == null || b("Sprig_BackForward", e));
189
- }, Oe = gt((e) => {
188
+ window.performance.getEntriesByType("navigation").map((t) => t.type).includes("back_forward") && ((e = { curUrl: window.location.href, fromUrl: document.referrer, currentPageTitle: document.title }).currentPageTitle && (e.currentPageTitle = he(e.currentPageTitle)), D == null || D("Sprig_BackForward", e));
189
+ }, He = yt((e) => {
190
190
  if (!(e.target instanceof HTMLElement || e.target instanceof Document)) return;
191
191
  let t = e.target;
192
- "scrollTop" in t || (t = t.documentElement), G == null || G({ xPath: Ae(t), x: t.scrollLeft, y: t.scrollTop, elementAttributes: { targetScrollWidth: t.scrollWidth, targetClientWidth: t.clientWidth, targetScrollHeight: t.scrollHeight, targetClientHeight: t.clientHeight } });
193
- }, 750), Fe = (Pe = "left_click", (e) => Ne(Pe, e));
194
- var Pe;
195
- const He = (e) => {
196
- e.button === 2 && Ne("right_click", e);
197
- }, je = (e) => {
192
+ "scrollTop" in t || (t = t.documentElement), G == null || G({ xPath: Le(t), x: t.scrollLeft, y: t.scrollTop, elementAttributes: { targetScrollWidth: t.scrollWidth, targetClientWidth: t.clientWidth, targetScrollHeight: t.scrollHeight, targetClientHeight: t.clientHeight } });
193
+ }, 750), je = (Ce = "left_click", (e) => Oe(Ce, e));
194
+ var Ce;
195
+ const Ve = (e) => {
196
+ e.button === 2 && Oe("right_click", e);
197
+ }, Ge = (e) => {
198
198
  window.Sprig && (window.Sprig.pointerDownTarget = e.target);
199
199
  }, g = { isRecording: !1, scrollEventUuids: {}, stopRecording: () => {
200
- } }, Ve = () => window.indexedDB && window.IDBKeyRange && window.CompressionStream, I = (() => {
200
+ } }, We = () => globalThis.indexedDB && globalThis.IDBKeyRange && globalThis.CompressionStream, I = (() => {
201
201
  const e = m.getItem("sprig.sessionId");
202
202
  if (e) return d.info("SessionIDFound", { savedSessionId: e }), m.removeItem("sprig.sessionId"), e;
203
203
  const t = X();
204
204
  return d.info("GeneratedSessionID", { uuid: t }), t;
205
- })(), le = () => {
205
+ })(), ce = () => {
206
206
  m.setItem("sprig.disableReplayRecording", "disabled");
207
- }, P = () => !!m.getItem("sprig.disableReplayRecording"), z = () => !!m.getItem("sprig.isReplayPaused");
208
- window.addEventListener("beforeunload", () => {
207
+ }, C = () => !!m.getItem("sprig.disableReplayRecording"), z = () => !!m.getItem("sprig.isReplayPaused");
208
+ var ke;
209
+ (ke = globalThis.addEventListener) == null || ke.call(globalThis, "beforeunload", () => {
209
210
  d.info("BeforeUnload", { sessionId: I }), m.setItem("sprig.sessionId", I);
210
211
  });
211
212
  const U = (e, t) => {
212
- var n, a;
213
- if (!P() && g.isRecording && !z()) try {
214
- (a = (n = window.rrwebRecord) == null ? void 0 : n.addCustomEvent) == null || a.call(n, e, t);
213
+ var a, n;
214
+ if (!C() && g.isRecording && !z()) try {
215
+ (n = (a = globalThis.rrwebRecord) == null ? void 0 : a.addCustomEvent) == null || n.call(a, e, t);
215
216
  } catch (r) {
216
217
  H("Error recording custom event", r);
217
218
  }
218
- }, xt = async (e) => {
219
- const { x: t, xPath: n, y: a } = e, r = g.scrollEventUuids[n];
220
- if (r) return D(async () => {
221
- var c, i, l, y;
222
- const o = await u.openDB(), s = await o.get("events", r);
223
- if (s != null && s.event) {
224
- const p = JSON.parse(s.event), h = t > ((i = (c = p.data) == null ? void 0 : c.payload) == null ? void 0 : i.x), w = a > ((y = (l = p.data) == null ? void 0 : l.payload) == null ? void 0 : y.y);
225
- if (!h && !w) return null;
226
- h && (p.data.payload.x = t), w && (p.data.payload.y = a), p.data.payload.elementAttributes = e.elementAttributes, s.event = JSON.stringify(p), await o.put("events", s);
219
+ }, Mt = async (e) => {
220
+ const { x: t, xPath: a, y: n } = e, r = g.scrollEventUuids[a];
221
+ if (r) return b(async () => {
222
+ var l, i, c, w;
223
+ const s = await u.openDB(), o = await s.get("events", r);
224
+ if (o != null && o.event) {
225
+ const p = JSON.parse(o.event), h = t > ((i = (l = p.data) == null ? void 0 : l.payload) == null ? void 0 : i.x), y = n > ((w = (c = p.data) == null ? void 0 : c.payload) == null ? void 0 : w.y);
226
+ if (!h && !y) return null;
227
+ h && (p.data.payload.x = t), y && (p.data.payload.y = n), p.data.payload.elementAttributes = e.elementAttributes, o.event = JSON.stringify(p), await s.put("events", o);
227
228
  } else U("Sprig_Scroll", e);
228
229
  }, "Error updating scroll event");
229
230
  U("Sprig_Scroll", e);
230
- }, Ge = () => {
231
+ }, $e = () => {
231
232
  g.stopRecording && (g.stopRecording(), g.stopRecording = void 0), g.isRecording = !1, ["cleanupInterval", "inactivityInterval", "pendingCheckInterval"].forEach((e) => {
232
233
  g[e] && (clearInterval(g[e]), g[e] = void 0);
233
- }), J && (window.removeEventListener("click", Fe, C), window.removeEventListener("pointerdown", je, C), window.removeEventListener("mousedown", He, C), window.removeEventListener("keydown", Le, C), window.removeEventListener("scroll", Oe, C), J = !1), fe.forEach((e) => {
234
+ }), J && (window.removeEventListener("click", je, R), window.removeEventListener("pointerdown", Ge, R), window.removeEventListener("mousedown", Ve, R), window.removeEventListener("keydown", Fe, R), window.removeEventListener("scroll", He, R), J = !1), fe.forEach((e) => {
234
235
  var t;
235
- (t = e.source) == null || t.postMessage({ type: Et }, { targetOrigin: e.origin });
236
+ (t = e.source) == null || t.postMessage({ type: Rt }, { targetOrigin: e.origin });
236
237
  });
237
- }, Bt = ["did not allow mutations", "called in an invalid security context"], Mt = (e, t, { reportError: n = !0, extraInfo: a = {} }) => {
238
- if (!P() && t instanceof Error) {
239
- if (le(), t.name === "VersionError") return d.error("VersionErr", { message: e }), void u.deleteDB();
238
+ }, _t = ["did not allow mutations", "called in an invalid security context"], At = (e, t, { reportError: a = !0, extraInfo: n = {} }) => {
239
+ if (!C() && t instanceof Error) {
240
+ if (ce(), t.name === "VersionError") return d.error("VersionErr", { message: e }), void u.deleteDB();
240
241
  ((r) => {
241
242
  if (!r) return !0;
242
- for (const o of Bt) if (r.toLowerCase().includes(o)) return !1;
243
+ for (const s of _t) if (r.toLowerCase().includes(s)) return !1;
243
244
  return !0;
244
- })(t == null ? void 0 : t.message) && (n && window.UserLeap.reportError(e, t, a), u.clearAll());
245
+ })(t == null ? void 0 : t.message) && (a && globalThis.UserLeap.reportError(e, t, n), u.clearAll());
245
246
  }
246
- }, H = (e, t, { reportError: n } = { reportError: !0 }) => {
247
- Ge(), d.error("ReplayErr", { code: t.code, name: t.name }), Mt(e, t, { reportError: n });
248
- }, D = async (e, t) => {
247
+ }, H = (e, t, { reportError: a } = { reportError: !0 }) => {
248
+ $e(), d.error("ReplayErr", { code: t.code, name: t.name }), At(e, t, { reportError: a });
249
+ }, b = async (e, t) => {
249
250
  try {
250
251
  return await e();
251
- } catch (n) {
252
- H(t, n);
252
+ } catch (a) {
253
+ H(t, a);
253
254
  }
254
255
  }, ue = () => {
255
- g.isRecording && (D(() => {
256
+ g.isRecording && (b(() => {
256
257
  var e, t;
257
- return (t = (e = window.rrwebRecord) == null ? void 0 : e.takeFullSnapshot) == null ? void 0 : t.call(e, !0);
258
+ return (t = (e = globalThis.rrwebRecord) == null ? void 0 : e.takeFullSnapshot) == null ? void 0 : t.call(e, !0);
258
259
  }, "Error recording full snapshot"), fe.forEach((e) => {
259
260
  var t;
260
- (t = e.source) == null || t.postMessage({ type: bt }, { targetOrigin: e.origin });
261
+ (t = e.source) == null || t.postMessage({ type: Et }, { targetOrigin: e.origin });
261
262
  }));
262
263
  };
263
264
  let te = 0;
264
- (async () => Ve() && Promise.allSettled([de("replayStorage"), de("sprig.replay")]))();
265
+ (async () => We() && Promise.allSettled([de("replayStorage"), de("sprig.replay")]))();
265
266
  const u = new class {
266
267
  constructor() {
267
268
  F(this, "wrapTransactionWithCounter", (e) => {
268
- var a, r;
269
- const t = (r = (a = window.Sprig) == null ? void 0 : a._config) == null ? void 0 : r.outstandingTransactionLimit, n = t === void 0 ? 100 : t;
270
- if (n && te > n) {
271
- const o = "Too many outstanding transactions";
272
- H(o, new Error(o), { reportError: !1 });
269
+ var n, r;
270
+ const t = (r = (n = window.Sprig) == null ? void 0 : n._config) == null ? void 0 : r.outstandingTransactionLimit, a = t === void 0 ? 100 : t;
271
+ if (a && te > a) {
272
+ const s = "Too many outstanding transactions";
273
+ H(s, new Error(s), { reportError: !1 });
273
274
  }
274
275
  te++, e.done.finally(() => {
275
276
  te--;
@@ -281,26 +282,26 @@ const u = new class {
281
282
  });
282
283
  }
283
284
  openDB() {
284
- return function(e, t, { blocked: n, upgrade: a, blocking: r, terminated: o } = {}) {
285
- const s = indexedDB.open(e, t), c = M(s);
286
- return a && (s.onupgradeneeded = (i) => {
287
- a(M(s.result), i.oldVersion, i.newVersion, M(s.transaction), i);
288
- }), n && (s.onblocked = (i) => n(i.oldVersion, i.newVersion, i)), c.then((i) => {
289
- o && (i.onclose = () => o()), r && (i.onversionchange = (l) => r(l.oldVersion, l.newVersion, l));
285
+ return function(e, t, { blocked: a, upgrade: n, blocking: r, terminated: s } = {}) {
286
+ const o = indexedDB.open(e, t), l = M(o);
287
+ return n && (o.onupgradeneeded = (i) => {
288
+ n(M(o.result), i.oldVersion, i.newVersion, M(o.transaction), i);
289
+ }), a && (o.onblocked = (i) => a(i.oldVersion, i.newVersion, i)), l.then((i) => {
290
+ s && (i.onclose = () => s()), r && (i.onversionchange = (c) => r(c.oldVersion, c.newVersion, c));
290
291
  }).catch(() => {
291
- }), c;
292
- }("sprigReplay", 1, { upgrade: (e, t, n) => {
293
- if (n === 0 && m.setItem("sprig.pendingCount", "0"), !e.objectStoreNames.contains("events")) {
294
- const a = e.createObjectStore("events", { keyPath: "uuid" });
295
- a.createIndex("sessionId", "sessionId"), a.createIndex("timestamp", "timestamp"), a.createIndex("[sessionId+timestamp]", ["sessionId", "timestamp"]);
292
+ }), l;
293
+ }("sprigReplay", 1, { upgrade: (e, t, a) => {
294
+ if (a === 0 && m.setItem("sprig.pendingCount", "0"), !e.objectStoreNames.contains("events")) {
295
+ const n = e.createObjectStore("events", { keyPath: "uuid" });
296
+ n.createIndex("sessionId", "sessionId"), n.createIndex("timestamp", "timestamp"), n.createIndex("[sessionId+timestamp]", ["sessionId", "timestamp"]);
296
297
  }
297
298
  if (!e.objectStoreNames.contains("chunkUploads")) {
298
- const a = e.createObjectStore("chunkUploads", { keyPath: "uuid" });
299
- a.createIndex("sessionId", "sessionId"), a.createIndex("timestamp", "timestamp"), a.createIndex("[sessionId+status]", ["sessionId", "status"]), a.createIndex("[uploadId+status]", ["uploadId", "status"]), a.createIndex("[sessionId+status+uploadId]", ["sessionId", "status", "uploadId"]);
299
+ const n = e.createObjectStore("chunkUploads", { keyPath: "uuid" });
300
+ n.createIndex("sessionId", "sessionId"), n.createIndex("timestamp", "timestamp"), n.createIndex("[sessionId+status]", ["sessionId", "status"]), n.createIndex("[uploadId+status]", ["uploadId", "status"]), n.createIndex("[sessionId+status+uploadId]", ["sessionId", "status", "uploadId"]);
300
301
  }
301
302
  if (!e.objectStoreNames.contains("pendingCaptures")) {
302
- const a = e.createObjectStore("pendingCaptures", { keyPath: "uuid" });
303
- a.createIndex("sessionId", "sessionId"), a.createIndex("timestamp", "timestamp"), a.createIndex("[sessionId+targetTimestamp]", ["sessionId", "targetTimestamp"]);
303
+ const n = e.createObjectStore("pendingCaptures", { keyPath: "uuid" });
304
+ n.createIndex("sessionId", "sessionId"), n.createIndex("timestamp", "timestamp"), n.createIndex("[sessionId+targetTimestamp]", ["sessionId", "targetTimestamp"]);
304
305
  }
305
306
  } });
306
307
  }
@@ -311,405 +312,406 @@ const u = new class {
311
312
  }
312
313
  }
313
314
  async bulkAdd(e, t) {
314
- const n = await this.getTransaction(e);
315
- return Promise.all([...t.map((a) => n.store.add(a)), n.done]);
315
+ const a = await this.getTransaction(e);
316
+ return Promise.all([...t.map((n) => a.store.add(n)), a.done]);
316
317
  }
317
318
  async clearAll() {
318
319
  const e = (await this.openDB()).transaction(["events", "chunkUploads", "pendingCaptures"], "readwrite");
319
320
  return this.wrapTransactionWithCounter(e), Promise.all([e.objectStore("events").clear(), e.objectStore("chunkUploads").clear(), e.objectStore("pendingCaptures").clear()]);
320
321
  }
321
322
  async deleteBySessionId(e, t) {
322
- const n = IDBKeyRange.only(t), a = await this.getTransaction(e), r = a.store.index("sessionId");
323
- for await (const o of r.iterate(n)) await o.delete();
324
- await a.done;
323
+ const a = IDBKeyRange.only(t), n = await this.getTransaction(e), r = n.store.index("sessionId");
324
+ for await (const s of r.iterate(a)) await s.delete();
325
+ await n.done;
325
326
  }
326
- async updatePartial(e, t, n) {
327
- const a = await this.getTransaction(e), r = await a.store.get(t);
328
- r && await a.store.put({ ...r, ...n }), await a.done;
327
+ async updatePartial(e, t, a) {
328
+ const n = await this.getTransaction(e), r = await n.store.get(t);
329
+ r && await n.store.put({ ...r, ...a }), await n.done;
329
330
  }
330
- async deleteRowsBefore(e, t, n = () => !0) {
331
- const a = IDBKeyRange.upperBound(t, !0), r = await this.getTransaction(e), o = r.store.index("timestamp");
332
- for await (const s of o.iterate(a)) n(s.value) && await s.delete();
331
+ async deleteRowsBefore(e, t, a = () => !0) {
332
+ const n = IDBKeyRange.upperBound(t, !0), r = await this.getTransaction(e), s = r.store.index("timestamp");
333
+ for await (const o of s.iterate(n)) a(o.value) && await o.delete();
333
334
  await r.done;
334
335
  }
335
336
  async getEventsBetween(e, t = Date.now()) {
336
337
  if (e >= t) return Promise.resolve([]);
337
- const n = IDBKeyRange.bound([I, e], [I, t], !1, !0);
338
- return (await this.openDB()).getAllFromIndex("events", "[sessionId+timestamp]", n);
338
+ const a = IDBKeyRange.bound([I, e], [I, t], !1, !0);
339
+ return (await this.openDB()).getAllFromIndex("events", "[sessionId+timestamp]", a);
339
340
  }
340
- async updateEventsExpiredAt(e, t, n = 30) {
341
- const a = /* @__PURE__ */ new Date(), r = a.setMinutes(a.getMinutes() + (n ?? 30)), o = await this.getTransaction("events"), s = o.store.index("[sessionId+timestamp]"), c = IDBKeyRange.bound([I, e], [I, t], !1, !0);
342
- for await (const i of s.iterate(c)) await i.update({ ...i.value, expiredAt: r });
343
- await o.done;
341
+ async updateEventsExpiredAt(e, t, a = 30) {
342
+ const n = /* @__PURE__ */ new Date(), r = n.setMinutes(n.getMinutes() + (a ?? 30)), s = await this.getTransaction("events"), o = s.store.index("[sessionId+timestamp]"), l = IDBKeyRange.bound([I, e], [I, t], !1, !0);
343
+ for await (const i of o.iterate(l)) await i.update({ ...i.value, expiredAt: r });
344
+ await s.done;
344
345
  }
345
346
  async deleteChunkUploads(e, t) {
346
- const n = IDBKeyRange.only([t, e]), a = await this.getTransaction("chunkUploads");
347
- let o = await a.store.index("[uploadId+status]").openCursor(n);
348
- for (; o; ) o.delete(), o = await o.continue();
349
- await a.done;
347
+ const a = IDBKeyRange.only([t, e]), n = await this.getTransaction("chunkUploads");
348
+ let s = await n.store.index("[uploadId+status]").openCursor(a);
349
+ for (; s; ) s.delete(), s = await s.continue();
350
+ await n.done;
350
351
  }
351
- async getChunkUploadsByStatus({ sessionId: e, status: t, uploadId: n }) {
352
- const a = (await this.openDB()).transaction("chunkUploads", "readonly");
353
- this.wrapTransactionWithCounter(a);
354
- const r = n ? a.store.index("[uploadId+status]") : a.store.index("[sessionId+status]"), o = n ? IDBKeyRange.only([n, t]) : IDBKeyRange.only([e, t]);
355
- return r.getAll(o);
352
+ async getChunkUploadsByStatus({ sessionId: e, status: t, uploadId: a }) {
353
+ const n = (await this.openDB()).transaction("chunkUploads", "readonly");
354
+ this.wrapTransactionWithCounter(n);
355
+ const r = a ? n.store.index("[uploadId+status]") : n.store.index("[sessionId+status]"), s = a ? IDBKeyRange.only([a, t]) : IDBKeyRange.only([e, t]);
356
+ return r.getAll(s);
356
357
  }
357
358
  async getPendingCaptures(e = {}) {
358
- return (await (await this.openDB()).getAllFromIndex("pendingCaptures", "sessionId", I)).filter((n) => !e.beforePresent || n.targetTimestamp < Date.now()).filter((n) => !e.isBeforeType || n.captureParams.replayParams.replayDurationType === "before").filter((n) => !e.isHeatmap || (n.captureParams.isHeatmap ?? !1));
359
+ return (await (await this.openDB()).getAllFromIndex("pendingCaptures", "sessionId", I)).filter((a) => !e.beforePresent || a.targetTimestamp < Date.now()).filter((a) => !e.isBeforeType || a.captureParams.replayParams.replayDurationType === "before").filter((a) => !e.isHeatmap || (a.captureParams.isHeatmap ?? !1));
359
360
  }
360
361
  async markPendingCaptureToCanUpload(e) {
361
- const t = await this.getTransaction("pendingCaptures"), n = t.store.index("sessionId");
362
- for await (const a of n.iterate(I)) {
363
- const r = a.value;
364
- r.captureParams.responseGroupId === e && await a.update({ ...r, canUpload: !0 });
362
+ const t = await this.getTransaction("pendingCaptures"), a = t.store.index("sessionId");
363
+ for await (const n of a.iterate(I)) {
364
+ const r = n.value;
365
+ r.captureParams.responseGroupId === e && await n.update({ ...r, canUpload: !0 });
365
366
  }
366
367
  await t.done;
367
368
  }
368
369
  async markPendingHeatmapsReady(e) {
369
370
  if (parseInt(m.getItem("sprig.pendingCount") ?? "0") === 0) return null;
370
- const t = Date.now(), n = await this.getTransaction("pendingCaptures"), a = n.store.index("sessionId");
371
- for await (const r of a.iterate(I)) {
372
- const o = r.value;
373
- !o.captureParams.isHeatmap || e && !e.includes(o.uuid) || await r.update({ ...o, targetTimestamp: t, captureParams: { ...o.captureParams, triggerTimestamp: t, replayParams: { ...o.captureParams.replayParams, replayDurationSeconds: Math.floor((t - o.timestamp) / 1e3) } } });
371
+ const t = Date.now(), a = await this.getTransaction("pendingCaptures"), n = a.store.index("sessionId");
372
+ for await (const r of n.iterate(I)) {
373
+ const s = r.value;
374
+ !s.captureParams.isHeatmap || e && !e.includes(s.uuid) || await r.update({ ...s, targetTimestamp: t, captureParams: { ...s.captureParams, triggerTimestamp: t, replayParams: { ...s.captureParams.replayParams, replayDurationSeconds: Math.floor((t - s.timestamp) / 1e3) } } });
374
375
  }
375
- await n.done;
376
+ await a.done;
376
377
  }
377
378
  }(), x = [];
378
- let j, We, A = [], L = !1, N = 0, W = !1, $e = !1;
379
+ let j, Ke, A = [], L = !1, N = 0, W = !1, Je = !1;
379
380
  const Ie = [];
380
- let q, Ke, $, Je, ne = !1;
381
- const O = () => W && !L && Date.now() <= q, _t = ({ apiUrl: e, config: t, triggerSnapshot: n, forceInit: a = !1 }) => {
382
- W && !a || (m.isStorageAvailable ? (A = [], Ie.splice(0), x.splice(0), N = 0, $ = n, We = e, j = { responseGroupUuid: t.responseGroupUuid, surveyId: t.surveyId, userAgent: t.userAgent, sdkVersion: t.sdkVersion }, Ke = t.maxDurationSeconds, Ot(), W || (Je = window.setInterval(Lt, 500)), W = !0) : L = !0);
383
- }, At = [k.Drag, k.Input, k.MediaInteraction, k.MouseInteraction, k.MouseMove, k.Scroll, k.Selection, k.TouchMove], Nt = (e) => e.type === B.Custom || e.type === B.IncrementalSnapshot && At.includes(e.data.source), ve = (e) => e.some(Nt), Lt = async () => {
384
- if (!O()) return void window.clearInterval(Je);
385
- if (ze(), !ve(x)) return;
381
+ let q, ze, $, qe, ae = !1;
382
+ const O = () => W && !L && Date.now() <= q, Nt = ({ apiUrl: e, config: t, triggerSnapshot: a, forceInit: n = !1 }) => {
383
+ W && !n || (m.isStorageAvailable ? (A = [], Ie.splice(0), x.splice(0), N = 0, $ = a, Ke = e, j = { responseGroupUuid: t.responseGroupUuid, surveyId: t.surveyId, userAgent: t.userAgent, sdkVersion: t.sdkVersion }, ze = t.maxDurationSeconds, Ht(), W || (qe = globalThis.setInterval(Ft, 500)), W = !0) : L = !0);
384
+ }, Lt = [k.Drag, k.Input, k.MediaInteraction, k.MouseInteraction, k.MouseMove, k.Scroll, k.Selection, k.TouchMove], Ot = (e) => e.type === B.Custom || e.type === B.IncrementalSnapshot && Lt.includes(e.data.source), ve = (e) => e.some(Ot), Ft = async () => {
385
+ if (!O()) return void globalThis.clearInterval(qe);
386
+ if (Qe(), !ve(x)) return;
386
387
  const e = x[0].timestamp;
387
388
  Date.now() - e > 35e3 && ($ == null || $());
388
- }, ze = async () => {
389
- if (A.length || ne) return;
390
- ne = !0;
391
- const e = await Ht();
389
+ }, Qe = async () => {
390
+ if (A.length || ae) return;
391
+ ae = !0;
392
+ const e = await Vt();
392
393
  if (!e) return void (L = !0);
393
- Ie.splice(0, e.length).forEach((t) => t(e.shift())), e.forEach((t) => A.push(t)), ne = !1;
394
- }, Ot = () => {
394
+ Ie.splice(0, e.length).forEach((t) => t(e.shift())), e.forEach((t) => A.push(t)), ae = !1;
395
+ }, Ht = () => {
395
396
  const e = m.getItem("sprig.alwayson.info");
396
397
  if (e) {
397
398
  d.info("Read stored session state", e);
398
399
  const t = JSON.parse(e);
399
- L = t.disabled, j = t.metadata, A = t.uploadUrls, N = t.currentIndex, q = t.expirationTimestamp, t.pendingEventTimestamp && (d.info(`Uploading with pending timestamp: ${t.pendingEventTimestamp}`), Ft(t.pendingEventTimestamp));
400
- } else q = 1e3 * Ke + Date.now();
401
- }, Ft = async (e) => {
402
- const t = Date.now(), n = (await u.getEventsBetween(e, t)).map((r) => JSON.parse(r.event));
403
- if (!ve(n)) return;
404
- Ye(n);
405
- const a = await Xe();
406
- a && await Qe(a, n);
407
- }, qe = async (e, t) => {
400
+ L = t.disabled, j = t.metadata, A = t.uploadUrls, N = t.currentIndex, q = t.expirationTimestamp, t.pendingEventTimestamp && (d.info(`Uploading with pending timestamp: ${t.pendingEventTimestamp}`), jt(t.pendingEventTimestamp));
401
+ } else q = 1e3 * ze + Date.now();
402
+ }, jt = async (e) => {
403
+ const t = Date.now(), a = (await u.getEventsBetween(e, t)).map((r) => JSON.parse(r.event));
404
+ if (!ve(a)) return;
405
+ et(a);
406
+ const n = await Ze();
407
+ n && await Ye(n, a);
408
+ }, Xe = async (e, t) => {
408
409
  try {
409
- const n = await e();
410
- if (!n.ok) throw new Error(`Error ${t}`);
411
- return n;
410
+ const a = await e();
411
+ if (!a.ok) throw new Error(`Error ${t}`);
412
+ return a;
412
413
  } catch {
413
414
  L = !0;
414
415
  }
415
- }, Qe = async (e, t) => {
416
+ }, Ye = async (e, t) => {
416
417
  if (!O() || !e) return;
417
- const n = await (async (a) => {
418
- const r = new TextEncoder(), o = new CompressionStream("gzip"), s = o.writable.getWriter(), c = r.encode(JSON.stringify(a));
419
- return s.write(c), s.close(), new Uint8Array(await new Response(o.readable).arrayBuffer());
418
+ const a = await (async (n) => {
419
+ const r = new TextEncoder(), s = new CompressionStream("gzip"), o = s.writable.getWriter(), l = r.encode(JSON.stringify(n));
420
+ return o.write(l), o.close(), new Uint8Array(await new Response(s.readable).arrayBuffer());
420
421
  })(t);
421
- d.info("Uploading always-on events with presigned url"), await qe(() => Q(e, { body: n, method: "PUT" }), "uploading always-on with presigned url");
422
- }, Ht = async () => {
422
+ d.info("Uploading always-on events with presigned url"), await Xe(() => Q(e, { body: a, method: "PUT" }), "uploading always-on with presigned url");
423
+ }, Vt = async () => {
423
424
  if (!O()) return;
424
- const { surveyId: e, responseGroupUuid: t } = j, n = { responseGroupUuid: t, surveyId: e, index: N + 1 };
425
- d.info("Fetching always-on upload urls", n);
426
- const a = await qe(() => Q(`${We}/sdk/1/replayUrls`, { method: "POST", body: JSON.stringify(n), headers: lt(window.UserLeap) }), "fetching always-on signed urls");
427
- if (!a) return;
428
- const r = a.json.signedUrls;
429
- return d.info("Fetched more always-on upload urls", { body: n, urls: r }), r;
430
- }, Xe = async () => {
425
+ const { surveyId: e, responseGroupUuid: t } = j, a = { responseGroupUuid: t, surveyId: e, index: N + 1 };
426
+ d.info("Fetching always-on upload urls", a);
427
+ const n = await Xe(() => Q(`${Ke}/sdk/1/replayUrls`, { method: "POST", body: JSON.stringify(a), headers: pt(globalThis.UserLeap) }), "fetching always-on signed urls");
428
+ if (!n) return;
429
+ const r = n.json.signedUrls;
430
+ return d.info("Fetched more always-on upload urls", { body: a, urls: r }), r;
431
+ }, Ze = async () => {
431
432
  if (A.length) return A.shift();
432
433
  const e = new Promise((t) => {
433
434
  Ie.push(t);
434
435
  });
435
- return ze(), e;
436
- }, Ye = (e) => {
437
- var r, o, s;
438
- const t = e.length ? e[e.length - 1].timestamp : Date.now(), n = N, a = ((o = (r = window.UserLeap) == null ? void 0 : r.config) == null ? void 0 : o.customMetadata) ?? ((s = window.__cfg) == null ? void 0 : s.customMetadata);
439
- N++, e.push({ timestamp: t, type: B.Custom, data: { tag: "Sprig_Meta", payload: { ...j, index: n, visitorId: window.UserLeap.visitorId ?? "", timestamp: t, customMetadata: a } } });
440
- }, jt = (e, t) => {
441
- O() && !$e && (e || x.length) && (e && x.length && (async () => {
442
- const n = x.splice(0);
443
- if (!ve(n)) return;
444
- d.info("Capturing always-on event array to upload"), Ye(n);
445
- const a = await Xe();
446
- a && await Qe(a, n);
436
+ return Qe(), e;
437
+ }, et = (e) => {
438
+ var r, s, o;
439
+ const t = e.length ? e[e.length - 1].timestamp : Date.now(), a = N, n = ((s = (r = globalThis.UserLeap) == null ? void 0 : r.config) == null ? void 0 : s.customMetadata) ?? ((o = globalThis.__cfg) == null ? void 0 : o.customMetadata);
440
+ N++, e.push({ timestamp: t, type: B.Custom, data: { tag: "Sprig_Meta", payload: { ...j, index: a, visitorId: globalThis.UserLeap.visitorId ?? "", timestamp: t, customMetadata: n } } });
441
+ }, Gt = (e, t) => {
442
+ O() && !Je && (e || x.length) && (e && x.length && (async () => {
443
+ const a = x.splice(0);
444
+ if (!ve(a)) return;
445
+ d.info("Capturing always-on event array to upload"), et(a);
446
+ const n = await Ze();
447
+ n && await Ye(n, a);
447
448
  })(), x.push(t));
448
449
  };
449
- window.addEventListener("beforeunload", async () => {
450
- $e = !0, O() && (d.info("Always On handle page unload"), (() => {
450
+ var Ue;
451
+ (Ue = globalThis.addEventListener) == null || Ue.call(globalThis, "beforeunload", async () => {
452
+ Je = !0, O() && (d.info("Always On handle page unload"), (() => {
451
453
  let e;
452
454
  x.length && (e = x[0].timestamp);
453
455
  const t = { disabled: L, metadata: j, uploadUrls: A, currentIndex: N, pendingEventTimestamp: e, expirationTimestamp: q };
454
456
  d.info("Storing session state on unload", t), m.setItem("sprig.alwayson.info", JSON.stringify(t));
455
457
  })());
456
458
  });
457
- const Ze = async (e, t) => {
458
- const n = performance.now();
459
- let a;
459
+ const tt = async (e, t) => {
460
+ const a = performance.now();
461
+ let n;
460
462
  try {
461
- a = await e();
463
+ n = await e();
462
464
  } finally {
463
- const r = performance.now() - n;
464
- let o = ke[t];
465
- o || (o = Ue(t)), o.report(r / 1e3);
465
+ const r = performance.now() - a;
466
+ let s = xe[t];
467
+ s || (s = Be(t)), s.report(r / 1e3);
466
468
  }
467
- return a;
468
- }, et = (e, t) => {
469
- const n = performance.now();
469
+ return n;
470
+ }, at = (e, t) => {
471
+ const a = performance.now();
470
472
  try {
471
473
  e();
472
474
  } finally {
473
- const a = performance.now() - n;
474
- let r = ke[t];
475
- r || (r = Ue(t)), r.report(a / 1e3);
475
+ const n = performance.now() - a;
476
+ let r = xe[t];
477
+ r || (r = Be(t)), r.report(n / 1e3);
476
478
  }
477
479
  };
478
- let tt = 5e3, pe = 6e4, ge = 0, _, me = !1, we = [];
479
- const Vt = (e) => {
480
- var t, n, a, r;
480
+ let nt = 5e3, pe = 6e4, ge = 0, _, me = !1, ye = [];
481
+ const Wt = (e) => {
482
+ var t, a, n, r;
481
483
  if ((t = e.event) != null && t.includes("Sprig_Scroll")) {
482
- const o = (r = (a = (n = JSON.parse(e.event)) == null ? void 0 : n.data) == null ? void 0 : a.payload) == null ? void 0 : r.xPath;
483
- if (!o) return;
484
- g.scrollEventUuids[o] = e.uuid;
484
+ const s = (r = (n = (a = JSON.parse(e.event)) == null ? void 0 : a.data) == null ? void 0 : n.payload) == null ? void 0 : r.xPath;
485
+ if (!s) return;
486
+ g.scrollEventUuids[s] = e.uuid;
485
487
  }
486
- we.push(e), me || Gt();
487
- }, Gt = () => {
488
+ ye.push(e), me || $t();
489
+ }, $t = () => {
488
490
  me = !0, setTimeout(async () => {
489
- if (P() || z()) return;
490
- const e = we;
491
- we = [], me = !1, et(async () => {
491
+ if (C() || z()) return;
492
+ const e = ye;
493
+ ye = [], me = !1, at(async () => {
492
494
  await (async (t) => {
493
- const n = t.map((a) => ({ ...a, sessionId: a.sessionId ?? I }));
494
- if (n.length !== 0) return D(() => u.bulkAdd("events", n), "Error storing replay events");
495
+ const a = t.map((n) => ({ ...n, sessionId: n.sessionId ?? I }));
496
+ if (a.length !== 0) return b(() => u.bulkAdd("events", a), "Error storing replay events");
495
497
  })(e);
496
498
  }, "sdk_replay_add_event_batch_seconds");
497
499
  }, 500);
498
- }, Wt = (e, t, n) => {
500
+ }, Kt = (e, t, a) => {
499
501
  g.cleanupInterval = window.setInterval(() => {
500
- const a = Date.now();
501
- Ze(() => D(async () => {
502
- P() || await Promise.all([u.deleteRowsBefore("events", a - 1e3 * e, (r) => r.expiredAt === void 0 || r.expiredAt < a - 1e3 * e), u.deleteRowsBefore("chunkUploads", a - 1e3 * t), u.deleteRowsBefore("pendingCaptures", a - 1e3 * n, (r) => !r.canUpload)]);
502
+ const n = Date.now();
503
+ tt(() => b(async () => {
504
+ C() || await Promise.all([u.deleteRowsBefore("events", n - 1e3 * e, (r) => r.expiredAt === void 0 || r.expiredAt < n - 1e3 * e), u.deleteRowsBefore("chunkUploads", n - 1e3 * t), u.deleteRowsBefore("pendingCaptures", n - 1e3 * a, (r) => !r.canUpload)]);
503
505
  }, "Error deleting table rows"), "sdk_replay_cleanup_seconds"), d.debug("CleanupComplete");
504
506
  }, 3e4);
505
- }, $t = () => {
507
+ }, Jt = () => {
506
508
  g.pendingCheckInterval = window.setInterval(async () => {
507
- D(async () => {
508
- await ye();
509
+ b(async () => {
510
+ await we();
509
511
  }, "Error initiating pending captures");
510
512
  }, 5e3);
511
513
  };
512
- let ae = !1;
513
- const ye = async (e = !1) => {
514
- if (!ae) try {
515
- ae = !0;
514
+ let ne = !1;
515
+ const we = async (e = !1) => {
516
+ if (!ne) try {
517
+ ne = !0;
516
518
  const t = parseInt(_ ?? "0");
517
519
  if (t === 0) return;
518
- const n = await u.getPendingCaptures({ beforePresent: !0, isBeforeType: e }), a = await u.openDB();
519
- await Promise.all(n.map(async (r) => (await a.delete("pendingCaptures", r.uuid), rt(r.captureParams, r.canUpload)))), _ = (t - n.length).toString(), m.setItem("sprig.pendingCount", _);
520
+ const a = await u.getPendingCaptures({ beforePresent: !0, isBeforeType: e }), n = await u.openDB();
521
+ await Promise.all(a.map(async (r) => (await n.delete("pendingCaptures", r.uuid), ot(r.captureParams, r.canUpload)))), _ = (t - a.length).toString(), m.setItem("sprig.pendingCount", _);
520
522
  } finally {
521
- ae = !1;
523
+ ne = !1;
522
524
  }
523
- }, Kt = async (e, t, n, a, r) => {
524
- const o = Math.min(e + r, n), s = await Ze(() => u.getEventsBetween(e, o), "sdk_replay_get_events_between_seconds");
525
- if (!(s != null && s.length)) return d.debug("NoEventsFound"), { validStartFound: a, events: [] };
526
- if (!a) {
525
+ }, zt = async (e, t, a, n, r) => {
526
+ const s = Math.min(e + r, a), o = await tt(() => u.getEventsBetween(e, s), "sdk_replay_get_events_between_seconds");
527
+ if (!(o != null && o.length)) return d.debug("NoEventsFound"), { validStartFound: n, events: [] };
528
+ if (!n) {
527
529
  d.debug("ValidStartSearch");
528
- let c = -1;
529
- return s == null || s.forEach((i, l) => {
530
+ let l = -1;
531
+ return o == null || o.forEach((i, c) => {
530
532
  if (!i.isValidStart) return;
531
- const y = i.timestamp <= t;
532
- (c < 0 || y) && (c = l);
533
- }), c < 0 ? (d.debug("ValidStartNotFound"), { validStartFound: a, events: [] }) : { validStartFound: !0, events: s == null ? void 0 : s.slice(c) };
534
- }
535
- return { validStartFound: a, events: s };
536
- }, nt = (e) => Promise.all(e.map(async (t) => {
537
- const n = await (async (a) => Me.execute(async () => {
538
- var s;
539
- d.info("UploadChunkStart", { chunkIndex: a.chunkIndex, surveyId: a.surveyId });
540
- const r = await Q(a.uploadUrl, { body: a.data, method: "PUT" });
541
- d.http("UploadChunkEnd", { url: a.uploadUrl, method: "PUT", status_code: r.status, reason: r.statusText ?? "OK", chunkIndex: a.chunkIndex, surveyId: a.surveyId });
542
- const o = (s = r.headers) == null ? void 0 : s.get("ETag");
543
- if (!o) throw new Error(`Upload response did not include etag for upload ${a.uploadId}, part ${a.chunkIndex}`);
544
- return o;
533
+ const w = i.timestamp <= t;
534
+ (l < 0 || w) && (l = c);
535
+ }), l < 0 ? (d.debug("ValidStartNotFound"), { validStartFound: n, events: [] }) : { validStartFound: !0, events: o == null ? void 0 : o.slice(l) };
536
+ }
537
+ return { validStartFound: n, events: o };
538
+ }, rt = (e) => Promise.all(e.map(async (t) => {
539
+ const a = await (async (n) => Ae.execute(async () => {
540
+ var o;
541
+ d.info("UploadChunkStart", { chunkIndex: n.chunkIndex, surveyId: n.surveyId });
542
+ const r = await Q(n.uploadUrl, { body: n.data, method: "PUT" });
543
+ d.http("UploadChunkEnd", { url: n.uploadUrl, method: "PUT", status_code: r.status, reason: r.statusText ?? "OK", chunkIndex: n.chunkIndex, surveyId: n.surveyId });
544
+ const s = (o = r.headers) == null ? void 0 : o.get("ETag");
545
+ if (!s) throw new Error(`Upload response did not include etag for upload ${n.uploadId}, part ${n.chunkIndex}`);
546
+ return s;
545
547
  }))(t);
546
- return await u.updatePartial("chunkUploads", t.uuid, { data: null, etag: n, status: "UploadComplete" }), t.uploadId;
547
- })), at = async (e) => {
548
+ return await u.updatePartial("chunkUploads", t.uuid, { data: null, etag: a, status: "UploadComplete" }), t.uploadId;
549
+ })), st = async (e) => {
548
550
  const t = await u.getChunkUploadsByStatus({ status: "UploadComplete", uploadId: e });
549
551
  if (!(t != null && t.length)) return void d.info("NoChunksForUpload", { uploadId: e });
550
- const n = t.reduce((o, s) => (o.find((c) => c.chunkIndex === s.chunkIndex) || o.push(s), o), []);
551
- n.sort((o, s) => o.chunkIndex - s.chunkIndex);
552
- const a = n.map((o) => ({ ETag: o.etag, PartNumber: o.chunkIndex })).filter((o) => o.ETag !== null), r = n[0];
553
- await _e({ apiUrl: r.apiUrl, surveyId: r.surveyId, uploadId: e, responseGroupUuid: r.responseGroupId, etags: a, headers: r.completeUploadHeaders, replayDuration: r.replayDuration }), await u.deleteChunkUploads("UploadComplete", e);
554
- }, Jt = () => {
555
- D(async () => {
552
+ const a = t.reduce((s, o) => (s.find((l) => l.chunkIndex === o.chunkIndex) || s.push(o), s), []);
553
+ a.sort((s, o) => s.chunkIndex - o.chunkIndex);
554
+ const n = a.map((s) => ({ ETag: s.etag, PartNumber: s.chunkIndex })).filter((s) => s.ETag !== null), r = a[0];
555
+ await Ne({ apiUrl: r.apiUrl, surveyId: r.surveyId, uploadId: e, responseGroupUuid: r.responseGroupId, etags: n, headers: r.completeUploadHeaders, replayDuration: r.replayDuration }), await u.deleteChunkUploads("UploadComplete", e);
556
+ }, qt = () => {
557
+ b(async () => {
556
558
  const e = await u.getChunkUploadsByStatus({ sessionId: I, status: "ReadyForUpload" });
557
559
  if (!(e != null && e.length)) return;
558
- const t = await nt(e);
559
- t != null && t.length && await Promise.all(t.map((n) => {
560
- if (n) return at(n);
560
+ const t = await rt(e);
561
+ t != null && t.length && await Promise.all(t.map((a) => {
562
+ if (a) return st(a);
561
563
  }));
562
564
  }, "Error uploading unfinished chunks");
563
- }, zt = async (e, t) => {
564
- const n = t ?? Date.now();
565
- return (async (a, r) => {
566
- const o = new TextEncoder();
567
- let s = null;
568
- const c = new CompressionStream("gzip"), i = c.writable.getWriter();
569
- let l = !1, y = !1, [p, h] = [0, 0], w = [];
570
- for (let T = a - 35e3; T < r; T += pe) {
571
- if ({ validStartFound: y, events: w } = await Kt(T, a, r, y, pe), !(w != null && w.length)) {
565
+ }, Qt = async (e, t) => {
566
+ const a = t ?? Date.now();
567
+ return (async (n, r) => {
568
+ const s = new TextEncoder();
569
+ let o = null;
570
+ const l = new CompressionStream("gzip"), i = l.writable.getWriter();
571
+ let c = !1, w = !1, [p, h] = [0, 0], y = [];
572
+ for (let P = n - 35e3; P < r; P += pe) {
573
+ if ({ validStartFound: w, events: y } = await zt(P, n, r, w, pe), !(y != null && y.length)) {
572
574
  d.debug("NoEventsFound");
573
575
  continue;
574
576
  }
575
- p === 0 && (p = w[0].timestamp), h = w[w.length - 1].timestamp;
576
- const f = w.map((R) => R.event);
577
+ p === 0 && (p = y[0].timestamp), h = y[y.length - 1].timestamp;
578
+ const f = y.map((E) => E.event);
577
579
  f.push(`{"timestamp":${r}}`);
578
- const v = `${l ? "," : "["}${f}`, S = o.encode(v);
579
- et(() => {
580
+ const v = `${c ? "," : "["}${f}`, S = s.encode(v);
581
+ at(() => {
580
582
  i.write(S);
581
- }, "sdk_replay_compression_seconds"), l = !0;
583
+ }, "sdk_replay_compression_seconds"), c = !0;
582
584
  }
583
- if (h - p < tt) return d.debug("ReplayTooShort"), null;
584
- const E = o.encode("]");
585
- return i.write(E), i.close(), s = new Uint8Array(await new Response(c.readable).arrayBuffer()), s;
586
- })(n - e, n);
587
- }, Te = async (e) => {
588
- const { surveyId: t, responseGroupId: n, visitorId: a, apiUrl: r, completeUploadHeaders: o, replayParams: s, triggerTimestamp: c } = e, i = await zt(1e3 * s.replayDurationSeconds, c);
585
+ if (h - p < nt) return d.debug("ReplayTooShort"), null;
586
+ const T = s.encode("]");
587
+ return i.write(T), i.close(), o = new Uint8Array(await new Response(l.readable).arrayBuffer()), o;
588
+ })(a - e, a);
589
+ }, Pe = async (e) => {
590
+ const { surveyId: t, responseGroupId: a, visitorId: n, apiUrl: r, completeUploadHeaders: s, replayParams: o, triggerTimestamp: l } = e, i = await Qt(1e3 * o.replayDurationSeconds, l);
589
591
  if (!(i != null && i.length)) return void d.info("FileDataEmpty", { surveyId: t });
590
- const l = ((p, h, w) => {
591
- const E = p.length, T = 1024 * h * 1024, f = Math.ceil(E / w), v = Math.max(T, f), S = [];
592
- let R = 0;
593
- for (; R < E; ) S.push(p.slice(R, R + v)), R += v;
592
+ const c = ((p, h, y) => {
593
+ const T = p.length, P = 1024 * h * 1024, f = Math.ceil(T / y), v = Math.max(P, f), S = [];
594
+ let E = 0;
595
+ for (; E < T; ) S.push(p.slice(E, E + v)), E += v;
594
596
  return S;
595
- })(i, s.minimumChunkSizeMb, s.signedUrls.length), y = await Promise.all(l.map(async (p, h) => {
596
- const w = X(), E = { apiUrl: r, chunkIndex: h + 1, completeUploadHeaders: o, etag: null, responseGroupId: n, status: "ReadyForUpload", surveyId: t, timestamp: c, totalChunks: l.length, data: p, uploadId: s.uploadId, uploadUrl: s.signedUrls[h].url, uuid: w, visitorId: a };
597
- return await (await u.openDB()).add("chunkUploads", { ...E, sessionId: E.sessionId ?? I }), E;
597
+ })(i, o.minimumChunkSizeMb, o.signedUrls.length), w = await Promise.all(c.map(async (p, h) => {
598
+ const y = X(), T = { apiUrl: r, chunkIndex: h + 1, completeUploadHeaders: s, etag: null, responseGroupId: a, status: "ReadyForUpload", surveyId: t, timestamp: l, totalChunks: c.length, data: p, uploadId: o.uploadId, uploadUrl: o.signedUrls[h].url, uuid: y, visitorId: n };
599
+ return await (await u.openDB()).add("chunkUploads", { ...T, sessionId: T.sessionId ?? I }), T;
598
600
  }));
599
601
  await (async (p, h) => {
600
- await nt(h), await Promise.all(p.map((w) => at(w)));
601
- })([s.uploadId], y);
602
- }, rt = async (e, t) => {
603
- if (P()) return d.debug("ReplayDisabled-ScheduleOrCapture");
604
- const { isHeatmap: n, isStandalone: a, replayParams: r, triggerTimestamp: o, responseGroupId: s } = e, c = async () => {
605
- setTimeout(() => V.removeListener(Y.QuestionAnswered, c), 0), D(async () => {
606
- r.replayDurationType === "before" ? await Te(e) : await u.markPendingCaptureToCanUpload(s);
602
+ await rt(h), await Promise.all(p.map((y) => st(y)));
603
+ })([o.uploadId], w);
604
+ }, ot = async (e, t) => {
605
+ if (C()) return d.debug("ReplayDisabled-ScheduleOrCapture");
606
+ const { isHeatmap: a, isStandalone: n, replayParams: r, triggerTimestamp: s, responseGroupId: o } = e, l = async () => {
607
+ setTimeout(() => V.removeListener(Y.QuestionAnswered, l), 0), b(async () => {
608
+ r.replayDurationType === "before" ? await Pe(e) : await u.markPendingCaptureToCanUpload(o);
607
609
  }, "Error in schedule/capture callback");
608
610
  };
609
- D(async () => {
611
+ b(async () => {
610
612
  if (r.replayDurationType === "after" || r.replayDurationType === "beforeAndAfter")
611
- return !a && !n && V.on(Y.QuestionAnswered, c), void await st(e);
612
- if (a || n || t) await Te(e), n && qt();
613
+ return !n && !a && V.on(Y.QuestionAnswered, l), void await dt(e);
614
+ if (n || a || t) await Pe(e), a && Xt();
613
615
  else {
614
- const i = 35 + r.replayDurationSeconds, l = o - 1e3 * i, y = o;
615
- await u.updateEventsExpiredAt(l, y, r.expirationTimeLimitMinutes), V.on(Y.QuestionAnswered, c);
616
+ const i = 35 + r.replayDurationSeconds, c = s - 1e3 * i, w = s;
617
+ await u.updateEventsExpiredAt(c, w, r.expirationTimeLimitMinutes), V.on(Y.QuestionAnswered, l);
616
618
  }
617
619
  }, "Error in scheduling/capturing replay");
618
- }, qt = async () => {
619
- parseInt(_ ?? "0") || m.removeItem("sprig.isCapturingHeatmap"), m.getItem("sprig.teardownAfterCapture") && (Ge(), ot(), m.removeItem("sprig.teardownAfterCapture"));
620
- }, ot = async () => P() ? d.debug("ReplayDisabled-ClearData") : Promise.all([u.deleteBySessionId("events", I), u.deleteBySessionId("pendingCaptures", I)]).catch((e) => {
620
+ }, Xt = async () => {
621
+ parseInt(_ ?? "0") || m.removeItem("sprig.isCapturingHeatmap"), m.getItem("sprig.teardownAfterCapture") && ($e(), it(), m.removeItem("sprig.teardownAfterCapture"));
622
+ }, it = async () => C() ? d.debug("ReplayDisabled-ClearData") : Promise.all([u.deleteBySessionId("events", I), u.deleteBySessionId("pendingCaptures", I)]).catch((e) => {
621
623
  H("Error clearing user replay data", e);
622
- }), st = async (e) => {
623
- if (P()) return;
624
- const { isHeatmap: t, surveyId: n } = e, a = await u.getPendingCaptures(), r = a == null ? void 0 : a.filter((i) => i.captureParams.surveyId === n);
625
- if (r != null && r.length) return void d.info("PendingCaptureExists", { surveyId: n });
624
+ }), dt = async (e) => {
625
+ if (C()) return;
626
+ const { isHeatmap: t, surveyId: a } = e, n = await u.getPendingCaptures(), r = n == null ? void 0 : n.filter((i) => i.captureParams.surveyId === a);
627
+ if (r != null && r.length) return void d.info("PendingCaptureExists", { surveyId: a });
626
628
  t && (ue(), m.setItem("sprig.isCapturingHeatmap", "true"), ge = Date.now(), g.inactivityInterval || (g.inactivityInterval = window.setInterval(() => {
627
629
  var i;
628
- i = ge, Date.now() - i >= 3e4 && D(() => u.markPendingHeatmapsReady(), "Error in heatmap inactivity");
630
+ i = ge, Date.now() - i >= 3e4 && b(() => u.markPendingHeatmapsReady(), "Error in heatmap inactivity");
629
631
  }, 1e3)));
630
- const o = { ...e, replayParams: { ...e.replayParams } };
631
- e.replayParams.replayDurationType === "beforeAndAfter" && (o.replayParams.replayDurationSeconds *= 2), o.replayParams.replayDurationType = "before";
632
- const s = e.triggerTimestamp + 1e3 * e.replayParams.replayDurationSeconds;
633
- o.triggerTimestamp = s, _ = (parseInt(_ ?? "0") + 1).toString(), m.setItem("sprig.pendingCount", _), await (await u.openDB()).add("pendingCaptures", { canUpload: !1, captureParams: o, sessionId: I, targetTimestamp: s, timestamp: Date.now(), uuid: X() });
634
- }, Qt = Object.freeze(Object.defineProperty({ __proto__: null, RecordEvent: (e) => {
632
+ const s = { ...e, replayParams: { ...e.replayParams } };
633
+ e.replayParams.replayDurationType === "beforeAndAfter" && (s.replayParams.replayDurationSeconds *= 2), s.replayParams.replayDurationType = "before";
634
+ const o = e.triggerTimestamp + 1e3 * e.replayParams.replayDurationSeconds;
635
+ s.triggerTimestamp = o, _ = (parseInt(_ ?? "0") + 1).toString(), m.setItem("sprig.pendingCount", _), await (await u.openDB()).add("pendingCaptures", { canUpload: !1, captureParams: s, sessionId: I, targetTimestamp: o, timestamp: Date.now(), uuid: X() });
636
+ }, Yt = Object.freeze(Object.defineProperty({ __proto__: null, RecordEvent: (e) => {
635
637
  U("Sprig_TrackEvent", e);
636
638
  }, RecordPageView: (e) => {
637
639
  e.description && (e.description = he(e.description)), U("Sprig_PageView", e);
638
640
  }, RecordSurveyShown: (e) => {
639
641
  U("Sprig_ShowSurvey", e);
640
- }, _completeSessionReplay: async ({ surveyId: e, responseGroupUuid: t, eventDigest: n, headers: a }) => {
642
+ }, _completeSessionReplay: async ({ surveyId: e, responseGroupUuid: t, eventDigest: a, headers: n }) => {
641
643
  if (!e || !t) return !1;
642
- const r = window.UserLeap._API_URL, o = await _e({ surveyId: e, responseGroupUuid: t, eventDigest: n, apiUrl: r, headers: a }, !0);
643
- return !(o != null && o.error);
644
- }, checkPendingHeatmapsUrl: () => P() ? d.debug("ReplayDisabled-PendingHeatmaps") : D(async () => {
645
- const e = (await u.getPendingCaptures({ isHeatmap: !0 })).map((t) => ({ eventId: t.captureParams.eventId, uuid: t.uuid })).filter(({ eventId: t }) => !ct(t)).map(({ uuid: t }) => t);
644
+ const r = globalThis.UserLeap._API_URL, s = await Ne({ surveyId: e, responseGroupUuid: t, eventDigest: a, apiUrl: r, headers: n }, !0);
645
+ return !(s != null && s.error);
646
+ }, checkPendingHeatmapsUrl: () => C() ? d.debug("ReplayDisabled-PendingHeatmaps") : b(async () => {
647
+ const e = (await u.getPendingCaptures({ isHeatmap: !0 })).map((t) => ({ eventId: t.captureParams.eventId, uuid: t.uuid })).filter(({ eventId: t }) => !ut(t)).map(({ uuid: t }) => t);
646
648
  return d.info("PendingHeatmapsToComplete", { count: e.length }), e.length && (await u.markPendingHeatmapsReady(e), d.info("MarkedPendingHeatmapsReady")), e.length;
647
- }, "Error marking pending heatmaps ready"), clearUserReplayData: ot, disableRecording: H, initializeReplay: async ({ maxReplayDurationSeconds: e, maxInflightRequests: t = 2, replaySettings: n, teardownAfter: a = !1, apiUrl: r, alwaysOnConfig: o }) => {
648
- if (o && _t({ apiUrl: r, config: o, triggerSnapshot: () => {
649
+ }, "Error marking pending heatmaps ready"), clearUserReplayData: it, disableRecording: H, initializeReplay: async ({ maxReplayDurationSeconds: e, maxInflightRequests: t = 2, replaySettings: a, teardownAfter: n = !1, apiUrl: r, alwaysOnConfig: s }) => {
650
+ if (s && Nt({ apiUrl: r, config: s, triggerSnapshot: () => {
649
651
  ue();
650
652
  } }), _ = m.getItem("sprig.pendingCount"), g.isRecording) return;
651
- if (a && m.setItem("sprig.teardownAfterCapture", "true"), P()) return d.debug("ReplayDisabled");
653
+ if (n && m.setItem("sprig.teardownAfterCapture", "true"), C()) return d.debug("ReplayDisabled");
652
654
  if (await (async () => {
653
655
  var i;
654
- if (!Ve()) return !0;
655
- if ((i = window.navigator.storage) != null && i.estimate) try {
656
- const { quota: l = 0, usage: y = 0 } = await window.navigator.storage.estimate(), p = (l - y) / 1024 ** 3;
656
+ if (!We()) return !0;
657
+ if ((i = globalThis.navigator.storage) != null && i.estimate) try {
658
+ const { quota: c = 0, usage: w = 0 } = await globalThis.navigator.storage.estimate(), p = (c - w) / 1024 ** 3;
657
659
  return d.info("Storage", { availableGb: p }), p < 0.5;
658
660
  } catch {
659
661
  return !0;
660
662
  }
661
663
  return !1;
662
- })()) return d.debug("IDBNotSupported"), le();
664
+ })()) return d.debug("IDBNotSupported"), ce();
663
665
  try {
664
666
  const i = await u.openDB();
665
667
  d.info("DBVersion", { version: i.version });
666
668
  } catch (i) {
667
- return d.error("ReplayOpenErr", { name: i.name }), i.name === "VersionError" && u.deleteDB(), le();
669
+ return d.error("ReplayOpenErr", { name: i.name }), i.name === "VersionError" && u.deleteDB(), ce();
668
670
  }
669
- D(async () => {
670
- await ye(!0);
671
+ b(async () => {
672
+ await we(!0);
671
673
  }, "Error uploading ready pending captures");
672
- const s = O() ? 30 : 0, c = Math.max(e ?? 0, s);
673
- if (!c) return d.debug("MissingDuration");
674
- d.debug("ReplayInit"), await D(async () => {
674
+ const o = O() ? 30 : 0, l = Math.max(e ?? 0, o);
675
+ if (!l) return d.debug("MissingDuration");
676
+ d.debug("ReplayInit"), await b(async () => {
675
677
  var i;
676
- n != null && n.minDuration && (tt = n.minDuration), n != null && n.batchDuration && (pe = n.batchDuration), i = t, Me.setLimit(i), Jt(), Wt(c + 35, 1800, c + 35), $t();
677
- const l = window.UserLeap.replayLibraryURL ?? "https://cdn.sprig.com/dependencies/record.min.js";
678
+ a != null && a.minDuration && (nt = a.minDuration), a != null && a.batchDuration && (pe = a.batchDuration), i = t, Ae.setLimit(i), qt(), Kt(l + 35, 1800, l + 35), Jt();
679
+ const c = window.UserLeap.replayLibraryURL ?? "https://cdn.sprig.com/dependencies/record.min.js";
678
680
  if (!window.rrwebRecord) {
679
681
  const { record: f } = await import(
680
682
  /* webpackIgnore: true */
681
683
  /* @vite-ignore */
682
- l
684
+ c
683
685
  );
684
686
  window.rrwebRecord = f;
685
687
  }
686
- const y = window.rrwebRecord;
687
- if (!y) return d.error("RecordScriptFailed");
688
+ const w = window.rrwebRecord;
689
+ if (!w) return d.error("RecordScriptFailed");
688
690
  let p = !0, h = 0;
689
- const w = { checkoutEveryNms: 3e4, sampling: { input: "last", scroll: 250, media: 800 }, ...n, mutationQueueEnabled: n == null ? void 0 : n.enableMutationQueue };
690
- var E, T;
691
- g.stopRecording = y({ emit: (f, v) => {
692
- if (f.type === B.Custom && (ge = Date.now()), P() || z()) return;
691
+ const y = { checkoutEveryNms: 3e4, sampling: { input: "last", scroll: 250, media: 800 }, ...a, mutationQueueEnabled: a == null ? void 0 : a.enableMutationQueue };
692
+ var T, P;
693
+ g.stopRecording = w({ emit: (f, v) => {
694
+ if (f.type === B.Custom && (ge = Date.now()), C() || z()) return;
693
695
  if (v && f.type === B.Meta) h = performance.now();
694
696
  else if (v && h && f.type === B.FullSnapshot) {
695
- const R = performance.now() - h;
696
- ut("sdk_replay_snapshot_seconds", R / 1e3);
697
+ const E = performance.now() - h;
698
+ gt("sdk_replay_snapshot_seconds", E / 1e3);
697
699
  }
698
700
  const S = p || !!v && f.type === B.Meta;
699
- p = !1, jt(S, f), Vt({ uuid: X(), event: JSON.stringify(f), isValidStart: S, timestamp: Date.now() });
700
- }, ...w }), g.isRecording = !!g.stopRecording, g.isRecording && (((f, v) => {
701
+ p = !1, Gt(S, f), Wt({ uuid: X(), event: JSON.stringify(f), isValidStart: S, timestamp: Date.now() });
702
+ }, ...y }), g.isRecording = !!g.stopRecording, g.isRecording && (((f, v) => {
701
703
  window.addEventListener("message", (S) => {
702
- var R;
703
- S.data.type === St && (fe.push({ source: S.source, origin: S.origin }), (R = S.source) == null || R.postMessage({ type: Dt, settings: f, replayLibraryUrl: v }, { targetOrigin: S.origin }));
704
+ var E;
705
+ S.data.type === Dt && (fe.push({ source: S.source, origin: S.origin }), (E = S.source) == null || E.postMessage({ type: Tt, settings: f, replayLibraryUrl: v }, { targetOrigin: S.origin }));
704
706
  });
705
- })(w, l), V.on("survey.complete", (f) => {
707
+ })(y, c), V.on("survey.complete", (f) => {
706
708
  var v;
707
709
  v = { id: f, userAgent: window.navigator.userAgent }, U("Sprig_SubmitSurvey", v);
708
- }), E = U, T = xt, J || (b = E, G = T, window.addEventListener("click", Fe, C), window.addEventListener("pointerdown", je, C), window.addEventListener("mousedown", He, C), window.addEventListener("keydown", Le, C), window.addEventListener("scroll", Oe, C), J = !0, kt(), Ut()));
710
+ }), T = U, P = Mt, J || (D = T, G = P, window.addEventListener("click", je, R), window.addEventListener("pointerdown", Ge, R), window.addEventListener("mousedown", Ve, R), window.addEventListener("keydown", Fe, R), window.addEventListener("scroll", He, R), J = !0, xt(), Bt()));
709
711
  }, "Error initializing replay");
710
712
  }, isReplayPaused: z, isReplayRecording: () => g.isRecording, recordFullSnapshot: ue, recordReplayPaused: () => {
711
713
  U("Sprig_ReplayPaused", { timestamp: Date.now() }), m.setItem("sprig.isReplayPaused", "true");
712
714
  }, recordReplayResumed: () => {
713
715
  m.removeItem("sprig.isReplayPaused"), U("Sprig_ReplayResumed", { timestamp: Date.now() });
714
- }, scheduleCapture: st, scheduleOrCaptureReplay: rt, tryReplayAction: D, uploadReadyPendingCaptures: ye }, Symbol.toStringTag, { value: "Module" }));
715
- pt(Qt);
716
+ }, scheduleCapture: dt, scheduleOrCaptureReplay: ot, tryReplayAction: b, uploadReadyPendingCaptures: we }, Symbol.toStringTag, { value: "Module" }));
717
+ mt(Yt);