Config as Code
Declare your service's flags in foredeck.yaml and sync them from CI or your terminal (PRD-16)
Declare your service's flags next to the code that reads them, and sync them from CI or your terminal. Init → edit → sync → evaluate in under 15 minutes:
# 1. init — scaffold foredeck.yaml from your service's current server state
npx foredeck init --service checkout-api \
--api-url http://localhost:8000 --sdk-key fd_server_acme
# 2. edit — declare a new flag in foredeck.yaml (schema-validated in your editor
# via spec/foredeck-config.schema.json)
# 3. sync — review the plan, then apply
npx foredeck sync --dry-run # Terraform-style plan; exits 2 if changes pending (CI gate)
npx foredeck sync # create/update the declared flags on the server// 4. evaluate — the client stamps service/env from the file and can evaluate
// from the file's defaults before the first ruleset fetch
import { createClient } from '@foredeck/sdk-js/node';
const foredeck = createClient({
sdkKey: process.env.FOREDECK_SDK_KEY!,
baseUrl: 'http://localhost:8000',
eventsUrl: 'http://localhost:5000',
configFile: './foredeck.yaml', // service/env stamping + defaults bootstrap
});
const { variation } = foredeck.getVariation('new-checkout', userId);Details
- File format —
service(required),env,display_name/description/tags,defaults:(flag → default variation),flags[],experiments[], and anenvs:per-environment overlay map (flags merge bykey, experiments byname). JSON Schema ships atspec/foredeck-config.schema.json. - Ownership & drift — resources created/adopted by
syncaremanaged_by: config; editing them in the UI flips them to drifted.syncnever overwrites drifted resources:--accept-remoteprints file blocks of the server state (UI change wins until reconciled),--force-localmakes the file win. Adoption of UI-created resources requires--adoptor per-resourcemanaged: true— sync never silently seizes UI resources. - Full-state updates — updates always send the complete resolved declared state (the server's
PUTresets omitted fields), plus a canonicalconfig_hashused for drift detection. - CI —
foredeck sync --dry-runexits2when changes are pending;--output jsonemits a machine-readable plan.foredeck validatechecks the file against the schema. - Undeclared-flag validation — with a config loaded, evaluating a flag key that the file doesn't declare warns once per key (
onUndeclaredFlag: 'warn' | 'error' | 'ignore');client.assertDeclared(key)for hard checks. - Browser/edge builds stay node-free: load the file yourself (or bundle it) and pass it as
configinstead ofconfigFile.