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:
giancarlo
2024-04-07 12:47:29 +08:00
parent 0a9c1f35c6
commit 0002ac6255
22 changed files with 244 additions and 82 deletions

View File

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

View File

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

View File

@@ -1,6 +0,0 @@
import { z } from 'zod';
export const TeamBillingPortalSchema = z.object({
accountId: z.string().uuid(),
slug: z.string().min(1),
});

View File

@@ -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),

View File

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

View File

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

View File

@@ -4,7 +4,7 @@ import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { ReactQueryStreamedHydration } from '@tanstack/react-query-next-experimental';
import { ThemeProvider } from 'next-themes';
import { CaptchaProvider, CaptchaTokenSetter } from '@kit/auth/captcha';
import { CaptchaProvider, CaptchaTokenSetter } from '@kit/auth/captcha/client';
import { I18nProvider } from '@kit/i18n/provider';
import { AuthChangeListener } from '@kit/supabase/components/auth-change-listener';

View File

@@ -20,7 +20,7 @@ const AuthConfigSchema = z.object({
const authConfig = AuthConfigSchema.parse({
// NB: This is a public key, so it's safe to expose.
// Copy the value from the Supabase Dashboard.
captchaTokenSiteKey: process.env.NEXT_PUBLIC_CAPTCHA_SITE_KEY ?? '',
captchaTokenSiteKey: process.env.NEXT_PUBLIC_CAPTCHA_SITE_KEY,
// NB: Enable the providers below in the Supabase Console
// in your production project

View File

@@ -17,6 +17,7 @@ const INTERNAL_PACKAGES = [
'@kit/database-webhooks',
'@kit/cms',
'@kit/monitoring',
'@kit/next'
];
/** @type {import('next').NextConfig} */

View File

@@ -28,6 +28,7 @@
"@kit/i18n": "workspace:^",
"@kit/mailers": "workspace:^",
"@kit/monitoring": "workspace:^",
"@kit/next": "workspace:^",
"@kit/shared": "workspace:^",
"@kit/supabase": "workspace:^",
"@kit/team-accounts": "workspace:^",
@@ -44,7 +45,7 @@
"i18next": "^23.10.1",
"i18next-resources-to-backend": "^1.2.0",
"lucide-react": "^0.363.0",
"next": "14.2.0-canary.60",
"next": "14.2.0-canary.61",
"next-sitemap": "^4.2.3",
"next-themes": "0.3.0",
"react": "18.2.0",