@vite-hub/cli 0.7.0 → 0.8.0
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 +2 -1
- package/dist/{commands-o_CHzNS9.js → commands-w7tEEJph.js} +57 -62
- package/dist/console-apps-BQX-Np9Q.js +271 -0
- package/dist/console-auth-cCodgT_T.js +2813 -0
- package/dist/{console-env-MPzeOLqu.js → console-env-eXdVI6kw.js} +4 -14
- package/dist/{deploy-CGRf9Pq-.js → deploy-CqR6pJa-.js} +9 -4
- package/dist/{env-DSPUdOVC.js → env-D_CN5DyX.js} +8 -2
- package/dist/envelope-BJQ7xPyX.js +99 -0
- package/dist/help-cache-BI6y5pN8.js +195 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +64 -27
- package/dist/link-BRNWNqT9.js +663 -0
- package/dist/provision-9QsGgeiq.js +1741 -0
- package/dist/provision-Fiosv3Un.js +1391 -0
- package/dist/setup/index.js +8 -7
- package/dist/status-gjvZVutV.js +599 -0
- package/dist/vercel-B5CJLsT0.js +701 -0
- package/package.json +4 -4
- package/dist/provision-DWEZYLWJ.js +0 -8091
|
@@ -0,0 +1,1741 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
import { spawn } from "node:child_process";
|
|
3
|
+
import { readFileSync } from "node:fs";
|
|
4
|
+
import { defineDiagnostics } from "nostics";
|
|
5
|
+
import { mkdtemp, rm, writeFile } from "node:fs/promises";
|
|
6
|
+
import { dirname, join, resolve } from "node:path";
|
|
7
|
+
// ../internal/dist/error-diagnostics-CcnGkqIk.js
|
|
8
|
+
const dynamicError$1 = { why: ({ message }) => message === void 0 ? "" : String(message) };
|
|
9
|
+
const internalErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
|
|
10
|
+
docsBase: "https://vitehub.dev/docs/development/diagnostics",
|
|
11
|
+
codes: {
|
|
12
|
+
INTERNAL_R0012: {
|
|
13
|
+
...dynamicError$1,
|
|
14
|
+
fix: "Check the URL, the headers, and the credentials of the HTTP request. `error.status` holds the status that the server sent."
|
|
15
|
+
},
|
|
16
|
+
INTERNAL_R0013: {
|
|
17
|
+
...dynamicError$1,
|
|
18
|
+
fix: "Check that the provider token can manage the resource in the path that the message names. `error.kind` and `error.codes` hold the provider failure."
|
|
19
|
+
},
|
|
20
|
+
INTERNAL_R0014: {
|
|
21
|
+
why: ({ path }) => `Cannot read Provision State from "${path}".`,
|
|
22
|
+
fix: "Check file access and restore valid JSON while preserving existing resource IDs."
|
|
23
|
+
},
|
|
24
|
+
INTERNAL_R0020: {
|
|
25
|
+
fix: "Give the operation a name like `content.publish`, a description, a section, a kind, an input schema, and a run function.",
|
|
26
|
+
why: ({ message }) => message === void 0 ? "" : String(message)
|
|
27
|
+
},
|
|
28
|
+
INTERNAL_R0021: {
|
|
29
|
+
fix: "Run `vitehub inspect definitions --kind operation` to list the operations of this app.",
|
|
30
|
+
why: ({ message }) => message === void 0 ? "" : String(message)
|
|
31
|
+
},
|
|
32
|
+
INTERNAL_R0022: {
|
|
33
|
+
fix: "Send input that matches the schema of the operation. `vitehub <namespace> <command> --help` shows the fields, and the list_operations tool of the ViteHub MCP gives the input schema of each operation.",
|
|
34
|
+
why: ({ message }) => message === void 0 ? "" : String(message)
|
|
35
|
+
},
|
|
36
|
+
INTERNAL_R0024: {
|
|
37
|
+
fix: "Start the dev server (`nuxt dev` or `vite dev`), or pass `--url <origin>` of a deployed app and set VITEHUB_CONSOLE_PRIVATE_KEY_<NAME> to a private key whose public key the app has in VITEHUB_CONSOLE_KEY_<NAME>.",
|
|
38
|
+
why: ({ message }) => message === void 0 ? "" : String(message)
|
|
39
|
+
},
|
|
40
|
+
INTERNAL_R0023: {
|
|
41
|
+
fix: "Ask for access to the section of this operation.",
|
|
42
|
+
why: ({ message }) => message === void 0 ? "" : String(message)
|
|
43
|
+
},
|
|
44
|
+
INTERNAL_B0001: {
|
|
45
|
+
...dynamicError$1,
|
|
46
|
+
fix: "Give the resource that the message names another name or binding in the `vitehub()` options of its feature, so that two different Cloudflare resources do not share one name."
|
|
47
|
+
},
|
|
48
|
+
INTERNAL_B0015: {
|
|
49
|
+
...dynamicError$1,
|
|
50
|
+
fix: "Install one version of the package that the message names, for example with `pnpm dedupe` or an `overrides` entry in `package.json`."
|
|
51
|
+
},
|
|
52
|
+
INTERNAL_B0016: {
|
|
53
|
+
...dynamicError$1,
|
|
54
|
+
fix: "Correct the field that the message names in the `package.json` of a runtime dependency of the app, such as a workspace package, or run `pnpm install` again to restore an installed package."
|
|
55
|
+
},
|
|
56
|
+
INTERNAL_B0017: {
|
|
57
|
+
...dynamicError$1,
|
|
58
|
+
fix: "Correct the field that the message names in the `package.json` of a runtime dependency of the app, such as a workspace package, or run `pnpm install` again to restore an installed package."
|
|
59
|
+
},
|
|
60
|
+
INTERNAL_B0018: {
|
|
61
|
+
...dynamicError$1,
|
|
62
|
+
fix: "Correct the field that the message names in the `package.json` of a runtime dependency of the app, such as a workspace package, or run `pnpm install` again to restore an installed package."
|
|
63
|
+
},
|
|
64
|
+
INTERNAL_B0019: {
|
|
65
|
+
...dynamicError$1,
|
|
66
|
+
fix: "Correct the field that the message names in the `package.json` of a runtime dependency of the app, such as a workspace package, or run `pnpm install` again to restore an installed package."
|
|
67
|
+
},
|
|
68
|
+
INTERNAL_B0020: {
|
|
69
|
+
...dynamicError$1,
|
|
70
|
+
fix: "Correct the field that the message names in the `package.json` of a runtime dependency of the app, such as a workspace package, or run `pnpm install` again to restore an installed package."
|
|
71
|
+
},
|
|
72
|
+
INTERNAL_B0021: {
|
|
73
|
+
...dynamicError$1,
|
|
74
|
+
fix: "Install the package that the message names in the app, for example with `pnpm add <name>`, then build again."
|
|
75
|
+
},
|
|
76
|
+
INTERNAL_B0022: {
|
|
77
|
+
...dynamicError$1,
|
|
78
|
+
fix: "Install one version of the package that the message names, for example with `pnpm dedupe` or an `overrides` entry in `package.json`."
|
|
79
|
+
},
|
|
80
|
+
INTERNAL_B0025: {
|
|
81
|
+
...dynamicError$1,
|
|
82
|
+
fix: "Replace the `new URL(\"./...\", import.meta.url)` in the project-root `main.ts`, or in a Schedule file of `server/schedules/` and the files it imports, with a static `import` of that file."
|
|
83
|
+
},
|
|
84
|
+
INTERNAL_B0026: {
|
|
85
|
+
...dynamicError$1,
|
|
86
|
+
fix: "Replace the computed `import()` in the project-root `main.ts`, or in a Schedule file of `server/schedules/` and the files it imports, with a static `import` or with `import(\"<literal path>\")`."
|
|
87
|
+
},
|
|
88
|
+
INTERNAL_B0027: {
|
|
89
|
+
...dynamicError$1,
|
|
90
|
+
fix: "Replace the computed `require()` in the project-root `main.ts`, or in a Schedule file of `server/schedules/` and the files it imports, with a static `import`."
|
|
91
|
+
},
|
|
92
|
+
INTERNAL_B0028: {
|
|
93
|
+
...dynamicError$1,
|
|
94
|
+
fix: "Wait for the other build of this app to finish, or stop the process that the message names, then build again."
|
|
95
|
+
},
|
|
96
|
+
INTERNAL_B0029: {
|
|
97
|
+
...dynamicError$1,
|
|
98
|
+
fix: "Stop the other builds that write the same Deno output folder, delete the `.vitehub-lock` folder next to that output folder, such as `.output.vitehub-lock`, then build again."
|
|
99
|
+
},
|
|
100
|
+
INTERNAL_B0031: {
|
|
101
|
+
...dynamicError$1,
|
|
102
|
+
fix: "Import `./schedule/deno-cron.mjs` at the top level of the project-root `main.ts`, for example with `await import(new URL(\"./schedule/deno-cron.mjs\", import.meta.url).href)` outside any condition."
|
|
103
|
+
},
|
|
104
|
+
INTERNAL_B0032: {
|
|
105
|
+
...dynamicError$1,
|
|
106
|
+
fix: "Import `./server/index.mjs` at the top level of the project-root `main.ts`, for example with `await import(new URL(\"./server/index.mjs\", import.meta.url).href)` outside any condition."
|
|
107
|
+
},
|
|
108
|
+
INTERNAL_B0035: {
|
|
109
|
+
...dynamicError$1,
|
|
110
|
+
fix: "Delete the provider output folder that holds the file that the message names, such as `dist/<app>` for Cloudflare, and build again."
|
|
111
|
+
},
|
|
112
|
+
INTERNAL_B0039: {
|
|
113
|
+
...dynamicError$1,
|
|
114
|
+
fix: "Fix the build error that ViteHub showed before this one. ViteHub stops writing the provider output when another part of the build fails."
|
|
115
|
+
},
|
|
116
|
+
INTERNAL_B0040: {
|
|
117
|
+
...dynamicError$1,
|
|
118
|
+
fix: "Remove the custom Nitro `output.serverDir`, so that the Nitro preset of the host writes the server entry that the message names."
|
|
119
|
+
},
|
|
120
|
+
INTERNAL_B0043: {
|
|
121
|
+
...dynamicError$1,
|
|
122
|
+
fix: "Delete the build output folder, such as `.output` or `.vercel/output`, and build again."
|
|
123
|
+
},
|
|
124
|
+
INTERNAL_B0046: {
|
|
125
|
+
...dynamicError$1,
|
|
126
|
+
fix: "Install the package that the message names in the app, for example with `pnpm add <name>`, then build again."
|
|
127
|
+
},
|
|
128
|
+
INTERNAL_B0047: {
|
|
129
|
+
...dynamicError$1,
|
|
130
|
+
fix: "Correct the `package.json` file that the message names so that it holds one JSON object, or run `pnpm install` again to restore an installed package."
|
|
131
|
+
},
|
|
132
|
+
INTERNAL_B0048: {
|
|
133
|
+
fix: "Rename one of the two operations. A name is `<section>.<verb>` and is unique in the app.",
|
|
134
|
+
why: ({ message }) => message === void 0 ? "" : String(message)
|
|
135
|
+
},
|
|
136
|
+
INTERNAL_B0049: {
|
|
137
|
+
fix: "Set `cli: { namespace, command }` on one of the two operations.",
|
|
138
|
+
why: ({ message }) => message === void 0 ? "" : String(message)
|
|
139
|
+
},
|
|
140
|
+
INTERNAL_B0050: {
|
|
141
|
+
fix: "Rename one of the two operations, or set `mcp: false` on it. MCP tool names replace every character outside letters, digits, `_`, and `-` with `_`.",
|
|
142
|
+
why: ({ message }) => message === void 0 ? "" : String(message)
|
|
143
|
+
},
|
|
144
|
+
INTERNAL_B0051: {
|
|
145
|
+
why: ({ field, generated, name, path, project, scope }) => `The Cloudflare ${path} entry "${name}"${scope} is written by ViteHub and by the project's Wrangler config with a different ${field}: ${generated} and ${project}.`,
|
|
146
|
+
fix: "Remove the entry from the project's Wrangler config, since ViteHub writes it, or give one of them another name."
|
|
147
|
+
},
|
|
148
|
+
INTERNAL_B0052: {
|
|
149
|
+
why: ({ column, section }) => `The column "${column}" of the Console section "${section}" needs both \`format: "switch"\` and a \`switch\` operation name such as "skills.set".`,
|
|
150
|
+
fix: "Give a switch column `format: \"switch\"` and `switch: { operation, input }` with a registered operation name, or remove both."
|
|
151
|
+
},
|
|
152
|
+
INTERNAL_R0025: {
|
|
153
|
+
fix: "Start the dev server (`nuxt dev` or `vite dev`) in the project that you run the command from, or pass `--url` of that server.",
|
|
154
|
+
why: ({ message }) => message === void 0 ? "" : String(message)
|
|
155
|
+
},
|
|
156
|
+
INTERNAL_R0026: {
|
|
157
|
+
why: "The server parsed a destructive operation that the CLI did not confirm.",
|
|
158
|
+
fix: "Review the operation, then run it again with --yes to confirm the change."
|
|
159
|
+
},
|
|
160
|
+
INTERNAL_C0001: {
|
|
161
|
+
...dynamicError$1,
|
|
162
|
+
fix: "Rename or remove one of the two files that the message lists. ViteHub takes the Definition name from the file path."
|
|
163
|
+
},
|
|
164
|
+
INTERNAL_C0002: {
|
|
165
|
+
...dynamicError$1,
|
|
166
|
+
fix: "Rename or remove one of the two files that the message lists. ViteHub takes the Definition name from the file path."
|
|
167
|
+
},
|
|
168
|
+
INTERNAL_R0001: {
|
|
169
|
+
...dynamicError$1,
|
|
170
|
+
fix: "Set `host` in `vitehub()`, or in the `vitehub` options of `nuxt.config.ts`, to `cloudflare`, `deno`, `netlify`, `node`, or `vercel`. Or remove `host` so that ViteHub finds the host from the environment."
|
|
171
|
+
},
|
|
172
|
+
INTERNAL_R0002: {
|
|
173
|
+
...dynamicError$1,
|
|
174
|
+
fix: ({ fix }) => fix ?? "Build for a host that provides this capability, or set the option named in the message to `false`."
|
|
175
|
+
},
|
|
176
|
+
INTERNAL_R0004: {
|
|
177
|
+
...dynamicError$1,
|
|
178
|
+
fix: "Set a larger `maxResponseBytes` on the HTTP request, such as the `url()` Source options, or ask the server for a smaller response."
|
|
179
|
+
},
|
|
180
|
+
INTERNAL_R0005: {
|
|
181
|
+
...dynamicError$1,
|
|
182
|
+
fix: "Set `method` of the HTTP request to `GET`, `HEAD`, or `POST`."
|
|
183
|
+
},
|
|
184
|
+
INTERNAL_R0006: {
|
|
185
|
+
...dynamicError$1,
|
|
186
|
+
fix: "Set `timeout` of the HTTP request to a number of milliseconds from 1 to 2147483647, or remove it to use the default."
|
|
187
|
+
},
|
|
188
|
+
INTERNAL_R0007: {
|
|
189
|
+
...dynamicError$1,
|
|
190
|
+
fix: "Set `maxResponseBytes` of the HTTP request to a positive integer no greater than the limit that the message names, or remove it to use the default."
|
|
191
|
+
},
|
|
192
|
+
INTERNAL_R0008: {
|
|
193
|
+
...dynamicError$1,
|
|
194
|
+
fix: "Make the value that the message names match its schema: the input, query, or body that you send, or the response schema that you declare for the request."
|
|
195
|
+
},
|
|
196
|
+
INTERNAL_R0009: {
|
|
197
|
+
...dynamicError$1,
|
|
198
|
+
fix: "Use a Standard Schema whose `validate()` returns `{ value }` or `{ issues }` for the value that the message names."
|
|
199
|
+
},
|
|
200
|
+
INTERNAL_R0010: {
|
|
201
|
+
...dynamicError$1,
|
|
202
|
+
fix: "Run the command again. If the error stays, check the Cloudflare API status, because Cloudflare sent a response that ViteHub cannot read."
|
|
203
|
+
},
|
|
204
|
+
INTERNAL_R0011: {
|
|
205
|
+
...dynamicError$1,
|
|
206
|
+
fix: "Pass an h3 app, an object with a `fetch(request)` method, or a fetch function as `app`."
|
|
207
|
+
},
|
|
208
|
+
INTERNAL_CONSOLE_KEY_NAME_INVALID: {
|
|
209
|
+
why: ({ name }) => `[vitehub] The Console key name ${JSON.stringify(name)} must be 1 to 64 of A-Z, 0-9, and _.`,
|
|
210
|
+
fix: "Name the Console key with 1 to 64 characters from A-Z, 0-9, and _, such as `CI`. The app reads its public key from `VITEHUB_CONSOLE_KEY_<NAME>`."
|
|
211
|
+
},
|
|
212
|
+
INTERNAL_CONSOLE_PRIVATE_KEY_INVALID: {
|
|
213
|
+
why: "[vitehub] A Console private key is the 32-byte Ed25519 seed as base64url (43 characters). `vitehub secret console-key` makes one.",
|
|
214
|
+
fix: "Run `vitehub secret console-key` and use the 43-character private key that it prints, without spaces or quotes."
|
|
215
|
+
},
|
|
216
|
+
INTERNAL_CONSOLE_PRIVATE_KEY_VARIABLES_MULTIPLE: {
|
|
217
|
+
why: ({ prefix, variables }) => `[vitehub] Set one ${prefix}<NAME> variable. This environment has ${variables}.`,
|
|
218
|
+
fix: "Keep one `VITEHUB_CONSOLE_PRIVATE_KEY_<NAME>` variable in the environment of the command, and unset the others that the message names."
|
|
219
|
+
},
|
|
220
|
+
INTERNAL_CONSOLE_PRIVATE_KEY_VARIABLE_INVALID: {
|
|
221
|
+
why: ({ variable }) => `[vitehub] ${variable} must be the 43-character private key that \`vitehub secret console-key\` prints, and its name 1 to 64 of A-Z, 0-9, and _.`,
|
|
222
|
+
fix: "Set the variable that the message names to the private key that `vitehub secret console-key` prints, and name it `VITEHUB_CONSOLE_PRIVATE_KEY_<NAME>` with A-Z, 0-9, and _ in `<NAME>`."
|
|
223
|
+
},
|
|
224
|
+
INTERNAL_DEV_SERVER_NOT_FOUND: {
|
|
225
|
+
why: ({ command }) => `[vitehub] No dev server of this project is running, and --url is not set, so \`vitehub ${command}\` has no app to call.`,
|
|
226
|
+
fix: "Start the dev server of this project, such as with `pnpm dev`, or pass --url with the app URL, such as --url http://localhost:3000."
|
|
227
|
+
},
|
|
228
|
+
INTERNAL_FORGE_NOT_INSTALLED: {
|
|
229
|
+
why: ({ feature }) => `${feature} needs @vite-hub/forge, and the app did not install it.`,
|
|
230
|
+
fix: "Install Forge in your app with `pnpm add @vite-hub/forge`, then build again."
|
|
231
|
+
},
|
|
232
|
+
INTERNAL_MCP_ARGUMENTS_INVALID: {
|
|
233
|
+
why: ({ detail }) => detail,
|
|
234
|
+
fix: "Pass the prompt or resource the arguments that `prompts/list` or `resources/templates/list` describes for it."
|
|
235
|
+
},
|
|
236
|
+
INTERNAL_MCP_METHOD_FAILED: {
|
|
237
|
+
why: ({ name }) => `${name} failed on the server.`,
|
|
238
|
+
fix: "Read the server log for the error of the MCP prompt or resource that the message names, and fix its handler."
|
|
239
|
+
},
|
|
240
|
+
INTERNAL_MCP_RESOURCE_NOT_FOUND: {
|
|
241
|
+
why: ({ uri }) => `Resource not found: ${uri}. Call resources/list or resources/templates/list for the resources of this server.`,
|
|
242
|
+
fix: "Call `resources/list` or `resources/templates/list`, and read a URI that one of them returns."
|
|
243
|
+
},
|
|
244
|
+
INTERNAL_PRESET_OPTION_UNKNOWN: {
|
|
245
|
+
why: ({ key, label }) => `[vitehub] Unknown ${label} option "${key}".`,
|
|
246
|
+
fix: "Remove the option that the message names from the preset options, or correct its spelling to an option that the preset declares."
|
|
247
|
+
},
|
|
248
|
+
INTERNAL_PRESET_TUPLE_INVALID: {
|
|
249
|
+
why: ({ owner }) => `[vitehub] ${owner} extends tuple requires [preset, options] with an options object.`,
|
|
250
|
+
fix: "Set `extends` to a preset, or to a two-item tuple `[preset, { ...options }]` whose second item is a plain object."
|
|
251
|
+
},
|
|
252
|
+
INTERNAL_RUNTIME_PACKAGE_VERSION_CONFLICT: {
|
|
253
|
+
why: ({ first, name, second }) => `[vitehub] One server function needs ${name} from two installations: ${first} and ${second}.`,
|
|
254
|
+
fix: "Install one version of the package that the message names, for example with `pnpm dedupe` or an `overrides` entry in `package.json`, then build again."
|
|
255
|
+
},
|
|
256
|
+
INTERNAL_SECRET_PURPOSE_MISSING: {
|
|
257
|
+
why: "[vitehub] A derived secret requires a purpose.",
|
|
258
|
+
fix: "Pass a non-empty purpose to `deriveSecret()`, such as `deriveSecret(\"my-module:session\")`."
|
|
259
|
+
},
|
|
260
|
+
INTERNAL_SECRET_TOO_SHORT: {
|
|
261
|
+
why: ({ minimum }) => `[vitehub] VITEHUB_SECRET must be at least ${minimum} characters. Generate one with \`openssl rand -base64 32\`.`,
|
|
262
|
+
fix: "Set `VITEHUB_SECRET` to the output of `openssl rand -base64 32`, which has 44 characters."
|
|
263
|
+
},
|
|
264
|
+
INTERNAL_SITE_TOKEN_TOO_LONG: {
|
|
265
|
+
why: ({ length, maximum }) => `The Site access token is ${length} characters, and an app accepts ${maximum}.`,
|
|
266
|
+
fix: "Open the app with a shorter path, or give the person and the project shorter names, so that the Site access token fits."
|
|
267
|
+
},
|
|
268
|
+
INTERNAL_SQLITE_ARGUMENT_INVALID: {
|
|
269
|
+
why: ({ value }) => value === "undefined" ? "undefined cannot be passed as argument to the database" : "Only finite numbers (not Infinity or NaN) can be passed as arguments",
|
|
270
|
+
fix: "Pass query arguments as finite numbers, strings, booleans, bigints, dates, byte arrays, or null. Replace undefined with null, and check numbers with `Number.isFinite()` before the query."
|
|
271
|
+
},
|
|
272
|
+
INTERNAL_SQLITE_INTEGER_UNSAFE: {
|
|
273
|
+
why: "Received integer which cannot be safely represented as a JavaScript number",
|
|
274
|
+
fix: "Create the client with `intMode: \"bigint\"` or `intMode: \"string\"`, or read the column with `CAST(column AS TEXT)` in the query."
|
|
275
|
+
},
|
|
276
|
+
INTERNAL_VALIBOT_JSON_SCHEMA_TARGET_UNSUPPORTED: {
|
|
277
|
+
why: ({ target }) => `[vitehub] Valibot cannot convert a schema to the ${target} JSON Schema target.`,
|
|
278
|
+
fix: "Ask for the `draft-07`, `draft-2020-12`, or `openapi-3.0` JSON Schema target, or pass one of them as `withValibotJsonSchema(schema, { target })`."
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
});
|
|
282
|
+
// ../internal/dist/object.js
|
|
283
|
+
/** A non-null object that is not an array. Functions do not pass. */
|
|
284
|
+
function isRecord(value) {
|
|
285
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
286
|
+
}
|
|
287
|
+
/** A non-null object or a function that is not an array. */
|
|
288
|
+
function isRecordOrFunction(value) {
|
|
289
|
+
return Object(value) === value && !Array.isArray(value);
|
|
290
|
+
}
|
|
291
|
+
// ../internal/dist/invariant.js
|
|
292
|
+
const invariantDiagnostics = /*#__PURE__*/ defineDiagnostics({
|
|
293
|
+
docsBase: "https://vitehub.dev/docs/development/diagnostics",
|
|
294
|
+
codes: { INTERNAL_INVARIANT_FAILED: {
|
|
295
|
+
why: ({ what }) => `ViteHub reached a state that it does not expect: ${what}`,
|
|
296
|
+
fix: "This is a ViteHub bug. Open an issue at https://github.com/vite-hub/vitehub/issues with this error message and its stack trace."
|
|
297
|
+
} }
|
|
298
|
+
});
|
|
299
|
+
/**
|
|
300
|
+
* The error for a state that only a ViteHub bug can reach, such as an impossible branch. `what` says which rule broke.
|
|
301
|
+
* Use a code from the package catalog when a developer can cause the error or fix it.
|
|
302
|
+
*/
|
|
303
|
+
function invariantError(what) {
|
|
304
|
+
return invariantDiagnostics.INTERNAL_INVARIANT_FAILED({ what });
|
|
305
|
+
}
|
|
306
|
+
/** Throws `INTERNAL_INVARIANT_FAILED` when `condition` is falsy. */
|
|
307
|
+
function invariant(condition, what) {
|
|
308
|
+
if (!condition) throw invariantError(what);
|
|
309
|
+
}
|
|
310
|
+
// ../internal/dist/features.js
|
|
311
|
+
/**
|
|
312
|
+
* The feature keys of `vitehub({...})`. `vitehub add <feature>` and `vitehub status` read this list before the owner
|
|
313
|
+
* package of a feature is installed, so the catalog is plain data with no owner imports.
|
|
314
|
+
*/
|
|
315
|
+
const featureIds = [
|
|
316
|
+
"agent",
|
|
317
|
+
"auth",
|
|
318
|
+
"blob",
|
|
319
|
+
"browser",
|
|
320
|
+
"cache",
|
|
321
|
+
"channels",
|
|
322
|
+
"comments",
|
|
323
|
+
"connections",
|
|
324
|
+
"console",
|
|
325
|
+
"database",
|
|
326
|
+
"email",
|
|
327
|
+
"env",
|
|
328
|
+
"i18n",
|
|
329
|
+
"kv",
|
|
330
|
+
"mcp",
|
|
331
|
+
"observability",
|
|
332
|
+
"queue",
|
|
333
|
+
"rateLimit",
|
|
334
|
+
"realtime",
|
|
335
|
+
"sandboxTask",
|
|
336
|
+
"schedule",
|
|
337
|
+
"workflow",
|
|
338
|
+
"workspace"
|
|
339
|
+
];
|
|
340
|
+
/** `dev` stores default Node development support. Use `featureSupport()` with the configured host for development lookups. */
|
|
341
|
+
const featureHosts = [
|
|
342
|
+
"dev",
|
|
343
|
+
"cloudflare",
|
|
344
|
+
"vercel",
|
|
345
|
+
"netlify",
|
|
346
|
+
"deno",
|
|
347
|
+
"node"
|
|
348
|
+
];
|
|
349
|
+
const noHostLimit = "No host limit in ViteHub.";
|
|
350
|
+
function native(driver, display, detail, guarantee = "native") {
|
|
351
|
+
return {
|
|
352
|
+
detail,
|
|
353
|
+
display,
|
|
354
|
+
driver,
|
|
355
|
+
guarantee,
|
|
356
|
+
level: "native"
|
|
357
|
+
};
|
|
358
|
+
}
|
|
359
|
+
function explicit(option, display, detail) {
|
|
360
|
+
return {
|
|
361
|
+
detail,
|
|
362
|
+
display,
|
|
363
|
+
level: "explicit",
|
|
364
|
+
option
|
|
365
|
+
};
|
|
366
|
+
}
|
|
367
|
+
function unsupported(detail) {
|
|
368
|
+
return {
|
|
369
|
+
detail,
|
|
370
|
+
level: "unsupported"
|
|
371
|
+
};
|
|
372
|
+
}
|
|
373
|
+
function everywhere(driver, display, detail = noHostLimit) {
|
|
374
|
+
const support = native(driver, display, detail);
|
|
375
|
+
return {
|
|
376
|
+
cloudflare: support,
|
|
377
|
+
deno: support,
|
|
378
|
+
dev: support,
|
|
379
|
+
netlify: support,
|
|
380
|
+
node: support,
|
|
381
|
+
vercel: support
|
|
382
|
+
};
|
|
383
|
+
}
|
|
384
|
+
function feature(definition) {
|
|
385
|
+
return {
|
|
386
|
+
devPackages: [],
|
|
387
|
+
enabledByDefault: false,
|
|
388
|
+
implies: [],
|
|
389
|
+
packages: [],
|
|
390
|
+
...definition
|
|
391
|
+
};
|
|
392
|
+
}
|
|
393
|
+
const sourceExtensions = [
|
|
394
|
+
"ts",
|
|
395
|
+
"mts",
|
|
396
|
+
"js",
|
|
397
|
+
"mjs",
|
|
398
|
+
"cts",
|
|
399
|
+
"cjs"
|
|
400
|
+
];
|
|
401
|
+
/** `<base>.<ext>` for each source extension. */
|
|
402
|
+
function sourceFiles(base) {
|
|
403
|
+
return sourceExtensions.map((extension) => `${base}.${extension}`);
|
|
404
|
+
}
|
|
405
|
+
/**
|
|
406
|
+
* A starter for Definitions in `dir`, one `<name>.ts` file each. With `suffix`, the owner also discovers the Vite
|
|
407
|
+
* form `src/<name>.<suffix>.ts`, and a Definition folder `<dir>/<name>/` when `folder` names its entry file.
|
|
408
|
+
*/
|
|
409
|
+
function starter(dir, template, options = {}) {
|
|
410
|
+
return {
|
|
411
|
+
conflicts: (name) => [
|
|
412
|
+
...sourceFiles(`${dir}/${name}`).slice(1),
|
|
413
|
+
...options.folder ? sourceFiles(`${dir}/${name}/${options.folder}`) : [],
|
|
414
|
+
...options.suffix ? [...sourceFiles(`src/${name}.${options.suffix}`), ...sourceFiles(`${name}.${options.suffix}`)] : []
|
|
415
|
+
],
|
|
416
|
+
dir,
|
|
417
|
+
file: (name) => `${dir}/${name}.ts`,
|
|
418
|
+
template
|
|
419
|
+
};
|
|
420
|
+
}
|
|
421
|
+
const features = {
|
|
422
|
+
agent: feature({
|
|
423
|
+
definition: starter("server/agents", (name) => `import { defineAgent } from "vite-hub/agent"
|
|
424
|
+
|
|
425
|
+
export default defineAgent({
|
|
426
|
+
driver: { run: () => ({ text: "Hello from ${name}." }) },
|
|
427
|
+
})
|
|
428
|
+
`, {
|
|
429
|
+
folder: "agent",
|
|
430
|
+
suffix: "agent"
|
|
431
|
+
}),
|
|
432
|
+
docs: "/docs/agents",
|
|
433
|
+
enabledByDiscovery: ["agents"],
|
|
434
|
+
hosts: {
|
|
435
|
+
...everywhere("nitro", "Nitro"),
|
|
436
|
+
deno: native("nitro", "Nitro", "Agent routes run in the Nitro output. The Agent Deno runtime is not supported on this host."),
|
|
437
|
+
netlify: native("nitro", "Nitro", "Agent HTTP routes run in generated functions. `agent.invocations` is not supported, so `agent: true` fails the build. Set `agent: { invocations: false }` and configure invocations on each Agent Definition.")
|
|
438
|
+
},
|
|
439
|
+
id: "agent",
|
|
440
|
+
packages: ["@vite-hub/agent"],
|
|
441
|
+
summary: "Agents in `server/agents/` with tools, Capabilities, channels, and invocations.",
|
|
442
|
+
title: "Agent"
|
|
443
|
+
}),
|
|
444
|
+
auth: feature({
|
|
445
|
+
docs: "/docs/auth",
|
|
446
|
+
enabledByDiscovery: sourceFiles("auth"),
|
|
447
|
+
hosts: everywhere("better-auth", "Better Auth"),
|
|
448
|
+
id: "auth",
|
|
449
|
+
packages: [
|
|
450
|
+
"@vite-hub/auth",
|
|
451
|
+
"better-auth",
|
|
452
|
+
"drizzle-orm"
|
|
453
|
+
],
|
|
454
|
+
summary: "Better Auth sign-in, sessions, and organizations, with tables that ViteHub owns.",
|
|
455
|
+
title: "Auth"
|
|
456
|
+
}),
|
|
457
|
+
blob: feature({
|
|
458
|
+
docs: "/docs/blob",
|
|
459
|
+
hosts: {
|
|
460
|
+
cloudflare: native("cloudflare", "R2", "Cloudflare R2 binding or S3-compatible HTTP access."),
|
|
461
|
+
deno: explicit("blob.driver", "S3", "Set `blob: { driver: \"s3\", bucket: \"my-bucket\" }` with a remote S3-compatible store. No Deno-native Blob driver is provided."),
|
|
462
|
+
dev: native("fs", "fs", "Local filesystem storage for development.", "single-host"),
|
|
463
|
+
netlify: native("netlify-blobs", "Netlify Blobs", "Netlify Blobs selected from the detected host."),
|
|
464
|
+
node: native("fs", "fs / S3", "Filesystem, S3-compatible, MinIO, or files-sdk drivers.", "single-host"),
|
|
465
|
+
vercel: native("vercel", "Vercel Blob", "Vercel Blob through the vercel driver.")
|
|
466
|
+
},
|
|
467
|
+
id: "blob",
|
|
468
|
+
packages: ["@vite-hub/blob"],
|
|
469
|
+
providerPackages: { driver: { s3: [
|
|
470
|
+
"@aws-sdk/client-s3",
|
|
471
|
+
"@aws-sdk/lib-storage",
|
|
472
|
+
"@aws-sdk/s3-presigned-post",
|
|
473
|
+
"@aws-sdk/s3-request-presigner"
|
|
474
|
+
] } },
|
|
475
|
+
service: "blob",
|
|
476
|
+
summary: "Object storage for files and uploads, with one API on every host.",
|
|
477
|
+
title: "Blob"
|
|
478
|
+
}),
|
|
479
|
+
browser: feature({
|
|
480
|
+
developmentOverrides: ["cloudflare", "vercel"],
|
|
481
|
+
docs: "/docs/browser",
|
|
482
|
+
enabledByDiscovery: ["browsers"],
|
|
483
|
+
hosts: {
|
|
484
|
+
cloudflare: native("cloudflare", "Browser Run", "Cloudflare Browser Run binding and provider output."),
|
|
485
|
+
deno: unsupported("Browser Definitions can connect to `BROWSER_CDP_URL`, which is not tested on Deno yet."),
|
|
486
|
+
dev: native("local", "Local Chromium", "Starts a Chromium on this machine, from `BROWSER_EXECUTABLE_PATH`, Playwright, or the system. `BROWSER_CDP_URL` connects to a remote Chromium. Set `browser: { remote: true }` to use Browser Run in Cloudflare dev.", "single-host"),
|
|
487
|
+
netlify: unsupported("Browser Definitions can connect to `BROWSER_CDP_URL`, which is not tested on Netlify yet."),
|
|
488
|
+
node: native("local", "Local Chromium", "Starts a Chromium on the server, from `BROWSER_EXECUTABLE_PATH`, Playwright, or the system. Install Chromium in the Docker image. `BROWSER_CDP_URL` connects to a remote Chromium.", "single-host"),
|
|
489
|
+
vercel: native("cdp", "Remote CDP", "Connects to the Chromium at `BROWSER_CDP_URL`, such as Browserless or Browserbase.")
|
|
490
|
+
},
|
|
491
|
+
id: "browser",
|
|
492
|
+
packages: ["@vite-hub/browser"],
|
|
493
|
+
service: "browser",
|
|
494
|
+
summary: "Headless browser sessions for Agents and server code.",
|
|
495
|
+
title: "Browser"
|
|
496
|
+
}),
|
|
497
|
+
cache: feature({
|
|
498
|
+
developmentOverrides: [
|
|
499
|
+
"cloudflare",
|
|
500
|
+
"deno",
|
|
501
|
+
"vercel"
|
|
502
|
+
],
|
|
503
|
+
docs: "/docs/reference/config-options",
|
|
504
|
+
hosts: {
|
|
505
|
+
cloudflare: native("cloudflare", "Workers KV", "Workers KV binding `CACHE`."),
|
|
506
|
+
deno: native("deno-kv", "Deno KV", "Native Deno KV."),
|
|
507
|
+
dev: native("fs-lite", "fs-lite", "`.vitehub/data/cache` during development.", "single-host"),
|
|
508
|
+
netlify: explicit("cache.driver", "KV", "`cache: true` has no default store on Netlify. Set `cache: { driver: \"kv\" }` and enable `kv`."),
|
|
509
|
+
node: native("fs-lite", "fs-lite", "`.vitehub/data/cache` on the server disk.", "single-host"),
|
|
510
|
+
vercel: native("vercel", "Runtime Cache", "Vercel Runtime Cache.")
|
|
511
|
+
},
|
|
512
|
+
id: "cache",
|
|
513
|
+
summary: "Storage for Nitro's cache mount, used by defineCachedFunction() and defineCachedEventHandler().",
|
|
514
|
+
title: "Cache"
|
|
515
|
+
}),
|
|
516
|
+
channels: feature({
|
|
517
|
+
docs: "/docs/channels",
|
|
518
|
+
enabledByDiscovery: ["channels"],
|
|
519
|
+
hosts: everywhere("nitro", "Nitro"),
|
|
520
|
+
id: "channels",
|
|
521
|
+
packages: ["@vite-hub/channels"],
|
|
522
|
+
summary: "Chat channels such as Slack, Discord, and GitHub that deliver messages to Agents.",
|
|
523
|
+
title: "Channels"
|
|
524
|
+
}),
|
|
525
|
+
comments: feature({
|
|
526
|
+
docs: "/docs/comments",
|
|
527
|
+
enabledByDiscovery: [
|
|
528
|
+
"comments.ts",
|
|
529
|
+
"comments.mts",
|
|
530
|
+
"comments.js",
|
|
531
|
+
"comments.mjs"
|
|
532
|
+
],
|
|
533
|
+
hosts: everywhere("database", "Database"),
|
|
534
|
+
id: "comments",
|
|
535
|
+
implies: [{ feature: "database" }],
|
|
536
|
+
packages: ["@vite-hub/comments"],
|
|
537
|
+
summary: "Comments on the app's pages, stored in a ViteHub Database.",
|
|
538
|
+
title: "Comments"
|
|
539
|
+
}),
|
|
540
|
+
connections: feature({
|
|
541
|
+
docs: "/docs/connections",
|
|
542
|
+
enabledByDiscovery: ["connections"],
|
|
543
|
+
hosts: everywhere("database", "Database"),
|
|
544
|
+
id: "connections",
|
|
545
|
+
implies: [{ feature: "database" }],
|
|
546
|
+
packages: [
|
|
547
|
+
"@vite-hub/connections",
|
|
548
|
+
"@vite-hub/database",
|
|
549
|
+
"drizzle-orm"
|
|
550
|
+
],
|
|
551
|
+
summary: "OAuth and API key Connections in `server/connections/`, with grants stored in a Database.",
|
|
552
|
+
title: "Connections"
|
|
553
|
+
}),
|
|
554
|
+
console: feature({
|
|
555
|
+
docs: "/docs/console",
|
|
556
|
+
hosts: everywhere("nitro", "Nitro"),
|
|
557
|
+
id: "console",
|
|
558
|
+
packages: [],
|
|
559
|
+
summary: "The Operations endpoint and MCP at `/_vitehub`, which the hosted Console at console.vitehub.dev and the CLI call.",
|
|
560
|
+
title: "Console"
|
|
561
|
+
}),
|
|
562
|
+
database: feature({
|
|
563
|
+
definition: {
|
|
564
|
+
conflicts: (name) => [
|
|
565
|
+
...sourceFiles(`server/databases/${name}`).slice(1),
|
|
566
|
+
...sourceFiles(`server/databases/${name}/index`),
|
|
567
|
+
...name === "default" ? ["src/database.ts"] : [...sourceFiles(`src/${name}.database`), "src/database.ts"]
|
|
568
|
+
],
|
|
569
|
+
dir: "server/databases",
|
|
570
|
+
file: (name) => `server/databases/${name}.ts`,
|
|
571
|
+
template: (name) => `import { integer, sqliteTable, text } from "drizzle-orm/sqlite-core"
|
|
572
|
+
import { defineDatabase } from "vite-hub/database"
|
|
573
|
+
|
|
574
|
+
export default defineDatabase({
|
|
575
|
+
${name === "default" ? "" : ` name: ${JSON.stringify(name)},\n`} schema: {
|
|
576
|
+
notes: sqliteTable("notes", {
|
|
577
|
+
id: integer("id").primaryKey(),
|
|
578
|
+
title: text("title").notNull(),
|
|
579
|
+
}),
|
|
580
|
+
},
|
|
581
|
+
})
|
|
582
|
+
`
|
|
583
|
+
},
|
|
584
|
+
developmentOverrides: [
|
|
585
|
+
"deno",
|
|
586
|
+
"netlify",
|
|
587
|
+
"vercel"
|
|
588
|
+
],
|
|
589
|
+
devPackages: ["drizzle-kit"],
|
|
590
|
+
docs: "/docs/database",
|
|
591
|
+
enabledByDiscovery: ["databases"],
|
|
592
|
+
hosts: {
|
|
593
|
+
cloudflare: native("cloudflare", "D1", "Cloudflare D1 binding, with authenticated HTTP available for development. A PostgreSQL Database Definition connects through Hyperdrive or `connection.url`."),
|
|
594
|
+
deno: explicit("database.connection", "libSQL / D1 / Postgres", "Configure hosted libSQL, D1 over authenticated HTTP, or a PostgreSQL Database Definition. No Deno-native database driver is provided."),
|
|
595
|
+
dev: native("sqlite", "SQLite", "Local SQLite through libSQL and Drizzle.", "single-host"),
|
|
596
|
+
netlify: explicit("database.connection", "libSQL / D1 / Postgres", "Configure hosted libSQL, D1 over authenticated HTTP, or a PostgreSQL Database Definition. No Netlify-native database driver is provided."),
|
|
597
|
+
node: native("sqlite", "SQLite / libSQL / Postgres", "SQLite or hosted libSQL through the selected Database connection, or a PostgreSQL Database Definition. Several servers can share Postgres and migrate on start under one advisory lock.", "single-host"),
|
|
598
|
+
vercel: explicit("database.connection", "libSQL / D1 / Postgres", "Configure hosted libSQL, D1 over authenticated HTTP, or a PostgreSQL Database Definition. The default local SQLite file is not supported in Vercel functions.")
|
|
599
|
+
},
|
|
600
|
+
id: "database",
|
|
601
|
+
packages: ["@vite-hub/database", "drizzle-orm"],
|
|
602
|
+
summary: "Drizzle Databases in `server/databases/` with migrations and a local SQLite in development.",
|
|
603
|
+
title: "Database"
|
|
604
|
+
}),
|
|
605
|
+
email: feature({
|
|
606
|
+
docs: "/docs/email",
|
|
607
|
+
hosts: {
|
|
608
|
+
cloudflare: native("cloudflare", "Cloudflare Email", "The Cloudflare Email driver is the default. Resend is also supported."),
|
|
609
|
+
deno: explicit("email.driver", "Resend", "Configure the built-in fetch-based Resend driver."),
|
|
610
|
+
dev: native("log", "Log", "`email: true` keeps each message in the development outbox and sends nothing. Set `email.driver` for a production build.", "process-local"),
|
|
611
|
+
netlify: explicit("email.driver", "Resend", "Configure the built-in Resend driver."),
|
|
612
|
+
node: explicit("email.driver", "Resend / SMTP / custom", "Configure Resend, `smtp` with the `nodemailer` package, or a driver module for another provider."),
|
|
613
|
+
vercel: explicit("email.driver", "Resend", "Configure the built-in Resend driver.")
|
|
614
|
+
},
|
|
615
|
+
developmentOverrides: [
|
|
616
|
+
"deno",
|
|
617
|
+
"netlify",
|
|
618
|
+
"vercel"
|
|
619
|
+
],
|
|
620
|
+
id: "email",
|
|
621
|
+
packages: ["@vite-hub/email"],
|
|
622
|
+
summary: "Send email from server code and Agents, with a development outbox.",
|
|
623
|
+
title: "Email"
|
|
624
|
+
}),
|
|
625
|
+
env: feature({
|
|
626
|
+
docs: "/docs/env",
|
|
627
|
+
enabledByDefault: true,
|
|
628
|
+
hosts: everywhere("nitro", "Nitro"),
|
|
629
|
+
id: "env",
|
|
630
|
+
summary: "Typed environment variables and secrets, validated at build and at runtime.",
|
|
631
|
+
title: "Env"
|
|
632
|
+
}),
|
|
633
|
+
i18n: feature({
|
|
634
|
+
docs: "/docs/i18n",
|
|
635
|
+
hosts: everywhere("nitro", "Nitro 3", "Requires Nitro 3 with request async context: Nuxt 4.7 or newer with the nitro package, Nuxt 5, or Vite with Nitro 3. On Nuxt 4, use i18n without i18n.workspace. Nitro 2 and Nuxt before 4.7 are unsupported."),
|
|
636
|
+
id: "i18n",
|
|
637
|
+
packages: ["@vite-hub/i18n"],
|
|
638
|
+
requiredOptions: [{
|
|
639
|
+
option: "i18n.locales",
|
|
640
|
+
detail: "Pass a nonempty JSON array of locale names or set locales in your I18n config."
|
|
641
|
+
}],
|
|
642
|
+
summary: "Messages with translation records for each locale and a locale for each request.",
|
|
643
|
+
title: "I18n"
|
|
644
|
+
}),
|
|
645
|
+
kv: feature({
|
|
646
|
+
developmentOverrides: ["netlify"],
|
|
647
|
+
docs: "/docs/kv",
|
|
648
|
+
hosts: {
|
|
649
|
+
cloudflare: native("cloudflare", "Workers KV", "Cloudflare Workers KV binding."),
|
|
650
|
+
deno: native("deno-kv", "Deno KV", "Native Deno KV through Deno.openKv()."),
|
|
651
|
+
dev: native("fs-lite", "fs-lite", "Local filesystem-backed KV for development.", "single-host"),
|
|
652
|
+
netlify: explicit("kv.driver", "Upstash / Redis", "Set `kv.driver` (or `kv.stores.default.driver` when using multiple stores) to `upstash`, `redis`, or `database`, or set Upstash REST credentials at build time. No Netlify-native KV output is provided. Without them, KV uses a Postgres Default Database, else `fs-lite` files that other function instances cannot read."),
|
|
653
|
+
node: native("fs-lite", "Redis / Postgres / fs-lite", "A table in a Postgres Default Database, else local files. Redis requires kv: { driver: 'redis' }; REDIS_URL supplies its URL on every server. Upstash with REST credentials at build time.", "single-host"),
|
|
654
|
+
vercel: native("upstash", "Upstash", "Upstash Redis with KV REST credentials.")
|
|
655
|
+
},
|
|
656
|
+
id: "kv",
|
|
657
|
+
packages: ["@vite-hub/kv"],
|
|
658
|
+
providerPackages: { driver: { upstash: ["@upstash/redis"] } },
|
|
659
|
+
summary: "Key-value storage with one API on every host.",
|
|
660
|
+
title: "KV"
|
|
661
|
+
}),
|
|
662
|
+
mcp: feature({
|
|
663
|
+
docs: "/docs/mcp",
|
|
664
|
+
hosts: everywhere("nitro", "Nitro"),
|
|
665
|
+
id: "mcp",
|
|
666
|
+
packages: ["@vite-hub/mcp"],
|
|
667
|
+
requiredOptions: [{
|
|
668
|
+
option: "mcp.auth",
|
|
669
|
+
detail: "Choose an access mode when Auth is disabled. With Auth enabled, MCP requires sign-in by default. The optional mode requires Auth and lets anyone call public tools. Set false only when anyone may call every tool."
|
|
670
|
+
}],
|
|
671
|
+
summary: "The app's own MCP server, with one tool per file in `server/mcp/tools/`.",
|
|
672
|
+
title: "MCP server"
|
|
673
|
+
}),
|
|
674
|
+
observability: feature({
|
|
675
|
+
docs: "/docs/agents/observability",
|
|
676
|
+
hosts: everywhere("evlog", "Evlog"),
|
|
677
|
+
id: "observability",
|
|
678
|
+
packages: ["evlog"],
|
|
679
|
+
summary: "Request logs through Evlog, the logs that the Console reads, and Agent telemetry with a service name.",
|
|
680
|
+
title: "Observability"
|
|
681
|
+
}),
|
|
682
|
+
queue: feature({
|
|
683
|
+
definition: starter("server/queues", (name) => `import { defineQueue } from "vite-hub/queue"
|
|
684
|
+
|
|
685
|
+
export default defineQueue<{ id: string }>({
|
|
686
|
+
handler: async ({ payload }) => {
|
|
687
|
+
console.log("${name}", payload.id)
|
|
688
|
+
},
|
|
689
|
+
})
|
|
690
|
+
`, { suffix: "queue" }),
|
|
691
|
+
docs: "/docs/queue",
|
|
692
|
+
enabledByDiscovery: ["queues"],
|
|
693
|
+
hosts: {
|
|
694
|
+
cloudflare: native("cloudflare", "Queues", "Cloudflare Queues bindings and consumers."),
|
|
695
|
+
deno: unsupported("No Deno Queue driver is provided."),
|
|
696
|
+
dev: native("local", "Local driver", "The local driver stores jobs in .vitehub/data/queue and runs them in the dev server process.", "single-host"),
|
|
697
|
+
netlify: unsupported("Netlify has no Queue driver, so `vitehub({ queue })` fails on Netlify."),
|
|
698
|
+
node: native("local", "Postgres / local driver", "With a Postgres Default Database, the postgres driver keeps jobs in Postgres and every instance runs them. Else the local driver keeps jobs on the disk of one host.", "single-host"),
|
|
699
|
+
vercel: native("vercel", "Vercel Queues", "Vercel Queues callbacks and runtime client.")
|
|
700
|
+
},
|
|
701
|
+
id: "queue",
|
|
702
|
+
packages: ["@vite-hub/queue"],
|
|
703
|
+
providerPackages: { driver: { postgres: ["postgres"] } },
|
|
704
|
+
service: "queue",
|
|
705
|
+
summary: "Background jobs in `server/queues/` with retries and delivery on every supported host.",
|
|
706
|
+
title: "Queue"
|
|
707
|
+
}),
|
|
708
|
+
rateLimit: feature({
|
|
709
|
+
developmentOverrides: ["cloudflare"],
|
|
710
|
+
docs: "/docs/rate-limit",
|
|
711
|
+
hosts: {
|
|
712
|
+
cloudflare: native("cloudflare", "Cloudflare", "Native Cloudflare Rate Limiting binding."),
|
|
713
|
+
deno: unsupported("ViteHub has no native Deno Rate Limit driver."),
|
|
714
|
+
dev: native("memory", "memory", "Process-local memory driver for development and tests.", "process-local"),
|
|
715
|
+
netlify: unsupported("ViteHub has no native Netlify Rate Limit driver."),
|
|
716
|
+
node: native("memory", "memory, or KV", "Without KV, each process counts alone. With KV on, ViteHub selects the kv provider, which shares the counts when KV uses Redis or a Postgres Database.", "process-local"),
|
|
717
|
+
vercel: native("kv", "KV (Upstash)", "Counts in the default KV store, which is Upstash Redis on Vercel, with one atomic increment for each request. Every function instance shares the counts. `rateLimit: true` turns KV on, which reads `KV_REST_API_URL` and `KV_REST_API_TOKEN`.")
|
|
718
|
+
},
|
|
719
|
+
id: "rateLimit",
|
|
720
|
+
packages: ["@vite-hub/rate-limit"],
|
|
721
|
+
service: "rateLimit",
|
|
722
|
+
summary: "Rate limits in `server/rate-limits/` that protect routes and Agent tools.",
|
|
723
|
+
title: "Rate Limit"
|
|
724
|
+
}),
|
|
725
|
+
realtime: feature({
|
|
726
|
+
definition: starter("server/realtime", (name) => `import { defineRealtime } from "vite-hub/realtime"
|
|
727
|
+
|
|
728
|
+
export default defineRealtime({
|
|
729
|
+
authorize: true,
|
|
730
|
+
document: { workspace: "${name}" },
|
|
731
|
+
})
|
|
732
|
+
`),
|
|
733
|
+
developmentOverrides: [
|
|
734
|
+
"cloudflare",
|
|
735
|
+
"deno",
|
|
736
|
+
"netlify",
|
|
737
|
+
"vercel"
|
|
738
|
+
],
|
|
739
|
+
docs: "/docs/realtime",
|
|
740
|
+
enabledByDiscovery: ["realtime"],
|
|
741
|
+
hosts: {
|
|
742
|
+
cloudflare: native("cloudflare", "Durable Objects", "Cloudflare Durable Objects run the production rooms."),
|
|
743
|
+
deno: unsupported("Realtime has no distributed Deno driver, and process memory is rejected for the Deno host."),
|
|
744
|
+
dev: native("memory", "memory", "Process-memory driver for local development.", "process-local"),
|
|
745
|
+
netlify: unsupported("Realtime has no distributed Netlify driver, and process memory is rejected for the Netlify host."),
|
|
746
|
+
node: native("node", "Postgres or Redis", "Each instance keeps its rooms in memory and shares them through Redis with REDIS_URL or a Redis KV_URL, else Postgres on a Postgres Default Database. Without either, rooms stay in one process."),
|
|
747
|
+
vercel: native("node", "Redis or Postgres", "Vercel Functions serve the WebSockets, and each function instance shares its rooms through Redis with REDIS_URL or the Redis KV_URL of Upstash, else Postgres with REALTIME_POSTGRES_URL or a Postgres Default Database. Without either, the server fails instead of keeping rooms in one instance. A connection closes at the maximum duration of the function, and the client reconnects.")
|
|
748
|
+
},
|
|
749
|
+
id: "realtime",
|
|
750
|
+
packages: ["@vite-hub/realtime"],
|
|
751
|
+
service: "realtime",
|
|
752
|
+
summary: "Shared rooms with presence and Yjs documents.",
|
|
753
|
+
title: "Realtime"
|
|
754
|
+
}),
|
|
755
|
+
sandboxTask: feature({
|
|
756
|
+
developmentOverrides: ["cloudflare", "vercel"],
|
|
757
|
+
docs: "/docs/sandbox",
|
|
758
|
+
hosts: {
|
|
759
|
+
cloudflare: native("cloudflare", "CF Sandbox", "Cloudflare Sandbox execution provider."),
|
|
760
|
+
deno: unsupported("No Deno Sandbox driver is provided."),
|
|
761
|
+
dev: native("container", "Docker", "`vite dev` runs each Sandbox Task in a local Docker container. Without Docker, the run fails with a fix. `sandboxTask: { remote: true }` uses the host's Sandbox instead, and `unsafeHostProcess: true` runs trusted tasks on this machine with no isolation.", "single-host"),
|
|
762
|
+
netlify: explicit("sandboxTask.driver", "Vercel Sandbox", "The Netlify host has no Sandbox, so `sandboxTask: true` fails. Set `sandboxTask: { driver: \"vercel\" }` and Vercel credentials to use Vercel Sandbox."),
|
|
763
|
+
node: native("container", "Docker", "Each run starts a Docker container on the daemon that the `docker` CLI reaches. In the generated Docker image, mount `/var/run/docker.sock` or set `DOCKER_HOST`. `sandboxTask: { driver: \"vercel\" }` uses Vercel Sandbox instead.", "single-host"),
|
|
764
|
+
vercel: native("vercel", "Vercel Sandbox", "Vercel Sandbox execution provider.")
|
|
765
|
+
},
|
|
766
|
+
id: "sandboxTask",
|
|
767
|
+
packages: ["@vite-hub/sandbox"],
|
|
768
|
+
service: "sandbox",
|
|
769
|
+
summary: "Sandbox Tasks in `server/sandbox-tasks/`. Each run starts an isolated Cloudflare Sandbox, Vercel Sandbox, or Docker container.",
|
|
770
|
+
title: "Sandbox"
|
|
771
|
+
}),
|
|
772
|
+
schedule: feature({
|
|
773
|
+
definition: starter("server/schedules", (name) => `import { defineSchedule } from "vite-hub/schedule"
|
|
774
|
+
|
|
775
|
+
export default defineSchedule({
|
|
776
|
+
cron: "0 * * * *",
|
|
777
|
+
handler: () => {
|
|
778
|
+
console.log("${name}")
|
|
779
|
+
},
|
|
780
|
+
})
|
|
781
|
+
`, { suffix: "schedule" }),
|
|
782
|
+
developmentOverrides: [
|
|
783
|
+
"cloudflare",
|
|
784
|
+
"netlify",
|
|
785
|
+
"vercel"
|
|
786
|
+
],
|
|
787
|
+
docs: "/docs/schedule",
|
|
788
|
+
enabledByDiscovery: ["schedules"],
|
|
789
|
+
hosts: {
|
|
790
|
+
cloudflare: native("cloudflare", "Cron triggers", "Cloudflare scheduled events and Nitro Provider Wake."),
|
|
791
|
+
deno: native("deno", "Deno.cron", "`Deno.cron` output that the generated `.output/main.ts` loads before the Nitro server."),
|
|
792
|
+
dev: native("local", "Local / process", "Local development runner and the explicit process runtime.", "single-host"),
|
|
793
|
+
netlify: native("netlify", "Scheduled fn", "One generated Netlify scheduled function per static Schedule."),
|
|
794
|
+
node: native("process", "process", "Process runtime in the server process. `schedule: true` uses it. Set `providerOutput: false` to wake Schedules yourself. With a Postgres or remote libSQL Default Database, servers claim occurrences in `vitehub_leases`. A run can repeat if its lease expires. Without a shared lease store, run one server.", "single-host"),
|
|
795
|
+
vercel: native("vercel", "Vercel Cron", "Vercel Cron Jobs provider output.")
|
|
796
|
+
},
|
|
797
|
+
id: "schedule",
|
|
798
|
+
packages: ["@vite-hub/schedule"],
|
|
799
|
+
summary: "Cron Schedules in `server/schedules/` that run on the host's scheduler.",
|
|
800
|
+
title: "Schedule"
|
|
801
|
+
}),
|
|
802
|
+
workflow: feature({
|
|
803
|
+
definition: starter("server/workflows", () => `import { defineWorkflow } from "vite-hub/workflow"
|
|
804
|
+
|
|
805
|
+
export default defineWorkflow<{ id: string }>({
|
|
806
|
+
handler: async ({ payload }) => {
|
|
807
|
+
return { id: payload.id }
|
|
808
|
+
},
|
|
809
|
+
})
|
|
810
|
+
`, {
|
|
811
|
+
folder: "index",
|
|
812
|
+
suffix: "workflow"
|
|
813
|
+
}),
|
|
814
|
+
docs: "/docs/workflows",
|
|
815
|
+
enabledByDiscovery: ["workflows"],
|
|
816
|
+
hosts: {
|
|
817
|
+
cloudflare: native("cloudflare", "CF Workflows", "Cloudflare Workflows provider."),
|
|
818
|
+
deno: explicit("workflow.driver", "OpenWorkflow", "Set `workflow.driver` to \"openworkflow\" with `workflow.postgres.url`, and start its worker. A build without a driver fails."),
|
|
819
|
+
dev: native("openworkflow", "OpenWorkflow", "The Node host runs OpenWorkflow and its worker in the dev server, on .vitehub/data/openworkflow.sqlite.db. workflow.remote lets it use the Postgres Default Database or OPENWORKFLOW_POSTGRES_URL."),
|
|
820
|
+
netlify: explicit("workflow.driver", "OpenWorkflow", "Use OpenWorkflow explicitly. No Netlify-native Workflow driver is provided."),
|
|
821
|
+
node: {
|
|
822
|
+
...native("openworkflow", "OpenWorkflow", "OpenWorkflow is the default, and each server runs its worker. It uses OPENWORKFLOW_POSTGRES_URL or the Postgres Default Database. Without them, runs use a SQLite file on one host.", "single-host"),
|
|
823
|
+
envOverrides: ["OPENWORKFLOW_POSTGRES_URL"].map((env) => ({
|
|
824
|
+
env,
|
|
825
|
+
support: native("openworkflow", "OpenWorkflow (Postgres)", `${env} selects Postgres. Several servers can run the worker on the same database, and each run executes once.`)
|
|
826
|
+
}))
|
|
827
|
+
},
|
|
828
|
+
vercel: native("vercel", "Vercel Workflow", "Vercel Workflow provider and Workflow DevKit output.")
|
|
829
|
+
},
|
|
830
|
+
id: "workflow",
|
|
831
|
+
packages: ["@vite-hub/workflow"],
|
|
832
|
+
summary: "Durable Workflows in `server/workflows/` with steps and driver retries.",
|
|
833
|
+
title: "Workflow"
|
|
834
|
+
}),
|
|
835
|
+
workspace: feature({
|
|
836
|
+
developmentOverrides: [
|
|
837
|
+
"cloudflare",
|
|
838
|
+
"deno",
|
|
839
|
+
"netlify",
|
|
840
|
+
"vercel"
|
|
841
|
+
],
|
|
842
|
+
docs: "/docs/workspace",
|
|
843
|
+
enabledByDiscovery: ["workspaces"],
|
|
844
|
+
hosts: {
|
|
845
|
+
cloudflare: native("memory", "Artifacts / GitHub", "Memory by default, or Cloudflare Artifacts beta and GitHub for durable state.", "process-local"),
|
|
846
|
+
deno: explicit("workspace.store", "GitHub", "Select the GitHub Workspace Store explicitly for durable state."),
|
|
847
|
+
dev: native("local", "local / memory", "Local filesystem or in-memory Workspace Store.", "single-host"),
|
|
848
|
+
netlify: explicit("workspace.store", "GitHub", "Select the GitHub Workspace Store explicitly for durable state."),
|
|
849
|
+
node: native("local", "local / GitHub", "Local filesystem, memory, or GitHub Workspace Store.", "single-host"),
|
|
850
|
+
vercel: {
|
|
851
|
+
...native("memory", "memory / Blob / GitHub", "Process-local memory by default. BLOB_READ_WRITE_TOKEN selects Vercel Blob; GitHub can be selected explicitly for durable state.", "process-local"),
|
|
852
|
+
envOverrides: [{
|
|
853
|
+
env: "BLOB_READ_WRITE_TOKEN",
|
|
854
|
+
support: native("vercel", "Blob / GitHub", "BLOB_READ_WRITE_TOKEN selects durable Vercel Blob storage by default.")
|
|
855
|
+
}]
|
|
856
|
+
}
|
|
857
|
+
},
|
|
858
|
+
id: "workspace",
|
|
859
|
+
packages: ["@vite-hub/workspace"],
|
|
860
|
+
summary: "File workspaces that Agents read and edit, backed by local, Blob, or GitHub stores.",
|
|
861
|
+
title: "Workspace"
|
|
862
|
+
})
|
|
863
|
+
};
|
|
864
|
+
/** Packages needed by a feature, its provider, and its enabled feature integrations. */
|
|
865
|
+
function featurePackages(id, value, host, enabled = []) {
|
|
866
|
+
const definition = features[id];
|
|
867
|
+
const options = value && typeof value === "object" && !Array.isArray(value) ? value : void 0;
|
|
868
|
+
const stores = options?.stores;
|
|
869
|
+
const selected = ((id === "blob" || id === "kv") && stores && typeof stores === "object" && !Array.isArray(stores) ? [value, ...Object.values(stores)] : [value]).flatMap((value) => Object.entries(definition.providerPackages ?? {}).flatMap(([key, choices]) => {
|
|
870
|
+
const choice = value && typeof value === "object" && !Array.isArray(value) ? Reflect.get(value, key) : void 0;
|
|
871
|
+
return typeof choice === "string" ? choices[choice] ?? [] : [];
|
|
872
|
+
}));
|
|
873
|
+
if (id === "observability" && typeof options?.service === "string") selected.push("@vite-hub/agent");
|
|
874
|
+
if (id === "observability" && options?.posthog) selected.push("posthog-node");
|
|
875
|
+
const sandboxDriver = typeof options?.driver === "string" ? options.driver : host;
|
|
876
|
+
if (id === "sandboxTask" && (sandboxDriver === "vercel" || sandboxDriver === "cloudflare")) selected.push(sandboxDriverPackages[sandboxDriver]);
|
|
877
|
+
if ((id === "queue" || id === "workflow") && host === "vercel" && (options?.driver ?? "vercel") === "vercel") selected.push(...vercelProviderPackages[id]);
|
|
878
|
+
if (id === "email" && options?.driver === "smtp" && host !== "cloudflare") selected.push(...ownerCheckedPackages.email ?? []);
|
|
879
|
+
if (id === "console" && enabled.includes("agent")) selected.push(...consoleFeaturePackages.agents);
|
|
880
|
+
return [.../* @__PURE__ */ new Set([...definition.packages, ...selected])];
|
|
881
|
+
}
|
|
882
|
+
const ownerCheckedPackages = { email: ["nodemailer"] };
|
|
883
|
+
const sandboxDriverPackages = {
|
|
884
|
+
cloudflare: "@cloudflare/sandbox",
|
|
885
|
+
vercel: "@vercel/sandbox"
|
|
886
|
+
};
|
|
887
|
+
/**
|
|
888
|
+
* The SDKs of the Vercel provider. Native Vercel Workflows also need `workflow` and `@workflow/builders`, but only
|
|
889
|
+
* `@vite-hub/workflow` knows when a Workflow is native, so it checks those two itself.
|
|
890
|
+
*/
|
|
891
|
+
const vercelProviderPackages = {
|
|
892
|
+
queue: ["@vercel/queue", "@vercel/functions"],
|
|
893
|
+
workflow: ["@vercel/functions"]
|
|
894
|
+
};
|
|
895
|
+
const drizzleRange = "1.0.0-rc.5 || 1.0.0-rc.6 || ^1.0.0";
|
|
896
|
+
const installRanges = {
|
|
897
|
+
"drizzle-kit": drizzleRange,
|
|
898
|
+
"drizzle-orm": drizzleRange
|
|
899
|
+
};
|
|
900
|
+
/**
|
|
901
|
+
* The package manager argument that installs `name`, such as `drizzle-orm@1.0.0-rc.5 || 1.0.0-rc.6 || ^1.0.0`. Drizzle tags 0.x as
|
|
902
|
+
* `latest` and the next 1.0 candidate as `rc`, so a plain name installs a version that ViteHub cannot import. npm saves
|
|
903
|
+
* the range as written, and an exact version would be saved as `^1.0.0-rc.5`, which also matches later candidates.
|
|
904
|
+
* Other packages keep their name. Feature catalogs, status, and removal use the plain name.
|
|
905
|
+
*/
|
|
906
|
+
function installSpecifier(name) {
|
|
907
|
+
const range = installRanges[name];
|
|
908
|
+
return range ? `${name}@${range}` : name;
|
|
909
|
+
}
|
|
910
|
+
function quoteSupportedInstallSpecifier(value) {
|
|
911
|
+
const separator = value.indexOf("@", 1);
|
|
912
|
+
if (separator < 0) return void 0;
|
|
913
|
+
const name = value.slice(0, separator);
|
|
914
|
+
return Object.hasOwn(installRanges, name) && value === installSpecifier(name) ? `"${value}"` : void 0;
|
|
915
|
+
}
|
|
916
|
+
function formatInstallArgument(value) {
|
|
917
|
+
return quoteSupportedInstallSpecifier(value) ?? (/^[\w@%+=:,./-]+$/u.test(value) ? value : `'${value.replaceAll("'", `'\\''`)}'`);
|
|
918
|
+
}
|
|
919
|
+
/** Additional Console owners selected by its enabled Agent integration. */
|
|
920
|
+
const consoleFeaturePackages = { agents: ["@libsql/client", "drizzle-orm"] };
|
|
921
|
+
function featureSupport(id, host, appHost) {
|
|
922
|
+
const definition = features[id];
|
|
923
|
+
if (host !== "dev") return definition.hosts[host];
|
|
924
|
+
invariant(appHost, "every caller of featureSupport() for the dev host passes the configured ViteHub host");
|
|
925
|
+
if (id === "workflow" && appHost === "deno") return native("vercel", "Inline", "Development runs each Workflow inline unless OpenWorkflow storage or a provider is configured.", "process-local");
|
|
926
|
+
return definition.hosts[appHost === "node" || definition.developmentOverrides?.includes(appHost) ? "dev" : appHost];
|
|
927
|
+
}
|
|
928
|
+
/**
|
|
929
|
+
* The features that `enabled` turn on through implications, without the ones already in `enabled`.
|
|
930
|
+
* This follows implications transitively.
|
|
931
|
+
* `disabled` lists features that the app sets to `false`; an implication never turns them on.
|
|
932
|
+
*/
|
|
933
|
+
function impliedFeatures(enabled, disabled = []) {
|
|
934
|
+
const on = new Set(enabled);
|
|
935
|
+
const implied = [];
|
|
936
|
+
const pending = [...enabled];
|
|
937
|
+
while (pending.length) {
|
|
938
|
+
const id = pending.shift();
|
|
939
|
+
for (const implication of features[id].implies) {
|
|
940
|
+
if (on.has(implication.feature) || disabled.includes(implication.feature)) continue;
|
|
941
|
+
on.add(implication.feature);
|
|
942
|
+
implied.push(implication.feature);
|
|
943
|
+
pending.push(implication.feature);
|
|
944
|
+
}
|
|
945
|
+
}
|
|
946
|
+
return implied;
|
|
947
|
+
}
|
|
948
|
+
// ../internal/dist/vite-stage.js
|
|
949
|
+
/**
|
|
950
|
+
* Vite's `loadEnv(mode, envDir, "")`: every `.env` value of the mode and the whole shell. With `DEBUG=vite:env`, Vite
|
|
951
|
+
* logs that result to stderr, secrets included. loadEnv is synchronous, so this drops only the writes of this call.
|
|
952
|
+
*/
|
|
953
|
+
function loadAllEnv(loadEnv, mode, envDir) {
|
|
954
|
+
const write = process.stderr.write;
|
|
955
|
+
process.stderr.write = () => true;
|
|
956
|
+
try {
|
|
957
|
+
return loadEnv(mode, envDir, "");
|
|
958
|
+
} finally {
|
|
959
|
+
process.stderr.write = write;
|
|
960
|
+
}
|
|
961
|
+
}
|
|
962
|
+
const viteStageQueueKey = Symbol.for("vitehub.cli.vite-stage-queue");
|
|
963
|
+
function definedEntries(env) {
|
|
964
|
+
return Object.entries(env).filter((entry) => entry[1] !== void 0);
|
|
965
|
+
}
|
|
966
|
+
function replaceProcessEnv(entries) {
|
|
967
|
+
for (const key of Object.keys(process.env)) delete process.env[key];
|
|
968
|
+
for (const [key, value] of entries) process.env[key] = value;
|
|
969
|
+
}
|
|
970
|
+
/** Load stage config and modules under the same serialized, temporary process environment. */
|
|
971
|
+
async function withViteStageEnvironment(env, callback) {
|
|
972
|
+
const carrier = globalThis;
|
|
973
|
+
const previous = carrier[viteStageQueueKey] ?? Promise.resolve();
|
|
974
|
+
let release;
|
|
975
|
+
carrier[viteStageQueueKey] = new Promise((resolve) => {
|
|
976
|
+
release = resolve;
|
|
977
|
+
});
|
|
978
|
+
await previous;
|
|
979
|
+
const previousEnvironment = definedEntries(process.env);
|
|
980
|
+
const selectedEnvironment = definedEntries(env);
|
|
981
|
+
try {
|
|
982
|
+
replaceProcessEnv(selectedEnvironment);
|
|
983
|
+
return await callback();
|
|
984
|
+
} finally {
|
|
985
|
+
replaceProcessEnv(previousEnvironment);
|
|
986
|
+
release();
|
|
987
|
+
}
|
|
988
|
+
}
|
|
989
|
+
// src/error-diagnostics.ts
|
|
990
|
+
const dynamicError = { why: ({ message }) => message === void 0 ? "" : String(message) };
|
|
991
|
+
const cliErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
|
|
992
|
+
docsBase: "https://vitehub.dev/docs/cli/diagnostics",
|
|
993
|
+
codes: {
|
|
994
|
+
CLI_CONSOLE_LOGIN_FAILED: {
|
|
995
|
+
fix: "Run `vitehub login` again, and approve the code in the browser within 15 minutes. Pass --console <url> for a self-hosted Console.",
|
|
996
|
+
why: ({ console, message }) => `Sign-in to ${String(console)} did not finish. ${String(message)}`
|
|
997
|
+
},
|
|
998
|
+
CLI_CONSOLE_REQUEST_FAILED: {
|
|
999
|
+
fix: ({ fix }) => typeof fix === "string" ? fix : "Check that you are an owner or admin of the team, and that the key opens the app. Run `vitehub whoami` to see both.",
|
|
1000
|
+
why: ({ code, console, message }) => `${String(console)} refused the request (${String(code)}). ${String(message)}`
|
|
1001
|
+
},
|
|
1002
|
+
CLI_CONSOLE_SIGNED_OUT: {
|
|
1003
|
+
fix: "Run `vitehub login`, or set VITEHUB_CONSOLE_TOKEN to an API key from Account settings in the Console.",
|
|
1004
|
+
why: ({ console }) => `There is no valid API key for ${String(console)}. The key is missing, expired, or revoked.`
|
|
1005
|
+
},
|
|
1006
|
+
CLI_ENV_FILE_EXISTS: {
|
|
1007
|
+
fix: ({ file }) => `Pass --yes to replace ${String(file)}, or move it first.`,
|
|
1008
|
+
why: ({ file }) => `${String(file)} exists. \`vitehub env pull\` does not replace a file without --yes.`
|
|
1009
|
+
},
|
|
1010
|
+
CLI_ENV_FILE_NOT_IGNORED: {
|
|
1011
|
+
fix: ({ file, tracked }) => tracked ? `Run \`git rm --cached ${String(file)}\` and add \`.env.*\` to .gitignore, then pull again.` : `Run \`echo '.env.*' >> .gitignore\`, then pull again.`,
|
|
1012
|
+
why: ({ file, tracked }) => tracked ? `git tracks ${String(file)}, so the values would be committed.` : `${String(file)} is not in .gitignore, so the values could be committed.`
|
|
1013
|
+
},
|
|
1014
|
+
CLI_ENV_PULL_FAILED: {
|
|
1015
|
+
fix: "Check that the Console stores env values, that the key opens the project, and that you are an owner or admin of the team.",
|
|
1016
|
+
why: ({ code, message }) => `The Console refused the pull (${String(code)}). ${String(message)}`
|
|
1017
|
+
},
|
|
1018
|
+
CLI_HOST_RESPONSE_INVALID: {
|
|
1019
|
+
fix: "Run the command again. If the error stays, check the status page of the host and update `@vite-hub/cli`.",
|
|
1020
|
+
why: ({ host }) => `[vitehub] The ${host} API returned an unexpected response.`
|
|
1021
|
+
},
|
|
1022
|
+
CLI_OPERATIONS_LOAD_FAILED: {
|
|
1023
|
+
fix: "Fix the error in the module or in a module that it imports, and make the export hold defineOperation() results. The CLI loads the module with Vite outside the server build, so import server-only modules, such as Nitro virtual modules, inside `run`.",
|
|
1024
|
+
why: ({ export: name, module, plugin, reason }) => `The CLI could not read the operations of ${String(plugin)} from the \`${String(name)}\` export of ${String(module)}, so their commands are missing. ${String(reason)}`
|
|
1025
|
+
},
|
|
1026
|
+
CLI_R0001: {
|
|
1027
|
+
...dynamicError,
|
|
1028
|
+
fix: "Install `nuxt` in the project, such as with `pnpm add nuxt`, then run the command again."
|
|
1029
|
+
},
|
|
1030
|
+
CLI_R0002: {
|
|
1031
|
+
...dynamicError,
|
|
1032
|
+
fix: "Install `@vite-hub/cli` again, such as with `pnpm add -D @vite-hub/cli`."
|
|
1033
|
+
},
|
|
1034
|
+
CLI_R0003: {
|
|
1035
|
+
fix: "Run the command with --help to see its input.",
|
|
1036
|
+
why: ({ message }) => message === void 0 ? "" : String(message)
|
|
1037
|
+
},
|
|
1038
|
+
CLI_R0005: {
|
|
1039
|
+
fix: "Start the dev server in this project (`nuxt dev` or `vite dev`), or pass `--url <origin>` of a running or deployed app. `VITEHUB_DEV_SERVER_URL` also names a server.",
|
|
1040
|
+
why: ({ message }) => message === void 0 ? "" : String(message)
|
|
1041
|
+
},
|
|
1042
|
+
CLI_SETUP_FAILED: {
|
|
1043
|
+
fix: "Fix the cause that the message names, then run the command again.",
|
|
1044
|
+
why: ({ message }) => message
|
|
1045
|
+
},
|
|
1046
|
+
CLI_UPDATE_INSTALL_FAILED: {
|
|
1047
|
+
fix: ({ command }) => `The package files already name the new versions. Fix the cause that the package manager printed, then run \`${String(command)}\`. To undo the update, restore the changed files with git.`,
|
|
1048
|
+
why: ({ command, exitCode }) => `\`${String(command)}\` exited with code ${String(exitCode)}.`
|
|
1049
|
+
},
|
|
1050
|
+
CLI_UPDATE_NO_PACKAGES: {
|
|
1051
|
+
fix: "Run `vitehub update` in the folder of the app or of the workspace that installs `vite-hub`. To start, run `pnpm add vite-hub`.",
|
|
1052
|
+
why: ({ root }) => `No package.json in ${String(root)} or its workspace packages names \`vite-hub\` or an \`@vite-hub/*\` package with a version or a pkg.pr.new URL.`
|
|
1053
|
+
},
|
|
1054
|
+
CLI_UPDATE_PACKAGE_MISSING: {
|
|
1055
|
+
fix: ({ target }) => String(target) === "npm" ? "Pass --preview <commit> to use a pkg.pr.new build that has these packages, or remove them from package.json." : "Pass the commit of a build that has these packages, such as a newer commit of main, or remove them from package.json.",
|
|
1056
|
+
why: ({ packages, target }) => `The project depends on ${String(packages)}, which ${String(target)} does not have. Nothing was changed.`
|
|
1057
|
+
},
|
|
1058
|
+
CLI_UPDATE_REQUEST_FAILED: {
|
|
1059
|
+
fix: "Check the network and the npm registry in `npm_config_registry`, then run `vitehub update` again.",
|
|
1060
|
+
why: ({ status, url }) => `The request to ${String(url)} failed (${String(status)}). Nothing was changed.`
|
|
1061
|
+
},
|
|
1062
|
+
SETUP_CONFIG_NOT_LITERAL: {
|
|
1063
|
+
fix: "Write the options as an object literal, such as `vitehub({ kv: true })`, or edit the config by hand.",
|
|
1064
|
+
why: ({ file, reason }) => `The vitehub() options in ${String(file)} cannot be read without running the config (${String(reason)}).`
|
|
1065
|
+
},
|
|
1066
|
+
SETUP_LOGS_OPTION_MOVED: {
|
|
1067
|
+
why: "`observability.logs` is no longer a ViteHub option.",
|
|
1068
|
+
fix: "Remove the option from the command. Configure the top-level `logs` key by hand, for example `logs: { source: './server/logs.ts' }` to set `logs.source`."
|
|
1069
|
+
},
|
|
1070
|
+
SETUP_NOT_A_PROJECT: {
|
|
1071
|
+
fix: "Run the command in the folder of your Vite or Nuxt app, where its package.json is.",
|
|
1072
|
+
why: ({ root }) => `${String(root)} has no package.json, vite.config, or nuxt.config file.`
|
|
1073
|
+
},
|
|
1074
|
+
SETUP_CONFIG_MANUAL: {
|
|
1075
|
+
fix: ({ fix, snippet }) => fix ?? `Add these keys to the vitehub() options by hand:\n${String(snippet)}`,
|
|
1076
|
+
why: ({ file, reason }) => `ViteHub cannot edit the vitehub() options in ${String(file)} without running the config (${String(reason)}).`
|
|
1077
|
+
},
|
|
1078
|
+
SETUP_FEATURE_UNSUPPORTED: {
|
|
1079
|
+
fix: "Remove the feature from the command, or set `host` to a host that supports it. Run `vitehub catalog` to compare hosts.",
|
|
1080
|
+
why: ({ detail, feature, host }) => `${String(feature)} is not supported on the ${String(host)} host. ${String(detail)}`
|
|
1081
|
+
},
|
|
1082
|
+
SETUP_FILE_EXISTS: {
|
|
1083
|
+
fix: "Choose another --name, or edit the file by hand.",
|
|
1084
|
+
why: ({ definition, file, starter }) => starter === void 0 ? `${String(file)} exists and is not the starter Definition. ViteHub never overwrites a file.` : `${String(file)} already defines a ${String(definition)} Definition that conflicts with ${String(starter)}, so the build would reject both.`
|
|
1085
|
+
},
|
|
1086
|
+
SETUP_SERVER_DIR_MANUAL: {
|
|
1087
|
+
fix: ({ command }) => command === "remove" ? "Pass --force to turn the features off without checking unresolved Definition files, or use literal directory options without layers or directory overrides." : "Create the Definition in your evaluated Nuxt server directory and rerun without --name, or use literal directory options without layers or directory overrides.",
|
|
1088
|
+
why: "ViteHub cannot determine the Nuxt application server directory without running the config."
|
|
1089
|
+
},
|
|
1090
|
+
SETUP_INPUT_NEEDED: {
|
|
1091
|
+
fix: ({ fix, rerun }) => fix ?? (rerun ? "Run the `rerun` command, or pass the missing values with --option." : "Pass the missing values, then run the command again."),
|
|
1092
|
+
why: ({ message }) => message === void 0 ? "" : String(message)
|
|
1093
|
+
},
|
|
1094
|
+
SETUP_INSTALL_FAILED: {
|
|
1095
|
+
fix: ({ filesWritten, ignored, workspaceFile }) => `${ignored?.length && workspaceFile ? `pnpm stopped at the build scripts of ${ignored.map((name) => `\`${name}\``).join(", ")}. Review their \`allowBuilds\` entries in \`${workspaceFile}\`: use \`false\` to skip a build script or \`true\` to run it, or run \`pnpm approve-builds\`. Then run the command again.` : "Read the package manager error above, fix it, then run the command again."} ${filesWritten === "possible" ? "Scaffolding may have left new app files on disk; inspect the target folder before retrying." : filesWritten ? "The new app files were written before installation failed; keep them when retrying." : "ViteHub did not write starter or config files; the package manager may have changed package manifests or lockfiles."}`,
|
|
1096
|
+
why: ({ command, exitCode, output }) => `\`${String(command)}\` exited with code ${String(exitCode)}.${output ? `\n${output}` : ""}`
|
|
1097
|
+
},
|
|
1098
|
+
SETUP_FEATURE_IMPLIED: {
|
|
1099
|
+
fix: ({ by, feature }) => `Remove ${String(by)} too, or pass --force to write \`${String(feature)}: false\`.`,
|
|
1100
|
+
why: ({ by, feature }) => `${String(feature)} stays on because ${String(by)} turns it on.`
|
|
1101
|
+
},
|
|
1102
|
+
SETUP_FEATURE_REQUIRED: {
|
|
1103
|
+
fix: ({ by, feature }) => `Remove ${String(by)} too, or change its options before removing ${String(feature)}. --force cannot remove a required feature.`,
|
|
1104
|
+
why: ({ by, feature }) => `${String(feature)} is required by the configured options of ${String(by)}.`
|
|
1105
|
+
},
|
|
1106
|
+
SETUP_FEATURE_IN_USE: {
|
|
1107
|
+
fix: "Delete or move the files in `references`, then run the command again. Pass --force to turn the feature off and keep the files.",
|
|
1108
|
+
why: ({ features, references }) => `The app still uses ${String(features)}:\n${String(references)}`
|
|
1109
|
+
},
|
|
1110
|
+
SETUP_UNINSTALL_FAILED: {
|
|
1111
|
+
fix: ({ configWritten }) => `Run the uninstall command by hand to see the error. ${configWritten === false ? "ViteHub kept the config unchanged; starter files may already be deleted. Plan the removal again after fixing the uninstall." : "ViteHub already changed the config and deleted the starter files."}`,
|
|
1112
|
+
why: ({ command, exitCode }) => `\`${String(command)}\` exited with code ${String(exitCode)}.`
|
|
1113
|
+
},
|
|
1114
|
+
SETUP_PLAN_UNKNOWN: {
|
|
1115
|
+
fix: "Plan the change again. A plan applies once, and only on the dev server that made it.",
|
|
1116
|
+
why: () => "The dev server has no plan with this id. It was applied already, or the server restarted."
|
|
1117
|
+
},
|
|
1118
|
+
SETUP_STALE_PLAN: {
|
|
1119
|
+
fix: "Run the command again to plan from the current file.",
|
|
1120
|
+
why: ({ file }) => `${String(file)} changed after ViteHub planned the change.`
|
|
1121
|
+
},
|
|
1122
|
+
SETUP_LINK_HOST_UNSUPPORTED: {
|
|
1123
|
+
fix: "Pass --host cloudflare, vercel, netlify, or deno, or set `host` in vitehub().",
|
|
1124
|
+
why: ({ host }) => `The ${String(host)} host has no project to link. A self-hosted Node server needs no link.`
|
|
1125
|
+
},
|
|
1126
|
+
SETUP_LINK_CREDENTIALS_MISSING: {
|
|
1127
|
+
fix: ({ fix }) => fix === void 0 ? "Log in with the host CLI, such as `npx wrangler login`, or set the host token, such as CLOUDFLARE_API_TOKEN, VERCEL_TOKEN, NETLIFY_AUTH_TOKEN, or DENO_DEPLOY_TOKEN, then run the command again." : String(fix),
|
|
1128
|
+
why: ({ host }) => `No ${String(host)} credentials were found in the environment or in the host CLI login.`
|
|
1129
|
+
},
|
|
1130
|
+
SETUP_LINK_ACCOUNT_REQUIRED: {
|
|
1131
|
+
fix: "Run the command again with --account <id>, using one of the account ids in `missing`.",
|
|
1132
|
+
why: ({ count }) => Number(count) === 0 ? "The Cloudflare token has access to no account." : `The Cloudflare token has access to ${String(count)} accounts, so the account to link is not clear.`
|
|
1133
|
+
},
|
|
1134
|
+
SETUP_LINK_HOST_REQUIRED: {
|
|
1135
|
+
fix: ({ command }) => `Run \`${String(command)} --host <host>\`, or make one host the default with \`vitehub link --host <host> --default\`.`,
|
|
1136
|
+
why: ({ hosts }) => `The project links several hosts (${String(hosts)}) and none is the default, so the host is not clear.`
|
|
1137
|
+
},
|
|
1138
|
+
SETUP_LINK_NAME_REQUIRED: {
|
|
1139
|
+
fix: "Pass --project <name>, or set `name` in vitehub() or in package.json.",
|
|
1140
|
+
why: () => "The project name is not known. vitehub() has no literal `name` and package.json has no name."
|
|
1141
|
+
},
|
|
1142
|
+
SETUP_LINK_PROJECT_NOT_FOUND: {
|
|
1143
|
+
fix: ({ host, rerun }) => host === "deno" ? "Create the app in Deno Deploy first, then run `vitehub link --host deno`, or pass --project with the name of an existing app." : `Run \`${String(rerun)}\` to create it, or pass --project with the name of a project that exists.`,
|
|
1144
|
+
why: ({ host, project, account }) => `The ${String(host)} project ${JSON.stringify(String(project))} does not exist${account ? ` in account ${String(account)}` : ""}.`
|
|
1145
|
+
},
|
|
1146
|
+
SETUP_INIT_DIR_NOT_EMPTY: {
|
|
1147
|
+
fix: "Choose a new or empty folder, or run `vitehub init` on the folder of a Vite or Nuxt app.",
|
|
1148
|
+
why: ({ dir }) => `${String(dir)} is not empty and holds no Vite or Nuxt app. ViteHub never overwrites a file.`
|
|
1149
|
+
},
|
|
1150
|
+
SETUP_INIT_FRAMEWORK_MISMATCH: {
|
|
1151
|
+
fix: ({ found }) => `Pass --framework ${String(found)}, or choose another folder.`,
|
|
1152
|
+
why: ({ dir, found, framework }) => `${String(dir)} holds a ${String(found)} app, not a ${String(framework)} app.`
|
|
1153
|
+
},
|
|
1154
|
+
SETUP_INIT_HOST_MIGRATION: {
|
|
1155
|
+
fix: "Use the app's current host, or migrate its enabled features, providers and Definitions in the config before running init again.",
|
|
1156
|
+
why: ({ host }) => `init cannot change an enabled ViteHub stack to the ${String(host)} host.`
|
|
1157
|
+
},
|
|
1158
|
+
SETUP_INIT_NITRO_VERSION: {
|
|
1159
|
+
fix: ({ dir, range, scaffolded }) => `${scaffolded ? `The scaffold files remain in ${String(dir)}. ` : ""}Set nitro to \`${String(range)}\` in each section of package.json that declares it, then run init again.`,
|
|
1160
|
+
why: ({ dir, range }) => `${String(dir)} declares a Nitro version that init cannot verify against Nuxt 4.7's requirement (${String(range)}). ViteHub did not adopt it.`
|
|
1161
|
+
},
|
|
1162
|
+
SETUP_INIT_NUXT_VERSION: {
|
|
1163
|
+
fix: ({ dir, scaffolded }) => `${scaffolded ? `The scaffold files remain in ${String(dir)}. ` : ""}Upgrade to Nuxt 4.7 with Nitro 3 (\`pnpm add nuxt@^4.7.0 nitro\`), or set nuxt to a Nuxt 5 version. Then run init on that folder again.`,
|
|
1164
|
+
why: ({ dir }) => `${String(dir)} does not declare a supported Nuxt version. ViteHub needs Nitro 3, which runs on Nuxt 4.7 with the nitro package, or on Nuxt 5. ViteHub did not adopt it.`
|
|
1165
|
+
},
|
|
1166
|
+
SETUP_DEPLOY_HOST_UNSUPPORTED: {
|
|
1167
|
+
fix: ({ host }) => host === "node" ? "Run the Node server yourself. A production build writes `.output/Dockerfile` by default. Run `docker build -t <name> .output`, then start the container with `docker run` as shown in the Dockerfile. Or run `node .output/server/index.mjs` directly. Then run `vitehub apps link <url>` with the public URL to link the app in the Console. To use `vitehub deploy` instead, set `host` in vitehub() to cloudflare, vercel, netlify, or deno." : "Run `vitehub deploy --host <host>` with your intended provider: cloudflare, vercel, netlify, or deno.",
|
|
1168
|
+
why: ({ host }) => host === "unknown" ? "`vitehub deploy` could not determine the host from the project config." : `\`vitehub deploy\` has no upload for the ${String(host)} host.`
|
|
1169
|
+
},
|
|
1170
|
+
SETUP_DEPLOY_CREDENTIALS_MISSING: {
|
|
1171
|
+
fix: ({ fix }) => fix === void 0 ? "Log in with the host CLI, such as `npx wrangler login`, or set the host token, such as CLOUDFLARE_API_TOKEN, VERCEL_TOKEN, NETLIFY_AUTH_TOKEN, or DENO_DEPLOY_TOKEN, then run the command again." : String(fix),
|
|
1172
|
+
why: ({ host }) => `No ${String(host)} credentials were found in the environment or in the host CLI login.`
|
|
1173
|
+
},
|
|
1174
|
+
SETUP_DEPLOY_D1_DATABASE_ID_MISSING: {
|
|
1175
|
+
fix: ({ wranglerOwned }) => wranglerOwned ? "Set `database_id` to the ID of an existing D1 database in the Wrangler binding and rebuild before uploading a preview." : "Run `vitehub deploy` with build and provisioning enabled. Or run `vitehub provision run --host cloudflare`, build again, then deploy.",
|
|
1176
|
+
why: ({ bindings }) => `The build output has no \`database_id\` for the D1 binding ${String(bindings)}. Nothing was deployed.`
|
|
1177
|
+
},
|
|
1178
|
+
SETUP_DEPLOY_D1_MIGRATIONS_PENDING: {
|
|
1179
|
+
fix: ({ apply }) => `Set \`database.migrateOnDeploy: true\` so that \`vitehub deploy\` applies them before the Worker deploys. Or run \`${String(apply)}\` in the build output folder, then deploy again.`,
|
|
1180
|
+
why: ({ binding, migrations }) => `The build has D1 migrations that the remote database of the binding ${String(binding)} has not applied: ${String(migrations)}. The new code would query tables or columns that do not exist yet. Nothing was deployed.`
|
|
1181
|
+
},
|
|
1182
|
+
SETUP_DEPLOY_TEMPORARY_UNSUPPORTED: {
|
|
1183
|
+
fix: "Remove --temporary and deploy with your host login.",
|
|
1184
|
+
why: ({ reason }) => `--temporary cannot run here. ${String(reason)}`
|
|
1185
|
+
},
|
|
1186
|
+
SETUP_DEPLOY_PREVIEW_UNSUPPORTED: {
|
|
1187
|
+
fix: "Remove --preview to deploy to production.",
|
|
1188
|
+
why: ({ host }) => `The ${String(host)} deploy that the build writes always deploys to production.`
|
|
1189
|
+
},
|
|
1190
|
+
SETUP_DEPLOY_ORG_REQUIRED: {
|
|
1191
|
+
fix: "Set DENO_DEPLOY_ORG to your Deno Deploy organization, or run `vitehub link --host deno --account <org>`.",
|
|
1192
|
+
why: () => "The Deno Deploy organization is not known."
|
|
1193
|
+
},
|
|
1194
|
+
SETUP_DEPLOY_BUILD_FAILED: {
|
|
1195
|
+
fix: ({ exitCode, framework }) => {
|
|
1196
|
+
if (exitCode !== void 0) return "Fix the build error above and run the command again.";
|
|
1197
|
+
if (framework === "nuxt" || framework === "vite") return `Add a \`build\` script to package.json, such as \`"build": "${framework} build"\`, and run the command again.`;
|
|
1198
|
+
return "Add a `build` script to package.json and run the command again.";
|
|
1199
|
+
},
|
|
1200
|
+
why: ({ command, exitCode }) => exitCode === void 0 ? `package.json has no \`build\` script, so \`${String(command)}\` cannot build the app.` : `\`${String(command)}\` exited with code ${String(exitCode)}.`
|
|
1201
|
+
},
|
|
1202
|
+
SETUP_DEPLOY_CHECK_FAILED: {
|
|
1203
|
+
fix: ({ rollback }) => `${String(rollback)} Then fix the app and deploy again. Pass --no-check only when the check itself is wrong.`,
|
|
1204
|
+
why: ({ failed, url }) => `The app is deployed to ${String(url)}, but a \`deploy.check\` path did not answer with a 2xx status: ${String(failed)}.`
|
|
1205
|
+
},
|
|
1206
|
+
SETUP_DEPLOY_OUTPUT_MISSING: {
|
|
1207
|
+
fix: "Build the app with vitehub() for this host, then run the command again without --no-build.",
|
|
1208
|
+
why: ({ file }) => `The build output has no ${String(file)}.`
|
|
1209
|
+
},
|
|
1210
|
+
SETUP_DEPLOY_HOST_MISMATCH: {
|
|
1211
|
+
fix: ({ host }) => `Build again for ${String(host)}: run \`vitehub deploy --host ${String(host)}\` without --no-build.`,
|
|
1212
|
+
why: ({ built, host }) => `The build output is for ${String(built)}, but this deploy goes to ${String(host)}.`
|
|
1213
|
+
},
|
|
1214
|
+
SETUP_DEPLOY_COMMAND_REJECTED: {
|
|
1215
|
+
fix: "Build again with vitehub(). If you set the deploy command yourself, run it yourself.",
|
|
1216
|
+
why: ({ command }) => `The build output names a deploy command that ViteHub did not write, so it does not run it: ${String(command)}`
|
|
1217
|
+
},
|
|
1218
|
+
SETUP_DEPLOY_ENV_MISSING: {
|
|
1219
|
+
fix: ({ console, firstDeploy, host }) => (console === true ? "For VITEHUB_CONSOLE_KEY_*, run `vitehub login`, and deploy links the app in the Console and sets its key. " : "") + (firstDeploy ? `Set each name in the shell or in .env.<stage>, then deploy again. If the ${String(host)} project already exists, run \`vitehub link --host ${String(host)}\` first, so deploy reads its variables.` : `Run \`vitehub env push --host ${String(host)}\`, set the names in the ${String(host)} dashboard, or set them in the shell or in .env.<stage> and deploy again.`),
|
|
1220
|
+
why: ({ firstDeploy, host, names, stage }) => firstDeploy ? `The app needs ${String(names)}, and no value was found. This is the first deploy to ${String(host)}: the project is not linked, so the host has no variables yet and every required name needs a local value for the ${String(stage)} stage. Nothing was deployed.` : `The app needs ${String(names)}, and neither ${String(host)} nor a local value for the ${String(stage)} stage has one. Nothing was deployed.`
|
|
1221
|
+
},
|
|
1222
|
+
SETUP_DEPLOY_ENV_NOT_LINKED: {
|
|
1223
|
+
fix: ({ host }) => host === "deno" ? "Create the app in Deno Deploy if needed, run `vitehub link --host deno`, then deploy again." : `Run \`vitehub link --host ${String(host)} --create\` to create the project, then deploy again.`,
|
|
1224
|
+
why: ({ host, names }) => `The ${String(host)} project is not linked, so deploy cannot set ${String(names)} before the first deploy. Nothing was deployed.`
|
|
1225
|
+
},
|
|
1226
|
+
SETUP_DEPLOY_ENV_STAGE_UNSAFE: {
|
|
1227
|
+
why: ({ names, stage }) => `These existing Cloudflare secrets have no local value for stage ${String(stage)}: ${String(names)}. The latest uploaded version may belong to another stage, so inheriting its values is unsafe. Nothing was deployed.`,
|
|
1228
|
+
fix: ({ console, stage }) => `Set every listed name in the shell or an untracked .env.${String(stage)} file and deploy again. Cloudflare deploys re-supply all existing secrets with the version to preserve stage isolation.${console ? " For a Console key, copy the public value of the existing link, or restore the Console connection with `vitehub login`." : ""}`
|
|
1229
|
+
},
|
|
1230
|
+
SETUP_DEPLOY_FAILED: {
|
|
1231
|
+
fix: "Read the host output above, fix the cause, and run the command again.",
|
|
1232
|
+
why: ({ exitCode, output, step }) => `\`${String(step)}\` failed${exitCode === void 0 ? "" : ` with exit code ${String(exitCode)}`}.${output ? `\n${String(output)}` : ""}`
|
|
1233
|
+
},
|
|
1234
|
+
SETUP_DEPLOYMENTS_NOT_LINKED: {
|
|
1235
|
+
fix: ({ host }) => host ? `Run \`vitehub link --host ${String(host)}\`, or deploy once with \`vitehub deploy --host ${String(host)}\`.` : "Run `vitehub link` to link the project to its host, or deploy once with `vitehub deploy`.",
|
|
1236
|
+
why: ({ host }) => host ? `The project has no ${String(host)} target in .vitehub/link.json, so the host project to read is not known.` : "The project has no host link in .vitehub/link.json, so the host project to read is not known."
|
|
1237
|
+
},
|
|
1238
|
+
SETUP_DEPLOYMENTS_CREDENTIALS_MISSING: {
|
|
1239
|
+
fix: ({ fix }) => fix === void 0 ? "Log in with the host CLI, such as `npx wrangler login`, or set the host token, such as CLOUDFLARE_API_TOKEN, VERCEL_TOKEN, NETLIFY_AUTH_TOKEN, or DENO_DEPLOY_TOKEN, then run the command again." : String(fix),
|
|
1240
|
+
why: ({ host }) => `No ${String(host)} credentials were found in the environment or in the host CLI login, so the deployments cannot be read.`
|
|
1241
|
+
},
|
|
1242
|
+
SETUP_DEPLOYMENTS_ACCOUNT_REQUIRED: {
|
|
1243
|
+
fix: "Set CLOUDFLARE_ACCOUNT_ID, or run `vitehub link --host cloudflare --account <id>`.",
|
|
1244
|
+
why: ({ host }) => `The ${String(host)} account of the linked project is not known.`
|
|
1245
|
+
},
|
|
1246
|
+
SETUP_DEPLOYMENTS_PROJECT_ID_REQUIRED: {
|
|
1247
|
+
fix: ({ host }) => `Run \`vitehub link --host ${String(host)}\` to store the project id.`,
|
|
1248
|
+
why: ({ host }) => `The ${String(host)} link has no project id, and the ${String(host)} API lists deployments by id.`
|
|
1249
|
+
},
|
|
1250
|
+
SETUP_DEPLOY_CHECKOUT_CONFLICT: {
|
|
1251
|
+
fix: "Edit each file and remove the conflict markers, or run `vitehub resolve` for a binary file. Then deploy again, or pass --no-push to deploy without the push.",
|
|
1252
|
+
why: ({ files }) => `A checkout folder of vitehub.lock has unresolved conflicts, so the Workspace push after the deploy would fail. Nothing was built or deployed: ${String(files)}`
|
|
1253
|
+
},
|
|
1254
|
+
SETUP_DEPLOY_CHECKOUT_MODULE_FAILED: {
|
|
1255
|
+
fix: "Reinstall the project dependencies and check that the Workspace package is the same version as the CLI. Or pass --no-push to deploy without the push.",
|
|
1256
|
+
why: ({ file, message, specifier }) => `The project installs ${String(specifier)}, but ViteHub cannot load it from ${String(file)}, so it cannot push the checkout folders of vitehub.lock. Nothing was built or deployed: ${String(message)}`
|
|
1257
|
+
},
|
|
1258
|
+
SETUP_DEPLOY_PROVISION_NEEDS_BUILD: {
|
|
1259
|
+
fix: "Deploy again without --no-build, so the build gets the new ids.",
|
|
1260
|
+
why: ({ count }) => `The deploy must create or change ${String(count)} resources, but --no-build deploys an output that was built without their ids. Nothing was created or deployed.`
|
|
1261
|
+
},
|
|
1262
|
+
SETUP_DEPLOY_PROVISION_UNCHECKED: {
|
|
1263
|
+
fix: "Set the credential that the reason names and deploy again. Or deploy with --no-provision to skip the resources.",
|
|
1264
|
+
why: ({ host, missing, warnings }) => `The deploy could not check the ${String(host)} resources of the app, so it created and deployed nothing: ${String(warnings)} ${String(missing)}`
|
|
1265
|
+
},
|
|
1266
|
+
SETUP_DEPLOY_PUSH_FAILED: {
|
|
1267
|
+
fix: ({ fix }) => `${fix ? `${String(fix)} ` : ""}Then run \`vitehub push\`. Do not deploy again.`,
|
|
1268
|
+
why: ({ message, url }) => `The app is deployed${url === void 0 ? "" : ` to ${String(url)}`}, but the Workspace push failed: ${String(message)}`
|
|
1269
|
+
},
|
|
1270
|
+
CLI_R0004: {
|
|
1271
|
+
fix: "Run it again with --yes, or check the change first with a dry run when the command has one.",
|
|
1272
|
+
why: ({ message }) => message === void 0 ? "" : String(message)
|
|
1273
|
+
},
|
|
1274
|
+
SETUP_DEPLOY_VERCEL_PREVIEW_REQUIRES_PRODUCTION: {
|
|
1275
|
+
fix: "Remove --preview to deploy to production first, then deploy again with --preview.",
|
|
1276
|
+
why: () => "The Vercel project does not exist yet. Vercel requires a production deploy before a preview deploy."
|
|
1277
|
+
},
|
|
1278
|
+
SETUP_ENV_DECRYPT_FAILED: {
|
|
1279
|
+
fix: ({ file, key }) => `Set ${String(key)} to the private key that encrypted ${String(file)}. Check it with \`dotenvx get -f ${String(file)}\`.`,
|
|
1280
|
+
why: ({ file, key, name, reason }) => `${String(key)} cannot decrypt ${String(name)} in ${String(file)} (${String(reason)}).`
|
|
1281
|
+
},
|
|
1282
|
+
SETUP_ENV_FILE_NOT_IGNORED: {
|
|
1283
|
+
fix: ({ file }) => `Add \`.env*\` or \`${String(file)}\` to .gitignore. Or set the values in the shell for this command.`,
|
|
1284
|
+
why: ({ file, names }) => `The secret ${String(names)} reads ${String(file)}, which git does not ignore, so a commit can add it. \`vitehub env push\` pushes a secret only from a file that git ignores.`
|
|
1285
|
+
},
|
|
1286
|
+
SETUP_ENV_FILE_TRACKED: {
|
|
1287
|
+
fix: ({ file }) => `Run \`git rm --cached ${String(file)}\`, add \`.env*\` to .gitignore, and rotate the values that git has seen. Or set the values in the shell for this command.`,
|
|
1288
|
+
why: ({ file, names }) => `The secret ${String(names)} reads ${String(file)}, which git tracks, directly or through \`$NAME\` expansion or a symlink. \`vitehub env push\` does not push a secret that is in git.`
|
|
1289
|
+
},
|
|
1290
|
+
SETUP_ENV_FILE_UNSAFE: {
|
|
1291
|
+
fix: ({ file, names }) => `Use a regular file without any links for ${String(file)}, or set ${String(names)} in the shell for this deploy.`,
|
|
1292
|
+
why: ({ file, names }) => `Deploy cannot safely save the generated secret ${String(names)} in ${String(file)}. It writes only to a regular file that is not a symlink or a hard link.`
|
|
1293
|
+
},
|
|
1294
|
+
SETUP_ENV_GIT_FAILED: {
|
|
1295
|
+
fix: "Fix the git repository so that `git ls-files` and `git check-ignore` work, then run the command again. Or set the values in the shell for this command.",
|
|
1296
|
+
why: ({ file, reason }) => `Git could not tell whether it tracks or ignores ${String(file)}, which holds a secret: ${String(reason)}. Nothing was pushed.`
|
|
1297
|
+
},
|
|
1298
|
+
SETUP_ENV_KEYS_TRACKED: {
|
|
1299
|
+
fix: ({ file }) => `Run \`git rm --cached ${String(file)}\`, add it to .gitignore, and rotate the keys with \`dotenvx rotate\`. Everyone with the repository can decrypt the values until then.`,
|
|
1300
|
+
why: ({ file }) => `${String(file)} holds the private keys of the encrypted env files and is tracked by git. \`vitehub env push\` does not decrypt with a key that is in git.`
|
|
1301
|
+
},
|
|
1302
|
+
SETUP_ENV_NAME_UNKNOWN: {
|
|
1303
|
+
fix: "Pass names that `vitehub env diff` lists, or build again after you declare the name.",
|
|
1304
|
+
why: ({ names }) => `The build output lists no variable named ${String(names)}.`
|
|
1305
|
+
},
|
|
1306
|
+
SETUP_ENV_PRIVATE_KEY_MISSING: {
|
|
1307
|
+
fix: ({ key }) => `Set ${String(key)} in the shell, or add it to .env.keys, which git must ignore.`,
|
|
1308
|
+
why: ({ file, key, names }) => `${String(file)} holds the encrypted ${String(names)}, and ${String(key)} is not set.`
|
|
1309
|
+
},
|
|
1310
|
+
SETUP_ENV_STAGE_UNSUPPORTED: {
|
|
1311
|
+
fix: ({ host, stage }) => stage !== "preview" ? "Use --stage production or --stage preview, the stages of `vitehub deploy` and `vitehub deploy --preview`." : host === "cloudflare" ? "A Worker has one set of secrets for every version. Push production values with --stage production." : "`vitehub deploy` deploys this host to production only. Push with --stage production.",
|
|
1312
|
+
why: ({ host, stage }) => `The ${String(host)} host has no environment for the ${String(stage)} stage.`
|
|
1313
|
+
},
|
|
1314
|
+
SETUP_ENV_VALUE_UNSUPPORTED: {
|
|
1315
|
+
fix: ({ host }) => `Set this value in the ${String(host)} dashboard.`,
|
|
1316
|
+
why: ({ host, name, reason }) => `The value of ${String(name)} cannot go to ${String(host)} without a terminal prompt or argv. ${String(reason)}`
|
|
1317
|
+
},
|
|
1318
|
+
SETUP_GITHUB_REPOSITORY_REQUIRED: {
|
|
1319
|
+
fix: "Pass --repo owner/name, or add a GitHub remote named origin.",
|
|
1320
|
+
why: ({ remote }) => remote ? `The git remote origin (${String(remote)}) is not a github.com repository.` : "This folder has no git remote named origin."
|
|
1321
|
+
},
|
|
1322
|
+
SETUP_GITHUB_REQUEST_FAILED: {
|
|
1323
|
+
fix: "Check that the token can write the Actions secrets of the repository, and that the repository and environment exist.",
|
|
1324
|
+
why: ({ operation, reason }) => `GitHub refused \`${String(operation)}\`: ${String(reason)}`
|
|
1325
|
+
}
|
|
1326
|
+
}
|
|
1327
|
+
});
|
|
1328
|
+
// ../internal/dist/host-credentials.js
|
|
1329
|
+
const missingFixes = {
|
|
1330
|
+
cloudflare: {
|
|
1331
|
+
missing: ["CLOUDFLARE_API_TOKEN"],
|
|
1332
|
+
fix: "Install Wrangler in the project and run `npx wrangler login`, or set CLOUDFLARE_API_TOKEN and CLOUDFLARE_ACCOUNT_ID."
|
|
1333
|
+
},
|
|
1334
|
+
vercel: {
|
|
1335
|
+
missing: ["VERCEL_TOKEN"],
|
|
1336
|
+
fix: "Set VERCEL_TOKEN to a token from https://vercel.com/account/tokens. Set VERCEL_TEAM_ID for a team."
|
|
1337
|
+
},
|
|
1338
|
+
netlify: {
|
|
1339
|
+
missing: ["NETLIFY_AUTH_TOKEN"],
|
|
1340
|
+
fix: "Set NETLIFY_AUTH_TOKEN to a token from https://app.netlify.com/user/applications#personal-access-tokens."
|
|
1341
|
+
},
|
|
1342
|
+
deno: {
|
|
1343
|
+
missing: ["DENO_DEPLOY_TOKEN"],
|
|
1344
|
+
fix: "Set DENO_DEPLOY_TOKEN to a token from your Deno Deploy account settings."
|
|
1345
|
+
}
|
|
1346
|
+
};
|
|
1347
|
+
const HOST_CLI_TIMEOUT_MS = 3e4;
|
|
1348
|
+
/** Reads host credentials from environment variables only. Returns undefined when the token is not set. */
|
|
1349
|
+
function readHostCredentialsFromEnv(host, env) {
|
|
1350
|
+
switch (host) {
|
|
1351
|
+
case "cloudflare": {
|
|
1352
|
+
const token = trimmed(env.CLOUDFLARE_API_TOKEN);
|
|
1353
|
+
const accountId = trimmed(env.CLOUDFLARE_ACCOUNT_ID);
|
|
1354
|
+
return token ? {
|
|
1355
|
+
token,
|
|
1356
|
+
...accountId && { accountId }
|
|
1357
|
+
} : void 0;
|
|
1358
|
+
}
|
|
1359
|
+
case "vercel": {
|
|
1360
|
+
const token = trimmed(env.VERCEL_TOKEN);
|
|
1361
|
+
const teamId = trimmed(env.VERCEL_TEAM_ID) ?? trimmed(env.VERCEL_ORG_ID);
|
|
1362
|
+
return token ? {
|
|
1363
|
+
token,
|
|
1364
|
+
...teamId && { teamId }
|
|
1365
|
+
} : void 0;
|
|
1366
|
+
}
|
|
1367
|
+
case "netlify": {
|
|
1368
|
+
const token = trimmed(env.NETLIFY_AUTH_TOKEN);
|
|
1369
|
+
return token ? { token } : void 0;
|
|
1370
|
+
}
|
|
1371
|
+
case "deno": {
|
|
1372
|
+
const token = trimmed(env.DENO_DEPLOY_TOKEN);
|
|
1373
|
+
return token ? { token } : void 0;
|
|
1374
|
+
}
|
|
1375
|
+
}
|
|
1376
|
+
}
|
|
1377
|
+
/**
|
|
1378
|
+
* Finds credentials for a host: environment variables first, then the host CLI login.
|
|
1379
|
+
* It never writes credentials and never reads another tool's auth files.
|
|
1380
|
+
*/
|
|
1381
|
+
async function resolveHostCredentials(host, context) {
|
|
1382
|
+
const fromEnv = readHostCredentialsFromEnv(host, context.env);
|
|
1383
|
+
if (fromEnv) return {
|
|
1384
|
+
ok: true,
|
|
1385
|
+
host,
|
|
1386
|
+
source: "env",
|
|
1387
|
+
...fromEnv
|
|
1388
|
+
};
|
|
1389
|
+
if (host === "cloudflare") {
|
|
1390
|
+
const token = await readWranglerToken(context);
|
|
1391
|
+
if (token) {
|
|
1392
|
+
const accountId = trimmed(context.env.CLOUDFLARE_ACCOUNT_ID) ?? await readWranglerAccountId(context);
|
|
1393
|
+
return {
|
|
1394
|
+
ok: true,
|
|
1395
|
+
host,
|
|
1396
|
+
source: "host-cli",
|
|
1397
|
+
token,
|
|
1398
|
+
...accountId && { accountId }
|
|
1399
|
+
};
|
|
1400
|
+
}
|
|
1401
|
+
}
|
|
1402
|
+
return {
|
|
1403
|
+
ok: false,
|
|
1404
|
+
host,
|
|
1405
|
+
...missingFixes[host]
|
|
1406
|
+
};
|
|
1407
|
+
}
|
|
1408
|
+
async function readWranglerToken(context) {
|
|
1409
|
+
const value = await runJson(context, "wrangler", [
|
|
1410
|
+
"auth",
|
|
1411
|
+
"token",
|
|
1412
|
+
"--json"
|
|
1413
|
+
]);
|
|
1414
|
+
if (!isRecord(value) || value.type !== "oauth" && value.type !== "api_token") return;
|
|
1415
|
+
return typeof value.token === "string" ? trimmed(value.token) : void 0;
|
|
1416
|
+
}
|
|
1417
|
+
async function readWranglerAccountId(context) {
|
|
1418
|
+
const value = await runJson(context, "wrangler", ["whoami", "--json"]);
|
|
1419
|
+
if (!isRecord(value) || value.loggedIn !== true || !Array.isArray(value.accounts) || value.accounts.length !== 1) return;
|
|
1420
|
+
const [account] = value.accounts;
|
|
1421
|
+
return isRecord(account) && typeof account.id === "string" ? trimmed(account.id) : void 0;
|
|
1422
|
+
}
|
|
1423
|
+
async function runJson(context, command, args) {
|
|
1424
|
+
const run = context.run ?? runHostCli;
|
|
1425
|
+
let result;
|
|
1426
|
+
let cwd;
|
|
1427
|
+
try {
|
|
1428
|
+
const local = command === "wrangler" ? localWrangler(context.cwd) : void 0;
|
|
1429
|
+
cwd = await mkdtemp(join(context.cwd ?? process.cwd(), ".vitehub-wrangler-auth-"));
|
|
1430
|
+
await writeFile(join(cwd, ".env"), "");
|
|
1431
|
+
await writeFile(join(cwd, "wrangler.json"), "{}");
|
|
1432
|
+
const isolatedArgs = [
|
|
1433
|
+
...args,
|
|
1434
|
+
"--env-file",
|
|
1435
|
+
".env",
|
|
1436
|
+
"--config",
|
|
1437
|
+
"wrangler.json"
|
|
1438
|
+
];
|
|
1439
|
+
result = await run(local ? process.execPath : command, local ? [local, ...isolatedArgs] : isolatedArgs, {
|
|
1440
|
+
cwd,
|
|
1441
|
+
env: context.env
|
|
1442
|
+
});
|
|
1443
|
+
} catch {
|
|
1444
|
+
return;
|
|
1445
|
+
} finally {
|
|
1446
|
+
if (cwd) await rm(cwd, {
|
|
1447
|
+
force: true,
|
|
1448
|
+
recursive: true
|
|
1449
|
+
});
|
|
1450
|
+
}
|
|
1451
|
+
if (result.exitCode !== 0) return;
|
|
1452
|
+
try {
|
|
1453
|
+
return JSON.parse(result.stdout);
|
|
1454
|
+
} catch {
|
|
1455
|
+
return;
|
|
1456
|
+
}
|
|
1457
|
+
}
|
|
1458
|
+
/** Resolve a project dependency before changing cwd, as package-manager invocations do. */
|
|
1459
|
+
function localWrangler(cwd) {
|
|
1460
|
+
if (!cwd) return;
|
|
1461
|
+
const require = createRequire(join(resolve(cwd), "package.json"));
|
|
1462
|
+
let directory = resolve(cwd);
|
|
1463
|
+
while (true) {
|
|
1464
|
+
try {
|
|
1465
|
+
const manifest = require.resolve(join(directory, "node_modules", "wrangler", "package.json"));
|
|
1466
|
+
const pkg = JSON.parse(readFileSync(manifest, "utf8"));
|
|
1467
|
+
if (!isRecord(pkg)) return;
|
|
1468
|
+
const bin = typeof pkg.bin === "string" ? pkg.bin : isRecord(pkg.bin) ? pkg.bin.wrangler : void 0;
|
|
1469
|
+
return typeof bin === "string" ? resolve(dirname(manifest), bin) : void 0;
|
|
1470
|
+
} catch {}
|
|
1471
|
+
const parent = dirname(directory);
|
|
1472
|
+
if (parent === directory) return;
|
|
1473
|
+
directory = parent;
|
|
1474
|
+
}
|
|
1475
|
+
}
|
|
1476
|
+
/** The default host CLI runner. stdin is closed so a CLI cannot wait for a prompt. */
|
|
1477
|
+
const runHostCli = (command, args, options) => new Promise((resolve, reject) => {
|
|
1478
|
+
const child = spawn(command, [...args], {
|
|
1479
|
+
cwd: options.cwd,
|
|
1480
|
+
env: options.env,
|
|
1481
|
+
shell: process.platform === "win32" && command !== process.execPath,
|
|
1482
|
+
stdio: [
|
|
1483
|
+
"ignore",
|
|
1484
|
+
"pipe",
|
|
1485
|
+
"ignore"
|
|
1486
|
+
],
|
|
1487
|
+
timeout: HOST_CLI_TIMEOUT_MS,
|
|
1488
|
+
...options.signal ? { signal: options.signal } : {}
|
|
1489
|
+
});
|
|
1490
|
+
const chunks = [];
|
|
1491
|
+
child.stdout.on("data", (chunk) => chunks.push(chunk));
|
|
1492
|
+
child.on("error", reject);
|
|
1493
|
+
child.on("close", (exitCode) => resolve({
|
|
1494
|
+
exitCode,
|
|
1495
|
+
stdout: Buffer.concat(chunks).toString("utf8")
|
|
1496
|
+
}));
|
|
1497
|
+
});
|
|
1498
|
+
function trimmed(value) {
|
|
1499
|
+
const result = value?.trim();
|
|
1500
|
+
return result ? result : void 0;
|
|
1501
|
+
}
|
|
1502
|
+
// ../internal/dist/provider-failure.js
|
|
1503
|
+
const cloudflareCodes = {
|
|
1504
|
+
d1: {},
|
|
1505
|
+
kv: { 10014: "conflict" },
|
|
1506
|
+
queues: {
|
|
1507
|
+
10104: "not-found",
|
|
1508
|
+
10106: "unauthorized",
|
|
1509
|
+
10107: "invalid",
|
|
1510
|
+
10201: "unavailable",
|
|
1511
|
+
10202: "invalid",
|
|
1512
|
+
10203: "invalid",
|
|
1513
|
+
10204: "invalid",
|
|
1514
|
+
10205: "invalid",
|
|
1515
|
+
10206: "invalid",
|
|
1516
|
+
10207: "invalid",
|
|
1517
|
+
10208: "invalid",
|
|
1518
|
+
10250: "throttled",
|
|
1519
|
+
10251: "throttled",
|
|
1520
|
+
10252: "throttled",
|
|
1521
|
+
10253: "throttled",
|
|
1522
|
+
15e3: "unavailable"
|
|
1523
|
+
},
|
|
1524
|
+
r2: {
|
|
1525
|
+
10001: "unavailable",
|
|
1526
|
+
10002: "unauthorized",
|
|
1527
|
+
10003: "unauthorized",
|
|
1528
|
+
10004: "conflict",
|
|
1529
|
+
10005: "invalid",
|
|
1530
|
+
10006: "not-found",
|
|
1531
|
+
10007: "not-found",
|
|
1532
|
+
10008: "conflict",
|
|
1533
|
+
10009: "invalid",
|
|
1534
|
+
10011: "invalid",
|
|
1535
|
+
10012: "invalid",
|
|
1536
|
+
10013: "invalid",
|
|
1537
|
+
10014: "invalid",
|
|
1538
|
+
10018: "unauthorized",
|
|
1539
|
+
10020: "invalid",
|
|
1540
|
+
10024: "not-found",
|
|
1541
|
+
10025: "invalid",
|
|
1542
|
+
10031: "conflict",
|
|
1543
|
+
10033: "invalid",
|
|
1544
|
+
10035: "unauthorized",
|
|
1545
|
+
10037: "invalid",
|
|
1546
|
+
10039: "invalid",
|
|
1547
|
+
10042: "unauthorized",
|
|
1548
|
+
10043: "unavailable",
|
|
1549
|
+
10048: "invalid",
|
|
1550
|
+
10054: "unavailable",
|
|
1551
|
+
10058: "throttled",
|
|
1552
|
+
10069: "conflict",
|
|
1553
|
+
10073: "conflict",
|
|
1554
|
+
100100: "invalid"
|
|
1555
|
+
}
|
|
1556
|
+
};
|
|
1557
|
+
const vercelCodes = {
|
|
1558
|
+
bad_request: "invalid",
|
|
1559
|
+
conflict_aliases: "conflict",
|
|
1560
|
+
forbidden: "unauthorized",
|
|
1561
|
+
internal_server_error: "unavailable",
|
|
1562
|
+
method_unknown: "invalid",
|
|
1563
|
+
not_found: "not-found",
|
|
1564
|
+
not_modified: "conflict",
|
|
1565
|
+
rate_limited: "throttled",
|
|
1566
|
+
service_unavailable: "unavailable"
|
|
1567
|
+
};
|
|
1568
|
+
function kindFromStatus(status) {
|
|
1569
|
+
if (status === 401 || status === 403) return "unauthorized";
|
|
1570
|
+
if (status === 404 || status === 410) return "not-found";
|
|
1571
|
+
if (status === 409 || status === 412) return "conflict";
|
|
1572
|
+
if (status === 429) return "throttled";
|
|
1573
|
+
if (status === 408 || status >= 500) return "unavailable";
|
|
1574
|
+
if (status >= 400) return "invalid";
|
|
1575
|
+
}
|
|
1576
|
+
/**
|
|
1577
|
+
* Classifies a failed provider call. A documented provider code wins over the HTTP status.
|
|
1578
|
+
* Returns `undefined` only when neither a known code nor an error status is present.
|
|
1579
|
+
*/
|
|
1580
|
+
function classifyProviderFailure(source, { codes = [], status }) {
|
|
1581
|
+
for (const code of codes) {
|
|
1582
|
+
const kind = source.host === "vercel" ? typeof code === "string" && Object.hasOwn(vercelCodes, code) ? vercelCodes[code] : void 0 : source.host === "cloudflare" && source.product && typeof code === "number" && Object.hasOwn(cloudflareCodes[source.product], code) ? cloudflareCodes[source.product][code] : void 0;
|
|
1583
|
+
if (kind) return kind;
|
|
1584
|
+
}
|
|
1585
|
+
return status === void 0 ? void 0 : kindFromStatus(status);
|
|
1586
|
+
}
|
|
1587
|
+
/** Finds the Cloudflare product of an account API path, such as `/r2/buckets`. */
|
|
1588
|
+
function cloudflareProductOfPath(path) {
|
|
1589
|
+
if (path.startsWith("/r2/")) return "r2";
|
|
1590
|
+
if (path.startsWith("/storage/kv/")) return "kv";
|
|
1591
|
+
if (path.startsWith("/d1/")) return "d1";
|
|
1592
|
+
if (path === "/queues" || path.startsWith("/queues/") || path.startsWith("/queues?")) return "queues";
|
|
1593
|
+
}
|
|
1594
|
+
/**
|
|
1595
|
+
* Reads the error codes of a Cloudflare (`errors[].code`) or Vercel (`error.code`) error body.
|
|
1596
|
+
* Keeps only codes that are safe to print: numbers, and short strings without spaces or line breaks.
|
|
1597
|
+
*/
|
|
1598
|
+
function readProviderErrorCodes(body) {
|
|
1599
|
+
if (!body || typeof body !== "object") return [];
|
|
1600
|
+
const error = Reflect.get(body, "error");
|
|
1601
|
+
const errors = Reflect.get(body, "errors");
|
|
1602
|
+
return [error && typeof error === "object" ? Reflect.get(error, "code") : void 0, ...Array.isArray(errors) ? errors.map((entry) => entry && typeof entry === "object" ? Reflect.get(entry, "code") : void 0) : []].filter((code) => typeof code === "number" && Number.isFinite(code) || typeof code === "string" && /^[\w.-]{1,128}$/.test(code));
|
|
1603
|
+
}
|
|
1604
|
+
// ../internal/dist/provision.js
|
|
1605
|
+
/** Plans one provider in step order and collects warnings and explicit unchecked state. */
|
|
1606
|
+
async function planProvisionSteps(provider, steps, context) {
|
|
1607
|
+
const warnings = [];
|
|
1608
|
+
let checked = true;
|
|
1609
|
+
const planContext = {
|
|
1610
|
+
...context,
|
|
1611
|
+
logger: {
|
|
1612
|
+
log: (message) => context.logger.log(message),
|
|
1613
|
+
warn(message) {
|
|
1614
|
+
warnings.push(message);
|
|
1615
|
+
context.logger.warn(message);
|
|
1616
|
+
}
|
|
1617
|
+
},
|
|
1618
|
+
markPlanUnchecked: () => {
|
|
1619
|
+
checked = false;
|
|
1620
|
+
}
|
|
1621
|
+
};
|
|
1622
|
+
const actions = [];
|
|
1623
|
+
for (const step of steps) {
|
|
1624
|
+
if (step.provider !== provider) continue;
|
|
1625
|
+
for (const action of await step.plan(planContext)) actions.push({
|
|
1626
|
+
action,
|
|
1627
|
+
step: step.id
|
|
1628
|
+
});
|
|
1629
|
+
}
|
|
1630
|
+
return {
|
|
1631
|
+
actions,
|
|
1632
|
+
checked,
|
|
1633
|
+
warnings
|
|
1634
|
+
};
|
|
1635
|
+
}
|
|
1636
|
+
function resolveCloudflareProvisionConfig(env) {
|
|
1637
|
+
const credentials = readHostCredentialsFromEnv("cloudflare", env);
|
|
1638
|
+
if (!credentials?.accountId) return;
|
|
1639
|
+
return {
|
|
1640
|
+
accountId: credentials.accountId,
|
|
1641
|
+
token: credentials.token
|
|
1642
|
+
};
|
|
1643
|
+
}
|
|
1644
|
+
function resolveVercelProvisionConfig(env) {
|
|
1645
|
+
const credentials = readHostCredentialsFromEnv("vercel", env);
|
|
1646
|
+
if (!credentials) return;
|
|
1647
|
+
return {
|
|
1648
|
+
token: credentials.token,
|
|
1649
|
+
teamId: credentials.teamId
|
|
1650
|
+
};
|
|
1651
|
+
}
|
|
1652
|
+
function ownParser(options) {
|
|
1653
|
+
if (!Object.hasOwn(options, "parse")) return;
|
|
1654
|
+
return options.parse;
|
|
1655
|
+
}
|
|
1656
|
+
function provisionRequestError(method, path, status, codes, kind) {
|
|
1657
|
+
const suffix = codes.length ? ` Provider code${codes.length === 1 ? "" : "s"}: ${codes.join(", ")}.` : "";
|
|
1658
|
+
return Object.assign(internalErrorDiagnostics.INTERNAL_R0013({ message: `Provision request failed: ${method} ${path} (${status}).${suffix}` }), {
|
|
1659
|
+
codes,
|
|
1660
|
+
kind,
|
|
1661
|
+
status
|
|
1662
|
+
});
|
|
1663
|
+
}
|
|
1664
|
+
/** Whether `error` is a failed provider API call of provisioning. */
|
|
1665
|
+
function isProvisionRequestError(error) {
|
|
1666
|
+
return error instanceof Error && Reflect.get(error, "code") === "INTERNAL_R0013";
|
|
1667
|
+
}
|
|
1668
|
+
function createJsonClient(source, baseURL, headers, fetchImpl, baseQuery) {
|
|
1669
|
+
return async function request(path, options = {}) {
|
|
1670
|
+
const url = new URL(`${baseURL}${path}`);
|
|
1671
|
+
const query = Object.hasOwn(options, "query") ? options.query : void 0;
|
|
1672
|
+
for (const [key, value] of Object.entries({
|
|
1673
|
+
...baseQuery,
|
|
1674
|
+
...query
|
|
1675
|
+
})) url.searchParams.set(key, value);
|
|
1676
|
+
const method = Object.hasOwn(options, "method") ? options.method : void 0;
|
|
1677
|
+
const body = Object.hasOwn(options, "body") ? options.body : void 0;
|
|
1678
|
+
const requestHeaders = Object.hasOwn(options, "headers") ? options.headers : void 0;
|
|
1679
|
+
const init = {
|
|
1680
|
+
method: method ?? "GET",
|
|
1681
|
+
headers: {
|
|
1682
|
+
...requestHeaders,
|
|
1683
|
+
...headers
|
|
1684
|
+
}
|
|
1685
|
+
};
|
|
1686
|
+
if (body !== void 0) {
|
|
1687
|
+
init.headers = {
|
|
1688
|
+
...init.headers,
|
|
1689
|
+
"content-type": "application/json"
|
|
1690
|
+
};
|
|
1691
|
+
init.body = JSON.stringify(body);
|
|
1692
|
+
}
|
|
1693
|
+
const response = await fetchImpl(url, init);
|
|
1694
|
+
if (!response.ok) {
|
|
1695
|
+
const codes = readProviderErrorCodes(await response.json().catch(() => void 0));
|
|
1696
|
+
const kind = classifyProviderFailure(source(path), {
|
|
1697
|
+
codes,
|
|
1698
|
+
status: response.status
|
|
1699
|
+
}) ?? "unavailable";
|
|
1700
|
+
throw provisionRequestError(method ?? "GET", path, response.status, codes, kind);
|
|
1701
|
+
}
|
|
1702
|
+
const value = await response.json();
|
|
1703
|
+
const parse = ownParser(options);
|
|
1704
|
+
return parse ? parse(value) : value;
|
|
1705
|
+
};
|
|
1706
|
+
}
|
|
1707
|
+
function createCloudflareProvisionClient(config, fetchImpl = globalThis.fetch) {
|
|
1708
|
+
return createCloudflareClient(`https://api.cloudflare.com/client/v4/accounts/${config.accountId}`, config.token, fetchImpl);
|
|
1709
|
+
}
|
|
1710
|
+
/** A Cloudflare REST client for requests outside one account, such as `GET /accounts`. */
|
|
1711
|
+
function createCloudflareApiClient(token, fetchImpl = globalThis.fetch) {
|
|
1712
|
+
return createCloudflareClient("https://api.cloudflare.com/client/v4", token, fetchImpl);
|
|
1713
|
+
}
|
|
1714
|
+
function createCloudflareClient(baseURL, token, fetchImpl) {
|
|
1715
|
+
const client = createJsonClient((path) => ({
|
|
1716
|
+
host: "cloudflare",
|
|
1717
|
+
product: cloudflareProductOfPath(path)
|
|
1718
|
+
}), baseURL, { authorization: `Bearer ${token}` }, fetchImpl);
|
|
1719
|
+
return async (path, options = {}) => {
|
|
1720
|
+
const parse = ownParser(options) ?? ((value) => value);
|
|
1721
|
+
return await client(path, {
|
|
1722
|
+
...options,
|
|
1723
|
+
parse(value) {
|
|
1724
|
+
if (!value || Object(value) !== value) throw internalErrorDiagnostics.INTERNAL_R0010({ message: "Cloudflare provisioning returned an invalid response." });
|
|
1725
|
+
const envelope = value;
|
|
1726
|
+
return {
|
|
1727
|
+
...envelope,
|
|
1728
|
+
result: envelope.result === void 0 ? void 0 : parse(envelope.result)
|
|
1729
|
+
};
|
|
1730
|
+
}
|
|
1731
|
+
});
|
|
1732
|
+
};
|
|
1733
|
+
}
|
|
1734
|
+
function createVercelProvisionClient(config, fetchImpl = globalThis.fetch) {
|
|
1735
|
+
return createJsonClient(() => ({ host: "vercel" }), "https://api.vercel.com", { authorization: `Bearer ${config.token}` }, fetchImpl, config.teamId ? { teamId: config.teamId } : void 0);
|
|
1736
|
+
}
|
|
1737
|
+
/** A Netlify REST client for `https://api.netlify.com/api/v1`. */
|
|
1738
|
+
function createNetlifyApiClient(token, fetchImpl = globalThis.fetch) {
|
|
1739
|
+
return createJsonClient(() => ({ host: "netlify" }), "https://api.netlify.com/api/v1", { authorization: `Bearer ${token}` }, fetchImpl);
|
|
1740
|
+
}
|
|
1741
|
+
export { invariant as C, internalErrorDiagnostics as E, quoteSupportedInstallSpecifier as S, isRecordOrFunction as T, featureSupport as _, isProvisionRequestError as a, impliedFeatures as b, resolveVercelProvisionConfig as c, cliErrorDiagnostics as d, loadAllEnv as f, featurePackages as g, featureIds as h, createVercelProvisionClient as i, resolveHostCredentials as l, featureHosts as m, createCloudflareProvisionClient as n, planProvisionSteps as o, withViteStageEnvironment as p, createNetlifyApiClient as r, resolveCloudflareProvisionConfig as s, createCloudflareApiClient as t, runHostCli as u, features as v, isRecord as w, installSpecifier as x, formatInstallArgument as y };
|