/** * Organization version-based feature gating module. */ /** * Organization version constants. * - V1: Legacy organizations (version "1") * - V2: New organizations (version "2") * * Note: The distinction between cloud-prem and hybrid-cloud deployments is * determined by the SUPERBLOCKS_DEPLOYMENT_TYPE environment variable, not the org version. */ export const OrgVersion = { V1: '1', V2: '2' } as const; export type OrgVersionType = (typeof OrgVersion)[keyof typeof OrgVersion]; /** * Features that can be gated by organization version. */ export enum OrgFeature { LegacyAuditLogs = 'LegacyAuditLogs', LegacyObservability = 'LegacyObservability', LegacySourceControl = 'LegacySourceControl', LegacySuperblocksOcr = 'LegacySuperblocksOcr', LegacySuperblocksEmail = 'LegacySuperblocksEmail', LegacyGoogleSheets = 'LegacyGoogleSheets', LegacyExecutionToken = 'LegacyExecutionToken', LegacySecretsManagement = 'LegacySecretsManagement', LegacyStreamingIntegrations = 'LegacyStreamingIntegrations', InternalLegacyEndpoints = 'InternalLegacyEndpoints', Workflows = 'Workflows', ScheduledJobs = 'ScheduledJobs', LegacyApps = 'LegacyApps', PublicApps = 'PublicApps', ReactApps = 'ReactApps', Knowledge = 'Knowledge' } /** * Determines if an organization has access to a specific feature based on its version. * * @param orgVersion - The organization's version ('1' or '2'), or undefined during migration * @param feature - The feature to check access for * @returns true if the organization has access to the feature */ export function orgHasFeature(orgVersion: OrgVersionType | undefined, feature: OrgFeature): boolean { switch (feature) { // V1-only features (legacy organizations) case OrgFeature.LegacyAuditLogs: case OrgFeature.LegacyObservability: case OrgFeature.LegacySourceControl: case OrgFeature.LegacySuperblocksOcr: case OrgFeature.LegacySuperblocksEmail: case OrgFeature.LegacyGoogleSheets: case OrgFeature.LegacyExecutionToken: case OrgFeature.LegacySecretsManagement: case OrgFeature.LegacyStreamingIntegrations: case OrgFeature.InternalLegacyEndpoints: case OrgFeature.Workflows: case OrgFeature.ScheduledJobs: case OrgFeature.LegacyApps: case OrgFeature.PublicApps: return orgVersion === OrgVersion.V1; // React apps are always available in V2 orgs. // V1 orgs can also access React apps, but that's controlled by feature flags // checked separately - this function only handles org-version gating. case OrgFeature.ReactApps: case OrgFeature.Knowledge: return orgVersion === OrgVersion.V2; default: return false; } }