@karmaniverous/aws-secrets-manager-tools 0.1.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/LICENSE +28 -0
- package/README.md +96 -0
- package/dist/cli/aws-secrets-manager-tools/index.js +889 -0
- package/dist/index.d.ts +250 -0
- package/dist/mjs/index.js +873 -0
- package/package.json +148 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
import { SecretsManagerClient, SecretsManagerClientConfig } from '@aws-sdk/client-secrets-manager';
|
|
2
|
+
import * as _karmaniverous_get_dotenv_cliHost from '@karmaniverous/get-dotenv/cliHost';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Requirements addressed:
|
|
6
|
+
* - Secret values are always a JSON object map of env vars.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Canonical “env secret” shape stored in AWS Secrets Manager.
|
|
10
|
+
*
|
|
11
|
+
* `undefined` values are not representable in JSON; readers should treat `null`
|
|
12
|
+
* values as `undefined` when decoding.
|
|
13
|
+
*/
|
|
14
|
+
type EnvSecretMap = Record<string, string | undefined>;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Requirements addressed:
|
|
18
|
+
* - Provide a public tools-style wrapper `AwsSecretsManagerTools`.
|
|
19
|
+
* - Package consumers should not need to construct SecretsManagerClient; they
|
|
20
|
+
* should use `AwsSecretsManagerTools.init(...)` and optionally import AWS SDK
|
|
21
|
+
* Commands for advanced operations.
|
|
22
|
+
* - Expose the fully configured SDK client via `tools.client`.
|
|
23
|
+
* - Support optional AWS X-Ray capture:
|
|
24
|
+
* - Default “auto”: enable only when AWS_XRAY_DAEMON_ADDRESS is set.
|
|
25
|
+
* - In “auto”, if the daemon address is set but aws-xray-sdk is missing,
|
|
26
|
+
* throw with a clear message.
|
|
27
|
+
* - Enforce a minimal logger contract (debug/info/warn/error); do not attempt
|
|
28
|
+
* to polyfill or proxy unknown loggers.
|
|
29
|
+
* - Secret values are JSON object maps of env vars.
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Console-like logger contract used by AwsSecretsManagerTools.
|
|
34
|
+
*
|
|
35
|
+
* If you pass a custom logger via `clientConfig.logger`, it must implement
|
|
36
|
+
* these methods (no internal polyfills are applied).
|
|
37
|
+
*/
|
|
38
|
+
type AwsSecretsManagerToolsLogger = Pick<Console, 'debug' | 'error' | 'info' | 'warn'>;
|
|
39
|
+
/** X-Ray capture mode for {@link AwsSecretsManagerTools.init}. */
|
|
40
|
+
type AwsSecretsManagerToolsXrayMode = 'auto' | 'on' | 'off';
|
|
41
|
+
/**
|
|
42
|
+
* Materialized X-Ray state for diagnostics and DX.
|
|
43
|
+
*
|
|
44
|
+
* Note: `enabled` reflects the effective runtime decision after applying the
|
|
45
|
+
* configured `mode` and checking daemon configuration.
|
|
46
|
+
*/
|
|
47
|
+
type XrayState = {
|
|
48
|
+
/** Capture mode configured for initialization. */
|
|
49
|
+
mode: AwsSecretsManagerToolsXrayMode;
|
|
50
|
+
/** Whether capture is enabled for the effective client instance. */
|
|
51
|
+
enabled: boolean;
|
|
52
|
+
/** Daemon address used when capture is enabled (if available). */
|
|
53
|
+
daemonAddress?: string;
|
|
54
|
+
};
|
|
55
|
+
/** Options for {@link AwsSecretsManagerTools.init}. */
|
|
56
|
+
type AwsSecretsManagerToolsInitOptions = {
|
|
57
|
+
/**
|
|
58
|
+
* AWS SDK v3 Secrets Manager client config.
|
|
59
|
+
*
|
|
60
|
+
* Include advanced settings here (region, credentials, retry config, custom
|
|
61
|
+
* endpoint, etc.). If a logger is provided, it must implement
|
|
62
|
+
* debug/info/warn/error.
|
|
63
|
+
*/
|
|
64
|
+
clientConfig?: SecretsManagerClientConfig;
|
|
65
|
+
/**
|
|
66
|
+
* AWS X-Ray capture mode.
|
|
67
|
+
*
|
|
68
|
+
* - `auto` (default): enable only when `AWS_XRAY_DAEMON_ADDRESS` is set.
|
|
69
|
+
* - `on`: force enable (throws if daemon address is missing).
|
|
70
|
+
* - `off`: disable.
|
|
71
|
+
*/
|
|
72
|
+
xray?: AwsSecretsManagerToolsXrayMode;
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* Tools-style AWS Secrets Manager wrapper for env-map secrets.
|
|
76
|
+
*
|
|
77
|
+
* The secret payload is always a JSON object map of environment variables:
|
|
78
|
+
* `Record<string, string | undefined>`.
|
|
79
|
+
*
|
|
80
|
+
* Consumers should typically use the convenience methods on this class, and
|
|
81
|
+
* use {@link AwsSecretsManagerTools.client} as an escape hatch when they need
|
|
82
|
+
* AWS SDK operations not wrapped here.
|
|
83
|
+
*/
|
|
84
|
+
declare class AwsSecretsManagerTools {
|
|
85
|
+
/**
|
|
86
|
+
* The effective SDK client (captured when X-Ray is enabled).
|
|
87
|
+
*
|
|
88
|
+
* Import AWS SDK `*Command` classes as needed and call `tools.client.send(...)`.
|
|
89
|
+
*/
|
|
90
|
+
readonly client: SecretsManagerClient;
|
|
91
|
+
/**
|
|
92
|
+
* The effective client config used to construct the base client.
|
|
93
|
+
*
|
|
94
|
+
* Note: this may contain functions/providers (e.g., credential providers).
|
|
95
|
+
*/
|
|
96
|
+
readonly clientConfig: SecretsManagerClientConfig;
|
|
97
|
+
/** The logger used by this wrapper and (when applicable) by the AWS client. */
|
|
98
|
+
readonly logger: AwsSecretsManagerToolsLogger;
|
|
99
|
+
/** Materialized X-Ray state (mode + enabled + daemonAddress when relevant). */
|
|
100
|
+
readonly xray: XrayState;
|
|
101
|
+
private constructor();
|
|
102
|
+
/**
|
|
103
|
+
* Initialize an `AwsSecretsManagerTools` instance.
|
|
104
|
+
*
|
|
105
|
+
* This factory owns all setup (including optional X-Ray capture) so consumers
|
|
106
|
+
* do not need to construct a base Secrets Manager client themselves.
|
|
107
|
+
*
|
|
108
|
+
* @throws If `clientConfig.logger` is provided but does not implement
|
|
109
|
+
* `debug`, `info`, `warn`, and `error`.
|
|
110
|
+
* @throws If X-Ray capture is enabled (via `xray: 'on'` or `xray: 'auto'`
|
|
111
|
+
* with `AWS_XRAY_DAEMON_ADDRESS` set) but `aws-xray-sdk` is not installed.
|
|
112
|
+
* @throws If X-Ray capture is requested but `AWS_XRAY_DAEMON_ADDRESS` is not set.
|
|
113
|
+
*/
|
|
114
|
+
static init({ clientConfig, xray: xrayMode, }?: AwsSecretsManagerToolsInitOptions): Promise<AwsSecretsManagerTools>;
|
|
115
|
+
/**
|
|
116
|
+
* Read a Secrets Manager secret and parse it as an env-map secret.
|
|
117
|
+
*
|
|
118
|
+
* @param opts - Options:
|
|
119
|
+
* - `secretId`: Secret name or ARN.
|
|
120
|
+
* - `versionId`: Optional version id to read.
|
|
121
|
+
*
|
|
122
|
+
* @throws If the secret is missing, binary, invalid JSON, or not an object map.
|
|
123
|
+
*/
|
|
124
|
+
readEnvSecret(opts: {
|
|
125
|
+
secretId: string;
|
|
126
|
+
versionId?: string;
|
|
127
|
+
}): Promise<EnvSecretMap>;
|
|
128
|
+
/**
|
|
129
|
+
* Write a new version value for an existing secret.
|
|
130
|
+
*
|
|
131
|
+
* This does not create the secret if it does not exist.
|
|
132
|
+
*
|
|
133
|
+
* @param opts - Options:
|
|
134
|
+
* - `secretId`: Secret name or ARN.
|
|
135
|
+
* - `value`: Env-map payload to store (JSON object map).
|
|
136
|
+
* - `versionId`: Optional client request token (idempotency).
|
|
137
|
+
*/
|
|
138
|
+
updateEnvSecret(opts: {
|
|
139
|
+
secretId: string;
|
|
140
|
+
value: EnvSecretMap;
|
|
141
|
+
versionId?: string;
|
|
142
|
+
}): Promise<void>;
|
|
143
|
+
/**
|
|
144
|
+
* Create a new secret containing an env-map.
|
|
145
|
+
*
|
|
146
|
+
* @param opts - Options:
|
|
147
|
+
* - `secretId`: Secret name (or ARN in some contexts).
|
|
148
|
+
* - `value`: Env-map payload to store (JSON object map).
|
|
149
|
+
* - `description`: Optional AWS secret description.
|
|
150
|
+
* - `forceOverwriteReplicaSecret`: See AWS CreateSecret behavior for replicas.
|
|
151
|
+
* - `versionId`: Optional client request token (idempotency).
|
|
152
|
+
*/
|
|
153
|
+
createEnvSecret(opts: {
|
|
154
|
+
secretId: string;
|
|
155
|
+
value: EnvSecretMap;
|
|
156
|
+
description?: string;
|
|
157
|
+
forceOverwriteReplicaSecret?: boolean;
|
|
158
|
+
versionId?: string;
|
|
159
|
+
}): Promise<void>;
|
|
160
|
+
/**
|
|
161
|
+
* Put a secret value, creating the secret only when it does not exist.
|
|
162
|
+
*
|
|
163
|
+
* This creates only when the update fails with `ResourceNotFoundException`;
|
|
164
|
+
* other errors are re-thrown.
|
|
165
|
+
*
|
|
166
|
+
* @returns `'updated'` if updated; `'created'` if the secret was created.
|
|
167
|
+
* @throws Re-throws any non-ResourceNotFound AWS errors.
|
|
168
|
+
*/
|
|
169
|
+
upsertEnvSecret({ secretId, value, }: {
|
|
170
|
+
secretId: string;
|
|
171
|
+
value: EnvSecretMap;
|
|
172
|
+
}): Promise<'updated' | 'created'>;
|
|
173
|
+
/**
|
|
174
|
+
* Delete a secret.
|
|
175
|
+
*
|
|
176
|
+
* By default, deletion is recoverable (AWS default recovery window) unless
|
|
177
|
+
* `forceDeleteWithoutRecovery` is set.
|
|
178
|
+
*
|
|
179
|
+
* @param opts - Options:
|
|
180
|
+
* - `secretId`: Secret name or ARN.
|
|
181
|
+
* - `recoveryWindowInDays`: Explicit recovery window to use.
|
|
182
|
+
* - `forceDeleteWithoutRecovery`: Dangerous: delete without recovery.
|
|
183
|
+
*
|
|
184
|
+
* @throws If both `recoveryWindowInDays` and `forceDeleteWithoutRecovery` are provided.
|
|
185
|
+
*/
|
|
186
|
+
deleteSecret(opts: {
|
|
187
|
+
secretId: string;
|
|
188
|
+
recoveryWindowInDays?: number;
|
|
189
|
+
forceDeleteWithoutRecovery?: boolean;
|
|
190
|
+
}): Promise<void>;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Requirements addressed:
|
|
195
|
+
* - Provide get-dotenv plugin mounted as `aws secrets` with commands:
|
|
196
|
+
* - `aws secrets pull`
|
|
197
|
+
* - `aws secrets push`
|
|
198
|
+
* - `aws secrets delete`
|
|
199
|
+
* - Keep the plugin adapter thin: command registration is decomposed into
|
|
200
|
+
* dedicated modules; core behavior lives outside this file.
|
|
201
|
+
* - For config-backed plugin options, register dynamic options on the command
|
|
202
|
+
* so help reflects composed defaults and option parsing is typed.
|
|
203
|
+
*/
|
|
204
|
+
/**
|
|
205
|
+
* get-dotenv plugin that provides `aws secrets pull|push|delete`.
|
|
206
|
+
*
|
|
207
|
+
* Intended usage: mount under `awsPlugin().use(secretsPlugin())`.
|
|
208
|
+
*/
|
|
209
|
+
declare const secretsPlugin: () => _karmaniverous_get_dotenv_cliHost.PluginWithInstanceHelpers<Omit<{
|
|
210
|
+
logger: unknown;
|
|
211
|
+
defaultEnv?: string | undefined;
|
|
212
|
+
dotenvToken?: string | undefined;
|
|
213
|
+
dynamicPath?: string | undefined;
|
|
214
|
+
dynamic?: Record<string, unknown> | undefined;
|
|
215
|
+
env?: string | undefined;
|
|
216
|
+
excludeDynamic?: boolean | undefined;
|
|
217
|
+
excludeEnv?: boolean | undefined;
|
|
218
|
+
excludeGlobal?: boolean | undefined;
|
|
219
|
+
excludePrivate?: boolean | undefined;
|
|
220
|
+
excludePublic?: boolean | undefined;
|
|
221
|
+
loadProcess?: boolean | undefined;
|
|
222
|
+
log?: boolean | undefined;
|
|
223
|
+
outputPath?: string | undefined;
|
|
224
|
+
paths?: string[] | undefined;
|
|
225
|
+
privateToken?: string | undefined;
|
|
226
|
+
vars?: Record<string, string | undefined> | undefined;
|
|
227
|
+
}, "dynamic" | "logger"> & {
|
|
228
|
+
logger: Record<string, (...args: unknown[]) => void> | Console;
|
|
229
|
+
dynamic?: {
|
|
230
|
+
[x: string]: string | ((vars: {
|
|
231
|
+
[x: string]: string | undefined;
|
|
232
|
+
}, env: string | undefined) => string | undefined) | undefined;
|
|
233
|
+
};
|
|
234
|
+
}, {
|
|
235
|
+
secretName?: string | undefined;
|
|
236
|
+
templateExtension?: string | undefined;
|
|
237
|
+
push?: {
|
|
238
|
+
from?: string[] | undefined;
|
|
239
|
+
include?: string[] | undefined;
|
|
240
|
+
exclude?: string[] | undefined;
|
|
241
|
+
} | undefined;
|
|
242
|
+
pull?: {
|
|
243
|
+
to?: string | undefined;
|
|
244
|
+
include?: string[] | undefined;
|
|
245
|
+
exclude?: string[] | undefined;
|
|
246
|
+
} | undefined;
|
|
247
|
+
}, [], {}, {}>;
|
|
248
|
+
|
|
249
|
+
export { AwsSecretsManagerTools, secretsPlugin };
|
|
250
|
+
export type { AwsSecretsManagerToolsInitOptions, AwsSecretsManagerToolsLogger, AwsSecretsManagerToolsXrayMode, EnvSecretMap, XrayState };
|