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,543 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
-
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;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
var EventValidator_1 = require("../eventSpec/EventValidator");
|
|
40
|
-
function makeSpecResponse(events, branchId) {
|
|
41
|
-
if (branchId === void 0) { branchId = "branch1"; }
|
|
42
|
-
return {
|
|
43
|
-
events: events,
|
|
44
|
-
metadata: {
|
|
45
|
-
schemaId: "schema1",
|
|
46
|
-
branchId: branchId,
|
|
47
|
-
latestActionId: "action1",
|
|
48
|
-
},
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
function makeEvent(id, props, variantIds) {
|
|
52
|
-
if (variantIds === void 0) { variantIds = []; }
|
|
53
|
-
return {
|
|
54
|
-
branchId: "branch1",
|
|
55
|
-
baseEventId: id,
|
|
56
|
-
variantIds: variantIds,
|
|
57
|
-
props: props,
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
describe("EventValidator", function () {
|
|
61
|
-
describe("pinned values", function () {
|
|
62
|
-
test("passes when value matches pinned value", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
63
|
-
var spec, result;
|
|
64
|
-
return __generator(this, function (_a) {
|
|
65
|
-
switch (_a.label) {
|
|
66
|
-
case 0:
|
|
67
|
-
spec = makeSpecResponse([
|
|
68
|
-
makeEvent("evt_1", {
|
|
69
|
-
method: {
|
|
70
|
-
type: "string",
|
|
71
|
-
required: true,
|
|
72
|
-
pinnedValues: { email: ["evt_1"] },
|
|
73
|
-
},
|
|
74
|
-
}),
|
|
75
|
-
]);
|
|
76
|
-
return [4 /*yield*/, (0, EventValidator_1.validateEvent)({ method: "email" }, spec)];
|
|
77
|
-
case 1:
|
|
78
|
-
result = _a.sent();
|
|
79
|
-
expect(result.propertyResults.method.failedEventIds).toBeUndefined();
|
|
80
|
-
expect(result.propertyResults.method.passedEventIds).toBeUndefined();
|
|
81
|
-
return [2 /*return*/];
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
}); });
|
|
85
|
-
test("fails when value does not match pinned value", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
86
|
-
var spec, result;
|
|
87
|
-
return __generator(this, function (_a) {
|
|
88
|
-
switch (_a.label) {
|
|
89
|
-
case 0:
|
|
90
|
-
spec = makeSpecResponse([
|
|
91
|
-
makeEvent("evt_1", {
|
|
92
|
-
method: {
|
|
93
|
-
type: "string",
|
|
94
|
-
required: true,
|
|
95
|
-
pinnedValues: { email: ["evt_1"] },
|
|
96
|
-
},
|
|
97
|
-
}),
|
|
98
|
-
]);
|
|
99
|
-
return [4 /*yield*/, (0, EventValidator_1.validateEvent)({ method: "phone" }, spec)];
|
|
100
|
-
case 1:
|
|
101
|
-
result = _a.sent();
|
|
102
|
-
expect(result.propertyResults.method.failedEventIds).toContain("evt_1");
|
|
103
|
-
return [2 /*return*/];
|
|
104
|
-
}
|
|
105
|
-
});
|
|
106
|
-
}); });
|
|
107
|
-
});
|
|
108
|
-
describe("allowed values", function () {
|
|
109
|
-
test("passes when value is in allowed list", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
110
|
-
var spec, result;
|
|
111
|
-
return __generator(this, function (_a) {
|
|
112
|
-
switch (_a.label) {
|
|
113
|
-
case 0:
|
|
114
|
-
spec = makeSpecResponse([
|
|
115
|
-
makeEvent("evt_1", {
|
|
116
|
-
status: {
|
|
117
|
-
type: "string",
|
|
118
|
-
required: true,
|
|
119
|
-
allowedValues: { '["active","inactive"]': ["evt_1"] },
|
|
120
|
-
},
|
|
121
|
-
}),
|
|
122
|
-
]);
|
|
123
|
-
return [4 /*yield*/, (0, EventValidator_1.validateEvent)({ status: "active" }, spec)];
|
|
124
|
-
case 1:
|
|
125
|
-
result = _a.sent();
|
|
126
|
-
expect(result.propertyResults.status.failedEventIds).toBeUndefined();
|
|
127
|
-
return [2 /*return*/];
|
|
128
|
-
}
|
|
129
|
-
});
|
|
130
|
-
}); });
|
|
131
|
-
test("fails when value is not in allowed list", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
132
|
-
var spec, result;
|
|
133
|
-
return __generator(this, function (_a) {
|
|
134
|
-
switch (_a.label) {
|
|
135
|
-
case 0:
|
|
136
|
-
spec = makeSpecResponse([
|
|
137
|
-
makeEvent("evt_1", {
|
|
138
|
-
status: {
|
|
139
|
-
type: "string",
|
|
140
|
-
required: true,
|
|
141
|
-
allowedValues: { '["active","inactive"]': ["evt_1"] },
|
|
142
|
-
},
|
|
143
|
-
}),
|
|
144
|
-
]);
|
|
145
|
-
return [4 /*yield*/, (0, EventValidator_1.validateEvent)({ status: "deleted" }, spec)];
|
|
146
|
-
case 1:
|
|
147
|
-
result = _a.sent();
|
|
148
|
-
expect(result.propertyResults.status.failedEventIds).toContain("evt_1");
|
|
149
|
-
return [2 /*return*/];
|
|
150
|
-
}
|
|
151
|
-
});
|
|
152
|
-
}); });
|
|
153
|
-
});
|
|
154
|
-
describe("regex patterns", function () {
|
|
155
|
-
test("passes when value matches regex", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
156
|
-
var spec, result;
|
|
157
|
-
return __generator(this, function (_a) {
|
|
158
|
-
switch (_a.label) {
|
|
159
|
-
case 0:
|
|
160
|
-
spec = makeSpecResponse([
|
|
161
|
-
makeEvent("evt_1", {
|
|
162
|
-
email: {
|
|
163
|
-
type: "string",
|
|
164
|
-
required: true,
|
|
165
|
-
regexPatterns: { "^[^@]+@[^@]+$": ["evt_1"] },
|
|
166
|
-
},
|
|
167
|
-
}),
|
|
168
|
-
]);
|
|
169
|
-
return [4 /*yield*/, (0, EventValidator_1.validateEvent)({ email: "user@example.com" }, spec)];
|
|
170
|
-
case 1:
|
|
171
|
-
result = _a.sent();
|
|
172
|
-
expect(result.propertyResults.email.failedEventIds).toBeUndefined();
|
|
173
|
-
return [2 /*return*/];
|
|
174
|
-
}
|
|
175
|
-
});
|
|
176
|
-
}); });
|
|
177
|
-
test("fails when value does not match regex", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
178
|
-
var spec, result;
|
|
179
|
-
return __generator(this, function (_a) {
|
|
180
|
-
switch (_a.label) {
|
|
181
|
-
case 0:
|
|
182
|
-
spec = makeSpecResponse([
|
|
183
|
-
makeEvent("evt_1", {
|
|
184
|
-
email: {
|
|
185
|
-
type: "string",
|
|
186
|
-
required: true,
|
|
187
|
-
regexPatterns: { "^[^@]+@[^@]+$": ["evt_1"] },
|
|
188
|
-
},
|
|
189
|
-
}),
|
|
190
|
-
]);
|
|
191
|
-
return [4 /*yield*/, (0, EventValidator_1.validateEvent)({ email: "invalid" }, spec)];
|
|
192
|
-
case 1:
|
|
193
|
-
result = _a.sent();
|
|
194
|
-
expect(result.propertyResults.email.failedEventIds).toContain("evt_1");
|
|
195
|
-
return [2 /*return*/];
|
|
196
|
-
}
|
|
197
|
-
});
|
|
198
|
-
}); });
|
|
199
|
-
test("safe-regex2: unsafe regex patterns are skipped with warning", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
200
|
-
var warnSpy, spec, result;
|
|
201
|
-
return __generator(this, function (_a) {
|
|
202
|
-
switch (_a.label) {
|
|
203
|
-
case 0:
|
|
204
|
-
warnSpy = jest.spyOn(console, "warn").mockImplementation();
|
|
205
|
-
spec = makeSpecResponse([
|
|
206
|
-
makeEvent("evt_1", {
|
|
207
|
-
input: {
|
|
208
|
-
type: "string",
|
|
209
|
-
required: true,
|
|
210
|
-
regexPatterns: { "(a+)+$": ["evt_1"] },
|
|
211
|
-
},
|
|
212
|
-
}),
|
|
213
|
-
]);
|
|
214
|
-
return [4 /*yield*/, (0, EventValidator_1.validateEvent)({ input: "aaaaaa" }, spec)];
|
|
215
|
-
case 1:
|
|
216
|
-
result = _a.sent();
|
|
217
|
-
// Unsafe pattern should be skipped, not cause failure
|
|
218
|
-
expect(warnSpy).toHaveBeenCalledWith(expect.stringContaining("[Avo Inspector] Warning: unsafe regex pattern skipped"));
|
|
219
|
-
warnSpy.mockRestore();
|
|
220
|
-
return [2 /*return*/];
|
|
221
|
-
}
|
|
222
|
-
});
|
|
223
|
-
}); });
|
|
224
|
-
test("non-string values fail all regex constraints", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
225
|
-
var spec, result;
|
|
226
|
-
return __generator(this, function (_a) {
|
|
227
|
-
switch (_a.label) {
|
|
228
|
-
case 0:
|
|
229
|
-
spec = makeSpecResponse([
|
|
230
|
-
makeEvent("evt_1", {
|
|
231
|
-
code: {
|
|
232
|
-
type: "string",
|
|
233
|
-
required: true,
|
|
234
|
-
regexPatterns: { "^[0-9]+$": ["evt_1"] },
|
|
235
|
-
},
|
|
236
|
-
}),
|
|
237
|
-
]);
|
|
238
|
-
return [4 /*yield*/, (0, EventValidator_1.validateEvent)({ code: 12345 }, spec)];
|
|
239
|
-
case 1:
|
|
240
|
-
result = _a.sent();
|
|
241
|
-
expect(result.propertyResults.code.failedEventIds).toContain("evt_1");
|
|
242
|
-
return [2 /*return*/];
|
|
243
|
-
}
|
|
244
|
-
});
|
|
245
|
-
}); });
|
|
246
|
-
});
|
|
247
|
-
describe("min/max ranges", function () {
|
|
248
|
-
test("passes when value is within range", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
249
|
-
var spec, result;
|
|
250
|
-
return __generator(this, function (_a) {
|
|
251
|
-
switch (_a.label) {
|
|
252
|
-
case 0:
|
|
253
|
-
spec = makeSpecResponse([
|
|
254
|
-
makeEvent("evt_1", {
|
|
255
|
-
age: {
|
|
256
|
-
type: "int",
|
|
257
|
-
required: true,
|
|
258
|
-
minMaxRanges: { "0,120": ["evt_1"] },
|
|
259
|
-
},
|
|
260
|
-
}),
|
|
261
|
-
]);
|
|
262
|
-
return [4 /*yield*/, (0, EventValidator_1.validateEvent)({ age: 25 }, spec)];
|
|
263
|
-
case 1:
|
|
264
|
-
result = _a.sent();
|
|
265
|
-
expect(result.propertyResults.age.failedEventIds).toBeUndefined();
|
|
266
|
-
return [2 /*return*/];
|
|
267
|
-
}
|
|
268
|
-
});
|
|
269
|
-
}); });
|
|
270
|
-
test("fails when value is below minimum", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
271
|
-
var spec, result;
|
|
272
|
-
return __generator(this, function (_a) {
|
|
273
|
-
switch (_a.label) {
|
|
274
|
-
case 0:
|
|
275
|
-
spec = makeSpecResponse([
|
|
276
|
-
makeEvent("evt_1", {
|
|
277
|
-
age: {
|
|
278
|
-
type: "int",
|
|
279
|
-
required: true,
|
|
280
|
-
minMaxRanges: { "0,120": ["evt_1"] },
|
|
281
|
-
},
|
|
282
|
-
}),
|
|
283
|
-
]);
|
|
284
|
-
return [4 /*yield*/, (0, EventValidator_1.validateEvent)({ age: -1 }, spec)];
|
|
285
|
-
case 1:
|
|
286
|
-
result = _a.sent();
|
|
287
|
-
expect(result.propertyResults.age.failedEventIds).toContain("evt_1");
|
|
288
|
-
return [2 /*return*/];
|
|
289
|
-
}
|
|
290
|
-
});
|
|
291
|
-
}); });
|
|
292
|
-
test("fails when value is above maximum", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
293
|
-
var spec, result;
|
|
294
|
-
return __generator(this, function (_a) {
|
|
295
|
-
switch (_a.label) {
|
|
296
|
-
case 0:
|
|
297
|
-
spec = makeSpecResponse([
|
|
298
|
-
makeEvent("evt_1", {
|
|
299
|
-
age: {
|
|
300
|
-
type: "int",
|
|
301
|
-
required: true,
|
|
302
|
-
minMaxRanges: { "0,120": ["evt_1"] },
|
|
303
|
-
},
|
|
304
|
-
}),
|
|
305
|
-
]);
|
|
306
|
-
return [4 /*yield*/, (0, EventValidator_1.validateEvent)({ age: 150 }, spec)];
|
|
307
|
-
case 1:
|
|
308
|
-
result = _a.sent();
|
|
309
|
-
expect(result.propertyResults.age.failedEventIds).toContain("evt_1");
|
|
310
|
-
return [2 /*return*/];
|
|
311
|
-
}
|
|
312
|
-
});
|
|
313
|
-
}); });
|
|
314
|
-
test("handles open-ended ranges (min only)", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
315
|
-
var spec, result;
|
|
316
|
-
return __generator(this, function (_a) {
|
|
317
|
-
switch (_a.label) {
|
|
318
|
-
case 0:
|
|
319
|
-
spec = makeSpecResponse([
|
|
320
|
-
makeEvent("evt_1", {
|
|
321
|
-
score: {
|
|
322
|
-
type: "int",
|
|
323
|
-
required: true,
|
|
324
|
-
minMaxRanges: { "0,": ["evt_1"] },
|
|
325
|
-
},
|
|
326
|
-
}),
|
|
327
|
-
]);
|
|
328
|
-
return [4 /*yield*/, (0, EventValidator_1.validateEvent)({ score: 999999 }, spec)];
|
|
329
|
-
case 1:
|
|
330
|
-
result = _a.sent();
|
|
331
|
-
expect(result.propertyResults.score.failedEventIds).toBeUndefined();
|
|
332
|
-
return [2 /*return*/];
|
|
333
|
-
}
|
|
334
|
-
});
|
|
335
|
-
}); });
|
|
336
|
-
test("non-numeric values fail all min/max constraints", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
337
|
-
var spec, result;
|
|
338
|
-
return __generator(this, function (_a) {
|
|
339
|
-
switch (_a.label) {
|
|
340
|
-
case 0:
|
|
341
|
-
spec = makeSpecResponse([
|
|
342
|
-
makeEvent("evt_1", {
|
|
343
|
-
count: {
|
|
344
|
-
type: "int",
|
|
345
|
-
required: true,
|
|
346
|
-
minMaxRanges: { "0,100": ["evt_1"] },
|
|
347
|
-
},
|
|
348
|
-
}),
|
|
349
|
-
]);
|
|
350
|
-
return [4 /*yield*/, (0, EventValidator_1.validateEvent)({ count: "fifty" }, spec)];
|
|
351
|
-
case 1:
|
|
352
|
-
result = _a.sent();
|
|
353
|
-
expect(result.propertyResults.count.failedEventIds).toContain("evt_1");
|
|
354
|
-
return [2 /*return*/];
|
|
355
|
-
}
|
|
356
|
-
});
|
|
357
|
-
}); });
|
|
358
|
-
});
|
|
359
|
-
describe("bandwidth optimization", function () {
|
|
360
|
-
test("returns passedEventIds when strictly smaller than failedEventIds", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
361
|
-
var spec, result, propResult;
|
|
362
|
-
return __generator(this, function (_a) {
|
|
363
|
-
switch (_a.label) {
|
|
364
|
-
case 0:
|
|
365
|
-
spec = makeSpecResponse([
|
|
366
|
-
makeEvent("evt_1", {
|
|
367
|
-
method: {
|
|
368
|
-
type: "string",
|
|
369
|
-
required: true,
|
|
370
|
-
pinnedValues: {
|
|
371
|
-
email: ["evt_1"],
|
|
372
|
-
phone: ["evt_2"],
|
|
373
|
-
sms: ["evt_3"],
|
|
374
|
-
},
|
|
375
|
-
},
|
|
376
|
-
}, ["evt_2", "evt_3"]),
|
|
377
|
-
]);
|
|
378
|
-
return [4 /*yield*/, (0, EventValidator_1.validateEvent)({ method: "email" }, spec)];
|
|
379
|
-
case 1:
|
|
380
|
-
result = _a.sent();
|
|
381
|
-
propResult = result.propertyResults.method;
|
|
382
|
-
// evt_1 passes, evt_2 and evt_3 fail
|
|
383
|
-
// passedEventIds=[evt_1] (len 1) < failedEventIds=[evt_2, evt_3] (len 2)
|
|
384
|
-
// So passedEventIds should be returned
|
|
385
|
-
expect(propResult.passedEventIds).toEqual(["evt_1"]);
|
|
386
|
-
expect(propResult.failedEventIds).toBeUndefined();
|
|
387
|
-
return [2 /*return*/];
|
|
388
|
-
}
|
|
389
|
-
});
|
|
390
|
-
}); });
|
|
391
|
-
});
|
|
392
|
-
describe("property not in spec", function () {
|
|
393
|
-
test("returns empty result for unknown properties", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
394
|
-
var spec, result;
|
|
395
|
-
return __generator(this, function (_a) {
|
|
396
|
-
switch (_a.label) {
|
|
397
|
-
case 0:
|
|
398
|
-
spec = makeSpecResponse([
|
|
399
|
-
makeEvent("evt_1", {
|
|
400
|
-
method: { type: "string", required: true },
|
|
401
|
-
}),
|
|
402
|
-
]);
|
|
403
|
-
return [4 /*yield*/, (0, EventValidator_1.validateEvent)({ method: "email", extraProp: "value" }, spec)];
|
|
404
|
-
case 1:
|
|
405
|
-
result = _a.sent();
|
|
406
|
-
expect(result.propertyResults.extraProp).toEqual({});
|
|
407
|
-
return [2 /*return*/];
|
|
408
|
-
}
|
|
409
|
-
});
|
|
410
|
-
}); });
|
|
411
|
-
});
|
|
412
|
-
describe("null/undefined on non-required properties", function () {
|
|
413
|
-
test("skips validation for null on non-required primitive property", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
414
|
-
var spec, result;
|
|
415
|
-
return __generator(this, function (_a) {
|
|
416
|
-
switch (_a.label) {
|
|
417
|
-
case 0:
|
|
418
|
-
spec = makeSpecResponse([
|
|
419
|
-
makeEvent("evt_1", {
|
|
420
|
-
nickname: {
|
|
421
|
-
type: "string",
|
|
422
|
-
required: false,
|
|
423
|
-
pinnedValues: { "some-name": ["evt_1"] },
|
|
424
|
-
},
|
|
425
|
-
}),
|
|
426
|
-
]);
|
|
427
|
-
return [4 /*yield*/, (0, EventValidator_1.validateEvent)({ nickname: null }, spec)];
|
|
428
|
-
case 1:
|
|
429
|
-
result = _a.sent();
|
|
430
|
-
expect(result.propertyResults.nickname.failedEventIds).toBeUndefined();
|
|
431
|
-
return [2 /*return*/];
|
|
432
|
-
}
|
|
433
|
-
});
|
|
434
|
-
}); });
|
|
435
|
-
});
|
|
436
|
-
describe("nested object properties", function () {
|
|
437
|
-
test("validates children of object properties", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
438
|
-
var spec, result;
|
|
439
|
-
var _a;
|
|
440
|
-
return __generator(this, function (_b) {
|
|
441
|
-
switch (_b.label) {
|
|
442
|
-
case 0:
|
|
443
|
-
spec = makeSpecResponse([
|
|
444
|
-
makeEvent("evt_1", {
|
|
445
|
-
address: {
|
|
446
|
-
type: "object",
|
|
447
|
-
required: true,
|
|
448
|
-
children: {
|
|
449
|
-
country: {
|
|
450
|
-
type: "string",
|
|
451
|
-
required: true,
|
|
452
|
-
pinnedValues: { US: ["evt_1"] },
|
|
453
|
-
},
|
|
454
|
-
},
|
|
455
|
-
},
|
|
456
|
-
}),
|
|
457
|
-
]);
|
|
458
|
-
return [4 /*yield*/, (0, EventValidator_1.validateEvent)({ address: { country: "UK" } }, spec)];
|
|
459
|
-
case 1:
|
|
460
|
-
result = _b.sent();
|
|
461
|
-
expect((_a = result.propertyResults.address.children) === null || _a === void 0 ? void 0 : _a.country.failedEventIds).toContain("evt_1");
|
|
462
|
-
return [2 /*return*/];
|
|
463
|
-
}
|
|
464
|
-
});
|
|
465
|
-
}); });
|
|
466
|
-
});
|
|
467
|
-
describe("list properties", function () {
|
|
468
|
-
test("validates each item in a list against constraints", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
469
|
-
var spec, result;
|
|
470
|
-
return __generator(this, function (_a) {
|
|
471
|
-
switch (_a.label) {
|
|
472
|
-
case 0:
|
|
473
|
-
spec = makeSpecResponse([
|
|
474
|
-
makeEvent("evt_1", {
|
|
475
|
-
tags: {
|
|
476
|
-
type: "string",
|
|
477
|
-
required: true,
|
|
478
|
-
isList: true,
|
|
479
|
-
allowedValues: { '["red","green","blue"]': ["evt_1"] },
|
|
480
|
-
},
|
|
481
|
-
}),
|
|
482
|
-
]);
|
|
483
|
-
return [4 /*yield*/, (0, EventValidator_1.validateEvent)({ tags: ["red", "yellow"] }, spec)];
|
|
484
|
-
case 1:
|
|
485
|
-
result = _a.sent();
|
|
486
|
-
expect(result.propertyResults.tags.failedEventIds).toContain("evt_1");
|
|
487
|
-
return [2 /*return*/];
|
|
488
|
-
}
|
|
489
|
-
});
|
|
490
|
-
}); });
|
|
491
|
-
});
|
|
492
|
-
describe("metadata", function () {
|
|
493
|
-
test("returns metadata from the spec response", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
494
|
-
var spec, result;
|
|
495
|
-
return __generator(this, function (_a) {
|
|
496
|
-
switch (_a.label) {
|
|
497
|
-
case 0:
|
|
498
|
-
spec = makeSpecResponse([makeEvent("evt_1", {})], "my-branch");
|
|
499
|
-
return [4 /*yield*/, (0, EventValidator_1.validateEvent)({ anything: "value" }, spec)];
|
|
500
|
-
case 1:
|
|
501
|
-
result = _a.sent();
|
|
502
|
-
expect(result.metadata).toEqual({
|
|
503
|
-
schemaId: "schema1",
|
|
504
|
-
branchId: "my-branch",
|
|
505
|
-
latestActionId: "action1",
|
|
506
|
-
});
|
|
507
|
-
return [2 /*return*/];
|
|
508
|
-
}
|
|
509
|
-
});
|
|
510
|
-
}); });
|
|
511
|
-
});
|
|
512
|
-
describe("multiple events", function () {
|
|
513
|
-
test("aggregates constraints from multiple events", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
514
|
-
var spec, result;
|
|
515
|
-
return __generator(this, function (_a) {
|
|
516
|
-
switch (_a.label) {
|
|
517
|
-
case 0:
|
|
518
|
-
spec = makeSpecResponse([
|
|
519
|
-
makeEvent("evt_1", {
|
|
520
|
-
method: {
|
|
521
|
-
type: "string",
|
|
522
|
-
required: true,
|
|
523
|
-
pinnedValues: { email: ["evt_1"] },
|
|
524
|
-
},
|
|
525
|
-
}),
|
|
526
|
-
makeEvent("evt_2", {
|
|
527
|
-
method: {
|
|
528
|
-
type: "string",
|
|
529
|
-
required: true,
|
|
530
|
-
pinnedValues: { phone: ["evt_2"] },
|
|
531
|
-
},
|
|
532
|
-
}),
|
|
533
|
-
]);
|
|
534
|
-
return [4 /*yield*/, (0, EventValidator_1.validateEvent)({ method: "email" }, spec)];
|
|
535
|
-
case 1:
|
|
536
|
-
result = _a.sent();
|
|
537
|
-
expect(result.propertyResults.method.failedEventIds).toContain("evt_2");
|
|
538
|
-
return [2 /*return*/];
|
|
539
|
-
}
|
|
540
|
-
});
|
|
541
|
-
}); });
|
|
542
|
-
});
|
|
543
|
-
});
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
-
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;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
var AvoStreamId_1 = require("../AvoStreamId");
|
|
40
|
-
var AvoInspector_1 = require("../AvoInspector");
|
|
41
|
-
var constants_1 = require("../__tests__/constants");
|
|
42
|
-
describe("InstallationId (replaced by AvoStreamId in Model A)", function () {
|
|
43
|
-
beforeAll(function () {
|
|
44
|
-
new AvoInspector_1.AvoInspector(constants_1.defaultOptions);
|
|
45
|
-
});
|
|
46
|
-
test("AvoStreamId provides anonymous ID as replacement for installation ID", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
47
|
-
var id;
|
|
48
|
-
return __generator(this, function (_a) {
|
|
49
|
-
switch (_a.label) {
|
|
50
|
-
case 0: return [4 /*yield*/, AvoStreamId_1.AvoStreamId.initialize()];
|
|
51
|
-
case 1:
|
|
52
|
-
id = _a.sent();
|
|
53
|
-
expect(id).not.toBeNull();
|
|
54
|
-
expect(typeof id).toBe("string");
|
|
55
|
-
expect(id.length).toBeGreaterThan(0);
|
|
56
|
-
return [2 /*return*/];
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
}); });
|
|
60
|
-
});
|