@nestjs/config
Advanced tools
Comparing version 3.1.1 to 3.2.0
@@ -0,2 +1,5 @@ | ||
/** | ||
* @publicApi | ||
*/ | ||
export declare class ConfigHostModule { | ||
} |
@@ -13,4 +13,8 @@ "use strict"; | ||
const config_service_1 = require("./config.service"); | ||
let ConfigHostModule = exports.ConfigHostModule = class ConfigHostModule { | ||
/** | ||
* @publicApi | ||
*/ | ||
let ConfigHostModule = class ConfigHostModule { | ||
}; | ||
exports.ConfigHostModule = ConfigHostModule; | ||
exports.ConfigHostModule = ConfigHostModule = __decorate([ | ||
@@ -17,0 +21,0 @@ (0, common_1.Global)(), |
import { DynamicModule } from '@nestjs/common'; | ||
import { ConfigFactory, ConfigModuleOptions } from './interfaces'; | ||
/** | ||
* @publicApi | ||
*/ | ||
export declare class ConfigModule { | ||
@@ -4,0 +7,0 @@ /** |
@@ -46,3 +46,6 @@ "use strict"; | ||
const merge_configs_util_1 = require("./utils/merge-configs.util"); | ||
let ConfigModule = exports.ConfigModule = ConfigModule_1 = class ConfigModule { | ||
/** | ||
* @publicApi | ||
*/ | ||
let ConfigModule = ConfigModule_1 = class ConfigModule { | ||
/** | ||
@@ -62,4 +65,9 @@ * This promise resolves when "dotenv" completes loading environment variables. | ||
static forRoot(options = {}) { | ||
const envFilePaths = Array.isArray(options.envFilePath) | ||
? options.envFilePath | ||
: [options.envFilePath || (0, path_1.resolve)(process.cwd(), '.env')]; | ||
let validatedEnvConfig = undefined; | ||
let config = options.ignoreEnvFile ? {} : this.loadEnvFile(options); | ||
let config = options.ignoreEnvFile | ||
? {} | ||
: this.loadEnvFile(envFilePaths, options); | ||
if (!options.ignoreEnvVars) { | ||
@@ -99,2 +107,3 @@ config = { | ||
} | ||
configService.setEnvFilePaths(envFilePaths); | ||
return configService; | ||
@@ -161,6 +170,3 @@ }, | ||
} | ||
static loadEnvFile(options) { | ||
const envFilePaths = Array.isArray(options.envFilePath) | ||
? options.envFilePath | ||
: [options.envFilePath || (0, path_1.resolve)(process.cwd(), '.env')]; | ||
static loadEnvFile(envFilePaths, options) { | ||
let config = {}; | ||
@@ -214,2 +220,3 @@ for (const envFilePath of envFilePaths) { | ||
}; | ||
exports.ConfigModule = ConfigModule; | ||
ConfigModule._envVariablesLoaded = new Promise(resolve => (ConfigModule_1.environmentVariablesLoadedSignal = resolve)); | ||
@@ -216,0 +223,0 @@ exports.ConfigModule = ConfigModule = ConfigModule_1 = __decorate([ |
@@ -0,1 +1,2 @@ | ||
import { ConfigChangeEvent } from './interfaces/config-change-event.interface'; | ||
import { NoInferType, Path, PathValue } from './types'; | ||
@@ -9,2 +10,5 @@ /** | ||
type ValidatedResult<WasValidated extends boolean, T> = WasValidated extends true ? T : T | undefined; | ||
/** | ||
* @publicApi | ||
*/ | ||
export interface ConfigGetOptions { | ||
@@ -19,2 +23,5 @@ /** | ||
type KeyOf<T> = keyof T extends never ? string : keyof T; | ||
/** | ||
* @publicApi | ||
*/ | ||
export declare class ConfigService<K = Record<string, unknown>, WasValidated extends boolean = false> { | ||
@@ -25,5 +32,12 @@ private readonly internalConfig; | ||
private readonly cache; | ||
private readonly _changes$; | ||
private _isCacheEnabled; | ||
private envFilePaths; | ||
constructor(internalConfig?: Record<string, any>); | ||
/** | ||
* Returns a stream of configuration changes. | ||
* Each event contains the attribute path, the old value and the new value. | ||
*/ | ||
get changes$(): import("rxjs").Observable<ConfigChangeEvent<any, any>>; | ||
/** | ||
* Get a configuration value (either custom configuration or process environment variable) | ||
@@ -90,2 +104,13 @@ * based on property path (you can use dot notation to traverse nested object, e.g. "database.host"). | ||
getOrThrow<T = K, P extends Path<T> = any, R = PathValue<T, P>>(propertyPath: P, defaultValue: NoInferType<R>, options: ConfigGetOptions): Exclude<R, undefined>; | ||
/** | ||
* Sets a configuration value based on property path. | ||
* @param propertyPath | ||
* @param value | ||
*/ | ||
set<T = any>(propertyPath: KeyOf<K>, value: T): void; | ||
/** | ||
* Sets env file paths from `config.module.ts` to parse. | ||
* @param paths | ||
*/ | ||
setEnvFilePaths(paths: string[]): void; | ||
private getFromCache; | ||
@@ -97,3 +122,4 @@ private getFromValidatedEnv; | ||
private isGetOptionsObject; | ||
private updateInterpolatedEnv; | ||
} | ||
export {}; |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { | ||
@@ -8,2 +24,9 @@ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; | ||
}; | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
var __metadata = (this && this.__metadata) || function (k, v) { | ||
@@ -22,7 +45,13 @@ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); | ||
const shared_utils_1 = require("@nestjs/common/utils/shared.utils"); | ||
const dotenv = __importStar(require("dotenv")); | ||
const fs_1 = __importDefault(require("fs")); | ||
const get_1 = __importDefault(require("lodash/get")); | ||
const has_1 = __importDefault(require("lodash/has")); | ||
const set_1 = __importDefault(require("lodash/set")); | ||
const rxjs_1 = require("rxjs"); | ||
const config_constants_1 = require("./config.constants"); | ||
let ConfigService = exports.ConfigService = class ConfigService { | ||
/** | ||
* @publicApi | ||
*/ | ||
let ConfigService = class ConfigService { | ||
set isCacheEnabled(value) { | ||
@@ -37,5 +66,14 @@ this._isCacheEnabled = value; | ||
this.cache = {}; | ||
this._changes$ = new rxjs_1.Subject(); | ||
this._isCacheEnabled = false; | ||
this.envFilePaths = []; | ||
} | ||
/** | ||
* Returns a stream of configuration changes. | ||
* Each event contains the attribute path, the old value and the new value. | ||
*/ | ||
get changes$() { | ||
return this._changes$.asObservable(); | ||
} | ||
/** | ||
* Get a configuration value (either custom configuration or process environment variable) | ||
@@ -82,2 +120,30 @@ * based on property path (you can use dot notation to traverse nested object, e.g. "database.host"). | ||
} | ||
/** | ||
* Sets a configuration value based on property path. | ||
* @param propertyPath | ||
* @param value | ||
*/ | ||
set(propertyPath, value) { | ||
const oldValue = this.get(propertyPath); | ||
(0, set_1.default)(this.internalConfig, propertyPath, value); | ||
if (typeof propertyPath === 'string') { | ||
process.env[propertyPath] = String(value); | ||
this.updateInterpolatedEnv(propertyPath, String(value)); | ||
} | ||
if (this.isCacheEnabled) { | ||
this.setInCacheIfDefined(propertyPath, value); | ||
} | ||
this._changes$.next({ | ||
path: propertyPath, | ||
oldValue, | ||
newValue: value, | ||
}); | ||
} | ||
/** | ||
* Sets env file paths from `config.module.ts` to parse. | ||
* @param paths | ||
*/ | ||
setEnvFilePaths(paths) { | ||
this.envFilePaths = paths; | ||
} | ||
getFromCache(propertyPath, defaultValue) { | ||
@@ -116,3 +182,18 @@ const cachedValue = (0, get_1.default)(this.cache, propertyPath); | ||
} | ||
updateInterpolatedEnv(propertyPath, value) { | ||
let config = {}; | ||
for (const envFilePath of this.envFilePaths) { | ||
if (fs_1.default.existsSync(envFilePath)) { | ||
config = Object.assign(dotenv.parse(fs_1.default.readFileSync(envFilePath)), config); | ||
} | ||
} | ||
const regex = new RegExp(`\\$\\{?${propertyPath}\\}?`, 'g'); | ||
for (const [k, v] of Object.entries(config)) { | ||
if (regex.test(v)) { | ||
process.env[k] = v.replace(regex, value); | ||
} | ||
} | ||
} | ||
}; | ||
exports.ConfigService = ConfigService; | ||
exports.ConfigService = ConfigService = __decorate([ | ||
@@ -119,0 +200,0 @@ (0, common_1.Injectable)(), |
import { ConfigFactory } from './config-factory.interface'; | ||
import { DotenvExpandOptions } from 'dotenv-expand'; | ||
/** | ||
* @publicApi | ||
*/ | ||
export interface ConfigModuleOptions { | ||
@@ -4,0 +7,0 @@ /** |
@@ -0,2 +1,3 @@ | ||
export * from './config-change-event.interface'; | ||
export * from './config-factory.interface'; | ||
export * from './config-module-options.interface'; |
@@ -17,3 +17,4 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
__exportStar(require("./config-change-event.interface"), exports); | ||
__exportStar(require("./config-factory.interface"), exports); | ||
__exportStar(require("./config-module-options.interface"), exports); |
@@ -0,1 +1,4 @@ | ||
/** | ||
* @publicApi | ||
*/ | ||
export type ConfigObject = Record<string, any>; |
@@ -0,1 +1,4 @@ | ||
/** | ||
* @publicApi | ||
*/ | ||
export type ConfigType<T extends (...args: any) => any> = T extends (...args: any) => infer ReturnVal ? ReturnVal extends Promise<infer AsyncReturnVal> ? AsyncReturnVal : ReturnVal : any; |
import { FactoryProvider } from '@nestjs/common/interfaces'; | ||
import { ConfigFactory } from '../interfaces'; | ||
import { ConfigFactoryKeyHost } from './register-as.util'; | ||
/** | ||
* @publicApi | ||
*/ | ||
export declare function createConfigProvider(factory: ConfigFactory & ConfigFactoryKeyHost): FactoryProvider; |
@@ -6,2 +6,5 @@ "use strict"; | ||
const get_config_token_util_1 = require("./get-config-token.util"); | ||
/** | ||
* @publicApi | ||
*/ | ||
function createConfigProvider(factory) { | ||
@@ -8,0 +11,0 @@ return { |
@@ -0,1 +1,4 @@ | ||
/** | ||
* @publicApi | ||
*/ | ||
export declare function getConfigToken(token: string): string; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getConfigToken = void 0; | ||
/** | ||
* @publicApi | ||
*/ | ||
function getConfigToken(token) { | ||
@@ -5,0 +8,0 @@ return `CONFIGURATION(${token})`; |
@@ -0,1 +1,4 @@ | ||
/** | ||
* @publicApi | ||
*/ | ||
export declare function getRegistrationToken(config: Record<string, any>): any; |
@@ -5,2 +5,5 @@ "use strict"; | ||
const config_constants_1 = require("../config.constants"); | ||
/** | ||
* @publicApi | ||
*/ | ||
function getRegistrationToken(config) { | ||
@@ -7,0 +10,0 @@ return config[config_constants_1.PARTIAL_CONFIGURATION_KEY]; |
@@ -0,1 +1,4 @@ | ||
/** | ||
* @publicApi | ||
*/ | ||
export declare function mergeConfigObject(host: Record<string, any>, partial: Record<string, any>, token?: string): Record<string, any> | undefined; |
@@ -8,2 +8,5 @@ "use strict"; | ||
const set_1 = __importDefault(require("lodash/set")); | ||
/** | ||
* @publicApi | ||
*/ | ||
function mergeConfigObject(host, partial, token) { | ||
@@ -10,0 +13,0 @@ if (token) { |
import { ConfigModule } from '..'; | ||
import { ConfigFactory } from '../interfaces'; | ||
import { ConfigObject } from '../types'; | ||
/** | ||
* @publicApi | ||
*/ | ||
export interface ConfigFactoryKeyHost<T = unknown> { | ||
@@ -13,4 +16,6 @@ KEY: string; | ||
/** | ||
* @publicApi | ||
* | ||
* Registers the configuration object behind a specified token. | ||
*/ | ||
export declare function registerAs<TConfig extends ConfigObject, TFactory extends ConfigFactory = ConfigFactory<TConfig>>(token: string, configFactory: TFactory): TFactory & ConfigFactoryKeyHost<ReturnType<TFactory>>; |
@@ -8,2 +8,4 @@ "use strict"; | ||
/** | ||
* @publicApi | ||
* | ||
* Registers the configuration object behind a specified token. | ||
@@ -10,0 +12,0 @@ */ |
{ | ||
"name": "@nestjs/config", | ||
"version": "3.1.1", | ||
"version": "3.2.0", | ||
"description": "Nest - modern, fast, powerful node.js web framework (@config)", | ||
@@ -21,37 +21,38 @@ "author": "Kamil Mysliwiec", | ||
"dependencies": { | ||
"dotenv": "16.3.1", | ||
"dotenv": "16.4.1", | ||
"dotenv-expand": "10.0.0", | ||
"lodash": "4.17.21", | ||
"uuid": "9.0.0" | ||
"uuid": "9.0.1" | ||
}, | ||
"devDependencies": { | ||
"@commitlint/cli": "17.7.1", | ||
"@commitlint/config-angular": "17.7.0", | ||
"@nestjs/common": "10.2.5", | ||
"@nestjs/core": "10.2.5", | ||
"@nestjs/platform-express": "10.2.5", | ||
"@nestjs/testing": "10.2.5", | ||
"@types/jest": "29.5.4", | ||
"@types/lodash": "4.14.198", | ||
"@types/node": "18.17.15", | ||
"@types/uuid": "9.0.3", | ||
"@typescript-eslint/eslint-plugin": "6.7.0", | ||
"@typescript-eslint/parser": "6.7.0", | ||
"eslint": "8.49.0", | ||
"eslint-config-prettier": "9.0.0", | ||
"eslint-plugin-import": "2.28.1", | ||
"husky": "8.0.3", | ||
"@commitlint/cli": "18.6.0", | ||
"@commitlint/config-angular": "18.6.0", | ||
"@nestjs/common": "10.3.2", | ||
"@nestjs/core": "10.3.2", | ||
"@nestjs/platform-express": "10.3.2", | ||
"@nestjs/testing": "10.3.2", | ||
"@types/jest": "29.5.12", | ||
"@types/lodash": "4.14.202", | ||
"@types/node": "20.11.16", | ||
"@types/uuid": "9.0.8", | ||
"@typescript-eslint/eslint-plugin": "6.21.0", | ||
"@typescript-eslint/parser": "6.21.0", | ||
"eslint": "8.56.0", | ||
"eslint-config-prettier": "9.1.0", | ||
"eslint-plugin-import": "2.29.1", | ||
"husky": "9.0.10", | ||
"jest": "29.7.0", | ||
"joi": "17.10.1", | ||
"lint-staged": "14.0.1", | ||
"prettier": "3.0.3", | ||
"reflect-metadata": "0.1.13", | ||
"release-it": "16.1.5", | ||
"rimraf": "5.0.1", | ||
"ts-jest": "29.1.1", | ||
"typescript": "5.2.2" | ||
"joi": "17.12.1", | ||
"lint-staged": "15.2.2", | ||
"prettier": "3.2.5", | ||
"reflect-metadata": "0.1.14", | ||
"release-it": "17.0.3", | ||
"rimraf": "5.0.5", | ||
"rxjs": "7.8.1", | ||
"ts-jest": "29.1.2", | ||
"typescript": "5.3.3" | ||
}, | ||
"peerDependencies": { | ||
"@nestjs/common": "^8.0.0 || ^9.0.0 || ^10.0.0", | ||
"reflect-metadata": "^0.1.13" | ||
"rxjs": "^7.1.0" | ||
}, | ||
@@ -58,0 +59,0 @@ "lint-staged": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
49270
48
1030
26
10
+ Addeddotenv@16.4.1(transitive)
+ Addedreflect-metadata@0.2.2(transitive)
+ Addeduuid@9.0.1(transitive)
- Removeddotenv@16.3.1(transitive)
- Removedreflect-metadata@0.1.14(transitive)
- Removeduuid@9.0.0(transitive)
Updateddotenv@16.4.1
Updateduuid@9.0.1