Add environment variable validation and parsing

Adds a validation schema for the application's environment variables using the Zod library. The parsed environment variables are then exported as constants that can be imported throughout the application, replacing the direct use of process.env.
This commit is contained in:
Aaron William Po
2023-04-06 23:38:03 -04:00
parent 6b65e09c17
commit 0d3785ad1a
21 changed files with 171 additions and 69 deletions

View File

@@ -1,3 +1,4 @@
import { SPARKPOST_SENDER_ADDRESS } from '../env';
import client from './client';
interface EmailParams {
@@ -7,12 +8,6 @@ interface EmailParams {
subject: string;
}
const { SPARKPOST_SENDER_ADDRESS } = process.env;
if (!SPARKPOST_SENDER_ADDRESS) {
throw new Error('SPARKPOST_SENDER_ADDRESS env variable is not set.');
}
const sendEmail = async ({ address, text, html, subject }: EmailParams) => {
const from = SPARKPOST_SENDER_ADDRESS;