Replace Logger with getLogger and update next version
This commit replaces the use of Logger with getLogger in various parts of the code to handle logging. The Logger has been replaced with getLogger, which assists in getting logs in an asynchronous manner. In addition to this, it updates the next version in pnpm-lock.yaml from next@14.2.0-canary.61 to next@14.2.0-canary.62 and various other dependencies. Also made minor annotations and comments to the function 'isBrowser' and 'formatCurrency' in the 'utils.ts' file.
This commit is contained in:
@@ -16,7 +16,7 @@ import {
|
||||
RetrieveCheckoutSessionSchema,
|
||||
UpdateSubscriptionParamsSchema,
|
||||
} from '@kit/billing/schema';
|
||||
import { Logger } from '@kit/shared/logger';
|
||||
import { getLogger } from '@kit/shared/logger';
|
||||
|
||||
import { createLemonSqueezyBillingPortalSession } from './create-lemon-squeezy-billing-portal-session';
|
||||
import { createLemonSqueezyCheckout } from './create-lemon-squeezy-checkout';
|
||||
@@ -27,13 +27,12 @@ export class LemonSqueezyBillingStrategyService
|
||||
async createCheckoutSession(
|
||||
params: z.infer<typeof CreateBillingCheckoutSchema>,
|
||||
) {
|
||||
Logger.info(
|
||||
const logger = await getLogger();
|
||||
|
||||
logger.info(
|
||||
{
|
||||
name: 'billing.lemon-squeezy',
|
||||
customerId: params.customerId,
|
||||
accountId: params.accountId,
|
||||
returnUrl: params.returnUrl,
|
||||
trialDays: params.trialDays,
|
||||
...params,
|
||||
},
|
||||
'Creating checkout session...',
|
||||
);
|
||||
@@ -43,7 +42,7 @@ export class LemonSqueezyBillingStrategyService
|
||||
if (error ?? !response?.data.id) {
|
||||
console.log(error);
|
||||
|
||||
Logger.error(
|
||||
logger.error(
|
||||
{
|
||||
name: 'billing.lemon-squeezy',
|
||||
customerId: params.customerId,
|
||||
@@ -56,7 +55,7 @@ export class LemonSqueezyBillingStrategyService
|
||||
throw new Error('Failed to create checkout session');
|
||||
}
|
||||
|
||||
Logger.info(
|
||||
logger.info(
|
||||
{
|
||||
name: 'billing.lemon-squeezy',
|
||||
customerId: params.customerId,
|
||||
@@ -73,7 +72,9 @@ export class LemonSqueezyBillingStrategyService
|
||||
async createBillingPortalSession(
|
||||
params: z.infer<typeof CreateBillingPortalSessionSchema>,
|
||||
) {
|
||||
Logger.info(
|
||||
const logger = await getLogger();
|
||||
|
||||
logger.info(
|
||||
{
|
||||
name: 'billing.lemon-squeezy',
|
||||
customerId: params.customerId,
|
||||
@@ -85,7 +86,7 @@ export class LemonSqueezyBillingStrategyService
|
||||
await createLemonSqueezyBillingPortalSession(params);
|
||||
|
||||
if (error ?? !data) {
|
||||
Logger.error(
|
||||
logger.error(
|
||||
{
|
||||
name: 'billing.lemon-squeezy',
|
||||
customerId: params.customerId,
|
||||
@@ -97,7 +98,7 @@ export class LemonSqueezyBillingStrategyService
|
||||
throw new Error('Failed to create billing portal session');
|
||||
}
|
||||
|
||||
Logger.info(
|
||||
logger.info(
|
||||
{
|
||||
name: 'billing.lemon-squeezy',
|
||||
customerId: params.customerId,
|
||||
@@ -111,7 +112,9 @@ export class LemonSqueezyBillingStrategyService
|
||||
async cancelSubscription(
|
||||
params: z.infer<typeof CancelSubscriptionParamsSchema>,
|
||||
) {
|
||||
Logger.info(
|
||||
const logger = await getLogger();
|
||||
|
||||
logger.info(
|
||||
{
|
||||
name: 'billing.lemon-squeezy',
|
||||
subscriptionId: params.subscriptionId,
|
||||
@@ -123,7 +126,7 @@ export class LemonSqueezyBillingStrategyService
|
||||
const { error } = await cancelSubscription(params.subscriptionId);
|
||||
|
||||
if (error) {
|
||||
Logger.error(
|
||||
logger.error(
|
||||
{
|
||||
name: 'billing.lemon-squeezy',
|
||||
subscriptionId: params.subscriptionId,
|
||||
@@ -135,7 +138,7 @@ export class LemonSqueezyBillingStrategyService
|
||||
throw error;
|
||||
}
|
||||
|
||||
Logger.info(
|
||||
logger.info(
|
||||
{
|
||||
name: 'billing.lemon-squeezy',
|
||||
subscriptionId: params.subscriptionId,
|
||||
@@ -145,7 +148,7 @@ export class LemonSqueezyBillingStrategyService
|
||||
|
||||
return { success: true };
|
||||
} catch (error) {
|
||||
Logger.error(
|
||||
logger.error(
|
||||
{
|
||||
name: 'billing.lemon-squeezy',
|
||||
subscriptionId: params.subscriptionId,
|
||||
@@ -161,7 +164,9 @@ export class LemonSqueezyBillingStrategyService
|
||||
async retrieveCheckoutSession(
|
||||
params: z.infer<typeof RetrieveCheckoutSessionSchema>,
|
||||
) {
|
||||
Logger.info(
|
||||
const logger = await getLogger();
|
||||
|
||||
logger.info(
|
||||
{
|
||||
name: 'billing.lemon-squeezy',
|
||||
sessionId: params.sessionId,
|
||||
@@ -172,7 +177,7 @@ export class LemonSqueezyBillingStrategyService
|
||||
const { data: session, error } = await getCheckout(params.sessionId);
|
||||
|
||||
if (error ?? !session?.data) {
|
||||
Logger.error(
|
||||
logger.error(
|
||||
{
|
||||
name: 'billing.lemon-squeezy',
|
||||
sessionId: params.sessionId,
|
||||
@@ -184,7 +189,7 @@ export class LemonSqueezyBillingStrategyService
|
||||
throw new Error('Failed to retrieve checkout session');
|
||||
}
|
||||
|
||||
Logger.info(
|
||||
logger.info(
|
||||
{
|
||||
name: 'billing.lemon-squeezy',
|
||||
sessionId: params.sessionId,
|
||||
@@ -205,7 +210,9 @@ export class LemonSqueezyBillingStrategyService
|
||||
}
|
||||
|
||||
async reportUsage(params: z.infer<typeof ReportBillingUsageSchema>) {
|
||||
Logger.info(
|
||||
const logger = await getLogger();
|
||||
|
||||
logger.info(
|
||||
{
|
||||
name: 'billing.lemon-squeezy',
|
||||
subscriptionItemId: params.subscriptionItemId,
|
||||
@@ -220,11 +227,11 @@ export class LemonSqueezyBillingStrategyService
|
||||
});
|
||||
|
||||
if (error) {
|
||||
Logger.error(
|
||||
logger.error(
|
||||
{
|
||||
name: 'billing.lemon-squeezy',
|
||||
subscriptionItemId: params.subscriptionItemId,
|
||||
error: error.message,
|
||||
error,
|
||||
},
|
||||
'Failed to report usage',
|
||||
);
|
||||
@@ -232,7 +239,7 @@ export class LemonSqueezyBillingStrategyService
|
||||
throw new Error('Failed to report usage');
|
||||
}
|
||||
|
||||
Logger.info(
|
||||
logger.info(
|
||||
{
|
||||
name: 'billing.lemon-squeezy',
|
||||
subscriptionItemId: params.subscriptionItemId,
|
||||
@@ -246,19 +253,21 @@ export class LemonSqueezyBillingStrategyService
|
||||
async updateSubscription(
|
||||
params: z.infer<typeof UpdateSubscriptionParamsSchema>,
|
||||
) {
|
||||
const logger = await getLogger();
|
||||
|
||||
const ctx = {
|
||||
name: 'billing.lemon-squeezy',
|
||||
...params,
|
||||
};
|
||||
|
||||
Logger.info(ctx, 'Updating subscription...');
|
||||
logger.info(ctx, 'Updating subscription...');
|
||||
|
||||
const { error } = await updateSubscriptionItem(params.subscriptionItemId, {
|
||||
quantity: params.quantity,
|
||||
});
|
||||
|
||||
if (error) {
|
||||
Logger.error(
|
||||
logger.error(
|
||||
{
|
||||
...ctx,
|
||||
error,
|
||||
@@ -269,7 +278,7 @@ export class LemonSqueezyBillingStrategyService
|
||||
throw error;
|
||||
}
|
||||
|
||||
Logger.info(ctx, 'Subscription updated successfully');
|
||||
logger.info(ctx, 'Subscription updated successfully');
|
||||
|
||||
return { success: true };
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import 'server-only';
|
||||
|
||||
import { Logger } from '@kit/shared/logger';
|
||||
import { getLogger } from '@kit/shared/logger';
|
||||
|
||||
import { getLemonSqueezyEnv } from '../schema/lemon-squeezy-server-env.schema';
|
||||
|
||||
@@ -10,11 +10,12 @@ import { getLemonSqueezyEnv } from '../schema/lemon-squeezy-server-env.schema';
|
||||
export async function initializeLemonSqueezyClient() {
|
||||
const { lemonSqueezySetup } = await import('@lemonsqueezy/lemonsqueezy.js');
|
||||
const env = getLemonSqueezyEnv();
|
||||
const logger = await getLogger();
|
||||
|
||||
lemonSqueezySetup({
|
||||
apiKey: env.secretKey,
|
||||
onError(error) {
|
||||
Logger.error(
|
||||
logger.error(
|
||||
{
|
||||
name: `billing.lemon-squeezy`,
|
||||
error: error.message,
|
||||
|
||||
@@ -6,7 +6,7 @@ import {
|
||||
BillingWebhookHandlerService,
|
||||
getLineItemTypeById,
|
||||
} from '@kit/billing';
|
||||
import { Logger } from '@kit/shared/logger';
|
||||
import { getLogger } from '@kit/shared/logger';
|
||||
import { Database } from '@kit/supabase/database';
|
||||
|
||||
import { getLemonSqueezyEnv } from '../schema/lemon-squeezy-server-env.schema';
|
||||
@@ -45,6 +45,9 @@ export class LemonSqueezyWebhookHandlerService
|
||||
* @description Verifies the webhook signature - should throw an error if the signature is invalid
|
||||
*/
|
||||
async verifyWebhookSignature(request: Request) {
|
||||
const logger = await getLogger();
|
||||
|
||||
// get the event name and signature from the headers
|
||||
const eventName = request.headers.get('x-event-name');
|
||||
const signature = request.headers.get('x-signature') as string;
|
||||
|
||||
@@ -53,8 +56,9 @@ export class LemonSqueezyWebhookHandlerService
|
||||
const body = (await request.json()) as SubscriptionWebhook | OrderWebhook;
|
||||
const rawBody = await reqClone.text();
|
||||
|
||||
// if no signature is found, throw an error
|
||||
if (!signature) {
|
||||
Logger.error(
|
||||
logger.error(
|
||||
{
|
||||
eventName,
|
||||
},
|
||||
@@ -64,8 +68,9 @@ export class LemonSqueezyWebhookHandlerService
|
||||
throw new Error('Signature header not found');
|
||||
}
|
||||
|
||||
// if the signature is invalid, throw an error
|
||||
if (!isSigningSecretValid(Buffer.from(rawBody), signature)) {
|
||||
Logger.error(
|
||||
logger.error(
|
||||
{
|
||||
eventName,
|
||||
},
|
||||
@@ -124,7 +129,9 @@ export class LemonSqueezyWebhookHandlerService
|
||||
}
|
||||
|
||||
default: {
|
||||
Logger.info(
|
||||
const logger = await getLogger();
|
||||
|
||||
logger.info(
|
||||
{
|
||||
eventType: eventName,
|
||||
name: this.namespace,
|
||||
@@ -211,7 +218,9 @@ export class LemonSqueezyWebhookHandlerService
|
||||
const { data: order, error } = await getOrder(orderId);
|
||||
|
||||
if (error ?? !order) {
|
||||
Logger.error(
|
||||
const logger = await getLogger();
|
||||
|
||||
logger.error(
|
||||
{
|
||||
orderId,
|
||||
subscriptionId,
|
||||
|
||||
Reference in New Issue
Block a user