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

@@ -16,7 +16,7 @@ const dbMock = {
id: `tenant-${where.slug}`,
slug: where.slug,
name: where.slug,
...(include ? { subscription: { id: `subscription-${where.slug}`, products: [] } } : {}),
...(include ? { subscription: { id: `subscription-${where.slug}`, lastInvoiceExternalId: null, lastPaymentExternalId: null, products: [] } } : {}),
})),
create: vi.fn(),
update: vi.fn(),
@@ -34,7 +34,7 @@ const dbMock = {
create: vi.fn(),
},
subscriptionProduct: {
findFirst: vi.fn(async ({ where }: { where: { stripeId: string } }) => ({ id: `product-${where.stripeId}` })),
findFirst: vi.fn(async ({ where }: { where: { billingProviderId: string } }) => ({ id: `product-${where.billingProviderId}` })),
},
tenantSubscriptionProduct: {
create: vi.fn(),
@@ -92,6 +92,9 @@ const dbMock = {
supportTicket: {
upsert: vi.fn(),
},
app: {
upsert: vi.fn(),
},
};
const hashMock = vi.fn(async () => "hashed-password");
@@ -109,12 +112,12 @@ vi.mock("~/utils/logger.server", () => ({
}));
vi.mock("bcryptjs", () => ({ default: { genSalt: genSaltMock, hash: hashMock } }));
vi.mock("@toolctrl/db/entitlements-seed.server", () => ({
getEntitlementPlanStripeId: ({ id }: { id: string }) => `toolctrl_entitlement_plan_${id}`,
vi.mock("@hivegrid/db/entitlements-seed.server", () => ({
getEntitlementPlanBillingProviderId: ({ id }: { id: string }) => `hivegrid_entitlement_plan_${id}`,
seedStandardEntitlements: seedStandardEntitlementsMock,
}));
vi.mock("@toolctrl/db/seed.server", async () => {
const actual = await vi.importActual<typeof import("@toolctrl/db/seed.server")>("@toolctrl/db/seed.server");
vi.mock("@hivegrid/db/seed.server", async () => {
const actual = await vi.importActual<typeof import("@hivegrid/db/seed.server")>("@hivegrid/db/seed.server");
return actual;
});
vi.mock("~/utils/services/emailService", () => ({ getAvailableTenantInboundAddress: vi.fn(async () => "seed@example.test") }));
@@ -245,26 +248,23 @@ describe("SeedService", () => {
expect(dbMock.tenant.findUnique).toHaveBeenCalledWith({ where: { slug: "demo-pro-crm" } });
expect(dbMock.tenant.findUnique).toHaveBeenCalledWith({ where: { slug: "demo-business-crm" } });
expect(dbMock.subscriptionProduct.findFirst).toHaveBeenCalledWith({
where: { stripeId: "toolctrl_entitlement_plan_starter" },
where: { billingProviderId: "hivegrid_entitlement_plan_starter" },
select: { id: true },
});
expect(dbMock.subscriptionProduct.findFirst).toHaveBeenCalledWith({
where: { stripeId: "toolctrl_entitlement_plan_pro" },
where: { billingProviderId: "hivegrid_entitlement_plan_pro" },
select: { id: true },
});
expect(dbMock.subscriptionProduct.findFirst).toHaveBeenCalledWith({
where: { stripeId: "toolctrl_entitlement_plan_business" },
where: { billingProviderId: "hivegrid_entitlement_plan_business" },
select: { id: true },
});
expect(dbMock.tenantSubscriptionProduct.create).toHaveBeenCalledTimes(3);
expect(dbMock.entity.findMany).toHaveBeenCalledWith({
where: { name: { in: ["company", "contact", "opportunity"] } },
select: { id: true, name: true, type: true },
});
expect(dbMock.entity.create).toHaveBeenCalledWith(expect.objectContaining({ data: expect.objectContaining({ name: "company", type: "all" }) }));
expect(dbMock.entity.create).toHaveBeenCalledWith(expect.objectContaining({ data: expect.objectContaining({ name: "contact", type: "all" }) }));
expect(dbMock.entity.create).toHaveBeenCalledWith(expect.objectContaining({ data: expect.objectContaining({ name: "opportunity", type: "all" }) }));
expect(dbMock.entity.create).not.toHaveBeenCalledWith(expect.objectContaining({ data: expect.objectContaining({ name: "submission" }) }));
// R-P6 (DoD 1 + 6): the legacy entity-builder CRM seed
// (ensureProductCoreCrmEntities) was removed from the seed path; demo
// tenants now receive the (currently empty) SHK custom-field template
// instead, so no `company`/`contact`/`opportunity` Entity rows are created.
expect(dbMock.entity.create).not.toHaveBeenCalled();
expect(dbMock.tenantProductConfiguration.upsert).toHaveBeenCalledTimes(3);
expect(dbMock.knowledgeBase.upsert).toHaveBeenCalledTimes(3);
expect(dbMock.supportTicket.upsert).toHaveBeenCalledTimes(6);
@@ -274,6 +274,41 @@ describe("SeedService", () => {
);
});
it("does not reassign a demo tenant plan after self-service checkout", async () => {
process.env.SEED_DEMO_DATA = "true";
dbMock.tenant.findUnique.mockImplementation(async ({ where, include }: { where: { slug: string }; include?: unknown }) => ({
id: `tenant-${where.slug}`,
slug: where.slug,
name: where.slug,
...(include
? {
subscription: {
id: `subscription-${where.slug}`,
lastInvoiceExternalId: where.slug === "demo-pro-crm" ? "hgco_paid_checkout" : null,
lastPaymentExternalId: where.slug === "demo-pro-crm" ? "hgco_paid_checkout" : null,
products: [],
},
}
: {}),
}));
const SeedService = await loadSeedService();
await SeedService.seed();
expect(dbMock.subscriptionProduct.findFirst).toHaveBeenCalledWith({
where: { billingProviderId: "hivegrid_entitlement_plan_starter" },
select: { id: true },
});
expect(dbMock.subscriptionProduct.findFirst).not.toHaveBeenCalledWith({
where: { billingProviderId: "hivegrid_entitlement_plan_pro" },
select: { id: true },
});
expect(dbMock.subscriptionProduct.findFirst).toHaveBeenCalledWith({
where: { billingProviderId: "hivegrid_entitlement_plan_business" },
select: { id: true },
});
});
it("refuses demo data in production without the explicit staging override", async () => {
process.env.NODE_ENV = "production";
process.env.SEED_DEMO_DATA = "true";
@@ -341,6 +376,22 @@ describe("SeedService", () => {
expect(calls).toEqual(["roles", "entitlements"]);
});
it("upserts the integration catalog into the global App table (R-P5)", async () => {
const SeedService = await loadSeedService();
const { INTEGRATION_CATALOG } = await import("@hivegrid/integrations");
await SeedService.seed();
expect(dbMock.app.upsert).toHaveBeenCalledTimes(INTEGRATION_CATALOG.length);
expect(dbMock.app.upsert).toHaveBeenCalledWith(
expect.objectContaining({
where: { key: "sample-data-sync" },
create: expect.objectContaining({ key: "sample-data-sync", title: "integrations.app.sampleDataSync.title", connectionType: "rest_api", isActive: true }),
update: expect.objectContaining({ title: "integrations.app.sampleDataSync.title" }),
})
);
});
it("logs redacted DB seed failure diagnostics without raw secret errors", async () => {
process.env.SEED_ADMIN_EMAIL = "owner@example.com";
process.env.SEED_ADMIN_PASSWORD = "safe-secret-password";
@@ -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 }),
]);
}