opticedge-cloud-utils 1.0.6 → 1.0.7

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/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from './auth/verify';
2
2
  export * from './db/mongo';
3
+ export * from './utils/env';
3
4
  export * from './utils/secrets';
4
5
  export * from './utils/task';
package/dist/index.js CHANGED
@@ -16,5 +16,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./auth/verify"), exports);
18
18
  __exportStar(require("./db/mongo"), exports);
19
+ __exportStar(require("./utils/env"), exports);
19
20
  __exportStar(require("./utils/secrets"), exports);
20
21
  __exportStar(require("./utils/task"), exports);
@@ -0,0 +1 @@
1
+ export declare function getEnv(name: string): string;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getEnv = getEnv;
4
+ function getEnv(name) {
5
+ const value = process.env[name];
6
+ if (!value) {
7
+ throw new Error(`Missing env var: ${name}`);
8
+ }
9
+ return value;
10
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ // src/utils/env.test.ts
4
+ const env_1 = require("./env");
5
+ describe('getEnv', () => {
6
+ it('should return the value of an existing env var', () => {
7
+ process.env.TEST_KEY = 'test-value';
8
+ expect((0, env_1.getEnv)('TEST_KEY')).toBe('test-value');
9
+ });
10
+ it('should throw an error if the env var is not set', () => {
11
+ delete process.env.MISSING_KEY;
12
+ expect(() => (0, env_1.getEnv)('MISSING_KEY')).toThrow('Missing env var: MISSING_KEY');
13
+ });
14
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opticedge-cloud-utils",
3
- "version": "1.0.6",
3
+ "version": "1.0.7",
4
4
  "description": "Common utilities for cloud functions",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/src/index.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from './auth/verify'
2
2
  export * from './db/mongo'
3
+ export * from './utils/env'
3
4
  export * from './utils/secrets'
4
5
  export * from './utils/task'
@@ -0,0 +1,14 @@
1
+ // src/utils/env.test.ts
2
+ import { getEnv } from './env'
3
+
4
+ describe('getEnv', () => {
5
+ it('should return the value of an existing env var', () => {
6
+ process.env.TEST_KEY = 'test-value'
7
+ expect(getEnv('TEST_KEY')).toBe('test-value')
8
+ })
9
+
10
+ it('should throw an error if the env var is not set', () => {
11
+ delete process.env.MISSING_KEY
12
+ expect(() => getEnv('MISSING_KEY')).toThrow('Missing env var: MISSING_KEY')
13
+ })
14
+ })
@@ -0,0 +1,7 @@
1
+ export function getEnv(name: string): string {
2
+ const value = process.env[name]
3
+ if (!value) {
4
+ throw new Error(`Missing env var: ${name}`)
5
+ }
6
+ return value
7
+ }