Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@vercel/routing-utils

Package Overview
Dependencies
Maintainers
2
Versions
106
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@vercel/routing-utils - npm Package Compare versions

Comparing version
5.3.2
to
5.3.3
+12
dist/service-route-ownership.d.ts
/**
* Normalize a route prefix to always have a leading slash and no trailing slash
* unless it is root (`/`).
*/
export declare function normalizeRoutePrefix(routePrefix: string): string;
/**
* Create a service ownership guard:
* - Root services exclude all non-root prefixes.
* - Non-root services are constrained to their prefix and exclude descendants.
*/
export declare function getOwnershipGuard(ownerPrefix: string, allRoutePrefixes: string[]): string;
export declare function scopeRouteSourceToOwnership(source: string, ownershipGuard: string): string;
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var service_route_ownership_exports = {};
__export(service_route_ownership_exports, {
getOwnershipGuard: () => getOwnershipGuard,
normalizeRoutePrefix: () => normalizeRoutePrefix,
scopeRouteSourceToOwnership: () => scopeRouteSourceToOwnership
});
module.exports = __toCommonJS(service_route_ownership_exports);
function normalizeRoutePrefix(routePrefix) {
let normalized = routePrefix.startsWith("/") ? routePrefix : `/${routePrefix}`;
if (normalized !== "/" && normalized.endsWith("/")) {
normalized = normalized.slice(0, -1);
}
return normalized || "/";
}
function escapeForRegex(value) {
return value.replace(/[|\\{}()[\]^$+*?.]/g, "\\$&");
}
function toPrefixMatcher(routePrefix) {
return `${escapeForRegex(routePrefix)}(?:/|$)`;
}
function isDescendantPrefix(candidate, prefix) {
return candidate !== prefix && candidate.startsWith(`${prefix}/`);
}
function getOwnershipGuard(ownerPrefix, allRoutePrefixes) {
const owner = normalizeRoutePrefix(ownerPrefix);
const normalizedPrefixes = Array.from(
new Set(allRoutePrefixes.map(normalizeRoutePrefix))
);
const nonRootPrefixes = normalizedPrefixes.filter((prefix) => prefix !== "/").sort((a, b) => b.length - a.length);
if (owner === "/") {
return nonRootPrefixes.map((prefix) => `(?!${toPrefixMatcher(prefix)})`).join("");
}
const descendants = nonRootPrefixes.filter(
(prefix) => isDescendantPrefix(prefix, owner)
);
const positive = `(?=${toPrefixMatcher(owner)})`;
const negative = descendants.map((prefix) => `(?!${toPrefixMatcher(prefix)})`).join("");
return `${positive}${negative}`;
}
function scopeRouteSourceToOwnership(source, ownershipGuard) {
if (!ownershipGuard) {
return source;
}
const inner = source.startsWith("^") ? source.slice(1) : source;
return `^${ownershipGuard}(?:${inner})`;
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
getOwnershipGuard,
normalizeRoutePrefix,
scopeRouteSourceToOwnership
});
+7
-0

@@ -24,2 +24,3 @@ "use strict";

getCleanUrls: () => import_superstatic2.getCleanUrls,
getOwnershipGuard: () => import_service_route_ownership.getOwnershipGuard,
getTransformedRoutes: () => getTransformedRoutes,

@@ -29,3 +30,5 @@ isHandler: () => isHandler,

mergeRoutes: () => import_merge.mergeRoutes,
normalizeRoutePrefix: () => import_service_route_ownership.normalizeRoutePrefix,
normalizeRoutes: () => normalizeRoutes,
scopeRouteSourceToOwnership: () => import_service_route_ownership.scopeRouteSourceToOwnership,
sourceToRegex: () => import_superstatic2.sourceToRegex

@@ -38,2 +41,3 @@ });

var import_merge = require("./merge");
var import_service_route_ownership = require("./service-route-ownership");
__reExport(src_exports, require("./schemas"), module.exports);

@@ -372,2 +376,3 @@ var import_superstatic2 = require("./superstatic");

getCleanUrls,
getOwnershipGuard,
getTransformedRoutes,

@@ -377,3 +382,5 @@ isHandler,

mergeRoutes,
normalizeRoutePrefix,
normalizeRoutes,
scopeRouteSourceToOwnership,
sourceToRegex,

@@ -380,0 +387,0 @@ ...require("./schemas"),

+1
-0
import { GetRoutesProps, NormalizedRoutes, Route, RouteWithHandle } from './types';
export { appendRoutesToPhase } from './append';
export { mergeRoutes } from './merge';
export { getOwnershipGuard, normalizeRoutePrefix, scopeRouteSourceToOwnership, } from './service-route-ownership';
export * from './schemas';

@@ -5,0 +6,0 @@ export { getCleanUrls, sourceToRegex } from './superstatic';

@@ -24,2 +24,3 @@ "use strict";

getCleanUrls: () => import_superstatic2.getCleanUrls,
getOwnershipGuard: () => import_service_route_ownership.getOwnershipGuard,
getTransformedRoutes: () => getTransformedRoutes,

@@ -29,3 +30,5 @@ isHandler: () => isHandler,

mergeRoutes: () => import_merge.mergeRoutes,
normalizeRoutePrefix: () => import_service_route_ownership.normalizeRoutePrefix,
normalizeRoutes: () => normalizeRoutes,
scopeRouteSourceToOwnership: () => import_service_route_ownership.scopeRouteSourceToOwnership,
sourceToRegex: () => import_superstatic2.sourceToRegex

@@ -38,2 +41,3 @@ });

var import_merge = require("./merge");
var import_service_route_ownership = require("./service-route-ownership");
__reExport(src_exports, require("./schemas"), module.exports);

@@ -372,2 +376,3 @@ var import_superstatic2 = require("./superstatic");

getCleanUrls,
getOwnershipGuard,
getTransformedRoutes,

@@ -377,3 +382,5 @@ isHandler,

mergeRoutes,
normalizeRoutePrefix,
normalizeRoutes,
scopeRouteSourceToOwnership,
sourceToRegex,

@@ -380,0 +387,0 @@ ...require("./schemas"),

+2
-2
{
"name": "@vercel/routing-utils",
"version": "5.3.2",
"version": "5.3.3",
"description": "Vercel routing utilities",

@@ -22,3 +22,3 @@ "main": "./dist/index.js",

"@types/jest": "27.4.1",
"@types/node": "14.18.33",
"@types/node": "20.11.0",
"ajv": "^6.12.3",

@@ -25,0 +25,0 @@ "jest-junit": "16.0.0",