avo-inspector 3.2.0 → 3.2.3
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 +10 -0
- package/dist/AvoBatcher.d.ts +9 -3
- package/dist/AvoInspector.d.ts +4 -0
- package/dist/AvoNetworkCallsHandler.d.ts +80 -5
- package/dist/__tests__/UnboundPublicMethods_test.d.ts +1 -0
- package/dist/__tests__/constants.d.ts +2 -1
- package/dist/__tests__/helpers/internalGateway.d.ts +23 -0
- package/dist/eventSpec/AvoEventSpecCache.d.ts +7 -4
- package/dist/eventSpec/AvoEventSpecFetchTypes.d.ts +12 -1
- package/dist/eventSpec/AvoEventSpecFetcher.d.ts +6 -1
- package/dist/index.js +1 -1
- package/dist/lite/AvoBatcherLite.d.ts +9 -3
- package/dist/lite/AvoBatcherLite.js +46 -7
- package/dist/lite/AvoInspectorLite.d.ts +2 -0
- package/dist/lite/AvoInspectorLite.js +95 -15
- package/dist/lite/AvoNetworkCallsHandlerLite.d.ts +79 -5
- package/dist/lite/AvoNetworkCallsHandlerLite.js +300 -20
- package/package.json +10 -1
- package/dist/AvoBatcher.js +0 -87
- package/dist/AvoDeduplicator.js +0 -142
- package/dist/AvoEncryption.js +0 -176
- package/dist/AvoInspector.js +0 -435
- package/dist/AvoNetworkCallsHandler.js +0 -229
- package/dist/AvoSchemaParser.js +0 -95
- package/dist/AvoStreamId.js +0 -82
- package/dist/__mocks__/xhr.js +0 -14
- package/dist/__mocks__/xhrError.js +0 -14
- package/dist/__tests__/AvoEncryption.js +0 -272
- package/dist/__tests__/AvoEncryptionIntegration.js +0 -191
- package/dist/__tests__/AvoEventSpecFetcher.js +0 -377
- package/dist/__tests__/AvoInspector.js +0 -335
- package/dist/__tests__/Batcher.js +0 -214
- package/dist/__tests__/BatcherPublic.js +0 -139
- package/dist/__tests__/Deduplicator.js +0 -190
- package/dist/__tests__/EventSpecCache.js +0 -143
- package/dist/__tests__/EventValidator.js +0 -543
- package/dist/__tests__/InstallationId.js +0 -60
- package/dist/__tests__/NetworkCallsHandler.js +0 -222
- package/dist/__tests__/NetworkCallsHandlerModelA.js +0 -206
- package/dist/__tests__/Parsing.js +0 -115
- package/dist/__tests__/Sessions.d.ts +0 -1
- package/dist/__tests__/Sessions.js +0 -10
- package/dist/__tests__/Storage.d.ts +0 -1
- package/dist/__tests__/Storage.js +0 -173
- package/dist/__tests__/StreamId.d.ts +0 -1
- package/dist/__tests__/StreamId.js +0 -153
- package/dist/__tests__/constants.js +0 -48
- package/dist/esm/AvoBatcher.js +0 -75
- package/dist/esm/AvoDeduplicator.js +0 -137
- package/dist/esm/AvoEncryption.js +0 -277
- package/dist/esm/AvoGuid.js +0 -9
- package/dist/esm/AvoInspector.js +0 -470
- package/dist/esm/AvoInspectorEnv.js +0 -5
- package/dist/esm/AvoNetworkCallsHandler.js +0 -181
- package/dist/esm/AvoSchemaParser.js +0 -128
- package/dist/esm/AvoStorage.js +0 -176
- package/dist/esm/AvoStreamId.js +0 -140
- package/dist/esm/eventSpec/AvoEventSpecCache.js +0 -165
- package/dist/esm/eventSpec/AvoEventSpecFetchTypes.js +0 -6
- package/dist/esm/eventSpec/AvoEventSpecFetcher.js +0 -203
- package/dist/esm/eventSpec/EventValidator.js +0 -687
- package/dist/esm/eventSpec/index.js +0 -4
- package/dist/esm/index.js +0 -3
- package/dist/esm/utils.js +0 -38
- package/dist/esm/version.js +0 -2
- package/dist/eventSpec/AvoEventSpecCache.js +0 -181
- package/dist/eventSpec/AvoEventSpecFetcher.js +0 -290
- package/dist/eventSpec/EventValidator.js +0 -846
- package/dist/eventSpec/index.js +0 -20
- package/dist/version.d.ts +0 -1
- package/dist/version.js +0 -5
- /package/dist/__tests__/{AvoEncryption.d.ts → ApiKeyHeaderInjection_test.d.ts} +0 -0
- /package/dist/__tests__/{AvoEncryptionIntegration.d.ts → BrowserBootstrap_test.d.ts} +0 -0
- /package/dist/__tests__/{AvoEventSpecFetcher.d.ts → EventSpecGatewayCoordinates_test.d.ts} +0 -0
- /package/dist/__tests__/{AvoInspector.d.ts → InFlightQueueGaps_test.d.ts} +0 -0
- /package/dist/__tests__/{Batcher.d.ts → InFlightQueue_test.d.ts} +0 -0
- /package/dist/__tests__/{BatcherPublic.d.ts → NetworkCallsHandlerLite_test.d.ts} +0 -0
- /package/dist/__tests__/{Deduplicator.d.ts → PublicSurface_test.d.ts} +0 -0
- /package/dist/__tests__/{EventSpecCache.d.ts → TrackOptionsIntegration_test.d.ts} +0 -0
- /package/dist/__tests__/{EventValidator.d.ts → TrackOptionsTransport_test.d.ts} +0 -0
- /package/dist/__tests__/{InstallationId.d.ts → TrackingHeaders_test.d.ts} +0 -0
- /package/dist/__tests__/{NetworkCallsHandler.d.ts → V1WireBaseline_test.d.ts} +0 -0
- /package/dist/__tests__/{NetworkCallsHandlerModelA.d.ts → V2QueuedAttribution_test.d.ts} +0 -0
- /package/dist/__tests__/{Parsing.d.ts → V2StopSending_test.d.ts} +0 -0
|
@@ -1,222 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
-
});
|
|
21
|
-
};
|
|
22
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
24
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
-
function step(op) {
|
|
27
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
29
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
30
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
-
switch (op[0]) {
|
|
32
|
-
case 0: case 1: t = op; break;
|
|
33
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
-
default:
|
|
37
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
-
if (t[2]) _.ops.pop();
|
|
42
|
-
_.trys.pop(); continue;
|
|
43
|
-
}
|
|
44
|
-
op = body.call(thisArg, _);
|
|
45
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
|
-
var AvoGuid_1 = require("../AvoGuid");
|
|
51
|
-
var AvoStreamId_1 = require("../AvoStreamId");
|
|
52
|
-
var AvoNetworkCallsHandler_1 = require("../AvoNetworkCallsHandler");
|
|
53
|
-
var xhr_1 = require("../__mocks__/xhr");
|
|
54
|
-
var constants_1 = require("./constants");
|
|
55
|
-
var inspectorVersion = process.env.npm_package_version || "";
|
|
56
|
-
describe("NetworkCallsHandler", function () {
|
|
57
|
-
var apiKey = constants_1.defaultOptions.apiKey, env = constants_1.defaultOptions.env, version = constants_1.defaultOptions.version;
|
|
58
|
-
var appName = "";
|
|
59
|
-
var networkHandler;
|
|
60
|
-
var baseBody;
|
|
61
|
-
var customCallback = jest.fn();
|
|
62
|
-
var now = new Date();
|
|
63
|
-
beforeAll(function () {
|
|
64
|
-
// @ts-ignore
|
|
65
|
-
jest.spyOn(global, "Date").mockImplementation(function () { return now; });
|
|
66
|
-
jest
|
|
67
|
-
.spyOn(AvoStreamId_1.AvoStreamId, "initialize")
|
|
68
|
-
.mockResolvedValue(constants_1.mockedReturns.ANONYMOUS_ID);
|
|
69
|
-
jest
|
|
70
|
-
.spyOn(AvoGuid_1.default, "newGuid")
|
|
71
|
-
.mockImplementation(function () { return constants_1.mockedReturns.GUID; });
|
|
72
|
-
networkHandler = new AvoNetworkCallsHandler_1.AvoNetworkCallsHandler(apiKey, env, "", version, inspectorVersion);
|
|
73
|
-
baseBody = {
|
|
74
|
-
apiKey: apiKey,
|
|
75
|
-
appName: appName,
|
|
76
|
-
appVersion: version,
|
|
77
|
-
libVersion: inspectorVersion,
|
|
78
|
-
env: env,
|
|
79
|
-
libPlatform: "react-native",
|
|
80
|
-
messageId: constants_1.mockedReturns.GUID,
|
|
81
|
-
trackingId: "",
|
|
82
|
-
sessionId: "",
|
|
83
|
-
anonymousId: constants_1.mockedReturns.ANONYMOUS_ID,
|
|
84
|
-
createdAt: new Date().toISOString(),
|
|
85
|
-
samplingRate: 1.0,
|
|
86
|
-
};
|
|
87
|
-
});
|
|
88
|
-
afterEach(function () {
|
|
89
|
-
jest.clearAllMocks();
|
|
90
|
-
});
|
|
91
|
-
test("bodyForEventSchemaCall returns base body + event schema used for event sending from non avo functions", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
92
|
-
var eventName, eventProperties, body;
|
|
93
|
-
return __generator(this, function (_a) {
|
|
94
|
-
switch (_a.label) {
|
|
95
|
-
case 0:
|
|
96
|
-
eventName = "event name";
|
|
97
|
-
eventProperties = [{ propertyName: "prop0", propertyType: "string" }];
|
|
98
|
-
return [4 /*yield*/, networkHandler.bodyForEventSchemaCall(eventName, eventProperties, null, null)];
|
|
99
|
-
case 1:
|
|
100
|
-
body = _a.sent();
|
|
101
|
-
expect(body).toEqual(__assign(__assign({}, baseBody), { type: "event", eventName: eventName, eventProperties: eventProperties, avoFunction: false, eventId: null, eventHash: null }));
|
|
102
|
-
return [2 /*return*/];
|
|
103
|
-
}
|
|
104
|
-
});
|
|
105
|
-
}); });
|
|
106
|
-
test("bodyForEventSchemaCall returns base body + event schema used for event sending from avo functions", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
107
|
-
var eventName, eventId, eventHash, eventProperties, body;
|
|
108
|
-
return __generator(this, function (_a) {
|
|
109
|
-
switch (_a.label) {
|
|
110
|
-
case 0:
|
|
111
|
-
eventName = "event name";
|
|
112
|
-
eventId = "event id";
|
|
113
|
-
eventHash = "event hash";
|
|
114
|
-
eventProperties = [{ propertyName: "prop0", propertyType: "string" }];
|
|
115
|
-
return [4 /*yield*/, networkHandler.bodyForEventSchemaCall(eventName, eventProperties, eventId, eventHash)];
|
|
116
|
-
case 1:
|
|
117
|
-
body = _a.sent();
|
|
118
|
-
expect(body).toEqual(__assign(__assign({}, baseBody), { type: "event", eventName: eventName, eventProperties: eventProperties, avoFunction: true, eventId: eventId, eventHash: eventHash }));
|
|
119
|
-
return [2 /*return*/];
|
|
120
|
-
}
|
|
121
|
-
});
|
|
122
|
-
}); });
|
|
123
|
-
test("POST request is not sent if event list is empty", function () {
|
|
124
|
-
var events = [];
|
|
125
|
-
networkHandler.callInspectorWithBatchBody(events, customCallback);
|
|
126
|
-
expect(xhr_1.default.open).not.toBeCalled();
|
|
127
|
-
});
|
|
128
|
-
test("callInspectorWithBatchBody sends POST request", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
129
|
-
var eventName, eventProperties, eventBody, events;
|
|
130
|
-
return __generator(this, function (_a) {
|
|
131
|
-
switch (_a.label) {
|
|
132
|
-
case 0:
|
|
133
|
-
eventName = "event name";
|
|
134
|
-
eventProperties = [{ propertyName: "prop0", propertyType: "string" }];
|
|
135
|
-
return [4 /*yield*/, networkHandler.bodyForEventSchemaCall(eventName, eventProperties, null, null)];
|
|
136
|
-
case 1:
|
|
137
|
-
eventBody = _a.sent();
|
|
138
|
-
events = [eventBody];
|
|
139
|
-
networkHandler.callInspectorWithBatchBody(events, customCallback);
|
|
140
|
-
expect(xhr_1.default.open).toBeCalledTimes(1);
|
|
141
|
-
expect(xhr_1.default.open).toBeCalledWith("POST", constants_1.trackingEndpoint, true);
|
|
142
|
-
expect(xhr_1.default.setRequestHeader).toBeCalledWith("Content-Type", "application/json");
|
|
143
|
-
expect(xhr_1.default.send).toBeCalledTimes(1);
|
|
144
|
-
expect(xhr_1.default.send).toBeCalledWith(JSON.stringify(events));
|
|
145
|
-
xhr_1.default.onload();
|
|
146
|
-
expect(customCallback).toBeCalledTimes(1);
|
|
147
|
-
expect(customCallback).toBeCalledWith(null);
|
|
148
|
-
return [2 /*return*/];
|
|
149
|
-
}
|
|
150
|
-
});
|
|
151
|
-
}); });
|
|
152
|
-
test("Custom callback is called when 200 OK", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
153
|
-
var eventBody, events;
|
|
154
|
-
return __generator(this, function (_a) {
|
|
155
|
-
switch (_a.label) {
|
|
156
|
-
case 0: return [4 /*yield*/, networkHandler.bodyForEventSchemaCall("test", [], null, null)];
|
|
157
|
-
case 1:
|
|
158
|
-
eventBody = _a.sent();
|
|
159
|
-
events = [eventBody];
|
|
160
|
-
networkHandler.callInspectorWithBatchBody(events, customCallback);
|
|
161
|
-
xhr_1.default.onload();
|
|
162
|
-
expect(customCallback).toBeCalledTimes(1);
|
|
163
|
-
expect(customCallback).toBeCalledWith(null);
|
|
164
|
-
return [2 /*return*/];
|
|
165
|
-
}
|
|
166
|
-
});
|
|
167
|
-
}); });
|
|
168
|
-
test("Custom callback is called with error when not 200 OK", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
169
|
-
var xhrErrorMock, eventBody, events;
|
|
170
|
-
return __generator(this, function (_a) {
|
|
171
|
-
switch (_a.label) {
|
|
172
|
-
case 0:
|
|
173
|
-
xhrErrorMock = require("../__mocks__/xhrError").default;
|
|
174
|
-
return [4 /*yield*/, networkHandler.bodyForEventSchemaCall("test", [], null, null)];
|
|
175
|
-
case 1:
|
|
176
|
-
eventBody = _a.sent();
|
|
177
|
-
events = [eventBody];
|
|
178
|
-
networkHandler.callInspectorWithBatchBody(events, customCallback);
|
|
179
|
-
xhrErrorMock.onload();
|
|
180
|
-
expect(customCallback).toBeCalledTimes(1);
|
|
181
|
-
expect(customCallback).toBeCalledWith("Error 400: Bad Request");
|
|
182
|
-
return [2 /*return*/];
|
|
183
|
-
}
|
|
184
|
-
});
|
|
185
|
-
}); });
|
|
186
|
-
test("Custom callback is called onerror", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
187
|
-
var xhrErrorMock, eventBody, events;
|
|
188
|
-
return __generator(this, function (_a) {
|
|
189
|
-
switch (_a.label) {
|
|
190
|
-
case 0:
|
|
191
|
-
xhrErrorMock = require("../__mocks__/xhrError").default;
|
|
192
|
-
return [4 /*yield*/, networkHandler.bodyForEventSchemaCall("test", [], null, null)];
|
|
193
|
-
case 1:
|
|
194
|
-
eventBody = _a.sent();
|
|
195
|
-
events = [eventBody];
|
|
196
|
-
networkHandler.callInspectorWithBatchBody(events, customCallback);
|
|
197
|
-
xhrErrorMock.onerror();
|
|
198
|
-
expect(customCallback).toBeCalledTimes(1);
|
|
199
|
-
expect(customCallback).toBeCalledWith(constants_1.requestMsg.ERROR);
|
|
200
|
-
return [2 /*return*/];
|
|
201
|
-
}
|
|
202
|
-
});
|
|
203
|
-
}); });
|
|
204
|
-
test("Custom callback is called ontimeout", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
205
|
-
var xhrErrorMock, eventBody, events;
|
|
206
|
-
return __generator(this, function (_a) {
|
|
207
|
-
switch (_a.label) {
|
|
208
|
-
case 0:
|
|
209
|
-
xhrErrorMock = require("../__mocks__/xhrError").default;
|
|
210
|
-
return [4 /*yield*/, networkHandler.bodyForEventSchemaCall("test", [], null, null)];
|
|
211
|
-
case 1:
|
|
212
|
-
eventBody = _a.sent();
|
|
213
|
-
events = [eventBody];
|
|
214
|
-
networkHandler.callInspectorWithBatchBody(events, customCallback);
|
|
215
|
-
xhrErrorMock.ontimeout();
|
|
216
|
-
expect(customCallback).toBeCalledTimes(1);
|
|
217
|
-
expect(customCallback).toBeCalledWith(constants_1.requestMsg.TIMEOUT);
|
|
218
|
-
return [2 /*return*/];
|
|
219
|
-
}
|
|
220
|
-
});
|
|
221
|
-
}); });
|
|
222
|
-
});
|
|
@@ -1,206 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
-
});
|
|
21
|
-
};
|
|
22
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
24
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
-
function step(op) {
|
|
27
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
29
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
30
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
-
switch (op[0]) {
|
|
32
|
-
case 0: case 1: t = op; break;
|
|
33
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
-
default:
|
|
37
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
-
if (t[2]) _.ops.pop();
|
|
42
|
-
_.trys.pop(); continue;
|
|
43
|
-
}
|
|
44
|
-
op = body.call(thisArg, _);
|
|
45
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
|
-
var AvoGuid_1 = require("../AvoGuid");
|
|
51
|
-
var AvoStreamId_1 = require("../AvoStreamId");
|
|
52
|
-
var AvoNetworkCallsHandler_1 = require("../AvoNetworkCallsHandler");
|
|
53
|
-
var xhr_1 = require("../__mocks__/xhr");
|
|
54
|
-
var constants_1 = require("./constants");
|
|
55
|
-
var inspectorVersion = process.env.npm_package_version || "";
|
|
56
|
-
describe("NetworkCallsHandler Model A", function () {
|
|
57
|
-
var apiKey = constants_1.defaultOptions.apiKey, env = constants_1.defaultOptions.env, version = constants_1.defaultOptions.version;
|
|
58
|
-
var appName = "";
|
|
59
|
-
var networkHandler;
|
|
60
|
-
var baseBody;
|
|
61
|
-
var customCallback = jest.fn();
|
|
62
|
-
var now = new Date();
|
|
63
|
-
beforeAll(function () {
|
|
64
|
-
// @ts-ignore
|
|
65
|
-
jest.spyOn(global, "Date").mockImplementation(function () { return now; });
|
|
66
|
-
jest
|
|
67
|
-
.spyOn(AvoStreamId_1.AvoStreamId, "initialize")
|
|
68
|
-
.mockResolvedValue(constants_1.mockedReturns.ANONYMOUS_ID);
|
|
69
|
-
jest
|
|
70
|
-
.spyOn(AvoGuid_1.default, "newGuid")
|
|
71
|
-
.mockImplementation(function () { return constants_1.mockedReturns.GUID; });
|
|
72
|
-
networkHandler = new AvoNetworkCallsHandler_1.AvoNetworkCallsHandler(apiKey, env, "", version, inspectorVersion);
|
|
73
|
-
baseBody = {
|
|
74
|
-
apiKey: apiKey,
|
|
75
|
-
appName: appName,
|
|
76
|
-
appVersion: version,
|
|
77
|
-
libVersion: inspectorVersion,
|
|
78
|
-
env: env,
|
|
79
|
-
libPlatform: "react-native",
|
|
80
|
-
messageId: constants_1.mockedReturns.GUID,
|
|
81
|
-
trackingId: "",
|
|
82
|
-
sessionId: "",
|
|
83
|
-
anonymousId: constants_1.mockedReturns.ANONYMOUS_ID,
|
|
84
|
-
createdAt: new Date().toISOString(),
|
|
85
|
-
samplingRate: 1.0,
|
|
86
|
-
};
|
|
87
|
-
});
|
|
88
|
-
afterEach(function () {
|
|
89
|
-
jest.clearAllMocks();
|
|
90
|
-
});
|
|
91
|
-
test("BaseBody contains anonymousId field", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
92
|
-
var body;
|
|
93
|
-
return __generator(this, function (_a) {
|
|
94
|
-
switch (_a.label) {
|
|
95
|
-
case 0: return [4 /*yield*/, networkHandler.bodyForEventSchemaCall("test event", [], null, null)];
|
|
96
|
-
case 1:
|
|
97
|
-
body = _a.sent();
|
|
98
|
-
expect(body).toHaveProperty("anonymousId");
|
|
99
|
-
return [2 /*return*/];
|
|
100
|
-
}
|
|
101
|
-
});
|
|
102
|
-
}); });
|
|
103
|
-
test("BaseBody contains empty sessionId field", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
104
|
-
var body;
|
|
105
|
-
return __generator(this, function (_a) {
|
|
106
|
-
switch (_a.label) {
|
|
107
|
-
case 0: return [4 /*yield*/, networkHandler.bodyForEventSchemaCall("test event", [], null, null)];
|
|
108
|
-
case 1:
|
|
109
|
-
body = _a.sent();
|
|
110
|
-
expect(body).toHaveProperty("sessionId", "");
|
|
111
|
-
return [2 /*return*/];
|
|
112
|
-
}
|
|
113
|
-
});
|
|
114
|
-
}); });
|
|
115
|
-
test("BaseBody contains empty trackingId field", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
116
|
-
var body;
|
|
117
|
-
return __generator(this, function (_a) {
|
|
118
|
-
switch (_a.label) {
|
|
119
|
-
case 0: return [4 /*yield*/, networkHandler.bodyForEventSchemaCall("test event", [], null, null)];
|
|
120
|
-
case 1:
|
|
121
|
-
body = _a.sent();
|
|
122
|
-
expect(body).toHaveProperty("trackingId", "");
|
|
123
|
-
return [2 /*return*/];
|
|
124
|
-
}
|
|
125
|
-
});
|
|
126
|
-
}); });
|
|
127
|
-
test("libPlatform is 'react-native'", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
128
|
-
var body;
|
|
129
|
-
return __generator(this, function (_a) {
|
|
130
|
-
switch (_a.label) {
|
|
131
|
-
case 0: return [4 /*yield*/, networkHandler.bodyForEventSchemaCall("test event", [], null, null)];
|
|
132
|
-
case 1:
|
|
133
|
-
body = _a.sent();
|
|
134
|
-
expect(body.libPlatform).toBe("react-native");
|
|
135
|
-
return [2 /*return*/];
|
|
136
|
-
}
|
|
137
|
-
});
|
|
138
|
-
}); });
|
|
139
|
-
test("bodyForEventSchemaCall returns base body + event schema from non avo functions", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
140
|
-
var eventName, eventProperties, body;
|
|
141
|
-
return __generator(this, function (_a) {
|
|
142
|
-
switch (_a.label) {
|
|
143
|
-
case 0:
|
|
144
|
-
eventName = "event name";
|
|
145
|
-
eventProperties = [{ propertyName: "prop0", propertyType: "string" }];
|
|
146
|
-
return [4 /*yield*/, networkHandler.bodyForEventSchemaCall(eventName, eventProperties, null, null)];
|
|
147
|
-
case 1:
|
|
148
|
-
body = _a.sent();
|
|
149
|
-
expect(body).toEqual(__assign(__assign({}, baseBody), { type: "event", eventName: eventName, eventProperties: eventProperties, avoFunction: false, eventId: null, eventHash: null }));
|
|
150
|
-
return [2 /*return*/];
|
|
151
|
-
}
|
|
152
|
-
});
|
|
153
|
-
}); });
|
|
154
|
-
test("bodyForEventSchemaCall returns base body + event schema from avo functions", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
155
|
-
var eventName, eventId, eventHash, eventProperties, body;
|
|
156
|
-
return __generator(this, function (_a) {
|
|
157
|
-
switch (_a.label) {
|
|
158
|
-
case 0:
|
|
159
|
-
eventName = "event name";
|
|
160
|
-
eventId = "event id";
|
|
161
|
-
eventHash = "event hash";
|
|
162
|
-
eventProperties = [{ propertyName: "prop0", propertyType: "string" }];
|
|
163
|
-
return [4 /*yield*/, networkHandler.bodyForEventSchemaCall(eventName, eventProperties, eventId, eventHash)];
|
|
164
|
-
case 1:
|
|
165
|
-
body = _a.sent();
|
|
166
|
-
expect(body).toEqual(__assign(__assign({}, baseBody), { type: "event", eventName: eventName, eventProperties: eventProperties, avoFunction: true, eventId: eventId, eventHash: eventHash }));
|
|
167
|
-
return [2 /*return*/];
|
|
168
|
-
}
|
|
169
|
-
});
|
|
170
|
-
}); });
|
|
171
|
-
test("bodyForSessionStartedCall does NOT exist", function () {
|
|
172
|
-
expect(networkHandler.bodyForSessionStartedCall).toBeUndefined();
|
|
173
|
-
});
|
|
174
|
-
test("fixSessionAndTrackingIds does NOT exist", function () {
|
|
175
|
-
expect(networkHandler.fixSessionAndTrackingIds).toBeUndefined();
|
|
176
|
-
});
|
|
177
|
-
test("POST request is not sent if event list is empty", function () {
|
|
178
|
-
var events = [];
|
|
179
|
-
networkHandler.callInspectorWithBatchBody(events, customCallback);
|
|
180
|
-
expect(xhr_1.default.open).not.toBeCalled();
|
|
181
|
-
});
|
|
182
|
-
test("callInspectorWithBatchBody sends POST request", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
183
|
-
var eventName, eventProperties, eventBody, events;
|
|
184
|
-
return __generator(this, function (_a) {
|
|
185
|
-
switch (_a.label) {
|
|
186
|
-
case 0:
|
|
187
|
-
eventName = "event name";
|
|
188
|
-
eventProperties = [{ propertyName: "prop0", propertyType: "string" }];
|
|
189
|
-
return [4 /*yield*/, networkHandler.bodyForEventSchemaCall(eventName, eventProperties, null, null)];
|
|
190
|
-
case 1:
|
|
191
|
-
eventBody = _a.sent();
|
|
192
|
-
events = [eventBody];
|
|
193
|
-
networkHandler.callInspectorWithBatchBody(events, customCallback);
|
|
194
|
-
expect(xhr_1.default.open).toBeCalledTimes(1);
|
|
195
|
-
expect(xhr_1.default.open).toBeCalledWith("POST", constants_1.trackingEndpoint, true);
|
|
196
|
-
expect(xhr_1.default.setRequestHeader).toBeCalledWith("Content-Type", "application/json");
|
|
197
|
-
expect(xhr_1.default.send).toBeCalledTimes(1);
|
|
198
|
-
expect(xhr_1.default.send).toBeCalledWith(JSON.stringify(events));
|
|
199
|
-
xhr_1.default.onload();
|
|
200
|
-
expect(customCallback).toBeCalledTimes(1);
|
|
201
|
-
expect(customCallback).toBeCalledWith(null);
|
|
202
|
-
return [2 /*return*/];
|
|
203
|
-
}
|
|
204
|
-
});
|
|
205
|
-
}); });
|
|
206
|
-
});
|
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
var AvoInspector_1 = require("../AvoInspector");
|
|
4
|
-
var constants_1 = require("../__tests__/constants");
|
|
5
|
-
describe("Schema Parsing", function () {
|
|
6
|
-
var inspector = new AvoInspector_1.AvoInspector(constants_1.defaultOptions);
|
|
7
|
-
beforeAll(function () {
|
|
8
|
-
inspector.enableLogging(false);
|
|
9
|
-
});
|
|
10
|
-
test("Empty array returned if eventProperties are not set", function () {
|
|
11
|
-
// @ts-ignore
|
|
12
|
-
var schema = inspector.extractSchema();
|
|
13
|
-
expect(schema).toEqual([]);
|
|
14
|
-
});
|
|
15
|
-
test("Property types and names are set", function () {
|
|
16
|
-
// Given
|
|
17
|
-
var eventProperties = {
|
|
18
|
-
prop0: true,
|
|
19
|
-
prop1: 1,
|
|
20
|
-
prop2: "str",
|
|
21
|
-
prop3: 0.5,
|
|
22
|
-
prop4: undefined,
|
|
23
|
-
prop5: null,
|
|
24
|
-
prop6: { an: "object" },
|
|
25
|
-
prop7: [
|
|
26
|
-
"a",
|
|
27
|
-
"list",
|
|
28
|
-
{
|
|
29
|
-
"obj in list": true,
|
|
30
|
-
"int field": 1,
|
|
31
|
-
},
|
|
32
|
-
["another", "list"],
|
|
33
|
-
[1, 2],
|
|
34
|
-
],
|
|
35
|
-
};
|
|
36
|
-
// When
|
|
37
|
-
var res = inspector.extractSchema(eventProperties);
|
|
38
|
-
// Then
|
|
39
|
-
res.forEach(function (_a, index) {
|
|
40
|
-
var propertyName = _a.propertyName;
|
|
41
|
-
expect(propertyName).toBe("prop".concat(index));
|
|
42
|
-
});
|
|
43
|
-
expect(res[0].propertyType).toBe(constants_1.type.BOOL);
|
|
44
|
-
expect(res[1].propertyType).toBe(constants_1.type.INT);
|
|
45
|
-
expect(res[2].propertyType).toBe(constants_1.type.STRING);
|
|
46
|
-
expect(res[3].propertyType).toBe(constants_1.type.FLOAT);
|
|
47
|
-
expect(res[4].propertyType).toBe(constants_1.type.NULL);
|
|
48
|
-
expect(res[5].propertyType).toBe(constants_1.type.NULL);
|
|
49
|
-
expect(res[6].propertyType).toBe(constants_1.type.OBJECT);
|
|
50
|
-
expect(res[6].children).toMatchObject([
|
|
51
|
-
{
|
|
52
|
-
propertyName: "an",
|
|
53
|
-
propertyType: constants_1.type.STRING,
|
|
54
|
-
},
|
|
55
|
-
]);
|
|
56
|
-
expect(res[7].propertyType).toBe(constants_1.type.LIST);
|
|
57
|
-
expect(res[7].children).toMatchObject([
|
|
58
|
-
constants_1.type.STRING,
|
|
59
|
-
[
|
|
60
|
-
{
|
|
61
|
-
propertyName: "obj in list",
|
|
62
|
-
propertyType: constants_1.type.BOOL,
|
|
63
|
-
},
|
|
64
|
-
{
|
|
65
|
-
propertyName: "int field",
|
|
66
|
-
propertyType: constants_1.type.INT,
|
|
67
|
-
},
|
|
68
|
-
],
|
|
69
|
-
[constants_1.type.STRING],
|
|
70
|
-
[constants_1.type.INT],
|
|
71
|
-
]);
|
|
72
|
-
});
|
|
73
|
-
test("Duplicated values are removed", function () {
|
|
74
|
-
// Given
|
|
75
|
-
var eventProperties = {
|
|
76
|
-
prop0: ["true", "false", true, 10, "true", true, 11, 10, 0.1, 0.1],
|
|
77
|
-
};
|
|
78
|
-
// When
|
|
79
|
-
var res = inspector.extractSchema(eventProperties);
|
|
80
|
-
// Then
|
|
81
|
-
expect(res[0].propertyType).toBe(constants_1.type.LIST);
|
|
82
|
-
expect(res[0].children).toMatchObject([
|
|
83
|
-
constants_1.type.STRING,
|
|
84
|
-
constants_1.type.BOOL,
|
|
85
|
-
constants_1.type.INT,
|
|
86
|
-
constants_1.type.FLOAT,
|
|
87
|
-
]);
|
|
88
|
-
});
|
|
89
|
-
test("Empty and falsy values are set correctly", function () {
|
|
90
|
-
// Given
|
|
91
|
-
var eventProperties = {
|
|
92
|
-
prop0: false,
|
|
93
|
-
prop1: 0,
|
|
94
|
-
prop2: "",
|
|
95
|
-
prop3: 0.0,
|
|
96
|
-
prop4: undefined,
|
|
97
|
-
prop5: null,
|
|
98
|
-
prop6: {},
|
|
99
|
-
prop7: [],
|
|
100
|
-
};
|
|
101
|
-
// When
|
|
102
|
-
var res = inspector.extractSchema(eventProperties);
|
|
103
|
-
// Then
|
|
104
|
-
expect(res[0].propertyType).toBe(constants_1.type.BOOL);
|
|
105
|
-
expect(res[1].propertyType).toBe(constants_1.type.INT);
|
|
106
|
-
expect(res[2].propertyType).toBe(constants_1.type.STRING);
|
|
107
|
-
expect(res[3].propertyType).toBe(constants_1.type.INT);
|
|
108
|
-
expect(res[4].propertyType).toBe(constants_1.type.NULL);
|
|
109
|
-
expect(res[5].propertyType).toBe(constants_1.type.NULL);
|
|
110
|
-
expect(res[6].propertyType).toBe(constants_1.type.OBJECT);
|
|
111
|
-
expect(res[6].children).toMatchObject([]);
|
|
112
|
-
expect(res[7].propertyType).toBe(constants_1.type.LIST);
|
|
113
|
-
expect(res[7].children).toMatchObject([]);
|
|
114
|
-
});
|
|
115
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
var AvoInspector_1 = require("../AvoInspector");
|
|
4
|
-
var constants_1 = require("../__tests__/constants");
|
|
5
|
-
describe("Sessions (Model A - no session tracking)", function () {
|
|
6
|
-
test("AvoInspector does not have a sessionTracker property", function () {
|
|
7
|
-
var inspector = new AvoInspector_1.AvoInspector(constants_1.defaultOptions);
|
|
8
|
-
expect(inspector.sessionTracker).toBeUndefined();
|
|
9
|
-
});
|
|
10
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|