@vite-hub/env 0.1.0 → 0.3.1
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 +178 -33
- package/dist/{access-B3qzBHye.js → access-B8lSDip4.js} +1 -1
- package/dist/{bridge-CdNdTN1V.d.ts → bridge-Cs9YfQWk.d.ts} +111 -38
- package/dist/{bridge-error-CFuU5zIz.js → bridge-error-BhJ77age.js} +14 -13
- package/dist/bridge.d.ts +2 -2
- package/dist/bridge.js +168 -6
- package/dist/cli-BPp7rdcA.d.ts +159 -0
- package/dist/{cli-CMQPQbii.js → cli-DLpY0QAo.js} +212 -30
- package/dist/cli.d.ts +2 -2
- package/dist/cli.js +1 -1
- package/dist/database.d.ts +29 -3
- package/dist/database.js +106 -15
- package/dist/declarations-C5XR3aKw.d.ts +58 -0
- package/dist/error-diagnostics-B8RFjQ1V.js +56 -0
- package/dist/index.d.ts +145 -10
- package/dist/index.js +240 -7
- package/dist/internal/agent.d.ts +1 -1
- package/dist/internal/agent.js +2 -2
- package/dist/internal/connections.d.ts +1 -1
- package/dist/internal/connections.js +2 -2
- package/dist/internal/server.d.ts +3 -0
- package/dist/internal/server.js +2 -0
- package/dist/object-_dlsZ4lP.js +276 -0
- package/dist/operation-definition-8gOe-ubD.d.ts +234 -0
- package/dist/operations-X1w--wds.js +30 -0
- package/dist/operations.d.ts +37 -0
- package/dist/operations.js +833 -0
- package/dist/runtime/public-env.d.ts +5 -0
- package/dist/runtime/public-env.js +8 -0
- package/dist/runtime/server-env.d.ts +22 -0
- package/dist/runtime/server-env.js +35 -0
- package/dist/schema-DMZ1_yhY.js +360 -0
- package/dist/seal.d.ts +8 -5
- package/dist/seal.js +9 -6
- package/dist/{secret.js → secret-DJd-fy5T.js} +1 -1
- package/dist/server-ChNL_Xc3.js +1279 -0
- package/dist/server-Dd8bjIKd.d.ts +145 -0
- package/dist/server.d.ts +3 -25
- package/dist/server.js +2 -2
- package/dist/virtual-module.d.ts +6 -6
- package/dist/vite.d.ts +59 -14
- package/dist/vite.js +304 -115
- package/package.json +27 -38
- package/dist/auth.d.ts +0 -32
- package/dist/auth.js +0 -44
- package/dist/cli-DEwcUIe0.d.ts +0 -81
- package/dist/declarations-CiRdb1qP.d.ts +0 -32
- package/dist/declarations-DAVgctKD.js +0 -236
- package/dist/error-diagnostics-CrxjYNYr.js +0 -43
- package/dist/http.d.ts +0 -2
- package/dist/http.js +0 -122
- package/dist/presets.d.ts +0 -20
- package/dist/presets.js +0 -44
- package/dist/provider.d.ts +0 -5
- package/dist/provider.js +0 -8
- package/dist/schema.d.ts +0 -15
- package/dist/schema.js +0 -55
- package/dist/secret-C2191nAa.d.ts +0 -11
- package/dist/secret.d.ts +0 -2
- package/dist/server-DufVswRJ.js +0 -670
- package/dist/values-D_r6V774.js +0 -148
package/dist/index.js
CHANGED
|
@@ -1,7 +1,240 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { SecretEnv } from "./secret.js";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
|
|
1
|
+
import { t as envErrorDiagnostics } from "./error-diagnostics-B8RFjQ1V.js";
|
|
2
|
+
import { r as env, t as parseSchema } from "./schema-DMZ1_yhY.js";
|
|
3
|
+
import { D as verifyViteHubHmacSignature, O as verifyViteHubStripeSignature, T as isViteHubBearerSecretEqual, _ as runtimeEnv, a as isBlockingServerEnvEntry, d as unseal, k as viteHubHmacSha256, u as seal, v as standardSource, w as githubHmacSignatureFormat } from "./server-ChNL_Xc3.js";
|
|
4
|
+
import { t as SecretEnv } from "./secret-DJd-fy5T.js";
|
|
5
|
+
import { defineErrors } from "@vite-hub/runtime";
|
|
6
|
+
import { getStandardContext } from "@vite-hub/runtime/internal/h3";
|
|
7
|
+
import { deriveSecret, describeServerEnv, inspectServerEnv, loadServerEnv, runWithServerEnv, useServerEnv } from "#vitehub/env/server";
|
|
8
|
+
import { usePublicEnv } from "#vitehub/env/public";
|
|
9
|
+
import { HTTPError } from "nitro/h3";
|
|
10
|
+
//#region src/presets.ts
|
|
11
|
+
function openWorkflowEnv(options = {}) {
|
|
12
|
+
return {
|
|
13
|
+
namespaceId: env({
|
|
14
|
+
default: options.namespaceId || "production",
|
|
15
|
+
source: env.source("OPENWORKFLOW_NAMESPACE_ID")
|
|
16
|
+
}),
|
|
17
|
+
postgresUrl: env({
|
|
18
|
+
optional: true,
|
|
19
|
+
secret: true,
|
|
20
|
+
source: env.source(["OPENWORKFLOW_POSTGRES_URL", "DATABASE_URL"])
|
|
21
|
+
}),
|
|
22
|
+
schema: env({
|
|
23
|
+
default: options.schema || "openworkflow",
|
|
24
|
+
source: env.source("OPENWORKFLOW_SCHEMA")
|
|
25
|
+
}),
|
|
26
|
+
workerConcurrency: env({
|
|
27
|
+
default: options.workerConcurrency || "10",
|
|
28
|
+
source: env.source("OPENWORKFLOW_WORKER_CONCURRENCY")
|
|
29
|
+
})
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Declares the Server Env of the `typesafe()` AI gateway from `vite-hub/gateways`: Secret `apiKey`
|
|
34
|
+
* (`TYPESAFE_API_KEY`) and `model` (`TYPESAFE_DEFAULT_MODEL`). `defineAgent({ driver: { ask } })` uses `typesafe()`
|
|
35
|
+
* when it gets no other gateway. The values are optional here: Jev diagnoses a
|
|
36
|
+
* missing key when it runs, so an application without AI still starts.
|
|
37
|
+
*/
|
|
38
|
+
function typesafeEnv(options = {}) {
|
|
39
|
+
return {
|
|
40
|
+
apiKey: env({
|
|
41
|
+
optional: true,
|
|
42
|
+
secret: true,
|
|
43
|
+
source: env.source("TYPESAFE_API_KEY")
|
|
44
|
+
}),
|
|
45
|
+
model: env({
|
|
46
|
+
default: options.model || "jev-latest",
|
|
47
|
+
source: env.source("TYPESAFE_DEFAULT_MODEL")
|
|
48
|
+
})
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
//#endregion
|
|
52
|
+
//#region src/provider.ts
|
|
53
|
+
function defineEnvProvider(provider) {
|
|
54
|
+
if (typeof provider !== "object" || provider === null || Array.isArray(provider) || typeof provider.read !== "function") throw envErrorDiagnostics.ENV_R0013({ message: "[vitehub] defineEnvProvider() requires a provider with a read({ env, keys, signal }) method." });
|
|
55
|
+
return provider;
|
|
56
|
+
}
|
|
57
|
+
//#endregion
|
|
58
|
+
//#region src/service-token.ts
|
|
59
|
+
const serviceTokenErrors = /*#__PURE__*/ defineErrors({
|
|
60
|
+
docs: "https://vitehub.dev/docs/env/diagnostics",
|
|
61
|
+
codes: {
|
|
62
|
+
ENV_SERVICE_TOKEN_INVALID: {
|
|
63
|
+
docs: "https://vitehub.dev/docs/env/diagnostics/env_service_token_invalid",
|
|
64
|
+
why: ({ name }) => `The request has no \`Authorization: Bearer\` token that matches a token in \`${name}\`.`,
|
|
65
|
+
fix: "Send the header `Authorization: Bearer <token>` with a token that the server variable holds. The variable holds one token, or a comma-separated list while you rotate tokens."
|
|
66
|
+
},
|
|
67
|
+
ENV_SERVICE_TOKEN_UNSET: {
|
|
68
|
+
docs: "https://vitehub.dev/docs/env/diagnostics/env_service_token_unset",
|
|
69
|
+
why: ({ name }) => `\`${name}\` has no token on this server, so every request is refused.`,
|
|
70
|
+
fix: "Set the variable to a long random token, such as the output of `openssl rand -base64 32`: in `.env` for `vite dev`, and as a secret on the host for production. To rotate, set the old and the new token separated by a comma, then remove the old one."
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
function readTokens(value) {
|
|
75
|
+
return typeof value === "string" ? value.split(",").map((token) => token.trim()).filter(Boolean) : [];
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Checks that a request carries `Authorization: Bearer <token>` with a token from the host variable `name`, and
|
|
79
|
+
* returns `[error, undefined]`. The variable holds one token, or a comma-separated list, so the old and the new token
|
|
80
|
+
* both pass while you rotate. It compares in constant time. Without a token in the variable, every request fails with
|
|
81
|
+
* `ENV_SERVICE_TOKEN_UNSET`.
|
|
82
|
+
*
|
|
83
|
+
* ```ts [server/api/health.get.ts]
|
|
84
|
+
* import { defineEventHandler } from "h3"
|
|
85
|
+
* import { checkServiceToken } from "vite-hub/env"
|
|
86
|
+
*
|
|
87
|
+
* export default defineEventHandler((event) => {
|
|
88
|
+
* const [error] = checkServiceToken(event, "ADMIN_TOKEN")
|
|
89
|
+
* return error ? { ok: true } : { ok: true, queue: 3 }
|
|
90
|
+
* })
|
|
91
|
+
* ```
|
|
92
|
+
*/
|
|
93
|
+
function checkServiceToken(event, name) {
|
|
94
|
+
const source = standardSource(event);
|
|
95
|
+
const tokens = readTokens(runtimeEnv(source)[name]);
|
|
96
|
+
if (!tokens.length) return [serviceTokenErrors.ENV_SERVICE_TOKEN_UNSET({ name }), void 0];
|
|
97
|
+
const authorization = getStandardContext(source).req.headers.get("authorization");
|
|
98
|
+
let valid = false;
|
|
99
|
+
for (const token of tokens) valid = isViteHubBearerSecretEqual(authorization, token) || valid;
|
|
100
|
+
return valid ? [void 0, void 0] : [serviceTokenErrors.ENV_SERVICE_TOKEN_INVALID({ name }), void 0];
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Returns when a request carries `Authorization: Bearer <token>` with a token from the host variable `name`. Otherwise
|
|
104
|
+
* it throws an `HTTPError`: `401` with `ENV_SERVICE_TOKEN_INVALID`, or `503` with `ENV_SERVICE_TOKEN_UNSET` when the
|
|
105
|
+
* variable has no token. Use it for routes that scripts, runners, and webhooks call.
|
|
106
|
+
*
|
|
107
|
+
* ```ts [server/api/ingest.post.ts]
|
|
108
|
+
* import { defineEventHandler } from "h3"
|
|
109
|
+
* import { requireServiceToken } from "vite-hub/env"
|
|
110
|
+
*
|
|
111
|
+
* export default defineEventHandler((event) => {
|
|
112
|
+
* requireServiceToken(event, "INGEST_TOKEN")
|
|
113
|
+
* return { ok: true }
|
|
114
|
+
* })
|
|
115
|
+
* ```
|
|
116
|
+
*/
|
|
117
|
+
function requireServiceToken(event, name) {
|
|
118
|
+
const [error] = checkServiceToken(event, name);
|
|
119
|
+
if (!error) return;
|
|
120
|
+
const unset = error.code === "ENV_SERVICE_TOKEN_UNSET";
|
|
121
|
+
throw new HTTPError({
|
|
122
|
+
cause: error,
|
|
123
|
+
data: { code: error.code },
|
|
124
|
+
headers: unset ? void 0 : { "www-authenticate": "Bearer" },
|
|
125
|
+
message: error.message,
|
|
126
|
+
status: unset ? 503 : 401
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
//#endregion
|
|
130
|
+
//#region src/webhook.ts
|
|
131
|
+
const webhookErrors = /*#__PURE__*/ defineErrors({
|
|
132
|
+
docs: "https://vitehub.dev/docs/env/diagnostics",
|
|
133
|
+
codes: {
|
|
134
|
+
ENV_WEBHOOK_BODY_INVALID: {
|
|
135
|
+
docs: "https://vitehub.dev/docs/env/diagnostics/env_webhook_body_invalid",
|
|
136
|
+
why: "The webhook has a valid signature, but its body is not JSON, or a GitHub form delivery has no JSON `payload` field.",
|
|
137
|
+
fix: "Set the provider to send JSON. GitHub can send `application/json` or `application/x-www-form-urlencoded`, and `verifyWebhook()` reads both."
|
|
138
|
+
},
|
|
139
|
+
ENV_WEBHOOK_SECRET_UNSET: {
|
|
140
|
+
docs: "https://vitehub.dev/docs/env/diagnostics/env_webhook_secret_unset",
|
|
141
|
+
why: ({ name }) => `\`${name}\` has no webhook secret on this server, so every delivery is refused.`,
|
|
142
|
+
fix: "Set the variable to the signing secret that the provider shows for this endpoint, such as Stripe's `whsec_...` value: in `.env` for `vite dev`, and as a secret on the host for production. To rotate, set the old and the new secret separated by a comma, then remove the old one."
|
|
143
|
+
},
|
|
144
|
+
ENV_WEBHOOK_SIGNATURE_INVALID: {
|
|
145
|
+
docs: "https://vitehub.dev/docs/env/diagnostics/env_webhook_signature_invalid",
|
|
146
|
+
why: ({ header, name }) => `The \`${header}\` header is missing, or it does not match the body signed with a secret in \`${name}\`.`,
|
|
147
|
+
fix: "Set the variable to the signing secret of this endpoint, and do not change the body before `verifyWebhook()` reads it. A Stripe signature also fails when it is older than `toleranceSeconds` (default 300), so check the server clock. Answer with `400`, so the provider shows the failed delivery and sends it again."
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
function readSecrets(value) {
|
|
152
|
+
return typeof value === "string" ? value.split(",").map((secret) => secret.trim()).filter(Boolean) : [];
|
|
153
|
+
}
|
|
154
|
+
function signatureHeader(options) {
|
|
155
|
+
if (options.provider === "stripe") return "stripe-signature";
|
|
156
|
+
if (options.provider === "github") return "x-hub-signature-256";
|
|
157
|
+
return options.header.toLowerCase();
|
|
158
|
+
}
|
|
159
|
+
function verifySignature(options, secret, header, body) {
|
|
160
|
+
if (options.provider === "stripe") return verifyViteHubStripeSignature(secret, header, body, { toleranceSeconds: options.toleranceSeconds });
|
|
161
|
+
if (options.provider === "github") return verifyViteHubHmacSignature(secret, header, body, githubHmacSignatureFormat);
|
|
162
|
+
return verifyViteHubHmacSignature(secret, header, body, options);
|
|
163
|
+
}
|
|
164
|
+
function webhookJson(options, headers, text) {
|
|
165
|
+
if (options.provider !== "github" || !headers.get("content-type")?.toLowerCase().startsWith("application/x-www-form-urlencoded")) return text;
|
|
166
|
+
return new URLSearchParams(text).get("payload");
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Checks the signature of a webhook that Stripe, GitHub, or another provider sends to a route, and returns
|
|
170
|
+
* `[error, body]` with the parsed JSON body. For a GitHub delivery with the form content type, `body` is the JSON
|
|
171
|
+
* of its `payload` field. It reads the raw body once, so do not read the body before you call it.
|
|
172
|
+
* It reads the secret from the server variable `secret` on each request. The variable holds one secret, or a
|
|
173
|
+
* comma-separated list while you rotate. It compares in constant time and runs on every host.
|
|
174
|
+
*
|
|
175
|
+
* ```ts [server/api/stripe/webhook.post.ts]
|
|
176
|
+
* import { defineEventHandler, HTTPError } from "h3"
|
|
177
|
+
* import { verifyWebhook } from "vite-hub/env"
|
|
178
|
+
*
|
|
179
|
+
* export default defineEventHandler(async (event) => {
|
|
180
|
+
* const [error, stripeEvent] = await verifyWebhook<{ type: string }>(event, { provider: "stripe", secret: "STRIPE_WEBHOOK_SECRET" })
|
|
181
|
+
* if (error) throw new HTTPError({ status: 400, message: error.message })
|
|
182
|
+
* return { received: stripeEvent.type }
|
|
183
|
+
* })
|
|
184
|
+
* ```
|
|
185
|
+
*/
|
|
186
|
+
async function verifyWebhook(event, options) {
|
|
187
|
+
const source = standardSource(event);
|
|
188
|
+
const name = options.secret;
|
|
189
|
+
const secrets = readSecrets(runtimeEnv(source)[name]);
|
|
190
|
+
if (!secrets.length) return [webhookErrors.ENV_WEBHOOK_SECRET_UNSET({ name }), void 0];
|
|
191
|
+
const request = getStandardContext(source).req;
|
|
192
|
+
const headerName = signatureHeader(options);
|
|
193
|
+
const header = request.headers.get(headerName);
|
|
194
|
+
if (!header) return [webhookErrors.ENV_WEBHOOK_SIGNATURE_INVALID({
|
|
195
|
+
header: headerName,
|
|
196
|
+
name
|
|
197
|
+
}), void 0];
|
|
198
|
+
const body = new Uint8Array(await request.arrayBuffer());
|
|
199
|
+
let valid = false;
|
|
200
|
+
for (const secret of secrets) valid = await verifySignature(options, secret, header, body) || valid;
|
|
201
|
+
if (!valid) return [webhookErrors.ENV_WEBHOOK_SIGNATURE_INVALID({
|
|
202
|
+
header: headerName,
|
|
203
|
+
name
|
|
204
|
+
}), void 0];
|
|
205
|
+
const json = webhookJson(options, request.headers, new TextDecoder().decode(body));
|
|
206
|
+
if (json === null) return [webhookErrors.ENV_WEBHOOK_BODY_INVALID(), void 0];
|
|
207
|
+
try {
|
|
208
|
+
return [void 0, JSON.parse(json)];
|
|
209
|
+
} catch (cause) {
|
|
210
|
+
return [webhookErrors.ENV_WEBHOOK_BODY_INVALID({ cause }), void 0];
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
function toHex(bytes) {
|
|
214
|
+
return Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Signs the raw body of an outgoing webhook with HMAC-SHA256 and returns the headers to send with it. The receiver
|
|
218
|
+
* checks them with `verifyWebhook()` or the provider's own SDK. Send the exact `body` that you signed. It uses Web
|
|
219
|
+
* Crypto only, so it runs on every host.
|
|
220
|
+
*
|
|
221
|
+
* ```ts
|
|
222
|
+
* import { signWebhook } from "vite-hub/env"
|
|
223
|
+
*
|
|
224
|
+
* const body = JSON.stringify({ type: "deploy.finished" })
|
|
225
|
+
* const headers = await signWebhook(body, { provider: "github", secret: process.env.HOOK_SECRET! })
|
|
226
|
+
* await fetch("https://example.com/hook", { method: "POST", body, headers: { ...headers, "content-type": "application/json" } })
|
|
227
|
+
* ```
|
|
228
|
+
*/
|
|
229
|
+
async function signWebhook(body, options) {
|
|
230
|
+
const bytes = typeof body === "string" ? new TextEncoder().encode(body) : body;
|
|
231
|
+
if (options.provider === "github") return { "x-hub-signature-256": `sha256=${toHex(await viteHubHmacSha256(options.secret, bytes))}` };
|
|
232
|
+
const timestamp = options.timestamp ?? Math.floor(Date.now() / 1e3);
|
|
233
|
+
const prefix = new TextEncoder().encode(`${timestamp}.`);
|
|
234
|
+
const payload = new Uint8Array(prefix.length + bytes.length);
|
|
235
|
+
payload.set(prefix);
|
|
236
|
+
payload.set(bytes, prefix.length);
|
|
237
|
+
return { "stripe-signature": `t=${timestamp},v1=${toHex(await viteHubHmacSha256(options.secret, payload))}` };
|
|
238
|
+
}
|
|
239
|
+
//#endregion
|
|
240
|
+
export { SecretEnv, checkServiceToken, defineEnvProvider, deriveSecret, describeServerEnv, env, inspectServerEnv, isBlockingServerEnvEntry, loadServerEnv, openWorkflowEnv, parseSchema, requireServiceToken, runWithServerEnv, seal, signWebhook, typesafeEnv, unseal, usePublicEnv, useServerEnv, verifyWebhook };
|
package/dist/internal/agent.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { $ as EnvAttribution, t as EnvAccessContext } from "../bridge-Cs9YfQWk.js";
|
|
2
2
|
//#region src/internal/agent.d.ts
|
|
3
3
|
/** Mint only for an identity registered by Agent Definition resolution. Names and copies are untrusted. */
|
|
4
4
|
export declare function agentEnvAccess(agent: unknown, attribution?: EnvAttribution): EnvAccessContext;
|
package/dist/internal/agent.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { t as envBridgeError } from "../bridge-error-
|
|
2
|
-
import { r as grantEnvAccess } from "../access-
|
|
1
|
+
import { t as envBridgeError } from "../bridge-error-BhJ77age.js";
|
|
2
|
+
import { r as grantEnvAccess } from "../access-B8lSDip4.js";
|
|
3
3
|
import { readAgentEnvIdentity, readAgentEnvParents } from "@vite-hub/agent/env-identity";
|
|
4
4
|
//#region src/internal/agent.ts
|
|
5
5
|
/** Mint only for an identity registered by Agent Definition resolution. Names and copies are untrusted. */
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as EnvActor, o as EnvBridge, t as EnvAccessContext } from "../bridge-
|
|
1
|
+
import { a as EnvActor, o as EnvBridge, t as EnvAccessContext } from "../bridge-Cs9YfQWk.js";
|
|
2
2
|
//#region src/internal/connections.d.ts
|
|
3
3
|
/**
|
|
4
4
|
* Internal to `@vite-hub/connections`. Call it only after the Connection access policy allows the call.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { t as envBridgeError } from "../bridge-error-
|
|
2
|
-
import { r as grantEnvAccess, t as envAccessAuthority } from "../access-
|
|
1
|
+
import { t as envBridgeError } from "../bridge-error-BhJ77age.js";
|
|
2
|
+
import { r as grantEnvAccess, t as envAccessAuthority } from "../access-B8lSDip4.js";
|
|
3
3
|
//#region src/internal/connections.ts
|
|
4
4
|
/**
|
|
5
5
|
* Internal to `@vite-hub/connections`. Call it only after the Connection access policy allows the call.
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { G as ServerEnvInspection, K as ServerEnvInspectionEntry, q as ServerEnvInspectionStatus, t as EnvAccessContext } from "../bridge-Cs9YfQWk.js";
|
|
2
|
+
import { _ as unseal, a as describeServerEnv, c as loadServerEnv, d as SealOptions, f as UnsealErrorCode, g as seal, h as createSealing, i as deriveSecret, l as resolveServerEnv, m as UnsealSchemaOptions, n as ViteHubContext, o as inspectServerEnv, p as UnsealOptions, r as bindServerEnvSchemas, s as isBlockingServerEnvEntry, t as DeriveSecretOptions, u as runWithCloudflareEnv } from "../server-Dd8bjIKd.js";
|
|
3
|
+
export { DeriveSecretOptions, type EnvAccessContext, type SealOptions, type ServerEnvInspection, type ServerEnvInspectionEntry, type ServerEnvInspectionStatus, type UnsealErrorCode, type UnsealOptions, type UnsealSchemaOptions, type ViteHubContext, bindServerEnvSchemas, createSealing, deriveSecret, describeServerEnv, inspectServerEnv, isBlockingServerEnvEntry, loadServerEnv, resolveServerEnv, runWithCloudflareEnv, seal, unseal };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as isBlockingServerEnvEntry, c as runWithCloudflareEnv, d as unseal, i as inspectServerEnv, l as createSealing, n as deriveSecret, o as loadServerEnv, r as describeServerEnv, s as resolveServerEnv, t as bindServerEnvSchemas, u as seal } from "../server-ChNL_Xc3.js";
|
|
2
|
+
export { bindServerEnvSchemas, createSealing, deriveSecret, describeServerEnv, inspectServerEnv, isBlockingServerEnvEntry, loadServerEnv, resolveServerEnv, runWithCloudflareEnv, seal, unseal };
|
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
import { defineDiagnostics } from "nostics";
|
|
2
|
+
//#region ../internal/src/error-diagnostics.ts
|
|
3
|
+
const dynamicError = { why: ({ message }) => message === void 0 ? "" : String(message) };
|
|
4
|
+
const internalErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
|
|
5
|
+
docsBase: "https://vitehub.dev/docs/development/diagnostics",
|
|
6
|
+
codes: {
|
|
7
|
+
INTERNAL_R0012: {
|
|
8
|
+
...dynamicError,
|
|
9
|
+
fix: "Check the URL, the headers, and the credentials of the HTTP request. `error.status` holds the status that the server sent."
|
|
10
|
+
},
|
|
11
|
+
INTERNAL_R0013: {
|
|
12
|
+
...dynamicError,
|
|
13
|
+
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."
|
|
14
|
+
},
|
|
15
|
+
INTERNAL_R0014: {
|
|
16
|
+
why: ({ path }) => `Cannot read Provision State from "${path}".`,
|
|
17
|
+
fix: "Check file access and restore valid JSON while preserving existing resource IDs."
|
|
18
|
+
},
|
|
19
|
+
INTERNAL_R0020: {
|
|
20
|
+
fix: "Give the operation a name like `content.publish`, a description, a section, a kind, an input schema, and a run function.",
|
|
21
|
+
why: ({ message }) => message === void 0 ? "" : String(message)
|
|
22
|
+
},
|
|
23
|
+
INTERNAL_R0021: {
|
|
24
|
+
fix: "Run `vitehub inspect definitions --kind operation` to list the operations of this app.",
|
|
25
|
+
why: ({ message }) => message === void 0 ? "" : String(message)
|
|
26
|
+
},
|
|
27
|
+
INTERNAL_R0022: {
|
|
28
|
+
fix: "Send input that matches the schema of the operation. `vitehub <namespace> <command> --help` shows the fields.",
|
|
29
|
+
why: ({ message }) => message === void 0 ? "" : String(message)
|
|
30
|
+
},
|
|
31
|
+
INTERNAL_R0024: {
|
|
32
|
+
fix: "Start the dev server with `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>.",
|
|
33
|
+
why: ({ message }) => message === void 0 ? "" : String(message)
|
|
34
|
+
},
|
|
35
|
+
INTERNAL_R0023: {
|
|
36
|
+
fix: "Ask for access to the section of this operation.",
|
|
37
|
+
why: ({ message }) => message === void 0 ? "" : String(message)
|
|
38
|
+
},
|
|
39
|
+
INTERNAL_B0001: {
|
|
40
|
+
...dynamicError,
|
|
41
|
+
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."
|
|
42
|
+
},
|
|
43
|
+
INTERNAL_B0015: {
|
|
44
|
+
...dynamicError,
|
|
45
|
+
fix: "Install one version of the package that the message names, for example with `pnpm dedupe` or an `overrides` entry in `package.json`."
|
|
46
|
+
},
|
|
47
|
+
INTERNAL_B0016: {
|
|
48
|
+
...dynamicError,
|
|
49
|
+
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."
|
|
50
|
+
},
|
|
51
|
+
INTERNAL_B0017: {
|
|
52
|
+
...dynamicError,
|
|
53
|
+
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."
|
|
54
|
+
},
|
|
55
|
+
INTERNAL_B0018: {
|
|
56
|
+
...dynamicError,
|
|
57
|
+
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."
|
|
58
|
+
},
|
|
59
|
+
INTERNAL_B0019: {
|
|
60
|
+
...dynamicError,
|
|
61
|
+
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."
|
|
62
|
+
},
|
|
63
|
+
INTERNAL_B0020: {
|
|
64
|
+
...dynamicError,
|
|
65
|
+
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."
|
|
66
|
+
},
|
|
67
|
+
INTERNAL_B0021: {
|
|
68
|
+
...dynamicError,
|
|
69
|
+
fix: "Install the package that the message names in the app, for example with `pnpm add <name>`, then build again."
|
|
70
|
+
},
|
|
71
|
+
INTERNAL_B0022: {
|
|
72
|
+
...dynamicError,
|
|
73
|
+
fix: "Install one version of the package that the message names, for example with `pnpm dedupe` or an `overrides` entry in `package.json`."
|
|
74
|
+
},
|
|
75
|
+
INTERNAL_B0025: {
|
|
76
|
+
...dynamicError,
|
|
77
|
+
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."
|
|
78
|
+
},
|
|
79
|
+
INTERNAL_B0026: {
|
|
80
|
+
...dynamicError,
|
|
81
|
+
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>\")`."
|
|
82
|
+
},
|
|
83
|
+
INTERNAL_B0027: {
|
|
84
|
+
...dynamicError,
|
|
85
|
+
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`."
|
|
86
|
+
},
|
|
87
|
+
INTERNAL_B0028: {
|
|
88
|
+
...dynamicError,
|
|
89
|
+
fix: "Wait for the other build of this app to finish, or stop the process that the message names, then build again."
|
|
90
|
+
},
|
|
91
|
+
INTERNAL_B0029: {
|
|
92
|
+
...dynamicError,
|
|
93
|
+
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."
|
|
94
|
+
},
|
|
95
|
+
INTERNAL_B0031: {
|
|
96
|
+
...dynamicError,
|
|
97
|
+
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."
|
|
98
|
+
},
|
|
99
|
+
INTERNAL_B0032: {
|
|
100
|
+
...dynamicError,
|
|
101
|
+
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."
|
|
102
|
+
},
|
|
103
|
+
INTERNAL_B0035: {
|
|
104
|
+
...dynamicError,
|
|
105
|
+
fix: "Delete the provider output folder that holds the file that the message names, such as `dist/<app>` for Cloudflare, and build again."
|
|
106
|
+
},
|
|
107
|
+
INTERNAL_B0039: {
|
|
108
|
+
...dynamicError,
|
|
109
|
+
fix: "Fix the build error that ViteHub showed before this one. ViteHub stops writing the provider output when another part of the build fails."
|
|
110
|
+
},
|
|
111
|
+
INTERNAL_B0040: {
|
|
112
|
+
...dynamicError,
|
|
113
|
+
fix: "Remove the custom Nitro `output.serverDir`, so that the Nitro preset of the host writes the server entry that the message names."
|
|
114
|
+
},
|
|
115
|
+
INTERNAL_B0043: {
|
|
116
|
+
...dynamicError,
|
|
117
|
+
fix: "Delete the build output folder, such as `.output` or `.vercel/output`, and build again."
|
|
118
|
+
},
|
|
119
|
+
INTERNAL_B0046: {
|
|
120
|
+
...dynamicError,
|
|
121
|
+
fix: "Install the package that the message names in the app, for example with `pnpm add <name>`, then build again."
|
|
122
|
+
},
|
|
123
|
+
INTERNAL_B0047: {
|
|
124
|
+
...dynamicError,
|
|
125
|
+
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."
|
|
126
|
+
},
|
|
127
|
+
INTERNAL_B0048: {
|
|
128
|
+
fix: "Rename one of the two operations. A name is `<section>.<verb>` and is unique in the app.",
|
|
129
|
+
why: ({ message }) => message === void 0 ? "" : String(message)
|
|
130
|
+
},
|
|
131
|
+
INTERNAL_B0049: {
|
|
132
|
+
fix: "Set `cli: { namespace, command }` on one of the two operations.",
|
|
133
|
+
why: ({ message }) => message === void 0 ? "" : String(message)
|
|
134
|
+
},
|
|
135
|
+
INTERNAL_B0050: {
|
|
136
|
+
fix: "Rename one of the two operations, or set `mcp: false` on it. MCP tool names replace every character outside letters, digits, `_`, and `-` with `_`.",
|
|
137
|
+
why: ({ message }) => message === void 0 ? "" : String(message)
|
|
138
|
+
},
|
|
139
|
+
INTERNAL_B0051: {
|
|
140
|
+
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}.`,
|
|
141
|
+
fix: "Remove the entry from the project's Wrangler config, since ViteHub writes it, or give one of them another name."
|
|
142
|
+
},
|
|
143
|
+
INTERNAL_B0052: {
|
|
144
|
+
why: ({ column, section }) => `The column "${column}" of the Console section "${section}" needs both \`format: "switch"\` and a \`switch\` operation name such as "skills.set".`,
|
|
145
|
+
fix: "Give a switch column `format: \"switch\"` and `switch: { operation, input }` with a registered operation name, or remove both."
|
|
146
|
+
},
|
|
147
|
+
INTERNAL_R0025: {
|
|
148
|
+
fix: "Start `vite dev` in the project that you run the command from, or pass `--url` of that server.",
|
|
149
|
+
why: ({ message }) => message === void 0 ? "" : String(message)
|
|
150
|
+
},
|
|
151
|
+
INTERNAL_R0026: {
|
|
152
|
+
why: "The server parsed a destructive operation that the CLI did not confirm.",
|
|
153
|
+
fix: "Review the operation, then run it again with --yes to confirm the change."
|
|
154
|
+
},
|
|
155
|
+
INTERNAL_C0001: {
|
|
156
|
+
...dynamicError,
|
|
157
|
+
fix: "Rename or remove one of the two files that the message lists. ViteHub takes the Definition name from the file path."
|
|
158
|
+
},
|
|
159
|
+
INTERNAL_C0002: {
|
|
160
|
+
...dynamicError,
|
|
161
|
+
fix: "Rename or remove one of the two files that the message lists. ViteHub takes the Definition name from the file path."
|
|
162
|
+
},
|
|
163
|
+
INTERNAL_R0001: {
|
|
164
|
+
...dynamicError,
|
|
165
|
+
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."
|
|
166
|
+
},
|
|
167
|
+
INTERNAL_R0002: {
|
|
168
|
+
...dynamicError,
|
|
169
|
+
fix: "Stop using the feature that the message names, or set `host` in `vitehub()` to a host that provides it. For Blob, you can also set `blob: { driver: \"s3\" }` with a remote store."
|
|
170
|
+
},
|
|
171
|
+
INTERNAL_R0004: {
|
|
172
|
+
...dynamicError,
|
|
173
|
+
fix: "Set a larger `maxResponseBytes` on the HTTP request, such as the `fetch()` Source options, or ask the server for a smaller response."
|
|
174
|
+
},
|
|
175
|
+
INTERNAL_R0005: {
|
|
176
|
+
...dynamicError,
|
|
177
|
+
fix: "Set `method` of the HTTP request to `GET`, `HEAD`, or `POST`."
|
|
178
|
+
},
|
|
179
|
+
INTERNAL_R0006: {
|
|
180
|
+
...dynamicError,
|
|
181
|
+
fix: "Set `timeout` of the HTTP request to a number of milliseconds from 1 to 2147483647, or remove it to use the default."
|
|
182
|
+
},
|
|
183
|
+
INTERNAL_R0007: {
|
|
184
|
+
...dynamicError,
|
|
185
|
+
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."
|
|
186
|
+
},
|
|
187
|
+
INTERNAL_R0008: {
|
|
188
|
+
...dynamicError,
|
|
189
|
+
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."
|
|
190
|
+
},
|
|
191
|
+
INTERNAL_R0009: {
|
|
192
|
+
...dynamicError,
|
|
193
|
+
fix: "Use a Standard Schema whose `validate()` returns `{ value }` or `{ issues }` for the value that the message names."
|
|
194
|
+
},
|
|
195
|
+
INTERNAL_R0010: {
|
|
196
|
+
...dynamicError,
|
|
197
|
+
fix: "Run the command again. If the error stays, check the Cloudflare API status, because Cloudflare sent a response that ViteHub cannot read."
|
|
198
|
+
},
|
|
199
|
+
INTERNAL_R0011: {
|
|
200
|
+
...dynamicError,
|
|
201
|
+
fix: "Pass an h3 app, an object with a `fetch(request)` method, or a fetch function as `app`."
|
|
202
|
+
},
|
|
203
|
+
INTERNAL_CONSOLE_KEY_NAME_INVALID: {
|
|
204
|
+
why: ({ name }) => `[vitehub] The Console key name ${JSON.stringify(name)} must be 1 to 64 of A-Z, 0-9, and _.`,
|
|
205
|
+
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>`."
|
|
206
|
+
},
|
|
207
|
+
INTERNAL_CONSOLE_PRIVATE_KEY_INVALID: {
|
|
208
|
+
why: "[vitehub] A Console private key is the 32-byte Ed25519 seed as base64url (43 characters). `vitehub secret console-key` makes one.",
|
|
209
|
+
fix: "Run `vitehub secret console-key` and use the 43-character private key that it prints, without spaces or quotes."
|
|
210
|
+
},
|
|
211
|
+
INTERNAL_CONSOLE_PRIVATE_KEY_VARIABLES_MULTIPLE: {
|
|
212
|
+
why: ({ prefix, variables }) => `[vitehub] Set one ${prefix}<NAME> variable. This environment has ${variables}.`,
|
|
213
|
+
fix: "Keep one `VITEHUB_CONSOLE_PRIVATE_KEY_<NAME>` variable in the environment of the command, and unset the others that the message names."
|
|
214
|
+
},
|
|
215
|
+
INTERNAL_CONSOLE_PRIVATE_KEY_VARIABLE_INVALID: {
|
|
216
|
+
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 _.`,
|
|
217
|
+
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>`."
|
|
218
|
+
},
|
|
219
|
+
INTERNAL_FORGE_NOT_INSTALLED: {
|
|
220
|
+
why: ({ feature }) => `${feature} needs @vite-hub/forge, and the app did not install it.`,
|
|
221
|
+
fix: "Install Forge in your app with `pnpm add @vite-hub/forge`, then build again."
|
|
222
|
+
},
|
|
223
|
+
INTERNAL_MCP_ARGUMENTS_INVALID: {
|
|
224
|
+
why: ({ detail }) => detail,
|
|
225
|
+
fix: "Pass the prompt or resource the arguments that `prompts/list` or `resources/templates/list` describes for it."
|
|
226
|
+
},
|
|
227
|
+
INTERNAL_MCP_METHOD_FAILED: {
|
|
228
|
+
why: ({ name }) => `${name} failed on the server.`,
|
|
229
|
+
fix: "Read the server log for the error of the MCP prompt or resource that the message names, and fix its handler."
|
|
230
|
+
},
|
|
231
|
+
INTERNAL_MCP_RESOURCE_NOT_FOUND: {
|
|
232
|
+
why: ({ uri }) => `Resource not found: ${uri}. Call resources/list or resources/templates/list for the resources of this server.`,
|
|
233
|
+
fix: "Call `resources/list` or `resources/templates/list`, and read a URI that one of them returns."
|
|
234
|
+
},
|
|
235
|
+
INTERNAL_PRESET_OPTION_UNKNOWN: {
|
|
236
|
+
why: ({ key, label }) => `[vitehub] Unknown ${label} option "${key}".`,
|
|
237
|
+
fix: "Remove the option that the message names from the preset options, or correct its spelling to an option that the preset declares."
|
|
238
|
+
},
|
|
239
|
+
INTERNAL_PRESET_TUPLE_INVALID: {
|
|
240
|
+
why: ({ owner }) => `[vitehub] ${owner} extends tuple requires [preset, options] with an options object.`,
|
|
241
|
+
fix: "Set `extends` to a preset, or to a two-item tuple `[preset, { ...options }]` whose second item is a plain object."
|
|
242
|
+
},
|
|
243
|
+
INTERNAL_SECRET_PURPOSE_MISSING: {
|
|
244
|
+
why: "[vitehub] A derived secret requires a purpose.",
|
|
245
|
+
fix: "Pass a non-empty purpose to `deriveSecret()`, such as `deriveSecret(\"my-module:session\")`."
|
|
246
|
+
},
|
|
247
|
+
INTERNAL_SECRET_TOO_SHORT: {
|
|
248
|
+
why: ({ minimum }) => `[vitehub] VITEHUB_SECRET must be at least ${minimum} characters. Generate one with \`openssl rand -base64 32\`.`,
|
|
249
|
+
fix: "Set `VITEHUB_SECRET` to the output of `openssl rand -base64 32`, which has 44 characters."
|
|
250
|
+
},
|
|
251
|
+
INTERNAL_SQLITE_ARGUMENT_INVALID: {
|
|
252
|
+
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",
|
|
253
|
+
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."
|
|
254
|
+
},
|
|
255
|
+
INTERNAL_SQLITE_INTEGER_UNSAFE: {
|
|
256
|
+
why: "Received integer which cannot be safely represented as a JavaScript number",
|
|
257
|
+
fix: "Create the client with `intMode: \"bigint\"` or `intMode: \"string\"`, or read the column with `CAST(column AS TEXT)` in the query."
|
|
258
|
+
},
|
|
259
|
+
INTERNAL_VALIBOT_JSON_SCHEMA_TARGET_UNSUPPORTED: {
|
|
260
|
+
why: ({ target }) => `[vitehub] Valibot cannot convert a schema to the ${target} JSON Schema target.`,
|
|
261
|
+
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 })`."
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
});
|
|
265
|
+
//#endregion
|
|
266
|
+
//#region ../internal/src/object.ts
|
|
267
|
+
/** A non-null object that is not an array. Functions do not pass. */
|
|
268
|
+
function isRecord(value) {
|
|
269
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
270
|
+
}
|
|
271
|
+
/** A non-null object or a function that is not an array. */
|
|
272
|
+
function isRecordOrFunction(value) {
|
|
273
|
+
return Object(value) === value && !Array.isArray(value);
|
|
274
|
+
}
|
|
275
|
+
//#endregion
|
|
276
|
+
export { isRecordOrFunction as n, internalErrorDiagnostics as r, isRecord as t };
|