@orion-js/env 3.1.9 → 3.1.10

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.
@@ -2,10 +2,12 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.env = void 0;
4
4
  const crypto_1 = require("@orion-js/crypto");
5
- const env = {};
6
- exports.env = env;
5
+ let variables = {};
7
6
  const g = global;
8
- if (g.__orion_env__) {
7
+ if (g.__orion_env_final__) {
8
+ variables = g.__orion_env_final__;
9
+ }
10
+ else if (g.__orion_env__) {
9
11
  const secretKey = process.env.ORION_ENV_SECRET_KEY;
10
12
  if (!secretKey) {
11
13
  throw new Error('Orion encrypted env was passed but process.env.ORION_ENV_SECRET_KEY is not defined');
@@ -14,15 +16,18 @@ if (g.__orion_env__) {
14
16
  const encryptedKeys = g.__orion_env__.encryptedKeys;
15
17
  for (const key in cleanKeys) {
16
18
  const value = cleanKeys[key];
17
- env[key] = value;
19
+ variables[key] = value;
18
20
  }
19
21
  for (const key in encryptedKeys) {
20
22
  const encrypted = encryptedKeys[key];
21
23
  try {
22
- env[key] = crypto_1.asymmetric.decrypt(secretKey, encrypted);
24
+ variables[key] = crypto_1.asymmetric.decrypt(secretKey, encrypted);
23
25
  }
24
26
  catch (error) {
25
27
  throw new Error(`Orion encrypted env was passed but process.env.ORION_ENV_SECRET_KEY is not the right key for "${key}"`);
26
28
  }
27
29
  }
28
30
  }
31
+ g.__orion_env_final__ = variables;
32
+ const env = variables;
33
+ exports.env = env;
@@ -4,6 +4,8 @@ require("reflect-metadata");
4
4
  const crypto_1 = require("@orion-js/crypto");
5
5
  describe('Environment', () => {
6
6
  beforeEach(() => {
7
+ ;
8
+ global.__orion_env_final__ = undefined;
7
9
  jest.resetModules();
8
10
  });
9
11
  it('should define all environment variables', async () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@orion-js/env",
3
- "version": "3.1.9",
3
+ "version": "3.1.10",
4
4
  "main": "lib/index.js",
5
5
  "author": "nicolaslopezj",
6
6
  "license": "MIT",
@@ -25,5 +25,5 @@
25
25
  "publishConfig": {
26
26
  "access": "public"
27
27
  },
28
- "gitHead": "b249f24ee282149ef9a69885662d69b74a4523e6"
28
+ "gitHead": "40fa0800303f49ad08890b2bedff2cdadb81360d"
29
29
  }