@grow-codes/aws-secrets-manager 0.0.0-stage → 0.1.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/LICENSE +202 -0
- package/NOTICE +115 -0
- package/README.md +33 -2
- package/lib/base-ClUDmFU5.d.cts +213 -0
- package/lib/base-ClUDmFU5.d.ts +213 -0
- package/lib/chunk-FGY6NSRU.js +822 -0
- package/lib/chunk-FGY6NSRU.js.map +1 -0
- package/lib/chunk-ZLYHN4AI.cjs +868 -0
- package/lib/chunk-ZLYHN4AI.cjs.map +1 -0
- package/lib/index.cjs +2964 -0
- package/lib/index.cjs.map +1 -0
- package/lib/index.d.cts +1424 -0
- package/lib/index.d.ts +1424 -0
- package/lib/index.js +2721 -0
- package/lib/index.js.map +1 -0
- package/lib/testing/index.cjs +678 -0
- package/lib/testing/index.cjs.map +1 -0
- package/lib/testing/index.d.cts +265 -0
- package/lib/testing/index.d.ts +265 -0
- package/lib/testing/index.js +655 -0
- package/lib/testing/index.js.map +1 -0
- package/package.json +100 -4
package/lib/index.cjs
ADDED
|
@@ -0,0 +1,2964 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkZLYHN4AI_cjs = require('./chunk-ZLYHN4AI.cjs');
|
|
4
|
+
var fs = require('fs');
|
|
5
|
+
var undici = require('undici');
|
|
6
|
+
var clientSecretsManager = require('@aws-sdk/client-secrets-manager');
|
|
7
|
+
var credentialProviders = require('@aws-sdk/credential-providers');
|
|
8
|
+
|
|
9
|
+
// src/core/health.ts
|
|
10
|
+
var HEALTHY_WORDS = /* @__PURE__ */ new Set([
|
|
11
|
+
"ok",
|
|
12
|
+
"up",
|
|
13
|
+
"healthy",
|
|
14
|
+
"pass",
|
|
15
|
+
"passing",
|
|
16
|
+
"green",
|
|
17
|
+
"ready",
|
|
18
|
+
"available",
|
|
19
|
+
"running",
|
|
20
|
+
"serving"
|
|
21
|
+
]);
|
|
22
|
+
function isHealthyWord(status) {
|
|
23
|
+
return HEALTHY_WORDS.has(status.trim().toLowerCase());
|
|
24
|
+
}
|
|
25
|
+
function healthStatus(status, details = {}, healthy = isHealthyWord(status)) {
|
|
26
|
+
const flat = {};
|
|
27
|
+
for (const [k, v] of Object.entries(details)) {
|
|
28
|
+
if (v === void 0 || v === null) continue;
|
|
29
|
+
if (typeof v === "string") flat[k] = v;
|
|
30
|
+
else if (typeof v === "number" || typeof v === "boolean" || typeof v === "bigint")
|
|
31
|
+
flat[k] = String(v);
|
|
32
|
+
else if (typeof v === "object") flat[k] = JSON.stringify(v);
|
|
33
|
+
}
|
|
34
|
+
return { healthy, status, details: flat };
|
|
35
|
+
}
|
|
36
|
+
async function probeHealth(probe) {
|
|
37
|
+
try {
|
|
38
|
+
return await probe();
|
|
39
|
+
} catch (err) {
|
|
40
|
+
if (err instanceof chunkZLYHN4AI_cjs.AwsSecretsManagerError) {
|
|
41
|
+
if (err.code === chunkZLYHN4AI_cjs.ErrorCode.Cancelled || err.code === chunkZLYHN4AI_cjs.ErrorCode.Config) throw err;
|
|
42
|
+
if (err.httpStatus !== void 0) {
|
|
43
|
+
return healthStatus("unhealthy", { httpStatus: err.httpStatus, error: err.code }, false);
|
|
44
|
+
}
|
|
45
|
+
return healthStatus("unreachable", { error: err.code }, false);
|
|
46
|
+
}
|
|
47
|
+
return healthStatus("unreachable", { error: chunkZLYHN4AI_cjs.ErrorCode.Unavailable }, false);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// src/core/hooks.ts
|
|
52
|
+
var silentLogger = Object.freeze({
|
|
53
|
+
debug: () => void 0,
|
|
54
|
+
info: () => void 0,
|
|
55
|
+
warn: () => void 0,
|
|
56
|
+
error: () => void 0
|
|
57
|
+
});
|
|
58
|
+
function safeCall(fn, ...args) {
|
|
59
|
+
if (fn === void 0) return;
|
|
60
|
+
try {
|
|
61
|
+
const result = fn(...args);
|
|
62
|
+
if (result instanceof Promise) result.catch(() => void 0);
|
|
63
|
+
} catch {
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
function safeLogger(logger) {
|
|
67
|
+
if (logger === void 0) return silentLogger;
|
|
68
|
+
return {
|
|
69
|
+
debug: (m, f) => {
|
|
70
|
+
safeCall(
|
|
71
|
+
(a, b) => {
|
|
72
|
+
logger.debug(a, b);
|
|
73
|
+
},
|
|
74
|
+
m,
|
|
75
|
+
f
|
|
76
|
+
);
|
|
77
|
+
},
|
|
78
|
+
info: (m, f) => {
|
|
79
|
+
safeCall(
|
|
80
|
+
(a, b) => {
|
|
81
|
+
logger.info(a, b);
|
|
82
|
+
},
|
|
83
|
+
m,
|
|
84
|
+
f
|
|
85
|
+
);
|
|
86
|
+
},
|
|
87
|
+
warn: (m, f) => {
|
|
88
|
+
safeCall(
|
|
89
|
+
(a, b) => {
|
|
90
|
+
logger.warn(a, b);
|
|
91
|
+
},
|
|
92
|
+
m,
|
|
93
|
+
f
|
|
94
|
+
);
|
|
95
|
+
},
|
|
96
|
+
error: (m, f) => {
|
|
97
|
+
safeCall(
|
|
98
|
+
(a, b) => {
|
|
99
|
+
logger.error(a, b);
|
|
100
|
+
},
|
|
101
|
+
m,
|
|
102
|
+
f
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// src/core/retry.ts
|
|
109
|
+
var RetryPolicy = class _RetryPolicy {
|
|
110
|
+
static DEFAULTS = Object.freeze({
|
|
111
|
+
maxRetries: 3,
|
|
112
|
+
initialBackoffMs: 100,
|
|
113
|
+
maxBackoffMs: 1e4,
|
|
114
|
+
multiplier: 2,
|
|
115
|
+
maxRetryAfterMs: 6e4
|
|
116
|
+
});
|
|
117
|
+
maxRetries;
|
|
118
|
+
initialBackoffMs;
|
|
119
|
+
maxBackoffMs;
|
|
120
|
+
multiplier;
|
|
121
|
+
maxRetryAfterMs;
|
|
122
|
+
random;
|
|
123
|
+
constructor(options = {}) {
|
|
124
|
+
const d = _RetryPolicy.DEFAULTS;
|
|
125
|
+
this.maxRetries = options.maxRetries ?? d.maxRetries;
|
|
126
|
+
this.initialBackoffMs = options.initialBackoffMs ?? d.initialBackoffMs;
|
|
127
|
+
this.maxBackoffMs = options.maxBackoffMs ?? d.maxBackoffMs;
|
|
128
|
+
this.multiplier = options.multiplier ?? d.multiplier;
|
|
129
|
+
this.maxRetryAfterMs = options.maxRetryAfterMs ?? d.maxRetryAfterMs;
|
|
130
|
+
this.random = options.random ?? Math.random;
|
|
131
|
+
Object.freeze(this);
|
|
132
|
+
}
|
|
133
|
+
/** Returns a policy from options, keeping an existing instance as is. */
|
|
134
|
+
static from(value) {
|
|
135
|
+
return value instanceof _RetryPolicy ? value : new _RetryPolicy(value);
|
|
136
|
+
}
|
|
137
|
+
/** Upper bound of the backoff before retry `n` (0-based): `min(max, initial * multiplier^n)`. */
|
|
138
|
+
backoffCapMs(retry) {
|
|
139
|
+
return Math.min(this.maxBackoffMs, this.initialBackoffMs * this.multiplier ** retry);
|
|
140
|
+
}
|
|
141
|
+
/** Full-jitter backoff before retry `n` (0-based): `random(0, backoffCapMs(n))`. */
|
|
142
|
+
backoffMs(retry) {
|
|
143
|
+
return this.random() * this.backoffCapMs(retry);
|
|
144
|
+
}
|
|
145
|
+
/** Validation problems (empty when valid). */
|
|
146
|
+
problems() {
|
|
147
|
+
const out = [];
|
|
148
|
+
if (!Number.isInteger(this.maxRetries) || this.maxRetries < 0)
|
|
149
|
+
out.push("retry.maxRetries must be an integer >= 0");
|
|
150
|
+
if (!(this.initialBackoffMs >= 0)) out.push("retry.initialBackoffMs must be >= 0");
|
|
151
|
+
if (!(this.maxBackoffMs >= 0)) out.push("retry.maxBackoffMs must be >= 0");
|
|
152
|
+
if (!(this.multiplier >= 1)) out.push("retry.multiplier must be >= 1");
|
|
153
|
+
if (!(this.maxRetryAfterMs >= 0)) out.push("retry.maxRetryAfterMs must be >= 0");
|
|
154
|
+
return out;
|
|
155
|
+
}
|
|
156
|
+
toJSON() {
|
|
157
|
+
return {
|
|
158
|
+
maxRetries: this.maxRetries,
|
|
159
|
+
initialBackoffMs: this.initialBackoffMs,
|
|
160
|
+
maxBackoffMs: this.maxBackoffMs,
|
|
161
|
+
multiplier: this.multiplier,
|
|
162
|
+
maxRetryAfterMs: this.maxRetryAfterMs
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
function parseRetryAfter(value, now = Date.now()) {
|
|
167
|
+
if (value === null || value === void 0) return void 0;
|
|
168
|
+
const text = value.trim();
|
|
169
|
+
if (text === "") return void 0;
|
|
170
|
+
if (/^\d+(\.\d+)?$/.test(text)) return Math.round(Number(text) * 1e3);
|
|
171
|
+
if (!/[a-z]/i.test(text)) return void 0;
|
|
172
|
+
const at = Date.parse(text);
|
|
173
|
+
if (Number.isNaN(at)) return void 0;
|
|
174
|
+
return Math.max(0, at - now);
|
|
175
|
+
}
|
|
176
|
+
var IDEMPOTENT_METHODS = /* @__PURE__ */ new Set([
|
|
177
|
+
"GET",
|
|
178
|
+
"HEAD",
|
|
179
|
+
"OPTIONS",
|
|
180
|
+
"PUT",
|
|
181
|
+
"DELETE"
|
|
182
|
+
]);
|
|
183
|
+
function isIdempotentMethod(method) {
|
|
184
|
+
return IDEMPOTENT_METHODS.has(method.toUpperCase());
|
|
185
|
+
}
|
|
186
|
+
function isRetryableStatus(status, idempotent) {
|
|
187
|
+
if (status === 429) return true;
|
|
188
|
+
if (!idempotent) return false;
|
|
189
|
+
return status === 408 || status === 500 || status === 502 || status === 503 || status === 504;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// src/core/options.ts
|
|
193
|
+
var DEFAULT_TIMEOUTS = Object.freeze({
|
|
194
|
+
connectTimeoutMs: 1e4,
|
|
195
|
+
requestTimeoutMs: 3e4,
|
|
196
|
+
totalTimeoutMs: 12e4
|
|
197
|
+
});
|
|
198
|
+
function resolveCommonConfig(options, defaultUrl) {
|
|
199
|
+
const out = {
|
|
200
|
+
url: options.url ?? defaultUrl,
|
|
201
|
+
connectTimeoutMs: options.connectTimeoutMs ?? DEFAULT_TIMEOUTS.connectTimeoutMs,
|
|
202
|
+
requestTimeoutMs: options.requestTimeoutMs ?? DEFAULT_TIMEOUTS.requestTimeoutMs,
|
|
203
|
+
totalTimeoutMs: options.totalTimeoutMs ?? DEFAULT_TIMEOUTS.totalTimeoutMs,
|
|
204
|
+
retry: RetryPolicy.from(options.retry),
|
|
205
|
+
tls: Object.freeze({ ...options.tls }),
|
|
206
|
+
headers: Object.freeze({ ...options.headers })
|
|
207
|
+
};
|
|
208
|
+
if (options.proxy !== void 0) out.proxy = options.proxy;
|
|
209
|
+
if (options.userAgentSuffix !== void 0) out.userAgentSuffix = options.userAgentSuffix;
|
|
210
|
+
if (options.hooks !== void 0) out.hooks = options.hooks;
|
|
211
|
+
if (options.logger !== void 0) out.logger = options.logger;
|
|
212
|
+
return out;
|
|
213
|
+
}
|
|
214
|
+
function isHttpUrl(value) {
|
|
215
|
+
try {
|
|
216
|
+
const u = new URL(value);
|
|
217
|
+
return u.protocol === "http:" || u.protocol === "https:";
|
|
218
|
+
} catch {
|
|
219
|
+
return false;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
function validateCommonConfig(config) {
|
|
223
|
+
const problems = [];
|
|
224
|
+
if (!isHttpUrl(config.url)) problems.push("url must be an http or https URL");
|
|
225
|
+
for (const key of ["connectTimeoutMs", "requestTimeoutMs", "totalTimeoutMs"]) {
|
|
226
|
+
const v = config[key];
|
|
227
|
+
if (!Number.isFinite(v) || v <= 0) problems.push(`${key} must be a positive number`);
|
|
228
|
+
}
|
|
229
|
+
problems.push(...config.retry.problems());
|
|
230
|
+
const tls = config.tls;
|
|
231
|
+
if (tls.clientCertPath === void 0 !== (tls.clientKeyPath === void 0)) {
|
|
232
|
+
problems.push("tls.clientCertPath and tls.clientKeyPath must be given together");
|
|
233
|
+
}
|
|
234
|
+
if (config.proxy !== void 0 && !isHttpUrl(config.proxy)) {
|
|
235
|
+
problems.push("proxy must be an http or https URL");
|
|
236
|
+
}
|
|
237
|
+
if (problems.length > 0) throw new chunkZLYHN4AI_cjs.ConfigError(`invalid configuration: ${problems.join("; ")}`);
|
|
238
|
+
}
|
|
239
|
+
function readCommonEnv(reader, vendor = {}) {
|
|
240
|
+
const out = {};
|
|
241
|
+
const url = reader.string("URL", vendor.url);
|
|
242
|
+
if (url !== void 0) out.url = url;
|
|
243
|
+
const connect = reader.duration("CONNECT_TIMEOUT");
|
|
244
|
+
if (connect !== void 0) out.connectTimeoutMs = connect;
|
|
245
|
+
const request = reader.duration("REQUEST_TIMEOUT");
|
|
246
|
+
if (request !== void 0) out.requestTimeoutMs = request;
|
|
247
|
+
const total = reader.duration("TOTAL_TIMEOUT");
|
|
248
|
+
if (total !== void 0) out.totalTimeoutMs = total;
|
|
249
|
+
const maxRetries = reader.int("MAX_RETRIES");
|
|
250
|
+
if (maxRetries !== void 0) out.retry = { maxRetries };
|
|
251
|
+
const tls = {};
|
|
252
|
+
const ca = reader.string("CA_CERT", vendor.caCert);
|
|
253
|
+
if (ca !== void 0) tls.caCertPath = ca;
|
|
254
|
+
const cert = reader.string("CLIENT_CERT", vendor.clientCert);
|
|
255
|
+
if (cert !== void 0) tls.clientCertPath = cert;
|
|
256
|
+
const key = reader.string("CLIENT_KEY", vendor.clientKey);
|
|
257
|
+
if (key !== void 0) tls.clientKeyPath = key;
|
|
258
|
+
const insecure = reader.bool("INSECURE_SKIP_VERIFY", vendor.insecureSkipVerify);
|
|
259
|
+
if (insecure !== void 0) tls.insecureSkipVerify = insecure;
|
|
260
|
+
if (Object.keys(tls).length > 0) out.tls = tls;
|
|
261
|
+
const proxy = reader.string("PROXY", vendor.proxy);
|
|
262
|
+
if (proxy !== void 0) out.proxy = proxy;
|
|
263
|
+
return out;
|
|
264
|
+
}
|
|
265
|
+
function definedOnly(value) {
|
|
266
|
+
const out = {};
|
|
267
|
+
for (const [k, v] of Object.entries(value)) {
|
|
268
|
+
if (v !== void 0) out[k] = v;
|
|
269
|
+
}
|
|
270
|
+
return out;
|
|
271
|
+
}
|
|
272
|
+
function mergeOptions(...layers) {
|
|
273
|
+
const out = {};
|
|
274
|
+
for (const layer of layers) {
|
|
275
|
+
if (layer === void 0) continue;
|
|
276
|
+
for (const [k, v] of Object.entries(definedOnly(layer))) {
|
|
277
|
+
const prev = out[k];
|
|
278
|
+
if ((k === "tls" || k === "headers" || k === "retry" && !(v instanceof RetryPolicy)) && typeof prev === "object" && prev !== null) {
|
|
279
|
+
const base = prev instanceof RetryPolicy ? prev.toJSON() : prev;
|
|
280
|
+
out[k] = { ...base, ...definedOnly(v) };
|
|
281
|
+
} else {
|
|
282
|
+
out[k] = v;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
return out;
|
|
287
|
+
}
|
|
288
|
+
function describeCommonConfig(config) {
|
|
289
|
+
const headers = {};
|
|
290
|
+
for (const k of Object.keys(config.headers)) headers[k] = chunkZLYHN4AI_cjs.REDACTED;
|
|
291
|
+
const out = {
|
|
292
|
+
url: chunkZLYHN4AI_cjs.redactUrl(config.url),
|
|
293
|
+
connectTimeoutMs: config.connectTimeoutMs,
|
|
294
|
+
requestTimeoutMs: config.requestTimeoutMs,
|
|
295
|
+
totalTimeoutMs: config.totalTimeoutMs,
|
|
296
|
+
retry: config.retry.toJSON(),
|
|
297
|
+
tls: {
|
|
298
|
+
...config.tls,
|
|
299
|
+
...config.tls.caCertPem === void 0 ? {} : { caCertPem: chunkZLYHN4AI_cjs.REDACTED }
|
|
300
|
+
},
|
|
301
|
+
headers
|
|
302
|
+
};
|
|
303
|
+
if (config.proxy !== void 0) out.proxy = chunkZLYHN4AI_cjs.redactUrl(config.proxy);
|
|
304
|
+
if (config.userAgentSuffix !== void 0) out.userAgentSuffix = config.userAgentSuffix;
|
|
305
|
+
return out;
|
|
306
|
+
}
|
|
307
|
+
function secretValues(...values) {
|
|
308
|
+
return values.filter((v) => v instanceof chunkZLYHN4AI_cjs.Secret).map((s) => s.reveal());
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
// src/core/version.ts
|
|
312
|
+
var SDK_VERSION = "0.1.1";
|
|
313
|
+
var PACKAGE_KEY = "aws-secrets-manager";
|
|
314
|
+
var LANGUAGE = "typescript";
|
|
315
|
+
var SDK_KIT_VERSION = "0.3.0";
|
|
316
|
+
|
|
317
|
+
// src/core/transport.ts
|
|
318
|
+
var DEFAULT_REQUEST_ID_HEADERS = [
|
|
319
|
+
"x-request-id",
|
|
320
|
+
"x-amzn-requestid",
|
|
321
|
+
"x-amz-request-id",
|
|
322
|
+
"x-datadog-request-id",
|
|
323
|
+
"request-id",
|
|
324
|
+
"x-correlation-id"
|
|
325
|
+
];
|
|
326
|
+
var MAX_VENDOR_TEXT = 300;
|
|
327
|
+
var PRE_SEND_CODES = /* @__PURE__ */ new Set([
|
|
328
|
+
"ECONNREFUSED",
|
|
329
|
+
"ENOTFOUND",
|
|
330
|
+
"EAI_AGAIN",
|
|
331
|
+
"EHOSTUNREACH",
|
|
332
|
+
"ENETUNREACH",
|
|
333
|
+
"EADDRNOTAVAIL",
|
|
334
|
+
"UND_ERR_CONNECT_TIMEOUT"
|
|
335
|
+
]);
|
|
336
|
+
var TLS_CODE = /CERT|SELF_SIGNED|UNABLE_TO_|ERR_TLS|ERR_SSL|DEPTH_ZERO/;
|
|
337
|
+
var CANCEL = /* @__PURE__ */ Symbol("cancel");
|
|
338
|
+
var ATTEMPT_TIMEOUT = /* @__PURE__ */ Symbol("attempt-timeout");
|
|
339
|
+
var insecureWarned = false;
|
|
340
|
+
var AbortedAttempt = class extends Error {
|
|
341
|
+
kind;
|
|
342
|
+
constructor(kind) {
|
|
343
|
+
super("aborted");
|
|
344
|
+
this.kind = kind;
|
|
345
|
+
}
|
|
346
|
+
};
|
|
347
|
+
function errorCode(err) {
|
|
348
|
+
let current = err;
|
|
349
|
+
for (let depth = 0; depth < 5 && current !== void 0 && current !== null; depth++) {
|
|
350
|
+
const code = current.code;
|
|
351
|
+
if (typeof code === "string") return code;
|
|
352
|
+
current = current.cause;
|
|
353
|
+
}
|
|
354
|
+
return void 0;
|
|
355
|
+
}
|
|
356
|
+
function readPem(path) {
|
|
357
|
+
return path === void 0 ? void 0 : fs.readFileSync(path, "utf8");
|
|
358
|
+
}
|
|
359
|
+
function createDispatcher(config, logger = safeLogger(config.logger)) {
|
|
360
|
+
const tls = config.tls;
|
|
361
|
+
if (tls.insecureSkipVerify === true && !insecureWarned) {
|
|
362
|
+
insecureWarned = true;
|
|
363
|
+
logger.warn("TLS certificate verification is disabled (insecureSkipVerify); use only in tests");
|
|
364
|
+
}
|
|
365
|
+
const caParts = [tls.caCertPem, readPem(tls.caCertPath)].filter(
|
|
366
|
+
(v) => v !== void 0
|
|
367
|
+
);
|
|
368
|
+
const tlsOptions = {
|
|
369
|
+
timeout: config.connectTimeoutMs,
|
|
370
|
+
rejectUnauthorized: tls.insecureSkipVerify !== true,
|
|
371
|
+
...caParts.length > 0 ? { ca: caParts } : {},
|
|
372
|
+
...tls.clientCertPath === void 0 ? {} : { cert: readPem(tls.clientCertPath) },
|
|
373
|
+
...tls.clientKeyPath === void 0 ? {} : { key: readPem(tls.clientKeyPath) }
|
|
374
|
+
};
|
|
375
|
+
if (config.proxy !== void 0) {
|
|
376
|
+
return new undici.ProxyAgent({
|
|
377
|
+
uri: config.proxy,
|
|
378
|
+
connect: { timeout: config.connectTimeoutMs },
|
|
379
|
+
requestTls: tlsOptions
|
|
380
|
+
});
|
|
381
|
+
}
|
|
382
|
+
return new undici.Agent({ connect: tlsOptions });
|
|
383
|
+
}
|
|
384
|
+
var HttpTransport = class {
|
|
385
|
+
/** `grow-codes-<key>/<version> (typescript)[ <suffix>]`. */
|
|
386
|
+
userAgent;
|
|
387
|
+
retry;
|
|
388
|
+
#config;
|
|
389
|
+
#options;
|
|
390
|
+
#logger;
|
|
391
|
+
#hooks;
|
|
392
|
+
#fetch;
|
|
393
|
+
#sleep;
|
|
394
|
+
#now;
|
|
395
|
+
#requestIdHeaders;
|
|
396
|
+
#dispatcher;
|
|
397
|
+
#closed = false;
|
|
398
|
+
constructor(options) {
|
|
399
|
+
this.#options = options;
|
|
400
|
+
this.#config = options.config;
|
|
401
|
+
this.retry = options.config.retry;
|
|
402
|
+
this.#logger = safeLogger(options.config.logger);
|
|
403
|
+
this.#hooks = options.config.hooks ?? {};
|
|
404
|
+
this.#fetch = undici.fetch;
|
|
405
|
+
this.#sleep = options.sleep ?? chunkZLYHN4AI_cjs.sleep;
|
|
406
|
+
this.#now = options.now ?? Date.now;
|
|
407
|
+
this.#requestIdHeaders = options.requestIdHeaders ?? DEFAULT_REQUEST_ID_HEADERS;
|
|
408
|
+
this.#dispatcher = options.dispatcher;
|
|
409
|
+
const suffix = options.config.userAgentSuffix;
|
|
410
|
+
this.userAgent = `grow-codes-${PACKAGE_KEY}/${SDK_VERSION} (${LANGUAGE})` + (suffix !== void 0 && suffix !== "" ? ` ${suffix}` : "");
|
|
411
|
+
}
|
|
412
|
+
/** Whether {@link close} was called. */
|
|
413
|
+
get closed() {
|
|
414
|
+
return this.#closed;
|
|
415
|
+
}
|
|
416
|
+
/**
|
|
417
|
+
* Throws `CancelledError` (`"<operation>: client is closed"`, not retryable) once {@link close}
|
|
418
|
+
* was called (SPEC §2.4). Requests check this themselves; service methods that send no request
|
|
419
|
+
* (cached reads, local helpers) call it first.
|
|
420
|
+
*/
|
|
421
|
+
ensureOpen(operation) {
|
|
422
|
+
if (this.#closed) throw new chunkZLYHN4AI_cjs.CancelledError(`${operation}: client is closed`);
|
|
423
|
+
}
|
|
424
|
+
/** Builds the absolute URL for a path and query. */
|
|
425
|
+
buildUrl(path, query) {
|
|
426
|
+
let url;
|
|
427
|
+
if (/^https?:\/\//i.test(path)) {
|
|
428
|
+
url = new URL(path);
|
|
429
|
+
} else {
|
|
430
|
+
const base = this.#config.url.endsWith("/") ? this.#config.url : this.#config.url + "/";
|
|
431
|
+
url = new URL(path.replace(/^\/+/, ""), base);
|
|
432
|
+
}
|
|
433
|
+
for (const [k, v] of Object.entries(query ?? {})) {
|
|
434
|
+
if (v === void 0 || v === null) continue;
|
|
435
|
+
if (Array.isArray(v)) {
|
|
436
|
+
for (const item of v)
|
|
437
|
+
url.searchParams.append(k, String(item));
|
|
438
|
+
} else {
|
|
439
|
+
url.searchParams.append(k, String(v));
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
return url;
|
|
443
|
+
}
|
|
444
|
+
/** Redacts known secrets from a text (error messages, vendor text). */
|
|
445
|
+
redact(text) {
|
|
446
|
+
return chunkZLYHN4AI_cjs.redactText(text, this.#knownSecrets());
|
|
447
|
+
}
|
|
448
|
+
#knownSecrets() {
|
|
449
|
+
return [...this.#options.knownSecrets?.() ?? []];
|
|
450
|
+
}
|
|
451
|
+
#getDispatcher() {
|
|
452
|
+
this.#dispatcher ??= createDispatcher(this.#config, this.#logger);
|
|
453
|
+
return this.#dispatcher;
|
|
454
|
+
}
|
|
455
|
+
/** `GET` shortcut. */
|
|
456
|
+
get(path, options = {}) {
|
|
457
|
+
return this.request({ ...options, method: "GET", path });
|
|
458
|
+
}
|
|
459
|
+
/** `POST` shortcut. */
|
|
460
|
+
post(path, options = {}) {
|
|
461
|
+
return this.request({ ...options, method: "POST", path });
|
|
462
|
+
}
|
|
463
|
+
/** `PUT` shortcut. */
|
|
464
|
+
put(path, options = {}) {
|
|
465
|
+
return this.request({ ...options, method: "PUT", path });
|
|
466
|
+
}
|
|
467
|
+
/** `DELETE` shortcut. */
|
|
468
|
+
delete(path, options = {}) {
|
|
469
|
+
return this.request({ ...options, method: "DELETE", path });
|
|
470
|
+
}
|
|
471
|
+
/**
|
|
472
|
+
* Sends a request with retries; throws an SDK error on failure. Every error message passes
|
|
473
|
+
* through {@link redact} with the known secrets.
|
|
474
|
+
*/
|
|
475
|
+
async request(options) {
|
|
476
|
+
try {
|
|
477
|
+
return await this.#request(options);
|
|
478
|
+
} catch (err) {
|
|
479
|
+
if (err instanceof chunkZLYHN4AI_cjs.AwsSecretsManagerError) err.message = this.redact(err.message);
|
|
480
|
+
throw err;
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
async #request(options) {
|
|
484
|
+
const method = (options.method ?? "GET").toUpperCase();
|
|
485
|
+
const operation = options.operation ?? `${method} ${options.path.split("?")[0] ?? ""}`;
|
|
486
|
+
this.ensureOpen(operation);
|
|
487
|
+
const signal = options.signal;
|
|
488
|
+
if (signal?.aborted === true) throw new chunkZLYHN4AI_cjs.CancelledError(`${operation}: cancelled`);
|
|
489
|
+
const url = this.buildUrl(options.path, options.query);
|
|
490
|
+
const safeUrl = chunkZLYHN4AI_cjs.redactUrl(url);
|
|
491
|
+
const headers = this.#buildHeaders(options);
|
|
492
|
+
const body = options.json !== void 0 ? JSON.stringify(options.json) : options.body;
|
|
493
|
+
const idempotent = options.idempotent ?? isIdempotentMethod(method);
|
|
494
|
+
const requestTimeout = options.requestTimeoutMs ?? this.#config.requestTimeoutMs;
|
|
495
|
+
const totalTimeout = options.totalTimeoutMs ?? this.#config.totalTimeoutMs;
|
|
496
|
+
const start = this.#now();
|
|
497
|
+
const deadline = start + totalTimeout;
|
|
498
|
+
const policy = this.retry;
|
|
499
|
+
for (let attempt = 1; ; attempt++) {
|
|
500
|
+
const remaining = deadline - this.#now();
|
|
501
|
+
if (remaining <= 0) {
|
|
502
|
+
throw new chunkZLYHN4AI_cjs.TimeoutError(`${operation}: total timeout of ${totalTimeout} ms exceeded`);
|
|
503
|
+
}
|
|
504
|
+
const attemptTimeout = Math.min(requestTimeout, remaining);
|
|
505
|
+
const isTotal = attemptTimeout < requestTimeout;
|
|
506
|
+
safeCall(this.#hooks.onRequest, {
|
|
507
|
+
method,
|
|
508
|
+
url: safeUrl,
|
|
509
|
+
headers: chunkZLYHN4AI_cjs.redactHeaders(headers),
|
|
510
|
+
attempt
|
|
511
|
+
});
|
|
512
|
+
this.#logger.debug("http request", { method, url: safeUrl, attempt });
|
|
513
|
+
const attemptStart = this.#now();
|
|
514
|
+
let failure;
|
|
515
|
+
let willRetry = false;
|
|
516
|
+
let waitMs = 0;
|
|
517
|
+
try {
|
|
518
|
+
const res = await this.#attempt(
|
|
519
|
+
url,
|
|
520
|
+
method,
|
|
521
|
+
headers,
|
|
522
|
+
body,
|
|
523
|
+
attemptTimeout,
|
|
524
|
+
signal,
|
|
525
|
+
options.responseType ?? "json",
|
|
526
|
+
options.allowStatus ?? []
|
|
527
|
+
);
|
|
528
|
+
const durationMs = this.#now() - attemptStart;
|
|
529
|
+
const requestId = this.#requestId(res.headers);
|
|
530
|
+
safeCall(this.#hooks.onResponse, {
|
|
531
|
+
method,
|
|
532
|
+
url: safeUrl,
|
|
533
|
+
status: res.status,
|
|
534
|
+
durationMs,
|
|
535
|
+
attempt,
|
|
536
|
+
...requestId === void 0 ? {} : { requestId }
|
|
537
|
+
});
|
|
538
|
+
this.#logger.debug("http response", {
|
|
539
|
+
method,
|
|
540
|
+
url: safeUrl,
|
|
541
|
+
status: res.status,
|
|
542
|
+
durationMs,
|
|
543
|
+
attempt
|
|
544
|
+
});
|
|
545
|
+
if (res.status < 400 || options.allowStatus?.includes(res.status) === true) {
|
|
546
|
+
return {
|
|
547
|
+
status: res.status,
|
|
548
|
+
headers: res.headers,
|
|
549
|
+
data: res.data,
|
|
550
|
+
...requestId === void 0 ? {} : { requestId },
|
|
551
|
+
durationMs: this.#now() - start,
|
|
552
|
+
attempts: attempt,
|
|
553
|
+
...res.status >= 400 ? { text: res.text } : {}
|
|
554
|
+
};
|
|
555
|
+
}
|
|
556
|
+
const retryAfter = res.status === 429 || res.status === 503 ? parseRetryAfter(res.headers.get("retry-after"), this.#now()) : void 0;
|
|
557
|
+
const reason = this.vendorText(res.text);
|
|
558
|
+
const defaultError = chunkZLYHN4AI_cjs.errorForStatus(operation, res.status, {
|
|
559
|
+
...reason === void 0 ? {} : { reason },
|
|
560
|
+
...requestId === void 0 ? {} : { requestId },
|
|
561
|
+
...retryAfter === void 0 ? {} : { retryAfterMs: retryAfter }
|
|
562
|
+
});
|
|
563
|
+
const classified = this.#classifyResponse(options.classifyError, {
|
|
564
|
+
operation,
|
|
565
|
+
method,
|
|
566
|
+
status: res.status,
|
|
567
|
+
headers: res.headers,
|
|
568
|
+
body: res.text,
|
|
569
|
+
...reason === void 0 ? {} : { reason },
|
|
570
|
+
...requestId === void 0 ? {} : { requestId },
|
|
571
|
+
...retryAfter === void 0 ? {} : { retryAfterMs: retryAfter },
|
|
572
|
+
attempt,
|
|
573
|
+
defaultError
|
|
574
|
+
});
|
|
575
|
+
failure = classified ?? defaultError;
|
|
576
|
+
if (isRetryableStatus(res.status, idempotent) && (classified === void 0 || classified.retryable) && attempt <= policy.maxRetries) {
|
|
577
|
+
const backoff = policy.backoffMs(attempt - 1);
|
|
578
|
+
if (retryAfter !== void 0) {
|
|
579
|
+
if (retryAfter > policy.maxRetryAfterMs || retryAfter >= deadline - this.#now()) {
|
|
580
|
+
willRetry = false;
|
|
581
|
+
} else {
|
|
582
|
+
willRetry = true;
|
|
583
|
+
waitMs = Math.max(retryAfter, backoff);
|
|
584
|
+
}
|
|
585
|
+
} else {
|
|
586
|
+
willRetry = true;
|
|
587
|
+
waitMs = backoff;
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
} catch (err) {
|
|
591
|
+
failure = this.#classify(err, operation, attemptTimeout, isTotal, totalTimeout);
|
|
592
|
+
const preSend = PRE_SEND_CODES.has(errorCode(err) ?? "");
|
|
593
|
+
willRetry = failure.retryable && !(failure.code === "TIMEOUT" && isTotal) && (idempotent || preSend) && attempt <= policy.maxRetries;
|
|
594
|
+
waitMs = willRetry ? policy.backoffMs(attempt - 1) : 0;
|
|
595
|
+
}
|
|
596
|
+
if (willRetry && waitMs >= deadline - this.#now()) {
|
|
597
|
+
safeCall(this.#hooks.onError, {
|
|
598
|
+
method,
|
|
599
|
+
url: safeUrl,
|
|
600
|
+
error: failure,
|
|
601
|
+
attempt,
|
|
602
|
+
willRetry: false
|
|
603
|
+
});
|
|
604
|
+
throw new chunkZLYHN4AI_cjs.TimeoutError(
|
|
605
|
+
`${operation}: total timeout of ${totalTimeout} ms exceeded after ${attempt} attempts`,
|
|
606
|
+
{
|
|
607
|
+
cause: failure,
|
|
608
|
+
...failure.httpStatus === void 0 ? {} : { httpStatus: failure.httpStatus },
|
|
609
|
+
...failure.requestId === void 0 ? {} : { requestId: failure.requestId }
|
|
610
|
+
}
|
|
611
|
+
);
|
|
612
|
+
}
|
|
613
|
+
safeCall(this.#hooks.onError, { method, url: safeUrl, error: failure, attempt, willRetry });
|
|
614
|
+
if (!willRetry) {
|
|
615
|
+
this.#logger.debug("http call failed", {
|
|
616
|
+
method,
|
|
617
|
+
url: safeUrl,
|
|
618
|
+
attempt,
|
|
619
|
+
code: failure.code
|
|
620
|
+
});
|
|
621
|
+
throw failure;
|
|
622
|
+
}
|
|
623
|
+
this.#logger.warn("http call failed, retrying", {
|
|
624
|
+
method,
|
|
625
|
+
url: safeUrl,
|
|
626
|
+
attempt,
|
|
627
|
+
code: failure.code,
|
|
628
|
+
waitMs: Math.round(waitMs)
|
|
629
|
+
});
|
|
630
|
+
await this.#sleep(waitMs, signal).catch((err) => {
|
|
631
|
+
throw err instanceof chunkZLYHN4AI_cjs.AwsSecretsManagerError ? err : new chunkZLYHN4AI_cjs.CancelledError(`${operation}: cancelled`);
|
|
632
|
+
});
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
#buildHeaders(options) {
|
|
636
|
+
const headers = {
|
|
637
|
+
accept: "application/json",
|
|
638
|
+
"user-agent": this.userAgent
|
|
639
|
+
};
|
|
640
|
+
const layers = [
|
|
641
|
+
this.#config.headers,
|
|
642
|
+
this.#options.defaultHeaders?.() ?? {},
|
|
643
|
+
options.headers ?? {}
|
|
644
|
+
];
|
|
645
|
+
for (const layer of layers) {
|
|
646
|
+
for (const [k, v] of Object.entries(layer)) headers[k.toLowerCase()] = v;
|
|
647
|
+
}
|
|
648
|
+
if (options.json !== void 0 && headers["content-type"] === void 0) {
|
|
649
|
+
headers["content-type"] = "application/json";
|
|
650
|
+
}
|
|
651
|
+
return headers;
|
|
652
|
+
}
|
|
653
|
+
async #attempt(url, method, headers, body, timeoutMs, signal, responseType, allowStatus) {
|
|
654
|
+
const controller = new AbortController();
|
|
655
|
+
const timer = setTimeout(() => {
|
|
656
|
+
controller.abort(ATTEMPT_TIMEOUT);
|
|
657
|
+
}, timeoutMs);
|
|
658
|
+
timer.unref();
|
|
659
|
+
const onAbort = () => {
|
|
660
|
+
controller.abort(CANCEL);
|
|
661
|
+
};
|
|
662
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
663
|
+
try {
|
|
664
|
+
const init = {
|
|
665
|
+
method,
|
|
666
|
+
headers,
|
|
667
|
+
signal: controller.signal,
|
|
668
|
+
dispatcher: this.#getDispatcher(),
|
|
669
|
+
redirect: "follow"
|
|
670
|
+
};
|
|
671
|
+
if (body !== void 0) init.body = body;
|
|
672
|
+
const res = await this.#fetch(url, init);
|
|
673
|
+
const bytes = new Uint8Array(await res.arrayBuffer());
|
|
674
|
+
const isError = res.status >= 400;
|
|
675
|
+
const allowed = isError && allowStatus.includes(res.status);
|
|
676
|
+
const text = isError || responseType === "json" || responseType === "text" ? new TextDecoder().decode(bytes) : "";
|
|
677
|
+
let data;
|
|
678
|
+
if (isError && !allowed || responseType === "none") {
|
|
679
|
+
data = void 0;
|
|
680
|
+
} else if (responseType === "bytes") {
|
|
681
|
+
data = bytes;
|
|
682
|
+
} else if (responseType === "text") {
|
|
683
|
+
data = text;
|
|
684
|
+
} else if (allowed) {
|
|
685
|
+
data = parseJsonOrUndefined(text);
|
|
686
|
+
} else {
|
|
687
|
+
data = this.#parseJson(text, res.status);
|
|
688
|
+
}
|
|
689
|
+
return { status: res.status, headers: res.headers, data, text };
|
|
690
|
+
} catch (err) {
|
|
691
|
+
const reason = controller.signal.reason;
|
|
692
|
+
if (controller.signal.aborted && (reason === CANCEL || reason === ATTEMPT_TIMEOUT)) {
|
|
693
|
+
throw new AbortedAttempt(reason);
|
|
694
|
+
}
|
|
695
|
+
throw err;
|
|
696
|
+
} finally {
|
|
697
|
+
clearTimeout(timer);
|
|
698
|
+
signal?.removeEventListener("abort", onAbort);
|
|
699
|
+
}
|
|
700
|
+
}
|
|
701
|
+
#parseJson(text, status) {
|
|
702
|
+
if (text.trim() === "") return void 0;
|
|
703
|
+
try {
|
|
704
|
+
return JSON.parse(text);
|
|
705
|
+
} catch {
|
|
706
|
+
throw new chunkZLYHN4AI_cjs.UnavailableError(`invalid JSON in response (HTTP ${status})`, {
|
|
707
|
+
retryable: false,
|
|
708
|
+
httpStatus: status
|
|
709
|
+
});
|
|
710
|
+
}
|
|
711
|
+
}
|
|
712
|
+
#classify(err, operation, timeoutMs, isTotal, totalTimeout) {
|
|
713
|
+
if (err instanceof chunkZLYHN4AI_cjs.AwsSecretsManagerError) return err;
|
|
714
|
+
if (err instanceof AbortedAttempt) {
|
|
715
|
+
if (err.kind === CANCEL) return new chunkZLYHN4AI_cjs.CancelledError(`${operation}: cancelled`);
|
|
716
|
+
return isTotal ? new chunkZLYHN4AI_cjs.TimeoutError(`${operation}: total timeout of ${totalTimeout} ms exceeded`) : new chunkZLYHN4AI_cjs.TimeoutError(`${operation}: request timed out after ${timeoutMs} ms`);
|
|
717
|
+
}
|
|
718
|
+
const cause = chunkZLYHN4AI_cjs.redactError(err, this.#knownSecrets());
|
|
719
|
+
const code = errorCode(err);
|
|
720
|
+
if (code === "UND_ERR_CONNECT_TIMEOUT") {
|
|
721
|
+
return new chunkZLYHN4AI_cjs.TimeoutError(
|
|
722
|
+
`${operation}: connect timeout after ${this.#config.connectTimeoutMs} ms`,
|
|
723
|
+
{ cause }
|
|
724
|
+
);
|
|
725
|
+
}
|
|
726
|
+
if (code !== void 0 && TLS_CODE.test(code)) {
|
|
727
|
+
return new chunkZLYHN4AI_cjs.UnavailableError(`${operation}: TLS error (${code})`, { cause, retryable: false });
|
|
728
|
+
}
|
|
729
|
+
return new chunkZLYHN4AI_cjs.UnavailableError(
|
|
730
|
+
`${operation}: network error${code === void 0 ? "" : ` (${code})`}`,
|
|
731
|
+
{ cause }
|
|
732
|
+
);
|
|
733
|
+
}
|
|
734
|
+
#classifyResponse(perRequest, response) {
|
|
735
|
+
for (const classify of [perRequest, this.#options.classifyError]) {
|
|
736
|
+
if (classify === void 0) continue;
|
|
737
|
+
let mapped;
|
|
738
|
+
try {
|
|
739
|
+
mapped = classify(response);
|
|
740
|
+
} catch (err) {
|
|
741
|
+
mapped = err instanceof chunkZLYHN4AI_cjs.AwsSecretsManagerError ? err : void 0;
|
|
742
|
+
}
|
|
743
|
+
if (mapped instanceof chunkZLYHN4AI_cjs.AwsSecretsManagerError) return mapped;
|
|
744
|
+
}
|
|
745
|
+
return void 0;
|
|
746
|
+
}
|
|
747
|
+
/**
|
|
748
|
+
* Extracts the vendor error message from a response body (JSON `message`, `error`, … or plain
|
|
749
|
+
* text; HTML is ignored), collapses whitespace, trims, redacts secrets and truncates it to
|
|
750
|
+
* {@link MAX_VENDOR_TEXT} characters. Returns `undefined` when there is nothing useful.
|
|
751
|
+
*/
|
|
752
|
+
vendorText(text) {
|
|
753
|
+
const trimmed = text.trim();
|
|
754
|
+
if (trimmed === "") return void 0;
|
|
755
|
+
let extracted;
|
|
756
|
+
try {
|
|
757
|
+
extracted = extractMessage(JSON.parse(trimmed));
|
|
758
|
+
} catch {
|
|
759
|
+
extracted = /^\s*</.test(trimmed) ? void 0 : trimmed;
|
|
760
|
+
}
|
|
761
|
+
const collapsed = extracted?.replace(/\s+/g, " ").trim();
|
|
762
|
+
if (collapsed === void 0 || collapsed === "") return void 0;
|
|
763
|
+
const redacted = redactSecretsInText(this.redact(collapsed));
|
|
764
|
+
return redacted.length > MAX_VENDOR_TEXT ? redacted.slice(0, MAX_VENDOR_TEXT - 1).trimEnd() + "\u2026" : redacted;
|
|
765
|
+
}
|
|
766
|
+
#requestId(headers) {
|
|
767
|
+
for (const name of this.#requestIdHeaders) {
|
|
768
|
+
const v = headers.get(name);
|
|
769
|
+
if (v !== null && v !== "") return v;
|
|
770
|
+
}
|
|
771
|
+
return void 0;
|
|
772
|
+
}
|
|
773
|
+
/** Releases connections. Idempotent. */
|
|
774
|
+
async close() {
|
|
775
|
+
if (this.#closed) return;
|
|
776
|
+
this.#closed = true;
|
|
777
|
+
const dispatcher = this.#dispatcher;
|
|
778
|
+
this.#dispatcher = void 0;
|
|
779
|
+
if (dispatcher !== void 0 && this.#options.dispatcher === void 0) {
|
|
780
|
+
await dispatcher.close().catch(() => void 0);
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
};
|
|
784
|
+
function parseJsonOrUndefined(text) {
|
|
785
|
+
if (text.trim() === "") return void 0;
|
|
786
|
+
try {
|
|
787
|
+
return JSON.parse(text);
|
|
788
|
+
} catch {
|
|
789
|
+
return void 0;
|
|
790
|
+
}
|
|
791
|
+
}
|
|
792
|
+
function extractMessage(body) {
|
|
793
|
+
if (typeof body === "string") return body;
|
|
794
|
+
if (body === null || typeof body !== "object") return void 0;
|
|
795
|
+
if (Array.isArray(body)) return body.length > 0 ? extractMessage(body[0]) : void 0;
|
|
796
|
+
const obj = body;
|
|
797
|
+
for (const key of [
|
|
798
|
+
"message",
|
|
799
|
+
"error_description",
|
|
800
|
+
"error",
|
|
801
|
+
"errors",
|
|
802
|
+
"detail",
|
|
803
|
+
"msg",
|
|
804
|
+
"title",
|
|
805
|
+
"reason"
|
|
806
|
+
]) {
|
|
807
|
+
const found = extractMessage(obj[key]);
|
|
808
|
+
if (found !== void 0 && found !== "") return found;
|
|
809
|
+
}
|
|
810
|
+
return void 0;
|
|
811
|
+
}
|
|
812
|
+
var SECRET_ASSIGNMENT = /((?:password|passwd|secret|token|authorization|api[_-]?key|access[_-]?key|private[_-]?key|credential|session|signature)["']?\s*[:=]\s*["']?)([^"'\s,;&}]+)/gi;
|
|
813
|
+
var BEARER = /\b(bearer|basic)\s+[A-Za-z0-9._~+/=-]+/gi;
|
|
814
|
+
function redactSecretsInText(text) {
|
|
815
|
+
return text.replace(BEARER, "$1 [REDACTED]").replace(SECRET_ASSIGNMENT, "$1[REDACTED]");
|
|
816
|
+
}
|
|
817
|
+
|
|
818
|
+
// src/config.ts
|
|
819
|
+
var INSPECT = /* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom");
|
|
820
|
+
var DEFAULT_RECOVERY_WINDOW_DAYS = 30;
|
|
821
|
+
var DEFAULT_ROLE_SESSION_NAME = "grow-sdk";
|
|
822
|
+
var VENDOR_ENV = {
|
|
823
|
+
url: ["AWS_ENDPOINT_URL_SECRETS_MANAGER", "AWS_ENDPOINT_URL"],
|
|
824
|
+
region: ["AWS_REGION", "AWS_DEFAULT_REGION"],
|
|
825
|
+
accessKeyId: ["AWS_ACCESS_KEY_ID"],
|
|
826
|
+
secretAccessKey: ["AWS_SECRET_ACCESS_KEY"],
|
|
827
|
+
sessionToken: ["AWS_SESSION_TOKEN"],
|
|
828
|
+
profile: ["AWS_PROFILE"]
|
|
829
|
+
};
|
|
830
|
+
var AwsSecretsManagerConfig = class _AwsSecretsManagerConfig {
|
|
831
|
+
/** Prefix of every environment variable. */
|
|
832
|
+
static ENV_PREFIX = "GROW_AWS_SECRETS_MANAGER_";
|
|
833
|
+
/**
|
|
834
|
+
* Effective endpoint: {@link endpoint} when set, otherwise the public AWS endpoint of
|
|
835
|
+
* {@link region} (`us-east-1` when the region is left to the SDK). Informational.
|
|
836
|
+
*/
|
|
837
|
+
url;
|
|
838
|
+
/** Explicit endpoint override passed to the AWS SDK (`undefined` = SDK resolves it). */
|
|
839
|
+
endpoint;
|
|
840
|
+
connectTimeoutMs;
|
|
841
|
+
requestTimeoutMs;
|
|
842
|
+
totalTimeoutMs;
|
|
843
|
+
retry;
|
|
844
|
+
tls;
|
|
845
|
+
proxy;
|
|
846
|
+
headers;
|
|
847
|
+
userAgentSuffix;
|
|
848
|
+
hooks;
|
|
849
|
+
logger;
|
|
850
|
+
/** AWS region (`undefined` = SDK chain: env, shared config). */
|
|
851
|
+
region;
|
|
852
|
+
/** Access key id. */
|
|
853
|
+
accessKeyId;
|
|
854
|
+
/** Secret access key. */
|
|
855
|
+
secretAccessKey;
|
|
856
|
+
/** Session token. */
|
|
857
|
+
sessionToken;
|
|
858
|
+
/** Shared config profile. */
|
|
859
|
+
profile;
|
|
860
|
+
/** Explicit SDK credentials. */
|
|
861
|
+
credentials;
|
|
862
|
+
/** Role assumed with STS. */
|
|
863
|
+
roleArn;
|
|
864
|
+
/** STS session name. */
|
|
865
|
+
roleSessionName;
|
|
866
|
+
/** STS external id. */
|
|
867
|
+
externalId;
|
|
868
|
+
/** Assumed-role session duration in ms. */
|
|
869
|
+
roleDurationMs;
|
|
870
|
+
/** Recovery window of deletes in days. */
|
|
871
|
+
recoveryWindowDays;
|
|
872
|
+
/** Caller-supplied AWS SDK client. */
|
|
873
|
+
sdkClient;
|
|
874
|
+
/** Applies defaults, validates (throws {@link ConfigError}) and freezes. */
|
|
875
|
+
constructor(options = {}) {
|
|
876
|
+
const region = blankToUndefined(options.region);
|
|
877
|
+
const fallbackUrl = `https://secretsmanager.${region ?? "us-east-1"}.amazonaws.com`;
|
|
878
|
+
const endpointOption = blankToUndefined(options.url);
|
|
879
|
+
const common = resolveCommonConfig(
|
|
880
|
+
endpointOption === void 0 ? { ...options, url: fallbackUrl } : options,
|
|
881
|
+
fallbackUrl
|
|
882
|
+
);
|
|
883
|
+
this.url = common.url;
|
|
884
|
+
if (endpointOption !== void 0) this.endpoint = endpointOption;
|
|
885
|
+
this.connectTimeoutMs = common.connectTimeoutMs;
|
|
886
|
+
this.requestTimeoutMs = common.requestTimeoutMs;
|
|
887
|
+
this.totalTimeoutMs = common.totalTimeoutMs;
|
|
888
|
+
this.retry = common.retry;
|
|
889
|
+
this.tls = common.tls;
|
|
890
|
+
this.headers = common.headers;
|
|
891
|
+
if (common.proxy !== void 0) this.proxy = common.proxy;
|
|
892
|
+
if (common.userAgentSuffix !== void 0) this.userAgentSuffix = common.userAgentSuffix;
|
|
893
|
+
if (common.hooks !== void 0) this.hooks = common.hooks;
|
|
894
|
+
if (common.logger !== void 0) this.logger = common.logger;
|
|
895
|
+
if (region !== void 0) this.region = region;
|
|
896
|
+
const accessKeyId = blankToUndefined(options.accessKeyId);
|
|
897
|
+
if (accessKeyId !== void 0) this.accessKeyId = accessKeyId;
|
|
898
|
+
const secretAccessKey = chunkZLYHN4AI_cjs.Secret.from(options.secretAccessKey);
|
|
899
|
+
if (secretAccessKey !== void 0) this.secretAccessKey = secretAccessKey;
|
|
900
|
+
const sessionToken = chunkZLYHN4AI_cjs.Secret.from(options.sessionToken);
|
|
901
|
+
if (sessionToken !== void 0) this.sessionToken = sessionToken;
|
|
902
|
+
const profile = blankToUndefined(options.profile);
|
|
903
|
+
if (profile !== void 0) this.profile = profile;
|
|
904
|
+
if (options.credentials !== void 0) this.credentials = options.credentials;
|
|
905
|
+
const roleArn = blankToUndefined(options.roleArn);
|
|
906
|
+
if (roleArn !== void 0) this.roleArn = roleArn;
|
|
907
|
+
this.roleSessionName = blankToUndefined(options.roleSessionName) ?? DEFAULT_ROLE_SESSION_NAME;
|
|
908
|
+
const externalId = blankToUndefined(options.externalId);
|
|
909
|
+
if (externalId !== void 0) this.externalId = externalId;
|
|
910
|
+
if (options.roleDurationMs !== void 0) this.roleDurationMs = options.roleDurationMs;
|
|
911
|
+
this.recoveryWindowDays = options.recoveryWindowDays ?? DEFAULT_RECOVERY_WINDOW_DAYS;
|
|
912
|
+
if (options.sdkClient !== void 0) this.sdkClient = options.sdkClient;
|
|
913
|
+
this.validate();
|
|
914
|
+
Object.freeze(this);
|
|
915
|
+
}
|
|
916
|
+
/** Returns `options` when it already is a config, otherwise builds one. */
|
|
917
|
+
static from(options = {}) {
|
|
918
|
+
if (options instanceof _AwsSecretsManagerConfig) return options;
|
|
919
|
+
return new _AwsSecretsManagerConfig(options);
|
|
920
|
+
}
|
|
921
|
+
/**
|
|
922
|
+
* Builds a config from the environment. Precedence: explicit `overrides` >
|
|
923
|
+
* `GROW_AWS_SECRETS_MANAGER_<NAME>` > standard AWS variables ({@link VENDOR_ENV}) > defaults.
|
|
924
|
+
* Credentials left unset use the AWS SDK default chain.
|
|
925
|
+
*/
|
|
926
|
+
static fromEnv(overrides = {}, env = process.env) {
|
|
927
|
+
const reader = new chunkZLYHN4AI_cjs.EnvReader(_AwsSecretsManagerConfig.ENV_PREFIX, env);
|
|
928
|
+
const fromEnv = readCommonEnv(reader, VENDOR_ENV);
|
|
929
|
+
const set = (key, value) => {
|
|
930
|
+
if (value !== void 0) fromEnv[key] = value;
|
|
931
|
+
};
|
|
932
|
+
set("region", reader.string("REGION", VENDOR_ENV.region));
|
|
933
|
+
const growKey = reader.string("ACCESS_KEY_ID");
|
|
934
|
+
if (growKey !== void 0) {
|
|
935
|
+
set("accessKeyId", growKey);
|
|
936
|
+
set("secretAccessKey", reader.secret("SECRET_ACCESS_KEY"));
|
|
937
|
+
set("sessionToken", reader.secret("SESSION_TOKEN"));
|
|
938
|
+
} else {
|
|
939
|
+
set("accessKeyId", firstEnv(env, VENDOR_ENV.accessKeyId));
|
|
940
|
+
set("secretAccessKey", chunkZLYHN4AI_cjs.Secret.from(firstEnv(env, VENDOR_ENV.secretAccessKey)));
|
|
941
|
+
set("sessionToken", chunkZLYHN4AI_cjs.Secret.from(firstEnv(env, VENDOR_ENV.sessionToken)));
|
|
942
|
+
}
|
|
943
|
+
set("profile", reader.string("PROFILE", VENDOR_ENV.profile));
|
|
944
|
+
set("roleArn", reader.string("ROLE_ARN"));
|
|
945
|
+
set("roleSessionName", reader.string("ROLE_SESSION_NAME"));
|
|
946
|
+
set("externalId", reader.string("EXTERNAL_ID"));
|
|
947
|
+
set("recoveryWindowDays", reader.int("RECOVERY_WINDOW_DAYS"));
|
|
948
|
+
const merged = mergeOptions(fromEnv, overrides);
|
|
949
|
+
if (overrides.sdkClient !== void 0 || overrides.credentials !== void 0) {
|
|
950
|
+
delete merged.accessKeyId;
|
|
951
|
+
delete merged.secretAccessKey;
|
|
952
|
+
delete merged.sessionToken;
|
|
953
|
+
if (overrides.sdkClient !== void 0) {
|
|
954
|
+
if (overrides.region === void 0) delete merged.region;
|
|
955
|
+
if (overrides.url === void 0) delete merged.url;
|
|
956
|
+
if (overrides.profile === void 0) delete merged.profile;
|
|
957
|
+
if (overrides.roleArn === void 0) delete merged.roleArn;
|
|
958
|
+
}
|
|
959
|
+
}
|
|
960
|
+
return new _AwsSecretsManagerConfig(merged);
|
|
961
|
+
}
|
|
962
|
+
/** Throws {@link ConfigError} when a setting is invalid. */
|
|
963
|
+
validate() {
|
|
964
|
+
validateCommonConfig(this);
|
|
965
|
+
const problems = [];
|
|
966
|
+
if (this.endpoint !== void 0 && !/^https?:\/\//i.test(this.endpoint)) {
|
|
967
|
+
problems.push("url must be an http or https URL");
|
|
968
|
+
}
|
|
969
|
+
if (this.region !== void 0 && !/^[a-z0-9-]+$/.test(this.region)) {
|
|
970
|
+
problems.push("region must look like us-east-1");
|
|
971
|
+
}
|
|
972
|
+
if (this.accessKeyId !== void 0 && this.secretAccessKey === void 0) {
|
|
973
|
+
problems.push("accessKeyId requires secretAccessKey");
|
|
974
|
+
}
|
|
975
|
+
if (this.accessKeyId === void 0 && this.secretAccessKey !== void 0) {
|
|
976
|
+
problems.push("secretAccessKey requires accessKeyId");
|
|
977
|
+
}
|
|
978
|
+
if (this.sessionToken !== void 0 && this.accessKeyId === void 0) {
|
|
979
|
+
problems.push("sessionToken requires accessKeyId and secretAccessKey");
|
|
980
|
+
}
|
|
981
|
+
if (this.credentials !== void 0 && this.accessKeyId !== void 0) {
|
|
982
|
+
problems.push("credentials and accessKeyId/secretAccessKey are mutually exclusive");
|
|
983
|
+
}
|
|
984
|
+
if (this.sdkClient !== void 0) {
|
|
985
|
+
const clash = [
|
|
986
|
+
["accessKeyId", this.accessKeyId],
|
|
987
|
+
["credentials", this.credentials],
|
|
988
|
+
["profile", this.profile],
|
|
989
|
+
["roleArn", this.roleArn],
|
|
990
|
+
["region", this.region],
|
|
991
|
+
["url", this.endpoint]
|
|
992
|
+
].filter(([, v]) => v !== void 0);
|
|
993
|
+
if (clash.length > 0) {
|
|
994
|
+
problems.push(`sdkClient is mutually exclusive with ${clash.map(([k]) => k).join(", ")}`);
|
|
995
|
+
}
|
|
996
|
+
}
|
|
997
|
+
if (this.roleArn !== void 0 && !this.roleArn.startsWith("arn:")) {
|
|
998
|
+
problems.push("roleArn must be an ARN");
|
|
999
|
+
}
|
|
1000
|
+
if (this.roleDurationMs !== void 0 && !(this.roleDurationMs >= 9e5 && this.roleDurationMs <= 432e5)) {
|
|
1001
|
+
problems.push("roleDurationMs must be between 900000 and 43200000");
|
|
1002
|
+
}
|
|
1003
|
+
if (!Number.isInteger(this.recoveryWindowDays) || this.recoveryWindowDays < 7 || this.recoveryWindowDays > 30) {
|
|
1004
|
+
problems.push("recoveryWindowDays must be an integer from 7 to 30");
|
|
1005
|
+
}
|
|
1006
|
+
if (problems.length > 0) {
|
|
1007
|
+
throw new chunkZLYHN4AI_cjs.ConfigError(`invalid configuration: ${problems.join("; ")}`);
|
|
1008
|
+
}
|
|
1009
|
+
}
|
|
1010
|
+
/** Credential values to redact from error messages and logs. */
|
|
1011
|
+
knownSecrets() {
|
|
1012
|
+
return secretValues(this.secretAccessKey, this.sessionToken);
|
|
1013
|
+
}
|
|
1014
|
+
/** Debug form with every credential redacted. */
|
|
1015
|
+
toJSON() {
|
|
1016
|
+
const out = {
|
|
1017
|
+
...describeCommonConfig(this),
|
|
1018
|
+
endpoint: this.endpoint ?? null,
|
|
1019
|
+
region: this.region ?? null,
|
|
1020
|
+
accessKeyId: this.accessKeyId ?? null,
|
|
1021
|
+
secretAccessKey: this.secretAccessKey === void 0 ? null : chunkZLYHN4AI_cjs.REDACTED,
|
|
1022
|
+
sessionToken: this.sessionToken === void 0 ? null : chunkZLYHN4AI_cjs.REDACTED,
|
|
1023
|
+
profile: this.profile ?? null,
|
|
1024
|
+
credentials: this.credentials === void 0 ? null : chunkZLYHN4AI_cjs.REDACTED,
|
|
1025
|
+
roleArn: this.roleArn ?? null,
|
|
1026
|
+
roleSessionName: this.roleSessionName,
|
|
1027
|
+
externalId: this.externalId === void 0 ? null : chunkZLYHN4AI_cjs.REDACTED,
|
|
1028
|
+
recoveryWindowDays: this.recoveryWindowDays,
|
|
1029
|
+
sdkClient: this.sdkClient === void 0 ? null : "SecretsManagerClient"
|
|
1030
|
+
};
|
|
1031
|
+
if (this.roleDurationMs !== void 0) out.roleDurationMs = this.roleDurationMs;
|
|
1032
|
+
return out;
|
|
1033
|
+
}
|
|
1034
|
+
toString() {
|
|
1035
|
+
return `AwsSecretsManagerConfig(${JSON.stringify(this.toJSON())})`;
|
|
1036
|
+
}
|
|
1037
|
+
[INSPECT]() {
|
|
1038
|
+
return this.toString();
|
|
1039
|
+
}
|
|
1040
|
+
};
|
|
1041
|
+
function firstEnv(env, names) {
|
|
1042
|
+
for (const name of names) {
|
|
1043
|
+
const value = env[name];
|
|
1044
|
+
if (value !== void 0 && value !== "") return value;
|
|
1045
|
+
}
|
|
1046
|
+
return void 0;
|
|
1047
|
+
}
|
|
1048
|
+
function blankToUndefined(value) {
|
|
1049
|
+
return value === void 0 || value.trim() === "" ? void 0 : value;
|
|
1050
|
+
}
|
|
1051
|
+
|
|
1052
|
+
// src/errors-map.ts
|
|
1053
|
+
var AWS_ERROR_CODES = Object.freeze({
|
|
1054
|
+
ResourceNotFoundException: chunkZLYHN4AI_cjs.ErrorCode.NotFound,
|
|
1055
|
+
ResourceExistsException: chunkZLYHN4AI_cjs.ErrorCode.Conflict,
|
|
1056
|
+
PreconditionNotMetException: chunkZLYHN4AI_cjs.ErrorCode.Conflict,
|
|
1057
|
+
InvalidRequestException: chunkZLYHN4AI_cjs.ErrorCode.Conflict,
|
|
1058
|
+
InvalidParameterException: chunkZLYHN4AI_cjs.ErrorCode.Validation,
|
|
1059
|
+
InvalidParameterValue: chunkZLYHN4AI_cjs.ErrorCode.Validation,
|
|
1060
|
+
ValidationException: chunkZLYHN4AI_cjs.ErrorCode.Validation,
|
|
1061
|
+
InvalidNextTokenException: chunkZLYHN4AI_cjs.ErrorCode.Validation,
|
|
1062
|
+
MalformedPolicyDocumentException: chunkZLYHN4AI_cjs.ErrorCode.Validation,
|
|
1063
|
+
PublicPolicyException: chunkZLYHN4AI_cjs.ErrorCode.Validation,
|
|
1064
|
+
LimitExceededException: chunkZLYHN4AI_cjs.ErrorCode.Validation,
|
|
1065
|
+
EncryptionFailure: chunkZLYHN4AI_cjs.ErrorCode.Validation,
|
|
1066
|
+
DecryptionFailure: chunkZLYHN4AI_cjs.ErrorCode.Validation,
|
|
1067
|
+
SerializationException: chunkZLYHN4AI_cjs.ErrorCode.Validation,
|
|
1068
|
+
AccessDeniedException: chunkZLYHN4AI_cjs.ErrorCode.PermissionDenied,
|
|
1069
|
+
AccessDenied: chunkZLYHN4AI_cjs.ErrorCode.PermissionDenied,
|
|
1070
|
+
UnrecognizedClientException: chunkZLYHN4AI_cjs.ErrorCode.Authentication,
|
|
1071
|
+
InvalidClientTokenId: chunkZLYHN4AI_cjs.ErrorCode.Authentication,
|
|
1072
|
+
InvalidSignatureException: chunkZLYHN4AI_cjs.ErrorCode.Authentication,
|
|
1073
|
+
SignatureDoesNotMatch: chunkZLYHN4AI_cjs.ErrorCode.Authentication,
|
|
1074
|
+
IncompleteSignature: chunkZLYHN4AI_cjs.ErrorCode.Authentication,
|
|
1075
|
+
IncompleteSignatureException: chunkZLYHN4AI_cjs.ErrorCode.Authentication,
|
|
1076
|
+
MissingAuthenticationToken: chunkZLYHN4AI_cjs.ErrorCode.Authentication,
|
|
1077
|
+
MissingAuthenticationTokenException: chunkZLYHN4AI_cjs.ErrorCode.Authentication,
|
|
1078
|
+
ExpiredToken: chunkZLYHN4AI_cjs.ErrorCode.Authentication,
|
|
1079
|
+
ExpiredTokenException: chunkZLYHN4AI_cjs.ErrorCode.Authentication,
|
|
1080
|
+
InvalidAccessKeyId: chunkZLYHN4AI_cjs.ErrorCode.Authentication,
|
|
1081
|
+
CredentialsProviderError: chunkZLYHN4AI_cjs.ErrorCode.Authentication,
|
|
1082
|
+
ThrottlingException: chunkZLYHN4AI_cjs.ErrorCode.RateLimited,
|
|
1083
|
+
Throttling: chunkZLYHN4AI_cjs.ErrorCode.RateLimited,
|
|
1084
|
+
TooManyRequestsException: chunkZLYHN4AI_cjs.ErrorCode.RateLimited,
|
|
1085
|
+
RequestLimitExceeded: chunkZLYHN4AI_cjs.ErrorCode.RateLimited,
|
|
1086
|
+
InternalServiceError: chunkZLYHN4AI_cjs.ErrorCode.Unavailable,
|
|
1087
|
+
InternalServiceErrorException: chunkZLYHN4AI_cjs.ErrorCode.Unavailable,
|
|
1088
|
+
InternalFailure: chunkZLYHN4AI_cjs.ErrorCode.Unavailable,
|
|
1089
|
+
ServiceUnavailable: chunkZLYHN4AI_cjs.ErrorCode.Unavailable,
|
|
1090
|
+
ServiceUnavailableException: chunkZLYHN4AI_cjs.ErrorCode.Unavailable,
|
|
1091
|
+
RequestTimeout: chunkZLYHN4AI_cjs.ErrorCode.Timeout,
|
|
1092
|
+
RequestTimeoutException: chunkZLYHN4AI_cjs.ErrorCode.Timeout,
|
|
1093
|
+
TimeoutError: chunkZLYHN4AI_cjs.ErrorCode.Timeout
|
|
1094
|
+
});
|
|
1095
|
+
var NETWORK_TIMEOUT_CODES = /* @__PURE__ */ new Set([
|
|
1096
|
+
"ETIMEDOUT",
|
|
1097
|
+
"UND_ERR_CONNECT_TIMEOUT",
|
|
1098
|
+
"UND_ERR_HEADERS_TIMEOUT",
|
|
1099
|
+
"UND_ERR_BODY_TIMEOUT"
|
|
1100
|
+
]);
|
|
1101
|
+
function bodyText(body) {
|
|
1102
|
+
if (typeof body === "string") return body;
|
|
1103
|
+
if (body instanceof Uint8Array) return new TextDecoder().decode(body);
|
|
1104
|
+
return "";
|
|
1105
|
+
}
|
|
1106
|
+
function errorCodeFromBody(text) {
|
|
1107
|
+
const xml = /<Code>\s*([^<\s]+)\s*<\/Code>/.exec(text)?.[1];
|
|
1108
|
+
if (xml !== void 0) return xml;
|
|
1109
|
+
try {
|
|
1110
|
+
const parsed = JSON.parse(text);
|
|
1111
|
+
const raw = typeof parsed.__type === "string" ? parsed.__type : parsed.code;
|
|
1112
|
+
if (typeof raw === "string") return raw.split("#").pop()?.split(":")[0];
|
|
1113
|
+
} catch {
|
|
1114
|
+
}
|
|
1115
|
+
return void 0;
|
|
1116
|
+
}
|
|
1117
|
+
function cleanVendorText(text, knownSecrets) {
|
|
1118
|
+
const collapsed = text.replace(/\s+/g, " ").trim();
|
|
1119
|
+
const redacted = redactSecretsInText(chunkZLYHN4AI_cjs.redactText(collapsed, knownSecrets));
|
|
1120
|
+
return redacted.length > MAX_VENDOR_TEXT ? `${redacted.slice(0, MAX_VENDOR_TEXT)}\u2026` : redacted;
|
|
1121
|
+
}
|
|
1122
|
+
function nodeCode(err) {
|
|
1123
|
+
let current = err;
|
|
1124
|
+
for (let depth = 0; depth < 5 && current !== void 0 && current !== null; depth++) {
|
|
1125
|
+
const code = current.code;
|
|
1126
|
+
if (typeof code === "string") return code;
|
|
1127
|
+
current = current.cause;
|
|
1128
|
+
}
|
|
1129
|
+
return void 0;
|
|
1130
|
+
}
|
|
1131
|
+
function mapAwsError(err, operation, options = {}) {
|
|
1132
|
+
if (chunkZLYHN4AI_cjs.isAwsSecretsManagerError(err)) return err;
|
|
1133
|
+
const known = [...options.knownSecrets ?? []];
|
|
1134
|
+
const e = typeof err === "object" && err !== null ? err : {};
|
|
1135
|
+
const name = typeof e.name === "string" ? e.name : "";
|
|
1136
|
+
const message = typeof e.message === "string" ? e.message : String(err);
|
|
1137
|
+
const status = e.$metadata?.httpStatusCode ?? e.$response?.statusCode;
|
|
1138
|
+
const requestId = e.$metadata?.requestId;
|
|
1139
|
+
const details = {
|
|
1140
|
+
...status === void 0 ? {} : { httpStatus: status },
|
|
1141
|
+
...requestId === void 0 ? {} : { requestId },
|
|
1142
|
+
cause: err
|
|
1143
|
+
};
|
|
1144
|
+
const suffix = status === void 0 ? "" : ` (HTTP ${String(status)})`;
|
|
1145
|
+
if (name === "AbortError") {
|
|
1146
|
+
return chunkZLYHN4AI_cjs.errorForCode(chunkZLYHN4AI_cjs.ErrorCode.Cancelled, `${operation}: cancelled`, { cause: err });
|
|
1147
|
+
}
|
|
1148
|
+
if (/Region is missing|Region not accepted/i.test(message)) {
|
|
1149
|
+
return chunkZLYHN4AI_cjs.errorForCode(
|
|
1150
|
+
chunkZLYHN4AI_cjs.ErrorCode.Config,
|
|
1151
|
+
`${operation}: no AWS region configured (set region or AWS_REGION)`,
|
|
1152
|
+
{ cause: err }
|
|
1153
|
+
);
|
|
1154
|
+
}
|
|
1155
|
+
if (status !== void 0) {
|
|
1156
|
+
const parsed = e.$fault !== void 0 && name !== "" ? name : void 0;
|
|
1157
|
+
const raw = bodyText(e.$response?.body);
|
|
1158
|
+
const awsCode = parsed ?? errorCodeFromBody(raw);
|
|
1159
|
+
let code = awsCode === void 0 ? void 0 : AWS_ERROR_CODES[awsCode];
|
|
1160
|
+
if (code === void 0) {
|
|
1161
|
+
if (status === 403) {
|
|
1162
|
+
code = /InvalidClientTokenId|SignatureDoesNotMatch|security token/i.test(raw) ? chunkZLYHN4AI_cjs.ErrorCode.Authentication : chunkZLYHN4AI_cjs.ErrorCode.PermissionDenied;
|
|
1163
|
+
} else if (status === 500 && options.unsupportedOnHtml500 === true && /<html/i.test(raw)) {
|
|
1164
|
+
code = chunkZLYHN4AI_cjs.ErrorCode.Unsupported;
|
|
1165
|
+
} else {
|
|
1166
|
+
code = chunkZLYHN4AI_cjs.codeForStatus(status);
|
|
1167
|
+
}
|
|
1168
|
+
}
|
|
1169
|
+
const vendor = parsed !== void 0 ? cleanVendorText(message, known) : "";
|
|
1170
|
+
const reason = awsCode === void 0 ? chunkZLYHN4AI_cjs.reasonForCode(code) : vendor === "" ? awsCode : `${awsCode}: ${vendor}`;
|
|
1171
|
+
const retryAfterRaw = e.$response?.headers?.["retry-after"];
|
|
1172
|
+
const retryAfterMs = code === chunkZLYHN4AI_cjs.ErrorCode.RateLimited && retryAfterRaw !== void 0 ? parseRetryAfter(retryAfterRaw) : void 0;
|
|
1173
|
+
return chunkZLYHN4AI_cjs.errorForCode(code, `${operation}: ${reason}${suffix}`, {
|
|
1174
|
+
...details,
|
|
1175
|
+
...retryAfterMs === void 0 ? {} : { retryAfterMs }
|
|
1176
|
+
});
|
|
1177
|
+
}
|
|
1178
|
+
const mappedByName = AWS_ERROR_CODES[name];
|
|
1179
|
+
if (mappedByName !== void 0) {
|
|
1180
|
+
const text2 = cleanVendorText(message, known);
|
|
1181
|
+
return chunkZLYHN4AI_cjs.errorForCode(
|
|
1182
|
+
mappedByName,
|
|
1183
|
+
`${operation}: ${chunkZLYHN4AI_cjs.reasonForCode(mappedByName)}: ${text2}`,
|
|
1184
|
+
details
|
|
1185
|
+
);
|
|
1186
|
+
}
|
|
1187
|
+
const net = nodeCode(err);
|
|
1188
|
+
if (net !== void 0 && NETWORK_TIMEOUT_CODES.has(net)) {
|
|
1189
|
+
return chunkZLYHN4AI_cjs.errorForCode(chunkZLYHN4AI_cjs.ErrorCode.Timeout, `${operation}: timed out (${net})`, details);
|
|
1190
|
+
}
|
|
1191
|
+
const text = cleanVendorText(message, known);
|
|
1192
|
+
return chunkZLYHN4AI_cjs.errorForCode(
|
|
1193
|
+
chunkZLYHN4AI_cjs.ErrorCode.Unavailable,
|
|
1194
|
+
`${operation}: service unavailable: ${net === void 0 ? text : `${net}: ${text}`}`,
|
|
1195
|
+
details
|
|
1196
|
+
);
|
|
1197
|
+
}
|
|
1198
|
+
var GROW_USER_AGENT = `grow-codes-${PACKAGE_KEY}/${SDK_VERSION} (${LANGUAGE})`;
|
|
1199
|
+
var AttemptTimeoutError = class extends Error {
|
|
1200
|
+
/** Node-style code, recognised by the SDK retry strategy as a transient error. */
|
|
1201
|
+
code = "ETIMEDOUT";
|
|
1202
|
+
constructor(ms) {
|
|
1203
|
+
super(`request timed out after ${ms} ms`);
|
|
1204
|
+
this.name = "TimeoutError";
|
|
1205
|
+
}
|
|
1206
|
+
};
|
|
1207
|
+
function parseAttemptHeader(value) {
|
|
1208
|
+
const attempt = /attempt=(\d+)/.exec(value ?? "")?.[1];
|
|
1209
|
+
const max = /max=(\d+)/.exec(value ?? "")?.[1];
|
|
1210
|
+
return {
|
|
1211
|
+
attempt: attempt === void 0 ? 1 : Number(attempt),
|
|
1212
|
+
max: max === void 0 ? 1 : Number(max)
|
|
1213
|
+
};
|
|
1214
|
+
}
|
|
1215
|
+
function buildUrl(request) {
|
|
1216
|
+
const port = request.port === void 0 ? "" : `:${String(request.port)}`;
|
|
1217
|
+
const path = request.path.startsWith("/") ? request.path : `/${request.path}`;
|
|
1218
|
+
const params = new URLSearchParams();
|
|
1219
|
+
for (const [k, v] of Object.entries(request.query ?? {})) {
|
|
1220
|
+
if (v === null) continue;
|
|
1221
|
+
for (const item of Array.isArray(v) ? v : [v]) params.append(k, item);
|
|
1222
|
+
}
|
|
1223
|
+
const qs = params.toString();
|
|
1224
|
+
return `${request.protocol}//${request.hostname}${port}${path}${qs === "" ? "" : `?${qs}`}`;
|
|
1225
|
+
}
|
|
1226
|
+
var GrowHttpHandler = class {
|
|
1227
|
+
#config;
|
|
1228
|
+
#hooks;
|
|
1229
|
+
#logger;
|
|
1230
|
+
#userAgent;
|
|
1231
|
+
#dispatcher;
|
|
1232
|
+
#ownsDispatcher;
|
|
1233
|
+
#destroyed = false;
|
|
1234
|
+
constructor(options) {
|
|
1235
|
+
this.#config = options.config;
|
|
1236
|
+
this.#hooks = options.config.hooks ?? {};
|
|
1237
|
+
this.#logger = safeLogger(options.config.logger);
|
|
1238
|
+
this.#dispatcher = options.dispatcher;
|
|
1239
|
+
this.#ownsDispatcher = options.dispatcher === void 0;
|
|
1240
|
+
const suffix = options.config.userAgentSuffix;
|
|
1241
|
+
this.#userAgent = GROW_USER_AGENT + (suffix !== void 0 && suffix !== "" ? ` ${suffix}` : "");
|
|
1242
|
+
}
|
|
1243
|
+
/** The User-Agent token appended to the SDK's own User-Agent. */
|
|
1244
|
+
get userAgent() {
|
|
1245
|
+
return this.#userAgent;
|
|
1246
|
+
}
|
|
1247
|
+
/** Smithy handler metadata. */
|
|
1248
|
+
metadata = { handlerProtocol: "http/1.1" };
|
|
1249
|
+
#getDispatcher() {
|
|
1250
|
+
this.#dispatcher ??= createDispatcher(this.#config, this.#logger);
|
|
1251
|
+
return this.#dispatcher;
|
|
1252
|
+
}
|
|
1253
|
+
/** Sends one attempt. Called by the SDK (after signing) for every attempt. */
|
|
1254
|
+
async handle(request, options = {}) {
|
|
1255
|
+
const url = buildUrl(request);
|
|
1256
|
+
const safeUrl = chunkZLYHN4AI_cjs.redactUrl(url);
|
|
1257
|
+
const headers = {};
|
|
1258
|
+
for (const [k, v] of Object.entries(this.#config.headers)) headers[k.toLowerCase()] = v;
|
|
1259
|
+
for (const [k, v] of Object.entries(request.headers)) headers[k.toLowerCase()] = v;
|
|
1260
|
+
headers["user-agent"] = headers["user-agent"] === void 0 ? this.#userAgent : `${headers["user-agent"]} ${this.#userAgent}`;
|
|
1261
|
+
const { attempt, max } = parseAttemptHeader(headers["amz-sdk-request"]);
|
|
1262
|
+
const method = request.method.toUpperCase();
|
|
1263
|
+
safeCall(this.#hooks.onRequest, {
|
|
1264
|
+
method,
|
|
1265
|
+
url: safeUrl,
|
|
1266
|
+
headers: chunkZLYHN4AI_cjs.redactHeaders(headers),
|
|
1267
|
+
attempt
|
|
1268
|
+
});
|
|
1269
|
+
this.#logger.debug("aws-secrets-manager request", { method, url: safeUrl, attempt });
|
|
1270
|
+
const timeoutMs = options.requestTimeout ?? this.#config.requestTimeoutMs;
|
|
1271
|
+
const controller = new AbortController();
|
|
1272
|
+
const external = options.abortSignal;
|
|
1273
|
+
const onAbort = () => {
|
|
1274
|
+
controller.abort(external?.reason);
|
|
1275
|
+
};
|
|
1276
|
+
if (external?.aborted === true) onAbort();
|
|
1277
|
+
else external?.addEventListener("abort", onAbort, { once: true });
|
|
1278
|
+
const state = { timedOut: false };
|
|
1279
|
+
const timer = setTimeout(() => {
|
|
1280
|
+
state.timedOut = true;
|
|
1281
|
+
controller.abort();
|
|
1282
|
+
}, timeoutMs);
|
|
1283
|
+
timer.unref();
|
|
1284
|
+
const start = performance.now();
|
|
1285
|
+
try {
|
|
1286
|
+
const res = await undici.fetch(url, {
|
|
1287
|
+
method,
|
|
1288
|
+
headers,
|
|
1289
|
+
...request.body === void 0 || request.body === null ? {} : { body: request.body },
|
|
1290
|
+
signal: controller.signal,
|
|
1291
|
+
dispatcher: this.#getDispatcher()
|
|
1292
|
+
});
|
|
1293
|
+
const body = new Uint8Array(await res.arrayBuffer());
|
|
1294
|
+
const responseHeaders = {};
|
|
1295
|
+
res.headers.forEach((value, key) => {
|
|
1296
|
+
responseHeaders[key] = value;
|
|
1297
|
+
});
|
|
1298
|
+
const requestId = responseHeaders["x-amzn-requestid"] ?? responseHeaders["x-amz-request-id"];
|
|
1299
|
+
safeCall(this.#hooks.onResponse, {
|
|
1300
|
+
method,
|
|
1301
|
+
url: safeUrl,
|
|
1302
|
+
status: res.status,
|
|
1303
|
+
durationMs: performance.now() - start,
|
|
1304
|
+
attempt,
|
|
1305
|
+
...requestId === void 0 ? {} : { requestId }
|
|
1306
|
+
});
|
|
1307
|
+
return {
|
|
1308
|
+
response: {
|
|
1309
|
+
statusCode: res.status,
|
|
1310
|
+
reason: res.statusText,
|
|
1311
|
+
headers: responseHeaders,
|
|
1312
|
+
body
|
|
1313
|
+
}
|
|
1314
|
+
};
|
|
1315
|
+
} catch (err) {
|
|
1316
|
+
const error = state.timedOut && external?.aborted !== true ? new AttemptTimeoutError(timeoutMs) : external?.aborted === true ? abortError() : toError(err);
|
|
1317
|
+
safeCall(this.#hooks.onError, {
|
|
1318
|
+
method,
|
|
1319
|
+
url: safeUrl,
|
|
1320
|
+
error,
|
|
1321
|
+
attempt,
|
|
1322
|
+
willRetry: external?.aborted !== true && attempt < max
|
|
1323
|
+
});
|
|
1324
|
+
throw error;
|
|
1325
|
+
} finally {
|
|
1326
|
+
clearTimeout(timer);
|
|
1327
|
+
external?.removeEventListener("abort", onAbort);
|
|
1328
|
+
}
|
|
1329
|
+
}
|
|
1330
|
+
/** Smithy handler API (no runtime-updatable settings). */
|
|
1331
|
+
updateHttpClientConfig() {
|
|
1332
|
+
}
|
|
1333
|
+
/** Smithy handler API. */
|
|
1334
|
+
httpHandlerConfigs() {
|
|
1335
|
+
return {};
|
|
1336
|
+
}
|
|
1337
|
+
/** Closes the dispatcher (only when this handler created it). Idempotent. */
|
|
1338
|
+
destroy() {
|
|
1339
|
+
if (this.#destroyed) return;
|
|
1340
|
+
this.#destroyed = true;
|
|
1341
|
+
const dispatcher = this.#dispatcher;
|
|
1342
|
+
this.#dispatcher = void 0;
|
|
1343
|
+
if (dispatcher !== void 0 && this.#ownsDispatcher) {
|
|
1344
|
+
dispatcher.close().catch(() => void 0);
|
|
1345
|
+
}
|
|
1346
|
+
}
|
|
1347
|
+
};
|
|
1348
|
+
function abortError() {
|
|
1349
|
+
const err = new Error("Request aborted");
|
|
1350
|
+
err.name = "AbortError";
|
|
1351
|
+
return err;
|
|
1352
|
+
}
|
|
1353
|
+
function toError(err) {
|
|
1354
|
+
if (err instanceof Error) {
|
|
1355
|
+
const cause = err.cause;
|
|
1356
|
+
if (typeof cause?.code === "string") {
|
|
1357
|
+
const wrapped = new Error(typeof cause.message === "string" ? cause.message : err.message, {
|
|
1358
|
+
cause: err
|
|
1359
|
+
});
|
|
1360
|
+
wrapped.code = cause.code;
|
|
1361
|
+
wrapped.name = cause.code;
|
|
1362
|
+
return wrapped;
|
|
1363
|
+
}
|
|
1364
|
+
return err;
|
|
1365
|
+
}
|
|
1366
|
+
return new Error(String(err));
|
|
1367
|
+
}
|
|
1368
|
+
|
|
1369
|
+
// src/secrets/cache.ts
|
|
1370
|
+
var SecretCache = class extends chunkZLYHN4AI_cjs.BaseSecretsProvider {
|
|
1371
|
+
#provider;
|
|
1372
|
+
#ttl;
|
|
1373
|
+
#max;
|
|
1374
|
+
#refreshAt;
|
|
1375
|
+
#swr;
|
|
1376
|
+
#clock;
|
|
1377
|
+
#onRefreshError;
|
|
1378
|
+
#entries = /* @__PURE__ */ new Map();
|
|
1379
|
+
#inflight = /* @__PURE__ */ new Map();
|
|
1380
|
+
#hits = 0;
|
|
1381
|
+
#misses = 0;
|
|
1382
|
+
#evictions = 0;
|
|
1383
|
+
#refreshes = 0;
|
|
1384
|
+
#generation = 0;
|
|
1385
|
+
constructor(provider, options = {}) {
|
|
1386
|
+
super();
|
|
1387
|
+
this.#provider = provider;
|
|
1388
|
+
this.#ttl = options.ttlMs ?? 6e4;
|
|
1389
|
+
this.#max = options.maxEntries ?? 1e3;
|
|
1390
|
+
const factor = options.refreshAheadFactor ?? 0.8;
|
|
1391
|
+
this.#swr = options.staleWhileRevalidateMs ?? 0;
|
|
1392
|
+
this.#clock = options.clock ?? Date.now;
|
|
1393
|
+
this.#onRefreshError = options.onRefreshError;
|
|
1394
|
+
if (!(this.#ttl > 0)) throw new chunkZLYHN4AI_cjs.ValidationError("SecretCache: ttlMs must be > 0");
|
|
1395
|
+
if (!Number.isInteger(this.#max) || this.#max < 1)
|
|
1396
|
+
throw new chunkZLYHN4AI_cjs.ValidationError("SecretCache: maxEntries must be >= 1");
|
|
1397
|
+
if (!(factor > 0)) throw new chunkZLYHN4AI_cjs.ValidationError("SecretCache: refreshAheadFactor must be > 0");
|
|
1398
|
+
if (!(this.#swr >= 0))
|
|
1399
|
+
throw new chunkZLYHN4AI_cjs.ValidationError("SecretCache: staleWhileRevalidateMs must be >= 0");
|
|
1400
|
+
this.#refreshAt = this.#ttl * factor;
|
|
1401
|
+
}
|
|
1402
|
+
/** The wrapped provider. */
|
|
1403
|
+
get provider() {
|
|
1404
|
+
return this.#provider;
|
|
1405
|
+
}
|
|
1406
|
+
async fetchSecret(name, options) {
|
|
1407
|
+
const key = cacheKey(name, options);
|
|
1408
|
+
const entry = this.#entries.get(key);
|
|
1409
|
+
if (entry !== void 0) {
|
|
1410
|
+
const age = this.#clock() - entry.storedAt;
|
|
1411
|
+
if (age < this.#ttl + this.#swr) {
|
|
1412
|
+
this.#hits++;
|
|
1413
|
+
this.#touch(key, entry);
|
|
1414
|
+
if (age >= this.#refreshAt) this.#refresh(key, name, options, entry);
|
|
1415
|
+
return entry.value;
|
|
1416
|
+
}
|
|
1417
|
+
this.#entries.delete(key);
|
|
1418
|
+
}
|
|
1419
|
+
this.#misses++;
|
|
1420
|
+
return this.#load(key, name, options);
|
|
1421
|
+
}
|
|
1422
|
+
#touch(key, entry) {
|
|
1423
|
+
this.#entries.delete(key);
|
|
1424
|
+
this.#entries.set(key, entry);
|
|
1425
|
+
}
|
|
1426
|
+
#load(key, name, options) {
|
|
1427
|
+
const pending = this.#inflight.get(key);
|
|
1428
|
+
if (pending !== void 0) return pending;
|
|
1429
|
+
const generation = this.#generation;
|
|
1430
|
+
const promise = this.#provider.get(name, stripSignal(options)).then((value) => {
|
|
1431
|
+
if (generation === this.#generation) this.#store(key, name, value);
|
|
1432
|
+
return value;
|
|
1433
|
+
}).finally(() => {
|
|
1434
|
+
if (this.#inflight.get(key) === promise) this.#inflight.delete(key);
|
|
1435
|
+
});
|
|
1436
|
+
this.#inflight.set(key, promise);
|
|
1437
|
+
return promise;
|
|
1438
|
+
}
|
|
1439
|
+
#refresh(key, name, options, entry) {
|
|
1440
|
+
if (entry.refreshing || this.#inflight.has(key)) return;
|
|
1441
|
+
entry.refreshing = true;
|
|
1442
|
+
this.#refreshes++;
|
|
1443
|
+
this.#load(key, name, options).catch((err) => {
|
|
1444
|
+
entry.refreshing = false;
|
|
1445
|
+
try {
|
|
1446
|
+
this.#onRefreshError?.(err);
|
|
1447
|
+
} catch {
|
|
1448
|
+
}
|
|
1449
|
+
});
|
|
1450
|
+
}
|
|
1451
|
+
#store(key, name, value) {
|
|
1452
|
+
this.#entries.delete(key);
|
|
1453
|
+
this.#entries.set(key, { name, value, storedAt: this.#clock(), refreshing: false });
|
|
1454
|
+
while (this.#entries.size > this.#max) {
|
|
1455
|
+
const oldest = this.#entries.keys().next().value;
|
|
1456
|
+
this.#entries.delete(oldest);
|
|
1457
|
+
this.#evictions++;
|
|
1458
|
+
}
|
|
1459
|
+
}
|
|
1460
|
+
listSecrets(prefixOrPath, options) {
|
|
1461
|
+
return this.#provider.list(prefixOrPath, options);
|
|
1462
|
+
}
|
|
1463
|
+
async putSecret(name, value, options) {
|
|
1464
|
+
try {
|
|
1465
|
+
return await this.#provider.set(name, value, options);
|
|
1466
|
+
} finally {
|
|
1467
|
+
this.invalidate(name);
|
|
1468
|
+
}
|
|
1469
|
+
}
|
|
1470
|
+
async removeSecret(name, options) {
|
|
1471
|
+
try {
|
|
1472
|
+
await this.#provider.delete(name, options);
|
|
1473
|
+
} finally {
|
|
1474
|
+
this.invalidate(name);
|
|
1475
|
+
}
|
|
1476
|
+
}
|
|
1477
|
+
fetchMetadata(name, options) {
|
|
1478
|
+
return this.#provider.metadata(name, options);
|
|
1479
|
+
}
|
|
1480
|
+
/** Drops every cached entry of `name` (all versions and paths). */
|
|
1481
|
+
invalidate(name) {
|
|
1482
|
+
for (const [key, entry] of this.#entries) {
|
|
1483
|
+
if (entry.name === name) this.#entries.delete(key);
|
|
1484
|
+
}
|
|
1485
|
+
for (const key of [...this.#inflight.keys()]) {
|
|
1486
|
+
if (keyName(key) === name) {
|
|
1487
|
+
this.#inflight.delete(key);
|
|
1488
|
+
this.#generation++;
|
|
1489
|
+
}
|
|
1490
|
+
}
|
|
1491
|
+
}
|
|
1492
|
+
/** Drops every cached entry. */
|
|
1493
|
+
clear() {
|
|
1494
|
+
this.#entries.clear();
|
|
1495
|
+
this.#inflight.clear();
|
|
1496
|
+
this.#generation++;
|
|
1497
|
+
}
|
|
1498
|
+
/** Counters and current size. */
|
|
1499
|
+
stats() {
|
|
1500
|
+
return {
|
|
1501
|
+
hits: this.#hits,
|
|
1502
|
+
misses: this.#misses,
|
|
1503
|
+
evictions: this.#evictions,
|
|
1504
|
+
refreshes: this.#refreshes,
|
|
1505
|
+
size: this.#entries.size
|
|
1506
|
+
};
|
|
1507
|
+
}
|
|
1508
|
+
};
|
|
1509
|
+
function cacheKey(name, options) {
|
|
1510
|
+
return JSON.stringify([name, options.path ?? null, options.version ?? null]);
|
|
1511
|
+
}
|
|
1512
|
+
function keyName(key) {
|
|
1513
|
+
return JSON.parse(key)[0];
|
|
1514
|
+
}
|
|
1515
|
+
function stripSignal(options) {
|
|
1516
|
+
const { signal: _signal, ...rest } = options;
|
|
1517
|
+
return rest;
|
|
1518
|
+
}
|
|
1519
|
+
|
|
1520
|
+
// src/models.ts
|
|
1521
|
+
var API_VERSION = "2017-10-17";
|
|
1522
|
+
var AWSCURRENT = "AWSCURRENT";
|
|
1523
|
+
var AWSPREVIOUS = "AWSPREVIOUS";
|
|
1524
|
+
var AWSPENDING = "AWSPENDING";
|
|
1525
|
+
var BATCH_GET_MAX_IDS = 20;
|
|
1526
|
+
function toAwsTags(tags) {
|
|
1527
|
+
return Object.entries(tags).map(([Key, Value]) => ({ Key, Value }));
|
|
1528
|
+
}
|
|
1529
|
+
function fromAwsTags(tags) {
|
|
1530
|
+
const out = {};
|
|
1531
|
+
for (const t of tags ?? []) if (t.Key !== void 0) out[t.Key] = t.Value ?? "";
|
|
1532
|
+
return out;
|
|
1533
|
+
}
|
|
1534
|
+
function encodeValue(value) {
|
|
1535
|
+
if (typeof value === "string") return { SecretString: value };
|
|
1536
|
+
if (value instanceof Uint8Array) return { SecretBinary: value };
|
|
1537
|
+
let json;
|
|
1538
|
+
try {
|
|
1539
|
+
json = JSON.stringify(value);
|
|
1540
|
+
} catch {
|
|
1541
|
+
json = void 0;
|
|
1542
|
+
}
|
|
1543
|
+
if (json === void 0) throw new chunkZLYHN4AI_cjs.ValidationError("secret value must be JSON-serialisable");
|
|
1544
|
+
return { SecretString: json };
|
|
1545
|
+
}
|
|
1546
|
+
function encodeBytes(bytes) {
|
|
1547
|
+
try {
|
|
1548
|
+
return { SecretString: new TextDecoder("utf-8", { fatal: true }).decode(bytes) };
|
|
1549
|
+
} catch {
|
|
1550
|
+
return { SecretBinary: bytes };
|
|
1551
|
+
}
|
|
1552
|
+
}
|
|
1553
|
+
function opt(key, value) {
|
|
1554
|
+
return value === void 0 || value === null ? {} : { [key]: value };
|
|
1555
|
+
}
|
|
1556
|
+
function toSecretValue(out) {
|
|
1557
|
+
const binary = out.SecretBinary !== void 0;
|
|
1558
|
+
const raw = binary ? out.SecretBinary : out.SecretString ?? "";
|
|
1559
|
+
return {
|
|
1560
|
+
arn: out.ARN ?? "",
|
|
1561
|
+
name: out.Name ?? "",
|
|
1562
|
+
...opt("versionId", out.VersionId),
|
|
1563
|
+
versionStages: [...out.VersionStages ?? []],
|
|
1564
|
+
...opt("createdDate", out.CreatedDate),
|
|
1565
|
+
binary,
|
|
1566
|
+
value: new chunkZLYHN4AI_cjs.SecretValue(raw, out.VersionId ?? void 0)
|
|
1567
|
+
};
|
|
1568
|
+
}
|
|
1569
|
+
function toRotationRules(r) {
|
|
1570
|
+
if (r === void 0 || r === null) return void 0;
|
|
1571
|
+
return {
|
|
1572
|
+
...opt("automaticallyAfterDays", r.AutomaticallyAfterDays),
|
|
1573
|
+
...opt("duration", r.Duration),
|
|
1574
|
+
...opt("scheduleExpression", r.ScheduleExpression)
|
|
1575
|
+
};
|
|
1576
|
+
}
|
|
1577
|
+
function toReplication(r) {
|
|
1578
|
+
return {
|
|
1579
|
+
...opt("region", r.Region),
|
|
1580
|
+
...opt("kmsKeyId", r.KmsKeyId),
|
|
1581
|
+
...opt("status", r.Status),
|
|
1582
|
+
...opt("statusMessage", r.StatusMessage),
|
|
1583
|
+
...opt("lastAccessedDate", r.LastAccessedDate)
|
|
1584
|
+
};
|
|
1585
|
+
}
|
|
1586
|
+
function toDescription(out) {
|
|
1587
|
+
const stages = {};
|
|
1588
|
+
for (const [id, list] of Object.entries(out.SecretVersionsToStages ?? {})) stages[id] = [...list];
|
|
1589
|
+
for (const [id, list] of Object.entries(out.VersionIdsToStages ?? {})) stages[id] = [...list];
|
|
1590
|
+
return {
|
|
1591
|
+
arn: out.ARN ?? "",
|
|
1592
|
+
name: out.Name ?? "",
|
|
1593
|
+
...opt("description", out.Description),
|
|
1594
|
+
...opt("kmsKeyId", out.KmsKeyId),
|
|
1595
|
+
rotationEnabled: out.RotationEnabled === true,
|
|
1596
|
+
...opt("rotationLambdaArn", out.RotationLambdaARN),
|
|
1597
|
+
...opt("rotationRules", toRotationRules(out.RotationRules)),
|
|
1598
|
+
...opt("lastRotatedDate", out.LastRotatedDate),
|
|
1599
|
+
...opt("lastChangedDate", out.LastChangedDate),
|
|
1600
|
+
...opt("lastAccessedDate", out.LastAccessedDate),
|
|
1601
|
+
...opt("deletedDate", out.DeletedDate),
|
|
1602
|
+
...opt("nextRotationDate", out.NextRotationDate),
|
|
1603
|
+
...opt("createdDate", out.CreatedDate),
|
|
1604
|
+
...opt("primaryRegion", out.PrimaryRegion),
|
|
1605
|
+
...opt("owningService", out.OwningService),
|
|
1606
|
+
tags: fromAwsTags(out.Tags),
|
|
1607
|
+
versionIdsToStages: stages,
|
|
1608
|
+
replicationStatus: (out.ReplicationStatus ?? []).map(toReplication)
|
|
1609
|
+
};
|
|
1610
|
+
}
|
|
1611
|
+
function toVersion(v) {
|
|
1612
|
+
return {
|
|
1613
|
+
versionId: v.VersionId ?? "",
|
|
1614
|
+
versionStages: [...v.VersionStages ?? []],
|
|
1615
|
+
...opt("createdDate", v.CreatedDate),
|
|
1616
|
+
...opt("lastAccessedDate", v.LastAccessedDate),
|
|
1617
|
+
kmsKeyIds: [...v.KmsKeyIds ?? []]
|
|
1618
|
+
};
|
|
1619
|
+
}
|
|
1620
|
+
function toBatchError(e) {
|
|
1621
|
+
return {
|
|
1622
|
+
...opt("secretId", e.SecretId),
|
|
1623
|
+
...opt("errorCode", e.ErrorCode),
|
|
1624
|
+
...opt("message", e.Message)
|
|
1625
|
+
};
|
|
1626
|
+
}
|
|
1627
|
+
function toPolicyError(e) {
|
|
1628
|
+
return { ...opt("checkName", e.CheckName), ...opt("errorMessage", e.ErrorMessage) };
|
|
1629
|
+
}
|
|
1630
|
+
function parsePolicy(text) {
|
|
1631
|
+
if (text === void 0 || text === "") return void 0;
|
|
1632
|
+
try {
|
|
1633
|
+
const parsed = JSON.parse(text);
|
|
1634
|
+
return typeof parsed === "object" && parsed !== null && !Array.isArray(parsed) ? parsed : void 0;
|
|
1635
|
+
} catch {
|
|
1636
|
+
return void 0;
|
|
1637
|
+
}
|
|
1638
|
+
}
|
|
1639
|
+
function toAwsFilters(filters) {
|
|
1640
|
+
return filters.map((f) => ({ Key: f.key, Values: [...f.values] }));
|
|
1641
|
+
}
|
|
1642
|
+
function hasMore(token) {
|
|
1643
|
+
return token !== void 0 && token !== null && token !== "";
|
|
1644
|
+
}
|
|
1645
|
+
|
|
1646
|
+
// src/paginator.ts
|
|
1647
|
+
var Paginator = class {
|
|
1648
|
+
#fetch;
|
|
1649
|
+
constructor(fetch) {
|
|
1650
|
+
this.#fetch = fetch;
|
|
1651
|
+
}
|
|
1652
|
+
/** Yields one array per page. */
|
|
1653
|
+
async *pages() {
|
|
1654
|
+
let token;
|
|
1655
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1656
|
+
do {
|
|
1657
|
+
const page = await this.#fetch(token);
|
|
1658
|
+
yield page.items;
|
|
1659
|
+
token = page.nextToken;
|
|
1660
|
+
if (token !== void 0) {
|
|
1661
|
+
if (seen.has(token)) return;
|
|
1662
|
+
seen.add(token);
|
|
1663
|
+
}
|
|
1664
|
+
} while (token !== void 0);
|
|
1665
|
+
}
|
|
1666
|
+
async *[Symbol.asyncIterator]() {
|
|
1667
|
+
for await (const page of this.pages()) yield* page;
|
|
1668
|
+
}
|
|
1669
|
+
/** Collects every item of every page. */
|
|
1670
|
+
async toArray() {
|
|
1671
|
+
const out = [];
|
|
1672
|
+
for await (const page of this.pages()) out.push(...page);
|
|
1673
|
+
return out;
|
|
1674
|
+
}
|
|
1675
|
+
};
|
|
1676
|
+
|
|
1677
|
+
// src/secret-cache.ts
|
|
1678
|
+
var AWS_SECRET_CACHE_DEFAULTS = Object.freeze({ ttlMs: 36e5, maxEntries: 1024 });
|
|
1679
|
+
var REFRESH_RETRY_MS = 1e3;
|
|
1680
|
+
var AwsSecretCache = class {
|
|
1681
|
+
/** The AWS caching-client defaults (TTL 1 h, 1 024 entries). */
|
|
1682
|
+
static awsDefaults() {
|
|
1683
|
+
return { ...AWS_SECRET_CACHE_DEFAULTS };
|
|
1684
|
+
}
|
|
1685
|
+
#source;
|
|
1686
|
+
#ttl;
|
|
1687
|
+
#max;
|
|
1688
|
+
#stage;
|
|
1689
|
+
#clock;
|
|
1690
|
+
#onRefreshError;
|
|
1691
|
+
#entries = /* @__PURE__ */ new Map();
|
|
1692
|
+
#inflight = /* @__PURE__ */ new Map();
|
|
1693
|
+
#hits = 0;
|
|
1694
|
+
#misses = 0;
|
|
1695
|
+
#refreshes = 0;
|
|
1696
|
+
#versionChanges = 0;
|
|
1697
|
+
#evictions = 0;
|
|
1698
|
+
constructor(source, options = {}) {
|
|
1699
|
+
this.#source = source;
|
|
1700
|
+
this.#ttl = options.ttlMs ?? AWS_SECRET_CACHE_DEFAULTS.ttlMs;
|
|
1701
|
+
this.#max = options.maxEntries ?? AWS_SECRET_CACHE_DEFAULTS.maxEntries;
|
|
1702
|
+
this.#stage = options.versionStage ?? AWSCURRENT;
|
|
1703
|
+
this.#clock = options.clock ?? Date.now;
|
|
1704
|
+
this.#onRefreshError = options.onRefreshError;
|
|
1705
|
+
if (!(this.#ttl > 0)) throw new chunkZLYHN4AI_cjs.ValidationError("AwsSecretCache: ttlMs must be > 0");
|
|
1706
|
+
if (!Number.isInteger(this.#max) || this.#max < 1) {
|
|
1707
|
+
throw new chunkZLYHN4AI_cjs.ValidationError("AwsSecretCache: maxEntries must be >= 1");
|
|
1708
|
+
}
|
|
1709
|
+
if (this.#stage.trim() === "") {
|
|
1710
|
+
throw new chunkZLYHN4AI_cjs.ValidationError("AwsSecretCache: versionStage must not be empty");
|
|
1711
|
+
}
|
|
1712
|
+
}
|
|
1713
|
+
/** The cached value of `secretId` at the stage (default `AWSCURRENT`). */
|
|
1714
|
+
async getSecretValue(secretId, options = {}) {
|
|
1715
|
+
const stage = options.versionStage ?? this.#stage;
|
|
1716
|
+
const key = keyOf(secretId, stage);
|
|
1717
|
+
const entry = this.#entries.get(key);
|
|
1718
|
+
if (entry !== void 0) {
|
|
1719
|
+
this.#hits++;
|
|
1720
|
+
this.#entries.delete(key);
|
|
1721
|
+
this.#entries.set(key, entry);
|
|
1722
|
+
if (this.#clock() - entry.checkedAt < this.#nextCheckAfter(entry)) return entry.value;
|
|
1723
|
+
return this.#coalesce(key, () => this.#refresh(key, entry, stage, options));
|
|
1724
|
+
}
|
|
1725
|
+
this.#misses++;
|
|
1726
|
+
return this.#coalesce(key, async () => {
|
|
1727
|
+
const value = await this.#source.getSecretValue(secretId, withStage(options, stage));
|
|
1728
|
+
this.#store(key, { secretId, value, checkedAt: this.#clock(), failures: 0 });
|
|
1729
|
+
return value;
|
|
1730
|
+
});
|
|
1731
|
+
}
|
|
1732
|
+
/** The value as text (`SecretString`, or UTF-8 of the binary). */
|
|
1733
|
+
async getSecretString(secretId, options = {}) {
|
|
1734
|
+
return (await this.getSecretValue(secretId, options)).value.reveal();
|
|
1735
|
+
}
|
|
1736
|
+
/** The value as bytes. */
|
|
1737
|
+
async getSecretBinary(secretId, options = {}) {
|
|
1738
|
+
return (await this.getSecretValue(secretId, options)).value.revealBytes();
|
|
1739
|
+
}
|
|
1740
|
+
/** Forces a refresh check now (and a fetch when the stage moved); returns the value. */
|
|
1741
|
+
async refreshNow(secretId, options = {}) {
|
|
1742
|
+
const stage = options.versionStage ?? this.#stage;
|
|
1743
|
+
const key = keyOf(secretId, stage);
|
|
1744
|
+
const entry = this.#entries.get(key);
|
|
1745
|
+
if (entry === void 0) return this.getSecretValue(secretId, options);
|
|
1746
|
+
entry.checkedAt = Number.NEGATIVE_INFINITY;
|
|
1747
|
+
entry.failures = 0;
|
|
1748
|
+
return this.getSecretValue(secretId, options);
|
|
1749
|
+
}
|
|
1750
|
+
/** Drops every cached stage of `secretId`. */
|
|
1751
|
+
invalidate(secretId) {
|
|
1752
|
+
for (const [key, entry] of this.#entries) {
|
|
1753
|
+
if (entry.secretId === secretId) this.#entries.delete(key);
|
|
1754
|
+
}
|
|
1755
|
+
}
|
|
1756
|
+
/** Drops every entry. */
|
|
1757
|
+
clear() {
|
|
1758
|
+
this.#entries.clear();
|
|
1759
|
+
}
|
|
1760
|
+
/** Counters and current size. */
|
|
1761
|
+
stats() {
|
|
1762
|
+
return {
|
|
1763
|
+
hits: this.#hits,
|
|
1764
|
+
misses: this.#misses,
|
|
1765
|
+
refreshes: this.#refreshes,
|
|
1766
|
+
versionChanges: this.#versionChanges,
|
|
1767
|
+
evictions: this.#evictions,
|
|
1768
|
+
size: this.#entries.size
|
|
1769
|
+
};
|
|
1770
|
+
}
|
|
1771
|
+
#nextCheckAfter(entry) {
|
|
1772
|
+
if (entry.failures === 0) return this.#ttl;
|
|
1773
|
+
return Math.min(this.#ttl, REFRESH_RETRY_MS * 2 ** (entry.failures - 1));
|
|
1774
|
+
}
|
|
1775
|
+
async #refresh(key, entry, stage, options) {
|
|
1776
|
+
this.#refreshes++;
|
|
1777
|
+
try {
|
|
1778
|
+
const described = await this.#source.describeSecret(entry.secretId, signalOnly(options));
|
|
1779
|
+
const current = Object.entries(described.versionIdsToStages).find(
|
|
1780
|
+
([, stages]) => stages.includes(stage)
|
|
1781
|
+
)?.[0];
|
|
1782
|
+
let value = entry.value;
|
|
1783
|
+
if (current === void 0 || current !== entry.value.versionId) {
|
|
1784
|
+
value = await this.#source.getSecretValue(entry.secretId, withStage(options, stage));
|
|
1785
|
+
this.#versionChanges++;
|
|
1786
|
+
}
|
|
1787
|
+
this.#store(key, { secretId: entry.secretId, value, checkedAt: this.#clock(), failures: 0 });
|
|
1788
|
+
return value;
|
|
1789
|
+
} catch (err) {
|
|
1790
|
+
entry.failures++;
|
|
1791
|
+
entry.checkedAt = this.#clock();
|
|
1792
|
+
try {
|
|
1793
|
+
this.#onRefreshError?.(err);
|
|
1794
|
+
} catch {
|
|
1795
|
+
}
|
|
1796
|
+
return entry.value;
|
|
1797
|
+
}
|
|
1798
|
+
}
|
|
1799
|
+
#coalesce(key, load) {
|
|
1800
|
+
const pending = this.#inflight.get(key);
|
|
1801
|
+
if (pending !== void 0) return pending;
|
|
1802
|
+
const promise = load().finally(() => {
|
|
1803
|
+
this.#inflight.delete(key);
|
|
1804
|
+
});
|
|
1805
|
+
this.#inflight.set(key, promise);
|
|
1806
|
+
return promise;
|
|
1807
|
+
}
|
|
1808
|
+
#store(key, entry) {
|
|
1809
|
+
this.#entries.delete(key);
|
|
1810
|
+
this.#entries.set(key, entry);
|
|
1811
|
+
while (this.#entries.size > this.#max) {
|
|
1812
|
+
const oldest = this.#entries.keys().next().value;
|
|
1813
|
+
this.#entries.delete(oldest);
|
|
1814
|
+
this.#evictions++;
|
|
1815
|
+
}
|
|
1816
|
+
}
|
|
1817
|
+
};
|
|
1818
|
+
function keyOf(secretId, stage) {
|
|
1819
|
+
return JSON.stringify([secretId, stage]);
|
|
1820
|
+
}
|
|
1821
|
+
function signalOnly(options) {
|
|
1822
|
+
return options.signal === void 0 ? {} : { signal: options.signal };
|
|
1823
|
+
}
|
|
1824
|
+
function withStage(options, stage) {
|
|
1825
|
+
return { ...signalOnly(options), versionStage: stage };
|
|
1826
|
+
}
|
|
1827
|
+
|
|
1828
|
+
// src/provider.ts
|
|
1829
|
+
var MISSING_BATCH_CODES = /* @__PURE__ */ new Set([
|
|
1830
|
+
"ResourceNotFoundException",
|
|
1831
|
+
"InvalidRequestException"
|
|
1832
|
+
]);
|
|
1833
|
+
function trimSlashes(path) {
|
|
1834
|
+
return path.replace(/^\/+|\/+$/g, "");
|
|
1835
|
+
}
|
|
1836
|
+
function fullName(name, path) {
|
|
1837
|
+
const p = path === void 0 ? "" : trimSlashes(path);
|
|
1838
|
+
return p === "" ? name : `${p}/${name}`;
|
|
1839
|
+
}
|
|
1840
|
+
function signalOnly2(options) {
|
|
1841
|
+
return options.signal === void 0 ? {} : { signal: options.signal };
|
|
1842
|
+
}
|
|
1843
|
+
function isMissing(err) {
|
|
1844
|
+
return chunkZLYHN4AI_cjs.isAwsSecretsManagerError(err, chunkZLYHN4AI_cjs.ErrorCode.NotFound) || // InvalidRequestException: the secret is scheduled for deletion.
|
|
1845
|
+
chunkZLYHN4AI_cjs.isAwsSecretsManagerError(err, chunkZLYHN4AI_cjs.ErrorCode.Conflict) && err.message.includes("InvalidRequestException");
|
|
1846
|
+
}
|
|
1847
|
+
function toMetadata(d) {
|
|
1848
|
+
const current = Object.entries(d.versionIdsToStages).find(
|
|
1849
|
+
([, stages]) => stages.includes("AWSCURRENT")
|
|
1850
|
+
)?.[0];
|
|
1851
|
+
const slash = d.name.lastIndexOf("/");
|
|
1852
|
+
const extra = { arn: d.arn, rotationEnabled: String(d.rotationEnabled) };
|
|
1853
|
+
if (d.description !== void 0) extra.description = d.description;
|
|
1854
|
+
if (d.kmsKeyId !== void 0) extra.kmsKeyId = d.kmsKeyId;
|
|
1855
|
+
if (d.nextRotationDate !== void 0) extra.nextRotationDate = d.nextRotationDate.toISOString();
|
|
1856
|
+
if (d.deletedDate !== void 0) extra.deletedDate = d.deletedDate.toISOString();
|
|
1857
|
+
if (d.primaryRegion !== void 0) extra.primaryRegion = d.primaryRegion;
|
|
1858
|
+
return {
|
|
1859
|
+
name: d.name,
|
|
1860
|
+
...slash > 0 ? { path: d.name.slice(0, slash) } : {},
|
|
1861
|
+
...current === void 0 ? {} : { version: current },
|
|
1862
|
+
...d.createdDate === void 0 ? {} : { createdAt: d.createdDate },
|
|
1863
|
+
...d.lastChangedDate === void 0 ? {} : { updatedAt: d.lastChangedDate },
|
|
1864
|
+
tags: { ...d.tags },
|
|
1865
|
+
versions: Object.keys(d.versionIdsToStages).length,
|
|
1866
|
+
extra
|
|
1867
|
+
};
|
|
1868
|
+
}
|
|
1869
|
+
var AwsSecretsManagerSecretsProvider = class extends chunkZLYHN4AI_cjs.BaseSecretsProvider {
|
|
1870
|
+
/** Capabilities declared to the conformance runner. */
|
|
1871
|
+
static capabilities = ["write", "versions", "delete"];
|
|
1872
|
+
#client;
|
|
1873
|
+
#recoveryWindowDays;
|
|
1874
|
+
#onClose;
|
|
1875
|
+
constructor(client, options = {}, onClose) {
|
|
1876
|
+
super();
|
|
1877
|
+
this.#client = client;
|
|
1878
|
+
const days = options.recoveryWindowDays ?? client.config.recoveryWindowDays;
|
|
1879
|
+
if (!Number.isInteger(days) || days < 7 || days > 30) {
|
|
1880
|
+
throw new chunkZLYHN4AI_cjs.ValidationError("secrets: recoveryWindowDays must be an integer from 7 to 30");
|
|
1881
|
+
}
|
|
1882
|
+
this.#recoveryWindowDays = days;
|
|
1883
|
+
this.#onClose = onClose;
|
|
1884
|
+
}
|
|
1885
|
+
/** The client this provider uses. */
|
|
1886
|
+
get client() {
|
|
1887
|
+
return this.#client;
|
|
1888
|
+
}
|
|
1889
|
+
async fetchSecret(name, options) {
|
|
1890
|
+
try {
|
|
1891
|
+
const out = await this.#client.getSecretValue(fullName(name, options.path), {
|
|
1892
|
+
...signalOnly2(options),
|
|
1893
|
+
...options.version === void 0 ? {} : { versionId: options.version }
|
|
1894
|
+
});
|
|
1895
|
+
return out.value;
|
|
1896
|
+
} catch (err) {
|
|
1897
|
+
if (isMissing(err)) return null;
|
|
1898
|
+
throw err;
|
|
1899
|
+
}
|
|
1900
|
+
}
|
|
1901
|
+
async listSecrets(prefixOrPath, options) {
|
|
1902
|
+
const prefix = prefixOrPath ?? "";
|
|
1903
|
+
return (await this.#listDescriptions(prefix, options)).map(toMetadata);
|
|
1904
|
+
}
|
|
1905
|
+
async #listDescriptions(prefix, options) {
|
|
1906
|
+
const all = await this.#client.listSecrets({
|
|
1907
|
+
...signalOnly2(options),
|
|
1908
|
+
...prefix === "" ? {} : { filters: [{ key: "name", values: [prefix] }] }
|
|
1909
|
+
}).toArray();
|
|
1910
|
+
return all.filter((d) => d.name.startsWith(prefix) && d.deletedDate === void 0);
|
|
1911
|
+
}
|
|
1912
|
+
/** Every secret directly under `path` (non-recursive), keyed by full name. */
|
|
1913
|
+
async getAll(path, options = {}) {
|
|
1914
|
+
chunkZLYHN4AI_cjs.throwIfAborted(options.signal, "secrets.getAll");
|
|
1915
|
+
const base = path === void 0 ? "" : trimSlashes(path);
|
|
1916
|
+
const prefix = base === "" ? "" : `${base}/`;
|
|
1917
|
+
const names = (await this.#listDescriptions(prefix, options)).map((d) => d.name).filter((n) => !n.slice(prefix.length).includes("/")).sort();
|
|
1918
|
+
return this.getMany(names, options);
|
|
1919
|
+
}
|
|
1920
|
+
/**
|
|
1921
|
+
* Present secrets in request order (`BatchGetSecretValue` in chunks of 20; per-name reads when
|
|
1922
|
+
* a `version` is requested).
|
|
1923
|
+
*/
|
|
1924
|
+
async getMany(names, options = {}) {
|
|
1925
|
+
if (options.version !== void 0) return super.getMany(names, options);
|
|
1926
|
+
chunkZLYHN4AI_cjs.throwIfAborted(options.signal, "secrets.getMany");
|
|
1927
|
+
const unique = [...new Set(names)];
|
|
1928
|
+
const byFull = /* @__PURE__ */ new Map();
|
|
1929
|
+
for (const n of unique) byFull.set(fullName(n, options.path), n);
|
|
1930
|
+
const found = /* @__PURE__ */ new Map();
|
|
1931
|
+
const ids = [...byFull.keys()];
|
|
1932
|
+
for (let i = 0; i < ids.length; i += BATCH_GET_MAX_IDS) {
|
|
1933
|
+
const chunk = ids.slice(i, i + BATCH_GET_MAX_IDS);
|
|
1934
|
+
const result = await this.#client.batchGetSecretValue(chunk, signalOnly2(options));
|
|
1935
|
+
for (const e of result.errors) {
|
|
1936
|
+
if (e.errorCode !== void 0 && MISSING_BATCH_CODES.has(e.errorCode)) continue;
|
|
1937
|
+
const code = (e.errorCode === void 0 ? void 0 : AWS_ERROR_CODES[e.errorCode]) ?? chunkZLYHN4AI_cjs.ErrorCode.Unavailable;
|
|
1938
|
+
throw chunkZLYHN4AI_cjs.errorForCode(code, `secrets.getMany ${e.secretId ?? ""}: ${e.errorCode ?? "error"}`);
|
|
1939
|
+
}
|
|
1940
|
+
for (const v of result.secretValues) {
|
|
1941
|
+
const requested = byFull.get(v.name) ?? byFull.get(v.arn);
|
|
1942
|
+
if (requested !== void 0) found.set(requested, v.value);
|
|
1943
|
+
}
|
|
1944
|
+
}
|
|
1945
|
+
const ordered = /* @__PURE__ */ new Map();
|
|
1946
|
+
for (const n of unique) {
|
|
1947
|
+
const value = found.get(n);
|
|
1948
|
+
if (value !== void 0) ordered.set(n, value);
|
|
1949
|
+
}
|
|
1950
|
+
return ordered;
|
|
1951
|
+
}
|
|
1952
|
+
async putSecret(name, value, options) {
|
|
1953
|
+
if (options.cas !== void 0) {
|
|
1954
|
+
throw new chunkZLYHN4AI_cjs.ValidationError(
|
|
1955
|
+
`secrets.set ${name}: AWS Secrets Manager has no compare-and-set (cas)`
|
|
1956
|
+
);
|
|
1957
|
+
}
|
|
1958
|
+
const id = fullName(name, options.path);
|
|
1959
|
+
const encoded = encodeBytes(value);
|
|
1960
|
+
const input = "SecretString" in encoded ? encoded.SecretString : encoded.SecretBinary;
|
|
1961
|
+
const call = signalOnly2(options);
|
|
1962
|
+
const putExisting = async () => {
|
|
1963
|
+
const out = await this.#client.putSecretValue(id, input, call);
|
|
1964
|
+
if (options.tags !== void 0 && Object.keys(options.tags).length > 0) {
|
|
1965
|
+
await this.#client.tagResource(id, options.tags, call);
|
|
1966
|
+
}
|
|
1967
|
+
if (options.description !== void 0) {
|
|
1968
|
+
await this.#client.updateSecret(id, { ...call, description: options.description });
|
|
1969
|
+
}
|
|
1970
|
+
return out.versionId;
|
|
1971
|
+
};
|
|
1972
|
+
try {
|
|
1973
|
+
return await putExisting();
|
|
1974
|
+
} catch (err) {
|
|
1975
|
+
if (!chunkZLYHN4AI_cjs.isAwsSecretsManagerError(err, chunkZLYHN4AI_cjs.ErrorCode.NotFound)) throw err;
|
|
1976
|
+
}
|
|
1977
|
+
try {
|
|
1978
|
+
const created = await this.#client.createSecret(id, input, {
|
|
1979
|
+
...call,
|
|
1980
|
+
...options.description === void 0 ? {} : { description: options.description },
|
|
1981
|
+
...options.tags === void 0 ? {} : { tags: options.tags }
|
|
1982
|
+
});
|
|
1983
|
+
return created.versionId ?? "";
|
|
1984
|
+
} catch (err) {
|
|
1985
|
+
if (chunkZLYHN4AI_cjs.isAwsSecretsManagerError(err, chunkZLYHN4AI_cjs.ErrorCode.Conflict) && err.message.includes("ResourceExistsException")) {
|
|
1986
|
+
return await putExisting();
|
|
1987
|
+
}
|
|
1988
|
+
throw err;
|
|
1989
|
+
}
|
|
1990
|
+
}
|
|
1991
|
+
async removeSecret(name, options) {
|
|
1992
|
+
if (options.versions !== void 0) {
|
|
1993
|
+
throw new chunkZLYHN4AI_cjs.ValidationError(
|
|
1994
|
+
`secrets.delete ${name}: AWS Secrets Manager cannot delete single versions; use updateSecretVersionStage`
|
|
1995
|
+
);
|
|
1996
|
+
}
|
|
1997
|
+
const id = fullName(name, options.path);
|
|
1998
|
+
const call = signalOnly2(options);
|
|
1999
|
+
const meta = await this.#describe(id, call);
|
|
2000
|
+
if (meta === null) throw new chunkZLYHN4AI_cjs.NotFoundError(`secrets.delete ${id}: not found`);
|
|
2001
|
+
await this.#client.deleteSecret(
|
|
2002
|
+
id,
|
|
2003
|
+
options.permanent === true ? { ...call, forceDeleteWithoutRecovery: true } : { ...call, recoveryWindowDays: this.#recoveryWindowDays }
|
|
2004
|
+
);
|
|
2005
|
+
}
|
|
2006
|
+
async fetchMetadata(name, options) {
|
|
2007
|
+
const d = await this.#describe(fullName(name, options.path), signalOnly2(options));
|
|
2008
|
+
return d === null ? null : toMetadata(d);
|
|
2009
|
+
}
|
|
2010
|
+
/** DescribeSecret; `null` when missing or scheduled for deletion. */
|
|
2011
|
+
async #describe(id, options) {
|
|
2012
|
+
try {
|
|
2013
|
+
const d = await this.#client.describeSecret(id, options);
|
|
2014
|
+
return d.deletedDate === void 0 ? d : null;
|
|
2015
|
+
} catch (err) {
|
|
2016
|
+
if (isMissing(err)) return null;
|
|
2017
|
+
throw err;
|
|
2018
|
+
}
|
|
2019
|
+
}
|
|
2020
|
+
/** Stops the watchers of this provider. Idempotent. */
|
|
2021
|
+
async close() {
|
|
2022
|
+
await super.close();
|
|
2023
|
+
this.#onClose?.();
|
|
2024
|
+
}
|
|
2025
|
+
};
|
|
2026
|
+
|
|
2027
|
+
// src/client.ts
|
|
2028
|
+
var EMULATOR_GAPS = /* @__PURE__ */ new Set(["validateResourcePolicy"]);
|
|
2029
|
+
var HEALTH_TIMEOUT_MS = 5e3;
|
|
2030
|
+
var AwsSecretsManagerClient = class _AwsSecretsManagerClient {
|
|
2031
|
+
/** The immutable configuration. */
|
|
2032
|
+
config;
|
|
2033
|
+
#sdk;
|
|
2034
|
+
#ownsSdk;
|
|
2035
|
+
#handler;
|
|
2036
|
+
#sdkConfig;
|
|
2037
|
+
#healthSdk;
|
|
2038
|
+
#providers = /* @__PURE__ */ new Set();
|
|
2039
|
+
#closed = false;
|
|
2040
|
+
/** Accepts a {@link AwsSecretsManagerConfig} or plain options. */
|
|
2041
|
+
constructor(config = {}, internals = {}) {
|
|
2042
|
+
const cfg = AwsSecretsManagerConfig.from(config);
|
|
2043
|
+
this.config = cfg;
|
|
2044
|
+
if (cfg.sdkClient !== void 0) {
|
|
2045
|
+
this.#sdk = cfg.sdkClient;
|
|
2046
|
+
this.#ownsSdk = false;
|
|
2047
|
+
return;
|
|
2048
|
+
}
|
|
2049
|
+
const handler = new GrowHttpHandler({
|
|
2050
|
+
config: cfg,
|
|
2051
|
+
...internals.dispatcher === void 0 ? {} : { dispatcher: internals.dispatcher }
|
|
2052
|
+
});
|
|
2053
|
+
this.#handler = handler;
|
|
2054
|
+
const credentials = buildCredentials(cfg, handler);
|
|
2055
|
+
this.#sdkConfig = {
|
|
2056
|
+
maxAttempts: cfg.retry.maxRetries + 1,
|
|
2057
|
+
retryMode: "standard",
|
|
2058
|
+
requestHandler: handler,
|
|
2059
|
+
...cfg.region === void 0 ? {} : { region: cfg.region },
|
|
2060
|
+
...cfg.endpoint === void 0 ? {} : { endpoint: cfg.endpoint },
|
|
2061
|
+
...cfg.profile === void 0 ? {} : { profile: cfg.profile },
|
|
2062
|
+
...credentials === void 0 ? {} : { credentials }
|
|
2063
|
+
};
|
|
2064
|
+
this.#sdk = new clientSecretsManager.SecretsManagerClient(this.#sdkConfig);
|
|
2065
|
+
this.#ownsSdk = true;
|
|
2066
|
+
}
|
|
2067
|
+
/** Builds a client from `GROW_AWS_SECRETS_MANAGER_*` and the standard AWS environment variables. */
|
|
2068
|
+
static fromEnv(overrides = {}) {
|
|
2069
|
+
return new _AwsSecretsManagerClient(AwsSecretsManagerConfig.fromEnv(overrides));
|
|
2070
|
+
}
|
|
2071
|
+
/** Wraps an existing AWS SDK client; `close()` leaves it open. */
|
|
2072
|
+
static withSdkClient(sdkClient, options = {}) {
|
|
2073
|
+
return new _AwsSecretsManagerClient({ ...options, sdkClient });
|
|
2074
|
+
}
|
|
2075
|
+
/** The underlying AWS SDK client (escape hatch for operations not wrapped here). */
|
|
2076
|
+
get sdk() {
|
|
2077
|
+
return this.#sdk;
|
|
2078
|
+
}
|
|
2079
|
+
/** Whether {@link close} was called. */
|
|
2080
|
+
get closed() {
|
|
2081
|
+
return this.#closed;
|
|
2082
|
+
}
|
|
2083
|
+
// ---------------------------------------------------------------------------------------
|
|
2084
|
+
// core
|
|
2085
|
+
/**
|
|
2086
|
+
* Liveness: a signed `ListSecrets {MaxResults: 1}` with a short timeout and no retries.
|
|
2087
|
+
* `ok` when AWS answers (also when the credentials are rejected: `details.auth = "failed"`),
|
|
2088
|
+
* `degraded` when throttled, `unhealthy` on HTTP 5xx, `unreachable` on network errors.
|
|
2089
|
+
* Throws only `CancelledError` (also on a closed client) and `ConfigError`.
|
|
2090
|
+
*/
|
|
2091
|
+
async health(options = {}) {
|
|
2092
|
+
try {
|
|
2093
|
+
await this.#send("health", new clientSecretsManager.ListSecretsCommand({ MaxResults: 1 }), {
|
|
2094
|
+
...options,
|
|
2095
|
+
requestTimeout: Math.min(this.config.requestTimeoutMs, HEALTH_TIMEOUT_MS),
|
|
2096
|
+
sdk: this.#healthClient()
|
|
2097
|
+
});
|
|
2098
|
+
return healthStatus("ok", {}, true);
|
|
2099
|
+
} catch (err) {
|
|
2100
|
+
const e = err;
|
|
2101
|
+
switch (e.code) {
|
|
2102
|
+
case chunkZLYHN4AI_cjs.ErrorCode.Cancelled:
|
|
2103
|
+
case chunkZLYHN4AI_cjs.ErrorCode.Config:
|
|
2104
|
+
throw e;
|
|
2105
|
+
case chunkZLYHN4AI_cjs.ErrorCode.RateLimited:
|
|
2106
|
+
return healthStatus("degraded", { code: e.code }, true);
|
|
2107
|
+
case chunkZLYHN4AI_cjs.ErrorCode.Authentication:
|
|
2108
|
+
case chunkZLYHN4AI_cjs.ErrorCode.PermissionDenied:
|
|
2109
|
+
return healthStatus("ok", { auth: "failed", code: e.code }, true);
|
|
2110
|
+
default:
|
|
2111
|
+
if (e.httpStatus === void 0) {
|
|
2112
|
+
return healthStatus("unreachable", { error: e.code }, false);
|
|
2113
|
+
}
|
|
2114
|
+
if (e.httpStatus >= 500) {
|
|
2115
|
+
return healthStatus("unhealthy", { httpStatus: e.httpStatus, error: e.code }, false);
|
|
2116
|
+
}
|
|
2117
|
+
return healthStatus("ok", { httpStatus: e.httpStatus, code: e.code }, true);
|
|
2118
|
+
}
|
|
2119
|
+
}
|
|
2120
|
+
}
|
|
2121
|
+
/**
|
|
2122
|
+
* Authenticated round trip (`ListSecrets {MaxResults: 1}`); returns the latency in ms.
|
|
2123
|
+
* `AuthenticationError` for unknown keys or bad signatures, `PermissionDeniedError` when the
|
|
2124
|
+
* principal may not call `secretsmanager:ListSecrets`.
|
|
2125
|
+
*/
|
|
2126
|
+
async ping(options = {}) {
|
|
2127
|
+
const start = performance.now();
|
|
2128
|
+
await this.#send("ping", new clientSecretsManager.ListSecretsCommand({ MaxResults: 1 }), options);
|
|
2129
|
+
return performance.now() - start;
|
|
2130
|
+
}
|
|
2131
|
+
/**
|
|
2132
|
+
* Always throws {@link UnsupportedError}: AWS Secrets Manager exposes no server version (the API
|
|
2133
|
+
* contract date is the constant `API_VERSION`).
|
|
2134
|
+
*/
|
|
2135
|
+
// eslint-disable-next-line @typescript-eslint/require-await
|
|
2136
|
+
async serverVersion(options = {}) {
|
|
2137
|
+
chunkZLYHN4AI_cjs.throwIfAborted(options.signal, "serverVersion");
|
|
2138
|
+
throw new chunkZLYHN4AI_cjs.UnsupportedError(
|
|
2139
|
+
"serverVersion: AWS Secrets Manager does not expose a server version"
|
|
2140
|
+
);
|
|
2141
|
+
}
|
|
2142
|
+
/**
|
|
2143
|
+
* Stops every watcher of the providers created by {@link secrets} and destroys the SDK client
|
|
2144
|
+
* this instance built (never a caller-supplied one). Idempotent.
|
|
2145
|
+
*/
|
|
2146
|
+
async close() {
|
|
2147
|
+
if (this.#closed) return;
|
|
2148
|
+
this.#closed = true;
|
|
2149
|
+
await Promise.all([...this.#providers].map((p) => p.close()));
|
|
2150
|
+
this.#providers.clear();
|
|
2151
|
+
if (this.#ownsSdk) {
|
|
2152
|
+
this.#sdk.destroy();
|
|
2153
|
+
this.#healthSdk?.destroy();
|
|
2154
|
+
}
|
|
2155
|
+
this.#handler?.destroy();
|
|
2156
|
+
}
|
|
2157
|
+
// ---------------------------------------------------------------------------------------
|
|
2158
|
+
// category interface
|
|
2159
|
+
/**
|
|
2160
|
+
* The {@link SecretsProvider} view (SPEC §3) of this client. `close()` of the client stops its
|
|
2161
|
+
* watchers.
|
|
2162
|
+
*/
|
|
2163
|
+
secrets(options = {}) {
|
|
2164
|
+
const provider = new AwsSecretsManagerSecretsProvider(
|
|
2165
|
+
this,
|
|
2166
|
+
options,
|
|
2167
|
+
() => this.#providers.delete(provider)
|
|
2168
|
+
);
|
|
2169
|
+
this.#providers.add(provider);
|
|
2170
|
+
return provider;
|
|
2171
|
+
}
|
|
2172
|
+
/** A version-stage aware cache with the AWS caching-client semantics (TTL 1 h, 1 024 entries). */
|
|
2173
|
+
secretCache(options = {}) {
|
|
2174
|
+
return new AwsSecretCache(this, options);
|
|
2175
|
+
}
|
|
2176
|
+
// ---------------------------------------------------------------------------------------
|
|
2177
|
+
// read
|
|
2178
|
+
/**
|
|
2179
|
+
* Reads a secret value (`GetSecretValue`), by default the `AWSCURRENT` version. `secretId` is a
|
|
2180
|
+
* name or ARN. `NotFoundError` when the secret, version or stage does not exist; `ConflictError`
|
|
2181
|
+
* when the secret is scheduled for deletion.
|
|
2182
|
+
*/
|
|
2183
|
+
async getSecretValue(secretId, options = {}) {
|
|
2184
|
+
requireId("getSecretValue", secretId);
|
|
2185
|
+
const out = await this.#send(
|
|
2186
|
+
`getSecretValue ${secretId}`,
|
|
2187
|
+
new clientSecretsManager.GetSecretValueCommand({
|
|
2188
|
+
SecretId: secretId,
|
|
2189
|
+
...options.versionId === void 0 ? {} : { VersionId: options.versionId },
|
|
2190
|
+
...options.versionStage === void 0 ? {} : { VersionStage: options.versionStage }
|
|
2191
|
+
}),
|
|
2192
|
+
options
|
|
2193
|
+
);
|
|
2194
|
+
return toSecretValue(out);
|
|
2195
|
+
}
|
|
2196
|
+
/**
|
|
2197
|
+
* Reads many secrets at once (`BatchGetSecretValue`). With a list of ids, lists longer than 20
|
|
2198
|
+
* are split and the values come back in request order; with `{ filters }` every page is read.
|
|
2199
|
+
* Per-secret failures are returned in `errors` (the call itself succeeds).
|
|
2200
|
+
*/
|
|
2201
|
+
async batchGetSecretValue(selector, options = {}) {
|
|
2202
|
+
const secretValues2 = [];
|
|
2203
|
+
const errors = [];
|
|
2204
|
+
if (Array.isArray(selector)) {
|
|
2205
|
+
const ids = selector;
|
|
2206
|
+
for (let i = 0; i < ids.length; i += BATCH_GET_MAX_IDS) {
|
|
2207
|
+
const chunk = ids.slice(i, i + BATCH_GET_MAX_IDS);
|
|
2208
|
+
const pageValues = [];
|
|
2209
|
+
let token2;
|
|
2210
|
+
do {
|
|
2211
|
+
const out = await this.#send(
|
|
2212
|
+
"batchGetSecretValue",
|
|
2213
|
+
new clientSecretsManager.BatchGetSecretValueCommand({
|
|
2214
|
+
SecretIdList: [...chunk],
|
|
2215
|
+
...token2 === void 0 ? {} : { NextToken: token2 }
|
|
2216
|
+
}),
|
|
2217
|
+
options
|
|
2218
|
+
);
|
|
2219
|
+
pageValues.push(...(out.SecretValues ?? []).map(toSecretValue));
|
|
2220
|
+
errors.push(...(out.Errors ?? []).map(toBatchError));
|
|
2221
|
+
token2 = hasMore(out.NextToken) ? out.NextToken : void 0;
|
|
2222
|
+
} while (token2 !== void 0);
|
|
2223
|
+
secretValues2.push(...orderByIds(pageValues, chunk));
|
|
2224
|
+
}
|
|
2225
|
+
return { secretValues: secretValues2, errors };
|
|
2226
|
+
}
|
|
2227
|
+
const filters = selector.filters;
|
|
2228
|
+
if (filters === void 0 || filters.length === 0) {
|
|
2229
|
+
throw new chunkZLYHN4AI_cjs.ValidationError("batchGetSecretValue: give secret ids or at least one filter");
|
|
2230
|
+
}
|
|
2231
|
+
let token;
|
|
2232
|
+
do {
|
|
2233
|
+
const input = {
|
|
2234
|
+
Filters: toAwsFilters(filters),
|
|
2235
|
+
...options.maxResults === void 0 ? {} : { MaxResults: options.maxResults },
|
|
2236
|
+
...token === void 0 ? {} : { NextToken: token }
|
|
2237
|
+
};
|
|
2238
|
+
const out = await this.#send(
|
|
2239
|
+
"batchGetSecretValue",
|
|
2240
|
+
new clientSecretsManager.BatchGetSecretValueCommand(input),
|
|
2241
|
+
options
|
|
2242
|
+
);
|
|
2243
|
+
secretValues2.push(...(out.SecretValues ?? []).map(toSecretValue));
|
|
2244
|
+
errors.push(...(out.Errors ?? []).map(toBatchError));
|
|
2245
|
+
token = hasMore(out.NextToken) ? out.NextToken : void 0;
|
|
2246
|
+
} while (token !== void 0);
|
|
2247
|
+
return { secretValues: secretValues2, errors };
|
|
2248
|
+
}
|
|
2249
|
+
/** Metadata of a secret (`DescribeSecret`), never the value. */
|
|
2250
|
+
async describeSecret(secretId, options = {}) {
|
|
2251
|
+
requireId("describeSecret", secretId);
|
|
2252
|
+
const out = await this.#send(
|
|
2253
|
+
`describeSecret ${secretId}`,
|
|
2254
|
+
new clientSecretsManager.DescribeSecretCommand({ SecretId: secretId }),
|
|
2255
|
+
options
|
|
2256
|
+
);
|
|
2257
|
+
return toDescription(out);
|
|
2258
|
+
}
|
|
2259
|
+
/**
|
|
2260
|
+
* Lists secrets (`ListSecrets`) lazily across all pages: `for await (const s of
|
|
2261
|
+
* client.listSecrets())` or `await client.listSecrets().toArray()`.
|
|
2262
|
+
*/
|
|
2263
|
+
listSecrets(options = {}) {
|
|
2264
|
+
return new Paginator(async (token) => {
|
|
2265
|
+
const out = await this.#send(
|
|
2266
|
+
"listSecrets",
|
|
2267
|
+
new clientSecretsManager.ListSecretsCommand({
|
|
2268
|
+
...options.filters === void 0 || options.filters.length === 0 ? {} : { Filters: toAwsFilters(options.filters) },
|
|
2269
|
+
...options.includePlannedDeletion === void 0 ? {} : { IncludePlannedDeletion: options.includePlannedDeletion },
|
|
2270
|
+
...options.sortOrder === void 0 ? {} : { SortOrder: options.sortOrder },
|
|
2271
|
+
...options.maxResults === void 0 ? {} : { MaxResults: options.maxResults },
|
|
2272
|
+
...token === void 0 ? {} : { NextToken: token }
|
|
2273
|
+
}),
|
|
2274
|
+
options
|
|
2275
|
+
);
|
|
2276
|
+
return {
|
|
2277
|
+
items: (out.SecretList ?? []).map(toDescription),
|
|
2278
|
+
nextToken: hasMore(out.NextToken) ? out.NextToken : void 0
|
|
2279
|
+
};
|
|
2280
|
+
});
|
|
2281
|
+
}
|
|
2282
|
+
/** Lists the versions of a secret (`ListSecretVersionIds`) lazily across all pages. */
|
|
2283
|
+
listSecretVersionIds(secretId, options = {}) {
|
|
2284
|
+
requireId("listSecretVersionIds", secretId);
|
|
2285
|
+
return new Paginator(async (token) => {
|
|
2286
|
+
const out = await this.#send(
|
|
2287
|
+
`listSecretVersionIds ${secretId}`,
|
|
2288
|
+
new clientSecretsManager.ListSecretVersionIdsCommand({
|
|
2289
|
+
SecretId: secretId,
|
|
2290
|
+
...options.includeDeprecated === void 0 ? {} : { IncludeDeprecated: options.includeDeprecated },
|
|
2291
|
+
...options.maxResults === void 0 ? {} : { MaxResults: options.maxResults },
|
|
2292
|
+
...token === void 0 ? {} : { NextToken: token }
|
|
2293
|
+
}),
|
|
2294
|
+
options
|
|
2295
|
+
);
|
|
2296
|
+
return {
|
|
2297
|
+
items: (out.Versions ?? []).map(toVersion),
|
|
2298
|
+
nextToken: hasMore(out.NextToken) ? out.NextToken : void 0
|
|
2299
|
+
};
|
|
2300
|
+
});
|
|
2301
|
+
}
|
|
2302
|
+
// ---------------------------------------------------------------------------------------
|
|
2303
|
+
// write
|
|
2304
|
+
/**
|
|
2305
|
+
* Creates a secret (`CreateSecret`). `value`: string → `SecretString`, bytes → `SecretBinary`,
|
|
2306
|
+
* object → JSON `SecretString`, `undefined`/`null` → a secret without a version.
|
|
2307
|
+
* `ConflictError` when the name exists (or is scheduled for deletion).
|
|
2308
|
+
*/
|
|
2309
|
+
async createSecret(name, value, options = {}) {
|
|
2310
|
+
requireId("createSecret", name);
|
|
2311
|
+
const input = {
|
|
2312
|
+
Name: name,
|
|
2313
|
+
...value === void 0 || value === null ? {} : encodeValue(value),
|
|
2314
|
+
...options.description === void 0 ? {} : { Description: options.description },
|
|
2315
|
+
...options.kmsKeyId === void 0 ? {} : { KmsKeyId: options.kmsKeyId },
|
|
2316
|
+
...options.tags === void 0 ? {} : { Tags: toAwsTags(options.tags) },
|
|
2317
|
+
...options.clientRequestToken === void 0 ? {} : { ClientRequestToken: options.clientRequestToken },
|
|
2318
|
+
...options.addReplicaRegions === void 0 ? {} : {
|
|
2319
|
+
AddReplicaRegions: options.addReplicaRegions.map((r) => ({
|
|
2320
|
+
Region: r.region,
|
|
2321
|
+
...r.kmsKeyId === void 0 ? {} : { KmsKeyId: r.kmsKeyId }
|
|
2322
|
+
}))
|
|
2323
|
+
},
|
|
2324
|
+
...options.forceOverwriteReplicaSecret === void 0 ? {} : { ForceOverwriteReplicaSecret: options.forceOverwriteReplicaSecret }
|
|
2325
|
+
};
|
|
2326
|
+
const out = await this.#send(`createSecret ${name}`, new clientSecretsManager.CreateSecretCommand(input), options);
|
|
2327
|
+
return writeResult(out);
|
|
2328
|
+
}
|
|
2329
|
+
/**
|
|
2330
|
+
* Stores a new version (`PutSecretValue`). By default it becomes `AWSCURRENT` (the old one
|
|
2331
|
+
* becomes `AWSPREVIOUS`); with custom `versionStages` only those labels are attached.
|
|
2332
|
+
*/
|
|
2333
|
+
async putSecretValue(secretId, value, options = {}) {
|
|
2334
|
+
requireId("putSecretValue", secretId);
|
|
2335
|
+
const out = await this.#send(
|
|
2336
|
+
`putSecretValue ${secretId}`,
|
|
2337
|
+
new clientSecretsManager.PutSecretValueCommand({
|
|
2338
|
+
SecretId: secretId,
|
|
2339
|
+
...encodeValue(value),
|
|
2340
|
+
...options.versionStages === void 0 ? {} : { VersionStages: [...options.versionStages] },
|
|
2341
|
+
...options.clientRequestToken === void 0 ? {} : { ClientRequestToken: options.clientRequestToken }
|
|
2342
|
+
}),
|
|
2343
|
+
options
|
|
2344
|
+
);
|
|
2345
|
+
return {
|
|
2346
|
+
arn: out.ARN ?? "",
|
|
2347
|
+
name: out.Name ?? "",
|
|
2348
|
+
versionId: out.VersionId ?? "",
|
|
2349
|
+
versionStages: [...out.VersionStages ?? []]
|
|
2350
|
+
};
|
|
2351
|
+
}
|
|
2352
|
+
/**
|
|
2353
|
+
* Updates description, KMS key and/or value (`UpdateSecret`). A new version is created only
|
|
2354
|
+
* when `value` is given.
|
|
2355
|
+
*/
|
|
2356
|
+
async updateSecret(secretId, options = {}) {
|
|
2357
|
+
requireId("updateSecret", secretId);
|
|
2358
|
+
const input = {
|
|
2359
|
+
SecretId: secretId,
|
|
2360
|
+
...options.value === void 0 ? {} : encodeValue(options.value),
|
|
2361
|
+
...options.description === void 0 ? {} : { Description: options.description },
|
|
2362
|
+
...options.kmsKeyId === void 0 ? {} : { KmsKeyId: options.kmsKeyId },
|
|
2363
|
+
...options.clientRequestToken === void 0 ? {} : { ClientRequestToken: options.clientRequestToken }
|
|
2364
|
+
};
|
|
2365
|
+
const out = await this.#send(
|
|
2366
|
+
`updateSecret ${secretId}`,
|
|
2367
|
+
new clientSecretsManager.UpdateSecretCommand(input),
|
|
2368
|
+
options
|
|
2369
|
+
);
|
|
2370
|
+
return writeResult(out);
|
|
2371
|
+
}
|
|
2372
|
+
/**
|
|
2373
|
+
* Moves a stage label between versions (`UpdateSecretVersionStage`). Moving `AWSCURRENT` needs
|
|
2374
|
+
* `removeFromVersionId` = the current version; the old current version gets `AWSPREVIOUS`.
|
|
2375
|
+
*/
|
|
2376
|
+
async updateSecretVersionStage(secretId, versionStage, options = {}) {
|
|
2377
|
+
requireId("updateSecretVersionStage", secretId);
|
|
2378
|
+
if (options.moveToVersionId === void 0 && options.removeFromVersionId === void 0) {
|
|
2379
|
+
throw new chunkZLYHN4AI_cjs.ValidationError(
|
|
2380
|
+
"updateSecretVersionStage: give moveToVersionId and/or removeFromVersionId"
|
|
2381
|
+
);
|
|
2382
|
+
}
|
|
2383
|
+
const out = await this.#send(
|
|
2384
|
+
`updateSecretVersionStage ${secretId}`,
|
|
2385
|
+
new clientSecretsManager.UpdateSecretVersionStageCommand({
|
|
2386
|
+
SecretId: secretId,
|
|
2387
|
+
VersionStage: versionStage,
|
|
2388
|
+
...options.moveToVersionId === void 0 ? {} : { MoveToVersionId: options.moveToVersionId },
|
|
2389
|
+
...options.removeFromVersionId === void 0 ? {} : { RemoveFromVersionId: options.removeFromVersionId }
|
|
2390
|
+
}),
|
|
2391
|
+
options
|
|
2392
|
+
);
|
|
2393
|
+
return { arn: out.ARN ?? "", name: out.Name ?? "" };
|
|
2394
|
+
}
|
|
2395
|
+
/**
|
|
2396
|
+
* Schedules deletion (`DeleteSecret`) after `recoveryWindowDays` (AWS default 30) or deletes
|
|
2397
|
+
* immediately with `forceDeleteWithoutRecovery`. Note: AWS answers success for a forced delete
|
|
2398
|
+
* of a secret that does not exist.
|
|
2399
|
+
*/
|
|
2400
|
+
async deleteSecret(secretId, options = {}) {
|
|
2401
|
+
requireId("deleteSecret", secretId);
|
|
2402
|
+
const { recoveryWindowDays: days, forceDeleteWithoutRecovery: force } = options;
|
|
2403
|
+
if (days !== void 0 && force === true) {
|
|
2404
|
+
throw new chunkZLYHN4AI_cjs.ValidationError(
|
|
2405
|
+
"deleteSecret: recoveryWindowDays and forceDeleteWithoutRecovery are mutually exclusive"
|
|
2406
|
+
);
|
|
2407
|
+
}
|
|
2408
|
+
if (days !== void 0 && !(Number.isInteger(days) && days >= 7 && days <= 30)) {
|
|
2409
|
+
throw new chunkZLYHN4AI_cjs.ValidationError("deleteSecret: recoveryWindowDays must be an integer from 7 to 30");
|
|
2410
|
+
}
|
|
2411
|
+
const input = {
|
|
2412
|
+
SecretId: secretId,
|
|
2413
|
+
...days === void 0 ? {} : { RecoveryWindowInDays: days },
|
|
2414
|
+
...force === void 0 ? {} : { ForceDeleteWithoutRecovery: force }
|
|
2415
|
+
};
|
|
2416
|
+
const out = await this.#send(
|
|
2417
|
+
`deleteSecret ${secretId}`,
|
|
2418
|
+
new clientSecretsManager.DeleteSecretCommand(input),
|
|
2419
|
+
options
|
|
2420
|
+
);
|
|
2421
|
+
return {
|
|
2422
|
+
arn: out.ARN ?? "",
|
|
2423
|
+
name: out.Name ?? "",
|
|
2424
|
+
...out.DeletionDate === void 0 ? {} : { deletionDate: out.DeletionDate }
|
|
2425
|
+
};
|
|
2426
|
+
}
|
|
2427
|
+
/** Cancels a scheduled deletion (`RestoreSecret`). A no-op for a live secret. */
|
|
2428
|
+
async restoreSecret(secretId, options = {}) {
|
|
2429
|
+
requireId("restoreSecret", secretId);
|
|
2430
|
+
const out = await this.#send(
|
|
2431
|
+
`restoreSecret ${secretId}`,
|
|
2432
|
+
new clientSecretsManager.RestoreSecretCommand({ SecretId: secretId }),
|
|
2433
|
+
options
|
|
2434
|
+
);
|
|
2435
|
+
return { arn: out.ARN ?? "", name: out.Name ?? "" };
|
|
2436
|
+
}
|
|
2437
|
+
// ---------------------------------------------------------------------------------------
|
|
2438
|
+
// tags and resource policy
|
|
2439
|
+
/** Adds or replaces tags (`TagResource`). */
|
|
2440
|
+
async tagResource(secretId, tags, options = {}) {
|
|
2441
|
+
requireId("tagResource", secretId);
|
|
2442
|
+
await this.#send(
|
|
2443
|
+
`tagResource ${secretId}`,
|
|
2444
|
+
new clientSecretsManager.TagResourceCommand({ SecretId: secretId, Tags: toAwsTags(tags) }),
|
|
2445
|
+
options
|
|
2446
|
+
);
|
|
2447
|
+
}
|
|
2448
|
+
/** Removes tags by key (`UntagResource`). */
|
|
2449
|
+
async untagResource(secretId, tagKeys, options = {}) {
|
|
2450
|
+
requireId("untagResource", secretId);
|
|
2451
|
+
await this.#send(
|
|
2452
|
+
`untagResource ${secretId}`,
|
|
2453
|
+
new clientSecretsManager.UntagResourceCommand({ SecretId: secretId, TagKeys: [...tagKeys] }),
|
|
2454
|
+
options
|
|
2455
|
+
);
|
|
2456
|
+
}
|
|
2457
|
+
/** Attaches a resource policy (`PutResourcePolicy`); objects are JSON-encoded. */
|
|
2458
|
+
async putResourcePolicy(secretId, policy, options = {}) {
|
|
2459
|
+
requireId("putResourcePolicy", secretId);
|
|
2460
|
+
const out = await this.#send(
|
|
2461
|
+
`putResourcePolicy ${secretId}`,
|
|
2462
|
+
new clientSecretsManager.PutResourcePolicyCommand({
|
|
2463
|
+
SecretId: secretId,
|
|
2464
|
+
ResourcePolicy: typeof policy === "string" ? policy : JSON.stringify(policy),
|
|
2465
|
+
...options.blockPublicPolicy === void 0 ? {} : { BlockPublicPolicy: options.blockPublicPolicy }
|
|
2466
|
+
}),
|
|
2467
|
+
options
|
|
2468
|
+
);
|
|
2469
|
+
return { arn: out.ARN ?? "", name: out.Name ?? "" };
|
|
2470
|
+
}
|
|
2471
|
+
/** Reads the resource policy (`GetResourcePolicy`); `resourcePolicy` is absent when there is none. */
|
|
2472
|
+
async getResourcePolicy(secretId, options = {}) {
|
|
2473
|
+
requireId("getResourcePolicy", secretId);
|
|
2474
|
+
const out = await this.#send(
|
|
2475
|
+
`getResourcePolicy ${secretId}`,
|
|
2476
|
+
new clientSecretsManager.GetResourcePolicyCommand({ SecretId: secretId }),
|
|
2477
|
+
options
|
|
2478
|
+
);
|
|
2479
|
+
const text = out.ResourcePolicy ?? void 0;
|
|
2480
|
+
const policy = parsePolicy(text);
|
|
2481
|
+
return {
|
|
2482
|
+
arn: out.ARN ?? "",
|
|
2483
|
+
name: out.Name ?? "",
|
|
2484
|
+
...text === void 0 ? {} : { resourcePolicy: text },
|
|
2485
|
+
...policy === void 0 ? {} : { policy }
|
|
2486
|
+
};
|
|
2487
|
+
}
|
|
2488
|
+
/** Removes the resource policy (`DeleteResourcePolicy`). */
|
|
2489
|
+
async deleteResourcePolicy(secretId, options = {}) {
|
|
2490
|
+
requireId("deleteResourcePolicy", secretId);
|
|
2491
|
+
const out = await this.#send(
|
|
2492
|
+
`deleteResourcePolicy ${secretId}`,
|
|
2493
|
+
new clientSecretsManager.DeleteResourcePolicyCommand({ SecretId: secretId }),
|
|
2494
|
+
options
|
|
2495
|
+
);
|
|
2496
|
+
return { arn: out.ARN ?? "", name: out.Name ?? "" };
|
|
2497
|
+
}
|
|
2498
|
+
/**
|
|
2499
|
+
* Checks a policy with IAM Access Analyzer (`ValidateResourcePolicy`). Emulators that lack the
|
|
2500
|
+
* operation (Moto 5.2.4) raise `UnsupportedError`.
|
|
2501
|
+
*/
|
|
2502
|
+
async validateResourcePolicy(policy, options = {}) {
|
|
2503
|
+
const out = await this.#send(
|
|
2504
|
+
"validateResourcePolicy",
|
|
2505
|
+
new clientSecretsManager.ValidateResourcePolicyCommand({
|
|
2506
|
+
ResourcePolicy: typeof policy === "string" ? policy : JSON.stringify(policy),
|
|
2507
|
+
...options.secretId === void 0 ? {} : { SecretId: options.secretId }
|
|
2508
|
+
}),
|
|
2509
|
+
options
|
|
2510
|
+
);
|
|
2511
|
+
return {
|
|
2512
|
+
policyValidationPassed: out.PolicyValidationPassed === true,
|
|
2513
|
+
validationErrors: (out.ValidationErrors ?? []).map(toPolicyError)
|
|
2514
|
+
};
|
|
2515
|
+
}
|
|
2516
|
+
// ---------------------------------------------------------------------------------------
|
|
2517
|
+
// rotation
|
|
2518
|
+
/**
|
|
2519
|
+
* Configures and/or starts rotation (`RotateSecret`). Without `lambdaArn` the secret's managed
|
|
2520
|
+
* or existing rotation function is used.
|
|
2521
|
+
*/
|
|
2522
|
+
async rotateSecret(secretId, options = {}) {
|
|
2523
|
+
requireId("rotateSecret", secretId);
|
|
2524
|
+
const rules = options.rules;
|
|
2525
|
+
const input = {
|
|
2526
|
+
SecretId: secretId,
|
|
2527
|
+
...options.lambdaArn === void 0 ? {} : { RotationLambdaARN: options.lambdaArn },
|
|
2528
|
+
...rules === void 0 ? {} : {
|
|
2529
|
+
RotationRules: {
|
|
2530
|
+
...rules.automaticallyAfterDays === void 0 ? {} : { AutomaticallyAfterDays: rules.automaticallyAfterDays },
|
|
2531
|
+
...rules.duration === void 0 ? {} : { Duration: rules.duration },
|
|
2532
|
+
...rules.scheduleExpression === void 0 ? {} : { ScheduleExpression: rules.scheduleExpression }
|
|
2533
|
+
}
|
|
2534
|
+
},
|
|
2535
|
+
...options.rotateImmediately === void 0 ? {} : { RotateImmediately: options.rotateImmediately },
|
|
2536
|
+
...options.clientRequestToken === void 0 ? {} : { ClientRequestToken: options.clientRequestToken }
|
|
2537
|
+
};
|
|
2538
|
+
const out = await this.#send(
|
|
2539
|
+
`rotateSecret ${secretId}`,
|
|
2540
|
+
new clientSecretsManager.RotateSecretCommand(input),
|
|
2541
|
+
options
|
|
2542
|
+
);
|
|
2543
|
+
return writeResult(out);
|
|
2544
|
+
}
|
|
2545
|
+
/** Turns rotation off and cancels a rotation in progress (`CancelRotateSecret`). */
|
|
2546
|
+
async cancelRotateSecret(secretId, options = {}) {
|
|
2547
|
+
requireId("cancelRotateSecret", secretId);
|
|
2548
|
+
const out = await this.#send(
|
|
2549
|
+
`cancelRotateSecret ${secretId}`,
|
|
2550
|
+
new clientSecretsManager.CancelRotateSecretCommand({ SecretId: secretId }),
|
|
2551
|
+
options
|
|
2552
|
+
);
|
|
2553
|
+
return writeResult(out);
|
|
2554
|
+
}
|
|
2555
|
+
// ---------------------------------------------------------------------------------------
|
|
2556
|
+
// utilities
|
|
2557
|
+
/** Generates a random password (`GetRandomPassword`), returned as a redacting {@link Secret}. */
|
|
2558
|
+
async getRandomPassword(options = {}) {
|
|
2559
|
+
const input = {
|
|
2560
|
+
PasswordLength: options.length ?? 32,
|
|
2561
|
+
...options.excludeCharacters === void 0 ? {} : { ExcludeCharacters: options.excludeCharacters },
|
|
2562
|
+
...options.excludeNumbers === void 0 ? {} : { ExcludeNumbers: options.excludeNumbers },
|
|
2563
|
+
...options.excludePunctuation === void 0 ? {} : { ExcludePunctuation: options.excludePunctuation },
|
|
2564
|
+
...options.excludeUppercase === void 0 ? {} : { ExcludeUppercase: options.excludeUppercase },
|
|
2565
|
+
...options.excludeLowercase === void 0 ? {} : { ExcludeLowercase: options.excludeLowercase },
|
|
2566
|
+
...options.includeSpace === void 0 ? {} : { IncludeSpace: options.includeSpace },
|
|
2567
|
+
...options.requireEachIncludedType === void 0 ? {} : { RequireEachIncludedType: options.requireEachIncludedType }
|
|
2568
|
+
};
|
|
2569
|
+
const out = await this.#send("getRandomPassword", new clientSecretsManager.GetRandomPasswordCommand(input), options);
|
|
2570
|
+
return new chunkZLYHN4AI_cjs.Secret(out.RandomPassword ?? "");
|
|
2571
|
+
}
|
|
2572
|
+
/**
|
|
2573
|
+
* Reads one field of a JSON secret: `GetSecretValue`, parse `SecretString` as a JSON object,
|
|
2574
|
+
* return `field` (an exact key first, otherwise a dot path such as `"db.host"`). `null` when
|
|
2575
|
+
* the field is absent; `ValidationError` when the value is binary or not a JSON object;
|
|
2576
|
+
* `NotFoundError` when the secret is missing.
|
|
2577
|
+
*/
|
|
2578
|
+
async getJsonField(secretId, field, options = {}) {
|
|
2579
|
+
const secret = await this.getSecretValue(secretId, options);
|
|
2580
|
+
if (secret.binary) {
|
|
2581
|
+
throw new chunkZLYHN4AI_cjs.ValidationError(`getJsonField ${secretId}: the secret is binary, not JSON`);
|
|
2582
|
+
}
|
|
2583
|
+
let parsed;
|
|
2584
|
+
try {
|
|
2585
|
+
parsed = secret.value.json();
|
|
2586
|
+
} catch {
|
|
2587
|
+
throw new chunkZLYHN4AI_cjs.ValidationError(`getJsonField ${secretId}: the value is not valid JSON`);
|
|
2588
|
+
}
|
|
2589
|
+
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
|
|
2590
|
+
throw new chunkZLYHN4AI_cjs.ValidationError(`getJsonField ${secretId}: the value is not a JSON object`);
|
|
2591
|
+
}
|
|
2592
|
+
return jsonField(parsed, field);
|
|
2593
|
+
}
|
|
2594
|
+
// ---------------------------------------------------------------------------------------
|
|
2595
|
+
// internals
|
|
2596
|
+
/** Known credential values for redaction. @internal */
|
|
2597
|
+
knownSecrets() {
|
|
2598
|
+
return this.config.knownSecrets();
|
|
2599
|
+
}
|
|
2600
|
+
#healthClient() {
|
|
2601
|
+
if (this.#sdkConfig === void 0) return this.#sdk;
|
|
2602
|
+
this.#healthSdk ??= new clientSecretsManager.SecretsManagerClient({ ...this.#sdkConfig, maxAttempts: 1 });
|
|
2603
|
+
return this.#healthSdk;
|
|
2604
|
+
}
|
|
2605
|
+
/** Sends a command with cancellation, the total timeout and error mapping. */
|
|
2606
|
+
async #send(operation, command, options = {}) {
|
|
2607
|
+
if (this.#closed) throw new chunkZLYHN4AI_cjs.CancelledError(`${operation}: client is closed`);
|
|
2608
|
+
const signal = options.signal;
|
|
2609
|
+
if (signal?.aborted === true) throw new chunkZLYHN4AI_cjs.CancelledError(`${operation}: cancelled`);
|
|
2610
|
+
const total = new AbortController();
|
|
2611
|
+
const timer = setTimeout(() => {
|
|
2612
|
+
total.abort();
|
|
2613
|
+
}, this.config.totalTimeoutMs);
|
|
2614
|
+
timer.unref();
|
|
2615
|
+
const abortSignal = signal === void 0 ? total.signal : AbortSignal.any([signal, total.signal]);
|
|
2616
|
+
const sdk = options.sdk ?? this.#sdk;
|
|
2617
|
+
try {
|
|
2618
|
+
const send = sdk.send.bind(sdk);
|
|
2619
|
+
return await send(command, {
|
|
2620
|
+
abortSignal,
|
|
2621
|
+
...options.requestTimeout === void 0 ? {} : { requestTimeout: options.requestTimeout }
|
|
2622
|
+
});
|
|
2623
|
+
} catch (err) {
|
|
2624
|
+
let mapped;
|
|
2625
|
+
if (isAborted(signal)) {
|
|
2626
|
+
mapped = new chunkZLYHN4AI_cjs.CancelledError(`${operation}: cancelled`, { cause: err });
|
|
2627
|
+
} else if (total.signal.aborted) {
|
|
2628
|
+
mapped = new chunkZLYHN4AI_cjs.TimeoutError(
|
|
2629
|
+
`${operation}: total timeout of ${String(this.config.totalTimeoutMs)} ms exceeded`,
|
|
2630
|
+
{ cause: err }
|
|
2631
|
+
);
|
|
2632
|
+
} else {
|
|
2633
|
+
mapped = mapAwsError(err, operation, {
|
|
2634
|
+
knownSecrets: this.knownSecrets(),
|
|
2635
|
+
unsupportedOnHtml500: EMULATOR_GAPS.has(operation.split(" ")[0] ?? "")
|
|
2636
|
+
});
|
|
2637
|
+
}
|
|
2638
|
+
if (mapped.httpStatus !== void 0) {
|
|
2639
|
+
safeCall(this.config.hooks?.onError, {
|
|
2640
|
+
method: "POST",
|
|
2641
|
+
url: this.config.url,
|
|
2642
|
+
error: mapped,
|
|
2643
|
+
attempt: attemptsOf(err),
|
|
2644
|
+
willRetry: false
|
|
2645
|
+
});
|
|
2646
|
+
}
|
|
2647
|
+
throw mapped;
|
|
2648
|
+
} finally {
|
|
2649
|
+
clearTimeout(timer);
|
|
2650
|
+
}
|
|
2651
|
+
}
|
|
2652
|
+
};
|
|
2653
|
+
function isAborted(signal) {
|
|
2654
|
+
return signal?.aborted === true;
|
|
2655
|
+
}
|
|
2656
|
+
function attemptsOf(err) {
|
|
2657
|
+
const attempts = err.$metadata?.attempts;
|
|
2658
|
+
return typeof attempts === "number" && attempts > 0 ? attempts : 1;
|
|
2659
|
+
}
|
|
2660
|
+
function requireId(operation, id) {
|
|
2661
|
+
if (typeof id !== "string" || id.trim() === "") {
|
|
2662
|
+
throw new chunkZLYHN4AI_cjs.ValidationError(`${operation}: secret id must not be empty`);
|
|
2663
|
+
}
|
|
2664
|
+
}
|
|
2665
|
+
function writeResult(out) {
|
|
2666
|
+
return {
|
|
2667
|
+
arn: out.ARN ?? "",
|
|
2668
|
+
name: out.Name ?? "",
|
|
2669
|
+
...out.VersionId === void 0 ? {} : { versionId: out.VersionId }
|
|
2670
|
+
};
|
|
2671
|
+
}
|
|
2672
|
+
function orderByIds(values, ids) {
|
|
2673
|
+
const rank = (v) => {
|
|
2674
|
+
const i = ids.findIndex(
|
|
2675
|
+
(id) => id === v.name || id === v.arn || id.startsWith("arn:") && v.arn.startsWith(id)
|
|
2676
|
+
);
|
|
2677
|
+
return i === -1 ? ids.length : i;
|
|
2678
|
+
};
|
|
2679
|
+
return [...values].sort((a, b) => rank(a) - rank(b));
|
|
2680
|
+
}
|
|
2681
|
+
function jsonField(obj, field) {
|
|
2682
|
+
if (Object.hasOwn(obj, field)) return obj[field] ?? null;
|
|
2683
|
+
let current = obj;
|
|
2684
|
+
for (const part of field.split(".")) {
|
|
2685
|
+
if (typeof current !== "object" || current === null || Array.isArray(current)) return null;
|
|
2686
|
+
if (!Object.hasOwn(current, part)) return null;
|
|
2687
|
+
current = current[part];
|
|
2688
|
+
}
|
|
2689
|
+
return current ?? null;
|
|
2690
|
+
}
|
|
2691
|
+
function buildCredentials(cfg, handler) {
|
|
2692
|
+
let base;
|
|
2693
|
+
if (cfg.accessKeyId !== void 0 && cfg.secretAccessKey !== void 0) {
|
|
2694
|
+
base = {
|
|
2695
|
+
accessKeyId: cfg.accessKeyId,
|
|
2696
|
+
secretAccessKey: cfg.secretAccessKey.reveal(),
|
|
2697
|
+
...cfg.sessionToken === void 0 ? {} : { sessionToken: cfg.sessionToken.reveal() }
|
|
2698
|
+
};
|
|
2699
|
+
} else if (cfg.credentials !== void 0) {
|
|
2700
|
+
base = cfg.credentials;
|
|
2701
|
+
} else if (cfg.profile !== void 0) {
|
|
2702
|
+
base = credentialProviders.fromIni({ profile: cfg.profile });
|
|
2703
|
+
}
|
|
2704
|
+
if (cfg.roleArn === void 0) return base;
|
|
2705
|
+
return credentialProviders.fromTemporaryCredentials({
|
|
2706
|
+
params: {
|
|
2707
|
+
RoleArn: cfg.roleArn,
|
|
2708
|
+
RoleSessionName: cfg.roleSessionName,
|
|
2709
|
+
...cfg.externalId === void 0 ? {} : { ExternalId: cfg.externalId },
|
|
2710
|
+
...cfg.roleDurationMs === void 0 ? {} : { DurationSeconds: Math.floor(cfg.roleDurationMs / 1e3) }
|
|
2711
|
+
},
|
|
2712
|
+
...base === void 0 ? {} : { masterCredentials: base },
|
|
2713
|
+
clientConfig: {
|
|
2714
|
+
requestHandler: handler,
|
|
2715
|
+
...cfg.region === void 0 ? {} : { region: cfg.region }
|
|
2716
|
+
}
|
|
2717
|
+
});
|
|
2718
|
+
}
|
|
2719
|
+
|
|
2720
|
+
Object.defineProperty(exports, "AuthenticationError", {
|
|
2721
|
+
enumerable: true,
|
|
2722
|
+
get: function () { return chunkZLYHN4AI_cjs.AuthenticationError; }
|
|
2723
|
+
});
|
|
2724
|
+
Object.defineProperty(exports, "AwsSecretsManagerError", {
|
|
2725
|
+
enumerable: true,
|
|
2726
|
+
get: function () { return chunkZLYHN4AI_cjs.AwsSecretsManagerError; }
|
|
2727
|
+
});
|
|
2728
|
+
Object.defineProperty(exports, "BaseSecretsProvider", {
|
|
2729
|
+
enumerable: true,
|
|
2730
|
+
get: function () { return chunkZLYHN4AI_cjs.BaseSecretsProvider; }
|
|
2731
|
+
});
|
|
2732
|
+
Object.defineProperty(exports, "CancelledError", {
|
|
2733
|
+
enumerable: true,
|
|
2734
|
+
get: function () { return chunkZLYHN4AI_cjs.CancelledError; }
|
|
2735
|
+
});
|
|
2736
|
+
Object.defineProperty(exports, "ConfigError", {
|
|
2737
|
+
enumerable: true,
|
|
2738
|
+
get: function () { return chunkZLYHN4AI_cjs.ConfigError; }
|
|
2739
|
+
});
|
|
2740
|
+
Object.defineProperty(exports, "ConflictError", {
|
|
2741
|
+
enumerable: true,
|
|
2742
|
+
get: function () { return chunkZLYHN4AI_cjs.ConflictError; }
|
|
2743
|
+
});
|
|
2744
|
+
Object.defineProperty(exports, "EnvReader", {
|
|
2745
|
+
enumerable: true,
|
|
2746
|
+
get: function () { return chunkZLYHN4AI_cjs.EnvReader; }
|
|
2747
|
+
});
|
|
2748
|
+
Object.defineProperty(exports, "ErrorCode", {
|
|
2749
|
+
enumerable: true,
|
|
2750
|
+
get: function () { return chunkZLYHN4AI_cjs.ErrorCode; }
|
|
2751
|
+
});
|
|
2752
|
+
Object.defineProperty(exports, "GET_MANY_CONCURRENCY", {
|
|
2753
|
+
enumerable: true,
|
|
2754
|
+
get: function () { return chunkZLYHN4AI_cjs.GET_MANY_CONCURRENCY; }
|
|
2755
|
+
});
|
|
2756
|
+
Object.defineProperty(exports, "MIN_SECRET_LENGTH", {
|
|
2757
|
+
enumerable: true,
|
|
2758
|
+
get: function () { return chunkZLYHN4AI_cjs.MIN_SECRET_LENGTH; }
|
|
2759
|
+
});
|
|
2760
|
+
Object.defineProperty(exports, "NotFoundError", {
|
|
2761
|
+
enumerable: true,
|
|
2762
|
+
get: function () { return chunkZLYHN4AI_cjs.NotFoundError; }
|
|
2763
|
+
});
|
|
2764
|
+
Object.defineProperty(exports, "PermissionDeniedError", {
|
|
2765
|
+
enumerable: true,
|
|
2766
|
+
get: function () { return chunkZLYHN4AI_cjs.PermissionDeniedError; }
|
|
2767
|
+
});
|
|
2768
|
+
Object.defineProperty(exports, "REDACTED", {
|
|
2769
|
+
enumerable: true,
|
|
2770
|
+
get: function () { return chunkZLYHN4AI_cjs.REDACTED; }
|
|
2771
|
+
});
|
|
2772
|
+
Object.defineProperty(exports, "RateLimitError", {
|
|
2773
|
+
enumerable: true,
|
|
2774
|
+
get: function () { return chunkZLYHN4AI_cjs.RateLimitError; }
|
|
2775
|
+
});
|
|
2776
|
+
Object.defineProperty(exports, "SENSITIVE_FIELD_PARTS", {
|
|
2777
|
+
enumerable: true,
|
|
2778
|
+
get: function () { return chunkZLYHN4AI_cjs.SENSITIVE_FIELD_PARTS; }
|
|
2779
|
+
});
|
|
2780
|
+
Object.defineProperty(exports, "Secret", {
|
|
2781
|
+
enumerable: true,
|
|
2782
|
+
get: function () { return chunkZLYHN4AI_cjs.Secret; }
|
|
2783
|
+
});
|
|
2784
|
+
Object.defineProperty(exports, "SecretValue", {
|
|
2785
|
+
enumerable: true,
|
|
2786
|
+
get: function () { return chunkZLYHN4AI_cjs.SecretValue; }
|
|
2787
|
+
});
|
|
2788
|
+
Object.defineProperty(exports, "TimeoutError", {
|
|
2789
|
+
enumerable: true,
|
|
2790
|
+
get: function () { return chunkZLYHN4AI_cjs.TimeoutError; }
|
|
2791
|
+
});
|
|
2792
|
+
Object.defineProperty(exports, "UnavailableError", {
|
|
2793
|
+
enumerable: true,
|
|
2794
|
+
get: function () { return chunkZLYHN4AI_cjs.UnavailableError; }
|
|
2795
|
+
});
|
|
2796
|
+
Object.defineProperty(exports, "UnsupportedError", {
|
|
2797
|
+
enumerable: true,
|
|
2798
|
+
get: function () { return chunkZLYHN4AI_cjs.UnsupportedError; }
|
|
2799
|
+
});
|
|
2800
|
+
Object.defineProperty(exports, "ValidationError", {
|
|
2801
|
+
enumerable: true,
|
|
2802
|
+
get: function () { return chunkZLYHN4AI_cjs.ValidationError; }
|
|
2803
|
+
});
|
|
2804
|
+
Object.defineProperty(exports, "applyEnv", {
|
|
2805
|
+
enumerable: true,
|
|
2806
|
+
get: function () { return chunkZLYHN4AI_cjs.applyEnv; }
|
|
2807
|
+
});
|
|
2808
|
+
Object.defineProperty(exports, "codeForStatus", {
|
|
2809
|
+
enumerable: true,
|
|
2810
|
+
get: function () { return chunkZLYHN4AI_cjs.codeForStatus; }
|
|
2811
|
+
});
|
|
2812
|
+
Object.defineProperty(exports, "encodeSecretInput", {
|
|
2813
|
+
enumerable: true,
|
|
2814
|
+
get: function () { return chunkZLYHN4AI_cjs.encodeSecretInput; }
|
|
2815
|
+
});
|
|
2816
|
+
Object.defineProperty(exports, "envNameFor", {
|
|
2817
|
+
enumerable: true,
|
|
2818
|
+
get: function () { return chunkZLYHN4AI_cjs.envNameFor; }
|
|
2819
|
+
});
|
|
2820
|
+
Object.defineProperty(exports, "errorForCode", {
|
|
2821
|
+
enumerable: true,
|
|
2822
|
+
get: function () { return chunkZLYHN4AI_cjs.errorForCode; }
|
|
2823
|
+
});
|
|
2824
|
+
Object.defineProperty(exports, "errorForStatus", {
|
|
2825
|
+
enumerable: true,
|
|
2826
|
+
get: function () { return chunkZLYHN4AI_cjs.errorForStatus; }
|
|
2827
|
+
});
|
|
2828
|
+
Object.defineProperty(exports, "isAwsSecretsManagerError", {
|
|
2829
|
+
enumerable: true,
|
|
2830
|
+
get: function () { return chunkZLYHN4AI_cjs.isAwsSecretsManagerError; }
|
|
2831
|
+
});
|
|
2832
|
+
Object.defineProperty(exports, "isSensitiveField", {
|
|
2833
|
+
enumerable: true,
|
|
2834
|
+
get: function () { return chunkZLYHN4AI_cjs.isSensitiveField; }
|
|
2835
|
+
});
|
|
2836
|
+
Object.defineProperty(exports, "isSensitiveHeader", {
|
|
2837
|
+
enumerable: true,
|
|
2838
|
+
get: function () { return chunkZLYHN4AI_cjs.isSensitiveHeader; }
|
|
2839
|
+
});
|
|
2840
|
+
Object.defineProperty(exports, "parseBool", {
|
|
2841
|
+
enumerable: true,
|
|
2842
|
+
get: function () { return chunkZLYHN4AI_cjs.parseBool; }
|
|
2843
|
+
});
|
|
2844
|
+
Object.defineProperty(exports, "parseDuration", {
|
|
2845
|
+
enumerable: true,
|
|
2846
|
+
get: function () { return chunkZLYHN4AI_cjs.parseDuration; }
|
|
2847
|
+
});
|
|
2848
|
+
Object.defineProperty(exports, "parseInteger", {
|
|
2849
|
+
enumerable: true,
|
|
2850
|
+
get: function () { return chunkZLYHN4AI_cjs.parseInteger; }
|
|
2851
|
+
});
|
|
2852
|
+
Object.defineProperty(exports, "pollUntil", {
|
|
2853
|
+
enumerable: true,
|
|
2854
|
+
get: function () { return chunkZLYHN4AI_cjs.pollUntil; }
|
|
2855
|
+
});
|
|
2856
|
+
Object.defineProperty(exports, "reasonForCode", {
|
|
2857
|
+
enumerable: true,
|
|
2858
|
+
get: function () { return chunkZLYHN4AI_cjs.reasonForCode; }
|
|
2859
|
+
});
|
|
2860
|
+
Object.defineProperty(exports, "redactError", {
|
|
2861
|
+
enumerable: true,
|
|
2862
|
+
get: function () { return chunkZLYHN4AI_cjs.redactError; }
|
|
2863
|
+
});
|
|
2864
|
+
Object.defineProperty(exports, "redactFields", {
|
|
2865
|
+
enumerable: true,
|
|
2866
|
+
get: function () { return chunkZLYHN4AI_cjs.redactFields; }
|
|
2867
|
+
});
|
|
2868
|
+
Object.defineProperty(exports, "redactHeaders", {
|
|
2869
|
+
enumerable: true,
|
|
2870
|
+
get: function () { return chunkZLYHN4AI_cjs.redactHeaders; }
|
|
2871
|
+
});
|
|
2872
|
+
Object.defineProperty(exports, "redactText", {
|
|
2873
|
+
enumerable: true,
|
|
2874
|
+
get: function () { return chunkZLYHN4AI_cjs.redactText; }
|
|
2875
|
+
});
|
|
2876
|
+
Object.defineProperty(exports, "redactUrl", {
|
|
2877
|
+
enumerable: true,
|
|
2878
|
+
get: function () { return chunkZLYHN4AI_cjs.redactUrl; }
|
|
2879
|
+
});
|
|
2880
|
+
Object.defineProperty(exports, "relativeName", {
|
|
2881
|
+
enumerable: true,
|
|
2882
|
+
get: function () { return chunkZLYHN4AI_cjs.relativeName; }
|
|
2883
|
+
});
|
|
2884
|
+
Object.defineProperty(exports, "secretFingerprint", {
|
|
2885
|
+
enumerable: true,
|
|
2886
|
+
get: function () { return chunkZLYHN4AI_cjs.secretFingerprint; }
|
|
2887
|
+
});
|
|
2888
|
+
Object.defineProperty(exports, "sleep", {
|
|
2889
|
+
enumerable: true,
|
|
2890
|
+
get: function () { return chunkZLYHN4AI_cjs.sleep; }
|
|
2891
|
+
});
|
|
2892
|
+
Object.defineProperty(exports, "throwIfAborted", {
|
|
2893
|
+
enumerable: true,
|
|
2894
|
+
get: function () { return chunkZLYHN4AI_cjs.throwIfAborted; }
|
|
2895
|
+
});
|
|
2896
|
+
Object.defineProperty(exports, "watchSecret", {
|
|
2897
|
+
enumerable: true,
|
|
2898
|
+
get: function () { return chunkZLYHN4AI_cjs.watchSecret; }
|
|
2899
|
+
});
|
|
2900
|
+
exports.API_VERSION = API_VERSION;
|
|
2901
|
+
exports.AWSCURRENT = AWSCURRENT;
|
|
2902
|
+
exports.AWSPENDING = AWSPENDING;
|
|
2903
|
+
exports.AWSPREVIOUS = AWSPREVIOUS;
|
|
2904
|
+
exports.AWS_ERROR_CODES = AWS_ERROR_CODES;
|
|
2905
|
+
exports.AWS_SECRET_CACHE_DEFAULTS = AWS_SECRET_CACHE_DEFAULTS;
|
|
2906
|
+
exports.AttemptTimeoutError = AttemptTimeoutError;
|
|
2907
|
+
exports.AwsSecretCache = AwsSecretCache;
|
|
2908
|
+
exports.AwsSecretsManagerClient = AwsSecretsManagerClient;
|
|
2909
|
+
exports.AwsSecretsManagerConfig = AwsSecretsManagerConfig;
|
|
2910
|
+
exports.AwsSecretsManagerSecretsProvider = AwsSecretsManagerSecretsProvider;
|
|
2911
|
+
exports.BATCH_GET_MAX_IDS = BATCH_GET_MAX_IDS;
|
|
2912
|
+
exports.DEFAULT_RECOVERY_WINDOW_DAYS = DEFAULT_RECOVERY_WINDOW_DAYS;
|
|
2913
|
+
exports.DEFAULT_REQUEST_ID_HEADERS = DEFAULT_REQUEST_ID_HEADERS;
|
|
2914
|
+
exports.DEFAULT_ROLE_SESSION_NAME = DEFAULT_ROLE_SESSION_NAME;
|
|
2915
|
+
exports.DEFAULT_TIMEOUTS = DEFAULT_TIMEOUTS;
|
|
2916
|
+
exports.GROW_USER_AGENT = GROW_USER_AGENT;
|
|
2917
|
+
exports.GrowHttpHandler = GrowHttpHandler;
|
|
2918
|
+
exports.HttpTransport = HttpTransport;
|
|
2919
|
+
exports.LANGUAGE = LANGUAGE;
|
|
2920
|
+
exports.MAX_VENDOR_TEXT = MAX_VENDOR_TEXT;
|
|
2921
|
+
exports.PACKAGE_KEY = PACKAGE_KEY;
|
|
2922
|
+
exports.Paginator = Paginator;
|
|
2923
|
+
exports.RetryPolicy = RetryPolicy;
|
|
2924
|
+
exports.SDK_KIT_VERSION = SDK_KIT_VERSION;
|
|
2925
|
+
exports.SDK_VERSION = SDK_VERSION;
|
|
2926
|
+
exports.SecretCache = SecretCache;
|
|
2927
|
+
exports.VENDOR_ENV = VENDOR_ENV;
|
|
2928
|
+
exports.createDispatcher = createDispatcher;
|
|
2929
|
+
exports.definedOnly = definedOnly;
|
|
2930
|
+
exports.describeCommonConfig = describeCommonConfig;
|
|
2931
|
+
exports.encodeBytes = encodeBytes;
|
|
2932
|
+
exports.encodeValue = encodeValue;
|
|
2933
|
+
exports.errorCodeFromBody = errorCodeFromBody;
|
|
2934
|
+
exports.fromAwsTags = fromAwsTags;
|
|
2935
|
+
exports.fullName = fullName;
|
|
2936
|
+
exports.hasMore = hasMore;
|
|
2937
|
+
exports.healthStatus = healthStatus;
|
|
2938
|
+
exports.isHealthyWord = isHealthyWord;
|
|
2939
|
+
exports.isIdempotentMethod = isIdempotentMethod;
|
|
2940
|
+
exports.isRetryableStatus = isRetryableStatus;
|
|
2941
|
+
exports.jsonField = jsonField;
|
|
2942
|
+
exports.mapAwsError = mapAwsError;
|
|
2943
|
+
exports.mergeOptions = mergeOptions;
|
|
2944
|
+
exports.parsePolicy = parsePolicy;
|
|
2945
|
+
exports.parseRetryAfter = parseRetryAfter;
|
|
2946
|
+
exports.probeHealth = probeHealth;
|
|
2947
|
+
exports.readCommonEnv = readCommonEnv;
|
|
2948
|
+
exports.redactSecretsInText = redactSecretsInText;
|
|
2949
|
+
exports.resolveCommonConfig = resolveCommonConfig;
|
|
2950
|
+
exports.safeCall = safeCall;
|
|
2951
|
+
exports.safeLogger = safeLogger;
|
|
2952
|
+
exports.secretValues = secretValues;
|
|
2953
|
+
exports.silentLogger = silentLogger;
|
|
2954
|
+
exports.toAwsFilters = toAwsFilters;
|
|
2955
|
+
exports.toAwsTags = toAwsTags;
|
|
2956
|
+
exports.toBatchError = toBatchError;
|
|
2957
|
+
exports.toDescription = toDescription;
|
|
2958
|
+
exports.toMetadata = toMetadata;
|
|
2959
|
+
exports.toPolicyError = toPolicyError;
|
|
2960
|
+
exports.toSecretValue = toSecretValue;
|
|
2961
|
+
exports.toVersion = toVersion;
|
|
2962
|
+
exports.validateCommonConfig = validateCommonConfig;
|
|
2963
|
+
//# sourceMappingURL=index.cjs.map
|
|
2964
|
+
//# sourceMappingURL=index.cjs.map
|