-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pdt24 25 | Create a wrapper for environment variables #9
Merged
Merged
Changes from 13 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
ed04c97
feat(fixes): sonar fixes
pratham-outside 8d28b90
chore: added environment variables validation
pratham-outside c5c0a83
Merge branch 'main' into PDT24-25
pratham-outside a0e9c52
chore: add node env in dockercompose file
pratham-outside 351952d
chore: change access of env variables from process.env to env.config …
pratham-outside 03d8a32
chore: edit .env.example file
pratham-outside 58b3343
chore: added environment variables and removed default value in main
pratham-outside f1a5e74
chore: added comment on env example
pratham-outside 5233053
chore: updates on docker compose,package.json and yarn.lock file
pratham-outside 81a71f0
chore: added absolute aliases and renamed variable env
pratham-outside b3e172f
chore: added validation schema and imported dotenv
pratham-outside 1976ee8
chore: removed dotenv import
pratham-outside 6872405
fix: typo
pratham-outside 02a5139
chore: seperated orm configurations
pratham-outside 4d17f87
fix: changed names from validation schema to env schema
pratham-outside 5a59750
chore: fixed type annotations
pratham-outside File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { z } from 'zod'; | ||
export const env = { | ||
POSTGRES_DB: process.env.POSTGRES_DB, | ||
POSTGRES_USER: process.env.POSTGRES_USER, | ||
POSTGRES_PASSWORD: process.env.POSTGRES_PASSWORD, | ||
POSTGRES_PORT: +(process.env.POSTGRES_PORT || 5432), | ||
DB_HOST: process.env.DB_HOST, | ||
APP_PORT: +(process.env.APP_PORT || 3000), | ||
noxiousghost marked this conversation as resolved.
Show resolved
Hide resolved
|
||
NODE_ENV: process.env.NODE_ENV, | ||
EMAIL_HOST: process.env.EMAIL_HOST, | ||
EMAIL_PASS: process.env.EMAIL_PASS, | ||
EMAIL_USER: process.env.EMAIL_USER, | ||
EMAIL_PORT: +(process.env.EMAIL_PORT || 587), | ||
} as const; | ||
|
||
export enum APP_ENVIRONVENT { | ||
DEVELOPMENT = 'development', | ||
PRODUCTION = 'production', | ||
} | ||
|
||
enum SMTP_PORTS { | ||
STANDARD = 25, | ||
DEFAULT = 587, | ||
TLS = 465, | ||
} | ||
const validationSchema = z | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
.object({ | ||
POSTGRES_DB: z.string().min(2, { message: 'Must be atleast 2 characters long' }), | ||
POSTGRES_USER: z.string().min(2, { message: 'Must be atleast 2 characters long' }), | ||
POSTGRES_PASSWORD: z.string().min(2, { message: 'Must be atleast 2 characters long' }), | ||
POSTGRES_PORT: z.number().gt(0, { message: 'Port cannot be empty' }), | ||
DB_HOST: z.string().min(2, { message: 'Must be atleast 2 characters long' }), | ||
APP_PORT: z.number().gt(0, { message: 'Port cannot be empty' }), | ||
NODE_ENV: z.nativeEnum(APP_ENVIRONVENT), | ||
EMAIL_HOST: z.string().min(2, { message: 'Must be atleast 2 characters long' }), | ||
EMAIL_PORT: z.nativeEnum(SMTP_PORTS), | ||
EMAIL_USER: z.string().min(2, { message: 'Must be atleast 2 characters long' }), | ||
EMAIL_PASS: z.string().min(2, { message: 'Must be atleast 2 characters long' }), | ||
}) | ||
.required(); | ||
|
||
type ValidationSchema = z.infer<typeof validationSchema>; | ||
|
||
export const validate = (): ValidationSchema => { | ||
const value = validationSchema.safeParse(env); | ||
if (!value.success) { | ||
throw new Error(`---${value.error.issues[0].path} :: ${value.error.issues[0].message.toUpperCase()}---`); | ||
noxiousghost marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
return value.data; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1623,7 +1623,7 @@ [email protected]: | |
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-16.4.5.tgz#cdd3b3b604cb327e286b4762e13502f717cb099f" | ||
integrity sha512-ZmdL2rui+eB2YwhsWzjInR8LldtZHGDoQ1ugH85ppHKwpUHL7j7rN0Ti9NCnGiQbhaZ11FpR+7ao1dNsmduNUg== | ||
|
||
dotenv@^16.0.3: | ||
dotenv@^16.0.3, dotenv@^16.4.7: | ||
version "16.4.7" | ||
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-16.4.7.tgz#0e20c5b82950140aa99be360a8a5f52335f53c26" | ||
integrity sha512-47qPchRCykZC03FhkYAhrvwU4xDBFIj1QPqaarj6mdM/hgUzfPHcpkHJOn3mJAufFeeAxAzeGsr5X0M4k6fLZQ== | ||
|
@@ -4375,3 +4375,8 @@ yocto-queue@^1.0.0: | |
version "1.1.1" | ||
resolved "https://registry.yarnpkg.com/yocto-queue/-/yocto-queue-1.1.1.tgz#fef65ce3ac9f8a32ceac5a634f74e17e5b232110" | ||
integrity sha512-b4JR1PFR10y1mKjhHY9LaGo6tmrgjit7hxVIeAmyMw3jegXR4dhYqLaQF5zMXZxY7tLpMyJeLjr1C4rLmkVe8g== | ||
|
||
zod@^3.24.1: | ||
version "3.24.1" | ||
resolved "https://registry.yarnpkg.com/zod/-/zod-3.24.1.tgz#27445c912738c8ad1e9de1bea0359fa44d9d35ee" | ||
integrity sha512-muH7gBL9sI1nciMZV67X5fTKKBLtwpZ5VBp1vsOQzj1MhrBZ4wlVCm3gedKZWLp0Oyel8sIGfeiz54Su+OVT+A== |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this file be ignored @pratham-outside