kv-test-lib 1.0.2 → 1.0.23
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/kochava.d.ts +6 -12
- package/dist/kochava.js +228 -191
- package/package.json +3 -3
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
|
|
32
|
-
private jobQueue;
|
|
31
|
+
#private;
|
|
33
32
|
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
|
-
//
|
|
26
|
+
// User will use the below factories instead of directly calling
|
|
27
|
+
// the constructor
|
|
15
28
|
constructor() {
|
|
16
|
-
|
|
17
|
-
this
|
|
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: "3.0.0" }));
|
|
42
|
+
return kochava;
|
|
43
|
+
}
|
|
44
|
+
static createForReact() {
|
|
45
|
+
const kochava = new Kochava();
|
|
46
|
+
kochava.executeAdvancedInstruction("wrapper", JSON.stringify({ name: "React", version: "3.0.0" }));
|
|
47
|
+
return kochava;
|
|
48
|
+
}
|
|
49
|
+
static createForVue() {
|
|
50
|
+
const kochava = new Kochava();
|
|
51
|
+
kochava.executeAdvancedInstruction("wrapper", JSON.stringify({ name: "Vue", version: "3.0.0" }));
|
|
52
|
+
return kochava;
|
|
53
|
+
}
|
|
54
|
+
static createForAngular() {
|
|
55
|
+
const kochava = new Kochava();
|
|
56
|
+
kochava.executeAdvancedInstruction("wrapper", JSON.stringify({ name: "Angular", version: "3.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.
|
|
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.
|
|
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
|
|
56
|
-
this.
|
|
57
|
-
if (this.
|
|
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.
|
|
63
|
-
this.
|
|
64
|
-
this.
|
|
65
|
-
if (!this.
|
|
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.
|
|
68
|
-
this.
|
|
69
|
-
this.
|
|
70
|
-
this.
|
|
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.
|
|
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.
|
|
129
|
+
__classPrivateFieldGet(this, _Kochava_jobQueue, "f").stop();
|
|
90
130
|
// wipe whatever was previously in the queue
|
|
91
|
-
this
|
|
92
|
-
this.
|
|
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
|
-
|
|
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.
|
|
177
|
+
__classPrivateFieldGet(this, _Kochava_instance, "f").overrideUrls.init = overrideUrls.init;
|
|
129
178
|
if (overrideUrls.event)
|
|
130
|
-
this.
|
|
179
|
+
__classPrivateFieldGet(this, _Kochava_instance, "f").overrideUrls.event = overrideUrls.event;
|
|
131
180
|
if (overrideUrls.install)
|
|
132
|
-
this.
|
|
181
|
+
__classPrivateFieldGet(this, _Kochava_instance, "f").overrideUrls.install = overrideUrls.install;
|
|
133
182
|
if (overrideUrls.identityLink)
|
|
134
|
-
this.
|
|
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.
|
|
191
|
+
__classPrivateFieldGet(this, _Kochava_instance, "f").overrideUrls.init = DEFAULTS.networking.urls.init;
|
|
143
192
|
if (url === "event")
|
|
144
|
-
this.
|
|
193
|
+
__classPrivateFieldGet(this, _Kochava_instance, "f").overrideUrls.event = DEFAULTS.networking.urls.event;
|
|
145
194
|
if (url === "install")
|
|
146
|
-
this.
|
|
195
|
+
__classPrivateFieldGet(this, _Kochava_instance, "f").overrideUrls.install =
|
|
147
196
|
DEFAULTS.networking.urls.install;
|
|
148
197
|
if (url === "identityLink")
|
|
149
|
-
this.
|
|
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
|
|
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.
|
|
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,10 @@ export class Kochava {
|
|
|
211
260
|
}
|
|
212
261
|
const idLink = {};
|
|
213
262
|
idLink[name] = identifier;
|
|
214
|
-
addPersistedIdLinks(name, identifier, this.
|
|
215
|
-
if (this.
|
|
263
|
+
addPersistedIdLinks(name, identifier, __classPrivateFieldGet(this, _Kochava_instance, "f").useCookies);
|
|
264
|
+
if (__classPrivateFieldGet(this, _Kochava_instance, "f").installStarted || __classPrivateFieldGet(this, _Kochava_instance, "f").installDone) {
|
|
216
265
|
// it will be sent standalone
|
|
217
|
-
this.
|
|
266
|
+
__classPrivateFieldGet(this, _Kochava_jobQueue, "f").enqueueIdLink(__classPrivateFieldGet(this, _Kochava_instance, "f"), idLink);
|
|
218
267
|
}
|
|
219
268
|
// will be sent in install
|
|
220
269
|
}
|
|
@@ -227,7 +276,7 @@ export class Kochava {
|
|
|
227
276
|
}
|
|
228
277
|
const dataToAdorn = {};
|
|
229
278
|
dataToAdorn[name] = value;
|
|
230
|
-
this.
|
|
279
|
+
__classPrivateFieldGet(this, _Kochava_instance, "f").customValues.push({ data: dataToAdorn, isDeviceId: false });
|
|
231
280
|
}
|
|
232
281
|
// Allows the client to attach arbitrary identifiers to go out in the install.
|
|
233
282
|
registerCustomDeviceIdentifier(name, value) {
|
|
@@ -238,7 +287,7 @@ export class Kochava {
|
|
|
238
287
|
}
|
|
239
288
|
const dataToAdorn = {};
|
|
240
289
|
dataToAdorn[name] = value;
|
|
241
|
-
this.
|
|
290
|
+
__classPrivateFieldGet(this, _Kochava_instance, "f").customValues.push({ data: dataToAdorn, isDeviceId: true });
|
|
242
291
|
}
|
|
243
292
|
/*
|
|
244
293
|
Returns whether or not the sdk is in a "started" state.
|
|
@@ -247,15 +296,15 @@ export class Kochava {
|
|
|
247
296
|
Likewise, shutdown will set "started" to false;
|
|
248
297
|
*/
|
|
249
298
|
getStarted() {
|
|
250
|
-
return this.
|
|
299
|
+
return __classPrivateFieldGet(this, _Kochava_instance, "f").started;
|
|
251
300
|
}
|
|
252
301
|
/*
|
|
253
302
|
Returns the current kochavaDeviceId, or "" if called too early.
|
|
254
303
|
*/
|
|
255
304
|
getDeviceId() {
|
|
256
305
|
Log.diagDebug(`Host called API: Get Kochava Device Id`);
|
|
257
|
-
if (this.
|
|
258
|
-
return this.
|
|
306
|
+
if (__classPrivateFieldGet(this, _Kochava_instance, "f").started)
|
|
307
|
+
return __classPrivateFieldGet(this, _Kochava_instance, "f").kochavaDeviceId;
|
|
259
308
|
else
|
|
260
309
|
return "";
|
|
261
310
|
}
|
|
@@ -266,171 +315,159 @@ export class Kochava {
|
|
|
266
315
|
*/
|
|
267
316
|
setSleep(sleep) {
|
|
268
317
|
Log.diagDebug(`Host called API: Sleep ${sleep ? "Stop" : "Start"}`);
|
|
269
|
-
if (sleep && !this.
|
|
318
|
+
if (sleep && !__classPrivateFieldGet(this, _Kochava_instance, "f").sleep) {
|
|
270
319
|
// only pause if it was running
|
|
271
|
-
this.
|
|
272
|
-
this.
|
|
320
|
+
__classPrivateFieldGet(this, _Kochava_instance, "f").sleep = sleep;
|
|
321
|
+
__classPrivateFieldGet(this, _Kochava_jobQueue, "f").pause();
|
|
273
322
|
}
|
|
274
|
-
else if (!sleep && this.
|
|
323
|
+
else if (!sleep && __classPrivateFieldGet(this, _Kochava_instance, "f").sleep) {
|
|
275
324
|
// only resume queueing if it was paused
|
|
276
|
-
this.
|
|
277
|
-
this.
|
|
325
|
+
__classPrivateFieldGet(this, _Kochava_instance, "f").sleep = sleep;
|
|
326
|
+
__classPrivateFieldGet(this, _Kochava_instances, "m", _Kochava_beginStart).call(this);
|
|
278
327
|
}
|
|
279
328
|
}
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
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
|
-
}
|
|
329
|
+
}
|
|
330
|
+
_Kochava_instance = new WeakMap(), _Kochava_jobQueue = new WeakMap(), _Kochava_instances = new WeakSet(), _Kochava_resetInstance = function _Kochava_resetInstance() {
|
|
331
|
+
__classPrivateFieldSet(this, _Kochava_instance, {
|
|
332
|
+
appGuid: "",
|
|
333
|
+
started: false,
|
|
334
|
+
installStarted: false,
|
|
335
|
+
kvinitDone: false,
|
|
336
|
+
installDone: false,
|
|
337
|
+
disableAutoPage: false,
|
|
338
|
+
useCookies: false,
|
|
339
|
+
sleep: false,
|
|
340
|
+
version: "",
|
|
341
|
+
buildDate: "",
|
|
342
|
+
overrideUrls: {
|
|
343
|
+
init: "",
|
|
344
|
+
install: "",
|
|
345
|
+
event: "",
|
|
346
|
+
identityLink: "",
|
|
347
|
+
},
|
|
348
|
+
customValues: [],
|
|
349
|
+
kochavaSession: "",
|
|
350
|
+
retryWaterfall: [],
|
|
351
|
+
startTimeMS: 0,
|
|
352
|
+
utm: "",
|
|
353
|
+
kochavaDeviceId: "",
|
|
354
|
+
kochavaInstallId: "",
|
|
355
|
+
kochavaSessionCount: -1,
|
|
356
|
+
kochavaInstallDate: -1,
|
|
357
|
+
kochavaConfig: undefined,
|
|
358
|
+
}, "f");
|
|
359
|
+
}, _Kochava_initInstance = function _Kochava_initInstance(appGuid) {
|
|
360
|
+
// init instance with defaults
|
|
361
|
+
__classPrivateFieldGet(this, _Kochava_instance, "f").appGuid = appGuid;
|
|
362
|
+
__classPrivateFieldGet(this, _Kochava_instance, "f").disableAutoPage = __classPrivateFieldGet(this, _Kochava_instance, "f").disableAutoPage || false;
|
|
363
|
+
__classPrivateFieldGet(this, _Kochava_instance, "f").useCookies = __classPrivateFieldGet(this, _Kochava_instance, "f").useCookies || false;
|
|
364
|
+
__classPrivateFieldGet(this, _Kochava_instance, "f").version = __classPrivateFieldGet(this, _Kochava_instance, "f").version || "WebTracker 3.0.0";
|
|
365
|
+
__classPrivateFieldGet(this, _Kochava_instance, "f").buildDate = "kbd: 3/31/2022, 10:50:51 AM";
|
|
366
|
+
__classPrivateFieldGet(this, _Kochava_instance, "f").kochavaSession = utils.uuidv4().substring(0, 5);
|
|
367
|
+
__classPrivateFieldGet(this, _Kochava_instance, "f").startTimeMS = utils.getCurrTimeMS();
|
|
368
|
+
__classPrivateFieldGet(this, _Kochava_instance, "f").retryWaterfall = [7, 30, 300, 1800];
|
|
369
|
+
__classPrivateFieldGet(this, _Kochava_instance, "f").kochavaConfig = JSON.parse(JSON.stringify(DEFAULTS));
|
|
370
|
+
}, _Kochava_checkFirstLaunchAndMigrate = function _Kochava_checkFirstLaunchAndMigrate() {
|
|
371
|
+
// If this is our first launch ever, set it in persistence.
|
|
372
|
+
if (!readAndUpdatePersistedValue(PersistKey.FirstStartDate, __classPrivateFieldGet(this, _Kochava_instance, "f").useCookies)) {
|
|
373
|
+
updatePersistedValue(PersistKey.FirstStartDate, String(utils.getCurrTimeSec()), __classPrivateFieldGet(this, _Kochava_instance, "f").useCookies);
|
|
374
|
+
/*
|
|
375
|
+
On a first launch of the v3 sdk, we need to migrate old persisted kv_id
|
|
376
|
+
from v2.2, v2.3, and v2.5
|
|
377
|
+
*/
|
|
378
|
+
// perform migration
|
|
379
|
+
const oldKvId = readAndUpdatePersistedValue(PersistKey.OldKvid, __classPrivateFieldGet(this, _Kochava_instance, "f").useCookies);
|
|
380
|
+
if (oldKvId) {
|
|
381
|
+
updatePersistedValue(PersistKey.DeviceId, oldKvId, __classPrivateFieldGet(this, _Kochava_instance, "f").useCookies);
|
|
382
|
+
updatePersistedValue(PersistKey.InstallSentDate, JSON.stringify(utils.getCurrTimeSec()), __classPrivateFieldGet(this, _Kochava_instance, "f").useCookies);
|
|
339
383
|
}
|
|
340
384
|
}
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
}
|
|
385
|
+
}, _Kochava_checkPersistedKvinit = function _Kochava_checkPersistedKvinit() {
|
|
386
|
+
// check if persisted kvinit
|
|
387
|
+
let persistedKvinit = {};
|
|
388
|
+
const persistedKvinitStr = readAndUpdatePersistedValue(PersistKey.LastKvinit, __classPrivateFieldGet(this, _Kochava_instance, "f").useCookies);
|
|
389
|
+
if (persistedKvinitStr) {
|
|
390
|
+
persistedKvinit = JSON.parse(persistedKvinitStr);
|
|
391
|
+
if (persistedKvinit) {
|
|
392
|
+
// if persisted kvinit, apply it
|
|
393
|
+
Log.trace("Found persisted kvinit.", persistedKvinit);
|
|
394
|
+
Kvinit.applyKvinitResp(__classPrivateFieldGet(this, _Kochava_instance, "f"), persistedKvinit);
|
|
395
|
+
Log.trace("KochavaConfig after persistedKvinit:", JSON.parse(JSON.stringify(__classPrivateFieldGet(this, _Kochava_instance, "f").kochavaConfig)));
|
|
353
396
|
}
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
397
|
+
}
|
|
398
|
+
// check refresh minimum too
|
|
399
|
+
const persistedKvinitDateStr = readAndUpdatePersistedValue(PersistKey.KvinitSentDate, __classPrivateFieldGet(this, _Kochava_instance, "f").useCookies);
|
|
400
|
+
if (persistedKvinitDateStr) {
|
|
401
|
+
const lastKvinitDate = JSON.parse(persistedKvinitDateStr);
|
|
402
|
+
if (lastKvinitDate) {
|
|
403
|
+
const refreshMin = __classPrivateFieldGet(this, _Kochava_instance, "f").kochavaConfig.config.refresh_minimum;
|
|
404
|
+
if (utils.getCurrTimeSec() - lastKvinitDate < refreshMin)
|
|
405
|
+
__classPrivateFieldGet(this, _Kochava_instance, "f").kvinitDone = true;
|
|
363
406
|
}
|
|
364
407
|
}
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
408
|
+
}, _Kochava_checkPersistedState = function _Kochava_checkPersistedState() {
|
|
409
|
+
__classPrivateFieldGet(this, _Kochava_instance, "f").installDone =
|
|
410
|
+
readAndUpdatePersistedValue(PersistKey.InstallSentDate, __classPrivateFieldGet(this, _Kochava_instance, "f").useCookies).length > 0;
|
|
411
|
+
__classPrivateFieldGet(this, _Kochava_instance, "f").kochavaInstallId = readAndUpdatePersistedValue(PersistKey.InstallId, __classPrivateFieldGet(this, _Kochava_instance, "f").useCookies);
|
|
412
|
+
__classPrivateFieldGet(this, _Kochava_instance, "f").kochavaDeviceId = readAndUpdateDeviceId(__classPrivateFieldGet(this, _Kochava_instance, "f").useCookies);
|
|
413
|
+
__classPrivateFieldGet(this, _Kochava_instance, "f").kochavaSessionCount = readAndUpdateSessionCount(__classPrivateFieldGet(this, _Kochava_instance, "f").useCookies);
|
|
414
|
+
__classPrivateFieldGet(this, _Kochava_instance, "f").utm = readAndUpdateUTM(__classPrivateFieldGet(this, _Kochava_instance, "f").appGuid, __classPrivateFieldGet(this, _Kochava_instance, "f").useCookies);
|
|
415
|
+
}, _Kochava_printStartupMsgs = function _Kochava_printStartupMsgs(appGuid) {
|
|
416
|
+
Log.diagInfo(`Started SDK ${__classPrivateFieldGet(this, _Kochava_instance, "f").version}
|
|
417
|
+
published ${__classPrivateFieldGet(this, _Kochava_instance, "f").buildDate}`);
|
|
418
|
+
Log.diagInfo(`The log level is set to ${Log.getLogLevel()}`);
|
|
419
|
+
Log.diagDebug(`This ${!__classPrivateFieldGet(this, _Kochava_instance, "f").installDone ? "is" : "is not"} the first tracker SDK launch`);
|
|
420
|
+
Log.diagDebug(`The kochava device id is ${__classPrivateFieldGet(this, _Kochava_instance, "f").kochavaDeviceId}`);
|
|
421
|
+
Log.diagDebug(`The kochava app GUID provided was ${appGuid}`);
|
|
422
|
+
}, _Kochava_beginStart = async function _Kochava_beginStart() {
|
|
423
|
+
// if we need to send a new kvinit, send it
|
|
424
|
+
if (!__classPrivateFieldGet(this, _Kochava_instance, "f").kvinitDone) {
|
|
425
|
+
Log.diagDebug(`A new kvinit will be sent`);
|
|
426
|
+
await __classPrivateFieldGet(this, _Kochava_instances, "m", _Kochava_performNewKvinit).call(this);
|
|
372
427
|
}
|
|
373
|
-
|
|
374
|
-
Log.
|
|
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}`);
|
|
428
|
+
else {
|
|
429
|
+
Log.diagDebug(`A new kvinit will not be sent`);
|
|
380
430
|
}
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
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
|
-
}
|
|
431
|
+
// if the install_id changed and thus a new install must go out
|
|
432
|
+
if (__classPrivateFieldGet(this, _Kochava_instances, "m", _Kochava_checkResendId).call(this))
|
|
433
|
+
__classPrivateFieldGet(this, _Kochava_instance, "f").installDone = false;
|
|
434
|
+
Log.diagDebug(`The install ${__classPrivateFieldGet(this, _Kochava_instance, "f").installDone ? "has already" : "has not yet"} been sent`);
|
|
435
|
+
if (__classPrivateFieldGet(this, _Kochava_instance, "f").sleep)
|
|
436
|
+
return;
|
|
437
|
+
if (!__classPrivateFieldGet(this, _Kochava_instance, "f").installDone) {
|
|
438
|
+
await __classPrivateFieldGet(this, _Kochava_instances, "m", _Kochava_performInstall).call(this);
|
|
402
439
|
}
|
|
403
|
-
|
|
404
|
-
this
|
|
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)));
|
|
440
|
+
if (__classPrivateFieldGet(this, _Kochava_instance, "f").kvinitDone && __classPrivateFieldGet(this, _Kochava_instance, "f").installDone) {
|
|
441
|
+
await __classPrivateFieldGet(this, _Kochava_jobQueue, "f").start(__classPrivateFieldGet(this, _Kochava_instance, "f"));
|
|
414
442
|
}
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
}
|
|
424
|
-
return needsNewInstall;
|
|
443
|
+
}, _Kochava_performNewKvinit = async function _Kochava_performNewKvinit() {
|
|
444
|
+
__classPrivateFieldGet(this, _Kochava_instance, "f").kvinitDone = await Kvinit.send(__classPrivateFieldGet(this, _Kochava_instance, "f"), __classPrivateFieldGet(this, _Kochava_instance, "f").retryWaterfall);
|
|
445
|
+
updatePersistedValue(PersistKey.KvinitSentDate, String(utils.getCurrTimeSec()), __classPrivateFieldGet(this, _Kochava_instance, "f").useCookies);
|
|
446
|
+
// if new kvinit, apply it
|
|
447
|
+
let newKvinit = {};
|
|
448
|
+
const newKvinitStr = readAndUpdatePersistedValue(PersistKey.LastKvinit, __classPrivateFieldGet(this, _Kochava_instance, "f").useCookies);
|
|
449
|
+
if (newKvinitStr) {
|
|
450
|
+
newKvinit = JSON.parse(newKvinitStr);
|
|
425
451
|
}
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
Install.onSuccess(this.instance);
|
|
433
|
-
updatePersistedValue(PersistKey.IdLinkQueue, JSON.stringify(this.jobQueue.idLinkQueue), false);
|
|
452
|
+
Kvinit.applyKvinitResp(__classPrivateFieldGet(this, _Kochava_instance, "f"), newKvinit);
|
|
453
|
+
Log.trace("KochavaConfig after new Kvinit:", JSON.parse(JSON.stringify(__classPrivateFieldGet(this, _Kochava_instance, "f").kochavaConfig)));
|
|
454
|
+
}, _Kochava_checkResendId = function _Kochava_checkResendId() {
|
|
455
|
+
let resendId = "";
|
|
456
|
+
if (__classPrivateFieldGet(this, _Kochava_instance, "f").kochavaConfig.install) {
|
|
457
|
+
resendId = __classPrivateFieldGet(this, _Kochava_instance, "f").kochavaConfig.install.resend_id;
|
|
434
458
|
}
|
|
435
|
-
|
|
436
|
-
|
|
459
|
+
const needsNewInstall = checkInstallIdChange(resendId, __classPrivateFieldGet(this, _Kochava_instance, "f").useCookies);
|
|
460
|
+
if (needsNewInstall) {
|
|
461
|
+
Log.debug(`resend_id ${resendId} found, forcing new install`);
|
|
462
|
+
}
|
|
463
|
+
return needsNewInstall;
|
|
464
|
+
}, _Kochava_performInstall = async function _Kochava_performInstall() {
|
|
465
|
+
const request = Install.build(__classPrivateFieldGet(this, _Kochava_instance, "f"));
|
|
466
|
+
__classPrivateFieldGet(this, _Kochava_instance, "f").installDone = await Install.send(__classPrivateFieldGet(this, _Kochava_instance, "f"), request);
|
|
467
|
+
if (!__classPrivateFieldGet(this, _Kochava_instance, "f").installDone)
|
|
468
|
+
return;
|
|
469
|
+
// If the install succeeded, remove all idLink that were passed to it
|
|
470
|
+
Install.onSuccess(__classPrivateFieldGet(this, _Kochava_instance, "f"));
|
|
471
|
+
updatePersistedValue(PersistKey.IdLinkQueue, JSON.stringify(__classPrivateFieldGet(this, _Kochava_jobQueue, "f").idLinkQueue), false);
|
|
472
|
+
};
|
|
473
|
+
// window.kochava = new Kochava();
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "kv-test-lib",
|
|
4
|
-
"version": "1.0.
|
|
5
|
-
"description": "",
|
|
4
|
+
"version": "1.0.23",
|
|
6
5
|
"main": "dist/kochava.js",
|
|
7
6
|
"files": [
|
|
8
|
-
"dist"
|
|
7
|
+
"dist/"
|
|
9
8
|
],
|
|
9
|
+
"description": "",
|
|
10
10
|
"scripts": {
|
|
11
11
|
"build": "tsc -p ../../src/tsconfig.node.json",
|
|
12
12
|
"test": "tsc -p ."
|