From b48380eb692b0ddb9d65ff4a120976d5c84d464c Mon Sep 17 00:00:00 2001 From: gbuomprisco Date: Tue, 18 Jun 2024 01:06:08 +0800 Subject: [PATCH] Filter out metered line items from billing schema This update refines the process of creating a billing schema by filtering out metered line items. The change is necessary as metered line items can be shared across different plans, potentially causing conflicts or duplicates in the schema. --- packages/billing/core/src/create-billing-schema.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/billing/core/src/create-billing-schema.ts b/packages/billing/core/src/create-billing-schema.ts index 159f4616e..ce4f9c875 100644 --- a/packages/billing/core/src/create-billing-schema.ts +++ b/packages/billing/core/src/create-billing-schema.ts @@ -173,7 +173,12 @@ export const PlanSchema = z ) .refine( (item) => { - const ids = item.lineItems.map((item) => item.id); + // metered line items can be shared across plans + const lineItems = item.lineItems.filter( + (item) => item.type !== LineItemType.Metered, + ); + + const ids = lineItems.map((item) => item.id); return ids.length === new Set(ids).size; },