kv-test-lib 1.0.26 → 3.3.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.

Potentially problematic release.


This version of kv-test-lib might be problematic. Click here for more details.

Files changed (70) hide show
  1. package/README.md +12 -0
  2. package/es5_dist/adapters/adapter.browser.js +3 -0
  3. package/es5_dist/adapters/adapter.browser.js.map +1 -0
  4. package/es5_dist/adapters/browser.js +117 -0
  5. package/es5_dist/adapters/browser.js.map +1 -0
  6. package/es5_dist/adapters/crypto.browser.js +11 -0
  7. package/es5_dist/adapters/crypto.browser.js.map +1 -0
  8. package/es5_dist/browser/browser.js +49 -0
  9. package/es5_dist/browser/browser.js.map +1 -0
  10. package/es5_dist/browser/cookies.js +36 -0
  11. package/es5_dist/browser/cookies.js.map +1 -0
  12. package/es5_dist/browser/persist.js +549 -0
  13. package/es5_dist/browser/persist.js.map +1 -0
  14. package/es5_dist/core/crypto.js +2 -0
  15. package/es5_dist/core/crypto.js.map +1 -0
  16. package/es5_dist/core/storage.js +2 -0
  17. package/es5_dist/core/storage.js.map +1 -0
  18. package/es5_dist/http.js +133 -0
  19. package/es5_dist/http.js.map +1 -0
  20. package/{dist → es5_dist}/interfaces.js +9 -7
  21. package/es5_dist/interfaces.js.map +1 -0
  22. package/es5_dist/jobqueue.js +484 -0
  23. package/es5_dist/jobqueue.js.map +1 -0
  24. package/es5_dist/kochava.js +790 -0
  25. package/es5_dist/kochava.js.map +1 -0
  26. package/es5_dist/measurementEvent.js +253 -0
  27. package/es5_dist/measurementEvent.js.map +1 -0
  28. package/es5_dist/payloads/event.js +192 -0
  29. package/es5_dist/payloads/event.js.map +1 -0
  30. package/es5_dist/payloads/identityLink.js +170 -0
  31. package/es5_dist/payloads/identityLink.js.map +1 -0
  32. package/es5_dist/payloads/install.js +324 -0
  33. package/es5_dist/payloads/install.js.map +1 -0
  34. package/es5_dist/payloads/kvinit.js +296 -0
  35. package/es5_dist/payloads/kvinit.js.map +1 -0
  36. package/{dist → es5_dist}/payloads/payload.js +9 -9
  37. package/es5_dist/payloads/payload.js.map +1 -0
  38. package/es5_dist/polyfills/browser.js +3 -0
  39. package/es5_dist/polyfills/browser.js.map +1 -0
  40. package/es5_dist/utils/log.js +140 -0
  41. package/es5_dist/utils/log.js.map +1 -0
  42. package/es5_dist/utils/utils.js +26 -0
  43. package/es5_dist/utils/utils.js.map +1 -0
  44. package/package.json +4 -4
  45. package/dist/browser/browser.d.ts +0 -8
  46. package/dist/browser/browser.js +0 -40
  47. package/dist/browser/cookies.d.ts +0 -3
  48. package/dist/browser/cookies.js +0 -40
  49. package/dist/browser/persist.d.ts +0 -33
  50. package/dist/browser/persist.js +0 -195
  51. package/dist/http.d.ts +0 -6
  52. package/dist/http.js +0 -23
  53. package/dist/interfaces.d.ts +0 -117
  54. package/dist/jobqueue.d.ts +0 -35
  55. package/dist/jobqueue.js +0 -220
  56. package/dist/kochava.d.ts +0 -52
  57. package/dist/kochava.js +0 -477
  58. package/dist/payloads/event.d.ts +0 -6
  59. package/dist/payloads/event.js +0 -92
  60. package/dist/payloads/identityLink.d.ts +0 -7
  61. package/dist/payloads/identityLink.js +0 -73
  62. package/dist/payloads/install.d.ts +0 -6
  63. package/dist/payloads/install.js +0 -148
  64. package/dist/payloads/kvinit.d.ts +0 -5
  65. package/dist/payloads/kvinit.js +0 -134
  66. package/dist/payloads/payload.d.ts +0 -33
  67. package/dist/utils/log.d.ts +0 -30
  68. package/dist/utils/log.js +0 -104
  69. package/dist/utils/utils.d.ts +0 -5
  70. package/dist/utils/utils.js +0 -21
@@ -0,0 +1,790 @@
1
+ var __assign = this && this.__assign || function () {
2
+ __assign = Object.assign || function (t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
6
+ }
7
+ return t;
8
+ };
9
+ return __assign.apply(this, arguments);
10
+ };
11
+ var __awaiter = this && this.__awaiter || function (thisArg, _arguments, P, generator) {
12
+ function adopt(value) {
13
+ return value instanceof P ? value : new P(function (resolve) {
14
+ resolve(value);
15
+ });
16
+ }
17
+ return new (P || (P = Promise))(function (resolve, reject) {
18
+ function fulfilled(value) {
19
+ try {
20
+ step(generator.next(value));
21
+ } catch (e) {
22
+ reject(e);
23
+ }
24
+ }
25
+ function rejected(value) {
26
+ try {
27
+ step(generator["throw"](value));
28
+ } catch (e) {
29
+ reject(e);
30
+ }
31
+ }
32
+ function step(result) {
33
+ result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
34
+ }
35
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
36
+ });
37
+ };
38
+ var __generator = this && this.__generator || function (thisArg, body) {
39
+ var _ = { label: 0, sent: function () {
40
+ if (t[0] & 1) throw t[1];return t[1];
41
+ }, trys: [], ops: [] },
42
+ f,
43
+ y,
44
+ t,
45
+ g;
46
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function () {
47
+ return this;
48
+ }), g;
49
+ function verb(n) {
50
+ return function (v) {
51
+ return step([n, v]);
52
+ };
53
+ }
54
+ function step(op) {
55
+ if (f) throw new TypeError("Generator is already executing.");
56
+ while (_) try {
57
+ 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;
58
+ if (y = 0, t) op = [op[0] & 2, t.value];
59
+ switch (op[0]) {
60
+ case 0:case 1:
61
+ t = op;break;
62
+ case 4:
63
+ _.label++;return { value: op[1], done: false };
64
+ case 5:
65
+ _.label++;y = op[1];op = [0];continue;
66
+ case 7:
67
+ op = _.ops.pop();_.trys.pop();continue;
68
+ default:
69
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
70
+ _ = 0;continue;
71
+ }
72
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
73
+ _.label = op[1];break;
74
+ }
75
+ if (op[0] === 6 && _.label < t[1]) {
76
+ _.label = t[1];t = op;break;
77
+ }
78
+ if (t && _.label < t[2]) {
79
+ _.label = t[2];_.ops.push(op);break;
80
+ }
81
+ if (t[2]) _.ops.pop();
82
+ _.trys.pop();continue;
83
+ }
84
+ op = body.call(thisArg, _);
85
+ } catch (e) {
86
+ op = [6, e];y = 0;
87
+ } finally {
88
+ f = t = 0;
89
+ }
90
+ if (op[0] & 5) throw op[1];return { value: op[0] ? op[1] : void 0, done: true };
91
+ }
92
+ };
93
+ /*
94
+ Authored by Jacob Bechler on 06/09/25.
95
+ Copyright (c) Kochava, Inc. All rights reserved.
96
+ */
97
+ import './polyfills/browser.js';
98
+ import 'whatwg-fetch';
99
+ import { Log } from "./utils/log";
100
+ import JobQueue from "./jobqueue";
101
+ import * as Kvinit from "./payloads/kvinit";
102
+ import * as Install from "./payloads/install";
103
+ import { KochavaMeasurementEvent } from "./measurementEvent";
104
+ export { KochavaMeasurementEventType } from "./measurementEvent";
105
+ import { DEFAULTS } from "./interfaces";
106
+ import { deleteAllPersisted, readAndUpdatePersistedValue, updatePersistedValue, PersistKey, checkDuplicateIdLink, addPersistedIdLinks, checkInstallIdChange, readAndUpdateSessionCount, readAndUpdateDeviceId, readAndUpdateUTM, getItem, configureStorage } from "./browser/persist";
107
+ import * as utils from "./utils/utils";
108
+ import { getPageName } from "./browser/browser";
109
+ import adapter from './adapters/adapter.browser.js';
110
+ // NOTE: Update this with new releases.
111
+ var SDK_VERSION = "3.3.0";
112
+ configureStorage(adapter);
113
+ var Kochava = /** @class */function () {
114
+ // User will use the below factories instead of directly calling
115
+ // the constructor
116
+ function Kochava() {
117
+ this._resetInstance();
118
+ this._jobQueue = new JobQueue();
119
+ }
120
+ // ============================= PUBLIC =============================== //
121
+ Kochava.create = function () {
122
+ return new Kochava();
123
+ };
124
+ Kochava.createForReactNative = function () {
125
+ var kochava = new Kochava();
126
+ kochava.executeAdvancedInstruction("wrapper", JSON.stringify({ name: "ReactNative", version: "" }));
127
+ return kochava;
128
+ };
129
+ Kochava.createForNode = function () {
130
+ var kochava = new Kochava();
131
+ kochava.executeAdvancedInstruction("wrapper", JSON.stringify({ name: "Node", version: "" }));
132
+ return kochava;
133
+ };
134
+ Kochava.createForReact = function () {
135
+ var kochava = new Kochava();
136
+ kochava.executeAdvancedInstruction("wrapper", JSON.stringify({ name: "React", version: "" }));
137
+ return kochava;
138
+ };
139
+ Kochava.createForVue = function () {
140
+ var kochava = new Kochava();
141
+ kochava.executeAdvancedInstruction("wrapper", JSON.stringify({ name: "Vue", version: "" }));
142
+ return kochava;
143
+ };
144
+ Kochava.createForAngular = function () {
145
+ var kochava = new Kochava();
146
+ kochava.executeAdvancedInstruction("wrapper", JSON.stringify({ name: "Angular", version: "1.0.0" }));
147
+ return kochava;
148
+ };
149
+ /*
150
+ Set if the SDK should also store persisted values in cookie storage.
151
+ - Not all values can be persisted in cookies, such as event/idlink queues
152
+ due to size constraints.
153
+ - true = yes use cookies
154
+ - no = no don't use cookies
155
+ - defaults to false
156
+ */
157
+ Kochava.prototype.useCookies = function (condition) {
158
+ if (condition === void 0) {
159
+ condition = false;
160
+ }
161
+ this._instance.useCookies = condition;
162
+ };
163
+ /*
164
+ - Set whether the sdk shouldn't automatically send a page or should.
165
+ - true = no auto page
166
+ - false = yes auto page
167
+ - defaults to false
168
+ */
169
+ Kochava.prototype.disableAutoPage = function (condition) {
170
+ if (condition === void 0) {
171
+ condition = false;
172
+ }
173
+ this._instance.disableAutoPage = condition;
174
+ };
175
+ Kochava.prototype.buildEventWithEventType = function (type) {
176
+ if (!type) {
177
+ Log.warn("Invalid event type, ignoring call.");
178
+ return;
179
+ }
180
+ return new KochavaMeasurementEvent(this, type);
181
+ };
182
+ Kochava.prototype.buildEventWithEventName = function (eventName) {
183
+ if (!eventName) {
184
+ Log.warn("Invalid event name, ignoring call.");
185
+ return;
186
+ }
187
+ return new KochavaMeasurementEvent(this, eventName);
188
+ };
189
+ /*
190
+ The primary means for starting the sdk.
191
+ Responsibilites:
192
+ - Checks for migrations.
193
+ - Creates the sdk instance.
194
+ - Checks for persisted state.
195
+ - Determines and sends kvinit.
196
+ - Determines and sends install.
197
+ - Optionally enqueues an auto_page.
198
+ - Starts the job queue.
199
+ */
200
+ Kochava.prototype.startWithAppGuid = function (appGuid) {
201
+ this._startWithAppGuid(appGuid);
202
+ };
203
+ Kochava.prototype._startWithAppGuid = function (appGuid) {
204
+ return __awaiter(this, void 0, void 0, function () {
205
+ return __generator(this, function (_a) {
206
+ switch (_a.label) {
207
+ case 0:
208
+ if (!appGuid) {
209
+ Log.error("Invalid appGuid ".concat(appGuid, ", start failed."));
210
+ return [2 /*return*/];
211
+ }
212
+ if (!this._instance) this._resetInstance();
213
+ if (this._instance.started) {
214
+ Log.warn("Kochava SDK already started.");
215
+ return [2 /*return*/];
216
+ }
217
+ Log.diagDebug("Host called API: Start With App Guid ".concat(appGuid));
218
+ this._instance.started = true;
219
+ return [4 /*yield*/, this._checkFirstLaunchAndMigrate()];
220
+ case 1:
221
+ _a.sent();
222
+ this._initInstance(appGuid);
223
+ if (!this._instance.disableAutoPage) this.sendPageEvent();
224
+ return [4 /*yield*/, this._checkPersistedState()];
225
+ case 2:
226
+ _a.sent();
227
+ return [4 /*yield*/, this._checkPersistedKvinit()];
228
+ case 3:
229
+ _a.sent();
230
+ this._printStartupMsgs(appGuid);
231
+ return [4 /*yield*/, this._beginStart()];
232
+ case 4:
233
+ _a.sent();
234
+ return [2 /*return*/];
235
+ }
236
+ });
237
+ });
238
+ };
239
+ /*
240
+ Primary means for stopping the sdk.
241
+ Will optionally delete all persisted data, and will shutdown the
242
+ sdk and job queue.
243
+ */
244
+ Kochava.prototype.shutdown = function (deleteData) {
245
+ this._shutdown(deleteData);
246
+ };
247
+ Kochava.prototype._shutdown = function (deleteData) {
248
+ return __awaiter(this, void 0, void 0, function () {
249
+ return __generator(this, function (_a) {
250
+ switch (_a.label) {
251
+ case 0:
252
+ Log.diagDebug("Host called API: Shutdown and ".concat(deleteData ? "delete data" : "keep data"));
253
+ if (!deleteData) return [3 /*break*/, 2];
254
+ Log.debug("Deleting persisted values");
255
+ return [4 /*yield*/, deleteAllPersisted()];
256
+ case 1:
257
+ _a.sent();
258
+ _a.label = 2;
259
+ case 2:
260
+ if (!this._instance.started) {
261
+ Log.warn("SDK already shutdown.");
262
+ }
263
+ Log.info("SDK shutting down.");
264
+ Kvinit.cancelRetries();
265
+ Install.cancelRetries();
266
+ this._jobQueue.stop();
267
+ // wipe whatever was previously in the queue
268
+ this._jobQueue = new JobQueue();
269
+ this._resetInstance();
270
+ return [2 /*return*/];
271
+ }
272
+ });
273
+ });
274
+ };
275
+ /*
276
+ Changes the current logLevel.
277
+ Options include:
278
+ - Off :: No logging whatsoever
279
+ - Error :: Only critical errors
280
+ - Warn :: Only critical errors and non-critical warnings
281
+ - Info :: High-level sdk behavior logs (default)
282
+ - Debug :: More in-depth sdk behavior logs and payload logs
283
+ - Trace :: Everything, granular detail
284
+ */
285
+ Kochava.prototype.setLogLevel = function (logLevel) {
286
+ Log.diagDebug("Host called API: Set Log Level ".concat(logLevel));
287
+ Log.setLogLevel(logLevel);
288
+ };
289
+ /*
290
+ Used internally, for special SDK behavior not utilized by a client.
291
+ Examples include:
292
+ - urls :: purposefully changing an endpoint for testing
293
+ - wrapper :: overwriting the version of a wrapper
294
+ several more ...
295
+ */
296
+ Kochava.prototype.executeAdvancedInstruction = function (key, valueStr, callback) {
297
+ Log.diagDebug("Host called API: Execute Advanced Instruction ".concat(key));
298
+ switch (key) {
299
+ case "wrapper":
300
+ {
301
+ var wrapperVersion = JSON.parse(valueStr);
302
+ if (!this._instance.version) this._instance.version = "WebTracker " + SDK_VERSION;
303
+ switch (wrapperVersion.name) {
304
+ case "Angular":
305
+ this._instance.version += " (".concat(wrapperVersion.name, " ").concat(wrapperVersion.version, ")");
306
+ break;
307
+ default:
308
+ this._instance.version += " (".concat(wrapperVersion.name, ")");
309
+ break;
310
+ }
311
+ }
312
+ break;
313
+ case "urls":
314
+ {
315
+ var overrideUrls = JSON.parse(valueStr);
316
+ if (overrideUrls.init) this._instance.overrideUrls.init = overrideUrls.init;
317
+ if (overrideUrls.event) this._instance.overrideUrls.event = overrideUrls.event;
318
+ if (overrideUrls.install) this._instance.overrideUrls.install = overrideUrls.install;
319
+ if (overrideUrls.identityLink) this._instance.overrideUrls.identityLink = overrideUrls.identityLink;
320
+ }
321
+ break;
322
+ case "urlsRestore":
323
+ {
324
+ var restoreUrls = JSON.parse(valueStr);
325
+ for (var _i = 0, restoreUrls_1 = restoreUrls; _i < restoreUrls_1.length; _i++) {
326
+ var url = restoreUrls_1[_i];
327
+ if (url === "init") this._instance.overrideUrls.init = DEFAULTS.networking.urls.init;
328
+ if (url === "event") this._instance.overrideUrls.event = DEFAULTS.networking.urls.event;
329
+ if (url === "install") this._instance.overrideUrls.install = DEFAULTS.networking.urls.install;
330
+ if (url === "identityLink") this._instance.overrideUrls.identityLink = DEFAULTS.networking.urls.identityLink;
331
+ }
332
+ }
333
+ break;
334
+ case "logFilter":
335
+ {
336
+ var disabled = JSON.parse(valueStr);
337
+ disabled.forEach(function (level) {
338
+ return Log.disableLogType(level);
339
+ });
340
+ }
341
+ break;
342
+ case "getInstance":
343
+ {
344
+ var currInstance = JSON.stringify(this._instance);
345
+ callback(currInstance);
346
+ Log.debug("capturing instance: ".concat(valueStr));
347
+ }
348
+ break;
349
+ case "logObjects":
350
+ Log.setLogObjects(JSON.parse(valueStr));
351
+ break;
352
+ default:
353
+ break;
354
+ }
355
+ };
356
+ /*
357
+ Builds and enqueues a kochava event. Must include an event_name string,
358
+ with optional event_data as either another string or object.
359
+ */
360
+ Kochava.prototype.sendEvent = function (name, data) {
361
+ this._sendEvent(name, data);
362
+ };
363
+ Kochava.prototype._sendEvent = function (name, data) {
364
+ return __awaiter(this, void 0, void 0, function () {
365
+ return __generator(this, function (_a) {
366
+ switch (_a.label) {
367
+ case 0:
368
+ Log.diagDebug("Host called API: Send Event");
369
+ if (!name) {
370
+ Log.warn("Invalid event name, ignoring call.");
371
+ return [2 /*return*/];
372
+ }
373
+ return [4 /*yield*/, this._jobQueue.enqueueEvent(this._instance, [name, data])];
374
+ case 1:
375
+ _a.sent();
376
+ return [2 /*return*/];
377
+ }
378
+ });
379
+ });
380
+ };
381
+ /*
382
+ Wraps the sendEvent call with predefined data specific to page events.
383
+ */
384
+ Kochava.prototype.sendPageEvent = function (pageName, additionalData) {
385
+ if (pageName) this.sendEvent("page", __assign({ page_name: pageName }, additionalData));else this.sendEvent("page", __assign({ page_name: getPageName() }, additionalData));
386
+ };
387
+ /*
388
+ - Registers new identity links with the sdk, either to be sent out with
389
+ the install, or standalone.
390
+ - Will update an identity link if its key already exists in storage.
391
+ - A max of 10 identity links are currently allowed to be stored
392
+ at any one time.
393
+ */
394
+ Kochava.prototype.registerIdentityLink = function (name, identifier) {
395
+ this._registerIdentityLink(name, identifier);
396
+ };
397
+ Kochava.prototype._registerIdentityLink = function (name, identifier) {
398
+ return __awaiter(this, void 0, void 0, function () {
399
+ var idLink;
400
+ return __generator(this, function (_a) {
401
+ switch (_a.label) {
402
+ case 0:
403
+ Log.diagDebug("Host called API: Register Identity Link ".concat(name));
404
+ if (!name || !identifier) {
405
+ Log.warn("Invalid identity link, ignoring call.");
406
+ return [2 /*return*/];
407
+ }
408
+ return [4 /*yield*/, checkDuplicateIdLink(name, identifier)];
409
+ case 1:
410
+ if (_a.sent()) {
411
+ Log.debug("Duplicate Identity Link found, ignoring.");
412
+ return [2 /*return*/];
413
+ }
414
+ idLink = {};
415
+ idLink[name] = identifier;
416
+ return [4 /*yield*/, addPersistedIdLinks(name, identifier, this._instance.useCookies)];
417
+ case 2:
418
+ _a.sent();
419
+ return [4 /*yield*/, getItem("com.kochava.tracker.InstallSentDate")];
420
+ case 3:
421
+ if (!_a.sent()) return [3 /*break*/, 5];
422
+ // it will be sent standalone
423
+ return [4 /*yield*/, this._jobQueue.enqueueIdLink(this._instance, idLink)];
424
+ case 4:
425
+ // it will be sent standalone
426
+ _a.sent();
427
+ _a.label = 5;
428
+ case 5:
429
+ return [2 /*return*/];
430
+ }
431
+ });
432
+ });
433
+ };
434
+ // Allows the client to attach arbitrary data to certain payloads.
435
+ Kochava.prototype.registerCustomValue = function (name, value) {
436
+ Log.diagDebug("Host called API: Register Custom Value ".concat(value ? 'setting' : 'clearing', " ").concat(name));
437
+ if (!name) {
438
+ Log.warn("Invalid custom value, ignoring call.");
439
+ return;
440
+ }
441
+ if (!value) {
442
+ this._instance.customValues = this._instance.customValues.filter(function (cv) {
443
+ return !cv.data.hasOwnProperty(name);
444
+ });
445
+ return;
446
+ }
447
+ var dataToAdorn = {};
448
+ dataToAdorn[name] = value;
449
+ this._instance.customValues.push({ data: dataToAdorn, isDeviceId: false });
450
+ };
451
+ // Allows the client to attach arbitrary identifiers to go out in the install.
452
+ Kochava.prototype.registerCustomDeviceIdentifier = function (name, value) {
453
+ Log.diagDebug("Host called API: Register Custom Device Identifier ".concat(value ? 'setting' : 'clearing', " ").concat(name));
454
+ if (!name) {
455
+ Log.warn("Invalid custom device identifier, ignoring call.");
456
+ return;
457
+ }
458
+ if (!value) {
459
+ this._instance.customValues = this._instance.customValues.filter(function (cv) {
460
+ return !cv.data.hasOwnProperty(name) || !cv.isDeviceId;
461
+ });
462
+ return;
463
+ }
464
+ var dataToAdorn = {};
465
+ dataToAdorn[name] = value;
466
+ this._instance.customValues.push({ data: dataToAdorn, isDeviceId: true });
467
+ };
468
+ /*
469
+ Returns whether or not the sdk is in a "started" state.
470
+ This basically amounts to if start has been called,
471
+ not if kvinit is done or the queue is started.
472
+ Likewise, shutdown will set "started" to false;
473
+ */
474
+ Kochava.prototype.getStarted = function () {
475
+ return this._instance.started;
476
+ };
477
+ /*
478
+ Returns the current kochavaDeviceId, or "" if called too early.
479
+ */
480
+ Kochava.prototype.getDeviceId = function () {
481
+ Log.diagDebug("Host called API: Get Kochava Device Id");
482
+ if (this._instance.started) return this._instance.kochavaDeviceId;else return "";
483
+ };
484
+ /*
485
+ Puts the sdk in a "sleep" state. This will stop the sdk from dequeuing
486
+ new jobs and retrying failed jobs. Different than shutdown, because the
487
+ current state is not destroyed.
488
+ */
489
+ Kochava.prototype.setSleep = function (sleep) {
490
+ return this._setSleep(sleep);
491
+ };
492
+ Kochava.prototype._setSleep = function (sleep) {
493
+ return __awaiter(this, void 0, void 0, function () {
494
+ return __generator(this, function (_a) {
495
+ switch (_a.label) {
496
+ case 0:
497
+ Log.diagDebug("Host called API: Sleep ".concat(sleep ? "Stop" : "Start"));
498
+ if (!(sleep && !this._instance.sleep)) return [3 /*break*/, 1];
499
+ // only pause if it was running
500
+ this._instance.sleep = sleep;
501
+ this._jobQueue.pause();
502
+ return [3 /*break*/, 3];
503
+ case 1:
504
+ if (!(!sleep && this._instance.sleep)) return [3 /*break*/, 3];
505
+ // only resume queueing if it was paused
506
+ this._instance.sleep = sleep;
507
+ return [4 /*yield*/, this._beginStart()];
508
+ case 2:
509
+ _a.sent();
510
+ _a.label = 3;
511
+ case 3:
512
+ return [2 /*return*/];
513
+ }
514
+ });
515
+ });
516
+ };
517
+ // ============================= =============================== //
518
+ // Unintialized/invalid state.
519
+ // start must be called before these values will be correct.
520
+ Kochava.prototype._resetInstance = function () {
521
+ this._instance = {
522
+ appGuid: "",
523
+ started: false,
524
+ installStarted: false,
525
+ kvinitDone: false,
526
+ installDone: false,
527
+ disableAutoPage: false,
528
+ useCookies: false,
529
+ sleep: false,
530
+ version: "",
531
+ buildDate: "",
532
+ overrideUrls: {
533
+ init: "",
534
+ install: "",
535
+ event: "",
536
+ identityLink: ""
537
+ },
538
+ customValues: [],
539
+ kochavaSession: "",
540
+ retryWaterfall: [],
541
+ startTimeMS: 0,
542
+ sdkDisabled: false,
543
+ utm: "",
544
+ installCount: 0,
545
+ kochavaDeviceId: "",
546
+ kochavaInstallId: "",
547
+ kochavaSessionCount: -1,
548
+ kochavaInstallDate: -1,
549
+ kochavaConfig: undefined
550
+ };
551
+ };
552
+ Kochava.prototype._initInstance = function (appGuid) {
553
+ // init instance with defaults
554
+ this._instance.appGuid = appGuid;
555
+ this._instance.disableAutoPage = this._instance.disableAutoPage || false;
556
+ this._instance.useCookies = this._instance.useCookies || false;
557
+ this._instance.version = this._instance.version || "WebTracker " + SDK_VERSION;
558
+ this._instance.buildDate = "kbd: 5/5/2026, 2:49:15 PM";
559
+ this._instance.kochavaSession = utils.uuidv4().substring(0, 5);
560
+ this._instance.startTimeMS = utils.getCurrTimeMS();
561
+ this._instance.retryWaterfall = [7, 30, 300, 1800];
562
+ this._instance.kochavaConfig = JSON.parse(JSON.stringify(DEFAULTS));
563
+ };
564
+ Kochava.prototype._checkFirstLaunchAndMigrate = function () {
565
+ return __awaiter(this, void 0, void 0, function () {
566
+ var firstLaunchDate, oldKvId;
567
+ return __generator(this, function (_a) {
568
+ switch (_a.label) {
569
+ case 0:
570
+ return [4 /*yield*/, readAndUpdatePersistedValue(PersistKey.FirstStartDate, this._instance.useCookies)];
571
+ case 1:
572
+ firstLaunchDate = _a.sent();
573
+ if (!!firstLaunchDate) return [3 /*break*/, 6];
574
+ return [4 /*yield*/, updatePersistedValue(PersistKey.FirstStartDate, String(utils.getCurrTimeSec()), this._instance.useCookies)];
575
+ case 2:
576
+ _a.sent();
577
+ return [4 /*yield*/, readAndUpdatePersistedValue(PersistKey.OldKvid, this._instance.useCookies)];
578
+ case 3:
579
+ oldKvId = _a.sent();
580
+ if (!oldKvId) return [3 /*break*/, 6];
581
+ return [4 /*yield*/, updatePersistedValue(PersistKey.DeviceId, oldKvId, this._instance.useCookies)];
582
+ case 4:
583
+ _a.sent();
584
+ return [4 /*yield*/, updatePersistedValue(PersistKey.InstallSentDate, JSON.stringify(utils.getCurrTimeSec()), this._instance.useCookies)];
585
+ case 5:
586
+ _a.sent();
587
+ _a.label = 6;
588
+ case 6:
589
+ return [2 /*return*/];
590
+ }
591
+ });
592
+ });
593
+ };
594
+ Kochava.prototype._checkPersistedKvinit = function () {
595
+ return __awaiter(this, void 0, void 0, function () {
596
+ var persistedKvinit, persistedKvinitStr, persistedKvinitDateStr, lastKvinitDate, refreshMin;
597
+ return __generator(this, function (_a) {
598
+ switch (_a.label) {
599
+ case 0:
600
+ persistedKvinit = {};
601
+ return [4 /*yield*/, readAndUpdatePersistedValue(PersistKey.LastKvinit, this._instance.useCookies)];
602
+ case 1:
603
+ persistedKvinitStr = _a.sent();
604
+ if (!persistedKvinitStr) return [3 /*break*/, 3];
605
+ persistedKvinit = JSON.parse(persistedKvinitStr);
606
+ if (!persistedKvinit) return [3 /*break*/, 3];
607
+ // if persisted kvinit, apply it
608
+ Log.trace("Found persisted kvinit.", persistedKvinit);
609
+ return [4 /*yield*/, Kvinit.applyKvinitResp(this._instance, persistedKvinit)];
610
+ case 2:
611
+ _a.sent();
612
+ Log.trace("KochavaConfig after persistedKvinit:", JSON.parse(JSON.stringify(this._instance.kochavaConfig)));
613
+ _a.label = 3;
614
+ case 3:
615
+ return [4 /*yield*/, readAndUpdatePersistedValue(PersistKey.KvinitSentDate, this._instance.useCookies)];
616
+ case 4:
617
+ persistedKvinitDateStr = _a.sent();
618
+ if (persistedKvinitDateStr) {
619
+ lastKvinitDate = JSON.parse(persistedKvinitDateStr);
620
+ if (lastKvinitDate) {
621
+ refreshMin = this._instance.kochavaConfig.config.refresh_minimum;
622
+ if (utils.getCurrTimeSec() - lastKvinitDate < refreshMin) this._instance.kvinitDone = true;
623
+ }
624
+ }
625
+ return [2 /*return*/];
626
+ }
627
+ });
628
+ });
629
+ };
630
+ Kochava.prototype._checkPersistedState = function () {
631
+ return __awaiter(this, void 0, void 0, function () {
632
+ var _a, _b, _c, _d, _e, installCountStr, parsedInstallCount;
633
+ return __generator(this, function (_f) {
634
+ switch (_f.label) {
635
+ case 0:
636
+ _a = this._instance;
637
+ return [4 /*yield*/, readAndUpdatePersistedValue(PersistKey.InstallSentDate, this._instance.useCookies)];
638
+ case 1:
639
+ _a.installDone = _f.sent().length > 0;
640
+ _b = this._instance;
641
+ return [4 /*yield*/, readAndUpdatePersistedValue(PersistKey.InstallId, this._instance.useCookies)];
642
+ case 2:
643
+ _b.kochavaInstallId = _f.sent();
644
+ _c = this._instance;
645
+ return [4 /*yield*/, readAndUpdateDeviceId(this._instance.useCookies)];
646
+ case 3:
647
+ _c.kochavaDeviceId = _f.sent();
648
+ _d = this._instance;
649
+ return [4 /*yield*/, readAndUpdateSessionCount(this._instance.useCookies)];
650
+ case 4:
651
+ _d.kochavaSessionCount = _f.sent();
652
+ _e = this._instance;
653
+ return [4 /*yield*/, readAndUpdateUTM(this._instance.appGuid, this._instance.useCookies)];
654
+ case 5:
655
+ _e.utm = _f.sent();
656
+ return [4 /*yield*/, readAndUpdatePersistedValue(PersistKey.InstallCount, this._instance.useCookies)];
657
+ case 6:
658
+ installCountStr = _f.sent();
659
+ parsedInstallCount = parseInt(installCountStr, 10);
660
+ this._instance.installCount = isNaN(parsedInstallCount) ? 0 : parsedInstallCount;
661
+ return [2 /*return*/];
662
+ }
663
+ });
664
+ });
665
+ };
666
+ Kochava.prototype._printStartupMsgs = function (appGuid) {
667
+ Log.diagInfo("Started SDK ".concat(this._instance.version, "\n published ").concat(this._instance.buildDate));
668
+ Log.diagInfo("The log level is set to ".concat(Log.getLogLevel()));
669
+ Log.diagDebug("This ".concat(!this._instance.installDone ? "is" : "is not", " the first tracker SDK launch"));
670
+ Log.diagDebug("The kochava device id is ".concat(this._instance.kochavaDeviceId));
671
+ Log.diagDebug("The kochava app GUID provided was ".concat(appGuid));
672
+ };
673
+ Kochava.prototype._beginStart = function () {
674
+ return __awaiter(this, void 0, void 0, function () {
675
+ return __generator(this, function (_a) {
676
+ switch (_a.label) {
677
+ case 0:
678
+ if (!!this._instance.kvinitDone) return [3 /*break*/, 2];
679
+ Log.diagDebug("A new kvinit will be sent");
680
+ return [4 /*yield*/, this.performNewKvinit()];
681
+ case 1:
682
+ _a.sent();
683
+ return [3 /*break*/, 3];
684
+ case 2:
685
+ Log.diagDebug("A new kvinit will not be sent");
686
+ _a.label = 3;
687
+ case 3:
688
+ return [4 /*yield*/, this.checkResendId()];
689
+ case 4:
690
+ // if the install_id changed and thus a new install must go out
691
+ if (_a.sent()) this._instance.installDone = false;
692
+ Log.diagDebug("The install ".concat(this._instance.installDone ? "has already" : "has not yet", " been sent"));
693
+ if (this._instance.sleep) return [2 /*return*/];
694
+ if (!!this._instance.installDone) return [3 /*break*/, 6];
695
+ return [4 /*yield*/, this.performInstall()];
696
+ case 5:
697
+ _a.sent();
698
+ _a.label = 6;
699
+ case 6:
700
+ if (!(this._instance.kvinitDone && this._instance.installDone)) return [3 /*break*/, 8];
701
+ return [4 /*yield*/, this._jobQueue.start(this._instance)];
702
+ case 7:
703
+ _a.sent();
704
+ _a.label = 8;
705
+ case 8:
706
+ return [2 /*return*/];
707
+ }
708
+ });
709
+ });
710
+ };
711
+ Kochava.prototype.performNewKvinit = function () {
712
+ return __awaiter(this, void 0, void 0, function () {
713
+ var _a, newKvinit, newKvinitStr;
714
+ return __generator(this, function (_b) {
715
+ switch (_b.label) {
716
+ case 0:
717
+ _a = this._instance;
718
+ return [4 /*yield*/, Kvinit.send(this._instance, this._instance.retryWaterfall)];
719
+ case 1:
720
+ _a.kvinitDone = _b.sent();
721
+ return [4 /*yield*/, updatePersistedValue(PersistKey.KvinitSentDate, String(utils.getCurrTimeSec()), this._instance.useCookies)];
722
+ case 2:
723
+ _b.sent();
724
+ newKvinit = {};
725
+ return [4 /*yield*/, readAndUpdatePersistedValue(PersistKey.LastKvinit, this._instance.useCookies)];
726
+ case 3:
727
+ newKvinitStr = _b.sent();
728
+ if (newKvinitStr) {
729
+ newKvinit = JSON.parse(newKvinitStr);
730
+ }
731
+ return [4 /*yield*/, Kvinit.applyKvinitResp(this._instance, newKvinit)];
732
+ case 4:
733
+ _b.sent();
734
+ Log.trace("KochavaConfig after new Kvinit:", JSON.parse(JSON.stringify(this._instance.kochavaConfig)));
735
+ return [2 /*return*/];
736
+ }
737
+ });
738
+ });
739
+ };
740
+ Kochava.prototype.checkResendId = function () {
741
+ return __awaiter(this, void 0, void 0, function () {
742
+ var resendId, needsNewInstall;
743
+ return __generator(this, function (_a) {
744
+ switch (_a.label) {
745
+ case 0:
746
+ resendId = "";
747
+ if (this._instance.kochavaConfig.install) {
748
+ resendId = this._instance.kochavaConfig.install.resend_id;
749
+ }
750
+ return [4 /*yield*/, checkInstallIdChange(resendId, this._instance.useCookies)];
751
+ case 1:
752
+ needsNewInstall = _a.sent();
753
+ if (needsNewInstall) {
754
+ Log.debug("resend_id ".concat(resendId, " found, forcing new install"));
755
+ }
756
+ return [2 /*return*/, needsNewInstall];
757
+ }
758
+ });
759
+ });
760
+ };
761
+ Kochava.prototype.performInstall = function () {
762
+ return __awaiter(this, void 0, void 0, function () {
763
+ var request, _a;
764
+ return __generator(this, function (_b) {
765
+ switch (_b.label) {
766
+ case 0:
767
+ return [4 /*yield*/, Install.build(this._instance)];
768
+ case 1:
769
+ request = _b.sent();
770
+ _a = this._instance;
771
+ return [4 /*yield*/, Install.send(this._instance, request)];
772
+ case 2:
773
+ _a.installDone = _b.sent();
774
+ if (!this._instance.installDone) return [2 /*return*/];
775
+ // If the install succeeded, remove all idLink that were passed to it
776
+ Install.onSuccess(this._instance);
777
+ return [4 /*yield*/, this._jobQueue.persistIdLinkQueue()];
778
+ case 3:
779
+ _b.sent();
780
+ return [2 /*return*/];
781
+ }
782
+ });
783
+ });
784
+ };
785
+ return Kochava;
786
+ }();
787
+ export { Kochava };
788
+ // Only here for generic Web integration
789
+ window.kochava = Kochava.create();
790
+ //# sourceMappingURL=kochava.js.map