@vercel/config 0.0.13 → 0.0.16

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.
@@ -0,0 +1,208 @@
1
+ /**
2
+ * Vercel configuration type that mirrors the vercel.json schema
3
+ * https://openapi.vercel.sh/vercel.json
4
+ */
5
+ 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;
6
+ export interface CronJob {
7
+ schedule: string;
8
+ path: string;
9
+ }
10
+ export interface FunctionConfig {
11
+ excludeFiles?: string;
12
+ includeFiles?: string;
13
+ maxDuration?: number;
14
+ memory?: number;
15
+ runtime?: string;
16
+ supportsCancellation?: boolean;
17
+ experimentalTriggers?: Array<{
18
+ type: 'queue/v1beta';
19
+ topic: string;
20
+ consumer: string;
21
+ maxDeliveries?: number;
22
+ retryAfterSeconds?: number;
23
+ initialDelaySeconds?: number;
24
+ }>;
25
+ }
26
+ export interface GitDeploymentConfig {
27
+ [branch: string]: boolean;
28
+ }
29
+ export interface GitConfig {
30
+ deploymentEnabled?: boolean | GitDeploymentConfig;
31
+ }
32
+ export interface GithubConfig {
33
+ enabled?: boolean;
34
+ autoAlias?: boolean;
35
+ autoJobCancelation?: boolean;
36
+ }
37
+ /**
38
+ * HTTP header key/value pair
39
+ */
40
+ export interface Header {
41
+ key: string;
42
+ value: string;
43
+ }
44
+ /**
45
+ * Condition for matching in redirects, rewrites, and headers
46
+ */
47
+ export interface Condition {
48
+ type: 'header' | 'cookie' | 'host' | 'query' | 'path';
49
+ key?: string;
50
+ value?: string | number;
51
+ inc?: string[];
52
+ pre?: string;
53
+ eq?: string | number;
54
+ neq?: string;
55
+ gt?: number;
56
+ gte?: number;
57
+ lt?: number;
58
+ lte?: number;
59
+ }
60
+ /**
61
+ * Redirect matching vercel.json schema
62
+ * Returned by router.redirect()
63
+ */
64
+ export interface Redirect {
65
+ source: string;
66
+ destination: string;
67
+ permanent?: boolean;
68
+ statusCode?: number;
69
+ has?: Condition[];
70
+ missing?: Condition[];
71
+ }
72
+ /**
73
+ * Rewrite matching vercel.json schema
74
+ * Returned by router.rewrite()
75
+ */
76
+ export interface Rewrite {
77
+ source: string;
78
+ destination: string;
79
+ has?: Condition[];
80
+ missing?: Condition[];
81
+ }
82
+ /**
83
+ * Header rule matching vercel.json schema
84
+ * Returned by router.header() and router.cacheControl()
85
+ */
86
+ export interface HeaderRule {
87
+ source: string;
88
+ headers: Header[];
89
+ has?: Condition[];
90
+ missing?: Condition[];
91
+ }
92
+ /**
93
+ * Union type for all router helper outputs
94
+ * Can be simple schema objects (Redirect, Rewrite, HeaderRule) or Routes with transforms
95
+ * Note: Route type is defined in router.ts (uses src/dest instead of source/destination)
96
+ */
97
+ export type RouteType = Redirect | Rewrite | HeaderRule | any;
98
+ export interface WildcardDomain {
99
+ domain: string;
100
+ value: string;
101
+ }
102
+ export interface VercelConfig {
103
+ /**
104
+ * Aliases that will get assigned when the deployment is `READY` and the target is `production`.
105
+ */
106
+ alias?: string | string[];
107
+ /**
108
+ * When set to `true`, all HTML files and Serverless Functions will have their extension removed.
109
+ */
110
+ cleanUrls?: boolean;
111
+ /**
112
+ * An array of cron jobs that should be created for production Deployments.
113
+ */
114
+ crons?: CronJob[];
115
+ /**
116
+ * An object containing the deployment's environment variables.
117
+ */
118
+ env?: Record<string, string>;
119
+ /**
120
+ * An array of the passive regions the deployment's Serverless Functions should be deployed to.
121
+ */
122
+ passiveRegions?: string[];
123
+ /**
124
+ * Same as passiveRegions. An array of passive regions for failover.
125
+ */
126
+ functionFailoverRegions?: string[];
127
+ /**
128
+ * An object describing custom options for Serverless Functions.
129
+ */
130
+ functions?: Record<string, FunctionConfig>;
131
+ /**
132
+ * Git-related configuration.
133
+ */
134
+ git?: GitConfig;
135
+ /**
136
+ * GitHub-related configuration.
137
+ */
138
+ github?: GithubConfig;
139
+ /**
140
+ * HTTP headers configuration.
141
+ * Can use router.header() and router.cacheControl() helpers.
142
+ */
143
+ headers?: RouteType[];
144
+ /**
145
+ * HTTP redirects configuration.
146
+ * Can use router.redirect() helper.
147
+ */
148
+ redirects?: RouteType[];
149
+ /**
150
+ * HTTP rewrites configuration.
151
+ * Can use router.rewrite() helper.
152
+ */
153
+ rewrites?: RouteType[];
154
+ /**
155
+ * Routes configuration using the lower-level routes primitive.
156
+ * Use this if you need transforms or want everything in one place.
157
+ * Cannot be mixed with headers, redirects, or rewrites.
158
+ */
159
+ routes?: RouteType[];
160
+ /**
161
+ * Wildcard domain configuration.
162
+ */
163
+ wildcard?: WildcardDomain[];
164
+ /**
165
+ * The build command for this project. When `null`, automatically detected.
166
+ */
167
+ buildCommand?: string | null;
168
+ /**
169
+ * The ignore command for this project.
170
+ */
171
+ ignoreCommand?: string | null;
172
+ /**
173
+ * The dev command for this project. When `null`, automatically detected.
174
+ */
175
+ devCommand?: string | null;
176
+ /**
177
+ * The framework being used. When `null`, no framework is selected.
178
+ */
179
+ framework?: Framework;
180
+ /**
181
+ * The install command for this project. When `null`, automatically detected.
182
+ */
183
+ installCommand?: string | null;
184
+ /**
185
+ * The output directory of the project. When `null`, automatically detected.
186
+ */
187
+ outputDirectory?: string | null;
188
+ /**
189
+ * When `false`, visiting a path that ends with a forward slash will redirect to the path without the trailing slash.
190
+ */
191
+ trailingSlash?: boolean;
192
+ /**
193
+ * An array of projectIds to associate with the current project.
194
+ */
195
+ relatedProjects?: string[];
196
+ /**
197
+ * Enables Fluid compute for the project.
198
+ */
199
+ fluid?: boolean;
200
+ /**
201
+ * Enables Bun for the project and specifies the version to use.
202
+ */
203
+ bunVersion?: string;
204
+ /**
205
+ * Node.js version for this project.
206
+ */
207
+ nodeVersion?: string;
208
+ }
package/dist/types.js ADDED
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ /**
3
+ * Vercel configuration type that mirrors the vercel.json schema
4
+ * https://openapi.vercel.sh/vercel.json
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -41,3 +41,30 @@ export declare function countCaptureGroups(pattern: string): number;
41
41
  * that don't exist in the source pattern.
42
42
  */
43
43
  export declare function validateCaptureGroupReferences(source: string, destination: string): void;
44
+ /**
45
+ * Validates that a value is a static string literal (not computed, not a function call, etc.)
46
+ * Used for static fields that must be extracted before build execution.
47
+ */
48
+ export declare function validateStaticString(value: any, fieldName: string): void;
49
+ /**
50
+ * Validates that a value is a static boolean literal
51
+ */
52
+ export declare function validateStaticBoolean(value: any, fieldName: string): void;
53
+ /**
54
+ * Validates that a value is a static object with primitive values
55
+ * Used for git.deploymentEnabled and similar objects that need to be static
56
+ */
57
+ export declare function validateStaticObject(value: any, fieldName: string): void;
58
+ /**
59
+ * Validates that a value is a static array of strings
60
+ */
61
+ export declare function validateStaticStringArray(value: any, fieldName: string): void;
62
+ /**
63
+ * Validates static fields in VercelConfig that must be extracted before build execution.
64
+ * These fields include:
65
+ * - buildCommand, devCommand, installCommand, framework, nodeVersion, outputDirectory
66
+ * - github.enabled, github.autoAlias, github.autoJobCancelation
67
+ * - git.deploymentEnabled
68
+ * - relatedProjects
69
+ */
70
+ export declare function validateStaticFields(config: Record<string, any>): void;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.validateCaptureGroupReferences = exports.countCaptureGroups = exports.createCronExpression = exports.parseCronExpression = exports.validateRegexPattern = void 0;
3
+ exports.validateStaticFields = exports.validateStaticStringArray = exports.validateStaticObject = exports.validateStaticBoolean = exports.validateStaticString = exports.validateCaptureGroupReferences = exports.countCaptureGroups = exports.createCronExpression = exports.parseCronExpression = exports.validateRegexPattern = void 0;
4
4
  const zod_1 = require("zod");
5
5
  /**
6
6
  * Validates and type-checks regex patterns for Vercel's path-to-regexp syntax.
@@ -122,3 +122,98 @@ function validateCaptureGroupReferences(source, destination) {
122
122
  }
123
123
  }
124
124
  exports.validateCaptureGroupReferences = validateCaptureGroupReferences;
125
+ /**
126
+ * Validates that a value is a static string literal (not computed, not a function call, etc.)
127
+ * Used for static fields that must be extracted before build execution.
128
+ */
129
+ function validateStaticString(value, fieldName) {
130
+ if (typeof value !== 'string') {
131
+ throw new Error(`Field "${fieldName}" must be a static string literal. ` +
132
+ `Got ${typeof value}. Function calls, variables, and expressions are not allowed.`);
133
+ }
134
+ }
135
+ exports.validateStaticString = validateStaticString;
136
+ /**
137
+ * Validates that a value is a static boolean literal
138
+ */
139
+ function validateStaticBoolean(value, fieldName) {
140
+ if (typeof value !== 'boolean') {
141
+ throw new Error(`Field "${fieldName}" must be a static boolean literal. ` +
142
+ `Got ${typeof value}. Only true or false are allowed.`);
143
+ }
144
+ }
145
+ exports.validateStaticBoolean = validateStaticBoolean;
146
+ /**
147
+ * Validates that a value is a static object with primitive values
148
+ * Used for git.deploymentEnabled and similar objects that need to be static
149
+ */
150
+ function validateStaticObject(value, fieldName) {
151
+ if (typeof value !== 'object' || value === null) {
152
+ throw new Error(`Field "${fieldName}" must be a static object with primitive values. ` +
153
+ `Got ${typeof value}.`);
154
+ }
155
+ for (const [key, val] of Object.entries(value)) {
156
+ if (typeof val !== 'boolean' && typeof val !== 'string' && typeof val !== 'number') {
157
+ throw new Error(`Field "${fieldName}.${key}" must contain only static primitive values (string, number, boolean). ` +
158
+ `Got ${typeof val}.`);
159
+ }
160
+ }
161
+ }
162
+ exports.validateStaticObject = validateStaticObject;
163
+ /**
164
+ * Validates that a value is a static array of strings
165
+ */
166
+ function validateStaticStringArray(value, fieldName) {
167
+ if (!Array.isArray(value)) {
168
+ throw new Error(`Field "${fieldName}" must be a static array of strings. ` +
169
+ `Got ${typeof value}.`);
170
+ }
171
+ for (let i = 0; i < value.length; i++) {
172
+ if (typeof value[i] !== 'string') {
173
+ throw new Error(`Field "${fieldName}[${i}]" must be a static string. ` +
174
+ `Got ${typeof value[i]}.`);
175
+ }
176
+ }
177
+ }
178
+ exports.validateStaticStringArray = validateStaticStringArray;
179
+ /**
180
+ * Validates static fields in VercelConfig that must be extracted before build execution.
181
+ * These fields include:
182
+ * - buildCommand, devCommand, installCommand, framework, nodeVersion, outputDirectory
183
+ * - github.enabled, github.autoAlias, github.autoJobCancelation
184
+ * - git.deploymentEnabled
185
+ * - relatedProjects
186
+ */
187
+ function validateStaticFields(config) {
188
+ // Validate string fields
189
+ const stringFields = ['buildCommand', 'devCommand', 'installCommand', 'framework', 'nodeVersion', 'outputDirectory'];
190
+ for (const field of stringFields) {
191
+ if (config[field] !== undefined && config[field] !== null) {
192
+ validateStaticString(config[field], field);
193
+ }
194
+ }
195
+ // Validate relatedProjects (array of strings)
196
+ if (config.relatedProjects !== undefined) {
197
+ validateStaticStringArray(config.relatedProjects, 'relatedProjects');
198
+ }
199
+ // Validate git.deploymentEnabled (boolean or object with branch booleans)
200
+ if (config.git !== undefined && config.git.deploymentEnabled !== undefined) {
201
+ const deploymentEnabled = config.git.deploymentEnabled;
202
+ if (typeof deploymentEnabled === 'boolean') {
203
+ validateStaticBoolean(deploymentEnabled, 'git.deploymentEnabled');
204
+ }
205
+ else {
206
+ validateStaticObject(deploymentEnabled, 'git.deploymentEnabled');
207
+ }
208
+ }
209
+ // Validate github fields (booleans)
210
+ const githubBooleanFields = ['enabled', 'autoAlias', 'autoJobCancelation'];
211
+ if (config.github !== undefined) {
212
+ for (const field of githubBooleanFields) {
213
+ if (config.github[field] !== undefined) {
214
+ validateStaticBoolean(config.github[field], `github.${field}`);
215
+ }
216
+ }
217
+ }
218
+ }
219
+ exports.validateStaticFields = validateStaticFields;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @vercel/config/v1 - Main API entry point
3
+ *
4
+ * Usage:
5
+ * import { createRouter, VercelConfig } from '@vercel/config/v1';
6
+ */
7
+ export { createRouter, Router } from "../router";
8
+ export * from "../router";
9
+ export type { VercelConfig, Redirect, Rewrite, HeaderRule, Condition, RouteType } from "../types";
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ /**
3
+ * @vercel/config/v1 - Main API entry point
4
+ *
5
+ * Usage:
6
+ * import { createRouter, VercelConfig } from '@vercel/config/v1';
7
+ */
8
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
9
+ if (k2 === undefined) k2 = k;
10
+ var desc = Object.getOwnPropertyDescriptor(m, k);
11
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
12
+ desc = { enumerable: true, get: function() { return m[k]; } };
13
+ }
14
+ Object.defineProperty(o, k2, desc);
15
+ }) : (function(o, m, k, k2) {
16
+ if (k2 === undefined) k2 = k;
17
+ o[k2] = m[k];
18
+ }));
19
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
20
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
21
+ };
22
+ Object.defineProperty(exports, "__esModule", { value: true });
23
+ exports.Router = exports.createRouter = void 0;
24
+ var router_1 = require("../router");
25
+ Object.defineProperty(exports, "createRouter", { enumerable: true, get: function () { return router_1.createRouter; } });
26
+ Object.defineProperty(exports, "Router", { enumerable: true, get: function () { return router_1.Router; } });
27
+ __exportStar(require("../router"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vercel/config",
3
- "version": "0.0.13",
3
+ "version": "0.0.16",
4
4
  "description": "A TypeScript SDK for programmatically generating Vercel configuration files",
5
5
  "bugs": {
6
6
  "url": "https://github.com/vercel/router-sdk/issues"
@@ -13,6 +13,20 @@
13
13
  "license": "MIT",
14
14
  "main": "dist/index.js",
15
15
  "types": "dist/index.d.ts",
16
+ "exports": {
17
+ ".": "./dist/index.js",
18
+ "./v1": "./dist/v1/index.js"
19
+ },
20
+ "typesVersions": {
21
+ "*": {
22
+ ".": [
23
+ "dist/index.d.ts"
24
+ ],
25
+ "v1": [
26
+ "dist/v1/index.d.ts"
27
+ ]
28
+ }
29
+ },
16
30
  "bin": {
17
31
  "@vercel/config": "./dist/cli.js"
18
32
  },