@vercel/config 0.0.16 → 0.0.18
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 +21 -44
- package/dist/router.d.ts +0 -6
- package/dist/router.js +0 -10
- package/dist/types.d.ts +4 -0
- package/dist/types.js +5 -0
- package/dist/v1/index.d.ts +3 -7
- package/dist/v1/index.js +9 -7
- package/package.json +9 -13
- package/dist/index.d.ts +0 -4
- package/dist/index.js +0 -27
package/README.md
CHANGED
|
@@ -13,7 +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
|
|
16
|
+
import { createRouter } from '@vercel/config';
|
|
17
|
+
import type { VercelConfig } from '@vercel/config';
|
|
17
18
|
|
|
18
19
|
const router = createRouter();
|
|
19
20
|
|
|
@@ -21,15 +22,11 @@ export const config: VercelConfig = {
|
|
|
21
22
|
buildCommand: 'npm run build',
|
|
22
23
|
framework: 'nextjs',
|
|
23
24
|
|
|
24
|
-
|
|
25
|
-
//
|
|
26
|
-
router.
|
|
27
|
-
public: true,
|
|
28
|
-
maxAge: '1 week',
|
|
29
|
-
immutable: true
|
|
30
|
-
}),
|
|
25
|
+
rewrites: [
|
|
26
|
+
// Simple rewrite
|
|
27
|
+
router.rewrite('/api/(.*)', 'https://backend.api.example.com/$1'),
|
|
31
28
|
|
|
32
|
-
//
|
|
29
|
+
// Rewrite with transforms
|
|
33
30
|
router.rewrite('/users/:userId', 'https://api.example.com/users/$1',
|
|
34
31
|
({ userId, env }) => ({
|
|
35
32
|
requestHeaders: {
|
|
@@ -37,12 +34,21 @@ export const config: VercelConfig = {
|
|
|
37
34
|
'authorization': `Bearer ${env.API_TOKEN}`
|
|
38
35
|
}
|
|
39
36
|
})
|
|
40
|
-
)
|
|
41
|
-
|
|
42
|
-
|
|
37
|
+
)
|
|
38
|
+
],
|
|
39
|
+
|
|
40
|
+
redirects: [
|
|
43
41
|
router.redirect('/old-docs', '/docs', { permanent: true })
|
|
44
42
|
],
|
|
45
43
|
|
|
44
|
+
headers: [
|
|
45
|
+
router.cacheControl('/static/(.*)', {
|
|
46
|
+
public: true,
|
|
47
|
+
maxAge: '1 week',
|
|
48
|
+
immutable: true
|
|
49
|
+
})
|
|
50
|
+
],
|
|
51
|
+
|
|
46
52
|
crons: [
|
|
47
53
|
{ path: '/api/cleanup', schedule: '0 0 * * *' }
|
|
48
54
|
]
|
|
@@ -53,7 +59,6 @@ export const config: VercelConfig = {
|
|
|
53
59
|
|
|
54
60
|
- **Type-safe configuration** - Full TypeScript support with IDE autocomplete
|
|
55
61
|
- **Readable syntax** - Helper methods like `router.redirect()`, `router.rewrite()`, `router.header()`
|
|
56
|
-
- **Static validation** - Catch configuration errors at development time
|
|
57
62
|
- **Transforms** - Modify request/response headers and query parameters on the fly
|
|
58
63
|
- **Conditions** - Advanced routing with `has` and `missing` conditions
|
|
59
64
|
- **CLI tools** - `compile` and `validate` commands for development
|
|
@@ -84,39 +89,11 @@ npx @vercel/config validate
|
|
|
84
89
|
npx @vercel/config generate
|
|
85
90
|
```
|
|
86
91
|
|
|
87
|
-
## Validation
|
|
88
|
-
|
|
89
|
-
Static fields are validated to ensure they only contain literal values (strings, booleans, objects with primitives):
|
|
90
|
-
|
|
91
|
-
```typescript
|
|
92
|
-
// ✅ Valid - static string
|
|
93
|
-
export const buildCommand = 'npm run build';
|
|
94
|
-
|
|
95
|
-
// ❌ Invalid - computed value
|
|
96
|
-
export const buildCommand = process.env.BUILD_CMD;
|
|
97
|
-
|
|
98
|
-
// ✅ Valid - static object
|
|
99
|
-
export const git = {
|
|
100
|
-
deploymentEnabled: {
|
|
101
|
-
'main': true,
|
|
102
|
-
'dev': false
|
|
103
|
-
}
|
|
104
|
-
};
|
|
105
|
-
```
|
|
106
|
-
|
|
107
|
-
Static fields that are validated:
|
|
108
|
-
- `buildCommand`, `devCommand`, `installCommand`
|
|
109
|
-
- `framework`, `nodeVersion`, `outputDirectory`
|
|
110
|
-
- `github.enabled`, `github.autoAlias`, `github.autoJobCancelation`
|
|
111
|
-
- `git.deploymentEnabled`
|
|
112
|
-
- `relatedProjects`
|
|
113
|
-
|
|
114
92
|
## Important Notes
|
|
115
93
|
|
|
116
|
-
- **One config file only**: You cannot have both `vercel.ts` and `vercel.json`.
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
- **Versioned API**: Use `@vercel/config/v1` for imports to enable future versioning.
|
|
94
|
+
- **One config file only**: You cannot have both `vercel.ts` and `vercel.json`.
|
|
95
|
+
- **Transforms compile to routes**: When you add transforms to rewrites/redirects (like `requestHeaders`), they're compiled to the lower-level `routes` primitive internally.
|
|
96
|
+
- **Automatic compilation**: The Vercel CLI compiles `vercel.ts` automatically.
|
|
120
97
|
|
|
121
98
|
## Learn More
|
|
122
99
|
|
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
|
@@ -111,14 +111,6 @@ class Router {
|
|
|
111
111
|
});
|
|
112
112
|
return { proxy, accessedVars };
|
|
113
113
|
}
|
|
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
114
|
/**
|
|
123
115
|
* Creates a rewrite rule. Returns either a Rewrite object (simple case) or Route with transforms.
|
|
124
116
|
*
|
|
@@ -134,7 +126,6 @@ class Router {
|
|
|
134
126
|
*/
|
|
135
127
|
rewrite(source, destination, optionsOrCallback) {
|
|
136
128
|
this.validateSourcePattern(source);
|
|
137
|
-
(0, validation_1.validateCaptureGroupReferences)(source, destination);
|
|
138
129
|
let options;
|
|
139
130
|
// Handle callback syntax
|
|
140
131
|
if (typeof optionsOrCallback === 'function') {
|
|
@@ -226,7 +217,6 @@ class Router {
|
|
|
226
217
|
*/
|
|
227
218
|
redirect(source, destination, optionsOrCallback) {
|
|
228
219
|
this.validateSourcePattern(source);
|
|
229
|
-
(0, validation_1.validateCaptureGroupReferences)(source, destination);
|
|
230
220
|
let options;
|
|
231
221
|
// Handle callback syntax
|
|
232
222
|
if (typeof optionsOrCallback === 'function') {
|
package/dist/types.d.ts
CHANGED
package/dist/types.js
CHANGED
package/dist/v1/index.d.ts
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @vercel/config/v1 - Main API entry point
|
|
3
|
-
*
|
|
4
|
-
* Usage:
|
|
5
|
-
* import { createRouter, VercelConfig } from '@vercel/config/v1';
|
|
6
|
-
*/
|
|
7
1
|
export { createRouter, Router } from "../router";
|
|
8
2
|
export * from "../router";
|
|
9
|
-
export
|
|
3
|
+
export { VercelConfig } from "../types";
|
|
4
|
+
export type { Redirect, Rewrite, HeaderRule, Condition, RouteType } from "../types";
|
|
5
|
+
export { validateStaticString, validateStaticBoolean, validateStaticObject, validateStaticStringArray, validateStaticFields } from "../utils/validation";
|
package/dist/v1/index.js
CHANGED
|
@@ -1,10 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* @vercel/config/v1 - Main API entry point
|
|
4
|
-
*
|
|
5
|
-
* Usage:
|
|
6
|
-
* import { createRouter, VercelConfig } from '@vercel/config/v1';
|
|
7
|
-
*/
|
|
8
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
9
3
|
if (k2 === undefined) k2 = k;
|
|
10
4
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
@@ -20,8 +14,16 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
20
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
21
15
|
};
|
|
22
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
-
exports.Router = exports.createRouter = void 0;
|
|
17
|
+
exports.validateStaticFields = exports.validateStaticStringArray = exports.validateStaticObject = exports.validateStaticBoolean = exports.validateStaticString = exports.VercelConfig = exports.Router = exports.createRouter = void 0;
|
|
24
18
|
var router_1 = require("../router");
|
|
25
19
|
Object.defineProperty(exports, "createRouter", { enumerable: true, get: function () { return router_1.createRouter; } });
|
|
26
20
|
Object.defineProperty(exports, "Router", { enumerable: true, get: function () { return router_1.Router; } });
|
|
27
21
|
__exportStar(require("../router"), exports);
|
|
22
|
+
var types_1 = require("../types");
|
|
23
|
+
Object.defineProperty(exports, "VercelConfig", { enumerable: true, get: function () { return types_1.VercelConfig; } });
|
|
24
|
+
var validation_1 = require("../utils/validation");
|
|
25
|
+
Object.defineProperty(exports, "validateStaticString", { enumerable: true, get: function () { return validation_1.validateStaticString; } });
|
|
26
|
+
Object.defineProperty(exports, "validateStaticBoolean", { enumerable: true, get: function () { return validation_1.validateStaticBoolean; } });
|
|
27
|
+
Object.defineProperty(exports, "validateStaticObject", { enumerable: true, get: function () { return validation_1.validateStaticObject; } });
|
|
28
|
+
Object.defineProperty(exports, "validateStaticStringArray", { enumerable: true, get: function () { return validation_1.validateStaticStringArray; } });
|
|
29
|
+
Object.defineProperty(exports, "validateStaticFields", { enumerable: true, get: function () { return validation_1.validateStaticFields; } });
|
package/package.json
CHANGED
|
@@ -1,32 +1,28 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vercel/config",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "A TypeScript SDK for programmatically
|
|
3
|
+
"version": "0.0.18",
|
|
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",
|
|
14
|
-
"main": "dist/index.js",
|
|
15
|
-
"types": "dist/index.d.ts",
|
|
16
|
-
"exports": {
|
|
17
|
-
".": "./dist/index.js",
|
|
18
|
-
"./v1": "./dist/v1/index.js"
|
|
19
|
-
},
|
|
14
|
+
"main": "dist/v1/index.js",
|
|
15
|
+
"types": "dist/v1/index.d.ts",
|
|
20
16
|
"typesVersions": {
|
|
21
17
|
"*": {
|
|
22
|
-
".": [
|
|
23
|
-
"dist/index.d.ts"
|
|
24
|
-
],
|
|
25
18
|
"v1": [
|
|
26
19
|
"dist/v1/index.d.ts"
|
|
27
20
|
]
|
|
28
21
|
}
|
|
29
22
|
},
|
|
23
|
+
"exports": {
|
|
24
|
+
"./v1": "./dist/v1/index.js"
|
|
25
|
+
},
|
|
30
26
|
"bin": {
|
|
31
27
|
"@vercel/config": "./dist/cli.js"
|
|
32
28
|
},
|
package/dist/index.d.ts
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
export { createRouter, Router } from "./router";
|
|
2
|
-
export * from "./router";
|
|
3
|
-
export type { VercelConfig, Redirect, Rewrite, HeaderRule, Condition, RouteType } from "./types";
|
|
4
|
-
export { validateStaticString, validateStaticBoolean, validateStaticObject, validateStaticStringArray, validateStaticFields } from "./utils/validation";
|
package/dist/index.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.validateStaticFields = exports.validateStaticStringArray = exports.validateStaticObject = exports.validateStaticBoolean = exports.validateStaticString = exports.Router = exports.createRouter = void 0;
|
|
18
|
-
var router_1 = require("./router");
|
|
19
|
-
Object.defineProperty(exports, "createRouter", { enumerable: true, get: function () { return router_1.createRouter; } });
|
|
20
|
-
Object.defineProperty(exports, "Router", { enumerable: true, get: function () { return router_1.Router; } });
|
|
21
|
-
__exportStar(require("./router"), exports);
|
|
22
|
-
var validation_1 = require("./utils/validation");
|
|
23
|
-
Object.defineProperty(exports, "validateStaticString", { enumerable: true, get: function () { return validation_1.validateStaticString; } });
|
|
24
|
-
Object.defineProperty(exports, "validateStaticBoolean", { enumerable: true, get: function () { return validation_1.validateStaticBoolean; } });
|
|
25
|
-
Object.defineProperty(exports, "validateStaticObject", { enumerable: true, get: function () { return validation_1.validateStaticObject; } });
|
|
26
|
-
Object.defineProperty(exports, "validateStaticStringArray", { enumerable: true, get: function () { return validation_1.validateStaticStringArray; } });
|
|
27
|
-
Object.defineProperty(exports, "validateStaticFields", { enumerable: true, get: function () { return validation_1.validateStaticFields; } });
|