← All @molecule/* packages · App templates
@molecule/api-secrets-moleculeProvider bond · secrets · API (Node) · v1.0.1 · Apache-2.0
Managed per-app secrets vault + credential-broker seam for molecule.dev-hosted backends
npm install @molecule/api-secrets-moleculenpm · Source on GitHub · Implements @molecule/api-secrets
@molecule/api-secrets-molecule is a provider bond on the API (Node) side: it implements the secrets core interface (@molecule/api-secrets) with a concrete vendor or library behind it.
Your code calls the core; you wire this provider once at startup. Swapping vendors later is one line in that wiring, not a rewrite.
import { bond } from '@molecule/api-bond'
import { provider } from '@molecule/api-secrets-molecule'
bond('secrets', provider)
// ...then, unchanged: await resolveAll([ ...keys... ]) → syncToEnv → process.envWorks with: @molecule/api-bond, @molecule/api-i18n, @molecule/api-secrets
Secrets: MOLECULE_VAULT_TOKEN, MOLECULE_APP_ID, MOLECULE_VAULT_URL (optional)
Auto-generated, AI-first package reference for the molecule.dev ecosystem. It is written to be read by coding agents as much as by people, and is generated from this package's source — edit
src/index.tsJSDoc, not this file.
Molecule managed-vault secrets provider for molecule.dev.
Fetches a single app's secrets from molecule.dev's managed, per-app encrypted
vault at runtime, caches them with a TTL, serves stale cache on transient
failure, and only then falls back to process.env. The bootstrap token + app
id are the only secrets that live in the environment. It is also the seam
through which credential brokering is delivered with no app-code change.
import { bond } from '@molecule/api-bond'
import { provider } from '@molecule/api-secrets-molecule'
bond('secrets', provider)
// ...then, unchanged: await resolveAll([ ...keys... ]) → syncToEnv → process.env
provider
npm install @molecule/api-secrets-molecule @molecule/api-bond @molecule/api-i18n @molecule/api-secrets
MoleculeSecretsProviderOptionsOptions for the molecule managed-vault secrets provider.
interface MoleculeSecretsProviderOptions {
/**
* Per-app bootstrap token.
* Falls back to the `MOLECULE_VAULT_TOKEN` env var.
*/
token?: string
/**
* App identifier the vault scopes secrets to.
* Falls back to the `MOLECULE_APP_ID` env var.
*/
appId?: string
/**
* Vault base URL.
* Falls back to the `MOLECULE_VAULT_URL` env var, then
* `https://api.molecule.dev/v1/vault`.
*/
vaultUrl?: string
/**
* Cache TTL in milliseconds.
* @default 60000 (1 minute)
*/
cacheTtl?: number
/**
* On fetch failure, serve last-good cached values (stale) before falling
* back to `process.env`. When `false`, fall back to `process.env` immediately.
* @default true
*/
staleWhileError?: boolean
}
createMoleculeSecretsProvider(options)Creates a managed-vault secrets provider that fetches a single app's secrets
from molecule.dev's vault, caches them for the TTL, serves stale cache on
transient failure, and only then falls back to process.env.
function createMoleculeSecretsProvider(options?: MoleculeSecretsProviderOptions): SecretsProvider
options — Vault connection options. Falls back to MOLECULE_* env vars.Returns: A SecretsProvider with get/getMany/set/delete/isAvailable/syncToEnv backed by the molecule vault.
providerDefault provider instance, created from MOLECULE_* environment variables.
const provider: SecretsProvider
secretsMoleculeSecretDefinitionsSecret definitions required by the molecule.dev vault secrets bond.
const secretsMoleculeSecretDefinitions: SecretDefinition[]
Implements @molecule/api-secrets interface.
Setup function to register this provider with the core interface:
import { setProvider } from '@molecule/api-secrets'
import { provider } from '@molecule/api-secrets-molecule'
export function setupSecretsMolecule(): void {
setProvider(provider)
}
Peer dependencies:
@molecule/api-bond ^1.0.1@molecule/api-i18n ^1.0.1@molecule/api-secrets ^1.0.1MOLECULE_VAULT_TOKEN (required) — molecule.dev vault token
MOLECULE_APP_ID (required) — molecule.dev app ID
MOLECULE_VAULT_URL (optional) — molecule.dev vault URL — default: https://api.molecule.dev/v1/vault
@molecule/api-bond
@molecule/api-i18n
@molecule/api-secrets
MOLECULE_VAULT_TOKEN / MOLECULE_APP_ID must be in the environment BEFORE
this module is imported — the default provider captures them at import time
(they are platform-provisioned in molecule.dev deployments, so this normally
holds). For late-arriving credentials, wire
createMoleculeSecretsProvider({ token, appId }) instead.
Without a reachable vault AND no cached values, reads fall back to process.env
with a logged warning — provider.isAvailable() at boot tells you which path
you're on.