@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
|
@@ -0,0 +1,868 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var crypto = require('crypto');
|
|
4
|
+
|
|
5
|
+
// src/core/errors.ts
|
|
6
|
+
var ErrorCode = {
|
|
7
|
+
Config: "CONFIG",
|
|
8
|
+
Authentication: "AUTHENTICATION",
|
|
9
|
+
PermissionDenied: "PERMISSION_DENIED",
|
|
10
|
+
NotFound: "NOT_FOUND",
|
|
11
|
+
Conflict: "CONFLICT",
|
|
12
|
+
RateLimited: "RATE_LIMITED",
|
|
13
|
+
Validation: "VALIDATION",
|
|
14
|
+
Unavailable: "UNAVAILABLE",
|
|
15
|
+
Timeout: "TIMEOUT",
|
|
16
|
+
Unsupported: "UNSUPPORTED",
|
|
17
|
+
Cancelled: "CANCELLED"
|
|
18
|
+
};
|
|
19
|
+
var RETRYABLE_BY_DEFAULT = /* @__PURE__ */ new Set([
|
|
20
|
+
ErrorCode.RateLimited,
|
|
21
|
+
ErrorCode.Unavailable,
|
|
22
|
+
ErrorCode.Timeout
|
|
23
|
+
]);
|
|
24
|
+
var AwsSecretsManagerError = class extends Error {
|
|
25
|
+
/** Canonical error code. */
|
|
26
|
+
code;
|
|
27
|
+
/** HTTP status when the error came from a response. */
|
|
28
|
+
httpStatus;
|
|
29
|
+
/** Vendor request id when the response carried one. */
|
|
30
|
+
requestId;
|
|
31
|
+
/** Whether retrying the same call may succeed. */
|
|
32
|
+
retryable;
|
|
33
|
+
/** Server-requested wait in milliseconds (rate limits, `Retry-After`). */
|
|
34
|
+
retryAfterMs;
|
|
35
|
+
constructor(code, message, details = {}) {
|
|
36
|
+
super(message, details.cause === void 0 ? void 0 : { cause: details.cause });
|
|
37
|
+
this.name = new.target.name;
|
|
38
|
+
this.code = code;
|
|
39
|
+
this.retryable = details.retryable ?? RETRYABLE_BY_DEFAULT.has(code);
|
|
40
|
+
if (details.httpStatus !== void 0) this.httpStatus = details.httpStatus;
|
|
41
|
+
if (details.requestId !== void 0) this.requestId = details.requestId;
|
|
42
|
+
if (details.retryAfterMs !== void 0) this.retryAfterMs = details.retryAfterMs;
|
|
43
|
+
}
|
|
44
|
+
/** JSON form (no stack, no cause). */
|
|
45
|
+
toJSON() {
|
|
46
|
+
const out = {
|
|
47
|
+
name: this.name,
|
|
48
|
+
code: this.code,
|
|
49
|
+
message: this.message,
|
|
50
|
+
retryable: this.retryable
|
|
51
|
+
};
|
|
52
|
+
if (this.httpStatus !== void 0) out.httpStatus = this.httpStatus;
|
|
53
|
+
if (this.requestId !== void 0) out.requestId = this.requestId;
|
|
54
|
+
if (this.retryAfterMs !== void 0) out.retryAfterMs = this.retryAfterMs;
|
|
55
|
+
return out;
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
var ConfigError = class extends AwsSecretsManagerError {
|
|
59
|
+
constructor(message, details) {
|
|
60
|
+
super(ErrorCode.Config, message, details);
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
var AuthenticationError = class extends AwsSecretsManagerError {
|
|
64
|
+
constructor(message, details) {
|
|
65
|
+
super(ErrorCode.Authentication, message, details);
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
var PermissionDeniedError = class extends AwsSecretsManagerError {
|
|
69
|
+
constructor(message, details) {
|
|
70
|
+
super(ErrorCode.PermissionDenied, message, details);
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
var NotFoundError = class extends AwsSecretsManagerError {
|
|
74
|
+
constructor(message, details) {
|
|
75
|
+
super(ErrorCode.NotFound, message, details);
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
var ConflictError = class extends AwsSecretsManagerError {
|
|
79
|
+
constructor(message, details) {
|
|
80
|
+
super(ErrorCode.Conflict, message, details);
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
var RateLimitError = class extends AwsSecretsManagerError {
|
|
84
|
+
constructor(message, details) {
|
|
85
|
+
super(ErrorCode.RateLimited, message, details);
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
var ValidationError = class extends AwsSecretsManagerError {
|
|
89
|
+
constructor(message, details) {
|
|
90
|
+
super(ErrorCode.Validation, message, details);
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
var UnavailableError = class extends AwsSecretsManagerError {
|
|
94
|
+
constructor(message, details) {
|
|
95
|
+
super(ErrorCode.Unavailable, message, details);
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
var TimeoutError = class extends AwsSecretsManagerError {
|
|
99
|
+
constructor(message, details) {
|
|
100
|
+
super(ErrorCode.Timeout, message, details);
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
var UnsupportedError = class extends AwsSecretsManagerError {
|
|
104
|
+
constructor(message, details) {
|
|
105
|
+
super(ErrorCode.Unsupported, message, details);
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
var CancelledError = class extends AwsSecretsManagerError {
|
|
109
|
+
constructor(message, details) {
|
|
110
|
+
super(ErrorCode.Cancelled, message, details);
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
var CLASS_BY_CODE = {
|
|
114
|
+
CONFIG: ConfigError,
|
|
115
|
+
AUTHENTICATION: AuthenticationError,
|
|
116
|
+
PERMISSION_DENIED: PermissionDeniedError,
|
|
117
|
+
NOT_FOUND: NotFoundError,
|
|
118
|
+
CONFLICT: ConflictError,
|
|
119
|
+
RATE_LIMITED: RateLimitError,
|
|
120
|
+
VALIDATION: ValidationError,
|
|
121
|
+
UNAVAILABLE: UnavailableError,
|
|
122
|
+
TIMEOUT: TimeoutError,
|
|
123
|
+
UNSUPPORTED: UnsupportedError,
|
|
124
|
+
CANCELLED: CancelledError
|
|
125
|
+
};
|
|
126
|
+
var REASON_BY_CODE = {
|
|
127
|
+
CONFIG: "invalid configuration",
|
|
128
|
+
AUTHENTICATION: "authentication failed",
|
|
129
|
+
PERMISSION_DENIED: "permission denied",
|
|
130
|
+
NOT_FOUND: "not found",
|
|
131
|
+
CONFLICT: "conflict",
|
|
132
|
+
RATE_LIMITED: "rate limited",
|
|
133
|
+
VALIDATION: "invalid request",
|
|
134
|
+
UNAVAILABLE: "service unavailable",
|
|
135
|
+
TIMEOUT: "timed out",
|
|
136
|
+
UNSUPPORTED: "not supported",
|
|
137
|
+
CANCELLED: "cancelled"
|
|
138
|
+
};
|
|
139
|
+
function errorForCode(code, message, details) {
|
|
140
|
+
return new CLASS_BY_CODE[code](message, details);
|
|
141
|
+
}
|
|
142
|
+
function reasonForCode(code) {
|
|
143
|
+
return REASON_BY_CODE[code];
|
|
144
|
+
}
|
|
145
|
+
function codeForStatus(status) {
|
|
146
|
+
switch (status) {
|
|
147
|
+
case 401:
|
|
148
|
+
return ErrorCode.Authentication;
|
|
149
|
+
case 403:
|
|
150
|
+
return ErrorCode.PermissionDenied;
|
|
151
|
+
case 404:
|
|
152
|
+
return ErrorCode.NotFound;
|
|
153
|
+
case 409:
|
|
154
|
+
case 412:
|
|
155
|
+
return ErrorCode.Conflict;
|
|
156
|
+
case 429:
|
|
157
|
+
return ErrorCode.RateLimited;
|
|
158
|
+
case 408:
|
|
159
|
+
case 504:
|
|
160
|
+
return ErrorCode.Timeout;
|
|
161
|
+
case 501:
|
|
162
|
+
return ErrorCode.Unsupported;
|
|
163
|
+
default:
|
|
164
|
+
return status >= 500 ? ErrorCode.Unavailable : ErrorCode.Validation;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
function errorForStatus(operation, status, details = {}) {
|
|
168
|
+
const code = codeForStatus(status);
|
|
169
|
+
const { reason, ...rest } = details;
|
|
170
|
+
const text = reason !== void 0 && reason !== "" ? reason : reasonForCode(code);
|
|
171
|
+
return errorForCode(code, `${operation}: ${text} (HTTP ${status})`, {
|
|
172
|
+
...rest,
|
|
173
|
+
httpStatus: status
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
function isAwsSecretsManagerError(err, code) {
|
|
177
|
+
return err instanceof AwsSecretsManagerError && (code === void 0 || err.code === code);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// src/core/abort.ts
|
|
181
|
+
function throwIfAborted(signal, operation) {
|
|
182
|
+
if (signal?.aborted === true) throw new CancelledError(`${operation}: cancelled`);
|
|
183
|
+
}
|
|
184
|
+
function sleep(ms, signal, operation = "sleep") {
|
|
185
|
+
return new Promise((resolve, reject) => {
|
|
186
|
+
if (signal?.aborted === true) {
|
|
187
|
+
reject(new CancelledError(`${operation}: cancelled`));
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
const onAbort = () => {
|
|
191
|
+
clearTimeout(timer);
|
|
192
|
+
reject(new CancelledError(`${operation}: cancelled`));
|
|
193
|
+
};
|
|
194
|
+
const timer = setTimeout(
|
|
195
|
+
() => {
|
|
196
|
+
signal?.removeEventListener("abort", onAbort);
|
|
197
|
+
resolve();
|
|
198
|
+
},
|
|
199
|
+
Math.max(0, ms)
|
|
200
|
+
);
|
|
201
|
+
timer.unref();
|
|
202
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// src/core/redaction.ts
|
|
207
|
+
var REDACTED = "[REDACTED]";
|
|
208
|
+
var INSPECT = /* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom");
|
|
209
|
+
var SENSITIVE_HEADERS = /* @__PURE__ */ new Set([
|
|
210
|
+
"authorization",
|
|
211
|
+
"proxy-authorization",
|
|
212
|
+
"cookie",
|
|
213
|
+
"set-cookie"
|
|
214
|
+
]);
|
|
215
|
+
var SENSITIVE_HEADER_PARTS = [
|
|
216
|
+
"token",
|
|
217
|
+
"secret",
|
|
218
|
+
"password",
|
|
219
|
+
"api-key",
|
|
220
|
+
"apikey",
|
|
221
|
+
"key",
|
|
222
|
+
"auth",
|
|
223
|
+
"session",
|
|
224
|
+
"signature",
|
|
225
|
+
"credential"
|
|
226
|
+
];
|
|
227
|
+
var SENSITIVE_FIELD_PARTS = [
|
|
228
|
+
"password",
|
|
229
|
+
"passwd",
|
|
230
|
+
"secret",
|
|
231
|
+
"token",
|
|
232
|
+
"authorization",
|
|
233
|
+
"cookie",
|
|
234
|
+
"api_key",
|
|
235
|
+
"apikey",
|
|
236
|
+
"api-key",
|
|
237
|
+
"access_key",
|
|
238
|
+
"private_key",
|
|
239
|
+
"client_secret",
|
|
240
|
+
"credential",
|
|
241
|
+
"session",
|
|
242
|
+
"signature"
|
|
243
|
+
];
|
|
244
|
+
var MIN_SECRET_LENGTH = 4;
|
|
245
|
+
function isSensitiveHeader(name) {
|
|
246
|
+
const n = name.toLowerCase();
|
|
247
|
+
return SENSITIVE_HEADERS.has(n) || SENSITIVE_HEADER_PARTS.some((p) => n.includes(p));
|
|
248
|
+
}
|
|
249
|
+
var PATH_NAME = /path$/;
|
|
250
|
+
function isSensitiveField(name, extraKeys = []) {
|
|
251
|
+
const n = name.toLowerCase();
|
|
252
|
+
return !PATH_NAME.test(n) && SENSITIVE_FIELD_PARTS.some((p) => n.includes(p)) || extraKeys.some((k) => k !== "" && n.includes(k.toLowerCase()));
|
|
253
|
+
}
|
|
254
|
+
function headerEntries(headers) {
|
|
255
|
+
if (Symbol.iterator in headers) {
|
|
256
|
+
return Array.from(headers, ([k, v]) => [k, v]);
|
|
257
|
+
}
|
|
258
|
+
const out = [];
|
|
259
|
+
for (const [k, v] of Object.entries(headers)) {
|
|
260
|
+
if (v === void 0) continue;
|
|
261
|
+
out.push([k, typeof v === "string" ? v : v.join(", ")]);
|
|
262
|
+
}
|
|
263
|
+
return out;
|
|
264
|
+
}
|
|
265
|
+
function redactHeaders(headers) {
|
|
266
|
+
const out = {};
|
|
267
|
+
for (const [k, v] of headerEntries(headers)) {
|
|
268
|
+
out[k] = isSensitiveHeader(k) ? REDACTED : v;
|
|
269
|
+
}
|
|
270
|
+
return out;
|
|
271
|
+
}
|
|
272
|
+
function redactUrl(url) {
|
|
273
|
+
let parsed;
|
|
274
|
+
try {
|
|
275
|
+
parsed = new URL(url.toString());
|
|
276
|
+
} catch {
|
|
277
|
+
return redactQueryString(url.toString());
|
|
278
|
+
}
|
|
279
|
+
if (parsed.password !== "") parsed.password = REDACTED;
|
|
280
|
+
if (parsed.password === "" && parsed.username !== "" && parsed.username !== REDACTED) {
|
|
281
|
+
parsed.username = REDACTED;
|
|
282
|
+
}
|
|
283
|
+
const params = parsed.searchParams;
|
|
284
|
+
let changed = false;
|
|
285
|
+
const next = new URLSearchParams();
|
|
286
|
+
for (const [k, v] of params) {
|
|
287
|
+
if (isSensitiveField(k)) {
|
|
288
|
+
next.append(k, REDACTED);
|
|
289
|
+
changed = true;
|
|
290
|
+
} else {
|
|
291
|
+
next.append(k, v);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
if (changed) parsed.search = next.toString();
|
|
295
|
+
return parsed.toString().replaceAll(encodeURIComponent(REDACTED), REDACTED);
|
|
296
|
+
}
|
|
297
|
+
function redactQueryString(text) {
|
|
298
|
+
return text.replace(
|
|
299
|
+
/([?&])([^=&#\s]+)=([^&#\s]*)/g,
|
|
300
|
+
(m, sep, k) => isSensitiveField(k) ? `${sep}${k}=${REDACTED}` : m
|
|
301
|
+
);
|
|
302
|
+
}
|
|
303
|
+
function redactFields(value, extraKeys = []) {
|
|
304
|
+
return redactValue(value, extraKeys, /* @__PURE__ */ new WeakMap());
|
|
305
|
+
}
|
|
306
|
+
function redactValue(value, extraKeys, seen) {
|
|
307
|
+
if (value === null || typeof value !== "object") return value;
|
|
308
|
+
if (value instanceof Date || value instanceof Uint8Array) return value;
|
|
309
|
+
const cached = seen.get(value);
|
|
310
|
+
if (cached !== void 0) return cached;
|
|
311
|
+
if (Array.isArray(value)) {
|
|
312
|
+
const arr = [];
|
|
313
|
+
seen.set(value, arr);
|
|
314
|
+
for (const item of value) arr.push(redactValue(item, extraKeys, seen));
|
|
315
|
+
return arr;
|
|
316
|
+
}
|
|
317
|
+
if (value instanceof Map) {
|
|
318
|
+
const map = /* @__PURE__ */ new Map();
|
|
319
|
+
seen.set(value, map);
|
|
320
|
+
for (const [k, v] of value) {
|
|
321
|
+
map.set(
|
|
322
|
+
k,
|
|
323
|
+
typeof k === "string" && isSensitiveField(k, extraKeys) ? REDACTED : redactValue(v, extraKeys, seen)
|
|
324
|
+
);
|
|
325
|
+
}
|
|
326
|
+
return map;
|
|
327
|
+
}
|
|
328
|
+
const out = {};
|
|
329
|
+
seen.set(value, out);
|
|
330
|
+
for (const [k, v] of Object.entries(value)) {
|
|
331
|
+
out[k] = isSensitiveField(k, extraKeys) ? REDACTED : redactValue(v, extraKeys, seen);
|
|
332
|
+
}
|
|
333
|
+
return out;
|
|
334
|
+
}
|
|
335
|
+
function redactText(text, knownSecrets = []) {
|
|
336
|
+
const values = /* @__PURE__ */ new Set();
|
|
337
|
+
for (const s of knownSecrets) {
|
|
338
|
+
const v = s instanceof Secret ? s.reveal() : s;
|
|
339
|
+
if (typeof v === "string" && v.length >= MIN_SECRET_LENGTH) values.add(v);
|
|
340
|
+
}
|
|
341
|
+
let out = text;
|
|
342
|
+
for (const v of [...values].sort((a, b) => b.length - a.length)) {
|
|
343
|
+
out = out.split(v).join(REDACTED);
|
|
344
|
+
}
|
|
345
|
+
return out;
|
|
346
|
+
}
|
|
347
|
+
var Secret = class _Secret {
|
|
348
|
+
#value;
|
|
349
|
+
constructor(value) {
|
|
350
|
+
this.#value = value;
|
|
351
|
+
}
|
|
352
|
+
/** Wraps a string (returns `undefined` for `undefined`/empty, keeps an existing Secret). */
|
|
353
|
+
static from(value) {
|
|
354
|
+
if (value === void 0 || value === null) return void 0;
|
|
355
|
+
if (value instanceof _Secret) return value;
|
|
356
|
+
return value === "" ? void 0 : new _Secret(value);
|
|
357
|
+
}
|
|
358
|
+
/** The wrapped value. */
|
|
359
|
+
reveal() {
|
|
360
|
+
return this.#value;
|
|
361
|
+
}
|
|
362
|
+
/** Constant-time-ish comparison with another value. */
|
|
363
|
+
equals(other) {
|
|
364
|
+
const a = this.#value;
|
|
365
|
+
const b = other instanceof _Secret ? other.reveal() : other;
|
|
366
|
+
if (a.length !== b.length) return false;
|
|
367
|
+
let diff = 0;
|
|
368
|
+
for (let i = 0; i < a.length; i++) diff |= a.charCodeAt(i) ^ b.charCodeAt(i);
|
|
369
|
+
return diff === 0;
|
|
370
|
+
}
|
|
371
|
+
toString() {
|
|
372
|
+
return REDACTED;
|
|
373
|
+
}
|
|
374
|
+
toJSON() {
|
|
375
|
+
return REDACTED;
|
|
376
|
+
}
|
|
377
|
+
[INSPECT]() {
|
|
378
|
+
return REDACTED;
|
|
379
|
+
}
|
|
380
|
+
};
|
|
381
|
+
function redactError(err, knownSecrets = []) {
|
|
382
|
+
const secrets = [...knownSecrets];
|
|
383
|
+
if (err instanceof Error) {
|
|
384
|
+
const copy = new Error(redactText(redactQueryString(err.message), secrets));
|
|
385
|
+
copy.name = err.name;
|
|
386
|
+
const code = err.code;
|
|
387
|
+
if (typeof code === "string") copy.code = code;
|
|
388
|
+
if (err.cause !== void 0) copy.cause = redactError(err.cause, secrets);
|
|
389
|
+
return copy;
|
|
390
|
+
}
|
|
391
|
+
return new Error(redactText(String(err), secrets));
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
// src/core/env.ts
|
|
395
|
+
var UNIT_MS = {
|
|
396
|
+
ns: 1e-6,
|
|
397
|
+
us: 1e-3,
|
|
398
|
+
\u00B5s: 1e-3,
|
|
399
|
+
ms: 1,
|
|
400
|
+
s: 1e3,
|
|
401
|
+
m: 6e4,
|
|
402
|
+
h: 36e5
|
|
403
|
+
};
|
|
404
|
+
var DURATION_PART = /(\d+(?:\.\d+)?|\.\d+)(ns|us|µs|ms|s|m|h)/gy;
|
|
405
|
+
function parseDuration(raw) {
|
|
406
|
+
const text = raw.trim();
|
|
407
|
+
if (/^\d+$/.test(text)) return Number(text);
|
|
408
|
+
if (text === "") return void 0;
|
|
409
|
+
DURATION_PART.lastIndex = 0;
|
|
410
|
+
let total = 0;
|
|
411
|
+
let pos = 0;
|
|
412
|
+
let match;
|
|
413
|
+
while ((match = DURATION_PART.exec(text)) !== null) {
|
|
414
|
+
total += Number(match[1]) * UNIT_MS[match[2]];
|
|
415
|
+
pos = DURATION_PART.lastIndex;
|
|
416
|
+
}
|
|
417
|
+
return pos === text.length && pos > 0 ? Math.round(total) : void 0;
|
|
418
|
+
}
|
|
419
|
+
var TRUE_WORDS = /* @__PURE__ */ new Set(["true", "1", "yes", "on"]);
|
|
420
|
+
var FALSE_WORDS = /* @__PURE__ */ new Set(["false", "0", "no", "off"]);
|
|
421
|
+
function parseBool(raw) {
|
|
422
|
+
const text = raw.trim().toLowerCase();
|
|
423
|
+
if (TRUE_WORDS.has(text)) return true;
|
|
424
|
+
if (FALSE_WORDS.has(text)) return false;
|
|
425
|
+
return void 0;
|
|
426
|
+
}
|
|
427
|
+
function parseInteger(raw) {
|
|
428
|
+
const text = raw.trim();
|
|
429
|
+
if (!/^[+-]?\d+$/.test(text)) return void 0;
|
|
430
|
+
const n = Number(text);
|
|
431
|
+
return Number.isSafeInteger(n) ? n : void 0;
|
|
432
|
+
}
|
|
433
|
+
var EnvReader = class {
|
|
434
|
+
prefix;
|
|
435
|
+
#env;
|
|
436
|
+
/**
|
|
437
|
+
* @param prefix e.g. `"GROW_AWS_SECRETS_MANAGER_"`.
|
|
438
|
+
* @param env environment map, defaults to `process.env`.
|
|
439
|
+
*/
|
|
440
|
+
constructor(prefix, env = process.env) {
|
|
441
|
+
this.prefix = prefix;
|
|
442
|
+
this.#env = env;
|
|
443
|
+
}
|
|
444
|
+
/** Finds the first present variable: `<prefix><name>`, then each vendor name. */
|
|
445
|
+
lookup(name, vendorNames = []) {
|
|
446
|
+
for (const candidate of [this.prefix + name, ...vendorNames]) {
|
|
447
|
+
const value = this.#env[candidate];
|
|
448
|
+
if (value !== void 0 && value !== "") return { name: candidate, value };
|
|
449
|
+
}
|
|
450
|
+
return void 0;
|
|
451
|
+
}
|
|
452
|
+
/** String value. */
|
|
453
|
+
string(name, vendorNames = []) {
|
|
454
|
+
return this.lookup(name, vendorNames)?.value;
|
|
455
|
+
}
|
|
456
|
+
/** Credential value wrapped in a {@link Secret}. */
|
|
457
|
+
secret(name, vendorNames = []) {
|
|
458
|
+
return Secret.from(this.string(name, vendorNames));
|
|
459
|
+
}
|
|
460
|
+
/** Duration in milliseconds (see {@link parseDuration}). */
|
|
461
|
+
duration(name, vendorNames = []) {
|
|
462
|
+
return this.#parse(name, vendorNames, parseDuration, "a duration such as 1500, 500ms or 10s");
|
|
463
|
+
}
|
|
464
|
+
/** Boolean (see {@link parseBool}). */
|
|
465
|
+
bool(name, vendorNames = []) {
|
|
466
|
+
return this.#parse(name, vendorNames, parseBool, "a boolean (true/false/1/0/yes/no/on/off)");
|
|
467
|
+
}
|
|
468
|
+
/** Integer. */
|
|
469
|
+
int(name, vendorNames = []) {
|
|
470
|
+
return this.#parse(name, vendorNames, parseInteger, "an integer");
|
|
471
|
+
}
|
|
472
|
+
#parse(name, vendorNames, parse, expected) {
|
|
473
|
+
const hit = this.lookup(name, vendorNames);
|
|
474
|
+
if (hit === void 0) return void 0;
|
|
475
|
+
const value = parse(hit.value);
|
|
476
|
+
if (value === void 0) {
|
|
477
|
+
throw new ConfigError(
|
|
478
|
+
`invalid value in environment variable ${hit.name}: expected ${expected}`
|
|
479
|
+
);
|
|
480
|
+
}
|
|
481
|
+
return value;
|
|
482
|
+
}
|
|
483
|
+
};
|
|
484
|
+
|
|
485
|
+
// src/core/poll.ts
|
|
486
|
+
async function pollUntil(fn, predicate, options = {}) {
|
|
487
|
+
const timeoutMs = options.timeoutMs ?? 3e4;
|
|
488
|
+
const intervalMs = options.intervalMs ?? 1e3;
|
|
489
|
+
const operation = options.operation ?? "poll";
|
|
490
|
+
const sleep2 = options.sleep ?? sleep;
|
|
491
|
+
const now = options.now ?? Date.now;
|
|
492
|
+
const deadline = now() + timeoutMs;
|
|
493
|
+
let lastError;
|
|
494
|
+
for (let attempt = 1; ; attempt++) {
|
|
495
|
+
throwIfAborted(options.signal, operation);
|
|
496
|
+
try {
|
|
497
|
+
const value = await fn(attempt);
|
|
498
|
+
if (predicate(value)) return value;
|
|
499
|
+
} catch (err) {
|
|
500
|
+
if (options.ignoreError?.(err) !== true) throw err;
|
|
501
|
+
lastError = err;
|
|
502
|
+
}
|
|
503
|
+
const remaining = deadline - now();
|
|
504
|
+
if (remaining <= 0) {
|
|
505
|
+
throw new TimeoutError(
|
|
506
|
+
`${operation}: condition not met within ${timeoutMs} ms after ${attempt} attempts`,
|
|
507
|
+
lastError === void 0 ? {} : { cause: lastError }
|
|
508
|
+
);
|
|
509
|
+
}
|
|
510
|
+
await sleep2(Math.min(intervalMs, remaining), options.signal);
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
// src/secrets/env.ts
|
|
515
|
+
function envNameFor(secretName, prefix = "") {
|
|
516
|
+
return prefix + secretName.toUpperCase().replace(/[^A-Z0-9_]/g, "_");
|
|
517
|
+
}
|
|
518
|
+
function relativeName(name, path) {
|
|
519
|
+
if (path === void 0 || path === "") return name;
|
|
520
|
+
if (name.startsWith(path)) return name.slice(path.length).replace(/^\/+/, "");
|
|
521
|
+
const withSlash = path.endsWith("/") ? path : path + "/";
|
|
522
|
+
return name.startsWith(withSlash) ? name.slice(withSlash.length) : name;
|
|
523
|
+
}
|
|
524
|
+
function applyEnv(values, env, override) {
|
|
525
|
+
const set = {};
|
|
526
|
+
for (const [envName, [secretName, value]] of values) {
|
|
527
|
+
if (!override && env[envName] !== void 0) continue;
|
|
528
|
+
env[envName] = value;
|
|
529
|
+
set[envName] = secretName;
|
|
530
|
+
}
|
|
531
|
+
return set;
|
|
532
|
+
}
|
|
533
|
+
var INSPECT2 = /* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom");
|
|
534
|
+
var STRING_FORM = `SecretValue(${REDACTED})`;
|
|
535
|
+
var SecretValue = class _SecretValue {
|
|
536
|
+
#bytes;
|
|
537
|
+
/** Opaque version string (KV `"3"`, AWS VersionId, …) when the service has versions. */
|
|
538
|
+
version;
|
|
539
|
+
constructor(value, version) {
|
|
540
|
+
this.#bytes = typeof value === "string" ? new TextEncoder().encode(value) : Uint8Array.from(value);
|
|
541
|
+
if (version !== void 0) this.version = version;
|
|
542
|
+
Object.freeze(this);
|
|
543
|
+
}
|
|
544
|
+
/** Encodes a string, bytes or a JSON-serialisable object (objects are JSON-encoded). */
|
|
545
|
+
static from(value, version) {
|
|
546
|
+
return new _SecretValue(encodeSecretInput(value), version);
|
|
547
|
+
}
|
|
548
|
+
/** UTF-8 text. Throws {@link ValidationError} when the value is not valid UTF-8. */
|
|
549
|
+
reveal() {
|
|
550
|
+
try {
|
|
551
|
+
return new TextDecoder("utf-8", { fatal: true }).decode(this.#bytes);
|
|
552
|
+
} catch {
|
|
553
|
+
throw new ValidationError("secret value is not valid UTF-8 text; use revealBytes()");
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
/** A copy of the raw bytes. */
|
|
557
|
+
revealBytes() {
|
|
558
|
+
return Uint8Array.from(this.#bytes);
|
|
559
|
+
}
|
|
560
|
+
/** Parses the value as JSON. Throws {@link ValidationError} when it is not JSON. */
|
|
561
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-parameters
|
|
562
|
+
json() {
|
|
563
|
+
const text = this.reveal();
|
|
564
|
+
try {
|
|
565
|
+
return JSON.parse(text);
|
|
566
|
+
} catch {
|
|
567
|
+
throw new ValidationError("secret value is not valid JSON");
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
/** Hex SHA-256 of the bytes (used to detect changes when there is no version). */
|
|
571
|
+
sha256() {
|
|
572
|
+
return crypto.createHash("sha256").update(this.#bytes).digest("hex");
|
|
573
|
+
}
|
|
574
|
+
/** Byte length. */
|
|
575
|
+
get byteLength() {
|
|
576
|
+
return this.#bytes.byteLength;
|
|
577
|
+
}
|
|
578
|
+
toString() {
|
|
579
|
+
return STRING_FORM;
|
|
580
|
+
}
|
|
581
|
+
toJSON() {
|
|
582
|
+
return STRING_FORM;
|
|
583
|
+
}
|
|
584
|
+
[INSPECT2]() {
|
|
585
|
+
return STRING_FORM;
|
|
586
|
+
}
|
|
587
|
+
};
|
|
588
|
+
function encodeSecretInput(value) {
|
|
589
|
+
if (typeof value === "string") return new TextEncoder().encode(value);
|
|
590
|
+
if (value instanceof Uint8Array) return value;
|
|
591
|
+
return new TextEncoder().encode(JSON.stringify(value));
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
// src/secrets/watch.ts
|
|
595
|
+
function secretFingerprint(value) {
|
|
596
|
+
if (value === null) return "absent";
|
|
597
|
+
return value.version !== void 0 && value.version !== "" ? `v:${value.version}` : `h:${value.sha256()}`;
|
|
598
|
+
}
|
|
599
|
+
function watchSecret(read, intervalMs, onChange, options = {}) {
|
|
600
|
+
if (!Number.isFinite(intervalMs) || intervalMs <= 0) {
|
|
601
|
+
throw new ValidationError("watch: intervalMs must be a positive number");
|
|
602
|
+
}
|
|
603
|
+
const report = (err) => {
|
|
604
|
+
try {
|
|
605
|
+
options.onError?.(err);
|
|
606
|
+
} catch {
|
|
607
|
+
}
|
|
608
|
+
};
|
|
609
|
+
let stopped = false;
|
|
610
|
+
let timer;
|
|
611
|
+
let known = false;
|
|
612
|
+
let current = null;
|
|
613
|
+
let fingerprint = "";
|
|
614
|
+
const tick = async () => {
|
|
615
|
+
try {
|
|
616
|
+
const next = await read();
|
|
617
|
+
if (stopped) return;
|
|
618
|
+
const fp = secretFingerprint(next);
|
|
619
|
+
if (!known) {
|
|
620
|
+
known = true;
|
|
621
|
+
} else if (fp !== fingerprint) {
|
|
622
|
+
const old = current;
|
|
623
|
+
current = next;
|
|
624
|
+
fingerprint = fp;
|
|
625
|
+
try {
|
|
626
|
+
await onChange(next, old);
|
|
627
|
+
} catch (err) {
|
|
628
|
+
report(err);
|
|
629
|
+
}
|
|
630
|
+
return;
|
|
631
|
+
}
|
|
632
|
+
current = next;
|
|
633
|
+
fingerprint = fp;
|
|
634
|
+
} catch (err) {
|
|
635
|
+
if (!stopped) report(err);
|
|
636
|
+
}
|
|
637
|
+
};
|
|
638
|
+
const schedule = () => {
|
|
639
|
+
if (stopped) return;
|
|
640
|
+
timer = setTimeout(() => {
|
|
641
|
+
void tick().finally(schedule);
|
|
642
|
+
}, intervalMs);
|
|
643
|
+
timer.unref();
|
|
644
|
+
};
|
|
645
|
+
const ready = tick().finally(schedule);
|
|
646
|
+
return {
|
|
647
|
+
stop() {
|
|
648
|
+
stopped = true;
|
|
649
|
+
if (timer !== void 0) clearTimeout(timer);
|
|
650
|
+
},
|
|
651
|
+
get stopped() {
|
|
652
|
+
return stopped;
|
|
653
|
+
},
|
|
654
|
+
ready
|
|
655
|
+
};
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
// src/secrets/base.ts
|
|
659
|
+
var GET_MANY_CONCURRENCY = 8;
|
|
660
|
+
var BaseSecretsProvider = class {
|
|
661
|
+
#watchers = /* @__PURE__ */ new Set();
|
|
662
|
+
#closed = false;
|
|
663
|
+
async get(name, options = {}) {
|
|
664
|
+
this.ensureOpen(`secrets.get ${name}`);
|
|
665
|
+
throwIfAborted(options.signal, `secrets.get ${name}`);
|
|
666
|
+
return await this.fetchSecret(name, options);
|
|
667
|
+
}
|
|
668
|
+
async getString(name, options) {
|
|
669
|
+
return (await this.get(name, options))?.reveal() ?? null;
|
|
670
|
+
}
|
|
671
|
+
async getJson(name, options) {
|
|
672
|
+
const value = await this.get(name, options);
|
|
673
|
+
if (value === null) return null;
|
|
674
|
+
try {
|
|
675
|
+
return value.json();
|
|
676
|
+
} catch {
|
|
677
|
+
throw new ValidationError(`secrets.getJson ${name}: value is not valid JSON`);
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
async getNumber(name, options) {
|
|
681
|
+
const text = await this.getString(name, options);
|
|
682
|
+
if (text === null) return null;
|
|
683
|
+
const trimmed = text.trim();
|
|
684
|
+
const n = trimmed === "" ? Number.NaN : Number(trimmed);
|
|
685
|
+
if (!Number.isFinite(n))
|
|
686
|
+
throw new ValidationError(`secrets.getNumber ${name}: value is not a number`);
|
|
687
|
+
return n;
|
|
688
|
+
}
|
|
689
|
+
async getBool(name, options) {
|
|
690
|
+
const text = await this.getString(name, options);
|
|
691
|
+
if (text === null) return null;
|
|
692
|
+
const b = parseBool(text);
|
|
693
|
+
if (b === void 0)
|
|
694
|
+
throw new ValidationError(`secrets.getBool ${name}: value is not a boolean`);
|
|
695
|
+
return b;
|
|
696
|
+
}
|
|
697
|
+
async require(name, options) {
|
|
698
|
+
const value = await this.get(name, options);
|
|
699
|
+
if (value === null) throw new NotFoundError(`secrets.require ${name}: not found`);
|
|
700
|
+
return value;
|
|
701
|
+
}
|
|
702
|
+
async exists(name, options) {
|
|
703
|
+
return await this.get(name, options) !== null;
|
|
704
|
+
}
|
|
705
|
+
async getMany(names, options) {
|
|
706
|
+
const unique = [...new Set(names)];
|
|
707
|
+
const found = /* @__PURE__ */ new Map();
|
|
708
|
+
let next = 0;
|
|
709
|
+
const worker = async () => {
|
|
710
|
+
while (next < unique.length) {
|
|
711
|
+
const name = unique[next++];
|
|
712
|
+
const value = await this.get(name, options);
|
|
713
|
+
if (value !== null) found.set(name, value);
|
|
714
|
+
}
|
|
715
|
+
};
|
|
716
|
+
await Promise.all(
|
|
717
|
+
Array.from({ length: Math.min(GET_MANY_CONCURRENCY, unique.length) }, worker)
|
|
718
|
+
);
|
|
719
|
+
const ordered = /* @__PURE__ */ new Map();
|
|
720
|
+
for (const name of unique) {
|
|
721
|
+
const value = found.get(name);
|
|
722
|
+
if (value !== void 0) ordered.set(name, value);
|
|
723
|
+
}
|
|
724
|
+
return ordered;
|
|
725
|
+
}
|
|
726
|
+
async getAll(path, options = {}) {
|
|
727
|
+
const metas = await this.list(path, options);
|
|
728
|
+
return this.getMany(
|
|
729
|
+
metas.map((m) => m.name),
|
|
730
|
+
options
|
|
731
|
+
);
|
|
732
|
+
}
|
|
733
|
+
async list(prefixOrPath, options = {}) {
|
|
734
|
+
this.ensureOpen("secrets.list");
|
|
735
|
+
throwIfAborted(options.signal, "secrets.list");
|
|
736
|
+
const metas = await this.listSecrets(prefixOrPath, options);
|
|
737
|
+
return [...metas].sort((a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0);
|
|
738
|
+
}
|
|
739
|
+
async set(name, value, options = {}) {
|
|
740
|
+
this.ensureOpen(`secrets.set ${name}`);
|
|
741
|
+
throwIfAborted(options.signal, `secrets.set ${name}`);
|
|
742
|
+
return await this.putSecret(name, encodeSecretInput(value), options);
|
|
743
|
+
}
|
|
744
|
+
async delete(name, options = {}) {
|
|
745
|
+
this.ensureOpen(`secrets.delete ${name}`);
|
|
746
|
+
throwIfAborted(options.signal, `secrets.delete ${name}`);
|
|
747
|
+
await this.removeSecret(name, options);
|
|
748
|
+
}
|
|
749
|
+
async metadata(name, options = {}) {
|
|
750
|
+
this.ensureOpen(`secrets.metadata ${name}`);
|
|
751
|
+
throwIfAborted(options.signal, `secrets.metadata ${name}`);
|
|
752
|
+
return await this.fetchMetadata(name, options);
|
|
753
|
+
}
|
|
754
|
+
async loadEnv(source, options = {}) {
|
|
755
|
+
const env = options.env ?? process.env;
|
|
756
|
+
const values = /* @__PURE__ */ new Map();
|
|
757
|
+
const signal = options.signal === void 0 ? {} : { signal: options.signal };
|
|
758
|
+
if (typeof source === "string") {
|
|
759
|
+
const all = await this.getAll(source, signal);
|
|
760
|
+
for (const [name, value] of all) {
|
|
761
|
+
values.set(envNameFor(relativeName(name, source), options.prefix ?? ""), [
|
|
762
|
+
name,
|
|
763
|
+
value.reveal()
|
|
764
|
+
]);
|
|
765
|
+
}
|
|
766
|
+
} else {
|
|
767
|
+
for (const [envName, secretName] of Object.entries(source)) {
|
|
768
|
+
const value = await this.require(secretName, signal);
|
|
769
|
+
values.set(envName, [secretName, value.reveal()]);
|
|
770
|
+
}
|
|
771
|
+
}
|
|
772
|
+
return applyEnv(values, env, options.override === true);
|
|
773
|
+
}
|
|
774
|
+
watch(name, intervalMs, onChange, options = {}) {
|
|
775
|
+
this.ensureOpen(`secrets.watch ${name}`);
|
|
776
|
+
const inner = watchSecret(() => this.get(name, options.get), intervalMs, onChange, options);
|
|
777
|
+
const watchers = this.#watchers;
|
|
778
|
+
const handle = {
|
|
779
|
+
stop() {
|
|
780
|
+
inner.stop();
|
|
781
|
+
watchers.delete(handle);
|
|
782
|
+
},
|
|
783
|
+
get stopped() {
|
|
784
|
+
return inner.stopped;
|
|
785
|
+
},
|
|
786
|
+
ready: inner.ready
|
|
787
|
+
};
|
|
788
|
+
watchers.add(handle);
|
|
789
|
+
return handle;
|
|
790
|
+
}
|
|
791
|
+
/** Number of active watchers. */
|
|
792
|
+
get activeWatchers() {
|
|
793
|
+
return this.#watchers.size;
|
|
794
|
+
}
|
|
795
|
+
/** Stops every watcher started by this provider. Idempotent. */
|
|
796
|
+
stopWatchers() {
|
|
797
|
+
for (const w of [...this.#watchers]) w.stop();
|
|
798
|
+
}
|
|
799
|
+
/** Whether {@link close} was called. */
|
|
800
|
+
get closed() {
|
|
801
|
+
return this.#closed;
|
|
802
|
+
}
|
|
803
|
+
/**
|
|
804
|
+
* Throws `CancelledError` (`"<operation>: client is closed"`, not retryable) once {@link close}
|
|
805
|
+
* was called (SPEC §2.4). The public operations call it before any I/O; service operations
|
|
806
|
+
* can call it too.
|
|
807
|
+
*/
|
|
808
|
+
ensureOpen(operation) {
|
|
809
|
+
if (this.#closed) throw new CancelledError(`${operation}: client is closed`);
|
|
810
|
+
}
|
|
811
|
+
/**
|
|
812
|
+
* Stops all watchers (the owning client calls this from `close()`); later calls fail with
|
|
813
|
+
* `CANCELLED`. Idempotent. Subclasses overriding it must call `super.close()`.
|
|
814
|
+
*/
|
|
815
|
+
close() {
|
|
816
|
+
this.stopWatchers();
|
|
817
|
+
this.#closed = true;
|
|
818
|
+
return Promise.resolve();
|
|
819
|
+
}
|
|
820
|
+
};
|
|
821
|
+
|
|
822
|
+
exports.AuthenticationError = AuthenticationError;
|
|
823
|
+
exports.AwsSecretsManagerError = AwsSecretsManagerError;
|
|
824
|
+
exports.BaseSecretsProvider = BaseSecretsProvider;
|
|
825
|
+
exports.CancelledError = CancelledError;
|
|
826
|
+
exports.ConfigError = ConfigError;
|
|
827
|
+
exports.ConflictError = ConflictError;
|
|
828
|
+
exports.EnvReader = EnvReader;
|
|
829
|
+
exports.ErrorCode = ErrorCode;
|
|
830
|
+
exports.GET_MANY_CONCURRENCY = GET_MANY_CONCURRENCY;
|
|
831
|
+
exports.MIN_SECRET_LENGTH = MIN_SECRET_LENGTH;
|
|
832
|
+
exports.NotFoundError = NotFoundError;
|
|
833
|
+
exports.PermissionDeniedError = PermissionDeniedError;
|
|
834
|
+
exports.REDACTED = REDACTED;
|
|
835
|
+
exports.RateLimitError = RateLimitError;
|
|
836
|
+
exports.SENSITIVE_FIELD_PARTS = SENSITIVE_FIELD_PARTS;
|
|
837
|
+
exports.Secret = Secret;
|
|
838
|
+
exports.SecretValue = SecretValue;
|
|
839
|
+
exports.TimeoutError = TimeoutError;
|
|
840
|
+
exports.UnavailableError = UnavailableError;
|
|
841
|
+
exports.UnsupportedError = UnsupportedError;
|
|
842
|
+
exports.ValidationError = ValidationError;
|
|
843
|
+
exports.applyEnv = applyEnv;
|
|
844
|
+
exports.codeForStatus = codeForStatus;
|
|
845
|
+
exports.encodeSecretInput = encodeSecretInput;
|
|
846
|
+
exports.envNameFor = envNameFor;
|
|
847
|
+
exports.errorForCode = errorForCode;
|
|
848
|
+
exports.errorForStatus = errorForStatus;
|
|
849
|
+
exports.isAwsSecretsManagerError = isAwsSecretsManagerError;
|
|
850
|
+
exports.isSensitiveField = isSensitiveField;
|
|
851
|
+
exports.isSensitiveHeader = isSensitiveHeader;
|
|
852
|
+
exports.parseBool = parseBool;
|
|
853
|
+
exports.parseDuration = parseDuration;
|
|
854
|
+
exports.parseInteger = parseInteger;
|
|
855
|
+
exports.pollUntil = pollUntil;
|
|
856
|
+
exports.reasonForCode = reasonForCode;
|
|
857
|
+
exports.redactError = redactError;
|
|
858
|
+
exports.redactFields = redactFields;
|
|
859
|
+
exports.redactHeaders = redactHeaders;
|
|
860
|
+
exports.redactText = redactText;
|
|
861
|
+
exports.redactUrl = redactUrl;
|
|
862
|
+
exports.relativeName = relativeName;
|
|
863
|
+
exports.secretFingerprint = secretFingerprint;
|
|
864
|
+
exports.sleep = sleep;
|
|
865
|
+
exports.throwIfAborted = throwIfAborted;
|
|
866
|
+
exports.watchSecret = watchSecret;
|
|
867
|
+
//# sourceMappingURL=chunk-ZLYHN4AI.cjs.map
|
|
868
|
+
//# sourceMappingURL=chunk-ZLYHN4AI.cjs.map
|