@vercel/config 0.0.17 → 0.0.19
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 +0 -6
- package/dist/router.js +66 -18
- package/package.json +4 -4
package/dist/router.d.ts
CHANGED
|
@@ -544,12 +544,6 @@ export declare class Router {
|
|
|
544
544
|
* Returns both the proxy and a set of accessed environment variable names.
|
|
545
545
|
*/
|
|
546
546
|
private createEnvProxy;
|
|
547
|
-
/**
|
|
548
|
-
* @deprecated No longer used after refactor to return schema objects directly
|
|
549
|
-
* Internal helper to convert TransformOptions to Transform array
|
|
550
|
-
* @param options Transform options to convert
|
|
551
|
-
* @param trackedEnvVars Optional set of environment variables that were accessed via the env proxy
|
|
552
|
-
*/
|
|
553
547
|
/**
|
|
554
548
|
* Creates a rewrite rule. Returns either a Rewrite object (simple case) or Route with transforms.
|
|
555
549
|
*
|
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,
|
|
@@ -111,14 +135,6 @@ class Router {
|
|
|
111
135
|
});
|
|
112
136
|
return { proxy, accessedVars };
|
|
113
137
|
}
|
|
114
|
-
// Deprecated: extractEnvVars method no longer needed after refactor
|
|
115
|
-
/**
|
|
116
|
-
* @deprecated No longer used after refactor to return schema objects directly
|
|
117
|
-
* Internal helper to convert TransformOptions to Transform array
|
|
118
|
-
* @param options Transform options to convert
|
|
119
|
-
* @param trackedEnvVars Optional set of environment variables that were accessed via the env proxy
|
|
120
|
-
*/
|
|
121
|
-
// Deprecated: transformOptionsToTransforms method removed after refactor
|
|
122
138
|
/**
|
|
123
139
|
* Creates a rewrite rule. Returns either a Rewrite object (simple case) or Route with transforms.
|
|
124
140
|
*
|
|
@@ -134,7 +150,6 @@ class Router {
|
|
|
134
150
|
*/
|
|
135
151
|
rewrite(source, destination, optionsOrCallback) {
|
|
136
152
|
this.validateSourcePattern(source);
|
|
137
|
-
(0, validation_1.validateCaptureGroupReferences)(source, destination);
|
|
138
153
|
let options;
|
|
139
154
|
// Handle callback syntax
|
|
140
155
|
if (typeof optionsOrCallback === 'function') {
|
|
@@ -158,34 +173,50 @@ class Router {
|
|
|
158
173
|
if (hasTransforms) {
|
|
159
174
|
// Build a Route object with transforms
|
|
160
175
|
const transforms = [];
|
|
176
|
+
const pathParams = this.extractPathParams(source);
|
|
161
177
|
if (requestHeaders) {
|
|
162
178
|
for (const [key, value] of Object.entries(requestHeaders)) {
|
|
163
|
-
|
|
179
|
+
const transform = {
|
|
164
180
|
type: 'request.headers',
|
|
165
181
|
op: 'set',
|
|
166
182
|
target: { key },
|
|
167
183
|
args: value,
|
|
168
|
-
}
|
|
184
|
+
};
|
|
185
|
+
const envVars = extractEnvVars(value, pathParams);
|
|
186
|
+
if (envVars.length > 0) {
|
|
187
|
+
transform.env = envVars;
|
|
188
|
+
}
|
|
189
|
+
transforms.push(transform);
|
|
169
190
|
}
|
|
170
191
|
}
|
|
171
192
|
if (responseHeaders) {
|
|
172
193
|
for (const [key, value] of Object.entries(responseHeaders)) {
|
|
173
|
-
|
|
194
|
+
const transform = {
|
|
174
195
|
type: 'response.headers',
|
|
175
196
|
op: 'set',
|
|
176
197
|
target: { key },
|
|
177
198
|
args: value,
|
|
178
|
-
}
|
|
199
|
+
};
|
|
200
|
+
const envVars = extractEnvVars(value, pathParams);
|
|
201
|
+
if (envVars.length > 0) {
|
|
202
|
+
transform.env = envVars;
|
|
203
|
+
}
|
|
204
|
+
transforms.push(transform);
|
|
179
205
|
}
|
|
180
206
|
}
|
|
181
207
|
if (requestQuery) {
|
|
182
208
|
for (const [key, value] of Object.entries(requestQuery)) {
|
|
183
|
-
|
|
209
|
+
const transform = {
|
|
184
210
|
type: 'request.query',
|
|
185
211
|
op: 'set',
|
|
186
212
|
target: { key },
|
|
187
213
|
args: value,
|
|
188
|
-
}
|
|
214
|
+
};
|
|
215
|
+
const envVars = extractEnvVars(value, pathParams);
|
|
216
|
+
if (envVars.length > 0) {
|
|
217
|
+
transform.env = envVars;
|
|
218
|
+
}
|
|
219
|
+
transforms.push(transform);
|
|
189
220
|
}
|
|
190
221
|
}
|
|
191
222
|
const route = {
|
|
@@ -226,7 +257,6 @@ class Router {
|
|
|
226
257
|
*/
|
|
227
258
|
redirect(source, destination, optionsOrCallback) {
|
|
228
259
|
this.validateSourcePattern(source);
|
|
229
|
-
(0, validation_1.validateCaptureGroupReferences)(source, destination);
|
|
230
260
|
let options;
|
|
231
261
|
// Handle callback syntax
|
|
232
262
|
if (typeof optionsOrCallback === 'function') {
|
|
@@ -249,13 +279,19 @@ class Router {
|
|
|
249
279
|
if (requestHeaders) {
|
|
250
280
|
// Build a Route object with transforms
|
|
251
281
|
const transforms = [];
|
|
282
|
+
const pathParams = this.extractPathParams(source);
|
|
252
283
|
for (const [key, value] of Object.entries(requestHeaders)) {
|
|
253
|
-
|
|
284
|
+
const transform = {
|
|
254
285
|
type: 'request.headers',
|
|
255
286
|
op: 'set',
|
|
256
287
|
target: { key },
|
|
257
288
|
args: value,
|
|
258
|
-
}
|
|
289
|
+
};
|
|
290
|
+
const envVars = extractEnvVars(value, pathParams);
|
|
291
|
+
if (envVars.length > 0) {
|
|
292
|
+
transform.env = envVars;
|
|
293
|
+
}
|
|
294
|
+
transforms.push(transform);
|
|
259
295
|
}
|
|
260
296
|
const route = {
|
|
261
297
|
src: source,
|
|
@@ -341,6 +377,18 @@ class Router {
|
|
|
341
377
|
*/
|
|
342
378
|
route(config) {
|
|
343
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
|
+
}
|
|
344
392
|
this.routeRules.push(config);
|
|
345
393
|
return this;
|
|
346
394
|
}
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vercel/config",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "A TypeScript SDK for programmatically
|
|
3
|
+
"version": "0.0.19",
|
|
4
|
+
"description": "A TypeScript SDK for programmatically configuring Vercel projects",
|
|
5
5
|
"bugs": {
|
|
6
|
-
"url": "https://github.com/vercel/
|
|
6
|
+
"url": "https://github.com/vercel/config/issues"
|
|
7
7
|
},
|
|
8
8
|
"repository": {
|
|
9
9
|
"type": "git",
|
|
10
|
-
"url": "https://github.com/vercel/
|
|
10
|
+
"url": "https://github.com/vercel/config"
|
|
11
11
|
},
|
|
12
12
|
"author": "Vercel",
|
|
13
13
|
"license": "MIT",
|