@vercel/config 0.0.31 → 0.0.33
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 +6 -0
- package/dist/router.js +65 -9
- package/package.json +3 -2
package/dist/router.d.ts
CHANGED
|
@@ -173,6 +173,12 @@ export interface Condition extends ConditionOperators {
|
|
|
173
173
|
*/
|
|
174
174
|
value?: string;
|
|
175
175
|
}
|
|
176
|
+
export declare const matchers: {
|
|
177
|
+
header: (key: string, value?: string | ConditionOperators) => Condition;
|
|
178
|
+
cookie: (key: string, value?: string | ConditionOperators) => Condition;
|
|
179
|
+
query: (key: string, value?: string | ConditionOperators) => Condition;
|
|
180
|
+
host: (value: string | ConditionOperators) => Condition;
|
|
181
|
+
};
|
|
176
182
|
/**
|
|
177
183
|
* Transform type specifies the scope of what the transform will apply to.
|
|
178
184
|
* - 'request.query': Transform query parameters in the request
|
package/dist/router.js
CHANGED
|
@@ -1,8 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.routes = exports.createRoutes = exports.Router = exports.deploymentEnv = void 0;
|
|
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.
|
|
@@ -21,6 +40,31 @@ function deploymentEnv(name) {
|
|
|
21
40
|
return `$${name}`;
|
|
22
41
|
}
|
|
23
42
|
exports.deploymentEnv = deploymentEnv;
|
|
43
|
+
function createKeyedConditionHelper(type) {
|
|
44
|
+
return (key, value) => {
|
|
45
|
+
if (value === undefined) {
|
|
46
|
+
return { type, key };
|
|
47
|
+
}
|
|
48
|
+
if (typeof value === 'string') {
|
|
49
|
+
return { type, key, value };
|
|
50
|
+
}
|
|
51
|
+
return { type, key, ...value };
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
function createKeylessConditionHelper(type) {
|
|
55
|
+
return (value) => {
|
|
56
|
+
if (typeof value === 'string') {
|
|
57
|
+
return { type, value };
|
|
58
|
+
}
|
|
59
|
+
return { type, ...value };
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
exports.matchers = {
|
|
63
|
+
header: createKeyedConditionHelper('header'),
|
|
64
|
+
cookie: createKeyedConditionHelper('cookie'),
|
|
65
|
+
query: createKeyedConditionHelper('query'),
|
|
66
|
+
host: createKeylessConditionHelper('host'),
|
|
67
|
+
};
|
|
24
68
|
/**
|
|
25
69
|
* Extract environment variable names from a string or array of strings
|
|
26
70
|
* Returns env var names without the $ prefix, excluding path parameters
|
|
@@ -138,9 +182,12 @@ class Router {
|
|
|
138
182
|
transforms.push(transform);
|
|
139
183
|
}
|
|
140
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);
|
|
141
188
|
const route = {
|
|
142
|
-
src:
|
|
143
|
-
dest:
|
|
189
|
+
src: regexSrc,
|
|
190
|
+
dest: convertedDest,
|
|
144
191
|
transforms,
|
|
145
192
|
};
|
|
146
193
|
if (has)
|
|
@@ -161,9 +208,12 @@ class Router {
|
|
|
161
208
|
const destEnvVars = extractEnvVars(destination, pathParams);
|
|
162
209
|
if (destEnvVars.length > 0) {
|
|
163
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);
|
|
164
214
|
const route = {
|
|
165
|
-
src:
|
|
166
|
-
dest:
|
|
215
|
+
src: regexSrc,
|
|
216
|
+
dest: convertedDest,
|
|
167
217
|
env: destEnvVars,
|
|
168
218
|
};
|
|
169
219
|
if (has)
|
|
@@ -220,9 +270,12 @@ class Router {
|
|
|
220
270
|
}
|
|
221
271
|
transforms.push(transform);
|
|
222
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);
|
|
223
276
|
const route = {
|
|
224
|
-
src:
|
|
225
|
-
dest:
|
|
277
|
+
src: regexSrc,
|
|
278
|
+
dest: convertedDest,
|
|
226
279
|
status: statusCode || (permanent ? 308 : 307),
|
|
227
280
|
transforms,
|
|
228
281
|
};
|
|
@@ -242,9 +295,12 @@ class Router {
|
|
|
242
295
|
const destEnvVars = extractEnvVars(destination, pathParams);
|
|
243
296
|
if (destEnvVars.length > 0) {
|
|
244
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);
|
|
245
301
|
const route = {
|
|
246
|
-
src:
|
|
247
|
-
dest:
|
|
302
|
+
src: regexSrc,
|
|
303
|
+
dest: convertedDest,
|
|
248
304
|
status: statusCode || (permanent ? 308 : 307),
|
|
249
305
|
env: destEnvVars,
|
|
250
306
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vercel/config",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.33",
|
|
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": "5.3.3"
|
|
39
40
|
},
|
|
40
41
|
"devDependencies": {
|
|
41
42
|
"@types/node": "20.11.0",
|