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

@@ -17,36 +17,36 @@ import {
deleteSubscriptionProduct,
deleteSubscriptionUsageBasedPrice,
deleteSubscriptionUsageBasedTier,
findTenantSubscriptionProductByStripeSubscriptionId,
findTenantSubscriptionProductByBillingProviderSubscriptionId,
getEffectiveTenantEntitlementPlanId,
getAllSubscriptionFeatures,
getAllSubscriptionProducts,
getAllSubscriptionProductsWithTenants,
getSubscriptionPrice,
getSubscriptionPriceByStripeId,
getSubscriptionPriceByBillingProviderId,
getSubscriptionPrices,
getSubscriptionProduct,
getSubscriptionProductByStripeId,
getSubscriptionProductByBillingProviderId,
getSubscriptionProductsInIds,
getSubscriptionUsageBasedPriceByStripeId,
getSubscriptionUsageBasedPriceByBillingProviderId,
getTenantSubscription,
getTenantSubscriptionProduct,
getTenantSubscriptionProductById,
getTenantSubscriptionProductByStripeSubscriptionId,
getTenantSubscriptionProductByBillingProviderSubscriptionId,
getTenantSubscriptions,
getAllTenantSubscriptionProducts,
getCheckoutSessionStatus,
listTenantSubscriptionIds,
updateCheckoutSessionStatus,
updateSubscriptionPrice,
updateSubscriptionPriceStripeId,
updateSubscriptionPriceBillingProviderId,
updateSubscriptionProduct,
updateSubscriptionProductStripeId,
updateSubscriptionProductBillingProviderId,
updateTenantSubscriptionCustomerId,
updateTenantSubscriptionProduct,
updateTenantSubscriptionProductCustomEntitlementPlan,
updateTenantSubscriptionProductFromStripe,
type StripeTenantSubscriptionProductClient,
updateTenantSubscriptionProductFromBillingProvider,
type BillingProviderTenantSubscriptionProductClient,
type SubscriptionCatalogClient,
type TenantBillingClient,
type TenantSubscriptionReaderClient,
@@ -96,13 +96,13 @@ function createTenantSubscriptionClient(items: unknown[] = []): TenantSubscripti
} as unknown as TenantSubscriptionReaderClient;
}
function createStripeTenantSubscriptionProductClient(item: unknown = null): StripeTenantSubscriptionProductClient {
function createBillingProviderTenantSubscriptionProductClient(item: unknown = null): BillingProviderTenantSubscriptionProductClient {
return {
tenantSubscriptionProduct: {
findFirst: vi.fn().mockResolvedValue(item),
update: vi.fn().mockResolvedValue({ tenantSubscription: { tenantId: "tenant_1" } }),
},
} as unknown as StripeTenantSubscriptionProductClient;
} as unknown as BillingProviderTenantSubscriptionProductClient;
}
function createTenantBillingClient(items: unknown[] = []): TenantBillingClient {
@@ -111,7 +111,7 @@ function createTenantBillingClient(items: unknown[] = []): TenantBillingClient {
findMany: vi.fn().mockResolvedValue(items.length > 0 ? items : [{ tenantId: "tenant_1" }]),
findUnique: vi.fn().mockResolvedValue(items[0] ?? null),
create: vi.fn().mockResolvedValue(items[0] ?? { id: "tenant_sub_1", tenantId: "tenant_1", products: [] }),
update: vi.fn().mockResolvedValue(items[0] ?? { id: "tenant_sub_1", tenantId: "tenant_1", stripeCustomerId: "cus_1" }),
update: vi.fn().mockResolvedValue(items[0] ?? { id: "tenant_sub_1", tenantId: "tenant_1", billingProviderCustomerId: "cus_1" }),
},
tenantSubscriptionProduct: {
findMany: vi.fn().mockResolvedValue(items),
@@ -213,19 +213,19 @@ describe("subscription product reads", () => {
await expect(getAllSubscriptionFeatures(client)).resolves.toEqual([]);
expect(client.subscriptionFeature.findMany).toHaveBeenCalledWith({
select: { name: true, order: true, title: true, type: true, value: true, accumulate: true },
select: { name: true, code: true, order: true, title: true, type: true, value: true, accumulate: true },
});
});
});
describe("subscription catalog helpers", () => {
it("fetches a product by Stripe id", async () => {
const product = { id: "plan_a", stripeId: "prod_123" };
it("fetches a product by billing provider id", async () => {
const product = { id: "plan_a", billingProviderId: "prod_123" };
const client = createSubscriptionProductClient([product]);
await expect(getSubscriptionProductByStripeId("prod_123", client)).resolves.toBe(product);
await expect(getSubscriptionProductByBillingProviderId("prod_123", client)).resolves.toBe(product);
expect(client.subscriptionProduct.findFirst).toHaveBeenCalledWith({
where: { stripeId: "prod_123" },
where: { billingProviderId: "prod_123" },
});
});
@@ -248,14 +248,14 @@ describe("subscription catalog helpers", () => {
await expect(getSubscriptionPrices(client)).resolves.toEqual([]);
await expect(getSubscriptionPrice("price_1", client)).resolves.toBeNull();
await expect(getSubscriptionPriceByStripeId("price_stripe_1", client)).resolves.toBeNull();
await expect(getSubscriptionUsageBasedPriceByStripeId("metered_stripe_1", client)).resolves.toBeNull();
await expect(getSubscriptionPriceByBillingProviderId("price_provider_1", client)).resolves.toBeNull();
await expect(getSubscriptionUsageBasedPriceByBillingProviderId("metered_provider_1", client)).resolves.toBeNull();
});
it("creates catalog rows without coercing decimal-compatible values", async () => {
const client = createSubscriptionProductClient([]);
const productData = {
stripeId: "prod_123",
billingProviderId: "prod_123",
order: 1,
title: "Pro",
model: 1,
@@ -271,7 +271,7 @@ describe("subscription catalog helpers", () => {
};
const priceData = {
subscriptionProductId: "plan_a",
stripeId: "price_123",
billingProviderId: "price_123",
type: 1,
billingPeriod: 1,
price: "19.99",
@@ -281,7 +281,7 @@ describe("subscription catalog helpers", () => {
};
const usagePriceData = {
subscriptionProductId: "plan_a",
stripeId: "metered_123",
billingProviderId: "metered_123",
currency: "usd",
billingPeriod: 1,
unit: "api_call",
@@ -338,9 +338,9 @@ describe("subscription catalog helpers", () => {
const client = createSubscriptionProductClient([]);
await updateSubscriptionProduct("plan_a", { title: "Business", public: false }, client);
await updateSubscriptionProductStripeId("plan_a", { stripeId: "prod_new" }, client);
await updateSubscriptionProductBillingProviderId("plan_a", { billingProviderId: "prod_new" }, client);
await updateSubscriptionPrice("price_a", { price: "29.99", active: false }, client);
await updateSubscriptionPriceStripeId("price_a", { stripeId: "price_new" }, client);
await updateSubscriptionPriceBillingProviderId("price_a", { billingProviderId: "price_new" }, client);
expect(client.subscriptionProduct.update).toHaveBeenNthCalledWith(1, {
where: { id: "plan_a" },
@@ -348,7 +348,7 @@ describe("subscription catalog helpers", () => {
});
expect(client.subscriptionProduct.update).toHaveBeenNthCalledWith(2, {
where: { id: "plan_a" },
data: { stripeId: "prod_new" },
data: { billingProviderId: "prod_new" },
});
expect(client.subscriptionPrice.update).toHaveBeenNthCalledWith(1, {
where: { id: "price_a" },
@@ -356,7 +356,7 @@ describe("subscription catalog helpers", () => {
});
expect(client.subscriptionPrice.update).toHaveBeenNthCalledWith(2, {
where: { id: "price_a" },
data: { stripeId: "price_new" },
data: { billingProviderId: "price_new" },
});
});
@@ -376,7 +376,7 @@ describe("subscription catalog helpers", () => {
expect(client.subscriptionFeature.deleteMany).toHaveBeenCalledWith({ where: { subscriptionProductId: "plan_a" } });
});
it("propagates mutation failures instead of hiding failed Stripe sync", async () => {
it("propagates mutation failures instead of hiding failed billing provider sync", async () => {
const client = createSubscriptionProductClient([]);
const error = new Error("write failed");
vi.mocked(client.subscriptionPrice.update).mockRejectedValueOnce(error);
@@ -427,12 +427,12 @@ describe("tenant billing boundary", () => {
it("creates and updates tenant subscriptions", async () => {
const client = createTenantBillingClient([]);
await createTenantSubscription({ tenantId: "tenant_1", stripeCustomerId: "cus_1" }, client);
await updateTenantSubscriptionCustomerId("tenant_1", { stripeCustomerId: "cus_2" }, client);
await createTenantSubscription({ tenantId: "tenant_1", billingProviderCustomerId: "cus_1" }, client);
await updateTenantSubscriptionCustomerId("tenant_1", { billingProviderCustomerId: "cus_2" }, client);
await expect(listTenantSubscriptionIds(client)).resolves.toEqual([{ tenantId: "tenant_1" }]);
expect(client.tenantSubscription.create).toHaveBeenCalledWith({
data: { tenantId: "tenant_1", stripeCustomerId: "cus_1" },
data: { tenantId: "tenant_1", billingProviderCustomerId: "cus_1" },
include: {
products: {
include: {
@@ -445,7 +445,7 @@ describe("tenant billing boundary", () => {
});
expect(client.tenantSubscription.update).toHaveBeenCalledWith({
where: { tenantId: "tenant_1" },
data: { stripeCustomerId: "cus_2" },
data: { billingProviderCustomerId: "cus_2" },
});
expect(client.tenantSubscription.findMany).toHaveBeenCalledWith({ select: { tenantId: true } });
});
@@ -518,21 +518,21 @@ describe("tenant billing boundary", () => {
);
});
it("looks up tenant products by tenant/product, id, and Stripe subscription id", async () => {
it("looks up tenant products by tenant/product, id, and Billing provider subscription id", async () => {
const item = { id: "tenant_product_1" };
const client = createTenantBillingClient([item]);
await expect(getTenantSubscriptionProduct("tenant_1", "plan_1", client)).resolves.toBe(item);
await expect(adminGetTenantSubscriptionProductById("tenant_product_1", client)).resolves.toBe(item);
await expect(getTenantSubscriptionProductById({ id: "tenant_product_1", tenantId: "tenant_1" }, client)).resolves.toBe(item);
await expect(getTenantSubscriptionProductByStripeSubscriptionId("sub_1", client)).resolves.toBe(item);
await expect(getTenantSubscriptionProductByBillingProviderSubscriptionId("sub_1", client)).resolves.toBe(item);
expect(client.tenantSubscriptionProduct.findFirst).toHaveBeenNthCalledWith(1, expect.objectContaining({
where: { tenantSubscription: { tenantId: "tenant_1" }, subscriptionProductId: "plan_1" },
}));
expect(client.tenantSubscriptionProduct.findUnique).toHaveBeenCalledWith(expect.objectContaining({ where: { id: "tenant_product_1" } }));
expect(client.tenantSubscriptionProduct.findFirst).toHaveBeenNthCalledWith(2, expect.objectContaining({ where: { id: "tenant_product_1", tenantSubscription: { tenantId: "tenant_1" } } }));
expect(client.tenantSubscriptionProduct.findFirst).toHaveBeenNthCalledWith(3, expect.objectContaining({ where: { stripeSubscriptionId: "sub_1" } }));
expect(client.tenantSubscriptionProduct.findFirst).toHaveBeenNthCalledWith(3, expect.objectContaining({ where: { billingProviderSubscriptionId: "sub_1" } }));
});
it("uses the billing product id when no custom entitlement override exists", () => {
@@ -560,7 +560,7 @@ describe("tenant billing boundary", () => {
{
tenantSubscriptionId: "tenant_sub_1",
subscriptionProductId: "plan_1",
stripeSubscriptionId: "sub_1",
billingProviderSubscriptionId: "sub_1",
quantity: 2,
fromCheckoutSessionId: "cs_1",
prices: [{ subscriptionPriceId: "price_1" }, { subscriptionUsageBasedPriceId: "usage_price_1" }],
@@ -580,7 +580,7 @@ describe("tenant billing boundary", () => {
data: {
tenantSubscriptionId: "tenant_sub_1",
subscriptionProductId: "plan_1",
stripeSubscriptionId: "sub_1",
billingProviderSubscriptionId: "sub_1",
quantity: 2,
fromCheckoutSessionId: "cs_1",
customEntitlementPlanId: undefined,
@@ -645,21 +645,35 @@ describe("tenant billing boundary", () => {
await updateCheckoutSessionStatus("cs_1", { pending: false, createdUserId: "user_1" }, client);
expect(client.checkoutSessionStatus.create).toHaveBeenCalledWith({
data: { id: "cs_1", pending: true, email: "user@example.com", fromUrl: "/subscribe/acme", fromUserId: null, fromTenantId: null },
data: expect.objectContaining({
id: "cs_1",
pending: true,
email: "user@example.com",
fromUrl: "/subscribe/acme",
fromUserId: null,
fromTenantId: null,
provider: null,
providerPaymentId: null,
quantity: 1,
status: "open",
}),
});
expect(client.checkoutSessionStatus.update).toHaveBeenCalledWith({
where: { id: "cs_1" },
data: { pending: false, createdUserId: "user_1", createdTenantId: null },
data: expect.objectContaining({ pending: false, createdUserId: "user_1", createdTenantId: null }),
});
});
it("creates usage records and propagates write rejections", async () => {
const client = createTenantBillingClient([{ id: "tenant_product_1", tenantSubscription: { tenantId: "tenant_1" } }]);
const usageData = {
tenantId: "tenant_1",
tenantSubscriptionId: "tenant_subscription_1",
tenantSubscriptionProductPriceId: "tenant_price_1",
metricCode: "usage_metric",
timestamp: 1_777_777,
quantity: 1,
stripeSubscriptionItemId: "si_1",
billingProviderSubscriptionItemId: "si_1",
};
await createTenantSubscriptionUsageRecord(usageData, client);
@@ -671,14 +685,14 @@ describe("tenant billing boundary", () => {
});
});
describe("stripe tenant subscription products", () => {
it("fetches the tenant subscription product needed by Stripe webhooks", async () => {
describe("billing provider tenant subscription products", () => {
it("fetches the tenant subscription product needed by billing webhooks", async () => {
const item = { id: "tenant_product_1" };
const client = createStripeTenantSubscriptionProductClient(item);
const client = createBillingProviderTenantSubscriptionProductClient(item);
await expect(findTenantSubscriptionProductByStripeSubscriptionId("sub_123", client)).resolves.toBe(item);
await expect(findTenantSubscriptionProductByBillingProviderSubscriptionId("sub_123", client)).resolves.toBe(item);
expect(client.tenantSubscriptionProduct.findFirst).toHaveBeenCalledWith({
where: { stripeSubscriptionId: "sub_123" },
where: { billingProviderSubscriptionId: "sub_123" },
select: {
id: true,
endsAt: true,
@@ -705,8 +719,8 @@ describe("stripe tenant subscription products", () => {
});
});
it("updates Stripe subscription dates and returns the owning tenant id", async () => {
const client = createStripeTenantSubscriptionProductClient();
it("updates Billing provider subscription dates and returns the owning tenant id", async () => {
const client = createBillingProviderTenantSubscriptionProductClient();
const data = {
cancelledAt: new Date("2026-05-01T00:00:00.000Z"),
currentPeriodStart: new Date("2026-05-01T00:00:00.000Z"),
@@ -714,7 +728,7 @@ describe("stripe tenant subscription products", () => {
endsAt: null,
};
await expect(updateTenantSubscriptionProductFromStripe("tenant_product_1", data, client)).resolves.toEqual({ tenantId: "tenant_1" });
await expect(updateTenantSubscriptionProductFromBillingProvider("tenant_product_1", data, client)).resolves.toEqual({ tenantId: "tenant_1" });
expect(client.tenantSubscriptionProduct.update).toHaveBeenCalledWith({
where: { id: "tenant_product_1" },
data,