Enforce config for billing; updated packages

This commit is contained in:
giancarlo
2024-05-08 21:47:17 +07:00
parent a501bb5444
commit b81cc94800
21 changed files with 393 additions and 252 deletions

View File

@@ -2,8 +2,6 @@ import 'server-only';
import { cache } from 'react';
import { SupabaseClient } from '@supabase/supabase-js';
import { z } from 'zod';
import { createAccountsApi } from '@kit/accounts/api';

View File

@@ -5,15 +5,27 @@ import { redirect } from 'next/navigation';
import { enhanceAction } from '@kit/next/actions';
import { getSupabaseServerActionClient } from '@kit/supabase/server-actions-client';
import featureFlagsConfig from '~/config/feature-flags.config';
import { PersonalAccountCheckoutSchema } from '../schema/personal-account-checkout.schema';
import { createUserBillingService } from './user-billing.service';
/**
* @name enabled
* @description This feature flag is used to enable or disable personal account billing.
*/
const enabled = featureFlagsConfig.enablePersonalAccountBilling;
/**
* @name createPersonalAccountCheckoutSession
* @description Creates a checkout session for a personal account.
*/
export const createPersonalAccountCheckoutSession = enhanceAction(
async function (data) {
if (!enabled) {
throw new Error('Personal account billing is not enabled');
}
const client = getSupabaseServerActionClient();
const service = createUserBillingService(client);
@@ -30,6 +42,10 @@ export const createPersonalAccountCheckoutSession = enhanceAction(
*/
export const createPersonalAccountBillingPortalSession = enhanceAction(
async () => {
if (!enabled) {
throw new Error('Personal account billing is not enabled');
}
const client = getSupabaseServerActionClient();
const service = createUserBillingService(client);

View File

@@ -5,6 +5,8 @@ import { redirect } from 'next/navigation';
import { enhanceAction } from '@kit/next/actions';
import { getSupabaseServerActionClient } from '@kit/supabase/server-actions-client';
import featureFlagsConfig from '~/config/feature-flags.config';
// billing imports
import {
TeamBillingPortalSchema,
@@ -12,12 +14,22 @@ import {
} from '../schema/team-billing.schema';
import { createTeamBillingService } from './team-billing.service';
/**
* @name enabled
* @description This feature flag is used to enable or disable team account billing.
*/
const enabled = featureFlagsConfig.enableTeamAccountBilling;
/**
* @name createTeamAccountCheckoutSession
* @description Creates a checkout session for a team account.
*/
export const createTeamAccountCheckoutSession = enhanceAction(
(data) => {
if (!enabled) {
throw new Error('Team account billing is not enabled');
}
const client = getSupabaseServerActionClient();
const service = createTeamBillingService(client);
@@ -35,6 +47,10 @@ export const createTeamAccountCheckoutSession = enhanceAction(
*/
export const createBillingPortalSession = enhanceAction(
async (formData: FormData) => {
if (!enabled) {
throw new Error('Team account billing is not enabled');
}
const params = TeamBillingPortalSchema.parse(Object.fromEntries(formData));
const client = getSupabaseServerActionClient();

View File

@@ -67,23 +67,23 @@
"react-dom": "18.3.1",
"react-hook-form": "^7.51.4",
"react-i18next": "^14.1.1",
"recharts": "^2.12.6",
"recharts": "^2.12.7",
"sonner": "^1.4.41",
"tailwind-merge": "^2.3.0",
"zod": "^3.23.6"
"zod": "^3.23.7"
},
"devDependencies": {
"@kit/eslint-config": "workspace:^",
"@kit/prettier-config": "workspace:^",
"@kit/tailwind-config": "workspace:^",
"@kit/tsconfig": "workspace:^",
"@next/bundle-analyzer": "14.3.0-canary.9",
"@next/bundle-analyzer": "14.2.3",
"@types/mdx": "^2.0.13",
"@types/node": "^20.12.8",
"@types/react": "^18.3.1",
"@types/react-dom": "^18.3.0",
"autoprefixer": "^10.4.19",
"dotenv-cli": "^7.4.1",
"dotenv-cli": "^7.4.2",
"eslint": "^8.57.0",
"prettier": "^3.2.5",
"supabase": "^1.165.0",
@@ -107,4 +107,4 @@
"> 0.2%",
"not dead"
]
}
}