avo-inspector 2.1.0 → 2.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/.claude/settings.local.json +9 -0
- package/CHANGELOG.md +9 -0
- package/README.md +8 -0
- package/dist/AvoAnonymousId.d.ts +26 -0
- package/dist/AvoInspector.d.ts +0 -2
- package/dist/AvoNetworkCallsHandler.d.ts +2 -1
- package/dist/index.js +1 -1
- package/jest.config.js +23 -0
- package/package.json +1 -21
- package/dist-native/AvoBatcher.d.ts +0 -24
- package/dist-native/AvoBatcher.js +0 -82
- package/dist-native/AvoDeduplicator.d.ts +0 -36
- package/dist-native/AvoDeduplicator.js +0 -142
- package/dist-native/AvoGuid.d.ts +0 -3
- package/dist-native/AvoGuid.js +0 -14
- package/dist-native/AvoInspector.d.ts +0 -52
- package/dist-native/AvoInspector.js +0 -220
- package/dist-native/AvoInspectorEnv.d.ts +0 -7
- package/dist-native/AvoInspectorEnv.js +0 -8
- package/dist-native/AvoInstallationId.d.ts +0 -5
- package/dist-native/AvoInstallationId.js +0 -36
- package/dist-native/AvoNetworkCallsHandler.d.ts +0 -48
- package/dist-native/AvoNetworkCallsHandler.js +0 -142
- package/dist-native/AvoSchemaParser.d.ts +0 -11
- package/dist-native/AvoSchemaParser.js +0 -95
- package/dist-native/AvoSessionTracker.d.ts +0 -15
- package/dist-native/AvoSessionTracker.js +0 -104
- package/dist-native/AvoStorage.d.ts +0 -22
- package/dist-native/AvoStorage.js +0 -336
- package/dist-native/__mocks__/xhr.d.ts +0 -12
- package/dist-native/__mocks__/xhr.js +0 -14
- package/dist-native/__mocks__/xhrError.d.ts +0 -12
- package/dist-native/__mocks__/xhrError.js +0 -14
- package/dist-native/__tests__/AvoInspector.d.ts +0 -1
- package/dist-native/__tests__/AvoInspector.js +0 -207
- package/dist-native/__tests__/Batcher.d.ts +0 -1
- package/dist-native/__tests__/Batcher.js +0 -280
- package/dist-native/__tests__/BatcherPublic.d.ts +0 -1
- package/dist-native/__tests__/BatcherPublic.js +0 -82
- package/dist-native/__tests__/Deduplicator.d.ts +0 -1
- package/dist-native/__tests__/Deduplicator.js +0 -111
- package/dist-native/__tests__/InstallationId.d.ts +0 -1
- package/dist-native/__tests__/InstallationId.js +0 -40
- package/dist-native/__tests__/NetworkCallsHandler.d.ts +0 -1
- package/dist-native/__tests__/NetworkCallsHandler.js +0 -132
- package/dist-native/__tests__/Parsing.d.ts +0 -1
- package/dist-native/__tests__/Parsing.js +0 -115
- package/dist-native/__tests__/Sessions.d.ts +0 -1
- package/dist-native/__tests__/Sessions.js +0 -179
- package/dist-native/__tests__/Storage.d.ts +0 -1
- package/dist-native/__tests__/Storage.js +0 -173
- package/dist-native/__tests__/constants.d.ts +0 -36
- package/dist-native/__tests__/constants.js +0 -47
- package/dist-native/index.d.ts +0 -2
- package/dist-native/index.js +0 -7
- package/dist-native/utils.d.ts +0 -3
- package/dist-native/utils.js +0 -42
|
@@ -1,220 +0,0 @@
|
|
|
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;
|
|
@@ -1,7 +0,0 @@
|
|
|
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];
|
|
@@ -1,36 +0,0 @@
|
|
|
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;
|
|
@@ -1,48 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,142 +0,0 @@
|
|
|
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;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export declare class AvoSchemaParser {
|
|
2
|
-
static extractSchema(eventProperties: {
|
|
3
|
-
[propName: string]: any;
|
|
4
|
-
}): Array<{
|
|
5
|
-
propertyName: string;
|
|
6
|
-
propertyType: string;
|
|
7
|
-
children?: any;
|
|
8
|
-
}>;
|
|
9
|
-
private static removeDuplicates;
|
|
10
|
-
private static getPropValueType;
|
|
11
|
-
}
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AvoSchemaParser = void 0;
|
|
4
|
-
var isArray = function (obj) {
|
|
5
|
-
return Object.prototype.toString.call(obj) === "[object Array]";
|
|
6
|
-
};
|
|
7
|
-
var AvoSchemaParser = /** @class */ (function () {
|
|
8
|
-
function AvoSchemaParser() {
|
|
9
|
-
}
|
|
10
|
-
AvoSchemaParser.extractSchema = function (eventProperties) {
|
|
11
|
-
var _this = this;
|
|
12
|
-
if (eventProperties === null || eventProperties === undefined) {
|
|
13
|
-
return [];
|
|
14
|
-
}
|
|
15
|
-
var mapping = function (object) {
|
|
16
|
-
if (isArray(object)) {
|
|
17
|
-
var list = object.map(function (x) {
|
|
18
|
-
return mapping(x);
|
|
19
|
-
});
|
|
20
|
-
return _this.removeDuplicates(list);
|
|
21
|
-
}
|
|
22
|
-
else if (typeof object === "object") {
|
|
23
|
-
var mappedResult = [];
|
|
24
|
-
for (var key in object) {
|
|
25
|
-
if (object.hasOwnProperty(key)) {
|
|
26
|
-
var val = object[key];
|
|
27
|
-
var mappedEntry = {
|
|
28
|
-
propertyName: key,
|
|
29
|
-
propertyType: _this.getPropValueType(val),
|
|
30
|
-
};
|
|
31
|
-
if (typeof val === "object" && val != null) {
|
|
32
|
-
mappedEntry["children"] = mapping(val);
|
|
33
|
-
}
|
|
34
|
-
mappedResult.push(mappedEntry);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
return mappedResult;
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
return _this.getPropValueType(object);
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
var mappedEventProps = mapping(eventProperties);
|
|
44
|
-
return mappedEventProps;
|
|
45
|
-
};
|
|
46
|
-
AvoSchemaParser.removeDuplicates = function (array) {
|
|
47
|
-
// XXX TODO fix any types
|
|
48
|
-
var primitives = { boolean: {}, number: {}, string: {} };
|
|
49
|
-
var objects = [];
|
|
50
|
-
return array.filter(function (item) {
|
|
51
|
-
var type = typeof item;
|
|
52
|
-
if (type in primitives) {
|
|
53
|
-
return primitives[type].hasOwnProperty(item)
|
|
54
|
-
? false
|
|
55
|
-
: (primitives[type][item] = true);
|
|
56
|
-
}
|
|
57
|
-
else {
|
|
58
|
-
return objects.indexOf(item) >= 0 ? false : objects.push(item);
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
};
|
|
62
|
-
AvoSchemaParser.getPropValueType = function (propValue) {
|
|
63
|
-
var propType = typeof propValue;
|
|
64
|
-
if (propValue == null) {
|
|
65
|
-
return "null";
|
|
66
|
-
}
|
|
67
|
-
else if (propType === "string") {
|
|
68
|
-
return "string";
|
|
69
|
-
}
|
|
70
|
-
else if (propType === "number" || propType === "bigint") {
|
|
71
|
-
if ((propValue + "").indexOf(".") >= 0) {
|
|
72
|
-
return "float";
|
|
73
|
-
}
|
|
74
|
-
else {
|
|
75
|
-
return "int";
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
else if (propType === "boolean") {
|
|
79
|
-
return "boolean";
|
|
80
|
-
}
|
|
81
|
-
else if (propType === "object") {
|
|
82
|
-
if (isArray(propValue)) {
|
|
83
|
-
return "list";
|
|
84
|
-
}
|
|
85
|
-
else {
|
|
86
|
-
return "object";
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
else {
|
|
90
|
-
return "unknown";
|
|
91
|
-
}
|
|
92
|
-
};
|
|
93
|
-
return AvoSchemaParser;
|
|
94
|
-
}());
|
|
95
|
-
exports.AvoSchemaParser = AvoSchemaParser;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { AvoBatcherType } from "./AvoBatcher";
|
|
2
|
-
export declare class AvoSessionTracker {
|
|
3
|
-
private static _sessionId;
|
|
4
|
-
static get sessionId(): string;
|
|
5
|
-
private _lastSessionTimestamp;
|
|
6
|
-
get lastSessionTimestamp(): number;
|
|
7
|
-
private _sessionLengthMillis;
|
|
8
|
-
get sessionLengthMillis(): number;
|
|
9
|
-
private avoBatcher;
|
|
10
|
-
constructor(avoBatcher: AvoBatcherType);
|
|
11
|
-
startOrProlongSession(atTime: number): void;
|
|
12
|
-
private static updateSessionId;
|
|
13
|
-
static get lastSessionTimestampKey(): string;
|
|
14
|
-
static get idCacheKey(): string;
|
|
15
|
-
}
|