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.
- package/README.md +14 -5
- package/dist/AvoDeduplicator.js +2 -2
- package/dist/AvoInspector.d.ts +2 -2
- package/dist/AvoInspector.js +34 -14
- package/dist/AvoInspectorEnv.d.ts +2 -2
- package/dist/AvoNetworkCallsHandler.js +2 -1
- package/dist/AvoSchemaParser.d.ts +1 -0
- package/dist/AvoSchemaParser.js +16 -5
- package/dist/__tests__/TestAvoInspector.js +10 -0
- package/dist/__tests__/TestDeduplicator.js +5 -6
- package/dist/__tests__/TestNetworkCallsHandler.js +2 -2
- package/dist/__tests__/TestNetworkCallsHandlerPublic.js +125 -0
- package/dist/__tests__/TestParsing.js +23 -9
- package/dist/__tests__/constants.d.ts +6 -1
- package/dist/__tests__/constants.js +6 -1
- package/dist/utils.js +2 -2
- package/examples/node-inspector-js/yarn.lock +1 -1
- package/package.json +6 -6
- package/src/AvoInspector.ts +41 -20
- package/src/AvoNetworkCallsHandler.ts +2 -1
- package/src/AvoSchemaParser.ts +24 -7
- package/src/__tests__/TestAvoInspector.ts +20 -1
- package/src/__tests__/TestDeduplicator.ts +1 -3
- package/src/__tests__/TestNetworkCallsHandler.ts +2 -2
- package/src/__tests__/TestNetworkCallsHandlerPublic.ts +137 -0
- package/src/__tests__/TestParsing.ts +32 -9
- package/src/__tests__/constants.ts +6 -1
- package/dist/AvoBatcher.d.ts +0 -17
- package/dist/AvoBatcher.js +0 -31
- package/dist/__tests__/TestBatcher.js +0 -66
- package/dist/__tests__/TestBatcherPublic.d.ts +0 -1
- package/dist/__tests__/TestBatcherPublic.js +0 -60
- package/src/AvoBatcher.ts +0 -60
- package/src/__tests__/TestBatcher.ts +0 -67
- package/src/__tests__/TestBatcherPublic.ts +0 -96
- /package/dist/__tests__/{TestBatcher.d.ts → TestNetworkCallsHandlerPublic.d.ts} +0 -0
package/src/AvoInspector.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { AvoInspectorEnv, AvoInspectorEnvValueType } from "./AvoInspectorEnv";
|
|
2
2
|
import { AvoSchemaParser } from "./AvoSchemaParser";
|
|
3
|
-
import { AvoBatcher } from "./AvoBatcher";
|
|
4
3
|
import { AvoNetworkCallsHandler } from "./AvoNetworkCallsHandler";
|
|
5
4
|
import { AvoDeduplicator } from "./AvoDeduplicator";
|
|
6
5
|
|
|
7
6
|
import { isValueEmpty } from "./utils";
|
|
7
|
+
import { AvoGuid } from "./AvoGuid";
|
|
8
8
|
|
|
9
9
|
const libVersion = require("../package.json").version;
|
|
10
10
|
|
|
11
11
|
export class AvoInspector {
|
|
12
12
|
environment: AvoInspectorEnvValueType;
|
|
13
|
-
|
|
13
|
+
avoNetworkCallsHandler: AvoNetworkCallsHandler;
|
|
14
14
|
avoDeduplicator: AvoDeduplicator;
|
|
15
15
|
apiKey: string;
|
|
16
16
|
version: string;
|
|
@@ -66,14 +66,13 @@ export class AvoInspector {
|
|
|
66
66
|
AvoInspector._shouldLog = false;
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
-
|
|
69
|
+
this.avoNetworkCallsHandler = new AvoNetworkCallsHandler(
|
|
70
70
|
this.apiKey,
|
|
71
71
|
this.environment.toString(),
|
|
72
72
|
options.appName || "",
|
|
73
73
|
this.version,
|
|
74
74
|
libVersion
|
|
75
75
|
);
|
|
76
|
-
this.avoBatcher = new AvoBatcher(avoNetworkCallsHandler);
|
|
77
76
|
this.avoDeduplicator = new AvoDeduplicator();
|
|
78
77
|
}
|
|
79
78
|
|
|
@@ -98,9 +97,9 @@ export class AvoInspector {
|
|
|
98
97
|
if (AvoInspector.shouldLog) {
|
|
99
98
|
console.log(
|
|
100
99
|
"Avo Inspector: supplied event " +
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
100
|
+
eventName +
|
|
101
|
+
" with params " +
|
|
102
|
+
JSON.stringify(eventProperties)
|
|
104
103
|
);
|
|
105
104
|
}
|
|
106
105
|
let eventSchema = this.extractSchema(eventProperties, false);
|
|
@@ -152,9 +151,9 @@ export class AvoInspector {
|
|
|
152
151
|
if (AvoInspector.shouldLog) {
|
|
153
152
|
console.log(
|
|
154
153
|
"Avo Inspector: supplied event " +
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
154
|
+
eventName +
|
|
155
|
+
" with params " +
|
|
156
|
+
JSON.stringify(eventProperties)
|
|
158
157
|
);
|
|
159
158
|
}
|
|
160
159
|
let eventSchema = this.extractSchema(eventProperties, false);
|
|
@@ -194,12 +193,34 @@ export class AvoInspector {
|
|
|
194
193
|
eventHash: string | null
|
|
195
194
|
): Promise<void> {
|
|
196
195
|
try {
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
196
|
+
const seesionId = AvoGuid.newGuid();
|
|
197
|
+
return this.avoNetworkCallsHandler
|
|
198
|
+
.callInspectorWithBatchBody([
|
|
199
|
+
this.avoNetworkCallsHandler.bodyForSessionStartedCall(seesionId),
|
|
200
|
+
])
|
|
201
|
+
.then(() => {
|
|
202
|
+
if (AvoInspector.shouldLog) {
|
|
203
|
+
console.log("Avo Inspector: session started sent successfully.");
|
|
204
|
+
}
|
|
205
|
+
this.avoNetworkCallsHandler.callInspectorWithBatchBody([
|
|
206
|
+
this.avoNetworkCallsHandler.bodyForEventSchemaCall(
|
|
207
|
+
seesionId,
|
|
208
|
+
eventName,
|
|
209
|
+
eventSchema,
|
|
210
|
+
eventId,
|
|
211
|
+
eventHash
|
|
212
|
+
),
|
|
213
|
+
]).then(() => {
|
|
214
|
+
if (AvoInspector.shouldLog) {
|
|
215
|
+
console.log("Avo Inspector: schema sent successfully.");
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
})
|
|
219
|
+
.catch((err) => {
|
|
220
|
+
if (AvoInspector.shouldLog) {
|
|
221
|
+
console.log("Avo Inspector: schema sending failed: " + err + ".");
|
|
222
|
+
}
|
|
223
|
+
});
|
|
203
224
|
} catch (e) {
|
|
204
225
|
console.error(
|
|
205
226
|
"Avo Inspector: something went wrong. Please report to support@avo.app.",
|
|
@@ -227,9 +248,9 @@ export class AvoInspector {
|
|
|
227
248
|
if (this.avoDeduplicator.hasSeenEventParams(eventProperties, true)) {
|
|
228
249
|
if (shouldLogIfEnabled && AvoInspector.shouldLog) {
|
|
229
250
|
console.warn(
|
|
230
|
-
"Avo Inspector: WARNING! You are trying to extract schema shape that was just reported by your
|
|
231
|
-
|
|
232
|
-
|
|
251
|
+
"Avo Inspector: WARNING! You are trying to extract schema shape that was just reported by your Codegen. " +
|
|
252
|
+
"This is an indicator of duplicate inspector reporting. " +
|
|
253
|
+
"Please reach out to support@avo.app for advice if you are not sure how to handle this."
|
|
233
254
|
);
|
|
234
255
|
}
|
|
235
256
|
}
|
|
@@ -237,7 +258,7 @@ export class AvoInspector {
|
|
|
237
258
|
if (AvoInspector.shouldLog) {
|
|
238
259
|
console.log(
|
|
239
260
|
"Avo Inspector: extracting schema from " +
|
|
240
|
-
|
|
261
|
+
JSON.stringify(eventProperties)
|
|
241
262
|
);
|
|
242
263
|
}
|
|
243
264
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { AvoGuid } from "./AvoGuid";
|
|
2
2
|
import { AvoInspector } from "./AvoInspector";
|
|
3
|
+
import { request } from "https";
|
|
3
4
|
|
|
4
5
|
export interface BaseBody {
|
|
5
6
|
apiKey: string;
|
|
@@ -102,7 +103,7 @@ export class AvoNetworkCallsHandler {
|
|
|
102
103
|
"Content-Length": Buffer.byteLength(data),
|
|
103
104
|
},
|
|
104
105
|
};
|
|
105
|
-
var req =
|
|
106
|
+
var req = request(options, (res: any) => {
|
|
106
107
|
const chunks: any = [];
|
|
107
108
|
res.on("data", (data: any) => chunks.push(data));
|
|
108
109
|
res.on("end", () => {
|
package/src/AvoSchemaParser.ts
CHANGED
|
@@ -71,7 +71,8 @@ export class AvoSchemaParser {
|
|
|
71
71
|
});
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
-
|
|
74
|
+
|
|
75
|
+
private static getBasicPropType(propValue: any): string {
|
|
75
76
|
let propType = typeof propValue;
|
|
76
77
|
if (propValue == null) {
|
|
77
78
|
return "null";
|
|
@@ -86,13 +87,29 @@ export class AvoSchemaParser {
|
|
|
86
87
|
} else if (propType === "boolean") {
|
|
87
88
|
return "boolean";
|
|
88
89
|
} else if (propType === "object") {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
90
|
+
return "object"
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
return "unknown";
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
private static getPropValueType(propValue: any): string {
|
|
98
|
+
if (isArray(propValue)){
|
|
99
|
+
|
|
100
|
+
//we now know that propValue is an array. get first element in propValue array
|
|
101
|
+
let propElement = propValue[0];
|
|
102
|
+
|
|
103
|
+
if (propElement == null) {
|
|
104
|
+
return "list(string)"; // Default to list(string) if the list is empty.
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
let propElementType = this.getBasicPropType(propElement);
|
|
108
|
+
return `list(${propElementType})`
|
|
93
109
|
}
|
|
94
|
-
}
|
|
95
|
-
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
return this.getBasicPropType(propValue);
|
|
96
113
|
}
|
|
97
114
|
}
|
|
98
115
|
}
|
|
@@ -1,9 +1,28 @@
|
|
|
1
1
|
import { AvoInspector } from "../AvoInspector";
|
|
2
2
|
import { AvoInspectorEnv } from "../AvoInspectorEnv";
|
|
3
3
|
|
|
4
|
-
import { error } from "./constants";
|
|
4
|
+
import { error, defaultOptions } from "./constants";
|
|
5
|
+
import { AvoNetworkCallsHandler } from "../AvoNetworkCallsHandler";
|
|
6
|
+
|
|
7
|
+
jest.mock("../AvoNetworkCallsHandler");
|
|
5
8
|
|
|
6
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
|
+
});
|
|
25
|
+
|
|
7
26
|
test("Api Key is set", () => {
|
|
8
27
|
// Given
|
|
9
28
|
const apiKey = "api-key-xxx";
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { AvoDeduplicator } from "../AvoDeduplicator";
|
|
2
2
|
import { deepEquals } from "../utils";
|
|
3
|
-
import { AvoSchemaParser } from "../AvoSchemaParser";
|
|
4
3
|
import { AvoInspector } from "../AvoInspector";
|
|
5
4
|
import { defaultOptions } from "./constants";
|
|
6
5
|
|
|
@@ -91,8 +90,7 @@ describe("Deduplicator", () => {
|
|
|
91
90
|
);
|
|
92
91
|
|
|
93
92
|
expect(manuallyTrackedSchema.length).toBe(4);
|
|
94
|
-
expect(avoTrackedSchema.length).toBe(
|
|
95
|
-
expect(manuallyTrackedSchemaAgain.length).toBe(4);
|
|
93
|
+
expect(manuallyTrackedSchema.length + avoTrackedSchema.length + manuallyTrackedSchemaAgain.length).toBe(8);
|
|
96
94
|
});
|
|
97
95
|
|
|
98
96
|
test(`Inspector deduplicates only one event when track in avo, manually and then in avo again`, async () => {
|
|
@@ -64,7 +64,7 @@ describe("NetworkCallsHandler", () => {
|
|
|
64
64
|
});
|
|
65
65
|
});
|
|
66
66
|
|
|
67
|
-
test("bodyForEventSchemaCall returns base body + event schema used for event sending from non
|
|
67
|
+
test("bodyForEventSchemaCall returns base body + event schema used for event sending from non Codegen", () => {
|
|
68
68
|
const eventName = "event name";
|
|
69
69
|
const eventProperties = [{ propertyName: "prop0", propertyType: "string" }];
|
|
70
70
|
|
|
@@ -87,7 +87,7 @@ describe("NetworkCallsHandler", () => {
|
|
|
87
87
|
});
|
|
88
88
|
});
|
|
89
89
|
|
|
90
|
-
test("bodyForEventSchemaCall returns base body + event schema used for event sending from
|
|
90
|
+
test("bodyForEventSchemaCall returns base body + event schema used for event sending from Codegen", () => {
|
|
91
91
|
const eventName = "event name";
|
|
92
92
|
const eventId = "event id";
|
|
93
93
|
const eventHash = "event hash";
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { AvoInspector } from "../AvoInspector";
|
|
2
|
+
import { AvoNetworkCallsHandler } from "../AvoNetworkCallsHandler";
|
|
3
|
+
|
|
4
|
+
import { defaultOptions } from "./constants";
|
|
5
|
+
|
|
6
|
+
describe("AvoNetworkCallsHandler", () => {
|
|
7
|
+
let inspectorCallSpy: jest.SpyInstance<any, unknown[]>;
|
|
8
|
+
|
|
9
|
+
let inspector: AvoInspector;
|
|
10
|
+
|
|
11
|
+
const { apiKey, env, version, appName } = defaultOptions;
|
|
12
|
+
|
|
13
|
+
beforeAll(() => {
|
|
14
|
+
inspector = new AvoInspector(defaultOptions);
|
|
15
|
+
inspector.enableLogging(false);
|
|
16
|
+
|
|
17
|
+
inspectorCallSpy = jest
|
|
18
|
+
.spyOn(AvoNetworkCallsHandler.prototype as any, "callInspectorWithBatchBody");
|
|
19
|
+
|
|
20
|
+
inspectorCallSpy.mockImplementation(() => {
|
|
21
|
+
inspector.avoNetworkCallsHandler["samplingRate"] = 0.1;
|
|
22
|
+
return Promise.resolve();
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
afterEach(() => {
|
|
27
|
+
jest.clearAllMocks();
|
|
28
|
+
// @ts-ignore
|
|
29
|
+
inspector.avoDeduplicator._clearEvents();
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
test("handleTrackSchema is called on trackSchemaFromEvent", async () => {
|
|
33
|
+
const eventName = "event name";
|
|
34
|
+
const properties = {
|
|
35
|
+
prop0: "",
|
|
36
|
+
prop2: false,
|
|
37
|
+
prop3: 0,
|
|
38
|
+
prop4: 0.0,
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const schema = inspector.extractSchema(properties);
|
|
42
|
+
|
|
43
|
+
await inspector.trackSchemaFromEvent(eventName, properties);
|
|
44
|
+
|
|
45
|
+
expect(inspector.avoNetworkCallsHandler.callInspectorWithBatchBody).toHaveBeenCalledTimes(2);
|
|
46
|
+
expect(inspector.avoNetworkCallsHandler.callInspectorWithBatchBody).toBeCalledWith([
|
|
47
|
+
expect.objectContaining({
|
|
48
|
+
type: "sessionStarted",
|
|
49
|
+
apiKey: apiKey,
|
|
50
|
+
appName: appName,
|
|
51
|
+
appVersion: version,
|
|
52
|
+
libVersion: expect.anything(),
|
|
53
|
+
env: env,
|
|
54
|
+
libPlatform: "node",
|
|
55
|
+
messageId: expect.anything(),
|
|
56
|
+
trackingId: "",
|
|
57
|
+
createdAt: expect.any(String),
|
|
58
|
+
sessionId: expect.anything(),
|
|
59
|
+
samplingRate: 1,
|
|
60
|
+
}),
|
|
61
|
+
]
|
|
62
|
+
);
|
|
63
|
+
expect(inspector.avoNetworkCallsHandler.callInspectorWithBatchBody).toHaveBeenCalledWith([
|
|
64
|
+
expect.objectContaining({
|
|
65
|
+
type: "event",
|
|
66
|
+
apiKey: apiKey,
|
|
67
|
+
appName: appName,
|
|
68
|
+
appVersion: version,
|
|
69
|
+
libVersion: expect.anything(),
|
|
70
|
+
env: env,
|
|
71
|
+
libPlatform: "node",
|
|
72
|
+
messageId: expect.anything(),
|
|
73
|
+
trackingId: "",
|
|
74
|
+
createdAt: expect.anything(),
|
|
75
|
+
sessionId: expect.anything(),
|
|
76
|
+
samplingRate: 0.1,
|
|
77
|
+
}),
|
|
78
|
+
]);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
test("handleTrackSchema is called on _avoFunctionTrackSchemaFromEvent", async () => {
|
|
82
|
+
const eventName = "event name";
|
|
83
|
+
const properties = {
|
|
84
|
+
prop0: "",
|
|
85
|
+
prop2: false,
|
|
86
|
+
prop3: 0,
|
|
87
|
+
prop4: 0.0,
|
|
88
|
+
};
|
|
89
|
+
const eventId = "testId";
|
|
90
|
+
const eventHash = "testHash";
|
|
91
|
+
|
|
92
|
+
const schema = inspector.extractSchema(properties);
|
|
93
|
+
|
|
94
|
+
// @ts-ignore
|
|
95
|
+
await inspector._avoFunctionTrackSchemaFromEvent(
|
|
96
|
+
eventName,
|
|
97
|
+
properties,
|
|
98
|
+
eventId,
|
|
99
|
+
eventHash
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
expect(inspector.avoNetworkCallsHandler.callInspectorWithBatchBody).toHaveBeenCalledTimes(2);
|
|
103
|
+
expect(inspector.avoNetworkCallsHandler.callInspectorWithBatchBody).toBeCalledWith([
|
|
104
|
+
expect.objectContaining({
|
|
105
|
+
type: "sessionStarted",
|
|
106
|
+
apiKey: apiKey,
|
|
107
|
+
appName: appName,
|
|
108
|
+
appVersion: version,
|
|
109
|
+
libVersion: expect.anything(),
|
|
110
|
+
env: env,
|
|
111
|
+
libPlatform: "node",
|
|
112
|
+
messageId: expect.anything(),
|
|
113
|
+
trackingId: "",
|
|
114
|
+
createdAt: expect.anything(),
|
|
115
|
+
sessionId: expect.anything(),
|
|
116
|
+
samplingRate: 0.1,
|
|
117
|
+
})
|
|
118
|
+
]
|
|
119
|
+
);
|
|
120
|
+
expect(inspector.avoNetworkCallsHandler.callInspectorWithBatchBody).toHaveBeenCalledWith([
|
|
121
|
+
expect.objectContaining({
|
|
122
|
+
type: "event",
|
|
123
|
+
apiKey: apiKey,
|
|
124
|
+
appName: appName,
|
|
125
|
+
appVersion: version,
|
|
126
|
+
libVersion: expect.anything(),
|
|
127
|
+
env: env,
|
|
128
|
+
libPlatform: "node",
|
|
129
|
+
messageId: expect.anything(),
|
|
130
|
+
trackingId: "",
|
|
131
|
+
createdAt: expect.anything(),
|
|
132
|
+
sessionId: expect.anything(),
|
|
133
|
+
samplingRate: 0.1,
|
|
134
|
+
}),
|
|
135
|
+
]);
|
|
136
|
+
});
|
|
137
|
+
});
|
|
@@ -60,7 +60,7 @@ describe("Schema Parsing", () => {
|
|
|
60
60
|
},
|
|
61
61
|
]);
|
|
62
62
|
|
|
63
|
-
expect(res[7].propertyType).toBe(type.
|
|
63
|
+
expect(res[7].propertyType).toBe(type.STRINGLIST);
|
|
64
64
|
expect(res[7].children).toMatchObject([
|
|
65
65
|
type.STRING,
|
|
66
66
|
[
|
|
@@ -88,13 +88,7 @@ describe("Schema Parsing", () => {
|
|
|
88
88
|
const res = inspector.extractSchema(eventProperties);
|
|
89
89
|
|
|
90
90
|
// Then
|
|
91
|
-
expect(res[0].propertyType).toBe(type.
|
|
92
|
-
expect(res[0].children).toMatchObject([
|
|
93
|
-
type.STRING,
|
|
94
|
-
type.BOOL,
|
|
95
|
-
type.INT,
|
|
96
|
-
type.FLOAT,
|
|
97
|
-
]);
|
|
91
|
+
expect(res[0].propertyType).toBe(type.STRINGLIST);
|
|
98
92
|
});
|
|
99
93
|
|
|
100
94
|
test("Empty and falsy values are set correctly", () => {
|
|
@@ -124,7 +118,36 @@ describe("Schema Parsing", () => {
|
|
|
124
118
|
expect(res[6].propertyType).toBe(type.OBJECT);
|
|
125
119
|
expect(res[6].children).toMatchObject([]);
|
|
126
120
|
|
|
127
|
-
expect(res[7].propertyType).toBe(type.
|
|
121
|
+
expect(res[7].propertyType).toBe(type.STRINGLIST);
|
|
128
122
|
expect(res[7].children).toMatchObject([]);
|
|
129
123
|
});
|
|
124
|
+
|
|
125
|
+
test("List of string returns list(string)", () => {
|
|
126
|
+
// Given
|
|
127
|
+
const eventProperties = {
|
|
128
|
+
prop0: ["a", "b", "c"],
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
// When
|
|
132
|
+
const res = inspector.extractSchema(eventProperties);
|
|
133
|
+
|
|
134
|
+
// Then
|
|
135
|
+
expect(res[0].propertyType).toBe(type.STRINGLIST);
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
test("List of multiple types returns list(`firstType`)", () => {
|
|
140
|
+
// Given
|
|
141
|
+
const eventProperties = {
|
|
142
|
+
prop0: [1.2, "two", {"three": 3}],
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
// When
|
|
146
|
+
const res = inspector.extractSchema(eventProperties);
|
|
147
|
+
|
|
148
|
+
// Then
|
|
149
|
+
expect(res[0].propertyType).toBe(type.FLOATLIST);
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
|
|
130
153
|
});
|
|
@@ -37,13 +37,18 @@ const sessionTimeMs = 5 * 60 * 1000;
|
|
|
37
37
|
|
|
38
38
|
const type = {
|
|
39
39
|
STRING: "string",
|
|
40
|
+
STRINGLIST: "list(string)",
|
|
40
41
|
INT: "int",
|
|
42
|
+
INTLIST: "list(int)",
|
|
41
43
|
OBJECT: "object",
|
|
44
|
+
OBJECTLIST: "list(object)",
|
|
42
45
|
FLOAT: "float",
|
|
43
|
-
|
|
46
|
+
FLOATLIST: "list(float)",
|
|
44
47
|
BOOL: "boolean",
|
|
48
|
+
BOOLLIST: "list(boolean)",
|
|
45
49
|
NULL: "null",
|
|
46
50
|
UNKNOWN: "unknown",
|
|
51
|
+
UNKNOWNLIST: "list(unknown)",
|
|
47
52
|
};
|
|
48
53
|
|
|
49
54
|
export {
|
package/dist/AvoBatcher.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { AvoNetworkCallsHandler } from "./AvoNetworkCallsHandler";
|
|
2
|
-
export interface AvoBatcherType {
|
|
3
|
-
handleTrackSchema(eventName: string, schema: Array<{
|
|
4
|
-
propertyName: string;
|
|
5
|
-
propertyType: string;
|
|
6
|
-
children?: any;
|
|
7
|
-
}>, eventId: string | null, eventHash: string | null): Promise<void>;
|
|
8
|
-
}
|
|
9
|
-
export declare class AvoBatcher implements AvoBatcherType {
|
|
10
|
-
private networkCallsHandler;
|
|
11
|
-
constructor(networkCallsHandler: AvoNetworkCallsHandler);
|
|
12
|
-
handleTrackSchema(eventName: string, schema: Array<{
|
|
13
|
-
propertyName: string;
|
|
14
|
-
propertyType: string;
|
|
15
|
-
children?: any;
|
|
16
|
-
}>, eventId: string | null, eventHash: string | null): Promise<void>;
|
|
17
|
-
}
|
package/dist/AvoBatcher.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AvoBatcher = void 0;
|
|
4
|
-
const AvoInspector_1 = require("./AvoInspector");
|
|
5
|
-
const AvoGuid_1 = require("./AvoGuid");
|
|
6
|
-
class AvoBatcher {
|
|
7
|
-
constructor(networkCallsHandler) {
|
|
8
|
-
this.networkCallsHandler = networkCallsHandler;
|
|
9
|
-
}
|
|
10
|
-
handleTrackSchema(eventName, schema, eventId, eventHash) {
|
|
11
|
-
const seeionId = AvoGuid_1.AvoGuid.newGuid();
|
|
12
|
-
return this.networkCallsHandler
|
|
13
|
-
.callInspectorWithBatchBody([
|
|
14
|
-
this.networkCallsHandler.bodyForSessionStartedCall(seeionId),
|
|
15
|
-
])
|
|
16
|
-
.then(() => {
|
|
17
|
-
if (AvoInspector_1.AvoInspector.shouldLog) {
|
|
18
|
-
console.log("Avo Inspector: schema sent successfully.");
|
|
19
|
-
}
|
|
20
|
-
this.networkCallsHandler.callInspectorWithBatchBody([
|
|
21
|
-
this.networkCallsHandler.bodyForEventSchemaCall(seeionId, eventName, schema, eventId, eventHash),
|
|
22
|
-
]);
|
|
23
|
-
})
|
|
24
|
-
.catch((err) => {
|
|
25
|
-
if (AvoInspector_1.AvoInspector.shouldLog) {
|
|
26
|
-
console.log("Avo Inspector: schema sending failed: " + err + ".");
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
exports.AvoBatcher = AvoBatcher;
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
const AvoInspector_1 = require("../AvoInspector");
|
|
13
|
-
const AvoNetworkCallsHandler_1 = require("../AvoNetworkCallsHandler");
|
|
14
|
-
const constants_1 = require("./constants");
|
|
15
|
-
describe("Batcher", () => {
|
|
16
|
-
let inspectorCallSpy;
|
|
17
|
-
const { apiKey, env, version, shouldLog, appName } = constants_1.defaultOptions;
|
|
18
|
-
beforeAll(() => {
|
|
19
|
-
inspectorCallSpy = jest.spyOn(AvoNetworkCallsHandler_1.AvoNetworkCallsHandler.prototype, "callInspectorWithBatchBody");
|
|
20
|
-
});
|
|
21
|
-
afterEach(() => {
|
|
22
|
-
jest.clearAllMocks();
|
|
23
|
-
});
|
|
24
|
-
test("handleTrackSchema sends session to AvoNetworkCallsHandler and then sends event respecting sampling rate", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
25
|
-
const inspector = new AvoInspector_1.AvoInspector(constants_1.defaultOptions);
|
|
26
|
-
inspector.enableLogging(false);
|
|
27
|
-
inspectorCallSpy.mockImplementation(() => {
|
|
28
|
-
inspector.avoBatcher["networkCallsHandler"]["samplingRate"] = 0.1;
|
|
29
|
-
return Promise.resolve();
|
|
30
|
-
});
|
|
31
|
-
yield inspector.avoBatcher.handleTrackSchema("event name", [], null, null);
|
|
32
|
-
expect(inspectorCallSpy).toHaveBeenCalledTimes(2);
|
|
33
|
-
expect(inspectorCallSpy).toHaveBeenCalledWith([
|
|
34
|
-
expect.objectContaining({
|
|
35
|
-
type: "sessionStarted",
|
|
36
|
-
apiKey: apiKey,
|
|
37
|
-
appName: appName,
|
|
38
|
-
appVersion: version,
|
|
39
|
-
libVersion: expect.anything(),
|
|
40
|
-
env: env,
|
|
41
|
-
libPlatform: "node",
|
|
42
|
-
messageId: expect.anything(),
|
|
43
|
-
trackingId: "",
|
|
44
|
-
createdAt: expect.anything(),
|
|
45
|
-
sessionId: expect.anything(),
|
|
46
|
-
samplingRate: 1,
|
|
47
|
-
}),
|
|
48
|
-
]);
|
|
49
|
-
expect(inspectorCallSpy).toHaveBeenCalledWith([
|
|
50
|
-
expect.objectContaining({
|
|
51
|
-
type: "event",
|
|
52
|
-
apiKey: apiKey,
|
|
53
|
-
appName: appName,
|
|
54
|
-
appVersion: version,
|
|
55
|
-
libVersion: expect.anything(),
|
|
56
|
-
env: env,
|
|
57
|
-
libPlatform: "node",
|
|
58
|
-
messageId: expect.anything(),
|
|
59
|
-
trackingId: "",
|
|
60
|
-
createdAt: expect.anything(),
|
|
61
|
-
sessionId: expect.anything(),
|
|
62
|
-
samplingRate: 0.1,
|
|
63
|
-
}),
|
|
64
|
-
]);
|
|
65
|
-
}));
|
|
66
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const AvoBatcher_1 = require("../AvoBatcher");
|
|
4
|
-
const AvoInspector_1 = require("../AvoInspector");
|
|
5
|
-
const AvoNetworkCallsHandler_1 = require("../AvoNetworkCallsHandler");
|
|
6
|
-
const constants_1 = require("./constants");
|
|
7
|
-
const inspectorVersion = process.env.npm_package_version || "";
|
|
8
|
-
jest.mock("../AvoBatcher");
|
|
9
|
-
describe("Batcher", () => {
|
|
10
|
-
let inspector;
|
|
11
|
-
const { apiKey, env, version } = constants_1.defaultOptions;
|
|
12
|
-
let networkHandler = new AvoNetworkCallsHandler_1.AvoNetworkCallsHandler(apiKey, env, "my-test-app", version, inspectorVersion);
|
|
13
|
-
beforeAll(() => {
|
|
14
|
-
inspector = new AvoInspector_1.AvoInspector(constants_1.defaultOptions);
|
|
15
|
-
inspector.enableLogging(false);
|
|
16
|
-
jest
|
|
17
|
-
.spyOn(AvoBatcher_1.AvoBatcher.prototype, "handleTrackSchema")
|
|
18
|
-
.mockImplementation(() => {
|
|
19
|
-
return Promise.resolve();
|
|
20
|
-
});
|
|
21
|
-
});
|
|
22
|
-
afterEach(() => {
|
|
23
|
-
jest.clearAllMocks();
|
|
24
|
-
// @ts-ignore
|
|
25
|
-
inspector.avoDeduplicator._clearEvents();
|
|
26
|
-
});
|
|
27
|
-
test("Batcher is initialized on Inspector init", () => {
|
|
28
|
-
expect(AvoBatcher_1.AvoBatcher).toHaveBeenCalledTimes(1);
|
|
29
|
-
expect(AvoBatcher_1.AvoBatcher).toHaveBeenCalledWith(networkHandler);
|
|
30
|
-
});
|
|
31
|
-
test("handleTrackSchema is called on trackSchemaFromEvent", () => {
|
|
32
|
-
const eventName = "event name";
|
|
33
|
-
const properties = {
|
|
34
|
-
prop0: "",
|
|
35
|
-
prop2: false,
|
|
36
|
-
prop3: 0,
|
|
37
|
-
prop4: 0.0,
|
|
38
|
-
};
|
|
39
|
-
const schema = inspector.extractSchema(properties);
|
|
40
|
-
inspector.trackSchemaFromEvent(eventName, properties);
|
|
41
|
-
expect(inspector.avoBatcher.handleTrackSchema).toHaveBeenCalledTimes(1);
|
|
42
|
-
expect(inspector.avoBatcher.handleTrackSchema).toBeCalledWith(eventName, schema, null, null);
|
|
43
|
-
});
|
|
44
|
-
test("handleTrackSchema is called on _avoFunctionTrackSchemaFromEvent", () => {
|
|
45
|
-
const eventName = "event name";
|
|
46
|
-
const properties = {
|
|
47
|
-
prop0: "",
|
|
48
|
-
prop2: false,
|
|
49
|
-
prop3: 0,
|
|
50
|
-
prop4: 0.0,
|
|
51
|
-
};
|
|
52
|
-
const eventId = "testId";
|
|
53
|
-
const eventHash = "testHash";
|
|
54
|
-
const schema = inspector.extractSchema(properties);
|
|
55
|
-
// @ts-ignore
|
|
56
|
-
inspector._avoFunctionTrackSchemaFromEvent(eventName, properties, eventId, eventHash);
|
|
57
|
-
expect(inspector.avoBatcher.handleTrackSchema).toHaveBeenCalledTimes(1);
|
|
58
|
-
expect(inspector.avoBatcher.handleTrackSchema).toBeCalledWith(eventName, schema, eventId, eventHash);
|
|
59
|
-
});
|
|
60
|
-
});
|