node-avo-inspector 1.2.0 → 2.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +46 -0
- package/README.md +268 -4
- package/package.json +17 -1
- package/.claude/scheduled_tasks.lock +0 -1
- package/.claude/settings.local.json +0 -11
- package/.claude/worktrees/release-1.1.1/LICENSE +0 -21
- package/.claude/worktrees/release-1.1.1/README.md +0 -69
- package/.claude/worktrees/release-1.1.1/examples/node-inspector-js/index.js +0 -30
- package/.claude/worktrees/release-1.1.1/examples/node-inspector-js/package.json +0 -15
- package/.claude/worktrees/release-1.1.1/examples/node-inspector-js/yarn.lock +0 -6
- package/.claude/worktrees/release-1.1.1/examples/node-inspector-ts/dist/index.js +0 -34
- package/.claude/worktrees/release-1.1.1/examples/node-inspector-ts/index.ts +0 -30
- package/.claude/worktrees/release-1.1.1/examples/node-inspector-ts/package.json +0 -18
- package/.claude/worktrees/release-1.1.1/examples/node-inspector-ts/tsconfig.json +0 -15
- package/.claude/worktrees/release-1.1.1/examples/node-inspector-ts/yarn.lock +0 -11
- package/.claude/worktrees/release-1.1.1/package-lock.json +0 -4039
- package/.claude/worktrees/release-1.1.1/package.json +0 -48
- package/.claude/worktrees/release-1.1.1/reason/AvoInspector.rei +0 -11
- package/.claude/worktrees/release-1.1.1/reason/NodeAvoInspector.re +0 -27
- package/.claude/worktrees/release-1.1.1/src/AvoDeduplicator.ts +0 -146
- package/.claude/worktrees/release-1.1.1/src/AvoEncryption.ts +0 -90
- package/.claude/worktrees/release-1.1.1/src/AvoGuid.ts +0 -9
- package/.claude/worktrees/release-1.1.1/src/AvoInspector.ts +0 -383
- package/.claude/worktrees/release-1.1.1/src/AvoInspectorEnv.ts +0 -8
- package/.claude/worktrees/release-1.1.1/src/AvoNetworkCallsHandler.ts +0 -267
- package/.claude/worktrees/release-1.1.1/src/AvoSchemaParser.ts +0 -115
- package/.claude/worktrees/release-1.1.1/src/AvoStreamId.ts +0 -16
- package/.claude/worktrees/release-1.1.1/src/__tests__/TestAvoEncryption.ts +0 -515
- package/.claude/worktrees/release-1.1.1/src/__tests__/TestAvoEventSpecCache.ts +0 -242
- package/.claude/worktrees/release-1.1.1/src/__tests__/TestAvoEventSpecFetcher.ts +0 -241
- package/.claude/worktrees/release-1.1.1/src/__tests__/TestAvoInspector.ts +0 -360
- package/.claude/worktrees/release-1.1.1/src/__tests__/TestAvoStreamId.ts +0 -72
- package/.claude/worktrees/release-1.1.1/src/__tests__/TestDeduplicator.ts +0 -191
- package/.claude/worktrees/release-1.1.1/src/__tests__/TestEventValidator.ts +0 -231
- package/.claude/worktrees/release-1.1.1/src/__tests__/TestNetworkCallsHandler.ts +0 -179
- package/.claude/worktrees/release-1.1.1/src/__tests__/TestNetworkCallsHandlerPublic.ts +0 -208
- package/.claude/worktrees/release-1.1.1/src/__tests__/TestParsing.ts +0 -153
- package/.claude/worktrees/release-1.1.1/src/__tests__/constants.ts +0 -63
- package/.claude/worktrees/release-1.1.1/src/eventSpec/AvoEventSpecCache.ts +0 -109
- package/.claude/worktrees/release-1.1.1/src/eventSpec/AvoEventSpecFetchTypes.ts +0 -47
- package/.claude/worktrees/release-1.1.1/src/eventSpec/AvoEventSpecFetcher.ts +0 -106
- package/.claude/worktrees/release-1.1.1/src/eventSpec/EventValidator.ts +0 -74
- package/.claude/worktrees/release-1.1.1/src/index.ts +0 -2
- package/.claude/worktrees/release-1.1.1/src/utils.ts +0 -49
- package/.claude/worktrees/release-1.1.1/tsconfig.json +0 -13
- package/.claude/worktrees/release-1.1.1/yarn.lock +0 -2310
- package/.github/workflows/claude.yml +0 -55
- package/dist/__tests__/TestAvoEncryption.d.ts +0 -1
- package/dist/__tests__/TestAvoEncryption.js +0 -288
- package/dist/__tests__/TestAvoEventSpecCache.d.ts +0 -1
- package/dist/__tests__/TestAvoEventSpecCache.js +0 -194
- package/dist/__tests__/TestAvoEventSpecFetcher.d.ts +0 -1
- package/dist/__tests__/TestAvoEventSpecFetcher.js +0 -219
- package/dist/__tests__/TestAvoInspector.d.ts +0 -1
- package/dist/__tests__/TestAvoInspector.js +0 -291
- package/dist/__tests__/TestAvoStreamId.d.ts +0 -1
- package/dist/__tests__/TestAvoStreamId.js +0 -55
- package/dist/__tests__/TestDeduplicator.d.ts +0 -1
- package/dist/__tests__/TestDeduplicator.js +0 -102
- package/dist/__tests__/TestEventValidator.d.ts +0 -1
- package/dist/__tests__/TestEventValidator.js +0 -196
- package/dist/__tests__/TestNetworkCallsHandler.d.ts +0 -1
- package/dist/__tests__/TestNetworkCallsHandler.js +0 -86
- package/dist/__tests__/TestNetworkCallsHandlerPublic.d.ts +0 -1
- package/dist/__tests__/TestNetworkCallsHandlerPublic.js +0 -160
- package/dist/__tests__/TestParsing.d.ts +0 -1
- package/dist/__tests__/TestParsing.js +0 -128
- package/dist/__tests__/constants.d.ts +0 -42
- package/dist/__tests__/constants.js +0 -53
- package/examples/node-inspector-js/index.js +0 -30
- package/examples/node-inspector-js/package.json +0 -15
- package/examples/node-inspector-js/yarn.lock +0 -6
- package/examples/node-inspector-ts/dist/index.js +0 -34
- package/examples/node-inspector-ts/index.ts +0 -30
- package/examples/node-inspector-ts/package.json +0 -18
- package/examples/node-inspector-ts/tsconfig.json +0 -15
- package/examples/node-inspector-ts/yarn.lock +0 -11
- package/reason/AvoInspector.rei +0 -11
- package/reason/NodeAvoInspector.re +0 -27
- package/src/AvoDeduplicator.ts +0 -150
- package/src/AvoEncryption.ts +0 -90
- package/src/AvoGuid.ts +0 -9
- package/src/AvoInspector.ts +0 -498
- package/src/AvoInspectorEnv.ts +0 -8
- package/src/AvoNetworkCallsHandler.ts +0 -340
- package/src/AvoSchemaParser.ts +0 -115
- package/src/AvoStreamId.ts +0 -16
- package/src/__tests__/TestAvoEncryption.ts +0 -515
- package/src/__tests__/TestAvoEventSpecCache.ts +0 -242
- package/src/__tests__/TestAvoEventSpecFetcher.ts +0 -279
- package/src/__tests__/TestAvoInspector.ts +0 -376
- package/src/__tests__/TestAvoStreamId.ts +0 -72
- package/src/__tests__/TestDeduplicator.ts +0 -191
- package/src/__tests__/TestEventValidator.ts +0 -231
- package/src/__tests__/TestNetworkCallsHandler.ts +0 -181
- package/src/__tests__/TestNetworkCallsHandlerPublic.ts +0 -208
- package/src/__tests__/TestParsing.ts +0 -153
- package/src/__tests__/constants.ts +0 -63
- package/src/eventSpec/AvoEventSpecCache.ts +0 -119
- package/src/eventSpec/AvoEventSpecFetchTypes.ts +0 -47
- package/src/eventSpec/AvoEventSpecFetcher.ts +0 -186
- package/src/eventSpec/EventValidator.ts +0 -74
- package/src/index.ts +0 -2
- package/src/utils.ts +0 -49
- package/tsconfig.json +0 -13
|
@@ -1,376 +0,0 @@
|
|
|
1
|
-
import { AvoInspector } from "../AvoInspector";
|
|
2
|
-
import { AvoInspectorEnv } from "../AvoInspectorEnv";
|
|
3
|
-
|
|
4
|
-
import { error, defaultOptions } from "./constants";
|
|
5
|
-
import { AvoNetworkCallsHandler } from "../AvoNetworkCallsHandler";
|
|
6
|
-
|
|
7
|
-
jest.mock("../AvoNetworkCallsHandler");
|
|
8
|
-
|
|
9
|
-
describe("Initialization", () => {
|
|
10
|
-
|
|
11
|
-
test("Network Handler is initialized on Inspector init", () => {
|
|
12
|
-
const inspectorVersion = process.env.npm_package_version || "";
|
|
13
|
-
const { apiKey, env, version, appName } = defaultOptions;
|
|
14
|
-
|
|
15
|
-
let inspector = new AvoInspector(defaultOptions);
|
|
16
|
-
inspector.enableLogging(true);
|
|
17
|
-
|
|
18
|
-
expect(AvoNetworkCallsHandler).toHaveBeenCalledTimes(1);
|
|
19
|
-
expect(AvoNetworkCallsHandler).toHaveBeenCalledWith(apiKey,
|
|
20
|
-
env,
|
|
21
|
-
"my-test-app",
|
|
22
|
-
version,
|
|
23
|
-
inspectorVersion,
|
|
24
|
-
undefined);
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
test("Api Key is set", () => {
|
|
28
|
-
// Given
|
|
29
|
-
const apiKey = "api-key-xxx";
|
|
30
|
-
|
|
31
|
-
// When
|
|
32
|
-
let inspector = new AvoInspector({
|
|
33
|
-
env: AvoInspectorEnv.Prod,
|
|
34
|
-
version: "0",
|
|
35
|
-
apiKey,
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
// Then
|
|
39
|
-
expect(inspector.apiKey).toBe(apiKey);
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
test("Error is thrown when Api Key is not set", () => {
|
|
43
|
-
// Given
|
|
44
|
-
// @ts-ignore
|
|
45
|
-
let apiKey;
|
|
46
|
-
|
|
47
|
-
// Then
|
|
48
|
-
expect(() => {
|
|
49
|
-
new AvoInspector({
|
|
50
|
-
env: AvoInspectorEnv.Prod,
|
|
51
|
-
version: "0",
|
|
52
|
-
// @ts-ignore
|
|
53
|
-
apiKey,
|
|
54
|
-
});
|
|
55
|
-
}).toThrow(error.API_KEY);
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
test("Error is thrown when whitespace Api Key is used", () => {
|
|
59
|
-
// Given
|
|
60
|
-
const apiKey = " ";
|
|
61
|
-
|
|
62
|
-
// Then
|
|
63
|
-
expect(() => {
|
|
64
|
-
new AvoInspector({
|
|
65
|
-
env: AvoInspectorEnv.Prod,
|
|
66
|
-
version: "0",
|
|
67
|
-
apiKey,
|
|
68
|
-
});
|
|
69
|
-
}).toThrow(error.API_KEY);
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
test("Error is thrown when empty string Api Key is used", () => {
|
|
73
|
-
expect(() => {
|
|
74
|
-
new AvoInspector({
|
|
75
|
-
env: AvoInspectorEnv.Prod,
|
|
76
|
-
version: "0",
|
|
77
|
-
apiKey: "",
|
|
78
|
-
});
|
|
79
|
-
}).toThrow(error.API_KEY);
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
test("Error is thrown when Api Key is set to null", () => {
|
|
83
|
-
// Given
|
|
84
|
-
const apiKey = null;
|
|
85
|
-
|
|
86
|
-
// Then
|
|
87
|
-
expect(() => {
|
|
88
|
-
new AvoInspector({
|
|
89
|
-
env: AvoInspectorEnv.Prod,
|
|
90
|
-
version: "0",
|
|
91
|
-
// @ts-ignore
|
|
92
|
-
apiKey,
|
|
93
|
-
});
|
|
94
|
-
}).toThrow(error.API_KEY);
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
test("Dev environment is used when env is not provided", () => {
|
|
98
|
-
// Given
|
|
99
|
-
// @ts-ignore
|
|
100
|
-
let env;
|
|
101
|
-
|
|
102
|
-
// When
|
|
103
|
-
let inspector = new AvoInspector({
|
|
104
|
-
apiKey: "api-key-xxx",
|
|
105
|
-
version: "0",
|
|
106
|
-
// @ts-ignore
|
|
107
|
-
env,
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
// Then
|
|
111
|
-
expect(inspector.environment).toBe(AvoInspectorEnv.Dev);
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
test("Dev environment is used when empty string is used", () => {
|
|
115
|
-
// Given
|
|
116
|
-
const env = "";
|
|
117
|
-
|
|
118
|
-
// When
|
|
119
|
-
let inspector = new AvoInspector({
|
|
120
|
-
apiKey: "api-key-xxx",
|
|
121
|
-
version: "0",
|
|
122
|
-
// @ts-ignore
|
|
123
|
-
env,
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
// Then
|
|
127
|
-
expect(inspector.environment).toBe(AvoInspectorEnv.Dev);
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
test("Dev env is set using AvoInspectorEnv", () => {
|
|
131
|
-
// When
|
|
132
|
-
let inspector = new AvoInspector({
|
|
133
|
-
apiKey: "api-key-xxx",
|
|
134
|
-
env: AvoInspectorEnv.Dev,
|
|
135
|
-
version: "0",
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
// Then
|
|
139
|
-
expect(inspector.environment).toBe(AvoInspectorEnv.Dev);
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
test("Dev environment is set using string", () => {
|
|
143
|
-
// When
|
|
144
|
-
let inspector = new AvoInspector({
|
|
145
|
-
apiKey: "api-key-xxx",
|
|
146
|
-
env: "dev",
|
|
147
|
-
version: "0",
|
|
148
|
-
});
|
|
149
|
-
|
|
150
|
-
// Then
|
|
151
|
-
expect(inspector.environment).toBe(AvoInspectorEnv.Dev);
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
test("Staging env is set using AvoInspectorEnv", () => {
|
|
155
|
-
// When
|
|
156
|
-
let inspector = new AvoInspector({
|
|
157
|
-
apiKey: "api-key-xxx",
|
|
158
|
-
env: AvoInspectorEnv.Staging,
|
|
159
|
-
version: "0",
|
|
160
|
-
});
|
|
161
|
-
|
|
162
|
-
// Then
|
|
163
|
-
expect(inspector.environment).toBe(AvoInspectorEnv.Staging);
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
test("Staging environment is set using string", () => {
|
|
167
|
-
// When
|
|
168
|
-
let inspector = new AvoInspector({
|
|
169
|
-
apiKey: "api-key-xxx",
|
|
170
|
-
env: "staging",
|
|
171
|
-
version: "0",
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
// Then
|
|
175
|
-
expect(inspector.environment).toBe(AvoInspectorEnv.Staging);
|
|
176
|
-
});
|
|
177
|
-
|
|
178
|
-
test("Prod env is set using AvoInspectorEnv", () => {
|
|
179
|
-
// When
|
|
180
|
-
let inspector = new AvoInspector({
|
|
181
|
-
apiKey: "api-key-xxx",
|
|
182
|
-
env: AvoInspectorEnv.Prod,
|
|
183
|
-
version: "0",
|
|
184
|
-
});
|
|
185
|
-
|
|
186
|
-
// Then
|
|
187
|
-
expect(inspector.environment).toBe(AvoInspectorEnv.Prod);
|
|
188
|
-
});
|
|
189
|
-
|
|
190
|
-
test("Prod environment is set using string", () => {
|
|
191
|
-
// When
|
|
192
|
-
let inspector = new AvoInspector({
|
|
193
|
-
apiKey: "api-key-xxx",
|
|
194
|
-
env: "prod",
|
|
195
|
-
version: "0",
|
|
196
|
-
});
|
|
197
|
-
|
|
198
|
-
// Then
|
|
199
|
-
expect(inspector.environment).toBe(AvoInspectorEnv.Prod);
|
|
200
|
-
});
|
|
201
|
-
|
|
202
|
-
test("Environment other than Dev, Staging, Prod falls back to Dev", () => {
|
|
203
|
-
// When
|
|
204
|
-
const env = "test";
|
|
205
|
-
|
|
206
|
-
let inspector = new AvoInspector({
|
|
207
|
-
apiKey: "api-key-xxx",
|
|
208
|
-
version: "0",
|
|
209
|
-
// @ts-ignore
|
|
210
|
-
env,
|
|
211
|
-
});
|
|
212
|
-
|
|
213
|
-
// Then
|
|
214
|
-
expect(inspector.environment).toBe(AvoInspectorEnv.Dev);
|
|
215
|
-
});
|
|
216
|
-
|
|
217
|
-
test("Version is set", () => {
|
|
218
|
-
const version = "1";
|
|
219
|
-
|
|
220
|
-
// When
|
|
221
|
-
let inspector = new AvoInspector({
|
|
222
|
-
apiKey: "api-key-xxx",
|
|
223
|
-
env: AvoInspectorEnv.Prod,
|
|
224
|
-
version,
|
|
225
|
-
});
|
|
226
|
-
|
|
227
|
-
// Then
|
|
228
|
-
expect(inspector.version).toBe(version);
|
|
229
|
-
});
|
|
230
|
-
|
|
231
|
-
test("Error is thrown when version is not set", () => {
|
|
232
|
-
// Given
|
|
233
|
-
// @ts-ignore
|
|
234
|
-
let version;
|
|
235
|
-
|
|
236
|
-
// Then
|
|
237
|
-
expect(() => {
|
|
238
|
-
new AvoInspector({
|
|
239
|
-
apiKey: "api-key-xxx",
|
|
240
|
-
env: AvoInspectorEnv.Prod,
|
|
241
|
-
// @ts-ignore
|
|
242
|
-
version,
|
|
243
|
-
});
|
|
244
|
-
}).toThrow(error.VERSION);
|
|
245
|
-
});
|
|
246
|
-
|
|
247
|
-
test("Error is thrown when version is set to empty string", () => {
|
|
248
|
-
// Given
|
|
249
|
-
const version = " ";
|
|
250
|
-
|
|
251
|
-
// Then
|
|
252
|
-
expect(() => {
|
|
253
|
-
new AvoInspector({
|
|
254
|
-
apiKey: "api-key-xxx",
|
|
255
|
-
env: AvoInspectorEnv.Prod,
|
|
256
|
-
version,
|
|
257
|
-
});
|
|
258
|
-
}).toThrow(error.VERSION);
|
|
259
|
-
});
|
|
260
|
-
|
|
261
|
-
test("Error is thrown when version is set to null", () => {
|
|
262
|
-
// Given
|
|
263
|
-
const version = null;
|
|
264
|
-
|
|
265
|
-
// Then
|
|
266
|
-
expect(() => {
|
|
267
|
-
new AvoInspector({
|
|
268
|
-
apiKey: "api-key-xxx",
|
|
269
|
-
env: AvoInspectorEnv.Prod,
|
|
270
|
-
// @ts-ignore
|
|
271
|
-
version,
|
|
272
|
-
});
|
|
273
|
-
}).toThrow(error.VERSION);
|
|
274
|
-
});
|
|
275
|
-
|
|
276
|
-
test("publicEncryptionKey is forwarded to AvoNetworkCallsHandler when provided", () => {
|
|
277
|
-
const inspectorVersion = process.env.npm_package_version || "";
|
|
278
|
-
|
|
279
|
-
(AvoNetworkCallsHandler as unknown as jest.Mock).mockClear();
|
|
280
|
-
|
|
281
|
-
let inspector = new AvoInspector({
|
|
282
|
-
apiKey: "api-key-xxx",
|
|
283
|
-
env: AvoInspectorEnv.Dev,
|
|
284
|
-
version: "1",
|
|
285
|
-
publicEncryptionKey: "my-public-key-123",
|
|
286
|
-
});
|
|
287
|
-
|
|
288
|
-
expect(AvoNetworkCallsHandler).toHaveBeenCalledWith(
|
|
289
|
-
"api-key-xxx",
|
|
290
|
-
AvoInspectorEnv.Dev,
|
|
291
|
-
"",
|
|
292
|
-
"1",
|
|
293
|
-
inspectorVersion,
|
|
294
|
-
"my-public-key-123"
|
|
295
|
-
);
|
|
296
|
-
});
|
|
297
|
-
|
|
298
|
-
test("publicEncryptionKey is forwarded as undefined to AvoNetworkCallsHandler when not provided", () => {
|
|
299
|
-
const inspectorVersion = process.env.npm_package_version || "";
|
|
300
|
-
|
|
301
|
-
(AvoNetworkCallsHandler as unknown as jest.Mock).mockClear();
|
|
302
|
-
|
|
303
|
-
let inspector = new AvoInspector({
|
|
304
|
-
apiKey: "api-key-xxx",
|
|
305
|
-
env: AvoInspectorEnv.Dev,
|
|
306
|
-
version: "1",
|
|
307
|
-
});
|
|
308
|
-
|
|
309
|
-
expect(AvoNetworkCallsHandler).toHaveBeenCalledWith(
|
|
310
|
-
"api-key-xxx",
|
|
311
|
-
AvoInspectorEnv.Dev,
|
|
312
|
-
"",
|
|
313
|
-
"1",
|
|
314
|
-
inspectorVersion,
|
|
315
|
-
undefined
|
|
316
|
-
);
|
|
317
|
-
});
|
|
318
|
-
|
|
319
|
-
test("warns when publicEncryptionKey is malformed in dev/staging", () => {
|
|
320
|
-
const consoleWarnSpy = jest.spyOn(console, "warn").mockImplementation(() => {});
|
|
321
|
-
|
|
322
|
-
new AvoInspector({
|
|
323
|
-
apiKey: "api-key-xxx",
|
|
324
|
-
env: AvoInspectorEnv.Dev,
|
|
325
|
-
version: "1",
|
|
326
|
-
publicEncryptionKey: "not-valid-hex",
|
|
327
|
-
});
|
|
328
|
-
|
|
329
|
-
expect(consoleWarnSpy).toHaveBeenCalledWith(
|
|
330
|
-
expect.stringContaining("publicEncryptionKey does not look like a valid")
|
|
331
|
-
);
|
|
332
|
-
consoleWarnSpy.mockRestore();
|
|
333
|
-
});
|
|
334
|
-
|
|
335
|
-
test("does not warn when publicEncryptionKey is a valid 130-char uncompressed hex key in dev/staging", () => {
|
|
336
|
-
const consoleWarnSpy = jest.spyOn(console, "warn").mockImplementation(() => {});
|
|
337
|
-
|
|
338
|
-
const validKey = "04" + "ab".repeat(64); // 2 + 128 = 130 hex chars
|
|
339
|
-
|
|
340
|
-
new AvoInspector({
|
|
341
|
-
apiKey: "api-key-xxx",
|
|
342
|
-
env: AvoInspectorEnv.Dev,
|
|
343
|
-
version: "1",
|
|
344
|
-
publicEncryptionKey: validKey,
|
|
345
|
-
});
|
|
346
|
-
|
|
347
|
-
expect(consoleWarnSpy).not.toHaveBeenCalled();
|
|
348
|
-
consoleWarnSpy.mockRestore();
|
|
349
|
-
});
|
|
350
|
-
|
|
351
|
-
test("does not warn when publicEncryptionKey is a valid 66-char compressed hex key in dev/staging", () => {
|
|
352
|
-
const consoleWarnSpy = jest.spyOn(console, "warn").mockImplementation(() => {});
|
|
353
|
-
|
|
354
|
-
const validKey = "02" + "4e".repeat(32); // 2 + 64 = 66 hex chars
|
|
355
|
-
|
|
356
|
-
new AvoInspector({
|
|
357
|
-
apiKey: "api-key-xxx",
|
|
358
|
-
env: AvoInspectorEnv.Dev,
|
|
359
|
-
version: "1",
|
|
360
|
-
publicEncryptionKey: validKey,
|
|
361
|
-
});
|
|
362
|
-
|
|
363
|
-
expect(consoleWarnSpy).not.toHaveBeenCalled();
|
|
364
|
-
consoleWarnSpy.mockRestore();
|
|
365
|
-
});
|
|
366
|
-
|
|
367
|
-
test("constructor works without publicEncryptionKey (backwards compatible)", () => {
|
|
368
|
-
expect(() => {
|
|
369
|
-
new AvoInspector({
|
|
370
|
-
apiKey: "api-key-xxx",
|
|
371
|
-
env: AvoInspectorEnv.Dev,
|
|
372
|
-
version: "1",
|
|
373
|
-
});
|
|
374
|
-
}).not.toThrow();
|
|
375
|
-
});
|
|
376
|
-
});
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import { AvoStreamId } from "../AvoStreamId";
|
|
2
|
-
|
|
3
|
-
describe("AvoStreamId", () => {
|
|
4
|
-
let consoleWarnSpy: jest.SpyInstance;
|
|
5
|
-
|
|
6
|
-
beforeEach(() => {
|
|
7
|
-
consoleWarnSpy = jest.spyOn(console, "warn").mockImplementation(() => {});
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
afterEach(() => {
|
|
11
|
-
jest.restoreAllMocks();
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
test("streamId getter returns empty string by default", () => {
|
|
15
|
-
const avoStreamId = new AvoStreamId();
|
|
16
|
-
expect(avoStreamId.streamId).toBe("");
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
test("streamId getter returns the value passed to constructor", () => {
|
|
20
|
-
const avoStreamId = new AvoStreamId("my-stream-id");
|
|
21
|
-
expect(avoStreamId.streamId).toBe("my-stream-id");
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
test("streamId containing ':' logs a warning", () => {
|
|
25
|
-
const avoStreamId = new AvoStreamId("invalid:stream:id");
|
|
26
|
-
const id = avoStreamId.streamId;
|
|
27
|
-
|
|
28
|
-
expect(consoleWarnSpy).toHaveBeenCalledWith(
|
|
29
|
-
"[Avo Inspector] Warning: streamId contains ':' which is not supported"
|
|
30
|
-
);
|
|
31
|
-
expect(id).toBe("invalid:stream:id");
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
test("streamId without ':' does not log a warning", () => {
|
|
35
|
-
const avoStreamId = new AvoStreamId("valid-stream-id");
|
|
36
|
-
const id = avoStreamId.streamId;
|
|
37
|
-
|
|
38
|
-
expect(consoleWarnSpy).not.toHaveBeenCalled();
|
|
39
|
-
expect(id).toBe("valid-stream-id");
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
test("empty streamId does not log a warning", () => {
|
|
43
|
-
const avoStreamId = new AvoStreamId("");
|
|
44
|
-
const id = avoStreamId.streamId;
|
|
45
|
-
|
|
46
|
-
expect(consoleWarnSpy).not.toHaveBeenCalled();
|
|
47
|
-
expect(id).toBe("");
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
test("explicit undefined arg returns empty string and does not warn", () => {
|
|
51
|
-
const avoStreamId = new AvoStreamId(undefined);
|
|
52
|
-
const id = avoStreamId.streamId;
|
|
53
|
-
|
|
54
|
-
expect(consoleWarnSpy).not.toHaveBeenCalled();
|
|
55
|
-
expect(id).toBe("");
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
test("warning is only logged once per instance, not on every .streamId access", () => {
|
|
59
|
-
const avoStreamId = new AvoStreamId("bad:id");
|
|
60
|
-
|
|
61
|
-
// The warning is logged in the constructor, so it's already been called once
|
|
62
|
-
expect(consoleWarnSpy).toHaveBeenCalledTimes(1);
|
|
63
|
-
|
|
64
|
-
// Access streamId multiple times
|
|
65
|
-
avoStreamId.streamId;
|
|
66
|
-
avoStreamId.streamId;
|
|
67
|
-
avoStreamId.streamId;
|
|
68
|
-
|
|
69
|
-
// Should still be only one warning total
|
|
70
|
-
expect(consoleWarnSpy).toHaveBeenCalledTimes(1);
|
|
71
|
-
});
|
|
72
|
-
});
|
|
@@ -1,191 +0,0 @@
|
|
|
1
|
-
import { AvoDeduplicator } from "../AvoDeduplicator";
|
|
2
|
-
import { deepEquals } from "../utils";
|
|
3
|
-
import { AvoInspector } from "../AvoInspector";
|
|
4
|
-
import { defaultOptions } from "./constants";
|
|
5
|
-
|
|
6
|
-
jest
|
|
7
|
-
.useFakeTimers()
|
|
8
|
-
.setSystemTime(new Date('2020-01-01'));
|
|
9
|
-
|
|
10
|
-
describe("Deduplicator", () => {
|
|
11
|
-
const deduplicator = new AvoDeduplicator();
|
|
12
|
-
|
|
13
|
-
const testObject = {
|
|
14
|
-
"0": "some string",
|
|
15
|
-
"1": [1, 2, 3],
|
|
16
|
-
2: [["str", true]],
|
|
17
|
-
3: { avo: [1.1, 2.2, 3.3] },
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
test(`AvoDeduplicator.deepEqual tests`, () => {
|
|
21
|
-
const secondObject = {
|
|
22
|
-
"0": "some string",
|
|
23
|
-
"1": [1, 2, 3],
|
|
24
|
-
2: [["str", true]],
|
|
25
|
-
3: { avo: [1.1, 2.2, 3.3] },
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
expect(deepEquals(testObject, secondObject)).toBe(true);
|
|
29
|
-
|
|
30
|
-
expect(deepEquals(testObject, { ...secondObject, "4": "4" })).toBe(false);
|
|
31
|
-
|
|
32
|
-
expect(
|
|
33
|
-
deepEquals(testObject, {
|
|
34
|
-
...secondObject,
|
|
35
|
-
3: { ...secondObject[3], avo: [1.1] },
|
|
36
|
-
})
|
|
37
|
-
).toBe(false);
|
|
38
|
-
|
|
39
|
-
expect(deepEquals(testObject, { ...secondObject, 0: "other string" })).toBe(
|
|
40
|
-
false
|
|
41
|
-
);
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
test(`Detects duplications when track in avo and then manually`, () => {
|
|
45
|
-
const shouldRegisterFromAvo = deduplicator.shouldRegisterEvent(
|
|
46
|
-
"Test",
|
|
47
|
-
testObject,
|
|
48
|
-
true
|
|
49
|
-
);
|
|
50
|
-
const shouldRegisterManual = deduplicator.shouldRegisterEvent(
|
|
51
|
-
"Test",
|
|
52
|
-
testObject,
|
|
53
|
-
false
|
|
54
|
-
);
|
|
55
|
-
|
|
56
|
-
expect(shouldRegisterFromAvo).toBe(true);
|
|
57
|
-
expect(shouldRegisterManual).toBe(false);
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
test(`Detects duplications when track manually and then in avo`, () => {
|
|
61
|
-
const shouldRegisterManual = deduplicator.shouldRegisterEvent(
|
|
62
|
-
"Test",
|
|
63
|
-
testObject,
|
|
64
|
-
false
|
|
65
|
-
);
|
|
66
|
-
const shouldRegisterFromAvo = deduplicator.shouldRegisterEvent(
|
|
67
|
-
"Test",
|
|
68
|
-
testObject,
|
|
69
|
-
true
|
|
70
|
-
);
|
|
71
|
-
|
|
72
|
-
expect(shouldRegisterManual).toBe(true);
|
|
73
|
-
expect(shouldRegisterFromAvo).toBe(false);
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
test(`Inspector deduplicates only one event when track manually, in avo and then manually again`, async () => {
|
|
77
|
-
const inspector = new AvoInspector(defaultOptions);
|
|
78
|
-
inspector.enableLogging(false);
|
|
79
|
-
|
|
80
|
-
const manuallyTrackedSchema = await inspector.trackSchemaFromEvent(
|
|
81
|
-
"test",
|
|
82
|
-
testObject
|
|
83
|
-
);
|
|
84
|
-
// @ts-ignore
|
|
85
|
-
const avoTrackedSchema = await inspector._avoFunctionTrackSchemaFromEvent(
|
|
86
|
-
"test",
|
|
87
|
-
testObject,
|
|
88
|
-
"eventId",
|
|
89
|
-
"eventhash"
|
|
90
|
-
);
|
|
91
|
-
const manuallyTrackedSchemaAgain = await inspector.trackSchemaFromEvent(
|
|
92
|
-
"test",
|
|
93
|
-
testObject
|
|
94
|
-
);
|
|
95
|
-
|
|
96
|
-
expect(manuallyTrackedSchema.length).toBe(4);
|
|
97
|
-
expect(manuallyTrackedSchema.length + avoTrackedSchema.length + manuallyTrackedSchemaAgain.length).toBe(8);
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
test(`Inspector deduplicates only one event when track in avo, manually and then in avo again`, async () => {
|
|
101
|
-
const inspector = new AvoInspector(defaultOptions);
|
|
102
|
-
inspector.enableLogging(false);
|
|
103
|
-
|
|
104
|
-
// @ts-ignore
|
|
105
|
-
const avoTrackedSchema = await inspector._avoFunctionTrackSchemaFromEvent(
|
|
106
|
-
"test",
|
|
107
|
-
testObject,
|
|
108
|
-
"eventId",
|
|
109
|
-
"eventhash"
|
|
110
|
-
);
|
|
111
|
-
const manuallyTrackedSchema = await inspector.trackSchemaFromEvent(
|
|
112
|
-
"test",
|
|
113
|
-
testObject
|
|
114
|
-
);
|
|
115
|
-
// @ts-ignore
|
|
116
|
-
const avoTrackedSchemaAgain = await inspector._avoFunctionTrackSchemaFromEvent(
|
|
117
|
-
"test",
|
|
118
|
-
testObject,
|
|
119
|
-
"eventId",
|
|
120
|
-
"eventhash"
|
|
121
|
-
);
|
|
122
|
-
|
|
123
|
-
expect(avoTrackedSchema.length).toBe(4);
|
|
124
|
-
expect(manuallyTrackedSchema.length).toBe(0);
|
|
125
|
-
expect(avoTrackedSchemaAgain.length).toBe(4);
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
test(`Allows two same manual events in a row`, async () => {
|
|
129
|
-
const inspector = new AvoInspector(defaultOptions);
|
|
130
|
-
inspector.enableLogging(false);
|
|
131
|
-
|
|
132
|
-
const manuallyTrackedSchema = await inspector.trackSchemaFromEvent(
|
|
133
|
-
"test",
|
|
134
|
-
testObject
|
|
135
|
-
);
|
|
136
|
-
const manuallyTrackedSchemaAgain = await inspector.trackSchemaFromEvent(
|
|
137
|
-
"test",
|
|
138
|
-
testObject
|
|
139
|
-
);
|
|
140
|
-
|
|
141
|
-
expect(manuallyTrackedSchema.length).toBe(4);
|
|
142
|
-
expect(manuallyTrackedSchemaAgain.length).toBe(4);
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
test(`Allows two same avo events in a row`, async () => {
|
|
146
|
-
const inspector = new AvoInspector(defaultOptions);
|
|
147
|
-
inspector.enableLogging(false);
|
|
148
|
-
|
|
149
|
-
// @ts-ignore
|
|
150
|
-
const avoTrackedSchema = await inspector._avoFunctionTrackSchemaFromEvent(
|
|
151
|
-
"test",
|
|
152
|
-
testObject,
|
|
153
|
-
"eventId",
|
|
154
|
-
"eventhash"
|
|
155
|
-
);
|
|
156
|
-
// @ts-ignore
|
|
157
|
-
const avoTrackedSchemaAgain = await inspector._avoFunctionTrackSchemaFromEvent(
|
|
158
|
-
"test",
|
|
159
|
-
testObject,
|
|
160
|
-
"eventId",
|
|
161
|
-
"eventhash"
|
|
162
|
-
);
|
|
163
|
-
|
|
164
|
-
expect(avoTrackedSchema.length).toBe(4);
|
|
165
|
-
expect(avoTrackedSchemaAgain.length).toBe(4);
|
|
166
|
-
});
|
|
167
|
-
|
|
168
|
-
test(`Does not deduplicate if more than 500ms pass`, () => {
|
|
169
|
-
const shouldRegisterFromAvo = deduplicator.shouldRegisterEvent(
|
|
170
|
-
"Test",
|
|
171
|
-
testObject,
|
|
172
|
-
true
|
|
173
|
-
);
|
|
174
|
-
const now = new Date();
|
|
175
|
-
const dateNowSpy = jest
|
|
176
|
-
.spyOn(Date, "now")
|
|
177
|
-
.mockImplementation(() =>
|
|
178
|
-
now.setMilliseconds(now.getMilliseconds() + 501)
|
|
179
|
-
);
|
|
180
|
-
const shouldRegisterManual = deduplicator.shouldRegisterEvent(
|
|
181
|
-
"Test",
|
|
182
|
-
testObject,
|
|
183
|
-
false
|
|
184
|
-
);
|
|
185
|
-
|
|
186
|
-
expect(shouldRegisterFromAvo).toBe(true);
|
|
187
|
-
expect(shouldRegisterManual).toBe(true);
|
|
188
|
-
|
|
189
|
-
dateNowSpy.mockRestore();
|
|
190
|
-
});
|
|
191
|
-
});
|