avo-inspector 2.2.2-alpha.2 → 2.2.2-alpha.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 (97) hide show
  1. package/.claude/settings.local.json +18 -0
  2. package/bin/avo-inspector.js +78 -26
  3. package/dist/AvoInspector.d.ts +5 -0
  4. package/dist/AvoNetworkCallsHandler.d.ts +5 -3
  5. package/dist/AvoStreamId.d.ts +58 -0
  6. package/dist/eventSpec/AvoEventSpecCache.d.ts +2 -1
  7. package/dist/eventSpec/AvoEventSpecFetchTypes.d.ts +24 -18
  8. package/dist/eventSpec/AvoEventSpecFetcher.d.ts +9 -3
  9. package/dist/eventSpec/fetcher.d.ts +52 -0
  10. package/dist/index.js +1 -1
  11. package/package.json +1 -1
  12. package/dist/browser.js.LICENSE.txt +0 -5
  13. package/dist-browser/AvoAnonymousId.d.ts +0 -26
  14. package/dist-browser/AvoBatcher.d.ts +0 -26
  15. package/dist-browser/AvoDeduplicator.d.ts +0 -20
  16. package/dist-browser/AvoEncryption.d.ts +0 -33
  17. package/dist-browser/AvoGuid.d.ts +0 -3
  18. package/dist-browser/AvoInspector.d.ts +0 -78
  19. package/dist-browser/AvoInspectorEnv.d.ts +0 -7
  20. package/dist-browser/AvoNetworkCallsHandler.d.ts +0 -74
  21. package/dist-browser/AvoSchemaParser.d.ts +0 -20
  22. package/dist-browser/AvoStorage.d.ts +0 -22
  23. package/dist-browser/__mocks__/xhr.d.ts +0 -12
  24. package/dist-browser/__mocks__/xhrError.d.ts +0 -12
  25. package/dist-browser/__tests__/AnonymousId_test.d.ts +0 -1
  26. package/dist-browser/__tests__/AvoEncryption_test.d.ts +0 -1
  27. package/dist-browser/__tests__/AvoInspectorEventSpec_test.d.ts +0 -1
  28. package/dist-browser/__tests__/AvoInspector_test.d.ts +0 -1
  29. package/dist-browser/__tests__/BatcherPublic_test.d.ts +0 -1
  30. package/dist-browser/__tests__/Batcher_test.d.ts +0 -1
  31. package/dist-browser/__tests__/Deduplicator_test.d.ts +0 -1
  32. package/dist-browser/__tests__/EncryptedPropertyTracking_test.d.ts +0 -1
  33. package/dist-browser/__tests__/EventSpecCache_test.d.ts +0 -1
  34. package/dist-browser/__tests__/EventSpecFetcher_test.d.ts +0 -1
  35. package/dist-browser/__tests__/EventValidator_test.d.ts +0 -1
  36. package/dist-browser/__tests__/NetworkCallsHandler_test.d.ts +0 -1
  37. package/dist-browser/__tests__/Parsing_test.d.ts +0 -1
  38. package/dist-browser/__tests__/Storage_test.d.ts +0 -1
  39. package/dist-browser/__tests__/ValidationIntegration_test.d.ts +0 -1
  40. package/dist-browser/__tests__/constants.d.ts +0 -36
  41. package/dist-browser/__tests__/helpers/encryptionHelpers.d.ts +0 -13
  42. package/dist-browser/__tests__/helpers/mockFactories.d.ts +0 -49
  43. package/dist-browser/eventSpec/AvoEventSpecCache.d.ts +0 -73
  44. package/dist-browser/eventSpec/AvoEventSpecFetchTypes.d.ts +0 -109
  45. package/dist-browser/eventSpec/AvoEventSpecFetcher.d.ts +0 -55
  46. package/dist-browser/eventSpec/EventValidator.d.ts +0 -90
  47. package/dist-browser/eventSpec/index.d.ts +0 -4
  48. package/dist-browser/index.d.ts +0 -2
  49. package/dist-browser/utils.d.ts +0 -3
  50. package/dist-native/AvoBatcher.d.ts +0 -24
  51. package/dist-native/AvoBatcher.js +0 -82
  52. package/dist-native/AvoDeduplicator.d.ts +0 -36
  53. package/dist-native/AvoDeduplicator.js +0 -142
  54. package/dist-native/AvoGuid.d.ts +0 -3
  55. package/dist-native/AvoGuid.js +0 -14
  56. package/dist-native/AvoInspector.d.ts +0 -52
  57. package/dist-native/AvoInspector.js +0 -220
  58. package/dist-native/AvoInspectorEnv.d.ts +0 -7
  59. package/dist-native/AvoInspectorEnv.js +0 -8
  60. package/dist-native/AvoInstallationId.d.ts +0 -5
  61. package/dist-native/AvoInstallationId.js +0 -36
  62. package/dist-native/AvoNetworkCallsHandler.d.ts +0 -48
  63. package/dist-native/AvoNetworkCallsHandler.js +0 -142
  64. package/dist-native/AvoSchemaParser.d.ts +0 -11
  65. package/dist-native/AvoSchemaParser.js +0 -95
  66. package/dist-native/AvoSessionTracker.d.ts +0 -15
  67. package/dist-native/AvoSessionTracker.js +0 -104
  68. package/dist-native/AvoStorage.d.ts +0 -22
  69. package/dist-native/AvoStorage.js +0 -336
  70. package/dist-native/__mocks__/xhr.d.ts +0 -12
  71. package/dist-native/__mocks__/xhr.js +0 -14
  72. package/dist-native/__mocks__/xhrError.d.ts +0 -12
  73. package/dist-native/__mocks__/xhrError.js +0 -14
  74. package/dist-native/__tests__/AvoInspector.d.ts +0 -1
  75. package/dist-native/__tests__/AvoInspector.js +0 -207
  76. package/dist-native/__tests__/Batcher.d.ts +0 -1
  77. package/dist-native/__tests__/Batcher.js +0 -280
  78. package/dist-native/__tests__/BatcherPublic.d.ts +0 -1
  79. package/dist-native/__tests__/BatcherPublic.js +0 -82
  80. package/dist-native/__tests__/Deduplicator.d.ts +0 -1
  81. package/dist-native/__tests__/Deduplicator.js +0 -111
  82. package/dist-native/__tests__/InstallationId.d.ts +0 -1
  83. package/dist-native/__tests__/InstallationId.js +0 -40
  84. package/dist-native/__tests__/NetworkCallsHandler.d.ts +0 -1
  85. package/dist-native/__tests__/NetworkCallsHandler.js +0 -132
  86. package/dist-native/__tests__/Parsing.d.ts +0 -1
  87. package/dist-native/__tests__/Parsing.js +0 -115
  88. package/dist-native/__tests__/Sessions.d.ts +0 -1
  89. package/dist-native/__tests__/Sessions.js +0 -179
  90. package/dist-native/__tests__/Storage.d.ts +0 -1
  91. package/dist-native/__tests__/Storage.js +0 -173
  92. package/dist-native/__tests__/constants.d.ts +0 -36
  93. package/dist-native/__tests__/constants.js +0 -47
  94. package/dist-native/index.d.ts +0 -2
  95. package/dist-native/index.js +0 -7
  96. package/dist-native/utils.d.ts +0 -3
  97. package/dist-native/utils.js +0 -42
@@ -1,207 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- var AvoInspector_1 = require("../AvoInspector");
4
- var AvoInspectorEnv_1 = require("../AvoInspectorEnv");
5
- var constants_1 = require("../__tests__/constants");
6
- describe("Initialization", function () {
7
- test("Api Key is set", function () {
8
- // Given
9
- var apiKey = "api-key-xxx";
10
- // When
11
- var inspector = new AvoInspector_1.AvoInspector({
12
- env: AvoInspectorEnv_1.AvoInspectorEnv.Prod,
13
- version: "0",
14
- apiKey: apiKey,
15
- });
16
- // Then
17
- expect(inspector.apiKey).toBe(apiKey);
18
- });
19
- test("Error is thrown when Api Key is not set", function () {
20
- // Given
21
- // @ts-ignore
22
- var apiKey;
23
- // Then
24
- expect(function () {
25
- new AvoInspector_1.AvoInspector({
26
- env: AvoInspectorEnv_1.AvoInspectorEnv.Prod,
27
- version: "0",
28
- // @ts-ignore
29
- apiKey: apiKey,
30
- });
31
- }).toThrow(constants_1.error.API_KEY);
32
- });
33
- test("Error is thrown when empty Api Key is used", function () {
34
- // Given
35
- var apiKey = " ";
36
- // Then
37
- expect(function () {
38
- new AvoInspector_1.AvoInspector({
39
- env: AvoInspectorEnv_1.AvoInspectorEnv.Prod,
40
- version: "0",
41
- apiKey: apiKey,
42
- });
43
- }).toThrow(constants_1.error.API_KEY);
44
- });
45
- test("Error is thrown when Api Key is set to null", function () {
46
- // Given
47
- var apiKey = null;
48
- // Then
49
- expect(function () {
50
- new AvoInspector_1.AvoInspector({
51
- env: AvoInspectorEnv_1.AvoInspectorEnv.Prod,
52
- version: "0",
53
- // @ts-ignore
54
- apiKey: apiKey,
55
- });
56
- }).toThrow(constants_1.error.API_KEY);
57
- });
58
- test("Dev environment is used when env is not provided", function () {
59
- // Given
60
- // @ts-ignore
61
- var env;
62
- // When
63
- var inspector = new AvoInspector_1.AvoInspector({
64
- apiKey: "api-key-xxx",
65
- version: "0",
66
- // @ts-ignore
67
- env: env,
68
- });
69
- // Then
70
- expect(inspector.environment).toBe(AvoInspectorEnv_1.AvoInspectorEnv.Dev);
71
- });
72
- test("Dev environment is used when empty string is used", function () {
73
- // Given
74
- var env = "";
75
- // When
76
- var inspector = new AvoInspector_1.AvoInspector({
77
- apiKey: "api-key-xxx",
78
- version: "0",
79
- // @ts-ignore
80
- env: env,
81
- });
82
- // Then
83
- expect(inspector.environment).toBe(AvoInspectorEnv_1.AvoInspectorEnv.Dev);
84
- });
85
- test("Dev env is set using AvoInspectorEnv", function () {
86
- // When
87
- var inspector = new AvoInspector_1.AvoInspector({
88
- apiKey: "api-key-xxx",
89
- env: AvoInspectorEnv_1.AvoInspectorEnv.Dev,
90
- version: "0",
91
- });
92
- // Then
93
- expect(inspector.environment).toBe(AvoInspectorEnv_1.AvoInspectorEnv.Dev);
94
- });
95
- test("Dev environment is set using string", function () {
96
- // When
97
- var inspector = new AvoInspector_1.AvoInspector({
98
- apiKey: "api-key-xxx",
99
- env: "dev",
100
- version: "0",
101
- });
102
- // Then
103
- expect(inspector.environment).toBe(AvoInspectorEnv_1.AvoInspectorEnv.Dev);
104
- });
105
- test("Staging env is set using AvoInspectorEnv", function () {
106
- // When
107
- var inspector = new AvoInspector_1.AvoInspector({
108
- apiKey: "api-key-xxx",
109
- env: AvoInspectorEnv_1.AvoInspectorEnv.Staging,
110
- version: "0",
111
- });
112
- // Then
113
- expect(inspector.environment).toBe(AvoInspectorEnv_1.AvoInspectorEnv.Staging);
114
- });
115
- test("Staging environment is set using string", function () {
116
- // When
117
- var inspector = new AvoInspector_1.AvoInspector({
118
- apiKey: "api-key-xxx",
119
- env: "staging",
120
- version: "0",
121
- });
122
- // Then
123
- expect(inspector.environment).toBe(AvoInspectorEnv_1.AvoInspectorEnv.Staging);
124
- });
125
- test("Prod env is set using AvoInspectorEnv", function () {
126
- // When
127
- var inspector = new AvoInspector_1.AvoInspector({
128
- apiKey: "api-key-xxx",
129
- env: AvoInspectorEnv_1.AvoInspectorEnv.Prod,
130
- version: "0",
131
- });
132
- // Then
133
- expect(inspector.environment).toBe(AvoInspectorEnv_1.AvoInspectorEnv.Prod);
134
- });
135
- test("Prod environment is set using string", function () {
136
- // When
137
- var inspector = new AvoInspector_1.AvoInspector({
138
- apiKey: "api-key-xxx",
139
- env: "prod",
140
- version: "0",
141
- });
142
- // Then
143
- expect(inspector.environment).toBe(AvoInspectorEnv_1.AvoInspectorEnv.Prod);
144
- });
145
- test("Environment other than Dev, Staging, Prod falls back to Dev", function () {
146
- // When
147
- var env = "test";
148
- var inspector = new AvoInspector_1.AvoInspector({
149
- apiKey: "api-key-xxx",
150
- version: "0",
151
- // @ts-ignore
152
- env: env,
153
- });
154
- // Then
155
- expect(inspector.environment).toBe(AvoInspectorEnv_1.AvoInspectorEnv.Dev);
156
- });
157
- test("Version is set", function () {
158
- var version = "1";
159
- // When
160
- var inspector = new AvoInspector_1.AvoInspector({
161
- apiKey: "api-key-xxx",
162
- env: AvoInspectorEnv_1.AvoInspectorEnv.Prod,
163
- version: version,
164
- });
165
- // Then
166
- expect(inspector.version).toBe(version);
167
- });
168
- test("Error is thrown when version is not set", function () {
169
- // Given
170
- // @ts-ignore
171
- var version;
172
- // Then
173
- expect(function () {
174
- new AvoInspector_1.AvoInspector({
175
- apiKey: "api-key-xxx",
176
- env: AvoInspectorEnv_1.AvoInspectorEnv.Prod,
177
- // @ts-ignore
178
- version: version,
179
- });
180
- }).toThrow(constants_1.error.VERSION);
181
- });
182
- test("Error is thrown when version is set to empty string", function () {
183
- // Given
184
- var version = " ";
185
- // Then
186
- expect(function () {
187
- new AvoInspector_1.AvoInspector({
188
- apiKey: "api-key-xxx",
189
- env: AvoInspectorEnv_1.AvoInspectorEnv.Prod,
190
- version: version,
191
- });
192
- }).toThrow(constants_1.error.VERSION);
193
- });
194
- test("Error is thrown when version is set to null", function () {
195
- // Given
196
- var version = null;
197
- // Then
198
- expect(function () {
199
- new AvoInspector_1.AvoInspector({
200
- apiKey: "api-key-xxx",
201
- env: AvoInspectorEnv_1.AvoInspectorEnv.Prod,
202
- // @ts-ignore
203
- version: version,
204
- });
205
- }).toThrow(constants_1.error.VERSION);
206
- });
207
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,280 +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
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
50
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
51
- if (ar || !(i in from)) {
52
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
53
- ar[i] = from[i];
54
- }
55
- }
56
- return to.concat(ar || Array.prototype.slice.call(from));
57
- };
58
- Object.defineProperty(exports, "__esModule", { value: true });
59
- var AvoBatcher_1 = require("../AvoBatcher");
60
- var AvoInspector_1 = require("../AvoInspector");
61
- var AvoNetworkCallsHandler_1 = require("../AvoNetworkCallsHandler");
62
- var AvoStorage_1 = require("../AvoStorage");
63
- var constants_1 = require("./constants");
64
- var inspectorVersion = process.env.npm_package_version || "";
65
- describe("Batcher", function () {
66
- var checkBatchSpy;
67
- var inspectorCallSpy;
68
- var apiKey = constants_1.defaultOptions.apiKey, env = constants_1.defaultOptions.env, version = constants_1.defaultOptions.version, shouldLog = constants_1.defaultOptions.shouldLog;
69
- var storage = new AvoStorage_1.AvoStorage(shouldLog);
70
- var networkHandler = new AvoNetworkCallsHandler_1.AvoNetworkCallsHandler(apiKey, env, "", version, inspectorVersion);
71
- beforeAll(function () {
72
- checkBatchSpy = jest.spyOn(AvoBatcher_1.AvoBatcher.prototype, "checkIfBatchNeedsToBeSent");
73
- inspectorCallSpy = jest.spyOn(AvoNetworkCallsHandler_1.AvoNetworkCallsHandler.prototype, "callInspectorWithBatchBody");
74
- });
75
- afterEach(function () {
76
- jest.clearAllMocks();
77
- AvoInspector_1.AvoInspector.avoStorage.removeItem(AvoBatcher_1.AvoBatcher.cacheKey);
78
- });
79
- test("handleSessionStarted adds event to storage", function () {
80
- var inspector = new AvoInspector_1.AvoInspector(constants_1.defaultOptions);
81
- inspector.enableLogging(false);
82
- inspector.avoBatcher.handleSessionStarted();
83
- var events = AvoInspector_1.AvoInspector.avoStorage.getItem(AvoBatcher_1.AvoBatcher.cacheKey);
84
- expect(events).not.toBeNull();
85
- if (events !== null) {
86
- expect(events.length).toEqual(1);
87
- expect(events[0].type === constants_1.networkCallType.SESSION_STARTED);
88
- }
89
- });
90
- test("handleTrackSchema adds event to storage", function () {
91
- var inspector = new AvoInspector_1.AvoInspector(constants_1.defaultOptions);
92
- inspector.enableLogging(false);
93
- AvoInspector_1.AvoInspector.avoStorage.removeItem(AvoBatcher_1.AvoBatcher.cacheKey);
94
- inspector.avoBatcher.handleSessionStarted();
95
- inspector.avoBatcher.handleTrackSchema("event name", [], null, null);
96
- var events = AvoInspector_1.AvoInspector.avoStorage.getItem(AvoBatcher_1.AvoBatcher.cacheKey);
97
- expect(events).not.toBeNull();
98
- if (events !== null) {
99
- expect(events.length).toEqual(2);
100
- expect(events[0].type === constants_1.networkCallType.SESSION_STARTED);
101
- expect(events[1].type === constants_1.networkCallType.EVENT);
102
- }
103
- });
104
- test("handleTrackSchema adds event to storage", function () {
105
- var inspector = new AvoInspector_1.AvoInspector(constants_1.defaultOptions);
106
- inspector.enableLogging(false);
107
- AvoInspector_1.AvoInspector.avoStorage.removeItem(AvoBatcher_1.AvoBatcher.cacheKey);
108
- inspector.avoBatcher.handleTrackSchema("event name", [], null, null);
109
- var events = AvoInspector_1.AvoInspector.avoStorage.getItem(AvoBatcher_1.AvoBatcher.cacheKey);
110
- expect(events).not.toBeNull();
111
- if (events !== null) {
112
- expect(events.length).toEqual(1);
113
- expect(events[0].type === constants_1.networkCallType.EVENT);
114
- }
115
- });
116
- test("checkIfBatchNeedsToBeSent is called on Batcher initialization", function () { return __awaiter(void 0, void 0, void 0, function () {
117
- var event;
118
- return __generator(this, function (_a) {
119
- switch (_a.label) {
120
- case 0:
121
- event = networkHandler.bodyForEventSchemaCall("name", [
122
- { propertyName: "prop0", propertyType: "string" },
123
- ], "testEventId", "testEventHash");
124
- storage.setItem(AvoBatcher_1.AvoBatcher.cacheKey, [event]);
125
- return [4 /*yield*/, new AvoBatcher_1.AvoBatcher(networkHandler)];
126
- case 1:
127
- _a.sent();
128
- expect(checkBatchSpy).toHaveBeenCalledTimes(1);
129
- return [2 /*return*/];
130
- }
131
- });
132
- }); });
133
- test("checkIfBatchNeedsToBeSent is called on handleSessionStarted", function () {
134
- var inspector = new AvoInspector_1.AvoInspector(constants_1.defaultOptions);
135
- inspector.enableLogging(false);
136
- inspector.avoBatcher.handleSessionStarted();
137
- expect(checkBatchSpy).toHaveBeenCalledTimes(1);
138
- });
139
- test("checkIfBatchNeedsToBeSent is called on handleTrackSchema", function () {
140
- var inspector = new AvoInspector_1.AvoInspector(constants_1.defaultOptions);
141
- inspector.enableLogging(false);
142
- inspector.avoBatcher.handleSessionStarted();
143
- expect(checkBatchSpy).toHaveBeenCalledTimes(1);
144
- });
145
- test("Batcher saves events produced by AvoNetworkCallsHandler", function () { return __awaiter(void 0, void 0, void 0, function () {
146
- var schemaEvent, sessionEvent, inspector, events;
147
- return __generator(this, function (_a) {
148
- AvoInspector_1.AvoInspector.avoStorage.removeItem(AvoBatcher_1.AvoBatcher.cacheKey);
149
- schemaEvent = networkHandler.bodyForEventSchemaCall("name", [
150
- { propertyName: "prop0", propertyType: "string" },
151
- ], "testEventId", "testEventHash");
152
- sessionEvent = networkHandler.bodyForSessionStartedCall();
153
- inspector = new AvoInspector_1.AvoInspector(constants_1.defaultOptions);
154
- inspector.enableLogging(false);
155
- inspector.avoBatcher.handleTrackSchema("name", [
156
- { propertyName: "prop0", propertyType: "string" },
157
- ], "testEventId", "testEventHash");
158
- inspector.avoBatcher.handleSessionStarted();
159
- events = storage.getItem(AvoBatcher_1.AvoBatcher.cacheKey);
160
- expect(events).not.toBeNull();
161
- if (events != null) {
162
- expect(events[0]).not.toBe(schemaEvent);
163
- expect(__assign(__assign({}, events[0]), { messageId: undefined, createdAt: undefined })).toStrictEqual(__assign(__assign({}, schemaEvent), { messageId: undefined, createdAt: undefined }));
164
- expect(events[1]).not.toBe(sessionEvent);
165
- expect(__assign(__assign({}, events[1]), { messageId: undefined, createdAt: undefined })).toStrictEqual(__assign(__assign({}, sessionEvent), { messageId: undefined, createdAt: undefined }));
166
- }
167
- return [2 /*return*/];
168
- });
169
- }); });
170
- test("Events are retrieved from Storage on init", function () {
171
- var getItemAsyncSpy = jest.spyOn(AvoStorage_1.AvoStorage.prototype, "getItemAsync");
172
- new AvoInspector_1.AvoInspector(constants_1.defaultOptions);
173
- expect(getItemAsyncSpy).toHaveBeenCalledTimes(1);
174
- expect(getItemAsyncSpy).toHaveBeenCalledWith(AvoBatcher_1.AvoBatcher.cacheKey);
175
- });
176
- test("Batch is not sent with batchSize - 1 events", function () {
177
- var eventCount = AvoInspector_1.AvoInspector.batchSize - 1;
178
- var inspector = new AvoInspector_1.AvoInspector(constants_1.defaultOptions);
179
- inspector.enableLogging(false);
180
- __spreadArray([], Array(eventCount), true).forEach(function () {
181
- inspector.avoBatcher.handleTrackSchema("event name", [], null, null);
182
- });
183
- expect(checkBatchSpy).toHaveBeenCalledTimes(eventCount);
184
- expect(inspectorCallSpy).not.toHaveBeenCalled();
185
- });
186
- test("Batch is sent when event count matches batchSize", function () {
187
- var eventCount = AvoInspector_1.AvoInspector.batchSize;
188
- var inspector = new AvoInspector_1.AvoInspector(constants_1.defaultOptions);
189
- inspector.enableLogging(false);
190
- __spreadArray([], Array(eventCount), true).forEach(function () {
191
- inspector.avoBatcher.handleTrackSchema("event name", [], null, null);
192
- });
193
- var events = storage.getItem(AvoBatcher_1.AvoBatcher.cacheKey);
194
- expect(checkBatchSpy).toHaveBeenCalledTimes(eventCount);
195
- expect(inspectorCallSpy).toHaveBeenCalledTimes(1);
196
- expect(inspectorCallSpy).toHaveBeenCalledWith(events, expect.any(Function));
197
- });
198
- test("Batch is sent only one time for batchSize + 1 events", function () {
199
- var eventCount = AvoInspector_1.AvoInspector.batchSize + 1;
200
- var inspector = new AvoInspector_1.AvoInspector(constants_1.defaultOptions);
201
- inspector.enableLogging(false);
202
- var events = [];
203
- __spreadArray([], Array(eventCount), true).forEach(function (_, i) {
204
- inspector.avoBatcher.handleTrackSchema("event name", [], null, null);
205
- if (i === AvoInspector_1.AvoInspector.batchSize - 1) {
206
- events = storage.getItem(AvoBatcher_1.AvoBatcher.cacheKey);
207
- }
208
- });
209
- expect(checkBatchSpy).toHaveBeenCalledTimes(eventCount);
210
- expect(inspectorCallSpy).toHaveBeenCalledTimes(1);
211
- expect(inspectorCallSpy).toHaveBeenCalledWith(events, expect.any(Function));
212
- events = storage.getItem(AvoBatcher_1.AvoBatcher.cacheKey);
213
- expect(events.length).toBe(1);
214
- });
215
- test("Batch is not sent if batchFlushSeconds not exceeded", function () {
216
- var inspector = new AvoInspector_1.AvoInspector(constants_1.defaultOptions);
217
- inspector.enableLogging(false);
218
- var now = new Date();
219
- var dateNowSpy = jest
220
- .spyOn(Date, "now")
221
- .mockImplementation(function () {
222
- return now.setMilliseconds(now.getMilliseconds() + (AvoInspector_1.AvoInspector.batchFlushSeconds - 1) * 1000);
223
- });
224
- inspector.avoBatcher.handleTrackSchema("event name", [], null, null);
225
- expect(checkBatchSpy).toHaveBeenCalledTimes(1);
226
- expect(inspectorCallSpy).not.toHaveBeenCalled();
227
- dateNowSpy.mockRestore();
228
- });
229
- test("Batch is sent if batchFlushSeconds exceeded", function () { return __awaiter(void 0, void 0, void 0, function () {
230
- var inspector, now, dateNowSpy, events;
231
- return __generator(this, function (_a) {
232
- switch (_a.label) {
233
- case 0:
234
- inspector = new AvoInspector_1.AvoInspector(constants_1.defaultOptions);
235
- inspector.enableLogging(false);
236
- now = new Date();
237
- dateNowSpy = jest
238
- .spyOn(Date, "now")
239
- .mockImplementation(function () {
240
- return now.setMilliseconds(now.getMilliseconds() + AvoInspector_1.AvoInspector.batchFlushSeconds * 1000);
241
- });
242
- return [4 /*yield*/, inspector.avoBatcher.handleTrackSchema("event name", [], null, null)];
243
- case 1:
244
- _a.sent();
245
- events = storage.getItem(AvoBatcher_1.AvoBatcher.cacheKey);
246
- expect(checkBatchSpy).toHaveBeenCalledTimes(1);
247
- expect(inspectorCallSpy).toHaveBeenCalledTimes(1);
248
- expect(inspectorCallSpy).toHaveBeenCalledWith(events, expect.any(Function));
249
- dateNowSpy.mockRestore();
250
- return [2 /*return*/];
251
- }
252
- });
253
- }); });
254
- test("Only latest 1000 events are stored in the storage", function (done) {
255
- AvoInspector_1.AvoInspector.avoStorage.removeItem(AvoBatcher_1.AvoBatcher.cacheKey);
256
- var eventLimit = 1000;
257
- var events = [];
258
- for (var i = 0; i < eventLimit + 1; i++) {
259
- events.push(networkHandler.bodyForEventSchemaCall("event-name-".concat(i), [
260
- { propertyName: "prop0", propertyType: "string" },
261
- ], null, null));
262
- }
263
- AvoInspector_1.AvoInspector.avoStorage.setItem(AvoBatcher_1.AvoBatcher.cacheKey, events);
264
- var inspector = new AvoInspector_1.AvoInspector(constants_1.defaultOptions);
265
- inspector.enableLogging(false);
266
- setTimeout(function () {
267
- var setItemsSpy = jest.spyOn(AvoStorage_1.AvoStorage.prototype, "setItem");
268
- inspector.avoBatcher.handleSessionStarted();
269
- var savedEvents = AvoInspector_1.AvoInspector.avoStorage.getItem(AvoBatcher_1.AvoBatcher.cacheKey);
270
- expect(savedEvents).not.toBeNull();
271
- if (savedEvents !== null && savedEvents.length > 0) {
272
- events.push(savedEvents[savedEvents.length - 1]);
273
- }
274
- events.splice(0, 2);
275
- expect(setItemsSpy).toHaveBeenCalledTimes(1);
276
- expect(setItemsSpy).toHaveBeenCalledWith(AvoBatcher_1.AvoBatcher.cacheKey, events);
277
- done();
278
- }, 1000);
279
- });
280
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,82 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- var AvoBatcher_1 = require("../AvoBatcher");
4
- var AvoInspector_1 = require("../AvoInspector");
5
- var AvoNetworkCallsHandler_1 = require("../AvoNetworkCallsHandler");
6
- var constants_1 = require("./constants");
7
- var inspectorVersion = process.env.npm_package_version || "";
8
- jest.mock("../AvoBatcher");
9
- jest.mock("../AvoStorage");
10
- describe("Batcher", function () {
11
- var inspector;
12
- var apiKey = constants_1.defaultOptions.apiKey, env = constants_1.defaultOptions.env, version = constants_1.defaultOptions.version;
13
- var networkHandler = new AvoNetworkCallsHandler_1.AvoNetworkCallsHandler(apiKey, env, "", version, inspectorVersion);
14
- beforeAll(function () {
15
- inspector = new AvoInspector_1.AvoInspector(constants_1.defaultOptions);
16
- inspector.enableLogging(false);
17
- });
18
- afterEach(function () {
19
- jest.clearAllMocks();
20
- // @ts-ignore
21
- inspector.avoDeduplicator._clearEvents();
22
- });
23
- test("Batcher is initialized on Inspector init", function () {
24
- expect(AvoBatcher_1.AvoBatcher).toHaveBeenCalledTimes(1);
25
- expect(AvoBatcher_1.AvoBatcher).toHaveBeenCalledWith(networkHandler);
26
- });
27
- test("handleTrackSchema is called on trackSchema", function () {
28
- var eventName = "event name";
29
- var schema = [
30
- {
31
- propertyName: "prop0",
32
- propertyType: "string",
33
- },
34
- {
35
- propertyName: "prop1",
36
- propertyType: "string",
37
- },
38
- ];
39
- inspector.trackSchema(eventName, schema);
40
- expect(inspector.avoBatcher.handleTrackSchema).toHaveBeenCalledTimes(1);
41
- expect(inspector.avoBatcher.handleTrackSchema).toBeCalledWith(eventName, schema, null, null);
42
- });
43
- test("handleTrackSchema is called on trackSchemaFromEvent", function () {
44
- var eventName = "event name";
45
- var properties = {
46
- prop0: "",
47
- prop2: false,
48
- prop3: 0,
49
- prop4: 0.0,
50
- };
51
- var schema = inspector.extractSchema(properties);
52
- inspector.trackSchemaFromEvent(eventName, properties);
53
- expect(inspector.avoBatcher.handleTrackSchema).toHaveBeenCalledTimes(1);
54
- expect(inspector.avoBatcher.handleTrackSchema).toBeCalledWith(eventName, schema, null, null);
55
- });
56
- test("handleTrackSchema is called on _avoFunctionTrackSchemaFromEvent", function () {
57
- var eventName = "event name";
58
- var properties = {
59
- prop0: "",
60
- prop2: false,
61
- prop3: 0,
62
- prop4: 0.0,
63
- };
64
- var eventId = "testId";
65
- var eventHash = "testHash";
66
- var schema = inspector.extractSchema(properties);
67
- // @ts-ignore
68
- inspector._avoFunctionTrackSchemaFromEvent(eventName, properties, eventId, eventHash);
69
- expect(inspector.avoBatcher.handleTrackSchema).toHaveBeenCalledTimes(1);
70
- expect(inspector.avoBatcher.handleTrackSchema).toBeCalledWith(eventName, schema, eventId, eventHash);
71
- });
72
- test("batchSize is updated", function () {
73
- var count = 10;
74
- inspector.setBatchSize(count);
75
- expect(AvoInspector_1.AvoInspector.batchSize).toBe(count);
76
- });
77
- test("batchFlushSeconds is updated", function () {
78
- var seconds = 10;
79
- inspector.setBatchFlushSeconds(seconds);
80
- expect(AvoInspector_1.AvoInspector.batchFlushSeconds).toBe(seconds);
81
- });
82
- });
@@ -1 +0,0 @@
1
- export {};