@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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@itgorillaz/configify",
3
- "version": "1.2.5",
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.9.3",
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",
@@ -6,11 +6,11 @@ import * as fs from 'fs';
6
6
  import { resolve } from 'path';
7
7
  import {
8
8
  AwsSecretsManagerConfigurationResolver,
9
- ConfigfyModuleOptions,
9
+ ConfigifyModuleOptions,
10
10
  ConfigurationParserFactory,
11
11
  ConfigurationProviders,
12
12
  ConfigurationRegistry,
13
- DefaultConfigfyModuleOptions,
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: ConfigfyModuleOptions) =>
54
+ (options: ConfigifyModuleOptions) =>
55
55
  new AwsSecretsManagerConfigurationResolver(
56
56
  options.secretsManagerClient || new SecretsManagerClient(),
57
57
  ),
58
58
 
59
- (options: ConfigfyModuleOptions) =>
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 { ConfigfyModuleOptions } options The module config options
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: ConfigfyModuleOptions = {},
78
+ options: ConfigifyModuleOptions = {},
79
79
  ): Promise<DynamicModule> {
80
- const settings = { ...options, ...DefaultConfigfyModuleOptions };
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 {ConfigfyModuleOptions} options the module options
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: ConfigfyModuleOptions,
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
- const value = parse
155
- ? parse(process.env[metadata.key])
156
- : process.env[metadata.key];
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 ConfigfyModuleOptions {
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 DefaultConfigfyModuleOptions: ConfigfyModuleOptions = {
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
- parse: (value: any) => any;
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
  /**