Amba
SDKsFeatures

Remote config

Fetch the project's key/value bundle for runtime configuration. Version-stamped; the SDK keeps no cache of its own.

config.fetch() returns the project's key/value bundle. Use it for values that the app reads on launch and needs to be able to change without a redeploy — pricing, copy, feature thresholds, default selections.

Config bundles hold strings, numbers, and structured config; feature flags hold boolean gates. One bundle per project. A signed-in user's bundle has each key's segment and percentage conditions applied; before sign-in it holds each key's default value.

Quick start

import { Amba } from '@layers/amba-web';
 
const bundle = await Amba.config.fetch();
console.log(bundle.version); // e.g. 'v42'
console.log(bundle.values); // { onboarding_steps: 3, hero_copy: '...', ... }

Operations

fetch()

Returns a single bundle:

{
  version: 'v42',       // version stamp set in the console
  values: {
    hero_copy: 'Welcome to amba',
    onboarding_steps: 3,
    pricing: {
      pro_monthly: 999,
      pro_annual: 9999,
    },
  },
}

The SDK keeps no cache of its own. The response carries Cache-Control: private, max-age=300, so in a browser a repeat config.fetch() within five minutes can return the browser's cached copy. Hold the result yourself when you read it often, as in the boot-time pattern below.

Patterns

Boot-time config

For values you need at app launch (splash screen copy, theme, etc.), fetch synchronously on boot and hold the result in memory:

let configCache: Awaited<ReturnType<typeof Amba.config.fetch>> | null = null;
 
export async function bootConfig(): Promise<void> {
  configCache = await Amba.config.fetch();
}
 
export function getConfig<T = unknown>(key: string, fallback: T): T {
  return ((configCache?.values as Record<string, unknown>)?.[key] as T) ?? fallback;
}

Per-flag vs. config

Use feature flags for on/off decisions and A/B variant assignment. Use config for values like copy, pricing, thresholds:

// Flag: "is the new checkout turned on?"
const newCheckout = useFlag('new_checkout')?.enabled ?? false;
 
// Config: "what discount do they see today?"
const config = await Amba.config.fetch();
const discount = config.values?.checkout_discount ?? 0;

Config evaluates each key's conditions for the signed-in user (defaults before sign-in), and flags return the same project-wide set of enabled flags to every user. flags.fetch() returns an array of flag assignments; config.fetch() returns a single typed bundle.

Refresh

Call config.fetch() again whenever you want current values (for example on app foreground or after a known server-side update). In a browser, a call within five minutes of the last one can return the browser's cached copy.

Caching

The SDK keeps no cache of its own. The response carries Cache-Control: private, max-age=300, so in a browser a repeat config.fetch() within five minutes can return the browser's cached copy.

Reference

On this page