@itgorillaz/configify 1.3.1 → 2.0.0
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 +33 -15
- package/dist/src/configify.module.d.ts +0 -1
- package/dist/src/configify.module.js +6 -11
- package/dist/src/configify.module.js.map +1 -1
- package/dist/src/configuration/configuration-options.interface.d.ts +2 -4
- package/dist/src/configuration/configuration-options.interface.js.map +1 -1
- package/dist/src/configuration/resolvers/aws/aws-secrets-resolver.factory.d.ts +5 -0
- package/dist/src/configuration/resolvers/aws/aws-secrets-resolver.factory.js +17 -0
- package/dist/src/configuration/resolvers/aws/aws-secrets-resolver.factory.js.map +1 -0
- package/dist/src/configuration/resolvers/aws/index.d.ts +1 -0
- package/dist/src/configuration/resolvers/aws/index.js +1 -0
- package/dist/src/configuration/resolvers/aws/index.js.map +1 -1
- package/dist/src/configuration/resolvers/aws/parameter-store-configuration.resolver.js.map +1 -1
- package/dist/src/configuration/resolvers/aws/secrets-manager-configuration.resolver.js.map +1 -1
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.js +1 -0
- package/dist/src/index.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/configify.module.ts +8 -28
- package/src/configuration/configuration-options.interface.ts +3 -11
- package/src/configuration/configuration-parser.interface.ts +1 -1
- package/src/configuration/resolvers/aws/aws-secrets-resolver.factory.ts +32 -0
- package/src/configuration/resolvers/aws/index.ts +1 -0
- package/src/configuration/resolvers/aws/parameter-store-configuration.resolver.ts +1 -1
- package/src/configuration/resolvers/aws/secrets-manager-configuration.resolver.ts +1 -1
- package/src/index.ts +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@itgorillaz/configify",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
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.10.
|
|
47
|
+
"@types/node": "22.10.2",
|
|
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
|
@@ -1,18 +1,14 @@
|
|
|
1
|
-
import { SecretsManagerClient } from '@aws-sdk/client-secrets-manager';
|
|
2
|
-
import { SSMClient } from '@aws-sdk/client-ssm';
|
|
3
1
|
import { DynamicModule, Module, Provider } from '@nestjs/common';
|
|
4
2
|
import { validateSync } from 'class-validator';
|
|
5
3
|
import * as fs from 'fs';
|
|
6
4
|
import { resolve } from 'path';
|
|
7
5
|
import {
|
|
8
|
-
AwsSecretsManagerConfigurationResolver,
|
|
9
6
|
ConfigifyModuleOptions,
|
|
10
7
|
ConfigurationParserFactory,
|
|
11
8
|
ConfigurationProviders,
|
|
12
9
|
ConfigurationRegistry,
|
|
13
10
|
DefaultConfigifyModuleOptions,
|
|
14
11
|
} from './configuration';
|
|
15
|
-
import { AwsParameterStoreConfigurationResolver } from './configuration/resolvers/aws/parameter-store-configuration.resolver';
|
|
16
12
|
import { Variables } from './interpolation/variables';
|
|
17
13
|
|
|
18
14
|
/**
|
|
@@ -26,7 +22,7 @@ import { Variables } from './interpolation/variables';
|
|
|
26
22
|
* - Reading configuration files
|
|
27
23
|
* - Resolving remote secrets
|
|
28
24
|
* - Expanding variables
|
|
29
|
-
* - Creating object instances
|
|
25
|
+
* - Creating object instances decorated with Configuration and assigning its values
|
|
30
26
|
* - Validating the configuration instance
|
|
31
27
|
*
|
|
32
28
|
* All the configuration set to the configuration files will be assigned to the process.env object
|
|
@@ -45,28 +41,11 @@ export class ConfigifyModule {
|
|
|
45
41
|
resolve(process.cwd(), 'application.json'),
|
|
46
42
|
];
|
|
47
43
|
|
|
48
|
-
/**
|
|
49
|
-
* The remote secrets resolvers pipeline.
|
|
50
|
-
* This module currently supports resolving secrets on
|
|
51
|
-
* AWS Secrets Manager and AWS Parameters Store.
|
|
52
|
-
*/
|
|
53
|
-
private static readonly SECRETS_RESOLVER_PIPELINE = [
|
|
54
|
-
(options: ConfigifyModuleOptions) =>
|
|
55
|
-
new AwsSecretsManagerConfigurationResolver(
|
|
56
|
-
options.secretsManagerClient || new SecretsManagerClient(),
|
|
57
|
-
),
|
|
58
|
-
|
|
59
|
-
(options: ConfigifyModuleOptions) =>
|
|
60
|
-
new AwsParameterStoreConfigurationResolver(
|
|
61
|
-
options.ssmClient || new SSMClient(),
|
|
62
|
-
),
|
|
63
|
-
];
|
|
64
|
-
|
|
65
44
|
/**
|
|
66
45
|
* Creates the configfy dynamic module.
|
|
67
46
|
*
|
|
68
47
|
* The module will manage the instance of all classes decorated the Configuration decorator,
|
|
69
|
-
* meaning, the module will
|
|
48
|
+
* meaning, the module will create the instance and associate the value to attributes according to the
|
|
70
49
|
* keys provided by the Value decorator.
|
|
71
50
|
*
|
|
72
51
|
* The configuration key pair values will also be available on process.env object.
|
|
@@ -118,10 +97,11 @@ export class ConfigifyModule {
|
|
|
118
97
|
options: ConfigifyModuleOptions,
|
|
119
98
|
): Promise<Record<string, any>> {
|
|
120
99
|
const secrets = {};
|
|
121
|
-
|
|
122
|
-
const resolver
|
|
123
|
-
|
|
124
|
-
|
|
100
|
+
if (options.secretsResolverStrategies?.length) {
|
|
101
|
+
for (const resolver of options.secretsResolverStrategies) {
|
|
102
|
+
const result = await resolver.resolve(config);
|
|
103
|
+
Object.assign(secrets, result);
|
|
104
|
+
}
|
|
125
105
|
}
|
|
126
106
|
return secrets;
|
|
127
107
|
}
|
|
@@ -134,7 +114,7 @@ export class ConfigifyModule {
|
|
|
134
114
|
* @returns {ConfigurationProviders} the module configuration providers
|
|
135
115
|
*/
|
|
136
116
|
private static buildConfigurationProviders(): ConfigurationProviders {
|
|
137
|
-
const exports = [];
|
|
117
|
+
const exports: unknown[] = [];
|
|
138
118
|
const providers: Provider[] = [];
|
|
139
119
|
|
|
140
120
|
const registry = ConfigurationRegistry.getRegistry();
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { SSMClient } from '@aws-sdk/client-ssm';
|
|
1
|
+
import { ConfigurationResolver } from './resolvers';
|
|
3
2
|
|
|
4
3
|
/**
|
|
5
4
|
* The configuration options interface
|
|
@@ -29,16 +28,9 @@ export interface ConfigifyModuleOptions {
|
|
|
29
28
|
expandConfig?: boolean;
|
|
30
29
|
|
|
31
30
|
/**
|
|
32
|
-
* The
|
|
33
|
-
* If no client is provided, the module will create one.
|
|
31
|
+
* The secrets resolvers strategies
|
|
34
32
|
*/
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* The AWS Systems Manager Client
|
|
39
|
-
* If no client is provided, the module will create one.
|
|
40
|
-
*/
|
|
41
|
-
ssmClient?: SSMClient;
|
|
33
|
+
secretsResolverStrategies?: ConfigurationResolver[];
|
|
42
34
|
}
|
|
43
35
|
|
|
44
36
|
/**
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { SecretsManagerClient } from '@aws-sdk/client-secrets-manager';
|
|
2
|
+
import { SSMClient } from '@aws-sdk/client-ssm';
|
|
3
|
+
import { ConfigurationResolver } from '../configuration-resolver.interface';
|
|
4
|
+
import { AwsParameterStoreConfigurationResolver } from './parameter-store-configuration.resolver';
|
|
5
|
+
import { AwsSecretsManagerConfigurationResolver } from './secrets-manager-configuration.resolver';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* The AWS secrets resolver factory.
|
|
9
|
+
* This class provides the default secrets resolvers for the module.
|
|
10
|
+
* The default secrets resolvers are:
|
|
11
|
+
* - Parameter Store
|
|
12
|
+
* - Secrets Manager
|
|
13
|
+
*/
|
|
14
|
+
export class AwsSecretsResolverFactory {
|
|
15
|
+
/**
|
|
16
|
+
* The default parameter store secrets resolver
|
|
17
|
+
* @returns {ConfigurationResolver} the default parameter store secrets resolver
|
|
18
|
+
*/
|
|
19
|
+
static defaultParameterStoreResolver(): ConfigurationResolver {
|
|
20
|
+
return new AwsParameterStoreConfigurationResolver(new SSMClient());
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* The default secrets manager secrets resolver
|
|
25
|
+
* @returns {ConfigurationResolver} the default secrets manager secrets resolver
|
|
26
|
+
*/
|
|
27
|
+
static defaultSecretsManagerResolver(): ConfigurationResolver {
|
|
28
|
+
return new AwsSecretsManagerConfigurationResolver(
|
|
29
|
+
new SecretsManagerClient(),
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -106,7 +106,7 @@ export class AwsParameterStoreConfigurationResolver
|
|
|
106
106
|
private buildBulkRequest(
|
|
107
107
|
config: Record<string, any>,
|
|
108
108
|
): Promise<ResolvedValue>[] {
|
|
109
|
-
const promises = [];
|
|
109
|
+
const promises: Promise<ResolvedValue>[] = [];
|
|
110
110
|
for (const [key, value] of Object.entries(config)) {
|
|
111
111
|
promises.push(this.resolveSecretValue(key, value));
|
|
112
112
|
}
|
|
@@ -108,7 +108,7 @@ export class AwsSecretsManagerConfigurationResolver
|
|
|
108
108
|
private buildBulkRequest(
|
|
109
109
|
config: Record<string, any>,
|
|
110
110
|
): Promise<ResolvedValue>[] {
|
|
111
|
-
const promises = [];
|
|
111
|
+
const promises: Promise<ResolvedValue>[] = [];
|
|
112
112
|
for (const [key, value] of Object.entries(config)) {
|
|
113
113
|
promises.push(this.resolveSecretValue(key, value));
|
|
114
114
|
}
|
package/src/index.ts
CHANGED