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