kv-test-lib 1.0.26 → 3.3.0

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.

Potentially problematic release.


This version of kv-test-lib might be problematic. Click here for more details.

Files changed (70) hide show
  1. package/README.md +12 -0
  2. package/es5_dist/adapters/adapter.browser.js +3 -0
  3. package/es5_dist/adapters/adapter.browser.js.map +1 -0
  4. package/es5_dist/adapters/browser.js +117 -0
  5. package/es5_dist/adapters/browser.js.map +1 -0
  6. package/es5_dist/adapters/crypto.browser.js +11 -0
  7. package/es5_dist/adapters/crypto.browser.js.map +1 -0
  8. package/es5_dist/browser/browser.js +49 -0
  9. package/es5_dist/browser/browser.js.map +1 -0
  10. package/es5_dist/browser/cookies.js +36 -0
  11. package/es5_dist/browser/cookies.js.map +1 -0
  12. package/es5_dist/browser/persist.js +549 -0
  13. package/es5_dist/browser/persist.js.map +1 -0
  14. package/es5_dist/core/crypto.js +2 -0
  15. package/es5_dist/core/crypto.js.map +1 -0
  16. package/es5_dist/core/storage.js +2 -0
  17. package/es5_dist/core/storage.js.map +1 -0
  18. package/es5_dist/http.js +133 -0
  19. package/es5_dist/http.js.map +1 -0
  20. package/{dist → es5_dist}/interfaces.js +9 -7
  21. package/es5_dist/interfaces.js.map +1 -0
  22. package/es5_dist/jobqueue.js +484 -0
  23. package/es5_dist/jobqueue.js.map +1 -0
  24. package/es5_dist/kochava.js +790 -0
  25. package/es5_dist/kochava.js.map +1 -0
  26. package/es5_dist/measurementEvent.js +253 -0
  27. package/es5_dist/measurementEvent.js.map +1 -0
  28. package/es5_dist/payloads/event.js +192 -0
  29. package/es5_dist/payloads/event.js.map +1 -0
  30. package/es5_dist/payloads/identityLink.js +170 -0
  31. package/es5_dist/payloads/identityLink.js.map +1 -0
  32. package/es5_dist/payloads/install.js +324 -0
  33. package/es5_dist/payloads/install.js.map +1 -0
  34. package/es5_dist/payloads/kvinit.js +296 -0
  35. package/es5_dist/payloads/kvinit.js.map +1 -0
  36. package/{dist → es5_dist}/payloads/payload.js +9 -9
  37. package/es5_dist/payloads/payload.js.map +1 -0
  38. package/es5_dist/polyfills/browser.js +3 -0
  39. package/es5_dist/polyfills/browser.js.map +1 -0
  40. package/es5_dist/utils/log.js +140 -0
  41. package/es5_dist/utils/log.js.map +1 -0
  42. package/es5_dist/utils/utils.js +26 -0
  43. package/es5_dist/utils/utils.js.map +1 -0
  44. package/package.json +4 -4
  45. package/dist/browser/browser.d.ts +0 -8
  46. package/dist/browser/browser.js +0 -40
  47. package/dist/browser/cookies.d.ts +0 -3
  48. package/dist/browser/cookies.js +0 -40
  49. package/dist/browser/persist.d.ts +0 -33
  50. package/dist/browser/persist.js +0 -195
  51. package/dist/http.d.ts +0 -6
  52. package/dist/http.js +0 -23
  53. package/dist/interfaces.d.ts +0 -117
  54. package/dist/jobqueue.d.ts +0 -35
  55. package/dist/jobqueue.js +0 -220
  56. package/dist/kochava.d.ts +0 -52
  57. package/dist/kochava.js +0 -477
  58. package/dist/payloads/event.d.ts +0 -6
  59. package/dist/payloads/event.js +0 -92
  60. package/dist/payloads/identityLink.d.ts +0 -7
  61. package/dist/payloads/identityLink.js +0 -73
  62. package/dist/payloads/install.d.ts +0 -6
  63. package/dist/payloads/install.js +0 -148
  64. package/dist/payloads/kvinit.d.ts +0 -5
  65. package/dist/payloads/kvinit.js +0 -134
  66. package/dist/payloads/payload.d.ts +0 -33
  67. package/dist/utils/log.d.ts +0 -30
  68. package/dist/utils/log.js +0 -104
  69. package/dist/utils/utils.d.ts +0 -5
  70. package/dist/utils/utils.js +0 -21
package/dist/jobqueue.js DELETED
@@ -1,220 +0,0 @@
1
- /*
2
- Authored by Brett Barinaga on 11/17/21.
3
- Copyright (c) Kochava, Inc. All rights reserved.
4
- */
5
- import * as Event from "./payloads/event";
6
- import * as IdLink from "./payloads/identityLink";
7
- import { Log } from "./utils/log";
8
- import { uuidv4 } from "./utils/utils";
9
- import { addToPersistedEventQueue, PersistKey, removeFromEventPersistedQueue, removeFromIdLinkPersistedQueue, updateOrAddPersistedIdLinkQueue, updatePersistedValue } from "./browser/persist";
10
- function jobIsEventJob(obj) {
11
- return 'eventName' in obj;
12
- }
13
- function jobIsIdLinkJob(obj) {
14
- return 'idLink' in obj;
15
- }
16
- export default class JobQueue {
17
- constructor() {
18
- this.eventQueue = [];
19
- this.idLinkQueue = [];
20
- this.processing = false;
21
- this.stopped = false;
22
- this.paused = false;
23
- }
24
- async start(instance) {
25
- this.eventQueue = JSON.parse(localStorage.getItem(PersistKey.EventQueue)) || [];
26
- this.idLinkQueue = JSON.parse(localStorage.getItem(PersistKey.IdLinkQueue)) || [];
27
- this.updateEventJobs(instance);
28
- this.updateIdLinkJobs(instance);
29
- Log.trace("Starting Event Queue", JSON.parse(JSON.stringify(this.eventQueue)));
30
- Log.trace("Starting IdLink Queue", JSON.parse(JSON.stringify(this.idLinkQueue)));
31
- this.stopped = false;
32
- this.paused = false;
33
- await this.dequeueJob(instance);
34
- }
35
- stop() {
36
- this.stopped = true;
37
- if (this.timeOut)
38
- clearTimeout(this.timeOut);
39
- this.processing = false;
40
- }
41
- pause() {
42
- this.paused = true;
43
- }
44
- async enqueueEvent(instance, args) {
45
- const eventName = args[0];
46
- const eventData = args[1];
47
- const eventPreStartBody = Event.constructPreStart(instance, eventName, eventData);
48
- if (instance.installDone && instance.kvinitDone) {
49
- const postStartBody = Event.constructPostStart(instance, eventPreStartBody);
50
- const newJob = {
51
- id: uuidv4(),
52
- queuedBeforeStart: false,
53
- preStartBody: eventPreStartBody,
54
- postStartBody,
55
- retries: 0,
56
- eventName,
57
- };
58
- this.eventQueue.push(newJob);
59
- addToPersistedEventQueue(newJob);
60
- await this.dequeueJob(instance);
61
- return;
62
- }
63
- const newEventJob = {
64
- id: uuidv4(),
65
- queuedBeforeStart: true,
66
- preStartBody: eventPreStartBody,
67
- postStartBody: undefined,
68
- retries: 0,
69
- eventName,
70
- };
71
- this.eventQueue.push(newEventJob);
72
- addToPersistedEventQueue(newEventJob);
73
- }
74
- async enqueueIdLink(instance, idLink) {
75
- const idLinkPreStartBody = IdLink.constructPreStart(instance, idLink);
76
- if (instance.installDone && instance.kvinitDone) {
77
- const postStartBody = IdLink.constructPostStart(instance, idLinkPreStartBody);
78
- const newJob = {
79
- id: uuidv4(),
80
- queuedBeforeStart: false,
81
- preStartBody: idLinkPreStartBody,
82
- postStartBody,
83
- retries: 0,
84
- idLink,
85
- };
86
- updateOrAddPersistedIdLinkQueue(newJob);
87
- this.idLinkQueue.push(newJob);
88
- await this.dequeueJob(instance);
89
- return;
90
- }
91
- const newJob = {
92
- id: uuidv4(),
93
- queuedBeforeStart: true,
94
- preStartBody: idLinkPreStartBody,
95
- postStartBody: undefined,
96
- retries: 0,
97
- idLink,
98
- };
99
- updateOrAddPersistedIdLinkQueue(newJob);
100
- this.idLinkQueue.push(newJob);
101
- }
102
- async dequeueJob(instance) {
103
- // If queue is busy, prev job not finished
104
- if (this.processing)
105
- return false;
106
- // If the queue is paused, do not dequeue a new job
107
- if (this.paused)
108
- return false;
109
- // If the queue is stopped do not dequeue a new job
110
- if (this.stopped) {
111
- return false;
112
- }
113
- // Prioritize sending identityLinks first
114
- // Remove first job from queue
115
- const idLinkJob = this.idLinkQueue.shift();
116
- if (idLinkJob) {
117
- // handle idlinkjob
118
- Log.trace("Dequeued Job: ", idLinkJob);
119
- this.processing = true;
120
- const result = await this.processJob(instance, idLinkJob);
121
- if (this.stopped) {
122
- return true;
123
- }
124
- this.processing = false;
125
- // If the job succeeded, dequeue the next job
126
- if (result) {
127
- removeFromIdLinkPersistedQueue(idLinkJob);
128
- return await this.dequeueJob(instance);
129
- }
130
- }
131
- const eventJob = this.eventQueue.shift();
132
- if (eventJob) {
133
- //handle eventJob
134
- Log.trace("Dequeued Job: ", eventJob);
135
- // Process the job
136
- this.processing = true;
137
- const result = await this.processJob(instance, eventJob);
138
- if (this.stopped) {
139
- return true;
140
- }
141
- this.processing = false;
142
- // If the job succeeded, dequeue the next job
143
- if (result) {
144
- removeFromEventPersistedQueue(eventJob);
145
- return await this.dequeueJob(instance);
146
- }
147
- }
148
- // If neither queue had a job, break out of recursion
149
- if (!idLinkJob && !eventJob)
150
- return false;
151
- return true;
152
- }
153
- async processJob(instance, job) {
154
- if (jobIsEventJob(job)) {
155
- for (const denyName of instance.kochavaConfig.privacy.deny_event_names) {
156
- if (denyName === job.eventName) {
157
- Log.debug(`Denied event_name ${denyName}, dropping request.`);
158
- return true;
159
- }
160
- }
161
- }
162
- else if (jobIsIdLinkJob(job)) {
163
- for (const denyIdLinkKey of instance.kochavaConfig.privacy.deny_identity_links) {
164
- if (denyIdLinkKey === Object.keys(job.idLink)[0]) {
165
- Log.debug(`Denied identity_link ${denyIdLinkKey}, dropping request.`);
166
- return true;
167
- }
168
- }
169
- }
170
- let success = false;
171
- do {
172
- success = await this.attemptJob(instance, job);
173
- // If our job succeeded
174
- if (success) {
175
- // Job Done
176
- Log.trace("Job processed successfully:", job);
177
- return true;
178
- }
179
- // If it didnt succeed, but we our queue isnt stopped
180
- if (!this.stopped) {
181
- //retry the job
182
- const retryWaterfall = instance.kochavaConfig.networking.retry_waterfall;
183
- const retryIndex = (job.retries > retryWaterfall.length - 1) ?
184
- retryWaterfall.length - 1 : job.retries;
185
- const retrySec = retryWaterfall[retryIndex];
186
- Log.error(`Job failed, attempting again in ${retrySec} seconds`);
187
- await new Promise(resolve => this.timeOut = setTimeout(resolve, retrySec * 1000));
188
- job.retries++;
189
- }
190
- } while (!success && !this.stopped);
191
- // Job Canceled
192
- return true;
193
- }
194
- async attemptJob(instance, job) {
195
- if (job.preStartBody.action === "event")
196
- return await Event.send(instance, job.preStartBody, job.postStartBody);
197
- else if (job.preStartBody.action === "identityLink")
198
- return await IdLink.send(instance, job);
199
- else {
200
- Log.warn("Invalid action in job from jobqueue, cancelling.");
201
- return true;
202
- }
203
- }
204
- updateEventJobs(instance) {
205
- for (const job of this.eventQueue) {
206
- if (job.queuedBeforeStart) {
207
- job.postStartBody = Event.constructPostStart(instance, job.preStartBody);
208
- }
209
- }
210
- updatePersistedValue(PersistKey.EventQueue, JSON.stringify(this.eventQueue), false);
211
- }
212
- updateIdLinkJobs(instance) {
213
- for (const job of this.idLinkQueue) {
214
- if (job.queuedBeforeStart) {
215
- job.postStartBody = IdLink.constructPostStart(instance, job.preStartBody);
216
- }
217
- }
218
- updatePersistedValue(PersistKey.IdLinkQueue, JSON.stringify(this.idLinkQueue), false);
219
- }
220
- }
package/dist/kochava.d.ts DELETED
@@ -1,52 +0,0 @@
1
- import { Json, Urls, CustomValue, KvConfig } from "./interfaces";
2
- declare global {
3
- interface Window {
4
- kochava: Kochava;
5
- }
6
- }
7
- export interface KochavaInstance {
8
- appGuid: string;
9
- started: boolean;
10
- installStarted: boolean;
11
- kvinitDone: boolean;
12
- installDone: boolean;
13
- disableAutoPage: boolean;
14
- useCookies: boolean;
15
- sleep: boolean;
16
- version: string;
17
- buildDate: string;
18
- overrideUrls: Urls;
19
- customValues: CustomValue[];
20
- kochavaSession: string;
21
- retryWaterfall: number[];
22
- startTimeMS: number;
23
- utm: string;
24
- kochavaDeviceId: string;
25
- kochavaInstallId: string;
26
- kochavaInstallDate: number;
27
- kochavaSessionCount: number;
28
- kochavaConfig?: KvConfig;
29
- }
30
- export declare class Kochava {
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;
38
- useCookies(condition?: boolean): void;
39
- disableAutoPage(condition?: boolean): void;
40
- startWithAppGuid(appGuid: string): void;
41
- shutdown(deleteData: boolean): void;
42
- setLogLevel(logLevel: string): void;
43
- executeAdvancedInstruction(key: string, valueStr: string, callback?: (input: string) => void): void;
44
- sendEvent(name: string, data?: Json | string): void;
45
- sendPageEvent(pageName?: string, additionalData?: Json): void;
46
- registerIdentityLink(name: string, identifier: string): void;
47
- registerCustomValue(name: string, value: string): void;
48
- registerCustomDeviceIdentifier(name: string, value: string): void;
49
- getStarted(): boolean;
50
- getDeviceId(): string;
51
- setSleep(sleep: boolean): void;
52
- }