🚨 Latest Research:Tanstack npm Packages Compromised in Ongoing Mini Shai-Hulud Supply-Chain Attack.Learn More
Socket
Book a DemoSign in
Socket

@vercel/config

Package Overview
Dependencies
Maintainers
2
Versions
37
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@vercel/config - npm Package Compare versions

Comparing version
0.1.0-canary.20260211174907.cdd2da6
to
0.1.0
+16
-81
dist/router.d.ts

@@ -1,2 +0,2 @@

import type { Redirect, Rewrite } from './types';
import type { Condition, MatchableValueObject, Redirect, Rewrite } from './types';
/**

@@ -99,80 +99,9 @@ * Type utility to extract path parameter names from a route pattern string.

}
export declare const matchers: {
header: (key: string, value?: string | MatchableValueObject) => Condition;
cookie: (key: string, value?: string | MatchableValueObject) => Condition;
query: (key: string, value?: string | MatchableValueObject) => Condition;
host: (value: string | MatchableValueObject) => Condition;
};
/**
* Condition type for matching in redirects, headers, and rewrites.
* - 'header': Match if a specific HTTP header key/value is present (or missing).
* - 'cookie': Match if a specific cookie is present (or missing).
* - 'host': Match if the incoming host matches a given pattern.
* - 'query': Match if a query parameter is present (or missing).
* - 'path': Match if the path matches a given pattern.
*/
export type ConditionType = 'header' | 'cookie' | 'host' | 'query' | 'path';
/**
* Conditional matching operators for has/missing conditions.
* These can be used with the value field to perform advanced matching.
*/
export interface ConditionOperators {
/** Check equality on a value (exact match) */
eq?: string | number;
/** Check inequality on a value (not equal) */
neq?: string;
/** Check inclusion in an array of values (value is one of) */
inc?: string[];
/** Check non-inclusion in an array of values (value is not one of) */
ninc?: string[];
/** Check if value starts with a prefix */
pre?: string;
/** Check if value ends with a suffix */
suf?: string;
/** Check if value is greater than (numeric comparison) */
gt?: number;
/** Check if value is greater than or equal to */
gte?: number;
/** Check if value is less than (numeric comparison) */
lt?: number;
/** Check if value is less than or equal to */
lte?: number;
}
/**
* Used to define "has" or "missing" conditions with advanced matching operators.
*
* @example
* // Simple header presence check
* { type: 'header', key: 'x-api-key' }
*
* @example
* // Header with exact value match
* { type: 'header', key: 'x-api-version', value: 'v2' }
*
* @example
* // Header with conditional operators
* { type: 'header', key: 'x-user-role', inc: ['admin', 'moderator'] }
*
* @example
* // Cookie with prefix matching
* { type: 'cookie', key: 'session', pre: 'prod-' }
*
* @example
* // Host matching
* { type: 'host', value: 'api.example.com' }
*
* @example
* // Query parameter with numeric comparison
* { type: 'query', key: 'version', gte: 2 }
*
* @example
* // Path pattern matching
* { type: 'path', value: '^/api/v[0-9]+/.*' }
*/
export interface Condition extends ConditionOperators {
type: ConditionType;
/** The key to match. Not used for 'host' or 'path' types. */
key?: string;
/**
* Simple string/regex pattern to match against.
* For 'host' and 'path' types, this is the only matching option.
* For other types, you can use value OR the conditional operators (eq, neq, etc).
*/
value?: string;
}
/**
* Transform type specifies the scope of what the transform will apply to.

@@ -265,5 +194,9 @@ * - 'request.query': Transform query parameters in the request

/** Pattern to match request paths using path-to-regexp syntax */
src: string;
src?: string;
/** Alias for `src`. A pattern that matches each incoming pathname (excluding querystring). */
source?: string;
/** Optional destination for rewrite/redirect */
dest?: string;
/** Alias for `dest`. An absolute pathname to an existing resource or an external URL. */
destination?: string;
/** Array of HTTP methods to match. If not provided, matches all methods */

@@ -279,2 +212,4 @@ methods?: string[];

status?: number;
/** Alias for `status`. An optional integer to override the status code of the response. */
statusCode?: number;
/** Headers to set (alternative to using transforms) */

@@ -547,3 +482,3 @@ headers?: Record<string, string>;

*/
rewrite<T extends string>(source: T, destination: string): Rewrite | Route;
rewrite<T extends string>(source: T, destination: string): Rewrite;
rewrite<T extends string>(source: T, destination: string, callback: (params: PathParams<T>) => {

@@ -595,3 +530,3 @@ has?: Condition[];

*/
redirect<T extends string>(source: T, destination: string): Redirect | Route;
redirect<T extends string>(source: T, destination: string): Redirect;
redirect<T extends string>(source: T, destination: string, callback: (params: PathParams<T>) => {

@@ -598,0 +533,0 @@ permanent?: boolean;

+87
-40
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.routes = exports.createRoutes = exports.Router = exports.deploymentEnv = void 0;
exports.routes = exports.createRoutes = exports.Router = exports.matchers = exports.deploymentEnv = void 0;
const pretty_cache_header_1 = require("pretty-cache-header");
const routing_utils_1 = require("@vercel/routing-utils");
const validation_1 = require("./utils/validation");
/**
* Convert a destination string from path-to-regexp format to use capture group references.
* Replaces :paramName with $index based on the segments array.
*/
function convertDestination(destination, segments) {
let result = destination;
segments.forEach((segment, index) => {
const patterns = [
new RegExp(`:${segment}\\*`, 'g'),
new RegExp(`:${segment}\\+`, 'g'),
new RegExp(`:${segment}(?![a-zA-Z0-9_])`, 'g'),
];
for (const pattern of patterns) {
result = result.replace(pattern, `$${index + 1}`);
}
});
return result;
}
/**
* Helper function to reference a Vercel project environment variable.

@@ -24,2 +43,27 @@ * These are placeholders that get resolved at request time by Vercel's routing layer.

exports.deploymentEnv = deploymentEnv;
function createKeyedConditionHelper(type) {
return (key, value) => {
if (value === undefined) {
return { type, key };
}
if (typeof value === 'string') {
return { type, key, value };
}
return { type, key, value };
};
}
function createKeylessConditionHelper(type) {
return (value) => {
if (typeof value === 'string') {
return { type, value };
}
return { type, value };
};
}
exports.matchers = {
header: createKeyedConditionHelper('header'),
cookie: createKeyedConditionHelper('cookie'),
query: createKeyedConditionHelper('query'),
host: createKeylessConditionHelper('host'),
};
/**

@@ -142,5 +186,8 @@ * Extract environment variable names from a string or array of strings

}
// Convert path-to-regexp patterns to regex for routes format
const { src: regexSrc, segments } = (0, routing_utils_1.sourceToRegex)(source);
const convertedDest = convertDestination(destination, segments);
const route = {
src: source,
dest: destination,
src: regexSrc,
dest: convertedDest,
transforms,

@@ -161,21 +208,5 @@ };

}
// Simple rewrite without transforms - check if destination has env vars
// Simple rewrite without transforms
const pathParams = this.extractPathParams(source);
const destEnvVars = extractEnvVars(destination, pathParams);
if (destEnvVars.length > 0) {
// Need Route format to include env field
const route = {
src: source,
dest: destination,
env: destEnvVars,
};
if (has)
route.has = has;
if (missing)
route.missing = missing;
if (respectOriginCacheControl !== undefined)
route.respectOriginCacheControl = respectOriginCacheControl;
return route;
}
// Simple rewrite without transforms or env vars
const rewrite = {

@@ -185,2 +216,4 @@ source,

};
if (destEnvVars.length > 0)
rewrite.env = destEnvVars;
if (has)

@@ -227,5 +260,8 @@ rewrite.has = has;

}
// Convert path-to-regexp patterns to regex for routes format
const { src: regexSrc, segments } = (0, routing_utils_1.sourceToRegex)(source);
const convertedDest = convertDestination(destination, segments);
const route = {
src: source,
dest: destination,
src: regexSrc,
dest: convertedDest,
status: statusCode || (permanent ? 308 : 307),

@@ -245,20 +281,5 @@ transforms,

}
// Simple redirect without transforms - check if destination has env vars
// Simple redirect without transforms
const pathParams = this.extractPathParams(source);
const destEnvVars = extractEnvVars(destination, pathParams);
if (destEnvVars.length > 0) {
// Need Route format to include env field
const route = {
src: source,
dest: destination,
status: statusCode || (permanent ? 308 : 307),
env: destEnvVars,
};
if (has)
route.has = has;
if (missing)
route.missing = missing;
return route;
}
// Simple redirect without transforms or env vars
const redirect = {

@@ -268,2 +289,4 @@ source,

};
if (destEnvVars.length > 0)
redirect.env = destEnvVars;
if (permanent !== undefined)

@@ -334,6 +357,30 @@ redirect.permanent = permanent;

route(config) {
this.validateSourcePattern(config.src);
if (config.src && config.source) {
throw new Error('Route cannot define both `src` and `source`. Use one or the other.');
}
if (config.dest && config.destination) {
throw new Error('Route cannot define both `dest` and `destination`. Use one or the other.');
}
if (config.status !== undefined && config.statusCode !== undefined) {
throw new Error('Route cannot define both `status` and `statusCode`. Use one or the other.');
}
const src = config.src ?? config.source;
if (!src) {
throw new Error('Route must define either `src` or `source`.');
}
this.validateSourcePattern(src);
// Normalize aliases to canonical names (src/dest/status)
config.src = src;
delete config.source;
if (config.destination !== undefined) {
config.dest = config.destination;
delete config.destination;
}
if (config.statusCode !== undefined) {
config.status = config.statusCode;
delete config.statusCode;
}
// Auto-extract env vars from each transform if not already specified
if (config.transforms) {
const pathParams = this.extractPathParams(config.src);
const pathParams = this.extractPathParams(src);
for (const transform of config.transforms) {

@@ -340,0 +387,0 @@ if (!transform.env && transform.args) {

/**
* Vercel configuration type that mirrors the vercel.json schema
* https://openapi.vercel.sh/vercel.json
* AUTO-GENERATED — DO NOT EDIT
*
* This file is generated from the vercel.json OpenAPI schema.
* To modify, update scripts/generate-types.ts and re-run:
* pnpm generate-types
*
* Schema: https://openapi.vercel.sh/vercel.json
*/
export type Framework = 'blitzjs' | 'nextjs' | 'gatsby' | 'remix' | 'react-router' | 'astro' | 'hexo' | 'eleventy' | 'docusaurus-2' | 'docusaurus' | 'preact' | 'solidstart-1' | 'solidstart' | 'dojo' | 'ember' | 'vue' | 'scully' | 'ionic-angular' | 'angular' | 'polymer' | 'svelte' | 'sveltekit' | 'sveltekit-1' | 'ionic-react' | 'create-react-app' | 'gridsome' | 'umijs' | 'sapper' | 'saber' | 'stencil' | 'nuxtjs' | 'redwoodjs' | 'hugo' | 'jekyll' | 'brunch' | 'middleman' | 'zola' | 'hydrogen' | 'vite' | 'tanstack-start' | 'vitepress' | 'vuepress' | 'parcel' | 'fastapi' | 'flask' | 'fasthtml' | 'sanity-v3' | 'sanity' | 'storybook' | 'nitro' | 'hono' | 'express' | 'h3' | 'nestjs' | 'elysia' | 'fastify' | 'xmcp' | null;
export type Framework = 'blitzjs' | 'nextjs' | 'gatsby' | 'remix' | 'react-router' | 'astro' | 'hexo' | 'eleventy' | 'docusaurus-2' | 'docusaurus' | 'preact' | 'solidstart-1' | 'solidstart' | 'dojo' | 'ember' | 'vue' | 'scully' | 'ionic-angular' | 'angular' | 'polymer' | 'svelte' | 'sveltekit' | 'sveltekit-1' | 'ionic-react' | 'create-react-app' | 'gridsome' | 'umijs' | 'sapper' | 'saber' | 'stencil' | 'nuxtjs' | 'redwoodjs' | 'hugo' | 'jekyll' | 'brunch' | 'middleman' | 'zola' | 'hydrogen' | 'vite' | 'tanstack-start' | 'vitepress' | 'vuepress' | 'parcel' | 'fastapi' | 'flask' | 'fasthtml' | 'django' | 'sanity-v3' | 'sanity' | 'storybook' | 'nitro' | 'hono' | 'express' | 'h3' | 'koa' | 'nestjs' | 'elysia' | 'fastify' | 'xmcp' | 'python' | 'ruby' | 'rust' | 'node' | 'go' | 'services' | null;
export interface FunctionConfig {

@@ -16,5 +21,5 @@ /**

/**
* An integer defining how long your Serverless Function should be allowed to run on every request in seconds (between 1 and the maximum limit of your plan).
* An integer defining how long your Serverless Function should be allowed to run on every request in seconds (between 1 and the maximum limit of your plan), or the string `'max'` to use the maximum duration allowed by your plan.
*/
maxDuration?: number;
maxDuration?: number | 'max';
/**

@@ -25,10 +30,13 @@ * An integer defining the memory your Serverless Function should be provided with (between 128 and 10240).

/**
* An array of regions where this Serverless Function will be deployed.
* This setting overrides the top-level `regions` setting for matching functions.
* The npm package name of a Runtime, including its version
*/
runtime?: string;
/**
* An array of regions this Serverless Function should be deployed to.
*/
regions?: string[];
/**
* The npm package name of a Runtime, including its version
* An array of passive regions this Serverless Function can fail over to during a lambda outage.
*/
runtime?: string;
functionFailoverRegions?: string[];
/**

@@ -41,7 +49,7 @@ * A boolean that defines whether the Function supports cancellation (default: false)

*/
experimentalTriggers?: {
experimentalTriggers?: ({
/**
* Event type pattern this trigger handles
*/
type: string;
type: 'queue/v1beta';
/**

@@ -71,3 +79,28 @@ * Name of the queue topic to consume from

maxConcurrency?: number;
}[];
} | {
/**
* Event type pattern this trigger handles
*/
type: 'queue/v2beta';
/**
* Name of the queue topic to consume from
*/
topic: string;
/**
* Maximum number of delivery attempts
*/
maxDeliveries?: number;
/**
* Delay in seconds before retrying failed executions
*/
retryAfterSeconds?: number;
/**
* Initial delay in seconds before first execution attempt
*/
initialDelaySeconds?: number;
/**
* Maximum number of concurrent executions for this consumer
*/
maxConcurrency?: number;
})[];
}

@@ -121,3 +154,3 @@ export interface CronJob {

domains?: string[];
formats?: 'image/avif' | 'image/webp' | 'image/jpeg' | 'image/png'[];
formats?: ('image/avif' | 'image/webp' | 'image/jpeg' | 'image/png')[];
localPatterns?: {

@@ -139,64 +172,162 @@ pathname?: string;

/**
* HTTP header key/value pair
* Value for condition matching - can be a string or an operator object
*/
export interface Header {
key: string;
value: string;
}
/**
* Condition for matching in redirects, rewrites, and headers
*/
export interface Condition {
type: 'header' | 'cookie' | 'host' | 'query' | 'path';
key?: string;
value?: string | number;
export type MatchableValue = string | {
/**
* Equal to
*/
eq?: string | number;
/**
* Not equal
*/
neq?: string;
/**
* In array
*/
inc?: string[];
/**
* Not in array
*/
ninc?: string[];
/**
* Starts with
*/
pre?: string;
/**
* Ends with
*/
suf?: string;
/**
* Regex
*/
re?: string;
/**
* Greater than
*/
gt?: number;
/**
* Greater than or equal to
*/
gte?: number;
/**
* Less than
*/
lt?: number;
/**
* Less than or equal to
*/
lte?: number;
};
/**
* Condition for matching in redirects, rewrites, and headers
*/
export type Condition = {
type: 'host';
value: MatchableValue;
} | {
type: 'header' | 'cookie' | 'query';
key: string;
value?: MatchableValue;
};
/**
* The object form of MatchableValue (excludes the plain string shorthand)
*/
export type MatchableValueObject = Exclude<MatchableValue, string>;
/**
* HTTP header key/value pair
*/
export interface Header {
key: string;
value: string;
}
/**
* Redirect matching vercel.json schema
* Returned by routes.redirect()
* Redirect definition matching vercel.json schema
*/
export interface Redirect {
/**
* A pattern that matches each incoming pathname (excluding querystring).
*/
source: string;
/**
* A location destination defined as an absolute pathname or external URL.
*/
destination: string;
/**
* A boolean to toggle between permanent and temporary redirect. When `true`, the status code is `308`. When `false` the status code is `307`.
*/
permanent?: boolean;
/**
* An optional integer to define the status code of the redirect.
* @private
*/
statusCode?: number;
/**
* An array of requirements that are needed to match
*/
has?: Condition[];
/**
* An array of requirements that are needed to match
*/
missing?: Condition[];
/**
* An array of environment variable names that should be replaced at runtime in the destination
*/
env?: string[];
}
/**
* Rewrite matching vercel.json schema
* Returned by routes.rewrite()
* Rewrite definition matching vercel.json schema
*/
export interface Rewrite {
/**
* A pattern that matches each incoming pathname (excluding querystring).
*/
source: string;
/**
* An absolute pathname to an existing resource or an external URL.
*/
destination: string;
/**
* An array of requirements that are needed to match
*/
has?: Condition[];
/**
* An array of requirements that are needed to match
*/
missing?: Condition[];
/**
* An optional integer to override the status code of the response.
*/
statusCode?: number;
/**
* An array of environment variable names that should be replaced at runtime in the destination
*/
env?: string[];
/**
* When set to true (default), external rewrites will respect the Cache-Control header from the origin. When false, caching is disabled for this rewrite.
*/
respectOriginCacheControl?: boolean;
}
/**
* Header rule matching vercel.json schema
* Returned by routes.header() and routes.cacheControl()
* Header rule definition matching vercel.json schema
*/
export interface HeaderRule {
/**
* A pattern that matches each incoming pathname (excluding querystring)
*/
source: string;
/**
* An array of key/value pairs representing each response header.
*/
headers: Header[];
/**
* An array of requirements that are needed to match
*/
has?: Condition[];
/**
* An array of requirements that are needed to match
*/
missing?: Condition[];
}
/**
* Union type for all router helper outputs
* Can be simple schema objects (Redirect, Rewrite, HeaderRule) or Routes with transforms
* Note: Route type is defined in router.ts (uses src/dest instead of source/destination)
* Union type for all routing helper outputs
*/

@@ -260,3 +391,3 @@ export type RouteType = Redirect | Rewrite | HeaderRule | any;

*/
headers?: RouteType[];
headers?: HeaderRule[];
images?: ImageConfig;

@@ -274,3 +405,3 @@ /**

*/
redirects?: RouteType[];
redirects?: Redirect[];
/**

@@ -287,6 +418,5 @@ * The path to a file containing bulk redirects; supports JSON, JSONL, and CSV

*/
rewrites?: RouteType[];
rewrites?: Rewrite[];
/**
* A list of routes objects used to rewrite paths to point towards other internal or external paths
* @deprecated
*/

@@ -348,2 +478,85 @@ routes?: RouteType[];

bunVersion?: string;
/**
* Enables configuration of multiple services in a single deployment. Map of service name to service configuration.
* @private
*/
experimentalServices?: Record<string, {
/**
* Service type: web, cron, or worker. Defaults to web.
*/
type?: 'web' | 'cron' | 'worker';
/**
* Entry file for the service, relative to the workspace directory.
*/
entrypoint?: string;
/**
* Path to the directory containing the service manifest file (package.json, pyproject.toml, etc.). Defaults to "." (project root).
*/
workspace?: string;
/**
* URL prefix for routing (web services only).
*/
routePrefix?: string;
/**
* Subdomain for host-based routing (web services only).
*/
subdomain?: string;
/**
* Framework to use.
*/
framework?: string;
/**
* Builder to use, e.g. @vercel/node, @vercel/python.
*/
builder?: string;
/**
* Specific lambda runtime to use, e.g. nodejs24.x, python3.14.
*/
runtime?: string;
/**
* Build command for the service.
*/
buildCommand?: string;
/**
* Install command for the service.
*/
installCommand?: string;
/**
* Memory allocation in MB (128-10240).
*/
memory?: number;
/**
* Max duration in seconds (1-900).
*/
maxDuration?: number;
/**
* Files to include in bundle.
*/
includeFiles?: string | string[];
/**
* Files to exclude from bundle.
*/
excludeFiles?: string | string[];
/**
* Cron schedule expression (e.g., "0 0 * * *"). Required for cron services.
*/
schedule?: string;
/**
* Topic names for worker subscription.
*/
topics?: string[];
/**
* Consumer group name for worker subscription.
*/
consumer?: string;
/**
* Custom prefix to use to inject service URL env vars.
*/
envPrefix?: string;
}>;
/**
* Enables grouping of services. Map of service group name to an array of service names belonging to that group.
* @private
*/
experimentalServiceGroups?: Record<string, string[]>;
}

@@ -350,0 +563,0 @@ /**

"use strict";
/**
* Vercel configuration type that mirrors the vercel.json schema
* https://openapi.vercel.sh/vercel.json
* AUTO-GENERATED — DO NOT EDIT
*
* This file is generated from the vercel.json OpenAPI schema.
* To modify, update scripts/generate-types.ts and re-run:
* pnpm generate-types
*
* Schema: https://openapi.vercel.sh/vercel.json
*/

@@ -6,0 +11,0 @@ Object.defineProperty(exports, "__esModule", { value: true });

@@ -35,3 +35,3 @@ "use strict";

}
catch (e) {
catch (_e) {
throw new Error(`Invalid regex pattern: ${pattern}`);

@@ -38,0 +38,0 @@ }

export { createRoutes, routes, Router } from '../router';
export * from '../router';
export { VercelConfig } from '../types';
export type { Redirect, Rewrite, HeaderRule, Condition, RouteType, } from '../types';
export type { Redirect, Rewrite, HeaderRule, Condition, MatchableValue, RouteType, } from '../types';
export { validateStaticString, validateStaticBoolean, validateStaticObject, validateStaticStringArray, validateStaticFields, } from '../utils/validation';

@@ -7,2 +7,2 @@ /**

*/
export type { VercelConfig, Framework, FunctionConfig, CronJob, GitDeploymentConfig, GitConfig, GithubConfig, ImageConfig, Header, Condition, Redirect, Rewrite, HeaderRule, RouteType, WildcardDomain, BuildConfig, BuildItem, } from '../types';
export type { VercelConfig, Framework, FunctionConfig, CronJob, GitDeploymentConfig, GitConfig, GithubConfig, ImageConfig, Header, Condition, MatchableValue, Redirect, Rewrite, HeaderRule, RouteType, WildcardDomain, BuildConfig, BuildItem, } from '../types';
{
"name": "@vercel/config",
"version": "0.1.0-canary.20260211174907.cdd2da6",
"version": "0.1.0",
"description": "A TypeScript SDK for programmatically configuring Vercel projects",

@@ -38,3 +38,4 @@ "license": "MIT",

"pretty-cache-header": "^1.0.0",
"zod": "^3.22.0"
"zod": "^3.22.0",
"@vercel/routing-utils": "6.1.1"
},

@@ -41,0 +42,0 @@ "devDependencies": {