Skip to content

Flags

The flags namespace exported from @flowcatalyst/sdk provides code-first flag declarations, definition sync, ETag/304 snapshot caching, delegated client overrides, and the deterministic in-memory evaluator pinned to the shared FlowCatalyst conformance vectors.

import { FlowCatalystClient, flags } from '@flowcatalyst/sdk';
const expressCheckout = flags.boolFlag('checkout.express', false, {
description: 'Enable one-click express checkout',
lifecycle: 'RELEASE',
governance: 'CLIENT_MANAGED',
exposeToClient: true,
});
const routingEngine = flags.enumFlag(
'routing.engine',
['standard', 'fast'] as const,
'standard',
{
description: 'Route calculation engine',
lifecycle: 'EXPERIMENT',
governance: 'OPERATORS_ONLY',
},
);
const ff = new flags.FeatureFlagsClient(client, 'orders', [
expressCheckout,
routingEngine,
]);
// Sync code declarations at start-up or deploy
await ff.syncDefinitions();
// Fetch snapshot (sends If-None-Match on subsequent refreshes; handles 304 Not Modified)
await ff.refresh();
const evalCtx: flags.EvalContext = {
client: 'acme',
principal: 'prn_0HZXEQ5Y8JY5Z',
tier: 'CLIENT',
roles: ['orders:manager'],
attrs: { site: 'west' },
};
const enabled: boolean = ff.bool(evalCtx, expressCheckout);
const engine: 'standard' | 'fast' = ff.enumValue(evalCtx, routingEngine);
const detailed = ff.evaluate(evalCtx, expressCheckout); // { value, reason, ruleId }
const exposed = ff.evaluateClientExposed(evalCtx);
// { revision: number, flags: Record<string, boolean | string> }

Only flags declared with exposeToClient: true are included.

await ff.setClientOverride('checkout.express', 'acme', { value: true }, actingPrincipalId);
await ff.deleteClientOverride('checkout.express', 'acme', actingPrincipalId);

Both methods send X-On-Behalf-Of when actingPrincipalId is provided so the platform records the acting user in its audit log.