@vite-hub/env 0.4.0 → 0.5.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 -2
- package/dist/{access-B8lSDip4.js → access-C5sPO6C2.js} +1 -1
- package/dist/{bridge-error-BhJ77age.js → bridge-error-t9bc6xvE.js} +0 -1
- package/dist/bridge.js +5 -3
- package/dist/cli-BctSFldY.js +1363 -0
- package/dist/{cli-BPp7rdcA.d.ts → cli-DJtQF4Wi.d.ts} +1 -0
- package/dist/cli.d.ts +1 -1
- package/dist/cli.js +1 -1
- package/dist/database.js +1 -3
- package/dist/{declarations-C5XR3aKw.d.ts → declarations-BEL0yvEY.d.ts} +0 -18
- package/dist/{error-diagnostics-DsDPsST_.js → error-diagnostics-CwQGNVnK.js} +1 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +3 -3
- package/dist/internal/agent.js +2 -2
- package/dist/internal/connections.js +2 -2
- package/dist/internal/server.d.ts +1 -1
- package/dist/internal/server.js +1 -1
- package/dist/{object-C7Jt4ez2.js → object-DICxAEoH.js} +5 -1
- package/dist/{operation-definition-nmRu_O3V.d.ts → operation-definition-CI2PJGqu.d.ts} +8 -2
- package/dist/{operations-B1PFpKzy.js → operations-LVaCzpR0.js} +1 -1
- package/dist/operations.d.ts +1 -1
- package/dist/operations.js +3 -3
- package/dist/runtime/public-env.js +1 -1
- package/dist/runtime/server-env.js +1 -1
- package/dist/{schema-C_a0WZyd.js → schema-CnCp0Muw.js} +39 -36
- package/dist/{server-B9-8r6MZ.js → server-Ct3uvhf9.js} +6 -18
- package/dist/{server-CgKAEAE6.d.ts → server-OvARy_y9.d.ts} +0 -1
- package/dist/server.d.ts +1 -1
- package/dist/server.js +1 -1
- package/dist/vite.d.ts +4 -4
- package/dist/vite.js +4 -20
- package/package.json +3 -3
- package/dist/cli-C51D6V-M.js +0 -669
|
@@ -3,6 +3,7 @@ import { Diagnostic } from "nostics";
|
|
|
3
3
|
interface HostCliRunResult {
|
|
4
4
|
exitCode: number | null;
|
|
5
5
|
stdout: string;
|
|
6
|
+
stderr?: string;
|
|
6
7
|
}
|
|
7
8
|
/** Runs a host CLI with an argument array and no shell, and returns its stdout. */
|
|
8
9
|
type HostCliRun = (command: string, args: readonly string[], options: {
|
package/dist/cli.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { G as ServerEnvInspection, K as ServerEnvInspectionEntry } from "./bridge-Cs9YfQWk.js";
|
|
2
|
-
import { n as ViteHubCliContributor, t as ViteHubCliContext } from "./cli-
|
|
2
|
+
import { n as ViteHubCliContributor, t as ViteHubCliContext } from "./cli-DJtQF4Wi.js";
|
|
3
3
|
//#region src/secret-cli.d.ts
|
|
4
4
|
interface SecretCliContext {
|
|
5
5
|
env: Readonly<Record<string, string | undefined>>;
|
package/dist/cli.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as secretCliFeatures, t as createEnvCliContributor } from "./cli-
|
|
1
|
+
import { n as secretCliFeatures, t as createEnvCliContributor } from "./cli-BctSFldY.js";
|
|
2
2
|
export { createEnvCliContributor, secretCliFeatures };
|
package/dist/database.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { t as envBridgeError } from "./bridge-error-
|
|
1
|
+
import { t as envBridgeError } from "./bridge-error-t9bc6xvE.js";
|
|
2
2
|
import { importSealKey, sealKeyId, sealWithKey, sealedPayloadPattern, unsealWithKey } from "./seal.js";
|
|
3
3
|
import { ViteHubError } from "@vite-hub/runtime";
|
|
4
4
|
import * as v from "valibot";
|
|
5
5
|
import { sql } from "drizzle-orm";
|
|
6
6
|
//#region src/database.ts
|
|
7
|
-
/** A stored value: `v2:<keyId>:<iv>:<ciphertext>`, or a legacy `<iv>:<ciphertext>` without a key id. */
|
|
8
7
|
const storedPayloadPattern = new RegExp(`^(?:v2:[a-f0-9]{16}:)?${sealedPayloadPattern.source.slice(1, -1)}$`);
|
|
9
8
|
const identifier = v.pipe(v.string(), v.minLength(1), v.maxLength(512), v.regex(/^[^\u0000-\u001f]+$/));
|
|
10
9
|
const actor = v.object({
|
|
@@ -83,7 +82,6 @@ const listRow = v.object({
|
|
|
83
82
|
preview: v.nullable(v.string())
|
|
84
83
|
});
|
|
85
84
|
const namespaceRow = v.object({ namespace: v.string() });
|
|
86
|
-
/** Create the Env tables when they are missing. Each store and `listDatabaseEnvNamespaces()` calls it first. */
|
|
87
85
|
async function createEnvTables(db) {
|
|
88
86
|
await db.run(sql`CREATE TABLE IF NOT EXISTS vitehub_env_secrets (namespace TEXT NOT NULL, key TEXT NOT NULL, payload TEXT NOT NULL, revision TEXT NOT NULL, updated_at TEXT NOT NULL, preview TEXT, PRIMARY KEY (namespace, key))`);
|
|
89
87
|
await db.run(sql`CREATE TABLE IF NOT EXISTS vitehub_env_activity (sequence INTEGER PRIMARY KEY AUTOINCREMENT, namespace TEXT NOT NULL, key TEXT NOT NULL, id TEXT NOT NULL UNIQUE, payload TEXT NOT NULL)`);
|
|
@@ -8,46 +8,28 @@ interface StandardSchemaLike {
|
|
|
8
8
|
}
|
|
9
9
|
interface EnvNamespace {
|
|
10
10
|
(options?: EnvVariableOptions): EnvVariableDeclaration;
|
|
11
|
-
/** Parse `true`, `false`, `1`, or `0` into a boolean. */
|
|
12
11
|
boolean: (options?: EnvTypedVariableOptions<boolean>) => EnvVariableDeclaration;
|
|
13
12
|
buildTimestamp: () => EnvSource;
|
|
14
13
|
custom: (label: string, resolver: EnvSourceResolver) => EnvSource;
|
|
15
|
-
/** Accept only the listed strings. The values are public metadata, so an enum cannot be secret. */
|
|
16
14
|
enum: <const TValues extends readonly [string, ...string[]]>(values: TValues, options?: EnvTypedVariableOptions<TValues[number]> & {
|
|
17
15
|
secret?: never;
|
|
18
16
|
}) => EnvVariableDeclaration;
|
|
19
|
-
/** The current branch: `GIT_BRANCH`, then `GITHUB_HEAD_REF`, then `GITHUB_REF_NAME` on a GitHub branch ref, then local Git. */
|
|
20
17
|
gitBranch: () => EnvSource;
|
|
21
|
-
/** The current commit SHA: `GIT_SHA`, then `GITHUB_SHA`, then local Git. `short` keeps 7 characters of a CI value. */
|
|
22
18
|
gitCommit: (options?: {
|
|
23
19
|
short?: boolean;
|
|
24
20
|
}) => EnvSource;
|
|
25
|
-
/** The current tag, or `undefined`: `GIT_TAG`, then `GITHUB_REF_NAME` on a GitHub tag ref, then local Git. */
|
|
26
21
|
gitTag: () => EnvSource;
|
|
27
|
-
/**
|
|
28
|
-
* Parse a JSON value. In `env.server`, validate it with `env.json(env.schemaFrom(module, exportName))`.
|
|
29
|
-
* With `mode: "build"`, pass the Standard Schema itself. Without a schema, the value is `unknown`.
|
|
30
|
-
*/
|
|
31
22
|
json: {
|
|
32
23
|
(options?: EnvTypedVariableOptions<unknown>): EnvVariableDeclaration;
|
|
33
24
|
(schema: EnvSchemaModuleReference | StandardSchemaLike, options?: EnvTypedVariableOptions<unknown>): EnvVariableDeclaration;
|
|
34
25
|
};
|
|
35
|
-
/**
|
|
36
|
-
* Parse a list separated by commas or line breaks. Items are trimmed and empty items are dropped. Pass `env.number()`, `env.boolean()`,
|
|
37
|
-
* or `env.enum()` to parse each item, for example `env.list(env.number())`.
|
|
38
|
-
*/
|
|
39
26
|
list: {
|
|
40
27
|
(options?: EnvTypedVariableOptions<readonly EnvListItem[]>): EnvVariableDeclaration;
|
|
41
28
|
(item: EnvVariableDeclaration, options?: EnvTypedVariableOptions<readonly EnvListItem[]>): EnvVariableDeclaration;
|
|
42
29
|
};
|
|
43
|
-
/** Parse a finite number. */
|
|
44
30
|
number: (options?: EnvTypedVariableOptions<number>) => EnvVariableDeclaration;
|
|
45
31
|
packageJson: (path: string) => EnvSource;
|
|
46
32
|
provider: (provider: string, key: string) => EnvSource;
|
|
47
|
-
/**
|
|
48
|
-
* Validate a Server Env value with a Standard Schema exported by a module, for example `env.schemaFrom("./server/env.schema.ts", "apiUrl")`.
|
|
49
|
-
* The server build imports the module, so refinements and transforms run on every resolution.
|
|
50
|
-
*/
|
|
51
33
|
schemaFrom: (module: string, exportName?: string) => EnvSchemaModuleReference;
|
|
52
34
|
source: (name: string | string[], options?: {
|
|
53
35
|
canonical?: boolean;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { defineDiagnostics } from "nostics";
|
|
2
2
|
//#region src/error-diagnostics.ts
|
|
3
3
|
const dynamicError = { why: ({ message }) => message === void 0 ? "" : String(message) };
|
|
4
|
-
/** A code whose call site passes the message as `why`. Pass the fix as a string literal: the docs catalog reads only literals. */
|
|
5
4
|
const withFix = (fix) => ({
|
|
6
5
|
...dynamicError,
|
|
7
6
|
fix
|
|
@@ -13,7 +12,7 @@ const envErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
|
|
|
13
12
|
ENV_R0002: withFix("Pass one or more variable names, for example `env.source('DATABASE_URL')`."),
|
|
14
13
|
ENV_R0003: withFix("Use a key of `vitehub({ env: { providers } })` or `hubEnv({ providers })` as the provider name, for example `env.provider('vault', 'db/password')`."),
|
|
15
14
|
ENV_R0004: withFix("Pass the key that the provider reads as the second argument, for example `env.provider('vault', 'db/password')`."),
|
|
16
|
-
ENV_R0005: withFix("Pass one plain options object
|
|
15
|
+
ENV_R0005: withFix("Pass one plain options object with only `default`, `mode`, `optional`, `schema`, `secret`, `source`, or `type`, for example `env({ secret: true })`."),
|
|
17
16
|
ENV_R0006: withFix("Remove `required`: a value is required by default. Set `optional: true` for a value that can be missing, or a `default` for a fallback value, not both."),
|
|
18
17
|
ENV_R0008: withFix("Change the Env declaration at the path in the error details, as the message says."),
|
|
19
18
|
ENV_R0009: withFix("Load Server Env with `await loadServerEnv()`, or run the code in `runWithServerEnv()`. A provider value cannot be read without `await`."),
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { A as EnvRuntimeRegistry, B as PublicEnv, C as EnvMode, D as EnvProviderValues, E as EnvProviderContext, F as EnvTypedVariableOptions, G as ServerEnvInspection, H as ServerEnv, I as EnvValueSchema, K as ServerEnvInspectionEntry, L as EnvVariableDeclaration, M as EnvSource, N as EnvSourceContext, O as EnvProviders, P as EnvSourceResolver, Q as SecretEnv, R as EnvVariableOptions, S as EnvDiagnostics, T as EnvProvider, U as ServerEnvDescription, V as ReadonlyServerEnv, W as ServerEnvDescriptionEntry, b as EnvDeclarations, j as EnvSchemaModuleReference, k as EnvRuntimeConfigOptions, q as ServerEnvInspectionStatus, w as EnvOptions, x as EnvDiagnosticEntry, y as DeepReadonly, z as LoadServerEnvOptions } from "./bridge-Cs9YfQWk.js";
|
|
2
|
-
import { t as env } from "./declarations-
|
|
3
|
-
import { C as parseSchema, S as StandardSchemaV1, _ as unseal, b as StandardSchemaResultFailure, d as SealOptions, f as UnsealErrorCode, g as seal, m as UnsealSchemaOptions, p as UnsealOptions, s as isBlockingServerEnvEntry, v as SealUsesDatabase, x as StandardSchemaResultSuccess, y as RequestEvent } from "./server-
|
|
2
|
+
import { t as env } from "./declarations-BEL0yvEY.js";
|
|
3
|
+
import { C as parseSchema, S as StandardSchemaV1, _ as unseal, b as StandardSchemaResultFailure, d as SealOptions, f as UnsealErrorCode, g as seal, m as UnsealSchemaOptions, p as UnsealOptions, s as isBlockingServerEnvEntry, v as SealUsesDatabase, x as StandardSchemaResultSuccess, y as RequestEvent } from "./server-OvARy_y9.js";
|
|
4
4
|
import { Result, ViteHubError } from "@vite-hub/runtime";
|
|
5
5
|
import { deriveSecret, describeServerEnv, inspectServerEnv, loadServerEnv, runWithServerEnv, useServerEnv } from "#vitehub/env/server";
|
|
6
6
|
import { usePublicEnv } from "#vitehub/env/public";
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { t as envErrorDiagnostics } from "./error-diagnostics-
|
|
2
|
-
import { r as env, t as parseSchema } from "./schema-
|
|
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-
|
|
1
|
+
import { t as envErrorDiagnostics } from "./error-diagnostics-CwQGNVnK.js";
|
|
2
|
+
import { r as env, t as parseSchema } from "./schema-CnCp0Muw.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-Ct3uvhf9.js";
|
|
4
4
|
import { t as SecretEnv } from "./secret-DJd-fy5T.js";
|
|
5
5
|
import { defineErrors } from "@vite-hub/runtime";
|
|
6
6
|
import { getStandardContext } from "@vite-hub/runtime/internal/h3";
|
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-t9bc6xvE.js";
|
|
2
|
+
import { r as grantEnvAccess } from "../access-C5sPO6C2.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,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-t9bc6xvE.js";
|
|
2
|
+
import { r as grantEnvAccess, t as envAccessAuthority } from "../access-C5sPO6C2.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.
|
|
@@ -1,3 +1,3 @@
|
|
|
1
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-
|
|
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-OvARy_y9.js";
|
|
3
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 };
|
package/dist/internal/server.js
CHANGED
|
@@ -1,2 +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-
|
|
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-Ct3uvhf9.js";
|
|
2
2
|
export { bindServerEnvSchemas, createSealing, deriveSecret, describeServerEnv, inspectServerEnv, isBlockingServerEnvEntry, loadServerEnv, resolveServerEnv, runWithCloudflareEnv, seal, unseal };
|
|
@@ -25,7 +25,7 @@ const internalErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
|
|
|
25
25
|
why: ({ message }) => message === void 0 ? "" : String(message)
|
|
26
26
|
},
|
|
27
27
|
INTERNAL_R0022: {
|
|
28
|
-
fix: "Send input that matches the schema of the operation. `vitehub <namespace> <command> --help` shows the fields.",
|
|
28
|
+
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.",
|
|
29
29
|
why: ({ message }) => message === void 0 ? "" : String(message)
|
|
30
30
|
},
|
|
31
31
|
INTERNAL_R0024: {
|
|
@@ -244,6 +244,10 @@ const internalErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
|
|
|
244
244
|
why: ({ owner }) => `[vitehub] ${owner} extends tuple requires [preset, options] with an options object.`,
|
|
245
245
|
fix: "Set `extends` to a preset, or to a two-item tuple `[preset, { ...options }]` whose second item is a plain object."
|
|
246
246
|
},
|
|
247
|
+
INTERNAL_RUNTIME_PACKAGE_VERSION_CONFLICT: {
|
|
248
|
+
why: ({ first, name, second }) => `[vitehub] One server function needs ${name} from two installations: ${first} and ${second}.`,
|
|
249
|
+
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."
|
|
250
|
+
},
|
|
247
251
|
INTERNAL_SECRET_PURPOSE_MISSING: {
|
|
248
252
|
why: "[vitehub] A derived secret requires a purpose.",
|
|
249
253
|
fix: "Pass a non-empty purpose to `deriveSecret()`, such as `deriveSecret(\"my-module:session\")`."
|
|
@@ -104,6 +104,11 @@ interface OperationAccess {
|
|
|
104
104
|
*/
|
|
105
105
|
readonly sections: "all" | readonly string[];
|
|
106
106
|
readonly user?: OperationUser;
|
|
107
|
+
/**
|
|
108
|
+
* Who signed the call: `"console"` when the ViteHub Console signed it for a person, whose `user` is then a Console
|
|
109
|
+
* account and not an app user, or `"cli"` for a key. Not set for other calls.
|
|
110
|
+
*/
|
|
111
|
+
readonly via?: "console" | "cli";
|
|
107
112
|
}
|
|
108
113
|
interface OperationContext {
|
|
109
114
|
/** The checked Console access of the call. */
|
|
@@ -166,7 +171,8 @@ interface OperationDefinition<Input, Output> {
|
|
|
166
171
|
/** Standard Schema (valibot in this repo). Its Standard JSON Schema builds CLI flags and the MCP input schema. */
|
|
167
172
|
input: StandardSchemaV1<unknown, Input>;
|
|
168
173
|
output?: StandardSchemaV1<unknown, Output>;
|
|
169
|
-
|
|
174
|
+
/** `false`: no `vitehub` command. The Console and MCP still call the operation. */
|
|
175
|
+
cli?: false | {
|
|
170
176
|
/** Defaults: namespace = section, command = verb. */
|
|
171
177
|
namespace?: string;
|
|
172
178
|
/** A space groups commands: `jobs list` and `jobs show` run as `vitehub <namespace> jobs list` and `jobs show`. */
|
|
@@ -207,7 +213,7 @@ interface OperationDefinition<Input, Output> {
|
|
|
207
213
|
/** An operation of any input and output, as a registry holds it. */
|
|
208
214
|
interface AnyOperation extends Omit<OperationDefinition<unknown, unknown>, "cli" | "input" | "mcp" | "output" | "readOnlyWhen" | "run" | "scope" | "section"> {
|
|
209
215
|
readOnlyWhen?: (input: never) => boolean;
|
|
210
|
-
cli?: {
|
|
216
|
+
cli?: false | {
|
|
211
217
|
namespace?: string;
|
|
212
218
|
command?: string;
|
|
213
219
|
default?: boolean;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as isBlockingServerEnvEntry, c as runWithCloudflareEnv } from "./server-
|
|
1
|
+
import { a as isBlockingServerEnvEntry, c as runWithCloudflareEnv } from "./server-Ct3uvhf9.js";
|
|
2
2
|
import { detectHost } from "@vite-hub/runtime";
|
|
3
3
|
import { inspectServerEnv } from "#vitehub/env/server";
|
|
4
4
|
//#region src/runtime/operations.ts
|
package/dist/operations.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { K as ServerEnvInspectionEntry, q as ServerEnvInspectionStatus } from "./bridge-Cs9YfQWk.js";
|
|
2
|
-
import { t as AnyOperation } from "./operation-definition-
|
|
2
|
+
import { t as AnyOperation } from "./operation-definition-CI2PJGqu.js";
|
|
3
3
|
import { ViteHubHost } from "@vite-hub/runtime";
|
|
4
4
|
//#region src/runtime/operations.d.ts
|
|
5
5
|
/** One Server Env declaration as the running app sees it. It never holds a value, a preview, or a length. */
|
package/dist/operations.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as isRecordOrFunction, r as internalErrorDiagnostics } from "./object-
|
|
1
|
+
import { n as isRecordOrFunction, r as internalErrorDiagnostics } from "./object-DICxAEoH.js";
|
|
2
2
|
import * as v from "valibot";
|
|
3
3
|
//#region ../internal/src/standard-schema.ts
|
|
4
4
|
function readOwn(value, key) {
|
|
@@ -817,10 +817,10 @@ function operationInputJsonSchema(operation) {
|
|
|
817
817
|
}
|
|
818
818
|
//#endregion
|
|
819
819
|
//#region src/operations.ts
|
|
820
|
-
const runtime = () => import("./operations-
|
|
820
|
+
const runtime = () => import("./operations-LVaCzpR0.js");
|
|
821
821
|
/** The `env.*` operations. The Console, the CLI, and agents run them on the signed `POST /_vitehub/rpc` endpoint. */
|
|
822
822
|
const envOperations = [defineOperation({
|
|
823
|
-
cli: { command: "
|
|
823
|
+
cli: { command: "list" },
|
|
824
824
|
description: "Show the status of each Server Env value as the running app sees it. Values are never returned.",
|
|
825
825
|
input: v.strictObject({}),
|
|
826
826
|
kind: "read",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as envErrorDiagnostics } from "../error-diagnostics-
|
|
1
|
+
import { t as envErrorDiagnostics } from "../error-diagnostics-CwQGNVnK.js";
|
|
2
2
|
//#region src/runtime/public-env.ts
|
|
3
3
|
/** Reads the declared Public Env. Its values are fixed when the app builds. */
|
|
4
4
|
function usePublicEnv() {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as envErrorDiagnostics } from "../error-diagnostics-
|
|
1
|
+
import { t as envErrorDiagnostics } from "../error-diagnostics-CwQGNVnK.js";
|
|
2
2
|
//#region src/runtime/server-env.ts
|
|
3
3
|
function notGenerated(accessor) {
|
|
4
4
|
throw envErrorDiagnostics.ENV_NOT_GENERATED({ accessor });
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { t as envErrorDiagnostics } from "./error-diagnostics-
|
|
2
|
-
import { A as envValueTypeName, F as stringValueSchema, M as parseEnvValue, N as readJsonInput, j as listItemKinds } from "./server-
|
|
1
|
+
import { t as envErrorDiagnostics } from "./error-diagnostics-CwQGNVnK.js";
|
|
2
|
+
import { A as envValueTypeName, F as stringValueSchema, M as parseEnvValue, N as readJsonInput, j as listItemKinds } from "./server-Ct3uvhf9.js";
|
|
3
3
|
//#region src/internal/runtime-type.ts
|
|
4
4
|
function isRuntimeRecord(value) {
|
|
5
5
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
@@ -171,7 +171,6 @@ function jsonVariable(schemaOrOptions, options) {
|
|
|
171
171
|
if (isSchemaModule(schemaOrOptions) || options !== void 0 || isRuntimeRecord(schemaOrOptions) && ("kind" in schemaOrOptions || "~standard" in schemaOrOptions)) throw envErrorDiagnostics.ENV_JSON_SCHEMA_INVALID({ message: "env.json() takes env.schemaFrom(), a Standard Schema, or only options." });
|
|
172
172
|
return typedVariable(createRuntimeValueSchema(Object.freeze({ kind: "json" })), schemaOrOptions ?? {});
|
|
173
173
|
}
|
|
174
|
-
/** Wrap a build-time Standard Schema so that it gets the parsed JSON value. */
|
|
175
174
|
function jsonStandardSchema(schema) {
|
|
176
175
|
const validate = schema["~standard"].validate;
|
|
177
176
|
return { "~standard": { validate: (value) => {
|
|
@@ -198,36 +197,44 @@ function isDeclaration(value) {
|
|
|
198
197
|
return false;
|
|
199
198
|
}
|
|
200
199
|
}
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
200
|
+
const declarationOptionKeys = /* @__PURE__ */ new Set([
|
|
201
|
+
"default",
|
|
202
|
+
"mode",
|
|
203
|
+
"optional",
|
|
204
|
+
"schema",
|
|
205
|
+
"secret",
|
|
206
|
+
"source",
|
|
207
|
+
"type"
|
|
208
|
+
]);
|
|
209
|
+
function copyOptions(options) {
|
|
210
|
+
if (!isRuntimeRecord(options)) return void 0;
|
|
211
|
+
return Object.fromEntries(Object.getOwnPropertyNames(options).map((key) => [key, options[key]]));
|
|
209
212
|
}
|
|
210
213
|
function readDeclarationOptions(options) {
|
|
211
|
-
if (!isInspectableRecord(options)) throw envErrorDiagnostics.ENV_R0005({ message: "env() only accepts a single options object." });
|
|
212
214
|
let snapshot;
|
|
213
|
-
let required;
|
|
214
215
|
try {
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
secret: options.secret,
|
|
222
|
-
source: options.source,
|
|
223
|
-
type: options.type
|
|
224
|
-
};
|
|
225
|
-
} catch {
|
|
226
|
-
throw envErrorDiagnostics.ENV_R0005({ message: "env() only accepts a single options object." });
|
|
216
|
+
snapshot = copyOptions(options);
|
|
217
|
+
} catch (cause) {
|
|
218
|
+
throw envErrorDiagnostics.ENV_R0005({
|
|
219
|
+
message: "env() only accepts a single options object.",
|
|
220
|
+
cause
|
|
221
|
+
});
|
|
227
222
|
}
|
|
228
|
-
if (
|
|
229
|
-
|
|
230
|
-
|
|
223
|
+
if (!snapshot) throw envErrorDiagnostics.ENV_R0005({ message: "env() only accepts a single options object." });
|
|
224
|
+
for (const key of Object.keys(snapshot)) {
|
|
225
|
+
if (key === "required") throw envErrorDiagnostics.ENV_R0006({ message: "env() does not accept required. A value is required by default. Use optional: true for a value that can be missing." });
|
|
226
|
+
if (!declarationOptionKeys.has(key)) throw envErrorDiagnostics.ENV_R0005({ message: `env() does not accept ${key}. Use default, mode, optional, schema, secret, source, or type.` });
|
|
227
|
+
}
|
|
228
|
+
if (snapshot.optional === true && snapshot.default !== void 0) throw envErrorDiagnostics.ENV_R0006({ message: "env() cannot use both optional and default. A default makes the value always present." });
|
|
229
|
+
return {
|
|
230
|
+
default: snapshot.default,
|
|
231
|
+
mode: snapshot.mode,
|
|
232
|
+
optional: snapshot.optional === true,
|
|
233
|
+
schema: snapshot.schema,
|
|
234
|
+
secret: snapshot.secret,
|
|
235
|
+
source: snapshot.source,
|
|
236
|
+
type: snapshot.type
|
|
237
|
+
};
|
|
231
238
|
}
|
|
232
239
|
function createDeclaration(options, schema, type) {
|
|
233
240
|
const required = !options.optional;
|
|
@@ -271,14 +278,10 @@ const env = Object.assign(variable, {
|
|
|
271
278
|
function runtimeValueSchema(declaration) {
|
|
272
279
|
const schema = declaration.schema;
|
|
273
280
|
if (runtimeSchemas.get(declaration) === schema && isRuntimeValueSchema(schema)) return runtimeSchemaParsers.get(schema.safeParse);
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
return typeof safeParse === "function" ? runtimeSchemaParsers.get(safeParse) : void 0;
|
|
279
|
-
} catch {
|
|
280
|
-
return;
|
|
281
|
-
}
|
|
281
|
+
if (Object.getOwnPropertyDescriptor(declaration, runtimeSchemaProperty)?.value !== runtimeSchemaToken || !isRuntimeRecord(schema)) return void 0;
|
|
282
|
+
if (Object.getOwnPropertyDescriptor(schema, runtimeSchemaProperty)?.value !== runtimeSchemaToken || !hasOnlyRuntimeSchemaKeys(schema)) return void 0;
|
|
283
|
+
const safeParse = Object.getOwnPropertyDescriptor(schema, "safeParse")?.value;
|
|
284
|
+
return typeof safeParse === "function" ? runtimeSchemaParsers.get(safeParse) : void 0;
|
|
282
285
|
}
|
|
283
286
|
function isRuntimeValueSchema(schema) {
|
|
284
287
|
try {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { t as envErrorDiagnostics } from "./error-diagnostics-
|
|
1
|
+
import { t as envErrorDiagnostics } from "./error-diagnostics-CwQGNVnK.js";
|
|
2
2
|
import { t as SecretEnv } from "./secret-DJd-fy5T.js";
|
|
3
|
-
import { r as internalErrorDiagnostics, t as isRecord } from "./object-
|
|
3
|
+
import { r as internalErrorDiagnostics, t as isRecord } from "./object-DICxAEoH.js";
|
|
4
4
|
import { defineDiagnostics } from "nostics";
|
|
5
5
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
6
6
|
import { ViteHubError, defineErrors, isViteHubError, parseDuration } from "@vite-hub/runtime";
|
|
@@ -535,6 +535,9 @@ function invariant(condition, what) {
|
|
|
535
535
|
}
|
|
536
536
|
//#endregion
|
|
537
537
|
//#region src/seal-uses.ts
|
|
538
|
+
function isSealUseCount(value) {
|
|
539
|
+
return typeof value === "number" && Number.isSafeInteger(value) && value >= 1;
|
|
540
|
+
}
|
|
538
541
|
const table = "vitehub_env_seal_uses";
|
|
539
542
|
const ready = /* @__PURE__ */ new WeakMap();
|
|
540
543
|
function checkId(id) {
|
|
@@ -555,7 +558,6 @@ function initialize(db) {
|
|
|
555
558
|
}
|
|
556
559
|
/** Keeps `uses` for a new id. The row holds no part of the value. */
|
|
557
560
|
async function createSealUses(db, id, uses, expiresAt) {
|
|
558
|
-
invariant(Number.isSafeInteger(uses) && uses >= 1, "`uses` must be a positive integer");
|
|
559
561
|
await initialize(db);
|
|
560
562
|
const now = Date.now();
|
|
561
563
|
await db.all(`DELETE FROM ${table} WHERE expires_at IS NOT NULL AND expires_at <= ${now}`);
|
|
@@ -646,10 +648,6 @@ function rootSecret(secret) {
|
|
|
646
648
|
if (typeof value !== "string" || value.length < 32) argumentError(`\`secret\` must be a string of at least 32 characters, or a non-empty list of them.`);
|
|
647
649
|
return value;
|
|
648
650
|
}
|
|
649
|
-
/**
|
|
650
|
-
* The root secrets in order: the one that seals first, then the old ones that `unseal()` also tries. `undefined` is
|
|
651
|
-
* `VITEHUB_SECRET` (or the development secret). Only `unseal()` passes `previous`, to add `VITEHUB_SECRET_PREVIOUS`.
|
|
652
|
-
*/
|
|
653
651
|
function rootSecrets(options, previous) {
|
|
654
652
|
const { secret } = options;
|
|
655
653
|
if (secret === void 0) return previous ? [void 0, ...previousSecrets(options.event)] : [void 0];
|
|
@@ -700,7 +698,7 @@ function createSealing(derive) {
|
|
|
700
698
|
const ttl = typeof options.ttl === "string" ? parseDuration(options.ttl) / 1e3 : options.ttl;
|
|
701
699
|
if (ttl !== void 0 && (typeof ttl !== "number" || !Number.isFinite(ttl) || ttl <= 0)) argumentError("`ttl` must be a positive number of seconds or a duration such as \"15m\".");
|
|
702
700
|
const { uses, db } = options;
|
|
703
|
-
if (uses !== void 0 &&
|
|
701
|
+
if (uses !== void 0 && !isSealUseCount(uses)) argumentError("`uses` must be a positive integer.");
|
|
704
702
|
const usesDb = uses === void 0 ? void 0 : usesDatabase(db, "`uses` needs a `db`, such as `db` from `vite-hub/database`, that every instance of the app shares.");
|
|
705
703
|
checkJsonValue(value);
|
|
706
704
|
let json;
|
|
@@ -818,7 +816,6 @@ async function deriveSecret(purpose, options = {}, development = {}) {
|
|
|
818
816
|
}
|
|
819
817
|
return await deriveViteHubSecret(root, purpose);
|
|
820
818
|
}
|
|
821
|
-
/** An empty variable counts as missing, so it never shadows a later name or satisfies a required value. */
|
|
822
819
|
function hasRuntimeName(env, name) {
|
|
823
820
|
return Object.hasOwn(env, name) && env[name] !== void 0 && env[name] !== "";
|
|
824
821
|
}
|
|
@@ -830,7 +827,6 @@ function readRuntimeSource(entry, env) {
|
|
|
830
827
|
};
|
|
831
828
|
return { found: false };
|
|
832
829
|
}
|
|
833
|
-
/** Report which kind of name supplied the value, and whether a shadowed conventional name holds another value. */
|
|
834
830
|
function runtimeSourceOrigin(entry, env, source) {
|
|
835
831
|
const canonical = entry.source.canonical;
|
|
836
832
|
if (!source.found || canonical === void 0 || canonical === false) return {};
|
|
@@ -840,7 +836,6 @@ function runtimeSourceOrigin(entry, env, source) {
|
|
|
840
836
|
via: "canonical"
|
|
841
837
|
} : { via: "canonical" };
|
|
842
838
|
}
|
|
843
|
-
/** Server Env resolves every declaration together, so the message must say why reading another value fails. */
|
|
844
839
|
function missingRuntimeValueMessage(entry, path) {
|
|
845
840
|
const supply = entry.source.kind === "env" ? `Set ${(entry.source.names || [entry.source.name]).join(" or ")}` : "Return it from the provider";
|
|
846
841
|
return `${path} is required and has no value. Server Env checks every declared value together, so this fails even when code reads only another value. ${entry.secret ? `${supply} or declare it with optional: true.` : `${supply}, give it a default, or declare it with optional: true.`}`;
|
|
@@ -950,10 +945,6 @@ function resolveRegistryValue(value, env, path) {
|
|
|
950
945
|
}
|
|
951
946
|
return output;
|
|
952
947
|
}
|
|
953
|
-
/**
|
|
954
|
-
* Copy the namespace records of a resolved registry, so a caller that changes its result does not change the cached
|
|
955
|
-
* one. resolveRegistryValue() creates each namespace without a prototype, and provider getters keep their descriptor.
|
|
956
|
-
*/
|
|
957
948
|
function copyNamespaces(value) {
|
|
958
949
|
const descriptors = Object.getOwnPropertyDescriptors(value);
|
|
959
950
|
for (const descriptor of Object.values(descriptors)) if (isNamespace(descriptor.value)) descriptor.value = copyNamespaces(descriptor.value);
|
|
@@ -1123,7 +1114,6 @@ function inspectionPath(path) {
|
|
|
1123
1114
|
return /^(?:env|runtime)(?:\.[A-Za-z_$][A-Za-z0-9_$-]{0,63}){0,8}$/.test(path) ? { path } : {};
|
|
1124
1115
|
}
|
|
1125
1116
|
const hostVariableName = /^[A-Za-z_][A-Za-z0-9_]{0,127}$/;
|
|
1126
|
-
/** The host variable names an env declaration reads, in read order. Never values. */
|
|
1127
1117
|
function inspectionNames(entry) {
|
|
1128
1118
|
const names = (entry.source.names || [entry.source.name]).filter((name) => hostVariableName.test(name));
|
|
1129
1119
|
return names.length ? { names } : {};
|
|
@@ -1184,7 +1174,6 @@ async function inspectRegistryEntry(value, env, options, loads, path, entries) {
|
|
|
1184
1174
|
}
|
|
1185
1175
|
const registryEnvNames = /* @__PURE__ */ new WeakMap();
|
|
1186
1176
|
const resolvedServerEnvs = /* @__PURE__ */ new WeakMap();
|
|
1187
|
-
/** The env names a registry reads, or null when it declares an array, list, JSON value, or object, since each call returns its own copy. */
|
|
1188
1177
|
function reusableEnvNames(registry) {
|
|
1189
1178
|
const known = registryEnvNames.get(registry);
|
|
1190
1179
|
if (known !== void 0) return known;
|
|
@@ -1200,7 +1189,6 @@ function reusableEnvNames(registry) {
|
|
|
1200
1189
|
registryEnvNames.set(registry, names);
|
|
1201
1190
|
return names;
|
|
1202
1191
|
}
|
|
1203
|
-
/** The values of every name the registry reads, as one string. Undefined when the result must not be reused. */
|
|
1204
1192
|
function serverEnvKey(registry, event) {
|
|
1205
1193
|
const names = reusableEnvNames(registry);
|
|
1206
1194
|
if (!names || getViteHubTestMode()) return void 0;
|
|
@@ -114,7 +114,6 @@ interface DeriveSecretOptions {
|
|
|
114
114
|
/** The root secret. Without it, ViteHub reads `VITEHUB_SECRET`. */
|
|
115
115
|
root?: string;
|
|
116
116
|
}
|
|
117
|
-
/** The development secret that the Vite plugin generated or selected for one project. Private to the generated module. */
|
|
118
117
|
interface DevelopmentSecret {
|
|
119
118
|
envKey?: string;
|
|
120
119
|
generated?: boolean;
|
package/dist/server.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
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-
|
|
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-OvARy_y9.js";
|
|
3
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 };
|
package/dist/server.js
CHANGED
|
@@ -1,2 +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-
|
|
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-Ct3uvhf9.js";
|
|
2
2
|
export { bindServerEnvSchemas, createSealing, deriveSecret, describeServerEnv, inspectServerEnv, isBlockingServerEnvEntry, loadServerEnv, resolveServerEnv, runWithCloudflareEnv, seal, unseal };
|
package/dist/vite.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { A as EnvRuntimeRegistry, b as EnvDeclarations, k as EnvRuntimeConfigOptions, w as EnvOptions } from "./bridge-Cs9YfQWk.js";
|
|
2
|
-
import { n as ViteHubCliContributor } from "./cli-
|
|
3
|
-
import { t as env } from "./declarations-
|
|
4
|
-
import { n as OperationContributionEntry } from "./operation-definition-
|
|
2
|
+
import { n as ViteHubCliContributor } from "./cli-DJtQF4Wi.js";
|
|
3
|
+
import { t as env } from "./declarations-BEL0yvEY.js";
|
|
4
|
+
import { n as OperationContributionEntry } from "./operation-definition-CI2PJGqu.js";
|
|
5
5
|
import { Plugin, UserConfig } from "vite";
|
|
6
6
|
//#region ../internal/src/deployment.d.ts
|
|
7
7
|
/** The host that ViteHub builds for: the `host` option of `vitehub()` and the value of `VITEHUB_HOST`. */
|
|
@@ -78,7 +78,7 @@ export interface EnvVitePluginAPI {
|
|
|
78
78
|
}
|
|
79
79
|
export type EnvVitePlugin = Plugin & {
|
|
80
80
|
api: EnvVitePluginAPI;
|
|
81
|
-
/** Contributes `vitehub env
|
|
81
|
+
/** Contributes `vitehub env list`, `vitehub env check`, and the `env.inspect` operation. */
|
|
82
82
|
vitehub: {
|
|
83
83
|
cli: () => ViteHubCliContributor;
|
|
84
84
|
operations: readonly OperationContributionEntry[];
|
package/dist/vite.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { t as envErrorDiagnostics } from "./error-diagnostics-
|
|
2
|
-
import { a as schemaModuleReference, i as runtimeValueSchema, n as descriptorVariable, r as env, t as parseSchema } from "./schema-
|
|
3
|
-
import { A as envValueTypeName, E as readViteHubSecret, F as stringValueSchema, I as isEnvSchemaValue, M as parseEnvValue, P as schemaContainsEnum, S as missingRequiredEnv, b as invalidEnvDeclaration, f as invariant, g as runtimeRegistryEntries, h as isRuntimeProviderEntry, m as isRuntimeLiteralEntry, p as isRuntimeEnvEntry, r as describeServerEnv, x as isAbortError, y as envSourceFailed } from "./server-
|
|
4
|
-
import { a as VITEHUB_ENV_SERVER, c as createViteHubEnvImportAliases, d as viteHubEnvAmbientTypesPath, f as viteHubEnvDescriptionModulePath, g as viteHubEnvServerModuleTypesPath, h as viteHubEnvServerModulePath, i as VITEHUB_ENV_PUBLIC_ID, l as isServerEnvironment, m as viteHubEnvPublicModuleTypesPath, o as VITEHUB_ENV_SERVER_ID, p as viteHubEnvPublicModulePath, r as loadAllEnv, s as createNoExternalAddition, t as createEnvCliContributor, u as resolveViteHubProjectRoot } from "./cli-
|
|
1
|
+
import { t as envErrorDiagnostics } from "./error-diagnostics-CwQGNVnK.js";
|
|
2
|
+
import { a as schemaModuleReference, i as runtimeValueSchema, n as descriptorVariable, r as env, t as parseSchema } from "./schema-CnCp0Muw.js";
|
|
3
|
+
import { A as envValueTypeName, E as readViteHubSecret, F as stringValueSchema, I as isEnvSchemaValue, M as parseEnvValue, P as schemaContainsEnum, S as missingRequiredEnv, b as invalidEnvDeclaration, f as invariant, g as runtimeRegistryEntries, h as isRuntimeProviderEntry, m as isRuntimeLiteralEntry, p as isRuntimeEnvEntry, r as describeServerEnv, x as isAbortError, y as envSourceFailed } from "./server-Ct3uvhf9.js";
|
|
4
|
+
import { a as VITEHUB_ENV_SERVER, c as createViteHubEnvImportAliases, d as viteHubEnvAmbientTypesPath, f as viteHubEnvDescriptionModulePath, g as viteHubEnvServerModuleTypesPath, h as viteHubEnvServerModulePath, i as VITEHUB_ENV_PUBLIC_ID, l as isServerEnvironment, m as viteHubEnvPublicModuleTypesPath, o as VITEHUB_ENV_SERVER_ID, p as viteHubEnvPublicModulePath, r as loadAllEnv, s as createNoExternalAddition, t as createEnvCliContributor, u as resolveViteHubProjectRoot } from "./cli-BctSFldY.js";
|
|
5
5
|
import { Diagnostic } from "nostics";
|
|
6
6
|
import { isViteHubError } from "@vite-hub/runtime";
|
|
7
7
|
import { existsSync, readFileSync } from "node:fs";
|
|
@@ -458,12 +458,7 @@ function parseRuntimeDefault(schema, value, path) {
|
|
|
458
458
|
if (!result.success) throw envErrorDiagnostics.ENV_R0023({ message: `[vitehub] Invalid default for ${path}: ${result.message}` });
|
|
459
459
|
return schema.kind === "json" ? value : result.data;
|
|
460
460
|
}
|
|
461
|
-
/** The default prefix of canonical variable names. */
|
|
462
461
|
const defaultEnvPrefix = "VITEHUB_";
|
|
463
|
-
/**
|
|
464
|
-
* The canonical variable name of a declaration path: the prefix plus the path in upper snake case.
|
|
465
|
-
* `env.server.cliproxy.apiKey` becomes `VITEHUB_CLIPROXY_API_KEY`. `false` disables canonical names.
|
|
466
|
-
*/
|
|
467
462
|
function canonicalEnvName(path, prefix = defaultEnvPrefix) {
|
|
468
463
|
return prefix === false ? void 0 : `${prefix}${pathToEnvName(path)}`;
|
|
469
464
|
}
|
|
@@ -1391,7 +1386,6 @@ function resolveProviderModules(providers, root) {
|
|
|
1391
1386
|
function assertConfiguredProviders(registry, providers) {
|
|
1392
1387
|
for (const { entry, path } of runtimeRegistryEntries(registry)) if (isRuntimeProviderEntry(entry) && !Object.hasOwn(providers, entry.source.provider)) throw envErrorDiagnostics.ENV_B0005({ message: `[vitehub] ${path} references Env provider ${JSON.stringify(entry.source.provider)}, but hubEnv({ providers }) does not configure it.` });
|
|
1393
1388
|
}
|
|
1394
|
-
/** Map each `env.schemaFrom()` specifier to the module the server build imports. Relative specifiers resolve from the project root. */
|
|
1395
1389
|
function resolveSchemaModules(registry, root) {
|
|
1396
1390
|
const output = {};
|
|
1397
1391
|
for (const { entry } of runtimeRegistryEntries(registry)) {
|
|
@@ -1401,7 +1395,6 @@ function resolveSchemaModules(registry, root) {
|
|
|
1401
1395
|
}
|
|
1402
1396
|
return output;
|
|
1403
1397
|
}
|
|
1404
|
-
/** A type-only import specifier for a schema module, relative to the generated declaration file. */
|
|
1405
1398
|
function schemaModuleTypeSpecifier(specifier, outputPath) {
|
|
1406
1399
|
const typed = specifier.replace(/\.([cm]?)tsx?$/, ".$1js");
|
|
1407
1400
|
if (!isAbsolute(typed)) return typed;
|
|
@@ -1409,10 +1402,6 @@ function schemaModuleTypeSpecifier(specifier, outputPath) {
|
|
|
1409
1402
|
return target.startsWith(".") ? target : `./${target}`;
|
|
1410
1403
|
}
|
|
1411
1404
|
const generatedSecretPattern = /^[0-9a-f]{64}$/;
|
|
1412
|
-
/**
|
|
1413
|
-
* Give the development server a root secret when none is configured, so `deriveSecret()` works without setup.
|
|
1414
|
-
* The secret is kept in `.vitehub/env/secret` with mode 0600 and survives restarts. Builds never generate one.
|
|
1415
|
-
*/
|
|
1416
1405
|
async function resolveDevelopmentSecret(projectRoot, loadedEnv) {
|
|
1417
1406
|
const existing = developmentSecretLocks.get(projectRoot);
|
|
1418
1407
|
if (existing) return existing;
|
|
@@ -1630,10 +1619,6 @@ function createServerEnvModuleTypes(serverRegistry, runtimeImports, schemaModule
|
|
|
1630
1619
|
function envAccessorTypesPath(root) {
|
|
1631
1620
|
return resolve(root, ".vitehub", "types", "env-accessors.d.ts");
|
|
1632
1621
|
}
|
|
1633
|
-
/**
|
|
1634
|
-
* Types `useServerEnv()` and `usePublicEnv()` of the Env root with the declared fields. The file is a module, so its
|
|
1635
|
-
* `declare module` blocks augment the package instead of replacing it.
|
|
1636
|
-
*/
|
|
1637
1622
|
function createEnvAccessorTypes(publicTypes, serverRegistry, runtimeImports, schemaModules, outputPath) {
|
|
1638
1623
|
const schemaTypes = {
|
|
1639
1624
|
modules: schemaModules,
|
|
@@ -1753,7 +1738,6 @@ function serverTypeFor(value, indent, schemaTypes, secretType) {
|
|
|
1753
1738
|
const prefix = " ".repeat(indent);
|
|
1754
1739
|
return `{\n${fields.join("\n")}\n${prefix}}`;
|
|
1755
1740
|
}
|
|
1756
|
-
/** Infer the output from optional Standard Schema type metadata, falling back to unknown when it is absent. */
|
|
1757
1741
|
function schemaOutputType(specifier, exportName, schemaTypes) {
|
|
1758
1742
|
const module = schemaModuleTypeSpecifier(schemaTypes.modules[specifier] ?? specifier, schemaTypes.outputPath);
|
|
1759
1743
|
return `typeof import(${JSON.stringify(module)})[${JSON.stringify(exportName)}] extends { readonly "~standard": { readonly types?: { readonly output: infer Output } | undefined } } ? Output : unknown`;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vite-hub/env",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Safe build and runtime environment variables for ViteHub.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"env",
|
|
@@ -97,7 +97,7 @@
|
|
|
97
97
|
},
|
|
98
98
|
"dependencies": {
|
|
99
99
|
"@env-spec/parser": "0.6.2",
|
|
100
|
-
"@vite-hub/runtime": "0.
|
|
100
|
+
"@vite-hub/runtime": "0.5.0",
|
|
101
101
|
"nostics": "1.4.0",
|
|
102
102
|
"valibot": "^1.5.0"
|
|
103
103
|
},
|
|
@@ -118,7 +118,7 @@
|
|
|
118
118
|
"peerDependencies": {
|
|
119
119
|
"vite": ">=8.0.0",
|
|
120
120
|
"drizzle-orm": "1.0.0-rc.5 || ^1.0.0",
|
|
121
|
-
"@vite-hub/agent": "0.
|
|
121
|
+
"@vite-hub/agent": "0.5.0",
|
|
122
122
|
"nitro": "3.0.261102-rc || ^3.0.261103-rc"
|
|
123
123
|
},
|
|
124
124
|
"peerDependenciesMeta": {
|