@edirect/config 11.0.62-beta.2 → 11.0.62
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/package.json +3 -20
- package/dist/README.md +0 -103
- package/dist/package.json +0 -24
- package/dist/src/config/config-missing.error.d.ts +0 -9
- package/dist/src/config/config-missing.error.d.ts.map +0 -1
- package/dist/src/config/config-missing.error.js +0 -16
- package/dist/src/config/config.constants.d.ts +0 -2
- package/dist/src/config/config.constants.d.ts.map +0 -1
- package/dist/src/config/config.constants.js +0 -4
- package/dist/src/config/config.interfaces.d.ts +0 -4
- package/dist/src/config/config.interfaces.d.ts.map +0 -1
- package/dist/src/config/config.interfaces.js +0 -2
- package/dist/src/config/config.module.d.ts +0 -3
- package/dist/src/config/config.module.d.ts.map +0 -1
- package/dist/src/config/config.module.js +0 -17
- package/dist/src/config/config.providers.d.ts +0 -3
- package/dist/src/config/config.providers.d.ts.map +0 -1
- package/dist/src/config/config.providers.js +0 -15
- package/dist/src/config/config.service.d.ts +0 -15
- package/dist/src/config/config.service.d.ts.map +0 -1
- package/dist/src/config/config.service.js +0 -48
- package/dist/src/index.d.ts +0 -5
- package/dist/src/index.d.ts.map +0 -1
- package/dist/src/index.js +0 -7
- package/dist/tsconfig.lib.tsbuildinfo +0 -1
package/package.json
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@edirect/config",
|
|
3
|
-
"version": "11.0.62
|
|
4
|
-
"packageScope": "@edirect",
|
|
3
|
+
"version": "11.0.62",
|
|
5
4
|
"main": "./dist/src/index.js",
|
|
6
5
|
"types": "./dist/src/index.d.ts",
|
|
7
6
|
"exports": {
|
|
@@ -17,25 +16,9 @@
|
|
|
17
16
|
"dist"
|
|
18
17
|
],
|
|
19
18
|
"dependencies": {
|
|
20
|
-
"@nestjs/common": "^11.1
|
|
19
|
+
"@nestjs/common": "^11.2.1",
|
|
21
20
|
"dotenv": "17.4.2",
|
|
22
21
|
"tslib": "^2.8.1"
|
|
23
22
|
},
|
|
24
|
-
"
|
|
25
|
-
"name": "@edirect/config",
|
|
26
|
-
"targets": {
|
|
27
|
-
"build": {
|
|
28
|
-
"executor": "@nx/js:tsc",
|
|
29
|
-
"options": {
|
|
30
|
-
"main": "{workspaceRoot}/packages/edirect-config/src/index.ts",
|
|
31
|
-
"tsConfig": "{workspaceRoot}/packages/edirect-config/tsconfig.lib.json",
|
|
32
|
-
"outputPath": "{workspaceRoot}/packages/edirect-config/dist",
|
|
33
|
-
"assets": [
|
|
34
|
-
"{workspaceRoot}/packages/edirect-config/package.json",
|
|
35
|
-
"{workspaceRoot}/packages/edirect-config/README.md"
|
|
36
|
-
]
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}
|
|
23
|
+
"type": "commonjs"
|
|
41
24
|
}
|
package/dist/README.md
DELETED
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
# @edirect/config
|
|
2
|
-
|
|
3
|
-
Global NestJS configuration module for eDirect applications. Provides environment variable loading via `dotenv` and a `ConfigService` for accessing configuration values across the application.
|
|
4
|
-
|
|
5
|
-
## Features
|
|
6
|
-
|
|
7
|
-
- Loads `.{NODE_ENV}.env` file automatically on startup (e.g., `.development.env`, `.production.env`)
|
|
8
|
-
- Global module — register once, inject `ConfigService` anywhere
|
|
9
|
-
- Simple `get(key)` / `getConfig()` API
|
|
10
|
-
- Dual injection tokens: class token (`ConfigService`) and string constant (`CONFIG_SERVICE_TOKEN`)
|
|
11
|
-
|
|
12
|
-
## Installation
|
|
13
|
-
|
|
14
|
-
```sh
|
|
15
|
-
pnpm add @edirect/config
|
|
16
|
-
# or
|
|
17
|
-
npm install @edirect/config
|
|
18
|
-
```
|
|
19
|
-
|
|
20
|
-
## Usage
|
|
21
|
-
|
|
22
|
-
### Register in your AppModule
|
|
23
|
-
|
|
24
|
-
```ts
|
|
25
|
-
import { Module } from '@nestjs/common';
|
|
26
|
-
import { ConfigModule } from '@edirect/config';
|
|
27
|
-
|
|
28
|
-
@Module({
|
|
29
|
-
imports: [ConfigModule],
|
|
30
|
-
})
|
|
31
|
-
export class AppModule {}
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
Because `ConfigModule` is decorated with `@Global()`, you only need to import it once at the root module. `ConfigService` will be available for injection in all feature modules automatically.
|
|
35
|
-
|
|
36
|
-
### Inject ConfigService
|
|
37
|
-
|
|
38
|
-
```ts
|
|
39
|
-
import { Injectable } from '@nestjs/common';
|
|
40
|
-
import { ConfigService } from '@edirect/config';
|
|
41
|
-
|
|
42
|
-
@Injectable()
|
|
43
|
-
export class MyService {
|
|
44
|
-
constructor(private readonly config: ConfigService) {}
|
|
45
|
-
|
|
46
|
-
doSomething() {
|
|
47
|
-
const dbUrl = this.config.get('DATABASE_URL');
|
|
48
|
-
const port = this.config.get('PORT') ?? '3000';
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
```
|
|
52
|
-
|
|
53
|
-
## API
|
|
54
|
-
|
|
55
|
-
### `ConfigService`
|
|
56
|
-
|
|
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
|
-
|
|
63
|
-
### `CONFIG_SERVICE_TOKEN`
|
|
64
|
-
|
|
65
|
-
An alternative injection token (string constant) for `ConfigService`. Useful when you need to inject by token rather than by class:
|
|
66
|
-
|
|
67
|
-
```ts
|
|
68
|
-
import { Inject } from '@nestjs/common';
|
|
69
|
-
import { CONFIG_SERVICE_TOKEN, ConfigService } from '@edirect/config';
|
|
70
|
-
|
|
71
|
-
constructor(@Inject(CONFIG_SERVICE_TOKEN) private config: ConfigService) {}
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
## Environment File Convention
|
|
75
|
-
|
|
76
|
-
The module automatically loads `.{NODE_ENV}.env` from the working directory:
|
|
77
|
-
|
|
78
|
-
| `NODE_ENV` | File loaded |
|
|
79
|
-
| ----------------------- | ------------------ |
|
|
80
|
-
| `development` (default) | `.development.env` |
|
|
81
|
-
| `staging` | `.staging.env` |
|
|
82
|
-
| `production` | `.production.env` |
|
|
83
|
-
| `test` | `.test.env` |
|
|
84
|
-
|
|
85
|
-
**Example `.development.env`:**
|
|
86
|
-
|
|
87
|
-
```env
|
|
88
|
-
PORT=3000
|
|
89
|
-
DATABASE_URL=mongodb://localhost:27017/mydb
|
|
90
|
-
REDIS_URL=redis://localhost:6379
|
|
91
|
-
LOGS_LEVEL=debug
|
|
92
|
-
```
|
|
93
|
-
|
|
94
|
-
> **Note:** Never commit `.env` files containing sensitive credentials to version control.
|
|
95
|
-
|
|
96
|
-
## Exports
|
|
97
|
-
|
|
98
|
-
```ts
|
|
99
|
-
export { ConfigModule } from './config/config.module';
|
|
100
|
-
export { ConfigService } from './config/config.service';
|
|
101
|
-
export { CONFIG_SERVICE_TOKEN } from './config/config.constants';
|
|
102
|
-
export type { IStringMapper } from './config/config.interfaces';
|
|
103
|
-
```
|
package/dist/package.json
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@edirect/config",
|
|
3
|
-
"version": "11.0.62-beta.2",
|
|
4
|
-
"main": "./dist/src/index.js",
|
|
5
|
-
"types": "./dist/src/index.d.ts",
|
|
6
|
-
"exports": {
|
|
7
|
-
".": {
|
|
8
|
-
"import": "./dist/src/index.js",
|
|
9
|
-
"default": "./dist/src/index.js",
|
|
10
|
-
"require": "./dist/src/index.js",
|
|
11
|
-
"types": "./dist/src/index.d.ts"
|
|
12
|
-
},
|
|
13
|
-
"./package.json": "./package.json"
|
|
14
|
-
},
|
|
15
|
-
"files": [
|
|
16
|
-
"dist"
|
|
17
|
-
],
|
|
18
|
-
"dependencies": {
|
|
19
|
-
"@nestjs/common": "^11.1.19",
|
|
20
|
-
"dotenv": "17.4.2",
|
|
21
|
-
"tslib": "^2.8.1"
|
|
22
|
-
},
|
|
23
|
-
"type": "commonjs"
|
|
24
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,16 +0,0 @@
|
|
|
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;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"config.constants.d.ts","sourceRoot":"","sources":["../../../src/config/config.constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,oBAAoB,mBAAmB,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"config.interfaces.d.ts","sourceRoot":"","sources":["../../../src/config/config.interfaces.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,aAAa;IAC5B,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;CACvB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"config.module.d.ts","sourceRoot":"","sources":["../../../src/config/config.module.ts"],"names":[],"mappings":"AAKA,qBAKa,YAAY;CAAG"}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ConfigModule = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const common_1 = require("@nestjs/common");
|
|
6
|
-
const config_providers_1 = require("./config.providers");
|
|
7
|
-
const config_service_1 = require("./config.service");
|
|
8
|
-
let ConfigModule = class ConfigModule {
|
|
9
|
-
};
|
|
10
|
-
exports.ConfigModule = ConfigModule;
|
|
11
|
-
exports.ConfigModule = ConfigModule = tslib_1.__decorate([
|
|
12
|
-
(0, common_1.Global)(),
|
|
13
|
-
(0, common_1.Module)({
|
|
14
|
-
providers: [...config_providers_1.ConfigProviders],
|
|
15
|
-
exports: [config_service_1.ConfigService],
|
|
16
|
-
})
|
|
17
|
-
], ConfigModule);
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"config.providers.d.ts","sourceRoot":"","sources":["../../../src/config/config.providers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAK1C,eAAO,MAAM,eAAe,EAAE,QAAQ,EAWrC,CAAC"}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ConfigProviders = void 0;
|
|
4
|
-
const config_service_1 = require("./config.service");
|
|
5
|
-
const config_constants_1 = require("./config.constants");
|
|
6
|
-
exports.ConfigProviders = [
|
|
7
|
-
{
|
|
8
|
-
provide: config_service_1.ConfigService,
|
|
9
|
-
useValue: new config_service_1.ConfigService(`.${process.env.NODE_ENV || 'development'}.env`),
|
|
10
|
-
},
|
|
11
|
-
{
|
|
12
|
-
provide: config_constants_1.CONFIG_SERVICE_TOKEN,
|
|
13
|
-
useExisting: config_service_1.ConfigService,
|
|
14
|
-
},
|
|
15
|
-
];
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { IStringMapper } from './config.interfaces';
|
|
2
|
-
export declare class ConfigService {
|
|
3
|
-
constructor(filePath?: string);
|
|
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;
|
|
13
|
-
getConfig(): IStringMapper;
|
|
14
|
-
}
|
|
15
|
-
//# sourceMappingURL=config.service.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"config.service.d.ts","sourceRoot":"","sources":["../../../src/config/config.service.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD,qBACa,aAAa;gBAC4B,QAAQ,CAAC,EAAE,MAAM;IAWrE,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"}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ConfigService = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const common_1 = require("@nestjs/common");
|
|
6
|
-
const dotenv_1 = require("dotenv");
|
|
7
|
-
const fs_1 = require("fs");
|
|
8
|
-
const config_missing_error_1 = require("./config-missing.error");
|
|
9
|
-
let ConfigService = class ConfigService {
|
|
10
|
-
constructor(filePath) {
|
|
11
|
-
try {
|
|
12
|
-
if (filePath && (0, fs_1.existsSync)(filePath)) {
|
|
13
|
-
process.env = { ...process.env, ...(0, dotenv_1.parse)((0, fs_1.readFileSync)(filePath)) };
|
|
14
|
-
}
|
|
15
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
16
|
-
}
|
|
17
|
-
catch (error) {
|
|
18
|
-
/* empty */
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
get(key) {
|
|
22
|
-
return process.env[key];
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Returns the value of an environment variable, or throws `ConfigMissingError` if it is
|
|
26
|
-
* absent or empty. Modules should use this for variables they strictly require.
|
|
27
|
-
*
|
|
28
|
-
* @example
|
|
29
|
-
* const url = configService.getOrThrow('MONGO_URL');
|
|
30
|
-
*/
|
|
31
|
-
getOrThrow(key) {
|
|
32
|
-
const value = process.env[key];
|
|
33
|
-
if (!value) {
|
|
34
|
-
throw new config_missing_error_1.ConfigMissingError(key);
|
|
35
|
-
}
|
|
36
|
-
return value;
|
|
37
|
-
}
|
|
38
|
-
getConfig() {
|
|
39
|
-
return process.env;
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
exports.ConfigService = ConfigService;
|
|
43
|
-
exports.ConfigService = ConfigService = tslib_1.__decorate([
|
|
44
|
-
(0, common_1.Injectable)(),
|
|
45
|
-
tslib_1.__param(0, (0, common_1.Optional)()),
|
|
46
|
-
tslib_1.__param(0, (0, common_1.Inject)('CONFIG_FILE_PATH')),
|
|
47
|
-
tslib_1.__metadata("design:paramtypes", [String])
|
|
48
|
-
], ConfigService);
|
package/dist/src/index.d.ts
DELETED
package/dist/src/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const tslib_1 = require("tslib");
|
|
4
|
-
tslib_1.__exportStar(require("./config/config.module"), exports);
|
|
5
|
-
tslib_1.__exportStar(require("./config/config.service"), exports);
|
|
6
|
-
tslib_1.__exportStar(require("./config/config.interfaces"), exports);
|
|
7
|
-
tslib_1.__exportStar(require("./config/config-missing.error"), exports);
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":"5.9.3"}
|