import { z } from "zod"; export interface DefineClientEnvOptions> { /** * zod schema describing the public, browser-bundled env vars. * Every key MUST start with `prefix` — enforced at definition time * so the mistake is caught long before a secret reaches the bundle. */ schema: TSchema; /** * Required prefix for every key in the schema. Conventional values: * - `"NEXT_PUBLIC_"` (Next.js) * - `"VITE_"` (Vite) * - `"PUBLIC_"` (Astro, SvelteKit, etc.) * * Pick the prefix your build tool already enforces; the helper is a * second line of defence so a misnamed key fails fast instead of * being silently dropped at build time. */ prefix: string; /** * When `true`, throw `CLIENT_ENV_UNDECLARED` if the runtime source * contains a `prefix`-starting key that is not in the schema. Catches * typos and forgotten-to-declare drift. Default: `false` (extra * prefixed keys are silently ignored). */ strict?: boolean; } /** * Type-safe loader for *client-bundled* env. Pair this with * `defineSettings` for the server side: secrets stay in the server * loader, public values live in the client loader, and the prefix * makes any mix-up a compile-time *and* runtime error. * * @example * ```ts * // settings.client.ts * import { z } from "zod"; * import { defineClientEnv } from "@env-kit/node-settings"; * * export const clientEnv = defineClientEnv({ * prefix: "VITE_", * schema: z.object({ * VITE_API_URL: z.string().url(), * VITE_SENTRY_DSN: z.string().optional(), * }), * }); * * // app code (browser) * const env = clientEnv(import.meta.env); * fetch(env.VITE_API_URL); * ``` * * The returned function: * 1. Filters `source` to keys starting with `prefix` (server-only * keys are dropped before zod ever sees them). * 2. Runs `schema.parse` on the filtered map. * 3. (optional) Fails if `strict` is set and a prefixed key wasn't * declared in the schema. * * Failures throw `NodeSettingsError` with a stable `code`: * - `CLIENT_ENV_PREFIX_VIOLATION` — thrown immediately from * `defineClientEnv` if any schema key omits the prefix. * - `CLIENT_ENV_UNDECLARED` — thrown at runtime under `strict: true`. * - `CLIENT_ENV_VALIDATION_FAILED` — wraps a zod ZodError. */ export declare function defineClientEnv>(options: DefineClientEnvOptions): (source: Record) => z.infer; //# sourceMappingURL=client-env.d.ts.map