@stacksee/analytics 0.2.2 → 0.3.3

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