@vercel/config 0.0.14 → 0.0.16

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.
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.validateCaptureGroupReferences = exports.countCaptureGroups = exports.createCronExpression = exports.parseCronExpression = exports.validateRegexPattern = void 0;
3
+ exports.validateStaticFields = exports.validateStaticStringArray = exports.validateStaticObject = exports.validateStaticBoolean = exports.validateStaticString = exports.validateCaptureGroupReferences = exports.countCaptureGroups = exports.createCronExpression = exports.parseCronExpression = exports.validateRegexPattern = void 0;
4
4
  const zod_1 = require("zod");
5
5
  /**
6
6
  * Validates and type-checks regex patterns for Vercel's path-to-regexp syntax.
@@ -122,3 +122,98 @@ function validateCaptureGroupReferences(source, destination) {
122
122
  }
123
123
  }
124
124
  exports.validateCaptureGroupReferences = validateCaptureGroupReferences;
125
+ /**
126
+ * Validates that a value is a static string literal (not computed, not a function call, etc.)
127
+ * Used for static fields that must be extracted before build execution.
128
+ */
129
+ function validateStaticString(value, fieldName) {
130
+ if (typeof value !== 'string') {
131
+ throw new Error(`Field "${fieldName}" must be a static string literal. ` +
132
+ `Got ${typeof value}. Function calls, variables, and expressions are not allowed.`);
133
+ }
134
+ }
135
+ exports.validateStaticString = validateStaticString;
136
+ /**
137
+ * Validates that a value is a static boolean literal
138
+ */
139
+ function validateStaticBoolean(value, fieldName) {
140
+ if (typeof value !== 'boolean') {
141
+ throw new Error(`Field "${fieldName}" must be a static boolean literal. ` +
142
+ `Got ${typeof value}. Only true or false are allowed.`);
143
+ }
144
+ }
145
+ exports.validateStaticBoolean = validateStaticBoolean;
146
+ /**
147
+ * Validates that a value is a static object with primitive values
148
+ * Used for git.deploymentEnabled and similar objects that need to be static
149
+ */
150
+ function validateStaticObject(value, fieldName) {
151
+ if (typeof value !== 'object' || value === null) {
152
+ throw new Error(`Field "${fieldName}" must be a static object with primitive values. ` +
153
+ `Got ${typeof value}.`);
154
+ }
155
+ for (const [key, val] of Object.entries(value)) {
156
+ if (typeof val !== 'boolean' && typeof val !== 'string' && typeof val !== 'number') {
157
+ throw new Error(`Field "${fieldName}.${key}" must contain only static primitive values (string, number, boolean). ` +
158
+ `Got ${typeof val}.`);
159
+ }
160
+ }
161
+ }
162
+ exports.validateStaticObject = validateStaticObject;
163
+ /**
164
+ * Validates that a value is a static array of strings
165
+ */
166
+ function validateStaticStringArray(value, fieldName) {
167
+ if (!Array.isArray(value)) {
168
+ throw new Error(`Field "${fieldName}" must be a static array of strings. ` +
169
+ `Got ${typeof value}.`);
170
+ }
171
+ for (let i = 0; i < value.length; i++) {
172
+ if (typeof value[i] !== 'string') {
173
+ throw new Error(`Field "${fieldName}[${i}]" must be a static string. ` +
174
+ `Got ${typeof value[i]}.`);
175
+ }
176
+ }
177
+ }
178
+ exports.validateStaticStringArray = validateStaticStringArray;
179
+ /**
180
+ * Validates static fields in VercelConfig that must be extracted before build execution.
181
+ * These fields include:
182
+ * - buildCommand, devCommand, installCommand, framework, nodeVersion, outputDirectory
183
+ * - github.enabled, github.autoAlias, github.autoJobCancelation
184
+ * - git.deploymentEnabled
185
+ * - relatedProjects
186
+ */
187
+ function validateStaticFields(config) {
188
+ // Validate string fields
189
+ const stringFields = ['buildCommand', 'devCommand', 'installCommand', 'framework', 'nodeVersion', 'outputDirectory'];
190
+ for (const field of stringFields) {
191
+ if (config[field] !== undefined && config[field] !== null) {
192
+ validateStaticString(config[field], field);
193
+ }
194
+ }
195
+ // Validate relatedProjects (array of strings)
196
+ if (config.relatedProjects !== undefined) {
197
+ validateStaticStringArray(config.relatedProjects, 'relatedProjects');
198
+ }
199
+ // Validate git.deploymentEnabled (boolean or object with branch booleans)
200
+ if (config.git !== undefined && config.git.deploymentEnabled !== undefined) {
201
+ const deploymentEnabled = config.git.deploymentEnabled;
202
+ if (typeof deploymentEnabled === 'boolean') {
203
+ validateStaticBoolean(deploymentEnabled, 'git.deploymentEnabled');
204
+ }
205
+ else {
206
+ validateStaticObject(deploymentEnabled, 'git.deploymentEnabled');
207
+ }
208
+ }
209
+ // Validate github fields (booleans)
210
+ const githubBooleanFields = ['enabled', 'autoAlias', 'autoJobCancelation'];
211
+ if (config.github !== undefined) {
212
+ for (const field of githubBooleanFields) {
213
+ if (config.github[field] !== undefined) {
214
+ validateStaticBoolean(config.github[field], `github.${field}`);
215
+ }
216
+ }
217
+ }
218
+ }
219
+ exports.validateStaticFields = validateStaticFields;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @vercel/config/v1 - Main API entry point
3
+ *
4
+ * Usage:
5
+ * import { createRouter, VercelConfig } from '@vercel/config/v1';
6
+ */
7
+ export { createRouter, Router } from "../router";
8
+ export * from "../router";
9
+ export type { VercelConfig, Redirect, Rewrite, HeaderRule, Condition, RouteType } from "../types";
@@ -0,0 +1,27 @@
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
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
9
+ if (k2 === undefined) k2 = k;
10
+ var desc = Object.getOwnPropertyDescriptor(m, k);
11
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
12
+ desc = { enumerable: true, get: function() { return m[k]; } };
13
+ }
14
+ Object.defineProperty(o, k2, desc);
15
+ }) : (function(o, m, k, k2) {
16
+ if (k2 === undefined) k2 = k;
17
+ o[k2] = m[k];
18
+ }));
19
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
20
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
21
+ };
22
+ Object.defineProperty(exports, "__esModule", { value: true });
23
+ exports.Router = exports.createRouter = void 0;
24
+ var router_1 = require("../router");
25
+ Object.defineProperty(exports, "createRouter", { enumerable: true, get: function () { return router_1.createRouter; } });
26
+ Object.defineProperty(exports, "Router", { enumerable: true, get: function () { return router_1.Router; } });
27
+ __exportStar(require("../router"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vercel/config",
3
- "version": "0.0.14",
3
+ "version": "0.0.16",
4
4
  "description": "A TypeScript SDK for programmatically generating Vercel configuration files",
5
5
  "bugs": {
6
6
  "url": "https://github.com/vercel/router-sdk/issues"
@@ -13,6 +13,20 @@
13
13
  "license": "MIT",
14
14
  "main": "dist/index.js",
15
15
  "types": "dist/index.d.ts",
16
+ "exports": {
17
+ ".": "./dist/index.js",
18
+ "./v1": "./dist/v1/index.js"
19
+ },
20
+ "typesVersions": {
21
+ "*": {
22
+ ".": [
23
+ "dist/index.d.ts"
24
+ ],
25
+ "v1": [
26
+ "dist/v1/index.d.ts"
27
+ ]
28
+ }
29
+ },
16
30
  "bin": {
17
31
  "@vercel/config": "./dist/cli.js"
18
32
  },