@orion-js/env 3.1.9

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/LICENSE ADDED
@@ -0,0 +1,21 @@
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 ADDED
@@ -0,0 +1,8 @@
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
+ }
@@ -0,0 +1,2 @@
1
+ declare const env: {};
2
+ export { env };
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.env = void 0;
4
+ const crypto_1 = require("@orion-js/crypto");
5
+ const env = {};
6
+ exports.env = env;
7
+ const g = global;
8
+ if (g.__orion_env__) {
9
+ const secretKey = process.env.ORION_ENV_SECRET_KEY;
10
+ if (!secretKey) {
11
+ throw new Error('Orion encrypted env was passed but process.env.ORION_ENV_SECRET_KEY is not defined');
12
+ }
13
+ const cleanKeys = g.__orion_env__.cleanKeys;
14
+ const encryptedKeys = g.__orion_env__.encryptedKeys;
15
+ for (const key in cleanKeys) {
16
+ const value = cleanKeys[key];
17
+ env[key] = value;
18
+ }
19
+ for (const key in encryptedKeys) {
20
+ const encrypted = encryptedKeys[key];
21
+ try {
22
+ env[key] = crypto_1.asymmetric.decrypt(secretKey, encrypted);
23
+ }
24
+ catch (error) {
25
+ throw new Error(`Orion encrypted env was passed but process.env.ORION_ENV_SECRET_KEY is not the right key for "${key}"`);
26
+ }
27
+ }
28
+ }
@@ -0,0 +1 @@
1
+ import 'reflect-metadata';
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ require("reflect-metadata");
4
+ const crypto_1 = require("@orion-js/crypto");
5
+ describe('Environment', () => {
6
+ beforeEach(() => {
7
+ jest.resetModules();
8
+ });
9
+ it('should define all environment variables', async () => {
10
+ const secretKey = 'QShwQT1+d5wk/F6FVpT5VmZFXm50aFRt9/LaDbwSEGo=';
11
+ const secretValue = 'this_is_secret';
12
+ global.__orion_env__ = {
13
+ version: '1.0',
14
+ publicKey: 'quyw/56O1P/BmjlHGfguZD27zKbjOtxNBDOTz+FOYho=',
15
+ cleanKeys: {
16
+ a_key: 'a_value'
17
+ },
18
+ encryptedKeys: {
19
+ secret1: 'nQCxsZxjVkOABeQSdIhYK7jSMYKUggUm9IWUGLpY3i4=:9gvH5IOhV/q5R4ngUIk2onf5oEZM5dIU89PRZ5TGjnnfcnrwkssLqsACNDmr0m4jQZVo0nBL'
20
+ }
21
+ };
22
+ process.env.ORION_ENV_SECRET_KEY = secretKey;
23
+ const { env } = require('./index');
24
+ expect(env).toEqual({
25
+ a_key: 'a_value',
26
+ secret1: secretValue
27
+ });
28
+ });
29
+ it('should thow an error when the secret key is not present', () => {
30
+ global.__orion_env__ = {
31
+ version: '1.0',
32
+ publicKey: 'quyw/56O1P/BmjlHGfguZD27zKbjOtxNBDOTz+FOYho=',
33
+ encryptedKeys: {
34
+ secret1: 'nQCxsZxjVkOABeQSdIhYK7jSMYKUggUm9IWUGLpY3i4=:9gvH5IOhV/q5R4ngUIk2onf5oEZM5dIU89PRZ5TGjnnfcnrwkssLqsACNDmr0m4jQZVo0nBL'
35
+ }
36
+ };
37
+ try {
38
+ process.env.ORION_ENV_SECRET_KEY = '';
39
+ const { env } = require('./index');
40
+ console.log(env);
41
+ }
42
+ catch (error) {
43
+ expect(error.message).toEqual('Orion encrypted env was passed but process.env.ORION_ENV_SECRET_KEY is not defined');
44
+ }
45
+ expect.assertions(1);
46
+ });
47
+ it('should thow an error when the secret key is not the one used to encrypt', () => {
48
+ global.__orion_env__ = {
49
+ version: '1.0',
50
+ publicKey: 'quyw/56O1P/BmjlHGfguZD27zKbjOtxNBDOTz+FOYho=',
51
+ encryptedKeys: {
52
+ secret1: 'nQCxsZxjVkOABeQSdIhYK7jSMYKUggUm9IWUGLpY3i4=:9gvH5IOhV/q5R4ngUIk2onf5oEZM5dIU89PRZ5TGjnnfcnrwkssLqsACNDmr0m4jQZVo0nBL'
53
+ }
54
+ };
55
+ try {
56
+ process.env.ORION_ENV_SECRET_KEY = crypto_1.asymmetric.generateKeys().decryptKey;
57
+ require('./index');
58
+ }
59
+ catch (error) {
60
+ expect(error.message).toEqual('Orion encrypted env was passed but process.env.ORION_ENV_SECRET_KEY is not the right key for "secret1"');
61
+ }
62
+ expect.assertions(1);
63
+ });
64
+ });
package/lib/index.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './environment';
package/lib/index.js ADDED
@@ -0,0 +1,13 @@
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
+ __exportStar(require("./environment"), exports);
package/package.json ADDED
@@ -0,0 +1,29 @@
1
+ {
2
+ "name": "@orion-js/env",
3
+ "version": "3.1.9",
4
+ "main": "lib/index.js",
5
+ "author": "nicolaslopezj",
6
+ "license": "MIT",
7
+ "scripts": {
8
+ "test": "ORION_DEV=1 jest",
9
+ "prepare": "yarn run build",
10
+ "clean": "rm -rf ./lib",
11
+ "build": "yarn run clean && tsc",
12
+ "watch": "tsc -w",
13
+ "upgrade-interactive": "yarn upgrade-interactive"
14
+ },
15
+ "dependencies": {
16
+ "@orion-js/crypto": "3.1.7"
17
+ },
18
+ "devDependencies": {
19
+ "@types/jest": "^27.0.2",
20
+ "jest": "27.3.1",
21
+ "reflect-metadata": "0.1.13",
22
+ "ts-jest": "27.0.7",
23
+ "typescript": "^4.4.4"
24
+ },
25
+ "publishConfig": {
26
+ "access": "public"
27
+ },
28
+ "gitHead": "b249f24ee282149ef9a69885662d69b74a4523e6"
29
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,20 @@
1
+ {
2
+ "compilerOptions": {
3
+ "strict": false,
4
+ "outDir": "./lib",
5
+ "rootDir": "./src",
6
+ "module": "commonjs",
7
+ "target": "es2020",
8
+ "moduleResolution": "node",
9
+ "lib": ["es2020"],
10
+ "declaration": true,
11
+
12
+ "esModuleInterop": true,
13
+ "skipLibCheck": true,
14
+ "forceConsistentCasingInFileNames": true,
15
+
16
+ // required for ioc
17
+ "experimentalDecorators": true,
18
+ "emitDecoratorMetadata": true
19
+ }
20
+ }