Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import {
bool,
cleanEnv,
email,
host,
json,
port,
num,
str,
url,
type ValidatorSpec
} from 'envalid'
const booleanValidatorSpec: ValidatorSpec = bool()
const numberValidatorSpec: ValidatorSpec = num()
const stringValidatorSpec: ValidatorSpec = str()
const jsonValidatorSpec: ValidatorSpec = json()
const urlValidatorSpec: ValidatorSpec = url()
const emailValidatorSpec: ValidatorSpec = email()
const hostValidatorSpec: ValidatorSpec = host()
const portValidatorSpec: ValidatorSpec = port()
const env1: { NODE_ENV: string, ... } = cleanEnv({ NODE_ENV: 'TEST' }, {
NODE_ENV: str()
})
// $ExpectError
const env2: { NODE_ENV: number, ... } = cleanEnv({ NODE_ENV: 'TEST' }, {
NODE_ENV: str()
})
const urlValidatorSpec: ValidatorSpec = url()
const emailValidatorSpec: ValidatorSpec = email()
const hostValidatorSpec: ValidatorSpec = host()
const portValidatorSpec: ValidatorSpec = port()
const env1: { NODE_ENV: string, ... } = cleanEnv({ NODE_ENV: 'TEST' }, {
NODE_ENV: str()
})
// $ExpectError
const env2: { NODE_ENV: number, ... } = cleanEnv({ NODE_ENV: 'TEST' }, {
NODE_ENV: str()
})
// $ExpectError
const invalidBooleanValidatorSpec: ValidatorSpec = bool()
import envalid, { bool, makeValidator, str } from "envalid";
const bodyParserValidator = makeValidator((value) => {
if (typeof value !== "number") throw new Error("Expected type number");
if (value <= 0) throw new Error("Expected value to be greater than 0");
return value;
});
export default envalid.cleanEnv(process.env, {
BODY_PARSER_SIZE_LIMIT: bodyParserValidator({
default: 5 * 1000000 // value in bytes = 5mb
}),
GRAPHQL_INTROSPECTION_ENABLED: bool({ default: false }),
GRAPHQL_PLAYGROUND_ENABLED: bool({ default: false }),
MIGRATION_BYPASS_ENABLED: bool({
default: false,
desc: "Bypasses migration version checks and migration runs. Enables startup if migration state is not compatible. " +
"This can be dangerous enough to cause data inconsistencies. Use at your own risk!"
}),
// This is necessary to override the envalid default
// validation for NODE_ENV, which uses
// str({ choices: ['development', 'test', 'production'] })
//
// We currently need to set NODE_ENV to "jesttest" when
// integration tests run.
NODE_ENV: str(),
ROOT_URL: str({
devDefault: "http://localhost:3000",
desc: "The protocol, domain, and port portion of the URL, to which relative paths will be appended. " +
"This is used when full URLs are generated for things such as emails and notifications, so it must be publicly accessible.",
example: "https://shop.mydomain.com"
"This can be dangerous enough to cause data inconsistencies. Use at your own risk!"
}),
// This is necessary to override the envalid default
// validation for NODE_ENV, which uses
// str({ choices: ['development', 'test', 'production'] })
//
// We currently need to set NODE_ENV to "jesttest" when
// integration tests run.
NODE_ENV: str(),
ROOT_URL: str({
devDefault: "http://localhost:3000",
desc: "The protocol, domain, and port portion of the URL, to which relative paths will be appended. " +
"This is used when full URLs are generated for things such as emails and notifications, so it must be publicly accessible.",
example: "https://shop.mydomain.com"
}),
SKIP_FIXTURES: bool({ default: false })
});
import envalid, { bool, makeValidator, str } from "envalid";
const bodyParserValidator = makeValidator((value) => {
if (typeof value !== "number") throw new Error("Expected type number");
if (value <= 0) throw new Error("Expected value to be greater than 0");
return value;
});
export default envalid.cleanEnv(process.env, {
BODY_PARSER_SIZE_LIMIT: bodyParserValidator({
default: 5 * 1000000 // value in bytes = 5mb
}),
GRAPHQL_INTROSPECTION_ENABLED: bool({ default: false }),
GRAPHQL_PLAYGROUND_ENABLED: bool({ default: false }),
MIGRATION_BYPASS_ENABLED: bool({
default: false,
desc: "Bypasses migration version checks and migration runs. Enables startup if migration state is not compatible. " +
"This can be dangerous enough to cause data inconsistencies. Use at your own risk!"
}),
// This is necessary to override the envalid default
// validation for NODE_ENV, which uses
// str({ choices: ['development', 'test', 'production'] })
//
// We currently need to set NODE_ENV to "jesttest" when
// integration tests run.
NODE_ENV: str(),
ROOT_URL: str({
devDefault: "http://localhost:3000",
desc: "The protocol, domain, and port portion of the URL, to which relative paths will be appended. " +
"This is used when full URLs are generated for things such as emails and notifications, so it must be publicly accessible.",
import envalid, { bool, makeValidator, str } from "envalid";
const bodyParserValidator = makeValidator((value) => {
if (typeof value !== "number") throw new Error("Expected type number");
if (value <= 0) throw new Error("Expected value to be greater than 0");
return value;
});
export default envalid.cleanEnv(process.env, {
BODY_PARSER_SIZE_LIMIT: bodyParserValidator({
default: 5 * 1000000 // value in bytes = 5mb
}),
GRAPHQL_INTROSPECTION_ENABLED: bool({ default: false }),
GRAPHQL_PLAYGROUND_ENABLED: bool({ default: false }),
MIGRATION_BYPASS_ENABLED: bool({
default: false,
desc: "Bypasses migration version checks and migration runs. Enables startup if migration state is not compatible. " +
"This can be dangerous enough to cause data inconsistencies. Use at your own risk!"
}),
// This is necessary to override the envalid default
// validation for NODE_ENV, which uses
// str({ choices: ['development', 'test', 'production'] })
//
// We currently need to set NODE_ENV to "jesttest" when
// integration tests run.
NODE_ENV: str(),
ROOT_URL: str({
devDefault: "http://localhost:3000",
desc: "The protocol, domain, and port portion of the URL, to which relative paths will be appended. " +
...validations,
DPOS_STAKING_ADDRESS: addressValidator(),
BLOCK_REWARD_ADDRESS: addressValidator()
}
}
}
if (BRIDGE_MODE === 'ERC_TO_ERC') {
validations = {
...validations,
ERC20_TOKEN_ADDRESS: addressValidator(),
BRIDGEABLE_TOKEN_NAME: envalid.str(),
BRIDGEABLE_TOKEN_SYMBOL: envalid.str(),
BRIDGEABLE_TOKEN_DECIMALS: envalid.num(),
DEPLOY_REWARDABLE_TOKEN: envalid.bool(),
ERC20_EXTENDED_BY_ERC677: envalid.bool()
}
if (ERC20_EXTENDED_BY_ERC677 === 'true') {
validations = {
...validations,
FOREIGN_MIN_AMOUNT_PER_TX: bigNumValidator()
}
}
if (DEPLOY_REWARDABLE_TOKEN === 'true') {
validations = {
...validations,
DPOS_STAKING_ADDRESS: addressValidator(),
BLOCK_REWARD_ADDRESS: addressValidator()
}
}
import envalid, { bool } from "envalid";
export default envalid.cleanEnv(process.env, {
AUTO_PUBLISH_INVENTORY_FIELDS: bool({ default: true })
});
validations = {
...validations,
DPOS_STAKING_ADDRESS: addressValidator(),
BLOCK_REWARD_ADDRESS: addressValidator()
}
}
}
if (BRIDGE_MODE === 'ERC_TO_ERC') {
validations = {
...validations,
ERC20_TOKEN_ADDRESS: addressValidator(),
BRIDGEABLE_TOKEN_NAME: envalid.str(),
BRIDGEABLE_TOKEN_SYMBOL: envalid.str(),
BRIDGEABLE_TOKEN_DECIMALS: envalid.num(),
DEPLOY_REWARDABLE_TOKEN: envalid.bool(),
ERC20_EXTENDED_BY_ERC677: envalid.bool()
}
if (ERC20_EXTENDED_BY_ERC677 === 'true') {
validations = {
...validations,
FOREIGN_MIN_AMOUNT_PER_TX: bigNumValidator()
}
}
if (DEPLOY_REWARDABLE_TOKEN === 'true') {
validations = {
...validations,
DPOS_STAKING_ADDRESS: addressValidator(),
BLOCK_REWARD_ADDRESS: addressValidator()
}