@orion-js/env 3.11.8 → 3.12.0

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.
Files changed (43) hide show
  1. package/dist/index.cjs +9544 -0
  2. package/dist/index.d.ts +39 -0
  3. package/dist/index.js +9518 -0
  4. package/package.json +23 -16
  5. package/LICENSE +0 -21
  6. package/jest.config.js +0 -8
  7. package/lib/cli/add/encryptValue.d.ts +0 -2
  8. package/lib/cli/add/encryptValue.js +0 -8
  9. package/lib/cli/add/getConfig.d.ts +0 -2
  10. package/lib/cli/add/getConfig.js +0 -16
  11. package/lib/cli/add/getParams.d.ts +0 -5
  12. package/lib/cli/add/getParams.js +0 -26
  13. package/lib/cli/add/index.d.ts +0 -3
  14. package/lib/cli/add/index.js +0 -38
  15. package/lib/cli/index.d.ts +0 -2
  16. package/lib/cli/index.js +0 -43
  17. package/lib/cli/init/index.d.ts +0 -3
  18. package/lib/cli/init/index.js +0 -29
  19. package/lib/cli/read/index.d.ts +0 -5
  20. package/lib/cli/read/index.js +0 -21
  21. package/lib/crypto/index.d.ts +0 -13
  22. package/lib/crypto/index.js +0 -37
  23. package/lib/crypto/index.test.d.ts +0 -1
  24. package/lib/crypto/index.test.js +0 -30
  25. package/lib/crypto/tweetnacl.d.ts +0 -3
  26. package/lib/crypto/tweetnacl.js +0 -31
  27. package/lib/environment/getDts.d.ts +0 -4
  28. package/lib/environment/getDts.js +0 -32
  29. package/lib/environment/getVariables.d.ts +0 -17
  30. package/lib/environment/getVariables.js +0 -58
  31. package/lib/environment/index.d.ts +0 -8
  32. package/lib/environment/index.js +0 -35
  33. package/lib/environment/index.test.d.ts +0 -1
  34. package/lib/environment/index.test.js +0 -136
  35. package/lib/environment/load.d.ts +0 -6
  36. package/lib/environment/load.js +0 -33
  37. package/lib/files/index.d.ts +0 -3
  38. package/lib/files/index.js +0 -27
  39. package/lib/index.d.ts +0 -2
  40. package/lib/index.js +0 -14
  41. package/lib/internalGetEnv.d.ts +0 -1
  42. package/lib/internalGetEnv.js +0 -14
  43. package/tsconfig.json +0 -20
package/package.json CHANGED
@@ -1,36 +1,43 @@
1
1
  {
2
2
  "name": "@orion-js/env",
3
- "version": "3.11.8",
4
- "main": "lib/index.js",
3
+ "version": "3.12.0",
4
+ "main": "./dist/index.cjs",
5
5
  "author": "nicolaslopezj",
6
6
  "license": "MIT",
7
7
  "bin": {
8
8
  "orion-env": "./lib/cli/index.js"
9
9
  },
10
10
  "scripts": {
11
- "test": "ORION_DEV=1 jest",
12
- "prepare": "yarn run build",
13
- "clean": "rm -rf ./lib",
14
- "build": "yarn run clean && tsc",
15
- "watch": "tsc -w",
16
- "upgrade-interactive": "yarn upgrade-interactive"
11
+ "test": "bun test",
12
+ "clean": "rm -rf ./dist",
13
+ "build": "bun run build.ts",
14
+ "dev": "bun --watch src/index.ts"
17
15
  },
18
16
  "dependencies": {
19
17
  "colors": "^1.4.0",
20
- "commander": "^9.1.0",
18
+ "commander": "^9.5.0",
21
19
  "prompts": "^2.4.2",
22
20
  "tweetnacl": "^1.0.3",
23
21
  "tweetnacl-util": "0.15.1",
24
- "yaml": "^2.0.0"
22
+ "yaml": "^2.7.0"
25
23
  },
26
24
  "devDependencies": {
27
- "@types/jest": "^27.0.2",
28
- "jest": "27.3.1",
29
- "ts-jest": "27.0.7",
30
- "typescript": "^4.4.4"
25
+ "@types/bun": "^1.2.4",
26
+ "typescript": "^5.8.2"
31
27
  },
32
28
  "publishConfig": {
33
29
  "access": "public"
34
30
  },
35
- "gitHead": "78d70ac414964ec657cc000cedfad8a5efff5cc3"
36
- }
31
+ "gitHead": "9d85ab24776533db109843c277324e42c65ddedd",
32
+ "type": "module",
33
+ "module": "./dist/index.js",
34
+ "types": "./dist/index.d.ts",
35
+ "exports": {
36
+ "types": "./dist/index.d.ts",
37
+ "import": "./dist/index.js",
38
+ "require": "./dist/index.cjs"
39
+ },
40
+ "files": [
41
+ "dist"
42
+ ]
43
+ }
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2022 Orionjs Team
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
package/jest.config.js DELETED
@@ -1,8 +0,0 @@
1
- module.exports = {
2
- roots: ['./src'],
3
- testMatch: ['**/__tests__/**/*.+(ts|tsx|js)', '**/?(*.)+(spec|test).+(ts|tsx|js)'],
4
- transform: {
5
- '^.+\\.(ts|tsx)$': 'ts-jest'
6
- },
7
- verbose: true
8
- }
@@ -1,2 +0,0 @@
1
- import { Config } from '../../environment/getVariables';
2
- export declare const encryptValue: (key: string, value: string, config: Config) => void;
@@ -1,8 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.encryptValue = void 0;
4
- const crypto_1 = require("../../crypto");
5
- const encryptValue = (key, value, config) => {
6
- config.encryptedKeys[key] = (0, crypto_1.encrypt)(config.publicKey, value);
7
- };
8
- exports.encryptValue = encryptValue;
@@ -1,2 +0,0 @@
1
- import { Config } from '../../environment/getVariables';
2
- export declare const getConfig: (envPath: string) => Config;
@@ -1,16 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getConfig = void 0;
7
- const yaml_1 = __importDefault(require("yaml"));
8
- const files_1 = require("../../files");
9
- const getConfig = (envPath) => {
10
- const configFile = (0, files_1.readFile)(envPath);
11
- if (!configFile) {
12
- throw new Error('No config file found at path ' + envPath);
13
- }
14
- return yaml_1.default.parse(configFile);
15
- };
16
- exports.getConfig = getConfig;
@@ -1,5 +0,0 @@
1
- import { Config } from '../../environment/getVariables';
2
- export declare const getParams: (config: Config) => Promise<{
3
- key: string;
4
- value: string;
5
- }>;
@@ -1,26 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getParams = void 0;
7
- const prompts_1 = __importDefault(require("prompts"));
8
- const getParams = async (config) => {
9
- const response = await (0, prompts_1.default)([
10
- {
11
- type: 'text',
12
- name: 'key',
13
- message: 'Key'
14
- },
15
- {
16
- type: 'text',
17
- name: 'value',
18
- message: 'Value'
19
- }
20
- ]);
21
- return {
22
- key: response.key,
23
- value: response.value
24
- };
25
- };
26
- exports.getParams = getParams;
@@ -1,3 +0,0 @@
1
- export default function envAdd({ path }: {
2
- path: any;
3
- }): Promise<void>;
@@ -1,38 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const encryptValue_1 = require("./encryptValue");
7
- const getConfig_1 = require("./getConfig");
8
- const getParams_1 = require("./getParams");
9
- const yaml_1 = __importDefault(require("yaml"));
10
- const files_1 = require("../../files");
11
- const sortObjectByKeys = (object) => {
12
- if (!object)
13
- return {};
14
- const sorted = {};
15
- Object.keys(object)
16
- .sort()
17
- .forEach(key => {
18
- sorted[key] = object[key];
19
- });
20
- return sorted;
21
- };
22
- async function envAdd({ path }) {
23
- if (!path) {
24
- path = '.env.local.yml';
25
- }
26
- const config = (0, getConfig_1.getConfig)(path);
27
- const { key, value } = await (0, getParams_1.getParams)(config);
28
- if (!value)
29
- return;
30
- (0, encryptValue_1.encryptValue)(key, value, config);
31
- // sort keys alphabetically
32
- config.cleanKeys = sortObjectByKeys(config.cleanKeys);
33
- config.encryptedKeys = sortObjectByKeys(config.encryptedKeys);
34
- config.readFromSecret = sortObjectByKeys(config.readFromSecret);
35
- const text = yaml_1.default.stringify(config);
36
- (0, files_1.writeFile)(path, text);
37
- }
38
- exports.default = envAdd;
@@ -1,2 +0,0 @@
1
- #!/usr/bin/env node
2
- export {};
package/lib/cli/index.js DELETED
@@ -1,43 +0,0 @@
1
- #!/usr/bin/env node
2
- "use strict";
3
- var __importDefault = (this && this.__importDefault) || function (mod) {
4
- return (mod && mod.__esModule) ? mod : { "default": mod };
5
- };
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- const commander_1 = require("commander");
8
- const safe_1 = __importDefault(require("colors/safe"));
9
- const init_1 = __importDefault(require("./init"));
10
- const add_1 = __importDefault(require("./add"));
11
- const read_1 = __importDefault(require("./read"));
12
- const program = new commander_1.Command();
13
- const run = function (action) {
14
- return async function (...args) {
15
- try {
16
- await action(...args);
17
- }
18
- catch (e) {
19
- console.error(safe_1.default.red('Error: ' + e.message));
20
- }
21
- };
22
- };
23
- program
24
- .command('init')
25
- .description('Creates a new encrypted env file')
26
- .option('--path <path>', 'Specify the env file name')
27
- .action(run(init_1.default));
28
- program
29
- .command('add')
30
- .description('Adds a new environment to the encrypted env file')
31
- .option('--path <path>', 'Specify the env file name')
32
- .action(run(add_1.default));
33
- program
34
- .command('read')
35
- .description('Prints the value of the env file in JSON or a specific variable in plain text')
36
- .option('--path <path>', 'Specify the env file name')
37
- .option('--key <key>', 'Prints the value of a specific variable in plain text')
38
- .option('--secret <secret>', 'The password to decrypt the keys')
39
- .action(run(read_1.default));
40
- program.parse(process.argv);
41
- if (!process.argv.slice(2).length) {
42
- program.outputHelp();
43
- }
@@ -1,3 +0,0 @@
1
- export default function envInit({ path }: {
2
- path: any;
3
- }): Promise<void>;
@@ -1,29 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const yaml_1 = __importDefault(require("yaml"));
7
- const crypto_1 = require("../../crypto");
8
- const files_1 = require("../../files");
9
- async function envInit({ path }) {
10
- if (!path) {
11
- path = '.env.local.yml';
12
- }
13
- const keypair = (0, crypto_1.generateKeys)();
14
- const envFile = {
15
- version: '1.0',
16
- publicKey: keypair.encryptKey,
17
- cleanKeys: {},
18
- encryptedKeys: {},
19
- readFromSecret: {}
20
- };
21
- const text = yaml_1.default.stringify(envFile);
22
- (0, files_1.writeFile)(path, text);
23
- console.log('');
24
- console.log(`Environment file created. You need to use the following key to decrypt the environment variables:`);
25
- console.log('');
26
- console.log(keypair.decryptKey);
27
- console.log('');
28
- }
29
- exports.default = envInit;
@@ -1,5 +0,0 @@
1
- export default function envRead({ path, key, secret }: {
2
- path: any;
3
- key: any;
4
- secret: any;
5
- }): Promise<void>;
@@ -1,21 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const getVariables_1 = require("../../environment/getVariables");
4
- const getConfig_1 = require("../add/getConfig");
5
- async function envRead({ path, key, secret }) {
6
- if (!path) {
7
- path = '.env.local.yml';
8
- }
9
- if (!secret) {
10
- throw new Error('Secret is required');
11
- }
12
- const config = (0, getConfig_1.getConfig)(path);
13
- const variables = (0, getVariables_1.getVariables)(config, secret);
14
- if (key) {
15
- console.log(variables[key]);
16
- }
17
- else {
18
- console.log(JSON.stringify(variables, null, 2));
19
- }
20
- }
21
- exports.default = envRead;
@@ -1,13 +0,0 @@
1
- export declare function generateKeys(): {
2
- encryptKey: string;
3
- decryptKey: string;
4
- };
5
- /**
6
- * Creates a temporal keypair just to encrypt one message.
7
- * Saves the public key in the result so that the message can be decrypted.
8
- */
9
- export declare function encrypt(encryptKey: string, message: string): string;
10
- /**
11
- * Ecrypts a message using the decrypt key
12
- */
13
- export declare function decrypt(decryptKey: string, encrypted: string): string;
@@ -1,37 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.decrypt = exports.encrypt = exports.generateKeys = void 0;
4
- const tweetnacl_1 = require("./tweetnacl");
5
- const tweetnacl_util_1 = require("tweetnacl-util");
6
- function generateKeys() {
7
- const { publicKey, secretKey } = (0, tweetnacl_1.generateKeyPair)();
8
- const encryptKeyHex = (0, tweetnacl_util_1.encodeBase64)(publicKey);
9
- const decryptKeyHex = (0, tweetnacl_util_1.encodeBase64)(secretKey);
10
- return {
11
- encryptKey: encryptKeyHex,
12
- decryptKey: decryptKeyHex
13
- };
14
- }
15
- exports.generateKeys = generateKeys;
16
- /**
17
- * Creates a temporal keypair just to encrypt one message.
18
- * Saves the public key in the result so that the message can be decrypted.
19
- */
20
- function encrypt(encryptKey, message) {
21
- const encryptPublicKey = (0, tweetnacl_util_1.decodeBase64)(encryptKey);
22
- const tempPair = (0, tweetnacl_1.generateKeyPair)();
23
- const encrypted = (0, tweetnacl_1.encrypt)(tempPair.secretKey, encryptPublicKey, message);
24
- const hexTempPublic = (0, tweetnacl_util_1.encodeBase64)(tempPair.publicKey);
25
- return `${hexTempPublic}:${encrypted}`;
26
- }
27
- exports.encrypt = encrypt;
28
- /**
29
- * Ecrypts a message using the decrypt key
30
- */
31
- function decrypt(decryptKey, encrypted) {
32
- const decryptSecretKey = (0, tweetnacl_util_1.decodeBase64)(decryptKey);
33
- const [messagePubKeyHex, encryptedMessage] = encrypted.split(':');
34
- const messagePubKey = (0, tweetnacl_util_1.decodeBase64)(messagePubKeyHex);
35
- return (0, tweetnacl_1.decrypt)(decryptSecretKey, messagePubKey, encryptedMessage);
36
- }
37
- exports.decrypt = decrypt;
@@ -1 +0,0 @@
1
- export {};
@@ -1,30 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const _1 = require(".");
4
- describe('Asymetric encryption lib', () => {
5
- it('should generate public and private keys', async () => {
6
- const { decryptKey, encryptKey } = (0, _1.generateKeys)();
7
- expect(decryptKey.length).toBeGreaterThan(0);
8
- expect(encryptKey.length).toBeGreaterThan(0);
9
- expect(decryptKey).not.toEqual(encryptKey);
10
- });
11
- it('should encrypt a message using the encrypt key', async () => {
12
- const { encryptKey } = (0, _1.generateKeys)();
13
- const encrypted = (0, _1.encrypt)(encryptKey, 'hello');
14
- expect(encrypted).toBeTruthy();
15
- expect(encrypted.length).toBeGreaterThan(0);
16
- });
17
- it('should decrypt a message using de decrypt key', async () => {
18
- const message = 'hello';
19
- const { encryptKey, decryptKey } = (0, _1.generateKeys)();
20
- const encrypted = (0, _1.encrypt)(encryptKey, message);
21
- const decrypted = (0, _1.decrypt)(decryptKey, encrypted);
22
- expect(decrypted).toEqual(message);
23
- });
24
- it('should not produce two equal encryptions for the same message', async () => {
25
- const { encryptKey } = (0, _1.generateKeys)();
26
- const encrypted = (0, _1.encrypt)(encryptKey, 'hello');
27
- const encrypted2 = (0, _1.encrypt)(encryptKey, 'hello');
28
- expect(encrypted).not.toEqual(encrypted2);
29
- });
30
- });
@@ -1,3 +0,0 @@
1
- export declare const generateKeyPair: () => import("tweetnacl").BoxKeyPair;
2
- export declare const encrypt: (bSecretKey: Uint8Array, aPublicKey: Uint8Array, message: string) => string;
3
- export declare const decrypt: (aSecretKey: Uint8Array, bPublicKey: Uint8Array, messageWithNonce: string) => string;
@@ -1,31 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.decrypt = exports.encrypt = exports.generateKeyPair = void 0;
4
- const tweetnacl_1 = require("tweetnacl");
5
- const tweetnacl_util_1 = require("tweetnacl-util");
6
- const newNonce = () => (0, tweetnacl_1.randomBytes)(tweetnacl_1.box.nonceLength);
7
- const generateKeyPair = () => tweetnacl_1.box.keyPair();
8
- exports.generateKeyPair = generateKeyPair;
9
- const encrypt = (bSecretKey, aPublicKey, message) => {
10
- const nonce = newNonce();
11
- const messageUint8 = (0, tweetnacl_util_1.decodeUTF8)(message);
12
- const encrypted = (0, tweetnacl_1.box)(messageUint8, nonce, aPublicKey, bSecretKey);
13
- const fullMessage = new Uint8Array(nonce.length + encrypted.length);
14
- fullMessage.set(nonce);
15
- fullMessage.set(encrypted, nonce.length);
16
- const base64FullMessage = (0, tweetnacl_util_1.encodeBase64)(fullMessage);
17
- return base64FullMessage;
18
- };
19
- exports.encrypt = encrypt;
20
- const decrypt = (aSecretKey, bPublicKey, messageWithNonce) => {
21
- const messageWithNonceAsUint8Array = (0, tweetnacl_util_1.decodeBase64)(messageWithNonce);
22
- const nonce = messageWithNonceAsUint8Array.slice(0, tweetnacl_1.box.nonceLength);
23
- const message = messageWithNonceAsUint8Array.slice(tweetnacl_1.box.nonceLength, messageWithNonce.length);
24
- const decrypted = tweetnacl_1.box.open(message, nonce, bPublicKey, aSecretKey);
25
- if (!decrypted) {
26
- throw new Error('Could not decrypt message');
27
- }
28
- const base64DecryptedMessage = (0, tweetnacl_util_1.encodeUTF8)(decrypted);
29
- return base64DecryptedMessage;
30
- };
31
- exports.decrypt = decrypt;
@@ -1,4 +0,0 @@
1
- import { Config } from './getVariables';
2
- export declare function getDts(config: Config): string;
3
- export declare function writeDtsFile(config: Config, path: string): void;
4
- export declare function writeDtsFileFromConfigFile(configFilePath: string, path: string): void;
@@ -1,32 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.writeDtsFileFromConfigFile = exports.writeDtsFile = exports.getDts = void 0;
4
- const getConfig_1 = require("../cli/add/getConfig");
5
- const files_1 = require("../files");
6
- function getDts(config) {
7
- const keys = [
8
- ...Object.keys(config.cleanKeys),
9
- ...Object.keys(config.encryptedKeys),
10
- ...Object.values(config.readFromSecret).flat()
11
- ];
12
- return `declare module '@orion-js/env' {
13
- export const env: {
14
- ${keys.map(key => ` ${key}: string`).join('\n')}
15
- }
16
- }
17
- `;
18
- }
19
- exports.getDts = getDts;
20
- function writeDtsFile(config, path) {
21
- const currentFile = (0, files_1.readFile)(path);
22
- const dts = getDts(config);
23
- if (currentFile !== dts) {
24
- (0, files_1.writeFile)(path, dts);
25
- }
26
- }
27
- exports.writeDtsFile = writeDtsFile;
28
- function writeDtsFileFromConfigFile(configFilePath, path) {
29
- const config = (0, getConfig_1.getConfig)(configFilePath);
30
- writeDtsFile(config, path);
31
- }
32
- exports.writeDtsFileFromConfigFile = writeDtsFileFromConfigFile;
@@ -1,17 +0,0 @@
1
- export interface Config {
2
- version: string;
3
- publicKey: string;
4
- cleanKeys: {
5
- [key: string]: string;
6
- };
7
- encryptedKeys: {
8
- [key: string]: string;
9
- };
10
- readFromSecret?: {
11
- [key: string]: string[];
12
- };
13
- }
14
- export interface Variables {
15
- [key: string]: string;
16
- }
17
- export declare function getVariables(config: Config, secretKey?: string): Variables;
@@ -1,58 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getVariables = void 0;
4
- const crypto_1 = require("../crypto");
5
- function readSecrets(readFromSecret) {
6
- const variables = {};
7
- let secretKey = null;
8
- if (!readFromSecret)
9
- return { variables, secretKey };
10
- for (const secretName in readFromSecret) {
11
- const keys = readFromSecret[secretName];
12
- if (!process.env[secretName]) {
13
- console.warn(`@orion/env could not find the secret "${secretName}" in the environment. Related variables will be undefined.`);
14
- continue;
15
- }
16
- try {
17
- const values = JSON.parse(process.env[secretName]);
18
- if (values.ORION_ENV_SECRET_KEY) {
19
- secretKey = values.ORION_ENV_SECRET_KEY;
20
- }
21
- for (const key of keys) {
22
- if (values[key]) {
23
- variables[key] = values[key];
24
- }
25
- else {
26
- console.warn(`@orion/env could not find the variable "${key}" in the secret "${secretName}". Related variables will be undefined.`);
27
- }
28
- }
29
- }
30
- catch (error) {
31
- console.warn(`'@orion/env found a the secret "${secretName}" variable in the environment but it is not a valid JSON. Related variables will be undefined.'`);
32
- }
33
- }
34
- return { variables, secretKey: secretKey };
35
- }
36
- function getVariables(config, secretKey) {
37
- const { cleanKeys, encryptedKeys, readFromSecret } = config;
38
- const { variables, secretKey: foundSecretKey } = readSecrets(readFromSecret);
39
- let decryptKey = foundSecretKey || secretKey;
40
- if (!decryptKey) {
41
- throw new Error('Orion encrypted env was passed but process.env.ORION_ENV_SECRET_KEY is not defined');
42
- }
43
- for (const key in cleanKeys) {
44
- const value = cleanKeys[key];
45
- variables[key] = value;
46
- }
47
- for (const key in encryptedKeys) {
48
- const encrypted = encryptedKeys[key];
49
- try {
50
- variables[key] = (0, crypto_1.decrypt)(decryptKey, encrypted);
51
- }
52
- catch (error) {
53
- throw new Error(`Orion encrypted env was passed but process.env.ORION_ENV_SECRET_KEY is not the right key for "${key}"`);
54
- }
55
- }
56
- return variables;
57
- }
58
- exports.getVariables = getVariables;
@@ -1,8 +0,0 @@
1
- export * from './getDts';
2
- export * from './load';
3
- export interface Variables {
4
- [key: string]: string;
5
- }
6
- export declare const readEnv: () => import("./getVariables").Variables;
7
- declare const env: Variables;
8
- export { env };
@@ -1,35 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
- };
12
- Object.defineProperty(exports, "__esModule", { value: true });
13
- exports.env = exports.readEnv = void 0;
14
- const getConfig_1 = require("../cli/add/getConfig");
15
- const getVariables_1 = require("./getVariables");
16
- __exportStar(require("./getDts"), exports);
17
- __exportStar(require("./load"), exports);
18
- let variables = {};
19
- const g = global;
20
- const secretKey = process.env.ORION_ENV_SECRET_KEY;
21
- const envFilePath = process.env.ORION_ENV_FILE_PATH;
22
- const readEnv = () => {
23
- const data = (0, getConfig_1.getConfig)(envFilePath);
24
- return (0, getVariables_1.getVariables)(data, secretKey);
25
- };
26
- exports.readEnv = readEnv;
27
- if (g.__orion_env_final__) {
28
- variables = g.__orion_env_final__;
29
- }
30
- else if (envFilePath) {
31
- variables = (0, exports.readEnv)();
32
- }
33
- g.__orion_env_final__ = variables;
34
- const env = variables;
35
- exports.env = env;
@@ -1 +0,0 @@
1
- export {};