kv-test-lib 1.0.2 → 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/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
+
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 {
@@ -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
@@ -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,9 +32,14 @@ export interface KochavaInstance {
28
32
  kochavaConfig?: KvConfig;
29
33
  }
30
34
  export declare class Kochava {
31
- private instance;
32
- private jobQueue;
33
- constructor();
35
+ instance: KochavaInstance;
36
+ jobQueue: JobQueue;
37
+ private constructor();
38
+ static create(): Kochava;
39
+ static createForNode(): Kochava;
40
+ static createForReact(): Kochava;
41
+ static createForVue(): Kochava;
42
+ static createForAngular(): Kochava;
34
43
  useCookies(condition?: boolean): void;
35
44
  disableAutoPage(condition?: boolean): void;
36
45
  startWithAppGuid(appGuid: string): void;
@@ -45,14 +54,14 @@ export declare class Kochava {
45
54
  getStarted(): boolean;
46
55
  getDeviceId(): string;
47
56
  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;
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>;
58
67
  }
package/dist/kochava.js CHANGED
@@ -2,6 +2,9 @@
2
2
  Authored by Brett Barinaga on 11/17/21.
3
3
  Copyright (c) Kochava, Inc. All rights reserved.
4
4
  */
5
+ import 'core-js/stable';
6
+ import 'regenerator-runtime/runtime';
7
+ import 'whatwg-fetch';
5
8
  import { Log } from "./utils/log";
6
9
  import JobQueue from "./jobqueue";
7
10
  import * as Kvinit from "./payloads/kvinit";
@@ -10,12 +13,39 @@ import { DEFAULTS, } from "./interfaces";
10
13
  import { deleteAllPersisted, readAndUpdatePersistedValue, updatePersistedValue, PersistKey, checkDuplicateIdLink, addPersistedIdLinks, checkInstallIdChange, readAndUpdateSessionCount, readAndUpdateDeviceId, readAndUpdateUTM, } from "./browser/persist";
11
14
  import * as utils from "./utils/utils";
12
15
  import { getPageName } from "./browser/browser";
16
+ // NOTE: Update this with new releases.
17
+ const SDK_VERSION = "3.1.0";
13
18
  export class Kochava {
14
- // ============================= PUBLIC =============================== //
19
+ // User will use the below factories instead of directly calling
20
+ // the constructor
15
21
  constructor() {
16
22
  this.resetInstance();
17
23
  this.jobQueue = new JobQueue();
18
24
  }
25
+ // ============================= PUBLIC =============================== //
26
+ static create() {
27
+ return new Kochava();
28
+ }
29
+ static createForNode() {
30
+ const kochava = new Kochava();
31
+ kochava.executeAdvancedInstruction("wrapper", JSON.stringify({ name: "Node", version: "" }));
32
+ return kochava;
33
+ }
34
+ static createForReact() {
35
+ const kochava = new Kochava();
36
+ kochava.executeAdvancedInstruction("wrapper", JSON.stringify({ name: "React", version: "" }));
37
+ return kochava;
38
+ }
39
+ static createForVue() {
40
+ const kochava = new Kochava();
41
+ kochava.executeAdvancedInstruction("wrapper", JSON.stringify({ name: "Vue", version: "" }));
42
+ return kochava;
43
+ }
44
+ static createForAngular() {
45
+ const kochava = new Kochava();
46
+ kochava.executeAdvancedInstruction("wrapper", JSON.stringify({ name: "Angular", version: "1.0.0" }));
47
+ return kochava;
48
+ }
19
49
  /*
20
50
  Set if the SDK should also store persisted values in cookie storage.
21
51
  - Not all values can be persisted in cookies, such as event/idlink queues
@@ -118,7 +148,16 @@ export class Kochava {
118
148
  case "wrapper":
119
149
  {
120
150
  const wrapperVersion = JSON.parse(valueStr);
121
- this.instance.version = `${this.instance.version} (${wrapperVersion.name} ${wrapperVersion.version})`;
151
+ if (!this.instance.version)
152
+ this.instance.version = "WebTracker " + SDK_VERSION;
153
+ switch (wrapperVersion.name) {
154
+ case "Angular":
155
+ this.instance.version += ` (${wrapperVersion.name} ${wrapperVersion.version})`;
156
+ break;
157
+ default:
158
+ this.instance.version += ` (${wrapperVersion.name})`;
159
+ break;
160
+ }
122
161
  }
123
162
  break;
124
163
  case "urls":
@@ -212,7 +251,8 @@ export class Kochava {
212
251
  const idLink = {};
213
252
  idLink[name] = identifier;
214
253
  addPersistedIdLinks(name, identifier, this.instance.useCookies);
215
- if (this.instance.installStarted || this.instance.installDone) {
254
+ // if (this.instance.installStarted || this.instance.installDone) {
255
+ if (localStorage.getItem("com.kochava.tracker.InstallSentDate")) {
216
256
  // it will be sent standalone
217
257
  this.jobQueue.enqueueIdLink(this.instance, idLink);
218
258
  }
@@ -277,7 +317,7 @@ export class Kochava {
277
317
  this.beginStart();
278
318
  }
279
319
  }
280
- // ============================= PRIVATE =============================== //
320
+ // ============================= =============================== //
281
321
  // Unintialized/invalid state.
282
322
  // start must be called before these values will be correct.
283
323
  resetInstance() {
@@ -290,7 +330,7 @@ export class Kochava {
290
330
  disableAutoPage: false,
291
331
  useCookies: false,
292
332
  sleep: false,
293
- version: "Web 3.0.0",
333
+ version: "",
294
334
  buildDate: "",
295
335
  overrideUrls: {
296
336
  init: "",
@@ -315,8 +355,8 @@ export class Kochava {
315
355
  this.instance.appGuid = appGuid;
316
356
  this.instance.disableAutoPage = this.instance.disableAutoPage || false;
317
357
  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";
358
+ this.instance.version = this.instance.version || "WebTracker " + SDK_VERSION;
359
+ this.instance.buildDate = "kbd: 8/16/2024, 3:02:42 PM";
320
360
  this.instance.kochavaSession = utils.uuidv4().substring(0, 5);
321
361
  this.instance.startTimeMS = utils.getCurrTimeMS();
322
362
  this.instance.retryWaterfall = [7, 30, 300, 1800];
@@ -433,4 +473,5 @@ export class Kochava {
433
473
  updatePersistedValue(PersistKey.IdLinkQueue, JSON.stringify(this.jobQueue.idLinkQueue), false);
434
474
  }
435
475
  }
436
- window.kochava = new Kochava();
476
+ // Only here for generic Web integration
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,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.4",
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 ."