Upgrade @arki/env 0.0.11 to 0.1.0
For @arki/[email protected] · source docs/upgrades/0.0.11-to-0.1.0.md
Every app that calls defineEnv must act: validation now runs in every environment, so builds without secrets need SKIP_ENV_VALIDATION=1. Apps that never use secret() or the zod types of secret() can skip steps 2 and 3.
What changed
-
secret()takes any Standard Schema (zod, valibot, arktype, hand-written) and returns a Standard Schema, not a zod schema..optional()is still there: it accepts a missing variable and leavesundefinedunwrapped. The result no longer has zod methods such as.parse; usesecret(schema)['~standard'].validate(value).A rejected secret's issues keep their path but get a fixed message, because some validators (valibot) repeat the received value in theirs and
defineEnvlogs issues. -
Validation now runs in production by default.
defineEnvused to skip validation wheneverNODE_ENV !== 'development', so an app without an explicitskipValidationbooted production on an unchecked config. The default now skips only whenCIis set (Docker build stages) or duringlintruns, the same rule most apps already passed by hand. Apps that setoptions.skipValidationare unaffected.New
secret(schema),reveal(value)andRedacted(from@arki/env/core): a secret variable becomes aRedactedvalue that prints as[redacted]in logs, JSON, template strings andutil.inspect, and is read with a deliberatereveal(env.KEY).revealalso accepts the raw string, for runs where validation is skipped. -
defineEnv()server,clientandsharedtake records of any Standard Schema (Zod, Valibot, ArkType, hand-written), not onlyZodType; values are typed as each schema's output.@arki/env/dot:EnvDotOptions,EnvServicesandenv()takeRecord<string, StandardSchemaV1>instead ofRecord<string, ZodType>. -
Breaking:
defineEnvnow validates in every environment.CIandlintruns no longer skip validation. The only implicit opt-out isSKIP_ENV_VALIDATION=1(exactly1); set it only in build stages that run without secrets.options.skipValidationstill overrides it. The@arki/env/dotplugin now validates at boot and fails withARKI_ENV_PLUGIN_E001(newENV_PLUGIN_ERROR_CODES), andEnvServices['env']is derived fromdefineEnvwithout a cast.
Public API changes
secret()now returns a Standard Schema, not a zod schema. It has no.parse..optional()still works.defineEnvserver,clientandsharedaccept any Standard Schema, not only zod.@arki/env/dot:EnvDotOptions,EnvServicesandenv()takeRecord<string, StandardSchemaV1>. The plugin validates at boot and fails withARKI_ENV_PLUGIN_E001.- New exports:
reveal,Redacted,ENV_PLUGIN_ERROR_CODES.
Steps
-
Find builds that run without secrets (Docker build stages, lint, CI).
defineEnvno longer skips validation there. SetSKIP_ENV_VALIDATION=1(exactly1) in those stages only.# before: CI=1 skipped validation CI=1 bun run build # after SKIP_ENV_VALIDATION=1 bun run build -
Replace zod methods on
secret()results. Use the Standard Schema call.// before const key = secret(z.string()).parse(value); // after const result = secret(z.string())['~standard'].validate(value); -
Read secrets with
reveal. A secret prints as[redacted]in logs and JSON.// after import { reveal } from '@arki/env/core'; // before const key = env.API_KEY; const key = reveal(env.API_KEY); -
Dot apps: expect
ARKI_ENV_PLUGIN_E001at boot when a variable is missing. Fix the variable. Do not add a skip.
Verify
Run the app's boot with a missing required variable and confirm it fails. Run bun run typecheck in the app to catch .parse calls on secret().