@klnap/next-proxy-chain 3.0.0 → 3.0.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## 3.0.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 8a67a83: Fix host scope matching when several host regular expressions are declared together. Each alternative is now compiled independently, so backreferences in one alternative no longer bind to another alternative's capture group.
8
+
3
9
  ## 3.0.0
4
10
 
5
11
  ### Major Changes
package/dist/index.cjs CHANGED
@@ -476,11 +476,10 @@ function hostGlobToRegex(value) {
476
476
  }
477
477
  function host(matcher) {
478
478
  const list = Array.isArray(matcher) ? matcher : [matcher];
479
- const parts = list.map((m) => {
480
- if (m instanceof RegExp) return `(?:${toStatelessRegExp(m).source})`;
481
- return `(?:${hostGlobToRegex(m)})`;
479
+ return list.map((m) => {
480
+ const source = m instanceof RegExp ? m.source : hostGlobToRegex(m);
481
+ return new RegExp(`^(?:${source})$`, "i");
482
482
  });
483
- return toStatelessRegExp(new RegExp(`^(?:${parts.join("|")})$`, "i"));
484
483
  }
485
484
  function isScopeObject(value) {
486
485
  return "host" in value || "path" in value;
@@ -567,7 +566,7 @@ function compileScopes(input) {
567
566
  }
568
567
  function scopeMatches(pathname, hostname, scope) {
569
568
  if (scope.host) {
570
- if (!hostname || !scope.host.test(hostname)) return false;
569
+ if (!hostname || !scope.host.some((alternative) => alternative.test(hostname))) return false;
571
570
  }
572
571
  if (scope.path) {
573
572
  if (!scope.path.some((alternative) => alternative.test(pathname))) return false;
@@ -589,7 +588,7 @@ function toRule(entry) {
589
588
  );
590
589
  }
591
590
  return {
592
- host: s.host ? toStatelessRegExp(s.host) : void 0,
591
+ host: s.host?.map(toStatelessRegExp),
593
592
  path: s.path?.map(toStatelessRegExp)
594
593
  };
595
594
  });
@@ -635,7 +634,8 @@ function canonicalPathname(pathname) {
635
634
  }
636
635
  function scopeKey(scope) {
637
636
  const path2 = scope.path?.map((alternative) => `${alternative.source}::${alternative.flags}`).join("&");
638
- return `${scope.host?.source ?? "*"}::${scope.host?.flags ?? ""}|${path2 ?? "*"}`;
637
+ const hostKey = scope.host?.map((alternative) => `${alternative.source}::${alternative.flags}`).join("&");
638
+ return `${hostKey ?? "*"}|${path2 ?? "*"}`;
639
639
  }
640
640
  function assertIncludeExcludeNoOverlap(include, exclude, label) {
641
641
  if (!include?.length || !exclude?.length) return;
package/dist/index.d.cts CHANGED
@@ -121,7 +121,8 @@ type RouteScopeInput = PathMatcher | {
121
121
  type RouteScopeList = RouteScopeInput | RouteScopeInput[];
122
122
  /** Compiled route scope evaluated during request execution. */
123
123
  type CompiledScope = {
124
- host?: RegExp;
124
+ /** Independent alternatives with OR semantics; each is anchored and case-insensitive. */
125
+ host?: RegExp[];
125
126
  /** Independent alternatives with OR semantics; each keeps its own flags. */
126
127
  path?: RegExp[];
127
128
  };
package/dist/index.d.ts CHANGED
@@ -121,7 +121,8 @@ type RouteScopeInput = PathMatcher | {
121
121
  type RouteScopeList = RouteScopeInput | RouteScopeInput[];
122
122
  /** Compiled route scope evaluated during request execution. */
123
123
  type CompiledScope = {
124
- host?: RegExp;
124
+ /** Independent alternatives with OR semantics; each is anchored and case-insensitive. */
125
+ host?: RegExp[];
125
126
  /** Independent alternatives with OR semantics; each keeps its own flags. */
126
127
  path?: RegExp[];
127
128
  };
package/dist/index.js CHANGED
@@ -449,11 +449,10 @@ function hostGlobToRegex(value) {
449
449
  }
450
450
  function host(matcher) {
451
451
  const list = Array.isArray(matcher) ? matcher : [matcher];
452
- const parts = list.map((m) => {
453
- if (m instanceof RegExp) return `(?:${toStatelessRegExp(m).source})`;
454
- return `(?:${hostGlobToRegex(m)})`;
452
+ return list.map((m) => {
453
+ const source = m instanceof RegExp ? m.source : hostGlobToRegex(m);
454
+ return new RegExp(`^(?:${source})$`, "i");
455
455
  });
456
- return toStatelessRegExp(new RegExp(`^(?:${parts.join("|")})$`, "i"));
457
456
  }
458
457
  function isScopeObject(value) {
459
458
  return "host" in value || "path" in value;
@@ -540,7 +539,7 @@ function compileScopes(input) {
540
539
  }
541
540
  function scopeMatches(pathname, hostname, scope) {
542
541
  if (scope.host) {
543
- if (!hostname || !scope.host.test(hostname)) return false;
542
+ if (!hostname || !scope.host.some((alternative) => alternative.test(hostname))) return false;
544
543
  }
545
544
  if (scope.path) {
546
545
  if (!scope.path.some((alternative) => alternative.test(pathname))) return false;
@@ -562,7 +561,7 @@ function toRule(entry) {
562
561
  );
563
562
  }
564
563
  return {
565
- host: s.host ? toStatelessRegExp(s.host) : void 0,
564
+ host: s.host?.map(toStatelessRegExp),
566
565
  path: s.path?.map(toStatelessRegExp)
567
566
  };
568
567
  });
@@ -608,7 +607,8 @@ function canonicalPathname(pathname) {
608
607
  }
609
608
  function scopeKey(scope) {
610
609
  const path2 = scope.path?.map((alternative) => `${alternative.source}::${alternative.flags}`).join("&");
611
- return `${scope.host?.source ?? "*"}::${scope.host?.flags ?? ""}|${path2 ?? "*"}`;
610
+ const hostKey = scope.host?.map((alternative) => `${alternative.source}::${alternative.flags}`).join("&");
611
+ return `${hostKey ?? "*"}|${path2 ?? "*"}`;
612
612
  }
613
613
  function assertIncludeExcludeNoOverlap(include, exclude, label) {
614
614
  if (!include?.length || !exclude?.length) return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@klnap/next-proxy-chain",
3
- "version": "3.0.0",
3
+ "version": "3.0.1",
4
4
  "description": "Composable proxy and middleware for Next.js.",
5
5
  "repository": {
6
6
  "type": "git",