Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@thinkmill/devops-env-vars

Package Overview
Dependencies
Maintainers
9
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@thinkmill/devops-env-vars - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

2

package.json
{
"name": "@thinkmill/devops-env-vars",
"version": "1.0.0",
"version": "1.0.1",
"description": "Helper functions that encapsulate our treatment of environment vars for KeystoneJS apps",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -11,62 +11,64 @@ Devops: Environment Variables

'use strict';
```javascript
'use strict';
const envLib = require('@thinkmill/devops-env-vars');
const path = require('path');
const dotenv = require('dotenv');
const envLib = require('@thinkmill/devops-env-vars');
const path = require('path');
const dotenv = require('dotenv');
// Determine the current APP_ENV
const APP_ENV = envLib.determineAppEnv(process.env.APP_ENV);
// Determine the current APP_ENV
const APP_ENV = envLib.determineAppEnv(process.env.APP_ENV);
// Convert the APP_ENV to some handy flags
const flags = envLib.buildAppFlags(APP_ENV);
// Convert the APP_ENV to some handy flags
const flags = envLib.buildAppFlags(APP_ENV);
// Attempt to read the local .env file for this APP_ENV
if (!flags.IN_DEVELOPMENT) dotenv.config({ path: path.resolve(`../${APP_ENV}.env`) });
// Attempt to read the local .env file for this APP_ENV
if (!flags.IN_DEVELOPMENT) dotenv.config({ path: path.resolve(`../${APP_ENV}.env`) });
// Extract the vars defined from process.env and apply validation and defaults
const config = envLib.mergeConfig(APP_ENV, flags, process.env, {
// Extract the vars defined from process.env and apply validation and defaults
const config = envLib.mergeConfig(APP_ENV, flags, process.env, {
// In development we can default the NODE_ENV but production envs should set it themselves
NODE_ENV: { required: !flags.IN_DEVELOPMENT, default: 'development' },
// In development we can default the NODE_ENV but production envs should set it themselves
NODE_ENV: { required: !flags.IN_DEVELOPMENT, default: 'development' },
// If not supplied, Keystone will default to localhost (ie. in dev)
MONGO_URI: { required: !flags.IN_DEVELOPMENT, default: 'mongodb://localhost/admyt-platform' },
// If not supplied, Keystone will default to localhost (ie. in dev)
MONGO_URI: { required: !flags.IN_DEVELOPMENT, default: 'mongodb://localhost/admyt-platform' },
// Used to encrypt user cookies; not important in dev
JWT_TOKEN_SECRET: { required: !flags.IN_DEVELOPMENT, default: 'gottalovejwts' },
// Used to encrypt user cookies; not important in dev
JWT_TOKEN_SECRET: { required: !flags.IN_DEVELOPMENT, default: 'gottalovejwts' },
// When not live, allow to be defaulted to a test key
MANDRILL_API_KEY: { required: flags.IN_LIVE, default: 'testkeygoeshere' },
// When not live, allow to be defaulted to a test key
MANDRILL_API_KEY: { required: flags.IN_LIVE, default: 'testkeygoeshere' },
// Cloudinary creds; used by Types.CloudinaryImage
CLOUDINARY_URL: { required: flags.IN_LIVE || flags.IN_STAGING, default: 'cloudinary://862989489411169:Wp74nFvzkSPGkQHgtCBH7wN4Yik@thinkmill' },
// Cloudinary creds; used by Types.CloudinaryImage
CLOUDINARY_URL: { required: flags.IN_LIVE || flags.IN_STAGING, default: 'cloudinary://862989489411169:Wp74nFvzkSPGkQHgtCBH7wN4Yik@thinkmill' },
// S3 credentials; used by Types.S3File
S3_BUCKET: { required: flags.IN_LIVE || flags.IN_STAGING },
S3_KEY: { required: flags.IN_LIVE || flags.IN_STAGING },
S3_SECRET: { required: flags.IN_LIVE || flags.IN_STAGING },
// S3 credentials; used by Types.S3File
S3_BUCKET: { required: flags.IN_LIVE || flags.IN_STAGING },
S3_KEY: { required: flags.IN_LIVE || flags.IN_STAGING },
S3_SECRET: { required: flags.IN_LIVE || flags.IN_STAGING },
// Urban Airship details; used to notify users
UA_APP_KEY: { required: flags.IN_LIVE || flags.IN_STAGING },
UA_SECRET_KEY: { required: flags.IN_LIVE || flags.IN_STAGING },
UA_MASTER_KEY: { required: flags.IN_LIVE || flags.IN_STAGING },
// Urban Airship details; used to notify users
UA_APP_KEY: { required: flags.IN_LIVE || flags.IN_STAGING },
UA_SECRET_KEY: { required: flags.IN_LIVE || flags.IN_STAGING },
UA_MASTER_KEY: { required: flags.IN_LIVE || flags.IN_STAGING },
// NewRelic app monitoring
NEW_RELIC_LICENSE_KEY: { required: flags.IN_LIVE },
NEW_RELIC_APP_NAME: { required: flags.IN_LIVE },
// NewRelic app monitoring
NEW_RELIC_LICENSE_KEY: { required: flags.IN_LIVE },
NEW_RELIC_APP_NAME: { required: flags.IN_LIVE },
// For the eCentric payment gateway
ECENTRIC_MERCHANT_ID: { required: flags.IN_LIVE || flags.IN_STAGING },
// For the eCentric payment gateway
ECENTRIC_MERCHANT_ID: { required: flags.IN_LIVE || flags.IN_STAGING },
});
});
// Set any other static or derived vars (that don't need to be overridden by .env or process vars)
config.OTHER_IMPORTANT_VARS = 'blah blah'
config.FORCE_SSL = (flags.IN_LIVE || flags.IN_STAGING);
// ..
// Set any other static or derived vars (that don't need to be overridden by .env or process vars)
config.OTHER_IMPORTANT_VARS = 'blah blah'
config.FORCE_SSL = (flags.IN_LIVE || flags.IN_STAGING);
// ..
```
## Breakdown

@@ -80,4 +82,6 @@

// Determine the current APP_ENV
const APP_ENV = envLib.determineAppEnv(process.env.APP_ENV);
```javascript
// Determine the current APP_ENV
const APP_ENV = envLib.determineAppEnv(process.env.APP_ENV);
```

@@ -98,11 +102,15 @@ This determination is based on the IP address ranges we use for VPCs in our deployed regions,

// Convert the APP_ENV to some handy flags
const flags = envLib.buildAppFlags(APP_ENV);
```javascript
// Convert the APP_ENV to some handy flags
const flags = envLib.buildAppFlags(APP_ENV);
```
This is totally optional but gives us a convenient convention for describing other conditions in the `config.js` file.
In `staging`, for example, the structure returned by this call would be:
console.log(flags);
// { IN_LIVE: false, IN_STAGING: true, IN_TESTING: false, IN_DEVELOPMENT: false }
```javascript
console.log(flags);
// { IN_LIVE: false, IN_STAGING: true, IN_TESTING: false, IN_DEVELOPMENT: false }
```
### `dotenv.config(..)`

@@ -112,4 +120,6 @@

// Attempt to read the local .env file for this APP_ENV
if (!flags.IN_DEVELOPMENT) dotenv.config({ path: path.resolve(`../${APP_ENV}.env`) });
```javascript
// Attempt to read the local .env file for this APP_ENV
if (!flags.IN_DEVELOPMENT) dotenv.config({ path: path.resolve(`../${APP_ENV}.env`) });
```

@@ -131,5 +141,8 @@ This file should contain any credentials, settings, etc. that are required for the environment but too sensitive to store in the codebase.

// Extract the vars defined from process.env and apply validation and defaults
const config = envLib.mergeConfig(APP_ENV, flags, process.env, {
// ..
```javascript
// Extract the vars defined from process.env and apply validation and defaults
const config = envLib.mergeConfig(APP_ENV, flags, process.env, {
// ..
});
```

@@ -163,12 +176,15 @@ The last argument to this function give us some simple defaulting and validation functionality.

config.CANISTER_EXCHANGE_PRICE_PER_UNIT_IN_CENTS = 1895;
config.CANISTER_SELL_PRICE_PER_UNIT_IN_CENTS = 4495;
```javascript
config.CANISTER_EXCHANGE_PRICE_PER_UNIT_IN_CENTS = 1895;
config.CANISTER_SELL_PRICE_PER_UNIT_IN_CENTS = 4495;
```
Blueshyft support contact details:
config.FROM_EMAIL = 'support@blueshyft.com.au';
config.FROM_NAME = 'Blueshyft Support';
config.SUPPORT_PHONE_NUMBER = '1800 817 483';
```javascript
config.FROM_EMAIL = 'support@blueshyft.com.au';
config.FROM_NAME = 'Blueshyft Support';
config.SUPPORT_PHONE_NUMBER = '1800 817 483';
```
#### Derived Values

@@ -179,8 +195,10 @@

config.CORE_API_URL = ({
production: 'https://core.blueshyft.com.au',
staging: 'https://core-staging.blueshyft.com.au',
testing: 'https://core-testing.blueshyft.com.au',
development: 'http://localhost:3000',
})[APP_ENV];
```javascript
config.CORE_API_URL = ({
production: 'https://core.blueshyft.com.au',
staging: 'https://core-staging.blueshyft.com.au',
testing: 'https://core-testing.blueshyft.com.au',
development: 'http://localhost:3000',
})[APP_ENV];
```

@@ -192,10 +210,11 @@ #### Feature Flags

// Are we disabling developer authentication to developer endpoints?
config.ALLOW_UNAUTHENTICATED_ACCESS_TO_DEVELOPER_ENDPOINTS = IN_DEVELOPMENT;
```javascript
// Are we disabling developer authentication to developer endpoints?
config.ALLOW_UNAUTHENTICATED_ACCESS_TO_DEVELOPER_ENDPOINTS = IN_DEVELOPMENT;
// Can calls to the /sweeps/create end point specify the sweepday used or do we exclusively rely on getNextSweepday()
config.ALLOW_SWEEPDAY_TO_BE_SPECIFIED_ON_CREATE = true;
// Can calls to the /sweeps/create end point specify the sweepday used or do we exclusively rely on getNextSweepday()
config.ALLOW_SWEEPDAY_TO_BE_SPECIFIED_ON_CREATE = true;
// Can sweeps be 'reset' after email generation has started
config.ALLOW_RESET_AFTER_EMAIL_GENERATION = !IN_PRODUCTION;
// Can sweeps be 'reset' after email generation has started
config.ALLOW_RESET_AFTER_EMAIL_GENERATION = !IN_PRODUCTION;
```
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc