@trackstall/sdk 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. package/README.md +75 -0
  2. package/index.d.ts +843 -0
  3. package/index.js +2734 -0
  4. package/package.json +53 -0
package/index.js ADDED
@@ -0,0 +1,2734 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __esm = (fn, res) => function __init() {
9
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
10
+ };
11
+ var __commonJS = (cb, mod) => function __require() {
12
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
13
+ };
14
+ var __export = (target, all) => {
15
+ for (var name in all)
16
+ __defProp(target, name, { get: all[name], enumerable: true });
17
+ };
18
+ var __copyProps = (to, from, except, desc) => {
19
+ if (from && typeof from === "object" || typeof from === "function") {
20
+ for (let key of __getOwnPropNames(from))
21
+ if (!__hasOwnProp.call(to, key) && key !== except)
22
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
23
+ }
24
+ return to;
25
+ };
26
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
27
+ // If the importer is in node compatibility mode or this is not an ESM
28
+ // file that has been converted to a CommonJS file using a Babel-
29
+ // compatible transform (i.e. "__esModule" has not been set), then set
30
+ // "default" to the CommonJS "module.exports" for node compatibility.
31
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
32
+ mod
33
+ ));
34
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
35
+
36
+ // ../core/dist/schema.js
37
+ var require_schema = __commonJS({
38
+ "../core/dist/schema.js"(exports) {
39
+ "use strict";
40
+ Object.defineProperty(exports, "__esModule", { value: true });
41
+ }
42
+ });
43
+
44
+ // ../core/dist/productEvent.js
45
+ var require_productEvent = __commonJS({
46
+ "../core/dist/productEvent.js"(exports) {
47
+ "use strict";
48
+ Object.defineProperty(exports, "__esModule", { value: true });
49
+ }
50
+ });
51
+
52
+ // ../../node_modules/uuid/dist/esm-browser/max.js
53
+ var max_default;
54
+ var init_max = __esm({
55
+ "../../node_modules/uuid/dist/esm-browser/max.js"() {
56
+ max_default = "ffffffff-ffff-ffff-ffff-ffffffffffff";
57
+ }
58
+ });
59
+
60
+ // ../../node_modules/uuid/dist/esm-browser/nil.js
61
+ var nil_default;
62
+ var init_nil = __esm({
63
+ "../../node_modules/uuid/dist/esm-browser/nil.js"() {
64
+ nil_default = "00000000-0000-0000-0000-000000000000";
65
+ }
66
+ });
67
+
68
+ // ../../node_modules/uuid/dist/esm-browser/regex.js
69
+ var regex_default;
70
+ var init_regex = __esm({
71
+ "../../node_modules/uuid/dist/esm-browser/regex.js"() {
72
+ regex_default = /^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/i;
73
+ }
74
+ });
75
+
76
+ // ../../node_modules/uuid/dist/esm-browser/validate.js
77
+ function validate(uuid) {
78
+ return typeof uuid === "string" && regex_default.test(uuid);
79
+ }
80
+ var validate_default;
81
+ var init_validate = __esm({
82
+ "../../node_modules/uuid/dist/esm-browser/validate.js"() {
83
+ init_regex();
84
+ validate_default = validate;
85
+ }
86
+ });
87
+
88
+ // ../../node_modules/uuid/dist/esm-browser/parse.js
89
+ function parse(uuid) {
90
+ if (!validate_default(uuid)) {
91
+ throw TypeError("Invalid UUID");
92
+ }
93
+ let v;
94
+ return Uint8Array.of((v = parseInt(uuid.slice(0, 8), 16)) >>> 24, v >>> 16 & 255, v >>> 8 & 255, v & 255, (v = parseInt(uuid.slice(9, 13), 16)) >>> 8, v & 255, (v = parseInt(uuid.slice(14, 18), 16)) >>> 8, v & 255, (v = parseInt(uuid.slice(19, 23), 16)) >>> 8, v & 255, (v = parseInt(uuid.slice(24, 36), 16)) / 1099511627776 & 255, v / 4294967296 & 255, v >>> 24 & 255, v >>> 16 & 255, v >>> 8 & 255, v & 255);
95
+ }
96
+ var parse_default;
97
+ var init_parse = __esm({
98
+ "../../node_modules/uuid/dist/esm-browser/parse.js"() {
99
+ init_validate();
100
+ parse_default = parse;
101
+ }
102
+ });
103
+
104
+ // ../../node_modules/uuid/dist/esm-browser/stringify.js
105
+ function unsafeStringify(arr, offset = 0) {
106
+ return (byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + "-" + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + "-" + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + "-" + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + "-" + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]]).toLowerCase();
107
+ }
108
+ function stringify(arr, offset = 0) {
109
+ const uuid = unsafeStringify(arr, offset);
110
+ if (!validate_default(uuid)) {
111
+ throw TypeError("Stringified UUID is invalid");
112
+ }
113
+ return uuid;
114
+ }
115
+ var byteToHex, stringify_default;
116
+ var init_stringify = __esm({
117
+ "../../node_modules/uuid/dist/esm-browser/stringify.js"() {
118
+ init_validate();
119
+ byteToHex = [];
120
+ for (let i = 0; i < 256; ++i) {
121
+ byteToHex.push((i + 256).toString(16).slice(1));
122
+ }
123
+ stringify_default = stringify;
124
+ }
125
+ });
126
+
127
+ // ../../node_modules/uuid/dist/esm-browser/rng.js
128
+ function rng() {
129
+ if (!getRandomValues) {
130
+ if (typeof crypto === "undefined" || !crypto.getRandomValues) {
131
+ throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
132
+ }
133
+ getRandomValues = crypto.getRandomValues.bind(crypto);
134
+ }
135
+ return getRandomValues(rnds8);
136
+ }
137
+ var getRandomValues, rnds8;
138
+ var init_rng = __esm({
139
+ "../../node_modules/uuid/dist/esm-browser/rng.js"() {
140
+ rnds8 = new Uint8Array(16);
141
+ }
142
+ });
143
+
144
+ // ../../node_modules/uuid/dist/esm-browser/v1.js
145
+ function v1(options, buf, offset) {
146
+ var _a, _b, _c, _d;
147
+ let bytes;
148
+ const isV6 = (_a = options == null ? void 0 : options._v6) != null ? _a : false;
149
+ if (options) {
150
+ const optionsKeys = Object.keys(options);
151
+ if (optionsKeys.length === 1 && optionsKeys[0] === "_v6") {
152
+ options = void 0;
153
+ }
154
+ }
155
+ if (options) {
156
+ bytes = v1Bytes((_d = (_c = options.random) != null ? _c : (_b = options.rng) == null ? void 0 : _b.call(options)) != null ? _d : rng(), options.msecs, options.nsecs, options.clockseq, options.node, buf, offset);
157
+ } else {
158
+ const now = Date.now();
159
+ const rnds = rng();
160
+ updateV1State(_state, now, rnds);
161
+ bytes = v1Bytes(rnds, _state.msecs, _state.nsecs, isV6 ? void 0 : _state.clockseq, isV6 ? void 0 : _state.node, buf, offset);
162
+ }
163
+ return buf != null ? buf : unsafeStringify(bytes);
164
+ }
165
+ function updateV1State(state, now, rnds) {
166
+ var _a, _b;
167
+ (_a = state.msecs) != null ? _a : state.msecs = -Infinity;
168
+ (_b = state.nsecs) != null ? _b : state.nsecs = 0;
169
+ if (now === state.msecs) {
170
+ state.nsecs++;
171
+ if (state.nsecs >= 1e4) {
172
+ state.node = void 0;
173
+ state.nsecs = 0;
174
+ }
175
+ } else if (now > state.msecs) {
176
+ state.nsecs = 0;
177
+ } else if (now < state.msecs) {
178
+ state.node = void 0;
179
+ }
180
+ if (!state.node) {
181
+ state.node = rnds.slice(10, 16);
182
+ state.node[0] |= 1;
183
+ state.clockseq = (rnds[8] << 8 | rnds[9]) & 16383;
184
+ }
185
+ state.msecs = now;
186
+ return state;
187
+ }
188
+ function v1Bytes(rnds, msecs, nsecs, clockseq, node, buf, offset = 0) {
189
+ if (rnds.length < 16) {
190
+ throw new Error("Random bytes length must be >= 16");
191
+ }
192
+ if (!buf) {
193
+ buf = new Uint8Array(16);
194
+ offset = 0;
195
+ } else {
196
+ if (offset < 0 || offset + 16 > buf.length) {
197
+ throw new RangeError(`UUID byte range ${offset}:${offset + 15} is out of buffer bounds`);
198
+ }
199
+ }
200
+ msecs != null ? msecs : msecs = Date.now();
201
+ nsecs != null ? nsecs : nsecs = 0;
202
+ clockseq != null ? clockseq : clockseq = (rnds[8] << 8 | rnds[9]) & 16383;
203
+ node != null ? node : node = rnds.slice(10, 16);
204
+ msecs += 122192928e5;
205
+ const tl = ((msecs & 268435455) * 1e4 + nsecs) % 4294967296;
206
+ buf[offset++] = tl >>> 24 & 255;
207
+ buf[offset++] = tl >>> 16 & 255;
208
+ buf[offset++] = tl >>> 8 & 255;
209
+ buf[offset++] = tl & 255;
210
+ const tmh = msecs / 4294967296 * 1e4 & 268435455;
211
+ buf[offset++] = tmh >>> 8 & 255;
212
+ buf[offset++] = tmh & 255;
213
+ buf[offset++] = tmh >>> 24 & 15 | 16;
214
+ buf[offset++] = tmh >>> 16 & 255;
215
+ buf[offset++] = clockseq >>> 8 | 128;
216
+ buf[offset++] = clockseq & 255;
217
+ for (let n = 0; n < 6; ++n) {
218
+ buf[offset++] = node[n];
219
+ }
220
+ return buf;
221
+ }
222
+ var _state, v1_default;
223
+ var init_v1 = __esm({
224
+ "../../node_modules/uuid/dist/esm-browser/v1.js"() {
225
+ init_rng();
226
+ init_stringify();
227
+ _state = {};
228
+ v1_default = v1;
229
+ }
230
+ });
231
+
232
+ // ../../node_modules/uuid/dist/esm-browser/v1ToV6.js
233
+ function v1ToV6(uuid) {
234
+ const v1Bytes2 = typeof uuid === "string" ? parse_default(uuid) : uuid;
235
+ const v6Bytes = _v1ToV6(v1Bytes2);
236
+ return typeof uuid === "string" ? unsafeStringify(v6Bytes) : v6Bytes;
237
+ }
238
+ function _v1ToV6(v1Bytes2) {
239
+ return Uint8Array.of((v1Bytes2[6] & 15) << 4 | v1Bytes2[7] >> 4 & 15, (v1Bytes2[7] & 15) << 4 | (v1Bytes2[4] & 240) >> 4, (v1Bytes2[4] & 15) << 4 | (v1Bytes2[5] & 240) >> 4, (v1Bytes2[5] & 15) << 4 | (v1Bytes2[0] & 240) >> 4, (v1Bytes2[0] & 15) << 4 | (v1Bytes2[1] & 240) >> 4, (v1Bytes2[1] & 15) << 4 | (v1Bytes2[2] & 240) >> 4, 96 | v1Bytes2[2] & 15, v1Bytes2[3], v1Bytes2[8], v1Bytes2[9], v1Bytes2[10], v1Bytes2[11], v1Bytes2[12], v1Bytes2[13], v1Bytes2[14], v1Bytes2[15]);
240
+ }
241
+ var init_v1ToV6 = __esm({
242
+ "../../node_modules/uuid/dist/esm-browser/v1ToV6.js"() {
243
+ init_parse();
244
+ init_stringify();
245
+ }
246
+ });
247
+
248
+ // ../../node_modules/uuid/dist/esm-browser/md5.js
249
+ function md5(bytes) {
250
+ const words = uint8ToUint32(bytes);
251
+ const md5Bytes = wordsToMd5(words, bytes.length * 8);
252
+ return uint32ToUint8(md5Bytes);
253
+ }
254
+ function uint32ToUint8(input) {
255
+ const bytes = new Uint8Array(input.length * 4);
256
+ for (let i = 0; i < input.length * 4; i++) {
257
+ bytes[i] = input[i >> 2] >>> i % 4 * 8 & 255;
258
+ }
259
+ return bytes;
260
+ }
261
+ function getOutputLength(inputLength8) {
262
+ return (inputLength8 + 64 >>> 9 << 4) + 14 + 1;
263
+ }
264
+ function wordsToMd5(x, len) {
265
+ const xpad = new Uint32Array(getOutputLength(len)).fill(0);
266
+ xpad.set(x);
267
+ xpad[len >> 5] |= 128 << len % 32;
268
+ xpad[xpad.length - 1] = len;
269
+ x = xpad;
270
+ let a = 1732584193;
271
+ let b = -271733879;
272
+ let c = -1732584194;
273
+ let d = 271733878;
274
+ for (let i = 0; i < x.length; i += 16) {
275
+ const olda = a;
276
+ const oldb = b;
277
+ const oldc = c;
278
+ const oldd = d;
279
+ a = md5ff(a, b, c, d, x[i], 7, -680876936);
280
+ d = md5ff(d, a, b, c, x[i + 1], 12, -389564586);
281
+ c = md5ff(c, d, a, b, x[i + 2], 17, 606105819);
282
+ b = md5ff(b, c, d, a, x[i + 3], 22, -1044525330);
283
+ a = md5ff(a, b, c, d, x[i + 4], 7, -176418897);
284
+ d = md5ff(d, a, b, c, x[i + 5], 12, 1200080426);
285
+ c = md5ff(c, d, a, b, x[i + 6], 17, -1473231341);
286
+ b = md5ff(b, c, d, a, x[i + 7], 22, -45705983);
287
+ a = md5ff(a, b, c, d, x[i + 8], 7, 1770035416);
288
+ d = md5ff(d, a, b, c, x[i + 9], 12, -1958414417);
289
+ c = md5ff(c, d, a, b, x[i + 10], 17, -42063);
290
+ b = md5ff(b, c, d, a, x[i + 11], 22, -1990404162);
291
+ a = md5ff(a, b, c, d, x[i + 12], 7, 1804603682);
292
+ d = md5ff(d, a, b, c, x[i + 13], 12, -40341101);
293
+ c = md5ff(c, d, a, b, x[i + 14], 17, -1502002290);
294
+ b = md5ff(b, c, d, a, x[i + 15], 22, 1236535329);
295
+ a = md5gg(a, b, c, d, x[i + 1], 5, -165796510);
296
+ d = md5gg(d, a, b, c, x[i + 6], 9, -1069501632);
297
+ c = md5gg(c, d, a, b, x[i + 11], 14, 643717713);
298
+ b = md5gg(b, c, d, a, x[i], 20, -373897302);
299
+ a = md5gg(a, b, c, d, x[i + 5], 5, -701558691);
300
+ d = md5gg(d, a, b, c, x[i + 10], 9, 38016083);
301
+ c = md5gg(c, d, a, b, x[i + 15], 14, -660478335);
302
+ b = md5gg(b, c, d, a, x[i + 4], 20, -405537848);
303
+ a = md5gg(a, b, c, d, x[i + 9], 5, 568446438);
304
+ d = md5gg(d, a, b, c, x[i + 14], 9, -1019803690);
305
+ c = md5gg(c, d, a, b, x[i + 3], 14, -187363961);
306
+ b = md5gg(b, c, d, a, x[i + 8], 20, 1163531501);
307
+ a = md5gg(a, b, c, d, x[i + 13], 5, -1444681467);
308
+ d = md5gg(d, a, b, c, x[i + 2], 9, -51403784);
309
+ c = md5gg(c, d, a, b, x[i + 7], 14, 1735328473);
310
+ b = md5gg(b, c, d, a, x[i + 12], 20, -1926607734);
311
+ a = md5hh(a, b, c, d, x[i + 5], 4, -378558);
312
+ d = md5hh(d, a, b, c, x[i + 8], 11, -2022574463);
313
+ c = md5hh(c, d, a, b, x[i + 11], 16, 1839030562);
314
+ b = md5hh(b, c, d, a, x[i + 14], 23, -35309556);
315
+ a = md5hh(a, b, c, d, x[i + 1], 4, -1530992060);
316
+ d = md5hh(d, a, b, c, x[i + 4], 11, 1272893353);
317
+ c = md5hh(c, d, a, b, x[i + 7], 16, -155497632);
318
+ b = md5hh(b, c, d, a, x[i + 10], 23, -1094730640);
319
+ a = md5hh(a, b, c, d, x[i + 13], 4, 681279174);
320
+ d = md5hh(d, a, b, c, x[i], 11, -358537222);
321
+ c = md5hh(c, d, a, b, x[i + 3], 16, -722521979);
322
+ b = md5hh(b, c, d, a, x[i + 6], 23, 76029189);
323
+ a = md5hh(a, b, c, d, x[i + 9], 4, -640364487);
324
+ d = md5hh(d, a, b, c, x[i + 12], 11, -421815835);
325
+ c = md5hh(c, d, a, b, x[i + 15], 16, 530742520);
326
+ b = md5hh(b, c, d, a, x[i + 2], 23, -995338651);
327
+ a = md5ii(a, b, c, d, x[i], 6, -198630844);
328
+ d = md5ii(d, a, b, c, x[i + 7], 10, 1126891415);
329
+ c = md5ii(c, d, a, b, x[i + 14], 15, -1416354905);
330
+ b = md5ii(b, c, d, a, x[i + 5], 21, -57434055);
331
+ a = md5ii(a, b, c, d, x[i + 12], 6, 1700485571);
332
+ d = md5ii(d, a, b, c, x[i + 3], 10, -1894986606);
333
+ c = md5ii(c, d, a, b, x[i + 10], 15, -1051523);
334
+ b = md5ii(b, c, d, a, x[i + 1], 21, -2054922799);
335
+ a = md5ii(a, b, c, d, x[i + 8], 6, 1873313359);
336
+ d = md5ii(d, a, b, c, x[i + 15], 10, -30611744);
337
+ c = md5ii(c, d, a, b, x[i + 6], 15, -1560198380);
338
+ b = md5ii(b, c, d, a, x[i + 13], 21, 1309151649);
339
+ a = md5ii(a, b, c, d, x[i + 4], 6, -145523070);
340
+ d = md5ii(d, a, b, c, x[i + 11], 10, -1120210379);
341
+ c = md5ii(c, d, a, b, x[i + 2], 15, 718787259);
342
+ b = md5ii(b, c, d, a, x[i + 9], 21, -343485551);
343
+ a = safeAdd(a, olda);
344
+ b = safeAdd(b, oldb);
345
+ c = safeAdd(c, oldc);
346
+ d = safeAdd(d, oldd);
347
+ }
348
+ return Uint32Array.of(a, b, c, d);
349
+ }
350
+ function uint8ToUint32(input) {
351
+ if (input.length === 0) {
352
+ return new Uint32Array();
353
+ }
354
+ const output = new Uint32Array(getOutputLength(input.length * 8)).fill(0);
355
+ for (let i = 0; i < input.length; i++) {
356
+ output[i >> 2] |= (input[i] & 255) << i % 4 * 8;
357
+ }
358
+ return output;
359
+ }
360
+ function safeAdd(x, y) {
361
+ const lsw = (x & 65535) + (y & 65535);
362
+ const msw = (x >> 16) + (y >> 16) + (lsw >> 16);
363
+ return msw << 16 | lsw & 65535;
364
+ }
365
+ function bitRotateLeft(num, cnt) {
366
+ return num << cnt | num >>> 32 - cnt;
367
+ }
368
+ function md5cmn(q, a, b, x, s, t) {
369
+ return safeAdd(bitRotateLeft(safeAdd(safeAdd(a, q), safeAdd(x, t)), s), b);
370
+ }
371
+ function md5ff(a, b, c, d, x, s, t) {
372
+ return md5cmn(b & c | ~b & d, a, b, x, s, t);
373
+ }
374
+ function md5gg(a, b, c, d, x, s, t) {
375
+ return md5cmn(b & d | c & ~d, a, b, x, s, t);
376
+ }
377
+ function md5hh(a, b, c, d, x, s, t) {
378
+ return md5cmn(b ^ c ^ d, a, b, x, s, t);
379
+ }
380
+ function md5ii(a, b, c, d, x, s, t) {
381
+ return md5cmn(c ^ (b | ~d), a, b, x, s, t);
382
+ }
383
+ var md5_default;
384
+ var init_md5 = __esm({
385
+ "../../node_modules/uuid/dist/esm-browser/md5.js"() {
386
+ md5_default = md5;
387
+ }
388
+ });
389
+
390
+ // ../../node_modules/uuid/dist/esm-browser/v35.js
391
+ function stringToBytes(str) {
392
+ str = unescape(encodeURIComponent(str));
393
+ const bytes = new Uint8Array(str.length);
394
+ for (let i = 0; i < str.length; ++i) {
395
+ bytes[i] = str.charCodeAt(i);
396
+ }
397
+ return bytes;
398
+ }
399
+ function v35(version2, hash, value, namespace, buf, offset) {
400
+ const valueBytes = typeof value === "string" ? stringToBytes(value) : value;
401
+ const namespaceBytes = typeof namespace === "string" ? parse_default(namespace) : namespace;
402
+ if (typeof namespace === "string") {
403
+ namespace = parse_default(namespace);
404
+ }
405
+ if ((namespace == null ? void 0 : namespace.length) !== 16) {
406
+ throw TypeError("Namespace must be array-like (16 iterable integer values, 0-255)");
407
+ }
408
+ let bytes = new Uint8Array(16 + valueBytes.length);
409
+ bytes.set(namespaceBytes);
410
+ bytes.set(valueBytes, namespaceBytes.length);
411
+ bytes = hash(bytes);
412
+ bytes[6] = bytes[6] & 15 | version2;
413
+ bytes[8] = bytes[8] & 63 | 128;
414
+ if (buf) {
415
+ offset = offset || 0;
416
+ if (offset < 0 || offset + 16 > buf.length) {
417
+ throw new RangeError(`UUID byte range ${offset}:${offset + 15} is out of buffer bounds`);
418
+ }
419
+ for (let i = 0; i < 16; ++i) {
420
+ buf[offset + i] = bytes[i];
421
+ }
422
+ return buf;
423
+ }
424
+ return unsafeStringify(bytes);
425
+ }
426
+ var DNS, URL;
427
+ var init_v35 = __esm({
428
+ "../../node_modules/uuid/dist/esm-browser/v35.js"() {
429
+ init_parse();
430
+ init_stringify();
431
+ DNS = "6ba7b810-9dad-11d1-80b4-00c04fd430c8";
432
+ URL = "6ba7b811-9dad-11d1-80b4-00c04fd430c8";
433
+ }
434
+ });
435
+
436
+ // ../../node_modules/uuid/dist/esm-browser/v3.js
437
+ function v3(value, namespace, buf, offset) {
438
+ return v35(48, md5_default, value, namespace, buf, offset);
439
+ }
440
+ var v3_default;
441
+ var init_v3 = __esm({
442
+ "../../node_modules/uuid/dist/esm-browser/v3.js"() {
443
+ init_md5();
444
+ init_v35();
445
+ v3.DNS = DNS;
446
+ v3.URL = URL;
447
+ v3_default = v3;
448
+ }
449
+ });
450
+
451
+ // ../../node_modules/uuid/dist/esm-browser/native.js
452
+ var randomUUID, native_default;
453
+ var init_native = __esm({
454
+ "../../node_modules/uuid/dist/esm-browser/native.js"() {
455
+ randomUUID = typeof crypto !== "undefined" && crypto.randomUUID && crypto.randomUUID.bind(crypto);
456
+ native_default = { randomUUID };
457
+ }
458
+ });
459
+
460
+ // ../../node_modules/uuid/dist/esm-browser/v4.js
461
+ function v4(options, buf, offset) {
462
+ var _a, _b, _c;
463
+ if (native_default.randomUUID && !buf && !options) {
464
+ return native_default.randomUUID();
465
+ }
466
+ options = options || {};
467
+ const rnds = (_c = (_b = options.random) != null ? _b : (_a = options.rng) == null ? void 0 : _a.call(options)) != null ? _c : rng();
468
+ if (rnds.length < 16) {
469
+ throw new Error("Random bytes length must be >= 16");
470
+ }
471
+ rnds[6] = rnds[6] & 15 | 64;
472
+ rnds[8] = rnds[8] & 63 | 128;
473
+ if (buf) {
474
+ offset = offset || 0;
475
+ if (offset < 0 || offset + 16 > buf.length) {
476
+ throw new RangeError(`UUID byte range ${offset}:${offset + 15} is out of buffer bounds`);
477
+ }
478
+ for (let i = 0; i < 16; ++i) {
479
+ buf[offset + i] = rnds[i];
480
+ }
481
+ return buf;
482
+ }
483
+ return unsafeStringify(rnds);
484
+ }
485
+ var v4_default;
486
+ var init_v4 = __esm({
487
+ "../../node_modules/uuid/dist/esm-browser/v4.js"() {
488
+ init_native();
489
+ init_rng();
490
+ init_stringify();
491
+ v4_default = v4;
492
+ }
493
+ });
494
+
495
+ // ../../node_modules/uuid/dist/esm-browser/sha1.js
496
+ function f(s, x, y, z) {
497
+ switch (s) {
498
+ case 0:
499
+ return x & y ^ ~x & z;
500
+ case 1:
501
+ return x ^ y ^ z;
502
+ case 2:
503
+ return x & y ^ x & z ^ y & z;
504
+ case 3:
505
+ return x ^ y ^ z;
506
+ }
507
+ }
508
+ function ROTL(x, n) {
509
+ return x << n | x >>> 32 - n;
510
+ }
511
+ function sha1(bytes) {
512
+ const K = [1518500249, 1859775393, 2400959708, 3395469782];
513
+ const H = [1732584193, 4023233417, 2562383102, 271733878, 3285377520];
514
+ const newBytes = new Uint8Array(bytes.length + 1);
515
+ newBytes.set(bytes);
516
+ newBytes[bytes.length] = 128;
517
+ bytes = newBytes;
518
+ const l = bytes.length / 4 + 2;
519
+ const N = Math.ceil(l / 16);
520
+ const M = new Array(N);
521
+ for (let i = 0; i < N; ++i) {
522
+ const arr = new Uint32Array(16);
523
+ for (let j = 0; j < 16; ++j) {
524
+ arr[j] = bytes[i * 64 + j * 4] << 24 | bytes[i * 64 + j * 4 + 1] << 16 | bytes[i * 64 + j * 4 + 2] << 8 | bytes[i * 64 + j * 4 + 3];
525
+ }
526
+ M[i] = arr;
527
+ }
528
+ M[N - 1][14] = (bytes.length - 1) * 8 / Math.pow(2, 32);
529
+ M[N - 1][14] = Math.floor(M[N - 1][14]);
530
+ M[N - 1][15] = (bytes.length - 1) * 8 & 4294967295;
531
+ for (let i = 0; i < N; ++i) {
532
+ const W = new Uint32Array(80);
533
+ for (let t = 0; t < 16; ++t) {
534
+ W[t] = M[i][t];
535
+ }
536
+ for (let t = 16; t < 80; ++t) {
537
+ W[t] = ROTL(W[t - 3] ^ W[t - 8] ^ W[t - 14] ^ W[t - 16], 1);
538
+ }
539
+ let a = H[0];
540
+ let b = H[1];
541
+ let c = H[2];
542
+ let d = H[3];
543
+ let e = H[4];
544
+ for (let t = 0; t < 80; ++t) {
545
+ const s = Math.floor(t / 20);
546
+ const T = ROTL(a, 5) + f(s, b, c, d) + e + K[s] + W[t] >>> 0;
547
+ e = d;
548
+ d = c;
549
+ c = ROTL(b, 30) >>> 0;
550
+ b = a;
551
+ a = T;
552
+ }
553
+ H[0] = H[0] + a >>> 0;
554
+ H[1] = H[1] + b >>> 0;
555
+ H[2] = H[2] + c >>> 0;
556
+ H[3] = H[3] + d >>> 0;
557
+ H[4] = H[4] + e >>> 0;
558
+ }
559
+ return Uint8Array.of(H[0] >> 24, H[0] >> 16, H[0] >> 8, H[0], H[1] >> 24, H[1] >> 16, H[1] >> 8, H[1], H[2] >> 24, H[2] >> 16, H[2] >> 8, H[2], H[3] >> 24, H[3] >> 16, H[3] >> 8, H[3], H[4] >> 24, H[4] >> 16, H[4] >> 8, H[4]);
560
+ }
561
+ var sha1_default;
562
+ var init_sha1 = __esm({
563
+ "../../node_modules/uuid/dist/esm-browser/sha1.js"() {
564
+ sha1_default = sha1;
565
+ }
566
+ });
567
+
568
+ // ../../node_modules/uuid/dist/esm-browser/v5.js
569
+ function v5(value, namespace, buf, offset) {
570
+ return v35(80, sha1_default, value, namespace, buf, offset);
571
+ }
572
+ var v5_default;
573
+ var init_v5 = __esm({
574
+ "../../node_modules/uuid/dist/esm-browser/v5.js"() {
575
+ init_sha1();
576
+ init_v35();
577
+ v5.DNS = DNS;
578
+ v5.URL = URL;
579
+ v5_default = v5;
580
+ }
581
+ });
582
+
583
+ // ../../node_modules/uuid/dist/esm-browser/v6.js
584
+ function v6(options, buf, offset) {
585
+ options != null ? options : options = {};
586
+ offset != null ? offset : offset = 0;
587
+ let bytes = v1_default({ ...options, _v6: true }, new Uint8Array(16));
588
+ bytes = v1ToV6(bytes);
589
+ if (buf) {
590
+ if (offset < 0 || offset + 16 > buf.length) {
591
+ throw new RangeError(`UUID byte range ${offset}:${offset + 15} is out of buffer bounds`);
592
+ }
593
+ for (let i = 0; i < 16; i++) {
594
+ buf[offset + i] = bytes[i];
595
+ }
596
+ return buf;
597
+ }
598
+ return unsafeStringify(bytes);
599
+ }
600
+ var v6_default;
601
+ var init_v6 = __esm({
602
+ "../../node_modules/uuid/dist/esm-browser/v6.js"() {
603
+ init_stringify();
604
+ init_v1();
605
+ init_v1ToV6();
606
+ v6_default = v6;
607
+ }
608
+ });
609
+
610
+ // ../../node_modules/uuid/dist/esm-browser/v6ToV1.js
611
+ function v6ToV1(uuid) {
612
+ const v6Bytes = typeof uuid === "string" ? parse_default(uuid) : uuid;
613
+ const v1Bytes2 = _v6ToV1(v6Bytes);
614
+ return typeof uuid === "string" ? unsafeStringify(v1Bytes2) : v1Bytes2;
615
+ }
616
+ function _v6ToV1(v6Bytes) {
617
+ return Uint8Array.of((v6Bytes[3] & 15) << 4 | v6Bytes[4] >> 4 & 15, (v6Bytes[4] & 15) << 4 | (v6Bytes[5] & 240) >> 4, (v6Bytes[5] & 15) << 4 | v6Bytes[6] & 15, v6Bytes[7], (v6Bytes[1] & 15) << 4 | (v6Bytes[2] & 240) >> 4, (v6Bytes[2] & 15) << 4 | (v6Bytes[3] & 240) >> 4, 16 | (v6Bytes[0] & 240) >> 4, (v6Bytes[0] & 15) << 4 | (v6Bytes[1] & 240) >> 4, v6Bytes[8], v6Bytes[9], v6Bytes[10], v6Bytes[11], v6Bytes[12], v6Bytes[13], v6Bytes[14], v6Bytes[15]);
618
+ }
619
+ var init_v6ToV1 = __esm({
620
+ "../../node_modules/uuid/dist/esm-browser/v6ToV1.js"() {
621
+ init_parse();
622
+ init_stringify();
623
+ }
624
+ });
625
+
626
+ // ../../node_modules/uuid/dist/esm-browser/v7.js
627
+ function v7(options, buf, offset) {
628
+ var _a, _b, _c;
629
+ let bytes;
630
+ if (options) {
631
+ bytes = v7Bytes((_c = (_b = options.random) != null ? _b : (_a = options.rng) == null ? void 0 : _a.call(options)) != null ? _c : rng(), options.msecs, options.seq, buf, offset);
632
+ } else {
633
+ const now = Date.now();
634
+ const rnds = rng();
635
+ updateV7State(_state2, now, rnds);
636
+ bytes = v7Bytes(rnds, _state2.msecs, _state2.seq, buf, offset);
637
+ }
638
+ return buf != null ? buf : unsafeStringify(bytes);
639
+ }
640
+ function updateV7State(state, now, rnds) {
641
+ var _a, _b;
642
+ (_a = state.msecs) != null ? _a : state.msecs = -Infinity;
643
+ (_b = state.seq) != null ? _b : state.seq = 0;
644
+ if (now > state.msecs) {
645
+ state.seq = rnds[6] << 23 | rnds[7] << 16 | rnds[8] << 8 | rnds[9];
646
+ state.msecs = now;
647
+ } else {
648
+ state.seq = state.seq + 1 | 0;
649
+ if (state.seq === 0) {
650
+ state.msecs++;
651
+ }
652
+ }
653
+ return state;
654
+ }
655
+ function v7Bytes(rnds, msecs, seq, buf, offset = 0) {
656
+ if (rnds.length < 16) {
657
+ throw new Error("Random bytes length must be >= 16");
658
+ }
659
+ if (!buf) {
660
+ buf = new Uint8Array(16);
661
+ offset = 0;
662
+ } else {
663
+ if (offset < 0 || offset + 16 > buf.length) {
664
+ throw new RangeError(`UUID byte range ${offset}:${offset + 15} is out of buffer bounds`);
665
+ }
666
+ }
667
+ msecs != null ? msecs : msecs = Date.now();
668
+ seq != null ? seq : seq = rnds[6] * 127 << 24 | rnds[7] << 16 | rnds[8] << 8 | rnds[9];
669
+ buf[offset++] = msecs / 1099511627776 & 255;
670
+ buf[offset++] = msecs / 4294967296 & 255;
671
+ buf[offset++] = msecs / 16777216 & 255;
672
+ buf[offset++] = msecs / 65536 & 255;
673
+ buf[offset++] = msecs / 256 & 255;
674
+ buf[offset++] = msecs & 255;
675
+ buf[offset++] = 112 | seq >>> 28 & 15;
676
+ buf[offset++] = seq >>> 20 & 255;
677
+ buf[offset++] = 128 | seq >>> 14 & 63;
678
+ buf[offset++] = seq >>> 6 & 255;
679
+ buf[offset++] = seq << 2 & 255 | rnds[10] & 3;
680
+ buf[offset++] = rnds[11];
681
+ buf[offset++] = rnds[12];
682
+ buf[offset++] = rnds[13];
683
+ buf[offset++] = rnds[14];
684
+ buf[offset++] = rnds[15];
685
+ return buf;
686
+ }
687
+ var _state2, v7_default;
688
+ var init_v7 = __esm({
689
+ "../../node_modules/uuid/dist/esm-browser/v7.js"() {
690
+ init_rng();
691
+ init_stringify();
692
+ _state2 = {};
693
+ v7_default = v7;
694
+ }
695
+ });
696
+
697
+ // ../../node_modules/uuid/dist/esm-browser/version.js
698
+ function version(uuid) {
699
+ if (!validate_default(uuid)) {
700
+ throw TypeError("Invalid UUID");
701
+ }
702
+ return parseInt(uuid.slice(14, 15), 16);
703
+ }
704
+ var version_default;
705
+ var init_version = __esm({
706
+ "../../node_modules/uuid/dist/esm-browser/version.js"() {
707
+ init_validate();
708
+ version_default = version;
709
+ }
710
+ });
711
+
712
+ // ../../node_modules/uuid/dist/esm-browser/index.js
713
+ var esm_browser_exports = {};
714
+ __export(esm_browser_exports, {
715
+ MAX: () => max_default,
716
+ NIL: () => nil_default,
717
+ parse: () => parse_default,
718
+ stringify: () => stringify_default,
719
+ v1: () => v1_default,
720
+ v1ToV6: () => v1ToV6,
721
+ v3: () => v3_default,
722
+ v4: () => v4_default,
723
+ v5: () => v5_default,
724
+ v6: () => v6_default,
725
+ v6ToV1: () => v6ToV1,
726
+ v7: () => v7_default,
727
+ validate: () => validate_default,
728
+ version: () => version_default
729
+ });
730
+ var init_esm_browser = __esm({
731
+ "../../node_modules/uuid/dist/esm-browser/index.js"() {
732
+ init_max();
733
+ init_nil();
734
+ init_parse();
735
+ init_stringify();
736
+ init_v1();
737
+ init_v1ToV6();
738
+ init_v3();
739
+ init_v4();
740
+ init_v5();
741
+ init_v6();
742
+ init_v6ToV1();
743
+ init_v7();
744
+ init_validate();
745
+ init_version();
746
+ }
747
+ });
748
+
749
+ // ../core/dist/eventId.js
750
+ var require_eventId = __commonJS({
751
+ "../core/dist/eventId.js"(exports) {
752
+ "use strict";
753
+ Object.defineProperty(exports, "__esModule", { value: true });
754
+ exports.TRACKSTALL_EVENT_NAMESPACE = void 0;
755
+ exports.deterministicEventId = deterministicEventId3;
756
+ exports.randomEventId = randomEventId3;
757
+ var uuid_1 = (init_esm_browser(), __toCommonJS(esm_browser_exports));
758
+ exports.TRACKSTALL_EVENT_NAMESPACE = "b7d2f0c4-1e8a-4c3b-9f6d-5a2e7c4b1d90";
759
+ function deterministicEventId3(input) {
760
+ var _a, _b;
761
+ if (!input.appId) {
762
+ throw new Error("deterministicEventId: appId is required");
763
+ }
764
+ if (!input.userId) {
765
+ throw new Error("deterministicEventId: userId is required");
766
+ }
767
+ if (!input.eventName) {
768
+ throw new Error("deterministicEventId: eventName is required");
769
+ }
770
+ const key = [
771
+ input.appId,
772
+ input.userId,
773
+ input.eventName,
774
+ (_a = input.transactionId) != null ? _a : "",
775
+ (_b = input.timestamp) != null ? _b : ""
776
+ ].join("|");
777
+ return (0, uuid_1.v5)(key, exports.TRACKSTALL_EVENT_NAMESPACE);
778
+ }
779
+ function randomEventId3() {
780
+ return (0, uuid_1.v4)();
781
+ }
782
+ }
783
+ });
784
+
785
+ // ../core/dist/revenueRules.js
786
+ var require_revenueRules = __commonJS({
787
+ "../core/dist/revenueRules.js"(exports) {
788
+ "use strict";
789
+ Object.defineProperty(exports, "__esModule", { value: true });
790
+ exports.STORE_FEE_DEFAULTS = void 0;
791
+ exports.buildRevenue = buildRevenue2;
792
+ exports.STORE_FEE_DEFAULTS = {
793
+ apple: 0.3,
794
+ google: 0.3,
795
+ stripe: 0.029,
796
+ web: 0.029,
797
+ unknown: 0
798
+ };
799
+ function buildRevenue2(input) {
800
+ if (!Number.isFinite(input.value)) {
801
+ throw new Error(`buildRevenue: value must be a finite number (got ${input.value})`);
802
+ }
803
+ if (input.value < 0) {
804
+ throw new Error(`buildRevenue: value must be non-negative (got ${input.value})`);
805
+ }
806
+ if (!input.currency || input.currency.length !== 3) {
807
+ throw new Error(`buildRevenue: currency must be a 3-letter ISO 4217 code (got ${JSON.stringify(input.currency)})`);
808
+ }
809
+ const rate = resolveFeeRate(input.store, input.feeRateOverride);
810
+ const isNetInput = input.netOfStoreFee === true;
811
+ const grossValue = isNetInput ? input.value / (1 - rate) : input.value;
812
+ const netValue = isNetInput ? input.value : input.value * (1 - rate);
813
+ return {
814
+ grossValue: round2(grossValue),
815
+ netValue: round2(netValue),
816
+ currency: input.currency.toUpperCase(),
817
+ store: input.store,
818
+ transactionId: input.transactionId
819
+ };
820
+ }
821
+ function resolveFeeRate(store, override) {
822
+ if (override !== void 0) {
823
+ if (!Number.isFinite(override) || override < 0 || override >= 1) {
824
+ throw new Error(`buildRevenue: feeRateOverride must be in [0, 1) (got ${override})`);
825
+ }
826
+ return override;
827
+ }
828
+ return exports.STORE_FEE_DEFAULTS[store];
829
+ }
830
+ function round2(value) {
831
+ return Math.round(value * 100) / 100;
832
+ }
833
+ }
834
+ });
835
+
836
+ // (disabled):crypto
837
+ var require_crypto = __commonJS({
838
+ "(disabled):crypto"() {
839
+ }
840
+ });
841
+
842
+ // (disabled):buffer
843
+ var require_buffer = __commonJS({
844
+ "(disabled):buffer"() {
845
+ }
846
+ });
847
+
848
+ // ../../node_modules/js-sha256/src/sha256.js
849
+ var require_sha256 = __commonJS({
850
+ "../../node_modules/js-sha256/src/sha256.js"(exports, module2) {
851
+ (function() {
852
+ "use strict";
853
+ var ERROR = "input is invalid type";
854
+ var WINDOW = typeof window === "object";
855
+ var root = WINDOW ? window : {};
856
+ if (root.JS_SHA256_NO_WINDOW) {
857
+ WINDOW = false;
858
+ }
859
+ var WEB_WORKER = !WINDOW && typeof self === "object";
860
+ var NODE_JS = !root.JS_SHA256_NO_NODE_JS && typeof process === "object" && process.versions && process.versions.node && process.type != "renderer";
861
+ if (NODE_JS) {
862
+ root = global;
863
+ } else if (WEB_WORKER) {
864
+ root = self;
865
+ }
866
+ var COMMON_JS = !root.JS_SHA256_NO_COMMON_JS && typeof module2 === "object" && module2.exports;
867
+ var AMD = typeof define === "function" && define.amd;
868
+ var ARRAY_BUFFER = !root.JS_SHA256_NO_ARRAY_BUFFER && typeof ArrayBuffer !== "undefined";
869
+ var HEX_CHARS = "0123456789abcdef".split("");
870
+ var EXTRA = [-2147483648, 8388608, 32768, 128];
871
+ var SHIFT = [24, 16, 8, 0];
872
+ var K = [
873
+ 1116352408,
874
+ 1899447441,
875
+ 3049323471,
876
+ 3921009573,
877
+ 961987163,
878
+ 1508970993,
879
+ 2453635748,
880
+ 2870763221,
881
+ 3624381080,
882
+ 310598401,
883
+ 607225278,
884
+ 1426881987,
885
+ 1925078388,
886
+ 2162078206,
887
+ 2614888103,
888
+ 3248222580,
889
+ 3835390401,
890
+ 4022224774,
891
+ 264347078,
892
+ 604807628,
893
+ 770255983,
894
+ 1249150122,
895
+ 1555081692,
896
+ 1996064986,
897
+ 2554220882,
898
+ 2821834349,
899
+ 2952996808,
900
+ 3210313671,
901
+ 3336571891,
902
+ 3584528711,
903
+ 113926993,
904
+ 338241895,
905
+ 666307205,
906
+ 773529912,
907
+ 1294757372,
908
+ 1396182291,
909
+ 1695183700,
910
+ 1986661051,
911
+ 2177026350,
912
+ 2456956037,
913
+ 2730485921,
914
+ 2820302411,
915
+ 3259730800,
916
+ 3345764771,
917
+ 3516065817,
918
+ 3600352804,
919
+ 4094571909,
920
+ 275423344,
921
+ 430227734,
922
+ 506948616,
923
+ 659060556,
924
+ 883997877,
925
+ 958139571,
926
+ 1322822218,
927
+ 1537002063,
928
+ 1747873779,
929
+ 1955562222,
930
+ 2024104815,
931
+ 2227730452,
932
+ 2361852424,
933
+ 2428436474,
934
+ 2756734187,
935
+ 3204031479,
936
+ 3329325298
937
+ ];
938
+ var OUTPUT_TYPES = ["hex", "array", "digest", "arrayBuffer"];
939
+ var blocks = [];
940
+ if (root.JS_SHA256_NO_NODE_JS || !Array.isArray) {
941
+ Array.isArray = function(obj) {
942
+ return Object.prototype.toString.call(obj) === "[object Array]";
943
+ };
944
+ }
945
+ if (ARRAY_BUFFER && (root.JS_SHA256_NO_ARRAY_BUFFER_IS_VIEW || !ArrayBuffer.isView)) {
946
+ ArrayBuffer.isView = function(obj) {
947
+ return typeof obj === "object" && obj.buffer && obj.buffer.constructor === ArrayBuffer;
948
+ };
949
+ }
950
+ var createOutputMethod = function(outputType, is224) {
951
+ return function(message) {
952
+ return new Sha256(is224, true).update(message)[outputType]();
953
+ };
954
+ };
955
+ var createMethod = function(is224) {
956
+ var method = createOutputMethod("hex", is224);
957
+ if (NODE_JS) {
958
+ method = nodeWrap(method, is224);
959
+ }
960
+ method.create = function() {
961
+ return new Sha256(is224);
962
+ };
963
+ method.update = function(message) {
964
+ return method.create().update(message);
965
+ };
966
+ for (var i = 0; i < OUTPUT_TYPES.length; ++i) {
967
+ var type = OUTPUT_TYPES[i];
968
+ method[type] = createOutputMethod(type, is224);
969
+ }
970
+ return method;
971
+ };
972
+ var nodeWrap = function(method, is224) {
973
+ var crypto2 = require_crypto();
974
+ var Buffer2 = require_buffer().Buffer;
975
+ var algorithm = is224 ? "sha224" : "sha256";
976
+ var bufferFrom;
977
+ if (Buffer2.from && !root.JS_SHA256_NO_BUFFER_FROM) {
978
+ bufferFrom = Buffer2.from;
979
+ } else {
980
+ bufferFrom = function(message) {
981
+ return new Buffer2(message);
982
+ };
983
+ }
984
+ var nodeMethod = function(message) {
985
+ if (typeof message === "string") {
986
+ return crypto2.createHash(algorithm).update(message, "utf8").digest("hex");
987
+ } else {
988
+ if (message === null || message === void 0) {
989
+ throw new Error(ERROR);
990
+ } else if (message.constructor === ArrayBuffer) {
991
+ message = new Uint8Array(message);
992
+ }
993
+ }
994
+ if (Array.isArray(message) || ArrayBuffer.isView(message) || message.constructor === Buffer2) {
995
+ return crypto2.createHash(algorithm).update(bufferFrom(message)).digest("hex");
996
+ } else {
997
+ return method(message);
998
+ }
999
+ };
1000
+ return nodeMethod;
1001
+ };
1002
+ var createHmacOutputMethod = function(outputType, is224) {
1003
+ return function(key, message) {
1004
+ return new HmacSha256(key, is224, true).update(message)[outputType]();
1005
+ };
1006
+ };
1007
+ var createHmacMethod = function(is224) {
1008
+ var method = createHmacOutputMethod("hex", is224);
1009
+ method.create = function(key) {
1010
+ return new HmacSha256(key, is224);
1011
+ };
1012
+ method.update = function(key, message) {
1013
+ return method.create(key).update(message);
1014
+ };
1015
+ for (var i = 0; i < OUTPUT_TYPES.length; ++i) {
1016
+ var type = OUTPUT_TYPES[i];
1017
+ method[type] = createHmacOutputMethod(type, is224);
1018
+ }
1019
+ return method;
1020
+ };
1021
+ function Sha256(is224, sharedMemory) {
1022
+ if (sharedMemory) {
1023
+ blocks[0] = blocks[16] = blocks[1] = blocks[2] = blocks[3] = blocks[4] = blocks[5] = blocks[6] = blocks[7] = blocks[8] = blocks[9] = blocks[10] = blocks[11] = blocks[12] = blocks[13] = blocks[14] = blocks[15] = 0;
1024
+ this.blocks = blocks;
1025
+ } else {
1026
+ this.blocks = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
1027
+ }
1028
+ if (is224) {
1029
+ this.h0 = 3238371032;
1030
+ this.h1 = 914150663;
1031
+ this.h2 = 812702999;
1032
+ this.h3 = 4144912697;
1033
+ this.h4 = 4290775857;
1034
+ this.h5 = 1750603025;
1035
+ this.h6 = 1694076839;
1036
+ this.h7 = 3204075428;
1037
+ } else {
1038
+ this.h0 = 1779033703;
1039
+ this.h1 = 3144134277;
1040
+ this.h2 = 1013904242;
1041
+ this.h3 = 2773480762;
1042
+ this.h4 = 1359893119;
1043
+ this.h5 = 2600822924;
1044
+ this.h6 = 528734635;
1045
+ this.h7 = 1541459225;
1046
+ }
1047
+ this.block = this.start = this.bytes = this.hBytes = 0;
1048
+ this.finalized = this.hashed = false;
1049
+ this.first = true;
1050
+ this.is224 = is224;
1051
+ }
1052
+ Sha256.prototype.update = function(message) {
1053
+ if (this.finalized) {
1054
+ return;
1055
+ }
1056
+ var notString, type = typeof message;
1057
+ if (type !== "string") {
1058
+ if (type === "object") {
1059
+ if (message === null) {
1060
+ throw new Error(ERROR);
1061
+ } else if (ARRAY_BUFFER && message.constructor === ArrayBuffer) {
1062
+ message = new Uint8Array(message);
1063
+ } else if (!Array.isArray(message)) {
1064
+ if (!ARRAY_BUFFER || !ArrayBuffer.isView(message)) {
1065
+ throw new Error(ERROR);
1066
+ }
1067
+ }
1068
+ } else {
1069
+ throw new Error(ERROR);
1070
+ }
1071
+ notString = true;
1072
+ }
1073
+ var code, index = 0, i, length = message.length, blocks2 = this.blocks;
1074
+ while (index < length) {
1075
+ if (this.hashed) {
1076
+ this.hashed = false;
1077
+ blocks2[0] = this.block;
1078
+ this.block = blocks2[16] = blocks2[1] = blocks2[2] = blocks2[3] = blocks2[4] = blocks2[5] = blocks2[6] = blocks2[7] = blocks2[8] = blocks2[9] = blocks2[10] = blocks2[11] = blocks2[12] = blocks2[13] = blocks2[14] = blocks2[15] = 0;
1079
+ }
1080
+ if (notString) {
1081
+ for (i = this.start; index < length && i < 64; ++index) {
1082
+ blocks2[i >>> 2] |= message[index] << SHIFT[i++ & 3];
1083
+ }
1084
+ } else {
1085
+ for (i = this.start; index < length && i < 64; ++index) {
1086
+ code = message.charCodeAt(index);
1087
+ if (code < 128) {
1088
+ blocks2[i >>> 2] |= code << SHIFT[i++ & 3];
1089
+ } else if (code < 2048) {
1090
+ blocks2[i >>> 2] |= (192 | code >>> 6) << SHIFT[i++ & 3];
1091
+ blocks2[i >>> 2] |= (128 | code & 63) << SHIFT[i++ & 3];
1092
+ } else if (code < 55296 || code >= 57344) {
1093
+ blocks2[i >>> 2] |= (224 | code >>> 12) << SHIFT[i++ & 3];
1094
+ blocks2[i >>> 2] |= (128 | code >>> 6 & 63) << SHIFT[i++ & 3];
1095
+ blocks2[i >>> 2] |= (128 | code & 63) << SHIFT[i++ & 3];
1096
+ } else {
1097
+ code = 65536 + ((code & 1023) << 10 | message.charCodeAt(++index) & 1023);
1098
+ blocks2[i >>> 2] |= (240 | code >>> 18) << SHIFT[i++ & 3];
1099
+ blocks2[i >>> 2] |= (128 | code >>> 12 & 63) << SHIFT[i++ & 3];
1100
+ blocks2[i >>> 2] |= (128 | code >>> 6 & 63) << SHIFT[i++ & 3];
1101
+ blocks2[i >>> 2] |= (128 | code & 63) << SHIFT[i++ & 3];
1102
+ }
1103
+ }
1104
+ }
1105
+ this.lastByteIndex = i;
1106
+ this.bytes += i - this.start;
1107
+ if (i >= 64) {
1108
+ this.block = blocks2[16];
1109
+ this.start = i - 64;
1110
+ this.hash();
1111
+ this.hashed = true;
1112
+ } else {
1113
+ this.start = i;
1114
+ }
1115
+ }
1116
+ if (this.bytes > 4294967295) {
1117
+ this.hBytes += this.bytes / 4294967296 << 0;
1118
+ this.bytes = this.bytes % 4294967296;
1119
+ }
1120
+ return this;
1121
+ };
1122
+ Sha256.prototype.finalize = function() {
1123
+ if (this.finalized) {
1124
+ return;
1125
+ }
1126
+ this.finalized = true;
1127
+ var blocks2 = this.blocks, i = this.lastByteIndex;
1128
+ blocks2[16] = this.block;
1129
+ blocks2[i >>> 2] |= EXTRA[i & 3];
1130
+ this.block = blocks2[16];
1131
+ if (i >= 56) {
1132
+ if (!this.hashed) {
1133
+ this.hash();
1134
+ }
1135
+ blocks2[0] = this.block;
1136
+ blocks2[16] = blocks2[1] = blocks2[2] = blocks2[3] = blocks2[4] = blocks2[5] = blocks2[6] = blocks2[7] = blocks2[8] = blocks2[9] = blocks2[10] = blocks2[11] = blocks2[12] = blocks2[13] = blocks2[14] = blocks2[15] = 0;
1137
+ }
1138
+ blocks2[14] = this.hBytes << 3 | this.bytes >>> 29;
1139
+ blocks2[15] = this.bytes << 3;
1140
+ this.hash();
1141
+ };
1142
+ Sha256.prototype.hash = function() {
1143
+ var a = this.h0, b = this.h1, c = this.h2, d = this.h3, e = this.h4, f2 = this.h5, g = this.h6, h = this.h7, blocks2 = this.blocks, j, s0, s1, maj, t1, t2, ch, ab, da, cd, bc;
1144
+ for (j = 16; j < 64; ++j) {
1145
+ t1 = blocks2[j - 15];
1146
+ s0 = (t1 >>> 7 | t1 << 25) ^ (t1 >>> 18 | t1 << 14) ^ t1 >>> 3;
1147
+ t1 = blocks2[j - 2];
1148
+ s1 = (t1 >>> 17 | t1 << 15) ^ (t1 >>> 19 | t1 << 13) ^ t1 >>> 10;
1149
+ blocks2[j] = blocks2[j - 16] + s0 + blocks2[j - 7] + s1 << 0;
1150
+ }
1151
+ bc = b & c;
1152
+ for (j = 0; j < 64; j += 4) {
1153
+ if (this.first) {
1154
+ if (this.is224) {
1155
+ ab = 300032;
1156
+ t1 = blocks2[0] - 1413257819;
1157
+ h = t1 - 150054599 << 0;
1158
+ d = t1 + 24177077 << 0;
1159
+ } else {
1160
+ ab = 704751109;
1161
+ t1 = blocks2[0] - 210244248;
1162
+ h = t1 - 1521486534 << 0;
1163
+ d = t1 + 143694565 << 0;
1164
+ }
1165
+ this.first = false;
1166
+ } else {
1167
+ s0 = (a >>> 2 | a << 30) ^ (a >>> 13 | a << 19) ^ (a >>> 22 | a << 10);
1168
+ s1 = (e >>> 6 | e << 26) ^ (e >>> 11 | e << 21) ^ (e >>> 25 | e << 7);
1169
+ ab = a & b;
1170
+ maj = ab ^ a & c ^ bc;
1171
+ ch = e & f2 ^ ~e & g;
1172
+ t1 = h + s1 + ch + K[j] + blocks2[j];
1173
+ t2 = s0 + maj;
1174
+ h = d + t1 << 0;
1175
+ d = t1 + t2 << 0;
1176
+ }
1177
+ s0 = (d >>> 2 | d << 30) ^ (d >>> 13 | d << 19) ^ (d >>> 22 | d << 10);
1178
+ s1 = (h >>> 6 | h << 26) ^ (h >>> 11 | h << 21) ^ (h >>> 25 | h << 7);
1179
+ da = d & a;
1180
+ maj = da ^ d & b ^ ab;
1181
+ ch = h & e ^ ~h & f2;
1182
+ t1 = g + s1 + ch + K[j + 1] + blocks2[j + 1];
1183
+ t2 = s0 + maj;
1184
+ g = c + t1 << 0;
1185
+ c = t1 + t2 << 0;
1186
+ s0 = (c >>> 2 | c << 30) ^ (c >>> 13 | c << 19) ^ (c >>> 22 | c << 10);
1187
+ s1 = (g >>> 6 | g << 26) ^ (g >>> 11 | g << 21) ^ (g >>> 25 | g << 7);
1188
+ cd = c & d;
1189
+ maj = cd ^ c & a ^ da;
1190
+ ch = g & h ^ ~g & e;
1191
+ t1 = f2 + s1 + ch + K[j + 2] + blocks2[j + 2];
1192
+ t2 = s0 + maj;
1193
+ f2 = b + t1 << 0;
1194
+ b = t1 + t2 << 0;
1195
+ s0 = (b >>> 2 | b << 30) ^ (b >>> 13 | b << 19) ^ (b >>> 22 | b << 10);
1196
+ s1 = (f2 >>> 6 | f2 << 26) ^ (f2 >>> 11 | f2 << 21) ^ (f2 >>> 25 | f2 << 7);
1197
+ bc = b & c;
1198
+ maj = bc ^ b & d ^ cd;
1199
+ ch = f2 & g ^ ~f2 & h;
1200
+ t1 = e + s1 + ch + K[j + 3] + blocks2[j + 3];
1201
+ t2 = s0 + maj;
1202
+ e = a + t1 << 0;
1203
+ a = t1 + t2 << 0;
1204
+ this.chromeBugWorkAround = true;
1205
+ }
1206
+ this.h0 = this.h0 + a << 0;
1207
+ this.h1 = this.h1 + b << 0;
1208
+ this.h2 = this.h2 + c << 0;
1209
+ this.h3 = this.h3 + d << 0;
1210
+ this.h4 = this.h4 + e << 0;
1211
+ this.h5 = this.h5 + f2 << 0;
1212
+ this.h6 = this.h6 + g << 0;
1213
+ this.h7 = this.h7 + h << 0;
1214
+ };
1215
+ Sha256.prototype.hex = function() {
1216
+ this.finalize();
1217
+ var h0 = this.h0, h1 = this.h1, h2 = this.h2, h3 = this.h3, h4 = this.h4, h5 = this.h5, h6 = this.h6, h7 = this.h7;
1218
+ var hex = HEX_CHARS[h0 >>> 28 & 15] + HEX_CHARS[h0 >>> 24 & 15] + HEX_CHARS[h0 >>> 20 & 15] + HEX_CHARS[h0 >>> 16 & 15] + HEX_CHARS[h0 >>> 12 & 15] + HEX_CHARS[h0 >>> 8 & 15] + HEX_CHARS[h0 >>> 4 & 15] + HEX_CHARS[h0 & 15] + HEX_CHARS[h1 >>> 28 & 15] + HEX_CHARS[h1 >>> 24 & 15] + HEX_CHARS[h1 >>> 20 & 15] + HEX_CHARS[h1 >>> 16 & 15] + HEX_CHARS[h1 >>> 12 & 15] + HEX_CHARS[h1 >>> 8 & 15] + HEX_CHARS[h1 >>> 4 & 15] + HEX_CHARS[h1 & 15] + HEX_CHARS[h2 >>> 28 & 15] + HEX_CHARS[h2 >>> 24 & 15] + HEX_CHARS[h2 >>> 20 & 15] + HEX_CHARS[h2 >>> 16 & 15] + HEX_CHARS[h2 >>> 12 & 15] + HEX_CHARS[h2 >>> 8 & 15] + HEX_CHARS[h2 >>> 4 & 15] + HEX_CHARS[h2 & 15] + HEX_CHARS[h3 >>> 28 & 15] + HEX_CHARS[h3 >>> 24 & 15] + HEX_CHARS[h3 >>> 20 & 15] + HEX_CHARS[h3 >>> 16 & 15] + HEX_CHARS[h3 >>> 12 & 15] + HEX_CHARS[h3 >>> 8 & 15] + HEX_CHARS[h3 >>> 4 & 15] + HEX_CHARS[h3 & 15] + HEX_CHARS[h4 >>> 28 & 15] + HEX_CHARS[h4 >>> 24 & 15] + HEX_CHARS[h4 >>> 20 & 15] + HEX_CHARS[h4 >>> 16 & 15] + HEX_CHARS[h4 >>> 12 & 15] + HEX_CHARS[h4 >>> 8 & 15] + HEX_CHARS[h4 >>> 4 & 15] + HEX_CHARS[h4 & 15] + HEX_CHARS[h5 >>> 28 & 15] + HEX_CHARS[h5 >>> 24 & 15] + HEX_CHARS[h5 >>> 20 & 15] + HEX_CHARS[h5 >>> 16 & 15] + HEX_CHARS[h5 >>> 12 & 15] + HEX_CHARS[h5 >>> 8 & 15] + HEX_CHARS[h5 >>> 4 & 15] + HEX_CHARS[h5 & 15] + HEX_CHARS[h6 >>> 28 & 15] + HEX_CHARS[h6 >>> 24 & 15] + HEX_CHARS[h6 >>> 20 & 15] + HEX_CHARS[h6 >>> 16 & 15] + HEX_CHARS[h6 >>> 12 & 15] + HEX_CHARS[h6 >>> 8 & 15] + HEX_CHARS[h6 >>> 4 & 15] + HEX_CHARS[h6 & 15];
1219
+ if (!this.is224) {
1220
+ hex += HEX_CHARS[h7 >>> 28 & 15] + HEX_CHARS[h7 >>> 24 & 15] + HEX_CHARS[h7 >>> 20 & 15] + HEX_CHARS[h7 >>> 16 & 15] + HEX_CHARS[h7 >>> 12 & 15] + HEX_CHARS[h7 >>> 8 & 15] + HEX_CHARS[h7 >>> 4 & 15] + HEX_CHARS[h7 & 15];
1221
+ }
1222
+ return hex;
1223
+ };
1224
+ Sha256.prototype.toString = Sha256.prototype.hex;
1225
+ Sha256.prototype.digest = function() {
1226
+ this.finalize();
1227
+ var h0 = this.h0, h1 = this.h1, h2 = this.h2, h3 = this.h3, h4 = this.h4, h5 = this.h5, h6 = this.h6, h7 = this.h7;
1228
+ var arr = [
1229
+ h0 >>> 24 & 255,
1230
+ h0 >>> 16 & 255,
1231
+ h0 >>> 8 & 255,
1232
+ h0 & 255,
1233
+ h1 >>> 24 & 255,
1234
+ h1 >>> 16 & 255,
1235
+ h1 >>> 8 & 255,
1236
+ h1 & 255,
1237
+ h2 >>> 24 & 255,
1238
+ h2 >>> 16 & 255,
1239
+ h2 >>> 8 & 255,
1240
+ h2 & 255,
1241
+ h3 >>> 24 & 255,
1242
+ h3 >>> 16 & 255,
1243
+ h3 >>> 8 & 255,
1244
+ h3 & 255,
1245
+ h4 >>> 24 & 255,
1246
+ h4 >>> 16 & 255,
1247
+ h4 >>> 8 & 255,
1248
+ h4 & 255,
1249
+ h5 >>> 24 & 255,
1250
+ h5 >>> 16 & 255,
1251
+ h5 >>> 8 & 255,
1252
+ h5 & 255,
1253
+ h6 >>> 24 & 255,
1254
+ h6 >>> 16 & 255,
1255
+ h6 >>> 8 & 255,
1256
+ h6 & 255
1257
+ ];
1258
+ if (!this.is224) {
1259
+ arr.push(h7 >>> 24 & 255, h7 >>> 16 & 255, h7 >>> 8 & 255, h7 & 255);
1260
+ }
1261
+ return arr;
1262
+ };
1263
+ Sha256.prototype.array = Sha256.prototype.digest;
1264
+ Sha256.prototype.arrayBuffer = function() {
1265
+ this.finalize();
1266
+ var buffer = new ArrayBuffer(this.is224 ? 28 : 32);
1267
+ var dataView = new DataView(buffer);
1268
+ dataView.setUint32(0, this.h0);
1269
+ dataView.setUint32(4, this.h1);
1270
+ dataView.setUint32(8, this.h2);
1271
+ dataView.setUint32(12, this.h3);
1272
+ dataView.setUint32(16, this.h4);
1273
+ dataView.setUint32(20, this.h5);
1274
+ dataView.setUint32(24, this.h6);
1275
+ if (!this.is224) {
1276
+ dataView.setUint32(28, this.h7);
1277
+ }
1278
+ return buffer;
1279
+ };
1280
+ function HmacSha256(key, is224, sharedMemory) {
1281
+ var i, type = typeof key;
1282
+ if (type === "string") {
1283
+ var bytes = [], length = key.length, index = 0, code;
1284
+ for (i = 0; i < length; ++i) {
1285
+ code = key.charCodeAt(i);
1286
+ if (code < 128) {
1287
+ bytes[index++] = code;
1288
+ } else if (code < 2048) {
1289
+ bytes[index++] = 192 | code >>> 6;
1290
+ bytes[index++] = 128 | code & 63;
1291
+ } else if (code < 55296 || code >= 57344) {
1292
+ bytes[index++] = 224 | code >>> 12;
1293
+ bytes[index++] = 128 | code >>> 6 & 63;
1294
+ bytes[index++] = 128 | code & 63;
1295
+ } else {
1296
+ code = 65536 + ((code & 1023) << 10 | key.charCodeAt(++i) & 1023);
1297
+ bytes[index++] = 240 | code >>> 18;
1298
+ bytes[index++] = 128 | code >>> 12 & 63;
1299
+ bytes[index++] = 128 | code >>> 6 & 63;
1300
+ bytes[index++] = 128 | code & 63;
1301
+ }
1302
+ }
1303
+ key = bytes;
1304
+ } else {
1305
+ if (type === "object") {
1306
+ if (key === null) {
1307
+ throw new Error(ERROR);
1308
+ } else if (ARRAY_BUFFER && key.constructor === ArrayBuffer) {
1309
+ key = new Uint8Array(key);
1310
+ } else if (!Array.isArray(key)) {
1311
+ if (!ARRAY_BUFFER || !ArrayBuffer.isView(key)) {
1312
+ throw new Error(ERROR);
1313
+ }
1314
+ }
1315
+ } else {
1316
+ throw new Error(ERROR);
1317
+ }
1318
+ }
1319
+ if (key.length > 64) {
1320
+ key = new Sha256(is224, true).update(key).array();
1321
+ }
1322
+ var oKeyPad = [], iKeyPad = [];
1323
+ for (i = 0; i < 64; ++i) {
1324
+ var b = key[i] || 0;
1325
+ oKeyPad[i] = 92 ^ b;
1326
+ iKeyPad[i] = 54 ^ b;
1327
+ }
1328
+ Sha256.call(this, is224, sharedMemory);
1329
+ this.update(iKeyPad);
1330
+ this.oKeyPad = oKeyPad;
1331
+ this.inner = true;
1332
+ this.sharedMemory = sharedMemory;
1333
+ }
1334
+ HmacSha256.prototype = new Sha256();
1335
+ HmacSha256.prototype.finalize = function() {
1336
+ Sha256.prototype.finalize.call(this);
1337
+ if (this.inner) {
1338
+ this.inner = false;
1339
+ var innerHash = this.array();
1340
+ Sha256.call(this, this.is224, this.sharedMemory);
1341
+ this.update(this.oKeyPad);
1342
+ this.update(innerHash);
1343
+ Sha256.prototype.finalize.call(this);
1344
+ }
1345
+ };
1346
+ var exports2 = createMethod();
1347
+ exports2.sha256 = exports2;
1348
+ exports2.sha224 = createMethod(true);
1349
+ exports2.sha256.hmac = createHmacMethod();
1350
+ exports2.sha224.hmac = createHmacMethod(true);
1351
+ if (COMMON_JS) {
1352
+ module2.exports = exports2;
1353
+ } else {
1354
+ root.sha256 = exports2.sha256;
1355
+ root.sha224 = exports2.sha224;
1356
+ if (AMD) {
1357
+ define(function() {
1358
+ return exports2;
1359
+ });
1360
+ }
1361
+ }
1362
+ })();
1363
+ }
1364
+ });
1365
+
1366
+ // ../core/dist/hash.js
1367
+ var require_hash = __commonJS({
1368
+ "../core/dist/hash.js"(exports) {
1369
+ "use strict";
1370
+ Object.defineProperty(exports, "__esModule", { value: true });
1371
+ exports.hashEmail = hashEmail2;
1372
+ exports.hashPhone = hashPhone2;
1373
+ exports.hashPii = hashPii;
1374
+ exports.sha256Hex = sha256Hex;
1375
+ var js_sha256_1 = require_sha256();
1376
+ function hashEmail2(email) {
1377
+ if (!email)
1378
+ return void 0;
1379
+ const normalized = email.trim().toLowerCase();
1380
+ if (normalized.length === 0)
1381
+ return void 0;
1382
+ return (0, js_sha256_1.sha256)(normalized);
1383
+ }
1384
+ function hashPhone2(phone) {
1385
+ if (!phone)
1386
+ return void 0;
1387
+ const digits = phone.replace(/\D/g, "");
1388
+ if (digits.length === 0)
1389
+ return void 0;
1390
+ return (0, js_sha256_1.sha256)(digits);
1391
+ }
1392
+ function hashPii(value) {
1393
+ if (!value)
1394
+ return void 0;
1395
+ const normalized = value.trim().toLowerCase();
1396
+ if (normalized.length === 0)
1397
+ return void 0;
1398
+ return (0, js_sha256_1.sha256)(normalized);
1399
+ }
1400
+ function sha256Hex(value) {
1401
+ return (0, js_sha256_1.sha256)(value);
1402
+ }
1403
+ }
1404
+ });
1405
+
1406
+ // ../core/dist/index.js
1407
+ var require_dist = __commonJS({
1408
+ "../core/dist/index.js"(exports) {
1409
+ "use strict";
1410
+ var __createBinding = exports && exports.__createBinding || (Object.create ? (function(o, m, k, k2) {
1411
+ if (k2 === void 0) k2 = k;
1412
+ var desc = Object.getOwnPropertyDescriptor(m, k);
1413
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
1414
+ desc = { enumerable: true, get: function() {
1415
+ return m[k];
1416
+ } };
1417
+ }
1418
+ Object.defineProperty(o, k2, desc);
1419
+ }) : (function(o, m, k, k2) {
1420
+ if (k2 === void 0) k2 = k;
1421
+ o[k2] = m[k];
1422
+ }));
1423
+ var __exportStar = exports && exports.__exportStar || function(m, exports2) {
1424
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports2, p)) __createBinding(exports2, m, p);
1425
+ };
1426
+ Object.defineProperty(exports, "__esModule", { value: true });
1427
+ __exportStar(require_schema(), exports);
1428
+ __exportStar(require_productEvent(), exports);
1429
+ __exportStar(require_eventId(), exports);
1430
+ __exportStar(require_revenueRules(), exports);
1431
+ __exportStar(require_hash(), exports);
1432
+ }
1433
+ });
1434
+
1435
+ // src/index.ts
1436
+ var index_exports = {};
1437
+ __export(index_exports, {
1438
+ DEFAULT_RETRY: () => DEFAULT_RETRY,
1439
+ EventQueue: () => EventQueue,
1440
+ MemoryStorage: () => MemoryStorage,
1441
+ MetaAdapter: () => MetaAdapter,
1442
+ TikTokAdapter: () => TikTokAdapter,
1443
+ Transport: () => Transport,
1444
+ buildRevenue: () => import_core3.buildRevenue,
1445
+ collectDeviceContext: () => collectDeviceContext,
1446
+ computeRetryDelayMs: () => computeRetryDelayMs,
1447
+ createTrackStallClient: () => createTrackStallClient,
1448
+ defaultStorage: () => defaultStorage,
1449
+ deterministicEventId: () => import_core3.deterministicEventId,
1450
+ getAttStatus: () => getAttStatus,
1451
+ isRetriableStatus: () => isRetriableStatus,
1452
+ loadAttModule: () => loadAttModule,
1453
+ mapToMetaEvent: () => mapToMetaEvent,
1454
+ mapToTikTokEvent: () => mapToTikTokEvent,
1455
+ normalizeAttStatus: () => normalizeAttStatus,
1456
+ randomEventId: () => import_core3.randomEventId,
1457
+ readAdvertisingId: () => readAdvertisingId,
1458
+ requestAttStatus: () => requestAttStatus,
1459
+ resolveRetryConfig: () => resolveRetryConfig,
1460
+ shouldRetry: () => shouldRetry
1461
+ });
1462
+ module.exports = __toCommonJS(index_exports);
1463
+
1464
+ // src/client.ts
1465
+ var import_core2 = __toESM(require_dist());
1466
+
1467
+ // src/att.ts
1468
+ function loadAttModule(injected) {
1469
+ if (injected) return injected;
1470
+ try {
1471
+ return require("expo-tracking-transparency");
1472
+ } catch {
1473
+ }
1474
+ try {
1475
+ return require("react-native-tracking-transparency");
1476
+ } catch {
1477
+ }
1478
+ return null;
1479
+ }
1480
+ async function requestAttStatus(mod) {
1481
+ if (mod.requestTrackingPermissionsAsync) {
1482
+ const res = await mod.requestTrackingPermissionsAsync();
1483
+ return normalizeAttStatus(res == null ? void 0 : res.status);
1484
+ }
1485
+ if (mod.requestTrackingPermission) {
1486
+ return normalizeAttStatus(await mod.requestTrackingPermission());
1487
+ }
1488
+ return "unavailable";
1489
+ }
1490
+ function readAdvertisingId(mod) {
1491
+ if (!mod.getAdvertisingId) return void 0;
1492
+ try {
1493
+ const id = mod.getAdvertisingId();
1494
+ if (!id || id === "00000000-0000-0000-0000-000000000000") return void 0;
1495
+ return id;
1496
+ } catch {
1497
+ return void 0;
1498
+ }
1499
+ }
1500
+ async function getAttStatus(mod) {
1501
+ if (mod.getTrackingPermissionsAsync) {
1502
+ const res = await mod.getTrackingPermissionsAsync();
1503
+ return normalizeAttStatus(res == null ? void 0 : res.status);
1504
+ }
1505
+ if (mod.getTrackingStatus) {
1506
+ return normalizeAttStatus(await mod.getTrackingStatus());
1507
+ }
1508
+ return "unavailable";
1509
+ }
1510
+ function normalizeAttStatus(raw) {
1511
+ switch (raw) {
1512
+ case "authorized":
1513
+ case "granted":
1514
+ return "authorized";
1515
+ case "denied":
1516
+ return "denied";
1517
+ case "restricted":
1518
+ return "restricted";
1519
+ case "not-determined":
1520
+ case "undetermined":
1521
+ return "undetermined";
1522
+ default:
1523
+ return "unavailable";
1524
+ }
1525
+ }
1526
+
1527
+ // src/deviceContext.ts
1528
+ var ZERO_UUID = "00000000-0000-0000-0000-000000000000";
1529
+ function collectDeviceContext() {
1530
+ var _a, _b;
1531
+ const out = {};
1532
+ const rn = loadReactNative();
1533
+ if (rn == null ? void 0 : rn.Dimensions) {
1534
+ try {
1535
+ const screen = (_a = rn.Dimensions.get("screen")) != null ? _a : rn.Dimensions.get("window");
1536
+ if (screen) {
1537
+ if (Number.isFinite(screen.width)) out.screenW = Math.round(screen.width);
1538
+ if (Number.isFinite(screen.height)) out.screenH = Math.round(screen.height);
1539
+ if (typeof screen.scale === "number" && Number.isFinite(screen.scale)) out.pixelRatio = screen.scale;
1540
+ }
1541
+ } catch {
1542
+ }
1543
+ }
1544
+ if (out.pixelRatio === void 0 && (rn == null ? void 0 : rn.PixelRatio)) {
1545
+ try {
1546
+ const ratio = rn.PixelRatio.get();
1547
+ if (typeof ratio === "number" && Number.isFinite(ratio)) out.pixelRatio = ratio;
1548
+ } catch {
1549
+ }
1550
+ }
1551
+ const expoDevice = loadExpoDevice();
1552
+ if (expoDevice == null ? void 0 : expoDevice.modelName) out.deviceModel = expoDevice.modelName;
1553
+ if (expoDevice == null ? void 0 : expoDevice.osVersion) out.osVersion = expoDevice.osVersion;
1554
+ if (out.osVersion === void 0 && ((_b = rn == null ? void 0 : rn.Platform) == null ? void 0 : _b.Version) !== void 0) {
1555
+ out.osVersion = String(rn.Platform.Version);
1556
+ }
1557
+ const locale = detectLocale();
1558
+ if (locale) out.locale = locale;
1559
+ const timezone = detectTimezone();
1560
+ if (timezone) out.timezone = timezone;
1561
+ return pruneUndefined(out);
1562
+ }
1563
+ function loadReactNative() {
1564
+ try {
1565
+ return require("react-native");
1566
+ } catch {
1567
+ return null;
1568
+ }
1569
+ }
1570
+ function loadExpoDevice() {
1571
+ try {
1572
+ return require("expo-device");
1573
+ } catch {
1574
+ return null;
1575
+ }
1576
+ }
1577
+ function loadExpoApplication() {
1578
+ try {
1579
+ return require("expo-application");
1580
+ } catch {
1581
+ return null;
1582
+ }
1583
+ }
1584
+ async function collectIosIdForVendor() {
1585
+ const app = loadExpoApplication();
1586
+ if (!(app == null ? void 0 : app.getIosIdForVendorAsync)) return void 0;
1587
+ try {
1588
+ const idfv = await app.getIosIdForVendorAsync();
1589
+ if (!idfv || idfv === ZERO_UUID) return void 0;
1590
+ return idfv;
1591
+ } catch {
1592
+ return void 0;
1593
+ }
1594
+ }
1595
+ function detectLocale() {
1596
+ try {
1597
+ const resolved = Intl.DateTimeFormat().resolvedOptions().locale;
1598
+ return resolved || void 0;
1599
+ } catch {
1600
+ return void 0;
1601
+ }
1602
+ }
1603
+ function detectTimezone() {
1604
+ try {
1605
+ const tz = Intl.DateTimeFormat().resolvedOptions().timeZone;
1606
+ return tz || void 0;
1607
+ } catch {
1608
+ return void 0;
1609
+ }
1610
+ }
1611
+ function pruneUndefined(obj) {
1612
+ for (const k of Object.keys(obj)) {
1613
+ if (obj[k] === void 0) delete obj[k];
1614
+ }
1615
+ return obj;
1616
+ }
1617
+
1618
+ // src/adapters/metaAdapter.ts
1619
+ var import_core = __toESM(require_dist());
1620
+ var MetaAdapter = class {
1621
+ constructor(options) {
1622
+ this.options = options;
1623
+ this.sdk = null;
1624
+ var _a;
1625
+ this.name = (_a = options.name) != null ? _a : "meta";
1626
+ this.honorAtt = options.honorAtt !== false;
1627
+ }
1628
+ async initialize() {
1629
+ var _a, _b, _c, _d, _e, _f;
1630
+ const sdk = this.loadSdk();
1631
+ sdk.Settings.setAppID(this.options.appId);
1632
+ sdk.Settings.setClientToken(this.options.clientToken);
1633
+ if (this.honorAtt) {
1634
+ await Promise.resolve((_b = (_a = sdk.Settings).setAdvertiserTrackingEnabled) == null ? void 0 : _b.call(_a, true));
1635
+ await Promise.resolve((_d = (_c = sdk.Settings).setAdvertiserIDCollectionEnabled) == null ? void 0 : _d.call(_c, true));
1636
+ }
1637
+ await Promise.resolve((_f = (_e = sdk.Settings).setAutoLogAppEventsEnabled) == null ? void 0 : _f.call(_e, false));
1638
+ sdk.Settings.initializeSDK();
1639
+ this.sdk = sdk;
1640
+ }
1641
+ setUser(identity) {
1642
+ var _a, _b, _c, _d, _e;
1643
+ if (!this.sdk) return;
1644
+ if (!identity) {
1645
+ this.sdk.AppEventsLogger.clearUserID();
1646
+ (_b = (_a = this.sdk.AppEventsLogger).clearUserData) == null ? void 0 : _b.call(_a);
1647
+ return;
1648
+ }
1649
+ this.sdk.AppEventsLogger.setUserID(identity.userId);
1650
+ this.sdk.AppEventsLogger.setUserData({
1651
+ em: (_c = (0, import_core.hashEmail)(identity.email)) != null ? _c : null,
1652
+ ph: (_d = (0, import_core.hashPhone)(identity.phone)) != null ? _d : null,
1653
+ country: (_e = identity.country) != null ? _e : null
1654
+ });
1655
+ }
1656
+ async deliver(event) {
1657
+ if (!this.sdk) {
1658
+ return { ok: false, code: "sdk_not_initialized", retriable: true };
1659
+ }
1660
+ try {
1661
+ const mapped = mapToMetaEvent(event);
1662
+ if (!mapped) return { ok: true, code: "unmapped" };
1663
+ const params = withEventId(mapped.parameters, event.eventId);
1664
+ if (mapped.kind === "purchase" && mapped.amount !== void 0 && mapped.currency) {
1665
+ this.sdk.AppEventsLogger.logPurchase(mapped.amount, mapped.currency, params);
1666
+ } else if (mapped.valueToSum !== void 0) {
1667
+ this.sdk.AppEventsLogger.logEvent(mapped.name, mapped.valueToSum, params);
1668
+ } else {
1669
+ this.sdk.AppEventsLogger.logEvent(mapped.name, params);
1670
+ }
1671
+ return { ok: true };
1672
+ } catch (err) {
1673
+ return {
1674
+ ok: false,
1675
+ code: "sdk_threw",
1676
+ message: err instanceof Error ? err.message : String(err),
1677
+ retriable: true
1678
+ };
1679
+ }
1680
+ }
1681
+ async flush() {
1682
+ var _a;
1683
+ (_a = this.sdk) == null ? void 0 : _a.AppEventsLogger.flush();
1684
+ }
1685
+ async setAdvertiserTracking(enabled) {
1686
+ var _a, _b, _c, _d;
1687
+ if (!this.sdk || !this.honorAtt) return;
1688
+ await Promise.resolve((_b = (_a = this.sdk.Settings).setAdvertiserTrackingEnabled) == null ? void 0 : _b.call(_a, enabled));
1689
+ await Promise.resolve((_d = (_c = this.sdk.Settings).setAdvertiserIDCollectionEnabled) == null ? void 0 : _d.call(_c, enabled));
1690
+ }
1691
+ loadSdk() {
1692
+ if (this.options.sdkLoader) return this.options.sdkLoader();
1693
+ try {
1694
+ return require("react-native-fbsdk-next");
1695
+ } catch (err) {
1696
+ throw new Error(
1697
+ `@trackstall/sdk: failed to load \`react-native-fbsdk-next\`. Install it in the host app and run \`pod install\`. Underlying error: ${err instanceof Error ? err.message : String(err)}`
1698
+ );
1699
+ }
1700
+ }
1701
+ };
1702
+ function mapToMetaEvent(event) {
1703
+ var _a, _b, _c, _d, _e, _f;
1704
+ const baseParams = { fb_event_source: "trackstall" };
1705
+ if (event.productId) baseParams["fb_content_id"] = event.productId;
1706
+ if (event.properties) {
1707
+ for (const [k, v] of Object.entries(event.properties)) {
1708
+ if (v === null) continue;
1709
+ baseParams[k] = v;
1710
+ }
1711
+ }
1712
+ switch (event.name) {
1713
+ case "purchase":
1714
+ if (!event.revenue) return null;
1715
+ return {
1716
+ name: "fb_mobile_purchase",
1717
+ kind: "purchase",
1718
+ amount: event.revenue.netValue,
1719
+ currency: event.revenue.currency,
1720
+ parameters: { ...baseParams, fb_content_type: "product", fb_currency: event.revenue.currency }
1721
+ };
1722
+ case "subscribe":
1723
+ if (!event.revenue) return null;
1724
+ return {
1725
+ name: "Subscribe",
1726
+ kind: "standard",
1727
+ valueToSum: event.revenue.netValue,
1728
+ parameters: { ...baseParams, fb_content_type: "product", fb_currency: event.revenue.currency }
1729
+ };
1730
+ case "renewal":
1731
+ if (!event.revenue) return null;
1732
+ return {
1733
+ name: "Renewal",
1734
+ kind: "custom",
1735
+ valueToSum: event.revenue.netValue,
1736
+ parameters: { ...baseParams, fb_content_type: "product", fb_currency: event.revenue.currency }
1737
+ };
1738
+ case "refund":
1739
+ if (!event.revenue) return null;
1740
+ return {
1741
+ name: "fb_mobile_purchase",
1742
+ kind: "purchase",
1743
+ amount: -Math.abs(event.revenue.netValue),
1744
+ currency: event.revenue.currency,
1745
+ parameters: { ...baseParams, fb_content_type: "product", is_refund: true }
1746
+ };
1747
+ case "trial_started":
1748
+ return {
1749
+ name: "StartTrial",
1750
+ kind: "standard",
1751
+ valueToSum: (_a = event.revenue) == null ? void 0 : _a.netValue,
1752
+ parameters: { ...baseParams, fb_currency: (_b = event.revenue) == null ? void 0 : _b.currency, fb_content_type: "product" }
1753
+ };
1754
+ case "start_checkout":
1755
+ return {
1756
+ name: "fb_mobile_initiated_checkout",
1757
+ kind: "standard",
1758
+ valueToSum: (_c = event.revenue) == null ? void 0 : _c.netValue,
1759
+ parameters: { ...baseParams, fb_currency: (_d = event.revenue) == null ? void 0 : _d.currency, fb_num_items: 1 }
1760
+ };
1761
+ case "add_to_cart":
1762
+ return {
1763
+ name: "fb_mobile_add_to_cart",
1764
+ kind: "standard",
1765
+ valueToSum: (_e = event.revenue) == null ? void 0 : _e.netValue,
1766
+ parameters: { ...baseParams, fb_currency: (_f = event.revenue) == null ? void 0 : _f.currency }
1767
+ };
1768
+ case "paywall_shown":
1769
+ case "content_view":
1770
+ return { name: "fb_mobile_content_view", kind: "standard", parameters: baseParams };
1771
+ case "install":
1772
+ return { name: "fb_mobile_activate_app", kind: "standard", parameters: baseParams };
1773
+ case "onboarding_completed":
1774
+ return { name: "fb_mobile_complete_registration", kind: "standard", parameters: baseParams };
1775
+ case "app_open":
1776
+ return null;
1777
+ case "cancellation":
1778
+ case "expiration":
1779
+ return null;
1780
+ case "onboarding_started":
1781
+ case "onboarding_step":
1782
+ case "paywall_dismissed":
1783
+ case "level_complete":
1784
+ case "tutorial_complete":
1785
+ return { name: event.name, kind: "custom", parameters: baseParams };
1786
+ default:
1787
+ return { name: event.name, kind: "custom", parameters: baseParams };
1788
+ }
1789
+ }
1790
+ function withEventId(parameters, eventId) {
1791
+ return { ...parameters, _eventID: eventId };
1792
+ }
1793
+
1794
+ // src/adapters/tiktokAdapter.ts
1795
+ var TikTokAdapter = class {
1796
+ constructor(options) {
1797
+ this.options = options;
1798
+ this.sdk = null;
1799
+ this.currentUserId = null;
1800
+ var _a;
1801
+ this.name = (_a = options.name) != null ? _a : "tiktok";
1802
+ }
1803
+ async initialize() {
1804
+ var _a;
1805
+ const sdk = this.loadSdk();
1806
+ await sdk.default.initialize(this.options.appId, this.options.tiktokAppId, {
1807
+ accessToken: this.options.accessToken,
1808
+ debugMode: (_a = this.options.debugMode) != null ? _a : false,
1809
+ autoTrackAppLifecycle: false,
1810
+ autoTrackRouteChanges: false
1811
+ });
1812
+ this.sdk = sdk.default;
1813
+ }
1814
+ setUser(identity) {
1815
+ var _a;
1816
+ this.currentUserId = (_a = identity == null ? void 0 : identity.userId) != null ? _a : null;
1817
+ }
1818
+ async deliver(event) {
1819
+ var _a;
1820
+ if (!this.sdk) {
1821
+ return { ok: false, code: "sdk_not_initialized", retriable: true };
1822
+ }
1823
+ const mapped = mapToTikTokEvent(event, this.currentUserId);
1824
+ if (!mapped) return { ok: true, code: "unmapped" };
1825
+ try {
1826
+ let ok;
1827
+ if (mapped.kind === "purchase" && mapped.value !== void 0 && mapped.currency) {
1828
+ ok = await this.sdk.trackCompletePurchase(
1829
+ mapped.value,
1830
+ mapped.currency,
1831
+ (_a = mapped.contents) != null ? _a : [],
1832
+ mapped.params
1833
+ );
1834
+ } else {
1835
+ ok = await this.sdk.trackEvent(mapped.name, mapped.params);
1836
+ }
1837
+ if (ok) return { ok: true };
1838
+ return { ok: false, code: "sdk_returned_false", retriable: true };
1839
+ } catch (err) {
1840
+ return {
1841
+ ok: false,
1842
+ code: "sdk_threw",
1843
+ message: err instanceof Error ? err.message : String(err),
1844
+ retriable: true
1845
+ };
1846
+ }
1847
+ }
1848
+ loadSdk() {
1849
+ if (this.options.sdkLoader) return this.options.sdkLoader();
1850
+ try {
1851
+ return require("@layers/expo-tiktok-business");
1852
+ } catch (err) {
1853
+ throw new Error(
1854
+ `@trackstall/sdk: failed to load \`@layers/expo-tiktok-business\`. Install it in the host app and run \`pod install\`. Underlying error: ${err instanceof Error ? err.message : String(err)}`
1855
+ );
1856
+ }
1857
+ }
1858
+ };
1859
+ function mapToTikTokEvent(event, userId) {
1860
+ var _a, _b, _c, _d, _e, _f;
1861
+ const baseParams = { event_id: event.eventId };
1862
+ if (userId) baseParams["external_id"] = userId;
1863
+ if (event.productId) baseParams["content_id"] = event.productId;
1864
+ if (event.properties) {
1865
+ for (const [k, v] of Object.entries(event.properties)) {
1866
+ if (v === null) continue;
1867
+ baseParams[k] = v;
1868
+ }
1869
+ }
1870
+ switch (event.name) {
1871
+ case "subscribe":
1872
+ if (!event.revenue) return null;
1873
+ return {
1874
+ name: "Subscribe",
1875
+ kind: "purchase",
1876
+ value: event.revenue.netValue,
1877
+ currency: event.revenue.currency,
1878
+ contents: contentsFromEvent(event),
1879
+ params: { ...baseParams, currency: event.revenue.currency, value: event.revenue.netValue, content_type: "product" }
1880
+ };
1881
+ case "purchase":
1882
+ case "renewal":
1883
+ if (!event.revenue) return null;
1884
+ return {
1885
+ name: "CompletePayment",
1886
+ kind: "purchase",
1887
+ value: event.revenue.netValue,
1888
+ currency: event.revenue.currency,
1889
+ contents: contentsFromEvent(event),
1890
+ params: { ...baseParams, currency: event.revenue.currency, value: event.revenue.netValue, content_type: "product" }
1891
+ };
1892
+ case "refund":
1893
+ if (!event.revenue) return null;
1894
+ return {
1895
+ name: "RefundOrder",
1896
+ kind: "custom",
1897
+ params: { ...baseParams, currency: event.revenue.currency, value: -Math.abs(event.revenue.netValue), content_type: "product" }
1898
+ };
1899
+ case "start_checkout":
1900
+ return {
1901
+ name: "InitiateCheckout",
1902
+ kind: "standard",
1903
+ params: { ...baseParams, currency: (_a = event.revenue) == null ? void 0 : _a.currency, value: (_b = event.revenue) == null ? void 0 : _b.netValue }
1904
+ };
1905
+ case "add_to_cart":
1906
+ return {
1907
+ name: "AddToCart",
1908
+ kind: "standard",
1909
+ params: { ...baseParams, currency: (_c = event.revenue) == null ? void 0 : _c.currency, value: (_d = event.revenue) == null ? void 0 : _d.netValue }
1910
+ };
1911
+ case "trial_started":
1912
+ return {
1913
+ name: "StartTrial",
1914
+ kind: "custom",
1915
+ params: { ...baseParams, currency: (_e = event.revenue) == null ? void 0 : _e.currency, value: (_f = event.revenue) == null ? void 0 : _f.netValue }
1916
+ };
1917
+ case "paywall_shown":
1918
+ case "content_view":
1919
+ return { name: "ViewContent", kind: "standard", params: { ...baseParams, content_type: "paywall" } };
1920
+ case "install":
1921
+ return { name: "AppInstall", kind: "standard", params: baseParams };
1922
+ case "app_open":
1923
+ return { name: "Launch", kind: "standard", params: baseParams };
1924
+ case "onboarding_completed":
1925
+ return { name: "CompleteRegistration", kind: "standard", params: baseParams };
1926
+ case "cancellation":
1927
+ case "expiration":
1928
+ return null;
1929
+ case "onboarding_started":
1930
+ case "onboarding_step":
1931
+ case "paywall_dismissed":
1932
+ case "level_complete":
1933
+ case "tutorial_complete":
1934
+ return { name: event.name, kind: "custom", params: baseParams };
1935
+ default:
1936
+ return { name: event.name, kind: "custom", params: baseParams };
1937
+ }
1938
+ }
1939
+ function contentsFromEvent(event) {
1940
+ var _a, _b;
1941
+ if (!event.revenue) return [];
1942
+ return [
1943
+ {
1944
+ content_id: (_b = (_a = event.productId) != null ? _a : event.revenue.transactionId) != null ? _b : "unknown",
1945
+ content_type: "product",
1946
+ quantity: 1,
1947
+ price: event.revenue.netValue
1948
+ }
1949
+ ];
1950
+ }
1951
+
1952
+ // src/eventQueue.ts
1953
+ var DEFAULT_CAPACITY = 500;
1954
+ var DEFAULT_STORAGE_KEY = "trackstall.queue.v1";
1955
+ var EventQueue = class {
1956
+ constructor(options) {
1957
+ this.entries = [];
1958
+ this.hydrated = false;
1959
+ this.counter = 0;
1960
+ this.chain = Promise.resolve();
1961
+ var _a, _b, _c;
1962
+ this.storage = options.storage;
1963
+ this.logger = options.logger;
1964
+ this.capacity = (_a = options.capacity) != null ? _a : DEFAULT_CAPACITY;
1965
+ this.storageKey = (_b = options.storageKey) != null ? _b : DEFAULT_STORAGE_KEY;
1966
+ this.now = (_c = options.now) != null ? _c : Date.now;
1967
+ }
1968
+ async hydrate() {
1969
+ if (this.hydrated) return;
1970
+ try {
1971
+ const raw = await this.storage.getItem(this.storageKey);
1972
+ if (raw) {
1973
+ const parsed = JSON.parse(raw);
1974
+ if (Array.isArray(parsed)) this.entries = parsed;
1975
+ }
1976
+ } catch (err) {
1977
+ this.logger.warn("trackstall: failed to hydrate queue \u2014 starting empty", {
1978
+ message: err instanceof Error ? err.message : String(err)
1979
+ });
1980
+ this.entries = [];
1981
+ }
1982
+ this.hydrated = true;
1983
+ }
1984
+ size() {
1985
+ return this.entries.length;
1986
+ }
1987
+ async enqueue(eventId, body) {
1988
+ return this.serialize(async () => {
1989
+ this.counter += 1;
1990
+ const entry = {
1991
+ id: `q-${this.now()}-${this.counter}`,
1992
+ eventId,
1993
+ body,
1994
+ attempts: 0,
1995
+ nextRetryAt: 0,
1996
+ createdAt: this.now()
1997
+ };
1998
+ this.entries.push(entry);
1999
+ if (this.entries.length > this.capacity) {
2000
+ const dropped = this.entries.length - this.capacity;
2001
+ this.entries.splice(0, dropped);
2002
+ this.logger.warn("trackstall: queue at capacity \u2014 dropped oldest", { dropped });
2003
+ }
2004
+ await this.persist();
2005
+ });
2006
+ }
2007
+ /** Snapshot of entries eligible to send now (does not mutate). */
2008
+ pullReady(limit) {
2009
+ const nowMs = this.now();
2010
+ return this.entries.filter((e) => e.nextRetryAt <= nowMs).slice(0, limit);
2011
+ }
2012
+ async markDelivered(ids) {
2013
+ if (ids.length === 0) return;
2014
+ return this.serialize(async () => {
2015
+ const set = new Set(ids);
2016
+ this.entries = this.entries.filter((e) => !set.has(e.id));
2017
+ await this.persist();
2018
+ });
2019
+ }
2020
+ async markFailed(ids, nextRetryAt) {
2021
+ if (ids.length === 0) return;
2022
+ return this.serialize(async () => {
2023
+ const set = new Set(ids);
2024
+ for (const e of this.entries) {
2025
+ if (set.has(e.id)) {
2026
+ e.attempts += 1;
2027
+ e.nextRetryAt = nextRetryAt;
2028
+ }
2029
+ }
2030
+ await this.persist();
2031
+ });
2032
+ }
2033
+ async clear() {
2034
+ return this.serialize(async () => {
2035
+ this.entries = [];
2036
+ await this.persist();
2037
+ });
2038
+ }
2039
+ async persist() {
2040
+ try {
2041
+ await this.storage.setItem(this.storageKey, JSON.stringify(this.entries));
2042
+ } catch (err) {
2043
+ this.logger.warn("trackstall: failed to persist queue", {
2044
+ message: err instanceof Error ? err.message : String(err)
2045
+ });
2046
+ }
2047
+ }
2048
+ serialize(fn) {
2049
+ const next = this.chain.then(fn, fn);
2050
+ this.chain = next.catch(() => void 0);
2051
+ return next;
2052
+ }
2053
+ };
2054
+
2055
+ // src/retryPolicy.ts
2056
+ var DEFAULT_RETRY = {
2057
+ maxAttempts: 6,
2058
+ initialDelayMs: 1e3,
2059
+ maxDelayMs: 5 * 60 * 1e3,
2060
+ jitter: 0.2
2061
+ };
2062
+ function resolveRetryConfig(input) {
2063
+ var _a, _b, _c, _d;
2064
+ return {
2065
+ maxAttempts: (_a = input == null ? void 0 : input.maxAttempts) != null ? _a : DEFAULT_RETRY.maxAttempts,
2066
+ initialDelayMs: (_b = input == null ? void 0 : input.initialDelayMs) != null ? _b : DEFAULT_RETRY.initialDelayMs,
2067
+ maxDelayMs: (_c = input == null ? void 0 : input.maxDelayMs) != null ? _c : DEFAULT_RETRY.maxDelayMs,
2068
+ jitter: (_d = input == null ? void 0 : input.jitter) != null ? _d : DEFAULT_RETRY.jitter
2069
+ };
2070
+ }
2071
+ function computeRetryDelayMs(attempt, config, random = Math.random) {
2072
+ if (attempt <= 0) return 0;
2073
+ const safeAttempt = Math.min(attempt, 30);
2074
+ const base = config.initialDelayMs * Math.pow(2, safeAttempt - 1);
2075
+ const capped = Math.min(base, config.maxDelayMs);
2076
+ const jitterFactor = 1 + (random() * 2 - 1) * config.jitter;
2077
+ return Math.max(0, Math.round(capped * jitterFactor));
2078
+ }
2079
+ function shouldRetry(attemptsSoFar, retriable, config) {
2080
+ if (retriable === false) return false;
2081
+ return attemptsSoFar < config.maxAttempts;
2082
+ }
2083
+
2084
+ // src/storage/memoryStorage.ts
2085
+ var MemoryStorage = class {
2086
+ constructor() {
2087
+ this.map = /* @__PURE__ */ new Map();
2088
+ }
2089
+ async getItem(key) {
2090
+ return this.map.has(key) ? this.map.get(key) : null;
2091
+ }
2092
+ async setItem(key, value) {
2093
+ this.map.set(key, value);
2094
+ }
2095
+ async removeItem(key) {
2096
+ this.map.delete(key);
2097
+ }
2098
+ };
2099
+ function defaultStorage() {
2100
+ const ls = globalThis.localStorage;
2101
+ if (!ls) return new MemoryStorage();
2102
+ return {
2103
+ async getItem(key) {
2104
+ return ls.getItem(key);
2105
+ },
2106
+ async setItem(key, value) {
2107
+ ls.setItem(key, value);
2108
+ },
2109
+ async removeItem(key) {
2110
+ ls.removeItem(key);
2111
+ }
2112
+ };
2113
+ }
2114
+
2115
+ // src/transport.ts
2116
+ var Transport = class {
2117
+ constructor(options) {
2118
+ var _a, _b;
2119
+ this.endpoint = options.endpoint.replace(/\/+$/, "");
2120
+ this.publicKey = options.publicKey;
2121
+ const f2 = (_a = options.fetchImpl) != null ? _a : globalThis.fetch;
2122
+ if (typeof f2 !== "function") {
2123
+ throw new Error("TrackStall: global fetch unavailable \u2014 pass `fetchImpl` in the config.");
2124
+ }
2125
+ this.fetchImpl = f2;
2126
+ this.timeoutMs = (_b = options.timeoutMs) != null ? _b : 8e3;
2127
+ }
2128
+ async get(path) {
2129
+ return this.send("GET", path, void 0);
2130
+ }
2131
+ async post(path, body) {
2132
+ return this.send("POST", path, body);
2133
+ }
2134
+ async send(httpMethod, path, body) {
2135
+ var _a;
2136
+ const url = `${this.endpoint}${path.startsWith("/") ? path : `/${path}`}`;
2137
+ const controller = new AbortController();
2138
+ const timer = setTimeout(() => controller.abort(), this.timeoutMs);
2139
+ let res;
2140
+ try {
2141
+ res = await this.fetchImpl(url, {
2142
+ method: httpMethod,
2143
+ headers: {
2144
+ "content-type": "application/json",
2145
+ authorization: `Bearer ${this.publicKey}`
2146
+ },
2147
+ body: httpMethod === "GET" ? void 0 : JSON.stringify(body != null ? body : {}),
2148
+ signal: controller.signal
2149
+ });
2150
+ } catch (err) {
2151
+ clearTimeout(timer);
2152
+ const isAbort = (err == null ? void 0 : err.name) === "AbortError";
2153
+ return {
2154
+ ok: false,
2155
+ status: 0,
2156
+ body: null,
2157
+ retriable: true,
2158
+ errorMessage: isAbort ? `request timed out after ${this.timeoutMs}ms` : `network error: ${(_a = err == null ? void 0 : err.message) != null ? _a : String(err)}`
2159
+ };
2160
+ } finally {
2161
+ clearTimeout(timer);
2162
+ }
2163
+ const parsed = await safeJson(res);
2164
+ if (res.ok) return { ok: true, status: res.status, body: parsed, retriable: false };
2165
+ return {
2166
+ ok: false,
2167
+ status: res.status,
2168
+ body: parsed,
2169
+ retriable: isRetriableStatus(res.status),
2170
+ errorMessage: `HTTP ${res.status}`
2171
+ };
2172
+ }
2173
+ };
2174
+ function isRetriableStatus(status) {
2175
+ if (status >= 500) return true;
2176
+ if (status === 408 || status === 429) return true;
2177
+ return false;
2178
+ }
2179
+ async function safeJson(res) {
2180
+ try {
2181
+ const text = await res.text();
2182
+ return text ? JSON.parse(text) : null;
2183
+ } catch {
2184
+ return null;
2185
+ }
2186
+ }
2187
+
2188
+ // src/client.ts
2189
+ function createTrackStallClient(config) {
2190
+ return new TrackStallClientImpl(config);
2191
+ }
2192
+ var EMPTY_FLUSH = { attempted: 0, delivered: 0, retryScheduled: 0, dropped: 0 };
2193
+ var ANONYMOUS_ID_STORAGE_KEY = "trackstall.anonymousId.v1";
2194
+ var ATT_REPORTED_STORAGE_KEY = "trackstall.att.reported.v1";
2195
+ var TrackStallClientImpl = class {
2196
+ constructor(config) {
2197
+ this.config = config;
2198
+ this.anonymousId = null;
2199
+ /** Latest ATT status seen at runtime — overrides `device.attStatus`. */
2200
+ this.attStatus = null;
2201
+ this.user = null;
2202
+ this.initialized = false;
2203
+ this.initializePromise = null;
2204
+ this.flushChain = Promise.resolve();
2205
+ /** In-app ad SDKs (Meta/TikTok) wired from remote config; dual-send lane. */
2206
+ this.nativeAdapters = [];
2207
+ var _a, _b, _c, _d, _e;
2208
+ if (!config.appId) throw new Error("TrackStall: `appId` is required");
2209
+ if (!config.publicKey) throw new Error("TrackStall: `publicKey` is required");
2210
+ if (!config.endpoint) throw new Error("TrackStall: `endpoint` is required");
2211
+ this.logger = (_a = config.logger) != null ? _a : defaultLogger;
2212
+ this.enabled = config.enabled !== false;
2213
+ this.platform = (_b = config.platform) != null ? _b : "ios";
2214
+ this.batchSize = Math.max(1, (_c = config.batchSize) != null ? _c : 20);
2215
+ this.now = (_d = config.now) != null ? _d : Date.now;
2216
+ this.retry = resolveRetryConfig(config.retry);
2217
+ this.device = { ...config.device };
2218
+ this.transport = new Transport({
2219
+ endpoint: config.endpoint,
2220
+ publicKey: config.publicKey,
2221
+ fetchImpl: config.fetchImpl,
2222
+ timeoutMs: config.requestTimeoutMs
2223
+ });
2224
+ this.storage = (_e = config.storage) != null ? _e : defaultStorage();
2225
+ this.queue = new EventQueue({
2226
+ storage: this.storage,
2227
+ logger: this.logger,
2228
+ capacity: config.bufferCapacity,
2229
+ now: this.now
2230
+ });
2231
+ this.analyticsQueue = new EventQueue({
2232
+ storage: this.storage,
2233
+ logger: this.logger,
2234
+ capacity: config.bufferCapacity,
2235
+ storageKey: "trackstall.analytics.queue.v1",
2236
+ now: this.now
2237
+ });
2238
+ }
2239
+ async initialize() {
2240
+ if (this.initialized) return;
2241
+ if (this.initializePromise) return this.initializePromise;
2242
+ this.initializePromise = (async () => {
2243
+ await Promise.all([this.queue.hydrate(), this.analyticsQueue.hydrate()]);
2244
+ this.resolveDeviceContext();
2245
+ await this.resolveIosIdfv();
2246
+ await this.loadAnonymousId();
2247
+ await this.wireNativeAdapters();
2248
+ this.initialized = true;
2249
+ this.logger.info("trackstall: initialized", {
2250
+ appId: this.config.appId,
2251
+ queueSize: this.queue.size(),
2252
+ nativeAdapters: this.nativeAdapters.map((a) => a.name)
2253
+ });
2254
+ void this.flushSafe();
2255
+ })();
2256
+ return this.initializePromise;
2257
+ }
2258
+ setUser(identity) {
2259
+ this.user = identity;
2260
+ for (const adapter of this.nativeAdapters) {
2261
+ try {
2262
+ adapter.setUser(identity);
2263
+ } catch (err) {
2264
+ this.logger.warn("trackstall: native setUser failed", { adapter: adapter.name });
2265
+ void err;
2266
+ }
2267
+ }
2268
+ }
2269
+ async recordClick(input) {
2270
+ var _a;
2271
+ const res = await this.transport.post("/v1/click", { ...this.deviceClickFields(), ...input });
2272
+ if (!res.ok) {
2273
+ throw new Error(`trackstall: recordClick failed (${res.status}) ${(_a = res.errorMessage) != null ? _a : ""}`.trim());
2274
+ }
2275
+ return res.body;
2276
+ }
2277
+ async matchInstall(input = {}) {
2278
+ var _a, _b, _c;
2279
+ const userId = (_b = input.userId) != null ? _b : (_a = this.user) == null ? void 0 : _a.userId;
2280
+ if (!userId) throw new Error("trackstall: matchInstall requires a userId (set a user first)");
2281
+ const res = await this.transport.post("/v1/match", {
2282
+ ...this.deviceClickFields(),
2283
+ ...input,
2284
+ userId
2285
+ });
2286
+ if (!res.ok) {
2287
+ throw new Error(`trackstall: matchInstall failed (${res.status}) ${(_c = res.errorMessage) != null ? _c : ""}`.trim());
2288
+ }
2289
+ return res.body;
2290
+ }
2291
+ async reportInstallReferrer(input) {
2292
+ var _a, _b, _c;
2293
+ if (!this.initialized) await this.initialize();
2294
+ const userId = (_b = input.userId) != null ? _b : (_a = this.user) == null ? void 0 : _a.userId;
2295
+ if (!userId) {
2296
+ throw new Error("trackstall: reportInstallReferrer requires a userId (set a user first)");
2297
+ }
2298
+ const res = await this.transport.post("/v1/referrer", {
2299
+ ...this.deviceClickFields(),
2300
+ ...input,
2301
+ userId
2302
+ });
2303
+ if (!res.ok) {
2304
+ throw new Error(
2305
+ `trackstall: reportInstallReferrer failed (${res.status}) ${(_c = res.errorMessage) != null ? _c : ""}`.trim()
2306
+ );
2307
+ }
2308
+ return res.body;
2309
+ }
2310
+ async track(input) {
2311
+ var _a, _b, _c, _d;
2312
+ const identity = (_a = input.user) != null ? _a : this.user;
2313
+ const timestampMs = (_b = input.timestampMs) != null ? _b : this.now();
2314
+ const timestamp = Math.floor(timestampMs / 1e3);
2315
+ const eventId = (_d = input.eventId) != null ? _d : (identity == null ? void 0 : identity.userId) ? (0, import_core2.deterministicEventId)({
2316
+ appId: this.config.appId,
2317
+ userId: identity.userId,
2318
+ eventName: input.name,
2319
+ transactionId: (_c = input.revenue) == null ? void 0 : _c.transactionId,
2320
+ timestamp
2321
+ }) : (0, import_core2.randomEventId)();
2322
+ if (!this.enabled) return eventId;
2323
+ if (!this.initialized) await this.initialize();
2324
+ const canonical = this.buildCanonicalEvent(input, identity, eventId, timestamp);
2325
+ if (this.nativeAdapters.length > 0) void this.deliverNative(canonical);
2326
+ await this.queue.enqueue(eventId, canonical);
2327
+ void this.flushSafe();
2328
+ return eventId;
2329
+ }
2330
+ async logEvent(name, properties, options = {}) {
2331
+ var _a, _b, _c, _d;
2332
+ const eventId = (_a = options.eventId) != null ? _a : (0, import_core2.randomEventId)();
2333
+ if (!this.enabled) return eventId;
2334
+ if (!this.initialized) await this.initialize();
2335
+ const timestampMs = (_b = options.timestampMs) != null ? _b : this.now();
2336
+ const device = this.device;
2337
+ const body = pruneUndefined2({
2338
+ eventId,
2339
+ name,
2340
+ timestamp: Math.floor(timestampMs / 1e3),
2341
+ platform: this.platform,
2342
+ userId: (_c = this.user) == null ? void 0 : _c.userId,
2343
+ anonymousId: (_d = this.anonymousId) != null ? _d : void 0,
2344
+ sessionId: options.sessionId,
2345
+ properties: properties && Object.keys(properties).length > 0 ? properties : void 0,
2346
+ context: pruneUndefined2({
2347
+ appVersion: device.appVersion,
2348
+ locale: device.locale,
2349
+ country: device.country,
2350
+ sdk: "trackstall-sdk"
2351
+ })
2352
+ });
2353
+ await this.analyticsQueue.enqueue(eventId, body);
2354
+ void this.flushSafe();
2355
+ return eventId;
2356
+ }
2357
+ async requestAttPermission() {
2358
+ var _a, _b, _c;
2359
+ if (this.platform !== "ios") return "unavailable";
2360
+ if (!this.enabled) return (_b = (_a = this.attStatus) != null ? _a : this.device.attStatus) != null ? _b : "unavailable";
2361
+ if (!this.initialized) await this.initialize();
2362
+ const mod = loadAttModule((_c = this.config.native) == null ? void 0 : _c.att);
2363
+ if (!mod) {
2364
+ this.logger.warn(
2365
+ "trackstall: no tracking-transparency module found \u2014 install `expo-tracking-transparency` or `react-native-tracking-transparency`, or inject `native.att`"
2366
+ );
2367
+ return "unavailable";
2368
+ }
2369
+ let status;
2370
+ try {
2371
+ const current = await getAttStatus(mod);
2372
+ status = current === "undetermined" ? await requestAttStatus(mod) : current;
2373
+ } catch (err) {
2374
+ this.logger.error("trackstall: ATT request failed", err);
2375
+ return "unavailable";
2376
+ }
2377
+ await this.applyAttStatus(status);
2378
+ return status;
2379
+ }
2380
+ async setAttStatus(status) {
2381
+ if (!this.enabled) return;
2382
+ if (!this.initialized) await this.initialize();
2383
+ await this.applyAttStatus(status);
2384
+ }
2385
+ async flush() {
2386
+ var _a;
2387
+ if (!this.enabled) return { ...EMPTY_FLUSH };
2388
+ for (const adapter of this.nativeAdapters) {
2389
+ try {
2390
+ await ((_a = adapter.flush) == null ? void 0 : _a.call(adapter));
2391
+ } catch (err) {
2392
+ this.logger.warn("trackstall: native flush failed", { adapter: adapter.name });
2393
+ void err;
2394
+ }
2395
+ }
2396
+ return this.scheduleFlush();
2397
+ }
2398
+ getDiagnostics() {
2399
+ var _a, _b;
2400
+ return {
2401
+ initialized: this.initialized,
2402
+ enabled: this.enabled,
2403
+ appId: this.config.appId,
2404
+ userId: (_b = (_a = this.user) == null ? void 0 : _a.userId) != null ? _b : null,
2405
+ anonymousId: this.anonymousId,
2406
+ queueSize: this.queue.size(),
2407
+ analyticsQueueSize: this.analyticsQueue.size()
2408
+ };
2409
+ }
2410
+ // ── Internals ──────────────────────────────────────────────────────────────
2411
+ buildCanonicalEvent(input, identity, eventId, timestamp) {
2412
+ var _a, _b, _c, _d;
2413
+ const device = this.device;
2414
+ const user = pruneUndefined2({
2415
+ userId: identity == null ? void 0 : identity.userId,
2416
+ email: identity == null ? void 0 : identity.email,
2417
+ phone: identity == null ? void 0 : identity.phone,
2418
+ country: (_a = identity == null ? void 0 : identity.country) != null ? _a : device.country,
2419
+ locale: (_b = identity == null ? void 0 : identity.locale) != null ? _b : device.locale,
2420
+ idfa: device.idfa,
2421
+ idfv: device.idfv,
2422
+ gaid: device.gaid,
2423
+ attStatus: (_c = this.attStatus) != null ? _c : device.attStatus
2424
+ });
2425
+ const properties = { ...(_d = input.properties) != null ? _d : {} };
2426
+ if (input.sandbox) properties.environment = "sandbox";
2427
+ return {
2428
+ appId: this.config.appId,
2429
+ eventId,
2430
+ name: input.name,
2431
+ platform: this.platform,
2432
+ timestamp,
2433
+ user,
2434
+ revenue: input.revenue,
2435
+ productId: input.productId,
2436
+ properties: Object.keys(properties).length > 0 ? properties : void 0
2437
+ };
2438
+ }
2439
+ /**
2440
+ * Resolve client-safe config (from `/v1/config` or the injected override) and
2441
+ * boot the matching native adapters. Every step is best-effort: a missing
2442
+ * config, a failed fetch, or a native SDK that won't initialize just disables
2443
+ * the native lane — the backend lane (CAPI/EAPI) keeps working.
2444
+ */
2445
+ async wireNativeAdapters() {
2446
+ var _a, _b;
2447
+ if (this.config.disableNativeDualSend) return;
2448
+ let cfg = this.config.remoteConfig;
2449
+ if (!cfg) {
2450
+ const res = await this.transport.get("/v1/config");
2451
+ if (!res.ok) {
2452
+ this.logger.warn("trackstall: /v1/config fetch failed \u2014 native dual-send disabled", {
2453
+ status: res.status
2454
+ });
2455
+ return;
2456
+ }
2457
+ cfg = res.body;
2458
+ }
2459
+ const pending = [];
2460
+ if (cfg.meta) {
2461
+ const injected = (_a = this.config.native) == null ? void 0 : _a.meta;
2462
+ pending.push(
2463
+ new MetaAdapter({
2464
+ appId: cfg.meta.appId,
2465
+ clientToken: cfg.meta.clientToken,
2466
+ sdkLoader: injected ? () => injected : void 0
2467
+ })
2468
+ );
2469
+ }
2470
+ if (cfg.tiktok) {
2471
+ const injected = (_b = this.config.native) == null ? void 0 : _b.tiktok;
2472
+ pending.push(
2473
+ new TikTokAdapter({
2474
+ appId: cfg.tiktok.appId,
2475
+ tiktokAppId: cfg.tiktok.ttAppId,
2476
+ accessToken: cfg.tiktok.accessToken,
2477
+ debugMode: cfg.sandbox,
2478
+ sdkLoader: injected ? () => injected : void 0
2479
+ })
2480
+ );
2481
+ }
2482
+ for (const adapter of pending) {
2483
+ try {
2484
+ await adapter.initialize();
2485
+ if (this.user) adapter.setUser(this.user);
2486
+ this.nativeAdapters.push(adapter);
2487
+ this.logger.info("trackstall: native adapter ready", { adapter: adapter.name });
2488
+ } catch (err) {
2489
+ this.logger.error("trackstall: native adapter init failed \u2014 skipping", err, {
2490
+ adapter: adapter.name
2491
+ });
2492
+ }
2493
+ }
2494
+ }
2495
+ async deliverNative(event) {
2496
+ const results = await Promise.allSettled(
2497
+ this.nativeAdapters.map((adapter) => adapter.deliver(event))
2498
+ );
2499
+ results.forEach((r, i) => {
2500
+ const adapter = this.nativeAdapters[i];
2501
+ if (r.status === "rejected") {
2502
+ this.logger.warn("trackstall: native deliver threw", { adapter: adapter == null ? void 0 : adapter.name });
2503
+ } else if (!r.value.ok) {
2504
+ this.logger.debug("trackstall: native deliver failed", {
2505
+ adapter: adapter == null ? void 0 : adapter.name,
2506
+ code: r.value.code
2507
+ });
2508
+ }
2509
+ });
2510
+ }
2511
+ /**
2512
+ * Device signals shared by `recordClick` / `matchInstall`. Beyond
2513
+ * locale/timezone/country, this carries the screen+OS fingerprint that the
2514
+ * server uses to build `deviceFp` — without it probabilistic matching falls
2515
+ * back to the weak IP-only tier and most installs go unattributed.
2516
+ */
2517
+ /**
2518
+ * Merge best-effort auto-collected device signals into the resolved device
2519
+ * context WITHOUT overriding anything the host already supplied. Runs once on
2520
+ * `initialize()`. Disable with `config.disableAutoDeviceContext`.
2521
+ */
2522
+ resolveDeviceContext() {
2523
+ var _a, _b;
2524
+ if (this.config.disableAutoDeviceContext) return;
2525
+ let collected;
2526
+ try {
2527
+ collected = collectDeviceContext();
2528
+ } catch (err) {
2529
+ this.logger.warn("trackstall: device auto-collection failed", {
2530
+ message: err instanceof Error ? err.message : String(err)
2531
+ });
2532
+ return;
2533
+ }
2534
+ for (const [key, value] of Object.entries(collected)) {
2535
+ if (value === void 0) continue;
2536
+ if (this.device[key] === void 0) {
2537
+ this.device[key] = value;
2538
+ }
2539
+ }
2540
+ this.logger.debug("trackstall: device context resolved", {
2541
+ screen: this.device.screenW && this.device.screenH ? `${this.device.screenW}x${this.device.screenH}` : null,
2542
+ osVersion: (_a = this.device.osVersion) != null ? _a : null,
2543
+ deviceModel: (_b = this.device.deviceModel) != null ? _b : null
2544
+ });
2545
+ }
2546
+ /**
2547
+ * iOS IDFV — no ATT consent required, so it's auto-collected for every iOS
2548
+ * install (host-supplied `config.device.idfv` always wins). Async because
2549
+ * `expo-application` only exposes the promise API.
2550
+ */
2551
+ async resolveIosIdfv() {
2552
+ if (this.platform !== "ios") return;
2553
+ if (this.config.disableAutoDeviceContext) return;
2554
+ if (this.device.idfv) return;
2555
+ try {
2556
+ const idfv = await collectIosIdForVendor();
2557
+ if (idfv) this.device.idfv = idfv;
2558
+ } catch (err) {
2559
+ this.logger.warn("trackstall: idfv collection failed", {
2560
+ message: err instanceof Error ? err.message : String(err)
2561
+ });
2562
+ }
2563
+ }
2564
+ deviceClickFields() {
2565
+ const d = this.device;
2566
+ return pruneUndefined2({
2567
+ locale: d.locale,
2568
+ timezone: d.timezone,
2569
+ country: d.country,
2570
+ screenW: d.screenW,
2571
+ screenH: d.screenH,
2572
+ pixelRatio: d.pixelRatio,
2573
+ osVersion: d.osVersion,
2574
+ deviceModel: d.deviceModel
2575
+ });
2576
+ }
2577
+ flushSafe() {
2578
+ return this.scheduleFlush().then(() => void 0).catch((err) => {
2579
+ this.logger.error("trackstall: flush failed (recoverable)", err);
2580
+ });
2581
+ }
2582
+ scheduleFlush() {
2583
+ const next = this.flushChain.then(
2584
+ () => this.flushOnce(),
2585
+ () => this.flushOnce()
2586
+ );
2587
+ this.flushChain = next.catch(() => void 0);
2588
+ return next;
2589
+ }
2590
+ /**
2591
+ * Remember the status locally (stamps future attribution events) and report
2592
+ * it to `POST /v1/att` — once per `(identity, status)` so retries/app opens
2593
+ * don't spam the backend.
2594
+ */
2595
+ async applyAttStatus(status) {
2596
+ var _a, _b, _c, _d, _e;
2597
+ this.attStatus = status;
2598
+ if (status === "authorized" && !this.device.idfa) {
2599
+ const mod = loadAttModule((_a = this.config.native) == null ? void 0 : _a.att);
2600
+ const idfa = mod ? readAdvertisingId(mod) : void 0;
2601
+ if (idfa) this.device.idfa = idfa;
2602
+ }
2603
+ const distinctId = (_c = (_b = this.user) == null ? void 0 : _b.userId) != null ? _c : this.anonymousId;
2604
+ if (!distinctId) return;
2605
+ const fingerprint = `${distinctId}:${status}`;
2606
+ try {
2607
+ if (await this.storage.getItem(ATT_REPORTED_STORAGE_KEY) === fingerprint) return;
2608
+ } catch {
2609
+ }
2610
+ const res = await this.transport.post("/v1/att", {
2611
+ status,
2612
+ userId: (_d = this.user) == null ? void 0 : _d.userId,
2613
+ anonymousId: (_e = this.anonymousId) != null ? _e : void 0,
2614
+ platform: this.platform
2615
+ });
2616
+ if (!res.ok) {
2617
+ this.logger.warn("trackstall: ATT report failed \u2014 will retry on next change", {
2618
+ status: res.status
2619
+ });
2620
+ return;
2621
+ }
2622
+ try {
2623
+ await this.storage.setItem(ATT_REPORTED_STORAGE_KEY, fingerprint);
2624
+ } catch {
2625
+ }
2626
+ }
2627
+ /** Load (or mint + persist) the device-scoped anonymous id. */
2628
+ async loadAnonymousId() {
2629
+ try {
2630
+ const existing = await this.storage.getItem(ANONYMOUS_ID_STORAGE_KEY);
2631
+ if (existing) {
2632
+ this.anonymousId = existing;
2633
+ return;
2634
+ }
2635
+ } catch (err) {
2636
+ this.logger.warn("trackstall: failed to read anonymousId \u2014 minting a fresh one", {
2637
+ message: err instanceof Error ? err.message : String(err)
2638
+ });
2639
+ }
2640
+ this.anonymousId = `anon-${(0, import_core2.randomEventId)()}`;
2641
+ try {
2642
+ await this.storage.setItem(ANONYMOUS_ID_STORAGE_KEY, this.anonymousId);
2643
+ } catch {
2644
+ }
2645
+ }
2646
+ async flushOnce() {
2647
+ const result = { ...EMPTY_FLUSH };
2648
+ for (let guard = 0; guard < 50; guard++) {
2649
+ const ready = this.queue.pullReady(this.batchSize);
2650
+ if (ready.length === 0) break;
2651
+ result.attempted += ready.length;
2652
+ await this.deliverBatch(this.queue, "/v1/events", ready, result);
2653
+ }
2654
+ for (let guard = 0; guard < 50; guard++) {
2655
+ const ready = this.analyticsQueue.pullReady(this.batchSize);
2656
+ if (ready.length === 0) break;
2657
+ result.attempted += ready.length;
2658
+ await this.deliverBatch(this.analyticsQueue, "/v1/track", ready, result);
2659
+ }
2660
+ return result;
2661
+ }
2662
+ async deliverBatch(queue, path, batch, result) {
2663
+ const ids = batch.map((e) => e.id);
2664
+ const res = await this.transport.post(path, { events: batch.map((e) => e.body) });
2665
+ if (res.ok) {
2666
+ const rejected = extractRejectedEventIds(res.body);
2667
+ const terminalIds = batch.map((e) => e.id);
2668
+ await queue.markDelivered(terminalIds);
2669
+ result.delivered += batch.length - rejected.size;
2670
+ result.dropped += countRejected(batch, rejected);
2671
+ return;
2672
+ }
2673
+ if (!res.retriable) {
2674
+ this.logger.error("trackstall: batch rejected (non-retriable) \u2014 dropping", void 0, {
2675
+ status: res.status,
2676
+ path,
2677
+ count: batch.length
2678
+ });
2679
+ await queue.markDelivered(ids);
2680
+ result.dropped += batch.length;
2681
+ return;
2682
+ }
2683
+ const maxAttempts = Math.max(...batch.map((e) => e.attempts)) + 1;
2684
+ if (!shouldRetry(maxAttempts, true, this.retry)) {
2685
+ this.logger.error("trackstall: batch exhausted retries \u2014 dropping", void 0, {
2686
+ status: res.status,
2687
+ path,
2688
+ count: batch.length
2689
+ });
2690
+ await queue.markDelivered(ids);
2691
+ result.dropped += batch.length;
2692
+ return;
2693
+ }
2694
+ const delay = computeRetryDelayMs(maxAttempts, this.retry);
2695
+ await queue.markFailed(ids, this.now() + delay);
2696
+ result.retryScheduled += batch.length;
2697
+ this.logger.warn("trackstall: batch delivery failed \u2014 scheduled retry", {
2698
+ status: res.status,
2699
+ path,
2700
+ count: batch.length,
2701
+ delayMs: delay
2702
+ });
2703
+ }
2704
+ };
2705
+ function extractRejectedEventIds(body) {
2706
+ const out = /* @__PURE__ */ new Set();
2707
+ const results = body == null ? void 0 : body.results;
2708
+ if (Array.isArray(results)) {
2709
+ for (const r of results) {
2710
+ if (r.status === "rejected" && r.eventId) out.add(r.eventId);
2711
+ }
2712
+ }
2713
+ return out;
2714
+ }
2715
+ function countRejected(batch, rejectedEventIds) {
2716
+ let n = 0;
2717
+ for (const e of batch) if (rejectedEventIds.has(e.eventId)) n += 1;
2718
+ return n;
2719
+ }
2720
+ function pruneUndefined2(obj) {
2721
+ for (const k of Object.keys(obj)) {
2722
+ if (obj[k] === void 0) delete obj[k];
2723
+ }
2724
+ return obj;
2725
+ }
2726
+ var defaultLogger = {
2727
+ debug: (m, c) => console.debug(`[trackstall] ${m}`, c != null ? c : ""),
2728
+ info: (m, c) => console.log(`[trackstall] ${m}`, c != null ? c : ""),
2729
+ warn: (m, c) => console.warn(`[trackstall] ${m}`, c != null ? c : ""),
2730
+ error: (m, e, c) => console.error(`[trackstall] ${m}`, e != null ? e : "", c != null ? c : "")
2731
+ };
2732
+
2733
+ // src/index.ts
2734
+ var import_core3 = __toESM(require_dist());