avo-inspector 3.1.0-alpha.2 → 3.2.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 +6 -13
- package/dist/AvoBatcher.js +52 -44
- package/dist/AvoDeduplicator.js +46 -45
- package/dist/AvoEncryption.js +147 -253
- package/dist/AvoInspector.js +295 -334
- package/dist/AvoNetworkCallsHandler.d.ts +6 -0
- package/dist/AvoNetworkCallsHandler.js +180 -136
- package/dist/AvoSchemaParser.js +34 -71
- package/dist/AvoStreamId.js +67 -129
- package/dist/__mocks__/xhr.js +14 -0
- package/dist/__mocks__/xhrError.js +14 -0
- package/dist/__tests__/AvoEncryption.d.ts +1 -0
- package/dist/__tests__/AvoEncryption.js +272 -0
- package/dist/__tests__/AvoEncryptionIntegration.d.ts +1 -0
- package/dist/__tests__/AvoEncryptionIntegration.js +191 -0
- package/dist/__tests__/AvoEventSpecFetcher.d.ts +1 -0
- package/dist/__tests__/AvoEventSpecFetcher.js +377 -0
- package/dist/__tests__/AvoInspector.d.ts +1 -0
- package/dist/__tests__/AvoInspector.js +335 -0
- package/dist/__tests__/Batcher.d.ts +1 -0
- package/dist/__tests__/Batcher.js +214 -0
- package/dist/__tests__/BatcherPublic.d.ts +1 -0
- package/dist/__tests__/BatcherPublic.js +139 -0
- package/dist/__tests__/Deduplicator.d.ts +1 -0
- package/dist/__tests__/Deduplicator.js +190 -0
- package/dist/__tests__/EventSpecCache.d.ts +1 -0
- package/dist/__tests__/EventSpecCache.js +143 -0
- package/dist/__tests__/EventValidator.d.ts +1 -0
- package/dist/__tests__/EventValidator.js +543 -0
- package/dist/__tests__/InstallationId.d.ts +1 -0
- package/dist/__tests__/InstallationId.js +60 -0
- package/dist/__tests__/NetworkCallsHandler.d.ts +1 -0
- package/dist/__tests__/NetworkCallsHandler.js +222 -0
- package/dist/__tests__/NetworkCallsHandlerGzip_test.d.ts +1 -0
- package/dist/__tests__/NetworkCallsHandlerModelA.d.ts +1 -0
- package/dist/__tests__/NetworkCallsHandlerModelA.js +206 -0
- package/dist/__tests__/Parsing.d.ts +1 -0
- package/dist/__tests__/Parsing.js +115 -0
- package/dist/__tests__/Sessions.d.ts +1 -0
- package/dist/__tests__/Sessions.js +10 -0
- package/dist/__tests__/Storage.d.ts +1 -0
- package/dist/__tests__/Storage.js +173 -0
- package/dist/__tests__/StreamId.d.ts +1 -0
- package/dist/__tests__/StreamId.js +153 -0
- package/dist/__tests__/constants.js +48 -0
- package/dist/eventSpec/AvoEventSpecCache.js +94 -82
- package/dist/eventSpec/AvoEventSpecFetcher.js +200 -117
- package/dist/eventSpec/EventValidator.js +460 -304
- package/dist/index.js +1 -1
- package/dist/lite/AvoNetworkCallsHandlerLite.d.ts +6 -0
- package/dist/lite/AvoNetworkCallsHandlerLite.js +110 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -25,9 +25,9 @@ or
|
|
|
25
25
|
yarn add avo-inspector
|
|
26
26
|
```
|
|
27
27
|
|
|
28
|
-
# Lite Build (Production
|
|
28
|
+
# Lite Build (Production Only)
|
|
29
29
|
|
|
30
|
-
For size
|
|
30
|
+
Available since version `3.1.0`. For production environments where bundle size matters (GTM, script tags, etc.), use the lite entry point which excludes encryption and event spec validation. Use the full build in dev/staging environments for the complete development experience:
|
|
31
31
|
|
|
32
32
|
```javascript
|
|
33
33
|
import { AvoInspector, AvoInspectorEnv } from "avo-inspector/lite";
|
|
@@ -41,19 +41,12 @@ let inspector = new AvoInspector({
|
|
|
41
41
|
|
|
42
42
|
The lite build has the same tracking API as the full version — `trackSchemaFromEvent`, `trackSchema`, and `extractSchema` all work identically. The differences:
|
|
43
43
|
|
|
44
|
-
-
|
|
45
|
-
-
|
|
46
|
-
-
|
|
47
|
-
- No stream ID generation/persistence (dev/staging debugger feature)
|
|
48
|
-
- No event deduplication — **if you use both Avo Codegen and manual `trackSchemaFromEvent` calls for the same events, use the full build instead** to avoid sending duplicate schemas
|
|
44
|
+
- Does not support [property value validation](https://www.avo.app/docs/inspector/inspector-debugger#enabling-advanced-debugger-features) in the [Inspector Debugger](https://www.avo.app/docs/inspector/inspector-debugger) (no `publicEncryptionKey` constructor option — TypeScript will error if passed)
|
|
45
|
+
- Does not support [session filtering](https://www.avo.app/docs/inspector/inspector-debugger) in the Inspector Debugger (no stream ID generation/persistence)
|
|
46
|
+
- Does not support event deduplication — **if you use both Avo Codegen and manual `trackSchemaFromEvent` calls for the same events, use the full build instead** to avoid sending duplicate schemas
|
|
49
47
|
- Works universally with any bundler or minifier — no flags or configuration needed
|
|
50
48
|
|
|
51
|
-
**
|
|
52
|
-
|
|
53
|
-
| | Minified | Gzipped |
|
|
54
|
-
|---|---|---|
|
|
55
|
-
| Full (`avo-inspector`) | 129 KB | 37 KB |
|
|
56
|
-
| Lite (`avo-inspector/lite`) | 20 KB | 5.2 KB |
|
|
49
|
+
**Lite build size:** ~20 KB minified, ~5.2 KB gzipped.
|
|
57
50
|
|
|
58
51
|
See `examples/lite-size-demos/` for working examples with terser, webpack, and rollup.
|
|
59
52
|
|
package/dist/AvoBatcher.js
CHANGED
|
@@ -1,58 +1,61 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AvoBatcher = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
var AvoInspector_1 = require("./AvoInspector");
|
|
5
|
+
var AvoBatcher = /** @class */ (function () {
|
|
6
|
+
function AvoBatcher(networkCallsHandler) {
|
|
7
|
+
var _this = this;
|
|
7
8
|
this.events = [];
|
|
8
9
|
this.networkCallsHandler = networkCallsHandler;
|
|
9
10
|
this.batchFlushAttemptTimestamp = Date.now();
|
|
10
11
|
AvoInspector_1.AvoInspector.avoStorage
|
|
11
12
|
.getItemAsync(AvoBatcher.cacheKey)
|
|
12
|
-
.then((savedEvents)
|
|
13
|
+
.then(function (savedEvents) {
|
|
13
14
|
if (savedEvents !== null) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
var nonNullSavedEvents = savedEvents.filter(function (event) { return event !== null; });
|
|
16
|
+
_this.events = _this.events.concat(nonNullSavedEvents);
|
|
17
|
+
_this.checkIfBatchNeedsToBeSent();
|
|
17
18
|
}
|
|
18
19
|
})
|
|
19
|
-
.catch((error)
|
|
20
|
-
|
|
20
|
+
.catch(function (error) {
|
|
21
|
+
if (AvoInspector_1.AvoInspector.shouldLog) {
|
|
22
|
+
console.error("Avo Inspector: failed to load cached events.", error);
|
|
23
|
+
}
|
|
21
24
|
});
|
|
22
25
|
}
|
|
23
|
-
|
|
24
|
-
this
|
|
25
|
-
this.
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
39
|
-
checkIfBatchNeedsToBeSent() {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
26
|
+
AvoBatcher.prototype.handleTrackSchema = function (eventName, schema, eventId, eventHash, eventProps) {
|
|
27
|
+
var _this = this;
|
|
28
|
+
this.networkCallsHandler.bodyForEventSchemaCall(eventName, schema, eventId, eventHash, eventProps).then(function (eventBody) {
|
|
29
|
+
_this.events.push(eventBody);
|
|
30
|
+
_this.saveEvents();
|
|
31
|
+
if (AvoInspector_1.AvoInspector.shouldLog) {
|
|
32
|
+
console.log("Avo Inspector: saved event " +
|
|
33
|
+
eventName +
|
|
34
|
+
" with schema " +
|
|
35
|
+
JSON.stringify(schema));
|
|
36
|
+
}
|
|
37
|
+
_this.checkIfBatchNeedsToBeSent();
|
|
38
|
+
}).catch(function (error) {
|
|
39
|
+
console.error("Avo Inspector: failed to prepare event body for " + eventName + ".", error);
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
AvoBatcher.prototype.checkIfBatchNeedsToBeSent = function () {
|
|
43
|
+
var batchSize = this.events.length;
|
|
44
|
+
var now = Date.now();
|
|
45
|
+
var timeSinceLastFlushAttempt = now - this.batchFlushAttemptTimestamp;
|
|
46
|
+
var sendBySize = batchSize % AvoInspector_1.AvoInspector.batchSize == 0;
|
|
47
|
+
var sendByTime = timeSinceLastFlushAttempt >= AvoInspector_1.AvoInspector.batchFlushSeconds * 1000;
|
|
48
|
+
var avoBatcher = this;
|
|
46
49
|
if (sendBySize || sendByTime) {
|
|
47
50
|
this.batchFlushAttemptTimestamp = now;
|
|
48
|
-
|
|
51
|
+
var sendingEvents_1 = avoBatcher.events;
|
|
49
52
|
avoBatcher.events = [];
|
|
50
|
-
this.networkCallsHandler.callInspectorWithBatchBody(
|
|
53
|
+
this.networkCallsHandler.callInspectorWithBatchBody(sendingEvents_1, function (error) {
|
|
51
54
|
if (error != null) {
|
|
52
|
-
avoBatcher.events = avoBatcher.events.concat(
|
|
55
|
+
avoBatcher.events = avoBatcher.events.concat(sendingEvents_1);
|
|
53
56
|
if (AvoInspector_1.AvoInspector.shouldLog) {
|
|
54
57
|
console.log("Avo Inspector: batch sending failed: " +
|
|
55
|
-
error
|
|
58
|
+
error +
|
|
56
59
|
". We will attempt to send your schemas with next batch");
|
|
57
60
|
}
|
|
58
61
|
}
|
|
@@ -64,16 +67,21 @@ class AvoBatcher {
|
|
|
64
67
|
avoBatcher.saveEvents();
|
|
65
68
|
});
|
|
66
69
|
}
|
|
67
|
-
}
|
|
68
|
-
saveEvents() {
|
|
70
|
+
};
|
|
71
|
+
AvoBatcher.prototype.saveEvents = function () {
|
|
69
72
|
if (this.events.length > 1000) {
|
|
70
|
-
|
|
73
|
+
var extraElements = this.events.length - 1000;
|
|
71
74
|
this.events.splice(0, extraElements);
|
|
72
75
|
}
|
|
73
76
|
AvoInspector_1.AvoInspector.avoStorage.setItem(AvoBatcher.cacheKey, this.events);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}
|
|
77
|
+
};
|
|
78
|
+
Object.defineProperty(AvoBatcher, "cacheKey", {
|
|
79
|
+
get: function () {
|
|
80
|
+
return "AvoInspectorEvents";
|
|
81
|
+
},
|
|
82
|
+
enumerable: false,
|
|
83
|
+
configurable: true
|
|
84
|
+
});
|
|
85
|
+
return AvoBatcher;
|
|
86
|
+
}());
|
|
79
87
|
exports.AvoBatcher = AvoBatcher;
|
package/dist/AvoDeduplicator.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AvoDeduplicator = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
var AvoSchemaParser_1 = require("./AvoSchemaParser");
|
|
5
|
+
var utils_1 = require("./utils");
|
|
6
|
+
var AvoDeduplicator = /** @class */ (function () {
|
|
7
|
+
function AvoDeduplicator() {
|
|
8
8
|
this.avoFunctionsEvents = {};
|
|
9
9
|
this.manualEvents = {};
|
|
10
10
|
this.avoFunctionsEventsParams = {};
|
|
11
11
|
this.manualEventsParams = {};
|
|
12
12
|
}
|
|
13
|
-
shouldRegisterEvent(eventName, params, fromAvoFunction) {
|
|
13
|
+
AvoDeduplicator.prototype.shouldRegisterEvent = function (eventName, params, fromAvoFunction) {
|
|
14
14
|
this.clearOldEvents();
|
|
15
15
|
if (fromAvoFunction) {
|
|
16
16
|
this.avoFunctionsEvents[Date.now()] = eventName;
|
|
@@ -20,11 +20,11 @@ class AvoDeduplicator {
|
|
|
20
20
|
this.manualEvents[Date.now()] = eventName;
|
|
21
21
|
this.manualEventsParams[eventName] = params;
|
|
22
22
|
}
|
|
23
|
-
|
|
23
|
+
var checkInAvoFunctions = !fromAvoFunction;
|
|
24
24
|
return !this.hasSameEventAs(eventName, params, checkInAvoFunctions);
|
|
25
|
-
}
|
|
26
|
-
hasSameEventAs(eventName, params, checkInAvoFunctions) {
|
|
27
|
-
|
|
25
|
+
};
|
|
26
|
+
AvoDeduplicator.prototype.hasSameEventAs = function (eventName, params, checkInAvoFunctions) {
|
|
27
|
+
var result = false;
|
|
28
28
|
if (checkInAvoFunctions) {
|
|
29
29
|
if (this.lookForEventIn(eventName, params, this.avoFunctionsEventsParams)) {
|
|
30
30
|
result = true;
|
|
@@ -40,12 +40,12 @@ class AvoDeduplicator {
|
|
|
40
40
|
delete this.manualEventsParams[eventName];
|
|
41
41
|
}
|
|
42
42
|
return result;
|
|
43
|
-
}
|
|
44
|
-
lookForEventIn(eventName, params, eventsStorage) {
|
|
45
|
-
for (
|
|
43
|
+
};
|
|
44
|
+
AvoDeduplicator.prototype.lookForEventIn = function (eventName, params, eventsStorage) {
|
|
45
|
+
for (var otherEventName in eventsStorage) {
|
|
46
46
|
if (eventsStorage.hasOwnProperty(otherEventName)) {
|
|
47
47
|
if (otherEventName === eventName) {
|
|
48
|
-
|
|
48
|
+
var otherParams = eventsStorage[eventName];
|
|
49
49
|
if (otherParams && (0, utils_1.deepEquals)(params, otherParams)) {
|
|
50
50
|
return true;
|
|
51
51
|
}
|
|
@@ -53,9 +53,9 @@ class AvoDeduplicator {
|
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
55
|
return false;
|
|
56
|
-
}
|
|
57
|
-
hasSeenEventParams(params, checkInAvoFunctions) {
|
|
58
|
-
|
|
56
|
+
};
|
|
57
|
+
AvoDeduplicator.prototype.hasSeenEventParams = function (params, checkInAvoFunctions) {
|
|
58
|
+
var result = false;
|
|
59
59
|
if (checkInAvoFunctions) {
|
|
60
60
|
if (this.lookForEventParamsIn(params, this.avoFunctionsEventsParams)) {
|
|
61
61
|
result = true;
|
|
@@ -67,37 +67,37 @@ class AvoDeduplicator {
|
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
69
|
return result;
|
|
70
|
-
}
|
|
71
|
-
lookForEventParamsIn(params, eventsStorage) {
|
|
72
|
-
for (
|
|
70
|
+
};
|
|
71
|
+
AvoDeduplicator.prototype.lookForEventParamsIn = function (params, eventsStorage) {
|
|
72
|
+
for (var otherEventName in eventsStorage) {
|
|
73
73
|
if (eventsStorage.hasOwnProperty(otherEventName)) {
|
|
74
|
-
|
|
74
|
+
var otherParams = eventsStorage[otherEventName];
|
|
75
75
|
if (otherParams && (0, utils_1.deepEquals)(params, otherParams)) {
|
|
76
76
|
return true;
|
|
77
77
|
}
|
|
78
78
|
}
|
|
79
79
|
}
|
|
80
80
|
return false;
|
|
81
|
-
}
|
|
82
|
-
|
|
81
|
+
};
|
|
82
|
+
AvoDeduplicator.prototype.shouldRegisterSchemaFromManually = function (eventName, eventSchema) {
|
|
83
83
|
this.clearOldEvents();
|
|
84
|
-
return !
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
if (
|
|
84
|
+
return !this.hasSameShapeInAvoFunctionsAs(eventName, eventSchema);
|
|
85
|
+
};
|
|
86
|
+
AvoDeduplicator.prototype.hasSameShapeInAvoFunctionsAs = function (eventName, eventSchema) {
|
|
87
|
+
var result = false;
|
|
88
|
+
if (this.lookForEventSchemaIn(eventName, eventSchema, this.avoFunctionsEventsParams)) {
|
|
89
89
|
result = true;
|
|
90
90
|
}
|
|
91
91
|
if (result) {
|
|
92
92
|
delete this.avoFunctionsEventsParams[eventName];
|
|
93
93
|
}
|
|
94
94
|
return result;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
for (
|
|
95
|
+
};
|
|
96
|
+
AvoDeduplicator.prototype.lookForEventSchemaIn = function (eventName, eventSchema, eventsStorage) {
|
|
97
|
+
for (var otherEventName in eventsStorage) {
|
|
98
98
|
if (eventsStorage.hasOwnProperty(otherEventName)) {
|
|
99
99
|
if (otherEventName === eventName) {
|
|
100
|
-
|
|
100
|
+
var otherSchema = AvoSchemaParser_1.AvoSchemaParser.extractSchema(eventsStorage[eventName]);
|
|
101
101
|
if (otherSchema && (0, utils_1.deepEquals)(eventSchema, otherSchema)) {
|
|
102
102
|
return true;
|
|
103
103
|
}
|
|
@@ -105,37 +105,38 @@ class AvoDeduplicator {
|
|
|
105
105
|
}
|
|
106
106
|
}
|
|
107
107
|
return false;
|
|
108
|
-
}
|
|
109
|
-
clearOldEvents() {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
for (
|
|
108
|
+
};
|
|
109
|
+
AvoDeduplicator.prototype.clearOldEvents = function () {
|
|
110
|
+
var now = Date.now();
|
|
111
|
+
var msToConsiderOld = 300;
|
|
112
|
+
for (var time in this.avoFunctionsEvents) {
|
|
113
113
|
if (this.avoFunctionsEvents.hasOwnProperty(time)) {
|
|
114
|
-
|
|
114
|
+
var timestamp = Number(time) || 0;
|
|
115
115
|
if (now - timestamp > msToConsiderOld) {
|
|
116
|
-
|
|
116
|
+
var eventName = this.avoFunctionsEvents[time];
|
|
117
117
|
delete this.avoFunctionsEvents[time];
|
|
118
118
|
delete this.avoFunctionsEventsParams[eventName];
|
|
119
119
|
}
|
|
120
120
|
}
|
|
121
121
|
}
|
|
122
|
-
for (
|
|
122
|
+
for (var time in this.manualEvents) {
|
|
123
123
|
if (this.manualEvents.hasOwnProperty(time)) {
|
|
124
|
-
|
|
124
|
+
var timestamp = Number(time) || 0;
|
|
125
125
|
if (now - timestamp > msToConsiderOld) {
|
|
126
|
-
|
|
126
|
+
var eventName = this.manualEvents[time];
|
|
127
127
|
delete this.manualEvents[time];
|
|
128
128
|
delete this.manualEventsParams[eventName];
|
|
129
129
|
}
|
|
130
130
|
}
|
|
131
131
|
}
|
|
132
|
-
}
|
|
132
|
+
};
|
|
133
133
|
// used in tests
|
|
134
|
-
_clearEvents() {
|
|
134
|
+
AvoDeduplicator.prototype._clearEvents = function () {
|
|
135
135
|
this.avoFunctionsEvents = {};
|
|
136
136
|
this.manualEvents = {};
|
|
137
137
|
this.avoFunctionsEventsParams = {};
|
|
138
138
|
this.manualEventsParams = {};
|
|
139
|
-
}
|
|
140
|
-
|
|
139
|
+
};
|
|
140
|
+
return AvoDeduplicator;
|
|
141
|
+
}());
|
|
141
142
|
exports.AvoDeduplicator = AvoDeduplicator;
|