@vercel/config 0.0.20 → 0.0.22

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,10 +13,8 @@ npm install @vercel/config
13
13
  Create a `vercel.ts` file in your project root:
14
14
 
15
15
  ```typescript
16
- import { createRouter } from '@vercel/config';
17
- import type { VercelConfig } from '@vercel/config';
18
-
19
- const router = createRouter();
16
+ import { routes } from '@vercel/config/v1';
17
+ import type { VercelConfig } from '@vercel/config/v1';
20
18
 
21
19
  export const config: VercelConfig = {
22
20
  buildCommand: 'npm run build',
@@ -24,10 +22,10 @@ export const config: VercelConfig = {
24
22
 
25
23
  rewrites: [
26
24
  // Simple rewrite
27
- router.rewrite('/api/(.*)', 'https://backend.api.example.com/$1'),
25
+ routes.rewrite('/api/(.*)', 'https://backend.api.example.com/$1'),
28
26
 
29
27
  // Rewrite with transforms
30
- router.rewrite('/users/:userId', 'https://api.example.com/users/$1',
28
+ routes.rewrite('/users/:userId', 'https://api.example.com/users/$1',
31
29
  ({ userId, env }) => ({
32
30
  requestHeaders: {
33
31
  'x-user-id': userId,
@@ -38,11 +36,11 @@ export const config: VercelConfig = {
38
36
  ],
39
37
 
40
38
  redirects: [
41
- router.redirect('/old-docs', '/docs', { permanent: true })
39
+ routes.redirect('/old-docs', '/docs', { permanent: true })
42
40
  ],
43
41
 
44
42
  headers: [
45
- router.cacheControl('/static/(.*)', {
43
+ routes.cacheControl('/static/(.*)', {
46
44
  public: true,
47
45
  maxAge: '1 week',
48
46
  immutable: true
@@ -58,7 +56,7 @@ export const config: VercelConfig = {
58
56
  ## Features
59
57
 
60
58
  - **Type-safe configuration** - Full TypeScript support with IDE autocomplete
61
- - **Readable syntax** - Helper methods like `router.redirect()`, `router.rewrite()`, `router.header()`
59
+ - **Readable syntax** - Helper methods like `routes.redirect()`, `routes.rewrite()`, `routes.header()`
62
60
  - **Transforms** - Modify request/response headers and query parameters on the fly
63
61
  - **Conditions** - Advanced routing with `has` and `missing` conditions
64
62
  - **CLI tools** - `compile` and `validate` commands for development
package/dist/router.d.ts CHANGED
@@ -1,21 +1,35 @@
1
1
  import type { Redirect, Rewrite } from './types';
2
2
  /**
3
- * Helper function to reference a path parameter in transforms.
4
- * Path parameters are extracted from the route pattern (e.g., :userId).
3
+ * Type utility to extract path parameter names from a route pattern string.
4
+ * Supports :paramName syntax used in path-to-regexp patterns.
5
5
  *
6
6
  * @example
7
- * param('userId') // Returns '$userId'
7
+ * ExtractPathParams<'/users/:userId/posts/:postId'> // 'userId' | 'postId'
8
+ * ExtractPathParams<'/api/(.*)'> // never
8
9
  */
9
- export declare function param(name: string): string;
10
+ type ExtractPathParams<T extends string> = T extends `${string}:${infer Param}/${infer Rest}` ? (Param extends `${infer P}(${string}` ? P : Param) | ExtractPathParams<`/${Rest}`> : T extends `${string}:${infer Param}` ? Param extends `${infer P}(${string}` ? P : Param : never;
10
11
  /**
11
- * Helper function to reference a runtime environment variable in transforms.
12
- * These are environment variables that get resolved at request time by Vercel's routing layer,
13
- * not at build time.
12
+ * Creates an object type where keys are the extracted path parameter names
13
+ * and values are strings (the resolved $paramName values).
14
+ */
15
+ type PathParams<T extends string> = {
16
+ [K in ExtractPathParams<T>]: string;
17
+ };
18
+ /**
19
+ * Helper function to reference a Vercel project environment variable.
20
+ * These are placeholders that get resolved at request time by Vercel's routing layer.
21
+ * They are set per-deployment and don't change until you redeploy.
14
22
  *
15
23
  * @example
16
- * runtimeEnv('BEARER_TOKEN') // Returns '$BEARER_TOKEN'
24
+ * // Usage in rewrites with type-safe path params:
25
+ * routes.rewrite('/users/:userId', 'https://api.example.com/$1', ({ userId }) => ({
26
+ * requestHeaders: {
27
+ * 'x-user-id': userId,
28
+ * 'authorization': `Bearer ${deploymentEnv('API_KEY')}`
29
+ * }
30
+ * }))
17
31
  */
18
- export declare function runtimeEnv(name: string): string;
32
+ export declare function deploymentEnv(name: string): string;
19
33
  /**
20
34
  * Template literal type for durations recognized by pretty-cache-header.
21
35
  *
@@ -466,31 +480,10 @@ export interface RouterConfig {
466
480
  * When routes is present, other fields (redirects, headers, rewrites, crons) are excluded.
467
481
  */
468
482
  routes?: Route[];
469
- /**
470
- * When true, Vercel automatically removes file extensions and normalizes
471
- * certain paths, serving HTML and serverless routes extension-free.
472
- */
473
- cleanUrls?: boolean;
474
- /**
475
- * When true, routes are normalized to include a trailing slash.
476
- */
477
- trailingSlash?: boolean;
478
- /**
479
- * Path to a JSON file containing bulk redirect rules.
480
- */
481
- bulkRedirectsPath?: string;
482
483
  /**
483
484
  * Array of cron definitions for scheduled invocations.
484
485
  */
485
486
  crons?: CronRule[];
486
- /**
487
- * Custom build command to run during deployment.
488
- */
489
- buildCommand?: string;
490
- /**
491
- * Custom install command to run during deployment.
492
- */
493
- installCommand?: string;
494
487
  }
495
488
  /**
496
489
  * The main Router class for building a Vercel configuration object in code.
@@ -503,35 +496,6 @@ export declare class Router {
503
496
  private rewriteRules;
504
497
  private routeRules;
505
498
  private cronRules;
506
- private cleanUrlsConfig;
507
- private trailingSlashConfig;
508
- private bulkRedirectsPathConfig;
509
- private buildCommandConfig;
510
- private installCommandConfig;
511
- /**
512
- * Property setter for cleanUrls configuration.
513
- */
514
- set cleanUrls(value: boolean | undefined);
515
- /**
516
- * Property getter for cleanUrls configuration.
517
- */
518
- get cleanUrls(): boolean | undefined;
519
- /**
520
- * Property setter for trailingSlash configuration.
521
- */
522
- set trailingSlash(value: boolean | undefined);
523
- /**
524
- * Property getter for trailingSlash configuration.
525
- */
526
- get trailingSlash(): boolean | undefined;
527
- /**
528
- * Property setter for bulkRedirectsPath configuration.
529
- */
530
- set bulkRedirectsPath(value: string | undefined);
531
- /**
532
- * Property getter for bulkRedirectsPath configuration.
533
- */
534
- get bulkRedirectsPath(): string | undefined;
535
499
  /**
536
500
  * Helper to extract path parameter names from a source pattern.
537
501
  * Path parameters are identified by :paramName syntax.
@@ -539,11 +503,6 @@ export declare class Router {
539
503
  * extractPathParams('/users/:userId/posts/:postId') // Returns ['userId', 'postId']
540
504
  */
541
505
  private extractPathParams;
542
- /**
543
- * Creates a Proxy object that tracks environment variable accesses.
544
- * Returns both the proxy and a set of accessed environment variable names.
545
- */
546
- private createEnvProxy;
547
506
  /**
548
507
  * Creates a rewrite rule. Returns either a Rewrite object (simple case) or Route with transforms.
549
508
  *
@@ -551,27 +510,42 @@ export declare class Router {
551
510
  * // Simple rewrite
552
511
  * router.rewrite('/api/(.*)', 'https://old-on-prem.com/$1')
553
512
  *
554
- * // With transforms
555
- * router.rewrite('/users/:userId', 'https://api.example.com/users/$1', ({userId, env}) => ({
556
- * requestHeaders: { 'x-user-id': userId }
513
+ * // With transforms but no path params
514
+ * router.rewrite('/(.*)', 'https://api.example.com/$1', {
515
+ * requestHeaders: {
516
+ * 'authorization': `Bearer ${deploymentEnv('API_KEY')}`
517
+ * }
518
+ * })
519
+ *
520
+ * // With type-safe path params
521
+ * router.rewrite('/users/:userId', 'https://api.example.com/users/$1', ({ userId }) => ({
522
+ * requestHeaders: {
523
+ * 'x-user-id': userId,
524
+ * 'authorization': `Bearer ${deploymentEnv('API_KEY')}`
525
+ * }
557
526
  * }))
527
+ *
528
+ * // With conditions only
529
+ * router.rewrite('/admin/(.*)', 'https://admin.example.com/$1', {
530
+ * has: [{ type: 'header', key: 'x-admin-token' }]
531
+ * })
558
532
  * @internal Can return Route with transforms internally
559
533
  */
560
- rewrite(source: string, destination: string, optionsOrCallback?: {
534
+ rewrite<T extends string>(source: T, destination: string): Rewrite | Route;
535
+ rewrite<T extends string>(source: T, destination: string, callback: (params: PathParams<T>) => {
561
536
  has?: Condition[];
562
537
  missing?: Condition[];
563
538
  requestHeaders?: Record<string, string | string[]>;
564
539
  responseHeaders?: Record<string, string | string[]>;
565
540
  requestQuery?: Record<string, string | string[]>;
566
- } | ((params: Record<string, string> & {
567
- env: any;
568
- }) => {
541
+ }): Rewrite | Route;
542
+ rewrite<T extends string>(source: T, destination: string, options: ({
569
543
  has?: Condition[];
570
544
  missing?: Condition[];
571
545
  requestHeaders?: Record<string, string | string[]>;
572
546
  responseHeaders?: Record<string, string | string[]>;
573
547
  requestQuery?: Record<string, string | string[]>;
574
- })): Rewrite | Route;
548
+ }) & Record<never, never>): Rewrite | Route;
575
549
  /**
576
550
  * Creates a redirect rule. Returns either a Redirect object (simple case) or Route with transforms.
577
551
  *
@@ -579,28 +553,44 @@ export declare class Router {
579
553
  * // Simple redirect
580
554
  * router.redirect('/old-path', '/new-path', { permanent: true })
581
555
  *
582
- * // With transforms
583
- * router.redirect('/users/:userId', '/new-users/$1', ({userId, env}) => ({
556
+ * // With transforms but no path params
557
+ * router.redirect('/old', '/new', {
584
558
  * permanent: true,
585
- * requestHeaders: { 'x-user-id': userId }
559
+ * requestHeaders: {
560
+ * 'x-api-key': deploymentEnv('API_KEY')
561
+ * }
562
+ * })
563
+ *
564
+ * // With type-safe path params
565
+ * router.redirect('/users/:userId', '/new-users/$1', ({ userId }) => ({
566
+ * permanent: true,
567
+ * requestHeaders: {
568
+ * 'x-user-id': userId,
569
+ * 'x-api-key': deploymentEnv('API_KEY')
570
+ * }
586
571
  * }))
572
+ *
573
+ * // With conditions only
574
+ * router.redirect('/dashboard/(.*)', '/login', {
575
+ * missing: [{ type: 'cookie', key: 'auth-token' }]
576
+ * })
587
577
  * @internal Can return Route with transforms internally
588
578
  */
589
- redirect(source: string, destination: string, optionsOrCallback?: {
579
+ redirect<T extends string>(source: T, destination: string): Redirect | Route;
580
+ redirect<T extends string>(source: T, destination: string, callback: (params: PathParams<T>) => {
590
581
  permanent?: boolean;
591
582
  statusCode?: number;
592
583
  has?: Condition[];
593
584
  missing?: Condition[];
594
585
  requestHeaders?: Record<string, string | string[]>;
595
- } | ((params: Record<string, string> & {
596
- env: any;
597
- }) => {
586
+ }): Redirect | Route;
587
+ redirect<T extends string>(source: T, destination: string, options: {
598
588
  permanent?: boolean;
599
589
  statusCode?: number;
600
590
  has?: Condition[];
601
591
  missing?: Condition[];
602
592
  requestHeaders?: Record<string, string | string[]>;
603
- })): Redirect | Route;
593
+ }): Redirect | Route;
604
594
  /**
605
595
  * Creates a header rule matching the vercel.json schema.
606
596
  * @example
@@ -661,27 +651,6 @@ export declare class Router {
661
651
  * });
662
652
  */
663
653
  route(config: Route): this;
664
- /**
665
- * When true, automatically serve HTML files and serverless functions
666
- * without the .html or .js extension. This is a built-in Vercel feature.
667
- */
668
- setCleanUrls(value: boolean): this;
669
- /**
670
- * When true, automatically normalize paths to include a trailing slash.
671
- */
672
- setTrailingSlash(value: boolean): this;
673
- /**
674
- * Sets a custom build command to run during deployment.
675
- * @example
676
- * router.setBuildCommand('pnpm run generate-config')
677
- */
678
- setBuildCommand(value: string): this;
679
- /**
680
- * Sets a custom install command to run during deployment.
681
- * @example
682
- * router.setInstallCommand('pnpm install --no-frozen-lockfile')
683
- */
684
- setInstallCommand(value: string): this;
685
654
  /**
686
655
  * Adds a single cron rule (synchronous).
687
656
  */
@@ -707,7 +676,15 @@ export declare class Router {
707
676
  /**
708
677
  * A simple factory function for creating a new Router instance.
709
678
  * @example
710
- * import { createRouter } from '@vercel/router-sdk';
711
- * const router = createRouter();
679
+ * import { createRoutes } from '@vercel/router-sdk';
680
+ * const routes = createRoutes();
681
+ */
682
+ export declare function createRoutes(): Router;
683
+ /**
684
+ * Default singleton router instance for convenience.
685
+ * @example
686
+ * import { routes } from '@vercel/router-sdk';
687
+ * routes.redirect('/old', '/new');
712
688
  */
713
- export declare function createRouter(): Router;
689
+ export declare const routes: Router;
690
+ export {};
package/dist/router.js CHANGED
@@ -1,31 +1,26 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createRouter = exports.Router = exports.runtimeEnv = exports.param = void 0;
3
+ exports.routes = exports.createRoutes = exports.Router = exports.deploymentEnv = void 0;
4
4
  const pretty_cache_header_1 = require("pretty-cache-header");
5
5
  const validation_1 = require("./utils/validation");
6
6
  /**
7
- * Helper function to reference a path parameter in transforms.
8
- * Path parameters are extracted from the route pattern (e.g., :userId).
7
+ * Helper function to reference a Vercel project environment variable.
8
+ * These are placeholders that get resolved at request time by Vercel's routing layer.
9
+ * They are set per-deployment and don't change until you redeploy.
9
10
  *
10
11
  * @example
11
- * param('userId') // Returns '$userId'
12
+ * // Usage in rewrites with type-safe path params:
13
+ * routes.rewrite('/users/:userId', 'https://api.example.com/$1', ({ userId }) => ({
14
+ * requestHeaders: {
15
+ * 'x-user-id': userId,
16
+ * 'authorization': `Bearer ${deploymentEnv('API_KEY')}`
17
+ * }
18
+ * }))
12
19
  */
13
- function param(name) {
20
+ function deploymentEnv(name) {
14
21
  return `$${name}`;
15
22
  }
16
- exports.param = param;
17
- /**
18
- * Helper function to reference a runtime environment variable in transforms.
19
- * These are environment variables that get resolved at request time by Vercel's routing layer,
20
- * not at build time.
21
- *
22
- * @example
23
- * runtimeEnv('BEARER_TOKEN') // Returns '$BEARER_TOKEN'
24
- */
25
- function runtimeEnv(name) {
26
- return `$${name}`;
27
- }
28
- exports.runtimeEnv = runtimeEnv;
23
+ exports.deploymentEnv = deploymentEnv;
29
24
  /**
30
25
  * Extract environment variable names from a string or array of strings
31
26
  * Returns env var names without the $ prefix, excluding path parameters
@@ -62,47 +57,6 @@ class Router {
62
57
  this.rewriteRules = [];
63
58
  this.routeRules = [];
64
59
  this.cronRules = [];
65
- this.cleanUrlsConfig = undefined;
66
- this.trailingSlashConfig = undefined;
67
- this.bulkRedirectsPathConfig = undefined;
68
- this.buildCommandConfig = undefined;
69
- this.installCommandConfig = undefined;
70
- }
71
- /**
72
- * Property setter for cleanUrls configuration.
73
- */
74
- set cleanUrls(value) {
75
- this.cleanUrlsConfig = value;
76
- }
77
- /**
78
- * Property getter for cleanUrls configuration.
79
- */
80
- get cleanUrls() {
81
- return this.cleanUrlsConfig;
82
- }
83
- /**
84
- * Property setter for trailingSlash configuration.
85
- */
86
- set trailingSlash(value) {
87
- this.trailingSlashConfig = value;
88
- }
89
- /**
90
- * Property getter for trailingSlash configuration.
91
- */
92
- get trailingSlash() {
93
- return this.trailingSlashConfig;
94
- }
95
- /**
96
- * Property setter for bulkRedirectsPath configuration.
97
- */
98
- set bulkRedirectsPath(value) {
99
- this.bulkRedirectsPathConfig = value;
100
- }
101
- /**
102
- * Property getter for bulkRedirectsPath configuration.
103
- */
104
- get bulkRedirectsPath() {
105
- return this.bulkRedirectsPathConfig;
106
60
  }
107
61
  /**
108
62
  * Helper to extract path parameter names from a source pattern.
@@ -118,50 +72,15 @@ class Router {
118
72
  }
119
73
  return params;
120
74
  }
121
- /**
122
- * Creates a Proxy object that tracks environment variable accesses.
123
- * Returns both the proxy and a set of accessed environment variable names.
124
- */
125
- createEnvProxy() {
126
- const accessedVars = new Set();
127
- const proxy = new Proxy({}, {
128
- get(_target, prop) {
129
- if (typeof prop === 'string') {
130
- accessedVars.add(prop);
131
- return `$${prop}`;
132
- }
133
- return undefined;
134
- }
135
- });
136
- return { proxy, accessedVars };
137
- }
138
- /**
139
- * Creates a rewrite rule. Returns either a Rewrite object (simple case) or Route with transforms.
140
- *
141
- * @example
142
- * // Simple rewrite
143
- * router.rewrite('/api/(.*)', 'https://old-on-prem.com/$1')
144
- *
145
- * // With transforms
146
- * router.rewrite('/users/:userId', 'https://api.example.com/users/$1', ({userId, env}) => ({
147
- * requestHeaders: { 'x-user-id': userId }
148
- * }))
149
- * @internal Can return Route with transforms internally
150
- */
151
75
  rewrite(source, destination, optionsOrCallback) {
152
76
  this.validateSourcePattern(source);
153
77
  let options;
154
- // Handle callback syntax
155
78
  if (typeof optionsOrCallback === 'function') {
156
79
  const pathParams = this.extractPathParams(source);
157
- const { proxy: envProxy } = this.createEnvProxy();
158
- // Create params object with path parameters as $paramName
159
80
  const paramsObj = {};
160
81
  for (const param of pathParams) {
161
82
  paramsObj[param] = `$${param}`;
162
83
  }
163
- paramsObj.env = envProxy;
164
- // Call the callback to get options
165
84
  options = optionsOrCallback(paramsObj);
166
85
  }
167
86
  else {
@@ -241,34 +160,15 @@ class Router {
241
160
  rewrite.missing = missing;
242
161
  return rewrite;
243
162
  }
244
- /**
245
- * Creates a redirect rule. Returns either a Redirect object (simple case) or Route with transforms.
246
- *
247
- * @example
248
- * // Simple redirect
249
- * router.redirect('/old-path', '/new-path', { permanent: true })
250
- *
251
- * // With transforms
252
- * router.redirect('/users/:userId', '/new-users/$1', ({userId, env}) => ({
253
- * permanent: true,
254
- * requestHeaders: { 'x-user-id': userId }
255
- * }))
256
- * @internal Can return Route with transforms internally
257
- */
258
163
  redirect(source, destination, optionsOrCallback) {
259
164
  this.validateSourcePattern(source);
260
165
  let options;
261
- // Handle callback syntax
262
166
  if (typeof optionsOrCallback === 'function') {
263
167
  const pathParams = this.extractPathParams(source);
264
- const { proxy: envProxy } = this.createEnvProxy();
265
- // Create params object with path parameters as $paramName
266
168
  const paramsObj = {};
267
169
  for (const param of pathParams) {
268
170
  paramsObj[param] = `$${param}`;
269
171
  }
270
- paramsObj.env = envProxy;
271
- // Call the callback to get options
272
172
  options = optionsOrCallback(paramsObj);
273
173
  }
274
174
  else {
@@ -392,39 +292,6 @@ class Router {
392
292
  this.routeRules.push(config);
393
293
  return this;
394
294
  }
395
- /**
396
- * When true, automatically serve HTML files and serverless functions
397
- * without the .html or .js extension. This is a built-in Vercel feature.
398
- */
399
- setCleanUrls(value) {
400
- this.cleanUrlsConfig = value;
401
- return this;
402
- }
403
- /**
404
- * When true, automatically normalize paths to include a trailing slash.
405
- */
406
- setTrailingSlash(value) {
407
- this.trailingSlashConfig = value;
408
- return this;
409
- }
410
- /**
411
- * Sets a custom build command to run during deployment.
412
- * @example
413
- * router.setBuildCommand('pnpm run generate-config')
414
- */
415
- setBuildCommand(value) {
416
- this.buildCommandConfig = value;
417
- return this;
418
- }
419
- /**
420
- * Sets a custom install command to run during deployment.
421
- * @example
422
- * router.setInstallCommand('pnpm install --no-frozen-lockfile')
423
- */
424
- setInstallCommand(value) {
425
- this.installCommandConfig = value;
426
- return this;
427
- }
428
295
  /**
429
296
  * Adds a single cron rule (synchronous).
430
297
  */
@@ -532,16 +399,6 @@ class Router {
532
399
  };
533
400
  // NOTE: crons are now handled via export const crons in vercel.ts
534
401
  // They are no longer included in router.getConfig()
535
- // Only include optional fields if they're explicitly set
536
- if (this.bulkRedirectsPathConfig !== undefined) {
537
- config.bulkRedirectsPath = this.bulkRedirectsPathConfig;
538
- }
539
- if (this.buildCommandConfig !== undefined) {
540
- config.buildCommand = this.buildCommandConfig;
541
- }
542
- if (this.installCommandConfig !== undefined) {
543
- config.installCommand = this.installCommandConfig;
544
- }
545
402
  return config;
546
403
  }
547
404
  // Otherwise, return the legacy format
@@ -549,20 +406,8 @@ class Router {
549
406
  redirects: this.redirectRules,
550
407
  headers: this.headerRules,
551
408
  rewrites: legacyRewrites,
552
- cleanUrls: this.cleanUrlsConfig,
553
- trailingSlash: this.trailingSlashConfig,
554
409
  // NOTE: crons are now handled via export const crons in vercel.ts
555
410
  };
556
- // Only include optional fields if they're explicitly set
557
- if (this.bulkRedirectsPathConfig !== undefined) {
558
- config.bulkRedirectsPath = this.bulkRedirectsPathConfig;
559
- }
560
- if (this.buildCommandConfig !== undefined) {
561
- config.buildCommand = this.buildCommandConfig;
562
- }
563
- if (this.installCommandConfig !== undefined) {
564
- config.installCommand = this.installCommandConfig;
565
- }
566
411
  return config;
567
412
  }
568
413
  /**
@@ -633,10 +478,17 @@ exports.Router = Router;
633
478
  /**
634
479
  * A simple factory function for creating a new Router instance.
635
480
  * @example
636
- * import { createRouter } from '@vercel/router-sdk';
637
- * const router = createRouter();
481
+ * import { createRoutes } from '@vercel/router-sdk';
482
+ * const routes = createRoutes();
638
483
  */
639
- function createRouter() {
484
+ function createRoutes() {
640
485
  return new Router();
641
486
  }
642
- exports.createRouter = createRouter;
487
+ exports.createRoutes = createRoutes;
488
+ /**
489
+ * Default singleton router instance for convenience.
490
+ * @example
491
+ * import { routes } from '@vercel/router-sdk';
492
+ * routes.redirect('/old', '/new');
493
+ */
494
+ exports.routes = new Router();
package/dist/types.d.ts CHANGED
@@ -3,75 +3,123 @@
3
3
  * https://openapi.vercel.sh/vercel.json
4
4
  */
5
5
  export type Framework = 'blitzjs' | 'nextjs' | 'gatsby' | 'remix' | 'react-router' | 'astro' | 'hexo' | 'eleventy' | 'docusaurus-2' | 'docusaurus' | 'preact' | 'solidstart-1' | 'solidstart' | 'dojo' | 'ember' | 'vue' | 'scully' | 'ionic-angular' | 'angular' | 'polymer' | 'svelte' | 'sveltekit' | 'sveltekit-1' | 'ionic-react' | 'create-react-app' | 'gridsome' | 'umijs' | 'sapper' | 'saber' | 'stencil' | 'nuxtjs' | 'redwoodjs' | 'hugo' | 'jekyll' | 'brunch' | 'middleman' | 'zola' | 'hydrogen' | 'vite' | 'tanstack-start' | 'vitepress' | 'vuepress' | 'parcel' | 'fastapi' | 'flask' | 'fasthtml' | 'sanity-v3' | 'sanity' | 'storybook' | 'nitro' | 'hono' | 'express' | 'h3' | 'nestjs' | 'elysia' | 'fastify' | 'xmcp' | null;
6
- export interface CronJob {
7
- schedule: string;
8
- path: string;
9
- }
10
6
  export interface FunctionConfig {
7
+ /**
8
+ * A glob pattern to match files that should be excluded from your Serverless Function. If you’re using a Community Runtime, the behavior might vary.
9
+ */
11
10
  excludeFiles?: string;
11
+ /**
12
+ * A glob pattern to match files that should be included in your Serverless Function. If you’re using a Community Runtime, the behavior might vary.
13
+ */
12
14
  includeFiles?: string;
15
+ /**
16
+ * An integer defining how long your Serverless Function should be allowed to run on every request in seconds (between 1 and the maximum limit of your plan).
17
+ */
13
18
  maxDuration?: number;
19
+ /**
20
+ * An integer defining the memory your Serverless Function should be provided with (between 128 and 10240).
21
+ */
14
22
  memory?: number;
23
+ /**
24
+ * The npm package name of a Runtime, including its version
25
+ */
15
26
  runtime?: string;
27
+ /**
28
+ * A boolean that defines whether the Function supports cancellation (default: false)
29
+ */
16
30
  supportsCancellation?: boolean;
17
- experimentalTriggers?: Array<{
18
- type: 'queue/v1beta';
31
+ /**
32
+ * An array of experimental triggers for this Serverless Function. Currently only supports queue triggers.
33
+ */
34
+ experimentalTriggers?: {
35
+ /**
36
+ * Event type pattern this trigger handles
37
+ */
38
+ type: string;
39
+ /**
40
+ * Name of the queue topic to consume from
41
+ */
19
42
  topic: string;
43
+ /**
44
+ * Name of the consumer group for this trigger
45
+ */
20
46
  consumer: string;
47
+ /**
48
+ * Maximum number of delivery attempts
49
+ */
21
50
  maxDeliveries?: number;
51
+ /**
52
+ * Delay in seconds before retrying failed executions
53
+ */
22
54
  retryAfterSeconds?: number;
55
+ /**
56
+ * Initial delay in seconds before first execution attempt
57
+ */
23
58
  initialDelaySeconds?: number;
24
- }>;
59
+ }[];
60
+ }
61
+ export interface CronJob {
62
+ schedule: string;
63
+ path: string;
25
64
  }
26
65
  export interface GitDeploymentConfig {
27
66
  [branch: string]: boolean;
28
67
  }
29
68
  export interface GitConfig {
69
+ /**
70
+ * Specifies the branches that will not trigger an auto-deployment when committing to them. Any non specified branch is `true` by default.
71
+ */
30
72
  deploymentEnabled?: boolean | GitDeploymentConfig;
31
73
  /**
74
+ * If specified, the git repository will be exclusive to the specificed Team IDs. Teams that are not specified in the list will not be able to link new projects or create new deployments.
32
75
  * @private
33
76
  */
34
77
  exclusivity?: {
78
+ /**
79
+ * A list of allowed Team IDs.
80
+ */
35
81
  teams?: string[];
36
82
  };
37
83
  }
38
84
  export interface GithubConfig {
39
- enabled?: boolean;
85
+ /**
86
+ * When set to `false`, Vercel for GitHub will not deploy the given project regardless of the GitHub app being installed.
87
+ */
40
88
  autoAlias?: boolean;
89
+ /**
90
+ * When set to `false`, Vercel for GitHub will always build pushes in sequence without cancelling a build for the most recent commit.
91
+ */
41
92
  autoJobCancelation?: boolean;
42
93
  /**
94
+ * When set to false, Vercel for GitHub will not apply the alias upon merge.
95
+ */
96
+ enabled?: boolean;
97
+ /**
98
+ * [deprecated] Please use the Project Settings in the dashboard instead: https://vercel.link/46vERTS When set to `true`, Vercel for GitHub will stop commenting on pull requests and commits.
43
99
  * @deprecated
44
100
  */
45
101
  silent?: boolean;
46
102
  }
47
103
  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
104
  contentDispositionType?: 'inline' | 'attachment';
55
- qualities?: number[];
56
- localPatterns?: Array<{
105
+ contentSecurityPolicy?: string;
106
+ dangerouslyAllowSVG?: boolean;
107
+ domains?: string[];
108
+ formats?: 'image/avif' | 'image/webp' | 'image/jpeg' | 'image/png'[];
109
+ localPatterns?: {
57
110
  pathname?: string;
58
111
  search?: string;
59
- }>;
60
- remotePatterns?: Array<{
112
+ }[];
113
+ minimumCacheTTL?: number;
114
+ qualities?: number[];
115
+ remotePatterns?: {
61
116
  protocol?: 'http' | 'https';
62
117
  hostname: string;
63
118
  port?: string;
64
119
  pathname?: string;
65
120
  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;
121
+ }[];
122
+ sizes: number[];
75
123
  }
76
124
  /**
77
125
  * HTTP header key/value pair
@@ -101,7 +149,7 @@ export interface Condition {
101
149
  }
102
150
  /**
103
151
  * Redirect matching vercel.json schema
104
- * Returned by router.redirect()
152
+ * Returned by routes.redirect()
105
153
  */
106
154
  export interface Redirect {
107
155
  source: string;
@@ -113,7 +161,7 @@ export interface Redirect {
113
161
  }
114
162
  /**
115
163
  * Rewrite matching vercel.json schema
116
- * Returned by router.rewrite()
164
+ * Returned by routes.rewrite()
117
165
  */
118
166
  export interface Rewrite {
119
167
  source: string;
@@ -123,7 +171,7 @@ export interface Rewrite {
123
171
  }
124
172
  /**
125
173
  * Header rule matching vercel.json schema
126
- * Returned by router.header() and router.cacheControl()
174
+ * Returned by routes.header() and routes.cacheControl()
127
175
  */
128
176
  export interface HeaderRule {
129
177
  source: string;
@@ -145,154 +193,133 @@ export interface BuildConfig {
145
193
  env?: Record<string, string>;
146
194
  }
147
195
  export interface BuildItem {
196
+ config?: Record<string, any>;
148
197
  src?: string;
149
198
  use: string;
150
- config?: Record<string, any>;
151
199
  }
152
200
  export interface VercelConfig {
153
201
  /**
154
- * JSON schema URL for editor completions and validation.
155
- */
156
- $schema?: string;
157
- /**
158
- * Aliases that will get assigned when the deployment is `READY` and the target is `production`.
202
+ * Aliases that will get assigned when the deployment is `READY` and the target is `production`. The client needs to make a `GET` request to its API to ensure the assignment
159
203
  */
160
204
  alias?: string | string[];
161
205
  /**
162
- * Build configuration (deprecated).
206
+ * An object containing another object with information to be passed to the Build Process
163
207
  * @deprecated
164
208
  */
165
209
  build?: BuildConfig;
166
210
  /**
167
- * Build descriptions (deprecated).
211
+ * A list of build descriptions whose src references valid source files.
168
212
  * @deprecated
169
213
  */
170
214
  builds?: BuildItem[];
171
215
  /**
172
- * Path to a JSON file containing bulk redirect rules.
173
- */
174
- bulkRedirectsPath?: string;
175
- /**
176
- * When set to `true`, all HTML files and Serverless Functions will have their extension removed.
216
+ * When set to `true`, all HTML files and Serverless Functions will have their extension removed. When visiting a path that ends with the extension, a 308 response will redirect the client to the extensionless path.
177
217
  */
178
218
  cleanUrls?: boolean;
179
219
  /**
180
- * An array of cron jobs that should be created for production Deployments.
181
- */
182
- crons?: CronJob[];
183
- /**
184
- * An object containing the deployment's environment variables.
220
+ * An object containing the deployment's environment variable names and values. Secrets can be referenced by prefixing the value with `@`
221
+ * @deprecated
185
222
  */
186
223
  env?: Record<string, string>;
187
224
  /**
188
- * An array of the passive regions the deployment's Serverless Functions should be deployed to.
225
+ * An array of the passive regions the deployment's Serverless Functions should be deployed to that can be failed over to during a lambda outage
189
226
  */
190
227
  passiveRegions?: string[];
191
228
  /**
192
- * Same as passiveRegions. An array of passive regions for failover.
229
+ * Same as passiveRegions. An array of the passive regions the deployment's Serverless Functions should be deployed to so we can failover to these regions on lambda outages
193
230
  */
194
231
  functionFailoverRegions?: string[];
195
232
  /**
196
- * An object describing custom options for Serverless Functions.
233
+ * An object describing custom options for your Serverless Functions. Each key must be glob pattern that matches the paths of the Serverless Functions you would like to customize (like `api/*.js` or `api/test.js`).
197
234
  */
198
235
  functions?: Record<string, FunctionConfig>;
199
- /**
200
- * Git-related configuration.
201
- */
202
236
  git?: GitConfig;
203
237
  /**
204
- * GitHub-related configuration.
238
+ * @private
205
239
  */
206
240
  github?: GithubConfig;
207
241
  /**
208
- * HTTP headers configuration.
209
- * Can use router.header() and router.cacheControl() helpers.
242
+ * A list of header definitions.
210
243
  */
211
244
  headers?: RouteType[];
212
- /**
213
- * Image optimization configuration.
214
- */
215
245
  images?: ImageConfig;
216
246
  /**
217
- * A name for the deployment.
247
+ * A name for the deployment
218
248
  */
219
249
  name?: string;
220
250
  /**
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.
251
+ * Whether a deployment's source and logs are available publicly
226
252
  */
227
253
  public?: boolean;
228
254
  /**
229
- * HTTP redirects configuration.
230
- * Can use router.redirect() helper.
255
+ * A list of redirect definitions.
231
256
  */
232
257
  redirects?: RouteType[];
233
258
  /**
234
- * An array of regions where the deployment's Serverless Functions and Edge Functions should be deployed to.
259
+ * The path to a file containing bulk redirects; supports JSON, JSONL, and CSV
260
+ */
261
+ bulkRedirectsPath?: string | null;
262
+ /**
263
+ * An array of the regions the deployment's Serverless Functions should be deployed to
235
264
  */
236
265
  regions?: string[];
237
266
  /**
238
- * HTTP rewrites configuration.
239
- * Can use router.rewrite() helper.
267
+ * A list of rewrite definitions.
240
268
  */
241
269
  rewrites?: RouteType[];
242
270
  /**
243
- * Routes configuration using the lower-level routes primitive.
244
- * Use this if you need transforms or want everything in one place.
245
- * Cannot be mixed with headers, redirects, or rewrites.
271
+ * A list of routes objects used to rewrite paths to point towards other internal or external paths
272
+ * @deprecated
246
273
  */
247
274
  routes?: RouteType[];
248
275
  /**
249
- * Scope (user or team) for deployment.
276
+ * This property determines the scope (user or team) under which the project will be deployed by Vercel CLI.
250
277
  * @private
251
278
  */
252
279
  scope?: string;
253
280
  /**
254
- * Wildcard domain configuration.
281
+ * When `false`, visiting a path that ends with a forward slash will respond with a `308` status code and redirect to the path without the trailing slash.
255
282
  */
256
- wildcard?: WildcardDomain[];
283
+ trailingSlash?: boolean;
257
284
  /**
258
- * Version of the configuration schema.
259
285
  * @private
260
286
  */
261
287
  version?: number;
262
288
  /**
263
- * The build command for this project. When `null`, automatically detected.
289
+ * @private
264
290
  */
265
- buildCommand?: string | null;
291
+ wildcard?: WildcardDomain[];
266
292
  /**
267
- * The ignore command for this project.
293
+ * The build command for this project. When `null` is used this value will be automatically detected
268
294
  */
295
+ buildCommand?: string | null;
269
296
  ignoreCommand?: string | null;
270
297
  /**
271
- * The dev command for this project. When `null`, automatically detected.
298
+ * The dev command for this project. When `null` is used this value will be automatically detected
272
299
  */
273
300
  devCommand?: string | null;
274
301
  /**
275
- * The framework being used. When `null`, no framework is selected.
302
+ * The framework that is being used for this project. When `null` is used no framework is selected
276
303
  */
277
304
  framework?: Framework;
278
305
  /**
279
- * The install command for this project. When `null`, automatically detected.
306
+ * The install command for this project. When `null` is used this value will be automatically detected
280
307
  */
281
308
  installCommand?: string | null;
282
309
  /**
283
- * The output directory of the project. When `null`, automatically detected.
310
+ * The output directory of the project. When `null` is used this value will be automatically detected
284
311
  */
285
312
  outputDirectory?: string | null;
286
313
  /**
287
- * When `false`, visiting a path that ends with a forward slash will redirect to the path without the trailing slash.
314
+ * An array of cron jobs that should be created for production Deployments.
288
315
  */
289
- trailingSlash?: boolean;
316
+ crons?: CronJob[];
290
317
  /**
291
318
  * An array of projectIds to associate with the current project.
292
319
  */
293
320
  relatedProjects?: string[];
294
321
  /**
295
- * Enables Fluid compute for the project.
322
+ * Enables Fluid compute for the project. It's enabled by default for new projects.
296
323
  */
297
324
  fluid?: boolean;
298
325
  /**
@@ -1,4 +1,4 @@
1
- export { createRouter, Router } from "../router";
1
+ export { createRoutes, routes, Router } from "../router";
2
2
  export * from "../router";
3
3
  export { VercelConfig } from "../types";
4
4
  export type { Redirect, Rewrite, HeaderRule, Condition, RouteType } from "../types";
package/dist/v1/index.js CHANGED
@@ -14,9 +14,10 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.validateStaticFields = exports.validateStaticStringArray = exports.validateStaticObject = exports.validateStaticBoolean = exports.validateStaticString = exports.VercelConfig = exports.Router = exports.createRouter = void 0;
17
+ exports.validateStaticFields = exports.validateStaticStringArray = exports.validateStaticObject = exports.validateStaticBoolean = exports.validateStaticString = exports.VercelConfig = exports.Router = exports.routes = exports.createRoutes = void 0;
18
18
  var router_1 = require("../router");
19
- Object.defineProperty(exports, "createRouter", { enumerable: true, get: function () { return router_1.createRouter; } });
19
+ Object.defineProperty(exports, "createRoutes", { enumerable: true, get: function () { return router_1.createRoutes; } });
20
+ Object.defineProperty(exports, "routes", { enumerable: true, get: function () { return router_1.routes; } });
20
21
  Object.defineProperty(exports, "Router", { enumerable: true, get: function () { return router_1.Router; } });
21
22
  __exportStar(require("../router"), exports);
22
23
  var types_1 = require("../types");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vercel/config",
3
- "version": "0.0.20",
3
+ "version": "0.0.22",
4
4
  "description": "A TypeScript SDK for programmatically configuring Vercel projects",
5
5
  "bugs": {
6
6
  "url": "https://github.com/vercel/config/issues"
@@ -40,6 +40,7 @@
40
40
  "@typescript-eslint/parser": "^5.0.0",
41
41
  "eslint": "^8.0.0",
42
42
  "prettier": "^2.8.0",
43
+ "tsx": "^4.7.0",
43
44
  "typescript": "^4.9.0",
44
45
  "vitest": "^1.0.0"
45
46
  },
@@ -49,6 +50,7 @@
49
50
  "scripts": {
50
51
  "build": "tsc",
51
52
  "format": "prettier --write \"src/**/*.ts\"",
53
+ "generate-types": "tsx scripts/generate-types.ts",
52
54
  "lint": "eslint . --ext .ts",
53
55
  "release": "npm run build && changeset publish",
54
56
  "test": "vitest",