/** * Platform presets for inferring `APP_ENV` from well-known * deployment-platform environment variables. * * Each preset is *opt-in*. The library never inspects the platform * automatically; users compose presets explicitly: * * ```ts * import { inferAppEnv, presets } from "@env-kit/node-settings"; * const APP_ENV = inferAppEnv({ * presets: [presets.vercel(), presets.githubActions({ branchToMode: { main: "prod" } })], * }); * ``` */ /** A single platform preset — given an env source, returns the inferred mode or `undefined`. */ export interface AppEnvPreset { readonly name: string; readonly detect: (env: Record) => string | undefined; } export interface InferAppEnvOptions { /** Env source. Default: `process.env`. */ source?: Record; /** Presets to consult, in priority order. Default: `[]`. */ presets?: readonly AppEnvPreset[]; /** Fallback mode when nothing matches. Default: `'local'`. */ default?: string; /** The env var that holds an explicit override. Default: `'APP_ENV'`. */ envKey?: string; } /** * Detailed result of {@link inferAppEnv}. Use when you want to log * *where* the mode came from (for debugging "why does my app think * it's local in production?" issues). */ export interface InferAppEnvResult { /** The resolved mode value. */ value: string; /** Where the value came from. */ source: "explicit" | "preset" | "default"; /** Name of the matching preset, if `source === 'preset'`. */ presetName: string | undefined; } /** * Resolve `APP_ENV` (or any chosen env key) from a chain of sources, * in priority order: * * 1. `source[envKey]` if set — always wins (explicit override). * 2. Each `preset.detect(source)` in array order — first non-undefined wins. * 3. `default` (fallback). * * `process.env`/explicit-override > platform-signal > default. This * matches the intuition that if VERCEL_ENV says "production" but the * operator has set APP_ENV manually, the operator wins. */ export declare function inferAppEnv(options?: InferAppEnvOptions): string; /** Same as {@link inferAppEnv} but returns the resolution metadata too. */ export declare function inferAppEnvDetailed(options?: InferAppEnvOptions): InferAppEnvResult; export interface VercelMapping { production?: string; preview?: string; development?: string; } /** * Vercel preset — maps `VERCEL_ENV` to a mode. * Default mapping: `production` -> `prod`, `preview` -> `stage`, * `development` -> `local`. */ declare function vercel(overrides?: VercelMapping): AppEnvPreset; export interface NetlifyMapping { production?: string; "deploy-preview"?: string; "branch-deploy"?: string; dev?: string; } /** * Netlify preset — maps `CONTEXT` to a mode. * Default: `production` -> `prod`, `deploy-preview` -> `stage`, * `branch-deploy` -> `dev`, `dev` -> `local`. */ declare function netlify(overrides?: NetlifyMapping): AppEnvPreset; export interface CloudflarePagesOptions { productionBranch?: string; productionMode?: string; defaultMode?: string; } /** * Cloudflare Pages preset — uses `CF_PAGES` + `CF_PAGES_BRANCH`. * The production branch (default `'main'`) maps to `prod`; everything * else maps to `defaultMode` (default `'dev'`). */ declare function cloudflarePages(options?: CloudflarePagesOptions): AppEnvPreset; export interface GithubActionsOptions { /** Branch -> mode lookup. Keys are branch names (without `refs/heads/`). */ branchToMode?: Record; /** Mode for branches not in `branchToMode`. Default: `'dev'`. */ default?: string; } /** * GitHub Actions preset — uses `GITHUB_REF_NAME` (or `GITHUB_REF`). * Map specific branches to modes; everything else falls through to * `default`. Only fires when `GITHUB_ACTIONS=true`. */ declare function githubActions(options?: GithubActionsOptions): AppEnvPreset; export interface RailwayMapping { production?: string; staging?: string; development?: string; } /** Railway preset — maps `RAILWAY_ENVIRONMENT_NAME` (falls back to `RAILWAY_ENVIRONMENT`). */ declare function railway(overrides?: RailwayMapping): AppEnvPreset; /** * Render preset — Render injects `RENDER=true` and `IS_PULL_REQUEST`. * The default mapping treats production deploys as `prod` and PR * previews as `stage`. */ declare function render(options?: { production?: string; preview?: string; }): AppEnvPreset; export interface NodeEnvMapping { production?: string; development?: string; test?: string; } /** * `NODE_ENV` preset — the Node.js convention. Default: `production` * -> `prod`, `development` -> `local`, `test` -> `test`. Useful as a * last-resort fallback for environments without their own signal. */ declare function nodeEnv(overrides?: NodeEnvMapping): AppEnvPreset; /** * Bundled preset factories. Each is opt-in — compose only the * platforms you actually deploy to. */ export declare const presets: { readonly vercel: typeof vercel; readonly netlify: typeof netlify; readonly cloudflarePages: typeof cloudflarePages; readonly githubActions: typeof githubActions; readonly railway: typeof railway; readonly render: typeof render; readonly nodeEnv: typeof nodeEnv; }; export {}; //# sourceMappingURL=presets.d.ts.map