@rtorcato/cf-common
Functions
getSecret()
getSecret(
env,name):Promise<string>
Defined in: index.ts:21
Read a secret from a Cloudflare Secrets Store binding by name.
A Secrets Store binding (secrets_store_secrets in wrangler config) is one
secret, read with an async get(). This looks the binding up like
getBinding (a missing one is a non-exposed 500) and returns the
secret as a string.
A failed read (the secret was deleted, the store is unreachable) throws a
non-exposed 500 with code SECRET_GET_FAILED and the original error as
cause. The message names the binding, never the value. Nothing is cached:
every call reads the store, so keep the result in a variable if you need it
more than once per request.
Example
const apiKey = await getSecret(env, 'STRIPE_KEY')
Parameters
env
Env
name
string
Returns
Promise<string>