Repository navigation
Conversation
Add a `client.secrets` namespace that manages the actual server-side
value of a Tinybird secret via the `/v0/variables` endpoints, mirroring
`tb secret ls/set/rm` in the Python CLI. This is a separate,
complementary concern to the existing `secret()` helper in
`src/schema/secret.ts`, which only emits a `{{ tb_secret(...) }}`
template reference for datafiles and never talks to the API.
- `src/api/secrets.ts`: low-level `listSecrets`/`createSecret`/
`updateSecret`/`setSecret`/`removeSecret` functions and a
`SecretApiError` class, following the `src/api/tokens.ts` pattern.
`setSecret` checks for an existing secret (`GET /v0/variables/{name}`)
before deciding to create or update, mirroring `load_secrets`/
`secret_set` in the Tinybird CLI.
- `src/client/secrets.ts`: `SecretsNamespace` class exposing
`list()`/`set(name, value)`/`remove(name)`, wired into
`TinybirdClient.secrets` in `src/client/base.ts` and into the
`Tinybird` project client (`src/schema/project.ts`) the same way
`tokens` already is.
- Secret values are never logged, never read back from success
responses, and are redacted from any thrown error message/body in
case the API ever echoes a submitted value back.
- Tests colocated per existing convention (`src/api/secrets.test.ts`,
`src/client/secrets.test.ts`), covering list/set(create)/set(update)/
remove and error paths, including value redaction.
Fixes PROTM-2271.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a
client.secretsnamespace for managing the actual server-side value of a Tinybird secret via the/v0/variablesAPI, matchingtb secret ls/set/rmin the Tinybird CLI.This is a separate, complementary concern to the existing
secret()helper (src/schema/secret.ts), which only emits a{{ tb_secret(...) }}template reference for datafiles and never talks to the API — that helper is untouched.Linear: https://linear.app/tinybird/issue/PROTM-2271/typescript-sdk-add-secrets-management-api-lssetrm
What's included
src/api/secrets.ts— low-levellistSecrets,createSecret,updateSecret,setSecret,removeSecretfunctions and aSecretApiErrorclass, mirroring the structure ofsrc/api/tokens.ts.GET /v0/variables→listSecretsPOST /v0/variables(form body{name, value}) →createSecretPUT /v0/variables/{name}(form body{value}) →updateSecretDELETE /v0/variables/{name}→removeSecretsetSecretchecks for an existing secret viaGET /v0/variables/{name}first and then creates or updates, mirroringload_secrets/secret_setin the Python CLI (tinybird/tb/modules/secret.py,secret_common.py), including treating any failure of the existence check (404, permission error, etc.) as "doesn't exist yet".src/client/secrets.ts—SecretsNamespaceclass exposinglist()/set(name, value)/remove(name), following the exact structural template ofTokensNamespace(src/client/tokens.ts).TinybirdClient.secretsinsrc/client/base.tsthe same wayclient.tokensis wired, and also into theTinybirdproject client (src/schema/project.ts) alongside the existingtokensgetter, for consistency.src/index.ts:SecretApiConfig,SecretInfo,SetSecretResult,RemoveSecretResult, pluslistSecrets/createSecret/updateSecret/setSecret/removeSecret/SecretApiError.Security
[REDACTED]) before being surfaced, in case an API error response ever echoes it back.list()only returns metadata (name,created_at,updated_at) — never a value.Assumptions about
/v0/variablesresponse shapes (couldn't fully confirm against a live API)GET /v0/variablesreturns{ variables: [...] }— confirmed against the Forward CLI's Python client (tinybird/tb/client.py: secrets()), which readsresponse["variables"].name,created_at,updated_at) — inferred fromtb secret ls's output columns insecret.py; not fully confirmed that the API never includes a value field, soSecretInfois typed loosely and this SDK never surfaces anything beyondname/timestamps regardless of what's in the response.GET /v0/variables/{name}(existence check): response body is intentionally never parsed or returned by this SDK — onlyresponse.okis used — since it's unconfirmed whether this endpoint returns the plaintext value for an existing secret.Test plan
pnpm typecheckpnpm test:run(all 1085 tests pass, including newsrc/api/secrets.test.tsandsrc/client/secrets.test.ts)