Flowtag Docs
JavaScript

@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/variables

createClient(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");
ParameterTypeDescription
tokenstringRequired. 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");
ParameterTypeDescription
idstringThe 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);
FieldTypeDescription
idstringVariable ID.
namestringVariable name.
type"toggle" | "json"Variable type.
digeststringHash of the current value — useful for cache invalidation.
updatedAtnumberUnix 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.

On this page