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.
This commit is contained in:
giancarlo
2024-04-16 12:48:33 +08:00
parent 8fde758671
commit 55535e04b7
4 changed files with 32 additions and 32 deletions

View File

@@ -12,7 +12,8 @@
"exports": { "exports": {
".": "./src/index.ts", ".": "./src/index.ts",
"./components/*": "./src/components/*", "./components/*": "./src/components/*",
"./schema": "./src/schema/index.ts" "./schema": "./src/schema/index.ts",
"./types": "./src/types/index.ts"
}, },
"peerDependencies": { "peerDependencies": {
"@kit/supabase": "0.1.0", "@kit/supabase": "0.1.0",

View File

@@ -1,10 +1,4 @@
import { Database } from '@kit/supabase/database'; import { UpsertOrderParams, UpsertSubscriptionParams } from '../types';
type UpsertSubscriptionParams =
Database['public']['Functions']['upsert_subscription']['Args'];
type UpsertOrderParams =
Database['public']['Functions']['upsert_order']['Args'];
/** /**
* @name BillingWebhookHandlerService * @name BillingWebhookHandlerService
@@ -44,7 +38,7 @@ export abstract class BillingWebhookHandlerService {
onPaymentFailed: (sessionId: string) => Promise<unknown>; onPaymentFailed: (sessionId: string) => Promise<unknown>;
// generic handler for any event // generic handler for any event
onEvent?: (event: string, data: unknown) => Promise<unknown>; onEvent?: <Data>(event: string, data: Data) => Promise<unknown>;
}, },
): Promise<unknown>; ): Promise<unknown>;
} }

View File

@@ -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;
};

View File

@@ -3,32 +3,13 @@ import 'server-only';
import { SupabaseClient } from '@supabase/supabase-js'; import { SupabaseClient } from '@supabase/supabase-js';
import { BillingWebhookHandlerService } from '@kit/billing'; import { BillingWebhookHandlerService } from '@kit/billing';
import {
UpsertOrderParams,
UpsertSubscriptionParams,
} from '@kit/billing/types';
import { getLogger } from '@kit/shared/logger'; import { getLogger } from '@kit/shared/logger';
import { Database } from '@kit/supabase/database'; 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 * @name CustomHandlersParams
* @description Allow consumers to provide custom handlers for the billing events * @description Allow consumers to provide custom handlers for the billing events