Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

fix(common): restore narrow Feature type (#50850)

Alaister Younga47397d5feeb
diff --git a/apps/studio/hooks/misc/useIsFeatureEnabled.ts b/apps/studio/hooks/misc/useIsFeatureEnabled.ts
index d50b7a7c4d1..8813e14ae7d 100644
--- a/apps/studio/hooks/misc/useIsFeatureEnabled.ts
+++ b/apps/studio/hooks/misc/useIsFeatureEnabled.ts
@@ -13,8 +13,8 @@ function useIsFeatureEnabled<T extends Feature | Feature[]>(features: T) {
const disabledFeatures = [
...(profile?.disabled_features ?? []),
- ...((override?.disabled_features ?? []) as Feature[]),
- ]
+ ...(override?.disabled_features ?? []),
+ ] as Feature[]
// This code branch is to make the type checker happy, it's intentionally
// the same as the isFeatureEnabled function call below.
diff --git a/packages/common/enabled-features/index.ts b/packages/common/enabled-features/index.ts
index 529337c386a..812a99dc5d7 100644
--- a/packages/common/enabled-features/index.ts
+++ b/packages/common/enabled-features/index.ts
@@ -1,14 +1,27 @@
-import type { components } from 'api-types'
-
import enabledFeaturesRaw from './enabled-features.json' with { type: 'json' }
const enabledFeaturesStaticObj = enabledFeaturesRaw as Omit<typeof enabledFeaturesRaw, '$schema'>
-type Profile = components['schemas']['ProfileResponse_Output']
+// Features the platform can disable per-user via the profile's `disabled_features`.
+// The API types this as `string[]`, so the known values are listed here to keep `Feature` narrow.
+type RuntimeFeature =
+ | 'organizations:create'
+ | 'organizations:delete'
+ | 'organization_members:create'
+ | 'organization_members:delete'
+ | 'projects:create'
+ | 'projects:transfer'
+ | 'project_auth:all'
+ | 'project_storage:all'
+ | 'project_edge_function:all'
+ | 'profile:update'
+ | 'billing:account_data'
+ | 'billing:credits'
+ | 'billing:invoices'
+ | 'billing:payment_methods'
+ | 'realtime:all'
-export type Feature =
- | NonNullable<Profile['disabled_features']>[number]
- | keyof typeof enabledFeaturesStaticObj
+export type Feature = RuntimeFeature | keyof typeof enabledFeaturesStaticObj
const disabledFeaturesStaticArray = Object.entries(enabledFeaturesStaticObj)
.filter(([_, value]) => !value)