SDK
Install the TypeScript SDK:
npm install @envlet/sdkSet ENVLET_TOKEN, or pass token in the options object.
Load typed values
Section titled “Load typed values”load() reads values and schema from GET /v1/values.
import { load } from "@envlet/sdk";
const env = await load();It returns these runtime types:
string,url, andenum:stringintegerandnumber:numberboolean:booleanjson: parsed object or array
An absent optional key is omitted. An absent required key throws EnvletError with code missing_value. A present value that does not match its schema throws EnvletError with code invalid_value. Both messages name the key and do not contain the value.
Without a generated declaration, load() returns Record<string, unknown>. Run envlet types to merge the declared keys and types into Env.
Get one typed value
Section titled “Get one typed value”get() reads one value and its schema:
import { get } from "@envlet/sdk";
const port = await get("PORT");With generated types, the argument is limited to keyof Env and the result is Env[typeof name]. A missing or withheld value throws EnvletNotFoundError.
Inject raw strings
Section titled “Inject raw strings”inject() validates the response schema, writes raw wire strings to process.env, and returns the raw string map:
import { inject } from "@envlet/sdk";
const raw = await inject();Existing host values win. Pass override: true to replace them. Use load() instead when process.env is unavailable.
Options
Section titled “Options”Each function accepts:
token: Use this token instead ofENVLET_TOKEN.apiUrl: Use this origin instead ofENVLET_API_URLorhttps://api.envlet.dev.retry: Set tofalsefor one request attempt.
inject() also accepts override.
Errors
Section titled “Errors”config_missing: No token is available.unsupported_runtime:inject()cannot accessprocess.env.invalid_response: A successful response has the wrong shape.invalid_value: A wire value does not match its schema.missing_value: A required schema key is absent.network_error: The API cannot be reached after the retry budget.not_found: A requested value is absent or withheld.- API authentication codes, including
token_expired, are preserved.
The SDK makes at most three attempts for network errors and 5xx responses. It does not retry 4xx responses or typed parsing errors.