@trafficwar/node 2.2.3 → 2.2.4
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 +19 -0
- package/dist/index.cjs +739 -65
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +11 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +735 -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,644 @@ 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 === "<dynamic>" || value === "<missing>" || 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 saw = false;
|
|
665
|
+
let index = open + 1;
|
|
666
|
+
while (index < limit) {
|
|
667
|
+
index = skipTrivia(source, index, limit);
|
|
668
|
+
if (index >= limit) {
|
|
669
|
+
break;
|
|
670
|
+
}
|
|
671
|
+
if (source[index] === "}") {
|
|
672
|
+
return {
|
|
673
|
+
row: saw ? finishRow(event, label, line) : void 0,
|
|
674
|
+
next: index + 1
|
|
675
|
+
};
|
|
676
|
+
}
|
|
677
|
+
if (source[index] === ",") {
|
|
678
|
+
index += 1;
|
|
679
|
+
continue;
|
|
680
|
+
}
|
|
681
|
+
if (source.startsWith("...", index)) {
|
|
682
|
+
index = skipExpression(source, index + 3, limit);
|
|
683
|
+
continue;
|
|
684
|
+
}
|
|
685
|
+
const key = readKey(source, index, limit);
|
|
686
|
+
if (key === void 0) {
|
|
687
|
+
index = skipExpression(source, index, limit);
|
|
688
|
+
continue;
|
|
689
|
+
}
|
|
690
|
+
index = skipTrivia(source, key.next, limit);
|
|
691
|
+
if (source[index] !== ":") {
|
|
692
|
+
if (key.name === "event" || key.name === "label") {
|
|
693
|
+
saw = true;
|
|
694
|
+
if (key.name === "event") {
|
|
695
|
+
event = "<dynamic>";
|
|
696
|
+
} else {
|
|
697
|
+
label = "<dynamic>";
|
|
698
|
+
}
|
|
699
|
+
}
|
|
700
|
+
continue;
|
|
701
|
+
}
|
|
702
|
+
const value = readValue(source, index + 1, limit);
|
|
703
|
+
if (key.name === "event" || key.name === "label") {
|
|
704
|
+
saw = true;
|
|
705
|
+
const text = value.literal ?? "<dynamic>";
|
|
706
|
+
if (key.name === "event") {
|
|
707
|
+
event = text;
|
|
708
|
+
} else {
|
|
709
|
+
label = text;
|
|
710
|
+
}
|
|
711
|
+
}
|
|
712
|
+
index = value.next;
|
|
713
|
+
}
|
|
714
|
+
return {
|
|
715
|
+
row: saw ? finishRow(event, label, line) : void 0,
|
|
716
|
+
next: index
|
|
717
|
+
};
|
|
718
|
+
}
|
|
719
|
+
function finishRow(event, label, line) {
|
|
720
|
+
return {
|
|
721
|
+
event: event ?? "<missing>",
|
|
722
|
+
label: label ?? "<missing>",
|
|
723
|
+
line
|
|
724
|
+
};
|
|
725
|
+
}
|
|
726
|
+
function readKey(source, start, limit) {
|
|
727
|
+
const index = skipTrivia(source, start, limit);
|
|
728
|
+
if (index >= limit) {
|
|
729
|
+
return void 0;
|
|
730
|
+
}
|
|
731
|
+
if (isIdentStart(source[index])) {
|
|
732
|
+
const end = readIdentEnd(source, index, limit);
|
|
733
|
+
return { name: source.slice(index, end), next: end };
|
|
734
|
+
}
|
|
735
|
+
const quoted = tryReadString(source, index, limit);
|
|
736
|
+
if (quoted?.complete === true && !quoted.template) {
|
|
737
|
+
return { name: quoted.value, next: quoted.next };
|
|
738
|
+
}
|
|
739
|
+
if (source[index] === "[") {
|
|
740
|
+
const inner = skipTrivia(source, index + 1, limit);
|
|
741
|
+
const computed = tryReadString(source, inner, limit);
|
|
742
|
+
if (computed?.complete === true && !computed.template) {
|
|
743
|
+
const after = skipTrivia(source, computed.next, limit);
|
|
744
|
+
if (source[after] === "]") {
|
|
745
|
+
return { name: computed.value, next: after + 1 };
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
}
|
|
749
|
+
return void 0;
|
|
750
|
+
}
|
|
751
|
+
function readValue(source, start, limit) {
|
|
752
|
+
const index = skipTrivia(source, start, limit);
|
|
753
|
+
const quoted = tryReadString(source, index, limit);
|
|
754
|
+
if (quoted?.complete === true) {
|
|
755
|
+
const after = skipTrivia(source, quoted.next, limit);
|
|
756
|
+
if (source.startsWith("as ", after) || source.startsWith("satisfies ", after)) {
|
|
757
|
+
return {
|
|
758
|
+
literal: quoted.value,
|
|
759
|
+
next: skipExpression(source, after, limit)
|
|
760
|
+
};
|
|
761
|
+
}
|
|
762
|
+
if (after >= limit || source[after] === "," || source[after] === "}" || source[after] === "]") {
|
|
763
|
+
return { literal: quoted.value, next: quoted.next };
|
|
764
|
+
}
|
|
765
|
+
}
|
|
766
|
+
return { literal: null, next: skipExpression(source, index, limit) };
|
|
767
|
+
}
|
|
768
|
+
function skipExpression(source, start, limit) {
|
|
769
|
+
let index = start;
|
|
770
|
+
let paren = 0;
|
|
771
|
+
let brace = 0;
|
|
772
|
+
let bracket = 0;
|
|
773
|
+
while (index < limit) {
|
|
774
|
+
const trivia = skipTrivia(source, index, limit);
|
|
775
|
+
if (trivia !== index) {
|
|
776
|
+
index = trivia;
|
|
777
|
+
continue;
|
|
778
|
+
}
|
|
779
|
+
if (index >= limit) {
|
|
780
|
+
break;
|
|
781
|
+
}
|
|
782
|
+
if (source[index] === "/" && looksLikeRegex(source, index)) {
|
|
783
|
+
index = skipRegex(source, index, limit);
|
|
784
|
+
continue;
|
|
785
|
+
}
|
|
786
|
+
if (source[index] === "`") {
|
|
787
|
+
index = skipTemplate(source, index, limit);
|
|
788
|
+
continue;
|
|
789
|
+
}
|
|
790
|
+
if (source[index] === "'" || source[index] === '"') {
|
|
791
|
+
index = skipQuoted(source, index, limit);
|
|
792
|
+
continue;
|
|
793
|
+
}
|
|
794
|
+
const char = source[index];
|
|
795
|
+
if (paren === 0 && brace === 0 && bracket === 0 && (char === "," || char === "}" || char === "]")) {
|
|
796
|
+
return index;
|
|
797
|
+
}
|
|
798
|
+
if (char === "(") {
|
|
799
|
+
paren += 1;
|
|
800
|
+
} else if (char === ")") {
|
|
801
|
+
if (paren === 0) {
|
|
802
|
+
return index;
|
|
803
|
+
}
|
|
804
|
+
paren -= 1;
|
|
805
|
+
} else if (char === "{") {
|
|
806
|
+
brace += 1;
|
|
807
|
+
} else if (char === "}") {
|
|
808
|
+
if (brace === 0) {
|
|
809
|
+
return index;
|
|
810
|
+
}
|
|
811
|
+
brace -= 1;
|
|
812
|
+
} else if (char === "[") {
|
|
813
|
+
bracket += 1;
|
|
814
|
+
} else if (char === "]") {
|
|
815
|
+
if (bracket === 0) {
|
|
816
|
+
return index;
|
|
817
|
+
}
|
|
818
|
+
bracket -= 1;
|
|
819
|
+
}
|
|
820
|
+
index += 1;
|
|
821
|
+
}
|
|
822
|
+
return index;
|
|
823
|
+
}
|
|
824
|
+
function skipTrivia(source, start, limit) {
|
|
825
|
+
let index = start;
|
|
826
|
+
while (index < limit) {
|
|
827
|
+
const char = source[index];
|
|
828
|
+
if (char === " " || char === " " || char === "\n" || char === "\r" || char === "\f") {
|
|
829
|
+
index += 1;
|
|
830
|
+
continue;
|
|
831
|
+
}
|
|
832
|
+
if (char === "/" && source[index + 1] === "/") {
|
|
833
|
+
index += 2;
|
|
834
|
+
while (index < limit && source[index] !== "\n") {
|
|
835
|
+
index += 1;
|
|
836
|
+
}
|
|
837
|
+
continue;
|
|
838
|
+
}
|
|
839
|
+
if (char === "/" && source[index + 1] === "*") {
|
|
840
|
+
index += 2;
|
|
841
|
+
while (index < limit && !(source[index] === "*" && source[index + 1] === "/")) {
|
|
842
|
+
index += 1;
|
|
843
|
+
}
|
|
844
|
+
index = Math.min(limit, index + 2);
|
|
845
|
+
continue;
|
|
846
|
+
}
|
|
847
|
+
break;
|
|
848
|
+
}
|
|
849
|
+
return index;
|
|
850
|
+
}
|
|
851
|
+
function skipQuoted(source, start, limit) {
|
|
852
|
+
const quote = source[start];
|
|
853
|
+
let index = start + 1;
|
|
854
|
+
while (index < limit) {
|
|
855
|
+
if (source[index] === "\\") {
|
|
856
|
+
index += 2;
|
|
857
|
+
continue;
|
|
858
|
+
}
|
|
859
|
+
if (source[index] === quote) {
|
|
860
|
+
return index + 1;
|
|
861
|
+
}
|
|
862
|
+
if (source[index] === "\n" || source[index] === "\r") {
|
|
863
|
+
return index;
|
|
864
|
+
}
|
|
865
|
+
index += 1;
|
|
866
|
+
}
|
|
867
|
+
return limit;
|
|
868
|
+
}
|
|
869
|
+
function skipTemplate(source, start, limit) {
|
|
870
|
+
let index = start + 1;
|
|
871
|
+
while (index < limit) {
|
|
872
|
+
if (source[index] === "\\") {
|
|
873
|
+
index += 2;
|
|
874
|
+
continue;
|
|
875
|
+
}
|
|
876
|
+
if (source[index] === "`") {
|
|
877
|
+
return index + 1;
|
|
878
|
+
}
|
|
879
|
+
if (source[index] === "$" && source[index + 1] === "{") {
|
|
880
|
+
const close = matchingDelimiter(source, index + 1, limit, "{", "}");
|
|
881
|
+
index = close === -1 ? limit : close + 1;
|
|
882
|
+
continue;
|
|
883
|
+
}
|
|
884
|
+
index += 1;
|
|
885
|
+
}
|
|
886
|
+
return limit;
|
|
887
|
+
}
|
|
888
|
+
function tryReadString(source, start, limit) {
|
|
889
|
+
const quote = source[start];
|
|
890
|
+
if (quote !== "'" && quote !== '"' && quote !== "`") {
|
|
891
|
+
return void 0;
|
|
892
|
+
}
|
|
893
|
+
let index = start + 1;
|
|
894
|
+
let value = "";
|
|
895
|
+
let complete = true;
|
|
896
|
+
while (index < limit) {
|
|
897
|
+
const char = source[index];
|
|
898
|
+
if (char === "\\") {
|
|
899
|
+
const escaped = source[index + 1];
|
|
900
|
+
if (escaped === void 0) {
|
|
901
|
+
complete = false;
|
|
902
|
+
break;
|
|
903
|
+
}
|
|
904
|
+
value += unescape(escaped);
|
|
905
|
+
index += 2;
|
|
906
|
+
continue;
|
|
907
|
+
}
|
|
908
|
+
if (quote === "`" && char === "$" && source[index + 1] === "{") {
|
|
909
|
+
return { value: "", next: start, complete: false, template: true };
|
|
910
|
+
}
|
|
911
|
+
if (char === quote) {
|
|
912
|
+
return { value, next: index + 1, complete, template: quote === "`" };
|
|
913
|
+
}
|
|
914
|
+
if ((quote === "'" || quote === '"') && (char === "\n" || char === "\r")) {
|
|
915
|
+
complete = false;
|
|
916
|
+
break;
|
|
917
|
+
}
|
|
918
|
+
value += char;
|
|
919
|
+
index += 1;
|
|
920
|
+
}
|
|
921
|
+
return { value, next: limit, complete: false, template: quote === "`" };
|
|
922
|
+
}
|
|
923
|
+
function unescape(char) {
|
|
924
|
+
switch (char) {
|
|
925
|
+
case "n":
|
|
926
|
+
return "\n";
|
|
927
|
+
case "r":
|
|
928
|
+
return "\r";
|
|
929
|
+
case "t":
|
|
930
|
+
return " ";
|
|
931
|
+
case "\\":
|
|
932
|
+
case "'":
|
|
933
|
+
case '"':
|
|
934
|
+
case "`":
|
|
935
|
+
return char;
|
|
936
|
+
default:
|
|
937
|
+
return char;
|
|
938
|
+
}
|
|
939
|
+
}
|
|
940
|
+
function looksLikeRegex(source, index) {
|
|
941
|
+
if (source[index] !== "/" || source[index + 1] === "/" || source[index + 1] === "*") {
|
|
942
|
+
return false;
|
|
943
|
+
}
|
|
944
|
+
let previous = index - 1;
|
|
945
|
+
while (previous >= 0 && /\s/.test(source[previous])) {
|
|
946
|
+
previous -= 1;
|
|
947
|
+
}
|
|
948
|
+
if (previous < 0) {
|
|
949
|
+
return true;
|
|
950
|
+
}
|
|
951
|
+
if (source[previous] === "*" && source[previous - 1] === "/") {
|
|
952
|
+
return true;
|
|
953
|
+
}
|
|
954
|
+
const char = source[previous];
|
|
955
|
+
if (REGEX_BEFORE.has(char)) {
|
|
956
|
+
return true;
|
|
957
|
+
}
|
|
958
|
+
if (isIdentChar(char)) {
|
|
959
|
+
const end = previous + 1;
|
|
960
|
+
let start = previous;
|
|
961
|
+
while (start > 0 && isIdentChar(source[start - 1])) {
|
|
962
|
+
start -= 1;
|
|
963
|
+
}
|
|
964
|
+
return REGEX_KEYWORDS.has(source.slice(start, end));
|
|
965
|
+
}
|
|
966
|
+
return false;
|
|
967
|
+
}
|
|
968
|
+
function skipRegex(source, start, limit) {
|
|
969
|
+
let index = start + 1;
|
|
970
|
+
let inClass = false;
|
|
971
|
+
while (index < limit) {
|
|
972
|
+
const char = source[index];
|
|
973
|
+
if (char === "\\") {
|
|
974
|
+
index += 2;
|
|
975
|
+
continue;
|
|
976
|
+
}
|
|
977
|
+
if (char === "[" && !inClass) {
|
|
978
|
+
inClass = true;
|
|
979
|
+
} else if (char === "]" && inClass) {
|
|
980
|
+
inClass = false;
|
|
981
|
+
} else if (char === "/" && !inClass) {
|
|
982
|
+
index += 1;
|
|
983
|
+
while (index < limit && /[a-z]/i.test(source[index])) {
|
|
984
|
+
index += 1;
|
|
985
|
+
}
|
|
986
|
+
return index;
|
|
987
|
+
} else if (char === "\n") {
|
|
988
|
+
return start + 1;
|
|
989
|
+
}
|
|
990
|
+
index += 1;
|
|
991
|
+
}
|
|
992
|
+
return limit;
|
|
993
|
+
}
|
|
994
|
+
function matchingDelimiter(source, openIndex, limit, open, close) {
|
|
995
|
+
let depth = 1;
|
|
996
|
+
let index = openIndex + 1;
|
|
997
|
+
while (index < limit) {
|
|
998
|
+
const trivia = skipTrivia(source, index, limit);
|
|
999
|
+
if (trivia !== index) {
|
|
1000
|
+
index = trivia;
|
|
1001
|
+
continue;
|
|
1002
|
+
}
|
|
1003
|
+
if (source[index] === "/" && looksLikeRegex(source, index)) {
|
|
1004
|
+
index = skipRegex(source, index, limit);
|
|
1005
|
+
continue;
|
|
1006
|
+
}
|
|
1007
|
+
if (source[index] === "`") {
|
|
1008
|
+
index = skipTemplate(source, index, limit);
|
|
1009
|
+
continue;
|
|
1010
|
+
}
|
|
1011
|
+
if (source[index] === "'" || source[index] === '"') {
|
|
1012
|
+
index = skipQuoted(source, index, limit);
|
|
1013
|
+
continue;
|
|
1014
|
+
}
|
|
1015
|
+
if (source[index] === open) {
|
|
1016
|
+
depth += 1;
|
|
1017
|
+
} else if (source[index] === close) {
|
|
1018
|
+
depth -= 1;
|
|
1019
|
+
if (depth === 0) {
|
|
1020
|
+
return index;
|
|
1021
|
+
}
|
|
1022
|
+
}
|
|
1023
|
+
index += 1;
|
|
1024
|
+
}
|
|
1025
|
+
return -1;
|
|
1026
|
+
}
|
|
1027
|
+
function isIdentStart(char) {
|
|
1028
|
+
return /[A-Za-z_$]/.test(char);
|
|
1029
|
+
}
|
|
1030
|
+
function isIdentChar(char) {
|
|
1031
|
+
return /[A-Za-z0-9_$]/.test(char);
|
|
1032
|
+
}
|
|
1033
|
+
function readIdentEnd(source, start, limit) {
|
|
1034
|
+
let index = start + 1;
|
|
1035
|
+
while (index < limit && isIdentChar(source[index])) {
|
|
1036
|
+
index += 1;
|
|
1037
|
+
}
|
|
1038
|
+
return index;
|
|
1039
|
+
}
|
|
1040
|
+
function lineAt(source, index) {
|
|
1041
|
+
let line = 1;
|
|
1042
|
+
const stop = Math.min(index, source.length);
|
|
1043
|
+
for (let cursor = 0; cursor < stop; cursor += 1) {
|
|
1044
|
+
if (source.charCodeAt(cursor) === 10) {
|
|
1045
|
+
line += 1;
|
|
1046
|
+
}
|
|
1047
|
+
}
|
|
1048
|
+
return line;
|
|
1049
|
+
}
|
|
410
1050
|
var RANDOM_BITS = 74n;
|
|
411
1051
|
var RANDOM_MASK = (1n << RANDOM_BITS) - 1n;
|
|
412
1052
|
var MAX_TIMESTAMP = (1n << 48n) - 1n;
|
|
@@ -478,7 +1118,7 @@ function uuidv7() {
|
|
|
478
1118
|
|
|
479
1119
|
// package.json
|
|
480
1120
|
var package_default = {
|
|
481
|
-
version: "2.2.
|
|
1121
|
+
version: "2.2.4"};
|
|
482
1122
|
|
|
483
1123
|
// src/client.ts
|
|
484
1124
|
var TRAFFICWAR_DEFAULT_BASE_URL = "https://ingest.trafficwar.tech";
|
|
@@ -577,6 +1217,18 @@ function validateBooleanOption(name, value, fallback) {
|
|
|
577
1217
|
}
|
|
578
1218
|
return actual;
|
|
579
1219
|
}
|
|
1220
|
+
function validateCatalogRoot(value) {
|
|
1221
|
+
if (value === void 0) {
|
|
1222
|
+
return void 0;
|
|
1223
|
+
}
|
|
1224
|
+
if (typeof value !== "string" || value.length === 0 || value.length > 4096) {
|
|
1225
|
+
throw new TrafficWarValidationError(
|
|
1226
|
+
"catalogRoot must be a non-empty path",
|
|
1227
|
+
{ path: "options.catalogRoot" }
|
|
1228
|
+
);
|
|
1229
|
+
}
|
|
1230
|
+
return value;
|
|
1231
|
+
}
|
|
580
1232
|
function validateCompression(value) {
|
|
581
1233
|
const actual = value ?? "auto";
|
|
582
1234
|
if (actual !== "auto" && actual !== "gzip" && actual !== "none") {
|
|
@@ -813,6 +1465,7 @@ function parseSuccess(response, parsed, expectedCount, idempotencyKey) {
|
|
|
813
1465
|
var TrafficWar = class {
|
|
814
1466
|
baseUrl;
|
|
815
1467
|
debug;
|
|
1468
|
+
verbose;
|
|
816
1469
|
timeoutMs;
|
|
817
1470
|
maxRetries;
|
|
818
1471
|
compression;
|
|
@@ -843,6 +1496,8 @@ var TrafficWar = class {
|
|
|
843
1496
|
this.#apiKey = validateApiKey(options.apiKey);
|
|
844
1497
|
this.baseUrl = normalizeBaseUrl(options.baseUrl);
|
|
845
1498
|
this.debug = validateBooleanOption("debug", options.debug, false);
|
|
1499
|
+
this.verbose = validateBooleanOption("verbose", options.verbose, false);
|
|
1500
|
+
const catalogRoot = validateCatalogRoot(options.catalogRoot);
|
|
846
1501
|
this.timeoutMs = validateIntegerOption(
|
|
847
1502
|
"timeoutMs",
|
|
848
1503
|
options.timeoutMs,
|
|
@@ -901,8 +1556,23 @@ var TrafficWar = class {
|
|
|
901
1556
|
flushIntervalMs: this.flushIntervalMs,
|
|
902
1557
|
maxQueueSize: this.maxQueueSize,
|
|
903
1558
|
maxRetries: this.maxRetries,
|
|
904
|
-
timeoutMs: this.timeoutMs
|
|
1559
|
+
timeoutMs: this.timeoutMs,
|
|
1560
|
+
verbose: this.verbose
|
|
905
1561
|
});
|
|
1562
|
+
if (this.verbose) {
|
|
1563
|
+
this.#printCaptureCatalog(catalogRoot ?? process.cwd());
|
|
1564
|
+
}
|
|
1565
|
+
}
|
|
1566
|
+
#printCaptureCatalog(root) {
|
|
1567
|
+
try {
|
|
1568
|
+
console.info(formatCaptureCatalog(discoverCaptures(root)));
|
|
1569
|
+
} catch (error) {
|
|
1570
|
+
const message = error instanceof Error ? error.message : "unknown error";
|
|
1571
|
+
try {
|
|
1572
|
+
console.info(`[TrafficWar] static capture scan failed: ${message}`);
|
|
1573
|
+
} catch {
|
|
1574
|
+
}
|
|
1575
|
+
}
|
|
906
1576
|
}
|
|
907
1577
|
#debugLog(message, details) {
|
|
908
1578
|
if (!this.debug) {
|
|
@@ -937,10 +1607,10 @@ var TrafficWar = class {
|
|
|
937
1607
|
if (isBatch) {
|
|
938
1608
|
for (let index = 0; index < events.length; index += 1) {
|
|
939
1609
|
if (!(index in events)) {
|
|
940
|
-
const
|
|
1610
|
+
const path2 = `events[${index}]`;
|
|
941
1611
|
throw new TrafficWarValidationError(
|
|
942
|
-
`${
|
|
943
|
-
{ path }
|
|
1612
|
+
`${path2} is missing; sparse event arrays are not supported`,
|
|
1613
|
+
{ path: path2 }
|
|
944
1614
|
);
|
|
945
1615
|
}
|
|
946
1616
|
}
|
|
@@ -953,8 +1623,8 @@ var TrafficWar = class {
|
|
|
953
1623
|
}
|
|
954
1624
|
const normalized = [];
|
|
955
1625
|
for (let index = 0; index < events.length; index += 1) {
|
|
956
|
-
const
|
|
957
|
-
normalized.push(normalizeEvent(events[index],
|
|
1626
|
+
const path2 = isBatch ? `events[${index}]` : "event";
|
|
1627
|
+
normalized.push(normalizeEvent(events[index], path2));
|
|
958
1628
|
}
|
|
959
1629
|
for (const event of normalized) {
|
|
960
1630
|
if (!Object.hasOwn(event, "event_id")) {
|
|
@@ -965,10 +1635,10 @@ var TrafficWar = class {
|
|
|
965
1635
|
for (let index = 0; index < normalized.length; index += 1) {
|
|
966
1636
|
const eventId = normalized[index].event_id;
|
|
967
1637
|
if (incomingEventIds.has(eventId) || this.#pendingEventIds.has(eventId)) {
|
|
968
|
-
const
|
|
1638
|
+
const path2 = isBatch ? `events[${index}].event_id` : "event.event_id";
|
|
969
1639
|
throw new TrafficWarValidationError(
|
|
970
|
-
`${
|
|
971
|
-
{ path }
|
|
1640
|
+
`${path2} duplicates an unacknowledged event_id`,
|
|
1641
|
+
{ path: path2 }
|
|
972
1642
|
);
|
|
973
1643
|
}
|
|
974
1644
|
incomingEventIds.add(eventId);
|