Feature Flags

sdk.flags provides server-side feature flag evaluation. Flags are defined in the cPod platform console and evaluated in your app at runtime with optional user, tenant, or entity context. The platform resolves the flag value — your app receives true, false, or a string/number variant.

No restarts required. Flag changes propagate within seconds.


Evaluate a Flag

import { CpodClient } from '@cpod/sdk'
const sdk = CpodClient.fromEnv()
 
// Simple boolean flag
const enabled = await sdk.flags.evaluate('new-dashboard')
// → true | false
 
if (enabled) {
  // render new dashboard
}

Evaluate with User Context

// Percentage rollout, beta opt-in, or per-user override
const value = await sdk.flags.evaluate('bulk-export', {
  userId: 'per-alice123',
  attributes: {
    plan: 'enterprise',
    region: 'us-east',
    betaOptIn: true,
  },
})
// → true (user is in rollout group)
 
// Multivariate flag — returns a variant string
const variant = await sdk.flags.evaluate('onboarding-flow', {
  userId: 'per-alice123',
})
// → "variant-b"
 
if (variant === 'variant-b') {
  // show new onboarding
}

Evaluate Multiple Flags

// Evaluate all flags for a user in one round trip
const all = await sdk.flags.evaluateAll({
  userId: 'per-alice123',
  attributes: { plan: 'enterprise' },
})
 
console.log(all['new-dashboard'])  // → true
console.log(all['bulk-export'])    // → false
console.log(all['onboarding-flow']) // → "variant-b"

Flag values are not cached client-side by default. Each evaluate call is a lightweight HTTP request. For high-frequency evaluation (e.g. per-request middleware), use evaluateAll once per request and pass the result through your context.