@vercel/config 0.0.32 → 0.0.35
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.d.ts +7 -1
- package/dist/router.js +65 -10
- package/dist/types.d.ts +0 -1
- package/package.json +3 -2
package/dist/router.d.ts
CHANGED
|
@@ -267,9 +267,13 @@ export interface Transform {
|
|
|
267
267
|
*/
|
|
268
268
|
export interface Route {
|
|
269
269
|
/** Pattern to match request paths using path-to-regexp syntax */
|
|
270
|
-
src
|
|
270
|
+
src?: string;
|
|
271
|
+
/** Alias for `src`. A pattern that matches each incoming pathname (excluding querystring). */
|
|
272
|
+
source?: string;
|
|
271
273
|
/** Optional destination for rewrite/redirect */
|
|
272
274
|
dest?: string;
|
|
275
|
+
/** Alias for `dest`. An absolute pathname to an existing resource or an external URL. */
|
|
276
|
+
destination?: string;
|
|
273
277
|
/** Array of HTTP methods to match. If not provided, matches all methods */
|
|
274
278
|
methods?: string[];
|
|
275
279
|
/** Array of transforms to apply */
|
|
@@ -280,6 +284,8 @@ export interface Route {
|
|
|
280
284
|
missing?: Condition[];
|
|
281
285
|
/** Status code for the response */
|
|
282
286
|
status?: number;
|
|
287
|
+
/** Alias for `status`. An optional integer to override the status code of the response. */
|
|
288
|
+
statusCode?: number;
|
|
283
289
|
/** Headers to set (alternative to using transforms) */
|
|
284
290
|
headers?: Record<string, string>;
|
|
285
291
|
/** Environment variables referenced in dest or transforms */
|
package/dist/router.js
CHANGED
|
@@ -2,7 +2,26 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.routes = exports.createRoutes = exports.Router = exports.matchers = exports.deploymentEnv = void 0;
|
|
4
4
|
const pretty_cache_header_1 = require("pretty-cache-header");
|
|
5
|
+
const routing_utils_1 = require("@vercel/routing-utils");
|
|
5
6
|
const validation_1 = require("./utils/validation");
|
|
7
|
+
/**
|
|
8
|
+
* Convert a destination string from path-to-regexp format to use capture group references.
|
|
9
|
+
* Replaces :paramName with $index based on the segments array.
|
|
10
|
+
*/
|
|
11
|
+
function convertDestination(destination, segments) {
|
|
12
|
+
let result = destination;
|
|
13
|
+
segments.forEach((segment, index) => {
|
|
14
|
+
const patterns = [
|
|
15
|
+
new RegExp(`:${segment}\\*`, 'g'),
|
|
16
|
+
new RegExp(`:${segment}\\+`, 'g'),
|
|
17
|
+
new RegExp(`:${segment}(?![a-zA-Z0-9_])`, 'g'),
|
|
18
|
+
];
|
|
19
|
+
for (const pattern of patterns) {
|
|
20
|
+
result = result.replace(pattern, `$${index + 1}`);
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
return result;
|
|
24
|
+
}
|
|
6
25
|
/**
|
|
7
26
|
* Helper function to reference a Vercel project environment variable.
|
|
8
27
|
* These are placeholders that get resolved at request time by Vercel's routing layer.
|
|
@@ -163,9 +182,12 @@ class Router {
|
|
|
163
182
|
transforms.push(transform);
|
|
164
183
|
}
|
|
165
184
|
}
|
|
185
|
+
// Convert path-to-regexp patterns to regex for routes format
|
|
186
|
+
const { src: regexSrc, segments } = (0, routing_utils_1.sourceToRegex)(source);
|
|
187
|
+
const convertedDest = convertDestination(destination, segments);
|
|
166
188
|
const route = {
|
|
167
|
-
src:
|
|
168
|
-
dest:
|
|
189
|
+
src: regexSrc,
|
|
190
|
+
dest: convertedDest,
|
|
169
191
|
transforms,
|
|
170
192
|
};
|
|
171
193
|
if (has)
|
|
@@ -186,9 +208,12 @@ class Router {
|
|
|
186
208
|
const destEnvVars = extractEnvVars(destination, pathParams);
|
|
187
209
|
if (destEnvVars.length > 0) {
|
|
188
210
|
// Need Route format to include env field
|
|
211
|
+
// Convert path-to-regexp patterns to regex for routes format
|
|
212
|
+
const { src: regexSrc, segments } = (0, routing_utils_1.sourceToRegex)(source);
|
|
213
|
+
const convertedDest = convertDestination(destination, segments);
|
|
189
214
|
const route = {
|
|
190
|
-
src:
|
|
191
|
-
dest:
|
|
215
|
+
src: regexSrc,
|
|
216
|
+
dest: convertedDest,
|
|
192
217
|
env: destEnvVars,
|
|
193
218
|
};
|
|
194
219
|
if (has)
|
|
@@ -245,9 +270,12 @@ class Router {
|
|
|
245
270
|
}
|
|
246
271
|
transforms.push(transform);
|
|
247
272
|
}
|
|
273
|
+
// Convert path-to-regexp patterns to regex for routes format
|
|
274
|
+
const { src: regexSrc, segments } = (0, routing_utils_1.sourceToRegex)(source);
|
|
275
|
+
const convertedDest = convertDestination(destination, segments);
|
|
248
276
|
const route = {
|
|
249
|
-
src:
|
|
250
|
-
dest:
|
|
277
|
+
src: regexSrc,
|
|
278
|
+
dest: convertedDest,
|
|
251
279
|
status: statusCode || (permanent ? 308 : 307),
|
|
252
280
|
transforms,
|
|
253
281
|
};
|
|
@@ -267,9 +295,12 @@ class Router {
|
|
|
267
295
|
const destEnvVars = extractEnvVars(destination, pathParams);
|
|
268
296
|
if (destEnvVars.length > 0) {
|
|
269
297
|
// Need Route format to include env field
|
|
298
|
+
// Convert path-to-regexp patterns to regex for routes format
|
|
299
|
+
const { src: regexSrc, segments } = (0, routing_utils_1.sourceToRegex)(source);
|
|
300
|
+
const convertedDest = convertDestination(destination, segments);
|
|
270
301
|
const route = {
|
|
271
|
-
src:
|
|
272
|
-
dest:
|
|
302
|
+
src: regexSrc,
|
|
303
|
+
dest: convertedDest,
|
|
273
304
|
status: statusCode || (permanent ? 308 : 307),
|
|
274
305
|
env: destEnvVars,
|
|
275
306
|
};
|
|
@@ -349,10 +380,34 @@ class Router {
|
|
|
349
380
|
* });
|
|
350
381
|
*/
|
|
351
382
|
route(config) {
|
|
352
|
-
|
|
383
|
+
if (config.src && config.source) {
|
|
384
|
+
throw new Error('Route cannot define both `src` and `source`. Use one or the other.');
|
|
385
|
+
}
|
|
386
|
+
if (config.dest && config.destination) {
|
|
387
|
+
throw new Error('Route cannot define both `dest` and `destination`. Use one or the other.');
|
|
388
|
+
}
|
|
389
|
+
if (config.status !== undefined && config.statusCode !== undefined) {
|
|
390
|
+
throw new Error('Route cannot define both `status` and `statusCode`. Use one or the other.');
|
|
391
|
+
}
|
|
392
|
+
const src = config.src ?? config.source;
|
|
393
|
+
if (!src) {
|
|
394
|
+
throw new Error('Route must define either `src` or `source`.');
|
|
395
|
+
}
|
|
396
|
+
this.validateSourcePattern(src);
|
|
397
|
+
// Normalize aliases to canonical names (src/dest/status)
|
|
398
|
+
config.src = src;
|
|
399
|
+
delete config.source;
|
|
400
|
+
if (config.destination !== undefined) {
|
|
401
|
+
config.dest = config.destination;
|
|
402
|
+
delete config.destination;
|
|
403
|
+
}
|
|
404
|
+
if (config.statusCode !== undefined) {
|
|
405
|
+
config.status = config.statusCode;
|
|
406
|
+
delete config.statusCode;
|
|
407
|
+
}
|
|
353
408
|
// Auto-extract env vars from each transform if not already specified
|
|
354
409
|
if (config.transforms) {
|
|
355
|
-
const pathParams = this.extractPathParams(
|
|
410
|
+
const pathParams = this.extractPathParams(src);
|
|
356
411
|
for (const transform of config.transforms) {
|
|
357
412
|
if (!transform.env && transform.args) {
|
|
358
413
|
const envVars = extractEnvVars(transform.args, pathParams);
|
package/dist/types.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vercel/config",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.35",
|
|
4
4
|
"description": "A TypeScript SDK for programmatically configuring Vercel projects",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://vercel.com/docs/projects/project-configuration",
|
|
@@ -35,7 +35,8 @@
|
|
|
35
35
|
],
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"pretty-cache-header": "^1.0.0",
|
|
38
|
-
"zod": "^3.22.0"
|
|
38
|
+
"zod": "^3.22.0",
|
|
39
|
+
"@vercel/routing-utils": "6.0.0"
|
|
39
40
|
},
|
|
40
41
|
"devDependencies": {
|
|
41
42
|
"@types/node": "20.11.0",
|