@vercel/routing-utils 5.3.1 → 5.3.3

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.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { GetRoutesProps, NormalizedRoutes, Route, RouteWithHandle } from './types';
2
2
  export { appendRoutesToPhase } from './append';
3
3
  export { mergeRoutes } from './merge';
4
+ export { getOwnershipGuard, normalizeRoutePrefix, scopeRouteSourceToOwnership, } from './service-route-ownership';
4
5
  export * from './schemas';
5
6
  export { getCleanUrls, sourceToRegex } from './superstatic';
6
7
  export * from './types';
package/dist/index.js CHANGED
@@ -21,11 +21,14 @@ var src_exports = {};
21
21
  __export(src_exports, {
22
22
  appendRoutesToPhase: () => import_append.appendRoutesToPhase,
23
23
  getCleanUrls: () => import_superstatic2.getCleanUrls,
24
+ getOwnershipGuard: () => import_service_route_ownership.getOwnershipGuard,
24
25
  getTransformedRoutes: () => getTransformedRoutes,
25
26
  isHandler: () => isHandler,
26
27
  isValidHandleValue: () => isValidHandleValue,
27
28
  mergeRoutes: () => import_merge.mergeRoutes,
29
+ normalizeRoutePrefix: () => import_service_route_ownership.normalizeRoutePrefix,
28
30
  normalizeRoutes: () => normalizeRoutes,
31
+ scopeRouteSourceToOwnership: () => import_service_route_ownership.scopeRouteSourceToOwnership,
29
32
  sourceToRegex: () => import_superstatic2.sourceToRegex
30
33
  });
31
34
  module.exports = __toCommonJS(src_exports);
@@ -33,6 +36,7 @@ var import_url = require("url");
33
36
  var import_superstatic = require("./superstatic");
34
37
  var import_append = require("./append");
35
38
  var import_merge = require("./merge");
39
+ var import_service_route_ownership = require("./service-route-ownership");
36
40
  __reExport(src_exports, require("./schemas"), module.exports);
37
41
  var import_superstatic2 = require("./superstatic");
38
42
  __reExport(src_exports, require("./types"), module.exports);
@@ -366,11 +370,14 @@ function getTransformedRoutes(vercelConfig) {
366
370
  0 && (module.exports = {
367
371
  appendRoutesToPhase,
368
372
  getCleanUrls,
373
+ getOwnershipGuard,
369
374
  getTransformedRoutes,
370
375
  isHandler,
371
376
  isValidHandleValue,
372
377
  mergeRoutes,
378
+ normalizeRoutePrefix,
373
379
  normalizeRoutes,
380
+ scopeRouteSourceToOwnership,
374
381
  sourceToRegex,
375
382
  ...require("./schemas"),
376
383
  ...require("./types")
package/dist/schemas.d.ts CHANGED
@@ -880,6 +880,10 @@ export declare const routesSchema: {
880
880
  readonly maxLength: 256;
881
881
  };
882
882
  };
883
+ readonly respectOriginCacheControl: {
884
+ readonly description: "When set to true (default), external rewrites will respect the Cache-Control header from the origin. When false, caching is disabled for this rewrite.";
885
+ readonly type: "boolean";
886
+ };
883
887
  };
884
888
  }, {
885
889
  readonly type: "object";
@@ -1304,6 +1308,10 @@ export declare const rewritesSchema: {
1304
1308
  readonly maxLength: 256;
1305
1309
  };
1306
1310
  };
1311
+ readonly respectOriginCacheControl: {
1312
+ readonly description: "When set to true (default), external rewrites will respect the Cache-Control header from the origin. When false, caching is disabled for this rewrite.";
1313
+ readonly type: "boolean";
1314
+ };
1307
1315
  };
1308
1316
  };
1309
1317
  };
package/dist/schemas.js CHANGED
@@ -484,6 +484,10 @@ const routesSchema = {
484
484
  type: "string",
485
485
  maxLength: 256
486
486
  }
487
+ },
488
+ respectOriginCacheControl: {
489
+ description: "When set to true (default), external rewrites will respect the Cache-Control header from the origin. When false, caching is disabled for this rewrite.",
490
+ type: "boolean"
487
491
  }
488
492
  }
489
493
  },
@@ -538,6 +542,10 @@ const rewritesSchema = {
538
542
  type: "string",
539
543
  maxLength: 256
540
544
  }
545
+ },
546
+ respectOriginCacheControl: {
547
+ description: "When set to true (default), external rewrites will respect the Cache-Control header from the origin. When false, caching is disabled for this rewrite.",
548
+ type: "boolean"
541
549
  }
542
550
  }
543
551
  }
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Normalize a route prefix to always have a leading slash and no trailing slash
3
+ * unless it is root (`/`).
4
+ */
5
+ export declare function normalizeRoutePrefix(routePrefix: string): string;
6
+ /**
7
+ * Create a service ownership guard:
8
+ * - Root services exclude all non-root prefixes.
9
+ * - Non-root services are constrained to their prefix and exclude descendants.
10
+ */
11
+ export declare function getOwnershipGuard(ownerPrefix: string, allRoutePrefixes: string[]): string;
12
+ export declare function scopeRouteSourceToOwnership(source: string, ownershipGuard: string): string;
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var service_route_ownership_exports = {};
20
+ __export(service_route_ownership_exports, {
21
+ getOwnershipGuard: () => getOwnershipGuard,
22
+ normalizeRoutePrefix: () => normalizeRoutePrefix,
23
+ scopeRouteSourceToOwnership: () => scopeRouteSourceToOwnership
24
+ });
25
+ module.exports = __toCommonJS(service_route_ownership_exports);
26
+ function normalizeRoutePrefix(routePrefix) {
27
+ let normalized = routePrefix.startsWith("/") ? routePrefix : `/${routePrefix}`;
28
+ if (normalized !== "/" && normalized.endsWith("/")) {
29
+ normalized = normalized.slice(0, -1);
30
+ }
31
+ return normalized || "/";
32
+ }
33
+ function escapeForRegex(value) {
34
+ return value.replace(/[|\\{}()[\]^$+*?.]/g, "\\$&");
35
+ }
36
+ function toPrefixMatcher(routePrefix) {
37
+ return `${escapeForRegex(routePrefix)}(?:/|$)`;
38
+ }
39
+ function isDescendantPrefix(candidate, prefix) {
40
+ return candidate !== prefix && candidate.startsWith(`${prefix}/`);
41
+ }
42
+ function getOwnershipGuard(ownerPrefix, allRoutePrefixes) {
43
+ const owner = normalizeRoutePrefix(ownerPrefix);
44
+ const normalizedPrefixes = Array.from(
45
+ new Set(allRoutePrefixes.map(normalizeRoutePrefix))
46
+ );
47
+ const nonRootPrefixes = normalizedPrefixes.filter((prefix) => prefix !== "/").sort((a, b) => b.length - a.length);
48
+ if (owner === "/") {
49
+ return nonRootPrefixes.map((prefix) => `(?!${toPrefixMatcher(prefix)})`).join("");
50
+ }
51
+ const descendants = nonRootPrefixes.filter(
52
+ (prefix) => isDescendantPrefix(prefix, owner)
53
+ );
54
+ const positive = `(?=${toPrefixMatcher(owner)})`;
55
+ const negative = descendants.map((prefix) => `(?!${toPrefixMatcher(prefix)})`).join("");
56
+ return `${positive}${negative}`;
57
+ }
58
+ function scopeRouteSourceToOwnership(source, ownershipGuard) {
59
+ if (!ownershipGuard) {
60
+ return source;
61
+ }
62
+ const inner = source.startsWith("^") ? source.slice(1) : source;
63
+ return `^${ownershipGuard}(?:${inner})`;
64
+ }
65
+ // Annotate the CommonJS export names for ESM import in node:
66
+ 0 && (module.exports = {
67
+ getOwnershipGuard,
68
+ normalizeRoutePrefix,
69
+ scopeRouteSourceToOwnership
70
+ });
package/dist/types.d.ts CHANGED
@@ -86,6 +86,7 @@ export type RouteWithSrc = {
86
86
  * A middleware index in the `middleware` key under the build result
87
87
  */
88
88
  middleware?: number;
89
+ respectOriginCacheControl?: boolean;
89
90
  };
90
91
  export type RouteWithHandle = {
91
92
  handle: HandleValue;
@@ -122,6 +123,7 @@ export interface Rewrite {
122
123
  missing?: HasField;
123
124
  statusCode?: number;
124
125
  env?: string[];
126
+ respectOriginCacheControl?: boolean;
125
127
  }
126
128
  export interface Redirect {
127
129
  source: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vercel/routing-utils",
3
- "version": "5.3.1",
3
+ "version": "5.3.3",
4
4
  "description": "Vercel routing utilities",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -19,7 +19,7 @@
19
19
  },
20
20
  "devDependencies": {
21
21
  "@types/jest": "27.4.1",
22
- "@types/node": "14.18.33",
22
+ "@types/node": "20.11.0",
23
23
  "ajv": "^6.12.3",
24
24
  "jest-junit": "16.0.0",
25
25
  "typescript": "4.9.5"