@trafficwar/node 2.2.3 → 2.2.5
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 +20 -0
- package/dist/index.cjs +731 -65
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +12 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +727 -65
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -2,8 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
var zlib = require('zlib');
|
|
4
4
|
var buffer = require('buffer');
|
|
5
|
+
var fs = require('fs');
|
|
6
|
+
var path = require('path');
|
|
5
7
|
var crypto = require('crypto');
|
|
6
8
|
|
|
9
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
10
|
+
|
|
11
|
+
var path__default = /*#__PURE__*/_interopDefault(path);
|
|
12
|
+
|
|
7
13
|
// src/client.ts
|
|
8
14
|
|
|
9
15
|
// src/errors.ts
|
|
@@ -104,22 +110,22 @@ var SPAN_KINDS = /* @__PURE__ */ new Set([
|
|
|
104
110
|
"internal"
|
|
105
111
|
]);
|
|
106
112
|
var FORBIDDEN_IDENTITY_FIELDS = ["user_id", "service", "service_id"];
|
|
107
|
-
function validationError(message,
|
|
113
|
+
function validationError(message, path2, idempotencyKey, cause) {
|
|
108
114
|
return new TrafficWarValidationError(message, {
|
|
109
|
-
path,
|
|
115
|
+
path: path2,
|
|
110
116
|
idempotencyKey,
|
|
111
117
|
cause
|
|
112
118
|
});
|
|
113
119
|
}
|
|
114
|
-
function snapshotJsonValue(value,
|
|
120
|
+
function snapshotJsonValue(value, path2, ancestors, idempotencyKey) {
|
|
115
121
|
if (value === null || typeof value === "string" || typeof value === "boolean") {
|
|
116
122
|
return value;
|
|
117
123
|
}
|
|
118
124
|
if (typeof value === "number") {
|
|
119
125
|
if (!Number.isFinite(value)) {
|
|
120
126
|
throw validationError(
|
|
121
|
-
`${
|
|
122
|
-
|
|
127
|
+
`${path2} must contain only finite JSON numbers`,
|
|
128
|
+
path2,
|
|
123
129
|
idempotencyKey
|
|
124
130
|
);
|
|
125
131
|
}
|
|
@@ -127,22 +133,22 @@ function snapshotJsonValue(value, path, ancestors, idempotencyKey) {
|
|
|
127
133
|
}
|
|
128
134
|
if (typeof value !== "object") {
|
|
129
135
|
throw validationError(
|
|
130
|
-
`${
|
|
131
|
-
|
|
136
|
+
`${path2} contains a value that JSON cannot represent`,
|
|
137
|
+
path2,
|
|
132
138
|
idempotencyKey
|
|
133
139
|
);
|
|
134
140
|
}
|
|
135
141
|
if (value instanceof Date) {
|
|
136
142
|
throw validationError(
|
|
137
|
-
`${
|
|
138
|
-
|
|
143
|
+
`${path2} contains a Date; only timestamp accepts Date values`,
|
|
144
|
+
path2,
|
|
139
145
|
idempotencyKey
|
|
140
146
|
);
|
|
141
147
|
}
|
|
142
148
|
if (ancestors.has(value)) {
|
|
143
149
|
throw validationError(
|
|
144
|
-
`${
|
|
145
|
-
|
|
150
|
+
`${path2} contains a circular reference`,
|
|
151
|
+
path2,
|
|
146
152
|
idempotencyKey
|
|
147
153
|
);
|
|
148
154
|
}
|
|
@@ -150,8 +156,8 @@ function snapshotJsonValue(value, path, ancestors, idempotencyKey) {
|
|
|
150
156
|
const prototype = Object.getPrototypeOf(value);
|
|
151
157
|
if (prototype !== Object.prototype && prototype !== null) {
|
|
152
158
|
throw validationError(
|
|
153
|
-
`${
|
|
154
|
-
|
|
159
|
+
`${path2} contains a non-JSON object`,
|
|
160
|
+
path2,
|
|
155
161
|
idempotencyKey
|
|
156
162
|
);
|
|
157
163
|
}
|
|
@@ -163,15 +169,15 @@ function snapshotJsonValue(value, path, ancestors, idempotencyKey) {
|
|
|
163
169
|
for (let index = 0; index < value.length; index += 1) {
|
|
164
170
|
if (!(index in value)) {
|
|
165
171
|
throw validationError(
|
|
166
|
-
`${
|
|
167
|
-
`${
|
|
172
|
+
`${path2}[${index}] is missing; sparse arrays are not valid JSON values`,
|
|
173
|
+
`${path2}[${index}]`,
|
|
168
174
|
idempotencyKey
|
|
169
175
|
);
|
|
170
176
|
}
|
|
171
177
|
snapshot2.push(
|
|
172
178
|
snapshotJsonValue(
|
|
173
179
|
value[index],
|
|
174
|
-
`${
|
|
180
|
+
`${path2}[${index}]`,
|
|
175
181
|
ancestors,
|
|
176
182
|
idempotencyKey
|
|
177
183
|
)
|
|
@@ -183,7 +189,7 @@ function snapshotJsonValue(value, path, ancestors, idempotencyKey) {
|
|
|
183
189
|
for (const [key, child] of Object.entries(value)) {
|
|
184
190
|
snapshot[key] = snapshotJsonValue(
|
|
185
191
|
child,
|
|
186
|
-
`${
|
|
192
|
+
`${path2}.${key}`,
|
|
187
193
|
ancestors,
|
|
188
194
|
idempotencyKey
|
|
189
195
|
);
|
|
@@ -193,12 +199,12 @@ function snapshotJsonValue(value, path, ancestors, idempotencyKey) {
|
|
|
193
199
|
ancestors.delete(value);
|
|
194
200
|
}
|
|
195
201
|
}
|
|
196
|
-
function normalizeTimestamp(timestamp,
|
|
202
|
+
function normalizeTimestamp(timestamp, path2, idempotencyKey) {
|
|
197
203
|
if (timestamp instanceof Date) {
|
|
198
204
|
if (!Number.isFinite(timestamp.getTime())) {
|
|
199
205
|
throw validationError(
|
|
200
|
-
`${
|
|
201
|
-
|
|
206
|
+
`${path2} must be a valid Date`,
|
|
207
|
+
path2,
|
|
202
208
|
idempotencyKey
|
|
203
209
|
);
|
|
204
210
|
}
|
|
@@ -207,8 +213,8 @@ function normalizeTimestamp(timestamp, path, idempotencyKey) {
|
|
|
207
213
|
if (typeof timestamp === "number") {
|
|
208
214
|
if (!Number.isSafeInteger(timestamp)) {
|
|
209
215
|
throw validationError(
|
|
210
|
-
`${
|
|
211
|
-
|
|
216
|
+
`${path2} must be an integer epoch-millisecond value`,
|
|
217
|
+
path2,
|
|
212
218
|
idempotencyKey
|
|
213
219
|
);
|
|
214
220
|
}
|
|
@@ -216,8 +222,8 @@ function normalizeTimestamp(timestamp, path, idempotencyKey) {
|
|
|
216
222
|
}
|
|
217
223
|
if (typeof timestamp !== "string") {
|
|
218
224
|
throw validationError(
|
|
219
|
-
`${
|
|
220
|
-
|
|
225
|
+
`${path2} must be an RFC3339 string, epoch-millisecond number, or Date`,
|
|
226
|
+
path2,
|
|
221
227
|
idempotencyKey
|
|
222
228
|
);
|
|
223
229
|
}
|
|
@@ -247,36 +253,36 @@ function normalizeTimestamp(timestamp, path, idempotencyKey) {
|
|
|
247
253
|
][month - 1];
|
|
248
254
|
if (match === null || month < 1 || month > 12 || daysInMonth === void 0 || day < 1 || day > daysInMonth || hour > 23 || minute > 59 || second > 59 || offsetHour > 23 || offsetMinute > 59 || !Number.isFinite(Date.parse(timestamp))) {
|
|
249
255
|
throw validationError(
|
|
250
|
-
`${
|
|
251
|
-
|
|
256
|
+
`${path2} must be an RFC3339 string, epoch-millisecond number, or Date`,
|
|
257
|
+
path2,
|
|
252
258
|
idempotencyKey
|
|
253
259
|
);
|
|
254
260
|
}
|
|
255
261
|
return timestamp;
|
|
256
262
|
}
|
|
257
|
-
function normalizeHttpMethod(value,
|
|
263
|
+
function normalizeHttpMethod(value, path2, idempotencyKey) {
|
|
258
264
|
if (typeof value !== "string") {
|
|
259
265
|
throw validationError(
|
|
260
|
-
`${
|
|
261
|
-
|
|
266
|
+
`${path2} must be an RFC HTTP token from 1 to 64 characters`,
|
|
267
|
+
path2,
|
|
262
268
|
idempotencyKey
|
|
263
269
|
);
|
|
264
270
|
}
|
|
265
271
|
const method = value.trim().toUpperCase();
|
|
266
272
|
if (method.length < 1 || method.length > 64 || !HTTP_TOKEN_PATTERN.test(method)) {
|
|
267
273
|
throw validationError(
|
|
268
|
-
`${
|
|
269
|
-
|
|
274
|
+
`${path2} must be an RFC HTTP token from 1 to 64 characters`,
|
|
275
|
+
path2,
|
|
270
276
|
idempotencyKey
|
|
271
277
|
);
|
|
272
278
|
}
|
|
273
279
|
return method;
|
|
274
280
|
}
|
|
275
|
-
function normalizeEvent(input,
|
|
281
|
+
function normalizeEvent(input, path2, idempotencyKey) {
|
|
276
282
|
if (input === null || typeof input !== "object" || Array.isArray(input)) {
|
|
277
283
|
throw validationError(
|
|
278
|
-
`${
|
|
279
|
-
|
|
284
|
+
`${path2} must be a non-empty object`,
|
|
285
|
+
path2,
|
|
280
286
|
idempotencyKey
|
|
281
287
|
);
|
|
282
288
|
}
|
|
@@ -285,8 +291,8 @@ function normalizeEvent(input, path, idempotencyKey) {
|
|
|
285
291
|
entries = Object.entries(input);
|
|
286
292
|
} catch (cause) {
|
|
287
293
|
throw validationError(
|
|
288
|
-
`${
|
|
289
|
-
|
|
294
|
+
`${path2} could not be read`,
|
|
295
|
+
path2,
|
|
290
296
|
idempotencyKey,
|
|
291
297
|
cause
|
|
292
298
|
);
|
|
@@ -303,16 +309,16 @@ function normalizeEvent(input, path, idempotencyKey) {
|
|
|
303
309
|
}
|
|
304
310
|
if (typeof normalized.event !== "string" || normalized.event.trim().length === 0) {
|
|
305
311
|
throw validationError(
|
|
306
|
-
`${
|
|
307
|
-
`${
|
|
312
|
+
`${path2}.event must be a non-empty string`,
|
|
313
|
+
`${path2}.event`,
|
|
308
314
|
idempotencyKey
|
|
309
315
|
);
|
|
310
316
|
}
|
|
311
317
|
for (const field of FORBIDDEN_IDENTITY_FIELDS) {
|
|
312
318
|
if (Object.hasOwn(normalized, field)) {
|
|
313
319
|
throw validationError(
|
|
314
|
-
`${
|
|
315
|
-
`${
|
|
320
|
+
`${path2}.${field} is derived from the API key and must not be sent`,
|
|
321
|
+
`${path2}.${field}`,
|
|
316
322
|
idempotencyKey
|
|
317
323
|
);
|
|
318
324
|
}
|
|
@@ -320,8 +326,8 @@ function normalizeEvent(input, path, idempotencyKey) {
|
|
|
320
326
|
if (Object.hasOwn(normalized, "event_id")) {
|
|
321
327
|
if (typeof normalized.event_id !== "string" || !UUID_PATTERN.test(normalized.event_id)) {
|
|
322
328
|
throw validationError(
|
|
323
|
-
`${
|
|
324
|
-
`${
|
|
329
|
+
`${path2}.event_id must be a UUID string`,
|
|
330
|
+
`${path2}.event_id`,
|
|
325
331
|
idempotencyKey
|
|
326
332
|
);
|
|
327
333
|
}
|
|
@@ -329,7 +335,7 @@ function normalizeEvent(input, path, idempotencyKey) {
|
|
|
329
335
|
if (Object.hasOwn(normalized, "timestamp")) {
|
|
330
336
|
normalized.timestamp = normalizeTimestamp(
|
|
331
337
|
normalized.timestamp,
|
|
332
|
-
`${
|
|
338
|
+
`${path2}.timestamp`,
|
|
333
339
|
idempotencyKey
|
|
334
340
|
);
|
|
335
341
|
} else {
|
|
@@ -337,45 +343,45 @@ function normalizeEvent(input, path, idempotencyKey) {
|
|
|
337
343
|
}
|
|
338
344
|
if (Object.hasOwn(normalized, "latency_ms") && (typeof normalized.latency_ms !== "number" || !Number.isFinite(normalized.latency_ms))) {
|
|
339
345
|
throw validationError(
|
|
340
|
-
`${
|
|
341
|
-
`${
|
|
346
|
+
`${path2}.latency_ms must be a finite number`,
|
|
347
|
+
`${path2}.latency_ms`,
|
|
342
348
|
idempotencyKey
|
|
343
349
|
);
|
|
344
350
|
}
|
|
345
351
|
if (Object.hasOwn(normalized, "status_code") && (typeof normalized.status_code !== "number" || !Number.isInteger(normalized.status_code) || normalized.status_code < 0 || normalized.status_code > 65535)) {
|
|
346
352
|
throw validationError(
|
|
347
|
-
`${
|
|
348
|
-
`${
|
|
353
|
+
`${path2}.status_code must be an integer from 0 to 65535`,
|
|
354
|
+
`${path2}.status_code`,
|
|
349
355
|
idempotencyKey
|
|
350
356
|
);
|
|
351
357
|
}
|
|
352
358
|
if (httpMethodProvided) {
|
|
353
359
|
normalized.http_method = normalizeHttpMethod(
|
|
354
360
|
normalized.http_method,
|
|
355
|
-
`${
|
|
361
|
+
`${path2}.http_method`,
|
|
356
362
|
idempotencyKey
|
|
357
363
|
);
|
|
358
364
|
}
|
|
359
365
|
for (const field of STRING_FIELDS) {
|
|
360
366
|
if (Object.hasOwn(normalized, field) && typeof normalized[field] !== "string") {
|
|
361
367
|
throw validationError(
|
|
362
|
-
`${
|
|
363
|
-
`${
|
|
368
|
+
`${path2}.${field} must be a string`,
|
|
369
|
+
`${path2}.${field}`,
|
|
364
370
|
idempotencyKey
|
|
365
371
|
);
|
|
366
372
|
}
|
|
367
373
|
}
|
|
368
374
|
if (Object.hasOwn(normalized, "span_kind") && (typeof normalized.span_kind !== "string" || !SPAN_KINDS.has(normalized.span_kind))) {
|
|
369
375
|
throw validationError(
|
|
370
|
-
`${
|
|
371
|
-
`${
|
|
376
|
+
`${path2}.span_kind must be server, client, producer, consumer, or internal`,
|
|
377
|
+
`${path2}.span_kind`,
|
|
372
378
|
idempotencyKey
|
|
373
379
|
);
|
|
374
380
|
}
|
|
375
381
|
try {
|
|
376
382
|
return snapshotJsonValue(
|
|
377
383
|
normalized,
|
|
378
|
-
|
|
384
|
+
path2,
|
|
379
385
|
/* @__PURE__ */ new WeakSet(),
|
|
380
386
|
idempotencyKey
|
|
381
387
|
);
|
|
@@ -384,8 +390,8 @@ function normalizeEvent(input, path, idempotencyKey) {
|
|
|
384
390
|
throw error;
|
|
385
391
|
}
|
|
386
392
|
throw validationError(
|
|
387
|
-
`${
|
|
388
|
-
|
|
393
|
+
`${path2} is not JSON-serializable`,
|
|
394
|
+
path2,
|
|
389
395
|
idempotencyKey,
|
|
390
396
|
error
|
|
391
397
|
);
|
|
@@ -409,6 +415,636 @@ function serializeJson(payload, idempotencyKey) {
|
|
|
409
415
|
}
|
|
410
416
|
return buffer.Buffer.from(serialized, "utf8");
|
|
411
417
|
}
|
|
418
|
+
var SOURCE_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
419
|
+
".ts",
|
|
420
|
+
".tsx",
|
|
421
|
+
".js",
|
|
422
|
+
".jsx",
|
|
423
|
+
".mjs",
|
|
424
|
+
".cjs",
|
|
425
|
+
".mts",
|
|
426
|
+
".cts"
|
|
427
|
+
]);
|
|
428
|
+
var SKIP_DIRECTORIES = /* @__PURE__ */ new Set([
|
|
429
|
+
"node_modules",
|
|
430
|
+
".git",
|
|
431
|
+
"dist",
|
|
432
|
+
"coverage",
|
|
433
|
+
".next",
|
|
434
|
+
".turbo",
|
|
435
|
+
".cache",
|
|
436
|
+
"target",
|
|
437
|
+
"vendor",
|
|
438
|
+
"__pycache__",
|
|
439
|
+
".venv",
|
|
440
|
+
"venv",
|
|
441
|
+
"build",
|
|
442
|
+
"out",
|
|
443
|
+
".output"
|
|
444
|
+
]);
|
|
445
|
+
var MAX_FILES = 4e3;
|
|
446
|
+
var MAX_FILE_BYTES = 512 * 1024;
|
|
447
|
+
var MAX_DEPTH = 12;
|
|
448
|
+
var MAX_LITERAL_CHARS = 256;
|
|
449
|
+
var REGEX_BEFORE = /* @__PURE__ */ new Set([
|
|
450
|
+
"(",
|
|
451
|
+
",",
|
|
452
|
+
"=",
|
|
453
|
+
":",
|
|
454
|
+
"[",
|
|
455
|
+
"!",
|
|
456
|
+
"&",
|
|
457
|
+
"|",
|
|
458
|
+
"?",
|
|
459
|
+
"{",
|
|
460
|
+
"}",
|
|
461
|
+
";",
|
|
462
|
+
"+",
|
|
463
|
+
"-",
|
|
464
|
+
"~",
|
|
465
|
+
"*",
|
|
466
|
+
"^",
|
|
467
|
+
"%",
|
|
468
|
+
">",
|
|
469
|
+
"<"
|
|
470
|
+
]);
|
|
471
|
+
var REGEX_KEYWORDS = /* @__PURE__ */ new Set([
|
|
472
|
+
"return",
|
|
473
|
+
"typeof",
|
|
474
|
+
"case",
|
|
475
|
+
"throw",
|
|
476
|
+
"void",
|
|
477
|
+
"delete",
|
|
478
|
+
"await",
|
|
479
|
+
"yield",
|
|
480
|
+
"else",
|
|
481
|
+
"do",
|
|
482
|
+
"in",
|
|
483
|
+
"of"
|
|
484
|
+
]);
|
|
485
|
+
function discoverCaptures(root) {
|
|
486
|
+
const resolved = path__default.default.resolve(root);
|
|
487
|
+
const rootStat = fs.statSync(resolved);
|
|
488
|
+
if (!rootStat.isDirectory()) {
|
|
489
|
+
throw new Error("catalog root is not a directory");
|
|
490
|
+
}
|
|
491
|
+
const found = [];
|
|
492
|
+
const state2 = { files: 0, truncated: false };
|
|
493
|
+
walk(resolved, resolved, 0, state2, found);
|
|
494
|
+
found.sort((left, right) => {
|
|
495
|
+
return left.file.localeCompare(right.file) || left.line - right.line || left.event.localeCompare(right.event) || left.label.localeCompare(right.label);
|
|
496
|
+
});
|
|
497
|
+
return { root: resolved, captures: found, truncated: state2.truncated };
|
|
498
|
+
}
|
|
499
|
+
function formatCaptureCatalog(scan) {
|
|
500
|
+
if (scan.captures.length === 0) {
|
|
501
|
+
const suffix2 = scan.truncated ? " (scan truncated)" : "";
|
|
502
|
+
return `[TrafficWar] no static capture() calls found under ${scan.root}${suffix2}`;
|
|
503
|
+
}
|
|
504
|
+
const suffix = scan.truncated ? ", scan truncated" : "";
|
|
505
|
+
const lines = scan.captures.map((capture) => {
|
|
506
|
+
return ` ${capture.event} ${capture.label} ${capture.file}:${capture.line}`;
|
|
507
|
+
});
|
|
508
|
+
return [
|
|
509
|
+
`[TrafficWar] static captures (${scan.captures.length}${suffix})`,
|
|
510
|
+
...lines
|
|
511
|
+
].join("\n");
|
|
512
|
+
}
|
|
513
|
+
function walk(root, dir, depth, state2, found) {
|
|
514
|
+
if (state2.truncated) {
|
|
515
|
+
return;
|
|
516
|
+
}
|
|
517
|
+
if (depth > MAX_DEPTH) {
|
|
518
|
+
state2.truncated = true;
|
|
519
|
+
return;
|
|
520
|
+
}
|
|
521
|
+
let entries;
|
|
522
|
+
try {
|
|
523
|
+
entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
524
|
+
} catch {
|
|
525
|
+
return;
|
|
526
|
+
}
|
|
527
|
+
for (const entry of entries) {
|
|
528
|
+
if (state2.truncated) {
|
|
529
|
+
return;
|
|
530
|
+
}
|
|
531
|
+
if (entry.isSymbolicLink()) {
|
|
532
|
+
continue;
|
|
533
|
+
}
|
|
534
|
+
const full = path__default.default.join(dir, entry.name);
|
|
535
|
+
if (entry.isDirectory()) {
|
|
536
|
+
if (!SKIP_DIRECTORIES.has(entry.name)) {
|
|
537
|
+
walk(root, full, depth + 1, state2, found);
|
|
538
|
+
}
|
|
539
|
+
continue;
|
|
540
|
+
}
|
|
541
|
+
if (!entry.isFile() || !isSourceFile(entry.name)) {
|
|
542
|
+
continue;
|
|
543
|
+
}
|
|
544
|
+
if (state2.files >= MAX_FILES) {
|
|
545
|
+
state2.truncated = true;
|
|
546
|
+
return;
|
|
547
|
+
}
|
|
548
|
+
state2.files += 1;
|
|
549
|
+
let source;
|
|
550
|
+
try {
|
|
551
|
+
const fileStat = fs.statSync(full);
|
|
552
|
+
if (!fileStat.isFile() || fileStat.size > MAX_FILE_BYTES) {
|
|
553
|
+
continue;
|
|
554
|
+
}
|
|
555
|
+
source = fs.readFileSync(full, "utf8");
|
|
556
|
+
} catch {
|
|
557
|
+
continue;
|
|
558
|
+
}
|
|
559
|
+
try {
|
|
560
|
+
for (const capture of scanSource(source)) {
|
|
561
|
+
found.push({
|
|
562
|
+
event: clip(capture.event),
|
|
563
|
+
label: clip(capture.label),
|
|
564
|
+
file: path__default.default.relative(root, full).split(path__default.default.sep).join("/"),
|
|
565
|
+
line: capture.line
|
|
566
|
+
});
|
|
567
|
+
}
|
|
568
|
+
} catch {
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
function isSourceFile(name) {
|
|
573
|
+
if (name.endsWith(".d.ts")) {
|
|
574
|
+
return false;
|
|
575
|
+
}
|
|
576
|
+
return SOURCE_EXTENSIONS.has(path__default.default.extname(name));
|
|
577
|
+
}
|
|
578
|
+
function clip(value) {
|
|
579
|
+
if (value.length <= MAX_LITERAL_CHARS) {
|
|
580
|
+
return value;
|
|
581
|
+
}
|
|
582
|
+
return `${value.slice(0, MAX_LITERAL_CHARS - 3)}...`;
|
|
583
|
+
}
|
|
584
|
+
function scanSource(source) {
|
|
585
|
+
const captures = [];
|
|
586
|
+
const limit = source.length;
|
|
587
|
+
let index = 0;
|
|
588
|
+
while (index < limit) {
|
|
589
|
+
index = skipTrivia(source, index, limit);
|
|
590
|
+
if (index >= limit) {
|
|
591
|
+
break;
|
|
592
|
+
}
|
|
593
|
+
if (source[index] === "/" && looksLikeRegex(source, index)) {
|
|
594
|
+
index = skipRegex(source, index, limit);
|
|
595
|
+
continue;
|
|
596
|
+
}
|
|
597
|
+
if (source[index] === "`") {
|
|
598
|
+
index = skipTemplate(source, index, limit);
|
|
599
|
+
continue;
|
|
600
|
+
}
|
|
601
|
+
if (source[index] === "'" || source[index] === '"') {
|
|
602
|
+
index = skipQuoted(source, index, limit);
|
|
603
|
+
continue;
|
|
604
|
+
}
|
|
605
|
+
if (isIdentStart(source[index])) {
|
|
606
|
+
const identEnd = readIdentEnd(source, index, limit);
|
|
607
|
+
const ident = source.slice(index, identEnd);
|
|
608
|
+
if (ident === "capture") {
|
|
609
|
+
const after = skipTrivia(source, identEnd, limit);
|
|
610
|
+
if (source[after] === "(") {
|
|
611
|
+
const close = matchingDelimiter(source, after, limit, "(", ")");
|
|
612
|
+
if (close !== -1) {
|
|
613
|
+
captures.push(
|
|
614
|
+
...extractArgument(source, after + 1, close)
|
|
615
|
+
);
|
|
616
|
+
index = close + 1;
|
|
617
|
+
continue;
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
index = identEnd;
|
|
622
|
+
continue;
|
|
623
|
+
}
|
|
624
|
+
index += 1;
|
|
625
|
+
}
|
|
626
|
+
return captures;
|
|
627
|
+
}
|
|
628
|
+
function extractArgument(source, start, end) {
|
|
629
|
+
const index = skipTrivia(source, start, end);
|
|
630
|
+
if (index >= end) {
|
|
631
|
+
return [];
|
|
632
|
+
}
|
|
633
|
+
if (source[index] === "{") {
|
|
634
|
+
const parsed = parseObject(source, index, end);
|
|
635
|
+
return parsed.row === void 0 ? [] : [parsed.row];
|
|
636
|
+
}
|
|
637
|
+
if (source[index] === "[") {
|
|
638
|
+
return parseArray(source, index, end);
|
|
639
|
+
}
|
|
640
|
+
return [];
|
|
641
|
+
}
|
|
642
|
+
function parseArray(source, open, limit) {
|
|
643
|
+
const rows = [];
|
|
644
|
+
let index = open + 1;
|
|
645
|
+
while (index < limit) {
|
|
646
|
+
index = skipTrivia(source, index, limit);
|
|
647
|
+
if (index >= limit || source[index] === "]") {
|
|
648
|
+
break;
|
|
649
|
+
}
|
|
650
|
+
if (source[index] === ",") {
|
|
651
|
+
index += 1;
|
|
652
|
+
continue;
|
|
653
|
+
}
|
|
654
|
+
if (source[index] === "{") {
|
|
655
|
+
const parsed = parseObject(source, index, limit);
|
|
656
|
+
if (parsed.row !== void 0) {
|
|
657
|
+
rows.push(parsed.row);
|
|
658
|
+
}
|
|
659
|
+
index = parsed.next;
|
|
660
|
+
continue;
|
|
661
|
+
}
|
|
662
|
+
index = skipExpression(source, index, limit);
|
|
663
|
+
}
|
|
664
|
+
return rows;
|
|
665
|
+
}
|
|
666
|
+
function parseObject(source, open, limit) {
|
|
667
|
+
const line = lineAt(source, open);
|
|
668
|
+
let event;
|
|
669
|
+
let label;
|
|
670
|
+
let index = open + 1;
|
|
671
|
+
while (index < limit) {
|
|
672
|
+
index = skipTrivia(source, index, limit);
|
|
673
|
+
if (index >= limit) {
|
|
674
|
+
break;
|
|
675
|
+
}
|
|
676
|
+
if (source[index] === "}") {
|
|
677
|
+
return {
|
|
678
|
+
row: fixedCapture(event, label, line),
|
|
679
|
+
next: index + 1
|
|
680
|
+
};
|
|
681
|
+
}
|
|
682
|
+
if (source[index] === ",") {
|
|
683
|
+
index += 1;
|
|
684
|
+
continue;
|
|
685
|
+
}
|
|
686
|
+
if (source.startsWith("...", index)) {
|
|
687
|
+
index = skipExpression(source, index + 3, limit);
|
|
688
|
+
continue;
|
|
689
|
+
}
|
|
690
|
+
const key = readKey(source, index, limit);
|
|
691
|
+
if (key === void 0) {
|
|
692
|
+
index = skipExpression(source, index, limit);
|
|
693
|
+
continue;
|
|
694
|
+
}
|
|
695
|
+
index = skipTrivia(source, key.next, limit);
|
|
696
|
+
if (source[index] !== ":") {
|
|
697
|
+
if (key.name === "event") {
|
|
698
|
+
event = void 0;
|
|
699
|
+
} else if (key.name === "label") {
|
|
700
|
+
label = void 0;
|
|
701
|
+
}
|
|
702
|
+
index = key.next;
|
|
703
|
+
continue;
|
|
704
|
+
}
|
|
705
|
+
const value = readValue(source, index + 1, limit);
|
|
706
|
+
if (key.name === "event") {
|
|
707
|
+
event = value.literal ?? void 0;
|
|
708
|
+
} else if (key.name === "label") {
|
|
709
|
+
label = value.literal ?? void 0;
|
|
710
|
+
}
|
|
711
|
+
index = value.next;
|
|
712
|
+
}
|
|
713
|
+
return {
|
|
714
|
+
row: fixedCapture(event, label, line),
|
|
715
|
+
next: index
|
|
716
|
+
};
|
|
717
|
+
}
|
|
718
|
+
function fixedCapture(event, label, line) {
|
|
719
|
+
if (event === void 0 || label === void 0) {
|
|
720
|
+
return void 0;
|
|
721
|
+
}
|
|
722
|
+
return { event, label, line };
|
|
723
|
+
}
|
|
724
|
+
function readKey(source, start, limit) {
|
|
725
|
+
const index = skipTrivia(source, start, limit);
|
|
726
|
+
if (index >= limit) {
|
|
727
|
+
return void 0;
|
|
728
|
+
}
|
|
729
|
+
if (isIdentStart(source[index])) {
|
|
730
|
+
const end = readIdentEnd(source, index, limit);
|
|
731
|
+
return { name: source.slice(index, end), next: end };
|
|
732
|
+
}
|
|
733
|
+
const quoted = tryReadString(source, index, limit);
|
|
734
|
+
if (quoted?.complete === true && !quoted.template) {
|
|
735
|
+
return { name: quoted.value, next: quoted.next };
|
|
736
|
+
}
|
|
737
|
+
if (source[index] === "[") {
|
|
738
|
+
const inner = skipTrivia(source, index + 1, limit);
|
|
739
|
+
const computed = tryReadString(source, inner, limit);
|
|
740
|
+
if (computed?.complete === true && !computed.template) {
|
|
741
|
+
const after = skipTrivia(source, computed.next, limit);
|
|
742
|
+
if (source[after] === "]") {
|
|
743
|
+
return { name: computed.value, next: after + 1 };
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
}
|
|
747
|
+
return void 0;
|
|
748
|
+
}
|
|
749
|
+
function readValue(source, start, limit) {
|
|
750
|
+
const index = skipTrivia(source, start, limit);
|
|
751
|
+
const quoted = tryReadString(source, index, limit);
|
|
752
|
+
if (quoted?.complete === true) {
|
|
753
|
+
const after = skipTrivia(source, quoted.next, limit);
|
|
754
|
+
if (source.startsWith("as ", after) || source.startsWith("satisfies ", after)) {
|
|
755
|
+
return {
|
|
756
|
+
literal: quoted.value,
|
|
757
|
+
next: skipExpression(source, after, limit)
|
|
758
|
+
};
|
|
759
|
+
}
|
|
760
|
+
if (after >= limit || source[after] === "," || source[after] === "}" || source[after] === "]") {
|
|
761
|
+
return { literal: quoted.value, next: quoted.next };
|
|
762
|
+
}
|
|
763
|
+
}
|
|
764
|
+
return { literal: null, next: skipExpression(source, index, limit) };
|
|
765
|
+
}
|
|
766
|
+
function skipExpression(source, start, limit) {
|
|
767
|
+
let index = start;
|
|
768
|
+
let paren = 0;
|
|
769
|
+
let brace = 0;
|
|
770
|
+
let bracket = 0;
|
|
771
|
+
while (index < limit) {
|
|
772
|
+
const trivia = skipTrivia(source, index, limit);
|
|
773
|
+
if (trivia !== index) {
|
|
774
|
+
index = trivia;
|
|
775
|
+
continue;
|
|
776
|
+
}
|
|
777
|
+
if (index >= limit) {
|
|
778
|
+
break;
|
|
779
|
+
}
|
|
780
|
+
if (source[index] === "/" && looksLikeRegex(source, index)) {
|
|
781
|
+
index = skipRegex(source, index, limit);
|
|
782
|
+
continue;
|
|
783
|
+
}
|
|
784
|
+
if (source[index] === "`") {
|
|
785
|
+
index = skipTemplate(source, index, limit);
|
|
786
|
+
continue;
|
|
787
|
+
}
|
|
788
|
+
if (source[index] === "'" || source[index] === '"') {
|
|
789
|
+
index = skipQuoted(source, index, limit);
|
|
790
|
+
continue;
|
|
791
|
+
}
|
|
792
|
+
const char = source[index];
|
|
793
|
+
if (paren === 0 && brace === 0 && bracket === 0 && (char === "," || char === "}" || char === "]")) {
|
|
794
|
+
return index;
|
|
795
|
+
}
|
|
796
|
+
if (char === "(") {
|
|
797
|
+
paren += 1;
|
|
798
|
+
} else if (char === ")") {
|
|
799
|
+
if (paren === 0) {
|
|
800
|
+
return index;
|
|
801
|
+
}
|
|
802
|
+
paren -= 1;
|
|
803
|
+
} else if (char === "{") {
|
|
804
|
+
brace += 1;
|
|
805
|
+
} else if (char === "}") {
|
|
806
|
+
if (brace === 0) {
|
|
807
|
+
return index;
|
|
808
|
+
}
|
|
809
|
+
brace -= 1;
|
|
810
|
+
} else if (char === "[") {
|
|
811
|
+
bracket += 1;
|
|
812
|
+
} else if (char === "]") {
|
|
813
|
+
if (bracket === 0) {
|
|
814
|
+
return index;
|
|
815
|
+
}
|
|
816
|
+
bracket -= 1;
|
|
817
|
+
}
|
|
818
|
+
index += 1;
|
|
819
|
+
}
|
|
820
|
+
return index;
|
|
821
|
+
}
|
|
822
|
+
function skipTrivia(source, start, limit) {
|
|
823
|
+
let index = start;
|
|
824
|
+
while (index < limit) {
|
|
825
|
+
const char = source[index];
|
|
826
|
+
if (char === " " || char === " " || char === "\n" || char === "\r" || char === "\f") {
|
|
827
|
+
index += 1;
|
|
828
|
+
continue;
|
|
829
|
+
}
|
|
830
|
+
if (char === "/" && source[index + 1] === "/") {
|
|
831
|
+
index += 2;
|
|
832
|
+
while (index < limit && source[index] !== "\n") {
|
|
833
|
+
index += 1;
|
|
834
|
+
}
|
|
835
|
+
continue;
|
|
836
|
+
}
|
|
837
|
+
if (char === "/" && source[index + 1] === "*") {
|
|
838
|
+
index += 2;
|
|
839
|
+
while (index < limit && !(source[index] === "*" && source[index + 1] === "/")) {
|
|
840
|
+
index += 1;
|
|
841
|
+
}
|
|
842
|
+
index = Math.min(limit, index + 2);
|
|
843
|
+
continue;
|
|
844
|
+
}
|
|
845
|
+
break;
|
|
846
|
+
}
|
|
847
|
+
return index;
|
|
848
|
+
}
|
|
849
|
+
function skipQuoted(source, start, limit) {
|
|
850
|
+
const quote = source[start];
|
|
851
|
+
let index = start + 1;
|
|
852
|
+
while (index < limit) {
|
|
853
|
+
if (source[index] === "\\") {
|
|
854
|
+
index += 2;
|
|
855
|
+
continue;
|
|
856
|
+
}
|
|
857
|
+
if (source[index] === quote) {
|
|
858
|
+
return index + 1;
|
|
859
|
+
}
|
|
860
|
+
if (source[index] === "\n" || source[index] === "\r") {
|
|
861
|
+
return index;
|
|
862
|
+
}
|
|
863
|
+
index += 1;
|
|
864
|
+
}
|
|
865
|
+
return limit;
|
|
866
|
+
}
|
|
867
|
+
function skipTemplate(source, start, limit) {
|
|
868
|
+
let index = start + 1;
|
|
869
|
+
while (index < limit) {
|
|
870
|
+
if (source[index] === "\\") {
|
|
871
|
+
index += 2;
|
|
872
|
+
continue;
|
|
873
|
+
}
|
|
874
|
+
if (source[index] === "`") {
|
|
875
|
+
return index + 1;
|
|
876
|
+
}
|
|
877
|
+
if (source[index] === "$" && source[index + 1] === "{") {
|
|
878
|
+
const close = matchingDelimiter(source, index + 1, limit, "{", "}");
|
|
879
|
+
index = close === -1 ? limit : close + 1;
|
|
880
|
+
continue;
|
|
881
|
+
}
|
|
882
|
+
index += 1;
|
|
883
|
+
}
|
|
884
|
+
return limit;
|
|
885
|
+
}
|
|
886
|
+
function tryReadString(source, start, limit) {
|
|
887
|
+
const quote = source[start];
|
|
888
|
+
if (quote !== "'" && quote !== '"' && quote !== "`") {
|
|
889
|
+
return void 0;
|
|
890
|
+
}
|
|
891
|
+
let index = start + 1;
|
|
892
|
+
let value = "";
|
|
893
|
+
let complete = true;
|
|
894
|
+
while (index < limit) {
|
|
895
|
+
const char = source[index];
|
|
896
|
+
if (char === "\\") {
|
|
897
|
+
const escaped = source[index + 1];
|
|
898
|
+
if (escaped === void 0) {
|
|
899
|
+
complete = false;
|
|
900
|
+
break;
|
|
901
|
+
}
|
|
902
|
+
value += unescape(escaped);
|
|
903
|
+
index += 2;
|
|
904
|
+
continue;
|
|
905
|
+
}
|
|
906
|
+
if (quote === "`" && char === "$" && source[index + 1] === "{") {
|
|
907
|
+
return { value: "", next: start, complete: false, template: true };
|
|
908
|
+
}
|
|
909
|
+
if (char === quote) {
|
|
910
|
+
return { value, next: index + 1, complete, template: quote === "`" };
|
|
911
|
+
}
|
|
912
|
+
if ((quote === "'" || quote === '"') && (char === "\n" || char === "\r")) {
|
|
913
|
+
complete = false;
|
|
914
|
+
break;
|
|
915
|
+
}
|
|
916
|
+
value += char;
|
|
917
|
+
index += 1;
|
|
918
|
+
}
|
|
919
|
+
return { value, next: limit, complete: false, template: quote === "`" };
|
|
920
|
+
}
|
|
921
|
+
function unescape(char) {
|
|
922
|
+
switch (char) {
|
|
923
|
+
case "n":
|
|
924
|
+
return "\n";
|
|
925
|
+
case "r":
|
|
926
|
+
return "\r";
|
|
927
|
+
case "t":
|
|
928
|
+
return " ";
|
|
929
|
+
case "\\":
|
|
930
|
+
case "'":
|
|
931
|
+
case '"':
|
|
932
|
+
case "`":
|
|
933
|
+
return char;
|
|
934
|
+
default:
|
|
935
|
+
return char;
|
|
936
|
+
}
|
|
937
|
+
}
|
|
938
|
+
function looksLikeRegex(source, index) {
|
|
939
|
+
if (source[index] !== "/" || source[index + 1] === "/" || source[index + 1] === "*") {
|
|
940
|
+
return false;
|
|
941
|
+
}
|
|
942
|
+
let previous = index - 1;
|
|
943
|
+
while (previous >= 0 && /\s/.test(source[previous])) {
|
|
944
|
+
previous -= 1;
|
|
945
|
+
}
|
|
946
|
+
if (previous < 0) {
|
|
947
|
+
return true;
|
|
948
|
+
}
|
|
949
|
+
if (source[previous] === "*" && source[previous - 1] === "/") {
|
|
950
|
+
return true;
|
|
951
|
+
}
|
|
952
|
+
const char = source[previous];
|
|
953
|
+
if (REGEX_BEFORE.has(char)) {
|
|
954
|
+
return true;
|
|
955
|
+
}
|
|
956
|
+
if (isIdentChar(char)) {
|
|
957
|
+
const end = previous + 1;
|
|
958
|
+
let start = previous;
|
|
959
|
+
while (start > 0 && isIdentChar(source[start - 1])) {
|
|
960
|
+
start -= 1;
|
|
961
|
+
}
|
|
962
|
+
return REGEX_KEYWORDS.has(source.slice(start, end));
|
|
963
|
+
}
|
|
964
|
+
return false;
|
|
965
|
+
}
|
|
966
|
+
function skipRegex(source, start, limit) {
|
|
967
|
+
let index = start + 1;
|
|
968
|
+
let inClass = false;
|
|
969
|
+
while (index < limit) {
|
|
970
|
+
const char = source[index];
|
|
971
|
+
if (char === "\\") {
|
|
972
|
+
index += 2;
|
|
973
|
+
continue;
|
|
974
|
+
}
|
|
975
|
+
if (char === "[" && !inClass) {
|
|
976
|
+
inClass = true;
|
|
977
|
+
} else if (char === "]" && inClass) {
|
|
978
|
+
inClass = false;
|
|
979
|
+
} else if (char === "/" && !inClass) {
|
|
980
|
+
index += 1;
|
|
981
|
+
while (index < limit && /[a-z]/i.test(source[index])) {
|
|
982
|
+
index += 1;
|
|
983
|
+
}
|
|
984
|
+
return index;
|
|
985
|
+
} else if (char === "\n") {
|
|
986
|
+
return start + 1;
|
|
987
|
+
}
|
|
988
|
+
index += 1;
|
|
989
|
+
}
|
|
990
|
+
return limit;
|
|
991
|
+
}
|
|
992
|
+
function matchingDelimiter(source, openIndex, limit, open, close) {
|
|
993
|
+
let depth = 1;
|
|
994
|
+
let index = openIndex + 1;
|
|
995
|
+
while (index < limit) {
|
|
996
|
+
const trivia = skipTrivia(source, index, limit);
|
|
997
|
+
if (trivia !== index) {
|
|
998
|
+
index = trivia;
|
|
999
|
+
continue;
|
|
1000
|
+
}
|
|
1001
|
+
if (source[index] === "/" && looksLikeRegex(source, index)) {
|
|
1002
|
+
index = skipRegex(source, index, limit);
|
|
1003
|
+
continue;
|
|
1004
|
+
}
|
|
1005
|
+
if (source[index] === "`") {
|
|
1006
|
+
index = skipTemplate(source, index, limit);
|
|
1007
|
+
continue;
|
|
1008
|
+
}
|
|
1009
|
+
if (source[index] === "'" || source[index] === '"') {
|
|
1010
|
+
index = skipQuoted(source, index, limit);
|
|
1011
|
+
continue;
|
|
1012
|
+
}
|
|
1013
|
+
if (source[index] === open) {
|
|
1014
|
+
depth += 1;
|
|
1015
|
+
} else if (source[index] === close) {
|
|
1016
|
+
depth -= 1;
|
|
1017
|
+
if (depth === 0) {
|
|
1018
|
+
return index;
|
|
1019
|
+
}
|
|
1020
|
+
}
|
|
1021
|
+
index += 1;
|
|
1022
|
+
}
|
|
1023
|
+
return -1;
|
|
1024
|
+
}
|
|
1025
|
+
function isIdentStart(char) {
|
|
1026
|
+
return /[A-Za-z_$]/.test(char);
|
|
1027
|
+
}
|
|
1028
|
+
function isIdentChar(char) {
|
|
1029
|
+
return /[A-Za-z0-9_$]/.test(char);
|
|
1030
|
+
}
|
|
1031
|
+
function readIdentEnd(source, start, limit) {
|
|
1032
|
+
let index = start + 1;
|
|
1033
|
+
while (index < limit && isIdentChar(source[index])) {
|
|
1034
|
+
index += 1;
|
|
1035
|
+
}
|
|
1036
|
+
return index;
|
|
1037
|
+
}
|
|
1038
|
+
function lineAt(source, index) {
|
|
1039
|
+
let line = 1;
|
|
1040
|
+
const stop = Math.min(index, source.length);
|
|
1041
|
+
for (let cursor = 0; cursor < stop; cursor += 1) {
|
|
1042
|
+
if (source.charCodeAt(cursor) === 10) {
|
|
1043
|
+
line += 1;
|
|
1044
|
+
}
|
|
1045
|
+
}
|
|
1046
|
+
return line;
|
|
1047
|
+
}
|
|
412
1048
|
var RANDOM_BITS = 74n;
|
|
413
1049
|
var RANDOM_MASK = (1n << RANDOM_BITS) - 1n;
|
|
414
1050
|
var MAX_TIMESTAMP = (1n << 48n) - 1n;
|
|
@@ -480,7 +1116,7 @@ function uuidv7() {
|
|
|
480
1116
|
|
|
481
1117
|
// package.json
|
|
482
1118
|
var package_default = {
|
|
483
|
-
version: "2.2.
|
|
1119
|
+
version: "2.2.5"};
|
|
484
1120
|
|
|
485
1121
|
// src/client.ts
|
|
486
1122
|
var TRAFFICWAR_DEFAULT_BASE_URL = "https://ingest.trafficwar.tech";
|
|
@@ -579,6 +1215,18 @@ function validateBooleanOption(name, value, fallback) {
|
|
|
579
1215
|
}
|
|
580
1216
|
return actual;
|
|
581
1217
|
}
|
|
1218
|
+
function validateCatalogRoot(value) {
|
|
1219
|
+
if (value === void 0) {
|
|
1220
|
+
return void 0;
|
|
1221
|
+
}
|
|
1222
|
+
if (typeof value !== "string" || value.length === 0 || value.length > 4096) {
|
|
1223
|
+
throw new TrafficWarValidationError(
|
|
1224
|
+
"catalogRoot must be a non-empty path",
|
|
1225
|
+
{ path: "options.catalogRoot" }
|
|
1226
|
+
);
|
|
1227
|
+
}
|
|
1228
|
+
return value;
|
|
1229
|
+
}
|
|
582
1230
|
function validateCompression(value) {
|
|
583
1231
|
const actual = value ?? "auto";
|
|
584
1232
|
if (actual !== "auto" && actual !== "gzip" && actual !== "none") {
|
|
@@ -815,6 +1463,7 @@ function parseSuccess(response, parsed, expectedCount, idempotencyKey) {
|
|
|
815
1463
|
var TrafficWar = class {
|
|
816
1464
|
baseUrl;
|
|
817
1465
|
debug;
|
|
1466
|
+
verbose;
|
|
818
1467
|
timeoutMs;
|
|
819
1468
|
maxRetries;
|
|
820
1469
|
compression;
|
|
@@ -845,6 +1494,8 @@ var TrafficWar = class {
|
|
|
845
1494
|
this.#apiKey = validateApiKey(options.apiKey);
|
|
846
1495
|
this.baseUrl = normalizeBaseUrl(options.baseUrl);
|
|
847
1496
|
this.debug = validateBooleanOption("debug", options.debug, false);
|
|
1497
|
+
this.verbose = validateBooleanOption("verbose", options.verbose, false);
|
|
1498
|
+
const catalogRoot = validateCatalogRoot(options.catalogRoot);
|
|
848
1499
|
this.timeoutMs = validateIntegerOption(
|
|
849
1500
|
"timeoutMs",
|
|
850
1501
|
options.timeoutMs,
|
|
@@ -903,8 +1554,23 @@ var TrafficWar = class {
|
|
|
903
1554
|
flushIntervalMs: this.flushIntervalMs,
|
|
904
1555
|
maxQueueSize: this.maxQueueSize,
|
|
905
1556
|
maxRetries: this.maxRetries,
|
|
906
|
-
timeoutMs: this.timeoutMs
|
|
1557
|
+
timeoutMs: this.timeoutMs,
|
|
1558
|
+
verbose: this.verbose
|
|
907
1559
|
});
|
|
1560
|
+
if (this.verbose) {
|
|
1561
|
+
this.#printCaptureCatalog(catalogRoot ?? process.cwd());
|
|
1562
|
+
}
|
|
1563
|
+
}
|
|
1564
|
+
#printCaptureCatalog(root) {
|
|
1565
|
+
try {
|
|
1566
|
+
console.info(formatCaptureCatalog(discoverCaptures(root)));
|
|
1567
|
+
} catch (error) {
|
|
1568
|
+
const message = error instanceof Error ? error.message : "unknown error";
|
|
1569
|
+
try {
|
|
1570
|
+
console.info(`[TrafficWar] static capture scan failed: ${message}`);
|
|
1571
|
+
} catch {
|
|
1572
|
+
}
|
|
1573
|
+
}
|
|
908
1574
|
}
|
|
909
1575
|
#debugLog(message, details) {
|
|
910
1576
|
if (!this.debug) {
|
|
@@ -939,10 +1605,10 @@ var TrafficWar = class {
|
|
|
939
1605
|
if (isBatch) {
|
|
940
1606
|
for (let index = 0; index < events.length; index += 1) {
|
|
941
1607
|
if (!(index in events)) {
|
|
942
|
-
const
|
|
1608
|
+
const path2 = `events[${index}]`;
|
|
943
1609
|
throw new TrafficWarValidationError(
|
|
944
|
-
`${
|
|
945
|
-
{ path }
|
|
1610
|
+
`${path2} is missing; sparse event arrays are not supported`,
|
|
1611
|
+
{ path: path2 }
|
|
946
1612
|
);
|
|
947
1613
|
}
|
|
948
1614
|
}
|
|
@@ -955,8 +1621,8 @@ var TrafficWar = class {
|
|
|
955
1621
|
}
|
|
956
1622
|
const normalized = [];
|
|
957
1623
|
for (let index = 0; index < events.length; index += 1) {
|
|
958
|
-
const
|
|
959
|
-
normalized.push(normalizeEvent(events[index],
|
|
1624
|
+
const path2 = isBatch ? `events[${index}]` : "event";
|
|
1625
|
+
normalized.push(normalizeEvent(events[index], path2));
|
|
960
1626
|
}
|
|
961
1627
|
for (const event of normalized) {
|
|
962
1628
|
if (!Object.hasOwn(event, "event_id")) {
|
|
@@ -967,10 +1633,10 @@ var TrafficWar = class {
|
|
|
967
1633
|
for (let index = 0; index < normalized.length; index += 1) {
|
|
968
1634
|
const eventId = normalized[index].event_id;
|
|
969
1635
|
if (incomingEventIds.has(eventId) || this.#pendingEventIds.has(eventId)) {
|
|
970
|
-
const
|
|
1636
|
+
const path2 = isBatch ? `events[${index}].event_id` : "event.event_id";
|
|
971
1637
|
throw new TrafficWarValidationError(
|
|
972
|
-
`${
|
|
973
|
-
{ path }
|
|
1638
|
+
`${path2} duplicates an unacknowledged event_id`,
|
|
1639
|
+
{ path: path2 }
|
|
974
1640
|
);
|
|
975
1641
|
}
|
|
976
1642
|
incomingEventIds.add(eventId);
|