nestjs-env-getter 1.0.0-beta.1 → 1.0.0-beta.2

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/CHANGELOG.md CHANGED
@@ -7,6 +7,16 @@ All notable changes to this project will be documented in this file.
7
7
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
8
8
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
9
9
 
10
+ ## [1.0.0-beta.2] - 2025-10-17
11
+
12
+ ### Added
13
+
14
+ - **Inject Custom Providers**: Added the ability to inject custom providers into `AppConfigModule` via `forRoot` and `forRootAsync`. This allows `AppConfig` classes to depend on other services for dynamic configuration.
15
+
16
+ ### Changed
17
+
18
+ - **Updated Example**: The `nestjs-server` example was updated to demonstrate how to inject a custom `AppConfigOptionsService` to dynamically select configuration files based on the environment.
19
+
10
20
  ## [1.0.0-beta.1] - 2025-10-08
11
21
 
12
22
  ### Added
@@ -1,12 +1,16 @@
1
- import { DynamicModule, Type, InjectionToken, OptionalFactoryDependency } from "@nestjs/common";
1
+ import { DynamicModule, Provider, Type, InjectionToken, OptionalFactoryDependency } from "@nestjs/common";
2
2
  export interface AppConfigModuleOptions {
3
3
  useClass?: Type<unknown>;
4
4
  useFactory?: (...args: unknown[]) => unknown;
5
5
  inject?: (InjectionToken | OptionalFactoryDependency)[];
6
+ imports?: any[];
7
+ providers?: Provider[];
6
8
  }
7
9
  export declare class AppConfigModule {
8
10
  static forRoot(options: {
9
11
  useClass: Type<unknown>;
12
+ imports?: any[];
13
+ providers?: Provider[];
10
14
  }): DynamicModule;
11
15
  static forRootAsync(options: AppConfigModuleOptions): DynamicModule;
12
16
  }
@@ -13,13 +13,16 @@ const env_getter_service_1 = require("../env-getter/env-getter.service");
13
13
  let AppConfigModule = AppConfigModule_1 = class AppConfigModule {
14
14
  static forRoot(options) {
15
15
  const provider = { provide: options.useClass, useClass: options.useClass };
16
+ const additionalProviders = options.providers || [];
16
17
  return {
17
18
  module: AppConfigModule_1,
18
- providers: [env_getter_service_1.EnvGetterService, provider],
19
- exports: [env_getter_service_1.EnvGetterService, provider],
19
+ imports: options.imports || [],
20
+ providers: [env_getter_service_1.EnvGetterService, provider, ...additionalProviders],
21
+ exports: [env_getter_service_1.EnvGetterService, provider, ...additionalProviders],
20
22
  };
21
23
  }
22
24
  static forRootAsync(options) {
25
+ const additionalProviders = options.providers || [];
23
26
  if (options.useFactory) {
24
27
  const provider = {
25
28
  provide: "APP_CONFIG",
@@ -28,8 +31,9 @@ let AppConfigModule = AppConfigModule_1 = class AppConfigModule {
28
31
  };
29
32
  return {
30
33
  module: AppConfigModule_1,
31
- providers: [env_getter_service_1.EnvGetterService, provider],
32
- exports: [env_getter_service_1.EnvGetterService, provider],
34
+ imports: options.imports || [],
35
+ providers: [env_getter_service_1.EnvGetterService, provider, ...additionalProviders],
36
+ exports: [env_getter_service_1.EnvGetterService, provider, ...additionalProviders],
33
37
  };
34
38
  }
35
39
  // useClass path (register the class itself as token so consumer can inject by class)
@@ -37,8 +41,9 @@ let AppConfigModule = AppConfigModule_1 = class AppConfigModule {
37
41
  const provider = { provide: options.useClass, useClass: options.useClass };
38
42
  return {
39
43
  module: AppConfigModule_1,
40
- providers: [env_getter_service_1.EnvGetterService, provider],
41
- exports: [env_getter_service_1.EnvGetterService, provider],
44
+ imports: options.imports || [],
45
+ providers: [env_getter_service_1.EnvGetterService, provider, ...additionalProviders],
46
+ exports: [env_getter_service_1.EnvGetterService, provider, ...additionalProviders],
42
47
  };
43
48
  }
44
49
  throw new Error("AppConfigModule.forRootAsync requires useClass or useFactory");
@@ -1,3 +1,3 @@
1
- export { ArrayValidatorType } from "./array-validator.type";
2
- export { FileWatcherOptions } from "./file-watcher-options.type";
3
- export { ConfigUpdatedEvent, ConfigErrorEvent, ConfigEventType, Disposable, WithConfigEvents, } from "./config-events.type";
1
+ export type { ArrayValidatorType } from "./array-validator.type";
2
+ export type { FileWatcherOptions } from "./file-watcher-options.type";
3
+ export type { ConfigUpdatedEvent, ConfigErrorEvent, ConfigEventType, Disposable, WithConfigEvents, } from "./config-events.type";
@@ -1,2 +1,2 @@
1
- export { ClassConstructor } from "./class-constructor.type";
2
- export { TimeMarker } from "./time-marker.type";
1
+ export type { ClassConstructor } from "./class-constructor.type";
2
+ export type { TimeMarker } from "./time-marker.type";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nestjs-env-getter",
3
- "version": "1.0.0-beta.1",
3
+ "version": "1.0.0-beta.2",
4
4
  "description": "Environment variables getter for Nestjs applications",
5
5
  "author": "Ivan Baha",
6
6
  "private": false,
@@ -9,7 +9,13 @@ export class AppConfig {
9
9
  // readonly mongoConnectionString: string;
10
10
  // readonly optionalConfigBoolean?: boolean;
11
11
 
12
- constructor(protected readonly envGetter: EnvGetterService) {
12
+ constructor(
13
+ protected readonly envGetter: EnvGetterService,
14
+ // You can inject additional providers that were registered in AppConfigModule
15
+ // For example:
16
+ // private readonly databaseService: DatabaseService,
17
+ // private readonly externalApiClient: ExternalApiClient,
18
+ ) {
13
19
  // initialize your config properties here, for example:
14
20
 
15
21
  // this.port = this.envGetter.getOptionalNumericEnv("PORT", 3000);
@@ -20,6 +26,10 @@ export class AppConfig {
20
26
  // { testConfigStringFromFile: 'default-value' },
21
27
  // TestConfig,
22
28
  // );
29
+
30
+ // You can use injected providers to initialize config values:
31
+ // this.dynamicPort = this.databaseService.getRecommendedPort();
32
+ // this.apiEndpoint = this.externalApiClient.getBaseUrl();
23
33
  }
24
34
  }
25
35