@maroonedsoftware/appconfig 1.5.1 → 1.7.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 +149 -1
- package/dist/helpers.d.ts +17 -0
- package/dist/helpers.d.ts.map +1 -1
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +388 -1
- package/dist/index.js.map +1 -1
- package/dist/options/app.config.options.d.ts +81 -0
- package/dist/options/app.config.options.d.ts.map +1 -0
- package/dist/options/app.config.options.manager.d.ts +52 -0
- package/dist/options/app.config.options.manager.d.ts.map +1 -0
- package/dist/options/app.config.options.monitor.d.ts +47 -0
- package/dist/options/app.config.options.monitor.d.ts.map +1 -0
- package/dist/options/app.config.options.registration.d.ts +51 -0
- package/dist/options/app.config.options.registration.d.ts.map +1 -0
- package/dist/options/app.config.store.d.ts +72 -0
- package/dist/options/app.config.store.d.ts.map +1 -0
- package/dist/providers/app.config.provider.aws.secrets.d.ts +106 -0
- package/dist/providers/app.config.provider.aws.secrets.d.ts.map +1 -0
- package/package.json +6 -3
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { AppConfigProvider } from '../app.config.provider.js';
|
|
2
|
+
import { ObjectVisitorMeta } from '../object.visitor.js';
|
|
3
|
+
/**
|
|
4
|
+
* Provider that resolves AWS Secrets Manager references in configuration values.
|
|
5
|
+
*
|
|
6
|
+
* This provider matches string values using a regex pattern and replaces them with
|
|
7
|
+
* secrets fetched from AWS Secrets Manager. The default pattern matches `${aws:SECRET_ID}`
|
|
8
|
+
* and extracts the secret id (a name or ARN) to look up in Secrets Manager.
|
|
9
|
+
*
|
|
10
|
+
* After retrieval, the secret value is attempted to be parsed as JSON. If parsing succeeds,
|
|
11
|
+
* the parsed value is used; otherwise, the string value is used.
|
|
12
|
+
*
|
|
13
|
+
* @remarks
|
|
14
|
+
* This provider requires valid AWS credentials to be configured. It uses the
|
|
15
|
+
* `@aws-sdk/client-secrets-manager` package and resolves credentials and region from the
|
|
16
|
+
* standard AWS provider chain (environment variables, shared config/credentials files,
|
|
17
|
+
* instance/task roles). The region can be passed explicitly to override the chain.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* // With default pattern /\$\{aws:(.+)\}/g
|
|
22
|
+
* // Value: "${aws:DATABASE_PASSWORD}"
|
|
23
|
+
* // Fetches the latest version of the "DATABASE_PASSWORD" secret
|
|
24
|
+
*
|
|
25
|
+
* const config = await new AppConfigBuilder()
|
|
26
|
+
* .addSource(new AppConfigSourceJson('./config.json'))
|
|
27
|
+
* .addProvider(new AppConfigProviderAwsSecrets('us-east-1'))
|
|
28
|
+
* .build();
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export declare class AppConfigProviderAwsSecrets implements AppConfigProvider {
|
|
32
|
+
private readonly region?;
|
|
33
|
+
private readonly secretsManagerClient;
|
|
34
|
+
private readonly prefix;
|
|
35
|
+
/**
|
|
36
|
+
* Creates a new AppConfigProviderAwsSecrets instance.
|
|
37
|
+
*
|
|
38
|
+
* @param region - The AWS region where secrets are stored. If omitted, the region is
|
|
39
|
+
* resolved from the standard AWS provider chain (e.g. `AWS_REGION`).
|
|
40
|
+
* @param prefix - A regex pattern or string to match secret references.
|
|
41
|
+
* If a string is provided, it will be converted to a RegExp. The regex must have
|
|
42
|
+
* at least one capture group that extracts the secret id.
|
|
43
|
+
* Defaults to `/\$\{aws:(.+)\}/g` which matches `${aws:SECRET_ID}` patterns.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```typescript
|
|
47
|
+
* // Default pattern, region from the AWS provider chain
|
|
48
|
+
* const provider1 = new AppConfigProviderAwsSecrets();
|
|
49
|
+
*
|
|
50
|
+
* // Explicit region
|
|
51
|
+
* const provider2 = new AppConfigProviderAwsSecrets('us-east-1');
|
|
52
|
+
*
|
|
53
|
+
* // Custom regex pattern
|
|
54
|
+
* const provider3 = new AppConfigProviderAwsSecrets('us-east-1', /\$\{secret:([^}]+)\}/g);
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
constructor(region?: string | undefined, prefix?: string | RegExp);
|
|
58
|
+
/**
|
|
59
|
+
* Checks if this provider can parse the given value.
|
|
60
|
+
*
|
|
61
|
+
* @param value - The string value to check.
|
|
62
|
+
* @returns `true` if the value matches the provider's regex pattern, `false` otherwise.
|
|
63
|
+
*/
|
|
64
|
+
canParse(value: string): boolean;
|
|
65
|
+
/**
|
|
66
|
+
* Fetches a secret from AWS Secrets Manager.
|
|
67
|
+
*
|
|
68
|
+
* @param secretId - The id (name or ARN) of the secret to fetch.
|
|
69
|
+
* @returns A promise that resolves to the secret value.
|
|
70
|
+
* @throws {ServerkitError} When Secrets Manager rejects the access request (e.g. missing
|
|
71
|
+
* secret, IAM denial, network failure). The original error is attached via `withCause`
|
|
72
|
+
* and the failing `secretId` / `region` are recorded in `internalDetails`. Surfacing
|
|
73
|
+
* the failure prevents callers booting with an empty password / API key.
|
|
74
|
+
* @internal
|
|
75
|
+
*/
|
|
76
|
+
private getSecret;
|
|
77
|
+
/**
|
|
78
|
+
* Parses the value by replacing AWS secret references with actual secret values.
|
|
79
|
+
*
|
|
80
|
+
* The method:
|
|
81
|
+
* 1. Finds all matches of the regex pattern in the value
|
|
82
|
+
* 2. Fetches each secret from AWS Secrets Manager in parallel
|
|
83
|
+
* 3. Attempts to parse each result as JSON
|
|
84
|
+
* 4. Updates the configuration object with the final value
|
|
85
|
+
*
|
|
86
|
+
* @param value - The string value containing AWS secret references.
|
|
87
|
+
* @param meta - Metadata about the value's location in the configuration object.
|
|
88
|
+
* @returns A promise that resolves when all secrets have been fetched and the
|
|
89
|
+
* transformation is complete.
|
|
90
|
+
* @throws {ServerkitError} Propagated from {@link getSecret} when any referenced secret
|
|
91
|
+
* cannot be resolved. The build call site is expected to fail loud and stop boot.
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* ```typescript
|
|
95
|
+
* // If AWS secret "API_KEY" contains "sk-abc123"
|
|
96
|
+
* // Value: "${aws:API_KEY}"
|
|
97
|
+
* // Result: "sk-abc123"
|
|
98
|
+
*
|
|
99
|
+
* // If AWS secret "CONFIG" contains '{"retries": 3}'
|
|
100
|
+
* // Value: "${aws:CONFIG}"
|
|
101
|
+
* // Result: { retries: 3 } (parsed as JSON object)
|
|
102
|
+
* ```
|
|
103
|
+
*/
|
|
104
|
+
parse(value: string, meta: ObjectVisitorMeta): Promise<void>;
|
|
105
|
+
}
|
|
106
|
+
//# sourceMappingURL=app.config.provider.aws.secrets.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app.config.provider.aws.secrets.d.ts","sourceRoot":"","sources":["../../src/providers/app.config.provider.aws.secrets.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAKzD;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,qBACa,2BAA4B,YAAW,iBAAiB;IA2BjE,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC;IA1B1B,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAAuB;IAC5D,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAEhC;;;;;;;;;;;;;;;;;;;;;OAqBG;gBAEgB,MAAM,CAAC,EAAE,MAAM,YAAA,EAChC,MAAM,GAAE,MAAM,GAAG,MAA0B;IAM7C;;;;;OAKG;IACH,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;IAQhC;;;;;;;;;;OAUG;YACW,SAAS;IAkBvB;;;;;;;;;;;;;;;;;;;;;;;;;;OA0BG;IACG,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC;CAiBnE"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@maroonedsoftware/appconfig",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.0",
|
|
4
4
|
"description": "A flexible, type-safe configuration management library with support for multiple sources and value transformation.",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Marooned Software",
|
|
@@ -32,16 +32,19 @@
|
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"deepmerge-ts": "^7.1.5",
|
|
34
34
|
"dotenv": "^17.4.2",
|
|
35
|
-
"injectkit": "^1.4.
|
|
36
|
-
"@maroonedsoftware/errors": "1.7.0"
|
|
35
|
+
"injectkit": "^1.4.2",
|
|
36
|
+
"@maroonedsoftware/errors": "1.7.0",
|
|
37
|
+
"@maroonedsoftware/logger": "1.1.1"
|
|
37
38
|
},
|
|
38
39
|
"devDependencies": {
|
|
40
|
+
"@aws-sdk/client-secrets-manager": "^3.1057.0",
|
|
39
41
|
"@google-cloud/secret-manager": "^6.1.2",
|
|
40
42
|
"yaml": "^2.9.0",
|
|
41
43
|
"@repo/config-eslint": "0.2.1",
|
|
42
44
|
"@repo/config-typescript": "0.1.0"
|
|
43
45
|
},
|
|
44
46
|
"peerDependencies": {
|
|
47
|
+
"@aws-sdk/client-secrets-manager": "^3.1057.0",
|
|
45
48
|
"@google-cloud/secret-manager": "^6.1.1",
|
|
46
49
|
"yaml": "^2.8.2"
|
|
47
50
|
},
|