Update packages and refactor logging in diverse services
This commit updates diverse packages such as "@makerkit/data-loader-supabase-core" and "@makerkit/data-loader-supabase-nextjs" to the new versions in the package.json files. Also, several refactorings were done in logging within services and loaders by progressing 'server-only' imports and improving context handling. Additionally, type annotations have been added to several exported functions for better code readability and maintainability.
This commit is contained in:
@@ -15,7 +15,6 @@ import {
|
||||
getPrimaryLineItem,
|
||||
getProductPlanPair,
|
||||
} from '@kit/billing';
|
||||
import config from '@kit/prettier-config/index.mjs';
|
||||
import { formatCurrency } from '@kit/shared/utils';
|
||||
import { Badge } from '@kit/ui/badge';
|
||||
import { Button } from '@kit/ui/button';
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import 'server-only';
|
||||
|
||||
import { SupabaseClient } from '@supabase/supabase-js';
|
||||
|
||||
import { BillingWebhookHandlerService } from '@kit/billing';
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import 'server-only';
|
||||
|
||||
import { z } from 'zod';
|
||||
|
||||
import {
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import 'server-only';
|
||||
|
||||
import { BillingConfig } from '@kit/billing';
|
||||
import { Database } from '@kit/supabase/database';
|
||||
import { getSupabaseServerActionClient } from '@kit/supabase/server-actions-client';
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import 'server-only';
|
||||
|
||||
import { z } from 'zod';
|
||||
|
||||
import {
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import 'server-only';
|
||||
|
||||
import { getSupabaseServerActionClient } from '@kit/supabase/server-actions-client';
|
||||
|
||||
import { BillingGatewayService } from './billing-gateway.service';
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import 'server-only';
|
||||
|
||||
import { z } from 'zod';
|
||||
|
||||
import { BillingProviderSchema } from '@kit/billing';
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import 'server-only';
|
||||
|
||||
import { Database } from '@kit/supabase/database';
|
||||
|
||||
import { BillingGatewayService } from '../billing-gateway/billing-gateway.service';
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import 'server-only';
|
||||
|
||||
import {
|
||||
cancelSubscription,
|
||||
createUsageRecord,
|
||||
getCheckout,
|
||||
updateSubscriptionItem,
|
||||
} from '@lemonsqueezy/lemonsqueezy.js';
|
||||
import 'server-only';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { BillingStrategyProviderService } from '@kit/billing';
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import 'server-only';
|
||||
|
||||
import type { Stripe } from 'stripe';
|
||||
import { z } from 'zod';
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import 'server-only';
|
||||
|
||||
import { SupabaseClient } from '@supabase/supabase-js';
|
||||
|
||||
import { getLogger } from '@kit/shared/logger';
|
||||
@@ -35,11 +37,9 @@ export class DeletePersonalAccountService {
|
||||
}) {
|
||||
const userId = params.userId;
|
||||
const logger = await getLogger();
|
||||
const ctx = { userId, name: this.namespace };
|
||||
|
||||
logger.info(
|
||||
{ name: this.namespace, userId },
|
||||
'User requested deletion. Processing...',
|
||||
);
|
||||
logger.info(ctx, 'User requested deletion. Processing...');
|
||||
|
||||
// execute the deletion of the user
|
||||
try {
|
||||
@@ -47,8 +47,7 @@ export class DeletePersonalAccountService {
|
||||
} catch (error) {
|
||||
logger.error(
|
||||
{
|
||||
name: this.namespace,
|
||||
userId,
|
||||
...ctx,
|
||||
error,
|
||||
},
|
||||
'Error deleting user',
|
||||
@@ -57,6 +56,6 @@ export class DeletePersonalAccountService {
|
||||
throw new Error('Error deleting user');
|
||||
}
|
||||
|
||||
logger.info({ name: this.namespace, userId }, 'User deleted successfully');
|
||||
logger.info(ctx, 'User deleted successfully');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,8 +14,8 @@
|
||||
"@kit/next": "workspace:*",
|
||||
"@kit/supabase": "workspace:*",
|
||||
"@kit/ui": "workspace:*",
|
||||
"@makerkit/data-loader-supabase-core": "0.0.5",
|
||||
"@makerkit/data-loader-supabase-nextjs": "^0.0.7",
|
||||
"@makerkit/data-loader-supabase-core": "^0.0.7",
|
||||
"@makerkit/data-loader-supabase-nextjs": "^0.0.9",
|
||||
"lucide-react": "^0.363.0",
|
||||
"react-hook-form": "^7.51.2",
|
||||
"zod": "^3.22.4"
|
||||
@@ -29,8 +29,8 @@
|
||||
"@kit/tailwind-config": "workspace:*",
|
||||
"@kit/tsconfig": "workspace:*",
|
||||
"@kit/ui": "workspace:^",
|
||||
"@makerkit/data-loader-supabase-core": "0.0.5",
|
||||
"@makerkit/data-loader-supabase-nextjs": "^0.0.7",
|
||||
"@makerkit/data-loader-supabase-core": "^0.0.7",
|
||||
"@makerkit/data-loader-supabase-nextjs": "^0.0.9",
|
||||
"@supabase/supabase-js": "^2.42.0",
|
||||
"lucide-react": "^0.363.0",
|
||||
"react-hook-form": "^7.51.2",
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { BadgeX, Ban, ShieldPlus, Trash, VenetianMask } from 'lucide-react';
|
||||
import { BadgeX, Ban, ShieldPlus, VenetianMask } from 'lucide-react';
|
||||
|
||||
import { Database } from '@kit/supabase/database';
|
||||
import { getSupabaseServerComponentClient } from '@kit/supabase/server-component-client';
|
||||
|
||||
@@ -4,6 +4,11 @@ import { getSupabaseServerActionClient } from '@kit/supabase/server-actions-clie
|
||||
|
||||
import { isSuperAdmin } from './is-super-admin';
|
||||
|
||||
/**
|
||||
* @name enhanceAdminAction
|
||||
* @description Wrap a server action to ensure the user is a super admin.
|
||||
* @param fn
|
||||
*/
|
||||
export function enhanceAdminAction<Args, Response>(
|
||||
fn: (params: Args) => Response,
|
||||
) {
|
||||
|
||||
@@ -2,6 +2,11 @@ import { SupabaseClient } from '@supabase/supabase-js';
|
||||
|
||||
import { Database } from '@kit/supabase/database';
|
||||
|
||||
/**
|
||||
* @name isSuperAdmin
|
||||
* @description Check if the current user is a super admin.
|
||||
* @param client
|
||||
*/
|
||||
export async function isSuperAdmin(client: SupabaseClient<Database>) {
|
||||
const { data, error } = await client.auth.getUser();
|
||||
|
||||
|
||||
@@ -1,5 +1,12 @@
|
||||
import 'server-only';
|
||||
|
||||
import { getSupabaseServerComponentClient } from '@kit/supabase/server-component-client';
|
||||
|
||||
/**
|
||||
* @name loadAdminDashboard
|
||||
* @description Load the admin dashboard data.
|
||||
* @param params
|
||||
*/
|
||||
export async function loadAdminDashboard(params?: {
|
||||
count: 'exact' | 'estimated' | 'planned';
|
||||
}) {
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import 'server-only';
|
||||
|
||||
import { SupabaseClient } from '@supabase/supabase-js';
|
||||
|
||||
import { Database } from '@kit/supabase/database';
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import 'server-only';
|
||||
|
||||
import { SupabaseClient } from '@supabase/supabase-js';
|
||||
|
||||
import { Database } from '@kit/supabase/database';
|
||||
|
||||
@@ -50,7 +50,7 @@ export function EmailPasswordSignUpContainer({
|
||||
console.error(error);
|
||||
}
|
||||
},
|
||||
[emailRedirectTo, loading, onSignUp, signUpMutation],
|
||||
[captchaToken, emailRedirectTo, loading, onSignUp, signUpMutation],
|
||||
);
|
||||
|
||||
return (
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import 'server-only';
|
||||
|
||||
import { SupabaseClient } from '@supabase/supabase-js';
|
||||
|
||||
import { addDays, formatISO } from 'date-fns';
|
||||
import 'server-only';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { getLogger } from '@kit/shared/logger';
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'server-only';
|
||||
|
||||
import { SupabaseClient } from '@supabase/supabase-js';
|
||||
|
||||
import 'server-only';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { getLogger } from '@kit/shared/logger';
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import 'server-only';
|
||||
|
||||
import { SupabaseClient } from '@supabase/supabase-js';
|
||||
|
||||
import { BillingGatewayService } from '@kit/billing-gateway';
|
||||
@@ -11,12 +13,10 @@ export class AccountPerSeatBillingService {
|
||||
|
||||
async getPerSeatSubscriptionItem(accountId: string) {
|
||||
const logger = await getLogger();
|
||||
const ctx = { accountId, name: this.namespace };
|
||||
|
||||
logger.info(
|
||||
{
|
||||
name: this.namespace,
|
||||
accountId,
|
||||
},
|
||||
ctx,
|
||||
`Getting per-seat subscription item for account ${accountId}...`,
|
||||
);
|
||||
|
||||
@@ -40,8 +40,7 @@ export class AccountPerSeatBillingService {
|
||||
if (error) {
|
||||
logger.error(
|
||||
{
|
||||
name: this.namespace,
|
||||
accountId,
|
||||
...ctx,
|
||||
error,
|
||||
},
|
||||
`Failed to get per-seat subscription item for account ${accountId}`,
|
||||
@@ -52,7 +51,7 @@ export class AccountPerSeatBillingService {
|
||||
|
||||
if (!data?.subscription_items) {
|
||||
logger.info(
|
||||
{ name: this.namespace, accountId },
|
||||
ctx,
|
||||
`No per-seat subscription item found for account ${accountId}. Exiting...`,
|
||||
);
|
||||
|
||||
@@ -60,10 +59,7 @@ export class AccountPerSeatBillingService {
|
||||
}
|
||||
|
||||
logger.info(
|
||||
{
|
||||
name: this.namespace,
|
||||
accountId,
|
||||
},
|
||||
ctx,
|
||||
`Per-seat subscription item found for account ${accountId}. Will update...`,
|
||||
);
|
||||
|
||||
@@ -88,14 +84,13 @@ export class AccountPerSeatBillingService {
|
||||
|
||||
const billingGateway = new BillingGatewayService(subscription.provider);
|
||||
|
||||
logger.info(
|
||||
{
|
||||
name: this.namespace,
|
||||
accountId,
|
||||
subscriptionItems,
|
||||
},
|
||||
`Increasing seats for account ${accountId}...`,
|
||||
);
|
||||
const ctx = {
|
||||
name: this.namespace,
|
||||
accountId,
|
||||
subscriptionItems,
|
||||
};
|
||||
|
||||
logger.info(ctx, `Increasing seats for account ${accountId}...`);
|
||||
|
||||
const promises = subscriptionItems.map(async (item) => {
|
||||
try {
|
||||
@@ -127,8 +122,7 @@ export class AccountPerSeatBillingService {
|
||||
} catch (error) {
|
||||
logger.error(
|
||||
{
|
||||
name: this.namespace,
|
||||
accountId,
|
||||
...ctx,
|
||||
error,
|
||||
},
|
||||
`Failed to increase seats for account ${accountId}`,
|
||||
@@ -155,14 +149,13 @@ export class AccountPerSeatBillingService {
|
||||
return;
|
||||
}
|
||||
|
||||
logger.info(
|
||||
{
|
||||
name: this.namespace,
|
||||
accountId,
|
||||
subscriptionItems,
|
||||
},
|
||||
`Decreasing seats for account ${accountId}...`,
|
||||
);
|
||||
const ctx = {
|
||||
name: this.namespace,
|
||||
accountId,
|
||||
subscriptionItems,
|
||||
};
|
||||
|
||||
logger.info(ctx, `Decreasing seats for account ${accountId}...`);
|
||||
|
||||
const billingGateway = new BillingGatewayService(subscription.provider);
|
||||
|
||||
@@ -196,8 +189,7 @@ export class AccountPerSeatBillingService {
|
||||
} catch (error) {
|
||||
logger.error(
|
||||
{
|
||||
name: this.namespace,
|
||||
accountId,
|
||||
...ctx,
|
||||
error,
|
||||
},
|
||||
`Failed to decrease seats for account ${accountId}`,
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import 'server-only';
|
||||
|
||||
import { SupabaseClient } from '@supabase/supabase-js';
|
||||
|
||||
import { getLogger } from '@kit/shared/logger';
|
||||
@@ -10,11 +12,9 @@ export class CreateTeamAccountService {
|
||||
|
||||
async createNewOrganizationAccount(params: { name: string; userId: string }) {
|
||||
const logger = await getLogger();
|
||||
const ctx = { ...params, namespace: this.namespace };
|
||||
|
||||
logger.info(
|
||||
{ ...params, namespace: this.namespace },
|
||||
`Creating new team account...`,
|
||||
);
|
||||
logger.info(ctx, `Creating new team account...`);
|
||||
|
||||
return await this.client.rpc('create_account', {
|
||||
account_name: params.name,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { SupabaseClient } from '@supabase/supabase-js';
|
||||
|
||||
import 'server-only';
|
||||
|
||||
import { SupabaseClient } from '@supabase/supabase-js';
|
||||
|
||||
import { getLogger } from '@kit/shared/logger';
|
||||
import { Database } from '@kit/supabase/database';
|
||||
|
||||
@@ -26,14 +26,13 @@ export class DeleteTeamAccountService {
|
||||
) {
|
||||
const logger = await getLogger();
|
||||
|
||||
logger.info(
|
||||
{
|
||||
name: this.namespace,
|
||||
accountId: params.accountId,
|
||||
userId: params.userId,
|
||||
},
|
||||
`Requested team account deletion. Processing...`,
|
||||
);
|
||||
const ctx = {
|
||||
accountId: params.accountId,
|
||||
userId: params.userId,
|
||||
name: this.namespace,
|
||||
};
|
||||
|
||||
logger.info(ctx, `Requested team account deletion. Processing...`);
|
||||
|
||||
// we can use the admin client to delete the account.
|
||||
const { error } = await adminClient
|
||||
@@ -44,9 +43,7 @@ export class DeleteTeamAccountService {
|
||||
if (error) {
|
||||
logger.error(
|
||||
{
|
||||
name: this.namespace,
|
||||
accountId: params.accountId,
|
||||
userId: params.userId,
|
||||
...ctx,
|
||||
error,
|
||||
},
|
||||
'Failed to delete team account',
|
||||
@@ -55,13 +52,6 @@ export class DeleteTeamAccountService {
|
||||
throw new Error('Failed to delete team account');
|
||||
}
|
||||
|
||||
logger.info(
|
||||
{
|
||||
name: this.namespace,
|
||||
accountId: params.accountId,
|
||||
userId: params.userId,
|
||||
},
|
||||
'Successfully deleted team account',
|
||||
);
|
||||
logger.info(ctx, 'Successfully deleted team account');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'server-only';
|
||||
|
||||
import { SupabaseClient } from '@supabase/supabase-js';
|
||||
|
||||
import 'server-only';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { getLogger } from '@kit/shared/logger';
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import 'server-only';
|
||||
|
||||
import { z } from 'zod';
|
||||
|
||||
import { Mailer } from '../../mailer';
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import 'server-only';
|
||||
|
||||
import { z } from 'zod';
|
||||
|
||||
import { Mailer } from '../../mailer';
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import 'server-only';
|
||||
|
||||
import { redirect } from 'next/navigation';
|
||||
|
||||
import type { User } from '@supabase/supabase-js';
|
||||
|
||||
import 'server-only';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { verifyCaptchaToken } from '@kit/auth/captcha/server';
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import 'server-only';
|
||||
|
||||
import { redirect } from 'next/navigation';
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
|
||||
import { User } from '@supabase/supabase-js';
|
||||
|
||||
import 'server-only';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { verifyCaptchaToken } from '@kit/auth/captcha/server';
|
||||
|
||||
@@ -4,11 +4,11 @@ export const zodParseFactory =
|
||||
<T extends z.ZodTypeAny>(schema: T) =>
|
||||
(data: unknown): z.infer<T> => {
|
||||
try {
|
||||
return schema.parse(data);
|
||||
return schema.parse(data) as unknown;
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
|
||||
// handle error
|
||||
throw new Error(`Invalid data: ${err}`);
|
||||
throw new Error(`Invalid data: ${err as string}`);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import 'server-only';
|
||||
|
||||
import { cookies } from 'next/headers';
|
||||
|
||||
import type { CookieOptions } from '@supabase/ssr';
|
||||
import { createServerClient } from '@supabase/ssr';
|
||||
import 'server-only';
|
||||
|
||||
import { Database } from '../database.types';
|
||||
import { getSupabaseClientKeys } from '../get-supabase-client-keys';
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import 'server-only';
|
||||
|
||||
import { cookies } from 'next/headers';
|
||||
|
||||
import { createServerClient } from '@supabase/ssr';
|
||||
import 'server-only';
|
||||
|
||||
import { Database } from '../database.types';
|
||||
import { getSupabaseClientKeys } from '../get-supabase-client-keys';
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import 'server-only';
|
||||
|
||||
import { cookies } from 'next/headers';
|
||||
|
||||
import { createServerClient } from '@supabase/ssr';
|
||||
import 'server-only';
|
||||
|
||||
import { Database } from '../database.types';
|
||||
import { getSupabaseClientKeys } from '../get-supabase-client-keys';
|
||||
|
||||
@@ -38,7 +38,7 @@
|
||||
"@tanstack/react-table": "^8.10.7",
|
||||
"class-variance-authority": "^0.7.0",
|
||||
"date-fns": "^3.2.0",
|
||||
"lucide-react": "^0.364.0",
|
||||
"lucide-react": "^0.366.0",
|
||||
"react-hook-form": "^7.51.2",
|
||||
"react-i18next": "^14.1.0",
|
||||
"sonner": "^1.4.41",
|
||||
|
||||
Reference in New Issue
Block a user