Skip to content

Commit c82faeb

Browse files
improvement(feature-flags): fallback is the env secret key (keyof typeof env), resolved to a boolean
1 parent 4b5adb2 commit c82faeb

3 files changed

Lines changed: 8 additions & 7 deletions

File tree

.claude/commands/add-feature-flag.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ Critically, **none of this is expressible in code** — gating (especially `admi
3737
const FEATURE_FLAGS = {
3838
'<flag-name>': {
3939
description: '<what this gates>',
40-
fallback: () => env.<FLAG_SECRET>,
40+
fallback: '<FLAG_SECRET>',
4141
},
4242
}
4343
```
4444

45-
Add `<FLAG_SECRET>` to `apps/sim/lib/core/config/env.ts` (and the deployment's secret store). Do **not** add org/user/admin defaults here — that gating exists only in AppConfig. Adding the entry makes `<flag-name>` a valid `FeatureFlagName`.
45+
`fallback` is the env/secret key (typed as `keyof typeof env`), so add `<FLAG_SECRET>` to `apps/sim/lib/core/config/env.ts` first (and the deployment's secret store) — it won't typecheck otherwise. Do **not** add org/user/admin defaults here — that gating exists only in AppConfig. Adding the entry makes `<flag-name>` a valid `FeatureFlagName`.
4646

4747
2. **Gate the call site.** Call `isFeatureEnabled` with whatever ids you have — admin status is resolved internally, so callers never pass it:
4848

.cursor/commands/add-feature-flag.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ Critically, **none of this is expressible in code** — gating (especially `admi
3232
const FEATURE_FLAGS = {
3333
'<flag-name>': {
3434
description: '<what this gates>',
35-
fallback: () => env.<FLAG_SECRET>,
35+
fallback: '<FLAG_SECRET>',
3636
},
3737
}
3838
```
3939

40-
Add `<FLAG_SECRET>` to `apps/sim/lib/core/config/env.ts` (and the deployment's secret store). Do **not** add org/user/admin defaults here — that gating exists only in AppConfig. Adding the entry makes `<flag-name>` a valid `FeatureFlagName`.
40+
`fallback` is the env/secret key (typed as `keyof typeof env`), so add `<FLAG_SECRET>` to `apps/sim/lib/core/config/env.ts` first (and the deployment's secret store) — it won't typecheck otherwise. Do **not** add org/user/admin defaults here — that gating exists only in AppConfig. Adding the entry makes `<flag-name>` a valid `FeatureFlagName`.
4141

4242
2. **Gate the call site.** Call `isFeatureEnabled` with whatever ids you have — admin status is resolved internally, so callers never pass it:
4343

apps/sim/lib/core/config/feature-flags.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,15 @@ export interface FeatureFlagContext {
5858
*/
5959
interface FeatureFlagDefinition {
6060
description: string
61-
fallback: () => string | boolean | number | undefined
61+
/** Env/secret key consulted when AppConfig isn't the source of truth. Truthy ⇒ on. */
62+
fallback: keyof typeof env
6263
}
6364

6465
/** The single registry of known flags. To add a flag, add one entry here. */
6566
const FEATURE_FLAGS = {
6667
// 'new-canvas': {
6768
// description: 'New canvas renderer',
68-
// fallback: () => env.NEW_CANVAS_ENABLED,
69+
// fallback: 'NEW_CANVAS_ENABLED',
6970
// },
7071
} satisfies Record<string, FeatureFlagDefinition>
7172

@@ -81,7 +82,7 @@ function fallbackFlags(): FeatureFlagsConfig {
8182
for (const [name, def] of Object.entries(FEATURE_FLAGS) as Array<
8283
[string, FeatureFlagDefinition]
8384
>) {
84-
flags[name] = { enabled: isTruthy(def.fallback()) }
85+
flags[name] = { enabled: isTruthy(env[def.fallback]) }
8586
}
8687
return { flags }
8788
}

0 commit comments

Comments
 (0)