Update hivegrid-cloud reference to latest main
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
e98d38e716
commit
7b21524c86
3781 files changed
+373484
-225607
No files matched your search
+1
-1
@@ -1,5 +1,5 @@
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { featureKeys } from "@toolctrl/entitlements";
|
||||
import { featureKeys } from "@hivegrid/entitlements";
|
||||
|
||||
const dbMock = {
|
||||
tenantProductConfiguration: {
|
||||
|
||||
+31
-8
@@ -1,17 +1,20 @@
|
||||
import { getDefaultProductBlueprint, getProductBlueprint, type ProductAccessDecision, type ProductBlueprintId, type TenantFeatureOverride } from "@toolctrl/entitlements";
|
||||
import { resolveTenantEntitlements, type TenantBillingEntitlements } from "@hivegrid/db/billing-domain.server";
|
||||
import {
|
||||
getDefaultProductBlueprint,
|
||||
getProductBlueprint,
|
||||
type ProductAccessDecision,
|
||||
type ProductBlueprintId,
|
||||
type TenantFeatureOverride,
|
||||
} from "@hivegrid/entitlements";
|
||||
import { redirect, type Params } from "react-router";
|
||||
import { appTenantPlanRequiredPath } from "~/utils/app/AppTenantStatusPaths";
|
||||
import { buildPermissionDeniedUrl } from "~/utils/helpers/.server/PermissionsService";
|
||||
import { getIsSuperAdminByUserId } from "~/utils/loaders.middleware";
|
||||
import { getTenantIdFromUrl } from "~/utils/services/.server/urlService";
|
||||
import { getUserInfo } from "~/utils/session.server";
|
||||
import { getActiveTenantSubscriptions } from "~/utils/services/.server/subscriptionService";
|
||||
import { db } from "~/utils/db.server";
|
||||
import { getPermissionsByUser } from "~/utils/db/permissions/userRoles.db.server";
|
||||
import {
|
||||
evaluateProductSubscriptionAccess,
|
||||
type SubscriptionEntitlementSubscription,
|
||||
} from "./subscriptionEntitlements.server";
|
||||
import { evaluateProductSubscriptionAccess, type SubscriptionEntitlementSubscription } from "./subscriptionEntitlements.server";
|
||||
|
||||
export type ResolveTenantProductAccessInput = {
|
||||
tenantId: string;
|
||||
@@ -31,6 +34,24 @@ function normalizeTenantOverride(value: string | null | undefined): TenantFeatur
|
||||
return "inherit";
|
||||
}
|
||||
|
||||
export function tenantBillingEntitlementsToSubscription(entitlements: TenantBillingEntitlements): SubscriptionEntitlementSubscription | null {
|
||||
const features = Object.values(entitlements.features).map((feature, index) => ({
|
||||
order: index,
|
||||
title: feature.title,
|
||||
name: feature.featureKey,
|
||||
code: feature.featureKey,
|
||||
type: feature.limitType,
|
||||
value: feature.limit,
|
||||
quotaValue: feature.quotaValue,
|
||||
accumulate: feature.accumulate,
|
||||
}));
|
||||
return features.length > 0 ? { products: [{ features }] } : null;
|
||||
}
|
||||
|
||||
export async function resolveTenantEntitlementSubscription(tenantId: string): Promise<SubscriptionEntitlementSubscription | null> {
|
||||
return tenantBillingEntitlementsToSubscription(await resolveTenantEntitlements(tenantId));
|
||||
}
|
||||
|
||||
export async function resolveTenantProductAccess(input: ResolveTenantProductAccessInput): Promise<ProductAccessDecision> {
|
||||
const [configuration, override, tenantRolePermissionNames, isSuperAdmin] = await Promise.all([
|
||||
db.tenantProductConfiguration.findUnique({
|
||||
@@ -47,7 +68,9 @@ export async function resolveTenantProductAccess(input: ResolveTenantProductAcce
|
||||
const blueprintId = (configuration?.blueprintId as ProductBlueprintId | undefined) ?? getDefaultProductBlueprint().id;
|
||||
const rolePermissionNames = [...tenantRolePermissionNames];
|
||||
if (isSuperAdmin || input.bypassTenantRolePermission) {
|
||||
for (const permissionName of getProductBlueprint(blueprintId)?.features.map((feature) => feature.requiresTenantRolePermission).filter((value): value is string => Boolean(value)) ?? []) {
|
||||
for (const permissionName of getProductBlueprint(blueprintId)
|
||||
?.features.map((feature) => feature.requiresTenantRolePermission)
|
||||
.filter((value): value is string => Boolean(value)) ?? []) {
|
||||
if (!rolePermissionNames.includes(permissionName)) {
|
||||
rolePermissionNames.push(permissionName);
|
||||
}
|
||||
@@ -81,7 +104,7 @@ export async function requireTenantProductAccess({
|
||||
throw redirect(`/login?${searchParams}`);
|
||||
}
|
||||
|
||||
const subscription = await getActiveTenantSubscriptions(tenantId);
|
||||
const subscription = await resolveTenantEntitlementSubscription(tenantId);
|
||||
const decision = await resolveTenantProductAccess({
|
||||
tenantId,
|
||||
userId: userInfo.userId,
|
||||
|
||||
+2
-2
@@ -2,8 +2,8 @@ import { describe, expect, it } from "vitest";
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
|
||||
import { featureKeys, productBlueprintIds } from "@toolctrl/entitlements";
|
||||
import type { EntitlementDecisionReason } from "@toolctrl/entitlements";
|
||||
import { featureKeys, productBlueprintIds } from "@hivegrid/entitlements";
|
||||
import type { EntitlementDecisionReason } from "@hivegrid/entitlements";
|
||||
import { DefaultFeatures } from "~/application/dtos/shared/DefaultFeatures";
|
||||
import type { SubscriptionFeatureDto } from "~/application/dtos/subscriptions/SubscriptionFeatureDto";
|
||||
import { SubscriptionFeatureLimitType } from "~/application/enums/subscriptions/SubscriptionFeatureLimitType";
|
||||
|
||||
+4
-4
@@ -10,7 +10,7 @@ import {
|
||||
type ProductAccessDecision,
|
||||
type ProductBlueprintId,
|
||||
type TenantFeatureOverride,
|
||||
} from "@toolctrl/entitlements";
|
||||
} from "@hivegrid/entitlements";
|
||||
import { DefaultFeatures } from "~/application/dtos/shared/DefaultFeatures";
|
||||
import type { SubscriptionFeatureDto } from "~/application/dtos/subscriptions/SubscriptionFeatureDto";
|
||||
import type { SubscriptionProductDto } from "~/application/dtos/subscriptions/SubscriptionProductDto";
|
||||
@@ -43,7 +43,7 @@ export interface SubscriptionEntitlementSubscription {
|
||||
}
|
||||
|
||||
export interface SubscriptionEntitlementProduct {
|
||||
readonly features?: readonly SubscriptionFeatureDto[] | null;
|
||||
readonly features?: readonly (SubscriptionFeatureDto & { code?: string | null })[] | null;
|
||||
readonly subscriptionProduct?: Pick<SubscriptionProductDto, "features"> | null;
|
||||
readonly customEntitlementPlanId?: string | null;
|
||||
}
|
||||
@@ -65,7 +65,7 @@ const defaultIncludedTrialFeature: SubscriptionFeatureDto = Object.freeze({
|
||||
accumulate: false,
|
||||
});
|
||||
|
||||
function getSubscriptionProductFeatures(product: SubscriptionEntitlementProduct): readonly SubscriptionFeatureDto[] {
|
||||
function getSubscriptionProductFeatures(product: SubscriptionEntitlementProduct): readonly (SubscriptionFeatureDto & { code?: string | null })[] {
|
||||
return product.features ?? product.subscriptionProduct?.features ?? [];
|
||||
}
|
||||
|
||||
@@ -97,7 +97,7 @@ function findSubscriptionFeature(
|
||||
if (customFeature) {
|
||||
return customFeature;
|
||||
}
|
||||
const feature = getSubscriptionProductFeatures(product).find((item) => item.name === featureKey);
|
||||
const feature = getSubscriptionProductFeatures(product).find((item) => (item.code ?? item.name) === featureKey);
|
||||
if (feature) {
|
||||
return feature;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user