Skip to content

SDK

Install the TypeScript SDK:

Terminal window
npm install @envlet/sdk

Set ENVLET_TOKEN, or pass token in the options object.

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, and enum: string
  • integer and number: number
  • boolean: boolean
  • json: 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() 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() 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.

Each function accepts:

  • token: Use this token instead of ENVLET_TOKEN.
  • apiUrl: Use this origin instead of ENVLET_API_URL or https://api.envlet.dev.
  • retry: Set to false for one request attempt.

inject() also accepts override.

  • config_missing: No token is available.
  • unsupported_runtime: inject() cannot access process.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.