@stacksee/analytics 0.2.2 → 0.3.2

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.
@@ -0,0 +1,2611 @@
1
+ var se = Object.defineProperty;
2
+ var ae = (s, r, e) => r in s ? se(s, r, { enumerable: !0, configurable: !0, writable: !0, value: e }) : s[r] = e;
3
+ var L = (s, r, e) => ae(s, typeof r != "symbol" ? r + "" : r, e);
4
+ class X {
5
+ constructor(r) {
6
+ L(this, "debug", !1);
7
+ L(this, "enabled", !0);
8
+ (r == null ? void 0 : r.debug) !== void 0 && (this.debug = r.debug), (r == null ? void 0 : r.enabled) !== void 0 && (this.enabled = r.enabled);
9
+ }
10
+ log(r, e) {
11
+ this.debug && console.log(`[${this.name}] ${r}`, e);
12
+ }
13
+ isEnabled() {
14
+ return this.enabled;
15
+ }
16
+ }
17
+ class xe extends X {
18
+ constructor(e) {
19
+ super({ debug: e.debug, enabled: e.enabled });
20
+ L(this, "name", "PostHog-Client");
21
+ L(this, "posthog");
22
+ L(this, "initialized", !1);
23
+ L(this, "config");
24
+ this.config = e;
25
+ }
26
+ async initialize() {
27
+ if (this.isEnabled() && !this.initialized) {
28
+ if (!this.config.apiKey || typeof this.config.apiKey != "string")
29
+ throw new Error("PostHog requires an apiKey");
30
+ try {
31
+ const { default: e } = await import("./module-BfXpy-Wp.js");
32
+ e.init(this.config.apiKey, {
33
+ api_host: this.config.host || "https://app.posthog.com",
34
+ autocapture: this.config.autocapture ?? !1,
35
+ capture_pageview: this.config.capturePageview ?? !1,
36
+ capture_pageleave: this.config.capturePageleave ?? !1,
37
+ debug: this.config.debug ?? this.debug,
38
+ disable_cookie: this.config.disableCookie ?? !1,
39
+ persistence: this.config.persistenceType ?? "localStorage",
40
+ person_profiles: this.config.personProfiles ?? "identified_only"
41
+ }), this.posthog = e, window.posthog = e, this.initialized = !0, this.log("Initialized successfully", this.config);
42
+ } catch (e) {
43
+ throw console.error("[PostHog-Client] Failed to initialize:", e), e;
44
+ }
45
+ }
46
+ }
47
+ identify(e, t) {
48
+ !this.isEnabled() || !this.initialized || !this.posthog || (this.posthog.identify(e, t), this.log("Identified user", { userId: e, traits: t }));
49
+ }
50
+ track(e, t) {
51
+ if (!this.isEnabled() || !this.initialized || !this.posthog) return;
52
+ const n = {
53
+ ...e.properties,
54
+ category: e.category,
55
+ timestamp: e.timestamp || Date.now(),
56
+ ...e.userId && { userId: e.userId },
57
+ ...e.sessionId && { sessionId: e.sessionId },
58
+ ...(t == null ? void 0 : t.page) && { $current_url: t.page.path },
59
+ ...(t == null ? void 0 : t.device) && { device: t.device },
60
+ ...(t == null ? void 0 : t.utm) && { utm: t.utm }
61
+ };
62
+ this.posthog.capture(e.action, n), this.log("Tracked event", { event: e, context: t });
63
+ }
64
+ page(e, t) {
65
+ if (!this.isEnabled() || !this.initialized || !this.posthog) return;
66
+ const n = {
67
+ ...e,
68
+ ...(t == null ? void 0 : t.page) && {
69
+ path: t.page.path,
70
+ title: t.page.title,
71
+ referrer: t.page.referrer
72
+ }
73
+ };
74
+ this.posthog.capture("$pageview", n), this.log("Tracked page view", { properties: e, context: t });
75
+ }
76
+ reset() {
77
+ !this.isEnabled() || !this.initialized || !this.posthog || (this.posthog.reset(), this.log("Reset user session"));
78
+ }
79
+ }
80
+ var D = { exports: {} }, ue = D.exports, K;
81
+ function le() {
82
+ return K || (K = 1, function(s, r) {
83
+ (function(t, n) {
84
+ s.exports = n();
85
+ })(typeof self < "u" ? self : ue, function() {
86
+ return (
87
+ /******/
88
+ function(e) {
89
+ var t = {};
90
+ function n(i) {
91
+ if (t[i])
92
+ return t[i].exports;
93
+ var o = t[i] = {
94
+ /******/
95
+ i,
96
+ /******/
97
+ l: !1,
98
+ /******/
99
+ exports: {}
100
+ /******/
101
+ };
102
+ return e[i].call(o.exports, o, o.exports, n), o.l = !0, o.exports;
103
+ }
104
+ return n.m = e, n.c = t, n.d = function(i, o, u) {
105
+ n.o(i, o) || Object.defineProperty(i, o, {
106
+ /******/
107
+ configurable: !1,
108
+ /******/
109
+ enumerable: !0,
110
+ /******/
111
+ get: u
112
+ /******/
113
+ });
114
+ }, n.n = function(i) {
115
+ var o = i && i.__esModule ? (
116
+ /******/
117
+ function() {
118
+ return i.default;
119
+ }
120
+ ) : (
121
+ /******/
122
+ function() {
123
+ return i;
124
+ }
125
+ );
126
+ return n.d(o, "a", o), o;
127
+ }, n.o = function(i, o) {
128
+ return Object.prototype.hasOwnProperty.call(i, o);
129
+ }, n.p = "", n(n.s = 3);
130
+ }([
131
+ /* 0 */
132
+ /***/
133
+ function(e, t, n) {
134
+ function i(p, w) {
135
+ if (!(p instanceof w))
136
+ throw new TypeError("Cannot call a class as a function");
137
+ }
138
+ var o = n(5), u = n(1), l = u.toHex, c = u.ceilHeapSize, h = n(6), g = function(p) {
139
+ for (p += 9; p % 64 > 0; p += 1)
140
+ ;
141
+ return p;
142
+ }, d = function(p, w) {
143
+ var y = new Uint8Array(p.buffer), m = w % 4, b = w - m;
144
+ switch (m) {
145
+ case 0:
146
+ y[b + 3] = 0;
147
+ case 1:
148
+ y[b + 2] = 0;
149
+ case 2:
150
+ y[b + 1] = 0;
151
+ case 3:
152
+ y[b + 0] = 0;
153
+ }
154
+ for (var P = (w >> 2) + 1; P < p.length; P++)
155
+ p[P] = 0;
156
+ }, f = function(p, w, y) {
157
+ p[w >> 2] |= 128 << 24 - (w % 4 << 3), p[((w >> 2) + 2 & -16) + 14] = y / (1 << 29) | 0, p[((w >> 2) + 2 & -16) + 15] = y << 3;
158
+ }, a = function(p, w) {
159
+ var y = new Int32Array(p, w + 320, 5), m = new Int32Array(5), b = new DataView(m.buffer);
160
+ return b.setInt32(0, y[0], !1), b.setInt32(4, y[1], !1), b.setInt32(8, y[2], !1), b.setInt32(12, y[3], !1), b.setInt32(16, y[4], !1), m;
161
+ }, v = function() {
162
+ function p(w) {
163
+ if (i(this, p), w = w || 64 * 1024, w % 64 > 0)
164
+ throw new Error("Chunk size must be a multiple of 128 bit");
165
+ this._offset = 0, this._maxChunkLen = w, this._padMaxChunkLen = g(w), this._heap = new ArrayBuffer(c(this._padMaxChunkLen + 320 + 20)), this._h32 = new Int32Array(this._heap), this._h8 = new Int8Array(this._heap), this._core = new o({ Int32Array }, {}, this._heap);
166
+ }
167
+ return p.prototype._initState = function(y, m) {
168
+ this._offset = 0;
169
+ var b = new Int32Array(y, m + 320, 5);
170
+ b[0] = 1732584193, b[1] = -271733879, b[2] = -1732584194, b[3] = 271733878, b[4] = -1009589776;
171
+ }, p.prototype._padChunk = function(y, m) {
172
+ var b = g(y), P = new Int32Array(this._heap, 0, b >> 2);
173
+ return d(P, y), f(P, y, m), b;
174
+ }, p.prototype._write = function(y, m, b, P) {
175
+ h(y, this._h8, this._h32, m, b, P || 0);
176
+ }, p.prototype._coreCall = function(y, m, b, P, S) {
177
+ var I = b;
178
+ this._write(y, m, b), S && (I = this._padChunk(b, P)), this._core.hash(I, this._padMaxChunkLen);
179
+ }, p.prototype.rawDigest = function(y) {
180
+ var m = y.byteLength || y.length || y.size || 0;
181
+ this._initState(this._heap, this._padMaxChunkLen);
182
+ var b = 0, P = this._maxChunkLen;
183
+ for (b = 0; m > b + P; b += P)
184
+ this._coreCall(y, b, P, m, !1);
185
+ return this._coreCall(y, b, m - b, m, !0), a(this._heap, this._padMaxChunkLen);
186
+ }, p.prototype.digest = function(y) {
187
+ return l(this.rawDigest(y).buffer);
188
+ }, p.prototype.digestFromString = function(y) {
189
+ return this.digest(y);
190
+ }, p.prototype.digestFromBuffer = function(y) {
191
+ return this.digest(y);
192
+ }, p.prototype.digestFromArrayBuffer = function(y) {
193
+ return this.digest(y);
194
+ }, p.prototype.resetState = function() {
195
+ return this._initState(this._heap, this._padMaxChunkLen), this;
196
+ }, p.prototype.append = function(y) {
197
+ var m = 0, b = y.byteLength || y.length || y.size || 0, P = this._offset % this._maxChunkLen, S = void 0;
198
+ for (this._offset += b; m < b; )
199
+ S = Math.min(b - m, this._maxChunkLen - P), this._write(y, m, S, P), P += S, m += S, P === this._maxChunkLen && (this._core.hash(this._maxChunkLen, this._padMaxChunkLen), P = 0);
200
+ return this;
201
+ }, p.prototype.getState = function() {
202
+ var y = this._offset % this._maxChunkLen, m = void 0;
203
+ if (y)
204
+ m = this._heap.slice(0);
205
+ else {
206
+ var b = new Int32Array(this._heap, this._padMaxChunkLen + 320, 5);
207
+ m = b.buffer.slice(b.byteOffset, b.byteOffset + b.byteLength);
208
+ }
209
+ return {
210
+ offset: this._offset,
211
+ heap: m
212
+ };
213
+ }, p.prototype.setState = function(y) {
214
+ if (this._offset = y.offset, y.heap.byteLength === 20) {
215
+ var m = new Int32Array(this._heap, this._padMaxChunkLen + 320, 5);
216
+ m.set(new Int32Array(y.heap));
217
+ } else
218
+ this._h32.set(new Int32Array(y.heap));
219
+ return this;
220
+ }, p.prototype.rawEnd = function() {
221
+ var y = this._offset, m = y % this._maxChunkLen, b = this._padChunk(m, y);
222
+ this._core.hash(b, this._padMaxChunkLen);
223
+ var P = a(this._heap, this._padMaxChunkLen);
224
+ return this._initState(this._heap, this._padMaxChunkLen), P;
225
+ }, p.prototype.end = function() {
226
+ return l(this.rawEnd().buffer);
227
+ }, p;
228
+ }();
229
+ e.exports = v, e.exports._core = o;
230
+ },
231
+ /* 1 */
232
+ /***/
233
+ function(e, t) {
234
+ for (var n = new Array(256), i = 0; i < 256; i++)
235
+ n[i] = (i < 16 ? "0" : "") + i.toString(16);
236
+ e.exports.toHex = function(o) {
237
+ for (var u = new Uint8Array(o), l = new Array(o.byteLength), c = 0; c < l.length; c++)
238
+ l[c] = n[u[c]];
239
+ return l.join("");
240
+ }, e.exports.ceilHeapSize = function(o) {
241
+ var u = 0;
242
+ if (o <= 65536) return 65536;
243
+ if (o < 16777216)
244
+ for (u = 1; u < o; u = u << 1)
245
+ ;
246
+ else
247
+ for (u = 16777216; u < o; u += 16777216)
248
+ ;
249
+ return u;
250
+ }, e.exports.isDedicatedWorkerScope = function(o) {
251
+ var u = "WorkerGlobalScope" in o && o instanceof o.WorkerGlobalScope, l = "SharedWorkerGlobalScope" in o && o instanceof o.SharedWorkerGlobalScope, c = "ServiceWorkerGlobalScope" in o && o instanceof o.ServiceWorkerGlobalScope;
252
+ return u && !l && !c;
253
+ };
254
+ },
255
+ /* 2 */
256
+ /***/
257
+ function(e, t, n) {
258
+ e.exports = function() {
259
+ var i = n(0), o = function(c, h, g) {
260
+ try {
261
+ return g(null, c.digest(h));
262
+ } catch (d) {
263
+ return g(d);
264
+ }
265
+ }, u = function(c, h, g, d, f) {
266
+ var a = new self.FileReader();
267
+ a.onloadend = function() {
268
+ if (a.error)
269
+ return f(a.error);
270
+ var p = a.result;
271
+ h += a.result.byteLength;
272
+ try {
273
+ c.append(p);
274
+ } catch (w) {
275
+ f(w);
276
+ return;
277
+ }
278
+ h < d.size ? u(c, h, g, d, f) : f(null, c.end());
279
+ }, a.readAsArrayBuffer(d.slice(h, h + g));
280
+ }, l = !0;
281
+ return self.onmessage = function(c) {
282
+ if (l) {
283
+ var h = c.data.data, g = c.data.file, d = c.data.id;
284
+ if (!(typeof d > "u") && !(!g && !h)) {
285
+ var f = c.data.blockSize || 4 * 1024 * 1024, a = new i(f);
286
+ a.resetState();
287
+ var v = function(p, w) {
288
+ p ? self.postMessage({ id: d, error: p.name }) : self.postMessage({ id: d, hash: w });
289
+ };
290
+ h && o(a, h, v), g && u(a, 0, f, g, v);
291
+ }
292
+ }
293
+ }, function() {
294
+ l = !1;
295
+ };
296
+ };
297
+ },
298
+ /* 3 */
299
+ /***/
300
+ function(e, t, n) {
301
+ var i = n(4), o = n(0), u = n(7), l = n(2), c = n(1), h = c.isDedicatedWorkerScope, g = typeof self < "u" && h(self);
302
+ o.disableWorkerBehaviour = g ? l() : function() {
303
+ }, o.createWorker = function() {
304
+ var d = i(
305
+ /*require.resolve*/
306
+ 2
307
+ ), f = d.terminate;
308
+ return d.terminate = function() {
309
+ URL.revokeObjectURL(d.objectURL), f.call(d);
310
+ }, d;
311
+ }, o.createHash = u, e.exports = o;
312
+ },
313
+ /* 4 */
314
+ /***/
315
+ function(e, t, n) {
316
+ function i(d) {
317
+ var f = {};
318
+ function a(p) {
319
+ if (f[p])
320
+ return f[p].exports;
321
+ var w = f[p] = {
322
+ /******/
323
+ i: p,
324
+ /******/
325
+ l: !1,
326
+ /******/
327
+ exports: {}
328
+ /******/
329
+ };
330
+ return d[p].call(w.exports, w, w.exports, a), w.l = !0, w.exports;
331
+ }
332
+ a.m = d, a.c = f, a.i = function(p) {
333
+ return p;
334
+ }, a.d = function(p, w, y) {
335
+ a.o(p, w) || Object.defineProperty(p, w, {
336
+ /******/
337
+ configurable: !1,
338
+ /******/
339
+ enumerable: !0,
340
+ /******/
341
+ get: y
342
+ /******/
343
+ });
344
+ }, a.r = function(p) {
345
+ Object.defineProperty(p, "__esModule", { value: !0 });
346
+ }, a.n = function(p) {
347
+ var w = p && p.__esModule ? (
348
+ /******/
349
+ function() {
350
+ return p.default;
351
+ }
352
+ ) : (
353
+ /******/
354
+ function() {
355
+ return p;
356
+ }
357
+ );
358
+ return a.d(w, "a", w), w;
359
+ }, a.o = function(p, w) {
360
+ return Object.prototype.hasOwnProperty.call(p, w);
361
+ }, a.p = "/", a.oe = function(p) {
362
+ throw console.error(p), p;
363
+ };
364
+ var v = a(a.s = ENTRY_MODULE);
365
+ return v.default || v;
366
+ }
367
+ var o = "[\\.|\\-|\\+|\\w|/|@]+", u = "\\((/\\*.*?\\*/)?s?.*?(" + o + ").*?\\)";
368
+ function l(d) {
369
+ return (d + "").replace(/[.?*+^$[\]\\(){}|-]/g, "\\$&");
370
+ }
371
+ function c(d, f, a) {
372
+ var v = {};
373
+ v[a] = [];
374
+ var p = f.toString(), w = p.match(/^function\s?\(\w+,\s*\w+,\s*(\w+)\)/);
375
+ if (!w) return v;
376
+ for (var y = w[1], m = new RegExp("(\\\\n|\\W)" + l(y) + u, "g"), b; b = m.exec(p); )
377
+ b[3] !== "dll-reference" && v[a].push(b[3]);
378
+ for (m = new RegExp("\\(" + l(y) + '\\("(dll-reference\\s(' + o + '))"\\)\\)' + u, "g"); b = m.exec(p); )
379
+ d[b[2]] || (v[a].push(b[1]), d[b[2]] = n(b[1]).m), v[b[2]] = v[b[2]] || [], v[b[2]].push(b[4]);
380
+ return v;
381
+ }
382
+ function h(d) {
383
+ var f = Object.keys(d);
384
+ return f.reduce(function(a, v) {
385
+ return a || d[v].length > 0;
386
+ }, !1);
387
+ }
388
+ function g(d, f) {
389
+ for (var a = {
390
+ main: [f]
391
+ }, v = {
392
+ main: []
393
+ }, p = {
394
+ main: {}
395
+ }; h(a); )
396
+ for (var w = Object.keys(a), y = 0; y < w.length; y++) {
397
+ var m = w[y], b = a[m], P = b.pop();
398
+ if (p[m] = p[m] || {}, !(p[m][P] || !d[m][P])) {
399
+ p[m][P] = !0, v[m] = v[m] || [], v[m].push(P);
400
+ for (var S = c(d, d[m][P], m), I = Object.keys(S), O = 0; O < I.length; O++)
401
+ a[I[O]] = a[I[O]] || [], a[I[O]] = a[I[O]].concat(S[I[O]]);
402
+ }
403
+ }
404
+ return v;
405
+ }
406
+ e.exports = function(d, f) {
407
+ f = f || {};
408
+ var a = {
409
+ main: n.m
410
+ }, v = f.all ? { main: Object.keys(a) } : g(a, d), p = "";
411
+ Object.keys(v).filter(function(P) {
412
+ return P !== "main";
413
+ }).forEach(function(P) {
414
+ for (var S = 0; v[P][S]; )
415
+ S++;
416
+ v[P].push(S), a[P][S] = "(function(module, exports, __webpack_require__) { module.exports = __webpack_require__; })", p = p + "var " + P + " = (" + i.toString().replace("ENTRY_MODULE", JSON.stringify(S)) + ")({" + v[P].map(function(I) {
417
+ return "" + JSON.stringify(I) + ": " + a[P][I].toString();
418
+ }).join(",") + `});
419
+ `;
420
+ }), p = p + "(" + i.toString().replace("ENTRY_MODULE", JSON.stringify(d)) + ")({" + v.main.map(function(P) {
421
+ return "" + JSON.stringify(P) + ": " + a.main[P].toString();
422
+ }).join(",") + "})(self);";
423
+ var w = new window.Blob([p], { type: "text/javascript" });
424
+ if (f.bare)
425
+ return w;
426
+ var y = window.URL || window.webkitURL || window.mozURL || window.msURL, m = y.createObjectURL(w), b = new window.Worker(m);
427
+ return b.objectURL = m, b;
428
+ };
429
+ },
430
+ /* 5 */
431
+ /***/
432
+ function(e, t) {
433
+ e.exports = function(i, o, u) {
434
+ var l = new i.Int32Array(u);
435
+ function c(h, g) {
436
+ h = h | 0, g = g | 0;
437
+ var d = 0, f = 0, a = 0, v = 0, p = 0, w = 0, y = 0, m = 0, b = 0, P = 0, S = 0, I = 0, O = 0, k = 0;
438
+ for (a = l[g + 320 >> 2] | 0, p = l[g + 324 >> 2] | 0, y = l[g + 328 >> 2] | 0, b = l[g + 332 >> 2] | 0, S = l[g + 336 >> 2] | 0, d = 0; (d | 0) < (h | 0); d = d + 64 | 0) {
439
+ for (v = a, w = p, m = y, P = b, I = S, f = 0; (f | 0) < 64; f = f + 4 | 0)
440
+ k = l[d + f >> 2] | 0, O = ((a << 5 | a >>> 27) + (p & y | ~p & b) | 0) + ((k + S | 0) + 1518500249 | 0) | 0, S = b, b = y, y = p << 30 | p >>> 2, p = a, a = O, l[h + f >> 2] = k;
441
+ for (f = h + 64 | 0; (f | 0) < (h + 80 | 0); f = f + 4 | 0)
442
+ k = (l[f - 12 >> 2] ^ l[f - 32 >> 2] ^ l[f - 56 >> 2] ^ l[f - 64 >> 2]) << 1 | (l[f - 12 >> 2] ^ l[f - 32 >> 2] ^ l[f - 56 >> 2] ^ l[f - 64 >> 2]) >>> 31, O = ((a << 5 | a >>> 27) + (p & y | ~p & b) | 0) + ((k + S | 0) + 1518500249 | 0) | 0, S = b, b = y, y = p << 30 | p >>> 2, p = a, a = O, l[f >> 2] = k;
443
+ for (f = h + 80 | 0; (f | 0) < (h + 160 | 0); f = f + 4 | 0)
444
+ k = (l[f - 12 >> 2] ^ l[f - 32 >> 2] ^ l[f - 56 >> 2] ^ l[f - 64 >> 2]) << 1 | (l[f - 12 >> 2] ^ l[f - 32 >> 2] ^ l[f - 56 >> 2] ^ l[f - 64 >> 2]) >>> 31, O = ((a << 5 | a >>> 27) + (p ^ y ^ b) | 0) + ((k + S | 0) + 1859775393 | 0) | 0, S = b, b = y, y = p << 30 | p >>> 2, p = a, a = O, l[f >> 2] = k;
445
+ for (f = h + 160 | 0; (f | 0) < (h + 240 | 0); f = f + 4 | 0)
446
+ k = (l[f - 12 >> 2] ^ l[f - 32 >> 2] ^ l[f - 56 >> 2] ^ l[f - 64 >> 2]) << 1 | (l[f - 12 >> 2] ^ l[f - 32 >> 2] ^ l[f - 56 >> 2] ^ l[f - 64 >> 2]) >>> 31, O = ((a << 5 | a >>> 27) + (p & y | p & b | y & b) | 0) + ((k + S | 0) - 1894007588 | 0) | 0, S = b, b = y, y = p << 30 | p >>> 2, p = a, a = O, l[f >> 2] = k;
447
+ for (f = h + 240 | 0; (f | 0) < (h + 320 | 0); f = f + 4 | 0)
448
+ k = (l[f - 12 >> 2] ^ l[f - 32 >> 2] ^ l[f - 56 >> 2] ^ l[f - 64 >> 2]) << 1 | (l[f - 12 >> 2] ^ l[f - 32 >> 2] ^ l[f - 56 >> 2] ^ l[f - 64 >> 2]) >>> 31, O = ((a << 5 | a >>> 27) + (p ^ y ^ b) | 0) + ((k + S | 0) - 899497514 | 0) | 0, S = b, b = y, y = p << 30 | p >>> 2, p = a, a = O, l[f >> 2] = k;
449
+ a = a + v | 0, p = p + w | 0, y = y + m | 0, b = b + P | 0, S = S + I | 0;
450
+ }
451
+ l[g + 320 >> 2] = a, l[g + 324 >> 2] = p, l[g + 328 >> 2] = y, l[g + 332 >> 2] = b, l[g + 336 >> 2] = S;
452
+ }
453
+ return { hash: c };
454
+ };
455
+ },
456
+ /* 6 */
457
+ /***/
458
+ function(e, t) {
459
+ var n = this, i = void 0;
460
+ typeof self < "u" && typeof self.FileReaderSync < "u" && (i = new self.FileReaderSync());
461
+ var o = function(c, h, g, d, f, a) {
462
+ var v = void 0, p = a % 4, w = (f + p) % 4, y = f - w;
463
+ switch (p) {
464
+ case 0:
465
+ h[a] = c.charCodeAt(d + 3);
466
+ case 1:
467
+ h[a + 1 - (p << 1) | 0] = c.charCodeAt(d + 2);
468
+ case 2:
469
+ h[a + 2 - (p << 1) | 0] = c.charCodeAt(d + 1);
470
+ case 3:
471
+ h[a + 3 - (p << 1) | 0] = c.charCodeAt(d);
472
+ }
473
+ if (!(f < w + (4 - p))) {
474
+ for (v = 4 - p; v < y; v = v + 4 | 0)
475
+ g[a + v >> 2] = c.charCodeAt(d + v) << 24 | c.charCodeAt(d + v + 1) << 16 | c.charCodeAt(d + v + 2) << 8 | c.charCodeAt(d + v + 3);
476
+ switch (w) {
477
+ case 3:
478
+ h[a + y + 1 | 0] = c.charCodeAt(d + y + 2);
479
+ case 2:
480
+ h[a + y + 2 | 0] = c.charCodeAt(d + y + 1);
481
+ case 1:
482
+ h[a + y + 3 | 0] = c.charCodeAt(d + y);
483
+ }
484
+ }
485
+ }, u = function(c, h, g, d, f, a) {
486
+ var v = void 0, p = a % 4, w = (f + p) % 4, y = f - w;
487
+ switch (p) {
488
+ case 0:
489
+ h[a] = c[d + 3];
490
+ case 1:
491
+ h[a + 1 - (p << 1) | 0] = c[d + 2];
492
+ case 2:
493
+ h[a + 2 - (p << 1) | 0] = c[d + 1];
494
+ case 3:
495
+ h[a + 3 - (p << 1) | 0] = c[d];
496
+ }
497
+ if (!(f < w + (4 - p))) {
498
+ for (v = 4 - p; v < y; v = v + 4 | 0)
499
+ g[a + v >> 2 | 0] = c[d + v] << 24 | c[d + v + 1] << 16 | c[d + v + 2] << 8 | c[d + v + 3];
500
+ switch (w) {
501
+ case 3:
502
+ h[a + y + 1 | 0] = c[d + y + 2];
503
+ case 2:
504
+ h[a + y + 2 | 0] = c[d + y + 1];
505
+ case 1:
506
+ h[a + y + 3 | 0] = c[d + y];
507
+ }
508
+ }
509
+ }, l = function(c, h, g, d, f, a) {
510
+ var v = void 0, p = a % 4, w = (f + p) % 4, y = f - w, m = new Uint8Array(i.readAsArrayBuffer(c.slice(d, d + f)));
511
+ switch (p) {
512
+ case 0:
513
+ h[a] = m[3];
514
+ case 1:
515
+ h[a + 1 - (p << 1) | 0] = m[2];
516
+ case 2:
517
+ h[a + 2 - (p << 1) | 0] = m[1];
518
+ case 3:
519
+ h[a + 3 - (p << 1) | 0] = m[0];
520
+ }
521
+ if (!(f < w + (4 - p))) {
522
+ for (v = 4 - p; v < y; v = v + 4 | 0)
523
+ g[a + v >> 2 | 0] = m[v] << 24 | m[v + 1] << 16 | m[v + 2] << 8 | m[v + 3];
524
+ switch (w) {
525
+ case 3:
526
+ h[a + y + 1 | 0] = m[y + 2];
527
+ case 2:
528
+ h[a + y + 2 | 0] = m[y + 1];
529
+ case 1:
530
+ h[a + y + 3 | 0] = m[y];
531
+ }
532
+ }
533
+ };
534
+ e.exports = function(c, h, g, d, f, a) {
535
+ if (typeof c == "string")
536
+ return o(c, h, g, d, f, a);
537
+ if (c instanceof Array || n && n.Buffer && n.Buffer.isBuffer(c))
538
+ return u(c, h, g, d, f, a);
539
+ if (c instanceof ArrayBuffer)
540
+ return u(new Uint8Array(c), h, g, d, f, a);
541
+ if (c.buffer instanceof ArrayBuffer)
542
+ return u(new Uint8Array(c.buffer, c.byteOffset, c.byteLength), h, g, d, f, a);
543
+ if (c instanceof Blob)
544
+ return l(c, h, g, d, f, a);
545
+ throw new Error("Unsupported data type.");
546
+ };
547
+ },
548
+ /* 7 */
549
+ /***/
550
+ function(e, t, n) {
551
+ var i = /* @__PURE__ */ function() {
552
+ function g(d, f) {
553
+ for (var a = 0; a < f.length; a++) {
554
+ var v = f[a];
555
+ v.enumerable = v.enumerable || !1, v.configurable = !0, "value" in v && (v.writable = !0), Object.defineProperty(d, v.key, v);
556
+ }
557
+ }
558
+ return function(d, f, a) {
559
+ return f && g(d.prototype, f), a && g(d, a), d;
560
+ };
561
+ }();
562
+ function o(g, d) {
563
+ if (!(g instanceof d))
564
+ throw new TypeError("Cannot call a class as a function");
565
+ }
566
+ var u = n(0), l = n(1), c = l.toHex, h = function() {
567
+ function g() {
568
+ o(this, g), this._rusha = new u(), this._rusha.resetState();
569
+ }
570
+ return g.prototype.update = function(f) {
571
+ return this._rusha.append(f), this;
572
+ }, g.prototype.digest = function(f) {
573
+ var a = this._rusha.rawEnd().buffer;
574
+ if (!f)
575
+ return a;
576
+ if (f === "hex")
577
+ return c(a);
578
+ throw new Error("unsupported digest encoding");
579
+ }, i(g, [{
580
+ key: "state",
581
+ get: function() {
582
+ return this._rusha.getState();
583
+ },
584
+ set: function(d) {
585
+ this._rusha.setState(d);
586
+ }
587
+ }]), g;
588
+ }();
589
+ e.exports = function() {
590
+ return new h();
591
+ };
592
+ }
593
+ /******/
594
+ ])
595
+ );
596
+ });
597
+ }(D)), D.exports;
598
+ }
599
+ var ce = le(), U = function(s, r) {
600
+ return U = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(e, t) {
601
+ e.__proto__ = t;
602
+ } || function(e, t) {
603
+ for (var n in t)
604
+ Object.prototype.hasOwnProperty.call(t, n) && (e[n] = t[n]);
605
+ }, U(s, r);
606
+ };
607
+ function x(s, r) {
608
+ if (typeof r != "function" && r !== null)
609
+ throw new TypeError("Class extends value " + String(r) + " is not a constructor or null");
610
+ U(s, r);
611
+ function e() {
612
+ this.constructor = s;
613
+ }
614
+ s.prototype = r === null ? Object.create(r) : (e.prototype = r.prototype, new e());
615
+ }
616
+ var F = function() {
617
+ return F = Object.assign || function(r) {
618
+ for (var e, t = 1, n = arguments.length; t < n; t++) {
619
+ e = arguments[t];
620
+ for (var i in e)
621
+ Object.prototype.hasOwnProperty.call(e, i) && (r[i] = e[i]);
622
+ }
623
+ return r;
624
+ }, F.apply(this, arguments);
625
+ };
626
+ function fe(s, r) {
627
+ var e = {};
628
+ for (var t in s)
629
+ Object.prototype.hasOwnProperty.call(s, t) && r.indexOf(t) < 0 && (e[t] = s[t]);
630
+ if (s != null && typeof Object.getOwnPropertySymbols == "function")
631
+ for (var n = 0, t = Object.getOwnPropertySymbols(s); n < t.length; n++)
632
+ r.indexOf(t[n]) < 0 && Object.prototype.propertyIsEnumerable.call(s, t[n]) && (e[t[n]] = s[t[n]]);
633
+ return e;
634
+ }
635
+ function A(s, r, e, t) {
636
+ function n(i) {
637
+ return i instanceof e ? i : new e(function(o) {
638
+ o(i);
639
+ });
640
+ }
641
+ return new (e || (e = Promise))(function(i, o) {
642
+ function u(h) {
643
+ try {
644
+ c(t.next(h));
645
+ } catch (g) {
646
+ o(g);
647
+ }
648
+ }
649
+ function l(h) {
650
+ try {
651
+ c(t.throw(h));
652
+ } catch (g) {
653
+ o(g);
654
+ }
655
+ }
656
+ function c(h) {
657
+ h.done ? i(h.value) : n(h.value).then(u, l);
658
+ }
659
+ c((t = t.apply(s, [])).next());
660
+ });
661
+ }
662
+ function E(s, r) {
663
+ var e = { label: 0, sent: function() {
664
+ if (i[0] & 1)
665
+ throw i[1];
666
+ return i[1];
667
+ }, trys: [], ops: [] }, t, n, i, o;
668
+ return o = { next: u(0), throw: u(1), return: u(2) }, typeof Symbol == "function" && (o[Symbol.iterator] = function() {
669
+ return this;
670
+ }), o;
671
+ function u(c) {
672
+ return function(h) {
673
+ return l([c, h]);
674
+ };
675
+ }
676
+ function l(c) {
677
+ if (t)
678
+ throw new TypeError("Generator is already executing.");
679
+ for (; e; )
680
+ try {
681
+ if (t = 1, n && (i = c[0] & 2 ? n.return : c[0] ? n.throw || ((i = n.return) && i.call(n), 0) : n.next) && !(i = i.call(n, c[1])).done)
682
+ return i;
683
+ switch (n = 0, i && (c = [c[0] & 2, i.value]), c[0]) {
684
+ case 0:
685
+ case 1:
686
+ i = c;
687
+ break;
688
+ case 4:
689
+ return e.label++, { value: c[1], done: !1 };
690
+ case 5:
691
+ e.label++, n = c[1], c = [0];
692
+ continue;
693
+ case 7:
694
+ c = e.ops.pop(), e.trys.pop();
695
+ continue;
696
+ default:
697
+ if (i = e.trys, !(i = i.length > 0 && i[i.length - 1]) && (c[0] === 6 || c[0] === 2)) {
698
+ e = 0;
699
+ continue;
700
+ }
701
+ if (c[0] === 3 && (!i || c[1] > i[0] && c[1] < i[3])) {
702
+ e.label = c[1];
703
+ break;
704
+ }
705
+ if (c[0] === 6 && e.label < i[1]) {
706
+ e.label = i[1], i = c;
707
+ break;
708
+ }
709
+ if (i && e.label < i[2]) {
710
+ e.label = i[2], e.ops.push(c);
711
+ break;
712
+ }
713
+ i[2] && e.ops.pop(), e.trys.pop();
714
+ continue;
715
+ }
716
+ c = r.call(s, e);
717
+ } catch (h) {
718
+ c = [6, h], n = 0;
719
+ } finally {
720
+ t = i = 0;
721
+ }
722
+ if (c[0] & 5)
723
+ throw c[1];
724
+ return { value: c[0] ? c[1] : void 0, done: !0 };
725
+ }
726
+ }
727
+ function Z(s, r, e) {
728
+ for (var t = 0, n = r.length, i; t < n; t++)
729
+ (i || !(t in r)) && (i || (i = Array.prototype.slice.call(r, 0, t)), i[t] = r[t]);
730
+ return s.concat(i || Array.prototype.slice.call(r));
731
+ }
732
+ var $ = "3.6.3", _;
733
+ (function(s) {
734
+ s.AnonymousId = "anonymous_id", s.DistinctId = "distinct_id", s.Props = "props", s.FeatureFlags = "feature_flags", s.FeatureFlagPayloads = "feature_flag_payloads", s.OverrideFeatureFlags = "override_feature_flags", s.Queue = "queue", s.OptedOut = "opted_out", s.SessionId = "session_id", s.SessionLastTimestamp = "session_timestamp", s.PersonProperties = "person_properties", s.GroupProperties = "group_properties", s.InstalledAppBuild = "installed_app_build", s.InstalledAppVersion = "installed_app_version";
735
+ })(_ || (_ = {}));
736
+ function he(s, r) {
737
+ if (!s)
738
+ throw new Error(r);
739
+ }
740
+ function de(s) {
741
+ return s == null ? void 0 : s.replace(/\/+$/, "");
742
+ }
743
+ function pe(s, r) {
744
+ return r === void 0 && (r = {}), A(this, void 0, void 0, function() {
745
+ var e, t, n, i, o, u, l, c, h, g;
746
+ return E(this, function(d) {
747
+ switch (d.label) {
748
+ case 0:
749
+ e = r.retryCount, t = e === void 0 ? 3 : e, n = r.retryDelay, i = n === void 0 ? 5e3 : n, o = r.retryCheck, u = o === void 0 ? function() {
750
+ return !0;
751
+ } : o, l = null, c = 0, d.label = 1;
752
+ case 1:
753
+ return c < t + 1 ? c > 0 ? [4, new Promise(function(f) {
754
+ return setTimeout(f, i);
755
+ })] : [3, 3] : [3, 7];
756
+ case 2:
757
+ d.sent(), d.label = 3;
758
+ case 3:
759
+ return d.trys.push([3, 5, , 6]), [4, s()];
760
+ case 4:
761
+ return h = d.sent(), [2, h];
762
+ case 5:
763
+ if (g = d.sent(), l = g, !u(g))
764
+ throw g;
765
+ return [3, 6];
766
+ case 6:
767
+ return c++, [3, 1];
768
+ case 7:
769
+ throw l;
770
+ }
771
+ });
772
+ });
773
+ }
774
+ function ve() {
775
+ return (/* @__PURE__ */ new Date()).getTime();
776
+ }
777
+ function W() {
778
+ return (/* @__PURE__ */ new Date()).toISOString();
779
+ }
780
+ function ee(s, r) {
781
+ var e = setTimeout(s, r);
782
+ return e != null && e.unref && (e == null || e.unref()), e;
783
+ }
784
+ var M = String.fromCharCode, B = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=", R = {};
785
+ function ge(s, r) {
786
+ if (!R[s]) {
787
+ R[s] = {};
788
+ for (var e = 0; e < s.length; e++)
789
+ R[s][s.charAt(e)] = e;
790
+ }
791
+ return R[s][r];
792
+ }
793
+ var j = {
794
+ compressToBase64: function(s) {
795
+ if (s == null)
796
+ return "";
797
+ var r = j._compress(s, 6, function(e) {
798
+ return B.charAt(e);
799
+ });
800
+ switch (r.length % 4) {
801
+ default:
802
+ // When could this happen ?
803
+ case 0:
804
+ return r;
805
+ case 1:
806
+ return r + "===";
807
+ case 2:
808
+ return r + "==";
809
+ case 3:
810
+ return r + "=";
811
+ }
812
+ },
813
+ decompressFromBase64: function(s) {
814
+ return s == null ? "" : s == "" ? null : j._decompress(s.length, 32, function(r) {
815
+ return ge(B, s.charAt(r));
816
+ });
817
+ },
818
+ compress: function(s) {
819
+ return j._compress(s, 16, function(r) {
820
+ return M(r);
821
+ });
822
+ },
823
+ _compress: function(s, r, e) {
824
+ if (s == null)
825
+ return "";
826
+ var t = {}, n = {}, i = [], o, u, l = "", c = "", h = "", g = 2, d = 3, f = 2, a = 0, v = 0, p;
827
+ for (p = 0; p < s.length; p += 1)
828
+ if (l = s.charAt(p), Object.prototype.hasOwnProperty.call(t, l) || (t[l] = d++, n[l] = !0), c = h + l, Object.prototype.hasOwnProperty.call(t, c))
829
+ h = c;
830
+ else {
831
+ if (Object.prototype.hasOwnProperty.call(n, h)) {
832
+ if (h.charCodeAt(0) < 256) {
833
+ for (o = 0; o < f; o++)
834
+ a = a << 1, v == r - 1 ? (v = 0, i.push(e(a)), a = 0) : v++;
835
+ for (u = h.charCodeAt(0), o = 0; o < 8; o++)
836
+ a = a << 1 | u & 1, v == r - 1 ? (v = 0, i.push(e(a)), a = 0) : v++, u = u >> 1;
837
+ } else {
838
+ for (u = 1, o = 0; o < f; o++)
839
+ a = a << 1 | u, v == r - 1 ? (v = 0, i.push(e(a)), a = 0) : v++, u = 0;
840
+ for (u = h.charCodeAt(0), o = 0; o < 16; o++)
841
+ a = a << 1 | u & 1, v == r - 1 ? (v = 0, i.push(e(a)), a = 0) : v++, u = u >> 1;
842
+ }
843
+ g--, g == 0 && (g = Math.pow(2, f), f++), delete n[h];
844
+ } else
845
+ for (u = t[h], o = 0; o < f; o++)
846
+ a = a << 1 | u & 1, v == r - 1 ? (v = 0, i.push(e(a)), a = 0) : v++, u = u >> 1;
847
+ g--, g == 0 && (g = Math.pow(2, f), f++), t[c] = d++, h = String(l);
848
+ }
849
+ if (h !== "") {
850
+ if (Object.prototype.hasOwnProperty.call(n, h)) {
851
+ if (h.charCodeAt(0) < 256) {
852
+ for (o = 0; o < f; o++)
853
+ a = a << 1, v == r - 1 ? (v = 0, i.push(e(a)), a = 0) : v++;
854
+ for (u = h.charCodeAt(0), o = 0; o < 8; o++)
855
+ a = a << 1 | u & 1, v == r - 1 ? (v = 0, i.push(e(a)), a = 0) : v++, u = u >> 1;
856
+ } else {
857
+ for (u = 1, o = 0; o < f; o++)
858
+ a = a << 1 | u, v == r - 1 ? (v = 0, i.push(e(a)), a = 0) : v++, u = 0;
859
+ for (u = h.charCodeAt(0), o = 0; o < 16; o++)
860
+ a = a << 1 | u & 1, v == r - 1 ? (v = 0, i.push(e(a)), a = 0) : v++, u = u >> 1;
861
+ }
862
+ g--, g == 0 && (g = Math.pow(2, f), f++), delete n[h];
863
+ } else
864
+ for (u = t[h], o = 0; o < f; o++)
865
+ a = a << 1 | u & 1, v == r - 1 ? (v = 0, i.push(e(a)), a = 0) : v++, u = u >> 1;
866
+ g--, g == 0 && (g = Math.pow(2, f), f++);
867
+ }
868
+ for (u = 2, o = 0; o < f; o++)
869
+ a = a << 1 | u & 1, v == r - 1 ? (v = 0, i.push(e(a)), a = 0) : v++, u = u >> 1;
870
+ for (; ; )
871
+ if (a = a << 1, v == r - 1) {
872
+ i.push(e(a));
873
+ break;
874
+ } else
875
+ v++;
876
+ return i.join("");
877
+ },
878
+ decompress: function(s) {
879
+ return s == null ? "" : s == "" ? null : j._decompress(s.length, 32768, function(r) {
880
+ return s.charCodeAt(r);
881
+ });
882
+ },
883
+ _decompress: function(s, r, e) {
884
+ var t = [], n = [], i = { val: e(0), position: r, index: 1 }, o = 4, u = 4, l = 3, c = "", h, g, d, f, a, v, p;
885
+ for (h = 0; h < 3; h += 1)
886
+ t[h] = h;
887
+ for (d = 0, a = Math.pow(2, 2), v = 1; v != a; )
888
+ f = i.val & i.position, i.position >>= 1, i.position == 0 && (i.position = r, i.val = e(i.index++)), d |= (f > 0 ? 1 : 0) * v, v <<= 1;
889
+ switch (d) {
890
+ case 0:
891
+ for (d = 0, a = Math.pow(2, 8), v = 1; v != a; )
892
+ f = i.val & i.position, i.position >>= 1, i.position == 0 && (i.position = r, i.val = e(i.index++)), d |= (f > 0 ? 1 : 0) * v, v <<= 1;
893
+ p = M(d);
894
+ break;
895
+ case 1:
896
+ for (d = 0, a = Math.pow(2, 16), v = 1; v != a; )
897
+ f = i.val & i.position, i.position >>= 1, i.position == 0 && (i.position = r, i.val = e(i.index++)), d |= (f > 0 ? 1 : 0) * v, v <<= 1;
898
+ p = M(d);
899
+ break;
900
+ case 2:
901
+ return "";
902
+ }
903
+ for (t[3] = p, g = p, n.push(p); ; ) {
904
+ if (i.index > s)
905
+ return "";
906
+ for (d = 0, a = Math.pow(2, l), v = 1; v != a; )
907
+ f = i.val & i.position, i.position >>= 1, i.position == 0 && (i.position = r, i.val = e(i.index++)), d |= (f > 0 ? 1 : 0) * v, v <<= 1;
908
+ switch (p = d) {
909
+ case 0:
910
+ for (d = 0, a = Math.pow(2, 8), v = 1; v != a; )
911
+ f = i.val & i.position, i.position >>= 1, i.position == 0 && (i.position = r, i.val = e(i.index++)), d |= (f > 0 ? 1 : 0) * v, v <<= 1;
912
+ t[u++] = M(d), p = u - 1, o--;
913
+ break;
914
+ case 1:
915
+ for (d = 0, a = Math.pow(2, 16), v = 1; v != a; )
916
+ f = i.val & i.position, i.position >>= 1, i.position == 0 && (i.position = r, i.val = e(i.index++)), d |= (f > 0 ? 1 : 0) * v, v <<= 1;
917
+ t[u++] = M(d), p = u - 1, o--;
918
+ break;
919
+ case 2:
920
+ return n.join("");
921
+ }
922
+ if (o == 0 && (o = Math.pow(2, l), l++), t[p])
923
+ c = t[p];
924
+ else if (p === u)
925
+ c = g + g.charAt(0);
926
+ else
927
+ return null;
928
+ n.push(c), t[u++] = g + c.charAt(0), o--, g = c, o == 0 && (o = Math.pow(2, l), l++);
929
+ }
930
+ }
931
+ }, ye = (
932
+ /** @class */
933
+ function() {
934
+ function s() {
935
+ this.events = {}, this.events = {};
936
+ }
937
+ return s.prototype.on = function(r, e) {
938
+ var t = this;
939
+ return this.events[r] || (this.events[r] = []), this.events[r].push(e), function() {
940
+ t.events[r] = t.events[r].filter(function(n) {
941
+ return n !== e;
942
+ });
943
+ };
944
+ }, s.prototype.emit = function(r, e) {
945
+ for (var t = 0, n = this.events[r] || []; t < n.length; t++) {
946
+ var i = n[t];
947
+ i(e);
948
+ }
949
+ for (var o = 0, u = this.events["*"] || []; o < u.length; o++) {
950
+ var i = u[o];
951
+ i(r, e);
952
+ }
953
+ }, s;
954
+ }()
955
+ );
956
+ /**
957
+ * uuidv7: An experimental implementation of the proposed UUID Version 7
958
+ *
959
+ * @license Apache-2.0
960
+ * @copyright 2021-2023 LiosK
961
+ * @packageDocumentation
962
+ */
963
+ var T = "0123456789abcdef", H = (
964
+ /** @class */
965
+ function() {
966
+ function s(r) {
967
+ this.bytes = r;
968
+ }
969
+ return s.ofInner = function(r) {
970
+ if (r.length !== 16)
971
+ throw new TypeError("not 128-bit length");
972
+ return new s(r);
973
+ }, s.fromFieldsV7 = function(r, e, t, n) {
974
+ if (!Number.isInteger(r) || !Number.isInteger(e) || !Number.isInteger(t) || !Number.isInteger(n) || r < 0 || e < 0 || t < 0 || n < 0 || r > 281474976710655 || e > 4095 || t > 1073741823 || n > 4294967295)
975
+ throw new RangeError("invalid field value");
976
+ var i = new Uint8Array(16);
977
+ return i[0] = r / Math.pow(2, 40), i[1] = r / Math.pow(2, 32), i[2] = r / Math.pow(2, 24), i[3] = r / Math.pow(2, 16), i[4] = r / Math.pow(2, 8), i[5] = r, i[6] = 112 | e >>> 8, i[7] = e, i[8] = 128 | t >>> 24, i[9] = t >>> 16, i[10] = t >>> 8, i[11] = t, i[12] = n >>> 24, i[13] = n >>> 16, i[14] = n >>> 8, i[15] = n, new s(i);
978
+ }, s.parse = function(r) {
979
+ var e, t, n, i, o = void 0;
980
+ switch (r.length) {
981
+ case 32:
982
+ o = (e = /^[0-9a-f]{32}$/i.exec(r)) === null || e === void 0 ? void 0 : e[0];
983
+ break;
984
+ case 36:
985
+ o = (t = /^([0-9a-f]{8})-([0-9a-f]{4})-([0-9a-f]{4})-([0-9a-f]{4})-([0-9a-f]{12})$/i.exec(r)) === null || t === void 0 ? void 0 : t.slice(1, 6).join("");
986
+ break;
987
+ case 38:
988
+ o = (n = /^\{([0-9a-f]{8})-([0-9a-f]{4})-([0-9a-f]{4})-([0-9a-f]{4})-([0-9a-f]{12})\}$/i.exec(r)) === null || n === void 0 ? void 0 : n.slice(1, 6).join("");
989
+ break;
990
+ case 45:
991
+ o = (i = /^urn:uuid:([0-9a-f]{8})-([0-9a-f]{4})-([0-9a-f]{4})-([0-9a-f]{4})-([0-9a-f]{12})$/i.exec(r)) === null || i === void 0 ? void 0 : i.slice(1, 6).join("");
992
+ break;
993
+ }
994
+ if (o) {
995
+ for (var u = new Uint8Array(16), l = 0; l < 16; l += 4) {
996
+ var c = parseInt(o.substring(2 * l, 2 * l + 8), 16);
997
+ u[l + 0] = c >>> 24, u[l + 1] = c >>> 16, u[l + 2] = c >>> 8, u[l + 3] = c;
998
+ }
999
+ return new s(u);
1000
+ } else
1001
+ throw new SyntaxError("could not parse UUID string");
1002
+ }, s.prototype.toString = function() {
1003
+ for (var r = "", e = 0; e < this.bytes.length; e++)
1004
+ r += T.charAt(this.bytes[e] >>> 4), r += T.charAt(this.bytes[e] & 15), (e === 3 || e === 5 || e === 7 || e === 9) && (r += "-");
1005
+ return r;
1006
+ }, s.prototype.toHex = function() {
1007
+ for (var r = "", e = 0; e < this.bytes.length; e++)
1008
+ r += T.charAt(this.bytes[e] >>> 4), r += T.charAt(this.bytes[e] & 15);
1009
+ return r;
1010
+ }, s.prototype.toJSON = function() {
1011
+ return this.toString();
1012
+ }, s.prototype.getVariant = function() {
1013
+ var r = this.bytes[8] >>> 4;
1014
+ if (r < 0)
1015
+ throw new Error("unreachable");
1016
+ if (r <= 7)
1017
+ return this.bytes.every(function(e) {
1018
+ return e === 0;
1019
+ }) ? "NIL" : "VAR_0";
1020
+ if (r <= 11)
1021
+ return "VAR_10";
1022
+ if (r <= 13)
1023
+ return "VAR_110";
1024
+ if (r <= 15)
1025
+ return this.bytes.every(function(e) {
1026
+ return e === 255;
1027
+ }) ? "MAX" : "VAR_RESERVED";
1028
+ throw new Error("unreachable");
1029
+ }, s.prototype.getVersion = function() {
1030
+ return this.getVariant() === "VAR_10" ? this.bytes[6] >>> 4 : void 0;
1031
+ }, s.prototype.clone = function() {
1032
+ return new s(this.bytes.slice(0));
1033
+ }, s.prototype.equals = function(r) {
1034
+ return this.compareTo(r) === 0;
1035
+ }, s.prototype.compareTo = function(r) {
1036
+ for (var e = 0; e < 16; e++) {
1037
+ var t = this.bytes[e] - r.bytes[e];
1038
+ if (t !== 0)
1039
+ return Math.sign(t);
1040
+ }
1041
+ return 0;
1042
+ }, s;
1043
+ }()
1044
+ ), we = (
1045
+ /** @class */
1046
+ function() {
1047
+ function s(r) {
1048
+ this.timestamp = 0, this.counter = 0, this.random = r ?? be();
1049
+ }
1050
+ return s.prototype.generate = function() {
1051
+ return this.generateOrResetCore(Date.now(), 1e4);
1052
+ }, s.prototype.generateOrAbort = function() {
1053
+ return this.generateOrAbortCore(Date.now(), 1e4);
1054
+ }, s.prototype.generateOrResetCore = function(r, e) {
1055
+ var t = this.generateOrAbortCore(r, e);
1056
+ return t === void 0 && (this.timestamp = 0, t = this.generateOrAbortCore(r, e)), t;
1057
+ }, s.prototype.generateOrAbortCore = function(r, e) {
1058
+ var t = 4398046511103;
1059
+ if (!Number.isInteger(r) || r < 1 || r > 281474976710655)
1060
+ throw new RangeError("`unixTsMs` must be a 48-bit positive integer");
1061
+ if (e < 0 || e > 281474976710655)
1062
+ throw new RangeError("`rollbackAllowance` out of reasonable range");
1063
+ if (r > this.timestamp)
1064
+ this.timestamp = r, this.resetCounter();
1065
+ else if (r + e >= this.timestamp)
1066
+ this.counter++, this.counter > t && (this.timestamp++, this.resetCounter());
1067
+ else
1068
+ return;
1069
+ return H.fromFieldsV7(this.timestamp, Math.trunc(this.counter / Math.pow(2, 30)), this.counter & Math.pow(2, 30) - 1, this.random.nextUint32());
1070
+ }, s.prototype.resetCounter = function() {
1071
+ this.counter = this.random.nextUint32() * 1024 + (this.random.nextUint32() & 1023);
1072
+ }, s.prototype.generateV4 = function() {
1073
+ var r = new Uint8Array(Uint32Array.of(this.random.nextUint32(), this.random.nextUint32(), this.random.nextUint32(), this.random.nextUint32()).buffer);
1074
+ return r[6] = 64 | r[6] >>> 4, r[8] = 128 | r[8] >>> 2, H.ofInner(r);
1075
+ }, s;
1076
+ }()
1077
+ ), be = function() {
1078
+ return {
1079
+ nextUint32: function() {
1080
+ return Math.trunc(Math.random() * 65536) * 65536 + Math.trunc(Math.random() * 65536);
1081
+ }
1082
+ };
1083
+ }, q, G = function() {
1084
+ return me().toString();
1085
+ }, me = function() {
1086
+ return (q || (q = new we())).generate();
1087
+ }, Fe = (
1088
+ /** @class */
1089
+ function(s) {
1090
+ x(r, s);
1091
+ function r(e) {
1092
+ var t = s.call(this, "HTTP error while fetching PostHog: " + e.status) || this;
1093
+ return t.response = e, t.name = "PostHogFetchHttpError", t;
1094
+ }
1095
+ return r;
1096
+ }(Error)
1097
+ ), Pe = (
1098
+ /** @class */
1099
+ function(s) {
1100
+ x(r, s);
1101
+ function r(e) {
1102
+ var t = (
1103
+ // TRICKY: "cause" is a newer property but is just ignored otherwise. Cast to any to ignore the type issue.
1104
+ // @ts-ignore
1105
+ s.call(this, "Network error while fetching PostHog", e instanceof Error ? { cause: e } : {}) || this
1106
+ );
1107
+ return t.error = e, t.name = "PostHogFetchNetworkError", t;
1108
+ }
1109
+ return r;
1110
+ }(Error)
1111
+ );
1112
+ function N(s) {
1113
+ return typeof s == "object" && (s.name === "PostHogFetchHttpError" || s.name === "PostHogFetchNetworkError");
1114
+ }
1115
+ var te = (
1116
+ /** @class */
1117
+ function() {
1118
+ function s(r, e) {
1119
+ var t, n, i, o, u;
1120
+ this.debugMode = !1, this.disableGeoip = !0, this.pendingPromises = {}, this._events = new ye(), he(r, "You must pass your PostHog project's api key."), this.apiKey = r, this.host = de((e == null ? void 0 : e.host) || "https://app.posthog.com"), this.flushAt = e != null && e.flushAt ? Math.max(e == null ? void 0 : e.flushAt, 1) : 20, this.flushInterval = (t = e == null ? void 0 : e.flushInterval) !== null && t !== void 0 ? t : 1e4, this.captureMode = (e == null ? void 0 : e.captureMode) || "form", this._optoutOverride = (e == null ? void 0 : e.enable) === !1, this._retryOptions = {
1121
+ retryCount: (n = e == null ? void 0 : e.fetchRetryCount) !== null && n !== void 0 ? n : 3,
1122
+ retryDelay: (i = e == null ? void 0 : e.fetchRetryDelay) !== null && i !== void 0 ? i : 3e3,
1123
+ retryCheck: N
1124
+ }, this.requestTimeout = (o = e == null ? void 0 : e.requestTimeout) !== null && o !== void 0 ? o : 1e4, this.disableGeoip = (u = e == null ? void 0 : e.disableGeoip) !== null && u !== void 0 ? u : !0;
1125
+ }
1126
+ return s.prototype.getCommonEventProperties = function() {
1127
+ return {
1128
+ $lib: this.getLibraryId(),
1129
+ $lib_version: this.getLibraryVersion()
1130
+ };
1131
+ }, Object.defineProperty(s.prototype, "optedOut", {
1132
+ get: function() {
1133
+ var r, e;
1134
+ return (e = (r = this.getPersistedProperty(_.OptedOut)) !== null && r !== void 0 ? r : this._optoutOverride) !== null && e !== void 0 ? e : !1;
1135
+ },
1136
+ enumerable: !1,
1137
+ configurable: !0
1138
+ }), s.prototype.optIn = function() {
1139
+ this.setPersistedProperty(_.OptedOut, !1);
1140
+ }, s.prototype.optOut = function() {
1141
+ this.setPersistedProperty(_.OptedOut, !0);
1142
+ }, s.prototype.on = function(r, e) {
1143
+ return this._events.on(r, e);
1144
+ }, s.prototype.debug = function(r) {
1145
+ var e;
1146
+ r === void 0 && (r = !0), (e = this.removeDebugCallback) === null || e === void 0 || e.call(this), this.debugMode = r, r && (this.removeDebugCallback = this.on("*", function(t, n) {
1147
+ return console.log("PostHog Debug", t, n);
1148
+ }));
1149
+ }, s.prototype.buildPayload = function(r) {
1150
+ return {
1151
+ distinct_id: r.distinct_id,
1152
+ event: r.event,
1153
+ properties: F(F({}, r.properties || {}), this.getCommonEventProperties())
1154
+ };
1155
+ }, s.prototype.addPendingPromise = function(r) {
1156
+ var e = this, t = G();
1157
+ this.pendingPromises[t] = r, r.finally(function() {
1158
+ delete e.pendingPromises[t];
1159
+ });
1160
+ }, s.prototype.identifyStateless = function(r, e, t) {
1161
+ var n = F({}, this.buildPayload({
1162
+ distinct_id: r,
1163
+ event: "$identify",
1164
+ properties: e
1165
+ }));
1166
+ return this.enqueue("identify", n, t), this;
1167
+ }, s.prototype.captureStateless = function(r, e, t, n) {
1168
+ var i = this.buildPayload({ distinct_id: r, event: e, properties: t });
1169
+ return this.enqueue("capture", i, n), this;
1170
+ }, s.prototype.aliasStateless = function(r, e, t, n) {
1171
+ var i = this.buildPayload({
1172
+ event: "$create_alias",
1173
+ distinct_id: e,
1174
+ properties: F(F({}, t || {}), { distinct_id: e, alias: r })
1175
+ });
1176
+ return this.enqueue("alias", i, n), this;
1177
+ }, s.prototype.groupIdentifyStateless = function(r, e, t, n, i, o) {
1178
+ var u = this.buildPayload({
1179
+ distinct_id: i || "$".concat(r, "_").concat(e),
1180
+ event: "$groupidentify",
1181
+ properties: F({ $group_type: r, $group_key: e, $group_set: t || {} }, o || {})
1182
+ });
1183
+ return this.enqueue("capture", u, n), this;
1184
+ }, s.prototype.getDecide = function(r, e, t, n, i) {
1185
+ return e === void 0 && (e = {}), t === void 0 && (t = {}), n === void 0 && (n = {}), i === void 0 && (i = {}), A(this, void 0, void 0, function() {
1186
+ var o, u, l = this;
1187
+ return E(this, function(c) {
1188
+ return o = "".concat(this.host, "/decide/?v=3"), u = {
1189
+ method: "POST",
1190
+ headers: { "Content-Type": "application/json" },
1191
+ body: JSON.stringify(F({ token: this.apiKey, distinct_id: r, groups: e, person_properties: t, group_properties: n }, i))
1192
+ }, [2, this.fetchWithRetry(o, u).then(function(h) {
1193
+ return h.json();
1194
+ }).catch(function(h) {
1195
+ l._events.emit("error", h);
1196
+ })];
1197
+ });
1198
+ });
1199
+ }, s.prototype.getFeatureFlagStateless = function(r, e, t, n, i, o) {
1200
+ return t === void 0 && (t = {}), n === void 0 && (n = {}), i === void 0 && (i = {}), A(this, void 0, void 0, function() {
1201
+ var u, l;
1202
+ return E(this, function(c) {
1203
+ switch (c.label) {
1204
+ case 0:
1205
+ return [4, this.getFeatureFlagsStateless(e, t, n, i, o)];
1206
+ case 1:
1207
+ return u = c.sent(), u ? (l = u[r], l === void 0 && (l = !1), [2, l]) : [2, void 0];
1208
+ }
1209
+ });
1210
+ });
1211
+ }, s.prototype.getFeatureFlagPayloadStateless = function(r, e, t, n, i, o) {
1212
+ return t === void 0 && (t = {}), n === void 0 && (n = {}), i === void 0 && (i = {}), A(this, void 0, void 0, function() {
1213
+ var u, l;
1214
+ return E(this, function(c) {
1215
+ switch (c.label) {
1216
+ case 0:
1217
+ return [4, this.getFeatureFlagPayloadsStateless(e, t, n, i, o)];
1218
+ case 1:
1219
+ return u = c.sent(), u ? (l = u[r], l === void 0 ? [2, null] : [2, this._parsePayload(l)]) : [2, void 0];
1220
+ }
1221
+ });
1222
+ });
1223
+ }, s.prototype.getFeatureFlagPayloadsStateless = function(r, e, t, n, i) {
1224
+ return e === void 0 && (e = {}), t === void 0 && (t = {}), n === void 0 && (n = {}), A(this, void 0, void 0, function() {
1225
+ var o, u = this;
1226
+ return E(this, function(l) {
1227
+ switch (l.label) {
1228
+ case 0:
1229
+ return [4, this.getFeatureFlagsAndPayloadsStateless(r, e, t, n, i)];
1230
+ case 1:
1231
+ return o = l.sent().payloads, o ? [2, Object.fromEntries(Object.entries(o).map(function(c) {
1232
+ var h = c[0], g = c[1];
1233
+ return [h, u._parsePayload(g)];
1234
+ }))] : [2, o];
1235
+ }
1236
+ });
1237
+ });
1238
+ }, s.prototype._parsePayload = function(r) {
1239
+ try {
1240
+ return JSON.parse(r);
1241
+ } catch {
1242
+ return r;
1243
+ }
1244
+ }, s.prototype.getFeatureFlagsStateless = function(r, e, t, n, i) {
1245
+ return e === void 0 && (e = {}), t === void 0 && (t = {}), n === void 0 && (n = {}), A(this, void 0, void 0, function() {
1246
+ return E(this, function(o) {
1247
+ switch (o.label) {
1248
+ case 0:
1249
+ return [4, this.getFeatureFlagsAndPayloadsStateless(r, e, t, n, i)];
1250
+ case 1:
1251
+ return [2, o.sent().flags];
1252
+ }
1253
+ });
1254
+ });
1255
+ }, s.prototype.getFeatureFlagsAndPayloadsStateless = function(r, e, t, n, i) {
1256
+ return e === void 0 && (e = {}), t === void 0 && (t = {}), n === void 0 && (n = {}), A(this, void 0, void 0, function() {
1257
+ var o, u, l, c;
1258
+ return E(this, function(h) {
1259
+ switch (h.label) {
1260
+ case 0:
1261
+ return o = {}, (i ?? this.disableGeoip) && (o.geoip_disable = !0), [4, this.getDecide(r, e, t, n, o)];
1262
+ case 1:
1263
+ return u = h.sent(), l = u == null ? void 0 : u.featureFlags, c = u == null ? void 0 : u.featureFlagPayloads, [2, {
1264
+ flags: l,
1265
+ payloads: c
1266
+ }];
1267
+ }
1268
+ });
1269
+ });
1270
+ }, s.prototype.enqueue = function(r, e, t) {
1271
+ var n = this, i;
1272
+ if (this.optedOut) {
1273
+ this._events.emit(r, "Library is disabled. Not sending event. To re-enable, call posthog.optIn()");
1274
+ return;
1275
+ }
1276
+ var o = F(F({}, e), { type: r, library: this.getLibraryId(), library_version: this.getLibraryVersion(), timestamp: t != null && t.timestamp ? t == null ? void 0 : t.timestamp : W(), uuid: t != null && t.uuid ? t.uuid : G() }), u = (i = t == null ? void 0 : t.disableGeoip) !== null && i !== void 0 ? i : this.disableGeoip;
1277
+ u && (o.properties || (o.properties = {}), o.properties.$geoip_disable = !0), o.distinctId && (o.distinct_id = o.distinctId, delete o.distinctId);
1278
+ var l = this.getPersistedProperty(_.Queue) || [];
1279
+ l.push({ message: o }), this.setPersistedProperty(_.Queue, l), this._events.emit(r, o), l.length >= this.flushAt && this.flush(), this.flushInterval && !this._flushTimer && (this._flushTimer = ee(function() {
1280
+ return n.flush();
1281
+ }, this.flushInterval));
1282
+ }, s.prototype.flushAsync = function() {
1283
+ var r = this;
1284
+ return new Promise(function(e, t) {
1285
+ r.flush(function(n, i) {
1286
+ return n ? t(n) : e(i);
1287
+ });
1288
+ });
1289
+ }, s.prototype.flush = function(r) {
1290
+ var e = this;
1291
+ this._flushTimer && (clearTimeout(this._flushTimer), this._flushTimer = null);
1292
+ var t = this.getPersistedProperty(_.Queue) || [];
1293
+ if (!t.length)
1294
+ return r == null ? void 0 : r();
1295
+ var n = t.splice(0, this.flushAt);
1296
+ this.setPersistedProperty(_.Queue, t);
1297
+ var i = n.map(function(d) {
1298
+ return d.message;
1299
+ }), o = {
1300
+ api_key: this.apiKey,
1301
+ batch: i,
1302
+ sent_at: W()
1303
+ }, u = function(d) {
1304
+ d && e._events.emit("error", d), r == null || r(d, i), e._events.emit("flush", i);
1305
+ };
1306
+ this.getCustomUserAgent();
1307
+ var l = JSON.stringify(o), c = this.captureMode === "form" ? "".concat(this.host, "/e/?ip=1&_=").concat(ve(), "&v=").concat(this.getLibraryVersion()) : "".concat(this.host, "/batch/"), h = this.captureMode === "form" ? {
1308
+ method: "POST",
1309
+ mode: "no-cors",
1310
+ credentials: "omit",
1311
+ headers: { "Content-Type": "application/x-www-form-urlencoded" },
1312
+ body: "data=".concat(encodeURIComponent(j.compressToBase64(l)), "&compression=lz64")
1313
+ } : {
1314
+ method: "POST",
1315
+ headers: { "Content-Type": "application/json" },
1316
+ body: l
1317
+ }, g = this.fetchWithRetry(c, h);
1318
+ this.addPendingPromise(g.then(function() {
1319
+ return u();
1320
+ }).catch(function(d) {
1321
+ u(d);
1322
+ }));
1323
+ }, s.prototype.fetchWithRetry = function(r, e, t) {
1324
+ var n, i;
1325
+ return A(this, void 0, void 0, function() {
1326
+ var o = this;
1327
+ return E(this, function(u) {
1328
+ switch (u.label) {
1329
+ case 0:
1330
+ return (n = (i = AbortSignal).timeout) !== null && n !== void 0 || (i.timeout = function(c) {
1331
+ var h = new AbortController();
1332
+ return setTimeout(function() {
1333
+ return h.abort();
1334
+ }, c), h.signal;
1335
+ }), [4, pe(function() {
1336
+ return A(o, void 0, void 0, function() {
1337
+ var l, c, h;
1338
+ return E(this, function(g) {
1339
+ switch (g.label) {
1340
+ case 0:
1341
+ l = null, g.label = 1;
1342
+ case 1:
1343
+ return g.trys.push([1, 3, , 4]), [4, this.fetch(r, F({ signal: AbortSignal.timeout(this.requestTimeout) }, e))];
1344
+ case 2:
1345
+ return l = g.sent(), [3, 4];
1346
+ case 3:
1347
+ throw c = g.sent(), new Pe(c);
1348
+ case 4:
1349
+ if (h = e.mode === "no-cors", !h && (l.status < 200 || l.status >= 400))
1350
+ throw new Fe(l);
1351
+ return [2, l];
1352
+ }
1353
+ });
1354
+ });
1355
+ }, F(F({}, this._retryOptions), t))];
1356
+ case 1:
1357
+ return [2, u.sent()];
1358
+ }
1359
+ });
1360
+ });
1361
+ }, s.prototype.shutdownAsync = function() {
1362
+ return A(this, void 0, void 0, function() {
1363
+ var r;
1364
+ return E(this, function(e) {
1365
+ switch (e.label) {
1366
+ case 0:
1367
+ clearTimeout(this._flushTimer), e.label = 1;
1368
+ case 1:
1369
+ return e.trys.push([1, 5, , 6]), [4, this.flushAsync()];
1370
+ case 2:
1371
+ return e.sent(), [
1372
+ 4,
1373
+ Promise.all(Object.values(this.pendingPromises).map(function(t) {
1374
+ return t.catch(function() {
1375
+ });
1376
+ }))
1377
+ // flush again to make sure we send all events, some of which might've been added
1378
+ // while we were waiting for the pending promises to resolve
1379
+ // For example, see sendFeatureFlags in posthog-node/src/posthog-node.ts::capture
1380
+ ];
1381
+ case 3:
1382
+ return e.sent(), [4, this.flushAsync()];
1383
+ case 4:
1384
+ return e.sent(), [3, 6];
1385
+ case 5:
1386
+ if (r = e.sent(), !N(r))
1387
+ throw r;
1388
+ return console.error("Error while shutting down PostHog", r), [3, 6];
1389
+ case 6:
1390
+ return [
1391
+ 2
1392
+ /*return*/
1393
+ ];
1394
+ }
1395
+ });
1396
+ });
1397
+ }, s.prototype.shutdown = function() {
1398
+ this.shutdownAsync();
1399
+ }, s;
1400
+ }()
1401
+ );
1402
+ (function(s) {
1403
+ x(r, s);
1404
+ function r(e, t) {
1405
+ var n = this, i, o, u, l = (i = t == null ? void 0 : t.disableGeoip) !== null && i !== void 0 ? i : !1;
1406
+ return n = s.call(this, e, F(F({}, t), { disableGeoip: l })) || this, n.flagCallReported = {}, n.sessionProps = {}, n.sendFeatureFlagEvent = (o = t == null ? void 0 : t.sendFeatureFlagEvent) !== null && o !== void 0 ? o : !0, n._sessionExpirationTimeSeconds = (u = t == null ? void 0 : t.sessionExpirationTimeSeconds) !== null && u !== void 0 ? u : 1800, n;
1407
+ }
1408
+ return r.prototype.setupBootstrap = function(e) {
1409
+ var t, n, i, o;
1410
+ if (!((t = e == null ? void 0 : e.bootstrap) === null || t === void 0) && t.distinctId && (!((n = e == null ? void 0 : e.bootstrap) === null || n === void 0) && n.isIdentifiedId ? this.setPersistedProperty(_.DistinctId, e.bootstrap.distinctId) : this.setPersistedProperty(_.AnonymousId, e.bootstrap.distinctId)), !((i = e == null ? void 0 : e.bootstrap) === null || i === void 0) && i.featureFlags) {
1411
+ var u = Object.keys(((o = e.bootstrap) === null || o === void 0 ? void 0 : o.featureFlags) || {}).filter(function(l) {
1412
+ var c, h;
1413
+ return !!(!((h = (c = e.bootstrap) === null || c === void 0 ? void 0 : c.featureFlags) === null || h === void 0) && h[l]);
1414
+ }).reduce(function(l, c) {
1415
+ var h, g;
1416
+ return l[c] = ((g = (h = e.bootstrap) === null || h === void 0 ? void 0 : h.featureFlags) === null || g === void 0 ? void 0 : g[c]) || !1, l;
1417
+ }, {});
1418
+ this.setKnownFeatureFlags(u), e != null && e.bootstrap.featureFlagPayloads && this.setKnownFeatureFlagPayloads(e == null ? void 0 : e.bootstrap.featureFlagPayloads);
1419
+ }
1420
+ }, Object.defineProperty(r.prototype, "props", {
1421
+ // NOTE: Props are lazy loaded from localstorage hence the complex getter setter logic
1422
+ get: function() {
1423
+ return this._props || (this._props = this.getPersistedProperty(_.Props)), this._props || {};
1424
+ },
1425
+ set: function(e) {
1426
+ this._props = e;
1427
+ },
1428
+ enumerable: !1,
1429
+ configurable: !0
1430
+ }), r.prototype.clearProps = function() {
1431
+ this.props = void 0, this.sessionProps = {};
1432
+ }, r.prototype.on = function(e, t) {
1433
+ return this._events.on(e, t);
1434
+ }, r.prototype.reset = function(e) {
1435
+ var t = Z([_.Queue], e || []);
1436
+ this.clearProps();
1437
+ for (var n = 0, i = Object.keys(_); n < i.length; n++) {
1438
+ var o = i[n];
1439
+ t.includes(_[o]) || this.setPersistedProperty(_[o], null);
1440
+ }
1441
+ }, r.prototype.getCommonEventProperties = function() {
1442
+ var e = this.getFeatureFlags(), t = {};
1443
+ if (e)
1444
+ for (var n = 0, i = Object.entries(e); n < i.length; n++) {
1445
+ var o = i[n], u = o[0], l = o[1];
1446
+ t["$feature/".concat(u)] = l;
1447
+ }
1448
+ return F(F({ $active_feature_flags: e ? Object.keys(e) : void 0 }, t), s.prototype.getCommonEventProperties.call(this));
1449
+ }, r.prototype.enrichProperties = function(e) {
1450
+ return F(F(F(F(F({}, this.props), this.sessionProps), e || {}), this.getCommonEventProperties()), { $session_id: this.getSessionId() });
1451
+ }, r.prototype.getSessionId = function() {
1452
+ var e = this.getPersistedProperty(_.SessionId), t = this.getPersistedProperty(_.SessionLastTimestamp) || 0;
1453
+ return (!e || Date.now() - t > this._sessionExpirationTimeSeconds * 1e3) && (e = G(), this.setPersistedProperty(_.SessionId, e)), this.setPersistedProperty(_.SessionLastTimestamp, Date.now()), e;
1454
+ }, r.prototype.resetSessionId = function() {
1455
+ this.setPersistedProperty(_.SessionId, null);
1456
+ }, r.prototype.getAnonymousId = function() {
1457
+ var e = this.getPersistedProperty(_.AnonymousId);
1458
+ return e || (e = G(), this.setPersistedProperty(_.AnonymousId, e)), e;
1459
+ }, r.prototype.getDistinctId = function() {
1460
+ return this.getPersistedProperty(_.DistinctId) || this.getAnonymousId();
1461
+ }, r.prototype.unregister = function(e) {
1462
+ delete this.props[e], this.setPersistedProperty(_.Props, this.props);
1463
+ }, r.prototype.register = function(e) {
1464
+ this.props = F(F({}, this.props), e), this.setPersistedProperty(_.Props, this.props);
1465
+ }, r.prototype.registerForSession = function(e) {
1466
+ this.sessionProps = F(F({}, this.sessionProps), e);
1467
+ }, r.prototype.unregisterForSession = function(e) {
1468
+ delete this.sessionProps[e];
1469
+ }, r.prototype.identify = function(e, t, n) {
1470
+ var i = this.getDistinctId();
1471
+ e = e || i, t != null && t.$groups && this.groups(t.$groups);
1472
+ var o = this.enrichProperties(F(F({}, t), { $anon_distinct_id: this.getAnonymousId(), $set: t }));
1473
+ return e !== i && (this.setPersistedProperty(_.AnonymousId, i), this.setPersistedProperty(_.DistinctId, e), this.reloadFeatureFlags()), s.prototype.identifyStateless.call(this, e, o, n), this;
1474
+ }, r.prototype.capture = function(e, t, n) {
1475
+ var i = this.getDistinctId();
1476
+ t != null && t.$groups && this.groups(t.$groups);
1477
+ var o = this.enrichProperties(t);
1478
+ return s.prototype.captureStateless.call(this, i, e, o, n), this;
1479
+ }, r.prototype.alias = function(e) {
1480
+ var t = this.getDistinctId(), n = this.enrichProperties({});
1481
+ return s.prototype.aliasStateless.call(this, e, t, n), this;
1482
+ }, r.prototype.autocapture = function(e, t, n, i) {
1483
+ n === void 0 && (n = {});
1484
+ var o = this.getDistinctId(), u = {
1485
+ distinct_id: o,
1486
+ event: "$autocapture",
1487
+ properties: F(F({}, this.enrichProperties(n)), { $event_type: e, $elements: t })
1488
+ };
1489
+ return this.enqueue("autocapture", u, i), this;
1490
+ }, r.prototype.groups = function(e) {
1491
+ var t = this.props.$groups || {};
1492
+ return this.register({
1493
+ $groups: F(F({}, t), e)
1494
+ }), Object.keys(e).find(function(n) {
1495
+ return t[n] !== e[n];
1496
+ }) && this.reloadFeatureFlags(), this;
1497
+ }, r.prototype.group = function(e, t, n, i) {
1498
+ var o;
1499
+ return this.groups((o = {}, o[e] = t, o)), n && this.groupIdentify(e, t, n, i), this;
1500
+ }, r.prototype.groupIdentify = function(e, t, n, i) {
1501
+ var o = this.getDistinctId(), u = this.enrichProperties({});
1502
+ return s.prototype.groupIdentifyStateless.call(this, e, t, n, i, o, u), this;
1503
+ }, r.prototype.setPersonPropertiesForFlags = function(e) {
1504
+ var t = this.getPersistedProperty(_.PersonProperties) || {};
1505
+ return this.setPersistedProperty(_.PersonProperties, F(F({}, t), e)), this;
1506
+ }, r.prototype.resetPersonPropertiesForFlags = function() {
1507
+ this.setPersistedProperty(_.PersonProperties, {});
1508
+ }, r.prototype.personProperties = function(e) {
1509
+ return this.setPersonPropertiesForFlags(e);
1510
+ }, r.prototype.setGroupPropertiesForFlags = function(e) {
1511
+ var t = this.getPersistedProperty(_.GroupProperties) || {};
1512
+ return Object.keys(t).length !== 0 && Object.keys(t).forEach(function(n) {
1513
+ t[n] = F(F({}, t[n]), e[n]), delete e[n];
1514
+ }), this.setPersistedProperty(_.GroupProperties, F(F({}, t), e)), this;
1515
+ }, r.prototype.resetGroupPropertiesForFlags = function() {
1516
+ this.setPersistedProperty(_.GroupProperties, {});
1517
+ }, r.prototype.groupProperties = function(e) {
1518
+ return this.setGroupPropertiesForFlags(e);
1519
+ }, r.prototype.decideAsync = function(e) {
1520
+ return e === void 0 && (e = !0), this._decideResponsePromise ? this._decideResponsePromise : this._decideAsync(e);
1521
+ }, r.prototype._decideAsync = function(e) {
1522
+ return e === void 0 && (e = !0), A(this, void 0, void 0, function() {
1523
+ var t, n, i, o, u, l = this;
1524
+ return E(this, function(c) {
1525
+ return t = this.getDistinctId(), n = this.props.$groups || {}, i = this.getPersistedProperty(_.PersonProperties) || {}, o = this.getPersistedProperty(_.GroupProperties) || {}, u = {
1526
+ $anon_distinct_id: e ? this.getAnonymousId() : void 0
1527
+ }, this._decideResponsePromise = s.prototype.getDecide.call(this, t, n, i, o, u).then(function(h) {
1528
+ if (h != null && h.featureFlags) {
1529
+ var g = h.featureFlags, d = h.featureFlagPayloads;
1530
+ if (h.errorsWhileComputingFlags) {
1531
+ var f = l.getPersistedProperty(_.FeatureFlags), a = l.getPersistedProperty(_.FeatureFlagPayloads);
1532
+ g = F(F({}, f), h.featureFlags), d = F(F({}, a), h.featureFlagPayloads);
1533
+ }
1534
+ l.setKnownFeatureFlags(g), l.setKnownFeatureFlagPayloads(d);
1535
+ }
1536
+ return h;
1537
+ }).finally(function() {
1538
+ l._decideResponsePromise = void 0;
1539
+ }), [2, this._decideResponsePromise];
1540
+ });
1541
+ });
1542
+ }, r.prototype.setKnownFeatureFlags = function(e) {
1543
+ this.setPersistedProperty(_.FeatureFlags, e), this._events.emit("featureflags", e);
1544
+ }, r.prototype.setKnownFeatureFlagPayloads = function(e) {
1545
+ this.setPersistedProperty(_.FeatureFlagPayloads, e);
1546
+ }, r.prototype.getFeatureFlag = function(e) {
1547
+ var t = this.getFeatureFlags();
1548
+ if (t) {
1549
+ var n = t[e];
1550
+ return n === void 0 && (n = !1), this.sendFeatureFlagEvent && !this.flagCallReported[e] && (this.flagCallReported[e] = !0, this.capture("$feature_flag_called", {
1551
+ $feature_flag: e,
1552
+ $feature_flag_response: n
1553
+ })), n;
1554
+ }
1555
+ }, r.prototype.getFeatureFlagPayload = function(e) {
1556
+ var t = this.getFeatureFlagPayloads();
1557
+ if (t) {
1558
+ var n = t[e];
1559
+ return n === void 0 ? null : this._parsePayload(n);
1560
+ }
1561
+ }, r.prototype.getFeatureFlagPayloads = function() {
1562
+ var e = this, t = this.getPersistedProperty(_.FeatureFlagPayloads);
1563
+ return t && Object.fromEntries(Object.entries(t).map(function(n) {
1564
+ var i = n[0], o = n[1];
1565
+ return [i, e._parsePayload(o)];
1566
+ }));
1567
+ }, r.prototype.getFeatureFlags = function() {
1568
+ var e = this.getPersistedProperty(_.FeatureFlags), t = this.getPersistedProperty(_.OverrideFeatureFlags);
1569
+ if (!t)
1570
+ return e;
1571
+ e = e || {};
1572
+ for (var n in t)
1573
+ t[n] ? e[n] = t[n] : delete e[n];
1574
+ return e;
1575
+ }, r.prototype.getFeatureFlagsAndPayloads = function() {
1576
+ var e = this.getFeatureFlags(), t = this.getFeatureFlagPayloads();
1577
+ return {
1578
+ flags: e,
1579
+ payloads: t
1580
+ };
1581
+ }, r.prototype.isFeatureEnabled = function(e) {
1582
+ var t = this.getFeatureFlag(e);
1583
+ if (t !== void 0)
1584
+ return !!t;
1585
+ }, r.prototype.reloadFeatureFlags = function(e) {
1586
+ this.decideAsync().then(function(t) {
1587
+ e == null || e(void 0, t == null ? void 0 : t.featureFlags);
1588
+ }).catch(function(t) {
1589
+ e == null || e(t, void 0), e || console.log("[PostHog] Error reloading feature flags", t);
1590
+ });
1591
+ }, r.prototype.reloadFeatureFlagsAsync = function(e) {
1592
+ var t;
1593
+ return e === void 0 && (e = !0), A(this, void 0, void 0, function() {
1594
+ return E(this, function(n) {
1595
+ switch (n.label) {
1596
+ case 0:
1597
+ return [4, this.decideAsync(e)];
1598
+ case 1:
1599
+ return [2, (t = n.sent()) === null || t === void 0 ? void 0 : t.featureFlags];
1600
+ }
1601
+ });
1602
+ });
1603
+ }, r.prototype.onFeatureFlags = function(e) {
1604
+ var t = this;
1605
+ return this.on("featureflags", function() {
1606
+ return A(t, void 0, void 0, function() {
1607
+ var n;
1608
+ return E(this, function(i) {
1609
+ return n = this.getFeatureFlags(), n && e(n), [
1610
+ 2
1611
+ /*return*/
1612
+ ];
1613
+ });
1614
+ });
1615
+ });
1616
+ }, r.prototype.onFeatureFlag = function(e, t) {
1617
+ var n = this;
1618
+ return this.on("featureflags", function() {
1619
+ return A(n, void 0, void 0, function() {
1620
+ var i;
1621
+ return E(this, function(o) {
1622
+ return i = this.getFeatureFlag(e), i !== void 0 && t(i), [
1623
+ 2
1624
+ /*return*/
1625
+ ];
1626
+ });
1627
+ });
1628
+ });
1629
+ }, r.prototype.overrideFeatureFlag = function(e) {
1630
+ return e === null ? this.setPersistedProperty(_.OverrideFeatureFlags, null) : this.setPersistedProperty(_.OverrideFeatureFlags, e);
1631
+ }, r;
1632
+ })(te);
1633
+ var _e = (
1634
+ /** @class */
1635
+ function() {
1636
+ function s() {
1637
+ this._memoryStorage = {};
1638
+ }
1639
+ return s.prototype.getProperty = function(r) {
1640
+ return this._memoryStorage[r];
1641
+ }, s.prototype.setProperty = function(r, e) {
1642
+ this._memoryStorage[r] = e !== null ? e : void 0;
1643
+ }, s;
1644
+ }()
1645
+ ), z = (
1646
+ // eslint-disable-next-line @typescript-eslint/prefer-ts-expect-error
1647
+ // @ts-ignore
1648
+ typeof fetch < "u" ? fetch : typeof global.fetch < "u" ? global.fetch : void 0
1649
+ );
1650
+ if (!z) {
1651
+ var Se = require("axios");
1652
+ z = function(s, r) {
1653
+ return A(void 0, void 0, void 0, function() {
1654
+ var e;
1655
+ return E(this, function(t) {
1656
+ switch (t.label) {
1657
+ case 0:
1658
+ return [
1659
+ 4,
1660
+ Se.request({
1661
+ url: s,
1662
+ headers: r.headers,
1663
+ method: r.method.toLowerCase(),
1664
+ data: r.body,
1665
+ signal: r.signal,
1666
+ // fetch only throws on network errors, not on HTTP errors
1667
+ validateStatus: function() {
1668
+ return !0;
1669
+ }
1670
+ })
1671
+ ];
1672
+ case 1:
1673
+ return e = t.sent(), [
1674
+ 2,
1675
+ {
1676
+ status: e.status,
1677
+ text: function() {
1678
+ return A(void 0, void 0, void 0, function() {
1679
+ return E(this, function(n) {
1680
+ return [
1681
+ 2,
1682
+ e.data
1683
+ ];
1684
+ });
1685
+ });
1686
+ },
1687
+ json: function() {
1688
+ return A(void 0, void 0, void 0, function() {
1689
+ return E(this, function(n) {
1690
+ return [
1691
+ 2,
1692
+ e.data
1693
+ ];
1694
+ });
1695
+ });
1696
+ }
1697
+ }
1698
+ ];
1699
+ }
1700
+ });
1701
+ });
1702
+ };
1703
+ }
1704
+ var re = z, Ae = 1152921504606847e3, J = (
1705
+ /** @class */
1706
+ function(s) {
1707
+ x(r, s);
1708
+ function r(e) {
1709
+ var t = s.call(this) || this;
1710
+ return Error.captureStackTrace(t, t.constructor), t.name = "ClientError", t.message = e, Object.setPrototypeOf(t, r.prototype), t;
1711
+ }
1712
+ return r;
1713
+ }(Error)
1714
+ ), C = (
1715
+ /** @class */
1716
+ function(s) {
1717
+ x(r, s);
1718
+ function r(e) {
1719
+ var t = s.call(this, e) || this;
1720
+ return t.name = t.constructor.name, Error.captureStackTrace(t, t.constructor), Object.setPrototypeOf(t, r.prototype), t;
1721
+ }
1722
+ return r;
1723
+ }(Error)
1724
+ ), Ee = (
1725
+ /** @class */
1726
+ function() {
1727
+ function s(r) {
1728
+ var e = r.pollingInterval, t = r.personalApiKey, n = r.projectApiKey, i = r.timeout, o = r.host, u = fe(r, ["pollingInterval", "personalApiKey", "projectApiKey", "timeout", "host"]);
1729
+ this.debugMode = !1, this.pollingInterval = e, this.personalApiKey = t, this.featureFlags = [], this.featureFlagsByKey = {}, this.groupTypeMapping = {}, this.cohorts = {}, this.loadedSuccessfullyOnce = !1, this.timeout = i, this.projectApiKey = n, this.host = o, this.poller = void 0, this.fetch = u.fetch || re, this.onError = u.onError, this.loadFeatureFlags();
1730
+ }
1731
+ return s.prototype.debug = function(r) {
1732
+ r === void 0 && (r = !0), this.debugMode = r;
1733
+ }, s.prototype.getFeatureFlag = function(r, e, t, n, i) {
1734
+ var o;
1735
+ return t === void 0 && (t = {}), n === void 0 && (n = {}), i === void 0 && (i = {}), A(this, void 0, void 0, function() {
1736
+ var u, l, c, h, g;
1737
+ return E(this, function(d) {
1738
+ switch (d.label) {
1739
+ case 0:
1740
+ return [
1741
+ 4,
1742
+ this.loadFeatureFlags()
1743
+ ];
1744
+ case 1:
1745
+ if (d.sent(), u = void 0, l = void 0, !this.loadedSuccessfullyOnce)
1746
+ return [
1747
+ 2,
1748
+ u
1749
+ ];
1750
+ for (c = 0, h = this.featureFlags; c < h.length; c++)
1751
+ if (g = h[c], r === g.key) {
1752
+ l = g;
1753
+ break;
1754
+ }
1755
+ if (l !== void 0)
1756
+ try {
1757
+ u = this.computeFlagLocally(l, e, t, n, i), this.debugMode && console.debug("Successfully computed flag locally: ".concat(r, " -> ").concat(u));
1758
+ } catch (f) {
1759
+ f instanceof C ? this.debugMode && console.debug("InconclusiveMatchError when computing flag locally: ".concat(r, ": ").concat(f)) : f instanceof Error && ((o = this.onError) === null || o === void 0 || o.call(this, new Error("Error computing flag locally: ".concat(r, ": ").concat(f))));
1760
+ }
1761
+ return [
1762
+ 2,
1763
+ u
1764
+ ];
1765
+ }
1766
+ });
1767
+ });
1768
+ }, s.prototype.computeFeatureFlagPayloadLocally = function(r, e) {
1769
+ var t, n, i, o, u, l, c, h;
1770
+ return A(this, void 0, void 0, function() {
1771
+ var g;
1772
+ return E(this, function(d) {
1773
+ switch (d.label) {
1774
+ case 0:
1775
+ return [
1776
+ 4,
1777
+ this.loadFeatureFlags()
1778
+ ];
1779
+ case 1:
1780
+ return d.sent(), g = void 0, this.loadedSuccessfullyOnce ? (typeof e == "boolean" ? g = (o = (i = (n = (t = this.featureFlagsByKey) === null || t === void 0 ? void 0 : t[r]) === null || n === void 0 ? void 0 : n.filters) === null || i === void 0 ? void 0 : i.payloads) === null || o === void 0 ? void 0 : o[e.toString()] : typeof e == "string" && (g = (h = (c = (l = (u = this.featureFlagsByKey) === null || u === void 0 ? void 0 : u[r]) === null || l === void 0 ? void 0 : l.filters) === null || c === void 0 ? void 0 : c.payloads) === null || h === void 0 ? void 0 : h[e]), g === void 0 ? [
1781
+ 2,
1782
+ null
1783
+ ] : [
1784
+ 2,
1785
+ g
1786
+ ]) : [
1787
+ 2,
1788
+ void 0
1789
+ ];
1790
+ }
1791
+ });
1792
+ });
1793
+ }, s.prototype.getAllFlagsAndPayloads = function(r, e, t, n) {
1794
+ return e === void 0 && (e = {}), t === void 0 && (t = {}), n === void 0 && (n = {}), A(this, void 0, void 0, function() {
1795
+ var i, o, u, l = this;
1796
+ return E(this, function(c) {
1797
+ switch (c.label) {
1798
+ case 0:
1799
+ return [
1800
+ 4,
1801
+ this.loadFeatureFlags()
1802
+ ];
1803
+ case 1:
1804
+ return c.sent(), i = {}, o = {}, u = this.featureFlags.length == 0, this.featureFlags.map(function(h) {
1805
+ return A(l, void 0, void 0, function() {
1806
+ var g, d, f, a;
1807
+ return E(this, function(v) {
1808
+ switch (v.label) {
1809
+ case 0:
1810
+ return v.trys.push([0, 2, , 3]), g = this.computeFlagLocally(h, r, e, t, n), i[h.key] = g, [
1811
+ 4,
1812
+ this.computeFeatureFlagPayloadLocally(h.key, g)
1813
+ ];
1814
+ case 1:
1815
+ return d = v.sent(), d && (o[h.key] = d), [
1816
+ 3,
1817
+ 3
1818
+ ];
1819
+ case 2:
1820
+ return f = v.sent(), f instanceof C || f instanceof Error && ((a = this.onError) === null || a === void 0 || a.call(this, new Error("Error computing flag locally: ".concat(h.key, ": ").concat(f)))), u = !0, [
1821
+ 3,
1822
+ 3
1823
+ ];
1824
+ case 3:
1825
+ return [
1826
+ 2
1827
+ /*return*/
1828
+ ];
1829
+ }
1830
+ });
1831
+ });
1832
+ }), [
1833
+ 2,
1834
+ {
1835
+ response: i,
1836
+ payloads: o,
1837
+ fallbackToDecide: u
1838
+ }
1839
+ ];
1840
+ }
1841
+ });
1842
+ });
1843
+ }, s.prototype.computeFlagLocally = function(r, e, t, n, i) {
1844
+ if (t === void 0 && (t = {}), n === void 0 && (n = {}), i === void 0 && (i = {}), r.ensure_experience_continuity)
1845
+ throw new C("Flag has experience continuity enabled");
1846
+ if (!r.active)
1847
+ return !1;
1848
+ var o = r.filters || {}, u = o.aggregation_group_type_index;
1849
+ if (u != null) {
1850
+ var l = this.groupTypeMapping[String(u)];
1851
+ if (!l)
1852
+ throw this.debugMode && console.warn("[FEATURE FLAGS] Unknown group type index ".concat(u, " for feature flag ").concat(r.key)), new C("Flag has unknown group type index");
1853
+ if (!(l in t))
1854
+ return this.debugMode && console.warn("[FEATURE FLAGS] Can't compute group feature flag: ".concat(r.key, " without group names passed in")), !1;
1855
+ var c = i[l];
1856
+ return this.matchFeatureFlagProperties(r, t[l], c);
1857
+ } else
1858
+ return this.matchFeatureFlagProperties(r, e, n);
1859
+ }, s.prototype.matchFeatureFlagProperties = function(r, e, t) {
1860
+ for (var n, i = r.filters || {}, o = i.groups || [], u = !1, l = void 0, c = Z([], o).sort(function(p, w) {
1861
+ var y = !!p.variant, m = !!w.variant;
1862
+ return y && m ? 0 : y ? -1 : m ? 1 : 0;
1863
+ }), h = function(p) {
1864
+ try {
1865
+ if (g.isConditionMatch(r, e, p, t)) {
1866
+ var w = p.variant, y = ((n = i.multivariate) === null || n === void 0 ? void 0 : n.variants) || [];
1867
+ return w && y.some(function(m) {
1868
+ return m.key === w;
1869
+ }) ? l = w : l = g.getMatchingVariant(r, e) || !0, "break";
1870
+ }
1871
+ } catch (m) {
1872
+ if (m instanceof C)
1873
+ u = !0;
1874
+ else
1875
+ throw m;
1876
+ }
1877
+ }, g = this, d = 0, f = c; d < f.length; d++) {
1878
+ var a = f[d], v = h(a);
1879
+ if (v === "break") break;
1880
+ }
1881
+ if (l !== void 0)
1882
+ return l;
1883
+ if (u)
1884
+ throw new C("Can't determine if feature flag is enabled or not with given properties");
1885
+ return !1;
1886
+ }, s.prototype.isConditionMatch = function(r, e, t, n) {
1887
+ var i = t.rollout_percentage;
1888
+ if ((t.properties || []).length > 0) {
1889
+ for (var o = 0, u = t.properties; o < u.length; o++) {
1890
+ var l = u[o], c = l.type, h = !1;
1891
+ if (c === "cohort" ? h = ne(l, n, this.cohorts) : h = ie(l, n), !h)
1892
+ return !1;
1893
+ }
1894
+ if (i == null)
1895
+ return !0;
1896
+ }
1897
+ return !(i != null && V(r.key, e) > i / 100);
1898
+ }, s.prototype.getMatchingVariant = function(r, e) {
1899
+ var t = V(r.key, e, "variant"), n = this.variantLookupTable(r).find(function(i) {
1900
+ return t >= i.valueMin && t < i.valueMax;
1901
+ });
1902
+ if (n)
1903
+ return n.key;
1904
+ }, s.prototype.variantLookupTable = function(r) {
1905
+ var e, t = [], n = 0, i = 0, o = r.filters || {}, u = ((e = o.multivariate) === null || e === void 0 ? void 0 : e.variants) || [];
1906
+ return u.forEach(function(l) {
1907
+ i = n + l.rollout_percentage / 100, t.push({
1908
+ valueMin: n,
1909
+ valueMax: i,
1910
+ key: l.key
1911
+ }), n = i;
1912
+ }), t;
1913
+ }, s.prototype.loadFeatureFlags = function(r) {
1914
+ return r === void 0 && (r = !1), A(this, void 0, void 0, function() {
1915
+ return E(this, function(e) {
1916
+ switch (e.label) {
1917
+ case 0:
1918
+ return !this.loadedSuccessfullyOnce || r ? [
1919
+ 4,
1920
+ this._loadFeatureFlags()
1921
+ ] : [
1922
+ 3,
1923
+ 2
1924
+ ];
1925
+ case 1:
1926
+ e.sent(), e.label = 2;
1927
+ case 2:
1928
+ return [
1929
+ 2
1930
+ /*return*/
1931
+ ];
1932
+ }
1933
+ });
1934
+ });
1935
+ }, s.prototype._loadFeatureFlags = function() {
1936
+ var r, e;
1937
+ return A(this, void 0, void 0, function() {
1938
+ var t, n, i, o = this;
1939
+ return E(this, function(u) {
1940
+ switch (u.label) {
1941
+ case 0:
1942
+ this.poller && (clearTimeout(this.poller), this.poller = void 0), this.poller = setTimeout(function() {
1943
+ return o._loadFeatureFlags();
1944
+ }, this.pollingInterval), u.label = 1;
1945
+ case 1:
1946
+ return u.trys.push([1, 4, , 5]), [
1947
+ 4,
1948
+ this._requestFeatureFlagDefinitions()
1949
+ ];
1950
+ case 2:
1951
+ if (t = u.sent(), t && t.status === 401)
1952
+ throw new J("Your personalApiKey is invalid. Are you sure you're not using your Project API key? More information: https://posthog.com/docs/api/overview");
1953
+ return t && t.status !== 200 ? [
1954
+ 2
1955
+ /*return*/
1956
+ ] : [
1957
+ 4,
1958
+ t.json()
1959
+ ];
1960
+ case 3:
1961
+ return n = u.sent(), "flags" in n || (r = this.onError) === null || r === void 0 || r.call(this, new Error("Invalid response when getting feature flags: ".concat(JSON.stringify(n)))), this.featureFlags = n.flags || [], this.featureFlagsByKey = this.featureFlags.reduce(function(l, c) {
1962
+ return l[c.key] = c, l;
1963
+ }, {}), this.groupTypeMapping = n.group_type_mapping || {}, this.cohorts = n.cohorts || [], this.loadedSuccessfullyOnce = !0, [
1964
+ 3,
1965
+ 5
1966
+ ];
1967
+ case 4:
1968
+ return i = u.sent(), i instanceof J && ((e = this.onError) === null || e === void 0 || e.call(this, i)), [
1969
+ 3,
1970
+ 5
1971
+ ];
1972
+ case 5:
1973
+ return [
1974
+ 2
1975
+ /*return*/
1976
+ ];
1977
+ }
1978
+ });
1979
+ });
1980
+ }, s.prototype._requestFeatureFlagDefinitions = function() {
1981
+ return A(this, void 0, void 0, function() {
1982
+ var r, e, t, n;
1983
+ return E(this, function(i) {
1984
+ switch (i.label) {
1985
+ case 0:
1986
+ r = "".concat(this.host, "/api/feature_flag/local_evaluation?token=").concat(this.projectApiKey, "&send_cohorts"), e = {
1987
+ method: "GET",
1988
+ headers: {
1989
+ "Content-Type": "application/json",
1990
+ Authorization: "Bearer ".concat(this.personalApiKey),
1991
+ "user-agent": "posthog-node/".concat($)
1992
+ }
1993
+ }, t = null, this.timeout && typeof this.timeout == "number" && (n = new AbortController(), t = ee(function() {
1994
+ n.abort();
1995
+ }, this.timeout), e.signal = n.signal), i.label = 1;
1996
+ case 1:
1997
+ return i.trys.push([1, , 3, 4]), [
1998
+ 4,
1999
+ this.fetch(r, e)
2000
+ ];
2001
+ case 2:
2002
+ return [
2003
+ 2,
2004
+ i.sent()
2005
+ ];
2006
+ case 3:
2007
+ return clearTimeout(t), [
2008
+ 7
2009
+ /*endfinally*/
2010
+ ];
2011
+ case 4:
2012
+ return [
2013
+ 2
2014
+ /*return*/
2015
+ ];
2016
+ }
2017
+ });
2018
+ });
2019
+ }, s.prototype.stopPoller = function() {
2020
+ clearTimeout(this.poller);
2021
+ }, s;
2022
+ }()
2023
+ );
2024
+ function V(s, r, e) {
2025
+ e === void 0 && (e = "");
2026
+ var t = ce.createHash();
2027
+ return t.update("".concat(s, ".").concat(r).concat(e)), parseInt(t.digest("hex").slice(0, 15), 16) / Ae;
2028
+ }
2029
+ function ie(s, r) {
2030
+ var e = s.key, t = s.value, n = s.operator || "exact";
2031
+ if (e in r) {
2032
+ if (n === "is_not_set")
2033
+ throw new C("Operator is_not_set is not supported");
2034
+ } else throw new C("Property ".concat(e, " not found in propertyValues"));
2035
+ var i = r[e];
2036
+ function o(g, d) {
2037
+ return Array.isArray(g) ? g.map(function(f) {
2038
+ return String(f).toLowerCase();
2039
+ }).includes(String(d).toLowerCase()) : String(g).toLowerCase() === String(d).toLowerCase();
2040
+ }
2041
+ function u(g, d, f) {
2042
+ if (f === "gt")
2043
+ return g > d;
2044
+ if (f === "gte")
2045
+ return g >= d;
2046
+ if (f === "lt")
2047
+ return g < d;
2048
+ if (f === "lte")
2049
+ return g <= d;
2050
+ throw new Error("Invalid operator: ".concat(f));
2051
+ }
2052
+ switch (n) {
2053
+ case "exact":
2054
+ return o(t, i);
2055
+ case "is_not":
2056
+ return !o(t, i);
2057
+ case "is_set":
2058
+ return e in r;
2059
+ case "icontains":
2060
+ return String(i).toLowerCase().includes(String(t).toLowerCase());
2061
+ case "not_icontains":
2062
+ return !String(i).toLowerCase().includes(String(t).toLowerCase());
2063
+ case "regex":
2064
+ return Q(String(t)) && String(i).match(String(t)) !== null;
2065
+ case "not_regex":
2066
+ return Q(String(t)) && String(i).match(String(t)) === null;
2067
+ case "gt":
2068
+ case "gte":
2069
+ case "lt":
2070
+ case "lte": {
2071
+ var l = typeof t == "number" ? t : null;
2072
+ if (typeof t == "string")
2073
+ try {
2074
+ l = parseFloat(t);
2075
+ } catch {
2076
+ }
2077
+ return l != null && i != null ? typeof i == "string" ? u(i, String(t), n) : u(i, l, n) : u(String(i), String(t), n);
2078
+ }
2079
+ case "is_date_after":
2080
+ case "is_date_before": {
2081
+ var c = Oe(String(t));
2082
+ if (c == null && (c = Y(t)), c == null)
2083
+ throw new C("Invalid date: ".concat(t));
2084
+ var h = Y(i);
2085
+ return ["is_date_before"].includes(n) ? h < c : h > c;
2086
+ }
2087
+ default:
2088
+ throw new C("Unknown operator: ".concat(n));
2089
+ }
2090
+ }
2091
+ function ne(s, r, e) {
2092
+ var t = String(s.value);
2093
+ if (!(t in e))
2094
+ throw new C("can't match cohort without a given cohort property value");
2095
+ var n = e[t];
2096
+ return oe(n, r, e);
2097
+ }
2098
+ function oe(s, r, e) {
2099
+ if (!s)
2100
+ return !0;
2101
+ var t = s.type, n = s.values;
2102
+ if (!n || n.length === 0)
2103
+ return !0;
2104
+ var i = !1;
2105
+ if ("values" in n[0]) {
2106
+ for (var o = 0, u = n; o < u.length; o++) {
2107
+ var l = u[o];
2108
+ try {
2109
+ var c = oe(l, r, e);
2110
+ if (t === "AND") {
2111
+ if (!c)
2112
+ return !1;
2113
+ } else if (c)
2114
+ return !0;
2115
+ } catch (f) {
2116
+ if (f instanceof C)
2117
+ console.debug("Failed to compute property ".concat(l, " locally: ").concat(f)), i = !0;
2118
+ else
2119
+ throw f;
2120
+ }
2121
+ }
2122
+ if (i)
2123
+ throw new C("Can't match cohort without a given cohort property value");
2124
+ return t === "AND";
2125
+ } else {
2126
+ for (var h = 0, g = n; h < g.length; h++) {
2127
+ var l = g[h];
2128
+ try {
2129
+ var c = void 0;
2130
+ l.type === "cohort" ? c = ne(l, r, e) : c = ie(l, r);
2131
+ var d = l.negation || !1;
2132
+ if (t === "AND") {
2133
+ if (!c && !d || c && d)
2134
+ return !1;
2135
+ } else if (c && !d || !c && d)
2136
+ return !0;
2137
+ } catch (a) {
2138
+ if (a instanceof C)
2139
+ console.debug("Failed to compute property ".concat(l, " locally: ").concat(a)), i = !0;
2140
+ else
2141
+ throw a;
2142
+ }
2143
+ }
2144
+ if (i)
2145
+ throw new C("can't match cohort without a given cohort property value");
2146
+ return t === "AND";
2147
+ }
2148
+ }
2149
+ function Q(s) {
2150
+ try {
2151
+ return new RegExp(s), !0;
2152
+ } catch {
2153
+ return !1;
2154
+ }
2155
+ }
2156
+ function Y(s) {
2157
+ if (s instanceof Date)
2158
+ return s;
2159
+ if (typeof s == "string" || typeof s == "number") {
2160
+ var r = new Date(s);
2161
+ if (!isNaN(r.valueOf()))
2162
+ return r;
2163
+ throw new C("".concat(s, " is in an invalid date format"));
2164
+ } else
2165
+ throw new C("The date provided ".concat(s, " must be a string, number, or date object"));
2166
+ }
2167
+ function Oe(s) {
2168
+ var r = /^-?(?<number>[0-9]+)(?<interval>[a-z])$/, e = s.match(r), t = new Date((/* @__PURE__ */ new Date()).toISOString());
2169
+ if (e) {
2170
+ if (!e.groups)
2171
+ return null;
2172
+ var n = parseInt(e.groups.number);
2173
+ if (n >= 1e4)
2174
+ return null;
2175
+ var i = e.groups.interval;
2176
+ if (i == "h")
2177
+ t.setUTCHours(t.getUTCHours() - n);
2178
+ else if (i == "d")
2179
+ t.setUTCDate(t.getUTCDate() - n);
2180
+ else if (i == "w")
2181
+ t.setUTCDate(t.getUTCDate() - n * 7);
2182
+ else if (i == "m")
2183
+ t.setUTCMonth(t.getUTCMonth() - n);
2184
+ else if (i == "y")
2185
+ t.setUTCFullYear(t.getUTCFullYear() - n);
2186
+ else
2187
+ return null;
2188
+ return t;
2189
+ } else
2190
+ return null;
2191
+ }
2192
+ var Ce = 30 * 1e3, Ie = 50 * 1e3, ke = (
2193
+ /** @class */
2194
+ function(s) {
2195
+ x(r, s);
2196
+ function r(e, t) {
2197
+ t === void 0 && (t = {});
2198
+ var n = this, i;
2199
+ return t.captureMode = (t == null ? void 0 : t.captureMode) || "json", n = s.call(this, e, t) || this, n._memoryStorage = new _e(), n.options = t, t.personalApiKey && (n.featureFlagsPoller = new Ee({
2200
+ pollingInterval: typeof t.featureFlagsPollingInterval == "number" ? t.featureFlagsPollingInterval : Ce,
2201
+ personalApiKey: t.personalApiKey,
2202
+ projectApiKey: e,
2203
+ timeout: (i = t.requestTimeout) !== null && i !== void 0 ? i : 1e4,
2204
+ host: n.host,
2205
+ fetch: t.fetch,
2206
+ onError: function(o) {
2207
+ n._events.emit("error", o);
2208
+ }
2209
+ })), n.distinctIdHasSentFlagCalls = {}, n.maxCacheSize = t.maxCacheSize || Ie, n;
2210
+ }
2211
+ return r.prototype.getPersistedProperty = function(e) {
2212
+ return this._memoryStorage.getProperty(e);
2213
+ }, r.prototype.setPersistedProperty = function(e, t) {
2214
+ return this._memoryStorage.setProperty(e, t);
2215
+ }, r.prototype.fetch = function(e, t) {
2216
+ return this.options.fetch ? this.options.fetch(e, t) : re(e, t);
2217
+ }, r.prototype.getLibraryId = function() {
2218
+ return "posthog-node";
2219
+ }, r.prototype.getLibraryVersion = function() {
2220
+ return $;
2221
+ }, r.prototype.getCustomUserAgent = function() {
2222
+ return "posthog-node/".concat($);
2223
+ }, r.prototype.enable = function() {
2224
+ return s.prototype.optIn.call(this);
2225
+ }, r.prototype.disable = function() {
2226
+ return s.prototype.optOut.call(this);
2227
+ }, r.prototype.debug = function(e) {
2228
+ var t;
2229
+ e === void 0 && (e = !0), s.prototype.debug.call(this, e), (t = this.featureFlagsPoller) === null || t === void 0 || t.debug(e);
2230
+ }, r.prototype.capture = function(e) {
2231
+ var t = this, n = e.distinctId, i = e.event, o = e.properties, u = e.groups, l = e.sendFeatureFlags, c = e.timestamp, h = e.disableGeoip, g = e.uuid, d = function(a) {
2232
+ s.prototype.captureStateless.call(t, n, i, a, {
2233
+ timestamp: c,
2234
+ disableGeoip: h,
2235
+ uuid: g
2236
+ });
2237
+ }, f = Promise.resolve().then(function() {
2238
+ return A(t, void 0, void 0, function() {
2239
+ var a, v, p, w, y, m, b, P;
2240
+ return E(this, function(S) {
2241
+ switch (S.label) {
2242
+ case 0:
2243
+ return l ? [
2244
+ 4,
2245
+ s.prototype.getFeatureFlagsStateless.call(this, n, u, void 0, void 0, h)
2246
+ ] : [
2247
+ 3,
2248
+ 2
2249
+ ];
2250
+ case 1:
2251
+ return [
2252
+ 2,
2253
+ S.sent()
2254
+ ];
2255
+ case 2:
2256
+ if (!((((P = (b = this.featureFlagsPoller) === null || b === void 0 ? void 0 : b.featureFlags) === null || P === void 0 ? void 0 : P.length) || 0) > 0)) return [
2257
+ 3,
2258
+ 4
2259
+ ];
2260
+ for (a = {}, v = 0, p = Object.entries(u || {}); v < p.length; v++)
2261
+ w = p[v], y = w[0], m = w[1], a[y] = String(m);
2262
+ return [
2263
+ 4,
2264
+ this.getAllFlags(n, {
2265
+ groups: a,
2266
+ disableGeoip: h,
2267
+ onlyEvaluateLocally: !0
2268
+ })
2269
+ ];
2270
+ case 3:
2271
+ return [
2272
+ 2,
2273
+ S.sent()
2274
+ ];
2275
+ case 4:
2276
+ return [
2277
+ 2,
2278
+ {}
2279
+ ];
2280
+ }
2281
+ });
2282
+ });
2283
+ }).then(function(a) {
2284
+ var v = {};
2285
+ if (a)
2286
+ for (var p = 0, w = Object.entries(a); p < w.length; p++) {
2287
+ var y = w[p], m = y[0], b = y[1];
2288
+ v["$feature/".concat(m)] = b;
2289
+ }
2290
+ var P = Object.keys(a || {}).filter(function(S) {
2291
+ return (a == null ? void 0 : a[S]) !== !1;
2292
+ });
2293
+ return P.length > 0 && (v.$active_feature_flags = P), v;
2294
+ }).catch(function() {
2295
+ return {};
2296
+ }).then(function(a) {
2297
+ d(F(F(F({}, a), o), {
2298
+ $groups: u
2299
+ }));
2300
+ });
2301
+ this.addPendingPromise(f);
2302
+ }, r.prototype.identify = function(e) {
2303
+ var t = e.distinctId, n = e.properties, i = e.disableGeoip, o = (n == null ? void 0 : n.$set) || n;
2304
+ s.prototype.identifyStateless.call(this, t, {
2305
+ $set: o
2306
+ }, {
2307
+ disableGeoip: i
2308
+ });
2309
+ }, r.prototype.alias = function(e) {
2310
+ s.prototype.aliasStateless.call(this, e.alias, e.distinctId, void 0, {
2311
+ disableGeoip: e.disableGeoip
2312
+ });
2313
+ }, r.prototype.getFeatureFlag = function(e, t, n) {
2314
+ var i;
2315
+ return A(this, void 0, void 0, function() {
2316
+ var o, u, l, c, h, g, d, f, a, v, p, w, y;
2317
+ return E(this, function(m) {
2318
+ switch (m.label) {
2319
+ case 0:
2320
+ return o = n || {}, u = o.groups, l = o.disableGeoip, c = n || {}, h = c.onlyEvaluateLocally, g = c.sendFeatureFlagEvents, d = c.personProperties, f = c.groupProperties, a = this.addLocalPersonAndGroupProperties(t, u, d, f), d = a.allPersonProperties, f = a.allGroupProperties, h == null && (h = !1), g == null && (g = !0), [
2321
+ 4,
2322
+ (i = this.featureFlagsPoller) === null || i === void 0 ? void 0 : i.getFeatureFlag(e, t, u, d, f)
2323
+ ];
2324
+ case 1:
2325
+ return v = m.sent(), p = v !== void 0, !p && !h ? [
2326
+ 4,
2327
+ s.prototype.getFeatureFlagStateless.call(this, e, t, u, d, f, l)
2328
+ ] : [
2329
+ 3,
2330
+ 3
2331
+ ];
2332
+ case 2:
2333
+ v = m.sent(), m.label = 3;
2334
+ case 3:
2335
+ return w = "".concat(e, "_").concat(v), g && (!(t in this.distinctIdHasSentFlagCalls) || !this.distinctIdHasSentFlagCalls[t].includes(w)) && (Object.keys(this.distinctIdHasSentFlagCalls).length >= this.maxCacheSize && (this.distinctIdHasSentFlagCalls = {}), Array.isArray(this.distinctIdHasSentFlagCalls[t]) ? this.distinctIdHasSentFlagCalls[t].push(w) : this.distinctIdHasSentFlagCalls[t] = [w], this.capture({
2336
+ distinctId: t,
2337
+ event: "$feature_flag_called",
2338
+ properties: (y = {
2339
+ $feature_flag: e,
2340
+ $feature_flag_response: v,
2341
+ locally_evaluated: p
2342
+ }, y["$feature/".concat(e)] = v, y),
2343
+ groups: u,
2344
+ disableGeoip: l
2345
+ })), [
2346
+ 2,
2347
+ v
2348
+ ];
2349
+ }
2350
+ });
2351
+ });
2352
+ }, r.prototype.getFeatureFlagPayload = function(e, t, n, i) {
2353
+ var o;
2354
+ return A(this, void 0, void 0, function() {
2355
+ var u, l, c, h, g, d, f, a, v, p;
2356
+ return E(this, function(w) {
2357
+ switch (w.label) {
2358
+ case 0:
2359
+ return u = i || {}, l = u.groups, c = u.disableGeoip, h = i || {}, g = h.onlyEvaluateLocally, h.sendFeatureFlagEvents, d = h.personProperties, f = h.groupProperties, a = this.addLocalPersonAndGroupProperties(t, l, d, f), d = a.allPersonProperties, f = a.allGroupProperties, v = void 0, n ? [
2360
+ 3,
2361
+ 2
2362
+ ] : [
2363
+ 4,
2364
+ this.getFeatureFlag(e, t, F(F({}, i), {
2365
+ onlyEvaluateLocally: !0
2366
+ }))
2367
+ ];
2368
+ case 1:
2369
+ n = w.sent(), w.label = 2;
2370
+ case 2:
2371
+ return n ? [
2372
+ 4,
2373
+ (o = this.featureFlagsPoller) === null || o === void 0 ? void 0 : o.computeFeatureFlagPayloadLocally(e, n)
2374
+ ] : [
2375
+ 3,
2376
+ 4
2377
+ ];
2378
+ case 3:
2379
+ v = w.sent(), w.label = 4;
2380
+ case 4:
2381
+ return g == null && (g = !1), g == null && (g = !1), p = v !== void 0, !p && !g ? [
2382
+ 4,
2383
+ s.prototype.getFeatureFlagPayloadStateless.call(this, e, t, l, d, f, c)
2384
+ ] : [
2385
+ 3,
2386
+ 6
2387
+ ];
2388
+ case 5:
2389
+ v = w.sent(), w.label = 6;
2390
+ case 6:
2391
+ try {
2392
+ return [
2393
+ 2,
2394
+ JSON.parse(v)
2395
+ ];
2396
+ } catch {
2397
+ return [
2398
+ 2,
2399
+ v
2400
+ ];
2401
+ }
2402
+ return [
2403
+ 2
2404
+ /*return*/
2405
+ ];
2406
+ }
2407
+ });
2408
+ });
2409
+ }, r.prototype.isFeatureEnabled = function(e, t, n) {
2410
+ return A(this, void 0, void 0, function() {
2411
+ var i;
2412
+ return E(this, function(o) {
2413
+ switch (o.label) {
2414
+ case 0:
2415
+ return [
2416
+ 4,
2417
+ this.getFeatureFlag(e, t, n)
2418
+ ];
2419
+ case 1:
2420
+ return i = o.sent(), i === void 0 ? [
2421
+ 2,
2422
+ void 0
2423
+ ] : [
2424
+ 2,
2425
+ !!i || !1
2426
+ ];
2427
+ }
2428
+ });
2429
+ });
2430
+ }, r.prototype.getAllFlags = function(e, t) {
2431
+ return A(this, void 0, void 0, function() {
2432
+ var n;
2433
+ return E(this, function(i) {
2434
+ switch (i.label) {
2435
+ case 0:
2436
+ return [
2437
+ 4,
2438
+ this.getAllFlagsAndPayloads(e, t)
2439
+ ];
2440
+ case 1:
2441
+ return n = i.sent(), [
2442
+ 2,
2443
+ n.featureFlags
2444
+ ];
2445
+ }
2446
+ });
2447
+ });
2448
+ }, r.prototype.getAllFlagsAndPayloads = function(e, t) {
2449
+ var n;
2450
+ return A(this, void 0, void 0, function() {
2451
+ var i, o, u, l, c, h, g, d, f, a, v, p, w;
2452
+ return E(this, function(y) {
2453
+ switch (y.label) {
2454
+ case 0:
2455
+ return i = t || {}, o = i.groups, u = i.disableGeoip, l = t || {}, c = l.onlyEvaluateLocally, h = l.personProperties, g = l.groupProperties, d = this.addLocalPersonAndGroupProperties(e, o, h, g), h = d.allPersonProperties, g = d.allGroupProperties, c == null && (c = !1), [
2456
+ 4,
2457
+ (n = this.featureFlagsPoller) === null || n === void 0 ? void 0 : n.getAllFlagsAndPayloads(e, o, h, g)
2458
+ ];
2459
+ case 1:
2460
+ return f = y.sent(), a = {}, v = {}, p = !0, f && (a = f.response, v = f.payloads, p = f.fallbackToDecide), p && !c ? [
2461
+ 4,
2462
+ s.prototype.getFeatureFlagsAndPayloadsStateless.call(this, e, o, h, g, u)
2463
+ ] : [
2464
+ 3,
2465
+ 3
2466
+ ];
2467
+ case 2:
2468
+ w = y.sent(), a = F(F({}, a), w.flags || {}), v = F(F({}, v), w.payloads || {}), y.label = 3;
2469
+ case 3:
2470
+ return [
2471
+ 2,
2472
+ {
2473
+ featureFlags: a,
2474
+ featureFlagPayloads: v
2475
+ }
2476
+ ];
2477
+ }
2478
+ });
2479
+ });
2480
+ }, r.prototype.groupIdentify = function(e) {
2481
+ var t = e.groupType, n = e.groupKey, i = e.properties, o = e.distinctId, u = e.disableGeoip;
2482
+ s.prototype.groupIdentifyStateless.call(this, t, n, i, {
2483
+ disableGeoip: u
2484
+ }, o);
2485
+ }, r.prototype.reloadFeatureFlags = function() {
2486
+ var e;
2487
+ return A(this, void 0, void 0, function() {
2488
+ return E(this, function(t) {
2489
+ switch (t.label) {
2490
+ case 0:
2491
+ return [
2492
+ 4,
2493
+ (e = this.featureFlagsPoller) === null || e === void 0 ? void 0 : e.loadFeatureFlags(!0)
2494
+ ];
2495
+ case 1:
2496
+ return t.sent(), [
2497
+ 2
2498
+ /*return*/
2499
+ ];
2500
+ }
2501
+ });
2502
+ });
2503
+ }, r.prototype.shutdown = function() {
2504
+ this.shutdownAsync();
2505
+ }, r.prototype.shutdownAsync = function() {
2506
+ var e;
2507
+ return A(this, void 0, void 0, function() {
2508
+ return E(this, function(t) {
2509
+ return (e = this.featureFlagsPoller) === null || e === void 0 || e.stopPoller(), [
2510
+ 2,
2511
+ s.prototype.shutdownAsync.call(this)
2512
+ ];
2513
+ });
2514
+ });
2515
+ }, r.prototype.addLocalPersonAndGroupProperties = function(e, t, n, i) {
2516
+ var o = F({
2517
+ distinct_id: e
2518
+ }, n || {}), u = {};
2519
+ if (t)
2520
+ for (var l = 0, c = Object.keys(t); l < c.length; l++) {
2521
+ var h = c[l];
2522
+ u[h] = F({
2523
+ $group_key: t[h]
2524
+ }, (i == null ? void 0 : i[h]) || {});
2525
+ }
2526
+ return {
2527
+ allPersonProperties: o,
2528
+ allGroupProperties: u
2529
+ };
2530
+ }, r;
2531
+ }(te)
2532
+ );
2533
+ class Me extends X {
2534
+ constructor(e) {
2535
+ super({ debug: e.debug, enabled: e.enabled });
2536
+ L(this, "name", "PostHog-Server");
2537
+ L(this, "client");
2538
+ L(this, "initialized", !1);
2539
+ L(this, "config");
2540
+ this.config = e;
2541
+ }
2542
+ initialize() {
2543
+ if (this.isEnabled() && !this.initialized) {
2544
+ if (!this.config.apiKey || typeof this.config.apiKey != "string")
2545
+ throw new Error("PostHog requires an apiKey");
2546
+ try {
2547
+ this.client = new ke(this.config.apiKey, {
2548
+ host: this.config.host || "https://app.posthog.com",
2549
+ flushAt: 20,
2550
+ flushInterval: 1e4
2551
+ }), this.initialized = !0, this.log("Initialized successfully", this.config);
2552
+ } catch (e) {
2553
+ throw console.error("[PostHog-Server] Failed to initialize:", e), e;
2554
+ }
2555
+ }
2556
+ }
2557
+ identify(e, t) {
2558
+ !this.isEnabled() || !this.initialized || !this.client || (this.client.identify({
2559
+ distinctId: e,
2560
+ properties: t
2561
+ }), this.log("Identified user", { userId: e, traits: t }));
2562
+ }
2563
+ track(e, t) {
2564
+ if (!this.isEnabled() || !this.initialized || !this.client) return;
2565
+ const n = {
2566
+ ...e.properties,
2567
+ category: e.category,
2568
+ timestamp: e.timestamp ? new Date(e.timestamp) : /* @__PURE__ */ new Date(),
2569
+ ...e.sessionId && { sessionId: e.sessionId },
2570
+ ...(t == null ? void 0 : t.page) && {
2571
+ $current_url: t.page.path,
2572
+ $page_title: t.page.title,
2573
+ $referrer: t.page.referrer
2574
+ },
2575
+ ...(t == null ? void 0 : t.device) && { device: t.device },
2576
+ ...(t == null ? void 0 : t.utm) && { utm: t.utm }
2577
+ };
2578
+ this.client.capture({
2579
+ distinctId: e.userId || "anonymous",
2580
+ event: e.action,
2581
+ properties: n
2582
+ }), this.log("Tracked event", { event: e, context: t });
2583
+ }
2584
+ page(e, t) {
2585
+ if (!this.isEnabled() || !this.initialized || !this.client) return;
2586
+ const n = {
2587
+ ...e,
2588
+ ...(t == null ? void 0 : t.page) && {
2589
+ path: t.page.path,
2590
+ title: t.page.title,
2591
+ referrer: t.page.referrer
2592
+ }
2593
+ };
2594
+ this.client.capture({
2595
+ distinctId: "anonymous",
2596
+ event: "$pageview",
2597
+ properties: n
2598
+ }), this.log("Tracked page view", { properties: e, context: t });
2599
+ }
2600
+ async reset() {
2601
+ !this.isEnabled() || !this.initialized || !this.client || (await this.client.flush(), this.log("Flushed pending events"));
2602
+ }
2603
+ async shutdown() {
2604
+ this.client && (await this.client.shutdown(), this.log("Shutdown complete"));
2605
+ }
2606
+ }
2607
+ export {
2608
+ X as BaseAnalyticsProvider,
2609
+ xe as PostHogClientProvider,
2610
+ Me as PostHogServerProvider
2611
+ };