@vercel/config 0.0.18 → 0.0.20
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/router.js +66 -8
- package/dist/types.d.ts +100 -6
- package/package.json +1 -1
package/dist/router.js
CHANGED
|
@@ -26,6 +26,30 @@ function runtimeEnv(name) {
|
|
|
26
26
|
return `$${name}`;
|
|
27
27
|
}
|
|
28
28
|
exports.runtimeEnv = runtimeEnv;
|
|
29
|
+
/**
|
|
30
|
+
* Extract environment variable names from a string or array of strings
|
|
31
|
+
* Returns env var names without the $ prefix, excluding path parameters
|
|
32
|
+
*/
|
|
33
|
+
function extractEnvVars(args, pathParams) {
|
|
34
|
+
if (!args)
|
|
35
|
+
return [];
|
|
36
|
+
const envVars = new Set();
|
|
37
|
+
const argsArray = Array.isArray(args) ? args : [args];
|
|
38
|
+
for (const arg of argsArray) {
|
|
39
|
+
// Find all $VAR patterns
|
|
40
|
+
const matches = arg.match(/\$([A-Z_][A-Z0-9_]*)/g);
|
|
41
|
+
if (matches) {
|
|
42
|
+
for (const match of matches) {
|
|
43
|
+
const varName = match.substring(1); // Remove the $
|
|
44
|
+
// Only add if it's not a path parameter
|
|
45
|
+
if (!pathParams.includes(varName)) {
|
|
46
|
+
envVars.add(varName);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return Array.from(envVars);
|
|
52
|
+
}
|
|
29
53
|
/**
|
|
30
54
|
* The main Router class for building a Vercel configuration object in code.
|
|
31
55
|
* Supports synchronous or asynchronous addition of rewrites, redirects, headers,
|
|
@@ -149,34 +173,50 @@ class Router {
|
|
|
149
173
|
if (hasTransforms) {
|
|
150
174
|
// Build a Route object with transforms
|
|
151
175
|
const transforms = [];
|
|
176
|
+
const pathParams = this.extractPathParams(source);
|
|
152
177
|
if (requestHeaders) {
|
|
153
178
|
for (const [key, value] of Object.entries(requestHeaders)) {
|
|
154
|
-
|
|
179
|
+
const transform = {
|
|
155
180
|
type: 'request.headers',
|
|
156
181
|
op: 'set',
|
|
157
182
|
target: { key },
|
|
158
183
|
args: value,
|
|
159
|
-
}
|
|
184
|
+
};
|
|
185
|
+
const envVars = extractEnvVars(value, pathParams);
|
|
186
|
+
if (envVars.length > 0) {
|
|
187
|
+
transform.env = envVars;
|
|
188
|
+
}
|
|
189
|
+
transforms.push(transform);
|
|
160
190
|
}
|
|
161
191
|
}
|
|
162
192
|
if (responseHeaders) {
|
|
163
193
|
for (const [key, value] of Object.entries(responseHeaders)) {
|
|
164
|
-
|
|
194
|
+
const transform = {
|
|
165
195
|
type: 'response.headers',
|
|
166
196
|
op: 'set',
|
|
167
197
|
target: { key },
|
|
168
198
|
args: value,
|
|
169
|
-
}
|
|
199
|
+
};
|
|
200
|
+
const envVars = extractEnvVars(value, pathParams);
|
|
201
|
+
if (envVars.length > 0) {
|
|
202
|
+
transform.env = envVars;
|
|
203
|
+
}
|
|
204
|
+
transforms.push(transform);
|
|
170
205
|
}
|
|
171
206
|
}
|
|
172
207
|
if (requestQuery) {
|
|
173
208
|
for (const [key, value] of Object.entries(requestQuery)) {
|
|
174
|
-
|
|
209
|
+
const transform = {
|
|
175
210
|
type: 'request.query',
|
|
176
211
|
op: 'set',
|
|
177
212
|
target: { key },
|
|
178
213
|
args: value,
|
|
179
|
-
}
|
|
214
|
+
};
|
|
215
|
+
const envVars = extractEnvVars(value, pathParams);
|
|
216
|
+
if (envVars.length > 0) {
|
|
217
|
+
transform.env = envVars;
|
|
218
|
+
}
|
|
219
|
+
transforms.push(transform);
|
|
180
220
|
}
|
|
181
221
|
}
|
|
182
222
|
const route = {
|
|
@@ -239,13 +279,19 @@ class Router {
|
|
|
239
279
|
if (requestHeaders) {
|
|
240
280
|
// Build a Route object with transforms
|
|
241
281
|
const transforms = [];
|
|
282
|
+
const pathParams = this.extractPathParams(source);
|
|
242
283
|
for (const [key, value] of Object.entries(requestHeaders)) {
|
|
243
|
-
|
|
284
|
+
const transform = {
|
|
244
285
|
type: 'request.headers',
|
|
245
286
|
op: 'set',
|
|
246
287
|
target: { key },
|
|
247
288
|
args: value,
|
|
248
|
-
}
|
|
289
|
+
};
|
|
290
|
+
const envVars = extractEnvVars(value, pathParams);
|
|
291
|
+
if (envVars.length > 0) {
|
|
292
|
+
transform.env = envVars;
|
|
293
|
+
}
|
|
294
|
+
transforms.push(transform);
|
|
249
295
|
}
|
|
250
296
|
const route = {
|
|
251
297
|
src: source,
|
|
@@ -331,6 +377,18 @@ class Router {
|
|
|
331
377
|
*/
|
|
332
378
|
route(config) {
|
|
333
379
|
this.validateSourcePattern(config.src);
|
|
380
|
+
// Auto-extract env vars from each transform if not already specified
|
|
381
|
+
if (config.transforms) {
|
|
382
|
+
const pathParams = this.extractPathParams(config.src);
|
|
383
|
+
for (const transform of config.transforms) {
|
|
384
|
+
if (!transform.env && transform.args) {
|
|
385
|
+
const envVars = extractEnvVars(transform.args, pathParams);
|
|
386
|
+
if (envVars.length > 0) {
|
|
387
|
+
transform.env = envVars;
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
}
|
|
334
392
|
this.routeRules.push(config);
|
|
335
393
|
return this;
|
|
336
394
|
}
|
package/dist/types.d.ts
CHANGED
|
@@ -28,11 +28,50 @@ export interface GitDeploymentConfig {
|
|
|
28
28
|
}
|
|
29
29
|
export interface GitConfig {
|
|
30
30
|
deploymentEnabled?: boolean | GitDeploymentConfig;
|
|
31
|
+
/**
|
|
32
|
+
* @private
|
|
33
|
+
*/
|
|
34
|
+
exclusivity?: {
|
|
35
|
+
teams?: string[];
|
|
36
|
+
};
|
|
31
37
|
}
|
|
32
38
|
export interface GithubConfig {
|
|
33
39
|
enabled?: boolean;
|
|
34
40
|
autoAlias?: boolean;
|
|
35
41
|
autoJobCancelation?: boolean;
|
|
42
|
+
/**
|
|
43
|
+
* @deprecated
|
|
44
|
+
*/
|
|
45
|
+
silent?: boolean;
|
|
46
|
+
}
|
|
47
|
+
export interface ImageConfig {
|
|
48
|
+
sizes: number[];
|
|
49
|
+
domains?: string[];
|
|
50
|
+
formats?: ('image/avif' | 'image/webp' | 'image/jpeg' | 'image/png')[];
|
|
51
|
+
minimumCacheTTL?: number;
|
|
52
|
+
dangerouslyAllowSVG?: boolean;
|
|
53
|
+
contentSecurityPolicy?: string;
|
|
54
|
+
contentDispositionType?: 'inline' | 'attachment';
|
|
55
|
+
qualities?: number[];
|
|
56
|
+
localPatterns?: Array<{
|
|
57
|
+
pathname?: string;
|
|
58
|
+
search?: string;
|
|
59
|
+
}>;
|
|
60
|
+
remotePatterns?: Array<{
|
|
61
|
+
protocol?: 'http' | 'https';
|
|
62
|
+
hostname: string;
|
|
63
|
+
port?: string;
|
|
64
|
+
pathname?: string;
|
|
65
|
+
search?: string;
|
|
66
|
+
}>;
|
|
67
|
+
}
|
|
68
|
+
export interface ProbeConfig {
|
|
69
|
+
path: string;
|
|
70
|
+
initialDelaySeconds?: number;
|
|
71
|
+
periodSeconds?: number;
|
|
72
|
+
timeoutSeconds?: number;
|
|
73
|
+
successThreshold?: number;
|
|
74
|
+
failureThreshold?: number;
|
|
36
75
|
}
|
|
37
76
|
/**
|
|
38
77
|
* HTTP header key/value pair
|
|
@@ -48,10 +87,13 @@ export interface Condition {
|
|
|
48
87
|
type: 'header' | 'cookie' | 'host' | 'query' | 'path';
|
|
49
88
|
key?: string;
|
|
50
89
|
value?: string | number;
|
|
51
|
-
inc?: string[];
|
|
52
|
-
pre?: string;
|
|
53
90
|
eq?: string | number;
|
|
54
91
|
neq?: string;
|
|
92
|
+
inc?: string[];
|
|
93
|
+
ninc?: string[];
|
|
94
|
+
pre?: string;
|
|
95
|
+
suf?: string;
|
|
96
|
+
re?: string;
|
|
55
97
|
gt?: number;
|
|
56
98
|
gte?: number;
|
|
57
99
|
lt?: number;
|
|
@@ -99,11 +141,37 @@ export interface WildcardDomain {
|
|
|
99
141
|
domain: string;
|
|
100
142
|
value: string;
|
|
101
143
|
}
|
|
144
|
+
export interface BuildConfig {
|
|
145
|
+
env?: Record<string, string>;
|
|
146
|
+
}
|
|
147
|
+
export interface BuildItem {
|
|
148
|
+
src?: string;
|
|
149
|
+
use: string;
|
|
150
|
+
config?: Record<string, any>;
|
|
151
|
+
}
|
|
102
152
|
export interface VercelConfig {
|
|
153
|
+
/**
|
|
154
|
+
* JSON schema URL for editor completions and validation.
|
|
155
|
+
*/
|
|
156
|
+
$schema?: string;
|
|
103
157
|
/**
|
|
104
158
|
* Aliases that will get assigned when the deployment is `READY` and the target is `production`.
|
|
105
159
|
*/
|
|
106
160
|
alias?: string | string[];
|
|
161
|
+
/**
|
|
162
|
+
* Build configuration (deprecated).
|
|
163
|
+
* @deprecated
|
|
164
|
+
*/
|
|
165
|
+
build?: BuildConfig;
|
|
166
|
+
/**
|
|
167
|
+
* Build descriptions (deprecated).
|
|
168
|
+
* @deprecated
|
|
169
|
+
*/
|
|
170
|
+
builds?: BuildItem[];
|
|
171
|
+
/**
|
|
172
|
+
* Path to a JSON file containing bulk redirect rules.
|
|
173
|
+
*/
|
|
174
|
+
bulkRedirectsPath?: string;
|
|
107
175
|
/**
|
|
108
176
|
* When set to `true`, all HTML files and Serverless Functions will have their extension removed.
|
|
109
177
|
*/
|
|
@@ -141,11 +209,31 @@ export interface VercelConfig {
|
|
|
141
209
|
* Can use router.header() and router.cacheControl() helpers.
|
|
142
210
|
*/
|
|
143
211
|
headers?: RouteType[];
|
|
212
|
+
/**
|
|
213
|
+
* Image optimization configuration.
|
|
214
|
+
*/
|
|
215
|
+
images?: ImageConfig;
|
|
216
|
+
/**
|
|
217
|
+
* A name for the deployment.
|
|
218
|
+
*/
|
|
219
|
+
name?: string;
|
|
220
|
+
/**
|
|
221
|
+
* Probe configuration for health checks.
|
|
222
|
+
*/
|
|
223
|
+
probes?: ProbeConfig[];
|
|
224
|
+
/**
|
|
225
|
+
* When true, the source code is not stored on the platform and only the production output will be deployed.
|
|
226
|
+
*/
|
|
227
|
+
public?: boolean;
|
|
144
228
|
/**
|
|
145
229
|
* HTTP redirects configuration.
|
|
146
230
|
* Can use router.redirect() helper.
|
|
147
231
|
*/
|
|
148
232
|
redirects?: RouteType[];
|
|
233
|
+
/**
|
|
234
|
+
* An array of regions where the deployment's Serverless Functions and Edge Functions should be deployed to.
|
|
235
|
+
*/
|
|
236
|
+
regions?: string[];
|
|
149
237
|
/**
|
|
150
238
|
* HTTP rewrites configuration.
|
|
151
239
|
* Can use router.rewrite() helper.
|
|
@@ -157,10 +245,20 @@ export interface VercelConfig {
|
|
|
157
245
|
* Cannot be mixed with headers, redirects, or rewrites.
|
|
158
246
|
*/
|
|
159
247
|
routes?: RouteType[];
|
|
248
|
+
/**
|
|
249
|
+
* Scope (user or team) for deployment.
|
|
250
|
+
* @private
|
|
251
|
+
*/
|
|
252
|
+
scope?: string;
|
|
160
253
|
/**
|
|
161
254
|
* Wildcard domain configuration.
|
|
162
255
|
*/
|
|
163
256
|
wildcard?: WildcardDomain[];
|
|
257
|
+
/**
|
|
258
|
+
* Version of the configuration schema.
|
|
259
|
+
* @private
|
|
260
|
+
*/
|
|
261
|
+
version?: number;
|
|
164
262
|
/**
|
|
165
263
|
* The build command for this project. When `null`, automatically detected.
|
|
166
264
|
*/
|
|
@@ -201,10 +299,6 @@ export interface VercelConfig {
|
|
|
201
299
|
* Enables Bun for the project and specifies the version to use.
|
|
202
300
|
*/
|
|
203
301
|
bunVersion?: string;
|
|
204
|
-
/**
|
|
205
|
-
* Node.js version for this project.
|
|
206
|
-
*/
|
|
207
|
-
nodeVersion?: string;
|
|
208
302
|
}
|
|
209
303
|
/**
|
|
210
304
|
* Runtime placeholder for VercelConfig to allow named imports.
|