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:
@@ -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",
|
||||||
|
|||||||
@@ -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>;
|
||||||
}
|
}
|
||||||
|
|||||||
24
packages/billing/core/src/types/index.ts
Normal file
24
packages/billing/core/src/types/index.ts
Normal 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;
|
||||||
|
};
|
||||||
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user