@orion-js/env 3.1.22 → 3.1.23
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 +48 -0
- package/lib/environment/index.d.ts +1 -0
- package/lib/environment/index.js +1 -0
- package/lib/environment/load.d.ts +6 -0
- package/lib/environment/load.js +33 -0
- package/package.json +2 -2
package/README.md
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# Orion Env
|
|
2
|
+
|
|
3
|
+
> This package works as standlaone package. It does not depend on any other orionjs package.
|
|
4
|
+
|
|
5
|
+
Orion Env is a utility for managing a collection of secrets in source control. The secrets are encrypted using public key, elliptic curve cryptography.
|
|
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
|
package/lib/environment/index.js
CHANGED
|
@@ -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,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.
|
|
3
|
+
"version": "3.1.23",
|
|
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": "
|
|
34
|
+
"gitHead": "0194171f6f326dfa921cf6e9f341e5b733b7d11e"
|
|
35
35
|
}
|