@flowtag/variables
JavaScript SDK for reading Flowtag Variables.
The @flowtag/variables package provides a typed client for reading Flowtag Variables from any JavaScript or TypeScript environment — Node.js, edge runtimes, or the browser.
Installation
pnpm add @flowtag/variablescreateClient(token)
Create a client bound to an access token. Create your token in the Dashboard under Variables → Tokens.
import { createClient } from "@flowtag/variables";
const client = createClient("YOUR_TOKEN");| Parameter | Type | Description |
|---|---|---|
token | string | Required. Access token created in the Dashboard. |
Never expose your token in client-side code. Read the security note in the Tokens docs.
.getVariable(id)
Fetch the value of a variable by its ID.
const value = await createClient("YOUR_TOKEN").getVariable("VARIABLE_ID");Pass a type parameter for a typed result:
// toggle → boolean
const showBanner = await createClient("YOUR_TOKEN").getVariable<boolean>("VARIABLE_ID");
// json → your type
const config = await createClient("YOUR_TOKEN").getVariable<{ limit: number; enabled: boolean }>("VARIABLE_ID");| Parameter | Type | Description |
|---|---|---|
id | string | The variable ID from the Dashboard. |
Returns Promise<T> — the variable's value cast to T.
.getVariableMeta(id)
Fetch metadata for a variable without its value.
const meta = await createClient("YOUR_TOKEN").getVariableMeta("VARIABLE_ID");
console.log(meta.name, meta.type, meta.updatedAt);| Field | Type | Description |
|---|---|---|
id | string | Variable ID. |
name | string | Variable name. |
type | "toggle" | "json" | Variable type. |
digest | string | Hash of the current value — useful for cache invalidation. |
updatedAt | number | Unix timestamp of the last update. |
.getSchema(id)
Fetch the JSON schema for a json-type variable.
const schema = await createClient("YOUR_TOKEN").getSchema("VARIABLE_ID");Returns Promise<Record<string, unknown>> — the variable's JSON schema.
getVariable(id)
A standalone export that reads the token from the FLOWTAG_VARIABLES_TOKEN environment variable. Useful in server environments where the token is already set.
import { getVariable } from "@flowtag/variables";
const showBanner = await getVariable<boolean>("VARIABLE_ID");Equivalent to createClient(process.env.FLOWTAG_VARIABLES_TOKEN).getVariable(id).
Example
import { createClient } from "@flowtag/variables";
const client = createClient(process.env.FLOWTAG_VARIABLES_TOKEN!);
const showBanner = await client.getVariable<boolean>("VARIABLE_ID");
const config = await client.getVariable<{ limit: number }>("VARIABLE_ID");
console.log(showBanner, config);Store your token in an environment variable and never commit it to source control.