kv-test-lib 1.0.3 → 1.0.5

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 (43) hide show
  1. package/dist/browser/browser.js +9 -13
  2. package/dist/browser/browser.js.map +1 -0
  3. package/dist/browser/cookies.js +7 -17
  4. package/dist/browser/cookies.js.map +1 -0
  5. package/dist/browser/persist.js +22 -49
  6. package/dist/browser/persist.js.map +1 -0
  7. package/dist/http.js +5 -4
  8. package/dist/http.js.map +1 -0
  9. package/dist/interfaces.js +7 -6
  10. package/dist/interfaces.js.map +1 -0
  11. package/dist/jobqueue.js +12 -21
  12. package/dist/jobqueue.js.map +1 -0
  13. package/dist/kochava.js +193 -216
  14. package/dist/kochava.js.map +1 -0
  15. package/dist/payloads/event.js +11 -16
  16. package/dist/payloads/event.js.map +1 -0
  17. package/dist/payloads/identityLink.js +9 -13
  18. package/dist/payloads/identityLink.js.map +1 -0
  19. package/dist/payloads/install.js +22 -24
  20. package/dist/payloads/install.js.map +1 -0
  21. package/dist/payloads/kvinit.js +17 -22
  22. package/dist/payloads/kvinit.js.map +1 -0
  23. package/dist/payloads/payload.js +5 -5
  24. package/dist/payloads/payload.js.map +1 -0
  25. package/dist/utils/log.js +10 -16
  26. package/dist/utils/log.js.map +1 -0
  27. package/dist/utils/utils.js +4 -6
  28. package/dist/utils/utils.js.map +1 -0
  29. package/package.json +1 -1
  30. package/dist/browser/browser.d.ts +0 -8
  31. package/dist/browser/cookies.d.ts +0 -3
  32. package/dist/browser/persist.d.ts +0 -33
  33. package/dist/http.d.ts +0 -6
  34. package/dist/interfaces.d.ts +0 -117
  35. package/dist/jobqueue.d.ts +0 -35
  36. package/dist/kochava.d.ts +0 -52
  37. package/dist/payloads/event.d.ts +0 -6
  38. package/dist/payloads/identityLink.d.ts +0 -7
  39. package/dist/payloads/install.d.ts +0 -6
  40. package/dist/payloads/kvinit.d.ts +0 -5
  41. package/dist/payloads/payload.d.ts +0 -33
  42. package/dist/utils/log.d.ts +0 -30
  43. package/dist/utils/utils.d.ts +0 -5
package/dist/kochava.js CHANGED
@@ -2,35 +2,25 @@
2
2
  Authored by Brett Barinaga on 11/17/21.
3
3
  Copyright (c) Kochava, Inc. All rights reserved.
4
4
  */
5
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
6
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
7
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
8
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
9
- };
10
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
11
- if (kind === "m") throw new TypeError("Private method is not writable");
12
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
13
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
14
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
15
- };
16
- var _Kochava_instances, _Kochava_instance, _Kochava_jobQueue, _Kochava_resetInstance, _Kochava_initInstance, _Kochava_checkFirstLaunchAndMigrate, _Kochava_checkPersistedKvinit, _Kochava_checkPersistedState, _Kochava_printStartupMsgs, _Kochava_beginStart, _Kochava_performNewKvinit, _Kochava_checkResendId, _Kochava_performInstall;
5
+ import 'core-js/stable';
6
+ import 'regenerator-runtime/runtime';
7
+ import 'whatwg-fetch';
17
8
  import { Log } from "./utils/log";
18
9
  import JobQueue from "./jobqueue";
19
10
  import * as Kvinit from "./payloads/kvinit";
20
11
  import * as Install from "./payloads/install";
21
- import { DEFAULTS, } from "./interfaces";
22
- import { deleteAllPersisted, readAndUpdatePersistedValue, updatePersistedValue, PersistKey, checkDuplicateIdLink, addPersistedIdLinks, checkInstallIdChange, readAndUpdateSessionCount, readAndUpdateDeviceId, readAndUpdateUTM, } from "./browser/persist";
12
+ import { DEFAULTS } from "./interfaces";
13
+ import { deleteAllPersisted, readAndUpdatePersistedValue, updatePersistedValue, PersistKey, checkDuplicateIdLink, addPersistedIdLinks, checkInstallIdChange, readAndUpdateSessionCount, readAndUpdateDeviceId, readAndUpdateUTM } from "./browser/persist";
23
14
  import * as utils from "./utils/utils";
24
15
  import { getPageName } from "./browser/browser";
16
+ // NOTE: Update this with new releases.
17
+ const SDK_VERSION = "3.1.0";
25
18
  export class Kochava {
26
19
  // User will use the below factories instead of directly calling
27
20
  // the constructor
28
21
  constructor() {
29
- _Kochava_instances.add(this);
30
- _Kochava_instance.set(this, void 0);
31
- _Kochava_jobQueue.set(this, void 0);
32
- __classPrivateFieldGet(this, _Kochava_instances, "m", _Kochava_resetInstance).call(this);
33
- __classPrivateFieldSet(this, _Kochava_jobQueue, new JobQueue(), "f");
22
+ this.resetInstance();
23
+ this.jobQueue = new JobQueue();
34
24
  }
35
25
  // ============================= PUBLIC =============================== //
36
26
  static create() {
@@ -65,7 +55,7 @@ export class Kochava {
65
55
  - defaults to false
66
56
  */
67
57
  useCookies(condition = false) {
68
- __classPrivateFieldGet(this, _Kochava_instance, "f").useCookies = condition;
58
+ this.instance.useCookies = condition;
69
59
  }
70
60
  /*
71
61
  - Set whether the sdk shouldn't automatically send a page or should.
@@ -74,7 +64,7 @@ export class Kochava {
74
64
  - defaults to false
75
65
  */
76
66
  disableAutoPage(condition = false) {
77
- __classPrivateFieldGet(this, _Kochava_instance, "f").disableAutoPage = condition;
67
+ this.instance.disableAutoPage = condition;
78
68
  }
79
69
  /*
80
70
  The primary means for starting the sdk.
@@ -92,22 +82,20 @@ export class Kochava {
92
82
  Log.error(`Invalid appGuid ${appGuid}, start failed.`);
93
83
  return;
94
84
  }
95
- if (!__classPrivateFieldGet(this, _Kochava_instance, "f"))
96
- __classPrivateFieldGet(this, _Kochava_instances, "m", _Kochava_resetInstance).call(this);
97
- if (__classPrivateFieldGet(this, _Kochava_instance, "f").started) {
85
+ if (!this.instance) this.resetInstance();
86
+ if (this.instance.started) {
98
87
  Log.warn("Kochava SDK already started.");
99
88
  return;
100
89
  }
101
90
  Log.diagDebug(`Host called API: Start With App Guid ${appGuid}`);
102
- __classPrivateFieldGet(this, _Kochava_instance, "f").started = true;
103
- __classPrivateFieldGet(this, _Kochava_instances, "m", _Kochava_checkFirstLaunchAndMigrate).call(this);
104
- __classPrivateFieldGet(this, _Kochava_instances, "m", _Kochava_initInstance).call(this, appGuid);
105
- if (!__classPrivateFieldGet(this, _Kochava_instance, "f").disableAutoPage)
106
- this.sendPageEvent();
107
- __classPrivateFieldGet(this, _Kochava_instances, "m", _Kochava_checkPersistedState).call(this);
108
- __classPrivateFieldGet(this, _Kochava_instances, "m", _Kochava_checkPersistedKvinit).call(this);
109
- __classPrivateFieldGet(this, _Kochava_instances, "m", _Kochava_printStartupMsgs).call(this, appGuid);
110
- __classPrivateFieldGet(this, _Kochava_instances, "m", _Kochava_beginStart).call(this);
91
+ this.instance.started = true;
92
+ this.checkFirstLaunchAndMigrate();
93
+ this.initInstance(appGuid);
94
+ if (!this.instance.disableAutoPage) this.sendPageEvent();
95
+ this.checkPersistedState();
96
+ this.checkPersistedKvinit();
97
+ this.printStartupMsgs(appGuid);
98
+ this.beginStart();
111
99
  }
112
100
  /*
113
101
  Primary means for stopping the sdk.
@@ -120,16 +108,16 @@ export class Kochava {
120
108
  Log.debug("Deleting persisted values");
121
109
  deleteAllPersisted();
122
110
  }
123
- if (!__classPrivateFieldGet(this, _Kochava_instance, "f").started) {
111
+ if (!this.instance.started) {
124
112
  Log.warn("SDK already shutdown.");
125
113
  }
126
114
  Log.info("SDK shutting down.");
127
115
  Kvinit.cancelRetries();
128
116
  Install.cancelRetries();
129
- __classPrivateFieldGet(this, _Kochava_jobQueue, "f").stop();
117
+ this.jobQueue.stop();
130
118
  // wipe whatever was previously in the queue
131
- __classPrivateFieldSet(this, _Kochava_jobQueue, new JobQueue(), "f");
132
- __classPrivateFieldGet(this, _Kochava_instances, "m", _Kochava_resetInstance).call(this);
119
+ this.jobQueue = new JobQueue();
120
+ this.resetInstance();
133
121
  }
134
122
  /*
135
123
  Changes the current logLevel.
@@ -158,14 +146,13 @@ export class Kochava {
158
146
  case "wrapper":
159
147
  {
160
148
  const wrapperVersion = JSON.parse(valueStr);
161
- if (!__classPrivateFieldGet(this, _Kochava_instance, "f").version)
162
- __classPrivateFieldGet(this, _Kochava_instance, "f").version = "WebTracker 3.0.0";
149
+ if (!this.instance.version) this.instance.version = "WebTracker " + SDK_VERSION;
163
150
  switch (wrapperVersion.name) {
164
151
  case "Angular":
165
- __classPrivateFieldGet(this, _Kochava_instance, "f").version += ` (${wrapperVersion.name} ${wrapperVersion.version})`;
152
+ this.instance.version += ` (${wrapperVersion.name} ${wrapperVersion.version})`;
166
153
  break;
167
154
  default:
168
- __classPrivateFieldGet(this, _Kochava_instance, "f").version += ` (${wrapperVersion.name})`;
155
+ this.instance.version += ` (${wrapperVersion.name})`;
169
156
  break;
170
157
  }
171
158
  }
@@ -173,42 +160,32 @@ export class Kochava {
173
160
  case "urls":
174
161
  {
175
162
  const overrideUrls = JSON.parse(valueStr);
176
- if (overrideUrls.init)
177
- __classPrivateFieldGet(this, _Kochava_instance, "f").overrideUrls.init = overrideUrls.init;
178
- if (overrideUrls.event)
179
- __classPrivateFieldGet(this, _Kochava_instance, "f").overrideUrls.event = overrideUrls.event;
180
- if (overrideUrls.install)
181
- __classPrivateFieldGet(this, _Kochava_instance, "f").overrideUrls.install = overrideUrls.install;
182
- if (overrideUrls.identityLink)
183
- __classPrivateFieldGet(this, _Kochava_instance, "f").overrideUrls.identityLink = overrideUrls.identityLink;
163
+ if (overrideUrls.init) this.instance.overrideUrls.init = overrideUrls.init;
164
+ if (overrideUrls.event) this.instance.overrideUrls.event = overrideUrls.event;
165
+ if (overrideUrls.install) this.instance.overrideUrls.install = overrideUrls.install;
166
+ if (overrideUrls.identityLink) this.instance.overrideUrls.identityLink = overrideUrls.identityLink;
184
167
  }
185
168
  break;
186
169
  case "urlsRestore":
187
170
  {
188
171
  const restoreUrls = JSON.parse(valueStr);
189
172
  for (const url of restoreUrls) {
190
- if (url === "init")
191
- __classPrivateFieldGet(this, _Kochava_instance, "f").overrideUrls.init = DEFAULTS.networking.urls.init;
192
- if (url === "event")
193
- __classPrivateFieldGet(this, _Kochava_instance, "f").overrideUrls.event = DEFAULTS.networking.urls.event;
194
- if (url === "install")
195
- __classPrivateFieldGet(this, _Kochava_instance, "f").overrideUrls.install =
196
- DEFAULTS.networking.urls.install;
197
- if (url === "identityLink")
198
- __classPrivateFieldGet(this, _Kochava_instance, "f").overrideUrls.identityLink =
199
- DEFAULTS.networking.urls.identityLink;
173
+ if (url === "init") this.instance.overrideUrls.init = DEFAULTS.networking.urls.init;
174
+ if (url === "event") this.instance.overrideUrls.event = DEFAULTS.networking.urls.event;
175
+ if (url === "install") this.instance.overrideUrls.install = DEFAULTS.networking.urls.install;
176
+ if (url === "identityLink") this.instance.overrideUrls.identityLink = DEFAULTS.networking.urls.identityLink;
200
177
  }
201
178
  }
202
179
  break;
203
180
  case "logFilter":
204
181
  {
205
182
  const disabled = JSON.parse(valueStr);
206
- disabled.forEach((level) => Log.disableLogType(level));
183
+ disabled.forEach(level => Log.disableLogType(level));
207
184
  }
208
185
  break;
209
186
  case "getInstance":
210
187
  {
211
- const currInstance = JSON.stringify(__classPrivateFieldGet(this, _Kochava_instance, "f"));
188
+ const currInstance = JSON.stringify(this.instance);
212
189
  callback(currInstance);
213
190
  Log.debug(`capturing instance: ${valueStr}`);
214
191
  }
@@ -230,16 +207,13 @@ export class Kochava {
230
207
  Log.warn("Invalid event name, ignoring call.");
231
208
  return;
232
209
  }
233
- __classPrivateFieldGet(this, _Kochava_jobQueue, "f").enqueueEvent(__classPrivateFieldGet(this, _Kochava_instance, "f"), [name, data]);
210
+ this.jobQueue.enqueueEvent(this.instance, [name, data]);
234
211
  }
235
212
  /*
236
213
  Wraps the sendEvent call with predefined data specific to page events.
237
214
  */
238
215
  sendPageEvent(pageName, additionalData) {
239
- if (pageName)
240
- this.sendEvent("page", Object.assign({ page_name: pageName }, additionalData));
241
- else
242
- this.sendEvent("page", Object.assign({ page_name: getPageName() }, additionalData));
216
+ if (pageName) this.sendEvent("page", Object.assign({ page_name: pageName }, additionalData));else this.sendEvent("page", Object.assign({ page_name: getPageName() }, additionalData));
243
217
  }
244
218
  /*
245
219
  - Registers new identity links with the sdk, either to be sent out with
@@ -260,11 +234,11 @@ export class Kochava {
260
234
  }
261
235
  const idLink = {};
262
236
  idLink[name] = identifier;
263
- addPersistedIdLinks(name, identifier, __classPrivateFieldGet(this, _Kochava_instance, "f").useCookies);
264
- // if (this.#instance.installStarted || this.#instance.installDone) {
237
+ addPersistedIdLinks(name, identifier, this.instance.useCookies);
238
+ // if (this.instance.installStarted || this.instance.installDone) {
265
239
  if (localStorage.getItem("com.kochava.tracker.InstallSentDate")) {
266
240
  // it will be sent standalone
267
- __classPrivateFieldGet(this, _Kochava_jobQueue, "f").enqueueIdLink(__classPrivateFieldGet(this, _Kochava_instance, "f"), idLink);
241
+ this.jobQueue.enqueueIdLink(this.instance, idLink);
268
242
  }
269
243
  // will be sent in install
270
244
  }
@@ -277,7 +251,7 @@ export class Kochava {
277
251
  }
278
252
  const dataToAdorn = {};
279
253
  dataToAdorn[name] = value;
280
- __classPrivateFieldGet(this, _Kochava_instance, "f").customValues.push({ data: dataToAdorn, isDeviceId: false });
254
+ this.instance.customValues.push({ data: dataToAdorn, isDeviceId: false });
281
255
  }
282
256
  // Allows the client to attach arbitrary identifiers to go out in the install.
283
257
  registerCustomDeviceIdentifier(name, value) {
@@ -288,7 +262,7 @@ export class Kochava {
288
262
  }
289
263
  const dataToAdorn = {};
290
264
  dataToAdorn[name] = value;
291
- __classPrivateFieldGet(this, _Kochava_instance, "f").customValues.push({ data: dataToAdorn, isDeviceId: true });
265
+ this.instance.customValues.push({ data: dataToAdorn, isDeviceId: true });
292
266
  }
293
267
  /*
294
268
  Returns whether or not the sdk is in a "started" state.
@@ -297,17 +271,14 @@ export class Kochava {
297
271
  Likewise, shutdown will set "started" to false;
298
272
  */
299
273
  getStarted() {
300
- return __classPrivateFieldGet(this, _Kochava_instance, "f").started;
274
+ return this.instance.started;
301
275
  }
302
276
  /*
303
277
  Returns the current kochavaDeviceId, or "" if called too early.
304
278
  */
305
279
  getDeviceId() {
306
280
  Log.diagDebug(`Host called API: Get Kochava Device Id`);
307
- if (__classPrivateFieldGet(this, _Kochava_instance, "f").started)
308
- return __classPrivateFieldGet(this, _Kochava_instance, "f").kochavaDeviceId;
309
- else
310
- return "";
281
+ if (this.instance.started) return this.instance.kochavaDeviceId;else return "";
311
282
  }
312
283
  /*
313
284
  Puts the sdk in a "sleep" state. This will stop the sdk from dequeuing
@@ -316,160 +287,166 @@ export class Kochava {
316
287
  */
317
288
  setSleep(sleep) {
318
289
  Log.diagDebug(`Host called API: Sleep ${sleep ? "Stop" : "Start"}`);
319
- if (sleep && !__classPrivateFieldGet(this, _Kochava_instance, "f").sleep) {
290
+ if (sleep && !this.instance.sleep) {
320
291
  // only pause if it was running
321
- __classPrivateFieldGet(this, _Kochava_instance, "f").sleep = sleep;
322
- __classPrivateFieldGet(this, _Kochava_jobQueue, "f").pause();
323
- }
324
- else if (!sleep && __classPrivateFieldGet(this, _Kochava_instance, "f").sleep) {
292
+ this.instance.sleep = sleep;
293
+ this.jobQueue.pause();
294
+ } else if (!sleep && this.instance.sleep) {
325
295
  // only resume queueing if it was paused
326
- __classPrivateFieldGet(this, _Kochava_instance, "f").sleep = sleep;
327
- __classPrivateFieldGet(this, _Kochava_instances, "m", _Kochava_beginStart).call(this);
296
+ this.instance.sleep = sleep;
297
+ this.beginStart();
328
298
  }
329
299
  }
330
- }
331
- _Kochava_instance = new WeakMap(), _Kochava_jobQueue = new WeakMap(), _Kochava_instances = new WeakSet(), _Kochava_resetInstance = function _Kochava_resetInstance() {
332
- __classPrivateFieldSet(this, _Kochava_instance, {
333
- appGuid: "",
334
- started: false,
335
- installStarted: false,
336
- kvinitDone: false,
337
- installDone: false,
338
- disableAutoPage: false,
339
- useCookies: false,
340
- sleep: false,
341
- version: "",
342
- buildDate: "",
343
- overrideUrls: {
344
- init: "",
345
- install: "",
346
- event: "",
347
- identityLink: "",
348
- },
349
- customValues: [],
350
- kochavaSession: "",
351
- retryWaterfall: [],
352
- startTimeMS: 0,
353
- utm: "",
354
- kochavaDeviceId: "",
355
- kochavaInstallId: "",
356
- kochavaSessionCount: -1,
357
- kochavaInstallDate: -1,
358
- kochavaConfig: undefined,
359
- }, "f");
360
- }, _Kochava_initInstance = function _Kochava_initInstance(appGuid) {
361
- // init instance with defaults
362
- __classPrivateFieldGet(this, _Kochava_instance, "f").appGuid = appGuid;
363
- __classPrivateFieldGet(this, _Kochava_instance, "f").disableAutoPage = __classPrivateFieldGet(this, _Kochava_instance, "f").disableAutoPage || false;
364
- __classPrivateFieldGet(this, _Kochava_instance, "f").useCookies = __classPrivateFieldGet(this, _Kochava_instance, "f").useCookies || false;
365
- __classPrivateFieldGet(this, _Kochava_instance, "f").version = __classPrivateFieldGet(this, _Kochava_instance, "f").version || "WebTracker 3.0.0";
366
- __classPrivateFieldGet(this, _Kochava_instance, "f").buildDate = "kbd: 7/12/2022, 9:10:58 AM";
367
- __classPrivateFieldGet(this, _Kochava_instance, "f").kochavaSession = utils.uuidv4().substring(0, 5);
368
- __classPrivateFieldGet(this, _Kochava_instance, "f").startTimeMS = utils.getCurrTimeMS();
369
- __classPrivateFieldGet(this, _Kochava_instance, "f").retryWaterfall = [7, 30, 300, 1800];
370
- __classPrivateFieldGet(this, _Kochava_instance, "f").kochavaConfig = JSON.parse(JSON.stringify(DEFAULTS));
371
- }, _Kochava_checkFirstLaunchAndMigrate = function _Kochava_checkFirstLaunchAndMigrate() {
372
- // If this is our first launch ever, set it in persistence.
373
- if (!readAndUpdatePersistedValue(PersistKey.FirstStartDate, __classPrivateFieldGet(this, _Kochava_instance, "f").useCookies)) {
374
- updatePersistedValue(PersistKey.FirstStartDate, String(utils.getCurrTimeSec()), __classPrivateFieldGet(this, _Kochava_instance, "f").useCookies);
375
- /*
376
- On a first launch of the v3 sdk, we need to migrate old persisted kv_id
377
- from v2.2, v2.3, and v2.5
378
- */
379
- // perform migration
380
- const oldKvId = readAndUpdatePersistedValue(PersistKey.OldKvid, __classPrivateFieldGet(this, _Kochava_instance, "f").useCookies);
381
- if (oldKvId) {
382
- updatePersistedValue(PersistKey.DeviceId, oldKvId, __classPrivateFieldGet(this, _Kochava_instance, "f").useCookies);
383
- updatePersistedValue(PersistKey.InstallSentDate, JSON.stringify(utils.getCurrTimeSec()), __classPrivateFieldGet(this, _Kochava_instance, "f").useCookies);
384
- }
300
+ // ============================= =============================== //
301
+ // Unintialized/invalid state.
302
+ // start must be called before these values will be correct.
303
+ resetInstance() {
304
+ this.instance = {
305
+ appGuid: "",
306
+ started: false,
307
+ installStarted: false,
308
+ kvinitDone: false,
309
+ installDone: false,
310
+ disableAutoPage: false,
311
+ useCookies: false,
312
+ sleep: false,
313
+ version: "",
314
+ buildDate: "",
315
+ overrideUrls: {
316
+ init: "",
317
+ install: "",
318
+ event: "",
319
+ identityLink: ""
320
+ },
321
+ customValues: [],
322
+ kochavaSession: "",
323
+ retryWaterfall: [],
324
+ startTimeMS: 0,
325
+ utm: "",
326
+ kochavaDeviceId: "",
327
+ kochavaInstallId: "",
328
+ kochavaSessionCount: -1,
329
+ kochavaInstallDate: -1,
330
+ kochavaConfig: undefined
331
+ };
385
332
  }
386
- }, _Kochava_checkPersistedKvinit = function _Kochava_checkPersistedKvinit() {
387
- // check if persisted kvinit
388
- let persistedKvinit = {};
389
- const persistedKvinitStr = readAndUpdatePersistedValue(PersistKey.LastKvinit, __classPrivateFieldGet(this, _Kochava_instance, "f").useCookies);
390
- if (persistedKvinitStr) {
391
- persistedKvinit = JSON.parse(persistedKvinitStr);
392
- if (persistedKvinit) {
393
- // if persisted kvinit, apply it
394
- Log.trace("Found persisted kvinit.", persistedKvinit);
395
- Kvinit.applyKvinitResp(__classPrivateFieldGet(this, _Kochava_instance, "f"), persistedKvinit);
396
- Log.trace("KochavaConfig after persistedKvinit:", JSON.parse(JSON.stringify(__classPrivateFieldGet(this, _Kochava_instance, "f").kochavaConfig)));
397
- }
333
+ initInstance(appGuid) {
334
+ // init instance with defaults
335
+ this.instance.appGuid = appGuid;
336
+ this.instance.disableAutoPage = this.instance.disableAutoPage || false;
337
+ this.instance.useCookies = this.instance.useCookies || false;
338
+ this.instance.version = this.instance.version || "WebTracker " + SDK_VERSION;
339
+ this.instance.buildDate = "kbd: 8/16/2024, 3:55:07 PM";
340
+ this.instance.kochavaSession = utils.uuidv4().substring(0, 5);
341
+ this.instance.startTimeMS = utils.getCurrTimeMS();
342
+ this.instance.retryWaterfall = [7, 30, 300, 1800];
343
+ this.instance.kochavaConfig = JSON.parse(JSON.stringify(DEFAULTS));
398
344
  }
399
- // check refresh minimum too
400
- const persistedKvinitDateStr = readAndUpdatePersistedValue(PersistKey.KvinitSentDate, __classPrivateFieldGet(this, _Kochava_instance, "f").useCookies);
401
- if (persistedKvinitDateStr) {
402
- const lastKvinitDate = JSON.parse(persistedKvinitDateStr);
403
- if (lastKvinitDate) {
404
- const refreshMin = __classPrivateFieldGet(this, _Kochava_instance, "f").kochavaConfig.config.refresh_minimum;
405
- if (utils.getCurrTimeSec() - lastKvinitDate < refreshMin)
406
- __classPrivateFieldGet(this, _Kochava_instance, "f").kvinitDone = true;
345
+ checkFirstLaunchAndMigrate() {
346
+ // If this is our first launch ever, set it in persistence.
347
+ if (!readAndUpdatePersistedValue(PersistKey.FirstStartDate, this.instance.useCookies)) {
348
+ updatePersistedValue(PersistKey.FirstStartDate, String(utils.getCurrTimeSec()), this.instance.useCookies);
349
+ /*
350
+ On a first launch of the v3 sdk, we need to migrate old persisted kv_id
351
+ from v2.2, v2.3, and v2.5
352
+ */
353
+ // perform migration
354
+ const oldKvId = readAndUpdatePersistedValue(PersistKey.OldKvid, this.instance.useCookies);
355
+ if (oldKvId) {
356
+ updatePersistedValue(PersistKey.DeviceId, oldKvId, this.instance.useCookies);
357
+ updatePersistedValue(PersistKey.InstallSentDate, JSON.stringify(utils.getCurrTimeSec()), this.instance.useCookies);
358
+ }
407
359
  }
408
360
  }
409
- }, _Kochava_checkPersistedState = function _Kochava_checkPersistedState() {
410
- __classPrivateFieldGet(this, _Kochava_instance, "f").installDone =
411
- readAndUpdatePersistedValue(PersistKey.InstallSentDate, __classPrivateFieldGet(this, _Kochava_instance, "f").useCookies).length > 0;
412
- __classPrivateFieldGet(this, _Kochava_instance, "f").kochavaInstallId = readAndUpdatePersistedValue(PersistKey.InstallId, __classPrivateFieldGet(this, _Kochava_instance, "f").useCookies);
413
- __classPrivateFieldGet(this, _Kochava_instance, "f").kochavaDeviceId = readAndUpdateDeviceId(__classPrivateFieldGet(this, _Kochava_instance, "f").useCookies);
414
- __classPrivateFieldGet(this, _Kochava_instance, "f").kochavaSessionCount = readAndUpdateSessionCount(__classPrivateFieldGet(this, _Kochava_instance, "f").useCookies);
415
- __classPrivateFieldGet(this, _Kochava_instance, "f").utm = readAndUpdateUTM(__classPrivateFieldGet(this, _Kochava_instance, "f").appGuid, __classPrivateFieldGet(this, _Kochava_instance, "f").useCookies);
416
- }, _Kochava_printStartupMsgs = function _Kochava_printStartupMsgs(appGuid) {
417
- Log.diagInfo(`Started SDK ${__classPrivateFieldGet(this, _Kochava_instance, "f").version}
418
- published ${__classPrivateFieldGet(this, _Kochava_instance, "f").buildDate}`);
419
- Log.diagInfo(`The log level is set to ${Log.getLogLevel()}`);
420
- Log.diagDebug(`This ${!__classPrivateFieldGet(this, _Kochava_instance, "f").installDone ? "is" : "is not"} the first tracker SDK launch`);
421
- Log.diagDebug(`The kochava device id is ${__classPrivateFieldGet(this, _Kochava_instance, "f").kochavaDeviceId}`);
422
- Log.diagDebug(`The kochava app GUID provided was ${appGuid}`);
423
- }, _Kochava_beginStart = async function _Kochava_beginStart() {
424
- // if we need to send a new kvinit, send it
425
- if (!__classPrivateFieldGet(this, _Kochava_instance, "f").kvinitDone) {
426
- Log.diagDebug(`A new kvinit will be sent`);
427
- await __classPrivateFieldGet(this, _Kochava_instances, "m", _Kochava_performNewKvinit).call(this);
361
+ checkPersistedKvinit() {
362
+ // check if persisted kvinit
363
+ let persistedKvinit = {};
364
+ const persistedKvinitStr = readAndUpdatePersistedValue(PersistKey.LastKvinit, this.instance.useCookies);
365
+ if (persistedKvinitStr) {
366
+ persistedKvinit = JSON.parse(persistedKvinitStr);
367
+ if (persistedKvinit) {
368
+ // if persisted kvinit, apply it
369
+ Log.trace("Found persisted kvinit.", persistedKvinit);
370
+ Kvinit.applyKvinitResp(this.instance, persistedKvinit);
371
+ Log.trace("KochavaConfig after persistedKvinit:", JSON.parse(JSON.stringify(this.instance.kochavaConfig)));
372
+ }
373
+ }
374
+ // check refresh minimum too
375
+ const persistedKvinitDateStr = readAndUpdatePersistedValue(PersistKey.KvinitSentDate, this.instance.useCookies);
376
+ if (persistedKvinitDateStr) {
377
+ const lastKvinitDate = JSON.parse(persistedKvinitDateStr);
378
+ if (lastKvinitDate) {
379
+ const refreshMin = this.instance.kochavaConfig.config.refresh_minimum;
380
+ if (utils.getCurrTimeSec() - lastKvinitDate < refreshMin) this.instance.kvinitDone = true;
381
+ }
382
+ }
428
383
  }
429
- else {
430
- Log.diagDebug(`A new kvinit will not be sent`);
384
+ checkPersistedState() {
385
+ this.instance.installDone = readAndUpdatePersistedValue(PersistKey.InstallSentDate, this.instance.useCookies).length > 0;
386
+ this.instance.kochavaInstallId = readAndUpdatePersistedValue(PersistKey.InstallId, this.instance.useCookies);
387
+ this.instance.kochavaDeviceId = readAndUpdateDeviceId(this.instance.useCookies);
388
+ this.instance.kochavaSessionCount = readAndUpdateSessionCount(this.instance.useCookies);
389
+ this.instance.utm = readAndUpdateUTM(this.instance.appGuid, this.instance.useCookies);
431
390
  }
432
- // if the install_id changed and thus a new install must go out
433
- if (__classPrivateFieldGet(this, _Kochava_instances, "m", _Kochava_checkResendId).call(this))
434
- __classPrivateFieldGet(this, _Kochava_instance, "f").installDone = false;
435
- Log.diagDebug(`The install ${__classPrivateFieldGet(this, _Kochava_instance, "f").installDone ? "has already" : "has not yet"} been sent`);
436
- if (__classPrivateFieldGet(this, _Kochava_instance, "f").sleep)
437
- return;
438
- if (!__classPrivateFieldGet(this, _Kochava_instance, "f").installDone) {
439
- await __classPrivateFieldGet(this, _Kochava_instances, "m", _Kochava_performInstall).call(this);
391
+ printStartupMsgs(appGuid) {
392
+ Log.diagInfo(`Started SDK ${this.instance.version}
393
+ published ${this.instance.buildDate}`);
394
+ Log.diagInfo(`The log level is set to ${Log.getLogLevel()}`);
395
+ Log.diagDebug(`This ${!this.instance.installDone ? "is" : "is not"} the first tracker SDK launch`);
396
+ Log.diagDebug(`The kochava device id is ${this.instance.kochavaDeviceId}`);
397
+ Log.diagDebug(`The kochava app GUID provided was ${appGuid}`);
440
398
  }
441
- if (__classPrivateFieldGet(this, _Kochava_instance, "f").kvinitDone && __classPrivateFieldGet(this, _Kochava_instance, "f").installDone) {
442
- await __classPrivateFieldGet(this, _Kochava_jobQueue, "f").start(__classPrivateFieldGet(this, _Kochava_instance, "f"));
399
+ async beginStart() {
400
+ // if we need to send a new kvinit, send it
401
+ if (!this.instance.kvinitDone) {
402
+ Log.diagDebug(`A new kvinit will be sent`);
403
+ await this.performNewKvinit();
404
+ } else {
405
+ Log.diagDebug(`A new kvinit will not be sent`);
406
+ }
407
+ // if the install_id changed and thus a new install must go out
408
+ if (this.checkResendId()) this.instance.installDone = false;
409
+ Log.diagDebug(`The install ${this.instance.installDone ? "has already" : "has not yet"} been sent`);
410
+ if (this.instance.sleep) return;
411
+ if (!this.instance.installDone) {
412
+ await this.performInstall();
413
+ }
414
+ if (this.instance.kvinitDone && this.instance.installDone) {
415
+ await this.jobQueue.start(this.instance);
416
+ }
443
417
  }
444
- }, _Kochava_performNewKvinit = async function _Kochava_performNewKvinit() {
445
- __classPrivateFieldGet(this, _Kochava_instance, "f").kvinitDone = await Kvinit.send(__classPrivateFieldGet(this, _Kochava_instance, "f"), __classPrivateFieldGet(this, _Kochava_instance, "f").retryWaterfall);
446
- updatePersistedValue(PersistKey.KvinitSentDate, String(utils.getCurrTimeSec()), __classPrivateFieldGet(this, _Kochava_instance, "f").useCookies);
447
- // if new kvinit, apply it
448
- let newKvinit = {};
449
- const newKvinitStr = readAndUpdatePersistedValue(PersistKey.LastKvinit, __classPrivateFieldGet(this, _Kochava_instance, "f").useCookies);
450
- if (newKvinitStr) {
451
- newKvinit = JSON.parse(newKvinitStr);
418
+ async performNewKvinit() {
419
+ this.instance.kvinitDone = await Kvinit.send(this.instance, this.instance.retryWaterfall);
420
+ updatePersistedValue(PersistKey.KvinitSentDate, String(utils.getCurrTimeSec()), this.instance.useCookies);
421
+ // if new kvinit, apply it
422
+ let newKvinit = {};
423
+ const newKvinitStr = readAndUpdatePersistedValue(PersistKey.LastKvinit, this.instance.useCookies);
424
+ if (newKvinitStr) {
425
+ newKvinit = JSON.parse(newKvinitStr);
426
+ }
427
+ Kvinit.applyKvinitResp(this.instance, newKvinit);
428
+ Log.trace("KochavaConfig after new Kvinit:", JSON.parse(JSON.stringify(this.instance.kochavaConfig)));
452
429
  }
453
- Kvinit.applyKvinitResp(__classPrivateFieldGet(this, _Kochava_instance, "f"), newKvinit);
454
- Log.trace("KochavaConfig after new Kvinit:", JSON.parse(JSON.stringify(__classPrivateFieldGet(this, _Kochava_instance, "f").kochavaConfig)));
455
- }, _Kochava_checkResendId = function _Kochava_checkResendId() {
456
- let resendId = "";
457
- if (__classPrivateFieldGet(this, _Kochava_instance, "f").kochavaConfig.install) {
458
- resendId = __classPrivateFieldGet(this, _Kochava_instance, "f").kochavaConfig.install.resend_id;
430
+ checkResendId() {
431
+ let resendId = "";
432
+ if (this.instance.kochavaConfig.install) {
433
+ resendId = this.instance.kochavaConfig.install.resend_id;
434
+ }
435
+ const needsNewInstall = checkInstallIdChange(resendId, this.instance.useCookies);
436
+ if (needsNewInstall) {
437
+ Log.debug(`resend_id ${resendId} found, forcing new install`);
438
+ }
439
+ return needsNewInstall;
459
440
  }
460
- const needsNewInstall = checkInstallIdChange(resendId, __classPrivateFieldGet(this, _Kochava_instance, "f").useCookies);
461
- if (needsNewInstall) {
462
- Log.debug(`resend_id ${resendId} found, forcing new install`);
441
+ async performInstall() {
442
+ const request = Install.build(this.instance);
443
+ this.instance.installDone = await Install.send(this.instance, request);
444
+ if (!this.instance.installDone) return;
445
+ // If the install succeeded, remove all idLink that were passed to it
446
+ Install.onSuccess(this.instance);
447
+ updatePersistedValue(PersistKey.IdLinkQueue, JSON.stringify(this.jobQueue.idLinkQueue), false);
463
448
  }
464
- return needsNewInstall;
465
- }, _Kochava_performInstall = async function _Kochava_performInstall() {
466
- const request = Install.build(__classPrivateFieldGet(this, _Kochava_instance, "f"));
467
- __classPrivateFieldGet(this, _Kochava_instance, "f").installDone = await Install.send(__classPrivateFieldGet(this, _Kochava_instance, "f"), request);
468
- if (!__classPrivateFieldGet(this, _Kochava_instance, "f").installDone)
469
- return;
470
- // If the install succeeded, remove all idLink that were passed to it
471
- Install.onSuccess(__classPrivateFieldGet(this, _Kochava_instance, "f"));
472
- updatePersistedValue(PersistKey.IdLinkQueue, JSON.stringify(__classPrivateFieldGet(this, _Kochava_jobQueue, "f").idLinkQueue), false);
473
- };
449
+ }
474
450
  // Only here for generic Web integration
475
451
  window.kochava = Kochava.create();
452
+ //# sourceMappingURL=kochava.js.map