avo-inspector 2.2.0 → 2.2.2-alpha.2

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 (108) hide show
  1. package/CHANGELOG.md +34 -1
  2. package/README.md +130 -0
  3. package/bin/avo-inspector.js +97 -0
  4. package/dist/AvoBatcher.d.ts +4 -11
  5. package/dist/AvoEncryption.d.ts +33 -0
  6. package/dist/AvoInspector.d.ts +35 -6
  7. package/dist/AvoNetworkCallsHandler.d.ts +42 -12
  8. package/dist/AvoSchemaParser.d.ts +12 -5
  9. package/dist/browser.js.LICENSE.txt +5 -0
  10. package/dist/eventSpec/AvoEventSpecCache.d.ts +73 -0
  11. package/dist/eventSpec/AvoEventSpecFetchTypes.d.ts +141 -0
  12. package/dist/eventSpec/AvoEventSpecFetcher.d.ts +54 -0
  13. package/dist/eventSpec/EventValidator.d.ts +34 -0
  14. package/dist/eventSpec/cache.d.ts +73 -0
  15. package/dist/eventSpec/index.d.ts +4 -0
  16. package/dist/eventSpec/types.d.ts +74 -0
  17. package/dist/index.js +2 -1
  18. package/dist/index.js.LICENSE.txt +5 -0
  19. package/dist-browser/AvoAnonymousId.d.ts +26 -0
  20. package/dist-browser/AvoBatcher.d.ts +26 -0
  21. package/dist-browser/AvoDeduplicator.d.ts +20 -0
  22. package/dist-browser/AvoEncryption.d.ts +33 -0
  23. package/dist-browser/AvoGuid.d.ts +3 -0
  24. package/dist-browser/AvoInspector.d.ts +78 -0
  25. package/dist-browser/AvoInspectorEnv.d.ts +7 -0
  26. package/dist-browser/AvoNetworkCallsHandler.d.ts +74 -0
  27. package/dist-browser/AvoSchemaParser.d.ts +20 -0
  28. package/dist-browser/AvoStorage.d.ts +22 -0
  29. package/dist-browser/__mocks__/xhr.d.ts +12 -0
  30. package/dist-browser/__mocks__/xhrError.d.ts +12 -0
  31. package/dist-browser/__tests__/AnonymousId_test.d.ts +1 -0
  32. package/dist-browser/__tests__/AvoEncryption_test.d.ts +1 -0
  33. package/dist-browser/__tests__/AvoInspectorEventSpec_test.d.ts +1 -0
  34. package/dist-browser/__tests__/AvoInspector_test.d.ts +1 -0
  35. package/dist-browser/__tests__/BatcherPublic_test.d.ts +1 -0
  36. package/dist-browser/__tests__/Batcher_test.d.ts +1 -0
  37. package/dist-browser/__tests__/Deduplicator_test.d.ts +1 -0
  38. package/dist-browser/__tests__/EncryptedPropertyTracking_test.d.ts +1 -0
  39. package/dist-browser/__tests__/EventSpecCache_test.d.ts +1 -0
  40. package/dist-browser/__tests__/EventSpecFetcher_test.d.ts +1 -0
  41. package/dist-browser/__tests__/EventValidator_test.d.ts +1 -0
  42. package/dist-browser/__tests__/NetworkCallsHandler_test.d.ts +1 -0
  43. package/dist-browser/__tests__/Parsing_test.d.ts +1 -0
  44. package/dist-browser/__tests__/Storage_test.d.ts +1 -0
  45. package/dist-browser/__tests__/ValidationIntegration_test.d.ts +1 -0
  46. package/dist-browser/__tests__/constants.d.ts +36 -0
  47. package/dist-browser/__tests__/helpers/encryptionHelpers.d.ts +13 -0
  48. package/dist-browser/__tests__/helpers/mockFactories.d.ts +49 -0
  49. package/dist-browser/eventSpec/AvoEventSpecCache.d.ts +73 -0
  50. package/dist-browser/eventSpec/AvoEventSpecFetchTypes.d.ts +109 -0
  51. package/dist-browser/eventSpec/AvoEventSpecFetcher.d.ts +55 -0
  52. package/dist-browser/eventSpec/EventValidator.d.ts +90 -0
  53. package/dist-browser/eventSpec/index.d.ts +4 -0
  54. package/dist-browser/index.d.ts +2 -0
  55. package/dist-browser/utils.d.ts +3 -0
  56. package/dist-native/AvoBatcher.d.ts +24 -0
  57. package/dist-native/AvoBatcher.js +82 -0
  58. package/dist-native/AvoDeduplicator.d.ts +36 -0
  59. package/dist-native/AvoDeduplicator.js +142 -0
  60. package/dist-native/AvoGuid.d.ts +3 -0
  61. package/dist-native/AvoGuid.js +14 -0
  62. package/dist-native/AvoInspector.d.ts +52 -0
  63. package/dist-native/AvoInspector.js +220 -0
  64. package/dist-native/AvoInspectorEnv.d.ts +7 -0
  65. package/dist-native/AvoInspectorEnv.js +8 -0
  66. package/dist-native/AvoInstallationId.d.ts +5 -0
  67. package/dist-native/AvoInstallationId.js +36 -0
  68. package/dist-native/AvoNetworkCallsHandler.d.ts +48 -0
  69. package/dist-native/AvoNetworkCallsHandler.js +142 -0
  70. package/dist-native/AvoSchemaParser.d.ts +11 -0
  71. package/dist-native/AvoSchemaParser.js +95 -0
  72. package/dist-native/AvoSessionTracker.d.ts +15 -0
  73. package/dist-native/AvoSessionTracker.js +104 -0
  74. package/dist-native/AvoStorage.d.ts +22 -0
  75. package/dist-native/AvoStorage.js +336 -0
  76. package/dist-native/__mocks__/xhr.d.ts +12 -0
  77. package/dist-native/__mocks__/xhr.js +14 -0
  78. package/dist-native/__mocks__/xhrError.d.ts +12 -0
  79. package/dist-native/__mocks__/xhrError.js +14 -0
  80. package/dist-native/__tests__/AvoInspector.d.ts +1 -0
  81. package/dist-native/__tests__/AvoInspector.js +207 -0
  82. package/dist-native/__tests__/Batcher.d.ts +1 -0
  83. package/dist-native/__tests__/Batcher.js +280 -0
  84. package/dist-native/__tests__/BatcherPublic.d.ts +1 -0
  85. package/dist-native/__tests__/BatcherPublic.js +82 -0
  86. package/dist-native/__tests__/Deduplicator.d.ts +1 -0
  87. package/dist-native/__tests__/Deduplicator.js +111 -0
  88. package/dist-native/__tests__/InstallationId.d.ts +1 -0
  89. package/dist-native/__tests__/InstallationId.js +40 -0
  90. package/dist-native/__tests__/NetworkCallsHandler.d.ts +1 -0
  91. package/dist-native/__tests__/NetworkCallsHandler.js +132 -0
  92. package/dist-native/__tests__/Parsing.d.ts +1 -0
  93. package/dist-native/__tests__/Parsing.js +115 -0
  94. package/dist-native/__tests__/Sessions.d.ts +1 -0
  95. package/dist-native/__tests__/Sessions.js +179 -0
  96. package/dist-native/__tests__/Storage.d.ts +1 -0
  97. package/dist-native/__tests__/Storage.js +173 -0
  98. package/dist-native/__tests__/constants.d.ts +36 -0
  99. package/dist-native/__tests__/constants.js +47 -0
  100. package/dist-native/index.d.ts +2 -0
  101. package/dist-native/index.js +7 -0
  102. package/dist-native/utils.d.ts +3 -0
  103. package/dist-native/utils.js +42 -0
  104. package/jest.config.js +6 -0
  105. package/package.json +8 -2
  106. package/webpack.browserConfig.js +1 -1
  107. package/webpack.config.js +1 -1
  108. package/.claude/settings.local.json +0 -9
@@ -0,0 +1,336 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.AvoStorage = void 0;
19
+ var PlatformAvoStorage = /** @class */ (function () {
20
+ function PlatformAvoStorage() {
21
+ }
22
+ PlatformAvoStorage.prototype.parseJson = function (maybeItem) {
23
+ if (maybeItem !== null && maybeItem !== undefined) {
24
+ return JSON.parse(maybeItem);
25
+ }
26
+ else {
27
+ return null;
28
+ }
29
+ };
30
+ return PlatformAvoStorage;
31
+ }());
32
+ var AndroidAvoStorage = /** @class */ (function (_super) {
33
+ __extends(AndroidAvoStorage, _super);
34
+ function AndroidAvoStorage() {
35
+ var _this = _super !== null && _super.apply(this, arguments) || this;
36
+ _this.androidMemoryDataToAvoidAsyncQueries = {};
37
+ _this.storageLib = null;
38
+ _this.AsyncStorage = null;
39
+ _this.memoryStorageInitialized = false;
40
+ _this.onStorageInitFuncs = [];
41
+ _this.shouldLog = false;
42
+ return _this;
43
+ }
44
+ AndroidAvoStorage.prototype.init = function (shouldLog) {
45
+ var _this = this;
46
+ if (!process.env.BROWSER) {
47
+ this.storageLib = require("@react-native-async-storage/async-storage");
48
+ this.shouldLog = shouldLog;
49
+ this.AsyncStorage = this.storageLib.default;
50
+ this.loadAndroidDataToMemoryToAvoidAsyncQueries(function () {
51
+ _this.initializeStorageAndroid();
52
+ });
53
+ }
54
+ };
55
+ AndroidAvoStorage.prototype.loadAndroidDataToMemoryToAvoidAsyncQueries = function (onLoaded) {
56
+ var _this = this;
57
+ this.AsyncStorage.getAllKeys().then(function (keys) {
58
+ return _this.AsyncStorage.multiGet(keys).then(function (keyVals) {
59
+ if (_this.shouldLog) {
60
+ console.log("Avo Inspector: android loaded data from memory");
61
+ }
62
+ keyVals.forEach(function (keyVal) {
63
+ var key = keyVal[0];
64
+ _this.androidMemoryDataToAvoidAsyncQueries[key] = keyVal[1];
65
+ if (_this.shouldLog) {
66
+ console.log(key, keyVal[1]);
67
+ }
68
+ });
69
+ onLoaded();
70
+ });
71
+ });
72
+ };
73
+ AndroidAvoStorage.prototype.initializeStorageAndroid = function () {
74
+ this.memoryStorageInitialized = true;
75
+ this.onStorageInitFuncs.forEach(function (func) {
76
+ func();
77
+ });
78
+ };
79
+ AndroidAvoStorage.prototype.isInitialized = function () {
80
+ return this.storageLib && this.memoryStorageInitialized;
81
+ };
82
+ AndroidAvoStorage.prototype.getItemAsync = function (key) {
83
+ var maybeItem = this.AsyncStorage.getItem(key);
84
+ return maybeItem.then(function (storedItem) {
85
+ return storedItem != null ? JSON.parse(storedItem) : null;
86
+ });
87
+ };
88
+ AndroidAvoStorage.prototype.getItem = function (key) {
89
+ var maybeItem = this.androidMemoryDataToAvoidAsyncQueries[key];
90
+ return this.parseJson(maybeItem);
91
+ };
92
+ AndroidAvoStorage.prototype.setItem = function (key, value) {
93
+ this.AsyncStorage.setItem(key, JSON.stringify(value));
94
+ this.androidMemoryDataToAvoidAsyncQueries[key] = JSON.stringify(value);
95
+ };
96
+ AndroidAvoStorage.prototype.removeItem = function (key) {
97
+ this.AsyncStorage.removeItem(key);
98
+ this.androidMemoryDataToAvoidAsyncQueries[key] = null;
99
+ };
100
+ AndroidAvoStorage.prototype.runAfterInit = function (func) {
101
+ if (this.memoryStorageInitialized === true) {
102
+ func();
103
+ }
104
+ else {
105
+ this.onStorageInitFuncs.push(func);
106
+ }
107
+ };
108
+ return AndroidAvoStorage;
109
+ }(PlatformAvoStorage));
110
+ var IosAvoStorage = /** @class */ (function (_super) {
111
+ __extends(IosAvoStorage, _super);
112
+ function IosAvoStorage() {
113
+ var _this = _super !== null && _super.apply(this, arguments) || this;
114
+ _this.reactNative = null;
115
+ return _this;
116
+ }
117
+ IosAvoStorage.prototype.init = function (_shouldLog) {
118
+ if (!process.env.BROWSER) {
119
+ this.reactNative = require("react-native");
120
+ }
121
+ };
122
+ IosAvoStorage.prototype.isInitialized = function () {
123
+ return this.reactNative != null;
124
+ };
125
+ IosAvoStorage.prototype.getItemAsync = function (key) {
126
+ var Settings = this.reactNative.Settings;
127
+ var maybeItem = Settings.get(key);
128
+ return Promise.resolve(this.parseJson(maybeItem));
129
+ };
130
+ IosAvoStorage.prototype.getItem = function (key) {
131
+ var Settings = this.reactNative.Settings;
132
+ var maybeItem = Settings.get(key);
133
+ return this.parseJson(maybeItem);
134
+ };
135
+ IosAvoStorage.prototype.setItem = function (key, value) {
136
+ var _a;
137
+ var Settings = this.reactNative.Settings;
138
+ Settings.set((_a = {}, _a[key] = JSON.stringify(value), _a));
139
+ };
140
+ IosAvoStorage.prototype.removeItem = function (key) {
141
+ var _a;
142
+ var Settings = this.reactNative.Settings;
143
+ Settings.set((_a = {}, _a[key] = null, _a));
144
+ };
145
+ IosAvoStorage.prototype.runAfterInit = function (func) {
146
+ func();
147
+ };
148
+ return IosAvoStorage;
149
+ }(PlatformAvoStorage));
150
+ var BrowserAvoStorage = /** @class */ (function (_super) {
151
+ __extends(BrowserAvoStorage, _super);
152
+ function BrowserAvoStorage() {
153
+ var _this = _super !== null && _super.apply(this, arguments) || this;
154
+ _this.useFallbackStorage = false;
155
+ _this.fallbackStorage = {};
156
+ _this.storageInitialized = false;
157
+ _this.onStorageInitFuncs = [];
158
+ _this.shouldLog = false;
159
+ return _this;
160
+ }
161
+ BrowserAvoStorage.prototype.init = function (shouldLog) {
162
+ this.shouldLog = shouldLog;
163
+ this.initializeStorageWeb(this.isLocalStorageAvailable());
164
+ };
165
+ BrowserAvoStorage.prototype.initializeStorageWeb = function (isLocalStorageAvailable) {
166
+ this.storageInitialized = true;
167
+ if (isLocalStorageAvailable === false) {
168
+ this.useFallbackStorage = true;
169
+ }
170
+ this.onStorageInitFuncs.forEach(function (func) {
171
+ func();
172
+ });
173
+ };
174
+ BrowserAvoStorage.prototype.isLocalStorageAvailable = function () {
175
+ var uid = new Date().toISOString();
176
+ try {
177
+ window.localStorage.setItem(uid, uid);
178
+ if (window.localStorage.getItem(uid) === uid) {
179
+ window.localStorage.removeItem(uid);
180
+ return true;
181
+ }
182
+ else {
183
+ return false;
184
+ }
185
+ }
186
+ catch (error) {
187
+ return false;
188
+ }
189
+ };
190
+ BrowserAvoStorage.prototype.isInitialized = function () {
191
+ return this.storageInitialized;
192
+ };
193
+ BrowserAvoStorage.prototype.getItemAsync = function (key) {
194
+ var thisStorage = this;
195
+ return new Promise(function (resolve, _reject) {
196
+ thisStorage.runAfterInit(function () {
197
+ if (thisStorage.useFallbackStorage === true) {
198
+ var maybeItem = thisStorage.fallbackStorage[key];
199
+ resolve(thisStorage.parseJson(maybeItem));
200
+ }
201
+ else {
202
+ if (typeof window !== "undefined") {
203
+ var maybeItem = void 0;
204
+ try {
205
+ maybeItem = window.localStorage.getItem(key);
206
+ }
207
+ catch (error) {
208
+ if (thisStorage.shouldLog) {
209
+ console.error("Avo Inspector Storage getItemAsync error:", error);
210
+ }
211
+ resolve(null);
212
+ }
213
+ resolve(thisStorage.parseJson(maybeItem));
214
+ }
215
+ else {
216
+ resolve(null);
217
+ }
218
+ }
219
+ });
220
+ });
221
+ };
222
+ BrowserAvoStorage.prototype.getItem = function (key) {
223
+ var maybeItem;
224
+ if (this.storageInitialized === false) {
225
+ maybeItem = null;
226
+ }
227
+ else if (this.useFallbackStorage === true) {
228
+ maybeItem = this.fallbackStorage[key];
229
+ }
230
+ else if (process.env.BROWSER) {
231
+ if (typeof window !== "undefined") {
232
+ try {
233
+ maybeItem = window.localStorage.getItem(key);
234
+ }
235
+ catch (error) {
236
+ if (this.shouldLog) {
237
+ console.error("Avo Inspector Storage getItem error:", error);
238
+ }
239
+ }
240
+ }
241
+ }
242
+ return this.parseJson(maybeItem);
243
+ };
244
+ BrowserAvoStorage.prototype.setItem = function (key, value) {
245
+ var _this = this;
246
+ this.runAfterInit(function () {
247
+ if (_this.useFallbackStorage === true) {
248
+ _this.fallbackStorage[key] = JSON.stringify(value);
249
+ }
250
+ else {
251
+ if (typeof window !== "undefined") {
252
+ try {
253
+ window.localStorage.setItem(key, JSON.stringify(value));
254
+ }
255
+ catch (error) {
256
+ if (_this.shouldLog) {
257
+ console.error("Avo Inspector Storage setItem error:", error);
258
+ }
259
+ }
260
+ }
261
+ }
262
+ });
263
+ };
264
+ BrowserAvoStorage.prototype.removeItem = function (key) {
265
+ var _this = this;
266
+ this.runAfterInit(function () {
267
+ if (_this.useFallbackStorage === true) {
268
+ _this.fallbackStorage[key] = null;
269
+ }
270
+ else {
271
+ if (typeof window !== "undefined") {
272
+ try {
273
+ window.localStorage.removeItem(key);
274
+ }
275
+ catch (error) {
276
+ if (_this.shouldLog) {
277
+ console.error("Avo Inspector Storage removeItem error:", error);
278
+ }
279
+ }
280
+ }
281
+ }
282
+ });
283
+ };
284
+ BrowserAvoStorage.prototype.runAfterInit = function (func) {
285
+ if (this.storageInitialized === true) {
286
+ func();
287
+ }
288
+ else {
289
+ this.onStorageInitFuncs.push(func);
290
+ }
291
+ };
292
+ return BrowserAvoStorage;
293
+ }(PlatformAvoStorage));
294
+ var AvoStorage = /** @class */ (function () {
295
+ function AvoStorage(shouldLog) {
296
+ this.Platform = null;
297
+ if (!process.env.BROWSER) {
298
+ var reactNative = require("react-native");
299
+ this.Platform = reactNative.Platform.OS;
300
+ if (this.Platform === "android") {
301
+ this.storageImpl = new AndroidAvoStorage();
302
+ }
303
+ else if (this.Platform === "ios") {
304
+ this.storageImpl = new IosAvoStorage();
305
+ }
306
+ else {
307
+ throw new Error("Avo Inpector is not supported on " + this.Platform);
308
+ }
309
+ }
310
+ else {
311
+ this.Platform = "browser";
312
+ this.storageImpl = new BrowserAvoStorage();
313
+ }
314
+ this.storageImpl.init(shouldLog);
315
+ }
316
+ AvoStorage.prototype.isInitialized = function () {
317
+ return this.storageImpl.isInitialized();
318
+ };
319
+ AvoStorage.prototype.getItemAsync = function (key) {
320
+ return this.storageImpl.getItemAsync(key);
321
+ };
322
+ AvoStorage.prototype.getItem = function (key) {
323
+ return this.storageImpl.getItem(key);
324
+ };
325
+ AvoStorage.prototype.setItem = function (key, value) {
326
+ this.storageImpl.setItem(key, value);
327
+ };
328
+ AvoStorage.prototype.removeItem = function (key) {
329
+ this.storageImpl.removeItem(key);
330
+ };
331
+ AvoStorage.prototype.runAfterInit = function (func) {
332
+ this.storageImpl.runAfterInit(func);
333
+ };
334
+ return AvoStorage;
335
+ }());
336
+ exports.AvoStorage = AvoStorage;
@@ -0,0 +1,12 @@
1
+ /// <reference types="jest" />
2
+ declare let xhrMock: {
3
+ open: jest.Mock<any, any, any>;
4
+ send: jest.Mock<any, any, any>;
5
+ setRequestHeader: jest.Mock<any, any, any>;
6
+ onload: jest.Mock<any, any, any>;
7
+ onerror: jest.Mock<any, any, any>;
8
+ ontimeout: jest.Mock<any, any, any>;
9
+ status: number;
10
+ response: string;
11
+ };
12
+ export default xhrMock;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var xhrMock = {
4
+ open: jest.fn(),
5
+ send: jest.fn(),
6
+ setRequestHeader: jest.fn(),
7
+ onload: jest.fn(),
8
+ onerror: jest.fn(),
9
+ ontimeout: jest.fn(),
10
+ status: 200,
11
+ response: "{}",
12
+ };
13
+ window.XMLHttpRequest = jest.fn(function () { return xhrMock; });
14
+ exports.default = xhrMock;
@@ -0,0 +1,12 @@
1
+ /// <reference types="jest" />
2
+ declare let xhrErrorMock: {
3
+ open: jest.Mock<any, any, any>;
4
+ send: jest.Mock<any, any, any>;
5
+ setRequestHeader: jest.Mock<any, any, any>;
6
+ onload: jest.Mock<any, any, any>;
7
+ onerror: jest.Mock<any, any, any>;
8
+ ontimeout: jest.Mock<any, any, any>;
9
+ status: number;
10
+ statusText: string;
11
+ };
12
+ export default xhrErrorMock;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var xhrErrorMock = {
4
+ open: jest.fn(),
5
+ send: jest.fn(),
6
+ setRequestHeader: jest.fn(),
7
+ onload: jest.fn(),
8
+ onerror: jest.fn(),
9
+ ontimeout: jest.fn(),
10
+ status: 400,
11
+ statusText: "Bad Request",
12
+ };
13
+ window.XMLHttpRequest = jest.fn(function () { return xhrErrorMock; });
14
+ exports.default = xhrErrorMock;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,207 @@
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
+ });
@@ -0,0 +1 @@
1
+ export {};