Update hivegrid-cloud reference to latest main

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
davidandClaude Fable 5 committed 2026-07-08 16:15:37 +02:00
1 parent e98d38e716
commit 7b21524c86
3781 files changed
+373484 -225607

No files matched your search

@@ -4,12 +4,13 @@ import { TenantUserJoined } from "~/application/enums/tenants/TenantUserJoined";
import { TenantUserType } from "~/application/enums/tenants/TenantUserType";
import { TenantUserStatus } from "~/application/enums/tenants/TenantUserStatus";
import { getAvailableTenantInboundAddress } from "~/utils/services/emailService";
import { getEntitlementPlanStripeId, seedStandardEntitlements, type EntitlementsSeedDiagnosticEvent } from "@toolctrl/db/entitlements-seed.server";
import { runDbSeed, type DbSeedDiagnosticEvent } from "@toolctrl/db/seed.server";
import { entitlementPlanIds, featureKeys, productBlueprintIds, type EntitlementPlanId } from "@toolctrl/entitlements";
import { getEntitlementPlanBillingProviderId, seedStandardEntitlements, type EntitlementsSeedDiagnosticEvent } from "@hivegrid/db/entitlements-seed.server";
import { runDbSeed, type DbSeedDiagnosticEvent } from "@hivegrid/db/seed.server";
import { entitlementPlanIds, featureKeys, productBlueprintIds, type EntitlementPlanId } from "@hivegrid/entitlements";
import { buildCatalogSeedPlan } from "@hivegrid/integrations";
import { seedRolesAndPermissions, type RolesAndPermissionsSeedDiagnosticEvent } from "~/utils/services/rolesAndPermissionsService";
import { db } from "~/utils/db.server";
import { ensureProductCoreCrmEntities } from "~/modules/crm/services/ProductCoreCrmEntities.server";
import { seedShkCustomFieldTemplate } from "~/utils/integrations/crm/customFieldService.server";
import { createScopedLogger } from "~/utils/logger.server";
const seedLogger = createScopedLogger("seed");
@@ -112,10 +113,6 @@ async function seed() {
);
}
if (shouldSeedDemoData) {
await ensureProductCoreCrmEntities({ ensurePermissions: false });
}
// Permissions
await seedRolesAndPermissions({
adminEmail: adminUser.email,
@@ -127,6 +124,10 @@ async function seed() {
diagnostics: logEntitlementsSeedDiagnostic,
});
// R-P5: global App definition table from the code catalog (idempotent by
// unique key; the tenant runtime keeps reading INTEGRATION_CATALOG).
await seedIntegrationCatalog();
if (shouldSeedDemoData) {
await Promise.all(demoCrmTenants.map((tenant) => assignTenantPlan(tenant.slug, tenant.planId)));
await Promise.all(demoCrmTenants.map((tenant) => seedDemoProductCoreTenant(tenant.slug, tenant.planId, demoUsers)));
@@ -135,6 +136,18 @@ async function seed() {
});
}
/** Upsert the code catalog into the global `App` table (R-P5, no RLS/tenant). */
async function seedIntegrationCatalog() {
const plan = buildCatalogSeedPlan();
for (const entry of plan) {
const { key, connectionSchema, ...rest } = entry;
// Prisma's InputJsonValue rejects readonly structures — deep-clone to plain.
const data = { ...rest, connectionSchema: JSON.parse(JSON.stringify(connectionSchema)) as object };
await db.app.upsert({ where: { key }, create: { key, ...data }, update: data });
}
seedLogger.info({ op: "seed.integrationCatalog", count: plan.length }, "Upserted integration catalog into App table");
}
function shouldSeedCrmDemoData() {
if (process.env.SEED_DEMO_DATA !== "true") {
return false;
@@ -318,7 +331,7 @@ async function ensureTenantSubscription(tenantId: string) {
return db.tenantSubscription.create({
data: {
tenantId,
stripeCustomerId: "",
billingProviderCustomerId: "",
},
});
}
@@ -366,9 +379,12 @@ async function assignTenantPlan(tenantSlug: string, planId: EntitlementPlanId) {
if (!tenant?.subscription) {
return;
}
if (tenant.subscription.lastPaymentExternalId?.startsWith("hgco_") || tenant.subscription.lastInvoiceExternalId?.startsWith("hgco_")) {
return;
}
const product = await db.subscriptionProduct.findFirst({
where: { stripeId: getEntitlementPlanStripeId({ id: planId }) },
where: { billingProviderId: getEntitlementPlanBillingProviderId({ id: planId }) },
select: { id: true },
});
if (!product) {
@@ -384,7 +400,7 @@ async function assignTenantPlan(tenantSlug: string, planId: EntitlementPlanId) {
data: {
tenantSubscriptionId: tenant.subscription.id,
subscriptionProductId: product.id,
stripeSubscriptionId: null,
billingProviderSubscriptionId: null,
quantity: 1,
fromCheckoutSessionId: null,
customEntitlementPlanId: planId,
@@ -406,6 +422,11 @@ async function seedDemoProductCoreTenant(tenantSlug: string, planId: Entitlement
seedDemoTenantRoles(tenant.id, demoUsers),
seedDemoTenantKnowledgeBase(tenant.id, tenant.slug, tenant.name, planId),
seedDemoSupportTickets(tenant.id, tenant.slug, planId, demoUsers[0]?.id),
// R-P6 (DoD 6): seed the tenant-scoped SHK custom-field template as demo
// data (`isDemoData = true`) instead of the legacy entity-builder CRM
// entities. The template is intentionally empty until the Geerkens
// workshop (E3), so this is currently an idempotent no-op.
seedShkCustomFieldTemplate({ tenantId: tenant.id }),
]);
}