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.
* refactor(dotenv): use esm import * feat(email-service): setup email templates * deps: bump @sendgrid/mail * feat(environment): implement assertEnv * feat(env): add dotenv to mocha * ci: add test placeholders for env * ci: update GH Actions versions
- Loading branch information
1 parent
bd29484
commit 9d97490
Showing
18 changed files
with
203 additions
and
103 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
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,52 @@ | ||
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", | ||
} | ||
|
||
const testPlaceHolders: { | ||
[key in BlEnvironment]?: string; | ||
} = { | ||
[BlEnvironment.SENDGRID_API_KEY]: "SG.placeholder", | ||
[BlEnvironment.TWILIO_SMS_SID]: "AC.placeholder", | ||
}; | ||
|
||
/** | ||
* | ||
* | ||
* @param key the environment variable key | ||
* @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): string { | ||
const value = process.env[key]; | ||
if (process.env[BlEnvironment.NODE_ENV] === "test") | ||
return testPlaceHolders[key] ?? "placeholder"; | ||
if (isNullish(value)) { | ||
throw new BlError(`${key} is a required environment variable`).code(200); | ||
} | ||
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
Oops, something went wrong.