kv-test-lib 1.0.2 → 1.0.3

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/README.md ADDED
@@ -0,0 +1,12 @@
1
+ ## Kochava Web SDK
2
+ The Kochava Web SDK is a lightweight plugin which can be easily integrated into your web project.
3
+
4
+ ### Installation
5
+ [SDK Integration](https://support.kochava.com/web-sdk-integration/)
6
+
7
+ ### Support
8
+ support@kochava.com
9
+
10
+ ### License
11
+ KochavaTracker is available under the [Kochava Terms of Service](https://www.kochava.com/terms-of-service/).
12
+
@@ -16,7 +16,7 @@ interface DefaultConfig {
16
16
  readonly init: "https://kvinit-prod.api.kochava.com/track/kvinit";
17
17
  readonly install: "https://web-sdk.control.kochava.com/track/json/";
18
18
  readonly event: "https://web-sdk.control.kochava.com/track/json/";
19
- readonly identityLink: "https://web-sdk.control.kochava.com/v1/cpi/identityLink.php";
19
+ readonly identityLink: "https://web-sdk.control.kochava.com/track/json/";
20
20
  };
21
21
  readonly retry_waterfall: [7, 30, 300, 1800];
22
22
  };
@@ -23,7 +23,7 @@ export const DEFAULTS = {
23
23
  init: "https://kvinit-prod.api.kochava.com/track/kvinit",
24
24
  install: "https://web-sdk.control.kochava.com/track/json/",
25
25
  event: "https://web-sdk.control.kochava.com/track/json/",
26
- identityLink: "https://web-sdk.control.kochava.com/v1/cpi/identityLink.php"
26
+ identityLink: "https://web-sdk.control.kochava.com/track/json/"
27
27
  },
28
28
  retry_waterfall: [7, 30, 300, 1800],
29
29
  },
package/dist/kochava.d.ts CHANGED
@@ -28,9 +28,13 @@ export interface KochavaInstance {
28
28
  kochavaConfig?: KvConfig;
29
29
  }
30
30
  export declare class Kochava {
31
- private instance;
32
- private jobQueue;
33
- constructor();
31
+ #private;
32
+ private constructor();
33
+ static create(): Kochava;
34
+ static createForNode(): Kochava;
35
+ static createForReact(): Kochava;
36
+ static createForVue(): Kochava;
37
+ static createForAngular(): Kochava;
34
38
  useCookies(condition?: boolean): void;
35
39
  disableAutoPage(condition?: boolean): void;
36
40
  startWithAppGuid(appGuid: string): void;
@@ -45,14 +49,4 @@ export declare class Kochava {
45
49
  getStarted(): boolean;
46
50
  getDeviceId(): string;
47
51
  setSleep(sleep: boolean): void;
48
- private resetInstance;
49
- private initInstance;
50
- private checkFirstLaunchAndMigrate;
51
- private checkPersistedKvinit;
52
- private checkPersistedState;
53
- private printStartupMsgs;
54
- private beginStart;
55
- private performNewKvinit;
56
- private checkResendId;
57
- private performInstall;
58
52
  }
package/dist/kochava.js CHANGED
@@ -2,6 +2,18 @@
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
17
  import { Log } from "./utils/log";
6
18
  import JobQueue from "./jobqueue";
7
19
  import * as Kvinit from "./payloads/kvinit";
@@ -11,10 +23,38 @@ import { deleteAllPersisted, readAndUpdatePersistedValue, updatePersistedValue,
11
23
  import * as utils from "./utils/utils";
12
24
  import { getPageName } from "./browser/browser";
13
25
  export class Kochava {
14
- // ============================= PUBLIC =============================== //
26
+ // User will use the below factories instead of directly calling
27
+ // the constructor
15
28
  constructor() {
16
- this.resetInstance();
17
- this.jobQueue = new JobQueue();
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");
34
+ }
35
+ // ============================= PUBLIC =============================== //
36
+ static create() {
37
+ return new Kochava();
38
+ }
39
+ static createForNode() {
40
+ const kochava = new Kochava();
41
+ kochava.executeAdvancedInstruction("wrapper", JSON.stringify({ name: "Node", version: "" }));
42
+ return kochava;
43
+ }
44
+ static createForReact() {
45
+ const kochava = new Kochava();
46
+ kochava.executeAdvancedInstruction("wrapper", JSON.stringify({ name: "React", version: "" }));
47
+ return kochava;
48
+ }
49
+ static createForVue() {
50
+ const kochava = new Kochava();
51
+ kochava.executeAdvancedInstruction("wrapper", JSON.stringify({ name: "Vue", version: "" }));
52
+ return kochava;
53
+ }
54
+ static createForAngular() {
55
+ const kochava = new Kochava();
56
+ kochava.executeAdvancedInstruction("wrapper", JSON.stringify({ name: "Angular", version: "1.0.0" }));
57
+ return kochava;
18
58
  }
19
59
  /*
20
60
  Set if the SDK should also store persisted values in cookie storage.
@@ -25,7 +65,7 @@ export class Kochava {
25
65
  - defaults to false
26
66
  */
27
67
  useCookies(condition = false) {
28
- this.instance.useCookies = condition;
68
+ __classPrivateFieldGet(this, _Kochava_instance, "f").useCookies = condition;
29
69
  }
30
70
  /*
31
71
  - Set whether the sdk shouldn't automatically send a page or should.
@@ -34,7 +74,7 @@ export class Kochava {
34
74
  - defaults to false
35
75
  */
36
76
  disableAutoPage(condition = false) {
37
- this.instance.disableAutoPage = condition;
77
+ __classPrivateFieldGet(this, _Kochava_instance, "f").disableAutoPage = condition;
38
78
  }
39
79
  /*
40
80
  The primary means for starting the sdk.
@@ -52,22 +92,22 @@ export class Kochava {
52
92
  Log.error(`Invalid appGuid ${appGuid}, start failed.`);
53
93
  return;
54
94
  }
55
- if (!this.instance)
56
- this.resetInstance();
57
- if (this.instance.started) {
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) {
58
98
  Log.warn("Kochava SDK already started.");
59
99
  return;
60
100
  }
61
101
  Log.diagDebug(`Host called API: Start With App Guid ${appGuid}`);
62
- this.instance.started = true;
63
- this.checkFirstLaunchAndMigrate();
64
- this.initInstance(appGuid);
65
- if (!this.instance.disableAutoPage)
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)
66
106
  this.sendPageEvent();
67
- this.checkPersistedState();
68
- this.checkPersistedKvinit();
69
- this.printStartupMsgs(appGuid);
70
- this.beginStart();
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);
71
111
  }
72
112
  /*
73
113
  Primary means for stopping the sdk.
@@ -80,16 +120,16 @@ export class Kochava {
80
120
  Log.debug("Deleting persisted values");
81
121
  deleteAllPersisted();
82
122
  }
83
- if (!this.instance.started) {
123
+ if (!__classPrivateFieldGet(this, _Kochava_instance, "f").started) {
84
124
  Log.warn("SDK already shutdown.");
85
125
  }
86
126
  Log.info("SDK shutting down.");
87
127
  Kvinit.cancelRetries();
88
128
  Install.cancelRetries();
89
- this.jobQueue.stop();
129
+ __classPrivateFieldGet(this, _Kochava_jobQueue, "f").stop();
90
130
  // wipe whatever was previously in the queue
91
- this.jobQueue = new JobQueue();
92
- this.resetInstance();
131
+ __classPrivateFieldSet(this, _Kochava_jobQueue, new JobQueue(), "f");
132
+ __classPrivateFieldGet(this, _Kochava_instances, "m", _Kochava_resetInstance).call(this);
93
133
  }
94
134
  /*
95
135
  Changes the current logLevel.
@@ -118,20 +158,29 @@ export class Kochava {
118
158
  case "wrapper":
119
159
  {
120
160
  const wrapperVersion = JSON.parse(valueStr);
121
- this.instance.version = `${this.instance.version} (${wrapperVersion.name} ${wrapperVersion.version})`;
161
+ if (!__classPrivateFieldGet(this, _Kochava_instance, "f").version)
162
+ __classPrivateFieldGet(this, _Kochava_instance, "f").version = "WebTracker 3.0.0";
163
+ switch (wrapperVersion.name) {
164
+ case "Angular":
165
+ __classPrivateFieldGet(this, _Kochava_instance, "f").version += ` (${wrapperVersion.name} ${wrapperVersion.version})`;
166
+ break;
167
+ default:
168
+ __classPrivateFieldGet(this, _Kochava_instance, "f").version += ` (${wrapperVersion.name})`;
169
+ break;
170
+ }
122
171
  }
123
172
  break;
124
173
  case "urls":
125
174
  {
126
175
  const overrideUrls = JSON.parse(valueStr);
127
176
  if (overrideUrls.init)
128
- this.instance.overrideUrls.init = overrideUrls.init;
177
+ __classPrivateFieldGet(this, _Kochava_instance, "f").overrideUrls.init = overrideUrls.init;
129
178
  if (overrideUrls.event)
130
- this.instance.overrideUrls.event = overrideUrls.event;
179
+ __classPrivateFieldGet(this, _Kochava_instance, "f").overrideUrls.event = overrideUrls.event;
131
180
  if (overrideUrls.install)
132
- this.instance.overrideUrls.install = overrideUrls.install;
181
+ __classPrivateFieldGet(this, _Kochava_instance, "f").overrideUrls.install = overrideUrls.install;
133
182
  if (overrideUrls.identityLink)
134
- this.instance.overrideUrls.identityLink = overrideUrls.identityLink;
183
+ __classPrivateFieldGet(this, _Kochava_instance, "f").overrideUrls.identityLink = overrideUrls.identityLink;
135
184
  }
136
185
  break;
137
186
  case "urlsRestore":
@@ -139,14 +188,14 @@ export class Kochava {
139
188
  const restoreUrls = JSON.parse(valueStr);
140
189
  for (const url of restoreUrls) {
141
190
  if (url === "init")
142
- this.instance.overrideUrls.init = DEFAULTS.networking.urls.init;
191
+ __classPrivateFieldGet(this, _Kochava_instance, "f").overrideUrls.init = DEFAULTS.networking.urls.init;
143
192
  if (url === "event")
144
- this.instance.overrideUrls.event = DEFAULTS.networking.urls.event;
193
+ __classPrivateFieldGet(this, _Kochava_instance, "f").overrideUrls.event = DEFAULTS.networking.urls.event;
145
194
  if (url === "install")
146
- this.instance.overrideUrls.install =
195
+ __classPrivateFieldGet(this, _Kochava_instance, "f").overrideUrls.install =
147
196
  DEFAULTS.networking.urls.install;
148
197
  if (url === "identityLink")
149
- this.instance.overrideUrls.identityLink =
198
+ __classPrivateFieldGet(this, _Kochava_instance, "f").overrideUrls.identityLink =
150
199
  DEFAULTS.networking.urls.identityLink;
151
200
  }
152
201
  }
@@ -159,7 +208,7 @@ export class Kochava {
159
208
  break;
160
209
  case "getInstance":
161
210
  {
162
- const currInstance = JSON.stringify(this.instance);
211
+ const currInstance = JSON.stringify(__classPrivateFieldGet(this, _Kochava_instance, "f"));
163
212
  callback(currInstance);
164
213
  Log.debug(`capturing instance: ${valueStr}`);
165
214
  }
@@ -181,7 +230,7 @@ export class Kochava {
181
230
  Log.warn("Invalid event name, ignoring call.");
182
231
  return;
183
232
  }
184
- this.jobQueue.enqueueEvent(this.instance, [name, data]);
233
+ __classPrivateFieldGet(this, _Kochava_jobQueue, "f").enqueueEvent(__classPrivateFieldGet(this, _Kochava_instance, "f"), [name, data]);
185
234
  }
186
235
  /*
187
236
  Wraps the sendEvent call with predefined data specific to page events.
@@ -211,10 +260,11 @@ export class Kochava {
211
260
  }
212
261
  const idLink = {};
213
262
  idLink[name] = identifier;
214
- addPersistedIdLinks(name, identifier, this.instance.useCookies);
215
- if (this.instance.installStarted || this.instance.installDone) {
263
+ addPersistedIdLinks(name, identifier, __classPrivateFieldGet(this, _Kochava_instance, "f").useCookies);
264
+ // if (this.#instance.installStarted || this.#instance.installDone) {
265
+ if (localStorage.getItem("com.kochava.tracker.InstallSentDate")) {
216
266
  // it will be sent standalone
217
- this.jobQueue.enqueueIdLink(this.instance, idLink);
267
+ __classPrivateFieldGet(this, _Kochava_jobQueue, "f").enqueueIdLink(__classPrivateFieldGet(this, _Kochava_instance, "f"), idLink);
218
268
  }
219
269
  // will be sent in install
220
270
  }
@@ -227,7 +277,7 @@ export class Kochava {
227
277
  }
228
278
  const dataToAdorn = {};
229
279
  dataToAdorn[name] = value;
230
- this.instance.customValues.push({ data: dataToAdorn, isDeviceId: false });
280
+ __classPrivateFieldGet(this, _Kochava_instance, "f").customValues.push({ data: dataToAdorn, isDeviceId: false });
231
281
  }
232
282
  // Allows the client to attach arbitrary identifiers to go out in the install.
233
283
  registerCustomDeviceIdentifier(name, value) {
@@ -238,7 +288,7 @@ export class Kochava {
238
288
  }
239
289
  const dataToAdorn = {};
240
290
  dataToAdorn[name] = value;
241
- this.instance.customValues.push({ data: dataToAdorn, isDeviceId: true });
291
+ __classPrivateFieldGet(this, _Kochava_instance, "f").customValues.push({ data: dataToAdorn, isDeviceId: true });
242
292
  }
243
293
  /*
244
294
  Returns whether or not the sdk is in a "started" state.
@@ -247,15 +297,15 @@ export class Kochava {
247
297
  Likewise, shutdown will set "started" to false;
248
298
  */
249
299
  getStarted() {
250
- return this.instance.started;
300
+ return __classPrivateFieldGet(this, _Kochava_instance, "f").started;
251
301
  }
252
302
  /*
253
303
  Returns the current kochavaDeviceId, or "" if called too early.
254
304
  */
255
305
  getDeviceId() {
256
306
  Log.diagDebug(`Host called API: Get Kochava Device Id`);
257
- if (this.instance.started)
258
- return this.instance.kochavaDeviceId;
307
+ if (__classPrivateFieldGet(this, _Kochava_instance, "f").started)
308
+ return __classPrivateFieldGet(this, _Kochava_instance, "f").kochavaDeviceId;
259
309
  else
260
310
  return "";
261
311
  }
@@ -266,171 +316,160 @@ export class Kochava {
266
316
  */
267
317
  setSleep(sleep) {
268
318
  Log.diagDebug(`Host called API: Sleep ${sleep ? "Stop" : "Start"}`);
269
- if (sleep && !this.instance.sleep) {
319
+ if (sleep && !__classPrivateFieldGet(this, _Kochava_instance, "f").sleep) {
270
320
  // only pause if it was running
271
- this.instance.sleep = sleep;
272
- this.jobQueue.pause();
321
+ __classPrivateFieldGet(this, _Kochava_instance, "f").sleep = sleep;
322
+ __classPrivateFieldGet(this, _Kochava_jobQueue, "f").pause();
273
323
  }
274
- else if (!sleep && this.instance.sleep) {
324
+ else if (!sleep && __classPrivateFieldGet(this, _Kochava_instance, "f").sleep) {
275
325
  // only resume queueing if it was paused
276
- this.instance.sleep = sleep;
277
- this.beginStart();
326
+ __classPrivateFieldGet(this, _Kochava_instance, "f").sleep = sleep;
327
+ __classPrivateFieldGet(this, _Kochava_instances, "m", _Kochava_beginStart).call(this);
278
328
  }
279
329
  }
280
- // ============================= PRIVATE =============================== //
281
- // Unintialized/invalid state.
282
- // start must be called before these values will be correct.
283
- resetInstance() {
284
- this.instance = {
285
- appGuid: "",
286
- started: false,
287
- installStarted: false,
288
- kvinitDone: false,
289
- installDone: false,
290
- disableAutoPage: false,
291
- useCookies: false,
292
- sleep: false,
293
- version: "Web 3.0.0",
294
- buildDate: "",
295
- overrideUrls: {
296
- init: "",
297
- install: "",
298
- event: "",
299
- identityLink: "",
300
- },
301
- customValues: [],
302
- kochavaSession: "",
303
- retryWaterfall: [],
304
- startTimeMS: 0,
305
- utm: "",
306
- kochavaDeviceId: "",
307
- kochavaInstallId: "",
308
- kochavaSessionCount: -1,
309
- kochavaInstallDate: -1,
310
- kochavaConfig: undefined,
311
- };
312
- }
313
- initInstance(appGuid) {
314
- // init instance with defaults
315
- this.instance.appGuid = appGuid;
316
- this.instance.disableAutoPage = this.instance.disableAutoPage || false;
317
- this.instance.useCookies = this.instance.useCookies || false;
318
- this.instance.version = "Web 3.0.0";
319
- this.instance.buildDate = "kbd: 3/29/2022, 9:27:29 AM";
320
- this.instance.kochavaSession = utils.uuidv4().substring(0, 5);
321
- this.instance.startTimeMS = utils.getCurrTimeMS();
322
- this.instance.retryWaterfall = [7, 30, 300, 1800];
323
- this.instance.kochavaConfig = JSON.parse(JSON.stringify(DEFAULTS));
324
- }
325
- checkFirstLaunchAndMigrate() {
326
- // If this is our first launch ever, set it in persistence.
327
- if (!readAndUpdatePersistedValue(PersistKey.FirstStartDate, this.instance.useCookies)) {
328
- updatePersistedValue(PersistKey.FirstStartDate, String(utils.getCurrTimeSec()), this.instance.useCookies);
329
- /*
330
- On a first launch of the v3 sdk, we need to migrate old persisted kv_id
331
- from v2.2, v2.3, and v2.5
332
- */
333
- // perform migration
334
- const oldKvId = readAndUpdatePersistedValue(PersistKey.OldKvid, this.instance.useCookies);
335
- if (oldKvId) {
336
- updatePersistedValue(PersistKey.DeviceId, oldKvId, this.instance.useCookies);
337
- updatePersistedValue(PersistKey.InstallSentDate, JSON.stringify(utils.getCurrTimeSec()), this.instance.useCookies);
338
- }
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);
339
384
  }
340
385
  }
341
- checkPersistedKvinit() {
342
- // check if persisted kvinit
343
- let persistedKvinit = {};
344
- const persistedKvinitStr = readAndUpdatePersistedValue(PersistKey.LastKvinit, this.instance.useCookies);
345
- if (persistedKvinitStr) {
346
- persistedKvinit = JSON.parse(persistedKvinitStr);
347
- if (persistedKvinit) {
348
- // if persisted kvinit, apply it
349
- Log.trace("Found persisted kvinit.", persistedKvinit);
350
- Kvinit.applyKvinitResp(this.instance, persistedKvinit);
351
- Log.trace("KochavaConfig after persistedKvinit:", JSON.parse(JSON.stringify(this.instance.kochavaConfig)));
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)));
353
397
  }
354
- // check refresh minimum too
355
- const persistedKvinitDateStr = readAndUpdatePersistedValue(PersistKey.KvinitSentDate, this.instance.useCookies);
356
- if (persistedKvinitDateStr) {
357
- const lastKvinitDate = JSON.parse(persistedKvinitDateStr);
358
- if (lastKvinitDate) {
359
- const refreshMin = this.instance.kochavaConfig.config.refresh_minimum;
360
- if (utils.getCurrTimeSec() - lastKvinitDate < refreshMin)
361
- this.instance.kvinitDone = true;
362
- }
398
+ }
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;
363
407
  }
364
408
  }
365
- checkPersistedState() {
366
- this.instance.installDone =
367
- readAndUpdatePersistedValue(PersistKey.InstallSentDate, this.instance.useCookies).length > 0;
368
- this.instance.kochavaInstallId = readAndUpdatePersistedValue(PersistKey.InstallId, this.instance.useCookies);
369
- this.instance.kochavaDeviceId = readAndUpdateDeviceId(this.instance.useCookies);
370
- this.instance.kochavaSessionCount = readAndUpdateSessionCount(this.instance.useCookies);
371
- this.instance.utm = readAndUpdateUTM(this.instance.appGuid, this.instance.useCookies);
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);
372
428
  }
373
- printStartupMsgs(appGuid) {
374
- Log.diagInfo(`Started SDK ${this.instance.version}
375
- published ${this.instance.buildDate}`);
376
- Log.diagInfo(`The log level is set to ${Log.getLogLevel()}`);
377
- Log.diagDebug(`This ${!this.instance.installDone ? "is" : "is not"} the first tracker SDK launch`);
378
- Log.diagDebug(`The kochava device id is ${this.instance.kochavaDeviceId}`);
379
- Log.diagDebug(`The kochava app GUID provided was ${appGuid}`);
429
+ else {
430
+ Log.diagDebug(`A new kvinit will not be sent`);
380
431
  }
381
- async beginStart() {
382
- // if we need to send a new kvinit, send it
383
- if (!this.instance.kvinitDone) {
384
- Log.diagDebug(`A new kvinit will be sent`);
385
- await this.performNewKvinit();
386
- }
387
- else {
388
- Log.diagDebug(`A new kvinit will not be sent`);
389
- }
390
- // if the install_id changed and thus a new install must go out
391
- if (this.checkResendId())
392
- this.instance.installDone = false;
393
- Log.diagDebug(`The install ${this.instance.installDone ? "has already" : "has not yet"} been sent`);
394
- if (this.instance.sleep)
395
- return;
396
- if (!this.instance.installDone) {
397
- await this.performInstall();
398
- }
399
- if (this.instance.kvinitDone && this.instance.installDone) {
400
- await this.jobQueue.start(this.instance);
401
- }
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);
402
440
  }
403
- async performNewKvinit() {
404
- this.instance.kvinitDone = await Kvinit.send(this.instance, this.instance.retryWaterfall);
405
- updatePersistedValue(PersistKey.KvinitSentDate, String(utils.getCurrTimeSec()), this.instance.useCookies);
406
- // if new kvinit, apply it
407
- let newKvinit = {};
408
- const newKvinitStr = readAndUpdatePersistedValue(PersistKey.LastKvinit, this.instance.useCookies);
409
- if (newKvinitStr) {
410
- newKvinit = JSON.parse(newKvinitStr);
411
- }
412
- Kvinit.applyKvinitResp(this.instance, newKvinit);
413
- Log.trace("KochavaConfig after new Kvinit:", JSON.parse(JSON.stringify(this.instance.kochavaConfig)));
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"));
414
443
  }
415
- checkResendId() {
416
- let resendId = "";
417
- if (this.instance.kochavaConfig.install) {
418
- resendId = this.instance.kochavaConfig.install.resend_id;
419
- }
420
- const needsNewInstall = checkInstallIdChange(resendId, this.instance.useCookies);
421
- if (needsNewInstall) {
422
- Log.debug(`resend_id ${resendId} found, forcing new install`);
423
- }
424
- return needsNewInstall;
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);
425
452
  }
426
- async performInstall() {
427
- const request = Install.build(this.instance);
428
- this.instance.installDone = await Install.send(this.instance, request);
429
- if (!this.instance.installDone)
430
- return;
431
- // If the install succeeded, remove all idLink that were passed to it
432
- Install.onSuccess(this.instance);
433
- updatePersistedValue(PersistKey.IdLinkQueue, JSON.stringify(this.jobQueue.idLinkQueue), false);
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;
434
459
  }
435
- }
436
- window.kochava = new Kochava();
460
+ const needsNewInstall = checkInstallIdChange(resendId, __classPrivateFieldGet(this, _Kochava_instance, "f").useCookies);
461
+ if (needsNewInstall) {
462
+ Log.debug(`resend_id ${resendId} found, forcing new install`);
463
+ }
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
+ };
474
+ // Only here for generic Web integration
475
+ window.kochava = Kochava.create();
package/package.json CHANGED
@@ -1,12 +1,11 @@
1
1
  {
2
- "type": "module",
3
2
  "name": "kv-test-lib",
4
- "version": "1.0.2",
5
- "description": "",
3
+ "version": "1.0.3",
6
4
  "main": "dist/kochava.js",
7
5
  "files": [
8
- "dist"
6
+ "dist/"
9
7
  ],
8
+ "description": "",
10
9
  "scripts": {
11
10
  "build": "tsc -p ../../src/tsconfig.node.json",
12
11
  "test": "tsc -p ."