@edirect/config 11.0.48 → 11.0.49
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 +10 -10
- package/dist/README.md +10 -10
- package/dist/package.json +1 -1
- package/dist/src/config/config-missing.error.d.ts +9 -0
- package/dist/src/config/config-missing.error.d.ts.map +1 -0
- package/dist/src/config/config-missing.error.js +16 -0
- package/dist/src/config/config.service.d.ts +8 -0
- package/dist/src/config/config.service.d.ts.map +1 -1
- package/dist/src/config/config.service.js +15 -0
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +1 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -54,11 +54,11 @@ export class MyService {
|
|
|
54
54
|
|
|
55
55
|
### `ConfigService`
|
|
56
56
|
|
|
57
|
-
| Method
|
|
58
|
-
|
|
59
|
-
| `constructor` | `(filePath?: string)`
|
|
60
|
-
| `get`
|
|
61
|
-
| `getConfig`
|
|
57
|
+
| Method | Signature | Description |
|
|
58
|
+
| ------------- | ------------------------------------ | ---------------------------------------------------------------------------------------------- |
|
|
59
|
+
| `constructor` | `(filePath?: string)` | Optionally pass a `.env` file path. Automatically called with `.{NODE_ENV}.env` by the module. |
|
|
60
|
+
| `get` | `(key: string): string \| undefined` | Returns the value for the given environment variable key from `process.env`. |
|
|
61
|
+
| `getConfig` | `(): IStringMapper` | Returns all environment variables as a `Record<string, string>`. |
|
|
62
62
|
|
|
63
63
|
### `CONFIG_SERVICE_TOKEN`
|
|
64
64
|
|
|
@@ -75,12 +75,12 @@ constructor(@Inject(CONFIG_SERVICE_TOKEN) private config: ConfigService) {}
|
|
|
75
75
|
|
|
76
76
|
The module automatically loads `.{NODE_ENV}.env` from the working directory:
|
|
77
77
|
|
|
78
|
-
| `NODE_ENV`
|
|
79
|
-
|
|
78
|
+
| `NODE_ENV` | File loaded |
|
|
79
|
+
| ----------------------- | ------------------ |
|
|
80
80
|
| `development` (default) | `.development.env` |
|
|
81
|
-
| `staging`
|
|
82
|
-
| `production`
|
|
83
|
-
| `test`
|
|
81
|
+
| `staging` | `.staging.env` |
|
|
82
|
+
| `production` | `.production.env` |
|
|
83
|
+
| `test` | `.test.env` |
|
|
84
84
|
|
|
85
85
|
**Example `.development.env`:**
|
|
86
86
|
|
package/dist/README.md
CHANGED
|
@@ -54,11 +54,11 @@ export class MyService {
|
|
|
54
54
|
|
|
55
55
|
### `ConfigService`
|
|
56
56
|
|
|
57
|
-
| Method
|
|
58
|
-
|
|
59
|
-
| `constructor` | `(filePath?: string)`
|
|
60
|
-
| `get`
|
|
61
|
-
| `getConfig`
|
|
57
|
+
| Method | Signature | Description |
|
|
58
|
+
| ------------- | ------------------------------------ | ---------------------------------------------------------------------------------------------- |
|
|
59
|
+
| `constructor` | `(filePath?: string)` | Optionally pass a `.env` file path. Automatically called with `.{NODE_ENV}.env` by the module. |
|
|
60
|
+
| `get` | `(key: string): string \| undefined` | Returns the value for the given environment variable key from `process.env`. |
|
|
61
|
+
| `getConfig` | `(): IStringMapper` | Returns all environment variables as a `Record<string, string>`. |
|
|
62
62
|
|
|
63
63
|
### `CONFIG_SERVICE_TOKEN`
|
|
64
64
|
|
|
@@ -75,12 +75,12 @@ constructor(@Inject(CONFIG_SERVICE_TOKEN) private config: ConfigService) {}
|
|
|
75
75
|
|
|
76
76
|
The module automatically loads `.{NODE_ENV}.env` from the working directory:
|
|
77
77
|
|
|
78
|
-
| `NODE_ENV`
|
|
79
|
-
|
|
78
|
+
| `NODE_ENV` | File loaded |
|
|
79
|
+
| ----------------------- | ------------------ |
|
|
80
80
|
| `development` (default) | `.development.env` |
|
|
81
|
-
| `staging`
|
|
82
|
-
| `production`
|
|
83
|
-
| `test`
|
|
81
|
+
| `staging` | `.staging.env` |
|
|
82
|
+
| `production` | `.production.env` |
|
|
83
|
+
| `test` | `.test.env` |
|
|
84
84
|
|
|
85
85
|
**Example `.development.env`:**
|
|
86
86
|
|
package/dist/package.json
CHANGED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Thrown when a required environment variable is absent or empty.
|
|
3
|
+
* Used by `ConfigService.getOrThrow()` and by modules that declare their own required config.
|
|
4
|
+
*/
|
|
5
|
+
export declare class ConfigMissingError extends Error {
|
|
6
|
+
readonly missingKey: string;
|
|
7
|
+
constructor(missingKey: string);
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=config-missing.error.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config-missing.error.d.ts","sourceRoot":"","sources":["../../../src/config/config-missing.error.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,qBAAa,kBAAmB,SAAQ,KAAK;IAC/B,QAAQ,CAAC,UAAU,EAAE,MAAM;gBAAlB,UAAU,EAAE,MAAM;CAIxC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ConfigMissingError = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Thrown when a required environment variable is absent or empty.
|
|
6
|
+
* Used by `ConfigService.getOrThrow()` and by modules that declare their own required config.
|
|
7
|
+
*/
|
|
8
|
+
class ConfigMissingError extends Error {
|
|
9
|
+
missingKey;
|
|
10
|
+
constructor(missingKey) {
|
|
11
|
+
super(`Missing required environment variable: "${missingKey}"`);
|
|
12
|
+
this.missingKey = missingKey;
|
|
13
|
+
this.name = 'ConfigMissingError';
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.ConfigMissingError = ConfigMissingError;
|
|
@@ -2,6 +2,14 @@ import { IStringMapper } from './config.interfaces';
|
|
|
2
2
|
export declare class ConfigService {
|
|
3
3
|
constructor(filePath?: string);
|
|
4
4
|
get(key: string): string | undefined;
|
|
5
|
+
/**
|
|
6
|
+
* Returns the value of an environment variable, or throws `ConfigMissingError` if it is
|
|
7
|
+
* absent or empty. Modules should use this for variables they strictly require.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* const url = configService.getOrThrow('MONGO_URL');
|
|
11
|
+
*/
|
|
12
|
+
getOrThrow(key: string): string;
|
|
5
13
|
getConfig(): IStringMapper;
|
|
6
14
|
}
|
|
7
15
|
//# sourceMappingURL=config.service.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.service.d.ts","sourceRoot":"","sources":["../../../src/config/config.service.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"config.service.d.ts","sourceRoot":"","sources":["../../../src/config/config.service.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD,qBAAa,aAAa;gBACZ,QAAQ,CAAC,EAAE,MAAM;IAW7B,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;IAIpC;;;;;;OAMG;IACH,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM;IAQ/B,SAAS,IAAI,aAAa;CAG3B"}
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.ConfigService = void 0;
|
|
4
4
|
const dotenv_1 = require("dotenv");
|
|
5
5
|
const fs_1 = require("fs");
|
|
6
|
+
const config_missing_error_1 = require("./config-missing.error");
|
|
6
7
|
class ConfigService {
|
|
7
8
|
constructor(filePath) {
|
|
8
9
|
try {
|
|
@@ -18,6 +19,20 @@ class ConfigService {
|
|
|
18
19
|
get(key) {
|
|
19
20
|
return process.env[key];
|
|
20
21
|
}
|
|
22
|
+
/**
|
|
23
|
+
* Returns the value of an environment variable, or throws `ConfigMissingError` if it is
|
|
24
|
+
* absent or empty. Modules should use this for variables they strictly require.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* const url = configService.getOrThrow('MONGO_URL');
|
|
28
|
+
*/
|
|
29
|
+
getOrThrow(key) {
|
|
30
|
+
const value = process.env[key];
|
|
31
|
+
if (!value) {
|
|
32
|
+
throw new config_missing_error_1.ConfigMissingError(key);
|
|
33
|
+
}
|
|
34
|
+
return value;
|
|
35
|
+
}
|
|
21
36
|
getConfig() {
|
|
22
37
|
return process.env;
|
|
23
38
|
}
|
package/dist/src/index.d.ts
CHANGED
package/dist/src/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC;AACvC,cAAc,yBAAyB,CAAC;AACxC,cAAc,4BAA4B,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC;AACvC,cAAc,yBAAyB,CAAC;AACxC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,+BAA+B,CAAC"}
|
package/dist/src/index.js
CHANGED
|
@@ -4,3 +4,4 @@ const tslib_1 = require("tslib");
|
|
|
4
4
|
tslib_1.__exportStar(require("./config/config.module"), exports);
|
|
5
5
|
tslib_1.__exportStar(require("./config/config.service"), exports);
|
|
6
6
|
tslib_1.__exportStar(require("./config/config.interfaces"), exports);
|
|
7
|
+
tslib_1.__exportStar(require("./config/config-missing.error"), exports);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@edirect/config",
|
|
3
|
-
"version": "11.0.
|
|
3
|
+
"version": "11.0.49",
|
|
4
4
|
"packageScope": "@edirect",
|
|
5
5
|
"main": "./dist/src/index.js",
|
|
6
6
|
"types": "./dist/src/index.d.ts",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"dist"
|
|
18
18
|
],
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@nestjs/common": "^11.1.
|
|
20
|
+
"@nestjs/common": "^11.1.16",
|
|
21
21
|
"dotenv": "17.3.1",
|
|
22
22
|
"tslib": "^2.8.1"
|
|
23
23
|
},
|