@dyanet/nestjs-config-aws 1.0.1
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/LICENSE +21 -0
- package/README.md +1183 -0
- package/dist/cjs/config.module.js +178 -0
- package/dist/cjs/config.module.js.map +1 -0
- package/dist/cjs/index.js +47 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/integration/index.js +23 -0
- package/dist/cjs/integration/index.js.map +1 -0
- package/dist/cjs/integration/interfaces/configuration-factory.interface.js +3 -0
- package/dist/cjs/integration/interfaces/configuration-factory.interface.js.map +1 -0
- package/dist/cjs/integration/interfaces/configuration-source.interface.js +3 -0
- package/dist/cjs/integration/interfaces/configuration-source.interface.js.map +1 -0
- package/dist/cjs/integration/interfaces/index.js +26 -0
- package/dist/cjs/integration/interfaces/index.js.map +1 -0
- package/dist/cjs/integration/interfaces/integration-options.interface.js +3 -0
- package/dist/cjs/integration/interfaces/integration-options.interface.js.map +1 -0
- package/dist/cjs/integration/interfaces/integration-state.interface.js +3 -0
- package/dist/cjs/integration/interfaces/integration-state.interface.js.map +1 -0
- package/dist/cjs/integration/interfaces/nestjs-config-compatibility.interface.js +73 -0
- package/dist/cjs/integration/interfaces/nestjs-config-compatibility.interface.js.map +1 -0
- package/dist/cjs/integration/interfaces/nestjs-config-integration.interface.js +3 -0
- package/dist/cjs/integration/interfaces/nestjs-config-integration.interface.js.map +1 -0
- package/dist/cjs/integration/interfaces/typed-configuration.interface.js +4 -0
- package/dist/cjs/integration/interfaces/typed-configuration.interface.js.map +1 -0
- package/dist/cjs/integration/interfaces/utility-types.interface.js +52 -0
- package/dist/cjs/integration/interfaces/utility-types.interface.js.map +1 -0
- package/dist/cjs/integration/nestjs-config-integration.module.js +124 -0
- package/dist/cjs/integration/nestjs-config-integration.module.js.map +1 -0
- package/dist/cjs/integration/providers/aws-configuration-loader.service.js +591 -0
- package/dist/cjs/integration/providers/aws-configuration-loader.service.js.map +1 -0
- package/dist/cjs/integration/providers/configuration-factory.provider.js +383 -0
- package/dist/cjs/integration/providers/configuration-factory.provider.js.map +1 -0
- package/dist/cjs/integration/providers/index.js +20 -0
- package/dist/cjs/integration/providers/index.js.map +1 -0
- package/dist/cjs/integration/services/async-config-helper.service.js +356 -0
- package/dist/cjs/integration/services/async-config-helper.service.js.map +1 -0
- package/dist/cjs/integration/services/error-handler.service.js +265 -0
- package/dist/cjs/integration/services/error-handler.service.js.map +1 -0
- package/dist/cjs/integration/services/factory-registration.service.js +512 -0
- package/dist/cjs/integration/services/factory-registration.service.js.map +1 -0
- package/dist/cjs/integration/services/index.js +26 -0
- package/dist/cjs/integration/services/index.js.map +1 -0
- package/dist/cjs/integration/services/integration-state.service.js +83 -0
- package/dist/cjs/integration/services/integration-state.service.js.map +1 -0
- package/dist/cjs/integration/services/namespace-handler.service.js +467 -0
- package/dist/cjs/integration/services/namespace-handler.service.js.map +1 -0
- package/dist/cjs/integration/services/nestjs-config-integration.service.js +316 -0
- package/dist/cjs/integration/services/nestjs-config-integration.service.js.map +1 -0
- package/dist/cjs/integration/services/precedence-handler.service.js +294 -0
- package/dist/cjs/integration/services/precedence-handler.service.js.map +1 -0
- package/dist/cjs/integration/services/validation-integration.service.js +591 -0
- package/dist/cjs/integration/services/validation-integration.service.js.map +1 -0
- package/dist/cjs/integration/utils/config-integration.util.js +283 -0
- package/dist/cjs/integration/utils/config-integration.util.js.map +1 -0
- package/dist/cjs/integration/utils/index.js +19 -0
- package/dist/cjs/integration/utils/index.js.map +1 -0
- package/dist/cjs/interfaces/config-loader.interface.js +3 -0
- package/dist/cjs/interfaces/config-loader.interface.js.map +1 -0
- package/dist/cjs/interfaces/config-service.interface.js +11 -0
- package/dist/cjs/interfaces/config-service.interface.js.map +1 -0
- package/dist/cjs/interfaces/default-schema.interface.js +63 -0
- package/dist/cjs/interfaces/default-schema.interface.js.map +1 -0
- package/dist/cjs/interfaces/errors.interface.js +77 -0
- package/dist/cjs/interfaces/errors.interface.js.map +1 -0
- package/dist/cjs/interfaces/index.js +25 -0
- package/dist/cjs/interfaces/index.js.map +1 -0
- package/dist/cjs/interfaces/module-options.interface.js +3 -0
- package/dist/cjs/interfaces/module-options.interface.js.map +1 -0
- package/dist/cjs/loaders/environment.loader.js +59 -0
- package/dist/cjs/loaders/environment.loader.js.map +1 -0
- package/dist/cjs/loaders/secrets-manager.loader.js +122 -0
- package/dist/cjs/loaders/secrets-manager.loader.js.map +1 -0
- package/dist/cjs/loaders/ssm-parameter-store.loader.js +146 -0
- package/dist/cjs/loaders/ssm-parameter-store.loader.js.map +1 -0
- package/dist/cjs/services/config.service.js +297 -0
- package/dist/cjs/services/config.service.js.map +1 -0
- package/dist/cjs/utils/validation.util.js +114 -0
- package/dist/cjs/utils/validation.util.js.map +1 -0
- package/dist/esm/config.module.js +175 -0
- package/dist/esm/config.module.js.map +1 -0
- package/dist/esm/index.js +18 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/integration/index.js +7 -0
- package/dist/esm/integration/index.js.map +1 -0
- package/dist/esm/integration/interfaces/configuration-factory.interface.js +2 -0
- package/dist/esm/integration/interfaces/configuration-factory.interface.js.map +1 -0
- package/dist/esm/integration/interfaces/configuration-source.interface.js +2 -0
- package/dist/esm/integration/interfaces/configuration-source.interface.js.map +1 -0
- package/dist/esm/integration/interfaces/index.js +10 -0
- package/dist/esm/integration/interfaces/index.js.map +1 -0
- package/dist/esm/integration/interfaces/integration-options.interface.js +2 -0
- package/dist/esm/integration/interfaces/integration-options.interface.js.map +1 -0
- package/dist/esm/integration/interfaces/integration-state.interface.js +2 -0
- package/dist/esm/integration/interfaces/integration-state.interface.js.map +1 -0
- package/dist/esm/integration/interfaces/nestjs-config-compatibility.interface.js +64 -0
- package/dist/esm/integration/interfaces/nestjs-config-compatibility.interface.js.map +1 -0
- package/dist/esm/integration/interfaces/nestjs-config-integration.interface.js +2 -0
- package/dist/esm/integration/interfaces/nestjs-config-integration.interface.js.map +1 -0
- package/dist/esm/integration/interfaces/typed-configuration.interface.js +3 -0
- package/dist/esm/integration/interfaces/typed-configuration.interface.js.map +1 -0
- package/dist/esm/integration/interfaces/utility-types.interface.js +44 -0
- package/dist/esm/integration/interfaces/utility-types.interface.js.map +1 -0
- package/dist/esm/integration/nestjs-config-integration.module.js +121 -0
- package/dist/esm/integration/nestjs-config-integration.module.js.map +1 -0
- package/dist/esm/integration/providers/aws-configuration-loader.service.js +588 -0
- package/dist/esm/integration/providers/aws-configuration-loader.service.js.map +1 -0
- package/dist/esm/integration/providers/configuration-factory.provider.js +380 -0
- package/dist/esm/integration/providers/configuration-factory.provider.js.map +1 -0
- package/dist/esm/integration/providers/index.js +4 -0
- package/dist/esm/integration/providers/index.js.map +1 -0
- package/dist/esm/integration/services/async-config-helper.service.js +353 -0
- package/dist/esm/integration/services/async-config-helper.service.js.map +1 -0
- package/dist/esm/integration/services/error-handler.service.js +262 -0
- package/dist/esm/integration/services/error-handler.service.js.map +1 -0
- package/dist/esm/integration/services/factory-registration.service.js +509 -0
- package/dist/esm/integration/services/factory-registration.service.js.map +1 -0
- package/dist/esm/integration/services/index.js +10 -0
- package/dist/esm/integration/services/index.js.map +1 -0
- package/dist/esm/integration/services/integration-state.service.js +80 -0
- package/dist/esm/integration/services/integration-state.service.js.map +1 -0
- package/dist/esm/integration/services/namespace-handler.service.js +464 -0
- package/dist/esm/integration/services/namespace-handler.service.js.map +1 -0
- package/dist/esm/integration/services/nestjs-config-integration.service.js +313 -0
- package/dist/esm/integration/services/nestjs-config-integration.service.js.map +1 -0
- package/dist/esm/integration/services/precedence-handler.service.js +291 -0
- package/dist/esm/integration/services/precedence-handler.service.js.map +1 -0
- package/dist/esm/integration/services/validation-integration.service.js +585 -0
- package/dist/esm/integration/services/validation-integration.service.js.map +1 -0
- package/dist/esm/integration/utils/config-integration.util.js +240 -0
- package/dist/esm/integration/utils/config-integration.util.js.map +1 -0
- package/dist/esm/integration/utils/index.js +3 -0
- package/dist/esm/integration/utils/index.js.map +1 -0
- package/dist/esm/interfaces/config-loader.interface.js +2 -0
- package/dist/esm/interfaces/config-loader.interface.js.map +1 -0
- package/dist/esm/interfaces/config-service.interface.js +7 -0
- package/dist/esm/interfaces/config-service.interface.js.map +1 -0
- package/dist/esm/interfaces/default-schema.interface.js +59 -0
- package/dist/esm/interfaces/default-schema.interface.js.map +1 -0
- package/dist/esm/interfaces/errors.interface.js +69 -0
- package/dist/esm/interfaces/errors.interface.js.map +1 -0
- package/dist/esm/interfaces/index.js +9 -0
- package/dist/esm/interfaces/index.js.map +1 -0
- package/dist/esm/interfaces/module-options.interface.js +2 -0
- package/dist/esm/interfaces/module-options.interface.js.map +1 -0
- package/dist/esm/loaders/environment.loader.js +55 -0
- package/dist/esm/loaders/environment.loader.js.map +1 -0
- package/dist/esm/loaders/secrets-manager.loader.js +118 -0
- package/dist/esm/loaders/secrets-manager.loader.js.map +1 -0
- package/dist/esm/loaders/ssm-parameter-store.loader.js +142 -0
- package/dist/esm/loaders/ssm-parameter-store.loader.js.map +1 -0
- package/dist/esm/services/config.service.js +261 -0
- package/dist/esm/services/config.service.js.map +1 -0
- package/dist/esm/utils/validation.util.js +110 -0
- package/dist/esm/utils/validation.util.js.map +1 -0
- package/dist/types/config.module.d.ts +46 -0
- package/dist/types/config.module.d.ts.map +1 -0
- package/dist/types/index.d.ts +13 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/integration/index.d.ts +6 -0
- package/dist/types/integration/index.d.ts.map +1 -0
- package/dist/types/integration/interfaces/configuration-factory.interface.d.ts +71 -0
- package/dist/types/integration/interfaces/configuration-factory.interface.d.ts.map +1 -0
- package/dist/types/integration/interfaces/configuration-source.interface.d.ts +24 -0
- package/dist/types/integration/interfaces/configuration-source.interface.d.ts.map +1 -0
- package/dist/types/integration/interfaces/index.d.ts +9 -0
- package/dist/types/integration/interfaces/index.d.ts.map +1 -0
- package/dist/types/integration/interfaces/integration-options.interface.d.ts +66 -0
- package/dist/types/integration/interfaces/integration-options.interface.d.ts.map +1 -0
- package/dist/types/integration/interfaces/integration-state.interface.d.ts +17 -0
- package/dist/types/integration/interfaces/integration-state.interface.d.ts.map +1 -0
- package/dist/types/integration/interfaces/nestjs-config-compatibility.interface.d.ts +332 -0
- package/dist/types/integration/interfaces/nestjs-config-compatibility.interface.d.ts.map +1 -0
- package/dist/types/integration/interfaces/nestjs-config-integration.interface.d.ts +259 -0
- package/dist/types/integration/interfaces/nestjs-config-integration.interface.d.ts.map +1 -0
- package/dist/types/integration/interfaces/typed-configuration.interface.d.ts +209 -0
- package/dist/types/integration/interfaces/typed-configuration.interface.d.ts.map +1 -0
- package/dist/types/integration/interfaces/utility-types.interface.d.ts +249 -0
- package/dist/types/integration/interfaces/utility-types.interface.d.ts.map +1 -0
- package/dist/types/integration/nestjs-config-integration.module.d.ts +36 -0
- package/dist/types/integration/nestjs-config-integration.module.d.ts.map +1 -0
- package/dist/types/integration/providers/aws-configuration-loader.service.d.ts +134 -0
- package/dist/types/integration/providers/aws-configuration-loader.service.d.ts.map +1 -0
- package/dist/types/integration/providers/configuration-factory.provider.d.ts +119 -0
- package/dist/types/integration/providers/configuration-factory.provider.d.ts.map +1 -0
- package/dist/types/integration/providers/index.d.ts +3 -0
- package/dist/types/integration/providers/index.d.ts.map +1 -0
- package/dist/types/integration/services/async-config-helper.service.d.ts +84 -0
- package/dist/types/integration/services/async-config-helper.service.d.ts.map +1 -0
- package/dist/types/integration/services/error-handler.service.d.ts +84 -0
- package/dist/types/integration/services/error-handler.service.d.ts.map +1 -0
- package/dist/types/integration/services/factory-registration.service.d.ts +158 -0
- package/dist/types/integration/services/factory-registration.service.d.ts.map +1 -0
- package/dist/types/integration/services/index.d.ts +9 -0
- package/dist/types/integration/services/index.d.ts.map +1 -0
- package/dist/types/integration/services/integration-state.service.d.ts +41 -0
- package/dist/types/integration/services/integration-state.service.d.ts.map +1 -0
- package/dist/types/integration/services/namespace-handler.service.d.ts +192 -0
- package/dist/types/integration/services/namespace-handler.service.d.ts.map +1 -0
- package/dist/types/integration/services/nestjs-config-integration.service.d.ts +87 -0
- package/dist/types/integration/services/nestjs-config-integration.service.d.ts.map +1 -0
- package/dist/types/integration/services/precedence-handler.service.d.ts +103 -0
- package/dist/types/integration/services/precedence-handler.service.d.ts.map +1 -0
- package/dist/types/integration/services/validation-integration.service.d.ts +222 -0
- package/dist/types/integration/services/validation-integration.service.d.ts.map +1 -0
- package/dist/types/integration/utils/config-integration.util.d.ts +81 -0
- package/dist/types/integration/utils/config-integration.util.d.ts.map +1 -0
- package/dist/types/integration/utils/index.d.ts +2 -0
- package/dist/types/integration/utils/index.d.ts.map +1 -0
- package/dist/types/interfaces/config-loader.interface.d.ts +22 -0
- package/dist/types/interfaces/config-loader.interface.d.ts.map +1 -0
- package/dist/types/interfaces/config-service.interface.d.ts +23 -0
- package/dist/types/interfaces/config-service.interface.d.ts.map +1 -0
- package/dist/types/interfaces/default-schema.interface.d.ts +195 -0
- package/dist/types/interfaces/default-schema.interface.d.ts.map +1 -0
- package/dist/types/interfaces/errors.interface.d.ts +38 -0
- package/dist/types/interfaces/errors.interface.d.ts.map +1 -0
- package/dist/types/interfaces/index.d.ts +6 -0
- package/dist/types/interfaces/index.d.ts.map +1 -0
- package/dist/types/interfaces/module-options.interface.d.ts +64 -0
- package/dist/types/interfaces/module-options.interface.d.ts.map +1 -0
- package/dist/types/loaders/environment.loader.d.ts +26 -0
- package/dist/types/loaders/environment.loader.d.ts.map +1 -0
- package/dist/types/loaders/secrets-manager.loader.d.ts +52 -0
- package/dist/types/loaders/secrets-manager.loader.d.ts.map +1 -0
- package/dist/types/loaders/ssm-parameter-store.loader.d.ts +68 -0
- package/dist/types/loaders/ssm-parameter-store.loader.d.ts.map +1 -0
- package/dist/types/services/config.service.d.ts +94 -0
- package/dist/types/services/config.service.d.ts.map +1 -0
- package/dist/types/utils/validation.util.d.ts +53 -0
- package/dist/types/utils/validation.util.d.ts.map +1 -0
- package/package.json +102 -0
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { GetParametersByPathCommand, SSMClient } from '@aws-sdk/client-ssm';
|
|
2
|
+
import { fromNodeProviderChain } from '@aws-sdk/credential-providers';
|
|
3
|
+
import { ConfigurationError } from '../interfaces/errors.interface';
|
|
4
|
+
/**
|
|
5
|
+
* Configuration loader that loads values from AWS Systems Manager Parameter Store.
|
|
6
|
+
* Supports environment-aware parameter path construction, recursive parameter fetching with pagination,
|
|
7
|
+
* and parameter name transformation (remove prefix, convert to uppercase).
|
|
8
|
+
*/
|
|
9
|
+
export class SSMParameterStoreLoader {
|
|
10
|
+
constructor(config = {}) {
|
|
11
|
+
this.appEnv = process.env['APP_ENV'] || process.env['NODE_ENV'] || 'local';
|
|
12
|
+
// Set default configuration
|
|
13
|
+
this.config = {
|
|
14
|
+
parameterPath: config.parameterPath || '/nestjs-config-aws',
|
|
15
|
+
region: config.region || process.env['AWS_REGION'] || 'us-east-1',
|
|
16
|
+
environmentMapping: config.environmentMapping || {
|
|
17
|
+
development: 'dev',
|
|
18
|
+
test: 'test',
|
|
19
|
+
production: 'production'
|
|
20
|
+
},
|
|
21
|
+
withDecryption: config.withDecryption ?? true
|
|
22
|
+
};
|
|
23
|
+
// Initialize AWS SSM client
|
|
24
|
+
this.client = new SSMClient({
|
|
25
|
+
credentials: fromNodeProviderChain(),
|
|
26
|
+
region: this.config.region,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Load configuration from AWS Systems Manager Parameter Store.
|
|
31
|
+
* Implements recursive parameter fetching with NextToken handling for pagination.
|
|
32
|
+
* @returns Promise resolving to configuration key-value pairs from parameters
|
|
33
|
+
*/
|
|
34
|
+
async load() {
|
|
35
|
+
// Skip loading in local environment or if AWS_REGION is not available
|
|
36
|
+
if (this.appEnv === 'local' || !process.env['AWS_REGION']) {
|
|
37
|
+
return {};
|
|
38
|
+
}
|
|
39
|
+
const parameterPath = this.buildParameterPath();
|
|
40
|
+
const result = {};
|
|
41
|
+
let nextToken;
|
|
42
|
+
try {
|
|
43
|
+
do {
|
|
44
|
+
const command = new GetParametersByPathCommand({
|
|
45
|
+
Path: parameterPath,
|
|
46
|
+
Recursive: true,
|
|
47
|
+
WithDecryption: this.config.withDecryption,
|
|
48
|
+
NextToken: nextToken,
|
|
49
|
+
});
|
|
50
|
+
const response = await this.client.send(command);
|
|
51
|
+
if (!response.Parameters) {
|
|
52
|
+
// No parameters found - this is not necessarily an error
|
|
53
|
+
break;
|
|
54
|
+
}
|
|
55
|
+
// Process each parameter
|
|
56
|
+
for (const param of response.Parameters) {
|
|
57
|
+
const key = this.transformParameterName(param.Name, parameterPath);
|
|
58
|
+
if (key && param.Value !== undefined) {
|
|
59
|
+
result[key] = param.Value;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
nextToken = response.NextToken;
|
|
63
|
+
} while (nextToken);
|
|
64
|
+
return result;
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
// Handle specific AWS errors
|
|
68
|
+
if (error instanceof Error) {
|
|
69
|
+
if (error.name === 'AccessDeniedException') {
|
|
70
|
+
throw new ConfigurationError(`Access denied when retrieving parameters from path '${parameterPath}'. Check AWS credentials and permissions.`, error);
|
|
71
|
+
}
|
|
72
|
+
if (error.name === 'InvalidFilterKey' || error.name === 'InvalidFilterValue') {
|
|
73
|
+
throw new ConfigurationError(`Invalid parameter path '${parameterPath}'. Check path format.`, error);
|
|
74
|
+
}
|
|
75
|
+
if (error.name === 'ParameterNotFound') {
|
|
76
|
+
// No parameters found at path - this is not necessarily an error
|
|
77
|
+
return {};
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
// For other errors, wrap in ConfigurationError
|
|
81
|
+
throw new ConfigurationError(`Failed to retrieve parameters from path '${parameterPath}' in AWS SSM Parameter Store: ${error instanceof Error ? error.message : String(error)}`, error instanceof Error ? error : undefined);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Get the name of this loader for logging and debugging.
|
|
86
|
+
* @returns The loader name with parameter path
|
|
87
|
+
*/
|
|
88
|
+
getName() {
|
|
89
|
+
const parameterPath = this.buildParameterPath();
|
|
90
|
+
return `SSMParameterStoreLoader(${parameterPath})`;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Check if this loader is available in the current environment.
|
|
94
|
+
* @returns Promise resolving to true if not in local environment, AWS_REGION is set, and AWS credentials are available
|
|
95
|
+
*/
|
|
96
|
+
async isAvailable() {
|
|
97
|
+
// Skip in local environment or if AWS_REGION is not available
|
|
98
|
+
if (this.appEnv === 'local' || !process.env['AWS_REGION']) {
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
try {
|
|
102
|
+
// Test AWS credentials by attempting to get caller identity
|
|
103
|
+
// This is a lightweight way to verify AWS access without making actual SSM calls
|
|
104
|
+
await this.client.config.credentials();
|
|
105
|
+
return true;
|
|
106
|
+
}
|
|
107
|
+
catch {
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Build the environment-aware parameter path.
|
|
113
|
+
* @returns The full parameter path with environment prefix
|
|
114
|
+
*/
|
|
115
|
+
buildParameterPath() {
|
|
116
|
+
const envPrefix = this.config.environmentMapping[this.appEnv];
|
|
117
|
+
if (!envPrefix) {
|
|
118
|
+
throw new ConfigurationError(`No environment mapping found for APP_ENV '${this.appEnv}'. ` +
|
|
119
|
+
`Available environments: ${Object.keys(this.config.environmentMapping).join(', ')}`);
|
|
120
|
+
}
|
|
121
|
+
return `/${envPrefix}${this.config.parameterPath}`;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Transform parameter name by removing the prefix and converting to uppercase.
|
|
125
|
+
* Example: '/dev/nestjs-config-aws/database/host' -> 'DATABASEHOST'
|
|
126
|
+
* This matches the original prospectory-backend implementation
|
|
127
|
+
* @param parameterName The full parameter name from AWS
|
|
128
|
+
* @param pathPrefix The path prefix to remove
|
|
129
|
+
* @returns The transformed parameter name or null if invalid
|
|
130
|
+
*/
|
|
131
|
+
transformParameterName(parameterName, pathPrefix) {
|
|
132
|
+
if (!parameterName) {
|
|
133
|
+
return null;
|
|
134
|
+
}
|
|
135
|
+
// Remove the path prefix and all slashes, then convert to uppercase
|
|
136
|
+
// This matches the original implementation: .replace(envPrefix, '').replace(/\//g, '').toUpperCase()
|
|
137
|
+
const key = parameterName.replace(pathPrefix, '').replace(/\//g, '').toUpperCase();
|
|
138
|
+
// Return null for empty keys
|
|
139
|
+
return key || null;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
//# sourceMappingURL=ssm-parameter-store.loader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ssm-parameter-store.loader.js","sourceRoot":"","sources":["../../../src/loaders/ssm-parameter-store.loader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,0BAA0B,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAC5E,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AAGtE,OAAO,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AA+BpE;;;;GAIG;AACH,MAAM,OAAO,uBAAuB;IAKlC,YAAY,SAAwC,EAAE;QACpD,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,IAAI,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,OAAO,CAAC;QAE3E,4BAA4B;QAC5B,IAAI,CAAC,MAAM,GAAG;YACZ,aAAa,EAAE,MAAM,CAAC,aAAa,IAAI,oBAAoB;YAC3D,MAAM,EAAE,MAAM,CAAC,MAAM,IAAI,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC,IAAI,WAAW;YACjE,kBAAkB,EAAE,MAAM,CAAC,kBAAkB,IAAI;gBAC/C,WAAW,EAAE,KAAK;gBAClB,IAAI,EAAE,MAAM;gBACZ,UAAU,EAAE,YAAY;aACzB;YACD,cAAc,EAAE,MAAM,CAAC,cAAc,IA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,CAAC;YAC1D,OAAO,KAAK,CAAC;QACf,CAAC;QAED,IAAI,CAAC;YACH,4DAA4D;YAC5D,iFAAiF;YACjF,MAAM,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC;YACvC,OAAO,IAAI,CAAC;QACd,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;IAED;;;OAGG;IACK,kBAAkB;QACxB,MAAM,SAAS,GAAG,IAAI,CAAC,MAAM,CAAC,kBAAkB,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAE9D,IAAI,CAAC,SAAS,EAAE,CAAC;YACf,MAAM,IAAI,kBAAkB,CAC1B,6CAA6C,IAAI,CAAC,MAAM,KAAK;gBAC7D,2BAA2B,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,kBAAkB,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CACpF,CAAC;QACJ,CAAC;QAED,OAAO,IAAI,SAAS,GAAG,IAAI,CAAC,MAAM,CAAC,aAAa,EAAE,CAAC;IACrD,CAAC;IAED;;;;;;;OAOG;IACK,sBAAsB,CAAC,aAAiC,EAAE,UAAkB;QAClF,IAAI,CAAC,aAAa,EAAE,CAAC;YACnB,OAAO,IAAI,CAAC;QACd,CAAC;QAED,oEAAoE;QACpE,qGAAqG;QACrG,MAAM,GAAG,GAAG,aAAa,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC;QAEnF,6BAA6B;QAC7B,OAAO,GAAG,IAAI,IAAI,CAAC;IACrB,CAAC;CACF"}
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
var ConfigServiceImpl_1;
|
|
11
|
+
import { Injectable, Logger } from '@nestjs/common';
|
|
12
|
+
import { ConfigService } from '../interfaces/config-service.interface';
|
|
13
|
+
import { getSchemaForEnvironment, appEnvSchema } from '../interfaces/default-schema.interface';
|
|
14
|
+
import { ConfigurationError, ConfigurationLoadError } from '../interfaces/errors.interface';
|
|
15
|
+
import { ConfigValidationUtil } from '../utils/validation.util';
|
|
16
|
+
import { EnvironmentLoader } from '../loaders/environment.loader';
|
|
17
|
+
import { SecretsManagerLoader } from '../loaders/secrets-manager.loader';
|
|
18
|
+
import { SSMParameterStoreLoader } from '../loaders/ssm-parameter-store.loader';
|
|
19
|
+
/**
|
|
20
|
+
* Implementation of ConfigService with AWS integration and APP_ENV logic.
|
|
21
|
+
* Provides type-safe configuration access with orchestrated loading from multiple sources.
|
|
22
|
+
*/
|
|
23
|
+
let ConfigServiceImpl = ConfigServiceImpl_1 = class ConfigServiceImpl extends ConfigService {
|
|
24
|
+
constructor(options = {}) {
|
|
25
|
+
super();
|
|
26
|
+
this.logger = new Logger(ConfigServiceImpl_1.name);
|
|
27
|
+
this.config = null;
|
|
28
|
+
this.initialized = false;
|
|
29
|
+
// Set default options
|
|
30
|
+
this.options = {
|
|
31
|
+
envPrefix: options.envPrefix,
|
|
32
|
+
validateOnLoad: options.validateOnLoad ?? true,
|
|
33
|
+
enableLogging: options.enableLogging ?? true,
|
|
34
|
+
};
|
|
35
|
+
// Initialize APP_ENV logic
|
|
36
|
+
this.appEnv = this.initializeAppEnv();
|
|
37
|
+
// Set schema - use environment-specific schema if no custom schema provided
|
|
38
|
+
this.schema = options.schema || getSchemaForEnvironment(this.appEnv);
|
|
39
|
+
// Initialize loaders
|
|
40
|
+
this.loaders = options.loaders || this.createDefaultLoaders();
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Initialize the configuration service by loading and validating configuration.
|
|
44
|
+
* This method should be called during application startup.
|
|
45
|
+
*/
|
|
46
|
+
async initialize() {
|
|
47
|
+
if (this.initialized) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
try {
|
|
51
|
+
if (this.options.enableLogging) {
|
|
52
|
+
this.logger.log(`Initializing configuration service with APP_ENV: ${this.appEnv}`);
|
|
53
|
+
}
|
|
54
|
+
// Load configuration from all sources
|
|
55
|
+
const rawConfig = await this.loadConfiguration();
|
|
56
|
+
// Validate configuration if enabled
|
|
57
|
+
if (this.options.validateOnLoad) {
|
|
58
|
+
this.config = ConfigValidationUtil.validateConfiguration(this.schema, rawConfig, 'merged configuration');
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
this.config = rawConfig;
|
|
62
|
+
}
|
|
63
|
+
this.initialized = true;
|
|
64
|
+
if (this.options.enableLogging) {
|
|
65
|
+
this.logger.log('Configuration service initialized successfully');
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
catch (error) {
|
|
69
|
+
const errorMessage = `Failed to initialize configuration service: ${error instanceof Error ? error.message : String(error)}`;
|
|
70
|
+
this.logger.error(errorMessage);
|
|
71
|
+
throw new ConfigurationError(errorMessage, error instanceof Error ? error : undefined);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Get a configuration value by key with type safety.
|
|
76
|
+
* @param key - The configuration key to retrieve
|
|
77
|
+
* @returns The configuration value with proper typing
|
|
78
|
+
*/
|
|
79
|
+
get(key) {
|
|
80
|
+
if (!this.initialized || !this.config) {
|
|
81
|
+
throw new ConfigurationError('Configuration service not initialized. Call initialize() first.');
|
|
82
|
+
}
|
|
83
|
+
return this.config[key];
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Check if the configuration service has been initialized.
|
|
87
|
+
* @returns True if the service is ready to serve configuration values
|
|
88
|
+
*/
|
|
89
|
+
isInitialized() {
|
|
90
|
+
return this.initialized;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Get all configuration values.
|
|
94
|
+
* @returns The complete configuration object
|
|
95
|
+
*/
|
|
96
|
+
getAll() {
|
|
97
|
+
if (!this.initialized || !this.config) {
|
|
98
|
+
throw new ConfigurationError('Configuration service not initialized. Call initialize() first.');
|
|
99
|
+
}
|
|
100
|
+
return this.config;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Get the current APP_ENV value.
|
|
104
|
+
* @returns The current application environment
|
|
105
|
+
*/
|
|
106
|
+
getAppEnv() {
|
|
107
|
+
return this.appEnv;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Initialize APP_ENV with NODE_ENV mirroring and warning logic.
|
|
111
|
+
* Implements requirement 2.0: APP_ENV mirroring NODE_ENV with "local" default and warning logic.
|
|
112
|
+
*/
|
|
113
|
+
initializeAppEnv() {
|
|
114
|
+
const nodeEnv = process.env['NODE_ENV'];
|
|
115
|
+
const appEnv = process.env['APP_ENV'];
|
|
116
|
+
// If APP_ENV is explicitly set
|
|
117
|
+
if (appEnv) {
|
|
118
|
+
// Validate APP_ENV value
|
|
119
|
+
const validation = ConfigValidationUtil.safeValidate(appEnvSchema, appEnv);
|
|
120
|
+
if (!validation.success) {
|
|
121
|
+
// If APP_ENV is invalid, try to use NODE_ENV as fallback
|
|
122
|
+
if (nodeEnv) {
|
|
123
|
+
const nodeEnvValidation = ConfigValidationUtil.safeValidate(appEnvSchema, nodeEnv);
|
|
124
|
+
if (nodeEnvValidation.success) {
|
|
125
|
+
if (this.options.enableLogging) {
|
|
126
|
+
this.logger.warn(`Invalid APP_ENV value '${appEnv}'. Using NODE_ENV '${nodeEnv}' as fallback.`);
|
|
127
|
+
}
|
|
128
|
+
return nodeEnv;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
// Both APP_ENV and NODE_ENV are invalid, default to 'local'
|
|
132
|
+
if (this.options.enableLogging) {
|
|
133
|
+
this.logger.warn(`Invalid APP_ENV value '${appEnv}' and no valid NODE_ENV fallback. Defaulting to 'local'.`);
|
|
134
|
+
}
|
|
135
|
+
return 'local';
|
|
136
|
+
}
|
|
137
|
+
// APP_ENV is valid, check if it differs from NODE_ENV
|
|
138
|
+
if (nodeEnv && nodeEnv !== appEnv) {
|
|
139
|
+
if (this.options.enableLogging) {
|
|
140
|
+
this.logger.warn(`APP_ENV '${appEnv}' differs from NODE_ENV '${nodeEnv}'. Using APP_ENV value.`);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
return appEnv;
|
|
144
|
+
}
|
|
145
|
+
// APP_ENV not set, try to use NODE_ENV
|
|
146
|
+
if (nodeEnv) {
|
|
147
|
+
const validation = ConfigValidationUtil.safeValidate(appEnvSchema, nodeEnv);
|
|
148
|
+
if (validation.success) {
|
|
149
|
+
return nodeEnv;
|
|
150
|
+
}
|
|
151
|
+
// NODE_ENV is invalid, log warning and default to 'local'
|
|
152
|
+
if (this.options.enableLogging) {
|
|
153
|
+
this.logger.warn(`Invalid NODE_ENV value '${nodeEnv}'. Defaulting to 'local'.`);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
// Neither APP_ENV nor NODE_ENV set, default to 'local'
|
|
157
|
+
return 'local';
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Create default configuration loaders.
|
|
161
|
+
* @returns Array of default loaders in precedence order
|
|
162
|
+
*/
|
|
163
|
+
createDefaultLoaders() {
|
|
164
|
+
return [
|
|
165
|
+
new EnvironmentLoader(this.options.envPrefix),
|
|
166
|
+
new SecretsManagerLoader(),
|
|
167
|
+
new SSMParameterStoreLoader(),
|
|
168
|
+
];
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Load configuration from all sources with proper precedence order.
|
|
172
|
+
* Implements orchestration: env -> secrets -> ssm with proper merging.
|
|
173
|
+
*/
|
|
174
|
+
async loadConfiguration() {
|
|
175
|
+
const mergedConfig = {};
|
|
176
|
+
for (const loader of this.loaders) {
|
|
177
|
+
try {
|
|
178
|
+
// Check if loader is available in current environment
|
|
179
|
+
const isAvailable = await loader.isAvailable();
|
|
180
|
+
if (!isAvailable) {
|
|
181
|
+
if (this.options.enableLogging) {
|
|
182
|
+
this.logger.debug(`Skipping ${loader.getName()} - not available in current environment`);
|
|
183
|
+
}
|
|
184
|
+
continue;
|
|
185
|
+
}
|
|
186
|
+
if (this.options.enableLogging) {
|
|
187
|
+
this.logger.debug(`Loading configuration from ${loader.getName()}`);
|
|
188
|
+
}
|
|
189
|
+
// Load configuration from this source
|
|
190
|
+
const loaderConfig = await loader.load();
|
|
191
|
+
// Merge with existing configuration
|
|
192
|
+
// Later loaders override earlier ones (environment variables have lowest precedence)
|
|
193
|
+
Object.assign(mergedConfig, loaderConfig);
|
|
194
|
+
if (this.options.enableLogging) {
|
|
195
|
+
const keyCount = Object.keys(loaderConfig).length;
|
|
196
|
+
this.logger.debug(`Loaded ${keyCount} configuration values from ${loader.getName()}`);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
catch (error) {
|
|
200
|
+
const errorMessage = `Failed to load configuration from ${loader.getName()}: ${error instanceof Error ? error.message : String(error)}`;
|
|
201
|
+
if (this.options.enableLogging) {
|
|
202
|
+
this.logger.error(errorMessage);
|
|
203
|
+
}
|
|
204
|
+
throw new ConfigurationLoadError(errorMessage, loader.getName(), error instanceof Error ? error : undefined);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
// Handle special case for local environment with .env file override
|
|
208
|
+
if (this.appEnv === 'local') {
|
|
209
|
+
await this.handleLocalEnvironmentOverrides(mergedConfig);
|
|
210
|
+
}
|
|
211
|
+
return mergedConfig;
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Handle local environment overrides according to requirement 2.4.
|
|
215
|
+
* In local mode with valid AWS profile and .env file, .env values override AWS values.
|
|
216
|
+
*/
|
|
217
|
+
async handleLocalEnvironmentOverrides(config) {
|
|
218
|
+
// Check if we have a valid AWS profile in the credential chain
|
|
219
|
+
const awsProfile = process.env['AWS_PROFILE'];
|
|
220
|
+
if (!awsProfile) {
|
|
221
|
+
return; // No AWS profile, no special handling needed
|
|
222
|
+
}
|
|
223
|
+
// Check if .env file exists (this is a simplified check - in real implementation
|
|
224
|
+
// you might want to use a library like dotenv to properly detect .env files)
|
|
225
|
+
try {
|
|
226
|
+
const fs = await import('fs');
|
|
227
|
+
const path = await import('path');
|
|
228
|
+
const envFilePath = path.resolve(process.cwd(), '.env');
|
|
229
|
+
const envFileExists = fs.existsSync(envFilePath);
|
|
230
|
+
if (envFileExists) {
|
|
231
|
+
if (this.options.enableLogging) {
|
|
232
|
+
this.logger.debug('Local environment detected with AWS profile and .env file. ' +
|
|
233
|
+
'Environment variables from .env will override AWS values.');
|
|
234
|
+
}
|
|
235
|
+
// Load .env file and override AWS values
|
|
236
|
+
const dotenv = await import('dotenv');
|
|
237
|
+
const envConfig = dotenv.config({ path: envFilePath });
|
|
238
|
+
if (envConfig.parsed) {
|
|
239
|
+
// Override AWS values with .env values
|
|
240
|
+
Object.assign(config, envConfig.parsed);
|
|
241
|
+
if (this.options.enableLogging) {
|
|
242
|
+
const overrideCount = Object.keys(envConfig.parsed).length;
|
|
243
|
+
this.logger.debug(`Applied ${overrideCount} overrides from .env file`);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
catch (error) {
|
|
249
|
+
// If we can't load .env file, just log a warning and continue
|
|
250
|
+
if (this.options.enableLogging) {
|
|
251
|
+
this.logger.warn(`Failed to load .env file for local overrides: ${error instanceof Error ? error.message : String(error)}`);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
};
|
|
256
|
+
ConfigServiceImpl = ConfigServiceImpl_1 = __decorate([
|
|
257
|
+
Injectable(),
|
|
258
|
+
__metadata("design:paramtypes", [Object])
|
|
259
|
+
], ConfigServiceImpl);
|
|
260
|
+
export { ConfigServiceImpl };
|
|
261
|
+
//# sourceMappingURL=config.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.service.js","sourceRoot":"","sources":["../../../src/services/config.service.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAGpD,OAAO,EAAE,aAAa,EAAE,MAAM,wCAAwC,CAAC;AAEvE,OAAO,EAAuB,uBAAuB,EAAE,YAAY,EAAE,MAAM,wCAAwC,CAAC;AACpH,OAAO,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAC;AAC5F,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAChE,OAAO,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAClE,OAAO,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAC;AACzE,OAAO,EAAE,uBAAuB,EAAE,MAAM,uCAAuC,CAAC;AAoChF;;;GAGG;AAEI,IAAM,iBAAiB,yBAAvB,MAAM,iBAA2C,SAAQ,aAAgB;IAc9E,YAAY,UAAmC,EAAE;QAC/C,KAAK,EAAE,CAAC;QAdO,WAAM,GAAG,IAAI,MAAM,CAAC,mBAAiB,CAAC,IAAI,CAAC,CAAC;QASrD,WAAM,GAAa,IAAI,CAAC;QACxB,gBAAW,GAAG,KAAK,CAAC;QAM1B,sBAAsB;QACtB,IAAI,CAAC,OAAO,GAAG;YACb,SAAS,EAAE,OAAO,CAAC,SAAS;YAC5B,cAAc,EAAE,OAAO,CAAC,cAAc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|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { ValidationError } from '../interfaces/errors.interface';
|
|
2
|
+
/**
|
|
3
|
+
* Framework-agnostic validation utility for configuration values
|
|
4
|
+
* Adapted from ZodValidationPipe for standalone use
|
|
5
|
+
*/
|
|
6
|
+
export class ConfigValidationUtil {
|
|
7
|
+
/**
|
|
8
|
+
* Validates a value against a Zod schema
|
|
9
|
+
* @param schema The Zod schema to validate against
|
|
10
|
+
* @param value The value to validate
|
|
11
|
+
* @param context Optional context for error messages
|
|
12
|
+
* @returns The validated and transformed value
|
|
13
|
+
* @throws ValidationError if validation fails
|
|
14
|
+
*/
|
|
15
|
+
static validate(schema, value, context) {
|
|
16
|
+
const result = schema.safeParse(value);
|
|
17
|
+
if (result.success) {
|
|
18
|
+
return result.data;
|
|
19
|
+
}
|
|
20
|
+
const errors = this.formatValidationErrors(result.error);
|
|
21
|
+
const contextMessage = context ? `Configuration validation failed for ${context}` : 'Configuration validation failed';
|
|
22
|
+
throw new ValidationError(contextMessage, errors);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Safely validates a value against a Zod schema without throwing
|
|
26
|
+
* @param schema The Zod schema to validate against
|
|
27
|
+
* @param value The value to validate
|
|
28
|
+
* @returns Object with success flag and either data or error
|
|
29
|
+
*/
|
|
30
|
+
static safeValidate(schema, value) {
|
|
31
|
+
const result = schema.safeParse(value);
|
|
32
|
+
if (result.success) {
|
|
33
|
+
return { success: true, data: result.data };
|
|
34
|
+
}
|
|
35
|
+
const errors = this.formatValidationErrors(result.error);
|
|
36
|
+
const validationError = new ValidationError('Configuration validation failed', errors);
|
|
37
|
+
return { success: false, error: validationError };
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Formats Zod validation errors into a structured format
|
|
41
|
+
* @param error The ZodError to format
|
|
42
|
+
* @returns Formatted error object or string
|
|
43
|
+
*/
|
|
44
|
+
static formatValidationErrors(error) {
|
|
45
|
+
// If there's only one error at the root level, return just the message
|
|
46
|
+
if (error.issues.length === 1) {
|
|
47
|
+
const issue = error.issues[0];
|
|
48
|
+
if (issue && Array.isArray(issue.path) && issue.path.length === 0) {
|
|
49
|
+
return issue.message;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
// For multiple errors or nested paths, create a structured object
|
|
53
|
+
return error.issues.reduce((errors, issue) => {
|
|
54
|
+
const path = issue.path.join('.');
|
|
55
|
+
const key = path || 'root';
|
|
56
|
+
if (!errors[key]) {
|
|
57
|
+
errors[key] = [];
|
|
58
|
+
}
|
|
59
|
+
errors[key].push({
|
|
60
|
+
message: issue.message,
|
|
61
|
+
code: issue.code,
|
|
62
|
+
path: issue.path,
|
|
63
|
+
});
|
|
64
|
+
return errors;
|
|
65
|
+
}, {});
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Creates a detailed error message for configuration validation failures
|
|
69
|
+
* @param error The ZodError to create a message for
|
|
70
|
+
* @param context Optional context for the error
|
|
71
|
+
* @returns Detailed error message string
|
|
72
|
+
*/
|
|
73
|
+
static createDetailedErrorMessage(error, context) {
|
|
74
|
+
const contextPrefix = context ? `${context}: ` : '';
|
|
75
|
+
if (error.issues.length === 1) {
|
|
76
|
+
const issue = error.issues[0];
|
|
77
|
+
if (issue) {
|
|
78
|
+
const pathStr = issue.path.length > 0 ? ` at '${issue.path.join('.')}'` : '';
|
|
79
|
+
return `${contextPrefix}${issue.message}${pathStr}`;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
const errorMessages = error.issues.map(issue => {
|
|
83
|
+
const pathStr = issue.path.length > 0 ? ` at '${issue.path.join('.')}'` : '';
|
|
84
|
+
return ` - ${issue.message}${pathStr}`;
|
|
85
|
+
});
|
|
86
|
+
return `${contextPrefix}Multiple validation errors:\n${errorMessages.join('\n')}`;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Validates configuration with enhanced error context
|
|
90
|
+
* @param schema The Zod schema to validate against
|
|
91
|
+
* @param value The configuration object to validate
|
|
92
|
+
* @param source The source of the configuration (e.g., 'environment', 'secrets-manager')
|
|
93
|
+
* @returns The validated configuration
|
|
94
|
+
* @throws ValidationError with enhanced context
|
|
95
|
+
*/
|
|
96
|
+
static validateConfiguration(schema, value, source) {
|
|
97
|
+
try {
|
|
98
|
+
return this.validate(schema, value, `${source} configuration`);
|
|
99
|
+
}
|
|
100
|
+
catch (error) {
|
|
101
|
+
if (error instanceof ValidationError) {
|
|
102
|
+
// Enhance the error with source information
|
|
103
|
+
const enhancedMessage = `Configuration validation failed for source '${source}': ${error.message}`;
|
|
104
|
+
throw new ValidationError(enhancedMessage, error.validationErrors);
|
|
105
|
+
}
|
|
106
|
+
throw error;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
//# sourceMappingURL=validation.util.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation.util.js","sourceRoot":"","sources":["../../../src/utils/validation.util.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AAEjE;;;GAGG;AACH,MAAM,OAAO,oBAAoB;IAC/B;;;;;;;OAOG;IACH,MAAM,CAAC,QAAQ,CACb,MAAS,EACT,KAAc,EACd,OAAgB;QAEhB,MAAM,MAAM,GAAG,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;QAEvC,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;YACnB,OAAO,MAAM,CAAC,IAAI,CAAC;QACrB,CAAC;QAED,MAAM,MAAM,GAAG,IAAI,CAAC,sBAAsB,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACzD,MAAM,cAAc,GAAG,OAAO,CAAC,CAAC,CAAC,uCAAuC,OAAO,EAAE,CAAC,CAAC,CAAC,iCAAiC,CAAC;QAEtH,MAAM,IAAI,eAAe,CAAC,cAAc,EAAE,MAAM,CAAC,CAAC;IACpD,CAAC;IAED;;;;;OAKG;IACH,MAAM,CAAC,YAA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AC,EAAE,CAAC;IACpF,CAAC;IAED;;;;;;;OAOG;IACH,MAAM,CAAC,qBAAqB,CAC1B,MAAS,EACT,KAAc,EACd,MAAc;QAEd,IAAI,CAAC;YACH,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,gBAAgB,CAAC,CAAC;QACjE,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,KAAK,YAAY,eAAe,EAAE,CAAC;gBACrC,4CAA4C;gBAC5C,MAAM,eAAe,GAAG,+CAA+C,MAAM,MAAM,KAAK,CAAC,OAAO,EAAE,CAAC;gBACnG,MAAM,IAAI,eAAe,CAAC,eAAe,EAAE,KAAK,CAAC,gBAAgB,CAAC,CAAC;YACrE,CAAC;YACD,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { DynamicModule } from '@nestjs/common';
|
|
2
|
+
import { NestConfigAwsModuleOptions, NestConfigAwsModuleAsyncOptions } from './interfaces/module-options.interface';
|
|
3
|
+
import { DefaultConfigSchema } from './interfaces/default-schema.interface';
|
|
4
|
+
/**
|
|
5
|
+
* Token for injecting module options
|
|
6
|
+
*/
|
|
7
|
+
export declare const NEST_CONFIG_AWS_OPTIONS = "NEST_CONFIG_AWS_OPTIONS";
|
|
8
|
+
/**
|
|
9
|
+
* NestJS module for AWS-integrated configuration management.
|
|
10
|
+
* Provides global configuration service with support for environment variables,
|
|
11
|
+
* AWS Secrets Manager, and AWS Systems Manager Parameter Store.
|
|
12
|
+
*/
|
|
13
|
+
export declare class ConfigModule {
|
|
14
|
+
/**
|
|
15
|
+
* Create a synchronous configuration module with provided options.
|
|
16
|
+
*
|
|
17
|
+
* @param options - Configuration options for the module
|
|
18
|
+
* @returns Dynamic module configuration
|
|
19
|
+
*/
|
|
20
|
+
static forRoot<T = DefaultConfigSchema>(options?: NestConfigAwsModuleOptions<T>): DynamicModule;
|
|
21
|
+
/**
|
|
22
|
+
* Create an asynchronous configuration module with factory-based options.
|
|
23
|
+
* Useful when configuration options depend on other services or async operations.
|
|
24
|
+
*
|
|
25
|
+
* @param options - Async configuration options with factory function
|
|
26
|
+
* @returns Dynamic module configuration
|
|
27
|
+
*/
|
|
28
|
+
static forRootAsync<T = DefaultConfigSchema>(options: NestConfigAwsModuleAsyncOptions<T>): DynamicModule;
|
|
29
|
+
/**
|
|
30
|
+
* Create the ConfigService provider for synchronous module registration.
|
|
31
|
+
*/
|
|
32
|
+
private static createConfigServiceProvider;
|
|
33
|
+
/**
|
|
34
|
+
* Create providers for asynchronous module registration.
|
|
35
|
+
*/
|
|
36
|
+
private static createAsyncProviders;
|
|
37
|
+
/**
|
|
38
|
+
* Create the ConfigService provider for asynchronous module registration.
|
|
39
|
+
*/
|
|
40
|
+
private static createAsyncConfigServiceProvider;
|
|
41
|
+
/**
|
|
42
|
+
* Create configuration loaders based on module options.
|
|
43
|
+
*/
|
|
44
|
+
private static createLoaders;
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=config.module.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.module.d.ts","sourceRoot":"","sources":["../../src/config.module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAA4B,MAAM,gBAAgB,CAAC;AAGzE,OAAO,EAAE,0BAA0B,EAAE,+BAA+B,EAAE,MAAM,uCAAuC,CAAC;AACpH,OAAO,EAAE,mBAAmB,EAAuB,MAAM,uCAAuC,CAAC;AAOjG;;GAEG;AACH,eAAO,MAAM,uBAAuB,4BAA4B,CAAC;AAEjE;;;;GAIG;AACH,qBAEa,YAAY;IACvB;;;;;OAKG;IACH,MAAM,CAAC,OAAO,CAAC,CAAC,GAAG,mBAAmB,EACpC,OAAO,GAAE,0BAA0B,CAAC,CAAC,CAAM,GAC1C,aAAa;IAiBhB;;;;;;OAMG;IACH,MAAM,CAAC,YAAY,CAAC,CAAC,GAAG,mBAAmB,EACzC,OAAO,EAAE,+BAA+B,CAAC,CAAC,CAAC,GAC1C,aAAa;IAehB;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,2BAA2B;IA+B1C;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,oBAAoB;IAYnC;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,gCAAgC;IA8B/C;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,aAAa;CAuC7B"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export * from './config.module';
|
|
2
|
+
export * from './interfaces';
|
|
3
|
+
export * from './loaders/environment.loader';
|
|
4
|
+
export * from './loaders/secrets-manager.loader';
|
|
5
|
+
export * from './loaders/ssm-parameter-store.loader';
|
|
6
|
+
export * from './services/config.service';
|
|
7
|
+
export * from './utils/validation.util';
|
|
8
|
+
export * from './integration';
|
|
9
|
+
export { isAwsSource, isLocalSource, hasMetadata, isValidationResult, isCacheEntry } from './integration/interfaces/utility-types.interface';
|
|
10
|
+
export { InjectEnhancedConfig, ConfigProperty, ConfigClass, ValidateConfig, TransformConfig, createTypeSafeConfigFactory } from './integration/interfaces/nestjs-config-compatibility.interface';
|
|
11
|
+
export { NestConfigAwsIntegrationModule } from './integration/nestjs-config-integration.module';
|
|
12
|
+
export type { IntegrationOptions, AsyncIntegrationOptions, PrecedenceRule, ErrorHandlingStrategy, FactoryOptions, AwsConfigurationFactory, ConfigurationFactoryProvider, ConfigurationSource, ConfigurationSourceType, IntegrationState, TypedConfiguration, TypedConfigurationFactory, TypedConfigurationAccessor, ConfigurationSchema, TypedConfigurationRegistry, TypedConfigurationOptions, ConfigurationType, StronglyTypedConfig, ConfigurationValue, ConfigurationPathResolver, NestJSConfigIntegrationService, EnhancedConfigModuleOptions, EnhancedAsyncConfigModuleOptions, EnhancedConfigModuleFactory, EnhancedAsyncConfigModuleFactory, EnhancedConfigModuleOptionsFactory, IntegrationStatus, AwsConfigurationLoader, ConfigurationMerger, AwsConfigurationValidator, EnhancedConfigService, ConfigValueWithSource, ConfigSourceInfo, ConfigHealthStatus, ConfigPropertyOptions, ConfigClassOptions, ConfigValidationOptions, TypeSafeConfigFactory, ConfigModuleBuilder, ConfigTestingUtils, ConfigMonitor, ConfigMetrics, ConfigEvent, ConfigAuditEntry, ConfigAuditLogger, ExtractConfigType, TypedConfigService, ConfigurationNamespaceRegistry, DeepReadonly, PartialDeep, RequiredDeep, ConfigPath, ConfigValue, AwsConfigSource, LocalConfigSource, AllConfigSource, ConfigSourceMetadata, ConfigWithSource, ExtractConfig, ConfigFactoryMap, ExtractConfigMap, NamespaceConfig, MultiNamespaceConfig, ValidationResult, AsyncValidationResult, ConfigTransformerFn, AsyncConfigTransformerFn, ConfigPredicate, AsyncConfigPredicate, ConfigBuilder, ConfigFluentAPI } from './integration/interfaces';
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAGA,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,8BAA8B,CAAC;AAC7C,cAAc,kCAAkC,CAAC;AACjD,cAAc,sCAAsC,CAAC;AACrD,cAAc,2BAA2B,CAAC;AAC1C,cAAc,yBAAyB,CAAC;AAGxC,cAAc,eAAe,CAAC;AAG9B,OAAO,EACL,WAAW,EACX,aAAa,EACb,WAAW,EACX,kBAAkB,EAClB,YAAY,EACb,MAAM,kDAAkD,CAAC;AAG1D,OAAO,EACL,oBAAoB,EACpB,cAAc,EACd,WAAW,EACX,cAAc,EACd,eAAe,EACf,2BAA2B,EAC5B,MAAM,gEAAgE,CAAC;AAGxE,OAAO,EAAE,8BAA8B,EAAE,MAAM,gDAAgD,CAAC;AAChG,YAAY,EAEV,kBAAkB,EAClB,uBAAuB,EACvB,cAAc,EACd,qBAAqB,EACrB,cAAc,EAGd,uBAAuB,EACvB,4BAA4B,EAG5B,mBAAmB,EACnB,uBAAuB,EAGvB,gBAAgB,EAGhB,kBAAkB,EAClB,yBAAyB,EACzB,0BAA0B,EAC1B,mBAAmB,EACnB,0BAA0B,EAC1B,yBAAyB,EACzB,iBAAiB,EACjB,mBAAmB,EACnB,kBAAkB,EAClB,yBAAyB,EAGzB,8BAA8B,EAC9B,2BAA2B,EAC3B,gCAAgC,EAChC,2BAA2B,EAC3B,gCAAgC,EAChC,kCAAkC,EAClC,iBAAiB,EACjB,sBAAsB,EACtB,mBAAmB,EACnB,yBAAyB,EAGzB,qBAAqB,EACrB,qBAAqB,EACrB,gBAAgB,EAChB,kBAAkB,EAClB,qBAAqB,EACrB,kBAAkB,EAClB,uBAAuB,EACvB,qBAAqB,EACrB,mBAAmB,EACnB,kBAAkB,EAClB,aAAa,EACb,aAAa,EACb,WAAW,EACX,gBAAgB,EAChB,iBAAiB,EAGjB,iBAAiB,EACjB,kBAAkB,EAClB,8BAA8B,EAC9B,YAAY,EACZ,WAAW,EACX,YAAY,EACZ,UAAU,EACV,WAAW,EACX,eAAe,EACf,iBAAiB,EACjB,eAAe,EACf,oBAAoB,EACpB,gBAAgB,EAChB,aAAa,EACb,gBAAgB,EAChB,gBAAgB,EAChB,eAAe,EACf,oBAAoB,EACpB,gBAAgB,EAChB,qBAAqB,EACrB,mBAAmB,EACnB,wBAAwB,EACxB,eAAe,EACf,oBAAoB,EACpB,aAAa,EACb,eAAe,EAChB,MAAM,0BAA0B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/integration/index.ts"],"names":[],"mappings":"AACA,cAAc,cAAc,CAAC;AAC7B,cAAc,oCAAoC,CAAC;AACnD,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,SAAS,CAAC"}
|