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"; import { Duration, Result, ViteHubContext, ViteHubContext as ViteHubContext$1 } from "@vite-hub/runtime"; //#region src/schema.d.ts interface StandardSchemaResultSuccess { issues?: undefined; value: T; } interface StandardSchemaResultFailure { issues: readonly unknown[]; } interface StandardSchemaV1 { "~standard": { validate: (input: unknown) => StandardSchemaResultSuccess | StandardSchemaResultFailure | Promise | StandardSchemaResultFailure>; }; } declare function parseSchema(schema: unknown, value: unknown, label: string): unknown; //#endregion //#region src/internal/runtime-env.d.ts type RuntimeEnv = Record; /** * A request event: an H3 event, another event with Standard Context, or a web `Request`. An H3 event matches `{ req }` * even when the app does not load the types that add `~standard` to it. */ type RequestEvent = Request | ViteHubContext | { readonly req: Request; }; //#endregion //#region src/seal-uses.d.ts /** * A SQLite, libSQL, or D1 Drizzle database, such as `db` from `vite-hub/database`. The uses of a sealed value live * there, because every instance of the app must see the same count. KV cannot take a use atomically. */ interface SealUsesDatabase { all: (query: string) => unknown[] | PromiseLike; } //#endregion //#region src/seal-value.d.ts /** The codes that `unseal()` returns. */ type UnsealErrorCode = "ENV_SEAL_EXPIRED" | "ENV_SEAL_INVALID" | "ENV_SEAL_SCHEMA_MISMATCH" | "ENV_SEAL_USED_UP" | "ENV_SEAL_WRONG_PURPOSE"; interface UnsealOptions { /** The request, so that on Cloudflare the root secret comes from its bindings. Without it, the active request's bindings. */ event?: ViteHubContext; /** * A root secret to use instead of `VITEHUB_SECRET`, of at least 32 characters. Use one for values that you store, * so that a rotation of `VITEHUB_SECRET` does not make them unreadable. To rotate it, pass a list: the new secret * first, then the old ones. `seal()` uses the first, and `unseal()` tries each in order. */ secret?: string | SecretEnv | readonly (string | SecretEnv)[]; /** * The database that counts the uses of a value sealed with `uses`, such as `db` from `vite-hub/database`. `unseal()` * needs it for such a value. SQLite, libSQL, and D1 work. It keeps a random id, the uses left, and the expiry, never * the value. */ db?: SealUsesDatabase; } interface UnsealSchemaOptions extends UnsealOptions { /** A Standard Schema, such as a Valibot or Zod schema. `unseal()` returns its output. */ schema: StandardSchemaV1; } interface SealOptions extends UnsealOptions { /** * How long until `unseal()` returns `ENV_SEAL_EXPIRED`: a number of seconds, or a duration such as `"15m"`. Without * it, the value does not expire. */ ttl?: number | Duration; /** * How many times `unseal()` can read the value. Each read takes one use atomically in `db`, so of two reads of the last * use, one gets the value and the other gets `ENV_SEAL_USED_UP`. Without it, the value opens any number of times. */ uses?: number; } /** Derives the key of a purpose. The generated `#vitehub/env/server` module passes one that also reads the development secret. */ type SealSecretDerivation = (purpose: string, event: ViteHubContext | undefined, root: string | undefined) => Promise; /** `seal()` and `unseal()` on one key derivation. */ interface Sealing { seal: (purpose: string, value: unknown, options?: SealOptions) => Promise; unseal: (purpose: string, sealed: string, options?: UnsealOptions & { schema?: StandardSchemaV1; }) => Promise>; } /** Builds `seal()` and `unseal()` on a key derivation. The generated `#vitehub/env/server` module uses it. */ declare function createSealing(derive: SealSecretDerivation): Sealing; /** * Encrypts and signs a JSON value for one purpose, with a key that ViteHub derives from `VITEHUB_SECRET`. * Returns a URL-safe string that only `unseal()` with the same purpose can read. * Throws `ENV_REQUIRED_MISSING` when no root secret is set, and `ENV_SEAL_ARGUMENT_INVALID` for a bad argument. * * @example * const ticket = await seal("my-app:upload", { userId }, { ttl: "15m" }) */ declare function seal(purpose: string, value: unknown, options?: SealOptions): Promise; /** * Reads a value from `seal()`. Returns `[error, undefined]` with `ENV_SEAL_EXPIRED`, `ENV_SEAL_INVALID`, * `ENV_SEAL_SCHEMA_MISMATCH`, or `ENV_SEAL_WRONG_PURPOSE`, else `[undefined, value]`. Pass `schema` to check the value * and type it. It tries `VITEHUB_SECRET`, then each old secret in `VITEHUB_SECRET_PREVIOUS` (comma-separated), so * values sealed before a rotation still open. Throws when no root secret is set. * * @example * const [error, upload] = await unseal("my-app:upload", ticket, { schema: v.object({ userId: v.string() }) }) */ declare function unseal(purpose: string, sealed: string, options: UnsealSchemaOptions): Promise>; declare function unseal(purpose: string, sealed: string, options?: UnsealOptions): Promise>; //#endregion //#region src/server.d.ts /** * Run `callback` with `env` as the active Cloudflare bindings. Server Env reads them when a call gets no request * event, such as for the module bindings of `cloudflare:workers` outside a request. */ declare function runWithCloudflareEnv(env: RuntimeEnv, callback: () => T): T; /** Options of `deriveSecret()`. */ interface DeriveSecretOptions { /** The request event. On Cloudflare, ViteHub reads `VITEHUB_SECRET` from its Worker bindings. */ event?: ViteHubContext; /** The root secret. Without it, ViteHub reads `VITEHUB_SECRET`. */ root?: string; } /** The development secret that the Vite plugin generated or selected for one project. Private to the generated module. */ interface DevelopmentSecret { envKey?: string; generated?: boolean; } /** * Derives a 32-byte hex secret for one purpose from the root app secret, `VITEHUB_SECRET`. * It uses HKDF-SHA256, so the result is stable while the root is unchanged and distinct for every purpose. * Namespace the purpose to its owner, such as `my-module:session`. ViteHub reserves the `vitehub:` prefix. * Throws `ENV_REQUIRED_MISSING` when no root secret is set, and `ENV_RUNTIME_VALUE_INVALID` when it is shorter than 32 characters. * Only the generated `#vitehub/env/server` module passes `development`, with the project's development secret. */ declare function deriveSecret(purpose: string, options?: DeriveSecretOptions, development?: DevelopmentSecret): Promise; /** * Attach the schemas that `env.schemaFrom()` declarations name. The generated `#vitehub/env/server` module imports * each schema module and calls this once, so a missing or wrong export fails when the server starts. */ declare function bindServerEnvSchemas(registry: EnvRuntimeRegistry, modules: Readonly>>>): void; /** * Apps call `useServerEnv()` on hot paths, often once per listed row. The result is reused while every name the * registry reads holds the same value, so a call does not copy the whole env and parse each declaration again. Each * call still gets its own records. */ declare function resolveServerEnv = Record>(registry: EnvRuntimeRegistry, event?: ViteHubContext): TServerEnv; declare function loadServerEnv = Record>(registry: EnvRuntimeRegistry, event?: ViteHubContext, options?: LoadServerEnvOptions): Promise>; /** Describe declarations without loading host values or calling providers. */ declare function describeServerEnv(registry: EnvRuntimeRegistry): ServerEnvDescription; /** Returns whether an inspection entry makes `loadServerEnv()` fail: invalid, provider error, or required and missing. */ declare function isBlockingServerEnvEntry(entry: ServerEnvInspectionEntry): boolean; declare function inspectServerEnv(registry: EnvRuntimeRegistry, event?: ViteHubContext, options?: LoadServerEnvOptions): Promise; //#endregion 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 };