avo-inspector 3.2.0 → 3.2.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.
Files changed (84) hide show
  1. package/README.md +10 -0
  2. package/dist/AvoBatcher.d.ts +9 -3
  3. package/dist/AvoInspector.d.ts +4 -0
  4. package/dist/AvoNetworkCallsHandler.d.ts +80 -5
  5. package/dist/__tests__/UnboundPublicMethods_test.d.ts +1 -0
  6. package/dist/__tests__/constants.d.ts +2 -1
  7. package/dist/__tests__/helpers/internalGateway.d.ts +23 -0
  8. package/dist/eventSpec/AvoEventSpecCache.d.ts +7 -4
  9. package/dist/eventSpec/AvoEventSpecFetchTypes.d.ts +12 -1
  10. package/dist/eventSpec/AvoEventSpecFetcher.d.ts +6 -1
  11. package/dist/index.js +1 -1
  12. package/dist/lite/AvoBatcherLite.d.ts +9 -3
  13. package/dist/lite/AvoBatcherLite.js +46 -7
  14. package/dist/lite/AvoInspectorLite.d.ts +2 -0
  15. package/dist/lite/AvoInspectorLite.js +95 -15
  16. package/dist/lite/AvoNetworkCallsHandlerLite.d.ts +79 -5
  17. package/dist/lite/AvoNetworkCallsHandlerLite.js +300 -20
  18. package/package.json +10 -1
  19. package/dist/AvoBatcher.js +0 -87
  20. package/dist/AvoDeduplicator.js +0 -142
  21. package/dist/AvoEncryption.js +0 -176
  22. package/dist/AvoInspector.js +0 -435
  23. package/dist/AvoNetworkCallsHandler.js +0 -229
  24. package/dist/AvoSchemaParser.js +0 -95
  25. package/dist/AvoStreamId.js +0 -82
  26. package/dist/__mocks__/xhr.js +0 -14
  27. package/dist/__mocks__/xhrError.js +0 -14
  28. package/dist/__tests__/AvoEncryption.js +0 -272
  29. package/dist/__tests__/AvoEncryptionIntegration.js +0 -191
  30. package/dist/__tests__/AvoEventSpecFetcher.js +0 -377
  31. package/dist/__tests__/AvoInspector.js +0 -335
  32. package/dist/__tests__/Batcher.js +0 -214
  33. package/dist/__tests__/BatcherPublic.js +0 -139
  34. package/dist/__tests__/Deduplicator.js +0 -190
  35. package/dist/__tests__/EventSpecCache.js +0 -143
  36. package/dist/__tests__/EventValidator.js +0 -543
  37. package/dist/__tests__/InstallationId.js +0 -60
  38. package/dist/__tests__/NetworkCallsHandler.js +0 -222
  39. package/dist/__tests__/NetworkCallsHandlerModelA.js +0 -206
  40. package/dist/__tests__/Parsing.js +0 -115
  41. package/dist/__tests__/Sessions.d.ts +0 -1
  42. package/dist/__tests__/Sessions.js +0 -10
  43. package/dist/__tests__/Storage.d.ts +0 -1
  44. package/dist/__tests__/Storage.js +0 -173
  45. package/dist/__tests__/StreamId.d.ts +0 -1
  46. package/dist/__tests__/StreamId.js +0 -153
  47. package/dist/__tests__/constants.js +0 -48
  48. package/dist/esm/AvoBatcher.js +0 -75
  49. package/dist/esm/AvoDeduplicator.js +0 -137
  50. package/dist/esm/AvoEncryption.js +0 -277
  51. package/dist/esm/AvoGuid.js +0 -9
  52. package/dist/esm/AvoInspector.js +0 -470
  53. package/dist/esm/AvoInspectorEnv.js +0 -5
  54. package/dist/esm/AvoNetworkCallsHandler.js +0 -181
  55. package/dist/esm/AvoSchemaParser.js +0 -128
  56. package/dist/esm/AvoStorage.js +0 -176
  57. package/dist/esm/AvoStreamId.js +0 -140
  58. package/dist/esm/eventSpec/AvoEventSpecCache.js +0 -165
  59. package/dist/esm/eventSpec/AvoEventSpecFetchTypes.js +0 -6
  60. package/dist/esm/eventSpec/AvoEventSpecFetcher.js +0 -203
  61. package/dist/esm/eventSpec/EventValidator.js +0 -687
  62. package/dist/esm/eventSpec/index.js +0 -4
  63. package/dist/esm/index.js +0 -3
  64. package/dist/esm/utils.js +0 -38
  65. package/dist/esm/version.js +0 -2
  66. package/dist/eventSpec/AvoEventSpecCache.js +0 -181
  67. package/dist/eventSpec/AvoEventSpecFetcher.js +0 -290
  68. package/dist/eventSpec/EventValidator.js +0 -846
  69. package/dist/eventSpec/index.js +0 -20
  70. package/dist/version.d.ts +0 -1
  71. package/dist/version.js +0 -5
  72. /package/dist/__tests__/{AvoEncryption.d.ts → ApiKeyHeaderInjection_test.d.ts} +0 -0
  73. /package/dist/__tests__/{AvoEncryptionIntegration.d.ts → BrowserBootstrap_test.d.ts} +0 -0
  74. /package/dist/__tests__/{AvoEventSpecFetcher.d.ts → EventSpecGatewayCoordinates_test.d.ts} +0 -0
  75. /package/dist/__tests__/{AvoInspector.d.ts → InFlightQueueGaps_test.d.ts} +0 -0
  76. /package/dist/__tests__/{Batcher.d.ts → InFlightQueue_test.d.ts} +0 -0
  77. /package/dist/__tests__/{BatcherPublic.d.ts → NetworkCallsHandlerLite_test.d.ts} +0 -0
  78. /package/dist/__tests__/{Deduplicator.d.ts → PublicSurface_test.d.ts} +0 -0
  79. /package/dist/__tests__/{EventSpecCache.d.ts → TrackOptionsIntegration_test.d.ts} +0 -0
  80. /package/dist/__tests__/{EventValidator.d.ts → TrackOptionsTransport_test.d.ts} +0 -0
  81. /package/dist/__tests__/{InstallationId.d.ts → TrackingHeaders_test.d.ts} +0 -0
  82. /package/dist/__tests__/{NetworkCallsHandler.d.ts → V1WireBaseline_test.d.ts} +0 -0
  83. /package/dist/__tests__/{NetworkCallsHandlerModelA.d.ts → V2QueuedAttribution_test.d.ts} +0 -0
  84. /package/dist/__tests__/{Parsing.d.ts → V2StopSending_test.d.ts} +0 -0
@@ -1,173 +0,0 @@
1
- "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
- return new (P || (P = Promise))(function (resolve, reject) {
16
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
17
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
18
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
19
- step((generator = generator.apply(thisArg, _arguments || [])).next());
20
- });
21
- };
22
- var __generator = (this && this.__generator) || function (thisArg, body) {
23
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
- function verb(n) { return function (v) { return step([n, v]); }; }
26
- function step(op) {
27
- if (f) throw new TypeError("Generator is already executing.");
28
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
29
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
30
- if (y = 0, t) op = [op[0] & 2, t.value];
31
- switch (op[0]) {
32
- case 0: case 1: t = op; break;
33
- case 4: _.label++; return { value: op[1], done: false };
34
- case 5: _.label++; y = op[1]; op = [0]; continue;
35
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
- default:
37
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
- if (t[2]) _.ops.pop();
42
- _.trys.pop(); continue;
43
- }
44
- op = body.call(thisArg, _);
45
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
- }
48
- };
49
- Object.defineProperty(exports, "__esModule", { value: true });
50
- var AvoStorage_1 = require("../AvoStorage");
51
- var constants_1 = require("../__tests__/constants");
52
- var originalWindow = __assign({}, window);
53
- beforeEach(function () {
54
- window = originalWindow;
55
- });
56
- describe("Avo Storage", function () {
57
- var storage = new AvoStorage_1.AvoStorage(constants_1.defaultOptions.shouldLog);
58
- var key = "avoKey";
59
- var value = "avoValue";
60
- test("Sets and gets item with shouldLog on", function () {
61
- var storage = new AvoStorage_1.AvoStorage(true);
62
- storage.setItem(key, value);
63
- var item = storage.getItem(key);
64
- expect(item).toBe(value);
65
- });
66
- test("Sets and gets item with shouldLog off", function () {
67
- var storage = new AvoStorage_1.AvoStorage(false);
68
- storage.setItem(key, value);
69
- var item = storage.getItem(key);
70
- expect(item).toBe(value);
71
- });
72
- test("Gets item asynchronously", function () { return __awaiter(void 0, void 0, void 0, function () {
73
- var item;
74
- return __generator(this, function (_a) {
75
- switch (_a.label) {
76
- case 0:
77
- storage.removeItem(key);
78
- storage.setItem(key, value);
79
- return [4 /*yield*/, storage.getItemAsync(key)];
80
- case 1:
81
- item = _a.sent();
82
- expect(item).toBe(value);
83
- return [2 /*return*/];
84
- }
85
- });
86
- }); });
87
- test("Returns null if key does not exist", function () {
88
- storage.removeItem(key);
89
- var item = storage.getItem(key);
90
- expect(item).toBeNull();
91
- });
92
- test("Deletes item with shouldLog on", function () {
93
- var storage = new AvoStorage_1.AvoStorage(true);
94
- storage.removeItem(key);
95
- var item = storage.getItem(key);
96
- expect(item).toBeNull();
97
- });
98
- test("Deletes item with shouldLog off", function () {
99
- var storage = new AvoStorage_1.AvoStorage(false);
100
- storage.removeItem(key);
101
- var item = storage.getItem(key);
102
- expect(item).toBeNull();
103
- });
104
- test("storage writes are delayed until the storage is initialized on web", function () {
105
- var storageWebImpl = storage.storageImpl;
106
- storageWebImpl.storageInitialized = false;
107
- storage.setItem(key, "OnStorageInitFuncs on web");
108
- var itemBeforeInit = storage.getItem(key);
109
- expect(itemBeforeInit).toBeNull();
110
- storageWebImpl.init(true);
111
- var itemAfterInit = storage.getItem(key);
112
- expect(itemAfterInit).toEqual("OnStorageInitFuncs on web");
113
- });
114
- });
115
- describe("Avo Storage unavailable", function () {
116
- var key = "avoKey";
117
- var value = "avoValue";
118
- beforeEach(function () {
119
- Object.defineProperty(window, "localStorage", {});
120
- });
121
- test("Fallback mode enabled", function () {
122
- var storage = new AvoStorage_1.AvoStorage(false);
123
- var storageImpl = storage.storageImpl;
124
- expect(storageImpl.useFallbackStorage).toBe(true);
125
- expect(storageImpl.storageInitialized).toBe(true);
126
- });
127
- test("Sets and gets item with shouldLog on", function () {
128
- var storage = new AvoStorage_1.AvoStorage(true);
129
- storage.setItem(key, value);
130
- var item = storage.getItem(key);
131
- expect(item).toBe(value);
132
- });
133
- test("Sets and gets item with shouldLog off", function () {
134
- var storage = new AvoStorage_1.AvoStorage(false);
135
- storage.setItem(key, value);
136
- var item = storage.getItem(key);
137
- expect(item).toBe(value);
138
- });
139
- test("Gets item asynchronously", function () { return __awaiter(void 0, void 0, void 0, function () {
140
- var storage, item;
141
- return __generator(this, function (_a) {
142
- switch (_a.label) {
143
- case 0:
144
- storage = new AvoStorage_1.AvoStorage(false);
145
- storage.removeItem(key);
146
- storage.setItem(key, value);
147
- return [4 /*yield*/, storage.getItemAsync(key)];
148
- case 1:
149
- item = _a.sent();
150
- expect(item).toBe(value);
151
- return [2 /*return*/];
152
- }
153
- });
154
- }); });
155
- test("Returns null if key does not exist", function () {
156
- var storage = new AvoStorage_1.AvoStorage(false);
157
- storage.removeItem(key);
158
- var item = storage.getItem(key);
159
- expect(item).toBeNull();
160
- });
161
- test("Deletes item with shouldLog on", function () {
162
- var storage = new AvoStorage_1.AvoStorage(true);
163
- storage.removeItem(key);
164
- var item = storage.getItem(key);
165
- expect(item).toBeNull();
166
- });
167
- test("Deletes item with shouldLog off", function () {
168
- var storage = new AvoStorage_1.AvoStorage(false);
169
- storage.removeItem(key);
170
- var item = storage.getItem(key);
171
- expect(item).toBeNull();
172
- });
173
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,153 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
- }
37
- };
38
- Object.defineProperty(exports, "__esModule", { value: true });
39
- var AvoStreamId_1 = require("../AvoStreamId");
40
- var AvoStorage_1 = require("../AvoStorage");
41
- var AvoInspector_1 = require("../AvoInspector");
42
- var constants_1 = require("../__tests__/constants");
43
- describe("StreamId", function () {
44
- var storage = new AvoStorage_1.AvoStorage(constants_1.defaultOptions.shouldLog);
45
- beforeAll(function () {
46
- new AvoInspector_1.AvoInspector(constants_1.defaultOptions);
47
- });
48
- beforeEach(function () {
49
- // Reset the cached anonymousId between tests
50
- AvoStreamId_1.AvoStreamId._anonymousId = null;
51
- AvoStreamId_1.AvoStreamId._initializationPromise = null;
52
- });
53
- afterEach(function () {
54
- storage.removeItem(AvoStreamId_1.AvoStreamId.cacheKey);
55
- AvoStreamId_1.AvoStreamId._anonymousId = null;
56
- AvoStreamId_1.AvoStreamId._initializationPromise = null;
57
- });
58
- test("cacheKey equal to \"AvoInspectorAnonymousId\"", function () {
59
- expect(AvoStreamId_1.AvoStreamId.cacheKey).toEqual("AvoInspectorAnonymousId");
60
- });
61
- test("Returns a UUID after initialize()", function () { return __awaiter(void 0, void 0, void 0, function () {
62
- var id;
63
- return __generator(this, function (_a) {
64
- switch (_a.label) {
65
- case 0: return [4 /*yield*/, AvoStreamId_1.AvoStreamId.initialize()];
66
- case 1:
67
- id = _a.sent();
68
- expect(id).not.toBeNull();
69
- expect(typeof id).toBe("string");
70
- expect(id.length).toBeGreaterThan(0);
71
- return [2 /*return*/];
72
- }
73
- });
74
- }); });
75
- test("Persists the same UUID across multiple initialize() calls", function () { return __awaiter(void 0, void 0, void 0, function () {
76
- var id1, id2;
77
- return __generator(this, function (_a) {
78
- switch (_a.label) {
79
- case 0: return [4 /*yield*/, AvoStreamId_1.AvoStreamId.initialize()];
80
- case 1:
81
- id1 = _a.sent();
82
- // Reset in-memory cache to force re-read from storage
83
- AvoStreamId_1.AvoStreamId._anonymousId = null;
84
- AvoStreamId_1.AvoStreamId._initializationPromise = null;
85
- return [4 /*yield*/, AvoStreamId_1.AvoStreamId.initialize()];
86
- case 2:
87
- id2 = _a.sent();
88
- expect(id1).toBe(id2);
89
- return [2 /*return*/];
90
- }
91
- });
92
- }); });
93
- test("Returns cached value on second call without re-reading storage", function () { return __awaiter(void 0, void 0, void 0, function () {
94
- var id1, id2;
95
- return __generator(this, function (_a) {
96
- switch (_a.label) {
97
- case 0: return [4 /*yield*/, AvoStreamId_1.AvoStreamId.initialize()];
98
- case 1:
99
- id1 = _a.sent();
100
- return [4 /*yield*/, AvoStreamId_1.AvoStreamId.initialize()];
101
- case 2:
102
- id2 = _a.sent();
103
- expect(id1).toBe(id2);
104
- return [2 /*return*/];
105
- }
106
- });
107
- }); });
108
- test("Concurrent calls before cache populated all return same UUID (promise lock)", function () { return __awaiter(void 0, void 0, void 0, function () {
109
- var _a, id1, id2, id3;
110
- return __generator(this, function (_b) {
111
- switch (_b.label) {
112
- case 0:
113
- // Reset cache to force concurrent initialization
114
- AvoStreamId_1.AvoStreamId._anonymousId = null;
115
- AvoStreamId_1.AvoStreamId._initializationPromise = null;
116
- return [4 /*yield*/, Promise.all([
117
- AvoStreamId_1.AvoStreamId.initialize(),
118
- AvoStreamId_1.AvoStreamId.initialize(),
119
- AvoStreamId_1.AvoStreamId.initialize(),
120
- ])];
121
- case 1:
122
- _a = _b.sent(), id1 = _a[0], id2 = _a[1], id3 = _a[2];
123
- expect(id1).toBe(id2);
124
- expect(id2).toBe(id3);
125
- return [2 /*return*/];
126
- }
127
- });
128
- }); });
129
- test("UUID never resets - calling initialize again returns same value", function () { return __awaiter(void 0, void 0, void 0, function () {
130
- var id1, id2, id3;
131
- return __generator(this, function (_a) {
132
- switch (_a.label) {
133
- case 0: return [4 /*yield*/, AvoStreamId_1.AvoStreamId.initialize()];
134
- case 1:
135
- id1 = _a.sent();
136
- // Simulate time passing / multiple app restarts by clearing memory cache
137
- AvoStreamId_1.AvoStreamId._anonymousId = null;
138
- AvoStreamId_1.AvoStreamId._initializationPromise = null;
139
- return [4 /*yield*/, AvoStreamId_1.AvoStreamId.initialize()];
140
- case 2:
141
- id2 = _a.sent();
142
- AvoStreamId_1.AvoStreamId._anonymousId = null;
143
- AvoStreamId_1.AvoStreamId._initializationPromise = null;
144
- return [4 /*yield*/, AvoStreamId_1.AvoStreamId.initialize()];
145
- case 3:
146
- id3 = _a.sent();
147
- expect(id1).toBe(id2);
148
- expect(id2).toBe(id3);
149
- return [2 /*return*/];
150
- }
151
- });
152
- }); });
153
- });
@@ -1,48 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.trackingEndpoint = exports.type = exports.sessionTimeMs = exports.requestMsg = exports.networkCallType = exports.mockedReturns = exports.error = exports.defaultOptions = void 0;
4
- var AvoInspectorEnv_1 = require("../AvoInspectorEnv");
5
- var defaultOptions = {
6
- apiKey: "api-key-xxx",
7
- env: AvoInspectorEnv_1.AvoInspectorEnv.Prod,
8
- version: "1",
9
- shouldLog: true
10
- };
11
- exports.defaultOptions = defaultOptions;
12
- var error = {
13
- API_KEY: "[Avo Inspector] No API key provided. Inspector can't operate without API key.",
14
- VERSION: "[Avo Inspector] No version provided. Many features of Inspector rely on versioning. Please provide comparable string version, i.e. integer or semantic.",
15
- };
16
- exports.error = error;
17
- var mockedReturns = {
18
- INSTALLATION_ID: "avo-instalation-id",
19
- GUID: "generated-guid",
20
- SESSION_ID: "session-id",
21
- ANONYMOUS_ID: "avo-anonymous-id",
22
- };
23
- exports.mockedReturns = mockedReturns;
24
- var networkCallType = {
25
- EVENT: "event",
26
- SESSION_STARTED: "sessionStarted",
27
- };
28
- exports.networkCallType = networkCallType;
29
- var requestMsg = {
30
- ERROR: "Request failed",
31
- TIMEOUT: "Request timed out",
32
- };
33
- exports.requestMsg = requestMsg;
34
- var trackingEndpoint = "https://api.avo.app/inspector/v1/track";
35
- exports.trackingEndpoint = trackingEndpoint;
36
- var sessionTimeMs = 5 * 60 * 1000;
37
- exports.sessionTimeMs = sessionTimeMs;
38
- var type = {
39
- STRING: "string",
40
- INT: "int",
41
- OBJECT: "object",
42
- FLOAT: "float",
43
- LIST: "list",
44
- BOOL: "boolean",
45
- NULL: "null",
46
- UNKNOWN: "unknown",
47
- };
48
- exports.type = type;
@@ -1,75 +0,0 @@
1
- import { AvoInspector } from "./AvoInspector";
2
- export class AvoBatcher {
3
- constructor(networkCallsHandler) {
4
- this.events = [];
5
- this.networkCallsHandler = networkCallsHandler;
6
- this.batchFlushAttemptTimestamp = Date.now();
7
- AvoInspector.avoStorage
8
- .getItemAsync(AvoBatcher.cacheKey)
9
- .then((savedEvents) => {
10
- if (savedEvents !== null) {
11
- const nonNullSavedEvents = savedEvents.filter((event) => event !== null);
12
- this.events = this.events.concat(nonNullSavedEvents);
13
- this.checkIfBatchNeedsToBeSent();
14
- }
15
- })
16
- .catch((error) => {
17
- console.error("Avo Inspector: error getting events from cache", error);
18
- });
19
- }
20
- handleSessionStarted() {
21
- this.events.push(this.networkCallsHandler.bodyForSessionStartedCall());
22
- this.saveEvents();
23
- this.checkIfBatchNeedsToBeSent();
24
- }
25
- handleTrackSchema(eventName, schema, eventId, eventHash, eventSpecMetadata) {
26
- this.events.push(this.networkCallsHandler.bodyForEventSchemaCall(eventName, schema, eventId, eventHash, eventSpecMetadata));
27
- this.saveEvents();
28
- if (AvoInspector.shouldLog) {
29
- console.log("Avo Inspector: saved event " +
30
- eventName +
31
- " with schema " +
32
- JSON.stringify(schema));
33
- }
34
- this.checkIfBatchNeedsToBeSent();
35
- }
36
- checkIfBatchNeedsToBeSent() {
37
- const batchSize = this.events.length;
38
- const now = Date.now();
39
- const timeSinceLastFlushAttempt = now - this.batchFlushAttemptTimestamp;
40
- const sendBySize = batchSize % AvoInspector.batchSize == 0;
41
- const sendByTime = timeSinceLastFlushAttempt >= AvoInspector.batchFlushSeconds * 1000;
42
- const avoBatcher = this;
43
- if (sendBySize || sendByTime) {
44
- this.batchFlushAttemptTimestamp = now;
45
- const sendingEvents = avoBatcher.events;
46
- avoBatcher.events = [];
47
- this.networkCallsHandler.callInspectorWithBatchBody(sendingEvents, function (error) {
48
- if (error != null) {
49
- avoBatcher.events = avoBatcher.events.concat(sendingEvents);
50
- if (AvoInspector.shouldLog) {
51
- console.log("Avo Inspector: batch sending failed: " +
52
- error.message +
53
- ". We will attempt to send your schemas with next batch");
54
- }
55
- }
56
- else {
57
- if (AvoInspector.shouldLog) {
58
- console.log("Avo Inspector: batch sent successfully.");
59
- }
60
- }
61
- avoBatcher.saveEvents();
62
- });
63
- }
64
- }
65
- saveEvents() {
66
- if (this.events.length > 1000) {
67
- const extraElements = this.events.length - 1000;
68
- this.events.splice(0, extraElements);
69
- }
70
- AvoInspector.avoStorage.setItem(AvoBatcher.cacheKey, this.events);
71
- }
72
- static get cacheKey() {
73
- return "AvoInspectorEvents";
74
- }
75
- }
@@ -1,137 +0,0 @@
1
- import { AvoSchemaParser } from "./AvoSchemaParser";
2
- import { deepEquals } from "./utils";
3
- export class AvoDeduplicator {
4
- constructor() {
5
- this.avoFunctionsEvents = {};
6
- this.manualEvents = {};
7
- this.avoFunctionsEventsParams = {};
8
- this.manualEventsParams = {};
9
- }
10
- shouldRegisterEvent(eventName, params, fromAvoFunction) {
11
- this.clearOldEvents();
12
- if (fromAvoFunction) {
13
- this.avoFunctionsEvents[Date.now()] = eventName;
14
- this.avoFunctionsEventsParams[eventName] = params;
15
- }
16
- else {
17
- this.manualEvents[Date.now()] = eventName;
18
- this.manualEventsParams[eventName] = params;
19
- }
20
- const checkInAvoFunctions = !fromAvoFunction;
21
- return !this.hasSameEventAs(eventName, params, checkInAvoFunctions);
22
- }
23
- hasSameEventAs(eventName, params, checkInAvoFunctions) {
24
- let result = false;
25
- if (checkInAvoFunctions) {
26
- if (this.lookForEventIn(eventName, params, this.avoFunctionsEventsParams)) {
27
- result = true;
28
- }
29
- }
30
- else {
31
- if (this.lookForEventIn(eventName, params, this.manualEventsParams)) {
32
- result = true;
33
- }
34
- }
35
- if (result) {
36
- delete this.avoFunctionsEventsParams[eventName];
37
- delete this.manualEventsParams[eventName];
38
- }
39
- return result;
40
- }
41
- lookForEventIn(eventName, params, eventsStorage) {
42
- for (const otherEventName in eventsStorage) {
43
- if (eventsStorage.hasOwnProperty(otherEventName)) {
44
- if (otherEventName === eventName) {
45
- const otherParams = eventsStorage[eventName];
46
- if (otherParams && deepEquals(params, otherParams)) {
47
- return true;
48
- }
49
- }
50
- }
51
- }
52
- return false;
53
- }
54
- hasSeenEventParams(params, checkInAvoFunctions) {
55
- let result = false;
56
- if (checkInAvoFunctions) {
57
- if (this.lookForEventParamsIn(params, this.avoFunctionsEventsParams)) {
58
- result = true;
59
- }
60
- }
61
- else {
62
- if (this.lookForEventParamsIn(params, this.manualEventsParams)) {
63
- result = true;
64
- }
65
- }
66
- return result;
67
- }
68
- lookForEventParamsIn(params, eventsStorage) {
69
- for (const otherEventName in eventsStorage) {
70
- if (eventsStorage.hasOwnProperty(otherEventName)) {
71
- const otherParams = eventsStorage[otherEventName];
72
- if (otherParams && deepEquals(params, otherParams)) {
73
- return true;
74
- }
75
- }
76
- }
77
- return false;
78
- }
79
- async shouldRegisterSchemaFromManually(eventName, eventSchema) {
80
- this.clearOldEvents();
81
- return !(await this.hasSameShapeInAvoFunctionsAs(eventName, eventSchema));
82
- }
83
- async hasSameShapeInAvoFunctionsAs(eventName, eventSchema) {
84
- let result = false;
85
- if (await this.lookForEventSchemaIn(eventName, eventSchema, this.avoFunctionsEventsParams)) {
86
- result = true;
87
- }
88
- if (result) {
89
- delete this.avoFunctionsEventsParams[eventName];
90
- }
91
- return result;
92
- }
93
- async lookForEventSchemaIn(eventName, eventSchema, eventsStorage) {
94
- for (const otherEventName in eventsStorage) {
95
- if (eventsStorage.hasOwnProperty(otherEventName)) {
96
- if (otherEventName === eventName) {
97
- const otherSchema = await AvoSchemaParser.extractSchema(eventsStorage[eventName]);
98
- if (otherSchema && deepEquals(eventSchema, otherSchema)) {
99
- return true;
100
- }
101
- }
102
- }
103
- }
104
- return false;
105
- }
106
- clearOldEvents() {
107
- const now = Date.now();
108
- const msToConsiderOld = 300;
109
- for (const time in this.avoFunctionsEvents) {
110
- if (this.avoFunctionsEvents.hasOwnProperty(time)) {
111
- const timestamp = Number(time) || 0;
112
- if (now - timestamp > msToConsiderOld) {
113
- const eventName = this.avoFunctionsEvents[time];
114
- delete this.avoFunctionsEvents[time];
115
- delete this.avoFunctionsEventsParams[eventName];
116
- }
117
- }
118
- }
119
- for (const time in this.manualEvents) {
120
- if (this.manualEvents.hasOwnProperty(time)) {
121
- const timestamp = Number(time) || 0;
122
- if (now - timestamp > msToConsiderOld) {
123
- const eventName = this.manualEvents[time];
124
- delete this.manualEvents[time];
125
- delete this.manualEventsParams[eventName];
126
- }
127
- }
128
- }
129
- }
130
- // used in tests
131
- _clearEvents() {
132
- this.avoFunctionsEvents = {};
133
- this.manualEvents = {};
134
- this.avoFunctionsEventsParams = {};
135
- this.manualEventsParams = {};
136
- }
137
- }