Files
HiveGrid-Wireframes/03 Quellen und Referenzen/hivegrid-cloud/prisma/tenant-scope-manifest.mjs
T

463 lines
12 KiB
JavaScript

/**
* Explicit tenant-boundary classification for every Prisma model.
*
* This manifest is intentionally independent from snapshot/delete registries:
* those lifecycle registries only understand a direct `tenantId` column, while
* this file also captures nullable/global hybrids, FK-derived children, the
* Tenant root, platform-admin data, and deliberately global data.
*
* Scope meanings:
* - tenant-required: every row belongs to exactly one tenant;
* - tenant-or-global: nullable ownership requires mixed policy semantics;
* - derived-child: ownership is inherited through an owning FK path;
* - tenant-root: the Tenant row is constrained by its own id;
* - global-catalog/global-shared: deliberately cross-tenant data;
* - platform-admin: isolated operator data, never a tenant-runtime bypass.
*/
export const TENANT_SCOPE_GROUPS = Object.freeze({
"tenant-required": Object.freeze([
"WorkspaceAuthProvider",
"TenantUser",
"TenantUserInvitation",
"TenantIpAddress",
"Activity",
"DataConnection",
"AppSyncRun",
"AppSyncRunLog",
"AppSyncItem",
"AppEntityBinding",
"KwpApiContractSnapshot",
"KwpCapabilityState",
"KwpErrorReport",
"KwpProjectRouting",
"KwpProjectCatalogState",
"KwpProjectCatalogItem",
"KwpMaterialPosition",
"ProjektMitglied",
"ProjektTermin",
"Rechnung",
"ProjektChecklist",
"ProjektChecklistItem",
"AuftragPipelineStageConfig",
"AcceptanceFormTemplate",
"ProjectTemplate",
"ScheduleEntry",
"ScheduleConflict",
"AbnahmeProtokoll",
"AbnahmeSignatur",
"OfflineSyncMutation",
"AutomationRule",
"AutomationRuleStep",
"AutomationExecution",
"AutomationStepExecution",
"AutomationCredential",
"AutomationTriggerMeter",
"BookingPage",
"BookingPageProvider",
"AvailabilityRule",
"AvailabilityException",
"Appointment",
"CalendarConnection",
"CalendarEvent",
"CalendarEventMapping",
"CalendarSyncCursor",
"CalendarWebhookEvent",
"CalendarConflict",
"CollabDoc",
"ApiKey",
"Kontakt",
"KontaktRelation",
"KontaktEmail",
"KontaktTelefon",
"Adresse",
"CustomFieldDefinition",
"CustomFieldValue",
"Tag",
"TagAssignment",
"TenantEncryptionKey",
"Dashboard",
"DashboardLayout",
"WidgetInstance",
"EmailIntegrationMailbox",
"EmailIntegrationMessage",
"EmailIntegrationSyncCursor",
"EmailIntegrationWebhookEvent",
"TelephonyConnection",
"TelephonyUserBinding",
"TelephonyCallSession",
"TelephonyWebhookEvent",
"TeamChat",
"TeamChatGroupSource",
"TeamChatMessage",
"TeamChatMember",
"TeamChatThread",
"TeamChatPinnedMessage",
"TeamChatReaction",
"TeamChatRead",
"TeamChatEvent",
"TenantInboundAddress",
"TenantSendingDomain",
"EmailSuppressionList",
"EmailTemplate",
"RecipientSegment",
"SegmentSnapshotMember",
"CampaignVariant",
"KontaktMarketingConsent",
"Unsubscribe",
"EntityLink",
"File",
"FileEntityLink",
"FileUpload",
"FileUploadChunk",
"Form",
"FormSubmission",
"FormField",
"FormFile",
"FormAction",
"FormActionLog",
"GdprExportJob",
"TenantDeletionRequest",
"AvvAcceptance",
"HrEmployeeProfile",
"HrLocation",
"HrEmployeeDocument",
"HrResource",
"HrQuickLink",
"EmployeePasswordSafeVault",
"EmployeePasswordSafeEntry",
"EmployeePasswordSafeAccess",
"EmployeeVacationRequest",
"EmployeeSickLeaveReport",
"HrAnnouncement",
"HrAnnouncementRead",
"HrAnnouncementReaction",
"HrAnnouncementComment",
"EmployeePayslip",
"EmployeeUploadReminder",
"EmployeeUploadReminderDispatch",
"HrRequestTemplate",
"HrRequest",
"HrSurvey",
"HrSurveyItem",
"HrSurveySubmission",
"ImportJob",
"InboxLead",
"LeadSource",
"LeadAntiSpamConfig",
"McpOAuthAuthorizationCode",
"McpOAuthAccessToken",
"McpOAuthRefreshToken",
"UserNotificationPreference",
"OnboardingDemoProvisioning",
"Plugin",
"TenantPluginCapabilityGrant",
"PluginInvocation",
"PluginCapabilityUse",
"Portal",
"PortalUser",
"PortalSession",
"PortalToken",
"PortalProjectAccess",
"PortalSubcontractorAccess",
"PortalStageVisibility",
"PortalProjectDocument",
"PortalEmailTemplate",
"PortalConfiguration",
"PortalDocumentAutoReleaseRule",
"PortalNotificationPreference",
"PortalUpload",
"PortalComplaint",
"PortalActivityRoutingRule",
"PortalServiceInboxItem",
"PortalDeletionRequest",
"PortalGdprExportJob",
"PortalDomainHostnameClaim",
"PortalCustomDomain",
"HiveNumberSeq",
"Pipeline",
"PipelineStage",
"PipelineAccess",
"PipelineAccessRequest",
"PipelineFieldConfig",
"PipelineFieldGroup",
"PipelineFieldVisibility",
"PipelineHandover",
"PipelineHandoverItem",
"LostReason",
"Projekt",
"ProjektNotiz",
"ProjektStageChange",
"PipelineAggregateSnapshot",
"ProjektKontakt",
"ProjektAdressDetail",
"PublicIncomingWebhookEndpoint",
"PublicWebhookIngestionLog",
"PublicWebhookSubscription",
"PublicWebhookDeliveryLog",
"ExportJob",
"SearchIndexEntry",
"RecentSearch",
"SignatureProviderConnection",
"ProjektSignatureDocument",
"ProjektSignatureSigner",
"SignatureEvent",
"Site",
"TenantSubscription",
"TenantSubscriptionUsageRecord",
"TenantProductAcquisition",
"TenantProductConfiguration",
"TenantFeatureOverride",
"CheckoutSessionStatus",
"Credit",
"Task",
"TaskWatcher",
]),
"tenant-or-global": Object.freeze([
"AuditChainCheckpoint",
"AuditChainHead",
"AuditChainCheckpointHead",
"IdempotencyKey",
"AutomationTemplate",
"Log",
"AuditEvent",
"ApiKeyLog",
"Event",
"MetricLog",
"Widget",
"EmailSender",
"Campaign",
"OutboundEmail",
"EmailSequence",
"EmailSequenceRun",
"FeatureFlag",
"KnowledgeBase",
"NotificationDelivery",
"DeviceToken",
"OnboardingSession",
"OutboxEvent",
"Role",
"UserRole",
"Group",
"Workflow",
"WorkflowExecution",
"WorkflowVariable",
"WorkflowCredential",
]),
"derived-child": Object.freeze([
"AnalyticsUniqueVisitor",
"AnalyticsPageView",
"AnalyticsEvent",
"EventWebhookAttempt",
"Email",
"EmailRead",
"EmailCc",
"EmailAttachment",
"OutboundEmailOpen",
"OutboundEmailClick",
"EmailSequenceStepDelivery",
"FeatureFlagFilter",
"FeatureFlagAudit",
"KnowledgeBaseCategory",
"KnowledgeBaseCategorySection",
"KnowledgeBaseArticle",
"KnowledgeBaseRelatedArticle",
"KnowledgeBaseViews",
"KnowledgeBaseArticleViews",
"KnowledgeBaseArticleUpvotes",
"KnowledgeBaseArticleDownvotes",
"OnboardingSessionAction",
"OnboardingSessionFilterMatch",
"OnboardingSessionStep",
"RolePermission",
"GroupUser",
"PluginUserConfig",
"PortalPage",
"TenantSubscriptionProduct",
"TenantSubscriptionProductPrice",
"WorkflowBlock",
"WorkflowBlockConditionGroup",
"WorkflowBlockCondition",
"WorkflowBlockToBlock",
"WorkflowInputExample",
"WorkflowBlockExecution",
]),
"tenant-root": Object.freeze(["Tenant"]),
"global-catalog": Object.freeze([
"App",
"Subprocessor",
"Onboarding",
"OnboardingFilter",
"OnboardingStep",
"Permission",
"SubscriptionProduct",
"SubscriptionPrice",
"SubscriptionUsageBasedPrice",
"SubscriptionUsageBasedTier",
"SubscriptionFeature",
]),
"global-shared": Object.freeze([
"User",
"MagicLinkToken",
"Registration",
"Blacklist",
"AnalyticsSettings",
"UserSession",
"TrustedDevice",
"AppConfiguration",
"FileUploadProgress",
"FileChunk",
"FileObject",
"IpAddress",
"IpAddressLog",
"Credential",
"McpOAuthClient",
"BillingWebhookLog",
]),
"platform-admin": Object.freeze([
"AdminUser",
"AdminSession",
"AdminRole",
"AdminPermission",
"AdminRolePermission",
"AdminUserRole",
"AdminDataConnection",
"AdminConnectionCredential",
"AdminCalendarConnection",
"AdminCalendarSyncCursor",
"AdminMeetingType",
"AdminAvailabilityRule",
"AdminAvailabilityOverride",
"AdminBookingPage",
"AdminBooking",
"AdminBookingParticipant",
"AdminBookingAssignment",
"AdminBookingReminder",
"AdminMailbox",
"AdminMailboxSyncCursor",
"AdminMailboxWebhookEvent",
"AdminEmailThread",
"AdminEmailMessage",
"AdminEmailParticipant",
"AdminEmailAttachment",
"AdminEmailEvent",
"AdminEmailLink",
"AdminEmailTemplate",
"AdminEmailSnippet",
"AdminEmailSignature",
"AdminEmailOutboundPolicy",
"AdminScheduledEmail",
"AdminNoReplyReminder",
"AdminBulkEmailRun",
"AdminSendingDomain",
"AdminBccAddress",
"AdminPhoneConnection",
"AdminPhoneNumber",
"AdminTelephonyPolicy",
"AdminCallDisposition",
"AdminCallSession",
"AdminCallParticipant",
"AdminCallEvent",
"AdminCallMatchCandidate",
"AdminCallRecording",
"AdminDialerList",
"AdminDialerEntry",
"AdminOutboundCallRequest",
"AdminFeatureFlagOverride",
"AdminLeadSource",
"AdminLeadSourceCredential",
"AdminLead",
"AdminLeadActivity",
"AdminCompany",
"AdminContact",
"AdminContactChannel",
"AdminPipeline",
"AdminPipelineStage",
"AdminStageRequiredField",
"AdminDealLossReason",
"AdminDeal",
"AdminDealContact",
"AdminDealStageHistory",
"AdminTaskRecurrence",
"AdminTask",
"AdminTag",
"AdminContactTag",
"AdminCustomFieldDefinition",
"AdminCustomFieldValue",
"AdminContactNote",
"AdminImportJob",
"AdminImportRowError",
"AdminExportJob",
"AdminActivity",
"AdminLeadAssignmentRule",
"AdminLeadScoreRule",
"AdminLeadQualification",
"AdminDuplicateCandidate",
"AdminMergeRecord",
"AdminTenantNote",
"ImpersonationAudit",
"Feedback",
"SupportTicket",
"SupportTicketMessage",
"Lead",
"LeadEvent",
"TenantAcquisition",
"MarketingIntegration",
"QueueFailedJob",
]),
});
// Prisma's implicit many-to-many join tables do not appear as models in the
// schema parser, so their database boundary must remain explicit here.
export const TENANT_SCOPED_IMPLICIT_TABLES = Object.freeze([]);
export const GLOBAL_IMPLICIT_TABLES = Object.freeze([]);
const DEFAULT_ENFORCEMENT = Object.freeze({
"tenant-required": "tenant-policy",
"tenant-or-global": "mixed-policy",
"derived-child": "join-policy",
"tenant-root": "root-policy",
"global-catalog": "none",
"global-shared": "none",
"platform-admin": "platform-role",
});
const MODEL_OVERRIDES = Object.freeze({
// AD-1 keeps feature flags outside tenant RLS. Their tenant relationship is
// still explicit so a future policy decision cannot lose the two children.
FeatureFlag: Object.freeze({ enforcement: "none", reason: "AD-1 global feature-flag exception" }),
FeatureFlagFilter: Object.freeze({ enforcement: "none", reason: "Child of the AD-1 feature-flag exception" }),
FeatureFlagAudit: Object.freeze({ enforcement: "none", reason: "Child of the AD-1 feature-flag exception" }),
// A registration is global pre-tenant state and only points at the tenant it
// created after conversion. The Tenant FK must not turn it into tenant data.
Registration: Object.freeze({
tenantParentBoundary: true,
reason: "Global signup state with an optional createdTenant audit link",
}),
});
function buildManifest() {
const manifest = {};
for (const [scope, models] of Object.entries(TENANT_SCOPE_GROUPS)) {
for (const model of models) {
if (manifest[model]) throw new Error(`Duplicate tenant scope classification for ${model}`);
manifest[model] = Object.freeze({
scope,
enforcement: DEFAULT_ENFORCEMENT[scope],
...(MODEL_OVERRIDES[model] ?? {}),
});
}
}
return Object.freeze(manifest);
}
export const TENANT_SCOPE_MANIFEST = buildManifest();