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