JavaScript SDK

JavaScript SDK

@fujiflag/js is the framework-agnostic FujiFlag SDK. It supports browsers and Node.js, has no external dependencies, and can cache and poll flag values.

Install

npm install @fujiflag/js

Create a client

import { createFujiFlagClient } from "@fujiflag/js";
const client = createFujiFlagClient({
apiKey: "ff-pk-your-api-key-here",
baseURL: "https://api.fujiflag.com",
cacheTTL: 5 * 60 * 1000,
refreshInterval: 60 * 1000,
});

baseURL is optional. Use it when connecting to a self-hosted or local FujiFlag API. cacheTTL and refreshInterval are optional and expressed in milliseconds.

Read one value

const enabled = await client.getFlagValue<boolean>("new-checkout");

Read all values

const flags = await client.getFlagValues();
console.log(flags);

Browser script tag

<script src="https://unpkg.com/@fujiflag/js/dist/index.umd.js"></script>
<script>
const client = FujiFlag.createClient({
apiKey: "ff-pk-your-api-key-here",
baseURL: "https://api.fujiflag.com"
});
</script>

For the complete package surface, see the SDK README.