@vercel/config 0.0.22 → 0.0.23

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/README.md CHANGED
@@ -13,7 +13,7 @@ npm install @vercel/config
13
13
  Create a `vercel.ts` file in your project root:
14
14
 
15
15
  ```typescript
16
- import { routes } from '@vercel/config/v1';
16
+ import { routes, deploymentEnv } from '@vercel/config/v1';
17
17
  import type { VercelConfig } from '@vercel/config/v1';
18
18
 
19
19
  export const config: VercelConfig = {
@@ -24,12 +24,20 @@ export const config: VercelConfig = {
24
24
  // Simple rewrite
25
25
  routes.rewrite('/api/(.*)', 'https://backend.api.example.com/$1'),
26
26
 
27
- // Rewrite with transforms
28
- routes.rewrite('/users/:userId', 'https://api.example.com/users/$1',
29
- ({ userId, env }) => ({
27
+ // Rewrite with transforms (no path params)
28
+ routes.rewrite('/(.*)', 'https://api.example.com/$1', {
29
+ requestHeaders: {
30
+ 'authorization': `Bearer ${deploymentEnv('API_TOKEN')}`
31
+ }
32
+ }),
33
+
34
+ // Type-safe path parameters with callback
35
+ routes.rewrite('/users/:userId/posts/:postId', 'https://api.example.com/users/$1/posts/$2',
36
+ ({ userId, postId }) => ({
30
37
  requestHeaders: {
31
38
  'x-user-id': userId,
32
- 'authorization': `Bearer ${env.API_TOKEN}`
39
+ 'x-post-id': postId,
40
+ 'authorization': `Bearer ${deploymentEnv('API_KEY')}`
33
41
  }
34
42
  })
35
43
  )
@@ -56,6 +64,8 @@ export const config: VercelConfig = {
56
64
  ## Features
57
65
 
58
66
  - **Type-safe configuration** - Full TypeScript support with IDE autocomplete
67
+ - **Type-safe path parameters** - Extract `:userId` from patterns with full IntelliSense
68
+ - **Deployment environment variables** - Use `deploymentEnv()` for Vercel project env vars
59
69
  - **Readable syntax** - Helper methods like `routes.redirect()`, `routes.rewrite()`, `routes.header()`
60
70
  - **Transforms** - Modify request/response headers and query parameters on the fly
61
71
  - **Conditions** - Advanced routing with `has` and `missing` conditions
package/dist/router.d.ts CHANGED
@@ -278,6 +278,8 @@ export interface Route {
278
278
  status?: number;
279
279
  /** Headers to set (alternative to using transforms) */
280
280
  headers?: Record<string, string>;
281
+ /** Environment variables referenced in dest or transforms */
282
+ env?: string[];
281
283
  }
282
284
  /**
283
285
  * Represents a single HTTP header key/value pair.
package/dist/router.js CHANGED
@@ -143,13 +143,34 @@ class Router {
143
143
  dest: destination,
144
144
  transforms,
145
145
  };
146
+ if (has)
147
+ route.has = has;
148
+ if (missing)
149
+ route.missing = missing;
150
+ // Extract env vars from destination
151
+ const destEnvVars = extractEnvVars(destination, pathParams);
152
+ if (destEnvVars.length > 0) {
153
+ route.env = destEnvVars;
154
+ }
155
+ return route;
156
+ }
157
+ // Simple rewrite without transforms - check if destination has env vars
158
+ const pathParams = this.extractPathParams(source);
159
+ const destEnvVars = extractEnvVars(destination, pathParams);
160
+ if (destEnvVars.length > 0) {
161
+ // Need Route format to include env field
162
+ const route = {
163
+ src: source,
164
+ dest: destination,
165
+ env: destEnvVars,
166
+ };
146
167
  if (has)
147
168
  route.has = has;
148
169
  if (missing)
149
170
  route.missing = missing;
150
171
  return route;
151
172
  }
152
- // Simple rewrite without transforms
173
+ // Simple rewrite without transforms or env vars
153
174
  const rewrite = {
154
175
  source,
155
176
  destination,
@@ -200,13 +221,36 @@ class Router {
200
221
  status: statusCode || (permanent ? 308 : 307),
201
222
  transforms,
202
223
  };
224
+ if (has)
225
+ route.has = has;
226
+ if (missing)
227
+ route.missing = missing;
228
+ // Extract env vars from destination
229
+ const destEnvVars = extractEnvVars(destination, pathParams);
230
+ if (destEnvVars.length > 0) {
231
+ route.env = destEnvVars;
232
+ }
233
+ return route;
234
+ }
235
+ // Simple redirect without transforms - check if destination has env vars
236
+ const pathParams = this.extractPathParams(source);
237
+ const destEnvVars = extractEnvVars(destination, pathParams);
238
+ if (destEnvVars.length > 0) {
239
+ // Need Route format to include env field
240
+ const route = {
241
+ src: source,
242
+ dest: destination,
243
+ redirect: true,
244
+ status: statusCode || (permanent ? 308 : 307),
245
+ env: destEnvVars,
246
+ };
203
247
  if (has)
204
248
  route.has = has;
205
249
  if (missing)
206
250
  route.missing = missing;
207
251
  return route;
208
252
  }
209
- // Simple redirect without transforms
253
+ // Simple redirect without transforms or env vars
210
254
  const redirect = {
211
255
  source,
212
256
  destination,
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Type declarations for @vercel/config
3
+ *
4
+ * Usage:
5
+ * /// <reference types="@vercel/config/v1/types" />
6
+ */
7
+ export type { VercelConfig, Framework, FunctionConfig, CronJob, GitDeploymentConfig, GitConfig, GithubConfig, ImageConfig, Header, Condition, Redirect, Rewrite, HeaderRule, RouteType, WildcardDomain, BuildConfig, BuildItem } from "../types";
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ /**
3
+ * Type declarations for @vercel/config
4
+ *
5
+ * Usage:
6
+ * /// <reference types="@vercel/config/v1/types" />
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vercel/config",
3
- "version": "0.0.22",
3
+ "version": "0.0.23",
4
4
  "description": "A TypeScript SDK for programmatically configuring Vercel projects",
5
5
  "bugs": {
6
6
  "url": "https://github.com/vercel/config/issues"
@@ -17,11 +17,17 @@
17
17
  "*": {
18
18
  "v1": [
19
19
  "dist/v1/index.d.ts"
20
+ ],
21
+ "v1/types": [
22
+ "dist/v1/types.d.ts"
20
23
  ]
21
24
  }
22
25
  },
23
26
  "exports": {
24
- "./v1": "./dist/v1/index.js"
27
+ "./v1": "./dist/v1/index.js",
28
+ "./v1/types": {
29
+ "types": "./dist/v1/types.d.ts"
30
+ }
25
31
  },
26
32
  "bin": {
27
33
  "@vercel/config": "./dist/cli.js"