From 117602ac5e18f571ca94a6cce6fb5c5db0fb6b24 Mon Sep 17 00:00:00 2001 From: gbuomprisco Date: Thu, 5 Sep 2024 15:36:11 +0200 Subject: [PATCH] Add Lemon Squeezy environment variable schema validation and removed NODE_ENV from production variables, as it causes issues in Vercel - Implement `getLemonSqueezyEnv` function to validate required environment variables for Lemon Squeezy integration using `zod`. - Ensure `LEMON_SQUEEZY_SECRET_KEY`, `LEMON_SQUEEZY_SIGNING_SECRET`, and `LEMON_SQUEEZY_STORE_ID` are present and valid. --- apps/web/.env.production | 3 --- .../schema/lemon-squeezy-server-env.schema.ts | 24 ++++++++++++++++--- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/apps/web/.env.production b/apps/web/.env.production index f9ac38874..13f173141 100644 --- a/apps/web/.env.production +++ b/apps/web/.env.production @@ -5,9 +5,6 @@ ## AVOID PLACING SENSITIVE DATA IN THIS FILE. ## PUBLIC KEYS OR CONFIGURATION ARE OKAY TO BE PLACED HERE. -# NODE ENV -NODE_ENV=production - # SUPABASE NEXT_PUBLIC_SUPABASE_URL= diff --git a/packages/billing/lemon-squeezy/src/schema/lemon-squeezy-server-env.schema.ts b/packages/billing/lemon-squeezy/src/schema/lemon-squeezy-server-env.schema.ts index ed3710c53..4cbdeea3d 100644 --- a/packages/billing/lemon-squeezy/src/schema/lemon-squeezy-server-env.schema.ts +++ b/packages/billing/lemon-squeezy/src/schema/lemon-squeezy-server-env.schema.ts @@ -1,11 +1,29 @@ import { z } from 'zod'; +/** + * @name getLemonSqueezyEnv + * @description Get the Lemon Squeezy environment variables. + * It will throw an error if any of the required variables are missing. + */ export const getLemonSqueezyEnv = () => z .object({ - secretKey: z.string().min(1), - webhooksSecret: z.string().min(1), - storeId: z.string(), + secretKey: z + .string({ + description: `The secret key you created for your store. Please use the variable LEMON_SQUEEZY_SECRET_KEY to set it.`, + }) + .min(1), + webhooksSecret: z + .string({ + description: `The shared secret you created for your webhook. Please use the variable LEMON_SQUEEZY_SIGNING_SECRET to set it.`, + }) + .min(1) + .max(40), + storeId: z + .string({ + description: `The ID of your store. Please use the variable LEMON_SQUEEZY_STORE_ID to set it.`, + }) + .min(1), }) .parse({ secretKey: process.env.LEMON_SQUEEZY_SECRET_KEY,