@saptools/cf-inspector 0.3.14 → 0.3.16

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/cli.js CHANGED
@@ -184,10 +184,7 @@ function splitCaptureExpressions(raw) {
184
184
  pieces: []
185
185
  };
186
186
  for (let idx = 0; idx < raw.length; idx += 1) {
187
- const char = raw[idx];
188
- if (char === void 0) {
189
- continue;
190
- }
187
+ const char = raw.charAt(idx);
191
188
  if (consumeQuotedChar(state, char)) {
192
189
  continue;
193
190
  }
@@ -261,7 +258,6 @@ function writeLogEvent(event, json) {
261
258
  }
262
259
 
263
260
  // src/inspector.ts
264
- import { request } from "http";
265
261
  import { performance } from "perf_hooks";
266
262
 
267
263
  // src/cdp.ts
@@ -474,6 +470,125 @@ var CdpClient = class _CdpClient {
474
470
  }
475
471
  };
476
472
 
473
+ // src/inspectorDiscovery.ts
474
+ init_types();
475
+ import { request } from "http";
476
+ async function fetchJson(url, timeoutMs) {
477
+ return await new Promise((resolve, reject) => {
478
+ const req = request(url, { method: "GET" }, (res) => {
479
+ const chunks = [];
480
+ res.on("data", (chunk) => {
481
+ chunks.push(chunk);
482
+ });
483
+ res.on("end", () => {
484
+ try {
485
+ const text = Buffer.concat(chunks).toString("utf8");
486
+ resolve(JSON.parse(text));
487
+ } catch (err) {
488
+ const message = err instanceof Error ? err.message : String(err);
489
+ reject(
490
+ new CfInspectorError(
491
+ "INSPECTOR_DISCOVERY_FAILED",
492
+ `Failed to parse inspector discovery response from ${url}: ${message}`
493
+ )
494
+ );
495
+ }
496
+ });
497
+ res.on("error", (err) => {
498
+ reject(
499
+ new CfInspectorError(
500
+ "INSPECTOR_DISCOVERY_FAILED",
501
+ `Inspector discovery response error: ${err.message}`
502
+ )
503
+ );
504
+ });
505
+ });
506
+ req.setTimeout(timeoutMs, () => {
507
+ req.destroy(
508
+ new CfInspectorError(
509
+ "INSPECTOR_DISCOVERY_FAILED",
510
+ `Inspector discovery at ${url} timed out after ${timeoutMs.toString()}ms`
511
+ )
512
+ );
513
+ });
514
+ req.on("error", (err) => {
515
+ reject(
516
+ err instanceof CfInspectorError ? err : new CfInspectorError(
517
+ "INSPECTOR_DISCOVERY_FAILED",
518
+ `Inspector discovery at ${url} failed: ${err.message}`
519
+ )
520
+ );
521
+ });
522
+ req.end();
523
+ });
524
+ }
525
+ function toInspectorTarget(value, source) {
526
+ if (typeof value !== "object" || value === null) {
527
+ throw new CfInspectorError(
528
+ "INSPECTOR_DISCOVERY_FAILED",
529
+ `Inspector target is not an object in ${source}`
530
+ );
531
+ }
532
+ const candidate = value;
533
+ const webSocketDebuggerUrl = candidate["webSocketDebuggerUrl"];
534
+ if (typeof webSocketDebuggerUrl !== "string" || webSocketDebuggerUrl.length === 0) {
535
+ throw new CfInspectorError(
536
+ "INSPECTOR_DISCOVERY_FAILED",
537
+ `Inspector target is missing webSocketDebuggerUrl in ${source}`
538
+ );
539
+ }
540
+ return {
541
+ description: typeof candidate["description"] === "string" ? candidate["description"] : "",
542
+ id: typeof candidate["id"] === "string" ? candidate["id"] : "",
543
+ title: typeof candidate["title"] === "string" ? candidate["title"] : "",
544
+ type: typeof candidate["type"] === "string" ? candidate["type"] : "",
545
+ url: typeof candidate["url"] === "string" ? candidate["url"] : "",
546
+ webSocketDebuggerUrl,
547
+ ...typeof candidate["devtoolsFrontendUrl"] === "string" ? { devtoolsFrontendUrl: candidate["devtoolsFrontendUrl"] } : {},
548
+ ...typeof candidate["faviconUrl"] === "string" ? { faviconUrl: candidate["faviconUrl"] } : {}
549
+ };
550
+ }
551
+ async function discoverInspectorTargets(host, port, timeoutMs) {
552
+ const url = `http://${host}:${port.toString()}/json/list`;
553
+ const raw = await fetchJson(url, timeoutMs);
554
+ if (!Array.isArray(raw) || raw.length === 0) {
555
+ throw new CfInspectorError(
556
+ "INSPECTOR_DISCOVERY_FAILED",
557
+ `No inspector targets returned from ${url}`
558
+ );
559
+ }
560
+ return raw.map((entry, idx) => toInspectorTarget(entry, `${url}[${idx.toString()}]`));
561
+ }
562
+ function readVersionField(value, ...keys) {
563
+ for (const key of keys) {
564
+ const entry = value[key];
565
+ if (typeof entry === "string" && entry.length > 0) {
566
+ return entry;
567
+ }
568
+ }
569
+ return void 0;
570
+ }
571
+ async function fetchInspectorVersion(host, port, timeoutMs) {
572
+ const url = `http://${host}:${port.toString()}/json/version`;
573
+ const raw = await fetchJson(url, timeoutMs);
574
+ if (typeof raw !== "object" || raw === null) {
575
+ throw new CfInspectorError(
576
+ "INSPECTOR_DISCOVERY_FAILED",
577
+ `Unexpected /json/version response from ${url}`
578
+ );
579
+ }
580
+ const value = raw;
581
+ const browser = readVersionField(value, "Browser", "browser");
582
+ const protocolVersion = readVersionField(value, "Protocol-Version", "protocolVersion");
583
+ if (browser === void 0 || protocolVersion === void 0) {
584
+ throw new CfInspectorError(
585
+ "INSPECTOR_DISCOVERY_FAILED",
586
+ `Unexpected /json/version response from ${url}`
587
+ );
588
+ }
589
+ return { browser, protocolVersion };
590
+ }
591
+
477
592
  // src/pathMapper.ts
478
593
  init_types();
479
594
  var REGEX_PREFIX = "regex:";
@@ -617,121 +732,6 @@ function buildBreakpointUrlRegex(input) {
617
732
  init_types();
618
733
  var DEFAULT_CONNECT_TIMEOUT_MS = 5e3;
619
734
  var DEFAULT_HOST = "127.0.0.1";
620
- async function fetchJson(url, timeoutMs) {
621
- return await new Promise((resolve, reject) => {
622
- const req = request(url, { method: "GET" }, (res) => {
623
- const chunks = [];
624
- res.on("data", (chunk) => {
625
- chunks.push(chunk);
626
- });
627
- res.on("end", () => {
628
- try {
629
- const text = Buffer.concat(chunks).toString("utf8");
630
- resolve(JSON.parse(text));
631
- } catch (err) {
632
- const message = err instanceof Error ? err.message : String(err);
633
- reject(
634
- new CfInspectorError(
635
- "INSPECTOR_DISCOVERY_FAILED",
636
- `Failed to parse inspector discovery response from ${url}: ${message}`
637
- )
638
- );
639
- }
640
- });
641
- res.on("error", (err) => {
642
- reject(
643
- new CfInspectorError(
644
- "INSPECTOR_DISCOVERY_FAILED",
645
- `Inspector discovery response error: ${err.message}`
646
- )
647
- );
648
- });
649
- });
650
- req.setTimeout(timeoutMs, () => {
651
- req.destroy(
652
- new CfInspectorError(
653
- "INSPECTOR_DISCOVERY_FAILED",
654
- `Inspector discovery at ${url} timed out after ${timeoutMs.toString()}ms`
655
- )
656
- );
657
- });
658
- req.on("error", (err) => {
659
- reject(
660
- err instanceof CfInspectorError ? err : new CfInspectorError(
661
- "INSPECTOR_DISCOVERY_FAILED",
662
- `Inspector discovery at ${url} failed: ${err.message}`
663
- )
664
- );
665
- });
666
- req.end();
667
- });
668
- }
669
- function toInspectorTarget(value, source) {
670
- if (typeof value !== "object" || value === null) {
671
- throw new CfInspectorError(
672
- "INSPECTOR_DISCOVERY_FAILED",
673
- `Inspector target is not an object in ${source}`
674
- );
675
- }
676
- const candidate = value;
677
- const webSocketDebuggerUrl = candidate["webSocketDebuggerUrl"];
678
- if (typeof webSocketDebuggerUrl !== "string" || webSocketDebuggerUrl.length === 0) {
679
- throw new CfInspectorError(
680
- "INSPECTOR_DISCOVERY_FAILED",
681
- `Inspector target is missing webSocketDebuggerUrl in ${source}`
682
- );
683
- }
684
- return {
685
- description: typeof candidate["description"] === "string" ? candidate["description"] : "",
686
- id: typeof candidate["id"] === "string" ? candidate["id"] : "",
687
- title: typeof candidate["title"] === "string" ? candidate["title"] : "",
688
- type: typeof candidate["type"] === "string" ? candidate["type"] : "",
689
- url: typeof candidate["url"] === "string" ? candidate["url"] : "",
690
- webSocketDebuggerUrl,
691
- ...typeof candidate["devtoolsFrontendUrl"] === "string" ? { devtoolsFrontendUrl: candidate["devtoolsFrontendUrl"] } : {},
692
- ...typeof candidate["faviconUrl"] === "string" ? { faviconUrl: candidate["faviconUrl"] } : {}
693
- };
694
- }
695
- async function discoverInspectorTargets(host, port, timeoutMs) {
696
- const url = `http://${host}:${port.toString()}/json/list`;
697
- const raw = await fetchJson(url, timeoutMs);
698
- if (!Array.isArray(raw) || raw.length === 0) {
699
- throw new CfInspectorError(
700
- "INSPECTOR_DISCOVERY_FAILED",
701
- `No inspector targets returned from ${url}`
702
- );
703
- }
704
- return raw.map((entry, idx) => toInspectorTarget(entry, `${url}[${idx.toString()}]`));
705
- }
706
- function readVersionField(value, ...keys) {
707
- for (const key of keys) {
708
- const entry = value[key];
709
- if (typeof entry === "string" && entry.length > 0) {
710
- return entry;
711
- }
712
- }
713
- return void 0;
714
- }
715
- async function fetchInspectorVersion(host, port, timeoutMs) {
716
- const url = `http://${host}:${port.toString()}/json/version`;
717
- const raw = await fetchJson(url, timeoutMs);
718
- if (typeof raw !== "object" || raw === null) {
719
- throw new CfInspectorError(
720
- "INSPECTOR_DISCOVERY_FAILED",
721
- `Unexpected /json/version response from ${url}`
722
- );
723
- }
724
- const value = raw;
725
- const browser = readVersionField(value, "Browser", "browser");
726
- const protocolVersion = readVersionField(value, "Protocol-Version", "protocolVersion");
727
- if (browser === void 0 || protocolVersion === void 0) {
728
- throw new CfInspectorError(
729
- "INSPECTOR_DISCOVERY_FAILED",
730
- `Unexpected /json/version response from ${url}`
731
- );
732
- }
733
- return { browser, protocolVersion };
734
- }
735
735
  async function connectInspector(options) {
736
736
  const host = options.host ?? DEFAULT_HOST;
737
737
  const connectTimeoutMs = options.connectTimeoutMs ?? DEFAULT_CONNECT_TIMEOUT_MS;