@itgorillaz/configify 1.2.5 → 1.3.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/README.md +23 -5
- package/dist/src/configify.module.d.ts +2 -2
- package/dist/src/configify.module.js +4 -5
- package/dist/src/configify.module.js.map +1 -1
- package/dist/src/configuration/configuration-options.interface.d.ts +2 -2
- package/dist/src/configuration/configuration-options.interface.js +2 -2
- package/dist/src/configuration/configuration-options.interface.js.map +1 -1
- package/dist/src/decorators/value.decorator.d.ts +2 -1
- package/dist/src/decorators/value.decorator.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/configify.module.ts +14 -12
- package/src/configuration/configuration-options.interface.ts +2 -2
- package/src/decorators/value.decorator.ts +11 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@itgorillaz/configify",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.1",
|
|
4
4
|
"description": "NestJS Config on Steroids",
|
|
5
5
|
"author": "tommelo",
|
|
6
6
|
"private": false,
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"@nestjs/testing": "^10.3.7",
|
|
45
45
|
"@types/jest": "29.5.14",
|
|
46
46
|
"@types/js-yaml": "^4.0.9",
|
|
47
|
-
"@types/node": "22.
|
|
47
|
+
"@types/node": "22.10.1",
|
|
48
48
|
"@types/supertest": "^6.0.2",
|
|
49
49
|
"@typescript-eslint/eslint-plugin": "^8.1.0",
|
|
50
50
|
"@typescript-eslint/parser": "^8.1.0",
|
package/src/configify.module.ts
CHANGED
|
@@ -6,11 +6,11 @@ import * as fs from 'fs';
|
|
|
6
6
|
import { resolve } from 'path';
|
|
7
7
|
import {
|
|
8
8
|
AwsSecretsManagerConfigurationResolver,
|
|
9
|
-
|
|
9
|
+
ConfigifyModuleOptions,
|
|
10
10
|
ConfigurationParserFactory,
|
|
11
11
|
ConfigurationProviders,
|
|
12
12
|
ConfigurationRegistry,
|
|
13
|
-
|
|
13
|
+
DefaultConfigifyModuleOptions,
|
|
14
14
|
} from './configuration';
|
|
15
15
|
import { AwsParameterStoreConfigurationResolver } from './configuration/resolvers/aws/parameter-store-configuration.resolver';
|
|
16
16
|
import { Variables } from './interpolation/variables';
|
|
@@ -51,12 +51,12 @@ export class ConfigifyModule {
|
|
|
51
51
|
* AWS Secrets Manager and AWS Parameters Store.
|
|
52
52
|
*/
|
|
53
53
|
private static readonly SECRETS_RESOLVER_PIPELINE = [
|
|
54
|
-
(options:
|
|
54
|
+
(options: ConfigifyModuleOptions) =>
|
|
55
55
|
new AwsSecretsManagerConfigurationResolver(
|
|
56
56
|
options.secretsManagerClient || new SecretsManagerClient(),
|
|
57
57
|
),
|
|
58
58
|
|
|
59
|
-
(options:
|
|
59
|
+
(options: ConfigifyModuleOptions) =>
|
|
60
60
|
new AwsParameterStoreConfigurationResolver(
|
|
61
61
|
options.ssmClient || new SSMClient(),
|
|
62
62
|
),
|
|
@@ -71,13 +71,13 @@ export class ConfigifyModule {
|
|
|
71
71
|
*
|
|
72
72
|
* The configuration key pair values will also be available on process.env object.
|
|
73
73
|
*
|
|
74
|
-
* @param {
|
|
74
|
+
* @param { ConfigifyModuleOptions } options The module config options
|
|
75
75
|
* @returns { DynamicModule } module The configy module
|
|
76
76
|
*/
|
|
77
77
|
static async forRootAsync(
|
|
78
|
-
options:
|
|
78
|
+
options: ConfigifyModuleOptions = {},
|
|
79
79
|
): Promise<DynamicModule> {
|
|
80
|
-
const settings = { ...options, ...
|
|
80
|
+
const settings = { ...options, ...DefaultConfigifyModuleOptions };
|
|
81
81
|
const files = this.resolveConfigurationFiles(settings.configFilePath);
|
|
82
82
|
|
|
83
83
|
const envVars = settings.ignoreEnvVars ? {} : process.env;
|
|
@@ -110,12 +110,12 @@ export class ConfigifyModule {
|
|
|
110
110
|
* Runs the secrets resolver pipeline.
|
|
111
111
|
*
|
|
112
112
|
* @param {Record<string, any>} config the configuration object
|
|
113
|
-
* @param {
|
|
113
|
+
* @param {ConfigifyModuleOptions} options the module options
|
|
114
114
|
* @returns {Promise<Record<string, any>>} the resolved secrets
|
|
115
115
|
*/
|
|
116
116
|
private static async runSecretsResolverPipeline(
|
|
117
117
|
config: Record<string, any>,
|
|
118
|
-
options:
|
|
118
|
+
options: ConfigifyModuleOptions,
|
|
119
119
|
): Promise<Record<string, any>> {
|
|
120
120
|
const secrets = {};
|
|
121
121
|
for (const buildResolver of this.SECRETS_RESOLVER_PIPELINE) {
|
|
@@ -151,9 +151,11 @@ export class ConfigifyModule {
|
|
|
151
151
|
);
|
|
152
152
|
|
|
153
153
|
const parse = metadata.options?.parse;
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
154
|
+
|
|
155
|
+
const defaultValue =
|
|
156
|
+
process.env[metadata.key] || metadata.options?.default;
|
|
157
|
+
|
|
158
|
+
const value = parse ? parse(defaultValue) : defaultValue;
|
|
157
159
|
|
|
158
160
|
instance[attribute] = value;
|
|
159
161
|
}
|
|
@@ -4,7 +4,7 @@ import { SSMClient } from '@aws-sdk/client-ssm';
|
|
|
4
4
|
/**
|
|
5
5
|
* The configuration options interface
|
|
6
6
|
*/
|
|
7
|
-
export interface
|
|
7
|
+
export interface ConfigifyModuleOptions {
|
|
8
8
|
/**
|
|
9
9
|
* Ignores any config file.
|
|
10
10
|
* The default value is false;
|
|
@@ -44,7 +44,7 @@ export interface ConfigfyModuleOptions {
|
|
|
44
44
|
/**
|
|
45
45
|
* The default module options
|
|
46
46
|
*/
|
|
47
|
-
export const
|
|
47
|
+
export const DefaultConfigifyModuleOptions: ConfigifyModuleOptions = {
|
|
48
48
|
ignoreConfigFile: false,
|
|
49
49
|
ignoreEnvVars: false,
|
|
50
50
|
expandConfig: true,
|
|
@@ -15,7 +15,17 @@ export const VALUE_PROPERTIES_METADATA = Symbol.for('__properties__');
|
|
|
15
15
|
* Allows custom parsing to configuration values
|
|
16
16
|
*/
|
|
17
17
|
export interface ValueOptions {
|
|
18
|
-
|
|
18
|
+
/**
|
|
19
|
+
* Parses the configuration value.
|
|
20
|
+
* @param value
|
|
21
|
+
* @returns parsed value
|
|
22
|
+
*/
|
|
23
|
+
parse?: (value: any) => unknown;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Sets a default value if the configuration key is not found.
|
|
27
|
+
*/
|
|
28
|
+
default?: any;
|
|
19
29
|
}
|
|
20
30
|
|
|
21
31
|
/**
|