From 55535e04b78b41cae30bdd2d3dd5c4cc2f6b0e2b Mon Sep 17 00:00:00 2001 From: giancarlo Date: Tue, 16 Apr 2024 12:48:33 +0800 Subject: [PATCH] Add new type definitions to billing/core package New type definitions have been added to the billing/core package: UpsertOrderParams and UpsertSubscriptionParams. These types were then exported and used in other services, removing duplication and ensuring type consistency across the package. The changes have been reflected in the package.json file of billing/core package. --- packages/billing/core/package.json | 3 ++- .../billing-webhook-handler.service.ts | 10 ++----- packages/billing/core/src/types/index.ts | 24 +++++++++++++++++ .../billing-event-handler.service.ts | 27 +++---------------- 4 files changed, 32 insertions(+), 32 deletions(-) create mode 100644 packages/billing/core/src/types/index.ts diff --git a/packages/billing/core/package.json b/packages/billing/core/package.json index c7825e493..433cb9eea 100644 --- a/packages/billing/core/package.json +++ b/packages/billing/core/package.json @@ -12,7 +12,8 @@ "exports": { ".": "./src/index.ts", "./components/*": "./src/components/*", - "./schema": "./src/schema/index.ts" + "./schema": "./src/schema/index.ts", + "./types": "./src/types/index.ts" }, "peerDependencies": { "@kit/supabase": "0.1.0", diff --git a/packages/billing/core/src/services/billing-webhook-handler.service.ts b/packages/billing/core/src/services/billing-webhook-handler.service.ts index ac7574a58..2a0084a97 100644 --- a/packages/billing/core/src/services/billing-webhook-handler.service.ts +++ b/packages/billing/core/src/services/billing-webhook-handler.service.ts @@ -1,10 +1,4 @@ -import { Database } from '@kit/supabase/database'; - -type UpsertSubscriptionParams = - Database['public']['Functions']['upsert_subscription']['Args']; - -type UpsertOrderParams = - Database['public']['Functions']['upsert_order']['Args']; +import { UpsertOrderParams, UpsertSubscriptionParams } from '../types'; /** * @name BillingWebhookHandlerService @@ -44,7 +38,7 @@ export abstract class BillingWebhookHandlerService { onPaymentFailed: (sessionId: string) => Promise; // generic handler for any event - onEvent?: (event: string, data: unknown) => Promise; + onEvent?: (event: string, data: Data) => Promise; }, ): Promise; } diff --git a/packages/billing/core/src/types/index.ts b/packages/billing/core/src/types/index.ts new file mode 100644 index 000000000..a77634d90 --- /dev/null +++ b/packages/billing/core/src/types/index.ts @@ -0,0 +1,24 @@ +import { Database } from '@kit/supabase/database'; + +type LineItems = Array<{ + id: string; + quantity: number; + product_id: string; + variant_id: string; + price_amount: number; +}>; + +export type UpsertSubscriptionParams = + Database['public']['Functions']['upsert_subscription']['Args'] & { + line_items: LineItems & { + interval: string; + subscription_id: string; + interval_count: number; + type: 'per_seat' | 'flat' | 'metered'; + }; + }; + +export type UpsertOrderParams = + Database['public']['Functions']['upsert_order']['Args'] & { + line_items: LineItems; + }; diff --git a/packages/billing/gateway/src/server/services/billing-event-handler/billing-event-handler.service.ts b/packages/billing/gateway/src/server/services/billing-event-handler/billing-event-handler.service.ts index f8e233a32..3879173b2 100644 --- a/packages/billing/gateway/src/server/services/billing-event-handler/billing-event-handler.service.ts +++ b/packages/billing/gateway/src/server/services/billing-event-handler/billing-event-handler.service.ts @@ -3,32 +3,13 @@ import 'server-only'; import { SupabaseClient } from '@supabase/supabase-js'; import { BillingWebhookHandlerService } from '@kit/billing'; +import { + UpsertOrderParams, + UpsertSubscriptionParams, +} from '@kit/billing/types'; import { getLogger } from '@kit/shared/logger'; import { Database } from '@kit/supabase/database'; -type LineItems = Array<{ - id: string; - quantity: number; - product_id: string; - variant_id: string; - price_amount: number; -}>; - -type UpsertSubscriptionParams = - Database['public']['Functions']['upsert_subscription']['Args'] & { - line_items: LineItems & { - interval: string; - subscription_id: string; - interval_count: number; - type: 'per_seat' | 'flat' | 'metered'; - }; - }; - -type UpsertOrderParams = - Database['public']['Functions']['upsert_order']['Args'] & { - line_items: LineItems; - }; - /** * @name CustomHandlersParams * @description Allow consumers to provide custom handlers for the billing events