@orion-js/env 3.1.22 → 3.1.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,48 @@
1
+ # Orion Env
2
+
3
+ Orion Env is a utility for managing a collection of secrets in source control. The secrets are encrypted using public key, elliptic curve cryptography.
4
+
5
+ > This package works as standlaone package. It does not depend on any other orionjs package.
6
+
7
+ It's like dotEnv but saved in source control.
8
+
9
+ ## Creating a new Env config file
10
+
11
+ Run the following script in a project that has the package installed. Save the password output because you will need to use it to decrypt the keys.
12
+
13
+ yarn orion-env init --path=<path>
14
+
15
+ ## Adding a new env variable
16
+
17
+ Run the following script in a project that has the package installed and you will be prompted for the variable name and value.
18
+
19
+ yarn orion-env add --path=<path>
20
+
21
+ ## Using in your app
22
+
23
+ Define the following environment variables (in the old way):
24
+
25
+ - `ORION_ENV_FILE_PATH=<path>` The path to the env file.
26
+ - `ORION_ENV_SECRET_KEY=<password>` The password to decrypt the keys.
27
+
28
+ Then you can access the variables by importing the package and all the env variables defined will be the env object.
29
+
30
+ import {env} from '@orion-js/env'
31
+
32
+ env.XX
33
+
34
+ ## Setting environment variables (process.env)
35
+
36
+ To add backwards compatibility you can also use this libary to set the environment variables.
37
+
38
+ import {loadEnv} from '@orion-js/env'
39
+
40
+ loadEnv(options)
41
+
42
+ This will set the environment variables for the current process.
43
+
44
+ Options:
45
+
46
+ - `secretKey` Secret password used to decrypt the encrypted env file. Default: process.env.ORION_ENV_SECRET_KEY
47
+ - `envFilePath` Location of the file to read. Default: process.env.ORION_ENV_FILE_PATH
48
+ - `override` Set to true to set the environment variables even if the variable was already set. Default: process.env.ORION_ENV_OVERRIDE
@@ -1,3 +1,3 @@
1
- export default function envAdd({ envPath }: {
2
- envPath: any;
1
+ export default function envAdd({ path }: {
2
+ path: any;
3
3
  }): Promise<void>;
@@ -17,11 +17,11 @@ const sortObjectByKeys = (object) => {
17
17
  });
18
18
  return sorted;
19
19
  };
20
- async function envAdd({ envPath }) {
21
- if (!envPath) {
22
- envPath = '.env.local.yml';
20
+ async function envAdd({ path }) {
21
+ if (!path) {
22
+ path = '.env.local.yml';
23
23
  }
24
- const config = (0, getConfig_1.getConfig)(envPath);
24
+ const config = (0, getConfig_1.getConfig)(path);
25
25
  const { key, value } = await (0, getParams_1.getParams)(config);
26
26
  if (!value)
27
27
  return;
@@ -30,6 +30,6 @@ async function envAdd({ envPath }) {
30
30
  config.cleanKeys = sortObjectByKeys(config.cleanKeys);
31
31
  config.encryptedKeys = sortObjectByKeys(config.encryptedKeys);
32
32
  const text = yaml_1.default.stringify(config);
33
- (0, files_1.writeFile)(envPath, text);
33
+ (0, files_1.writeFile)(path, text);
34
34
  }
35
35
  exports.default = envAdd;
@@ -1,3 +1,3 @@
1
- export default function envInit({ envPath }: {
2
- envPath: any;
1
+ export default function envInit({ path }: {
2
+ path: any;
3
3
  }): Promise<void>;
@@ -6,9 +6,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const yaml_1 = __importDefault(require("yaml"));
7
7
  const crypto_1 = require("../../crypto");
8
8
  const files_1 = require("../../files");
9
- async function envInit({ envPath }) {
10
- if (!envPath) {
11
- envPath = '.env.local.yml';
9
+ async function envInit({ path }) {
10
+ if (!path) {
11
+ path = '.env.local.yml';
12
12
  }
13
13
  const keypair = (0, crypto_1.generateKeys)();
14
14
  const envFile = {
@@ -18,7 +18,7 @@ async function envInit({ envPath }) {
18
18
  encryptedKeys: {}
19
19
  };
20
20
  const text = yaml_1.default.stringify(envFile);
21
- (0, files_1.writeFile)(envPath, text);
21
+ (0, files_1.writeFile)(path, text);
22
22
  console.log('');
23
23
  console.log(`Environment file created. You need to use the following key to decrypt the environment variables:`);
24
24
  console.log('');
@@ -7,7 +7,7 @@ function getDts(config) {
7
7
  const keys = [...Object.keys(config.cleanKeys), ...Object.keys(config.encryptedKeys)];
8
8
  return `declare module '@orion-js/env' {
9
9
  export const env: {
10
- ${keys.map(key => ` ${key}: string;`).join('\n')}
10
+ ${keys.map(key => ` ${key}: string`).join('\n')}
11
11
  }
12
12
  }
13
13
  `;
@@ -1,4 +1,5 @@
1
1
  export * from './getDts';
2
+ export * from './load';
2
3
  export interface Variables {
3
4
  [key: string]: string;
4
5
  }
@@ -14,6 +14,7 @@ exports.env = exports.readEnv = void 0;
14
14
  const getConfig_1 = require("../cli/add/getConfig");
15
15
  const getVariables_1 = require("./getVariables");
16
16
  __exportStar(require("./getDts"), exports);
17
+ __exportStar(require("./load"), exports);
17
18
  let variables = {};
18
19
  const g = global;
19
20
  const secretKey = process.env.ORION_ENV_SECRET_KEY;
@@ -0,0 +1,6 @@
1
+ export interface LoadEnvOptions {
2
+ secretKey?: string;
3
+ envFilePath?: string;
4
+ override?: boolean;
5
+ }
6
+ export declare function loadEnv(passedOptions?: LoadEnvOptions): void;
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.loadEnv = void 0;
4
+ const getConfig_1 = require("../cli/add/getConfig");
5
+ const getVariables_1 = require("./getVariables");
6
+ const defaultOptions = {
7
+ secretKey: process.env.ORION_ENV_SECRET_KEY,
8
+ envFilePath: process.env.ORION_ENV_FILE_PATH,
9
+ override: !!process.env.ORION_ENV_OVERRIDE
10
+ };
11
+ function loadEnv(passedOptions = {}) {
12
+ const options = { ...defaultOptions, ...passedOptions };
13
+ const data = (0, getConfig_1.getConfig)(options.envFilePath);
14
+ const variables = (0, getVariables_1.getVariables)(data, options.secretKey);
15
+ for (const key in variables) {
16
+ const variable = variables[key];
17
+ if (!Object.prototype.hasOwnProperty.call(process.env, key)) {
18
+ process.env[key] = variable;
19
+ }
20
+ else {
21
+ if (options.override) {
22
+ process.env[key] = variable;
23
+ }
24
+ if (options.override) {
25
+ console.log(`"${key}" is already defined in \`process.env\` and WAS overwritten`);
26
+ }
27
+ else {
28
+ console.log(`"${key}" is already defined in \`process.env\` and was NOT overwritten`);
29
+ }
30
+ }
31
+ }
32
+ }
33
+ exports.loadEnv = loadEnv;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@orion-js/env",
3
- "version": "3.1.22",
3
+ "version": "3.1.25",
4
4
  "main": "lib/index.js",
5
5
  "author": "nicolaslopezj",
6
6
  "license": "MIT",
@@ -31,5 +31,5 @@
31
31
  "publishConfig": {
32
32
  "access": "public"
33
33
  },
34
- "gitHead": "51b5af5952a486e40392381f769c69cfdfdc7b5e"
34
+ "gitHead": "48f30c51fea96518fab7fedf7643d6493f4f56bc"
35
35
  }