@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/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, path, idempotencyKey, cause) {
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, path, ancestors, idempotencyKey) {
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
- `${path} must contain only finite JSON numbers`,
122
- path,
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
- `${path} contains a value that JSON cannot represent`,
131
- path,
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
- `${path} contains a Date; only timestamp accepts Date values`,
138
- path,
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
- `${path} contains a circular reference`,
145
- path,
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
- `${path} contains a non-JSON object`,
154
- path,
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
- `${path}[${index}] is missing; sparse arrays are not valid JSON values`,
167
- `${path}[${index}]`,
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
- `${path}[${index}]`,
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
- `${path}.${key}`,
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, path, idempotencyKey) {
202
+ function normalizeTimestamp(timestamp, path2, idempotencyKey) {
197
203
  if (timestamp instanceof Date) {
198
204
  if (!Number.isFinite(timestamp.getTime())) {
199
205
  throw validationError(
200
- `${path} must be a valid Date`,
201
- path,
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
- `${path} must be an integer epoch-millisecond value`,
211
- path,
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
- `${path} must be an RFC3339 string, epoch-millisecond number, or Date`,
220
- path,
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
- `${path} must be an RFC3339 string, epoch-millisecond number, or Date`,
251
- path,
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, path, idempotencyKey) {
263
+ function normalizeHttpMethod(value, path2, idempotencyKey) {
258
264
  if (typeof value !== "string") {
259
265
  throw validationError(
260
- `${path} must be an RFC HTTP token from 1 to 64 characters`,
261
- path,
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
- `${path} must be an RFC HTTP token from 1 to 64 characters`,
269
- path,
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, path, idempotencyKey) {
281
+ function normalizeEvent(input, path2, idempotencyKey) {
276
282
  if (input === null || typeof input !== "object" || Array.isArray(input)) {
277
283
  throw validationError(
278
- `${path} must be a non-empty object`,
279
- path,
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
- `${path} could not be read`,
289
- path,
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
- `${path}.event must be a non-empty string`,
307
- `${path}.event`,
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
- `${path}.${field} is derived from the API key and must not be sent`,
315
- `${path}.${field}`,
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
- `${path}.event_id must be a UUID string`,
324
- `${path}.event_id`,
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
- `${path}.timestamp`,
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
- `${path}.latency_ms must be a finite number`,
341
- `${path}.latency_ms`,
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
- `${path}.status_code must be an integer from 0 to 65535`,
348
- `${path}.status_code`,
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
- `${path}.http_method`,
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
- `${path}.${field} must be a string`,
363
- `${path}.${field}`,
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
- `${path}.span_kind must be server, client, producer, consumer, or internal`,
371
- `${path}.span_kind`,
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
- path,
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
- `${path} is not JSON-serializable`,
388
- path,
393
+ `${path2} is not JSON-serializable`,
394
+ path2,
389
395
  idempotencyKey,
390
396
  error
391
397
  );
@@ -409,6 +415,644 @@ 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 === "<dynamic>" || value === "<missing>" || 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 saw = false;
671
+ let index = open + 1;
672
+ while (index < limit) {
673
+ index = skipTrivia(source, index, limit);
674
+ if (index >= limit) {
675
+ break;
676
+ }
677
+ if (source[index] === "}") {
678
+ return {
679
+ row: saw ? finishRow(event, label, line) : void 0,
680
+ next: index + 1
681
+ };
682
+ }
683
+ if (source[index] === ",") {
684
+ index += 1;
685
+ continue;
686
+ }
687
+ if (source.startsWith("...", index)) {
688
+ index = skipExpression(source, index + 3, limit);
689
+ continue;
690
+ }
691
+ const key = readKey(source, index, limit);
692
+ if (key === void 0) {
693
+ index = skipExpression(source, index, limit);
694
+ continue;
695
+ }
696
+ index = skipTrivia(source, key.next, limit);
697
+ if (source[index] !== ":") {
698
+ if (key.name === "event" || key.name === "label") {
699
+ saw = true;
700
+ if (key.name === "event") {
701
+ event = "<dynamic>";
702
+ } else {
703
+ label = "<dynamic>";
704
+ }
705
+ }
706
+ continue;
707
+ }
708
+ const value = readValue(source, index + 1, limit);
709
+ if (key.name === "event" || key.name === "label") {
710
+ saw = true;
711
+ const text = value.literal ?? "<dynamic>";
712
+ if (key.name === "event") {
713
+ event = text;
714
+ } else {
715
+ label = text;
716
+ }
717
+ }
718
+ index = value.next;
719
+ }
720
+ return {
721
+ row: saw ? finishRow(event, label, line) : void 0,
722
+ next: index
723
+ };
724
+ }
725
+ function finishRow(event, label, line) {
726
+ return {
727
+ event: event ?? "<missing>",
728
+ label: label ?? "<missing>",
729
+ line
730
+ };
731
+ }
732
+ function readKey(source, start, limit) {
733
+ const index = skipTrivia(source, start, limit);
734
+ if (index >= limit) {
735
+ return void 0;
736
+ }
737
+ if (isIdentStart(source[index])) {
738
+ const end = readIdentEnd(source, index, limit);
739
+ return { name: source.slice(index, end), next: end };
740
+ }
741
+ const quoted = tryReadString(source, index, limit);
742
+ if (quoted?.complete === true && !quoted.template) {
743
+ return { name: quoted.value, next: quoted.next };
744
+ }
745
+ if (source[index] === "[") {
746
+ const inner = skipTrivia(source, index + 1, limit);
747
+ const computed = tryReadString(source, inner, limit);
748
+ if (computed?.complete === true && !computed.template) {
749
+ const after = skipTrivia(source, computed.next, limit);
750
+ if (source[after] === "]") {
751
+ return { name: computed.value, next: after + 1 };
752
+ }
753
+ }
754
+ }
755
+ return void 0;
756
+ }
757
+ function readValue(source, start, limit) {
758
+ const index = skipTrivia(source, start, limit);
759
+ const quoted = tryReadString(source, index, limit);
760
+ if (quoted?.complete === true) {
761
+ const after = skipTrivia(source, quoted.next, limit);
762
+ if (source.startsWith("as ", after) || source.startsWith("satisfies ", after)) {
763
+ return {
764
+ literal: quoted.value,
765
+ next: skipExpression(source, after, limit)
766
+ };
767
+ }
768
+ if (after >= limit || source[after] === "," || source[after] === "}" || source[after] === "]") {
769
+ return { literal: quoted.value, next: quoted.next };
770
+ }
771
+ }
772
+ return { literal: null, next: skipExpression(source, index, limit) };
773
+ }
774
+ function skipExpression(source, start, limit) {
775
+ let index = start;
776
+ let paren = 0;
777
+ let brace = 0;
778
+ let bracket = 0;
779
+ while (index < limit) {
780
+ const trivia = skipTrivia(source, index, limit);
781
+ if (trivia !== index) {
782
+ index = trivia;
783
+ continue;
784
+ }
785
+ if (index >= limit) {
786
+ break;
787
+ }
788
+ if (source[index] === "/" && looksLikeRegex(source, index)) {
789
+ index = skipRegex(source, index, limit);
790
+ continue;
791
+ }
792
+ if (source[index] === "`") {
793
+ index = skipTemplate(source, index, limit);
794
+ continue;
795
+ }
796
+ if (source[index] === "'" || source[index] === '"') {
797
+ index = skipQuoted(source, index, limit);
798
+ continue;
799
+ }
800
+ const char = source[index];
801
+ if (paren === 0 && brace === 0 && bracket === 0 && (char === "," || char === "}" || char === "]")) {
802
+ return index;
803
+ }
804
+ if (char === "(") {
805
+ paren += 1;
806
+ } else if (char === ")") {
807
+ if (paren === 0) {
808
+ return index;
809
+ }
810
+ paren -= 1;
811
+ } else if (char === "{") {
812
+ brace += 1;
813
+ } else if (char === "}") {
814
+ if (brace === 0) {
815
+ return index;
816
+ }
817
+ brace -= 1;
818
+ } else if (char === "[") {
819
+ bracket += 1;
820
+ } else if (char === "]") {
821
+ if (bracket === 0) {
822
+ return index;
823
+ }
824
+ bracket -= 1;
825
+ }
826
+ index += 1;
827
+ }
828
+ return index;
829
+ }
830
+ function skipTrivia(source, start, limit) {
831
+ let index = start;
832
+ while (index < limit) {
833
+ const char = source[index];
834
+ if (char === " " || char === " " || char === "\n" || char === "\r" || char === "\f") {
835
+ index += 1;
836
+ continue;
837
+ }
838
+ if (char === "/" && source[index + 1] === "/") {
839
+ index += 2;
840
+ while (index < limit && source[index] !== "\n") {
841
+ index += 1;
842
+ }
843
+ continue;
844
+ }
845
+ if (char === "/" && source[index + 1] === "*") {
846
+ index += 2;
847
+ while (index < limit && !(source[index] === "*" && source[index + 1] === "/")) {
848
+ index += 1;
849
+ }
850
+ index = Math.min(limit, index + 2);
851
+ continue;
852
+ }
853
+ break;
854
+ }
855
+ return index;
856
+ }
857
+ function skipQuoted(source, start, limit) {
858
+ const quote = source[start];
859
+ let index = start + 1;
860
+ while (index < limit) {
861
+ if (source[index] === "\\") {
862
+ index += 2;
863
+ continue;
864
+ }
865
+ if (source[index] === quote) {
866
+ return index + 1;
867
+ }
868
+ if (source[index] === "\n" || source[index] === "\r") {
869
+ return index;
870
+ }
871
+ index += 1;
872
+ }
873
+ return limit;
874
+ }
875
+ function skipTemplate(source, start, limit) {
876
+ let index = start + 1;
877
+ while (index < limit) {
878
+ if (source[index] === "\\") {
879
+ index += 2;
880
+ continue;
881
+ }
882
+ if (source[index] === "`") {
883
+ return index + 1;
884
+ }
885
+ if (source[index] === "$" && source[index + 1] === "{") {
886
+ const close = matchingDelimiter(source, index + 1, limit, "{", "}");
887
+ index = close === -1 ? limit : close + 1;
888
+ continue;
889
+ }
890
+ index += 1;
891
+ }
892
+ return limit;
893
+ }
894
+ function tryReadString(source, start, limit) {
895
+ const quote = source[start];
896
+ if (quote !== "'" && quote !== '"' && quote !== "`") {
897
+ return void 0;
898
+ }
899
+ let index = start + 1;
900
+ let value = "";
901
+ let complete = true;
902
+ while (index < limit) {
903
+ const char = source[index];
904
+ if (char === "\\") {
905
+ const escaped = source[index + 1];
906
+ if (escaped === void 0) {
907
+ complete = false;
908
+ break;
909
+ }
910
+ value += unescape(escaped);
911
+ index += 2;
912
+ continue;
913
+ }
914
+ if (quote === "`" && char === "$" && source[index + 1] === "{") {
915
+ return { value: "", next: start, complete: false, template: true };
916
+ }
917
+ if (char === quote) {
918
+ return { value, next: index + 1, complete, template: quote === "`" };
919
+ }
920
+ if ((quote === "'" || quote === '"') && (char === "\n" || char === "\r")) {
921
+ complete = false;
922
+ break;
923
+ }
924
+ value += char;
925
+ index += 1;
926
+ }
927
+ return { value, next: limit, complete: false, template: quote === "`" };
928
+ }
929
+ function unescape(char) {
930
+ switch (char) {
931
+ case "n":
932
+ return "\n";
933
+ case "r":
934
+ return "\r";
935
+ case "t":
936
+ return " ";
937
+ case "\\":
938
+ case "'":
939
+ case '"':
940
+ case "`":
941
+ return char;
942
+ default:
943
+ return char;
944
+ }
945
+ }
946
+ function looksLikeRegex(source, index) {
947
+ if (source[index] !== "/" || source[index + 1] === "/" || source[index + 1] === "*") {
948
+ return false;
949
+ }
950
+ let previous = index - 1;
951
+ while (previous >= 0 && /\s/.test(source[previous])) {
952
+ previous -= 1;
953
+ }
954
+ if (previous < 0) {
955
+ return true;
956
+ }
957
+ if (source[previous] === "*" && source[previous - 1] === "/") {
958
+ return true;
959
+ }
960
+ const char = source[previous];
961
+ if (REGEX_BEFORE.has(char)) {
962
+ return true;
963
+ }
964
+ if (isIdentChar(char)) {
965
+ const end = previous + 1;
966
+ let start = previous;
967
+ while (start > 0 && isIdentChar(source[start - 1])) {
968
+ start -= 1;
969
+ }
970
+ return REGEX_KEYWORDS.has(source.slice(start, end));
971
+ }
972
+ return false;
973
+ }
974
+ function skipRegex(source, start, limit) {
975
+ let index = start + 1;
976
+ let inClass = false;
977
+ while (index < limit) {
978
+ const char = source[index];
979
+ if (char === "\\") {
980
+ index += 2;
981
+ continue;
982
+ }
983
+ if (char === "[" && !inClass) {
984
+ inClass = true;
985
+ } else if (char === "]" && inClass) {
986
+ inClass = false;
987
+ } else if (char === "/" && !inClass) {
988
+ index += 1;
989
+ while (index < limit && /[a-z]/i.test(source[index])) {
990
+ index += 1;
991
+ }
992
+ return index;
993
+ } else if (char === "\n") {
994
+ return start + 1;
995
+ }
996
+ index += 1;
997
+ }
998
+ return limit;
999
+ }
1000
+ function matchingDelimiter(source, openIndex, limit, open, close) {
1001
+ let depth = 1;
1002
+ let index = openIndex + 1;
1003
+ while (index < limit) {
1004
+ const trivia = skipTrivia(source, index, limit);
1005
+ if (trivia !== index) {
1006
+ index = trivia;
1007
+ continue;
1008
+ }
1009
+ if (source[index] === "/" && looksLikeRegex(source, index)) {
1010
+ index = skipRegex(source, index, limit);
1011
+ continue;
1012
+ }
1013
+ if (source[index] === "`") {
1014
+ index = skipTemplate(source, index, limit);
1015
+ continue;
1016
+ }
1017
+ if (source[index] === "'" || source[index] === '"') {
1018
+ index = skipQuoted(source, index, limit);
1019
+ continue;
1020
+ }
1021
+ if (source[index] === open) {
1022
+ depth += 1;
1023
+ } else if (source[index] === close) {
1024
+ depth -= 1;
1025
+ if (depth === 0) {
1026
+ return index;
1027
+ }
1028
+ }
1029
+ index += 1;
1030
+ }
1031
+ return -1;
1032
+ }
1033
+ function isIdentStart(char) {
1034
+ return /[A-Za-z_$]/.test(char);
1035
+ }
1036
+ function isIdentChar(char) {
1037
+ return /[A-Za-z0-9_$]/.test(char);
1038
+ }
1039
+ function readIdentEnd(source, start, limit) {
1040
+ let index = start + 1;
1041
+ while (index < limit && isIdentChar(source[index])) {
1042
+ index += 1;
1043
+ }
1044
+ return index;
1045
+ }
1046
+ function lineAt(source, index) {
1047
+ let line = 1;
1048
+ const stop = Math.min(index, source.length);
1049
+ for (let cursor = 0; cursor < stop; cursor += 1) {
1050
+ if (source.charCodeAt(cursor) === 10) {
1051
+ line += 1;
1052
+ }
1053
+ }
1054
+ return line;
1055
+ }
412
1056
  var RANDOM_BITS = 74n;
413
1057
  var RANDOM_MASK = (1n << RANDOM_BITS) - 1n;
414
1058
  var MAX_TIMESTAMP = (1n << 48n) - 1n;
@@ -480,7 +1124,7 @@ function uuidv7() {
480
1124
 
481
1125
  // package.json
482
1126
  var package_default = {
483
- version: "2.2.3"};
1127
+ version: "2.2.4"};
484
1128
 
485
1129
  // src/client.ts
486
1130
  var TRAFFICWAR_DEFAULT_BASE_URL = "https://ingest.trafficwar.tech";
@@ -579,6 +1223,18 @@ function validateBooleanOption(name, value, fallback) {
579
1223
  }
580
1224
  return actual;
581
1225
  }
1226
+ function validateCatalogRoot(value) {
1227
+ if (value === void 0) {
1228
+ return void 0;
1229
+ }
1230
+ if (typeof value !== "string" || value.length === 0 || value.length > 4096) {
1231
+ throw new TrafficWarValidationError(
1232
+ "catalogRoot must be a non-empty path",
1233
+ { path: "options.catalogRoot" }
1234
+ );
1235
+ }
1236
+ return value;
1237
+ }
582
1238
  function validateCompression(value) {
583
1239
  const actual = value ?? "auto";
584
1240
  if (actual !== "auto" && actual !== "gzip" && actual !== "none") {
@@ -815,6 +1471,7 @@ function parseSuccess(response, parsed, expectedCount, idempotencyKey) {
815
1471
  var TrafficWar = class {
816
1472
  baseUrl;
817
1473
  debug;
1474
+ verbose;
818
1475
  timeoutMs;
819
1476
  maxRetries;
820
1477
  compression;
@@ -845,6 +1502,8 @@ var TrafficWar = class {
845
1502
  this.#apiKey = validateApiKey(options.apiKey);
846
1503
  this.baseUrl = normalizeBaseUrl(options.baseUrl);
847
1504
  this.debug = validateBooleanOption("debug", options.debug, false);
1505
+ this.verbose = validateBooleanOption("verbose", options.verbose, false);
1506
+ const catalogRoot = validateCatalogRoot(options.catalogRoot);
848
1507
  this.timeoutMs = validateIntegerOption(
849
1508
  "timeoutMs",
850
1509
  options.timeoutMs,
@@ -903,8 +1562,23 @@ var TrafficWar = class {
903
1562
  flushIntervalMs: this.flushIntervalMs,
904
1563
  maxQueueSize: this.maxQueueSize,
905
1564
  maxRetries: this.maxRetries,
906
- timeoutMs: this.timeoutMs
1565
+ timeoutMs: this.timeoutMs,
1566
+ verbose: this.verbose
907
1567
  });
1568
+ if (this.verbose) {
1569
+ this.#printCaptureCatalog(catalogRoot ?? process.cwd());
1570
+ }
1571
+ }
1572
+ #printCaptureCatalog(root) {
1573
+ try {
1574
+ console.info(formatCaptureCatalog(discoverCaptures(root)));
1575
+ } catch (error) {
1576
+ const message = error instanceof Error ? error.message : "unknown error";
1577
+ try {
1578
+ console.info(`[TrafficWar] static capture scan failed: ${message}`);
1579
+ } catch {
1580
+ }
1581
+ }
908
1582
  }
909
1583
  #debugLog(message, details) {
910
1584
  if (!this.debug) {
@@ -939,10 +1613,10 @@ var TrafficWar = class {
939
1613
  if (isBatch) {
940
1614
  for (let index = 0; index < events.length; index += 1) {
941
1615
  if (!(index in events)) {
942
- const path = `events[${index}]`;
1616
+ const path2 = `events[${index}]`;
943
1617
  throw new TrafficWarValidationError(
944
- `${path} is missing; sparse event arrays are not supported`,
945
- { path }
1618
+ `${path2} is missing; sparse event arrays are not supported`,
1619
+ { path: path2 }
946
1620
  );
947
1621
  }
948
1622
  }
@@ -955,8 +1629,8 @@ var TrafficWar = class {
955
1629
  }
956
1630
  const normalized = [];
957
1631
  for (let index = 0; index < events.length; index += 1) {
958
- const path = isBatch ? `events[${index}]` : "event";
959
- normalized.push(normalizeEvent(events[index], path));
1632
+ const path2 = isBatch ? `events[${index}]` : "event";
1633
+ normalized.push(normalizeEvent(events[index], path2));
960
1634
  }
961
1635
  for (const event of normalized) {
962
1636
  if (!Object.hasOwn(event, "event_id")) {
@@ -967,10 +1641,10 @@ var TrafficWar = class {
967
1641
  for (let index = 0; index < normalized.length; index += 1) {
968
1642
  const eventId = normalized[index].event_id;
969
1643
  if (incomingEventIds.has(eventId) || this.#pendingEventIds.has(eventId)) {
970
- const path = isBatch ? `events[${index}].event_id` : "event.event_id";
1644
+ const path2 = isBatch ? `events[${index}].event_id` : "event.event_id";
971
1645
  throw new TrafficWarValidationError(
972
- `${path} duplicates an unacknowledged event_id`,
973
- { path }
1646
+ `${path2} duplicates an unacknowledged event_id`,
1647
+ { path: path2 }
974
1648
  );
975
1649
  }
976
1650
  incomingEventIds.add(eventId);