import { featureKeys, type FeatureKey } from "./features.js"; export const productBlueprintIds = Object.freeze({ crmSaas: "crm-saas", } as const); export type ProductBlueprintId = (typeof productBlueprintIds)[keyof typeof productBlueprintIds]; export interface ProductBlueprintFeatureDefinition { readonly featureKey: FeatureKey; readonly defaultEnabled: boolean; readonly tenantToggleable: boolean; readonly requiresTenantRolePermission?: string; } export interface ProductBlueprintDefinition { readonly id: ProductBlueprintId; readonly version: string; readonly title: string; readonly description: string; readonly defaultShowcase: boolean; readonly features: readonly ProductBlueprintFeatureDefinition[]; } function blueprintFeature( featureKey: FeatureKey, defaultEnabled: boolean, tenantToggleable: boolean, requiresTenantRolePermission?: string ): ProductBlueprintFeatureDefinition { return Object.freeze({ featureKey, defaultEnabled, tenantToggleable, ...(requiresTenantRolePermission ? { requiresTenantRolePermission } : {}), }); } export const productBlueprints = Object.freeze([ Object.freeze({ id: productBlueprintIds.crmSaas, version: "2026.05.15", title: "CRM SaaS", description: "Default CRM SaaS product core with support, knowledge base, marketing, billing, search, automation, API, and optional tenant MCP.", defaultShowcase: true, features: Object.freeze([ blueprintFeature(featureKeys.dashboard, true, false, "dashboard.read"), blueprintFeature(featureKeys.crmBasic, true, false, "app.dashboard.view"), blueprintFeature(featureKeys.leads, true, true, "leads.read_own"), blueprintFeature(featureKeys.projects, true, true, "projects.read_own"), blueprintFeature(featureKeys.files, true, true, "files.read_own"), blueprintFeature(featureKeys.tasks, true, true, "tasks.read_own"), blueprintFeature(featureKeys.hr, true, true, "hr.read_own"), blueprintFeature(featureKeys.integrations, true, true, "integrations.read"), blueprintFeature(featureKeys.booking, true, true, "bookings.read_own"), blueprintFeature(featureKeys.forms, true, true, "forms.basic"), blueprintFeature(featureKeys.signature, true, true, "signature.read"), blueprintFeature(featureKeys.billing, true, true, "app.settings.subscription.view"), blueprintFeature(featureKeys.search, true, true, "search.use"), blueprintFeature(featureKeys.automation, true, true, "automation.read"), blueprintFeature(featureKeys.supportTickets, true, true, "app.dashboard.view"), blueprintFeature(featureKeys.knowledgeBaseRead, true, true, "app.dashboard.view"), blueprintFeature(featureKeys.knowledgeBaseTenant, true, true, "app.settings.roles.set"), blueprintFeature(featureKeys.emailMarketing, true, true, "app.settings.roles.set"), blueprintFeature(featureKeys.emailInbox, true, true, "email.read_own"), blueprintFeature(featureKeys.importedLists, true, true, "app.settings.roles.set"), blueprintFeature(featureKeys.crmBasedLists, true, true, "app.settings.roles.set"), blueprintFeature(featureKeys.onboarding, true, true, "app.settings.roles.set"), blueprintFeature(featureKeys.api, true, true, "app.settings.apiKeys.create"), blueprintFeature(featureKeys.workflowEngine, true, true, "app.settings.roles.set"), blueprintFeature(featureKeys.mcp, true, true, "app.settings.roles.set"), blueprintFeature(featureKeys.advancedBuilder, true, true, "app.settings.roles.set"), blueprintFeature(featureKeys.importExport, true, true, "app.dashboard.view"), blueprintFeature(featureKeys.credits, true, false, "app.dashboard.view"), blueprintFeature(featureKeys.users, true, false, "app.settings.members.view"), ]), }), ] as const satisfies readonly ProductBlueprintDefinition[]); const blueprintById = new Map(productBlueprints.map((blueprint) => [blueprint.id, blueprint])); export function getProductBlueprint(blueprintId: ProductBlueprintId): ProductBlueprintDefinition; export function getProductBlueprint(blueprintId: string): ProductBlueprintDefinition | undefined; export function getProductBlueprint(blueprintId: string): ProductBlueprintDefinition | undefined { return blueprintById.get(blueprintId as ProductBlueprintId); } export function getDefaultProductBlueprint(): ProductBlueprintDefinition { const blueprint = productBlueprints.find((item) => item.defaultShowcase); if (!blueprint) { throw new Error("No default product blueprint is configured."); } return blueprint; }