avo-inspector 1.4.1 → 1.4.2
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 +4 -0
- package/dist/index.js +1 -1
- package/dist-browser/AvoBatcher.d.ts +24 -0
- package/dist-browser/AvoDeduplicator.d.ts +20 -0
- package/dist-browser/AvoGuid.d.ts +3 -0
- package/dist-browser/AvoInspector.d.ts +49 -0
- package/dist-browser/AvoInspectorEnv.d.ts +7 -0
- package/dist-browser/AvoInstallationId.d.ts +5 -0
- package/dist-browser/AvoNetworkCallsHandler.d.ts +48 -0
- package/dist-browser/AvoSchemaParser.d.ts +9 -0
- package/dist-browser/AvoSessionTracker.d.ts +15 -0
- package/dist-browser/AvoStorage.d.ts +22 -0
- package/dist-browser/__mocks__/xhr.d.ts +12 -0
- package/dist-browser/__mocks__/xhrError.d.ts +12 -0
- package/dist-browser/__tests__/AvoInspector.d.ts +1 -0
- package/dist-browser/__tests__/Batcher.d.ts +1 -0
- package/dist-browser/__tests__/BatcherPublic.d.ts +1 -0
- package/dist-browser/__tests__/Deduplicator.d.ts +1 -0
- package/dist-browser/__tests__/InstallationId.d.ts +1 -0
- package/dist-browser/__tests__/NetworkCallsHandler.d.ts +1 -0
- package/dist-browser/__tests__/Parsing.d.ts +1 -0
- package/dist-browser/__tests__/Sessions.d.ts +1 -0
- package/dist-browser/__tests__/Storage.d.ts +1 -0
- package/dist-browser/__tests__/constants.d.ts +36 -0
- package/dist-browser/index.d.ts +2 -0
- package/dist-browser/utils.d.ts +3 -0
- package/dist-native/AvoBatcher.d.ts +24 -0
- package/dist-native/AvoBatcher.js +82 -0
- package/dist-native/AvoDeduplicator.d.ts +36 -0
- package/dist-native/AvoDeduplicator.js +142 -0
- package/dist-native/AvoGuid.d.ts +3 -0
- package/dist-native/AvoGuid.js +14 -0
- package/dist-native/AvoInspector.d.ts +52 -0
- package/dist-native/AvoInspector.js +220 -0
- package/dist-native/AvoInspectorEnv.d.ts +7 -0
- package/dist-native/AvoInspectorEnv.js +8 -0
- package/dist-native/AvoInstallationId.d.ts +5 -0
- package/dist-native/AvoInstallationId.js +36 -0
- package/dist-native/AvoNetworkCallsHandler.d.ts +48 -0
- package/dist-native/AvoNetworkCallsHandler.js +142 -0
- package/dist-native/AvoSchemaParser.d.ts +11 -0
- package/dist-native/AvoSchemaParser.js +95 -0
- package/dist-native/AvoSessionTracker.d.ts +15 -0
- package/dist-native/AvoSessionTracker.js +104 -0
- package/dist-native/AvoStorage.d.ts +22 -0
- package/dist-native/AvoStorage.js +336 -0
- package/dist-native/__mocks__/xhr.d.ts +11 -0
- package/dist-native/__mocks__/xhr.js +14 -0
- package/dist-native/__mocks__/xhrError.d.ts +11 -0
- package/dist-native/__mocks__/xhrError.js +14 -0
- package/dist-native/__tests__/AvoInspector.d.ts +1 -0
- package/dist-native/__tests__/AvoInspector.js +207 -0
- package/dist-native/__tests__/Batcher.d.ts +1 -0
- package/dist-native/__tests__/Batcher.js +280 -0
- package/dist-native/__tests__/BatcherPublic.d.ts +1 -0
- package/dist-native/__tests__/BatcherPublic.js +82 -0
- package/dist-native/__tests__/Deduplicator.d.ts +1 -0
- package/dist-native/__tests__/Deduplicator.js +111 -0
- package/dist-native/__tests__/InstallationId.d.ts +1 -0
- package/dist-native/__tests__/InstallationId.js +40 -0
- package/dist-native/__tests__/NetworkCallsHandler.d.ts +1 -0
- package/dist-native/__tests__/NetworkCallsHandler.js +132 -0
- package/dist-native/__tests__/Parsing.d.ts +1 -0
- package/dist-native/__tests__/Parsing.js +115 -0
- package/dist-native/__tests__/Sessions.d.ts +1 -0
- package/dist-native/__tests__/Sessions.js +179 -0
- package/dist-native/__tests__/Storage.d.ts +1 -0
- package/dist-native/__tests__/Storage.js +173 -0
- package/dist-native/__tests__/constants.d.ts +36 -0
- package/dist-native/__tests__/constants.js +47 -0
- package/dist-native/index.d.ts +2 -0
- package/dist-native/index.js +7 -0
- package/dist-native/utils.d.ts +3 -0
- package/dist-native/utils.js +42 -0
- package/package.json +3 -2
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AvoDeduplicator = void 0;
|
|
4
|
+
var AvoSchemaParser_1 = require("./AvoSchemaParser");
|
|
5
|
+
var utils_1 = require("./utils");
|
|
6
|
+
var AvoDeduplicator = /** @class */ (function () {
|
|
7
|
+
function AvoDeduplicator() {
|
|
8
|
+
this.avoFunctionsEvents = {};
|
|
9
|
+
this.manualEvents = {};
|
|
10
|
+
this.avoFunctionsEventsParams = {};
|
|
11
|
+
this.manualEventsParams = {};
|
|
12
|
+
}
|
|
13
|
+
AvoDeduplicator.prototype.shouldRegisterEvent = function (eventName, params, fromAvoFunction) {
|
|
14
|
+
this.clearOldEvents();
|
|
15
|
+
if (fromAvoFunction) {
|
|
16
|
+
this.avoFunctionsEvents[Date.now()] = eventName;
|
|
17
|
+
this.avoFunctionsEventsParams[eventName] = params;
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
this.manualEvents[Date.now()] = eventName;
|
|
21
|
+
this.manualEventsParams[eventName] = params;
|
|
22
|
+
}
|
|
23
|
+
var checkInAvoFunctions = !fromAvoFunction;
|
|
24
|
+
return !this.hasSameEventAs(eventName, params, checkInAvoFunctions);
|
|
25
|
+
};
|
|
26
|
+
AvoDeduplicator.prototype.hasSameEventAs = function (eventName, params, checkInAvoFunctions) {
|
|
27
|
+
var result = false;
|
|
28
|
+
if (checkInAvoFunctions) {
|
|
29
|
+
if (this.lookForEventIn(eventName, params, this.avoFunctionsEventsParams)) {
|
|
30
|
+
result = true;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
if (this.lookForEventIn(eventName, params, this.manualEventsParams)) {
|
|
35
|
+
result = true;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
if (result) {
|
|
39
|
+
delete this.avoFunctionsEventsParams[eventName];
|
|
40
|
+
delete this.manualEventsParams[eventName];
|
|
41
|
+
}
|
|
42
|
+
return result;
|
|
43
|
+
};
|
|
44
|
+
AvoDeduplicator.prototype.lookForEventIn = function (eventName, params, eventsStorage) {
|
|
45
|
+
for (var otherEventName in eventsStorage) {
|
|
46
|
+
if (eventsStorage.hasOwnProperty(otherEventName)) {
|
|
47
|
+
if (otherEventName === eventName) {
|
|
48
|
+
var otherParams = eventsStorage[eventName];
|
|
49
|
+
if (otherParams && (0, utils_1.deepEquals)(params, otherParams)) {
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return false;
|
|
56
|
+
};
|
|
57
|
+
AvoDeduplicator.prototype.hasSeenEventParams = function (params, checkInAvoFunctions) {
|
|
58
|
+
var result = false;
|
|
59
|
+
if (checkInAvoFunctions) {
|
|
60
|
+
if (this.lookForEventParamsIn(params, this.avoFunctionsEventsParams)) {
|
|
61
|
+
result = true;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
if (this.lookForEventParamsIn(params, this.manualEventsParams)) {
|
|
66
|
+
result = true;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return result;
|
|
70
|
+
};
|
|
71
|
+
AvoDeduplicator.prototype.lookForEventParamsIn = function (params, eventsStorage) {
|
|
72
|
+
for (var otherEventName in eventsStorage) {
|
|
73
|
+
if (eventsStorage.hasOwnProperty(otherEventName)) {
|
|
74
|
+
var otherParams = eventsStorage[otherEventName];
|
|
75
|
+
if (otherParams && (0, utils_1.deepEquals)(params, otherParams)) {
|
|
76
|
+
return true;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return false;
|
|
81
|
+
};
|
|
82
|
+
AvoDeduplicator.prototype.shouldRegisterSchemaFromManually = function (eventName, eventSchema) {
|
|
83
|
+
this.clearOldEvents();
|
|
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
|
+
result = true;
|
|
90
|
+
}
|
|
91
|
+
if (result) {
|
|
92
|
+
delete this.avoFunctionsEventsParams[eventName];
|
|
93
|
+
}
|
|
94
|
+
return result;
|
|
95
|
+
};
|
|
96
|
+
AvoDeduplicator.prototype.lookForEventSchemaIn = function (eventName, eventSchema, eventsStorage) {
|
|
97
|
+
for (var otherEventName in eventsStorage) {
|
|
98
|
+
if (eventsStorage.hasOwnProperty(otherEventName)) {
|
|
99
|
+
if (otherEventName === eventName) {
|
|
100
|
+
var otherSchema = AvoSchemaParser_1.AvoSchemaParser.extractSchema(eventsStorage[eventName]);
|
|
101
|
+
if (otherSchema && (0, utils_1.deepEquals)(eventSchema, otherSchema)) {
|
|
102
|
+
return true;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return false;
|
|
108
|
+
};
|
|
109
|
+
AvoDeduplicator.prototype.clearOldEvents = function () {
|
|
110
|
+
var now = Date.now();
|
|
111
|
+
var msToConsiderOld = 300;
|
|
112
|
+
for (var time in this.avoFunctionsEvents) {
|
|
113
|
+
if (this.avoFunctionsEvents.hasOwnProperty(time)) {
|
|
114
|
+
var timestamp = Number(time) || 0;
|
|
115
|
+
if (now - timestamp > msToConsiderOld) {
|
|
116
|
+
var eventName = this.avoFunctionsEvents[time];
|
|
117
|
+
delete this.avoFunctionsEvents[time];
|
|
118
|
+
delete this.avoFunctionsEventsParams[eventName];
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
for (var time in this.manualEvents) {
|
|
123
|
+
if (this.manualEvents.hasOwnProperty(time)) {
|
|
124
|
+
var timestamp = Number(time) || 0;
|
|
125
|
+
if (now - timestamp > msToConsiderOld) {
|
|
126
|
+
var eventName = this.manualEvents[time];
|
|
127
|
+
delete this.manualEvents[time];
|
|
128
|
+
delete this.manualEventsParams[eventName];
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
// used in tests
|
|
134
|
+
AvoDeduplicator.prototype._clearEvents = function () {
|
|
135
|
+
this.avoFunctionsEvents = {};
|
|
136
|
+
this.manualEvents = {};
|
|
137
|
+
this.avoFunctionsEventsParams = {};
|
|
138
|
+
this.manualEventsParams = {};
|
|
139
|
+
};
|
|
140
|
+
return AvoDeduplicator;
|
|
141
|
+
}());
|
|
142
|
+
exports.AvoDeduplicator = AvoDeduplicator;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var AvoGuid = /** @class */ (function () {
|
|
4
|
+
function AvoGuid() {
|
|
5
|
+
}
|
|
6
|
+
AvoGuid.newGuid = function () {
|
|
7
|
+
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (c) {
|
|
8
|
+
var r = (Math.random() * 16) | 0, v = c == "x" ? r : (r & 0x3) | 0x8;
|
|
9
|
+
return v.toString(16);
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
return AvoGuid;
|
|
13
|
+
}());
|
|
14
|
+
exports.default = AvoGuid;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { AvoInspectorEnvValueType } from "./AvoInspectorEnv";
|
|
2
|
+
import { AvoSessionTracker } from "./AvoSessionTracker";
|
|
3
|
+
import { AvoBatcher } from "./AvoBatcher";
|
|
4
|
+
import { AvoStorage } from "./AvoStorage";
|
|
5
|
+
import { AvoDeduplicator } from "./AvoDeduplicator";
|
|
6
|
+
export declare class AvoInspector {
|
|
7
|
+
environment: AvoInspectorEnvValueType;
|
|
8
|
+
avoBatcher: AvoBatcher;
|
|
9
|
+
avoDeduplicator: AvoDeduplicator;
|
|
10
|
+
sessionTracker: AvoSessionTracker;
|
|
11
|
+
apiKey: string;
|
|
12
|
+
version: string;
|
|
13
|
+
static avoStorage: AvoStorage;
|
|
14
|
+
private static _batchSize;
|
|
15
|
+
static get batchSize(): number;
|
|
16
|
+
static set batchSize(newSize: number);
|
|
17
|
+
private static _batchFlushSeconds;
|
|
18
|
+
static get batchFlushSeconds(): number;
|
|
19
|
+
private static _shouldLog;
|
|
20
|
+
static get shouldLog(): boolean;
|
|
21
|
+
static set shouldLog(enable: boolean);
|
|
22
|
+
constructor(options: {
|
|
23
|
+
apiKey: string;
|
|
24
|
+
env: AvoInspectorEnvValueType;
|
|
25
|
+
version: string;
|
|
26
|
+
appName?: string;
|
|
27
|
+
});
|
|
28
|
+
trackSchemaFromEvent(eventName: string, eventProperties: {
|
|
29
|
+
[propName: string]: any;
|
|
30
|
+
}): Array<{
|
|
31
|
+
propertyName: string;
|
|
32
|
+
propertyType: string;
|
|
33
|
+
children?: any;
|
|
34
|
+
}>;
|
|
35
|
+
private _avoFunctionTrackSchemaFromEvent;
|
|
36
|
+
trackSchema(eventName: string, eventSchema: Array<{
|
|
37
|
+
propertyName: string;
|
|
38
|
+
propertyType: string;
|
|
39
|
+
children?: any;
|
|
40
|
+
}>): void;
|
|
41
|
+
private trackSchemaInternal;
|
|
42
|
+
enableLogging(enable: boolean): void;
|
|
43
|
+
extractSchema(eventProperties: {
|
|
44
|
+
[propName: string]: any;
|
|
45
|
+
}, shouldLogIfEnabled?: boolean): Array<{
|
|
46
|
+
propertyName: string;
|
|
47
|
+
propertyType: string;
|
|
48
|
+
children?: any;
|
|
49
|
+
}>;
|
|
50
|
+
setBatchSize(newBatchSize: number): void;
|
|
51
|
+
setBatchFlushSeconds(newBatchFlushSeconds: number): void;
|
|
52
|
+
}
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AvoInspector = void 0;
|
|
4
|
+
var AvoInspectorEnv_1 = require("./AvoInspectorEnv");
|
|
5
|
+
var AvoSchemaParser_1 = require("./AvoSchemaParser");
|
|
6
|
+
var AvoSessionTracker_1 = require("./AvoSessionTracker");
|
|
7
|
+
var AvoBatcher_1 = require("./AvoBatcher");
|
|
8
|
+
var AvoNetworkCallsHandler_1 = require("./AvoNetworkCallsHandler");
|
|
9
|
+
var AvoStorage_1 = require("./AvoStorage");
|
|
10
|
+
var AvoDeduplicator_1 = require("./AvoDeduplicator");
|
|
11
|
+
var utils_1 = require("./utils");
|
|
12
|
+
var libVersion = require("../package.json").version;
|
|
13
|
+
var AvoInspector = /** @class */ (function () {
|
|
14
|
+
// constructor(apiKey: string, env: AvoInspectorEnv, version: string) {
|
|
15
|
+
function AvoInspector(options) {
|
|
16
|
+
var _this = this;
|
|
17
|
+
// the constructor does aggressive null/undefined checking because same code paths will be accessible from JS
|
|
18
|
+
if ((0, utils_1.isValueEmpty)(options.env)) {
|
|
19
|
+
this.environment = AvoInspectorEnv_1.AvoInspectorEnv.Dev;
|
|
20
|
+
console.warn("[Avo Inspector] No environment provided. Defaulting to dev.");
|
|
21
|
+
}
|
|
22
|
+
else if (Object.values(AvoInspectorEnv_1.AvoInspectorEnv).indexOf(options.env) === -1) {
|
|
23
|
+
this.environment = AvoInspectorEnv_1.AvoInspectorEnv.Dev;
|
|
24
|
+
console.warn("[Avo Inspector] Unsupported environment provided. Defaulting to dev. Supported environments - Dev, Staging, Prod.");
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
this.environment = options.env;
|
|
28
|
+
}
|
|
29
|
+
if ((0, utils_1.isValueEmpty)(options.apiKey)) {
|
|
30
|
+
throw new Error("[Avo Inspector] No API key provided. Inspector can't operate without API key.");
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
this.apiKey = options.apiKey;
|
|
34
|
+
}
|
|
35
|
+
if ((0, utils_1.isValueEmpty)(options.version)) {
|
|
36
|
+
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.");
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
this.version = options.version;
|
|
40
|
+
}
|
|
41
|
+
if (this.environment === AvoInspectorEnv_1.AvoInspectorEnv.Dev) {
|
|
42
|
+
AvoInspector._batchSize = 1;
|
|
43
|
+
AvoInspector._shouldLog = true;
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
AvoInspector._batchSize = 30;
|
|
47
|
+
AvoInspector._batchFlushSeconds = 30;
|
|
48
|
+
AvoInspector._shouldLog = false;
|
|
49
|
+
}
|
|
50
|
+
AvoInspector.avoStorage = new AvoStorage_1.AvoStorage(AvoInspector._shouldLog);
|
|
51
|
+
var avoNetworkCallsHandler = new AvoNetworkCallsHandler_1.AvoNetworkCallsHandler(this.apiKey, this.environment.toString(), options.appName || "", this.version, libVersion);
|
|
52
|
+
this.avoBatcher = new AvoBatcher_1.AvoBatcher(avoNetworkCallsHandler);
|
|
53
|
+
this.sessionTracker = new AvoSessionTracker_1.AvoSessionTracker(this.avoBatcher);
|
|
54
|
+
this.avoDeduplicator = new AvoDeduplicator_1.AvoDeduplicator();
|
|
55
|
+
try {
|
|
56
|
+
if (process.env.BROWSER) {
|
|
57
|
+
// XXX make node/browser split clearer
|
|
58
|
+
if (typeof window !== "undefined") {
|
|
59
|
+
window.addEventListener("load", function () {
|
|
60
|
+
_this.sessionTracker.startOrProlongSession(Date.now());
|
|
61
|
+
}, false);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
this.sessionTracker.startOrProlongSession(Date.now());
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
catch (e) {
|
|
69
|
+
console.error("Avo Inspector: something went wrong. Please report to support@avo.app.", e);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
Object.defineProperty(AvoInspector, "batchSize", {
|
|
73
|
+
get: function () {
|
|
74
|
+
return this._batchSize;
|
|
75
|
+
},
|
|
76
|
+
set: function (newSize) {
|
|
77
|
+
if (newSize < 1) {
|
|
78
|
+
this._batchSize = 1;
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
this._batchSize = newSize;
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
enumerable: false,
|
|
85
|
+
configurable: true
|
|
86
|
+
});
|
|
87
|
+
Object.defineProperty(AvoInspector, "batchFlushSeconds", {
|
|
88
|
+
get: function () {
|
|
89
|
+
return this._batchFlushSeconds;
|
|
90
|
+
},
|
|
91
|
+
enumerable: false,
|
|
92
|
+
configurable: true
|
|
93
|
+
});
|
|
94
|
+
Object.defineProperty(AvoInspector, "shouldLog", {
|
|
95
|
+
get: function () {
|
|
96
|
+
return this._shouldLog;
|
|
97
|
+
},
|
|
98
|
+
set: function (enable) {
|
|
99
|
+
this._shouldLog = enable;
|
|
100
|
+
},
|
|
101
|
+
enumerable: false,
|
|
102
|
+
configurable: true
|
|
103
|
+
});
|
|
104
|
+
AvoInspector.prototype.trackSchemaFromEvent = function (eventName, eventProperties) {
|
|
105
|
+
try {
|
|
106
|
+
if (this.avoDeduplicator.shouldRegisterEvent(eventName, eventProperties, false)) {
|
|
107
|
+
if (AvoInspector.shouldLog) {
|
|
108
|
+
console.log("Avo Inspector: supplied event " +
|
|
109
|
+
eventName +
|
|
110
|
+
" with params " +
|
|
111
|
+
JSON.stringify(eventProperties));
|
|
112
|
+
}
|
|
113
|
+
var eventSchema = this.extractSchema(eventProperties, false);
|
|
114
|
+
this.trackSchemaInternal(eventName, eventSchema, null, null);
|
|
115
|
+
return eventSchema;
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
if (AvoInspector.shouldLog) {
|
|
119
|
+
console.log("Avo Inspector: Deduplicated event: " + eventName);
|
|
120
|
+
}
|
|
121
|
+
return [];
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
catch (e) {
|
|
125
|
+
console.error("Avo Inspector: something went wrong. Please report to support@avo.app.", e);
|
|
126
|
+
return [];
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
AvoInspector.prototype._avoFunctionTrackSchemaFromEvent = function (eventName, eventProperties, eventId, eventHash) {
|
|
130
|
+
try {
|
|
131
|
+
if (this.avoDeduplicator.shouldRegisterEvent(eventName, eventProperties, true)) {
|
|
132
|
+
if (AvoInspector.shouldLog) {
|
|
133
|
+
console.log("Avo Inspector: supplied event " +
|
|
134
|
+
eventName +
|
|
135
|
+
" with params " +
|
|
136
|
+
JSON.stringify(eventProperties));
|
|
137
|
+
}
|
|
138
|
+
var eventSchema = this.extractSchema(eventProperties, false);
|
|
139
|
+
this.trackSchemaInternal(eventName, eventSchema, eventId, eventHash);
|
|
140
|
+
return eventSchema;
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
if (AvoInspector.shouldLog) {
|
|
144
|
+
console.log("Avo Inspector: Deduplicated event: " + eventName);
|
|
145
|
+
}
|
|
146
|
+
return [];
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
catch (e) {
|
|
150
|
+
console.error("Avo Inspector: something went wrong. Please report to support@avo.app.", e);
|
|
151
|
+
return [];
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
AvoInspector.prototype.trackSchema = function (eventName, eventSchema) {
|
|
155
|
+
try {
|
|
156
|
+
if (this.avoDeduplicator.shouldRegisterSchemaFromManually(eventName, eventSchema)) {
|
|
157
|
+
if (AvoInspector.shouldLog) {
|
|
158
|
+
console.log("Avo Inspector: supplied event " +
|
|
159
|
+
eventName +
|
|
160
|
+
" with schema " +
|
|
161
|
+
JSON.stringify(eventSchema));
|
|
162
|
+
}
|
|
163
|
+
this.trackSchemaInternal(eventName, eventSchema, null, null);
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
if (AvoInspector.shouldLog) {
|
|
167
|
+
console.log("Avo Inspector: Deduplicated event: " + eventName);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
catch (e) {
|
|
172
|
+
console.error("Avo Inspector: something went wrong. Please report to support@avo.app.", e);
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
AvoInspector.prototype.trackSchemaInternal = function (eventName, eventSchema, eventId, eventHash) {
|
|
176
|
+
try {
|
|
177
|
+
this.sessionTracker.startOrProlongSession(Date.now());
|
|
178
|
+
this.avoBatcher.handleTrackSchema(eventName, eventSchema, eventId, eventHash);
|
|
179
|
+
}
|
|
180
|
+
catch (e) {
|
|
181
|
+
console.error("Avo Inspector: something went wrong. Please report to support@avo.app.", e);
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
AvoInspector.prototype.enableLogging = function (enable) {
|
|
185
|
+
AvoInspector._shouldLog = enable;
|
|
186
|
+
};
|
|
187
|
+
AvoInspector.prototype.extractSchema = function (eventProperties, shouldLogIfEnabled) {
|
|
188
|
+
if (shouldLogIfEnabled === void 0) { shouldLogIfEnabled = true; }
|
|
189
|
+
try {
|
|
190
|
+
this.sessionTracker.startOrProlongSession(Date.now());
|
|
191
|
+
if (this.avoDeduplicator.hasSeenEventParams(eventProperties, true)) {
|
|
192
|
+
if (shouldLogIfEnabled && AvoInspector.shouldLog) {
|
|
193
|
+
console.warn("Avo Inspector: WARNING! You are trying to extract schema shape that was just reported by your Avo functions. " +
|
|
194
|
+
"This is an indicator of duplicate inspector reporting. " +
|
|
195
|
+
"Please reach out to support@avo.app for advice if you are not sure how to handle this.");
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
if (AvoInspector.shouldLog) {
|
|
199
|
+
console.log("Avo Inspector: extracting schema from " +
|
|
200
|
+
JSON.stringify(eventProperties));
|
|
201
|
+
}
|
|
202
|
+
return AvoSchemaParser_1.AvoSchemaParser.extractSchema(eventProperties);
|
|
203
|
+
}
|
|
204
|
+
catch (e) {
|
|
205
|
+
console.error("Avo Inspector: something went wrong. Please report to support@avo.app.", e);
|
|
206
|
+
return [];
|
|
207
|
+
}
|
|
208
|
+
};
|
|
209
|
+
AvoInspector.prototype.setBatchSize = function (newBatchSize) {
|
|
210
|
+
AvoInspector._batchSize = newBatchSize;
|
|
211
|
+
};
|
|
212
|
+
AvoInspector.prototype.setBatchFlushSeconds = function (newBatchFlushSeconds) {
|
|
213
|
+
AvoInspector._batchFlushSeconds = newBatchFlushSeconds;
|
|
214
|
+
};
|
|
215
|
+
AvoInspector._batchSize = 30;
|
|
216
|
+
AvoInspector._batchFlushSeconds = 30;
|
|
217
|
+
AvoInspector._shouldLog = false;
|
|
218
|
+
return AvoInspector;
|
|
219
|
+
}());
|
|
220
|
+
exports.AvoInspector = AvoInspector;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const AvoInspectorEnv: {
|
|
2
|
+
readonly Prod: "prod";
|
|
3
|
+
readonly Dev: "dev";
|
|
4
|
+
readonly Staging: "staging";
|
|
5
|
+
};
|
|
6
|
+
export type AvoInspectorEnvType = typeof AvoInspectorEnv;
|
|
7
|
+
export type AvoInspectorEnvValueType = AvoInspectorEnvType[keyof AvoInspectorEnvType];
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AvoInstallationId = void 0;
|
|
4
|
+
var AvoGuid_1 = require("./AvoGuid");
|
|
5
|
+
var AvoInspector_1 = require("./AvoInspector");
|
|
6
|
+
var AvoInstallationId = /** @class */ (function () {
|
|
7
|
+
function AvoInstallationId() {
|
|
8
|
+
}
|
|
9
|
+
AvoInstallationId.getInstallationId = function () {
|
|
10
|
+
if (AvoInstallationId.installationId !== null) {
|
|
11
|
+
return AvoInstallationId.installationId;
|
|
12
|
+
}
|
|
13
|
+
if (!AvoInspector_1.AvoInspector.avoStorage.isInitialized()) {
|
|
14
|
+
return "unknown";
|
|
15
|
+
}
|
|
16
|
+
var maybeInstallationId = AvoInspector_1.AvoInspector.avoStorage.getItem(AvoInstallationId.cacheKey);
|
|
17
|
+
if (maybeInstallationId === null || maybeInstallationId === undefined) {
|
|
18
|
+
AvoInstallationId.installationId = AvoGuid_1.default.newGuid();
|
|
19
|
+
AvoInspector_1.AvoInspector.avoStorage.setItem(AvoInstallationId.cacheKey, AvoInstallationId.installationId);
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
AvoInstallationId.installationId = maybeInstallationId;
|
|
23
|
+
}
|
|
24
|
+
return AvoInstallationId.installationId;
|
|
25
|
+
};
|
|
26
|
+
Object.defineProperty(AvoInstallationId, "cacheKey", {
|
|
27
|
+
get: function () {
|
|
28
|
+
return "AvoInstallationId";
|
|
29
|
+
},
|
|
30
|
+
enumerable: false,
|
|
31
|
+
configurable: true
|
|
32
|
+
});
|
|
33
|
+
AvoInstallationId.installationId = null;
|
|
34
|
+
return AvoInstallationId;
|
|
35
|
+
}());
|
|
36
|
+
exports.AvoInstallationId = AvoInstallationId;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
export interface BaseBody {
|
|
2
|
+
apiKey: string;
|
|
3
|
+
appName: string;
|
|
4
|
+
appVersion: string;
|
|
5
|
+
libVersion: string;
|
|
6
|
+
env: string;
|
|
7
|
+
libPlatform: "web";
|
|
8
|
+
messageId: string;
|
|
9
|
+
trackingId: string;
|
|
10
|
+
createdAt: string;
|
|
11
|
+
sessionId: string;
|
|
12
|
+
samplingRate: number;
|
|
13
|
+
}
|
|
14
|
+
export interface SessionStartedBody extends BaseBody {
|
|
15
|
+
type: "sessionStarted";
|
|
16
|
+
}
|
|
17
|
+
export interface EventSchemaBody extends BaseBody {
|
|
18
|
+
type: "event";
|
|
19
|
+
eventName: string;
|
|
20
|
+
eventProperties: Array<{
|
|
21
|
+
propertyName: string;
|
|
22
|
+
propertyType: string;
|
|
23
|
+
children?: any;
|
|
24
|
+
}>;
|
|
25
|
+
avoFunction: boolean;
|
|
26
|
+
eventId: string | null;
|
|
27
|
+
eventHash: string | null;
|
|
28
|
+
}
|
|
29
|
+
export declare class AvoNetworkCallsHandler {
|
|
30
|
+
private apiKey;
|
|
31
|
+
private envName;
|
|
32
|
+
private appName;
|
|
33
|
+
private appVersion;
|
|
34
|
+
private libVersion;
|
|
35
|
+
private samplingRate;
|
|
36
|
+
private sending;
|
|
37
|
+
private static trackingEndpoint;
|
|
38
|
+
constructor(apiKey: string, envName: string, appName: string, appVersion: string, libVersion: string);
|
|
39
|
+
callInspectorWithBatchBody(inEvents: Array<SessionStartedBody | EventSchemaBody>, onCompleted: (error: string | null) => any): void;
|
|
40
|
+
private fixSessionAndTrackingIds;
|
|
41
|
+
bodyForSessionStartedCall(): SessionStartedBody;
|
|
42
|
+
bodyForEventSchemaCall(eventName: string, eventProperties: Array<{
|
|
43
|
+
propertyName: string;
|
|
44
|
+
propertyType: string;
|
|
45
|
+
children?: any;
|
|
46
|
+
}>, eventId: string | null, eventHash: string | null): EventSchemaBody;
|
|
47
|
+
private createBaseCallBody;
|
|
48
|
+
}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AvoNetworkCallsHandler = void 0;
|
|
4
|
+
var AvoGuid_1 = require("./AvoGuid");
|
|
5
|
+
var AvoSessionTracker_1 = require("./AvoSessionTracker");
|
|
6
|
+
var AvoInspector_1 = require("./AvoInspector");
|
|
7
|
+
var AvoInstallationId_1 = require("./AvoInstallationId");
|
|
8
|
+
var AvoNetworkCallsHandler = /** @class */ (function () {
|
|
9
|
+
function AvoNetworkCallsHandler(apiKey, envName, appName, appVersion, libVersion) {
|
|
10
|
+
this.samplingRate = 1.0;
|
|
11
|
+
this.sending = false;
|
|
12
|
+
this.apiKey = apiKey;
|
|
13
|
+
this.envName = envName;
|
|
14
|
+
this.appName = appName;
|
|
15
|
+
this.appVersion = appVersion;
|
|
16
|
+
this.libVersion = libVersion;
|
|
17
|
+
}
|
|
18
|
+
AvoNetworkCallsHandler.prototype.callInspectorWithBatchBody = function (inEvents, onCompleted) {
|
|
19
|
+
var _this = this;
|
|
20
|
+
if (this.sending) {
|
|
21
|
+
onCompleted("Batch sending cancelled because another batch sending is in progress. Your events will be sent with next batch.");
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
var events = inEvents.filter(function (x) { return x != null; });
|
|
25
|
+
this.fixSessionAndTrackingIds(events);
|
|
26
|
+
if (events.length === 0) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
if (Math.random() > this.samplingRate) {
|
|
30
|
+
if (AvoInspector_1.AvoInspector.shouldLog) {
|
|
31
|
+
console.log("Avo Inspector: last event schema dropped due to sampling rate.");
|
|
32
|
+
}
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
if (AvoInspector_1.AvoInspector.shouldLog) {
|
|
36
|
+
console.log("Avo Inspector: events", events);
|
|
37
|
+
events.forEach(function (event) {
|
|
38
|
+
if (event.type === "sessionStarted") {
|
|
39
|
+
console.log("Avo Inspector: sending session started event.");
|
|
40
|
+
}
|
|
41
|
+
else if (event.type === "event") {
|
|
42
|
+
var schemaEvent = event;
|
|
43
|
+
console.log("Avo Inspector: sending event " + schemaEvent.eventName + " with schema " + JSON.stringify(schemaEvent.eventProperties));
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
this.sending = true;
|
|
48
|
+
var xmlhttp = new XMLHttpRequest();
|
|
49
|
+
xmlhttp.open("POST", AvoNetworkCallsHandler.trackingEndpoint, true);
|
|
50
|
+
xmlhttp.setRequestHeader("Content-Type", "text/plain");
|
|
51
|
+
xmlhttp.send(JSON.stringify(events));
|
|
52
|
+
xmlhttp.onload = function () {
|
|
53
|
+
if (xmlhttp.status != 200) {
|
|
54
|
+
onCompleted("Error ".concat(xmlhttp.status, ": ").concat(xmlhttp.statusText));
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
var samplingRate = JSON.parse(xmlhttp.response).samplingRate;
|
|
58
|
+
if (samplingRate !== undefined) {
|
|
59
|
+
_this.samplingRate = samplingRate;
|
|
60
|
+
}
|
|
61
|
+
onCompleted(null);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
xmlhttp.onerror = function () {
|
|
65
|
+
onCompleted("Request failed");
|
|
66
|
+
};
|
|
67
|
+
xmlhttp.ontimeout = function () {
|
|
68
|
+
onCompleted("Request timed out");
|
|
69
|
+
};
|
|
70
|
+
this.sending = false;
|
|
71
|
+
};
|
|
72
|
+
AvoNetworkCallsHandler.prototype.fixSessionAndTrackingIds = function (events) {
|
|
73
|
+
var knownSessionId = null;
|
|
74
|
+
var knownTrackingId = null;
|
|
75
|
+
events.forEach(function (event) {
|
|
76
|
+
if (event.sessionId !== null && event.sessionId !== undefined && event.sessionId !== "unknown") {
|
|
77
|
+
knownSessionId = event.sessionId;
|
|
78
|
+
}
|
|
79
|
+
if (event.trackingId !== null && event.trackingId !== undefined && event.trackingId !== "unknown") {
|
|
80
|
+
knownTrackingId = event.trackingId;
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
events.forEach(function (event) {
|
|
84
|
+
if (event.sessionId === "unknown") {
|
|
85
|
+
if (knownSessionId != null) {
|
|
86
|
+
event.sessionId = knownSessionId;
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
event.sessionId = AvoSessionTracker_1.AvoSessionTracker.sessionId;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
if (event.trackingId === "unknown") {
|
|
93
|
+
if (knownTrackingId != null) {
|
|
94
|
+
event.trackingId = knownTrackingId;
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
event.trackingId = AvoInstallationId_1.AvoInstallationId.getInstallationId();
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
};
|
|
102
|
+
AvoNetworkCallsHandler.prototype.bodyForSessionStartedCall = function () {
|
|
103
|
+
var sessionBody = this.createBaseCallBody();
|
|
104
|
+
sessionBody.type = "sessionStarted";
|
|
105
|
+
return sessionBody;
|
|
106
|
+
};
|
|
107
|
+
AvoNetworkCallsHandler.prototype.bodyForEventSchemaCall = function (eventName, eventProperties, eventId, eventHash) {
|
|
108
|
+
var eventSchemaBody = this.createBaseCallBody();
|
|
109
|
+
eventSchemaBody.type = "event";
|
|
110
|
+
eventSchemaBody.eventName = eventName;
|
|
111
|
+
eventSchemaBody.eventProperties = eventProperties;
|
|
112
|
+
if (eventId != null) {
|
|
113
|
+
eventSchemaBody.avoFunction = true;
|
|
114
|
+
eventSchemaBody.eventId = eventId;
|
|
115
|
+
eventSchemaBody.eventHash = eventHash;
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
eventSchemaBody.avoFunction = false;
|
|
119
|
+
eventSchemaBody.eventId = null;
|
|
120
|
+
eventSchemaBody.eventHash = null;
|
|
121
|
+
}
|
|
122
|
+
return eventSchemaBody;
|
|
123
|
+
};
|
|
124
|
+
AvoNetworkCallsHandler.prototype.createBaseCallBody = function () {
|
|
125
|
+
return {
|
|
126
|
+
apiKey: this.apiKey,
|
|
127
|
+
appName: this.appName,
|
|
128
|
+
appVersion: this.appVersion,
|
|
129
|
+
libVersion: this.libVersion,
|
|
130
|
+
env: this.envName,
|
|
131
|
+
libPlatform: "web",
|
|
132
|
+
messageId: AvoGuid_1.default.newGuid(),
|
|
133
|
+
trackingId: AvoInstallationId_1.AvoInstallationId.getInstallationId(),
|
|
134
|
+
createdAt: new Date().toISOString(),
|
|
135
|
+
sessionId: AvoSessionTracker_1.AvoSessionTracker.sessionId,
|
|
136
|
+
samplingRate: this.samplingRate,
|
|
137
|
+
};
|
|
138
|
+
};
|
|
139
|
+
AvoNetworkCallsHandler.trackingEndpoint = "https://api.avo.app/inspector/v1/track";
|
|
140
|
+
return AvoNetworkCallsHandler;
|
|
141
|
+
}());
|
|
142
|
+
exports.AvoNetworkCallsHandler = AvoNetworkCallsHandler;
|