@rogatio/cli 6.4.0 → 6.4.1

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.
Files changed (2) hide show
  1. package/dist/node/index.js +36 -4
  2. package/package.json +1 -1
@@ -22646,12 +22646,42 @@ async function startInterceptProxy(options = {}) {
22646
22646
  }
22647
22647
  };
22648
22648
  }
22649
+ function pacCheck(route) {
22650
+ if (typeof route.url === "string" && isExactHttpUrl(route.url)) {
22651
+ return {
22652
+ key: `url:${route.url}`,
22653
+ line: `url === ${JSON.stringify(route.url)}`
22654
+ };
22655
+ }
22656
+ if (typeof route.hostname === "string" && route.hostname.length > 0 && !route.hostname.includes("://")) {
22657
+ return {
22658
+ key: `host:${route.hostname}`,
22659
+ line: `host === ${JSON.stringify(route.hostname)}`
22660
+ };
22661
+ }
22662
+ return null;
22663
+ }
22664
+ function isExactHttpUrl(value) {
22665
+ try {
22666
+ const url = new URL(value);
22667
+ return (url.protocol === "http:" || url.protocol === "https:") && url.username === "" && url.password === "" && url.href === value;
22668
+ } catch {
22669
+ return false;
22670
+ }
22671
+ }
22649
22672
  function generatePacScript(routes, endpoint, options) {
22650
22673
  if (!Array.isArray(routes)) {
22651
22674
  throw new Error("runtime.pac-route-limit");
22652
22675
  }
22653
- const unique = routes.map((route) => route.hostname).filter((hostname) => typeof hostname === "string" && hostname.length > 0);
22654
- const sorted = [...new Set(unique)].sort();
22676
+ const checksByKey = /* @__PURE__ */ new Map();
22677
+ for (const route of routes) {
22678
+ const check = pacCheck(route);
22679
+ if (check === null) continue;
22680
+ checksByKey.set(check.key, check.line);
22681
+ }
22682
+ const sorted = [...checksByKey.entries()].sort(
22683
+ ([left], [right]) => left.localeCompare(right)
22684
+ );
22655
22685
  if (sorted.length > MAX_PAC_ROUTES) {
22656
22686
  throw new Error("runtime.pac-route-limit");
22657
22687
  }
@@ -22659,7 +22689,7 @@ function generatePacScript(routes, endpoint, options) {
22659
22689
  const proxy = `${proxyType} ${endpoint.host}:${endpoint.port}`;
22660
22690
  const proxyLiteral = JSON.stringify(proxy);
22661
22691
  const checks = sorted.map(
22662
- (hostname) => ` if (host === ${JSON.stringify(hostname)}) {
22692
+ ([, predicate]) => ` if (${predicate}) {
22663
22693
  return ${proxyLiteral};
22664
22694
  }`
22665
22695
  );
@@ -22775,7 +22805,9 @@ function createPlatformInterceptionProvider(adapter) {
22775
22805
  }
22776
22806
  const endpoint = await adapter.startTlsProxy(activation);
22777
22807
  const pac = generatePacScript(
22778
- pacRoutes.map((hostname) => ({ hostname })),
22808
+ pacRoutes.map(
22809
+ (entry) => entry.includes("://") ? { url: entry } : { hostname: entry }
22810
+ ),
22779
22811
  endpoint
22780
22812
  );
22781
22813
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rogatio/cli",
3
- "version": "6.4.0",
3
+ "version": "6.4.1",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "Local-first browser request and response rules — editor host, file verification, test runner, and runtime dispatch.",