37 lines
1.9 KiB
TypeScript
37 lines
1.9 KiB
TypeScript
// Read-only: is crm-basic / leads visible (entitled) on each CRM demo tenant?
|
|
// Replicates the connector decision with workspace packages only (no ~ app alias):
|
|
// blueprint (tenantProductConfiguration) + tenant override + subscription
|
|
// entitlements -> evaluateProductAccess. No writes.
|
|
import { getDbClient } from "@hivegrid/db/client.server";
|
|
import { resolveTenantEntitlements } from "@hivegrid/db/billing-domain.server";
|
|
import { evaluateProductAccess, getDefaultProductBlueprint } from "@hivegrid/entitlements";
|
|
|
|
const DEMO_SLUGS = ["demo-starter-crm", "demo-pro-crm", "demo-business-crm"];
|
|
const KEYS = ["crm-basic", "leads"];
|
|
const db = getDbClient() as any;
|
|
|
|
const tenants = await db.tenant.findMany({ where: { slug: { in: DEMO_SLUGS } }, select: { id: true, slug: true } });
|
|
for (const t of tenants) {
|
|
const config = await db.tenantProductConfiguration.findUnique({ where: { tenantId: t.id }, select: { blueprintId: true } });
|
|
const blueprintId = config?.blueprintId ?? getDefaultProductBlueprint().id;
|
|
const ent = await resolveTenantEntitlements(t.id);
|
|
const parts: string[] = [];
|
|
for (const key of KEYS) {
|
|
const override = (await db.tenantFeatureOverride.findUnique({ where: { tenantId_featureKey: { tenantId: t.id, featureKey: key } }, select: { override: true } }))?.override ?? "inherit";
|
|
const f = (ent.features as any)[key];
|
|
const decision = evaluateProductAccess({
|
|
blueprintId,
|
|
featureKey: key,
|
|
hasSubscription: Boolean(f),
|
|
limitType: f?.limitType,
|
|
limit: f?.limit,
|
|
tenantOverride: override,
|
|
// neutralise the role gate — we only ask whether the tenant/plan grants it.
|
|
tenantRolePermissionNames: ["crm.admin", "crm.read_own", "leads.admin", "leads.read_own"],
|
|
});
|
|
parts.push(`${key}=${decision.allowed ? "YES" : "no"}(${decision.reason},ovr:${override})`);
|
|
}
|
|
console.log(`${t.slug} [blueprint:${blueprintId}] ${parts.join(" ")}`);
|
|
}
|
|
process.exit(0);
|