autotel-subscribers 4.0.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 (87) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +669 -0
  3. package/dist/amplitude.cjs +2486 -0
  4. package/dist/amplitude.cjs.map +1 -0
  5. package/dist/amplitude.d.cts +49 -0
  6. package/dist/amplitude.d.ts +49 -0
  7. package/dist/amplitude.js +2463 -0
  8. package/dist/amplitude.js.map +1 -0
  9. package/dist/event-subscriber-base-CnF3V56W.d.cts +182 -0
  10. package/dist/event-subscriber-base-CnF3V56W.d.ts +182 -0
  11. package/dist/factories.cjs +16660 -0
  12. package/dist/factories.cjs.map +1 -0
  13. package/dist/factories.d.cts +304 -0
  14. package/dist/factories.d.ts +304 -0
  15. package/dist/factories.js +16624 -0
  16. package/dist/factories.js.map +1 -0
  17. package/dist/index.cjs +16575 -0
  18. package/dist/index.cjs.map +1 -0
  19. package/dist/index.d.cts +179 -0
  20. package/dist/index.d.ts +179 -0
  21. package/dist/index.js +16539 -0
  22. package/dist/index.js.map +1 -0
  23. package/dist/middleware.cjs +220 -0
  24. package/dist/middleware.cjs.map +1 -0
  25. package/dist/middleware.d.cts +227 -0
  26. package/dist/middleware.d.ts +227 -0
  27. package/dist/middleware.js +208 -0
  28. package/dist/middleware.js.map +1 -0
  29. package/dist/mixpanel.cjs +2940 -0
  30. package/dist/mixpanel.cjs.map +1 -0
  31. package/dist/mixpanel.d.cts +47 -0
  32. package/dist/mixpanel.d.ts +47 -0
  33. package/dist/mixpanel.js +2932 -0
  34. package/dist/mixpanel.js.map +1 -0
  35. package/dist/posthog.cjs +4115 -0
  36. package/dist/posthog.cjs.map +1 -0
  37. package/dist/posthog.d.cts +299 -0
  38. package/dist/posthog.d.ts +299 -0
  39. package/dist/posthog.js +4113 -0
  40. package/dist/posthog.js.map +1 -0
  41. package/dist/segment.cjs +6822 -0
  42. package/dist/segment.cjs.map +1 -0
  43. package/dist/segment.d.cts +49 -0
  44. package/dist/segment.d.ts +49 -0
  45. package/dist/segment.js +6794 -0
  46. package/dist/segment.js.map +1 -0
  47. package/dist/slack.cjs +368 -0
  48. package/dist/slack.cjs.map +1 -0
  49. package/dist/slack.d.cts +126 -0
  50. package/dist/slack.d.ts +126 -0
  51. package/dist/slack.js +366 -0
  52. package/dist/slack.js.map +1 -0
  53. package/dist/webhook.cjs +100 -0
  54. package/dist/webhook.cjs.map +1 -0
  55. package/dist/webhook.d.cts +53 -0
  56. package/dist/webhook.d.ts +53 -0
  57. package/dist/webhook.js +98 -0
  58. package/dist/webhook.js.map +1 -0
  59. package/examples/quickstart-custom-subscriber.ts +144 -0
  60. package/examples/subscriber-bigquery.ts +219 -0
  61. package/examples/subscriber-databricks.ts +280 -0
  62. package/examples/subscriber-kafka.ts +326 -0
  63. package/examples/subscriber-kinesis.ts +307 -0
  64. package/examples/subscriber-posthog.ts +421 -0
  65. package/examples/subscriber-pubsub.ts +336 -0
  66. package/examples/subscriber-snowflake.ts +232 -0
  67. package/package.json +141 -0
  68. package/src/amplitude.test.ts +231 -0
  69. package/src/amplitude.ts +148 -0
  70. package/src/event-subscriber-base.ts +325 -0
  71. package/src/factories.ts +197 -0
  72. package/src/index.ts +50 -0
  73. package/src/middleware.ts +489 -0
  74. package/src/mixpanel.test.ts +194 -0
  75. package/src/mixpanel.ts +134 -0
  76. package/src/mock-event-subscriber.ts +333 -0
  77. package/src/posthog.test.ts +629 -0
  78. package/src/posthog.ts +530 -0
  79. package/src/segment.test.ts +228 -0
  80. package/src/segment.ts +148 -0
  81. package/src/slack.ts +383 -0
  82. package/src/streaming-event-subscriber.ts +323 -0
  83. package/src/testing/index.ts +37 -0
  84. package/src/testing/mock-webhook-server.ts +242 -0
  85. package/src/testing/subscriber-test-harness.ts +365 -0
  86. package/src/webhook.test.ts +264 -0
  87. package/src/webhook.ts +158 -0
@@ -0,0 +1,2463 @@
1
+ import * as http from 'http';
2
+ import * as https from 'https';
3
+
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __esm = (fn, res) => function __init() {
7
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
8
+ };
9
+ var __export = (target, all) => {
10
+ for (var name in all)
11
+ __defProp(target, name, { get: all[name], enumerable: true });
12
+ };
13
+
14
+ // ../../node_modules/.pnpm/tslib@2.8.1/node_modules/tslib/tslib.es6.mjs
15
+ function __extends(d, b) {
16
+ if (typeof b !== "function" && b !== null)
17
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
18
+ extendStatics(d, b);
19
+ function __() {
20
+ this.constructor = d;
21
+ }
22
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
23
+ }
24
+ function __rest(s, e) {
25
+ var t = {};
26
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
27
+ t[p] = s[p];
28
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
29
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
30
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
31
+ t[p[i]] = s[p[i]];
32
+ }
33
+ return t;
34
+ }
35
+ function __awaiter(thisArg, _arguments, P, generator) {
36
+ function adopt(value) {
37
+ return value instanceof P ? value : new P(function(resolve) {
38
+ resolve(value);
39
+ });
40
+ }
41
+ return new (P || (P = Promise))(function(resolve, reject) {
42
+ function fulfilled(value) {
43
+ try {
44
+ step(generator.next(value));
45
+ } catch (e) {
46
+ reject(e);
47
+ }
48
+ }
49
+ function rejected(value) {
50
+ try {
51
+ step(generator["throw"](value));
52
+ } catch (e) {
53
+ reject(e);
54
+ }
55
+ }
56
+ function step(result) {
57
+ result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
58
+ }
59
+ step((generator = generator.apply(thisArg, [])).next());
60
+ });
61
+ }
62
+ function __generator(thisArg, body) {
63
+ var _ = { label: 0, sent: function() {
64
+ if (t[0] & 1) throw t[1];
65
+ return t[1];
66
+ }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
67
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() {
68
+ return this;
69
+ }), g;
70
+ function verb(n) {
71
+ return function(v) {
72
+ return step([n, v]);
73
+ };
74
+ }
75
+ function step(op) {
76
+ if (f) throw new TypeError("Generator is already executing.");
77
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
78
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
79
+ if (y = 0, t) op = [op[0] & 2, t.value];
80
+ switch (op[0]) {
81
+ case 0:
82
+ case 1:
83
+ t = op;
84
+ break;
85
+ case 4:
86
+ _.label++;
87
+ return { value: op[1], done: false };
88
+ case 5:
89
+ _.label++;
90
+ y = op[1];
91
+ op = [0];
92
+ continue;
93
+ case 7:
94
+ op = _.ops.pop();
95
+ _.trys.pop();
96
+ continue;
97
+ default:
98
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
99
+ _ = 0;
100
+ continue;
101
+ }
102
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
103
+ _.label = op[1];
104
+ break;
105
+ }
106
+ if (op[0] === 6 && _.label < t[1]) {
107
+ _.label = t[1];
108
+ t = op;
109
+ break;
110
+ }
111
+ if (t && _.label < t[2]) {
112
+ _.label = t[2];
113
+ _.ops.push(op);
114
+ break;
115
+ }
116
+ if (t[2]) _.ops.pop();
117
+ _.trys.pop();
118
+ continue;
119
+ }
120
+ op = body.call(thisArg, _);
121
+ } catch (e) {
122
+ op = [6, e];
123
+ y = 0;
124
+ } finally {
125
+ f = t = 0;
126
+ }
127
+ if (op[0] & 5) throw op[1];
128
+ return { value: op[0] ? op[1] : void 0, done: true };
129
+ }
130
+ }
131
+ function __values(o) {
132
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
133
+ if (m) return m.call(o);
134
+ if (o && typeof o.length === "number") return {
135
+ next: function() {
136
+ if (o && i >= o.length) o = void 0;
137
+ return { value: o && o[i++], done: !o };
138
+ }
139
+ };
140
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
141
+ }
142
+ function __read(o, n) {
143
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
144
+ if (!m) return o;
145
+ var i = m.call(o), r, ar = [], e;
146
+ try {
147
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
148
+ } catch (error) {
149
+ e = { error };
150
+ } finally {
151
+ try {
152
+ if (r && !r.done && (m = i["return"])) m.call(i);
153
+ } finally {
154
+ if (e) throw e.error;
155
+ }
156
+ }
157
+ return ar;
158
+ }
159
+ function __spreadArray(to, from, pack) {
160
+ if (arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
161
+ if (ar || !(i in from)) {
162
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
163
+ ar[i] = from[i];
164
+ }
165
+ }
166
+ return to.concat(ar || Array.prototype.slice.call(from));
167
+ }
168
+ var extendStatics, __assign;
169
+ var init_tslib_es6 = __esm({
170
+ "../../node_modules/.pnpm/tslib@2.8.1/node_modules/tslib/tslib.es6.mjs"() {
171
+ extendStatics = function(d, b) {
172
+ extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(d2, b2) {
173
+ d2.__proto__ = b2;
174
+ } || function(d2, b2) {
175
+ for (var p in b2) if (Object.prototype.hasOwnProperty.call(b2, p)) d2[p] = b2[p];
176
+ };
177
+ return extendStatics(d, b);
178
+ };
179
+ __assign = function() {
180
+ __assign = Object.assign || function __assign2(t) {
181
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
182
+ s = arguments[i];
183
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
184
+ }
185
+ return t;
186
+ };
187
+ return __assign.apply(this, arguments);
188
+ };
189
+ }
190
+ });
191
+
192
+ // ../../node_modules/.pnpm/@amplitude+analytics-core@2.33.0/node_modules/@amplitude/analytics-core/lib/esm/types/event/event.js
193
+ var IdentifyOperation, SpecialEventType;
194
+ var init_event = __esm({
195
+ "../../node_modules/.pnpm/@amplitude+analytics-core@2.33.0/node_modules/@amplitude/analytics-core/lib/esm/types/event/event.js"() {
196
+ (function(IdentifyOperation3) {
197
+ IdentifyOperation3["SET"] = "$set";
198
+ IdentifyOperation3["SET_ONCE"] = "$setOnce";
199
+ IdentifyOperation3["ADD"] = "$add";
200
+ IdentifyOperation3["APPEND"] = "$append";
201
+ IdentifyOperation3["PREPEND"] = "$prepend";
202
+ IdentifyOperation3["REMOVE"] = "$remove";
203
+ IdentifyOperation3["PREINSERT"] = "$preInsert";
204
+ IdentifyOperation3["POSTINSERT"] = "$postInsert";
205
+ IdentifyOperation3["UNSET"] = "$unset";
206
+ IdentifyOperation3["CLEAR_ALL"] = "$clearAll";
207
+ })(IdentifyOperation || (IdentifyOperation = {}));
208
+ (function(SpecialEventType2) {
209
+ SpecialEventType2["IDENTIFY"] = "$identify";
210
+ SpecialEventType2["GROUP_IDENTIFY"] = "$groupidentify";
211
+ SpecialEventType2["REVENUE"] = "revenue_amount";
212
+ })(SpecialEventType || (SpecialEventType = {}));
213
+ }
214
+ });
215
+
216
+ // ../../node_modules/.pnpm/@amplitude+analytics-core@2.33.0/node_modules/@amplitude/analytics-core/lib/esm/types/constants.js
217
+ var UNSET_VALUE, AMPLITUDE_PREFIX, STORAGE_PREFIX, DEFAULT_INSTANCE_NAME, AMPLITUDE_SERVER_URL, EU_AMPLITUDE_SERVER_URL, AMPLITUDE_BATCH_SERVER_URL, EU_AMPLITUDE_BATCH_SERVER_URL;
218
+ var init_constants = __esm({
219
+ "../../node_modules/.pnpm/@amplitude+analytics-core@2.33.0/node_modules/@amplitude/analytics-core/lib/esm/types/constants.js"() {
220
+ UNSET_VALUE = "-";
221
+ AMPLITUDE_PREFIX = "AMP";
222
+ STORAGE_PREFIX = "".concat(AMPLITUDE_PREFIX, "_unsent");
223
+ DEFAULT_INSTANCE_NAME = "$default_instance";
224
+ AMPLITUDE_SERVER_URL = "https://api2.amplitude.com/2/httpapi";
225
+ EU_AMPLITUDE_SERVER_URL = "https://api.eu.amplitude.com/2/httpapi";
226
+ AMPLITUDE_BATCH_SERVER_URL = "https://api2.amplitude.com/batch";
227
+ EU_AMPLITUDE_BATCH_SERVER_URL = "https://api.eu.amplitude.com/batch";
228
+ }
229
+ });
230
+
231
+ // ../../node_modules/.pnpm/@amplitude+analytics-core@2.33.0/node_modules/@amplitude/analytics-core/lib/esm/utils/valid-properties.js
232
+ var MAX_PROPERTY_KEYS, isValidObject, isValidProperties;
233
+ var init_valid_properties = __esm({
234
+ "../../node_modules/.pnpm/@amplitude+analytics-core@2.33.0/node_modules/@amplitude/analytics-core/lib/esm/utils/valid-properties.js"() {
235
+ init_tslib_es6();
236
+ MAX_PROPERTY_KEYS = 1e3;
237
+ isValidObject = function(properties) {
238
+ if (Object.keys(properties).length > MAX_PROPERTY_KEYS) {
239
+ return false;
240
+ }
241
+ for (var key in properties) {
242
+ var value = properties[key];
243
+ if (!isValidProperties(key, value))
244
+ return false;
245
+ }
246
+ return true;
247
+ };
248
+ isValidProperties = function(property, value) {
249
+ var e_1, _a;
250
+ if (typeof property !== "string")
251
+ return false;
252
+ if (Array.isArray(value)) {
253
+ var isValid = true;
254
+ try {
255
+ for (var value_1 = __values(value), value_1_1 = value_1.next(); !value_1_1.done; value_1_1 = value_1.next()) {
256
+ var valueElement = value_1_1.value;
257
+ if (Array.isArray(valueElement)) {
258
+ return false;
259
+ } else if (typeof valueElement === "object") {
260
+ isValid = isValid && isValidObject(valueElement);
261
+ } else if (!["number", "string"].includes(typeof valueElement)) {
262
+ return false;
263
+ }
264
+ if (!isValid) {
265
+ return false;
266
+ }
267
+ }
268
+ } catch (e_1_1) {
269
+ e_1 = { error: e_1_1 };
270
+ } finally {
271
+ try {
272
+ if (value_1_1 && !value_1_1.done && (_a = value_1.return)) _a.call(value_1);
273
+ } finally {
274
+ if (e_1) throw e_1.error;
275
+ }
276
+ }
277
+ } else if (value === null || value === void 0) {
278
+ return false;
279
+ } else if (typeof value === "object") {
280
+ return isValidObject(value);
281
+ } else if (!["number", "string", "boolean"].includes(typeof value)) {
282
+ return false;
283
+ }
284
+ return true;
285
+ };
286
+ }
287
+ });
288
+
289
+ // ../../node_modules/.pnpm/@amplitude+analytics-core@2.33.0/node_modules/@amplitude/analytics-core/lib/esm/identify.js
290
+ var Identify, IdentifyOperation2, OrderedIdentifyOperations;
291
+ var init_identify = __esm({
292
+ "../../node_modules/.pnpm/@amplitude+analytics-core@2.33.0/node_modules/@amplitude/analytics-core/lib/esm/identify.js"() {
293
+ init_tslib_es6();
294
+ init_constants();
295
+ init_valid_properties();
296
+ Identify = /** @class */
297
+ (function() {
298
+ function Identify2() {
299
+ this._propertySet = /* @__PURE__ */ new Set();
300
+ this._properties = {};
301
+ }
302
+ Identify2.prototype.getUserProperties = function() {
303
+ return __assign({}, this._properties);
304
+ };
305
+ Identify2.prototype.set = function(property, value) {
306
+ this._safeSet(IdentifyOperation2.SET, property, value);
307
+ return this;
308
+ };
309
+ Identify2.prototype.setOnce = function(property, value) {
310
+ this._safeSet(IdentifyOperation2.SET_ONCE, property, value);
311
+ return this;
312
+ };
313
+ Identify2.prototype.append = function(property, value) {
314
+ this._safeSet(IdentifyOperation2.APPEND, property, value);
315
+ return this;
316
+ };
317
+ Identify2.prototype.prepend = function(property, value) {
318
+ this._safeSet(IdentifyOperation2.PREPEND, property, value);
319
+ return this;
320
+ };
321
+ Identify2.prototype.postInsert = function(property, value) {
322
+ this._safeSet(IdentifyOperation2.POSTINSERT, property, value);
323
+ return this;
324
+ };
325
+ Identify2.prototype.preInsert = function(property, value) {
326
+ this._safeSet(IdentifyOperation2.PREINSERT, property, value);
327
+ return this;
328
+ };
329
+ Identify2.prototype.remove = function(property, value) {
330
+ this._safeSet(IdentifyOperation2.REMOVE, property, value);
331
+ return this;
332
+ };
333
+ Identify2.prototype.add = function(property, value) {
334
+ this._safeSet(IdentifyOperation2.ADD, property, value);
335
+ return this;
336
+ };
337
+ Identify2.prototype.unset = function(property) {
338
+ this._safeSet(IdentifyOperation2.UNSET, property, UNSET_VALUE);
339
+ return this;
340
+ };
341
+ Identify2.prototype.clearAll = function() {
342
+ this._properties = {};
343
+ this._properties[IdentifyOperation2.CLEAR_ALL] = UNSET_VALUE;
344
+ return this;
345
+ };
346
+ Identify2.prototype._safeSet = function(operation, property, value) {
347
+ if (this._validate(operation, property, value)) {
348
+ var userPropertyMap = this._properties[operation];
349
+ if (userPropertyMap === void 0) {
350
+ userPropertyMap = {};
351
+ this._properties[operation] = userPropertyMap;
352
+ }
353
+ userPropertyMap[property] = value;
354
+ this._propertySet.add(property);
355
+ return true;
356
+ }
357
+ return false;
358
+ };
359
+ Identify2.prototype._validate = function(operation, property, value) {
360
+ if (this._properties[IdentifyOperation2.CLEAR_ALL] !== void 0) {
361
+ return false;
362
+ }
363
+ if (this._propertySet.has(property)) {
364
+ return false;
365
+ }
366
+ if (operation === IdentifyOperation2.ADD) {
367
+ return typeof value === "number";
368
+ }
369
+ if (operation !== IdentifyOperation2.UNSET && operation !== IdentifyOperation2.REMOVE) {
370
+ return isValidProperties(property, value);
371
+ }
372
+ return true;
373
+ };
374
+ return Identify2;
375
+ })();
376
+ (function(IdentifyOperation3) {
377
+ IdentifyOperation3["SET"] = "$set";
378
+ IdentifyOperation3["SET_ONCE"] = "$setOnce";
379
+ IdentifyOperation3["ADD"] = "$add";
380
+ IdentifyOperation3["APPEND"] = "$append";
381
+ IdentifyOperation3["PREPEND"] = "$prepend";
382
+ IdentifyOperation3["REMOVE"] = "$remove";
383
+ IdentifyOperation3["PREINSERT"] = "$preInsert";
384
+ IdentifyOperation3["POSTINSERT"] = "$postInsert";
385
+ IdentifyOperation3["UNSET"] = "$unset";
386
+ IdentifyOperation3["CLEAR_ALL"] = "$clearAll";
387
+ })(IdentifyOperation2 || (IdentifyOperation2 = {}));
388
+ OrderedIdentifyOperations = [
389
+ IdentifyOperation2.CLEAR_ALL,
390
+ IdentifyOperation2.UNSET,
391
+ IdentifyOperation2.SET,
392
+ IdentifyOperation2.SET_ONCE,
393
+ IdentifyOperation2.ADD,
394
+ IdentifyOperation2.APPEND,
395
+ IdentifyOperation2.PREPEND,
396
+ IdentifyOperation2.PREINSERT,
397
+ IdentifyOperation2.POSTINSERT,
398
+ IdentifyOperation2.REMOVE
399
+ ];
400
+ }
401
+ });
402
+
403
+ // ../../node_modules/.pnpm/@amplitude+analytics-core@2.33.0/node_modules/@amplitude/analytics-core/lib/esm/types/messages.js
404
+ var SUCCESS_MESSAGE, UNEXPECTED_ERROR_MESSAGE, MAX_RETRIES_EXCEEDED_MESSAGE, OPT_OUT_MESSAGE, MISSING_API_KEY_MESSAGE, INVALID_API_KEY, CLIENT_NOT_INITIALIZED;
405
+ var init_messages = __esm({
406
+ "../../node_modules/.pnpm/@amplitude+analytics-core@2.33.0/node_modules/@amplitude/analytics-core/lib/esm/types/messages.js"() {
407
+ SUCCESS_MESSAGE = "Event tracked successfully";
408
+ UNEXPECTED_ERROR_MESSAGE = "Unexpected error occurred";
409
+ MAX_RETRIES_EXCEEDED_MESSAGE = "Event rejected due to exceeded retry count";
410
+ OPT_OUT_MESSAGE = "Event skipped due to optOut config";
411
+ MISSING_API_KEY_MESSAGE = "Event rejected due to missing API key";
412
+ INVALID_API_KEY = "Invalid API key";
413
+ CLIENT_NOT_INITIALIZED = "Client not initialized";
414
+ }
415
+ });
416
+
417
+ // ../../node_modules/.pnpm/@amplitude+analytics-core@2.33.0/node_modules/@amplitude/analytics-core/lib/esm/types/status.js
418
+ var Status;
419
+ var init_status = __esm({
420
+ "../../node_modules/.pnpm/@amplitude+analytics-core@2.33.0/node_modules/@amplitude/analytics-core/lib/esm/types/status.js"() {
421
+ (function(Status2) {
422
+ Status2["Unknown"] = "unknown";
423
+ Status2["Skipped"] = "skipped";
424
+ Status2["Success"] = "success";
425
+ Status2["RateLimit"] = "rate_limit";
426
+ Status2["PayloadTooLarge"] = "payload_too_large";
427
+ Status2["Invalid"] = "invalid";
428
+ Status2["Failed"] = "failed";
429
+ Status2["Timeout"] = "Timeout";
430
+ Status2["SystemError"] = "SystemError";
431
+ })(Status || (Status = {}));
432
+ }
433
+ });
434
+
435
+ // ../../node_modules/.pnpm/@amplitude+analytics-core@2.33.0/node_modules/@amplitude/analytics-core/lib/esm/utils/result-builder.js
436
+ var buildResult;
437
+ var init_result_builder = __esm({
438
+ "../../node_modules/.pnpm/@amplitude+analytics-core@2.33.0/node_modules/@amplitude/analytics-core/lib/esm/utils/result-builder.js"() {
439
+ init_status();
440
+ buildResult = function(event, code, message) {
441
+ if (code === void 0) {
442
+ code = 0;
443
+ }
444
+ if (message === void 0) {
445
+ message = Status.Unknown;
446
+ }
447
+ return { event, code, message };
448
+ };
449
+ }
450
+ });
451
+
452
+ // ../../node_modules/.pnpm/@amplitude+analytics-core@2.33.0/node_modules/@amplitude/analytics-core/lib/esm/global-scope.js
453
+ var getGlobalScope;
454
+ var init_global_scope = __esm({
455
+ "../../node_modules/.pnpm/@amplitude+analytics-core@2.33.0/node_modules/@amplitude/analytics-core/lib/esm/global-scope.js"() {
456
+ getGlobalScope = function() {
457
+ var ampIntegrationContextName = "ampIntegrationContext";
458
+ if (typeof globalThis !== "undefined" && typeof globalThis[ampIntegrationContextName] !== "undefined") {
459
+ return globalThis[ampIntegrationContextName];
460
+ }
461
+ if (typeof globalThis !== "undefined") {
462
+ return globalThis;
463
+ }
464
+ if (typeof window !== "undefined") {
465
+ return window;
466
+ }
467
+ if (typeof self !== "undefined") {
468
+ return self;
469
+ }
470
+ if (typeof global !== "undefined") {
471
+ return global;
472
+ }
473
+ return void 0;
474
+ };
475
+ }
476
+ });
477
+
478
+ // ../../node_modules/.pnpm/@amplitude+analytics-core@2.33.0/node_modules/@amplitude/analytics-core/lib/esm/utils/uuid.js
479
+ var legacyUUID, hex, UUID;
480
+ var init_uuid = __esm({
481
+ "../../node_modules/.pnpm/@amplitude+analytics-core@2.33.0/node_modules/@amplitude/analytics-core/lib/esm/utils/uuid.js"() {
482
+ init_tslib_es6();
483
+ init_global_scope();
484
+ legacyUUID = function(a) {
485
+ return a ? (
486
+ // a random number from 0 to 15
487
+ (a ^ // unless b is 8,
488
+ Math.random() * // in which case
489
+ 16 >> // a random number from
490
+ a / 4).toString(16)
491
+ ) : (
492
+ // or otherwise a concatenated string:
493
+ (String(1e7) + // 10000000 +
494
+ String(-1e3) + // -1000 +
495
+ String(-4e3) + // -4000 +
496
+ String(-8e3) + // -80000000 +
497
+ String(-1e11)).replace(
498
+ // replacing
499
+ /[018]/g,
500
+ // zeroes, ones, and eights with
501
+ UUID
502
+ )
503
+ );
504
+ };
505
+ hex = __spreadArray([], __read(Array(256).keys()), false).map(function(index) {
506
+ return index.toString(16).padStart(2, "0");
507
+ });
508
+ UUID = function(a) {
509
+ var _a;
510
+ var globalScope = getGlobalScope();
511
+ if (!((_a = globalScope === null || globalScope === void 0 ? void 0 : globalScope.crypto) === null || _a === void 0 ? void 0 : _a.getRandomValues)) {
512
+ return legacyUUID(a);
513
+ }
514
+ var r = globalScope.crypto.getRandomValues(new Uint8Array(16));
515
+ r[6] = r[6] & 15 | 64;
516
+ r[8] = r[8] & 63 | 128;
517
+ return __spreadArray([], __read(r.entries()), false).map(function(_a2) {
518
+ var _b = __read(_a2, 2), index = _b[0], int = _b[1];
519
+ return [4, 6, 8, 10].includes(index) ? "-".concat(hex[int]) : hex[int];
520
+ }).join("");
521
+ };
522
+ }
523
+ });
524
+
525
+ // ../../node_modules/.pnpm/@amplitude+analytics-core@2.33.0/node_modules/@amplitude/analytics-core/lib/esm/timeline.js
526
+ var Timeline;
527
+ var init_timeline = __esm({
528
+ "../../node_modules/.pnpm/@amplitude+analytics-core@2.33.0/node_modules/@amplitude/analytics-core/lib/esm/timeline.js"() {
529
+ init_tslib_es6();
530
+ init_result_builder();
531
+ init_uuid();
532
+ Timeline = /** @class */
533
+ (function() {
534
+ function Timeline2(client) {
535
+ this.client = client;
536
+ this.queue = [];
537
+ this.applying = false;
538
+ this.plugins = [];
539
+ }
540
+ Timeline2.prototype.register = function(plugin, config) {
541
+ var _a, _b;
542
+ return __awaiter(this, void 0, void 0, function() {
543
+ return __generator(this, function(_c) {
544
+ switch (_c.label) {
545
+ case 0:
546
+ if (this.plugins.some(function(existingPlugin) {
547
+ return existingPlugin.name === plugin.name;
548
+ })) {
549
+ this.loggerProvider.warn("Plugin with name ".concat(plugin.name, " already exists, skipping registration"));
550
+ return [
551
+ 2
552
+ /*return*/
553
+ ];
554
+ }
555
+ if (plugin.name === void 0) {
556
+ plugin.name = UUID();
557
+ this.loggerProvider.warn("Plugin name is undefined. \n Generating a random UUID for plugin name: ".concat(plugin.name, ". \n Set a name for the plugin to prevent it from being added multiple times."));
558
+ }
559
+ plugin.type = (_a = plugin.type) !== null && _a !== void 0 ? _a : "enrichment";
560
+ return [4, (_b = plugin.setup) === null || _b === void 0 ? void 0 : _b.call(plugin, config, this.client)];
561
+ case 1:
562
+ _c.sent();
563
+ this.plugins.push(plugin);
564
+ return [
565
+ 2
566
+ /*return*/
567
+ ];
568
+ }
569
+ });
570
+ });
571
+ };
572
+ Timeline2.prototype.deregister = function(pluginName, config) {
573
+ var _a;
574
+ return __awaiter(this, void 0, void 0, function() {
575
+ var index, plugin;
576
+ return __generator(this, function(_b) {
577
+ switch (_b.label) {
578
+ case 0:
579
+ index = this.plugins.findIndex(function(plugin2) {
580
+ return plugin2.name === pluginName;
581
+ });
582
+ if (index === -1) {
583
+ config.loggerProvider.warn("Plugin with name ".concat(pluginName, " does not exist, skipping deregistration"));
584
+ return [
585
+ 2
586
+ /*return*/
587
+ ];
588
+ }
589
+ plugin = this.plugins[index];
590
+ this.plugins.splice(index, 1);
591
+ return [4, (_a = plugin.teardown) === null || _a === void 0 ? void 0 : _a.call(plugin)];
592
+ case 1:
593
+ _b.sent();
594
+ return [
595
+ 2
596
+ /*return*/
597
+ ];
598
+ }
599
+ });
600
+ });
601
+ };
602
+ Timeline2.prototype.reset = function(client) {
603
+ this.applying = false;
604
+ var plugins = this.plugins;
605
+ plugins.map(function(plugin) {
606
+ var _a;
607
+ return (_a = plugin.teardown) === null || _a === void 0 ? void 0 : _a.call(plugin);
608
+ });
609
+ this.plugins = [];
610
+ this.client = client;
611
+ };
612
+ Timeline2.prototype.push = function(event) {
613
+ var _this = this;
614
+ return new Promise(function(resolve) {
615
+ _this.queue.push([event, resolve]);
616
+ _this.scheduleApply(0);
617
+ });
618
+ };
619
+ Timeline2.prototype.scheduleApply = function(timeout) {
620
+ var _this = this;
621
+ if (this.applying)
622
+ return;
623
+ this.applying = true;
624
+ setTimeout(function() {
625
+ void _this.apply(_this.queue.shift()).then(function() {
626
+ _this.applying = false;
627
+ if (_this.queue.length > 0) {
628
+ _this.scheduleApply(0);
629
+ }
630
+ });
631
+ }, timeout);
632
+ };
633
+ Timeline2.prototype.apply = function(item) {
634
+ return __awaiter(this, void 0, void 0, function() {
635
+ var _a, event, _b, resolve, before, before_1, before_1_1, plugin, e, e_1_1, enrichment, enrichment_1, enrichment_1_1, plugin, e, e_2_1, destination, executeDestinations;
636
+ var e_1, _c, e_2, _d;
637
+ return __generator(this, function(_e) {
638
+ switch (_e.label) {
639
+ case 0:
640
+ if (!item) {
641
+ return [
642
+ 2
643
+ /*return*/
644
+ ];
645
+ }
646
+ _a = __read(item, 1), event = _a[0];
647
+ _b = __read(item, 2), resolve = _b[1];
648
+ this.loggerProvider.log("Timeline.apply: Initial event", event);
649
+ before = this.plugins.filter(function(plugin2) {
650
+ return plugin2.type === "before";
651
+ });
652
+ _e.label = 1;
653
+ case 1:
654
+ _e.trys.push([1, 6, 7, 8]);
655
+ before_1 = __values(before), before_1_1 = before_1.next();
656
+ _e.label = 2;
657
+ case 2:
658
+ if (!!before_1_1.done) return [3, 5];
659
+ plugin = before_1_1.value;
660
+ if (!plugin.execute) {
661
+ return [3, 4];
662
+ }
663
+ return [4, plugin.execute(__assign({}, event))];
664
+ case 3:
665
+ e = _e.sent();
666
+ if (e === null) {
667
+ this.loggerProvider.log("Timeline.apply: Event filtered out by before plugin '".concat(String(plugin.name), "', event: ").concat(JSON.stringify(event)));
668
+ resolve({ event, code: 0, message: "" });
669
+ return [
670
+ 2
671
+ /*return*/
672
+ ];
673
+ } else {
674
+ event = e;
675
+ this.loggerProvider.log("Timeline.apply: Event after before plugin '".concat(String(plugin.name), "', event: ").concat(JSON.stringify(event)));
676
+ }
677
+ _e.label = 4;
678
+ case 4:
679
+ before_1_1 = before_1.next();
680
+ return [3, 2];
681
+ case 5:
682
+ return [3, 8];
683
+ case 6:
684
+ e_1_1 = _e.sent();
685
+ e_1 = { error: e_1_1 };
686
+ return [3, 8];
687
+ case 7:
688
+ try {
689
+ if (before_1_1 && !before_1_1.done && (_c = before_1.return)) _c.call(before_1);
690
+ } finally {
691
+ if (e_1) throw e_1.error;
692
+ }
693
+ return [
694
+ 7
695
+ /*endfinally*/
696
+ ];
697
+ case 8:
698
+ enrichment = this.plugins.filter(function(plugin2) {
699
+ return plugin2.type === "enrichment" || plugin2.type === void 0;
700
+ });
701
+ _e.label = 9;
702
+ case 9:
703
+ _e.trys.push([9, 14, 15, 16]);
704
+ enrichment_1 = __values(enrichment), enrichment_1_1 = enrichment_1.next();
705
+ _e.label = 10;
706
+ case 10:
707
+ if (!!enrichment_1_1.done) return [3, 13];
708
+ plugin = enrichment_1_1.value;
709
+ if (!plugin.execute) {
710
+ return [3, 12];
711
+ }
712
+ return [4, plugin.execute(__assign({}, event))];
713
+ case 11:
714
+ e = _e.sent();
715
+ if (e === null) {
716
+ this.loggerProvider.log("Timeline.apply: Event filtered out by enrichment plugin '".concat(String(plugin.name), "', event: ").concat(JSON.stringify(event)));
717
+ resolve({ event, code: 0, message: "" });
718
+ return [
719
+ 2
720
+ /*return*/
721
+ ];
722
+ } else {
723
+ event = e;
724
+ this.loggerProvider.log("Timeline.apply: Event after enrichment plugin '".concat(String(plugin.name), "', event: ").concat(JSON.stringify(event)));
725
+ }
726
+ _e.label = 12;
727
+ case 12:
728
+ enrichment_1_1 = enrichment_1.next();
729
+ return [3, 10];
730
+ case 13:
731
+ return [3, 16];
732
+ case 14:
733
+ e_2_1 = _e.sent();
734
+ e_2 = { error: e_2_1 };
735
+ return [3, 16];
736
+ case 15:
737
+ try {
738
+ if (enrichment_1_1 && !enrichment_1_1.done && (_d = enrichment_1.return)) _d.call(enrichment_1);
739
+ } finally {
740
+ if (e_2) throw e_2.error;
741
+ }
742
+ return [
743
+ 7
744
+ /*endfinally*/
745
+ ];
746
+ case 16:
747
+ destination = this.plugins.filter(function(plugin2) {
748
+ return plugin2.type === "destination";
749
+ });
750
+ this.loggerProvider.log("Timeline.apply: Final event before destinations, event: ".concat(JSON.stringify(event)));
751
+ executeDestinations = destination.map(function(plugin2) {
752
+ var eventClone = __assign({}, event);
753
+ return plugin2.execute(eventClone).catch(function(e2) {
754
+ return buildResult(eventClone, 0, String(e2));
755
+ });
756
+ });
757
+ void Promise.all(executeDestinations).then(function(_a2) {
758
+ var _b2 = __read(_a2, 1), result = _b2[0];
759
+ var resolveResult = result || buildResult(event, 100, "Event not tracked, no destination plugins on the instance");
760
+ resolve(resolveResult);
761
+ });
762
+ return [
763
+ 2
764
+ /*return*/
765
+ ];
766
+ }
767
+ });
768
+ });
769
+ };
770
+ Timeline2.prototype.flush = function() {
771
+ return __awaiter(this, void 0, void 0, function() {
772
+ var queue, destination, executeDestinations;
773
+ var _this = this;
774
+ return __generator(this, function(_a) {
775
+ switch (_a.label) {
776
+ case 0:
777
+ queue = this.queue;
778
+ this.queue = [];
779
+ return [4, Promise.all(queue.map(function(item) {
780
+ return _this.apply(item);
781
+ }))];
782
+ case 1:
783
+ _a.sent();
784
+ destination = this.plugins.filter(function(plugin) {
785
+ return plugin.type === "destination";
786
+ });
787
+ executeDestinations = destination.map(function(plugin) {
788
+ return plugin.flush && plugin.flush();
789
+ });
790
+ return [4, Promise.all(executeDestinations)];
791
+ case 2:
792
+ _a.sent();
793
+ return [
794
+ 2
795
+ /*return*/
796
+ ];
797
+ }
798
+ });
799
+ });
800
+ };
801
+ Timeline2.prototype.onIdentityChanged = function(identity) {
802
+ this.plugins.forEach(function(plugin) {
803
+ var _a;
804
+ void ((_a = plugin.onIdentityChanged) === null || _a === void 0 ? void 0 : _a.call(plugin, identity));
805
+ });
806
+ };
807
+ Timeline2.prototype.onSessionIdChanged = function(sessionId) {
808
+ this.plugins.forEach(function(plugin) {
809
+ var _a;
810
+ void ((_a = plugin.onSessionIdChanged) === null || _a === void 0 ? void 0 : _a.call(plugin, sessionId));
811
+ });
812
+ };
813
+ Timeline2.prototype.onOptOutChanged = function(optOut) {
814
+ this.plugins.forEach(function(plugin) {
815
+ var _a;
816
+ void ((_a = plugin.onOptOutChanged) === null || _a === void 0 ? void 0 : _a.call(plugin, optOut));
817
+ });
818
+ };
819
+ Timeline2.prototype.onReset = function() {
820
+ this.plugins.forEach(function(plugin) {
821
+ var _a;
822
+ void ((_a = plugin.onReset) === null || _a === void 0 ? void 0 : _a.call(plugin));
823
+ });
824
+ };
825
+ return Timeline2;
826
+ })();
827
+ }
828
+ });
829
+
830
+ // ../../node_modules/.pnpm/@amplitude+analytics-core@2.33.0/node_modules/@amplitude/analytics-core/lib/esm/utils/event-builder.js
831
+ var createTrackEvent, createIdentifyEvent, createGroupIdentifyEvent, createGroupEvent, createRevenueEvent;
832
+ var init_event_builder = __esm({
833
+ "../../node_modules/.pnpm/@amplitude+analytics-core@2.33.0/node_modules/@amplitude/analytics-core/lib/esm/utils/event-builder.js"() {
834
+ init_tslib_es6();
835
+ init_identify();
836
+ init_event();
837
+ createTrackEvent = function(eventInput, eventProperties, eventOptions) {
838
+ var baseEvent = typeof eventInput === "string" ? { event_type: eventInput } : eventInput;
839
+ return __assign(__assign(__assign({}, baseEvent), eventOptions), eventProperties && { event_properties: eventProperties });
840
+ };
841
+ createIdentifyEvent = function(identify2, eventOptions) {
842
+ var identifyEvent = __assign(__assign({}, eventOptions), { event_type: SpecialEventType.IDENTIFY, user_properties: identify2.getUserProperties() });
843
+ return identifyEvent;
844
+ };
845
+ createGroupIdentifyEvent = function(groupType, groupName, identify2, eventOptions) {
846
+ var _a;
847
+ var groupIdentify2 = __assign(__assign({}, eventOptions), { event_type: SpecialEventType.GROUP_IDENTIFY, group_properties: identify2.getUserProperties(), groups: (_a = {}, _a[groupType] = groupName, _a) });
848
+ return groupIdentify2;
849
+ };
850
+ createGroupEvent = function(groupType, groupName, eventOptions) {
851
+ var _a;
852
+ var identify2 = new Identify();
853
+ identify2.set(groupType, groupName);
854
+ var groupEvent = __assign(__assign({}, eventOptions), { event_type: SpecialEventType.IDENTIFY, user_properties: identify2.getUserProperties(), groups: (_a = {}, _a[groupType] = groupName, _a) });
855
+ return groupEvent;
856
+ };
857
+ createRevenueEvent = function(revenue2, eventOptions) {
858
+ return __assign(__assign({}, eventOptions), { event_type: SpecialEventType.REVENUE, event_properties: revenue2.getEventProperties() });
859
+ };
860
+ }
861
+ });
862
+
863
+ // ../../node_modules/.pnpm/@amplitude+analytics-core@2.33.0/node_modules/@amplitude/analytics-core/lib/esm/utils/return-wrapper.js
864
+ var returnWrapper;
865
+ var init_return_wrapper = __esm({
866
+ "../../node_modules/.pnpm/@amplitude+analytics-core@2.33.0/node_modules/@amplitude/analytics-core/lib/esm/utils/return-wrapper.js"() {
867
+ returnWrapper = function(awaitable) {
868
+ return {
869
+ promise: awaitable || Promise.resolve()
870
+ };
871
+ };
872
+ }
873
+ });
874
+
875
+ // ../../node_modules/.pnpm/@amplitude+analytics-core@2.33.0/node_modules/@amplitude/analytics-core/lib/esm/core-client.js
876
+ var AmplitudeCore;
877
+ var init_core_client = __esm({
878
+ "../../node_modules/.pnpm/@amplitude+analytics-core@2.33.0/node_modules/@amplitude/analytics-core/lib/esm/core-client.js"() {
879
+ init_tslib_es6();
880
+ init_event();
881
+ init_identify();
882
+ init_messages();
883
+ init_timeline();
884
+ init_event_builder();
885
+ init_result_builder();
886
+ init_return_wrapper();
887
+ AmplitudeCore = /** @class */
888
+ (function() {
889
+ function AmplitudeCore2(name) {
890
+ if (name === void 0) {
891
+ name = "$default";
892
+ }
893
+ this.initializing = false;
894
+ this.isReady = false;
895
+ this.q = [];
896
+ this.dispatchQ = [];
897
+ this.logEvent = this.track.bind(this);
898
+ this.timeline = new Timeline(this);
899
+ this.name = name;
900
+ }
901
+ AmplitudeCore2.prototype._init = function(config) {
902
+ return __awaiter(this, void 0, void 0, function() {
903
+ return __generator(this, function(_a) {
904
+ switch (_a.label) {
905
+ case 0:
906
+ this.config = config;
907
+ this.timeline.reset(this);
908
+ this.timeline.loggerProvider = this.config.loggerProvider;
909
+ return [4, this.runQueuedFunctions("q")];
910
+ case 1:
911
+ _a.sent();
912
+ this.isReady = true;
913
+ return [
914
+ 2
915
+ /*return*/
916
+ ];
917
+ }
918
+ });
919
+ });
920
+ };
921
+ AmplitudeCore2.prototype.runQueuedFunctions = function(queueName) {
922
+ return __awaiter(this, void 0, void 0, function() {
923
+ var queuedFunctions, queuedFunctions_1, queuedFunctions_1_1, queuedFunction, val, e_1_1;
924
+ var e_1, _a;
925
+ return __generator(this, function(_b) {
926
+ switch (_b.label) {
927
+ case 0:
928
+ queuedFunctions = this[queueName];
929
+ this[queueName] = [];
930
+ _b.label = 1;
931
+ case 1:
932
+ _b.trys.push([1, 8, 9, 10]);
933
+ queuedFunctions_1 = __values(queuedFunctions), queuedFunctions_1_1 = queuedFunctions_1.next();
934
+ _b.label = 2;
935
+ case 2:
936
+ if (!!queuedFunctions_1_1.done) return [3, 7];
937
+ queuedFunction = queuedFunctions_1_1.value;
938
+ val = queuedFunction();
939
+ if (!(val && "promise" in val)) return [3, 4];
940
+ return [4, val.promise];
941
+ case 3:
942
+ _b.sent();
943
+ return [3, 6];
944
+ case 4:
945
+ return [4, val];
946
+ case 5:
947
+ _b.sent();
948
+ _b.label = 6;
949
+ case 6:
950
+ queuedFunctions_1_1 = queuedFunctions_1.next();
951
+ return [3, 2];
952
+ case 7:
953
+ return [3, 10];
954
+ case 8:
955
+ e_1_1 = _b.sent();
956
+ e_1 = { error: e_1_1 };
957
+ return [3, 10];
958
+ case 9:
959
+ try {
960
+ if (queuedFunctions_1_1 && !queuedFunctions_1_1.done && (_a = queuedFunctions_1.return)) _a.call(queuedFunctions_1);
961
+ } finally {
962
+ if (e_1) throw e_1.error;
963
+ }
964
+ return [
965
+ 7
966
+ /*endfinally*/
967
+ ];
968
+ case 10:
969
+ if (!this[queueName].length) return [3, 12];
970
+ return [4, this.runQueuedFunctions(queueName)];
971
+ case 11:
972
+ _b.sent();
973
+ _b.label = 12;
974
+ case 12:
975
+ return [
976
+ 2
977
+ /*return*/
978
+ ];
979
+ }
980
+ });
981
+ });
982
+ };
983
+ AmplitudeCore2.prototype.track = function(eventInput, eventProperties, eventOptions) {
984
+ var event = createTrackEvent(eventInput, eventProperties, eventOptions);
985
+ return returnWrapper(this.dispatch(event));
986
+ };
987
+ AmplitudeCore2.prototype.identify = function(identify2, eventOptions) {
988
+ var event = createIdentifyEvent(identify2, eventOptions);
989
+ return returnWrapper(this.dispatch(event));
990
+ };
991
+ AmplitudeCore2.prototype.groupIdentify = function(groupType, groupName, identify2, eventOptions) {
992
+ var event = createGroupIdentifyEvent(groupType, groupName, identify2, eventOptions);
993
+ return returnWrapper(this.dispatch(event));
994
+ };
995
+ AmplitudeCore2.prototype.setGroup = function(groupType, groupName, eventOptions) {
996
+ var event = createGroupEvent(groupType, groupName, eventOptions);
997
+ return returnWrapper(this.dispatch(event));
998
+ };
999
+ AmplitudeCore2.prototype.revenue = function(revenue2, eventOptions) {
1000
+ var event = createRevenueEvent(revenue2, eventOptions);
1001
+ return returnWrapper(this.dispatch(event));
1002
+ };
1003
+ AmplitudeCore2.prototype.add = function(plugin) {
1004
+ if (!this.isReady) {
1005
+ this.q.push(this._addPlugin.bind(this, plugin));
1006
+ return returnWrapper();
1007
+ }
1008
+ return this._addPlugin(plugin);
1009
+ };
1010
+ AmplitudeCore2.prototype._addPlugin = function(plugin) {
1011
+ return returnWrapper(this.timeline.register(plugin, this.config));
1012
+ };
1013
+ AmplitudeCore2.prototype.remove = function(pluginName) {
1014
+ if (!this.isReady) {
1015
+ this.q.push(this._removePlugin.bind(this, pluginName));
1016
+ return returnWrapper();
1017
+ }
1018
+ return this._removePlugin(pluginName);
1019
+ };
1020
+ AmplitudeCore2.prototype._removePlugin = function(pluginName) {
1021
+ return returnWrapper(this.timeline.deregister(pluginName, this.config));
1022
+ };
1023
+ AmplitudeCore2.prototype.dispatchWithCallback = function(event, callback) {
1024
+ if (!this.isReady) {
1025
+ return callback(buildResult(event, 0, CLIENT_NOT_INITIALIZED));
1026
+ }
1027
+ void this.process(event).then(callback);
1028
+ };
1029
+ AmplitudeCore2.prototype.dispatch = function(event) {
1030
+ return __awaiter(this, void 0, void 0, function() {
1031
+ var _this = this;
1032
+ return __generator(this, function(_a) {
1033
+ if (!this.isReady) {
1034
+ return [2, new Promise(function(resolve) {
1035
+ _this.dispatchQ.push(_this.dispatchWithCallback.bind(_this, event, resolve));
1036
+ })];
1037
+ }
1038
+ return [2, this.process(event)];
1039
+ });
1040
+ });
1041
+ };
1042
+ AmplitudeCore2.prototype.getOperationAppliedUserProperties = function(userProperties) {
1043
+ var updatedProperties = {};
1044
+ if (userProperties === void 0) {
1045
+ return updatedProperties;
1046
+ }
1047
+ var nonOpProperties = {};
1048
+ Object.keys(userProperties).forEach(function(key) {
1049
+ if (!Object.values(IdentifyOperation).includes(key)) {
1050
+ nonOpProperties[key] = userProperties[key];
1051
+ }
1052
+ });
1053
+ OrderedIdentifyOperations.forEach(function(operation) {
1054
+ if (!Object.keys(userProperties).includes(operation))
1055
+ return;
1056
+ var opProperties = userProperties[operation];
1057
+ switch (operation) {
1058
+ case IdentifyOperation.CLEAR_ALL:
1059
+ Object.keys(updatedProperties).forEach(function(prop) {
1060
+ delete updatedProperties[prop];
1061
+ });
1062
+ break;
1063
+ case IdentifyOperation.UNSET:
1064
+ Object.keys(opProperties).forEach(function(prop) {
1065
+ delete updatedProperties[prop];
1066
+ });
1067
+ break;
1068
+ case IdentifyOperation.SET:
1069
+ Object.assign(updatedProperties, opProperties);
1070
+ break;
1071
+ }
1072
+ });
1073
+ Object.assign(updatedProperties, nonOpProperties);
1074
+ return updatedProperties;
1075
+ };
1076
+ AmplitudeCore2.prototype.process = function(event) {
1077
+ return __awaiter(this, void 0, void 0, function() {
1078
+ var userProperties, result, e_2, message, result;
1079
+ return __generator(this, function(_a) {
1080
+ switch (_a.label) {
1081
+ case 0:
1082
+ _a.trys.push([0, 2, , 3]);
1083
+ if (this.config.optOut) {
1084
+ return [2, buildResult(event, 0, OPT_OUT_MESSAGE)];
1085
+ }
1086
+ if (event.event_type === SpecialEventType.IDENTIFY) {
1087
+ userProperties = this.getOperationAppliedUserProperties(event.user_properties);
1088
+ this.timeline.onIdentityChanged({ userProperties });
1089
+ }
1090
+ return [4, this.timeline.push(event)];
1091
+ case 1:
1092
+ result = _a.sent();
1093
+ result.code === 200 ? this.config.loggerProvider.log(result.message) : result.code === 100 ? this.config.loggerProvider.warn(result.message) : this.config.loggerProvider.error(result.message);
1094
+ return [2, result];
1095
+ case 2:
1096
+ e_2 = _a.sent();
1097
+ message = String(e_2);
1098
+ this.config.loggerProvider.error(message);
1099
+ result = buildResult(event, 0, message);
1100
+ return [2, result];
1101
+ case 3:
1102
+ return [
1103
+ 2
1104
+ /*return*/
1105
+ ];
1106
+ }
1107
+ });
1108
+ });
1109
+ };
1110
+ AmplitudeCore2.prototype.setOptOut = function(optOut) {
1111
+ if (!this.isReady) {
1112
+ this.q.push(this._setOptOut.bind(this, Boolean(optOut)));
1113
+ return;
1114
+ }
1115
+ this._setOptOut(optOut);
1116
+ };
1117
+ AmplitudeCore2.prototype._setOptOut = function(optOut) {
1118
+ if (this.config.optOut !== optOut) {
1119
+ this.timeline.onOptOutChanged(optOut);
1120
+ this.config.optOut = Boolean(optOut);
1121
+ }
1122
+ };
1123
+ AmplitudeCore2.prototype.flush = function() {
1124
+ return returnWrapper(this.timeline.flush());
1125
+ };
1126
+ AmplitudeCore2.prototype.plugin = function(name) {
1127
+ var plugin = this.timeline.plugins.find(function(plugin2) {
1128
+ return plugin2.name === name;
1129
+ });
1130
+ if (plugin === void 0) {
1131
+ this.config.loggerProvider.debug("Cannot find plugin with name ".concat(name));
1132
+ return void 0;
1133
+ }
1134
+ return plugin;
1135
+ };
1136
+ AmplitudeCore2.prototype.plugins = function(pluginClass) {
1137
+ return this.timeline.plugins.filter(function(plugin) {
1138
+ return plugin instanceof pluginClass;
1139
+ });
1140
+ };
1141
+ return AmplitudeCore2;
1142
+ })();
1143
+ }
1144
+ });
1145
+
1146
+ // ../../node_modules/.pnpm/@amplitude+analytics-core@2.33.0/node_modules/@amplitude/analytics-core/lib/esm/revenue.js
1147
+ var Revenue, RevenueProperty;
1148
+ var init_revenue = __esm({
1149
+ "../../node_modules/.pnpm/@amplitude+analytics-core@2.33.0/node_modules/@amplitude/analytics-core/lib/esm/revenue.js"() {
1150
+ init_tslib_es6();
1151
+ init_valid_properties();
1152
+ Revenue = /** @class */
1153
+ (function() {
1154
+ function Revenue2() {
1155
+ this.productId = "";
1156
+ this.quantity = 1;
1157
+ this.price = 0;
1158
+ }
1159
+ Revenue2.prototype.setProductId = function(productId) {
1160
+ this.productId = productId;
1161
+ return this;
1162
+ };
1163
+ Revenue2.prototype.setQuantity = function(quantity) {
1164
+ if (quantity > 0) {
1165
+ this.quantity = quantity;
1166
+ }
1167
+ return this;
1168
+ };
1169
+ Revenue2.prototype.setPrice = function(price) {
1170
+ this.price = price;
1171
+ return this;
1172
+ };
1173
+ Revenue2.prototype.setRevenueType = function(revenueType) {
1174
+ this.revenueType = revenueType;
1175
+ return this;
1176
+ };
1177
+ Revenue2.prototype.setCurrency = function(currency) {
1178
+ this.currency = currency;
1179
+ return this;
1180
+ };
1181
+ Revenue2.prototype.setRevenue = function(revenue2) {
1182
+ this.revenue = revenue2;
1183
+ return this;
1184
+ };
1185
+ Revenue2.prototype.setReceipt = function(receipt) {
1186
+ this.receipt = receipt;
1187
+ return this;
1188
+ };
1189
+ Revenue2.prototype.setReceiptSig = function(receiptSig) {
1190
+ this.receiptSig = receiptSig;
1191
+ return this;
1192
+ };
1193
+ Revenue2.prototype.setEventProperties = function(properties) {
1194
+ if (isValidObject(properties)) {
1195
+ this.properties = properties;
1196
+ }
1197
+ return this;
1198
+ };
1199
+ Revenue2.prototype.getEventProperties = function() {
1200
+ var eventProperties = this.properties ? __assign({}, this.properties) : {};
1201
+ eventProperties[RevenueProperty.REVENUE_PRODUCT_ID] = this.productId;
1202
+ eventProperties[RevenueProperty.REVENUE_QUANTITY] = this.quantity;
1203
+ eventProperties[RevenueProperty.REVENUE_PRICE] = this.price;
1204
+ eventProperties[RevenueProperty.REVENUE_TYPE] = this.revenueType;
1205
+ eventProperties[RevenueProperty.REVENUE_CURRENCY] = this.currency;
1206
+ eventProperties[RevenueProperty.REVENUE] = this.revenue;
1207
+ eventProperties[RevenueProperty.RECEIPT] = this.receipt;
1208
+ eventProperties[RevenueProperty.RECEIPT_SIG] = this.receiptSig;
1209
+ return eventProperties;
1210
+ };
1211
+ return Revenue2;
1212
+ })();
1213
+ (function(RevenueProperty2) {
1214
+ RevenueProperty2["REVENUE_PRODUCT_ID"] = "$productId";
1215
+ RevenueProperty2["REVENUE_QUANTITY"] = "$quantity";
1216
+ RevenueProperty2["REVENUE_PRICE"] = "$price";
1217
+ RevenueProperty2["REVENUE_TYPE"] = "$revenueType";
1218
+ RevenueProperty2["REVENUE_CURRENCY"] = "$currency";
1219
+ RevenueProperty2["REVENUE"] = "$revenue";
1220
+ RevenueProperty2["RECEIPT"] = "$receipt";
1221
+ RevenueProperty2["RECEIPT_SIG"] = "$receiptSig";
1222
+ })(RevenueProperty || (RevenueProperty = {}));
1223
+ }
1224
+ });
1225
+
1226
+ // ../../node_modules/.pnpm/@amplitude+analytics-core@2.33.0/node_modules/@amplitude/analytics-core/lib/esm/utils/chunk.js
1227
+ var chunk;
1228
+ var init_chunk = __esm({
1229
+ "../../node_modules/.pnpm/@amplitude+analytics-core@2.33.0/node_modules/@amplitude/analytics-core/lib/esm/utils/chunk.js"() {
1230
+ chunk = function(arr, size) {
1231
+ var chunkSize = Math.max(size, 1);
1232
+ return arr.reduce(function(chunks, element, index) {
1233
+ var chunkIndex = Math.floor(index / chunkSize);
1234
+ if (!chunks[chunkIndex]) {
1235
+ chunks[chunkIndex] = [];
1236
+ }
1237
+ chunks[chunkIndex].push(element);
1238
+ return chunks;
1239
+ }, []);
1240
+ };
1241
+ }
1242
+ });
1243
+
1244
+ // ../../node_modules/.pnpm/@amplitude+analytics-core@2.33.0/node_modules/@amplitude/analytics-core/lib/esm/types/loglevel.js
1245
+ var LogLevel;
1246
+ var init_loglevel = __esm({
1247
+ "../../node_modules/.pnpm/@amplitude+analytics-core@2.33.0/node_modules/@amplitude/analytics-core/lib/esm/types/loglevel.js"() {
1248
+ (function(LogLevel2) {
1249
+ LogLevel2[LogLevel2["None"] = 0] = "None";
1250
+ LogLevel2[LogLevel2["Error"] = 1] = "Error";
1251
+ LogLevel2[LogLevel2["Warn"] = 2] = "Warn";
1252
+ LogLevel2[LogLevel2["Verbose"] = 3] = "Verbose";
1253
+ LogLevel2[LogLevel2["Debug"] = 4] = "Debug";
1254
+ })(LogLevel || (LogLevel = {}));
1255
+ }
1256
+ });
1257
+
1258
+ // ../../node_modules/.pnpm/@amplitude+analytics-core@2.33.0/node_modules/@amplitude/analytics-core/lib/esm/logger.js
1259
+ var PREFIX, Logger;
1260
+ var init_logger = __esm({
1261
+ "../../node_modules/.pnpm/@amplitude+analytics-core@2.33.0/node_modules/@amplitude/analytics-core/lib/esm/logger.js"() {
1262
+ init_loglevel();
1263
+ PREFIX = "Amplitude Logger ";
1264
+ Logger = /** @class */
1265
+ (function() {
1266
+ function Logger2() {
1267
+ this.logLevel = LogLevel.None;
1268
+ }
1269
+ Logger2.prototype.disable = function() {
1270
+ this.logLevel = LogLevel.None;
1271
+ };
1272
+ Logger2.prototype.enable = function(logLevel) {
1273
+ if (logLevel === void 0) {
1274
+ logLevel = LogLevel.Warn;
1275
+ }
1276
+ this.logLevel = logLevel;
1277
+ };
1278
+ Logger2.prototype.log = function() {
1279
+ var args = [];
1280
+ for (var _i = 0; _i < arguments.length; _i++) {
1281
+ args[_i] = arguments[_i];
1282
+ }
1283
+ if (this.logLevel < LogLevel.Verbose) {
1284
+ return;
1285
+ }
1286
+ console.log("".concat(PREFIX, "[Log]: ").concat(args.join(" ")));
1287
+ };
1288
+ Logger2.prototype.warn = function() {
1289
+ var args = [];
1290
+ for (var _i = 0; _i < arguments.length; _i++) {
1291
+ args[_i] = arguments[_i];
1292
+ }
1293
+ if (this.logLevel < LogLevel.Warn) {
1294
+ return;
1295
+ }
1296
+ console.warn("".concat(PREFIX, "[Warn]: ").concat(args.join(" ")));
1297
+ };
1298
+ Logger2.prototype.error = function() {
1299
+ var args = [];
1300
+ for (var _i = 0; _i < arguments.length; _i++) {
1301
+ args[_i] = arguments[_i];
1302
+ }
1303
+ if (this.logLevel < LogLevel.Error) {
1304
+ return;
1305
+ }
1306
+ console.error("".concat(PREFIX, "[Error]: ").concat(args.join(" ")));
1307
+ };
1308
+ Logger2.prototype.debug = function() {
1309
+ var args = [];
1310
+ for (var _i = 0; _i < arguments.length; _i++) {
1311
+ args[_i] = arguments[_i];
1312
+ }
1313
+ if (this.logLevel < LogLevel.Debug) {
1314
+ return;
1315
+ }
1316
+ console.log("".concat(PREFIX, "[Debug]: ").concat(args.join(" ")));
1317
+ };
1318
+ return Logger2;
1319
+ })();
1320
+ }
1321
+ });
1322
+
1323
+ // ../../node_modules/.pnpm/@amplitude+analytics-core@2.33.0/node_modules/@amplitude/analytics-core/lib/esm/config.js
1324
+ var getDefaultConfig, Config, getServerUrl, createServerConfig, RequestMetadata;
1325
+ var init_config = __esm({
1326
+ "../../node_modules/.pnpm/@amplitude+analytics-core@2.33.0/node_modules/@amplitude/analytics-core/lib/esm/config.js"() {
1327
+ init_constants();
1328
+ init_logger();
1329
+ init_loglevel();
1330
+ getDefaultConfig = function() {
1331
+ return {
1332
+ flushMaxRetries: 12,
1333
+ flushQueueSize: 200,
1334
+ flushIntervalMillis: 1e4,
1335
+ instanceName: DEFAULT_INSTANCE_NAME,
1336
+ logLevel: LogLevel.Warn,
1337
+ loggerProvider: new Logger(),
1338
+ offline: false,
1339
+ optOut: false,
1340
+ serverUrl: AMPLITUDE_SERVER_URL,
1341
+ serverZone: "US",
1342
+ useBatch: false
1343
+ };
1344
+ };
1345
+ Config = /** @class */
1346
+ (function() {
1347
+ function Config2(options) {
1348
+ var _a, _b, _c, _d;
1349
+ this._optOut = false;
1350
+ var defaultConfig = getDefaultConfig();
1351
+ this.apiKey = options.apiKey;
1352
+ this.flushIntervalMillis = (_a = options.flushIntervalMillis) !== null && _a !== void 0 ? _a : defaultConfig.flushIntervalMillis;
1353
+ this.flushMaxRetries = options.flushMaxRetries || defaultConfig.flushMaxRetries;
1354
+ this.flushQueueSize = options.flushQueueSize || defaultConfig.flushQueueSize;
1355
+ this.instanceName = options.instanceName || defaultConfig.instanceName;
1356
+ this.loggerProvider = options.loggerProvider || defaultConfig.loggerProvider;
1357
+ this.logLevel = (_b = options.logLevel) !== null && _b !== void 0 ? _b : defaultConfig.logLevel;
1358
+ this.minIdLength = options.minIdLength;
1359
+ this.plan = options.plan;
1360
+ this.ingestionMetadata = options.ingestionMetadata;
1361
+ this.offline = options.offline !== void 0 ? options.offline : defaultConfig.offline;
1362
+ this.optOut = (_c = options.optOut) !== null && _c !== void 0 ? _c : defaultConfig.optOut;
1363
+ this.serverUrl = options.serverUrl;
1364
+ this.serverZone = options.serverZone || defaultConfig.serverZone;
1365
+ this.storageProvider = options.storageProvider;
1366
+ this.transportProvider = options.transportProvider;
1367
+ this.useBatch = (_d = options.useBatch) !== null && _d !== void 0 ? _d : defaultConfig.useBatch;
1368
+ this.loggerProvider.enable(this.logLevel);
1369
+ var serverConfig = createServerConfig(options.serverUrl, options.serverZone, options.useBatch);
1370
+ this.serverZone = serverConfig.serverZone;
1371
+ this.serverUrl = serverConfig.serverUrl;
1372
+ }
1373
+ Object.defineProperty(Config2.prototype, "optOut", {
1374
+ get: function() {
1375
+ return this._optOut;
1376
+ },
1377
+ set: function(optOut) {
1378
+ this._optOut = optOut;
1379
+ },
1380
+ enumerable: false,
1381
+ configurable: true
1382
+ });
1383
+ return Config2;
1384
+ })();
1385
+ getServerUrl = function(serverZone, useBatch) {
1386
+ if (serverZone === "EU") {
1387
+ return useBatch ? EU_AMPLITUDE_BATCH_SERVER_URL : EU_AMPLITUDE_SERVER_URL;
1388
+ }
1389
+ return useBatch ? AMPLITUDE_BATCH_SERVER_URL : AMPLITUDE_SERVER_URL;
1390
+ };
1391
+ createServerConfig = function(serverUrl, serverZone, useBatch) {
1392
+ if (serverUrl === void 0) {
1393
+ serverUrl = "";
1394
+ }
1395
+ if (serverZone === void 0) {
1396
+ serverZone = getDefaultConfig().serverZone;
1397
+ }
1398
+ if (useBatch === void 0) {
1399
+ useBatch = getDefaultConfig().useBatch;
1400
+ }
1401
+ if (serverUrl) {
1402
+ return { serverUrl, serverZone: void 0 };
1403
+ }
1404
+ var _serverZone = ["US", "EU"].includes(serverZone) ? serverZone : getDefaultConfig().serverZone;
1405
+ return {
1406
+ serverZone: _serverZone,
1407
+ serverUrl: getServerUrl(_serverZone, useBatch)
1408
+ };
1409
+ };
1410
+ RequestMetadata = /** @class */
1411
+ (function() {
1412
+ function RequestMetadata2() {
1413
+ this.sdk = {
1414
+ metrics: {
1415
+ histogram: {}
1416
+ }
1417
+ };
1418
+ }
1419
+ RequestMetadata2.prototype.recordHistogram = function(key, value) {
1420
+ this.sdk.metrics.histogram[key] = value;
1421
+ };
1422
+ return RequestMetadata2;
1423
+ })();
1424
+ }
1425
+ });
1426
+
1427
+ // ../../node_modules/.pnpm/@amplitude+analytics-core@2.33.0/node_modules/@amplitude/analytics-core/lib/esm/utils/status-code.js
1428
+ function isSuccessStatusCode(code) {
1429
+ return code >= 200 && code < 300;
1430
+ }
1431
+ var init_status_code = __esm({
1432
+ "../../node_modules/.pnpm/@amplitude+analytics-core@2.33.0/node_modules/@amplitude/analytics-core/lib/esm/utils/status-code.js"() {
1433
+ }
1434
+ });
1435
+
1436
+ // ../../node_modules/.pnpm/@amplitude+analytics-core@2.33.0/node_modules/@amplitude/analytics-core/lib/esm/utils/debug.js
1437
+ var getStacktrace, getClientLogConfig, getValueByStringPath, getClientStates, debugWrapper;
1438
+ var init_debug = __esm({
1439
+ "../../node_modules/.pnpm/@amplitude+analytics-core@2.33.0/node_modules/@amplitude/analytics-core/lib/esm/utils/debug.js"() {
1440
+ init_tslib_es6();
1441
+ init_loglevel();
1442
+ getStacktrace = function(ignoreDepth) {
1443
+ if (ignoreDepth === void 0) {
1444
+ ignoreDepth = 0;
1445
+ }
1446
+ var trace = new Error().stack || "";
1447
+ return trace.split("\n").slice(2 + ignoreDepth).map(function(text) {
1448
+ return text.trim();
1449
+ });
1450
+ };
1451
+ getClientLogConfig = function(client) {
1452
+ return function() {
1453
+ var _a = __assign({}, client.config), logger = _a.loggerProvider, logLevel = _a.logLevel;
1454
+ return {
1455
+ logger,
1456
+ logLevel
1457
+ };
1458
+ };
1459
+ };
1460
+ getValueByStringPath = function(obj, path) {
1461
+ var e_1, _a;
1462
+ path = path.replace(/\[(\w+)\]/g, ".$1");
1463
+ path = path.replace(/^\./, "");
1464
+ try {
1465
+ for (var _b = __values(path.split(".")), _c = _b.next(); !_c.done; _c = _b.next()) {
1466
+ var attr = _c.value;
1467
+ if (attr in obj) {
1468
+ obj = obj[attr];
1469
+ } else {
1470
+ return;
1471
+ }
1472
+ }
1473
+ } catch (e_1_1) {
1474
+ e_1 = { error: e_1_1 };
1475
+ } finally {
1476
+ try {
1477
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
1478
+ } finally {
1479
+ if (e_1) throw e_1.error;
1480
+ }
1481
+ }
1482
+ return obj;
1483
+ };
1484
+ getClientStates = function(client, paths) {
1485
+ return function() {
1486
+ var e_2, _a;
1487
+ var res = {};
1488
+ try {
1489
+ for (var paths_1 = __values(paths), paths_1_1 = paths_1.next(); !paths_1_1.done; paths_1_1 = paths_1.next()) {
1490
+ var path = paths_1_1.value;
1491
+ res[path] = getValueByStringPath(client, path);
1492
+ }
1493
+ } catch (e_2_1) {
1494
+ e_2 = { error: e_2_1 };
1495
+ } finally {
1496
+ try {
1497
+ if (paths_1_1 && !paths_1_1.done && (_a = paths_1.return)) _a.call(paths_1);
1498
+ } finally {
1499
+ if (e_2) throw e_2.error;
1500
+ }
1501
+ }
1502
+ return res;
1503
+ };
1504
+ };
1505
+ debugWrapper = function(fn, fnName, getLogConfig, getStates, fnContext) {
1506
+ if (fnContext === void 0) {
1507
+ fnContext = null;
1508
+ }
1509
+ return function() {
1510
+ var args = [];
1511
+ for (var _i = 0; _i < arguments.length; _i++) {
1512
+ args[_i] = arguments[_i];
1513
+ }
1514
+ var _a = getLogConfig(), logger = _a.logger, logLevel = _a.logLevel;
1515
+ if (logLevel && logLevel < LogLevel.Debug || !logLevel || !logger) {
1516
+ return fn.apply(fnContext, args);
1517
+ }
1518
+ var debugContext = {
1519
+ type: "invoke public method",
1520
+ name: fnName,
1521
+ args,
1522
+ stacktrace: getStacktrace(1),
1523
+ time: {
1524
+ start: (/* @__PURE__ */ new Date()).toISOString()
1525
+ },
1526
+ states: {}
1527
+ };
1528
+ if (getStates && debugContext.states) {
1529
+ debugContext.states.before = getStates();
1530
+ }
1531
+ var result = fn.apply(fnContext, args);
1532
+ if (result && result.promise) {
1533
+ result.promise.then(function() {
1534
+ if (getStates && debugContext.states) {
1535
+ debugContext.states.after = getStates();
1536
+ }
1537
+ if (debugContext.time) {
1538
+ debugContext.time.end = (/* @__PURE__ */ new Date()).toISOString();
1539
+ }
1540
+ logger.debug(JSON.stringify(debugContext, null, 2));
1541
+ });
1542
+ } else {
1543
+ if (getStates && debugContext.states) {
1544
+ debugContext.states.after = getStates();
1545
+ }
1546
+ if (debugContext.time) {
1547
+ debugContext.time.end = (/* @__PURE__ */ new Date()).toISOString();
1548
+ }
1549
+ logger.debug(JSON.stringify(debugContext, null, 2));
1550
+ }
1551
+ return result;
1552
+ };
1553
+ };
1554
+ }
1555
+ });
1556
+
1557
+ // ../../node_modules/.pnpm/@amplitude+analytics-core@2.33.0/node_modules/@amplitude/analytics-core/lib/esm/plugins/destination.js
1558
+ function getErrorMessage(error) {
1559
+ if (error instanceof Error)
1560
+ return error.message;
1561
+ return String(error);
1562
+ }
1563
+ function getResponseBodyString(res) {
1564
+ var responseBodyString = "";
1565
+ try {
1566
+ if ("body" in res) {
1567
+ responseBodyString = JSON.stringify(res.body, null, 2);
1568
+ }
1569
+ } catch (_a) {
1570
+ }
1571
+ return responseBodyString;
1572
+ }
1573
+ var Destination;
1574
+ var init_destination = __esm({
1575
+ "../../node_modules/.pnpm/@amplitude+analytics-core@2.33.0/node_modules/@amplitude/analytics-core/lib/esm/plugins/destination.js"() {
1576
+ init_tslib_es6();
1577
+ init_status();
1578
+ init_messages();
1579
+ init_constants();
1580
+ init_chunk();
1581
+ init_result_builder();
1582
+ init_config();
1583
+ init_uuid();
1584
+ init_status_code();
1585
+ init_debug();
1586
+ Destination = /** @class */
1587
+ (function() {
1588
+ function Destination2(context) {
1589
+ this.name = "amplitude";
1590
+ this.type = "destination";
1591
+ this.retryTimeout = 1e3;
1592
+ this.throttleTimeout = 3e4;
1593
+ this.storageKey = "";
1594
+ this.scheduleId = null;
1595
+ this.scheduledTimeout = 0;
1596
+ this.flushId = null;
1597
+ this.queue = [];
1598
+ this.diagnosticsClient = context === null || context === void 0 ? void 0 : context.diagnosticsClient;
1599
+ }
1600
+ Destination2.prototype.setup = function(config) {
1601
+ var _a;
1602
+ return __awaiter(this, void 0, void 0, function() {
1603
+ var unsent;
1604
+ var _this = this;
1605
+ return __generator(this, function(_b) {
1606
+ switch (_b.label) {
1607
+ case 0:
1608
+ this.config = config;
1609
+ this.storageKey = "".concat(STORAGE_PREFIX, "_").concat(this.config.apiKey.substring(0, 10));
1610
+ return [4, (_a = this.config.storageProvider) === null || _a === void 0 ? void 0 : _a.get(this.storageKey)];
1611
+ case 1:
1612
+ unsent = _b.sent();
1613
+ if (unsent && unsent.length > 0) {
1614
+ void Promise.all(unsent.map(function(event) {
1615
+ return _this.execute(event);
1616
+ })).catch();
1617
+ }
1618
+ return [2, Promise.resolve(void 0)];
1619
+ }
1620
+ });
1621
+ });
1622
+ };
1623
+ Destination2.prototype.execute = function(event) {
1624
+ var _this = this;
1625
+ if (!event.insert_id) {
1626
+ event.insert_id = UUID();
1627
+ }
1628
+ return new Promise(function(resolve) {
1629
+ var context = {
1630
+ event,
1631
+ attempts: 0,
1632
+ callback: function(result) {
1633
+ return resolve(result);
1634
+ },
1635
+ timeout: 0
1636
+ };
1637
+ _this.queue.push(context);
1638
+ _this.schedule(_this.config.flushIntervalMillis);
1639
+ _this.saveEvents();
1640
+ });
1641
+ };
1642
+ Destination2.prototype.removeEventsExceedFlushMaxRetries = function(list) {
1643
+ var _this = this;
1644
+ return list.filter(function(context) {
1645
+ context.attempts += 1;
1646
+ if (context.attempts < _this.config.flushMaxRetries) {
1647
+ return true;
1648
+ }
1649
+ void _this.fulfillRequest([context], 500, MAX_RETRIES_EXCEEDED_MESSAGE);
1650
+ return false;
1651
+ });
1652
+ };
1653
+ Destination2.prototype.scheduleEvents = function(list) {
1654
+ var _this = this;
1655
+ list.forEach(function(context) {
1656
+ _this.schedule(context.timeout === 0 ? _this.config.flushIntervalMillis : context.timeout);
1657
+ });
1658
+ };
1659
+ Destination2.prototype.schedule = function(timeout) {
1660
+ var _this = this;
1661
+ if (this.config.offline) {
1662
+ return;
1663
+ }
1664
+ if (this.scheduleId === null || this.scheduleId && timeout > this.scheduledTimeout) {
1665
+ if (this.scheduleId) {
1666
+ clearTimeout(this.scheduleId);
1667
+ }
1668
+ this.scheduledTimeout = timeout;
1669
+ this.scheduleId = setTimeout(function() {
1670
+ _this.queue = _this.queue.map(function(context) {
1671
+ context.timeout = 0;
1672
+ return context;
1673
+ });
1674
+ void _this.flush(true);
1675
+ }, timeout);
1676
+ return;
1677
+ }
1678
+ };
1679
+ Destination2.prototype.resetSchedule = function() {
1680
+ this.scheduleId = null;
1681
+ this.scheduledTimeout = 0;
1682
+ };
1683
+ Destination2.prototype.flush = function(useRetry) {
1684
+ if (useRetry === void 0) {
1685
+ useRetry = false;
1686
+ }
1687
+ return __awaiter(this, void 0, void 0, function() {
1688
+ var list, later, batches;
1689
+ var _this = this;
1690
+ return __generator(this, function(_a) {
1691
+ switch (_a.label) {
1692
+ case 0:
1693
+ if (this.config.offline) {
1694
+ this.resetSchedule();
1695
+ this.config.loggerProvider.debug("Skipping flush while offline.");
1696
+ return [
1697
+ 2
1698
+ /*return*/
1699
+ ];
1700
+ }
1701
+ if (this.flushId) {
1702
+ this.resetSchedule();
1703
+ this.config.loggerProvider.debug("Skipping flush because previous flush has not resolved.");
1704
+ return [
1705
+ 2
1706
+ /*return*/
1707
+ ];
1708
+ }
1709
+ this.flushId = this.scheduleId;
1710
+ this.resetSchedule();
1711
+ list = [];
1712
+ later = [];
1713
+ this.queue.forEach(function(context) {
1714
+ return context.timeout === 0 ? list.push(context) : later.push(context);
1715
+ });
1716
+ batches = chunk(list, this.config.flushQueueSize);
1717
+ return [4, batches.reduce(function(promise, batch) {
1718
+ return __awaiter(_this, void 0, void 0, function() {
1719
+ return __generator(this, function(_a2) {
1720
+ switch (_a2.label) {
1721
+ case 0:
1722
+ return [4, promise];
1723
+ case 1:
1724
+ _a2.sent();
1725
+ return [4, this.send(batch, useRetry)];
1726
+ case 2:
1727
+ return [2, _a2.sent()];
1728
+ }
1729
+ });
1730
+ });
1731
+ }, Promise.resolve())];
1732
+ case 1:
1733
+ _a.sent();
1734
+ this.flushId = null;
1735
+ this.scheduleEvents(this.queue);
1736
+ return [
1737
+ 2
1738
+ /*return*/
1739
+ ];
1740
+ }
1741
+ });
1742
+ });
1743
+ };
1744
+ Destination2.prototype.send = function(list, useRetry) {
1745
+ var _a;
1746
+ if (useRetry === void 0) {
1747
+ useRetry = true;
1748
+ }
1749
+ return __awaiter(this, void 0, void 0, function() {
1750
+ var payload, serverUrl, res, e_1, errorMessage;
1751
+ return __generator(this, function(_b) {
1752
+ switch (_b.label) {
1753
+ case 0:
1754
+ if (!this.config.apiKey) {
1755
+ return [2, this.fulfillRequest(list, 400, MISSING_API_KEY_MESSAGE)];
1756
+ }
1757
+ payload = {
1758
+ api_key: this.config.apiKey,
1759
+ events: list.map(function(context) {
1760
+ var _a2 = context.event; _a2.extra; var eventWithoutExtra = __rest(_a2, ["extra"]);
1761
+ return eventWithoutExtra;
1762
+ }),
1763
+ options: {
1764
+ min_id_length: this.config.minIdLength
1765
+ },
1766
+ client_upload_time: (/* @__PURE__ */ new Date()).toISOString(),
1767
+ request_metadata: this.config.requestMetadata
1768
+ };
1769
+ this.config.requestMetadata = new RequestMetadata();
1770
+ _b.label = 1;
1771
+ case 1:
1772
+ _b.trys.push([1, 3, , 4]);
1773
+ serverUrl = createServerConfig(this.config.serverUrl, this.config.serverZone, this.config.useBatch).serverUrl;
1774
+ return [4, this.config.transportProvider.send(serverUrl, payload)];
1775
+ case 2:
1776
+ res = _b.sent();
1777
+ if (res === null) {
1778
+ this.fulfillRequest(list, 0, UNEXPECTED_ERROR_MESSAGE);
1779
+ return [
1780
+ 2
1781
+ /*return*/
1782
+ ];
1783
+ }
1784
+ if (!useRetry) {
1785
+ if ("body" in res) {
1786
+ this.fulfillRequest(list, res.statusCode, "".concat(res.status, ": ").concat(getResponseBodyString(res)));
1787
+ } else {
1788
+ this.fulfillRequest(list, res.statusCode, res.status);
1789
+ }
1790
+ return [
1791
+ 2
1792
+ /*return*/
1793
+ ];
1794
+ }
1795
+ this.handleResponse(res, list);
1796
+ return [3, 4];
1797
+ case 3:
1798
+ e_1 = _b.sent();
1799
+ errorMessage = getErrorMessage(e_1);
1800
+ this.config.loggerProvider.error(errorMessage);
1801
+ (_a = this.diagnosticsClient) === null || _a === void 0 ? void 0 : _a.recordEvent("analytics.events.unsuccessful.from.catch.error", {
1802
+ events: list.map(function(context) {
1803
+ return context.event.event_type;
1804
+ }),
1805
+ message: errorMessage,
1806
+ stack_trace: getStacktrace()
1807
+ });
1808
+ this.handleResponse({ status: Status.Failed, statusCode: 0 }, list);
1809
+ return [3, 4];
1810
+ case 4:
1811
+ return [
1812
+ 2
1813
+ /*return*/
1814
+ ];
1815
+ }
1816
+ });
1817
+ });
1818
+ };
1819
+ Destination2.prototype.handleResponse = function(res, list) {
1820
+ var _a;
1821
+ if (!isSuccessStatusCode(res.statusCode)) {
1822
+ (_a = this.diagnosticsClient) === null || _a === void 0 ? void 0 : _a.recordEvent("analytics.events.unsuccessful", {
1823
+ events: list.map(function(context) {
1824
+ return context.event.event_type;
1825
+ }),
1826
+ code: res.statusCode,
1827
+ status: res.status,
1828
+ body: getResponseBodyString(res),
1829
+ stack_trace: getStacktrace()
1830
+ });
1831
+ }
1832
+ var status = res.status;
1833
+ switch (status) {
1834
+ case Status.Success: {
1835
+ this.handleSuccessResponse(res, list);
1836
+ break;
1837
+ }
1838
+ case Status.Invalid: {
1839
+ this.handleInvalidResponse(res, list);
1840
+ break;
1841
+ }
1842
+ case Status.PayloadTooLarge: {
1843
+ this.handlePayloadTooLargeResponse(res, list);
1844
+ break;
1845
+ }
1846
+ case Status.RateLimit: {
1847
+ this.handleRateLimitResponse(res, list);
1848
+ break;
1849
+ }
1850
+ default: {
1851
+ this.config.loggerProvider.warn(`{code: 0, error: "Status '`.concat(status, "' provided for ").concat(list.length, ' events"}'));
1852
+ this.handleOtherResponse(list);
1853
+ break;
1854
+ }
1855
+ }
1856
+ };
1857
+ Destination2.prototype.handleSuccessResponse = function(res, list) {
1858
+ this.fulfillRequest(list, res.statusCode, SUCCESS_MESSAGE);
1859
+ };
1860
+ Destination2.prototype.handleInvalidResponse = function(res, list) {
1861
+ var _this = this;
1862
+ if (res.body.missingField || res.body.error.startsWith(INVALID_API_KEY)) {
1863
+ this.fulfillRequest(list, res.statusCode, res.body.error);
1864
+ return;
1865
+ }
1866
+ var dropIndex = __spreadArray(__spreadArray(__spreadArray(__spreadArray([], __read(Object.values(res.body.eventsWithInvalidFields)), false), __read(Object.values(res.body.eventsWithMissingFields)), false), __read(Object.values(res.body.eventsWithInvalidIdLengths)), false), __read(res.body.silencedEvents), false).flat();
1867
+ var dropIndexSet = new Set(dropIndex);
1868
+ var retry = list.filter(function(context, index) {
1869
+ if (dropIndexSet.has(index)) {
1870
+ _this.fulfillRequest([context], res.statusCode, res.body.error);
1871
+ return;
1872
+ }
1873
+ return true;
1874
+ });
1875
+ if (retry.length > 0) {
1876
+ this.config.loggerProvider.warn(getResponseBodyString(res));
1877
+ }
1878
+ var tryable = this.removeEventsExceedFlushMaxRetries(retry);
1879
+ this.scheduleEvents(tryable);
1880
+ };
1881
+ Destination2.prototype.handlePayloadTooLargeResponse = function(res, list) {
1882
+ if (list.length === 1) {
1883
+ this.fulfillRequest(list, res.statusCode, res.body.error);
1884
+ return;
1885
+ }
1886
+ this.config.loggerProvider.warn(getResponseBodyString(res));
1887
+ this.config.flushQueueSize /= 2;
1888
+ var tryable = this.removeEventsExceedFlushMaxRetries(list);
1889
+ this.scheduleEvents(tryable);
1890
+ };
1891
+ Destination2.prototype.handleRateLimitResponse = function(res, list) {
1892
+ var _this = this;
1893
+ var dropUserIds = Object.keys(res.body.exceededDailyQuotaUsers);
1894
+ var dropDeviceIds = Object.keys(res.body.exceededDailyQuotaDevices);
1895
+ var throttledIndex = res.body.throttledEvents;
1896
+ var dropUserIdsSet = new Set(dropUserIds);
1897
+ var dropDeviceIdsSet = new Set(dropDeviceIds);
1898
+ var throttledIndexSet = new Set(throttledIndex);
1899
+ var retry = list.filter(function(context, index) {
1900
+ if (context.event.user_id && dropUserIdsSet.has(context.event.user_id) || context.event.device_id && dropDeviceIdsSet.has(context.event.device_id)) {
1901
+ _this.fulfillRequest([context], res.statusCode, res.body.error);
1902
+ return;
1903
+ }
1904
+ if (throttledIndexSet.has(index)) {
1905
+ context.timeout = _this.throttleTimeout;
1906
+ }
1907
+ return true;
1908
+ });
1909
+ if (retry.length > 0) {
1910
+ this.config.loggerProvider.warn(getResponseBodyString(res));
1911
+ }
1912
+ var tryable = this.removeEventsExceedFlushMaxRetries(retry);
1913
+ this.scheduleEvents(tryable);
1914
+ };
1915
+ Destination2.prototype.handleOtherResponse = function(list) {
1916
+ var _this = this;
1917
+ var later = list.map(function(context) {
1918
+ context.timeout = context.attempts * _this.retryTimeout;
1919
+ return context;
1920
+ });
1921
+ var tryable = this.removeEventsExceedFlushMaxRetries(later);
1922
+ this.scheduleEvents(tryable);
1923
+ };
1924
+ Destination2.prototype.fulfillRequest = function(list, code, message) {
1925
+ var _a, _b, _c;
1926
+ if (!isSuccessStatusCode(code)) {
1927
+ (_a = this.diagnosticsClient) === null || _a === void 0 ? void 0 : _a.increment("analytics.events.dropped", list.length);
1928
+ (_b = this.diagnosticsClient) === null || _b === void 0 ? void 0 : _b.recordEvent("analytics.events.dropped", {
1929
+ events: list.map(function(context) {
1930
+ return context.event.event_type;
1931
+ }),
1932
+ code,
1933
+ message,
1934
+ stack_trace: getStacktrace()
1935
+ });
1936
+ } else {
1937
+ (_c = this.diagnosticsClient) === null || _c === void 0 ? void 0 : _c.increment("analytics.events.sent", list.length);
1938
+ }
1939
+ this.removeEvents(list);
1940
+ list.forEach(function(context) {
1941
+ return context.callback(buildResult(context.event, code, message));
1942
+ });
1943
+ };
1944
+ Destination2.prototype.saveEvents = function() {
1945
+ if (!this.config.storageProvider) {
1946
+ return;
1947
+ }
1948
+ var updatedEvents = this.queue.map(function(context) {
1949
+ return context.event;
1950
+ });
1951
+ void this.config.storageProvider.set(this.storageKey, updatedEvents);
1952
+ };
1953
+ Destination2.prototype.removeEvents = function(eventsToRemove) {
1954
+ this.queue = this.queue.filter(function(queuedContext) {
1955
+ return !eventsToRemove.some(function(context) {
1956
+ return context.event.insert_id === queuedContext.event.insert_id;
1957
+ });
1958
+ });
1959
+ this.saveEvents();
1960
+ };
1961
+ return Destination2;
1962
+ })();
1963
+ }
1964
+ });
1965
+
1966
+ // ../../node_modules/.pnpm/@amplitude+analytics-core@2.33.0/node_modules/@amplitude/analytics-core/lib/esm/transports/base.js
1967
+ var BaseTransport;
1968
+ var init_base = __esm({
1969
+ "../../node_modules/.pnpm/@amplitude+analytics-core@2.33.0/node_modules/@amplitude/analytics-core/lib/esm/transports/base.js"() {
1970
+ init_status();
1971
+ init_status_code();
1972
+ BaseTransport = /** @class */
1973
+ (function() {
1974
+ function BaseTransport2() {
1975
+ }
1976
+ BaseTransport2.prototype.send = function(_serverUrl, _payload) {
1977
+ return Promise.resolve(null);
1978
+ };
1979
+ BaseTransport2.prototype.buildResponse = function(responseJSON) {
1980
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x;
1981
+ if (typeof responseJSON !== "object") {
1982
+ return null;
1983
+ }
1984
+ var statusCode = responseJSON.code || 0;
1985
+ var status = this.buildStatus(statusCode);
1986
+ switch (status) {
1987
+ case Status.Success:
1988
+ return {
1989
+ status,
1990
+ statusCode,
1991
+ body: {
1992
+ eventsIngested: (_a = responseJSON.events_ingested) !== null && _a !== void 0 ? _a : 0,
1993
+ payloadSizeBytes: (_b = responseJSON.payload_size_bytes) !== null && _b !== void 0 ? _b : 0,
1994
+ serverUploadTime: (_c = responseJSON.server_upload_time) !== null && _c !== void 0 ? _c : 0
1995
+ }
1996
+ };
1997
+ case Status.Invalid:
1998
+ return {
1999
+ status,
2000
+ statusCode,
2001
+ body: {
2002
+ error: (_d = responseJSON.error) !== null && _d !== void 0 ? _d : "",
2003
+ missingField: (_e = responseJSON.missing_field) !== null && _e !== void 0 ? _e : "",
2004
+ eventsWithInvalidFields: (_f = responseJSON.events_with_invalid_fields) !== null && _f !== void 0 ? _f : {},
2005
+ eventsWithMissingFields: (_g = responseJSON.events_with_missing_fields) !== null && _g !== void 0 ? _g : {},
2006
+ eventsWithInvalidIdLengths: (_h = responseJSON.events_with_invalid_id_lengths) !== null && _h !== void 0 ? _h : {},
2007
+ epsThreshold: (_j = responseJSON.eps_threshold) !== null && _j !== void 0 ? _j : 0,
2008
+ exceededDailyQuotaDevices: (_k = responseJSON.exceeded_daily_quota_devices) !== null && _k !== void 0 ? _k : {},
2009
+ silencedDevices: (_l = responseJSON.silenced_devices) !== null && _l !== void 0 ? _l : [],
2010
+ silencedEvents: (_m = responseJSON.silenced_events) !== null && _m !== void 0 ? _m : [],
2011
+ throttledDevices: (_o = responseJSON.throttled_devices) !== null && _o !== void 0 ? _o : {},
2012
+ throttledEvents: (_p = responseJSON.throttled_events) !== null && _p !== void 0 ? _p : []
2013
+ }
2014
+ };
2015
+ case Status.PayloadTooLarge:
2016
+ return {
2017
+ status,
2018
+ statusCode,
2019
+ body: {
2020
+ error: (_q = responseJSON.error) !== null && _q !== void 0 ? _q : ""
2021
+ }
2022
+ };
2023
+ case Status.RateLimit:
2024
+ return {
2025
+ status,
2026
+ statusCode,
2027
+ body: {
2028
+ error: (_r = responseJSON.error) !== null && _r !== void 0 ? _r : "",
2029
+ epsThreshold: (_s = responseJSON.eps_threshold) !== null && _s !== void 0 ? _s : 0,
2030
+ throttledDevices: (_t = responseJSON.throttled_devices) !== null && _t !== void 0 ? _t : {},
2031
+ throttledUsers: (_u = responseJSON.throttled_users) !== null && _u !== void 0 ? _u : {},
2032
+ exceededDailyQuotaDevices: (_v = responseJSON.exceeded_daily_quota_devices) !== null && _v !== void 0 ? _v : {},
2033
+ exceededDailyQuotaUsers: (_w = responseJSON.exceeded_daily_quota_users) !== null && _w !== void 0 ? _w : {},
2034
+ throttledEvents: (_x = responseJSON.throttled_events) !== null && _x !== void 0 ? _x : []
2035
+ }
2036
+ };
2037
+ case Status.Timeout:
2038
+ default:
2039
+ return {
2040
+ status,
2041
+ statusCode
2042
+ };
2043
+ }
2044
+ };
2045
+ BaseTransport2.prototype.buildStatus = function(code) {
2046
+ if (isSuccessStatusCode(code)) {
2047
+ return Status.Success;
2048
+ }
2049
+ if (code === 429) {
2050
+ return Status.RateLimit;
2051
+ }
2052
+ if (code === 413) {
2053
+ return Status.PayloadTooLarge;
2054
+ }
2055
+ if (code === 408) {
2056
+ return Status.Timeout;
2057
+ }
2058
+ if (code >= 400 && code < 500) {
2059
+ return Status.Invalid;
2060
+ }
2061
+ if (code >= 500) {
2062
+ return Status.Failed;
2063
+ }
2064
+ return Status.Unknown;
2065
+ };
2066
+ return BaseTransport2;
2067
+ })();
2068
+ }
2069
+ });
2070
+
2071
+ // ../../node_modules/.pnpm/@amplitude+analytics-core@2.33.0/node_modules/@amplitude/analytics-core/lib/esm/types/server-zone.js
2072
+ var ServerZone;
2073
+ var init_server_zone = __esm({
2074
+ "../../node_modules/.pnpm/@amplitude+analytics-core@2.33.0/node_modules/@amplitude/analytics-core/lib/esm/types/server-zone.js"() {
2075
+ (function(ServerZone2) {
2076
+ ServerZone2["US"] = "US";
2077
+ ServerZone2["EU"] = "EU";
2078
+ ServerZone2["STAGING"] = "STAGING";
2079
+ })(ServerZone || (ServerZone = {}));
2080
+ }
2081
+ });
2082
+
2083
+ // ../../node_modules/.pnpm/@amplitude+analytics-core@2.33.0/node_modules/@amplitude/analytics-core/lib/esm/types/offline.js
2084
+ var OfflineDisabled;
2085
+ var init_offline = __esm({
2086
+ "../../node_modules/.pnpm/@amplitude+analytics-core@2.33.0/node_modules/@amplitude/analytics-core/lib/esm/types/offline.js"() {
2087
+ OfflineDisabled = null;
2088
+ }
2089
+ });
2090
+
2091
+ // ../../node_modules/.pnpm/@amplitude+analytics-core@2.33.0/node_modules/@amplitude/analytics-core/lib/esm/index.js
2092
+ var init_esm = __esm({
2093
+ "../../node_modules/.pnpm/@amplitude+analytics-core@2.33.0/node_modules/@amplitude/analytics-core/lib/esm/index.js"() {
2094
+ init_core_client();
2095
+ init_identify();
2096
+ init_revenue();
2097
+ init_destination();
2098
+ init_config();
2099
+ init_return_wrapper();
2100
+ init_debug();
2101
+ init_uuid();
2102
+ init_base();
2103
+ init_loglevel();
2104
+ init_event();
2105
+ init_server_zone();
2106
+ init_offline();
2107
+ }
2108
+ });
2109
+
2110
+ // ../../node_modules/.pnpm/@amplitude+analytics-node@1.5.26/node_modules/@amplitude/analytics-node/lib/esm/version.js
2111
+ var VERSION;
2112
+ var init_version = __esm({
2113
+ "../../node_modules/.pnpm/@amplitude+analytics-node@1.5.26/node_modules/@amplitude/analytics-node/lib/esm/version.js"() {
2114
+ VERSION = "1.5.26";
2115
+ }
2116
+ });
2117
+
2118
+ // ../../node_modules/.pnpm/@amplitude+analytics-node@1.5.26/node_modules/@amplitude/analytics-node/lib/esm/plugins/context.js
2119
+ var Context;
2120
+ var init_context = __esm({
2121
+ "../../node_modules/.pnpm/@amplitude+analytics-node@1.5.26/node_modules/@amplitude/analytics-node/lib/esm/plugins/context.js"() {
2122
+ init_tslib_es6();
2123
+ init_esm();
2124
+ init_version();
2125
+ Context = /** @class */
2126
+ (function() {
2127
+ function Context2() {
2128
+ this.name = "context";
2129
+ this.type = "before";
2130
+ this.eventId = 0;
2131
+ this.library = "amplitude-node-ts/".concat(VERSION);
2132
+ }
2133
+ Context2.prototype.setup = function(config) {
2134
+ this.config = config;
2135
+ return Promise.resolve(void 0);
2136
+ };
2137
+ Context2.prototype.execute = function(context) {
2138
+ var _this = this;
2139
+ return new Promise(function(resolve) {
2140
+ var time = (/* @__PURE__ */ new Date()).getTime();
2141
+ var contextEvent = __assign(__assign(__assign({ time, insert_id: UUID(), plan: _this.config.plan }, _this.config.ingestionMetadata && {
2142
+ ingestion_metadata: {
2143
+ source_name: _this.config.ingestionMetadata.sourceName,
2144
+ source_version: _this.config.ingestionMetadata.sourceVersion
2145
+ }
2146
+ }), context), { event_id: _this.eventId++, library: _this.library });
2147
+ return resolve(contextEvent);
2148
+ });
2149
+ };
2150
+ return Context2;
2151
+ })();
2152
+ }
2153
+ });
2154
+ var Http;
2155
+ var init_http = __esm({
2156
+ "../../node_modules/.pnpm/@amplitude+analytics-node@1.5.26/node_modules/@amplitude/analytics-node/lib/esm/transports/http.js"() {
2157
+ init_tslib_es6();
2158
+ init_esm();
2159
+ Http = /** @class */
2160
+ (function(_super) {
2161
+ __extends(Http2, _super);
2162
+ function Http2() {
2163
+ return _super !== null && _super.apply(this, arguments) || this;
2164
+ }
2165
+ Http2.prototype.send = function(serverUrl, payload) {
2166
+ var _this = this;
2167
+ var protocol;
2168
+ if (serverUrl.startsWith("http://")) {
2169
+ protocol = http;
2170
+ } else if (serverUrl.startsWith("https://")) {
2171
+ protocol = https;
2172
+ } else {
2173
+ throw new Error("Invalid server url");
2174
+ }
2175
+ var url = new URL(serverUrl);
2176
+ var requestPayload = JSON.stringify(payload);
2177
+ var options = {
2178
+ headers: {
2179
+ "Content-Type": "application/json",
2180
+ "Content-Length": Buffer.byteLength(requestPayload)
2181
+ },
2182
+ hostname: url.hostname,
2183
+ method: "POST",
2184
+ path: url.pathname,
2185
+ port: url.port,
2186
+ protocol: url.protocol
2187
+ };
2188
+ return new Promise(function(resolve) {
2189
+ var req = protocol.request(options, function(res) {
2190
+ res.setEncoding("utf8");
2191
+ var responsePayload = "";
2192
+ res.on("data", function(chunk2) {
2193
+ responsePayload += chunk2;
2194
+ });
2195
+ res.on("end", function() {
2196
+ if (res.complete && responsePayload.length > 0) {
2197
+ try {
2198
+ var parsedResponsePayload = JSON.parse(responsePayload);
2199
+ var result = _this.buildResponse(parsedResponsePayload);
2200
+ resolve(result);
2201
+ } catch (_a) {
2202
+ resolve(_this.buildResponse({ code: res.statusCode }));
2203
+ }
2204
+ }
2205
+ });
2206
+ });
2207
+ req.on("error", function() {
2208
+ return resolve(null);
2209
+ });
2210
+ req.end(requestPayload);
2211
+ });
2212
+ };
2213
+ return Http2;
2214
+ })(BaseTransport);
2215
+ }
2216
+ });
2217
+
2218
+ // ../../node_modules/.pnpm/@amplitude+analytics-node@1.5.26/node_modules/@amplitude/analytics-node/lib/esm/config.js
2219
+ var NodeConfig, useNodeConfig;
2220
+ var init_config2 = __esm({
2221
+ "../../node_modules/.pnpm/@amplitude+analytics-node@1.5.26/node_modules/@amplitude/analytics-node/lib/esm/config.js"() {
2222
+ init_tslib_es6();
2223
+ init_esm();
2224
+ init_http();
2225
+ NodeConfig = /** @class */
2226
+ (function(_super) {
2227
+ __extends(NodeConfig2, _super);
2228
+ function NodeConfig2(apiKey, options) {
2229
+ return _super.call(this, __assign(__assign({ transportProvider: new Http() }, options), { apiKey })) || this;
2230
+ }
2231
+ return NodeConfig2;
2232
+ })(Config);
2233
+ useNodeConfig = function(apiKey, overrides) {
2234
+ return new NodeConfig(apiKey, overrides);
2235
+ };
2236
+ }
2237
+ });
2238
+
2239
+ // ../../node_modules/.pnpm/@amplitude+analytics-node@1.5.26/node_modules/@amplitude/analytics-node/lib/esm/node-client.js
2240
+ var AmplitudeNode, createInstance, node_client_default;
2241
+ var init_node_client = __esm({
2242
+ "../../node_modules/.pnpm/@amplitude+analytics-node@1.5.26/node_modules/@amplitude/analytics-node/lib/esm/node-client.js"() {
2243
+ init_tslib_es6();
2244
+ init_esm();
2245
+ init_context();
2246
+ init_config2();
2247
+ AmplitudeNode = /** @class */
2248
+ (function(_super) {
2249
+ __extends(AmplitudeNode2, _super);
2250
+ function AmplitudeNode2() {
2251
+ return _super !== null && _super.apply(this, arguments) || this;
2252
+ }
2253
+ AmplitudeNode2.prototype.init = function(apiKey, options) {
2254
+ if (apiKey === void 0) {
2255
+ apiKey = "";
2256
+ }
2257
+ return returnWrapper(this._init(__assign(__assign({}, options), { apiKey })));
2258
+ };
2259
+ AmplitudeNode2.prototype._init = function(options) {
2260
+ return __awaiter(this, void 0, void 0, function() {
2261
+ var nodeOptions;
2262
+ return __generator(this, function(_a) {
2263
+ switch (_a.label) {
2264
+ case 0:
2265
+ if (this.initializing) {
2266
+ return [
2267
+ 2
2268
+ /*return*/
2269
+ ];
2270
+ }
2271
+ this.initializing = true;
2272
+ nodeOptions = useNodeConfig(options.apiKey, __assign({}, options));
2273
+ return [4, _super.prototype._init.call(this, nodeOptions)];
2274
+ case 1:
2275
+ _a.sent();
2276
+ return [4, this.add(new Destination()).promise];
2277
+ case 2:
2278
+ _a.sent();
2279
+ return [4, this.add(new Context()).promise];
2280
+ case 3:
2281
+ _a.sent();
2282
+ this.initializing = false;
2283
+ return [4, this.runQueuedFunctions("dispatchQ")];
2284
+ case 4:
2285
+ _a.sent();
2286
+ return [
2287
+ 2
2288
+ /*return*/
2289
+ ];
2290
+ }
2291
+ });
2292
+ });
2293
+ };
2294
+ return AmplitudeNode2;
2295
+ })(AmplitudeCore);
2296
+ createInstance = function() {
2297
+ var client = new AmplitudeNode();
2298
+ return {
2299
+ init: debugWrapper(client.init.bind(client), "init", getClientLogConfig(client), getClientStates(client, ["config"])),
2300
+ add: debugWrapper(client.add.bind(client), "add", getClientLogConfig(client), getClientStates(client, ["config.apiKey", "timeline.plugins"])),
2301
+ remove: debugWrapper(client.remove.bind(client), "remove", getClientLogConfig(client), getClientStates(client, ["config.apiKey", "timeline.plugins"])),
2302
+ track: debugWrapper(client.track.bind(client), "track", getClientLogConfig(client), getClientStates(client, ["config.apiKey", "timeline.queue.length"])),
2303
+ logEvent: debugWrapper(client.logEvent.bind(client), "logEvent", getClientLogConfig(client), getClientStates(client, ["config.apiKey", "timeline.queue.length"])),
2304
+ identify: debugWrapper(client.identify.bind(client), "identify", getClientLogConfig(client), getClientStates(client, ["config.apiKey", "timeline.queue.length"])),
2305
+ groupIdentify: debugWrapper(client.groupIdentify.bind(client), "groupIdentify", getClientLogConfig(client), getClientStates(client, ["config.apiKey", "timeline.queue.length"])),
2306
+ setGroup: debugWrapper(client.setGroup.bind(client), "setGroup", getClientLogConfig(client), getClientStates(client, ["config.apiKey", "timeline.queue.length"])),
2307
+ revenue: debugWrapper(client.revenue.bind(client), "revenue", getClientLogConfig(client), getClientStates(client, ["config.apiKey", "timeline.queue.length"])),
2308
+ flush: debugWrapper(client.flush.bind(client), "flush", getClientLogConfig(client), getClientStates(client, ["config.apiKey", "timeline.queue.length"])),
2309
+ setOptOut: debugWrapper(client.setOptOut.bind(client), "setOptOut", getClientLogConfig(client), getClientStates(client, ["config"]))
2310
+ };
2311
+ };
2312
+ node_client_default = createInstance();
2313
+ }
2314
+ });
2315
+
2316
+ // ../../node_modules/.pnpm/@amplitude+analytics-node@1.5.26/node_modules/@amplitude/analytics-node/lib/esm/types.js
2317
+ var types_exports = {};
2318
+ __export(types_exports, {
2319
+ IdentifyOperation: () => IdentifyOperation,
2320
+ LogLevel: () => LogLevel,
2321
+ OfflineDisabled: () => OfflineDisabled,
2322
+ RevenueProperty: () => RevenueProperty,
2323
+ ServerZone: () => ServerZone,
2324
+ SpecialEventType: () => SpecialEventType
2325
+ });
2326
+ var init_types = __esm({
2327
+ "../../node_modules/.pnpm/@amplitude+analytics-node@1.5.26/node_modules/@amplitude/analytics-node/lib/esm/types.js"() {
2328
+ init_esm();
2329
+ }
2330
+ });
2331
+
2332
+ // ../../node_modules/.pnpm/@amplitude+analytics-node@1.5.26/node_modules/@amplitude/analytics-node/lib/esm/index.js
2333
+ var esm_exports = {};
2334
+ __export(esm_exports, {
2335
+ Identify: () => Identify,
2336
+ Revenue: () => Revenue,
2337
+ Types: () => types_exports,
2338
+ add: () => add,
2339
+ createInstance: () => createInstance,
2340
+ flush: () => flush,
2341
+ groupIdentify: () => groupIdentify,
2342
+ identify: () => identify,
2343
+ init: () => init,
2344
+ logEvent: () => logEvent,
2345
+ remove: () => remove,
2346
+ revenue: () => revenue,
2347
+ setGroup: () => setGroup,
2348
+ setOptOut: () => setOptOut,
2349
+ track: () => track
2350
+ });
2351
+ var add, groupIdentify, identify, init, logEvent, remove, revenue, setGroup, setOptOut, track, flush;
2352
+ var init_esm2 = __esm({
2353
+ "../../node_modules/.pnpm/@amplitude+analytics-node@1.5.26/node_modules/@amplitude/analytics-node/lib/esm/index.js"() {
2354
+ init_node_client();
2355
+ init_node_client();
2356
+ init_esm();
2357
+ init_types();
2358
+ add = node_client_default.add;
2359
+ groupIdentify = node_client_default.groupIdentify;
2360
+ identify = node_client_default.identify;
2361
+ init = node_client_default.init;
2362
+ logEvent = node_client_default.logEvent;
2363
+ remove = node_client_default.remove;
2364
+ revenue = node_client_default.revenue;
2365
+ setGroup = node_client_default.setGroup;
2366
+ setOptOut = node_client_default.setOptOut;
2367
+ track = node_client_default.track;
2368
+ flush = node_client_default.flush;
2369
+ }
2370
+ });
2371
+
2372
+ // src/amplitude.ts
2373
+ var AmplitudeSubscriber = class {
2374
+ name = "AmplitudeSubscriber";
2375
+ version = "1.0.0";
2376
+ amplitude;
2377
+ enabled;
2378
+ config;
2379
+ initPromise = null;
2380
+ constructor(config) {
2381
+ this.enabled = config.enabled ?? true;
2382
+ this.config = config;
2383
+ if (this.enabled) {
2384
+ this.initPromise = this.initialize();
2385
+ }
2386
+ }
2387
+ async initialize() {
2388
+ try {
2389
+ const { init: init2 } = await Promise.resolve().then(() => (init_esm2(), esm_exports));
2390
+ this.amplitude = init2(this.config.apiKey);
2391
+ } catch (error) {
2392
+ console.error(
2393
+ "Amplitude subscriber failed to initialize. Install @amplitude/events-node: pnpm add @amplitude/events-node",
2394
+ error
2395
+ );
2396
+ this.enabled = false;
2397
+ }
2398
+ }
2399
+ async ensureInitialized() {
2400
+ if (this.initPromise) {
2401
+ await this.initPromise;
2402
+ this.initPromise = null;
2403
+ }
2404
+ }
2405
+ async trackEvent(name, attributes) {
2406
+ if (!this.enabled) return;
2407
+ await this.ensureInitialized();
2408
+ this.amplitude?.track({
2409
+ event_type: name,
2410
+ user_id: attributes?.userId || attributes?.user_id || "anonymous",
2411
+ event_properties: attributes
2412
+ });
2413
+ }
2414
+ async trackFunnelStep(funnelName, step, attributes) {
2415
+ if (!this.enabled) return;
2416
+ await this.ensureInitialized();
2417
+ this.amplitude?.trackEvent({
2418
+ event_type: `${funnelName}.${step}`,
2419
+ user_id: attributes?.userId || attributes?.user_id || "anonymous",
2420
+ event_properties: {
2421
+ funnel: funnelName,
2422
+ step,
2423
+ ...attributes
2424
+ }
2425
+ });
2426
+ }
2427
+ async trackOutcome(operationName, outcome, attributes) {
2428
+ if (!this.enabled) return;
2429
+ await this.ensureInitialized();
2430
+ this.amplitude?.trackEvent({
2431
+ event_type: `${operationName}.${outcome}`,
2432
+ user_id: attributes?.userId || attributes?.user_id || "anonymous",
2433
+ event_properties: {
2434
+ operation: operationName,
2435
+ outcome,
2436
+ ...attributes
2437
+ }
2438
+ });
2439
+ }
2440
+ async trackValue(name, value, attributes) {
2441
+ if (!this.enabled) return;
2442
+ await this.ensureInitialized();
2443
+ this.amplitude?.trackEvent({
2444
+ event_type: name,
2445
+ user_id: attributes?.userId || attributes?.user_id || "anonymous",
2446
+ event_properties: {
2447
+ value,
2448
+ ...attributes
2449
+ }
2450
+ });
2451
+ }
2452
+ /** Flush pending events before shutdown */
2453
+ async shutdown() {
2454
+ await this.ensureInitialized();
2455
+ if (this.amplitude) {
2456
+ await this.amplitude.flush();
2457
+ }
2458
+ }
2459
+ };
2460
+
2461
+ export { AmplitudeSubscriber };
2462
+ //# sourceMappingURL=amplitude.js.map
2463
+ //# sourceMappingURL=amplitude.js.map