node-avo-inspector 1.0.1 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/README.md +14 -5
  2. package/dist/AvoDeduplicator.js +2 -2
  3. package/dist/AvoInspector.d.ts +2 -2
  4. package/dist/AvoInspector.js +34 -14
  5. package/dist/AvoInspectorEnv.d.ts +2 -2
  6. package/dist/AvoNetworkCallsHandler.js +2 -1
  7. package/dist/AvoSchemaParser.d.ts +1 -0
  8. package/dist/AvoSchemaParser.js +16 -5
  9. package/dist/__tests__/TestAvoInspector.js +10 -0
  10. package/dist/__tests__/TestDeduplicator.js +5 -6
  11. package/dist/__tests__/TestNetworkCallsHandler.js +2 -2
  12. package/dist/__tests__/TestNetworkCallsHandlerPublic.js +125 -0
  13. package/dist/__tests__/TestParsing.js +23 -9
  14. package/dist/__tests__/constants.d.ts +6 -1
  15. package/dist/__tests__/constants.js +6 -1
  16. package/dist/utils.js +2 -2
  17. package/examples/node-inspector-js/yarn.lock +1 -1
  18. package/package.json +6 -6
  19. package/src/AvoInspector.ts +41 -20
  20. package/src/AvoNetworkCallsHandler.ts +2 -1
  21. package/src/AvoSchemaParser.ts +24 -7
  22. package/src/__tests__/TestAvoInspector.ts +20 -1
  23. package/src/__tests__/TestDeduplicator.ts +1 -3
  24. package/src/__tests__/TestNetworkCallsHandler.ts +2 -2
  25. package/src/__tests__/TestNetworkCallsHandlerPublic.ts +137 -0
  26. package/src/__tests__/TestParsing.ts +32 -9
  27. package/src/__tests__/constants.ts +6 -1
  28. package/dist/AvoBatcher.d.ts +0 -17
  29. package/dist/AvoBatcher.js +0 -31
  30. package/dist/__tests__/TestBatcher.js +0 -66
  31. package/dist/__tests__/TestBatcherPublic.d.ts +0 -1
  32. package/dist/__tests__/TestBatcherPublic.js +0 -60
  33. package/src/AvoBatcher.ts +0 -60
  34. package/src/__tests__/TestBatcher.ts +0 -67
  35. package/src/__tests__/TestBatcherPublic.ts +0 -96
  36. /package/dist/__tests__/{TestBatcher.d.ts → TestNetworkCallsHandlerPublic.d.ts} +0 -0
package/src/AvoBatcher.ts DELETED
@@ -1,60 +0,0 @@
1
- import { AvoNetworkCallsHandler } from "./AvoNetworkCallsHandler";
2
- import { AvoInspector } from "./AvoInspector";
3
- import { AvoGuid } from "./AvoGuid";
4
-
5
- export interface AvoBatcherType {
6
- handleTrackSchema(
7
- eventName: string,
8
- schema: Array<{
9
- propertyName: string;
10
- propertyType: string;
11
- children?: any;
12
- }>,
13
- eventId: string | null,
14
- eventHash: string | null
15
- ): Promise<void>;
16
- }
17
-
18
- export class AvoBatcher implements AvoBatcherType {
19
- private networkCallsHandler: AvoNetworkCallsHandler;
20
-
21
- constructor(networkCallsHandler: AvoNetworkCallsHandler) {
22
- this.networkCallsHandler = networkCallsHandler;
23
- }
24
-
25
- handleTrackSchema(
26
- eventName: string,
27
- schema: Array<{
28
- propertyName: string;
29
- propertyType: string;
30
- children?: any;
31
- }>,
32
- eventId: string | null,
33
- eventHash: string | null
34
- ): Promise<void> {
35
- const seeionId = AvoGuid.newGuid();
36
- return this.networkCallsHandler
37
- .callInspectorWithBatchBody([
38
- this.networkCallsHandler.bodyForSessionStartedCall(seeionId),
39
- ])
40
- .then(() => {
41
- if (AvoInspector.shouldLog) {
42
- console.log("Avo Inspector: schema sent successfully.");
43
- }
44
- this.networkCallsHandler.callInspectorWithBatchBody([
45
- this.networkCallsHandler.bodyForEventSchemaCall(
46
- seeionId,
47
- eventName,
48
- schema,
49
- eventId,
50
- eventHash
51
- ),
52
- ]);
53
- })
54
- .catch((err) => {
55
- if (AvoInspector.shouldLog) {
56
- console.log("Avo Inspector: schema sending failed: " + err + ".");
57
- }
58
- });
59
- }
60
- }
@@ -1,67 +0,0 @@
1
- import { AvoInspector } from "../AvoInspector";
2
- import { AvoNetworkCallsHandler } from "../AvoNetworkCallsHandler";
3
-
4
- import { defaultOptions } from "./constants";
5
-
6
- describe("Batcher", () => {
7
- let inspectorCallSpy: jest.SpyInstance<any, unknown[]>;
8
-
9
- const { apiKey, env, version, shouldLog, appName } = defaultOptions;
10
-
11
- beforeAll(() => {
12
- inspectorCallSpy = jest.spyOn(
13
- AvoNetworkCallsHandler.prototype as any,
14
- "callInspectorWithBatchBody"
15
- );
16
- });
17
-
18
- afterEach(() => {
19
- jest.clearAllMocks();
20
- });
21
-
22
- test("handleTrackSchema sends session to AvoNetworkCallsHandler and then sends event respecting sampling rate", async () => {
23
- const inspector = new AvoInspector(defaultOptions);
24
- inspector.enableLogging(false);
25
-
26
- inspectorCallSpy.mockImplementation(() => {
27
- inspector.avoBatcher["networkCallsHandler"]["samplingRate"] = 0.1;
28
- return Promise.resolve();
29
- });
30
-
31
- await inspector.avoBatcher.handleTrackSchema("event name", [], null, null);
32
-
33
- expect(inspectorCallSpy).toHaveBeenCalledTimes(2);
34
- expect(inspectorCallSpy).toHaveBeenCalledWith([
35
- expect.objectContaining({
36
- type: "sessionStarted",
37
- apiKey: apiKey,
38
- appName: appName,
39
- appVersion: version,
40
- libVersion: expect.anything(),
41
- env: env,
42
- libPlatform: "node",
43
- messageId: expect.anything(),
44
- trackingId: "",
45
- createdAt: expect.anything(),
46
- sessionId: expect.anything(),
47
- samplingRate: 1,
48
- }),
49
- ]);
50
- expect(inspectorCallSpy).toHaveBeenCalledWith([
51
- expect.objectContaining({
52
- type: "event",
53
- apiKey: apiKey,
54
- appName: appName,
55
- appVersion: version,
56
- libVersion: expect.anything(),
57
- env: env,
58
- libPlatform: "node",
59
- messageId: expect.anything(),
60
- trackingId: "",
61
- createdAt: expect.anything(),
62
- sessionId: expect.anything(),
63
- samplingRate: 0.1,
64
- }),
65
- ]);
66
- });
67
- });
@@ -1,96 +0,0 @@
1
- import { AvoBatcher } from "../AvoBatcher";
2
- import { AvoInspector } from "../AvoInspector";
3
- import { AvoNetworkCallsHandler } from "../AvoNetworkCallsHandler";
4
-
5
- import { defaultOptions } from "./constants";
6
-
7
- const inspectorVersion = process.env.npm_package_version || "";
8
-
9
- jest.mock("../AvoBatcher");
10
-
11
- describe("Batcher", () => {
12
- let inspector: AvoInspector;
13
-
14
- const { apiKey, env, version } = defaultOptions;
15
- let networkHandler = new AvoNetworkCallsHandler(
16
- apiKey,
17
- env,
18
- "my-test-app",
19
- version,
20
- inspectorVersion
21
- );
22
-
23
- beforeAll(() => {
24
- inspector = new AvoInspector(defaultOptions);
25
- inspector.enableLogging(false);
26
-
27
- jest
28
- .spyOn(AvoBatcher.prototype as any, "handleTrackSchema")
29
- .mockImplementation(() => {
30
- return Promise.resolve();
31
- });
32
- });
33
-
34
- afterEach(() => {
35
- jest.clearAllMocks();
36
- // @ts-ignore
37
- inspector.avoDeduplicator._clearEvents();
38
- });
39
-
40
- test("Batcher is initialized on Inspector init", () => {
41
- expect(AvoBatcher).toHaveBeenCalledTimes(1);
42
- expect(AvoBatcher).toHaveBeenCalledWith(networkHandler);
43
- });
44
-
45
- test("handleTrackSchema is called on trackSchemaFromEvent", () => {
46
- const eventName = "event name";
47
- const properties = {
48
- prop0: "",
49
- prop2: false,
50
- prop3: 0,
51
- prop4: 0.0,
52
- };
53
-
54
- const schema = inspector.extractSchema(properties);
55
-
56
- inspector.trackSchemaFromEvent(eventName, properties);
57
-
58
- expect(inspector.avoBatcher.handleTrackSchema).toHaveBeenCalledTimes(1);
59
- expect(inspector.avoBatcher.handleTrackSchema).toBeCalledWith(
60
- eventName,
61
- schema,
62
- null,
63
- null
64
- );
65
- });
66
-
67
- test("handleTrackSchema is called on _avoFunctionTrackSchemaFromEvent", () => {
68
- const eventName = "event name";
69
- const properties = {
70
- prop0: "",
71
- prop2: false,
72
- prop3: 0,
73
- prop4: 0.0,
74
- };
75
- const eventId = "testId";
76
- const eventHash = "testHash";
77
-
78
- const schema = inspector.extractSchema(properties);
79
-
80
- // @ts-ignore
81
- inspector._avoFunctionTrackSchemaFromEvent(
82
- eventName,
83
- properties,
84
- eventId,
85
- eventHash
86
- );
87
-
88
- expect(inspector.avoBatcher.handleTrackSchema).toHaveBeenCalledTimes(1);
89
- expect(inspector.avoBatcher.handleTrackSchema).toBeCalledWith(
90
- eventName,
91
- schema,
92
- eventId,
93
- eventHash
94
- );
95
- });
96
- });