Refactor billing imports, reorganize package scripts and improve action structure
Deleted unnecessary schema files and reorganized their imports into more logical order. Modified the package script structure to align more accurately with standard conventions. Also refactored the team-billing.service file to improve action structure, making it easier to understand and edit. Furthermore, upgraded various dependencies, reflecting their new versions in the lockfile.
This commit is contained in:
@@ -2,25 +2,26 @@
|
||||
|
||||
import { redirect } from 'next/navigation';
|
||||
|
||||
import { z } from 'zod';
|
||||
|
||||
import { enhanceAction } from '@kit/next/actions';
|
||||
import { getSupabaseServerActionClient } from '@kit/supabase/server-actions-client';
|
||||
|
||||
import { PersonalAccountCheckoutSchema } from './_lib/schema/personal-account-checkout.schema';
|
||||
import { UserBillingService } from './_lib/server/user-billing.service';
|
||||
|
||||
/**
|
||||
* @name createPersonalAccountCheckoutSession
|
||||
* @description Creates a checkout session for a personal account.
|
||||
*/
|
||||
export async function createPersonalAccountCheckoutSession(
|
||||
params: z.infer<typeof PersonalAccountCheckoutSchema>,
|
||||
) {
|
||||
// parse the parameters
|
||||
const data = PersonalAccountCheckoutSchema.parse(params);
|
||||
const service = new UserBillingService(getSupabaseServerActionClient());
|
||||
export const createPersonalAccountCheckoutSession = enhanceAction(
|
||||
async function (data) {
|
||||
const service = new UserBillingService(getSupabaseServerActionClient());
|
||||
|
||||
return await service.createCheckoutSession(data);
|
||||
}
|
||||
return await service.createCheckoutSession(data);
|
||||
},
|
||||
{
|
||||
schema: PersonalAccountCheckoutSchema,
|
||||
},
|
||||
);
|
||||
|
||||
/**
|
||||
* @description Creates a billing Portal session for a personal account
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
'use server';
|
||||
|
||||
import { getSupabaseServerActionClient } from '@kit/supabase/server-actions-client';
|
||||
|
||||
/**
|
||||
* Refreshes the user session on the server when updating the user profile.
|
||||
*/
|
||||
export async function refreshSessionAction() {
|
||||
const supabase = getSupabaseServerActionClient();
|
||||
|
||||
await supabase.auth.refreshSession();
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
export const TeamBillingPortalSchema = z.object({
|
||||
accountId: z.string().uuid(),
|
||||
slug: z.string().min(1),
|
||||
});
|
||||
@@ -1,5 +1,10 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
export const TeamBillingPortalSchema = z.object({
|
||||
accountId: z.string().uuid(),
|
||||
slug: z.string().min(1),
|
||||
});
|
||||
|
||||
export const TeamCheckoutSchema = z.object({
|
||||
slug: z.string().min(1),
|
||||
productId: z.string().min(1),
|
||||
@@ -14,7 +14,7 @@ import appConfig from '~/config/app.config';
|
||||
import billingConfig from '~/config/billing.config';
|
||||
import pathsConfig from '~/config/paths.config';
|
||||
|
||||
import { TeamCheckoutSchema } from '../../_lib/schema/team-checkout.schema';
|
||||
import { TeamCheckoutSchema } from '../../_lib/schema/team-billing.schema';
|
||||
|
||||
export class TeamBillingService {
|
||||
private readonly namespace = 'billing.team-account';
|
||||
|
||||
@@ -6,9 +6,11 @@ import { z } from 'zod';
|
||||
|
||||
import { getSupabaseServerActionClient } from '@kit/supabase/server-actions-client';
|
||||
|
||||
import { TeamBillingPortalSchema } from '~/(dashboard)/home/[account]/_lib/schema/team-billing-portal.schema';
|
||||
|
||||
import { TeamCheckoutSchema } from '../_lib/schema/team-checkout.schema';
|
||||
// billing imports
|
||||
import {
|
||||
TeamBillingPortalSchema,
|
||||
TeamCheckoutSchema,
|
||||
} from '../_lib/schema/team-billing.schema';
|
||||
import { TeamBillingService } from '../_lib/server/team-billing.service';
|
||||
|
||||
/**
|
||||
@@ -19,7 +21,6 @@ export async function createTeamAccountCheckoutSession(
|
||||
params: z.infer<typeof TeamCheckoutSchema>,
|
||||
) {
|
||||
const data = TeamCheckoutSchema.parse(params);
|
||||
|
||||
const service = new TeamBillingService(getSupabaseServerActionClient());
|
||||
|
||||
return service.createCheckout(data);
|
||||
@@ -32,7 +33,6 @@ export async function createTeamAccountCheckoutSession(
|
||||
*/
|
||||
export async function createBillingPortalSession(formData: FormData) {
|
||||
const params = TeamBillingPortalSchema.parse(Object.fromEntries(formData));
|
||||
|
||||
const service = new TeamBillingService(getSupabaseServerActionClient());
|
||||
|
||||
// get url to billing portal
|
||||
|
||||
Reference in New Issue
Block a user