Reorganize repo structure and standards references

This commit is contained in:
david committed 2026-06-29 05:03:42 +02:00
1 parent 3cb93a81be
commit be2054274d
5885 files changed
+2588 -195

No files matched your search

@@ -0,0 +1,115 @@
import { describe, expect, it } from "vitest";
import {
entitlementLimitTypes,
entitlementPlanIds,
entitlementsPackageName,
evaluateProductAccess,
featureKeys,
getDefaultProductBlueprint,
getStandardEntitlementPlan,
productBlueprintIds,
} from "./index.js";
describe("entitlements package shell", () => {
it("exports the package identity placeholder", () => {
expect(entitlementsPackageName).toBe("@toolctrl/entitlements");
});
it("defines the CRM SaaS product core blueprint as the default showcase", () => {
const blueprint = getDefaultProductBlueprint();
expect(blueprint).toMatchObject({
id: productBlueprintIds.crmSaas,
version: "2026.05.15",
defaultShowcase: true,
});
expect(blueprint.features.map((feature) => feature.featureKey)).toEqual(
expect.arrayContaining([featureKeys.crmBasic, featureKeys.supportTickets, featureKeys.workflowEngine, featureKeys.mcp])
);
});
it("keeps Starter, Pro, and Business realistically strict", () => {
expect(getStandardEntitlementPlan(entitlementPlanIds.starter)?.features).toEqual(
expect.arrayContaining([
expect.objectContaining({ featureKey: featureKeys.crmBasic, limitType: entitlementLimitTypes.included }),
expect.objectContaining({ featureKey: featureKeys.api, limitType: entitlementLimitTypes.notIncluded }),
expect.objectContaining({ featureKey: featureKeys.workflowEngine, limitType: entitlementLimitTypes.notIncluded }),
])
);
expect(getStandardEntitlementPlan(entitlementPlanIds.pro)?.features).toEqual(
expect.arrayContaining([
expect.objectContaining({ featureKey: featureKeys.emailMarketing, limitType: entitlementLimitTypes.monthly }),
expect.objectContaining({ featureKey: featureKeys.api, limitType: entitlementLimitTypes.included }),
expect.objectContaining({ featureKey: featureKeys.workflowEngine, limitType: entitlementLimitTypes.notIncluded }),
])
);
expect(getStandardEntitlementPlan(entitlementPlanIds.business)?.features).toEqual(
expect.arrayContaining([
expect.objectContaining({ featureKey: featureKeys.workflowEngine, limitType: entitlementLimitTypes.monthly }),
expect.objectContaining({ featureKey: featureKeys.mcp, limitType: entitlementLimitTypes.included }),
expect.objectContaining({ featureKey: featureKeys.advancedBuilder, limitType: entitlementLimitTypes.included }),
])
);
});
it("evaluates product access through blueprint, plan, tenant override, and tenant-owned role permission", () => {
expect(
evaluateProductAccess({
blueprintId: productBlueprintIds.crmSaas,
featureKey: featureKeys.workflowEngine,
hasSubscription: true,
limitType: entitlementLimitTypes.notIncluded,
tenantRolePermissionNames: ["app.settings.roles.set"],
})
).toMatchObject({ allowed: false, reason: "not-included" });
expect(
evaluateProductAccess({
blueprintId: productBlueprintIds.crmSaas,
featureKey: featureKeys.workflowEngine,
hasSubscription: true,
limitType: entitlementLimitTypes.monthly,
limit: 100,
used: 10,
tenantOverride: "disabled",
tenantRolePermissionNames: ["app.settings.roles.set"],
})
).toMatchObject({ allowed: false, reason: "tenant-override-disabled" });
expect(
evaluateProductAccess({
blueprintId: productBlueprintIds.crmSaas,
featureKey: featureKeys.workflowEngine,
hasSubscription: true,
limitType: entitlementLimitTypes.monthly,
limit: 100,
used: 10,
tenantRolePermissionNames: [],
})
).toMatchObject({ allowed: false, reason: "tenant-role-missing", requiredTenantRolePermission: "app.settings.roles.set" });
expect(
evaluateProductAccess({
blueprintId: productBlueprintIds.crmSaas,
featureKey: featureKeys.workflowEngine,
hasSubscription: true,
limitType: entitlementLimitTypes.monthly,
limit: 100,
used: 10,
tenantRolePermissionNames: ["app.settings.roles.set"],
})
).toMatchObject({ allowed: true, reason: "monthly-remaining", remaining: 90 });
expect(
evaluateProductAccess({
blueprintId: productBlueprintIds.crmSaas,
featureKey: featureKeys.crmBasic,
hasSubscription: true,
limitType: entitlementLimitTypes.notIncluded,
tenantOverride: "enabled",
tenantRolePermissionNames: ["app.dashboard.view"],
})
).toMatchObject({ allowed: false, reason: "tenant-override-not-toggleable" });
});
});