export const featureKeys = { dashboard: "dashboard", crmBasic: "crm-basic", leads: "leads", projects: "projects", files: "files", tasks: "tasks", hr: "hr", integrations: "integrations", kwpIntegration: "kwp_integration", telephony: "telephony", chat: "chat", booking: "booking", forms: "forms", signature: "signature", billing: "billing", customerPortal: "customer_portal", customerPortalCustomDomain: "customer_portal_custom_domain", search: "search", automation: "automation", supportTickets: "support-tickets", knowledgeBaseRead: "knowledge-base-read", knowledgeBaseTenant: "knowledge-base-tenant", users: "users", emailMarketing: "email-marketing", emailInbox: "email-inbox", importedLists: "imported-lists", crmBasedLists: "crm-based-lists", onboarding: "onboarding", api: "api", workflowEngine: "workflow-engine", mcp: "mcp", advancedBuilder: "advanced-builder", importExport: "import-export", rateLimitPerMinute: "rate-limit-per-minute", rateLimitPerSecond: "rate-limit-per-second", prioritySupport: "priority-support", credits: "ai-credits", privateGenerations: "private-generations", } as const; export type FeatureKey = (typeof featureKeys)[keyof typeof featureKeys]; export type FeatureCategory = "access" | "usage" | "support" | "generation" | "crm" | "marketing" | "automation" | "customization"; export type FeatureLimitType = "not-included" | "included" | "monthly" | "max" | "unlimited"; export interface FeatureGateRegistryItem { readonly key: FeatureKey; readonly title: string; readonly category: FeatureCategory; readonly supportedLimitTypes: readonly FeatureLimitType[]; readonly defaultOrder: number; readonly description: string; } const accessLimitTypes = ["not-included", "included", "unlimited"] as const satisfies readonly FeatureLimitType[]; const quotaLimitTypes = ["not-included", "monthly", "max", "unlimited"] as const satisfies readonly FeatureLimitType[]; const rateLimitTypes = ["not-included", "max", "unlimited"] as const satisfies readonly FeatureLimitType[]; export const featureGateRegistry = Object.freeze([ Object.freeze({ key: featureKeys.dashboard, title: "Dashboard", category: "access", supportedLimitTypes: accessLimitTypes, defaultOrder: 4, description: "Controls access to the tenant dashboard, role layouts, and dashboard widget catalog.", }), Object.freeze({ key: featureKeys.crmBasic, title: "CRM basics", category: "crm", supportedLimitTypes: accessLimitTypes, defaultOrder: 5, description: "Controls access to the default CRM account, contact, and opportunity surfaces.", }), Object.freeze({ key: featureKeys.leads, title: "Lead inbox", category: "crm", supportedLimitTypes: accessLimitTypes, defaultOrder: 6, description: "Controls access to the lead intake, triage, anti-spam, and lead-to-project preparation surfaces.", }), Object.freeze({ key: featureKeys.projects, title: "Projects and pipelines", category: "crm", supportedLimitTypes: accessLimitTypes, defaultOrder: 6.5, description: "Controls access to the project core, pipeline engine, project CRUD, and sales pipeline surfaces.", }), Object.freeze({ key: featureKeys.supportTickets, title: "Support tickets", category: "support", supportedLimitTypes: quotaLimitTypes, defaultOrder: 7, description: "Controls support ticket creation and ticket volume.", }), Object.freeze({ key: featureKeys.knowledgeBaseRead, title: "Knowledge base read", category: "support", supportedLimitTypes: accessLimitTypes, defaultOrder: 8, description: "Controls read access to the global and product knowledge bases.", }), Object.freeze({ key: featureKeys.knowledgeBaseTenant, title: "Tenant knowledge base", category: "support", supportedLimitTypes: accessLimitTypes, defaultOrder: 9, description: "Controls tenant-owned knowledge base authoring and publishing.", }), Object.freeze({ key: featureKeys.files, title: "Files", category: "access", supportedLimitTypes: accessLimitTypes, defaultOrder: 10, description: "Controls access to the central file storage (chunked upload, preview, sharing).", }), Object.freeze({ key: featureKeys.users, title: "Users", category: "access", supportedLimitTypes: quotaLimitTypes, defaultOrder: 11, description: "Controls the number of workspace members available to an account.", }), Object.freeze({ key: featureKeys.tasks, title: "Tasks", category: "access", supportedLimitTypes: accessLimitTypes, defaultOrder: 12, description: "Controls access to the cross-cutting task module (assignment, reminders, entity links).", }), Object.freeze({ key: featureKeys.hr, title: "HR hub", category: "access", supportedLimitTypes: accessLimitTypes, defaultOrder: 13, description: "Controls access to the HR hub (employee master data, locations, documents, encrypted password safe).", }), Object.freeze({ key: featureKeys.integrations, title: "Integrations", category: "automation", supportedLimitTypes: accessLimitTypes, defaultOrder: 14, description: "Controls the Apps-Engine integrations framework (OAuth/API-key connections, sync, health).", }), Object.freeze({ key: featureKeys.kwpIntegration, title: "KWP integration", category: "automation", supportedLimitTypes: accessLimitTypes, defaultOrder: 14.25, description: "Controls access to the KWP pilot connector, its OAuth setup, token lifecycle, and read-only health checks.", }), Object.freeze({ key: featureKeys.telephony, title: "Telephony", category: "access", supportedLimitTypes: accessLimitTypes, defaultOrder: 14.5, description: "Controls connected calling, inbound call handling, call history, and tenant telephony settings.", }), Object.freeze({ key: featureKeys.chat, title: "Team chat", category: "access", supportedLimitTypes: accessLimitTypes, defaultOrder: 14.75, description: "Controls access to tenant-scoped realtime channels, direct messages, threads, and chat administration.", }), Object.freeze({ key: featureKeys.booking, title: "Booking", category: "access", supportedLimitTypes: accessLimitTypes, defaultOrder: 15, description: "Controls access to the Booking module (public booking pages, availability, appointment lifecycle).", }), Object.freeze({ key: featureKeys.forms, title: "Forms", category: "access", supportedLimitTypes: accessLimitTypes, defaultOrder: 16, description: "Controls access to the form builder, public form publishing, submissions, and post-submit actions.", }), Object.freeze({ key: featureKeys.signature, title: "Signature", category: "access", supportedLimitTypes: accessLimitTypes, defaultOrder: 17, description: "Controls access to the signature module (self-hosted SES default and optional provider adapters).", }), Object.freeze({ key: featureKeys.billing, title: "Billing", category: "access", supportedLimitTypes: accessLimitTypes, defaultOrder: 17.5, description: "Controls access to subscription, usage, billing recovery, and tenant-facing billing settings.", }), Object.freeze({ key: featureKeys.customerPortal, title: "Project portal", category: "access", supportedLimitTypes: accessLimitTypes, defaultOrder: 17.6, description: "Controls access to the separate project portal surface.", }), Object.freeze({ key: featureKeys.customerPortalCustomDomain, title: "Project portal custom domain", category: "customization", supportedLimitTypes: accessLimitTypes, defaultOrder: 17.7, description: "Controls whether a verified custom hostname may serve the project portal.", }), Object.freeze({ key: featureKeys.search, title: "Global search", category: "access", supportedLimitTypes: accessLimitTypes, defaultOrder: 18, description: "Controls access to permission-aware global search and recent searches.", }), Object.freeze({ key: featureKeys.automation, title: "Automation", category: "automation", supportedLimitTypes: quotaLimitTypes, defaultOrder: 19, description: "Controls the typed automation engine, trigger/action registry, guards, templates, and execution volume.", }), Object.freeze({ key: featureKeys.api, title: "API Access", category: "access", supportedLimitTypes: accessLimitTypes, defaultOrder: 20, description: "Controls whether programmatic API access is available.", }), Object.freeze({ key: featureKeys.emailMarketing, title: "Email marketing", category: "marketing", supportedLimitTypes: quotaLimitTypes, defaultOrder: 21, description: "Controls email campaign creation and monthly campaign sends.", }), Object.freeze({ key: featureKeys.importedLists, title: "Imported lists", category: "marketing", supportedLimitTypes: accessLimitTypes, defaultOrder: 22, description: "Controls whether imported audience lists can be used.", }), Object.freeze({ key: featureKeys.crmBasedLists, title: "CRM based lists", category: "marketing", supportedLimitTypes: accessLimitTypes, defaultOrder: 23, description: "Controls whether CRM segments can be used as audiences.", }), Object.freeze({ key: featureKeys.onboarding, title: "Onboarding", category: "access", supportedLimitTypes: accessLimitTypes, defaultOrder: 24, description: "Controls tenant onboarding builder access.", }), Object.freeze({ key: featureKeys.workflowEngine, title: "Workflow engine", category: "automation", supportedLimitTypes: quotaLimitTypes, defaultOrder: 25, description: "Controls tenant workflow builder and workflow run volume.", }), Object.freeze({ key: featureKeys.mcp, title: "Tenant MCP", category: "automation", supportedLimitTypes: accessLimitTypes, defaultOrder: 26, description: "Controls tenant MCP access when the active product blueprint enables MCP.", }), Object.freeze({ key: featureKeys.advancedBuilder, title: "Advanced builder", category: "customization", supportedLimitTypes: accessLimitTypes, defaultOrder: 27, description: "Controls advanced entity, UI, and product customization tools.", }), Object.freeze({ key: featureKeys.importExport, title: "Import and export", category: "usage", supportedLimitTypes: quotaLimitTypes, defaultOrder: 28, description: "Controls import/export heavy workflows and monthly operation volume.", }), Object.freeze({ key: featureKeys.emailInbox, title: "Email inbox", category: "access", supportedLimitTypes: accessLimitTypes, defaultOrder: 29, description: "Controls access to the personal mailbox sync (Gmail/Microsoft), inbox surfaces, and mailbox sending.", }), Object.freeze({ key: featureKeys.rateLimitPerMinute, title: "Rate limit per minute", category: "usage", supportedLimitTypes: rateLimitTypes, defaultOrder: 30, description: "Controls the maximum permitted requests in a one minute window.", }), Object.freeze({ key: featureKeys.rateLimitPerSecond, title: "Rate limit per second", category: "usage", supportedLimitTypes: rateLimitTypes, defaultOrder: 40, description: "Controls the maximum permitted requests in a one second window.", }), Object.freeze({ key: featureKeys.prioritySupport, title: "Priority support", category: "support", supportedLimitTypes: accessLimitTypes, defaultOrder: 50, description: "Controls whether priority support handling is available.", }), Object.freeze({ key: featureKeys.credits, title: "Credits", category: "usage", supportedLimitTypes: quotaLimitTypes, defaultOrder: 60, description: "Controls the amount of metered product credits available in a billing period.", }), Object.freeze({ key: featureKeys.privateGenerations, title: "Private generations", category: "generation", supportedLimitTypes: accessLimitTypes, defaultOrder: 70, description: "Controls whether generated outputs are handled with private visibility.", }), ] as const satisfies readonly FeatureGateRegistryItem[]); const featureGateRegistryByKey = new Map(featureGateRegistry.map((feature) => [feature.key, feature])); export function isFeatureKey(value: string): value is FeatureKey { return featureGateRegistryByKey.has(value as FeatureKey); } export function getFeatureGate(featureKey: FeatureKey): FeatureGateRegistryItem; export function getFeatureGate(featureKey: string): FeatureGateRegistryItem | undefined; export function getFeatureGate(featureKey: string): FeatureGateRegistryItem | undefined { return isFeatureKey(featureKey) ? featureGateRegistryByKey.get(featureKey) : undefined; } export function assertKnownFeatureKey(value: string): asserts value is FeatureKey { if (!isFeatureKey(value)) { throw new RangeError(`Unknown feature key: ${value}`); } }