This repository has been archived by the owner on Dec 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(environment): implement assertEnv
- Loading branch information
1 parent
01d11e2
commit fdeae7b
Showing
15 changed files
with
130 additions
and
71 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
import { assertEnv, BlEnvironment } from "../../../config/environment"; | ||
|
||
export class AccessTokenSecret { | ||
public get(): string { | ||
return process.env["ACCESS_TOKEN_SECRET"] ?? "hello this is dog"; | ||
return assertEnv(BlEnvironment.ACCESS_TOKEN_SECRET); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import { assertEnv, BlEnvironment } from "../../../config/environment"; | ||
|
||
export class RefreshTokenSecret { | ||
get(): string { | ||
return ( | ||
process.env["REFRESH_TOKEN_SECRET"] ?? "secretly a string is just chars" | ||
); | ||
return assertEnv(BlEnvironment.REFRESH_TOKEN_SECRET); | ||
} | ||
} |
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,49 @@ | ||
import { BlError } from "@boklisten/bl-model"; | ||
|
||
import { isNullish } from "../helper/typescript-helpers"; | ||
|
||
export enum BlEnvironment { | ||
PORT = "PORT", | ||
SERVER_PATH = "SERVER_PATH", | ||
NODE_ENV = "NODE_ENV", | ||
LOG_LEVEL = "LOG_LEVEL", | ||
URI_WHITELIST = "URI_WHITELIST", | ||
ACCESS_TOKEN_SECRET = "ACCESS_TOKEN_SECRET", | ||
REFRESH_TOKEN_SECRET = "REFRESH_TOKEN_SECRET", | ||
BL_API_URI = "BL_API_URI", | ||
CLIENT_URI = "CLIENT_URI", | ||
MONGODB_URI = "MONGODB_URI", | ||
DIBS_SECRET_KEY = "DIBS_SECRET_KEY", | ||
DIBS_URI = "DIBS_URI", | ||
FACEBOOK_CLIENT_ID = "FACEBOOK_CLIENT_ID", | ||
FACEBOOK_SECRET = "FACEBOOK_SECRET", | ||
GOOGLE_CLIENT_ID = "GOOGLE_CLIENT_ID", | ||
GOOGLE_SECRET = "GOOGLE_SECRET", | ||
SENDGRID_API_KEY = "SENDGRID_API_KEY", | ||
TWILIO_SMS_AUTH_TOKEN = "TWILIO_SMS_AUTH_TOKEN", | ||
TWILIO_SMS_SID = "TWILIO_SMS_SID", | ||
BRING_API_KEY = "BRING_API_KEY", | ||
BRING_API_ID = "BRING_API_ID", | ||
} | ||
|
||
/** | ||
* | ||
* | ||
* @param key the environment variable key | ||
* @param callback optional callback that runs if the environment variable is present, and we are not in a test | ||
* @returns the value of the environment variable if the environment variable is present, and we are not in a test | ||
* | ||
* @throws BlError if the environment variable is not present, and we are not in a test | ||
*/ | ||
export function assertEnv( | ||
key: BlEnvironment, | ||
callback?: (value: string) => unknown, | ||
): string { | ||
const value = process.env[key]; | ||
if (process.env[BlEnvironment.NODE_ENV] === "test") return "placeholder"; | ||
if (isNullish(value)) { | ||
throw new BlError(`${key} is a required environment variable`).code(200); | ||
} | ||
callback?.(value); | ||
return value; | ||
} |
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
Oops, something went wrong.