@vite-hub/env 0.1.0 → 0.3.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.
Files changed (61) hide show
  1. package/README.md +178 -33
  2. package/dist/{access-B3qzBHye.js → access-B8lSDip4.js} +1 -1
  3. package/dist/{bridge-CdNdTN1V.d.ts → bridge-Cs9YfQWk.d.ts} +111 -38
  4. package/dist/{bridge-error-CFuU5zIz.js → bridge-error-BhJ77age.js} +14 -13
  5. package/dist/bridge.d.ts +2 -2
  6. package/dist/bridge.js +168 -6
  7. package/dist/cli-BPp7rdcA.d.ts +159 -0
  8. package/dist/{cli-CMQPQbii.js → cli-DLpY0QAo.js} +212 -30
  9. package/dist/cli.d.ts +2 -2
  10. package/dist/cli.js +1 -1
  11. package/dist/database.d.ts +29 -3
  12. package/dist/database.js +106 -15
  13. package/dist/declarations-C5XR3aKw.d.ts +58 -0
  14. package/dist/error-diagnostics-B8RFjQ1V.js +56 -0
  15. package/dist/index.d.ts +145 -10
  16. package/dist/index.js +240 -7
  17. package/dist/internal/agent.d.ts +1 -1
  18. package/dist/internal/agent.js +2 -2
  19. package/dist/internal/connections.d.ts +1 -1
  20. package/dist/internal/connections.js +2 -2
  21. package/dist/internal/server.d.ts +3 -0
  22. package/dist/internal/server.js +2 -0
  23. package/dist/object-_dlsZ4lP.js +276 -0
  24. package/dist/operation-definition-8gOe-ubD.d.ts +234 -0
  25. package/dist/operations-X1w--wds.js +30 -0
  26. package/dist/operations.d.ts +37 -0
  27. package/dist/operations.js +833 -0
  28. package/dist/runtime/public-env.d.ts +5 -0
  29. package/dist/runtime/public-env.js +8 -0
  30. package/dist/runtime/server-env.d.ts +22 -0
  31. package/dist/runtime/server-env.js +35 -0
  32. package/dist/schema-DMZ1_yhY.js +360 -0
  33. package/dist/seal.d.ts +8 -5
  34. package/dist/seal.js +9 -6
  35. package/dist/{secret.js → secret-DJd-fy5T.js} +1 -1
  36. package/dist/server-ChNL_Xc3.js +1279 -0
  37. package/dist/server-Dd8bjIKd.d.ts +145 -0
  38. package/dist/server.d.ts +3 -25
  39. package/dist/server.js +2 -2
  40. package/dist/virtual-module.d.ts +6 -6
  41. package/dist/vite.d.ts +59 -14
  42. package/dist/vite.js +304 -115
  43. package/package.json +27 -38
  44. package/dist/auth.d.ts +0 -32
  45. package/dist/auth.js +0 -44
  46. package/dist/cli-DEwcUIe0.d.ts +0 -81
  47. package/dist/declarations-CiRdb1qP.d.ts +0 -32
  48. package/dist/declarations-DAVgctKD.js +0 -236
  49. package/dist/error-diagnostics-CrxjYNYr.js +0 -43
  50. package/dist/http.d.ts +0 -2
  51. package/dist/http.js +0 -122
  52. package/dist/presets.d.ts +0 -20
  53. package/dist/presets.js +0 -44
  54. package/dist/provider.d.ts +0 -5
  55. package/dist/provider.js +0 -8
  56. package/dist/schema.d.ts +0 -15
  57. package/dist/schema.js +0 -55
  58. package/dist/secret-C2191nAa.d.ts +0 -11
  59. package/dist/secret.d.ts +0 -2
  60. package/dist/server-DufVswRJ.js +0 -670
  61. package/dist/values-D_r6V774.js +0 -148
@@ -0,0 +1,145 @@
1
+ import { A as EnvRuntimeRegistry, G as ServerEnvInspection, K as ServerEnvInspectionEntry, Q as SecretEnv, U as ServerEnvDescription, y as DeepReadonly, z as LoadServerEnvOptions } from "./bridge-Cs9YfQWk.js";
2
+ import { Result, ViteHubContext, ViteHubContext as ViteHubContext$1 } from "@vite-hub/runtime";
3
+ //#region src/schema.d.ts
4
+ interface StandardSchemaResultSuccess<T = unknown> {
5
+ issues?: undefined;
6
+ value: T;
7
+ }
8
+ interface StandardSchemaResultFailure {
9
+ issues: readonly unknown[];
10
+ }
11
+ interface StandardSchemaV1<T = unknown> {
12
+ "~standard": {
13
+ validate: (input: unknown) => StandardSchemaResultSuccess<T> | StandardSchemaResultFailure | Promise<StandardSchemaResultSuccess<T> | StandardSchemaResultFailure>;
14
+ };
15
+ }
16
+ declare function parseSchema(schema: unknown, value: unknown, label: string): unknown;
17
+ //#endregion
18
+ //#region src/internal/runtime-env.d.ts
19
+ type RuntimeEnv = Record<string, unknown>;
20
+ /**
21
+ * A request event: an H3 event, another event with Standard Context, or a web `Request`. An H3 event matches `{ req }`
22
+ * even when the app does not load the types that add `~standard` to it.
23
+ */
24
+ type RequestEvent = Request | ViteHubContext | {
25
+ readonly req: Request;
26
+ };
27
+ //#endregion
28
+ //#region src/seal-uses.d.ts
29
+ /**
30
+ * A SQLite, libSQL, or D1 Drizzle database, such as `db` from `vite-hub/database`. The uses of a sealed value live
31
+ * there, because every instance of the app must see the same count. KV cannot take a use atomically.
32
+ */
33
+ interface SealUsesDatabase {
34
+ all: (query: string) => unknown[] | PromiseLike<unknown[]>;
35
+ }
36
+ //#endregion
37
+ //#region src/seal-value.d.ts
38
+ /** The codes that `unseal()` returns. */
39
+ type UnsealErrorCode = "ENV_SEAL_EXPIRED" | "ENV_SEAL_INVALID" | "ENV_SEAL_SCHEMA_MISMATCH" | "ENV_SEAL_USED_UP" | "ENV_SEAL_WRONG_PURPOSE";
40
+ interface UnsealOptions {
41
+ /** The request, so that on Cloudflare the root secret comes from its bindings. Without it, the active request's bindings. */
42
+ event?: ViteHubContext;
43
+ /**
44
+ * A root secret to use instead of `VITEHUB_SECRET`, of at least 32 characters. Use one for values that you store,
45
+ * so that a rotation of `VITEHUB_SECRET` does not make them unreadable. To rotate it, pass a list: the new secret
46
+ * first, then the old ones. `seal()` uses the first, and `unseal()` tries each in order.
47
+ */
48
+ secret?: string | SecretEnv<string> | readonly (string | SecretEnv<string>)[];
49
+ /**
50
+ * The database that counts the uses of a value sealed with `uses`, such as `db` from `vite-hub/database`. `unseal()`
51
+ * needs it for such a value. SQLite, libSQL, and D1 work. It keeps a random id, the uses left, and the expiry, never
52
+ * the value.
53
+ */
54
+ db?: SealUsesDatabase;
55
+ }
56
+ interface UnsealSchemaOptions<T> extends UnsealOptions {
57
+ /** A Standard Schema, such as a Valibot or Zod schema. `unseal()` returns its output. */
58
+ schema: StandardSchemaV1<T>;
59
+ }
60
+ interface SealOptions extends UnsealOptions {
61
+ /** Seconds until `unseal()` returns `ENV_SEAL_EXPIRED`. Without it, the value does not expire. */
62
+ ttl?: number;
63
+ /**
64
+ * How many times `unseal()` can read the value. Each read takes one use atomically in `db`, so of two reads of the last
65
+ * use, one gets the value and the other gets `ENV_SEAL_USED_UP`. Without it, the value opens any number of times.
66
+ */
67
+ uses?: number;
68
+ }
69
+ /** Derives the key of a purpose. The generated `#vitehub/env/server` module passes one that also reads the development secret. */
70
+ type SealSecretDerivation = (purpose: string, event: ViteHubContext | undefined, root: string | undefined) => Promise<string>;
71
+ /** `seal()` and `unseal()` on one key derivation. */
72
+ interface Sealing {
73
+ seal: (purpose: string, value: unknown, options?: SealOptions) => Promise<string>;
74
+ unseal: (purpose: string, sealed: string, options?: UnsealOptions & {
75
+ schema?: StandardSchemaV1;
76
+ }) => Promise<Result<unknown, UnsealErrorCode>>;
77
+ }
78
+ /** Builds `seal()` and `unseal()` on a key derivation. The generated `#vitehub/env/server` module uses it. */
79
+ declare function createSealing(derive: SealSecretDerivation): Sealing;
80
+ /**
81
+ * Encrypts and signs a JSON value for one purpose, with a key that ViteHub derives from `VITEHUB_SECRET`.
82
+ * Returns a URL-safe string that only `unseal()` with the same purpose can read.
83
+ * Throws `ENV_REQUIRED_MISSING` when no root secret is set, and `ENV_SEAL_ARGUMENT_INVALID` for a bad argument.
84
+ *
85
+ * @example
86
+ * const ticket = await seal("my-app:upload", { userId }, { ttl: 900 })
87
+ */
88
+ declare function seal(purpose: string, value: unknown, options?: SealOptions): Promise<string>;
89
+ /**
90
+ * Reads a value from `seal()`. Returns `[error, undefined]` with `ENV_SEAL_EXPIRED`, `ENV_SEAL_INVALID`,
91
+ * `ENV_SEAL_SCHEMA_MISMATCH`, or `ENV_SEAL_WRONG_PURPOSE`, else `[undefined, value]`. Pass `schema` to check the value
92
+ * and type it. It tries `VITEHUB_SECRET`, then each old secret in `VITEHUB_SECRET_PREVIOUS` (comma-separated), so
93
+ * values sealed before a rotation still open. Throws when no root secret is set.
94
+ *
95
+ * @example
96
+ * const [error, upload] = await unseal("my-app:upload", ticket, { schema: v.object({ userId: v.string() }) })
97
+ */
98
+ declare function unseal<T>(purpose: string, sealed: string, options: UnsealSchemaOptions<T>): Promise<Result<T, UnsealErrorCode>>;
99
+ declare function unseal(purpose: string, sealed: string, options?: UnsealOptions): Promise<Result<unknown, UnsealErrorCode>>;
100
+ //#endregion
101
+ //#region src/server.d.ts
102
+ /**
103
+ * Run `callback` with `env` as the active Cloudflare bindings. Server Env reads them when a call gets no request
104
+ * event, such as for the module bindings of `cloudflare:workers` outside a request.
105
+ */
106
+ declare function runWithCloudflareEnv<T>(env: RuntimeEnv, callback: () => T): T;
107
+ /** Options of `deriveSecret()`. */
108
+ interface DeriveSecretOptions {
109
+ /** The request event. On Cloudflare, ViteHub reads `VITEHUB_SECRET` from its Worker bindings. */
110
+ event?: ViteHubContext;
111
+ /** The root secret. Without it, ViteHub reads `VITEHUB_SECRET`. */
112
+ root?: string;
113
+ }
114
+ /** The development secret that the Vite plugin generated or selected for one project. Private to the generated module. */
115
+ interface DevelopmentSecret {
116
+ envKey?: string;
117
+ generated?: boolean;
118
+ }
119
+ /**
120
+ * Derives a 32-byte hex secret for one purpose from the root app secret, `VITEHUB_SECRET`.
121
+ * It uses HKDF-SHA256, so the result is stable while the root is unchanged and distinct for every purpose.
122
+ * Namespace the purpose to its owner, such as `my-module:session`. ViteHub reserves the `vitehub:` prefix.
123
+ * Throws `ENV_REQUIRED_MISSING` when no root secret is set, and `ENV_RUNTIME_VALUE_INVALID` when it is shorter than 32 characters.
124
+ * Only the generated `#vitehub/env/server` module passes `development`, with the project's development secret.
125
+ */
126
+ declare function deriveSecret(purpose: string, options?: DeriveSecretOptions, development?: DevelopmentSecret): Promise<string>;
127
+ /**
128
+ * Attach the schemas that `env.schemaFrom()` declarations name. The generated `#vitehub/env/server` module imports
129
+ * each schema module and calls this once, so a missing or wrong export fails when the server starts.
130
+ */
131
+ declare function bindServerEnvSchemas(registry: EnvRuntimeRegistry, modules: Readonly<Record<string, Readonly<Record<string, unknown>>>>): void;
132
+ /**
133
+ * Apps call `useServerEnv()` on hot paths, often once per listed row. The result is reused while every name the
134
+ * registry reads holds the same value, so a call does not copy the whole env and parse each declaration again. Each
135
+ * call still gets its own records.
136
+ */
137
+ declare function resolveServerEnv<TServerEnv extends Record<string, unknown> = Record<string, unknown>>(registry: EnvRuntimeRegistry<TServerEnv>, event?: ViteHubContext): TServerEnv;
138
+ declare function loadServerEnv<TServerEnv extends Record<string, unknown> = Record<string, unknown>>(registry: EnvRuntimeRegistry<TServerEnv>, event?: ViteHubContext, options?: LoadServerEnvOptions): Promise<DeepReadonly<TServerEnv>>;
139
+ /** Describe declarations without loading host values or calling providers. */
140
+ declare function describeServerEnv(registry: EnvRuntimeRegistry): ServerEnvDescription;
141
+ /** Returns whether an inspection entry makes `loadServerEnv()` fail: invalid, provider error, or required and missing. */
142
+ declare function isBlockingServerEnvEntry(entry: ServerEnvInspectionEntry): boolean;
143
+ declare function inspectServerEnv(registry: EnvRuntimeRegistry, event?: ViteHubContext, options?: LoadServerEnvOptions): Promise<ServerEnvInspection>;
144
+ //#endregion
145
+ export { parseSchema as C, StandardSchemaV1 as S, unseal as _, describeServerEnv as a, StandardSchemaResultFailure as b, loadServerEnv as c, SealOptions as d, UnsealErrorCode as f, seal as g, createSealing as h, deriveSecret as i, resolveServerEnv as l, UnsealSchemaOptions as m, ViteHubContext$1 as n, inspectServerEnv as o, UnsealOptions as p, bindServerEnvSchemas as r, isBlockingServerEnvEntry as s, DeriveSecretOptions as t, runWithCloudflareEnv as u, SealUsesDatabase as v, StandardSchemaResultSuccess as x, RequestEvent as y };
package/dist/server.d.ts CHANGED
@@ -1,25 +1,3 @@
1
- import { B as ServerEnvInspection, C as EnvProviders, F as LoadServerEnvOptions, H as ServerEnvInspectionStatus, R as ServerEnvDescription, T as EnvRuntimeRegistry, V as ServerEnvInspectionEntry, m as DeepReadonly, t as EnvAccessContext } from "./bridge-CdNdTN1V.js";
2
- //#region src/server.d.ts
3
- /**
4
- * Derives a 32-byte hex secret for one purpose from the root app secret, `VITEHUB_SECRET` (or `NUXT_APP_SECRET`).
5
- * It uses HKDF-SHA256, so the result is stable while the root is unchanged and distinct for every purpose.
6
- * Namespace the purpose to its owner, such as `my-module:session`. ViteHub reserves the `vitehub:` prefix.
7
- * Throws `ENV_REQUIRED_MISSING` when no root secret is set, and `ENV_RUNTIME_VALUE_INVALID` when it is shorter than 32 characters.
8
- */
9
- export declare function deriveSecret(purpose: string, event?: unknown, rootOverride?: string, generatedOverride?: boolean, rootEnvKey?: string): Promise<string>;
10
- /**
11
- * Apps call `useServerEnv()` on hot paths, often once per listed row. The result is reused while every name the
12
- * registry reads holds the same value, so a call does not copy the whole env and parse each declaration again. Each
13
- * call still gets its own records.
14
- */
15
- export declare function resolveServerEnv<TServerEnv extends Record<string, unknown> = Record<string, unknown>>(registry: EnvRuntimeRegistry<TServerEnv>, event?: unknown): TServerEnv;
16
- export declare function loadServerEnv<TServerEnv extends Record<string, unknown> = Record<string, unknown>>(registry: EnvRuntimeRegistry<TServerEnv>, event?: unknown, options?: LoadServerEnvOptions): Promise<DeepReadonly<TServerEnv>>;
17
- /** Describe declarations without loading host values or calling providers. */
18
- export declare function describeServerEnv(registry: EnvRuntimeRegistry): ServerEnvDescription;
19
- /** Returns whether an inspection entry makes `loadServerEnv()` fail: invalid, provider error, or required and missing. */
20
- export declare function isBlockingServerEnvEntry(entry: ServerEnvInspectionEntry): boolean;
21
- export declare function inspectServerEnv(registry: EnvRuntimeRegistry, event?: unknown, options?: LoadServerEnvOptions): Promise<ServerEnvInspection>;
22
- /** Limit management to safe, declared provider paths. Host variables stay read-only. */
23
- export declare function createServerEnvManagement(registry: EnvRuntimeRegistry, providers: EnvProviders): (request: Request) => Promise<Response>;
24
- //#endregion
25
- export type { EnvAccessContext, ServerEnvInspection, ServerEnvInspectionEntry, ServerEnvInspectionStatus };
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 };
package/dist/server.js CHANGED
@@ -1,2 +1,2 @@
1
- import { a as isBlockingServerEnvEntry, i as inspectServerEnv, n as deriveSecret, o as loadServerEnv, r as describeServerEnv, s as resolveServerEnv, t as createServerEnvManagement } from "./server-DufVswRJ.js";
2
- export { createServerEnvManagement, deriveSecret, describeServerEnv, inspectServerEnv, isBlockingServerEnvEntry, loadServerEnv, resolveServerEnv };
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 };
@@ -6,7 +6,6 @@ declare module "#vitehub/env/public" {
6
6
 
7
7
  declare module "#vitehub/env/server" {
8
8
  export interface ServerEnv extends Record<string, unknown> {}
9
- export function manageServerEnv(request: Request): Promise<Response>
10
9
  export function describeServerEnv(): import("@vite-hub/env").ServerEnvDescription
11
10
  export interface ServerEnvInspectionEntry {
12
11
  masked: boolean
@@ -20,15 +19,16 @@ declare module "#vitehub/env/server" {
20
19
  entries: readonly ServerEnvInspectionEntry[]
21
20
  }
22
21
  export type ReadonlyServerEnv = DeepReadonly<ServerEnv>
23
- type DeepReadonly<T> = T extends import("@vite-hub/env/secret").SecretEnv<unknown>
22
+ type DeepReadonly<T> = T extends import("@vite-hub/env").SecretEnv<unknown>
24
23
  ? T
25
24
  : T extends (...args: infer TArguments) => infer TResult
26
25
  ? (...args: TArguments) => TResult
27
26
  : T extends object
28
27
  ? { readonly [TKey in keyof T]: DeepReadonly<T[TKey]> }
29
28
  : T
30
- export function inspectServerEnv(event?: unknown, options?: { signal?: AbortSignal; access?: import("@vite-hub/env/bridge").EnvAccessContext }): Promise<ServerEnvInspection>
31
- export function loadServerEnv(event?: unknown, options?: { signal?: AbortSignal; access?: import("@vite-hub/env/bridge").EnvAccessContext }): Promise<ReadonlyServerEnv>
32
- export function useServerEnv(event?: unknown): ServerEnv
33
- export function runWithServerEnv<T>(event: unknown, callback: (env: ReadonlyServerEnv) => T | Promise<T>, options?: { signal?: AbortSignal; access?: import("@vite-hub/env/bridge").EnvAccessContext }): Promise<T>
29
+ export function inspectServerEnv(event?: import("@vite-hub/env/internal/server").ViteHubContext, options?: { signal?: AbortSignal; access?: import("@vite-hub/env/bridge").EnvAccessContext }): Promise<ServerEnvInspection>
30
+ export function loadServerEnv(event?: import("@vite-hub/env/internal/server").ViteHubContext, options?: { signal?: AbortSignal; access?: import("@vite-hub/env/bridge").EnvAccessContext }): Promise<ReadonlyServerEnv>
31
+ export function useServerEnv(event?: import("@vite-hub/env/internal/server").ViteHubContext): ServerEnv
32
+ export function deriveSecret(purpose: string, options?: { event?: import("@vite-hub/env/internal/server").ViteHubContext; root?: string }): Promise<string>
33
+ export function runWithServerEnv<T>(event: import("@vite-hub/env/internal/server").ViteHubContext | undefined, callback: (env: ReadonlyServerEnv) => T | Promise<T>, options?: { signal?: AbortSignal; access?: import("@vite-hub/env/bridge").EnvAccessContext }): Promise<T>
34
34
  }
package/dist/vite.d.ts CHANGED
@@ -1,16 +1,55 @@
1
- import { N as EnvViteConfigOptions, T as EnvRuntimeRegistry, v as EnvIntegrationOptions, w as EnvRuntimeConfigOptions } from "./bridge-CdNdTN1V.js";
2
- import { n as ViteHubCliContributor } from "./cli-DEwcUIe0.js";
3
- import { t as env } from "./declarations-CiRdb1qP.js";
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-BPp7rdcA.js";
3
+ import { t as env } from "./declarations-C5XR3aKw.js";
4
+ import { n as OperationContributionEntry } from "./operation-definition-8gOe-ubD.js";
4
5
  import { Plugin, UserConfig } from "vite";
6
+ //#region ../internal/src/deployment.d.ts
7
+ /** The host that ViteHub builds for: the `host` option of `vitehub()` and the value of `VITEHUB_HOST`. */
8
+ type ViteHubHost = "cloudflare" | "deno" | "netlify" | "node" | "vercel";
9
+ //#endregion
10
+ //#region ../internal/src/build/deployment-plan-output.d.ts
11
+ /**
12
+ * One set of host variables that the deployed app reads, as `deployment.json` lists it: a Server Env declaration, or
13
+ * a variable that a primitive reads itself, such as `VITEHUB_SECRET` or `BLOB_READ_WRITE_TOKEN`.
14
+ * It holds names only, so `vitehub deploy` can check the host without booting Vite. It never holds a value.
15
+ */
16
+ interface DeploymentEnvEntry {
17
+ /** The declaration path, such as `env.server.github.token`, when it is safe to show. Primitive entries have none. */
18
+ path?: string;
19
+ /** The host variable names, in read order. The first name that is set supplies the value. */
20
+ names: readonly string[];
21
+ /** Any variable whose name starts with this prefix supplies the value, such as `VITEHUB_CONSOLE_KEY_`. */
22
+ prefix?: string;
23
+ required: boolean;
24
+ secret: boolean;
25
+ /** A default supplies the value when no name is set. */
26
+ hasDefault: boolean;
27
+ /** The primitives that read these names, such as `blob`. Server Env declarations have none. */
28
+ owners?: readonly string[];
29
+ }
30
+ /** What a primitive needs to know to name the variables it reads in the deployed app. */
31
+ interface DeploymentEnvContext {
32
+ host: ViteHubHost;
33
+ }
34
+ /**
35
+ * The host variables that a primitive reads itself, outside the Server Env registry, for one host and its resolved
36
+ * config. A Vite plugin exposes it as `api.deploymentEnv`, and the build writes the result to `deployment.json`.
37
+ * Return names only, never values.
38
+ */
39
+ type DeploymentEnvContribution = (context: DeploymentEnvContext) => readonly DeploymentEnvEntry[];
40
+ //#endregion
5
41
  //#region ../internal/src/build/vite.d.ts
6
42
  declare const VITEHUB_ENV_PUBLIC_ID: "#vitehub/env/public";
7
43
  declare const VITEHUB_ENV_SERVER_ID: "#vitehub/env/server";
8
44
  //#endregion
9
45
  //#region src/core/resolve.d.ts
10
- declare function createRuntimeRegistry(declarations: EnvRuntimeConfigOptions | undefined, options?: {
46
+ interface RuntimeRegistryOptions {
11
47
  path?: string;
12
48
  prefix?: string | false;
13
- }): EnvRuntimeRegistry;
49
+ /** Accept `env.schemaFrom()`. Only generated modules that import and bind the schema modules set it. */
50
+ schemaModules?: boolean;
51
+ }
52
+ declare function createRuntimeRegistry(declarations: EnvRuntimeConfigOptions | undefined, options?: RuntimeRegistryOptions): EnvRuntimeRegistry;
14
53
  //#endregion
15
54
  //#region src/env-schema/importer.d.ts
16
55
  interface EnvSchemaOptions {
@@ -19,7 +58,7 @@ interface EnvSchemaOptions {
19
58
  paths?: Record<string, string>;
20
59
  }
21
60
  /** Import a committed env-spec-v1 contract. Reads schema metadata, never developer env files. */
22
- export declare function envSchema(file: string | URL, options?: EnvSchemaOptions): EnvViteConfigOptions;
61
+ export declare function envSchema(file: string | URL, options?: EnvSchemaOptions): EnvDeclarations;
23
62
  //#endregion
24
63
  //#region src/vite.d.ts
25
64
  export declare const ENV_VITE_PLUGIN_NAME = "@vite-hub/env/vite";
@@ -27,17 +66,22 @@ export declare const ENV_PUBLIC_ID: typeof VITEHUB_ENV_PUBLIC_ID;
27
66
  export declare const ENV_SERVER_ID: typeof VITEHUB_ENV_SERVER_ID;
28
67
  export interface EnvVitePluginAPI {
29
68
  createServerEnvRegistry: (declarations: EnvRuntimeConfigOptions | undefined) => EnvRuntimeRegistry;
69
+ /** `VITEHUB_SECRET`, which `deriveSecret()` and `seal()` read at runtime. Optional here: features that need it say so. */
70
+ deploymentEnv: DeploymentEnvContribution;
30
71
  getPublicEnv: () => Record<string, unknown>;
31
72
  getServerEnvRegistry: () => EnvRuntimeRegistry;
32
73
  onServerEnvRegistry: (handler: (registry: EnvRuntimeRegistry, config: UserConfig) => void) => void;
33
- prepareTypes: (config: EnvViteConfigOptions | undefined, viteRoot: string) => Promise<void>;
74
+ prepareTypes: (declarations: EnvDeclarations | undefined, viteRoot: string) => Promise<void>;
75
+ /** The declarations of this plugin's options, with the Server Env that ViteHub features add to this Vite config. */
76
+ resolveDeclarations: (config: object) => EnvDeclarations | undefined;
34
77
  resolveProjectRoot: (viteRoot: string) => string;
35
78
  }
36
79
  export type EnvVitePlugin = Plugin & {
37
80
  api: EnvVitePluginAPI;
38
- /** Contributes `vitehub env inspect` and `vitehub env check`. */
81
+ /** Contributes `vitehub env inspect`, `vitehub env check`, and the `env.inspect` operation. */
39
82
  vitehub: {
40
83
  cli: () => ViteHubCliContributor;
84
+ operations: readonly OperationContributionEntry[];
41
85
  };
42
86
  };
43
87
  export interface EnvGeneratedPathOptions {
@@ -46,11 +90,12 @@ export interface EnvGeneratedPathOptions {
46
90
  }
47
91
  export declare function createEnvImportAliases(options?: EnvGeneratedPathOptions): Record<string, string>;
48
92
  export declare function createEnvTypeScriptPaths(options?: EnvGeneratedPathOptions): Record<string, string[]>;
49
- export declare function hubEnv(options?: EnvIntegrationOptions): EnvVitePlugin;
50
- declare module "vite" {
51
- interface UserConfig {
52
- env?: EnvViteConfigOptions;
53
- }
54
- }
93
+ /**
94
+ * Returns the declarations that the Vite Integration writes to `.vitehub/types/env.d.ts` for an `env` config: the
95
+ * `PublicEnv` and `ServerEnv` types of `#vitehub/env/public` and `#vitehub/env/server`. A TypeScript host that does
96
+ * not run Vite, such as a test or a docs check, can write them itself.
97
+ */
98
+ export declare function createEnvTypes(config: EnvDeclarations | undefined, options?: Pick<EnvOptions, "prefix" | "runtimeImports" | "projectRoot">): string;
99
+ export declare function hubEnv(options?: EnvOptions): EnvVitePlugin;
55
100
  //#endregion
56
101
  export { type EnvSchemaOptions, createRuntimeRegistry as createRuntimeEnvRegistry, env };