kv-test-lib 1.0.3 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/http.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import 'whatwg-fetch';
1
2
  import { Payload } from "./payloads/payload";
2
3
  export interface BaseResp {
3
4
  success: string | number | boolean;
package/dist/http.js CHANGED
@@ -2,6 +2,7 @@
2
2
  Authored by Brett Barinaga on 11/17/21.
3
3
  Copyright (c) Kochava, Inc. All rights reserved.
4
4
  */
5
+ import 'whatwg-fetch';
5
6
  import { Log } from "./utils/log";
6
7
  export const sendRequest = async (payload, endpoint) => {
7
8
  try {
package/dist/kochava.d.ts CHANGED
@@ -1,3 +1,7 @@
1
+ import 'core-js/stable';
2
+ import 'regenerator-runtime/runtime';
3
+ import 'whatwg-fetch';
4
+ import JobQueue from "./jobqueue";
1
5
  import { Json, Urls, CustomValue, KvConfig } from "./interfaces";
2
6
  declare global {
3
7
  interface Window {
@@ -28,7 +32,8 @@ export interface KochavaInstance {
28
32
  kochavaConfig?: KvConfig;
29
33
  }
30
34
  export declare class Kochava {
31
- #private;
35
+ instance: KochavaInstance;
36
+ jobQueue: JobQueue;
32
37
  private constructor();
33
38
  static create(): Kochava;
34
39
  static createForNode(): Kochava;
@@ -49,4 +54,14 @@ export declare class Kochava {
49
54
  getStarted(): boolean;
50
55
  getDeviceId(): string;
51
56
  setSleep(sleep: boolean): void;
57
+ resetInstance(): void;
58
+ initInstance(appGuid: string): void;
59
+ checkFirstLaunchAndMigrate(): void;
60
+ checkPersistedKvinit(): void;
61
+ checkPersistedState(): void;
62
+ printStartupMsgs(appGuid: string): void;
63
+ beginStart(): Promise<void>;
64
+ performNewKvinit(): Promise<void>;
65
+ checkResendId(): boolean;
66
+ performInstall(): Promise<void>;
52
67
  }
package/dist/kochava.js CHANGED
@@ -2,18 +2,9 @@
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";
@@ -22,15 +13,14 @@ import { DEFAULTS, } from "./interfaces";
22
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,22 @@ 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)
86
+ this.resetInstance();
87
+ if (this.instance.started) {
98
88
  Log.warn("Kochava SDK already started.");
99
89
  return;
100
90
  }
101
91
  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)
92
+ this.instance.started = true;
93
+ this.checkFirstLaunchAndMigrate();
94
+ this.initInstance(appGuid);
95
+ if (!this.instance.disableAutoPage)
106
96
  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);
97
+ this.checkPersistedState();
98
+ this.checkPersistedKvinit();
99
+ this.printStartupMsgs(appGuid);
100
+ this.beginStart();
111
101
  }
112
102
  /*
113
103
  Primary means for stopping the sdk.
@@ -120,16 +110,16 @@ export class Kochava {
120
110
  Log.debug("Deleting persisted values");
121
111
  deleteAllPersisted();
122
112
  }
123
- if (!__classPrivateFieldGet(this, _Kochava_instance, "f").started) {
113
+ if (!this.instance.started) {
124
114
  Log.warn("SDK already shutdown.");
125
115
  }
126
116
  Log.info("SDK shutting down.");
127
117
  Kvinit.cancelRetries();
128
118
  Install.cancelRetries();
129
- __classPrivateFieldGet(this, _Kochava_jobQueue, "f").stop();
119
+ this.jobQueue.stop();
130
120
  // 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);
121
+ this.jobQueue = new JobQueue();
122
+ this.resetInstance();
133
123
  }
134
124
  /*
135
125
  Changes the current logLevel.
@@ -158,14 +148,14 @@ export class Kochava {
158
148
  case "wrapper":
159
149
  {
160
150
  const wrapperVersion = JSON.parse(valueStr);
161
- if (!__classPrivateFieldGet(this, _Kochava_instance, "f").version)
162
- __classPrivateFieldGet(this, _Kochava_instance, "f").version = "WebTracker 3.0.0";
151
+ if (!this.instance.version)
152
+ this.instance.version = "WebTracker " + SDK_VERSION;
163
153
  switch (wrapperVersion.name) {
164
154
  case "Angular":
165
- __classPrivateFieldGet(this, _Kochava_instance, "f").version += ` (${wrapperVersion.name} ${wrapperVersion.version})`;
155
+ this.instance.version += ` (${wrapperVersion.name} ${wrapperVersion.version})`;
166
156
  break;
167
157
  default:
168
- __classPrivateFieldGet(this, _Kochava_instance, "f").version += ` (${wrapperVersion.name})`;
158
+ this.instance.version += ` (${wrapperVersion.name})`;
169
159
  break;
170
160
  }
171
161
  }
@@ -174,13 +164,13 @@ export class Kochava {
174
164
  {
175
165
  const overrideUrls = JSON.parse(valueStr);
176
166
  if (overrideUrls.init)
177
- __classPrivateFieldGet(this, _Kochava_instance, "f").overrideUrls.init = overrideUrls.init;
167
+ this.instance.overrideUrls.init = overrideUrls.init;
178
168
  if (overrideUrls.event)
179
- __classPrivateFieldGet(this, _Kochava_instance, "f").overrideUrls.event = overrideUrls.event;
169
+ this.instance.overrideUrls.event = overrideUrls.event;
180
170
  if (overrideUrls.install)
181
- __classPrivateFieldGet(this, _Kochava_instance, "f").overrideUrls.install = overrideUrls.install;
171
+ this.instance.overrideUrls.install = overrideUrls.install;
182
172
  if (overrideUrls.identityLink)
183
- __classPrivateFieldGet(this, _Kochava_instance, "f").overrideUrls.identityLink = overrideUrls.identityLink;
173
+ this.instance.overrideUrls.identityLink = overrideUrls.identityLink;
184
174
  }
185
175
  break;
186
176
  case "urlsRestore":
@@ -188,14 +178,14 @@ export class Kochava {
188
178
  const restoreUrls = JSON.parse(valueStr);
189
179
  for (const url of restoreUrls) {
190
180
  if (url === "init")
191
- __classPrivateFieldGet(this, _Kochava_instance, "f").overrideUrls.init = DEFAULTS.networking.urls.init;
181
+ this.instance.overrideUrls.init = DEFAULTS.networking.urls.init;
192
182
  if (url === "event")
193
- __classPrivateFieldGet(this, _Kochava_instance, "f").overrideUrls.event = DEFAULTS.networking.urls.event;
183
+ this.instance.overrideUrls.event = DEFAULTS.networking.urls.event;
194
184
  if (url === "install")
195
- __classPrivateFieldGet(this, _Kochava_instance, "f").overrideUrls.install =
185
+ this.instance.overrideUrls.install =
196
186
  DEFAULTS.networking.urls.install;
197
187
  if (url === "identityLink")
198
- __classPrivateFieldGet(this, _Kochava_instance, "f").overrideUrls.identityLink =
188
+ this.instance.overrideUrls.identityLink =
199
189
  DEFAULTS.networking.urls.identityLink;
200
190
  }
201
191
  }
@@ -208,7 +198,7 @@ export class Kochava {
208
198
  break;
209
199
  case "getInstance":
210
200
  {
211
- const currInstance = JSON.stringify(__classPrivateFieldGet(this, _Kochava_instance, "f"));
201
+ const currInstance = JSON.stringify(this.instance);
212
202
  callback(currInstance);
213
203
  Log.debug(`capturing instance: ${valueStr}`);
214
204
  }
@@ -230,7 +220,7 @@ export class Kochava {
230
220
  Log.warn("Invalid event name, ignoring call.");
231
221
  return;
232
222
  }
233
- __classPrivateFieldGet(this, _Kochava_jobQueue, "f").enqueueEvent(__classPrivateFieldGet(this, _Kochava_instance, "f"), [name, data]);
223
+ this.jobQueue.enqueueEvent(this.instance, [name, data]);
234
224
  }
235
225
  /*
236
226
  Wraps the sendEvent call with predefined data specific to page events.
@@ -260,11 +250,11 @@ export class Kochava {
260
250
  }
261
251
  const idLink = {};
262
252
  idLink[name] = identifier;
263
- addPersistedIdLinks(name, identifier, __classPrivateFieldGet(this, _Kochava_instance, "f").useCookies);
264
- // if (this.#instance.installStarted || this.#instance.installDone) {
253
+ addPersistedIdLinks(name, identifier, this.instance.useCookies);
254
+ // if (this.instance.installStarted || this.instance.installDone) {
265
255
  if (localStorage.getItem("com.kochava.tracker.InstallSentDate")) {
266
256
  // it will be sent standalone
267
- __classPrivateFieldGet(this, _Kochava_jobQueue, "f").enqueueIdLink(__classPrivateFieldGet(this, _Kochava_instance, "f"), idLink);
257
+ this.jobQueue.enqueueIdLink(this.instance, idLink);
268
258
  }
269
259
  // will be sent in install
270
260
  }
@@ -277,7 +267,7 @@ export class Kochava {
277
267
  }
278
268
  const dataToAdorn = {};
279
269
  dataToAdorn[name] = value;
280
- __classPrivateFieldGet(this, _Kochava_instance, "f").customValues.push({ data: dataToAdorn, isDeviceId: false });
270
+ this.instance.customValues.push({ data: dataToAdorn, isDeviceId: false });
281
271
  }
282
272
  // Allows the client to attach arbitrary identifiers to go out in the install.
283
273
  registerCustomDeviceIdentifier(name, value) {
@@ -288,7 +278,7 @@ export class Kochava {
288
278
  }
289
279
  const dataToAdorn = {};
290
280
  dataToAdorn[name] = value;
291
- __classPrivateFieldGet(this, _Kochava_instance, "f").customValues.push({ data: dataToAdorn, isDeviceId: true });
281
+ this.instance.customValues.push({ data: dataToAdorn, isDeviceId: true });
292
282
  }
293
283
  /*
294
284
  Returns whether or not the sdk is in a "started" state.
@@ -297,15 +287,15 @@ export class Kochava {
297
287
  Likewise, shutdown will set "started" to false;
298
288
  */
299
289
  getStarted() {
300
- return __classPrivateFieldGet(this, _Kochava_instance, "f").started;
290
+ return this.instance.started;
301
291
  }
302
292
  /*
303
293
  Returns the current kochavaDeviceId, or "" if called too early.
304
294
  */
305
295
  getDeviceId() {
306
296
  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;
297
+ if (this.instance.started)
298
+ return this.instance.kochavaDeviceId;
309
299
  else
310
300
  return "";
311
301
  }
@@ -316,160 +306,172 @@ export class Kochava {
316
306
  */
317
307
  setSleep(sleep) {
318
308
  Log.diagDebug(`Host called API: Sleep ${sleep ? "Stop" : "Start"}`);
319
- if (sleep && !__classPrivateFieldGet(this, _Kochava_instance, "f").sleep) {
309
+ if (sleep && !this.instance.sleep) {
320
310
  // only pause if it was running
321
- __classPrivateFieldGet(this, _Kochava_instance, "f").sleep = sleep;
322
- __classPrivateFieldGet(this, _Kochava_jobQueue, "f").pause();
311
+ this.instance.sleep = sleep;
312
+ this.jobQueue.pause();
323
313
  }
324
- else if (!sleep && __classPrivateFieldGet(this, _Kochava_instance, "f").sleep) {
314
+ else if (!sleep && this.instance.sleep) {
325
315
  // 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);
316
+ this.instance.sleep = sleep;
317
+ this.beginStart();
328
318
  }
329
319
  }
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
- }
320
+ // ============================= =============================== //
321
+ // Unintialized/invalid state.
322
+ // start must be called before these values will be correct.
323
+ resetInstance() {
324
+ this.instance = {
325
+ appGuid: "",
326
+ started: false,
327
+ installStarted: false,
328
+ kvinitDone: false,
329
+ installDone: false,
330
+ disableAutoPage: false,
331
+ useCookies: false,
332
+ sleep: false,
333
+ version: "",
334
+ buildDate: "",
335
+ overrideUrls: {
336
+ init: "",
337
+ install: "",
338
+ event: "",
339
+ identityLink: "",
340
+ },
341
+ customValues: [],
342
+ kochavaSession: "",
343
+ retryWaterfall: [],
344
+ startTimeMS: 0,
345
+ utm: "",
346
+ kochavaDeviceId: "",
347
+ kochavaInstallId: "",
348
+ kochavaSessionCount: -1,
349
+ kochavaInstallDate: -1,
350
+ kochavaConfig: undefined,
351
+ };
385
352
  }
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
- }
353
+ initInstance(appGuid) {
354
+ // init instance with defaults
355
+ this.instance.appGuid = appGuid;
356
+ this.instance.disableAutoPage = this.instance.disableAutoPage || false;
357
+ this.instance.useCookies = this.instance.useCookies || false;
358
+ this.instance.version = this.instance.version || "WebTracker " + SDK_VERSION;
359
+ this.instance.buildDate = "kbd: 8/16/2024, 3:02:42 PM";
360
+ this.instance.kochavaSession = utils.uuidv4().substring(0, 5);
361
+ this.instance.startTimeMS = utils.getCurrTimeMS();
362
+ this.instance.retryWaterfall = [7, 30, 300, 1800];
363
+ this.instance.kochavaConfig = JSON.parse(JSON.stringify(DEFAULTS));
398
364
  }
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;
365
+ checkFirstLaunchAndMigrate() {
366
+ // If this is our first launch ever, set it in persistence.
367
+ if (!readAndUpdatePersistedValue(PersistKey.FirstStartDate, this.instance.useCookies)) {
368
+ updatePersistedValue(PersistKey.FirstStartDate, String(utils.getCurrTimeSec()), this.instance.useCookies);
369
+ /*
370
+ On a first launch of the v3 sdk, we need to migrate old persisted kv_id
371
+ from v2.2, v2.3, and v2.5
372
+ */
373
+ // perform migration
374
+ const oldKvId = readAndUpdatePersistedValue(PersistKey.OldKvid, this.instance.useCookies);
375
+ if (oldKvId) {
376
+ updatePersistedValue(PersistKey.DeviceId, oldKvId, this.instance.useCookies);
377
+ updatePersistedValue(PersistKey.InstallSentDate, JSON.stringify(utils.getCurrTimeSec()), this.instance.useCookies);
378
+ }
407
379
  }
408
380
  }
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);
381
+ checkPersistedKvinit() {
382
+ // check if persisted kvinit
383
+ let persistedKvinit = {};
384
+ const persistedKvinitStr = readAndUpdatePersistedValue(PersistKey.LastKvinit, this.instance.useCookies);
385
+ if (persistedKvinitStr) {
386
+ persistedKvinit = JSON.parse(persistedKvinitStr);
387
+ if (persistedKvinit) {
388
+ // if persisted kvinit, apply it
389
+ Log.trace("Found persisted kvinit.", persistedKvinit);
390
+ Kvinit.applyKvinitResp(this.instance, persistedKvinit);
391
+ Log.trace("KochavaConfig after persistedKvinit:", JSON.parse(JSON.stringify(this.instance.kochavaConfig)));
392
+ }
393
+ }
394
+ // check refresh minimum too
395
+ const persistedKvinitDateStr = readAndUpdatePersistedValue(PersistKey.KvinitSentDate, this.instance.useCookies);
396
+ if (persistedKvinitDateStr) {
397
+ const lastKvinitDate = JSON.parse(persistedKvinitDateStr);
398
+ if (lastKvinitDate) {
399
+ const refreshMin = this.instance.kochavaConfig.config.refresh_minimum;
400
+ if (utils.getCurrTimeSec() - lastKvinitDate < refreshMin)
401
+ this.instance.kvinitDone = true;
402
+ }
403
+ }
428
404
  }
429
- else {
430
- Log.diagDebug(`A new kvinit will not be sent`);
405
+ checkPersistedState() {
406
+ this.instance.installDone =
407
+ readAndUpdatePersistedValue(PersistKey.InstallSentDate, this.instance.useCookies).length > 0;
408
+ this.instance.kochavaInstallId = readAndUpdatePersistedValue(PersistKey.InstallId, this.instance.useCookies);
409
+ this.instance.kochavaDeviceId = readAndUpdateDeviceId(this.instance.useCookies);
410
+ this.instance.kochavaSessionCount = readAndUpdateSessionCount(this.instance.useCookies);
411
+ this.instance.utm = readAndUpdateUTM(this.instance.appGuid, this.instance.useCookies);
431
412
  }
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);
413
+ printStartupMsgs(appGuid) {
414
+ Log.diagInfo(`Started SDK ${this.instance.version}
415
+ published ${this.instance.buildDate}`);
416
+ Log.diagInfo(`The log level is set to ${Log.getLogLevel()}`);
417
+ Log.diagDebug(`This ${!this.instance.installDone ? "is" : "is not"} the first tracker SDK launch`);
418
+ Log.diagDebug(`The kochava device id is ${this.instance.kochavaDeviceId}`);
419
+ Log.diagDebug(`The kochava app GUID provided was ${appGuid}`);
440
420
  }
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"));
421
+ async beginStart() {
422
+ // if we need to send a new kvinit, send it
423
+ if (!this.instance.kvinitDone) {
424
+ Log.diagDebug(`A new kvinit will be sent`);
425
+ await this.performNewKvinit();
426
+ }
427
+ else {
428
+ Log.diagDebug(`A new kvinit will not be sent`);
429
+ }
430
+ // if the install_id changed and thus a new install must go out
431
+ if (this.checkResendId())
432
+ this.instance.installDone = false;
433
+ Log.diagDebug(`The install ${this.instance.installDone ? "has already" : "has not yet"} been sent`);
434
+ if (this.instance.sleep)
435
+ return;
436
+ if (!this.instance.installDone) {
437
+ await this.performInstall();
438
+ }
439
+ if (this.instance.kvinitDone && this.instance.installDone) {
440
+ await this.jobQueue.start(this.instance);
441
+ }
443
442
  }
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);
443
+ async performNewKvinit() {
444
+ this.instance.kvinitDone = await Kvinit.send(this.instance, this.instance.retryWaterfall);
445
+ updatePersistedValue(PersistKey.KvinitSentDate, String(utils.getCurrTimeSec()), this.instance.useCookies);
446
+ // if new kvinit, apply it
447
+ let newKvinit = {};
448
+ const newKvinitStr = readAndUpdatePersistedValue(PersistKey.LastKvinit, this.instance.useCookies);
449
+ if (newKvinitStr) {
450
+ newKvinit = JSON.parse(newKvinitStr);
451
+ }
452
+ Kvinit.applyKvinitResp(this.instance, newKvinit);
453
+ Log.trace("KochavaConfig after new Kvinit:", JSON.parse(JSON.stringify(this.instance.kochavaConfig)));
452
454
  }
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;
455
+ checkResendId() {
456
+ let resendId = "";
457
+ if (this.instance.kochavaConfig.install) {
458
+ resendId = this.instance.kochavaConfig.install.resend_id;
459
+ }
460
+ const needsNewInstall = checkInstallIdChange(resendId, this.instance.useCookies);
461
+ if (needsNewInstall) {
462
+ Log.debug(`resend_id ${resendId} found, forcing new install`);
463
+ }
464
+ return needsNewInstall;
459
465
  }
460
- const needsNewInstall = checkInstallIdChange(resendId, __classPrivateFieldGet(this, _Kochava_instance, "f").useCookies);
461
- if (needsNewInstall) {
462
- Log.debug(`resend_id ${resendId} found, forcing new install`);
466
+ async performInstall() {
467
+ const request = Install.build(this.instance);
468
+ this.instance.installDone = await Install.send(this.instance, request);
469
+ if (!this.instance.installDone)
470
+ return;
471
+ // If the install succeeded, remove all idLink that were passed to it
472
+ Install.onSuccess(this.instance);
473
+ updatePersistedValue(PersistKey.IdLinkQueue, JSON.stringify(this.jobQueue.idLinkQueue), false);
463
474
  }
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
- };
475
+ }
474
476
  // Only here for generic Web integration
475
477
  window.kochava = Kochava.create();
@@ -101,18 +101,27 @@ const constructInstallData = (instance) => {
101
101
  returnObj.device_ids = {};
102
102
  instance.customValues.forEach((custom) => {
103
103
  const customKey = Object.keys(custom.data)[0];
104
+ console.log("customData: ", custom);
104
105
  if (instance.kochavaConfig.privacy) {
105
106
  let keyAllowed = false;
107
+ console.log("1");
106
108
  for (const allowed of instance.kochavaConfig.privacy.allow_custom_ids) {
107
109
  if (customKey === allowed) {
110
+ console.log("2");
108
111
  keyAllowed = true;
109
112
  }
110
113
  }
111
114
  if (keyAllowed) {
112
- if (custom.isDeviceId)
115
+ console.log("3");
116
+ if (custom.isDeviceId) {
117
+ console.log("4");
113
118
  returnObj.device_ids = Object.assign(Object.assign({}, returnObj.device_ids), custom.data);
114
- else
119
+ }
120
+ else {
121
+ console.log("before: ", returnObj);
115
122
  returnObj = Object.assign(Object.assign({}, custom.data), returnObj);
123
+ console.log("after: ", returnObj);
124
+ }
116
125
  }
117
126
  }
118
127
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kv-test-lib",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "main": "dist/kochava.js",
5
5
  "files": [
6
6
  "dist/"