How to use the envalid.num function in envalid

To help you get started, weā€™ve selected a few envalid examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github tibdex / autorebase / src / tests-utils.ts View on Github external
const createTestContext = async (
  applicationFunction: (app: Application) => void,
): Promise => {
  const env = envalid.cleanEnv(
    // eslint-disable-next-line no-process-env
    process.env,
    {
      TEST_APP_ID: envalid.num({
        desc:
          "The ID of the GitHub App used during tests." +
          " It must have at least the same permissions than the Autorebase GitHub App.",
      }),
      TEST_APP_PRIVATE_KEY: envalid.makeValidator(str => {
        const privateKeyFromEnv = isBase64(str)
          ? Buffer.from(str, "base64").toString("utf8")
          : str;
        if (
          /-----BEGIN RSA PRIVATE KEY-----[\s\S]+-----END RSA PRIVATE KEY-----/m.test(
            privateKeyFromEnv,
          )
        ) {
          return privateKeyFromEnv;
        }
        throw new Error("invalid GitHub App RSA private key");
github flow-typed / flow-typed / definitions / npm / envalid_v4.x.x / flow_v0.104.x- / test_envalid_v4.x.x.js View on Github external
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()
})
github SolidZORO / leaa / packages / leaa-www / server-devenv.ts View on Github external
import path from 'path';
import envalid from 'envalid';
import { IDotEnvServer } from '@leaa/www/interfaces';

const dev = process.env.NODE_ENV !== 'production';

// `next-dotenv-object.js` cannot be used here, because ts compilation will overwrite it
const rootPath = path.resolve(__dirname);
const dotEnvPath = dev ? `${rootPath}/.env` : `${rootPath}/.env.production`;

// @ts-ignore
export const serverDotenv: IDotEnvServer = envalid.cleanEnv(
  process.env,
  { PORT: envalid.num({ devDefault: 3300 }) },
  { dotEnvPath },
);
github SolidZORO / leaa / packages / leaa-api / src / modules / config / config.service.ts View on Github external
PROTOCOL: envalid.str({ choices: ['http', 'https'], default: 'http' }),
      PORT: envalid.port({ default: 5555 }),
      //
      DEMO_MODE: envalid.str({ choices: ['true', 'false'], default: 'false' }),
      DEBUG_MODE: envalid.str({ choices: ['true', 'false'], default: 'false' }),
      //
      BASE_HOST: envalid.str(),
      PUBLIC_DIR: envalid.str(),
      ATTACHMENT_DIR: envalid.str(),
      ATTACHMENT_LIMIT_SIZE_MB: envalid.num(),
      ATTACHMENT_SAVE_IN_LOCAL: envalid.str({ choices: ['true', 'false'], default: 'false' }),
      ATTACHMENT_SAVE_IN_OSS: envalid.str({ choices: ['true', 'false'], default: 'false' }),
      //
      DB_TYPE: envalid.str({ choices: ['mysql'], default: 'mysql' }),
      DB_HOST: envalid.str(),
      DB_PORT: envalid.num(),
      DB_USER: envalid.str(),
      DB_PASSWORD: envalid.str(),
      DB_DATABASE: envalid.str(),
      DB_SYNCHRONIZE: envalid.str(),
      //
      TRUST_PROXY: envalid.str(),
      JWT_SECRET_KEY: envalid.str(),
      CLIENT_COOKIE_EXPIRES_SECOND: envalid.num(),
      SERVER_COOKIE_EXPIRES_SECOND: envalid.num(),
      //
      // OSS_ALIYUN_BUCKET: envalid.str(),
      // OSS_ALIYUN_AK_SECRET: envalid.str(),
      // OSS_ALIYUN_AK_ID: envalid.str(),
      // OSS_ALIYUN_REGION: envalid.str(),
      // OSS_ALIYUN_ASSUME_ROLE: envalid.str(),
      //
github SolidZORO / leaa / packages / leaa-api / src / modules / config / config.service.ts View on Github external
ATTACHMENT_DIR: envalid.str(),
      ATTACHMENT_LIMIT_SIZE_MB: envalid.num(),
      ATTACHMENT_SAVE_IN_LOCAL: envalid.str({ choices: ['true', 'false'], default: 'false' }),
      ATTACHMENT_SAVE_IN_OSS: envalid.str({ choices: ['true', 'false'], default: 'false' }),
      //
      DB_TYPE: envalid.str({ choices: ['mysql'], default: 'mysql' }),
      DB_HOST: envalid.str(),
      DB_PORT: envalid.num(),
      DB_USER: envalid.str(),
      DB_PASSWORD: envalid.str(),
      DB_DATABASE: envalid.str(),
      DB_SYNCHRONIZE: envalid.str(),
      //
      TRUST_PROXY: envalid.str(),
      JWT_SECRET_KEY: envalid.str(),
      CLIENT_COOKIE_EXPIRES_SECOND: envalid.num(),
      SERVER_COOKIE_EXPIRES_SECOND: envalid.num(),
      //
      // OSS_ALIYUN_BUCKET: envalid.str(),
      // OSS_ALIYUN_AK_SECRET: envalid.str(),
      // OSS_ALIYUN_AK_ID: envalid.str(),
      // OSS_ALIYUN_REGION: envalid.str(),
      // OSS_ALIYUN_ASSUME_ROLE: envalid.str(),
      //
      // OAUTH_WECHAT_APP_ID: envalid.str(),
      // OAUTH_WECHAT_APP_SECRET: envalid.str(),
      // OAUTH_WECHAT_MINIPROGRAM_APP_ID: envalid.str(),
      // OAUTH_WECHAT_MINIPROGRAM_APP_SECRET: envalid.str(),
      // OAUTH_WECHAT_TOKEN: envalid.str(),
      // OAUTH_WECHAT_REDIRECT_URL: envalid.str(),
    };
github tibdex / autorebase / src / tests-utils.ts View on Github external
const privateKeyFromEnv = isBase64(str)
          ? Buffer.from(str, "base64").toString("utf8")
          : str;
        if (
          /-----BEGIN RSA PRIVATE KEY-----[\s\S]+-----END RSA PRIVATE KEY-----/m.test(
            privateKeyFromEnv,
          )
        ) {
          return privateKeyFromEnv;
        }
        throw new Error("invalid GitHub App RSA private key");
      })({
        docs:
          "https://developer.github.com/apps/building-integrations/setting-up-and-registering-github-apps/registering-github-apps/#generating-a-private-key",
      }),
      TEST_INSTALLATION_ID: envalid.num({
        desc:
          'Can be found in the "Installed GitHub Apps" section of the developer settings',
      }),
      TEST_REPOSITORY_NAME: envalid.str({
        desc: "Name of the repository against which the tests will be run",
      }),
      TEST_REPOSITORY_OWNER: envalid.str({
        desc: "Owner of the repository against which the tests will be run.",
      }),
      TEST_SMEE_URL: envalid.url({
        desc: "The smee URL used as the webhook URL of the test APP.",
      }),
      TEST_WEBHOOK_SECRET: envalid.str({
        desc: "The webhook secret used by the test App.",
      }),
    },
github poanetwork / tokenbridge-contracts / deploy / src / loadEnv.js View on Github external
if (!validRewardModes.includes(HOME_REWARDABLE)) {
  throw new Error(
    `Invalid HOME_REWARDABLE: ${HOME_REWARDABLE}. Supported values are ${validRewardModes}`
  )
}

if (!validRewardModes.includes(FOREIGN_REWARDABLE)) {
  throw new Error(
    `Invalid FOREIGN_REWARDABLE: ${FOREIGN_REWARDABLE}. Supported values are ${validRewardModes}`
  )
}

let validations = {
  DEPLOYMENT_ACCOUNT_PRIVATE_KEY: envalid.str(),
  DEPLOYMENT_GAS_LIMIT_EXTRA: envalid.num(),
  HOME_DEPLOYMENT_GAS_PRICE: bigNumValidator(),
  FOREIGN_DEPLOYMENT_GAS_PRICE: bigNumValidator(),
  GET_RECEIPT_INTERVAL_IN_MILLISECONDS: bigNumValidator(),
  HOME_RPC_URL: envalid.str(),
  HOME_BRIDGE_OWNER: addressValidator(),
  HOME_VALIDATORS_OWNER: addressesValidator(),
  HOME_UPGRADEABLE_ADMIN: addressValidator(),
  HOME_DAILY_LIMIT: bigNumValidator(),
  HOME_MAX_AMOUNT_PER_TX: bigNumValidator(),
  HOME_MIN_AMOUNT_PER_TX: bigNumValidator(),
  HOME_REQUIRED_BLOCK_CONFIRMATIONS: envalid.num(),
  HOME_GAS_PRICE: bigNumValidator(),
  FOREIGN_RPC_URL: envalid.str(),
  FOREIGN_BRIDGE_OWNER: addressValidator(),
  FOREIGN_VALIDATORS_OWNER: addressValidator(),
  FOREIGN_UPGRADEABLE_ADMIN: addressValidator(),
github poanetwork / tokenbridge-contracts / deploy / src / loadEnv.js View on Github external
FOREIGN_VALIDATORS_OWNER: addressValidator(),
  FOREIGN_UPGRADEABLE_ADMIN: addressValidator(),
  FOREIGN_REQUIRED_BLOCK_CONFIRMATIONS: envalid.num(),
  FOREIGN_GAS_PRICE: bigNumValidator(),
  FOREIGN_MAX_AMOUNT_PER_TX: bigNumValidator(),
  FOREIGN_DAILY_LIMIT: bigNumValidator(),
  REQUIRED_NUMBER_OF_VALIDATORS: envalid.num(),
  VALIDATORS: addressesValidator()
}

if (BRIDGE_MODE === 'NATIVE_TO_ERC') {
  validations = {
    ...validations,
    BRIDGEABLE_TOKEN_NAME: envalid.str(),
    BRIDGEABLE_TOKEN_SYMBOL: envalid.str(),
    BRIDGEABLE_TOKEN_DECIMALS: envalid.num(),
    FOREIGN_MIN_AMOUNT_PER_TX: bigNumValidator(),
    DEPLOY_REWARDABLE_TOKEN: envalid.bool()
  }

  if (DEPLOY_REWARDABLE_TOKEN === 'true') {
    validations = {
      ...validations,
      DPOS_STAKING_ADDRESS: addressValidator(),
      BLOCK_REWARD_ADDRESS: addressValidator()
    }
  }
}

if (BRIDGE_MODE === 'ERC_TO_ERC') {
  validations = {
    ...validations,
github ImmoweltGroup / create-react-microservice / packages / create-react-microservice-scaffold / src / packages / my-fancy-ui-config / src / index.js View on Github external
src: 'packages/my-fancy-ui/src',
    dist: 'packages/my-fancy-ui/dist',
    config: 'packages/my-fancy-ui-config/dist',
    static: 'packages/my-fancy-ui-static-assets'
  },
  requiredVariablesByKey: {
    MY_FANCY_UI_HOST: str({
      default: 'localhost',
      desc: 'The hostname the application will use to spawn the servers on.'
    }),
    MY_FANCY_UI_PORT: num({
      default: 8080,
      desc:
        'The HTTP port of the webserver that will serve the application to the user.'
    }),
    MY_FANCY_UI_SSR_PORT: num({
      default: 8081,
      desc: 'The HTTP port of the hypernova microservice.'
    }),
    MY_FANCY_UI_API_STAGE: str({
      default: 'development',
      desc: 'The stage pointer for the APIĀ“s you use in the service.'
    })
  },
  configsPathsByEnvironmentKey: {
    production: path.join(__dirname, 'index.production.js')
  },
  extend: (config: ConfigType) => ({
    appId: 'my-fancy-ui',

    server: {
      url: `http://${config.env.MY_FANCY_UI_HOST}:${
github poanetwork / tokenbridge-contracts / deploy / src / loadEnv.js View on Github external
}

if (BRIDGE_MODE === 'ERC_TO_NATIVE') {
  validations = {
    ...validations,
    ERC20_TOKEN_ADDRESS: addressValidator(),
    BLOCK_REWARD_ADDRESS: addressValidator({
      default: ZERO_ADDRESS
    })
  }
}

if (HOME_REWARDABLE !== 'false' || FOREIGN_REWARDABLE !== 'false') {
  validations = {
    ...validations,
    HOME_TRANSACTIONS_FEE: envalid.num(),
    FOREIGN_TRANSACTIONS_FEE: envalid.num(),
  }
  if (
    (BRIDGE_MODE === 'ERC_TO_NATIVE' &&
      HOME_REWARDABLE === 'BOTH_DIRECTIONS' &&
      HOME_FEE_MANAGER_TYPE === 'POSDAO_REWARD') ||
    (BRIDGE_MODE === 'ERC_TO_ERC' &&
      HOME_REWARDABLE === 'BOTH_DIRECTIONS')
  ) {
    validations = {
      ...validations,
      BLOCK_REWARD_ADDRESS: addressValidator({
        default: ZERO_ADDRESS
      })
    }
  } else {