node-avo-inspector 1.0.3-beta.0 → 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/dist/AvoDeduplicator.js +2 -2
- package/dist/AvoInspector.js +9 -9
- package/dist/AvoInspectorEnv.d.ts +2 -2
- package/dist/AvoNetworkCallsHandler.js +1 -1
- package/dist/AvoSchemaParser.d.ts +1 -0
- package/dist/AvoSchemaParser.js +16 -5
- package/dist/__tests__/TestDeduplicator.js +4 -4
- 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/AvoSchemaParser.ts +24 -7
- package/src/__tests__/TestParsing.ts +32 -9
- package/src/__tests__/constants.ts +6 -1
package/dist/AvoDeduplicator.js
CHANGED
|
@@ -46,7 +46,7 @@ class AvoDeduplicator {
|
|
|
46
46
|
if (eventsStorage.hasOwnProperty(otherEventName)) {
|
|
47
47
|
if (otherEventName === eventName) {
|
|
48
48
|
const otherParams = eventsStorage[eventName];
|
|
49
|
-
if (otherParams && utils_1.deepEquals(params, otherParams)) {
|
|
49
|
+
if (otherParams && (0, utils_1.deepEquals)(params, otherParams)) {
|
|
50
50
|
return true;
|
|
51
51
|
}
|
|
52
52
|
}
|
|
@@ -72,7 +72,7 @@ class AvoDeduplicator {
|
|
|
72
72
|
for (const otherEventName in eventsStorage) {
|
|
73
73
|
if (eventsStorage.hasOwnProperty(otherEventName)) {
|
|
74
74
|
const otherParams = eventsStorage[otherEventName];
|
|
75
|
-
if (otherParams && utils_1.deepEquals(params, otherParams)) {
|
|
75
|
+
if (otherParams && (0, utils_1.deepEquals)(params, otherParams)) {
|
|
76
76
|
return true;
|
|
77
77
|
}
|
|
78
78
|
}
|
package/dist/AvoInspector.js
CHANGED
|
@@ -9,9 +9,15 @@ const utils_1 = require("./utils");
|
|
|
9
9
|
const AvoGuid_1 = require("./AvoGuid");
|
|
10
10
|
const libVersion = require("../package.json").version;
|
|
11
11
|
class AvoInspector {
|
|
12
|
+
static get shouldLog() {
|
|
13
|
+
return this._shouldLog;
|
|
14
|
+
}
|
|
15
|
+
static set shouldLog(enable) {
|
|
16
|
+
this._shouldLog = enable;
|
|
17
|
+
}
|
|
12
18
|
constructor(options) {
|
|
13
19
|
// the constructor does aggressive null/undefined checking because same code paths will be accessible from JS
|
|
14
|
-
if (utils_1.isValueEmpty(options.env)) {
|
|
20
|
+
if ((0, utils_1.isValueEmpty)(options.env)) {
|
|
15
21
|
this.environment = AvoInspectorEnv_1.AvoInspectorEnv.Dev;
|
|
16
22
|
console.warn("[Avo Inspector] No environment provided. Defaulting to dev.");
|
|
17
23
|
}
|
|
@@ -22,13 +28,13 @@ class AvoInspector {
|
|
|
22
28
|
else {
|
|
23
29
|
this.environment = options.env;
|
|
24
30
|
}
|
|
25
|
-
if (utils_1.isValueEmpty(options.apiKey)) {
|
|
31
|
+
if ((0, utils_1.isValueEmpty)(options.apiKey)) {
|
|
26
32
|
throw new Error("[Avo Inspector] No API key provided. Inspector can't operate without API key.");
|
|
27
33
|
}
|
|
28
34
|
else {
|
|
29
35
|
this.apiKey = options.apiKey;
|
|
30
36
|
}
|
|
31
|
-
if (utils_1.isValueEmpty(options.version)) {
|
|
37
|
+
if ((0, utils_1.isValueEmpty)(options.version)) {
|
|
32
38
|
throw new Error("[Avo Inspector] No version provided. Many features of Inspector rely on versioning. Please provide comparable string version, i.e. integer or semantic.");
|
|
33
39
|
}
|
|
34
40
|
else {
|
|
@@ -43,12 +49,6 @@ class AvoInspector {
|
|
|
43
49
|
this.avoNetworkCallsHandler = new AvoNetworkCallsHandler_1.AvoNetworkCallsHandler(this.apiKey, this.environment.toString(), options.appName || "", this.version, libVersion);
|
|
44
50
|
this.avoDeduplicator = new AvoDeduplicator_1.AvoDeduplicator();
|
|
45
51
|
}
|
|
46
|
-
static get shouldLog() {
|
|
47
|
-
return this._shouldLog;
|
|
48
|
-
}
|
|
49
|
-
static set shouldLog(enable) {
|
|
50
|
-
this._shouldLog = enable;
|
|
51
|
-
}
|
|
52
52
|
trackSchemaFromEvent(eventName, eventProperties) {
|
|
53
53
|
try {
|
|
54
54
|
if (this.avoDeduplicator.shouldRegisterEvent(eventName, eventProperties, false)) {
|
|
@@ -3,5 +3,5 @@ export declare const AvoInspectorEnv: {
|
|
|
3
3
|
readonly Dev: "dev";
|
|
4
4
|
readonly Staging: "staging";
|
|
5
5
|
};
|
|
6
|
-
export
|
|
7
|
-
export
|
|
6
|
+
export type AvoInspectorEnvType = typeof AvoInspectorEnv;
|
|
7
|
+
export type AvoInspectorEnvValueType = AvoInspectorEnvType[keyof AvoInspectorEnvType];
|
|
@@ -50,7 +50,7 @@ class AvoNetworkCallsHandler {
|
|
|
50
50
|
"Content-Length": Buffer.byteLength(data),
|
|
51
51
|
},
|
|
52
52
|
};
|
|
53
|
-
var req = https_1.request(options, (res) => {
|
|
53
|
+
var req = (0, https_1.request)(options, (res) => {
|
|
54
54
|
const chunks = [];
|
|
55
55
|
res.on("data", (data) => chunks.push(data));
|
|
56
56
|
res.on("end", () => {
|
package/dist/AvoSchemaParser.js
CHANGED
|
@@ -56,7 +56,7 @@ class AvoSchemaParser {
|
|
|
56
56
|
}
|
|
57
57
|
});
|
|
58
58
|
}
|
|
59
|
-
static
|
|
59
|
+
static getBasicPropType(propValue) {
|
|
60
60
|
let propType = typeof propValue;
|
|
61
61
|
if (propValue == null) {
|
|
62
62
|
return "null";
|
|
@@ -76,15 +76,26 @@ class AvoSchemaParser {
|
|
|
76
76
|
return "boolean";
|
|
77
77
|
}
|
|
78
78
|
else if (propType === "object") {
|
|
79
|
-
|
|
80
|
-
|
|
79
|
+
return "object";
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
return "unknown";
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
static getPropValueType(propValue) {
|
|
86
|
+
if (isArray(propValue)) {
|
|
87
|
+
//we now know that propValue is an array. get first element in propValue array
|
|
88
|
+
let propElement = propValue[0];
|
|
89
|
+
if (propElement == null) {
|
|
90
|
+
return "list(string)"; // Default to list(string) if the list is empty.
|
|
81
91
|
}
|
|
82
92
|
else {
|
|
83
|
-
|
|
93
|
+
let propElementType = this.getBasicPropType(propElement);
|
|
94
|
+
return `list(${propElementType})`;
|
|
84
95
|
}
|
|
85
96
|
}
|
|
86
97
|
else {
|
|
87
|
-
return
|
|
98
|
+
return this.getBasicPropType(propValue);
|
|
88
99
|
}
|
|
89
100
|
}
|
|
90
101
|
}
|
|
@@ -28,10 +28,10 @@ describe("Deduplicator", () => {
|
|
|
28
28
|
2: [["str", true]],
|
|
29
29
|
3: { avo: [1.1, 2.2, 3.3] },
|
|
30
30
|
};
|
|
31
|
-
expect(utils_1.deepEquals(testObject, secondObject)).toBe(true);
|
|
32
|
-
expect(utils_1.deepEquals(testObject, Object.assign(Object.assign({}, secondObject), { "4": "4" }))).toBe(false);
|
|
33
|
-
expect(utils_1.deepEquals(testObject, Object.assign(Object.assign({}, secondObject), { 3: Object.assign(Object.assign({}, secondObject[3]), { avo: [1.1] }) }))).toBe(false);
|
|
34
|
-
expect(utils_1.deepEquals(testObject, Object.assign(Object.assign({}, secondObject), { 0: "other string" }))).toBe(false);
|
|
31
|
+
expect((0, utils_1.deepEquals)(testObject, secondObject)).toBe(true);
|
|
32
|
+
expect((0, utils_1.deepEquals)(testObject, Object.assign(Object.assign({}, secondObject), { "4": "4" }))).toBe(false);
|
|
33
|
+
expect((0, utils_1.deepEquals)(testObject, Object.assign(Object.assign({}, secondObject), { 3: Object.assign(Object.assign({}, secondObject[3]), { avo: [1.1] }) }))).toBe(false);
|
|
34
|
+
expect((0, utils_1.deepEquals)(testObject, Object.assign(Object.assign({}, secondObject), { 0: "other string" }))).toBe(false);
|
|
35
35
|
});
|
|
36
36
|
test(`Detects duplications when track in avo and then manually`, () => {
|
|
37
37
|
const shouldRegisterFromAvo = deduplicator.shouldRegisterEvent("Test", testObject, true);
|
|
@@ -52,7 +52,7 @@ describe("Schema Parsing", () => {
|
|
|
52
52
|
propertyType: constants_1.type.STRING,
|
|
53
53
|
},
|
|
54
54
|
]);
|
|
55
|
-
expect(res[7].propertyType).toBe(constants_1.type.
|
|
55
|
+
expect(res[7].propertyType).toBe(constants_1.type.STRINGLIST);
|
|
56
56
|
expect(res[7].children).toMatchObject([
|
|
57
57
|
constants_1.type.STRING,
|
|
58
58
|
[
|
|
@@ -77,13 +77,7 @@ describe("Schema Parsing", () => {
|
|
|
77
77
|
// When
|
|
78
78
|
const res = inspector.extractSchema(eventProperties);
|
|
79
79
|
// Then
|
|
80
|
-
expect(res[0].propertyType).toBe(constants_1.type.
|
|
81
|
-
expect(res[0].children).toMatchObject([
|
|
82
|
-
constants_1.type.STRING,
|
|
83
|
-
constants_1.type.BOOL,
|
|
84
|
-
constants_1.type.INT,
|
|
85
|
-
constants_1.type.FLOAT,
|
|
86
|
-
]);
|
|
80
|
+
expect(res[0].propertyType).toBe(constants_1.type.STRINGLIST);
|
|
87
81
|
});
|
|
88
82
|
test("Empty and falsy values are set correctly", () => {
|
|
89
83
|
// Given
|
|
@@ -108,7 +102,27 @@ describe("Schema Parsing", () => {
|
|
|
108
102
|
expect(res[5].propertyType).toBe(constants_1.type.NULL);
|
|
109
103
|
expect(res[6].propertyType).toBe(constants_1.type.OBJECT);
|
|
110
104
|
expect(res[6].children).toMatchObject([]);
|
|
111
|
-
expect(res[7].propertyType).toBe(constants_1.type.
|
|
105
|
+
expect(res[7].propertyType).toBe(constants_1.type.STRINGLIST);
|
|
112
106
|
expect(res[7].children).toMatchObject([]);
|
|
113
107
|
});
|
|
108
|
+
test("List of string returns list(string)", () => {
|
|
109
|
+
// Given
|
|
110
|
+
const eventProperties = {
|
|
111
|
+
prop0: ["a", "b", "c"],
|
|
112
|
+
};
|
|
113
|
+
// When
|
|
114
|
+
const res = inspector.extractSchema(eventProperties);
|
|
115
|
+
// Then
|
|
116
|
+
expect(res[0].propertyType).toBe(constants_1.type.STRINGLIST);
|
|
117
|
+
});
|
|
118
|
+
test("List of multiple types returns list(`firstType`)", () => {
|
|
119
|
+
// Given
|
|
120
|
+
const eventProperties = {
|
|
121
|
+
prop0: [1.2, "two", { "three": 3 }],
|
|
122
|
+
};
|
|
123
|
+
// When
|
|
124
|
+
const res = inspector.extractSchema(eventProperties);
|
|
125
|
+
// Then
|
|
126
|
+
expect(res[0].propertyType).toBe(constants_1.type.FLOATLIST);
|
|
127
|
+
});
|
|
114
128
|
});
|
|
@@ -26,12 +26,17 @@ declare const trackingEndpoint = "https://api.avo.app/inspector/v1/track";
|
|
|
26
26
|
declare const sessionTimeMs: number;
|
|
27
27
|
declare const type: {
|
|
28
28
|
STRING: string;
|
|
29
|
+
STRINGLIST: string;
|
|
29
30
|
INT: string;
|
|
31
|
+
INTLIST: string;
|
|
30
32
|
OBJECT: string;
|
|
33
|
+
OBJECTLIST: string;
|
|
31
34
|
FLOAT: string;
|
|
32
|
-
|
|
35
|
+
FLOATLIST: string;
|
|
33
36
|
BOOL: string;
|
|
37
|
+
BOOLLIST: string;
|
|
34
38
|
NULL: string;
|
|
35
39
|
UNKNOWN: string;
|
|
40
|
+
UNKNOWNLIST: string;
|
|
36
41
|
};
|
|
37
42
|
export { defaultOptions, error, mockedReturns, networkCallType, requestMsg, sessionTimeMs, type, trackingEndpoint, };
|
|
@@ -37,12 +37,17 @@ const sessionTimeMs = 5 * 60 * 1000;
|
|
|
37
37
|
exports.sessionTimeMs = sessionTimeMs;
|
|
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
|
exports.type = type;
|
package/dist/utils.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.isValueEmpty = void 0;
|
|
4
|
+
exports.deepEquals = deepEquals;
|
|
4
5
|
const isValueEmpty = (value) => {
|
|
5
6
|
return value === null || value === undefined || value.trim().length == 0;
|
|
6
7
|
};
|
|
@@ -39,4 +40,3 @@ function deepEquals(x, y) {
|
|
|
39
40
|
}
|
|
40
41
|
return true;
|
|
41
42
|
}
|
|
42
|
-
exports.deepEquals = deepEquals;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-avo-inspector",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Avo Inspector for Node.js",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"repository": "https://github.com/avohq/node-avo-inspector",
|
|
@@ -36,11 +36,11 @@
|
|
|
36
36
|
]
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@types/jest": "^
|
|
40
|
-
"@types/node": "^
|
|
41
|
-
"jest": "^
|
|
42
|
-
"ts-jest": "^
|
|
43
|
-
"typescript": "
|
|
39
|
+
"@types/jest": "^29.5.12",
|
|
40
|
+
"@types/node": "^22.3.0",
|
|
41
|
+
"jest": "^29.7.0",
|
|
42
|
+
"ts-jest": "^29.2.4",
|
|
43
|
+
"typescript": "*"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {}
|
|
46
46
|
}
|
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
|
}
|
|
@@ -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 {
|