@aligent/aws-wrappers 0.2.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/cjs/index.cjs CHANGED
@@ -13,133 +13,25 @@ var clientSns = require('@aws-sdk/client-sns');
13
13
  var clientSqs = require('@aws-sdk/client-sqs');
14
14
  var clientSsm = require('@aws-sdk/client-ssm');
15
15
 
16
- /******************************************************************************
17
- Copyright (c) Microsoft Corporation.
18
-
19
- Permission to use, copy, modify, and/or distribute this software for any
20
- purpose with or without fee is hereby granted.
21
-
22
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
23
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
24
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
25
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
26
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
27
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
28
- PERFORMANCE OF THIS SOFTWARE.
29
- ***************************************************************************** */
30
- /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
31
-
32
-
33
- var __assign = function() {
34
- __assign = Object.assign || function __assign(t) {
35
- for (var s, i = 1, n = arguments.length; i < n; i++) {
36
- s = arguments[i];
37
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
38
- }
39
- return t;
40
- };
41
- return __assign.apply(this, arguments);
42
- };
43
-
44
- function __rest(s, e) {
45
- var t = {};
46
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
47
- t[p] = s[p];
48
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
49
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
50
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
51
- t[p[i]] = s[p[i]];
52
- }
53
- return t;
54
- }
55
-
56
- function __awaiter(thisArg, _arguments, P, generator) {
57
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
58
- return new (P || (P = Promise))(function (resolve, reject) {
59
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
60
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
61
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
62
- step((generator = generator.apply(thisArg, _arguments || [])).next());
63
- });
64
- }
65
-
66
- function __generator(thisArg, body) {
67
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
68
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
69
- function verb(n) { return function (v) { return step([n, v]); }; }
70
- function step(op) {
71
- if (f) throw new TypeError("Generator is already executing.");
72
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
73
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
74
- if (y = 0, t) op = [op[0] & 2, t.value];
75
- switch (op[0]) {
76
- case 0: case 1: t = op; break;
77
- case 4: _.label++; return { value: op[1], done: false };
78
- case 5: _.label++; y = op[1]; op = [0]; continue;
79
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
80
- default:
81
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
82
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
83
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
84
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
85
- if (t[2]) _.ops.pop();
86
- _.trys.pop(); continue;
87
- }
88
- op = body.call(thisArg, _);
89
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
90
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
91
- }
92
- }
93
-
94
- function __values(o) {
95
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
96
- if (m) return m.call(o);
97
- if (o && typeof o.length === "number") return {
98
- next: function () {
99
- if (o && i >= o.length) o = void 0;
100
- return { value: o && o[i++], done: !o };
101
- }
102
- };
103
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
104
- }
105
-
106
- function __await(v) {
107
- return this instanceof __await ? (this.v = v, this) : new __await(v);
108
- }
109
-
110
- function __asyncGenerator(thisArg, _arguments, generator) {
111
- if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
112
- var g = generator.apply(thisArg, _arguments || []), i, q = [];
113
- return i = Object.create((typeof AsyncIterator === "function" ? AsyncIterator : Object).prototype), verb("next"), verb("throw"), verb("return", awaitReturn), i[Symbol.asyncIterator] = function () { return this; }, i;
114
- function awaitReturn(f) { return function (v) { return Promise.resolve(v).then(f, reject); }; }
115
- function verb(n, f) { if (g[n]) { i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; if (f) i[n] = f(i[n]); } }
116
- function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
117
- function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
118
- function fulfill(value) { resume("next", value); }
119
- function reject(value) { resume("throw", value); }
120
- function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
121
- }
122
-
123
- function __asyncValues(o) {
124
- if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
125
- var m = o[Symbol.asyncIterator], i;
126
- return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
127
- function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
128
- function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
129
- }
130
-
131
- typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
132
- var e = new Error(message);
133
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
134
- };
135
-
16
+ /**
17
+ * Whether the logger is verbose enough that full SDK inputs — payloads, secret
18
+ * material and PII — may be written to the log.
19
+ *
20
+ * **This is the only place in the package that reads the log level.** Never
21
+ * compare `logger.getLevelName()` yourself: Powertools orders `TRACE` as *more*
22
+ * verbose than `DEBUG` (thresholds 6 and 8), so the obvious
23
+ * `getLevelName() === 'DEBUG'` check silently redacts at the most verbose level
24
+ * available. Route every disclosure decision through this predicate instead.
25
+ */
26
+ function shouldLogFullInput(logger$1) {
27
+ return logger.LogLevelThreshold[logger$1.getLevelName()] <= logger.LogLevelThreshold.DEBUG;
28
+ }
136
29
  /**
137
30
  * Return a log-safe projection of `input` based on the logger's configured level.
138
31
  *
139
- * At `DEBUG`, the full input is returned unchanged — operators who set
140
- * `POWERTOOLS_LOG_LEVEL=DEBUG` (or call `logger.setLogLevel('DEBUG')`) have
141
- * explicitly opted into seeing everything, including payloads, secret material
142
- * and PII.
32
+ * At the verbose levels — see {@link shouldLogFullInput} — the full input is
33
+ * returned unchanged: operators who asked for that verbosity have explicitly
34
+ * opted into seeing everything, including payloads, secret material and PII.
143
35
  *
144
36
  * At any other level, only the fields listed in `safeFields` are included.
145
37
  * Missing fields are silently skipped — the result type narrows to
@@ -150,24 +42,22 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
150
42
  * the design rationale and conventions on building the safe-field lists.
151
43
  */
152
44
  function filterFieldsForLogLevel(logger, input, safeFields) {
153
- if (logger.getLevelName() === 'DEBUG')
45
+ if (shouldLogFullInput(logger))
154
46
  return input;
155
- var out = {};
156
- for (var _i = 0, safeFields_1 = safeFields; _i < safeFields_1.length; _i++) {
157
- var key = safeFields_1[_i];
47
+ const out = {};
48
+ for (const key of safeFields) {
158
49
  if (key in input)
159
50
  out[key] = input[key];
160
51
  }
161
52
  return out;
162
53
  }
163
54
 
164
- var BATCH_WRITE_MAX_ATTEMPTS = 5;
165
- var BATCH_WRITE_BASE_DELAY_MS = 200;
55
+ const BATCH_WRITE_MAX_ATTEMPTS = 5;
56
+ const BATCH_WRITE_BASE_DELAY_MS = 200;
166
57
  /**
167
58
  * Fields safe to log at INFO. Omits `Key` (may carry customer IDs / tenant IDs).
168
- * `POWERTOOLS_LOG_LEVEL=DEBUG` unlocks the full input.
169
59
  */
170
- var GET_ITEM_SAFE_FIELDS = [
60
+ const GET_ITEM_SAFE_FIELDS = [
171
61
  'TableName',
172
62
  'ConsistentRead',
173
63
  'ProjectionExpression',
@@ -177,9 +67,8 @@ var GET_ITEM_SAFE_FIELDS = [
177
67
  /**
178
68
  * Fields safe to log at INFO. Omits `Item` (the payload itself) and
179
69
  * `ExpressionAttributeValues` (values bound to ConditionExpression, often PII).
180
- * `POWERTOOLS_LOG_LEVEL=DEBUG` unlocks the full input.
181
70
  */
182
- var PUT_ITEM_SAFE_FIELDS = [
71
+ const PUT_ITEM_SAFE_FIELDS = [
183
72
  'TableName',
184
73
  'ConditionExpression',
185
74
  'ExpressionAttributeNames',
@@ -190,9 +79,8 @@ var PUT_ITEM_SAFE_FIELDS = [
190
79
  ];
191
80
  /**
192
81
  * Fields safe to log at INFO. Omits `Key` and `ExpressionAttributeValues`.
193
- * `POWERTOOLS_LOG_LEVEL=DEBUG` unlocks the full input.
194
82
  */
195
- var UPDATE_ITEM_SAFE_FIELDS = [
83
+ const UPDATE_ITEM_SAFE_FIELDS = [
196
84
  'TableName',
197
85
  'UpdateExpression',
198
86
  'ConditionExpression',
@@ -205,9 +93,8 @@ var UPDATE_ITEM_SAFE_FIELDS = [
205
93
  /**
206
94
  * Fields safe to log at INFO. Omits `Key` and `ExpressionAttributeValues`
207
95
  * (the latter binds to ConditionExpression and may carry PII).
208
- * `POWERTOOLS_LOG_LEVEL=DEBUG` unlocks the full input.
209
96
  */
210
- var DELETE_ITEM_SAFE_FIELDS = [
97
+ const DELETE_ITEM_SAFE_FIELDS = [
211
98
  'TableName',
212
99
  'ConditionExpression',
213
100
  'ExpressionAttributeNames',
@@ -219,10 +106,9 @@ var DELETE_ITEM_SAFE_FIELDS = [
219
106
  /**
220
107
  * Fields safe to log at INFO for `query` and `paginateItems`. Omits
221
108
  * `ExpressionAttributeValues` (values often carry PII) and `ExclusiveStartKey`
222
- * (pagination cursor includes Key shape). `POWERTOOLS_LOG_LEVEL=DEBUG` unlocks
223
- * the full input.
109
+ * (pagination cursor includes Key shape).
224
110
  */
225
- var QUERY_SAFE_FIELDS = [
111
+ const QUERY_SAFE_FIELDS = [
226
112
  'TableName',
227
113
  'IndexName',
228
114
  'KeyConditionExpression',
@@ -238,9 +124,8 @@ var QUERY_SAFE_FIELDS = [
238
124
  /**
239
125
  * Fields safe to log at INFO for `scan` and `paginateScan`. Omits
240
126
  * `ExpressionAttributeValues` and `ExclusiveStartKey`.
241
- * `POWERTOOLS_LOG_LEVEL=DEBUG` unlocks the full input.
242
127
  */
243
- var SCAN_SAFE_FIELDS = [
128
+ const SCAN_SAFE_FIELDS = [
244
129
  'TableName',
245
130
  'IndexName',
246
131
  'FilterExpression',
@@ -253,19 +138,25 @@ var SCAN_SAFE_FIELDS = [
253
138
  'TotalSegments',
254
139
  'ReturnConsumedCapacity',
255
140
  ];
256
- var sleep = function (ms) { return new Promise(function (resolve) { return setTimeout(resolve, ms); }); };
257
- var backoffDelay = function (attempt) {
258
- var exp = BATCH_WRITE_BASE_DELAY_MS * Math.pow(2, attempt);
141
+ const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms));
142
+ const backoffDelay = (attempt) => {
143
+ const exp = BATCH_WRITE_BASE_DELAY_MS * 2 ** attempt;
259
144
  return exp + Math.random() * exp;
260
145
  };
261
146
  /**
262
147
  * Wrapper around the AWS DynamoDB Document client providing structured
263
148
  * Powertools logging and X-Ray tracing by default.
264
149
  *
150
+ * Where a method's input carries payloads, secret material or PII, the INFO
151
+ * log line omits them; the verbose levels (`POWERTOOLS_LOG_LEVEL=DEBUG` or
152
+ * `TRACE`) log full SDK inputs.
153
+ *
265
154
  * Items are automatically marshalled / unmarshalled via the document client —
266
155
  * callers work with plain TypeScript objects in both directions.
267
156
  */
268
- var DynamoDBService = /** @class */ (function () {
157
+ class DynamoDBService {
158
+ client;
159
+ logger;
269
160
  /**
270
161
  * @param opts.logger - Optional Powertools logger. Defaults to `new Logger()`,
271
162
  * which picks up `POWERTOOLS_SERVICE_NAME` from the environment.
@@ -275,13 +166,13 @@ var DynamoDBService = /** @class */ (function () {
275
166
  * *before* being passed to `DynamoDBDocumentClient.from`, so X-Ray
276
167
  * tracing captures every DynamoDB call.
277
168
  */
278
- function DynamoDBService(opts) {
279
- var _a, _b;
169
+ constructor(opts) {
280
170
  this.client =
281
- (_a = opts === null || opts === void 0 ? void 0 : opts.client) !== null && _a !== void 0 ? _a : libDynamodb.DynamoDBDocumentClient.from(xray.captureAWSv3Client(new clientDynamodb.DynamoDBClient({})), {
282
- marshallOptions: { removeUndefinedValues: true },
283
- });
284
- this.logger = (_b = opts === null || opts === void 0 ? void 0 : opts.logger) !== null && _b !== void 0 ? _b : new logger.Logger();
171
+ opts?.client ??
172
+ libDynamodb.DynamoDBDocumentClient.from(xray.captureAWSv3Client(new clientDynamodb.DynamoDBClient({})), {
173
+ marshallOptions: { removeUndefinedValues: true },
174
+ });
175
+ this.logger = opts?.logger ?? new logger.Logger();
285
176
  }
286
177
  /**
287
178
  * Get an item from DynamoDB.
@@ -289,38 +180,24 @@ var DynamoDBService = /** @class */ (function () {
289
180
  * @template R - Expected unmarshalled item shape.
290
181
  * @returns The item, or `undefined` if not found.
291
182
  */
292
- DynamoDBService.prototype.getItem = function (input) {
293
- return __awaiter(this, void 0, void 0, function () {
294
- var response;
295
- return __generator(this, function (_a) {
296
- switch (_a.label) {
297
- case 0:
298
- this.logger.info('Getting DynamoDB item', {
299
- input: filterFieldsForLogLevel(this.logger, input, GET_ITEM_SAFE_FIELDS),
300
- });
301
- return [4 /*yield*/, this.client.send(new libDynamodb.GetCommand(input))];
302
- case 1:
303
- response = _a.sent();
304
- return [2 /*return*/, response.Item];
305
- }
306
- });
183
+ async getItem(input) {
184
+ this.logger.info('Getting DynamoDB item', {
185
+ input: filterFieldsForLogLevel(this.logger, input, GET_ITEM_SAFE_FIELDS),
307
186
  });
308
- };
187
+ const response = await this.client.send(new libDynamodb.GetCommand(input));
188
+ return response.Item;
189
+ }
309
190
  /**
310
191
  * Put an item into DynamoDB. The caller's `Item` is typed as `T`, which
311
192
  * the document client marshalls automatically.
312
193
  * @template T - Type of the item being stored.
313
194
  */
314
- DynamoDBService.prototype.putItem = function (input) {
315
- return __awaiter(this, void 0, void 0, function () {
316
- return __generator(this, function (_a) {
317
- this.logger.info('Putting DynamoDB item', {
318
- input: filterFieldsForLogLevel(this.logger, input, PUT_ITEM_SAFE_FIELDS),
319
- });
320
- return [2 /*return*/, this.client.send(new libDynamodb.PutCommand(input))];
321
- });
195
+ async putItem(input) {
196
+ this.logger.info('Putting DynamoDB item', {
197
+ input: filterFieldsForLogLevel(this.logger, input, PUT_ITEM_SAFE_FIELDS),
322
198
  });
323
- };
199
+ return this.client.send(new libDynamodb.PutCommand(input));
200
+ }
324
201
  /**
325
202
  * Update an item in DynamoDB. The `Attributes` field on the response is
326
203
  * typed as `R` — the caller should choose `R` to match their
@@ -331,69 +208,39 @@ var DynamoDBService = /** @class */ (function () {
331
208
  * @template K - Shape of the partition / sort key.
332
209
  * @template R - Expected shape of the returned `Attributes`.
333
210
  */
334
- DynamoDBService.prototype.updateItem = function (input) {
335
- return __awaiter(this, void 0, void 0, function () {
336
- var response;
337
- return __generator(this, function (_a) {
338
- switch (_a.label) {
339
- case 0:
340
- this.logger.info('Updating DynamoDB item', {
341
- input: filterFieldsForLogLevel(this.logger, input, UPDATE_ITEM_SAFE_FIELDS),
342
- });
343
- return [4 /*yield*/, this.client.send(new libDynamodb.UpdateCommand(input))];
344
- case 1:
345
- response = _a.sent();
346
- return [2 /*return*/, response];
347
- }
348
- });
211
+ async updateItem(input) {
212
+ this.logger.info('Updating DynamoDB item', {
213
+ input: filterFieldsForLogLevel(this.logger, input, UPDATE_ITEM_SAFE_FIELDS),
349
214
  });
350
- };
215
+ const response = await this.client.send(new libDynamodb.UpdateCommand(input));
216
+ return response;
217
+ }
351
218
  /**
352
219
  * Delete an item from DynamoDB. The `Attributes` field on the response is
353
220
  * typed as `R` — relevant when `ReturnValues: 'ALL_OLD'` is set.
354
221
  * @template K - Shape of the partition / sort key.
355
222
  * @template R - Expected shape of the returned `Attributes`.
356
223
  */
357
- DynamoDBService.prototype.deleteItem = function (input) {
358
- return __awaiter(this, void 0, void 0, function () {
359
- var response;
360
- return __generator(this, function (_a) {
361
- switch (_a.label) {
362
- case 0:
363
- this.logger.info('Deleting DynamoDB item', {
364
- input: filterFieldsForLogLevel(this.logger, input, DELETE_ITEM_SAFE_FIELDS),
365
- });
366
- return [4 /*yield*/, this.client.send(new libDynamodb.DeleteCommand(input))];
367
- case 1:
368
- response = _a.sent();
369
- return [2 /*return*/, response];
370
- }
371
- });
224
+ async deleteItem(input) {
225
+ this.logger.info('Deleting DynamoDB item', {
226
+ input: filterFieldsForLogLevel(this.logger, input, DELETE_ITEM_SAFE_FIELDS),
372
227
  });
373
- };
228
+ const response = await this.client.send(new libDynamodb.DeleteCommand(input));
229
+ return response;
230
+ }
374
231
  /**
375
232
  * Execute a DynamoDB Query. The full `QueryCommandOutput` is returned with
376
233
  * `Items` typed as `T[]` so callers retain pagination metadata
377
234
  * (`LastEvaluatedKey`, `Count`, etc.).
378
235
  * @template T - Expected shape of each unmarshalled item.
379
236
  */
380
- DynamoDBService.prototype.query = function (input) {
381
- return __awaiter(this, void 0, void 0, function () {
382
- var response;
383
- return __generator(this, function (_a) {
384
- switch (_a.label) {
385
- case 0:
386
- this.logger.info('Querying DynamoDB', {
387
- input: filterFieldsForLogLevel(this.logger, input, QUERY_SAFE_FIELDS),
388
- });
389
- return [4 /*yield*/, this.client.send(new libDynamodb.QueryCommand(input))];
390
- case 1:
391
- response = _a.sent();
392
- return [2 /*return*/, response];
393
- }
394
- });
237
+ async query(input) {
238
+ this.logger.info('Querying DynamoDB', {
239
+ input: filterFieldsForLogLevel(this.logger, input, QUERY_SAFE_FIELDS),
395
240
  });
396
- };
241
+ const response = await this.client.send(new libDynamodb.QueryCommand(input));
242
+ return response;
243
+ }
397
244
  /**
398
245
  * Scan a DynamoDB table. The full `ScanCommandOutput` is returned with
399
246
  * `Items` typed as `T[]` so callers retain pagination metadata.
@@ -413,23 +260,13 @@ var DynamoDBService = /** @class */ (function () {
413
260
  *
414
261
  * @template T - Expected shape of each unmarshalled item.
415
262
  */
416
- DynamoDBService.prototype.scan = function (input) {
417
- return __awaiter(this, void 0, void 0, function () {
418
- var response;
419
- return __generator(this, function (_a) {
420
- switch (_a.label) {
421
- case 0:
422
- this.logger.info('Scanning DynamoDB', {
423
- input: filterFieldsForLogLevel(this.logger, input, SCAN_SAFE_FIELDS),
424
- });
425
- return [4 /*yield*/, this.client.send(new libDynamodb.ScanCommand(input))];
426
- case 1:
427
- response = _a.sent();
428
- return [2 /*return*/, response];
429
- }
430
- });
263
+ async scan(input) {
264
+ this.logger.info('Scanning DynamoDB', {
265
+ input: filterFieldsForLogLevel(this.logger, input, SCAN_SAFE_FIELDS),
431
266
  });
432
- };
267
+ const response = await this.client.send(new libDynamodb.ScanCommand(input));
268
+ return response;
269
+ }
433
270
  /**
434
271
  * Batch-get items from one or more DynamoDB tables.
435
272
  *
@@ -438,214 +275,119 @@ var DynamoDBService = /** @class */ (function () {
438
275
  * shapes can differ per table — no single `T` can soundly describe it.
439
276
  * Callers should narrow the result type at the call site.
440
277
  */
441
- DynamoDBService.prototype.batchGet = function (input) {
442
- return __awaiter(this, void 0, void 0, function () {
443
- var isDebug;
444
- var _a;
445
- return __generator(this, function (_b) {
446
- isDebug = this.logger.getLevelName() === 'DEBUG';
447
- this.logger.info('Batch getting DynamoDB items', {
448
- input: isDebug ? input : { tables: Object.keys((_a = input.RequestItems) !== null && _a !== void 0 ? _a : {}) },
449
- });
450
- return [2 /*return*/, this.client.send(new libDynamodb.BatchGetCommand(input))];
451
- });
278
+ async batchGet(input) {
279
+ // Inline verbosity check rather than `filterFieldsForLogLevel` because
280
+ // `RequestItems` is a `Record<tableName, KeysAndAttributes>` — the
281
+ // payload (`Keys[]`) lives inside the value, not as a top-level key
282
+ // the helper could pick or drop.
283
+ const logFullInput = shouldLogFullInput(this.logger);
284
+ this.logger.info('Batch getting DynamoDB items', {
285
+ input: logFullInput ? input : { tables: Object.keys(input.RequestItems ?? {}) },
452
286
  });
453
- };
287
+ return this.client.send(new libDynamodb.BatchGetCommand(input));
288
+ }
454
289
  /**
455
290
  * Batch-write items to DynamoDB, retrying `UnprocessedItems` with jittered
456
291
  * exponential backoff. Up to 5 attempts (200ms base delay). Throws when
457
292
  * items remain unprocessed after the final attempt.
458
293
  */
459
- DynamoDBService.prototype.batchWrite = function (input) {
460
- return __awaiter(this, void 0, void 0, function () {
461
- var isDebug, current, attempt, response, unprocessed;
462
- var _a;
463
- return __generator(this, function (_b) {
464
- switch (_b.label) {
465
- case 0:
466
- isDebug = this.logger.getLevelName() === 'DEBUG';
467
- this.logger.info('Batch writing DynamoDB items', {
468
- input: isDebug ? input : { tables: Object.keys((_a = input.RequestItems) !== null && _a !== void 0 ? _a : {}) },
469
- });
470
- current = input;
471
- attempt = 0;
472
- _b.label = 1;
473
- case 1:
474
- if (!(attempt < BATCH_WRITE_MAX_ATTEMPTS)) return [3 /*break*/, 6];
475
- return [4 /*yield*/, this.client.send(new libDynamodb.BatchWriteCommand(current))];
476
- case 2:
477
- response = _b.sent();
478
- unprocessed = response.UnprocessedItems;
479
- if (!unprocessed || Object.keys(unprocessed).length === 0)
480
- return [2 /*return*/, response];
481
- this.logger.warn('Retrying unprocessed DynamoDB items', {
482
- attempt: attempt + 1,
483
- tables: Object.keys(unprocessed),
484
- });
485
- if (!(attempt < BATCH_WRITE_MAX_ATTEMPTS - 1)) return [3 /*break*/, 4];
486
- return [4 /*yield*/, sleep(backoffDelay(attempt))];
487
- case 3:
488
- _b.sent();
489
- _b.label = 4;
490
- case 4:
491
- current = __assign(__assign({}, input), { RequestItems: unprocessed });
492
- _b.label = 5;
493
- case 5:
494
- attempt++;
495
- return [3 /*break*/, 1];
496
- case 6: throw new Error("batchWrite failed after ".concat(BATCH_WRITE_MAX_ATTEMPTS, " attempts"));
497
- }
498
- });
294
+ async batchWrite(input) {
295
+ // Inline verbosity check rather than `filterFieldsForLogLevel` because
296
+ // `RequestItems` is a `Record<tableName, WriteRequest[]>` — the
297
+ // payload (`PutRequest.Item` / `DeleteRequest.Key`) lives inside the
298
+ // value, not as a top-level key the helper could pick or drop.
299
+ const logFullInput = shouldLogFullInput(this.logger);
300
+ this.logger.info('Batch writing DynamoDB items', {
301
+ input: logFullInput ? input : { tables: Object.keys(input.RequestItems ?? {}) },
499
302
  });
500
- };
303
+ let current = input;
304
+ for (let attempt = 0; attempt < BATCH_WRITE_MAX_ATTEMPTS; attempt++) {
305
+ const response = await this.client.send(new libDynamodb.BatchWriteCommand(current));
306
+ const unprocessed = response.UnprocessedItems;
307
+ if (!unprocessed || Object.keys(unprocessed).length === 0)
308
+ return response;
309
+ this.logger.warn('Retrying unprocessed DynamoDB items', {
310
+ attempt: attempt + 1,
311
+ tables: Object.keys(unprocessed),
312
+ });
313
+ if (attempt < BATCH_WRITE_MAX_ATTEMPTS - 1)
314
+ await sleep(backoffDelay(attempt));
315
+ current = { ...input, RequestItems: unprocessed };
316
+ }
317
+ throw new Error(`batchWrite failed after ${BATCH_WRITE_MAX_ATTEMPTS} attempts`);
318
+ }
501
319
  /**
502
320
  * Paginate over Query results, yielding one unmarshalled item at a time.
321
+ *
322
+ * **`Limit` is a page size, not a total cap.** DynamoDB applies it per
323
+ * request, and this method walks every page until `LastEvaluatedKey` is
324
+ * exhausted — so `paginateItems({ Limit: 10 })` yields *every* matching
325
+ * item, in pages of 10, not the first 10 items.
326
+ *
327
+ * To bound the number of items, `break` out of the loop. This is an
328
+ * `AsyncGenerator`, so `break` calls its `return()`, which unwinds the
329
+ * pagination and issues no further requests:
330
+ *
331
+ * ```ts
332
+ * const firstTen: Item[] = [];
333
+ * for await (const item of ddb.paginateItems<Item>(input)) {
334
+ * firstTen.push(item);
335
+ * if (firstTen.length === 10) break;
336
+ * }
337
+ * ```
338
+ *
339
+ * `Limit` remains the right knob for tuning per-request consumed capacity
340
+ * and page memory — set it deliberately, just don't expect it to stop the
341
+ * walk.
342
+ *
503
343
  * @template T - Expected shape of each yielded item.
504
344
  */
505
- DynamoDBService.prototype.paginateItems = function (input) {
506
- return __asyncGenerator(this, arguments, function paginateItems_1() {
507
- var paginator, _a, paginator_1, paginator_1_1, page, _i, _b, item, e_1_1;
508
- var _c, e_1, _d, _e;
509
- return __generator(this, function (_f) {
510
- switch (_f.label) {
511
- case 0:
512
- this.logger.info('Paginating DynamoDB query', {
513
- input: filterFieldsForLogLevel(this.logger, input, QUERY_SAFE_FIELDS),
514
- });
515
- paginator = libDynamodb.paginateQuery({ client: this.client }, input);
516
- _f.label = 1;
517
- case 1:
518
- _f.trys.push([1, 10, 11, 16]);
519
- _a = true, paginator_1 = __asyncValues(paginator);
520
- _f.label = 2;
521
- case 2: return [4 /*yield*/, __await(paginator_1.next())];
522
- case 3:
523
- if (!(paginator_1_1 = _f.sent(), _c = paginator_1_1.done, !_c)) return [3 /*break*/, 9];
524
- _e = paginator_1_1.value;
525
- _a = false;
526
- page = _e;
527
- if (!page.Items)
528
- return [3 /*break*/, 8];
529
- _i = 0, _b = page.Items;
530
- _f.label = 4;
531
- case 4:
532
- if (!(_i < _b.length)) return [3 /*break*/, 8];
533
- item = _b[_i];
534
- return [4 /*yield*/, __await(item)];
535
- case 5: return [4 /*yield*/, _f.sent()];
536
- case 6:
537
- _f.sent();
538
- _f.label = 7;
539
- case 7:
540
- _i++;
541
- return [3 /*break*/, 4];
542
- case 8:
543
- _a = true;
544
- return [3 /*break*/, 2];
545
- case 9: return [3 /*break*/, 16];
546
- case 10:
547
- e_1_1 = _f.sent();
548
- e_1 = { error: e_1_1 };
549
- return [3 /*break*/, 16];
550
- case 11:
551
- _f.trys.push([11, , 14, 15]);
552
- if (!(!_a && !_c && (_d = paginator_1.return))) return [3 /*break*/, 13];
553
- return [4 /*yield*/, __await(_d.call(paginator_1))];
554
- case 12:
555
- _f.sent();
556
- _f.label = 13;
557
- case 13: return [3 /*break*/, 15];
558
- case 14:
559
- if (e_1) throw e_1.error;
560
- return [7 /*endfinally*/];
561
- case 15: return [7 /*endfinally*/];
562
- case 16: return [2 /*return*/];
563
- }
564
- });
345
+ async *paginateItems(input) {
346
+ this.logger.info('Paginating DynamoDB query', {
347
+ input: filterFieldsForLogLevel(this.logger, input, QUERY_SAFE_FIELDS),
565
348
  });
566
- };
349
+ const paginator = libDynamodb.paginateQuery({ client: this.client }, input);
350
+ for await (const page of paginator) {
351
+ if (!page.Items)
352
+ continue;
353
+ for (const item of page.Items)
354
+ yield item;
355
+ }
356
+ }
567
357
  /**
568
358
  * Paginate over Scan results, yielding one unmarshalled item at a time.
359
+ *
360
+ * **`Limit` is a page size, not a total cap** — see `paginateItems` for the
361
+ * detail. `break` out of the loop to bound the number of items; `Limit`
362
+ * stays the right knob for per-request consumed capacity and page memory.
363
+ *
569
364
  * @template T - Expected shape of each yielded item.
570
365
  */
571
- DynamoDBService.prototype.paginateScan = function (input) {
572
- return __asyncGenerator(this, arguments, function paginateScan_1() {
573
- var paginator, _a, paginator_2, paginator_2_1, page, _i, _b, item, e_2_1;
574
- var _c, e_2, _d, _e;
575
- return __generator(this, function (_f) {
576
- switch (_f.label) {
577
- case 0:
578
- this.logger.info('Paginating DynamoDB scan', {
579
- input: filterFieldsForLogLevel(this.logger, input, SCAN_SAFE_FIELDS),
580
- });
581
- paginator = libDynamodb.paginateScan({ client: this.client }, input);
582
- _f.label = 1;
583
- case 1:
584
- _f.trys.push([1, 10, 11, 16]);
585
- _a = true, paginator_2 = __asyncValues(paginator);
586
- _f.label = 2;
587
- case 2: return [4 /*yield*/, __await(paginator_2.next())];
588
- case 3:
589
- if (!(paginator_2_1 = _f.sent(), _c = paginator_2_1.done, !_c)) return [3 /*break*/, 9];
590
- _e = paginator_2_1.value;
591
- _a = false;
592
- page = _e;
593
- if (!page.Items)
594
- return [3 /*break*/, 8];
595
- _i = 0, _b = page.Items;
596
- _f.label = 4;
597
- case 4:
598
- if (!(_i < _b.length)) return [3 /*break*/, 8];
599
- item = _b[_i];
600
- return [4 /*yield*/, __await(item)];
601
- case 5: return [4 /*yield*/, _f.sent()];
602
- case 6:
603
- _f.sent();
604
- _f.label = 7;
605
- case 7:
606
- _i++;
607
- return [3 /*break*/, 4];
608
- case 8:
609
- _a = true;
610
- return [3 /*break*/, 2];
611
- case 9: return [3 /*break*/, 16];
612
- case 10:
613
- e_2_1 = _f.sent();
614
- e_2 = { error: e_2_1 };
615
- return [3 /*break*/, 16];
616
- case 11:
617
- _f.trys.push([11, , 14, 15]);
618
- if (!(!_a && !_c && (_d = paginator_2.return))) return [3 /*break*/, 13];
619
- return [4 /*yield*/, __await(_d.call(paginator_2))];
620
- case 12:
621
- _f.sent();
622
- _f.label = 13;
623
- case 13: return [3 /*break*/, 15];
624
- case 14:
625
- if (e_2) throw e_2.error;
626
- return [7 /*endfinally*/];
627
- case 15: return [7 /*endfinally*/];
628
- case 16: return [2 /*return*/];
629
- }
630
- });
366
+ async *paginateScan(input) {
367
+ this.logger.info('Paginating DynamoDB scan', {
368
+ input: filterFieldsForLogLevel(this.logger, input, SCAN_SAFE_FIELDS),
631
369
  });
632
- };
633
- return DynamoDBService;
634
- }());
370
+ const paginator = libDynamodb.paginateScan({ client: this.client }, input);
371
+ for await (const page of paginator) {
372
+ if (!page.Items)
373
+ continue;
374
+ for (const item of page.Items)
375
+ yield item;
376
+ }
377
+ }
378
+ }
635
379
 
636
- var DEFAULT_PRESIGNED_URL_EXPIRES_IN_SECONDS = 3600;
637
- var DELETE_OBJECTS_BATCH_LIMIT = 1000;
380
+ const DEFAULT_PRESIGNED_URL_EXPIRES_IN_SECONDS = 3600;
381
+ const DELETE_OBJECTS_BATCH_LIMIT = 1000;
638
382
  /**
639
383
  * Fields safe to log at INFO for `putObject`. Omits `Body` (object payload).
640
- * `POWERTOOLS_LOG_LEVEL=DEBUG` unlocks the full input.
641
384
  */
642
- var PUT_OBJECT_SAFE_FIELDS = ['Bucket', 'Key'];
385
+ const PUT_OBJECT_SAFE_FIELDS = ['Bucket', 'Key'];
643
386
  /**
644
387
  * Fields safe to log at INFO for `putJsonObject`. Omits `Body` (the
645
388
  * unserialised JSON payload). `Metadata` is included (operational labels).
646
- * `POWERTOOLS_LOG_LEVEL=DEBUG` unlocks the full input.
647
389
  */
648
- var PUT_JSON_OBJECT_SAFE_FIELDS = [
390
+ const PUT_JSON_OBJECT_SAFE_FIELDS = [
649
391
  'Bucket',
650
392
  'Key',
651
393
  'Metadata',
@@ -654,21 +396,26 @@ var PUT_JSON_OBJECT_SAFE_FIELDS = [
654
396
  * Wrapper around the AWS S3 client providing structured Powertools logging
655
397
  * and X-Ray tracing by default.
656
398
  *
399
+ * Where a method's input carries payloads, secret material or PII, the INFO
400
+ * log line omits them; the verbose levels (`POWERTOOLS_LOG_LEVEL=DEBUG` or
401
+ * `TRACE`) log full SDK inputs.
402
+ *
657
403
  * Input shapes are intentionally tight (Bucket/Key/Body only). Callers
658
404
  * needing SDK-level options not exposed here (server-side encryption,
659
405
  * tagging, version IDs) should use `S3Client` directly.
660
406
  */
661
- var S3Service = /** @class */ (function () {
407
+ class S3Service {
408
+ client;
409
+ logger;
662
410
  /**
663
411
  * @param opts.logger - Optional Powertools logger. Defaults to `new Logger()`,
664
412
  * which picks up `POWERTOOLS_SERVICE_NAME` from the environment.
665
413
  * @param opts.client - Optional pre-configured `S3Client`. When supplied,
666
414
  * the wrapper does not apply X-Ray instrumentation.
667
415
  */
668
- function S3Service(opts) {
669
- var _a, _b;
670
- this.client = (_a = opts === null || opts === void 0 ? void 0 : opts.client) !== null && _a !== void 0 ? _a : xray.captureAWSv3Client(new clientS3.S3Client());
671
- this.logger = (_b = opts === null || opts === void 0 ? void 0 : opts.logger) !== null && _b !== void 0 ? _b : new logger.Logger();
416
+ constructor(opts) {
417
+ this.client = opts?.client ?? xray.captureAWSv3Client(new clientS3.S3Client());
418
+ this.logger = opts?.logger ?? new logger.Logger();
672
419
  }
673
420
  /**
674
421
  * Put an object into S3.
@@ -679,16 +426,12 @@ var S3Service = /** @class */ (function () {
679
426
  *
680
427
  * @param input - Bucket, Key, and Body of the object to store.
681
428
  */
682
- S3Service.prototype.putObject = function (input) {
683
- return __awaiter(this, void 0, void 0, function () {
684
- return __generator(this, function (_a) {
685
- this.logger.info('Putting S3 object', {
686
- input: filterFieldsForLogLevel(this.logger, input, PUT_OBJECT_SAFE_FIELDS),
687
- });
688
- return [2 /*return*/, this.client.send(new clientS3.PutObjectCommand(input))];
689
- });
429
+ async putObject(input) {
430
+ this.logger.info('Putting S3 object', {
431
+ input: filterFieldsForLogLevel(this.logger, input, PUT_OBJECT_SAFE_FIELDS),
690
432
  });
691
- };
433
+ return this.client.send(new clientS3.PutObjectCommand(input));
434
+ }
692
435
  /**
693
436
  * Serialise a value to JSON and store it as an S3 object.
694
437
  *
@@ -698,228 +441,97 @@ var S3Service = /** @class */ (function () {
698
441
  *
699
442
  * @template T - Type of the value being stored.
700
443
  */
701
- S3Service.prototype.putJsonObject = function (input) {
702
- return __awaiter(this, void 0, void 0, function () {
703
- return __generator(this, function (_a) {
704
- this.logger.info('Putting S3 JSON object', {
705
- input: filterFieldsForLogLevel(this.logger, input, PUT_JSON_OBJECT_SAFE_FIELDS),
706
- });
707
- return [2 /*return*/, this.client.send(new clientS3.PutObjectCommand({
708
- Bucket: input.Bucket,
709
- Key: input.Key,
710
- Body: JSON.stringify(input.Body),
711
- Metadata: input.Metadata,
712
- }))];
713
- });
444
+ async putJsonObject(input) {
445
+ this.logger.info('Putting S3 JSON object', {
446
+ input: filterFieldsForLogLevel(this.logger, input, PUT_JSON_OBJECT_SAFE_FIELDS),
714
447
  });
715
- };
448
+ return this.client.send(new clientS3.PutObjectCommand({
449
+ Bucket: input.Bucket,
450
+ Key: input.Key,
451
+ Body: JSON.stringify(input.Body),
452
+ Metadata: input.Metadata,
453
+ }));
454
+ }
716
455
  /**
717
456
  * Get an object from S3.
718
457
  */
719
- S3Service.prototype.getObject = function (input) {
720
- return __awaiter(this, void 0, void 0, function () {
721
- return __generator(this, function (_a) {
722
- this.logger.info('Getting S3 object', { input: input });
723
- return [2 /*return*/, this.client.send(new clientS3.GetObjectCommand(input))];
724
- });
725
- });
726
- };
458
+ async getObject(input) {
459
+ this.logger.info('Getting S3 object', { input });
460
+ return this.client.send(new clientS3.GetObjectCommand(input));
461
+ }
727
462
  /**
728
463
  * Get an object from S3 and return its body as a string.
729
464
  * @returns The object body as a string, or `undefined` if the response
730
465
  * has no body.
731
466
  */
732
- S3Service.prototype.getObjectBody = function (input) {
733
- return __awaiter(this, void 0, void 0, function () {
734
- var response;
735
- var _a;
736
- return __generator(this, function (_b) {
737
- switch (_b.label) {
738
- case 0:
739
- this.logger.info('Getting S3 object body', { input: input });
740
- return [4 /*yield*/, this.client.send(new clientS3.GetObjectCommand(input))];
741
- case 1:
742
- response = _b.sent();
743
- return [2 /*return*/, (_a = response.Body) === null || _a === void 0 ? void 0 : _a.transformToString()];
744
- }
745
- });
746
- });
747
- };
467
+ async getObjectBody(input) {
468
+ this.logger.info('Getting S3 object body', { input });
469
+ const response = await this.client.send(new clientS3.GetObjectCommand(input));
470
+ return response.Body?.transformToString();
471
+ }
748
472
  /**
749
473
  * Get an object from S3 and parse it as JSON.
750
474
  * @template T - Expected type of the parsed value.
751
475
  * @returns The parsed value, or `undefined` if the response has no body.
752
476
  * @throws If the body is non-empty and not valid JSON.
753
477
  */
754
- S3Service.prototype.getJsonObject = function (input) {
755
- return __awaiter(this, void 0, void 0, function () {
756
- var response, body;
757
- var _a;
758
- return __generator(this, function (_b) {
759
- switch (_b.label) {
760
- case 0:
761
- this.logger.info('Getting S3 JSON object', { input: input });
762
- return [4 /*yield*/, this.client.send(new clientS3.GetObjectCommand(input))];
763
- case 1:
764
- response = _b.sent();
765
- return [4 /*yield*/, ((_a = response.Body) === null || _a === void 0 ? void 0 : _a.transformToString())];
766
- case 2:
767
- body = _b.sent();
768
- return [2 /*return*/, body ? JSON.parse(body) : undefined];
769
- }
770
- });
771
- });
772
- };
478
+ async getJsonObject(input) {
479
+ this.logger.info('Getting S3 JSON object', { input });
480
+ const response = await this.client.send(new clientS3.GetObjectCommand(input));
481
+ const body = await response.Body?.transformToString();
482
+ return body ? JSON.parse(body) : undefined;
483
+ }
773
484
  /**
774
485
  * Fetch the metadata for an S3 object without downloading its body.
775
486
  */
776
- S3Service.prototype.headObject = function (input) {
777
- return __awaiter(this, void 0, void 0, function () {
778
- return __generator(this, function (_a) {
779
- this.logger.info('Fetching S3 object metadata', { input: input });
780
- return [2 /*return*/, this.client.send(new clientS3.HeadObjectCommand(input))];
781
- });
782
- });
783
- };
487
+ async headObject(input) {
488
+ this.logger.info('Fetching S3 object metadata', { input });
489
+ return this.client.send(new clientS3.HeadObjectCommand(input));
490
+ }
784
491
  /**
785
492
  * Copy an object within S3.
786
493
  */
787
- S3Service.prototype.copyObject = function (input) {
788
- return __awaiter(this, void 0, void 0, function () {
789
- return __generator(this, function (_a) {
790
- this.logger.info('Copying S3 object', { input: input });
791
- return [2 /*return*/, this.client.send(new clientS3.CopyObjectCommand(input))];
792
- });
793
- });
794
- };
494
+ async copyObject(input) {
495
+ this.logger.info('Copying S3 object', { input });
496
+ return this.client.send(new clientS3.CopyObjectCommand(input));
497
+ }
795
498
  /**
796
499
  * List object keys under a bucket and optional prefix, auto-paginating
797
500
  * across all pages.
798
501
  */
799
- S3Service.prototype.listObjects = function (bucket, prefix) {
800
- return __awaiter(this, void 0, void 0, function () {
801
- var paginator, keys, _a, paginator_1, paginator_1_1, page, _i, _b, object, e_1_1;
802
- var _c, e_1, _d, _e;
803
- var _f;
804
- return __generator(this, function (_g) {
805
- switch (_g.label) {
806
- case 0:
807
- this.logger.info('Listing S3 objects', { input: { bucket: bucket, prefix: prefix } });
808
- paginator = clientS3.paginateListObjectsV2({ client: this.client }, { Bucket: bucket, Prefix: prefix });
809
- keys = [];
810
- _g.label = 1;
811
- case 1:
812
- _g.trys.push([1, 6, 7, 12]);
813
- _a = true, paginator_1 = __asyncValues(paginator);
814
- _g.label = 2;
815
- case 2: return [4 /*yield*/, paginator_1.next()];
816
- case 3:
817
- if (!(paginator_1_1 = _g.sent(), _c = paginator_1_1.done, !_c)) return [3 /*break*/, 5];
818
- _e = paginator_1_1.value;
819
- _a = false;
820
- page = _e;
821
- for (_i = 0, _b = (_f = page.Contents) !== null && _f !== void 0 ? _f : []; _i < _b.length; _i++) {
822
- object = _b[_i];
823
- if (object.Key)
824
- keys.push(object.Key);
825
- }
826
- _g.label = 4;
827
- case 4:
828
- _a = true;
829
- return [3 /*break*/, 2];
830
- case 5: return [3 /*break*/, 12];
831
- case 6:
832
- e_1_1 = _g.sent();
833
- e_1 = { error: e_1_1 };
834
- return [3 /*break*/, 12];
835
- case 7:
836
- _g.trys.push([7, , 10, 11]);
837
- if (!(!_a && !_c && (_d = paginator_1.return))) return [3 /*break*/, 9];
838
- return [4 /*yield*/, _d.call(paginator_1)];
839
- case 8:
840
- _g.sent();
841
- _g.label = 9;
842
- case 9: return [3 /*break*/, 11];
843
- case 10:
844
- if (e_1) throw e_1.error;
845
- return [7 /*endfinally*/];
846
- case 11: return [7 /*endfinally*/];
847
- case 12: return [2 /*return*/, keys];
848
- }
849
- });
850
- });
851
- };
502
+ async listObjects(bucket, prefix) {
503
+ this.logger.info('Listing S3 objects', { input: { bucket, prefix } });
504
+ const paginator = clientS3.paginateListObjectsV2({ client: this.client }, { Bucket: bucket, Prefix: prefix });
505
+ const keys = [];
506
+ for await (const page of paginator) {
507
+ for (const object of page.Contents ?? []) {
508
+ if (object.Key)
509
+ keys.push(object.Key);
510
+ }
511
+ }
512
+ return keys;
513
+ }
852
514
  /**
853
515
  * List and JSON-parse every object under a bucket and optional prefix.
854
516
  * Auto-paginated. Objects without a body are skipped.
855
517
  * @template T - Expected type of each parsed object.
856
518
  */
857
- S3Service.prototype.getAllObjects = function (bucket, prefix) {
858
- return __awaiter(this, void 0, void 0, function () {
859
- var paginator, bodies, _a, paginator_2, paginator_2_1, page, _i, _b, object, response, body, e_2_1;
860
- var _c, e_2, _d, _e;
861
- var _f, _g;
862
- return __generator(this, function (_h) {
863
- switch (_h.label) {
864
- case 0:
865
- this.logger.info('Getting all S3 objects', { input: { bucket: bucket, prefix: prefix } });
866
- paginator = clientS3.paginateListObjectsV2({ client: this.client }, { Bucket: bucket, Prefix: prefix });
867
- bodies = [];
868
- _h.label = 1;
869
- case 1:
870
- _h.trys.push([1, 10, 11, 16]);
871
- _a = true, paginator_2 = __asyncValues(paginator);
872
- _h.label = 2;
873
- case 2: return [4 /*yield*/, paginator_2.next()];
874
- case 3:
875
- if (!(paginator_2_1 = _h.sent(), _c = paginator_2_1.done, !_c)) return [3 /*break*/, 9];
876
- _e = paginator_2_1.value;
877
- _a = false;
878
- page = _e;
879
- _i = 0, _b = (_f = page.Contents) !== null && _f !== void 0 ? _f : [];
880
- _h.label = 4;
881
- case 4:
882
- if (!(_i < _b.length)) return [3 /*break*/, 8];
883
- object = _b[_i];
884
- if (!object.Key)
885
- return [3 /*break*/, 7];
886
- return [4 /*yield*/, this.client.send(new clientS3.GetObjectCommand({ Bucket: bucket, Key: object.Key }))];
887
- case 5:
888
- response = _h.sent();
889
- return [4 /*yield*/, ((_g = response.Body) === null || _g === void 0 ? void 0 : _g.transformToString())];
890
- case 6:
891
- body = _h.sent();
892
- if (body)
893
- bodies.push(JSON.parse(body));
894
- _h.label = 7;
895
- case 7:
896
- _i++;
897
- return [3 /*break*/, 4];
898
- case 8:
899
- _a = true;
900
- return [3 /*break*/, 2];
901
- case 9: return [3 /*break*/, 16];
902
- case 10:
903
- e_2_1 = _h.sent();
904
- e_2 = { error: e_2_1 };
905
- return [3 /*break*/, 16];
906
- case 11:
907
- _h.trys.push([11, , 14, 15]);
908
- if (!(!_a && !_c && (_d = paginator_2.return))) return [3 /*break*/, 13];
909
- return [4 /*yield*/, _d.call(paginator_2)];
910
- case 12:
911
- _h.sent();
912
- _h.label = 13;
913
- case 13: return [3 /*break*/, 15];
914
- case 14:
915
- if (e_2) throw e_2.error;
916
- return [7 /*endfinally*/];
917
- case 15: return [7 /*endfinally*/];
918
- case 16: return [2 /*return*/, bodies];
919
- }
920
- });
921
- });
922
- };
519
+ async getAllObjects(bucket, prefix) {
520
+ this.logger.info('Getting all S3 objects', { input: { bucket, prefix } });
521
+ const paginator = clientS3.paginateListObjectsV2({ client: this.client }, { Bucket: bucket, Prefix: prefix });
522
+ const bodies = [];
523
+ for await (const page of paginator) {
524
+ for (const object of page.Contents ?? []) {
525
+ if (!object.Key)
526
+ continue;
527
+ const response = await this.client.send(new clientS3.GetObjectCommand({ Bucket: bucket, Key: object.Key }));
528
+ const body = await response.Body?.transformToString();
529
+ if (body)
530
+ bodies.push(JSON.parse(body));
531
+ }
532
+ }
533
+ return bodies;
534
+ }
923
535
  /**
924
536
  * Generate a presigned URL that callers can use to GET or PUT an S3 object
925
537
  * directly, without going through the wrapper. The signing happens against
@@ -938,137 +550,81 @@ var S3Service = /** @class */ (function () {
938
550
  * @param input.action - `'get'` to download, `'put'` to upload.
939
551
  * @param input.expiresIn - URL lifetime in seconds. Defaults to 3600 (1 hour).
940
552
  */
941
- S3Service.prototype.getPresignedUrl = function (input) {
942
- return __awaiter(this, void 0, void 0, function () {
943
- var expiresIn, command;
944
- var _a;
945
- return __generator(this, function (_b) {
946
- expiresIn = (_a = input.expiresIn) !== null && _a !== void 0 ? _a : DEFAULT_PRESIGNED_URL_EXPIRES_IN_SECONDS;
947
- this.logger.info('Generating S3 presigned URL', {
948
- input: { Bucket: input.Bucket, Key: input.Key, action: input.action, expiresIn: expiresIn },
949
- });
950
- command = input.action === 'get'
951
- ? new clientS3.GetObjectCommand({
952
- Bucket: input.Bucket,
953
- Key: input.Key,
954
- ResponseContentDisposition: 'attachment',
955
- })
956
- : new clientS3.PutObjectCommand({ Bucket: input.Bucket, Key: input.Key });
957
- return [2 /*return*/, s3RequestPresigner.getSignedUrl(this.client, command, { expiresIn: expiresIn })];
958
- });
553
+ async getPresignedUrl(input) {
554
+ const expiresIn = input.expiresIn ?? DEFAULT_PRESIGNED_URL_EXPIRES_IN_SECONDS;
555
+ this.logger.info('Generating S3 presigned URL', {
556
+ input: { Bucket: input.Bucket, Key: input.Key, action: input.action, expiresIn },
959
557
  });
960
- };
558
+ const command = input.action === 'get'
559
+ ? new clientS3.GetObjectCommand({
560
+ Bucket: input.Bucket,
561
+ Key: input.Key,
562
+ ResponseContentDisposition: 'attachment',
563
+ })
564
+ : new clientS3.PutObjectCommand({ Bucket: input.Bucket, Key: input.Key });
565
+ return s3RequestPresigner.getSignedUrl(this.client, command, { expiresIn });
566
+ }
961
567
  /**
962
568
  * Delete a single object from S3.
963
569
  */
964
- S3Service.prototype.deleteObject = function (input) {
965
- return __awaiter(this, void 0, void 0, function () {
966
- return __generator(this, function (_a) {
967
- this.logger.info('Deleting S3 object', { input: input });
968
- return [2 /*return*/, this.client.send(new clientS3.DeleteObjectCommand(input))];
969
- });
970
- });
971
- };
570
+ async deleteObject(input) {
571
+ this.logger.info('Deleting S3 object', { input });
572
+ return this.client.send(new clientS3.DeleteObjectCommand(input));
573
+ }
972
574
  /**
973
575
  * Delete multiple objects from S3, auto-chunking the request into batches
974
576
  * of 1000 keys (the S3-enforced DeleteObjects limit). Returns one output
975
577
  * per chunk.
976
578
  */
977
- S3Service.prototype.deleteObjects = function (bucket, keys) {
978
- return __awaiter(this, void 0, void 0, function () {
979
- var isDebug, results, i, batch, _a, _b;
980
- return __generator(this, function (_c) {
981
- switch (_c.label) {
982
- case 0:
983
- isDebug = this.logger.getLevelName() === 'DEBUG';
984
- this.logger.info('Deleting S3 objects', {
985
- input: isDebug ? { bucket: bucket, keys: keys } : { bucket: bucket, keyCount: keys.length },
986
- });
987
- results = [];
988
- i = 0;
989
- _c.label = 1;
990
- case 1:
991
- if (!(i < keys.length)) return [3 /*break*/, 4];
992
- batch = keys.slice(i, i + DELETE_OBJECTS_BATCH_LIMIT);
993
- _b = (_a = results).push;
994
- return [4 /*yield*/, this.client.send(new clientS3.DeleteObjectsCommand({
995
- Bucket: bucket,
996
- Delete: { Objects: batch.map(function (Key) { return ({ Key: Key }); }) },
997
- }))];
998
- case 2:
999
- _b.apply(_a, [_c.sent()]);
1000
- _c.label = 3;
1001
- case 3:
1002
- i += DELETE_OBJECTS_BATCH_LIMIT;
1003
- return [3 /*break*/, 1];
1004
- case 4: return [2 /*return*/, results];
1005
- }
1006
- });
1007
- });
1008
- };
1009
- /**
1010
- * Delete every object in a bucket. Streams the listing page-by-page and
1011
- * delegates each page's deletion to `deleteObjects`, so peak memory stays
1012
- * bounded by one page (~1000 keys) regardless of bucket size.
1013
- * @returns The keys of every deleted object.
1014
- */
1015
- S3Service.prototype.emptyBucket = function (bucket) {
1016
- return __awaiter(this, void 0, void 0, function () {
1017
- var paginator, deletedKeys, _a, paginator_3, paginator_3_1, page, keys, e_3_1;
1018
- var _b, e_3, _c, _d;
1019
- var _e;
1020
- return __generator(this, function (_f) {
1021
- switch (_f.label) {
1022
- case 0:
1023
- this.logger.info('Emptying S3 bucket', { input: { bucket: bucket } });
1024
- paginator = clientS3.paginateListObjectsV2({ client: this.client }, { Bucket: bucket });
1025
- deletedKeys = [];
1026
- _f.label = 1;
1027
- case 1:
1028
- _f.trys.push([1, 7, 8, 13]);
1029
- _a = true, paginator_3 = __asyncValues(paginator);
1030
- _f.label = 2;
1031
- case 2: return [4 /*yield*/, paginator_3.next()];
1032
- case 3:
1033
- if (!(paginator_3_1 = _f.sent(), _b = paginator_3_1.done, !_b)) return [3 /*break*/, 6];
1034
- _d = paginator_3_1.value;
1035
- _a = false;
1036
- page = _d;
1037
- keys = ((_e = page.Contents) !== null && _e !== void 0 ? _e : []).flatMap(function (o) { return (o.Key ? [o.Key] : []); });
1038
- if (keys.length === 0)
1039
- return [3 /*break*/, 5];
1040
- return [4 /*yield*/, this.deleteObjects(bucket, keys)];
1041
- case 4:
1042
- _f.sent();
1043
- deletedKeys.push.apply(deletedKeys, keys);
1044
- _f.label = 5;
1045
- case 5:
1046
- _a = true;
1047
- return [3 /*break*/, 2];
1048
- case 6: return [3 /*break*/, 13];
1049
- case 7:
1050
- e_3_1 = _f.sent();
1051
- e_3 = { error: e_3_1 };
1052
- return [3 /*break*/, 13];
1053
- case 8:
1054
- _f.trys.push([8, , 11, 12]);
1055
- if (!(!_a && !_b && (_c = paginator_3.return))) return [3 /*break*/, 10];
1056
- return [4 /*yield*/, _c.call(paginator_3)];
1057
- case 9:
1058
- _f.sent();
1059
- _f.label = 10;
1060
- case 10: return [3 /*break*/, 12];
1061
- case 11:
1062
- if (e_3) throw e_3.error;
1063
- return [7 /*endfinally*/];
1064
- case 12: return [7 /*endfinally*/];
1065
- case 13: return [2 /*return*/, deletedKeys];
1066
- }
1067
- });
579
+ async deleteObjects(bucket, keys) {
580
+ // Inline verbosity check rather than `filterFieldsForLogLevel` because the
581
+ // safe log shape includes the computed `keyCount`, which isn't a key
582
+ // on any SDK input type.
583
+ const logFullInput = shouldLogFullInput(this.logger);
584
+ this.logger.info('Deleting S3 objects', {
585
+ input: logFullInput ? { bucket, keys } : { bucket, keyCount: keys.length },
1068
586
  });
1069
- };
1070
- return S3Service;
1071
- }());
587
+ const results = [];
588
+ for (let i = 0; i < keys.length; i += DELETE_OBJECTS_BATCH_LIMIT) {
589
+ const batch = keys.slice(i, i + DELETE_OBJECTS_BATCH_LIMIT);
590
+ results.push(await this.client.send(new clientS3.DeleteObjectsCommand({
591
+ Bucket: bucket,
592
+ Delete: { Objects: batch.map(Key => ({ Key })) },
593
+ })));
594
+ }
595
+ return results;
596
+ }
597
+ /**
598
+ * Delete every object in an **unversioned** bucket. Streams the listing
599
+ * page-by-page and delegates each page's deletion to `deleteObjects`, so
600
+ * peak memory stays bounded by one page (~1000 keys) regardless of bucket
601
+ * size.
602
+ *
603
+ * **Versioned buckets are out of scope.** This paginates `ListObjectsV2`,
604
+ * which reports only current object versions — never noncurrent versions or
605
+ * delete markers. Against a versioned bucket the call therefore succeeds and
606
+ * the bucket then *looks* empty to `ListObjectsV2`, but the deletes only
607
+ * added delete markers: every object version is still stored, still billed,
608
+ * and `DeleteBucket` will still fail with `BucketNotEmpty`. Emptying a
609
+ * versioned bucket requires `ListObjectVersions` and per-version deletes;
610
+ * use `S3Client` directly for that.
611
+ *
612
+ * @returns The keys this call issued deletes for.
613
+ */
614
+ async emptyBucket(bucket) {
615
+ this.logger.info('Emptying S3 bucket', { input: { bucket } });
616
+ const paginator = clientS3.paginateListObjectsV2({ client: this.client }, { Bucket: bucket });
617
+ const deletedKeys = [];
618
+ for await (const page of paginator) {
619
+ const keys = (page.Contents ?? []).flatMap(o => (o.Key ? [o.Key] : []));
620
+ if (keys.length === 0)
621
+ continue;
622
+ await this.deleteObjects(bucket, keys);
623
+ deletedKeys.push(...keys);
624
+ }
625
+ return deletedKeys;
626
+ }
627
+ }
1072
628
 
1073
629
  /**
1074
630
  * `CreateSchedule` / `UpdateSchedule` inputs carry the payload handed to the
@@ -1084,22 +640,26 @@ var S3Service = /** @class */ (function () {
1084
640
  * bespoke case: keep every top-level field and shallow-strip only
1085
641
  * `Target.Input`.
1086
642
  *
1087
- * At `DEBUG` the input is returned unchanged — operators who set
1088
- * `POWERTOOLS_LOG_LEVEL=DEBUG` have opted into seeing payloads and PII.
643
+ * At the verbose levels — see {@link shouldLogFullInput} — the input is
644
+ * returned unchanged: operators who asked for that verbosity have opted into
645
+ * seeing payloads and PII.
1089
646
  */
1090
647
  function redactTargetInput(logger, input) {
1091
- var _a;
1092
- if (logger.getLevelName() === 'DEBUG')
648
+ if (shouldLogFullInput(logger))
1093
649
  return input;
1094
- if (((_a = input.Target) === null || _a === void 0 ? void 0 : _a.Input) === undefined)
650
+ if (input.Target?.Input === undefined)
1095
651
  return input;
1096
- var _b = input.Target; _b.Input; var safeTarget = __rest(_b, ["Input"]);
1097
- return __assign(__assign({}, input), { Target: safeTarget });
652
+ const { Input: _input, ...safeTarget } = input.Target;
653
+ return { ...input, Target: safeTarget };
1098
654
  }
1099
655
  /**
1100
656
  * Wrapper around the AWS EventBridge Scheduler client providing structured
1101
657
  * Powertools logging and X-Ray tracing by default.
1102
658
  *
659
+ * Where a method's input carries payloads, secret material or PII, the INFO
660
+ * log line omits them; the verbose levels (`POWERTOOLS_LOG_LEVEL=DEBUG` or
661
+ * `TRACE`) log full SDK inputs.
662
+ *
1103
663
  * Covers CRUD on schedules and their groups. Named `SchedulerService` (not
1104
664
  * `EventBridgeSchedulerService`) so it doesn't collide with a future wrapper
1105
665
  * over the separate EventBridge bus/rules API (`@aws-sdk/client-eventbridge`).
@@ -1108,42 +668,34 @@ function redactTargetInput(logger, input) {
1108
668
  * untouched — the wrapper bakes in no default, so the caller must state their
1109
669
  * intent (`{ Mode: 'OFF' }` for a fixed-time schedule).
1110
670
  */
1111
- var SchedulerService = /** @class */ (function () {
671
+ class SchedulerService {
672
+ client;
673
+ logger;
1112
674
  /**
1113
675
  * @param opts.logger - Optional Powertools logger. Defaults to `new Logger()`,
1114
676
  * which picks up `POWERTOOLS_SERVICE_NAME` from the environment.
1115
677
  * @param opts.client - Optional pre-configured `SchedulerClient`. When
1116
678
  * supplied, the wrapper does not apply X-Ray instrumentation.
1117
679
  */
1118
- function SchedulerService(opts) {
1119
- var _a, _b;
1120
- this.client = (_a = opts === null || opts === void 0 ? void 0 : opts.client) !== null && _a !== void 0 ? _a : xray.captureAWSv3Client(new clientScheduler.SchedulerClient());
1121
- this.logger = (_b = opts === null || opts === void 0 ? void 0 : opts.logger) !== null && _b !== void 0 ? _b : new logger.Logger();
680
+ constructor(opts) {
681
+ this.client = opts?.client ?? xray.captureAWSv3Client(new clientScheduler.SchedulerClient());
682
+ this.logger = opts?.logger ?? new logger.Logger();
1122
683
  }
1123
684
  /**
1124
685
  * Create a new schedule. At INFO the log line omits `Target.Input` (the
1125
- * target payload, a PII carrier); `POWERTOOLS_LOG_LEVEL=DEBUG` unlocks the
1126
- * full input.
1127
- */
1128
- SchedulerService.prototype.createSchedule = function (input) {
1129
- return __awaiter(this, void 0, void 0, function () {
1130
- return __generator(this, function (_a) {
1131
- this.logger.info('Creating schedule', { input: redactTargetInput(this.logger, input) });
1132
- return [2 /*return*/, this.client.send(new clientScheduler.CreateScheduleCommand(input))];
1133
- });
1134
- });
1135
- };
686
+ * target payload, a PII carrier).
687
+ */
688
+ async createSchedule(input) {
689
+ this.logger.info('Creating schedule', { input: redactTargetInput(this.logger, input) });
690
+ return this.client.send(new clientScheduler.CreateScheduleCommand(input));
691
+ }
1136
692
  /**
1137
693
  * Fetch a schedule's full configuration.
1138
694
  */
1139
- SchedulerService.prototype.getSchedule = function (input) {
1140
- return __awaiter(this, void 0, void 0, function () {
1141
- return __generator(this, function (_a) {
1142
- this.logger.info('Getting schedule', { input: input });
1143
- return [2 /*return*/, this.client.send(new clientScheduler.GetScheduleCommand(input))];
1144
- });
1145
- });
1146
- };
695
+ async getSchedule(input) {
696
+ this.logger.info('Getting schedule', { input });
697
+ return this.client.send(new clientScheduler.GetScheduleCommand(input));
698
+ }
1147
699
  /**
1148
700
  * Update an existing schedule.
1149
701
  *
@@ -1155,180 +707,79 @@ var SchedulerService = /** @class */ (function () {
1155
707
  * your behalf: deep-merging a `Target` (with its mutually-exclusive
1156
708
  * target-type params) has no single correct semantics.
1157
709
  *
1158
- * At INFO the log line omits `Target.Input`; `POWERTOOLS_LOG_LEVEL=DEBUG`
1159
- * unlocks the full input.
1160
- */
1161
- SchedulerService.prototype.updateSchedule = function (input) {
1162
- return __awaiter(this, void 0, void 0, function () {
1163
- return __generator(this, function (_a) {
1164
- this.logger.info('Updating schedule', { input: redactTargetInput(this.logger, input) });
1165
- return [2 /*return*/, this.client.send(new clientScheduler.UpdateScheduleCommand(input))];
1166
- });
1167
- });
1168
- };
710
+ * At INFO the log line omits `Target.Input`.
711
+ */
712
+ async updateSchedule(input) {
713
+ this.logger.info('Updating schedule', { input: redactTargetInput(this.logger, input) });
714
+ return this.client.send(new clientScheduler.UpdateScheduleCommand(input));
715
+ }
1169
716
  /**
1170
717
  * Delete a schedule.
1171
718
  */
1172
- SchedulerService.prototype.deleteSchedule = function (input) {
1173
- return __awaiter(this, void 0, void 0, function () {
1174
- return __generator(this, function (_a) {
1175
- this.logger.info('Deleting schedule', { input: input });
1176
- return [2 /*return*/, this.client.send(new clientScheduler.DeleteScheduleCommand(input))];
1177
- });
1178
- });
1179
- };
719
+ async deleteSchedule(input) {
720
+ this.logger.info('Deleting schedule', { input });
721
+ return this.client.send(new clientScheduler.DeleteScheduleCommand(input));
722
+ }
1180
723
  /**
1181
724
  * List schedules, auto-paginating across all pages. Bounded in practice by
1182
725
  * the account's schedule count and the `GroupName` / `NamePrefix` / `State`
1183
726
  * filters, so the flat-array shape is safe.
1184
727
  */
1185
- SchedulerService.prototype.listSchedules = function (input) {
1186
- return __awaiter(this, void 0, void 0, function () {
1187
- var paginator, schedules, _a, paginator_1, paginator_1_1, page, e_1_1;
1188
- var _b, e_1, _c, _d;
1189
- return __generator(this, function (_e) {
1190
- switch (_e.label) {
1191
- case 0:
1192
- this.logger.info('Listing schedules', { input: input });
1193
- paginator = clientScheduler.paginateListSchedules({ client: this.client }, input !== null && input !== void 0 ? input : {});
1194
- schedules = [];
1195
- _e.label = 1;
1196
- case 1:
1197
- _e.trys.push([1, 6, 7, 12]);
1198
- _a = true, paginator_1 = __asyncValues(paginator);
1199
- _e.label = 2;
1200
- case 2: return [4 /*yield*/, paginator_1.next()];
1201
- case 3:
1202
- if (!(paginator_1_1 = _e.sent(), _b = paginator_1_1.done, !_b)) return [3 /*break*/, 5];
1203
- _d = paginator_1_1.value;
1204
- _a = false;
1205
- page = _d;
1206
- if (page.Schedules)
1207
- schedules.push.apply(schedules, page.Schedules);
1208
- _e.label = 4;
1209
- case 4:
1210
- _a = true;
1211
- return [3 /*break*/, 2];
1212
- case 5: return [3 /*break*/, 12];
1213
- case 6:
1214
- e_1_1 = _e.sent();
1215
- e_1 = { error: e_1_1 };
1216
- return [3 /*break*/, 12];
1217
- case 7:
1218
- _e.trys.push([7, , 10, 11]);
1219
- if (!(!_a && !_b && (_c = paginator_1.return))) return [3 /*break*/, 9];
1220
- return [4 /*yield*/, _c.call(paginator_1)];
1221
- case 8:
1222
- _e.sent();
1223
- _e.label = 9;
1224
- case 9: return [3 /*break*/, 11];
1225
- case 10:
1226
- if (e_1) throw e_1.error;
1227
- return [7 /*endfinally*/];
1228
- case 11: return [7 /*endfinally*/];
1229
- case 12: return [2 /*return*/, schedules];
1230
- }
1231
- });
1232
- });
1233
- };
728
+ async listSchedules(input) {
729
+ this.logger.info('Listing schedules', { input });
730
+ const paginator = clientScheduler.paginateListSchedules({ client: this.client }, input ?? {});
731
+ const schedules = [];
732
+ for await (const page of paginator) {
733
+ if (page.Schedules)
734
+ schedules.push(...page.Schedules);
735
+ }
736
+ return schedules;
737
+ }
1234
738
  /**
1235
739
  * Create a new schedule group. Groups are containers for schedules and are
1236
740
  * typically IaC-managed; use this for dynamically-provisioned groups only.
1237
741
  */
1238
- SchedulerService.prototype.createScheduleGroup = function (input) {
1239
- return __awaiter(this, void 0, void 0, function () {
1240
- return __generator(this, function (_a) {
1241
- this.logger.info('Creating schedule group', { input: input });
1242
- return [2 /*return*/, this.client.send(new clientScheduler.CreateScheduleGroupCommand(input))];
1243
- });
1244
- });
1245
- };
742
+ async createScheduleGroup(input) {
743
+ this.logger.info('Creating schedule group', { input });
744
+ return this.client.send(new clientScheduler.CreateScheduleGroupCommand(input));
745
+ }
1246
746
  /**
1247
747
  * Fetch a schedule group's configuration.
1248
748
  */
1249
- SchedulerService.prototype.getScheduleGroup = function (input) {
1250
- return __awaiter(this, void 0, void 0, function () {
1251
- return __generator(this, function (_a) {
1252
- this.logger.info('Getting schedule group', { input: input });
1253
- return [2 /*return*/, this.client.send(new clientScheduler.GetScheduleGroupCommand(input))];
1254
- });
1255
- });
1256
- };
749
+ async getScheduleGroup(input) {
750
+ this.logger.info('Getting schedule group', { input });
751
+ return this.client.send(new clientScheduler.GetScheduleGroupCommand(input));
752
+ }
1257
753
  /**
1258
754
  * Delete a schedule group. Deleting a group also deletes every schedule it
1259
755
  * contains, asynchronously — the API has no `UpdateScheduleGroup`, so this
1260
756
  * is the only mutating group operation besides create.
1261
757
  */
1262
- SchedulerService.prototype.deleteScheduleGroup = function (input) {
1263
- return __awaiter(this, void 0, void 0, function () {
1264
- return __generator(this, function (_a) {
1265
- this.logger.info('Deleting schedule group', { input: input });
1266
- return [2 /*return*/, this.client.send(new clientScheduler.DeleteScheduleGroupCommand(input))];
1267
- });
1268
- });
1269
- };
758
+ async deleteScheduleGroup(input) {
759
+ this.logger.info('Deleting schedule group', { input });
760
+ return this.client.send(new clientScheduler.DeleteScheduleGroupCommand(input));
761
+ }
1270
762
  /**
1271
763
  * List schedule groups, auto-paginating across all pages. Bounded in
1272
764
  * practice by the account's group count and the `NamePrefix` filter.
1273
765
  */
1274
- SchedulerService.prototype.listScheduleGroups = function (input) {
1275
- return __awaiter(this, void 0, void 0, function () {
1276
- var paginator, groups, _a, paginator_2, paginator_2_1, page, e_2_1;
1277
- var _b, e_2, _c, _d;
1278
- return __generator(this, function (_e) {
1279
- switch (_e.label) {
1280
- case 0:
1281
- this.logger.info('Listing schedule groups', { input: input });
1282
- paginator = clientScheduler.paginateListScheduleGroups({ client: this.client }, input !== null && input !== void 0 ? input : {});
1283
- groups = [];
1284
- _e.label = 1;
1285
- case 1:
1286
- _e.trys.push([1, 6, 7, 12]);
1287
- _a = true, paginator_2 = __asyncValues(paginator);
1288
- _e.label = 2;
1289
- case 2: return [4 /*yield*/, paginator_2.next()];
1290
- case 3:
1291
- if (!(paginator_2_1 = _e.sent(), _b = paginator_2_1.done, !_b)) return [3 /*break*/, 5];
1292
- _d = paginator_2_1.value;
1293
- _a = false;
1294
- page = _d;
1295
- if (page.ScheduleGroups)
1296
- groups.push.apply(groups, page.ScheduleGroups);
1297
- _e.label = 4;
1298
- case 4:
1299
- _a = true;
1300
- return [3 /*break*/, 2];
1301
- case 5: return [3 /*break*/, 12];
1302
- case 6:
1303
- e_2_1 = _e.sent();
1304
- e_2 = { error: e_2_1 };
1305
- return [3 /*break*/, 12];
1306
- case 7:
1307
- _e.trys.push([7, , 10, 11]);
1308
- if (!(!_a && !_b && (_c = paginator_2.return))) return [3 /*break*/, 9];
1309
- return [4 /*yield*/, _c.call(paginator_2)];
1310
- case 8:
1311
- _e.sent();
1312
- _e.label = 9;
1313
- case 9: return [3 /*break*/, 11];
1314
- case 10:
1315
- if (e_2) throw e_2.error;
1316
- return [7 /*endfinally*/];
1317
- case 11: return [7 /*endfinally*/];
1318
- case 12: return [2 /*return*/, groups];
1319
- }
1320
- });
1321
- });
1322
- };
1323
- return SchedulerService;
1324
- }());
766
+ async listScheduleGroups(input) {
767
+ this.logger.info('Listing schedule groups', { input });
768
+ const paginator = clientScheduler.paginateListScheduleGroups({ client: this.client }, input ?? {});
769
+ const groups = [];
770
+ for await (const page of paginator) {
771
+ if (page.ScheduleGroups)
772
+ groups.push(...page.ScheduleGroups);
773
+ }
774
+ return groups;
775
+ }
776
+ }
1325
777
 
1326
778
  /**
1327
779
  * Fields safe to log at INFO level. Omits `SecretString` and `SecretBinary` —
1328
- * the secret material itself. `POWERTOOLS_LOG_LEVEL=DEBUG` unlocks the full
1329
- * input.
780
+ * the secret material itself.
1330
781
  */
1331
- var CREATE_SECRET_SAFE_FIELDS = [
782
+ const CREATE_SECRET_SAFE_FIELDS = [
1332
783
  'Name',
1333
784
  'Description',
1334
785
  'KmsKeyId',
@@ -1337,13 +788,13 @@ var CREATE_SECRET_SAFE_FIELDS = [
1337
788
  'AddReplicaRegions',
1338
789
  'ForceOverwriteReplicaSecret',
1339
790
  ];
1340
- var UPDATE_SECRET_SAFE_FIELDS = [
791
+ const UPDATE_SECRET_SAFE_FIELDS = [
1341
792
  'SecretId',
1342
793
  'Description',
1343
794
  'KmsKeyId',
1344
795
  'ClientRequestToken',
1345
796
  ];
1346
- var PUT_SECRET_VALUE_SAFE_FIELDS = [
797
+ const PUT_SECRET_VALUE_SAFE_FIELDS = [
1347
798
  'SecretId',
1348
799
  'VersionStages',
1349
800
  'ClientRequestToken',
@@ -1353,7 +804,7 @@ var PUT_SECRET_VALUE_SAFE_FIELDS = [
1353
804
  * explicit allowlist keeps the log shape consistent with the other write
1354
805
  * methods and protects against future field additions.
1355
806
  */
1356
- var DELETE_SECRET_SAFE_FIELDS = [
807
+ const DELETE_SECRET_SAFE_FIELDS = [
1357
808
  'SecretId',
1358
809
  'RecoveryWindowInDays',
1359
810
  'ForceDeleteWithoutRecovery',
@@ -1362,6 +813,10 @@ var DELETE_SECRET_SAFE_FIELDS = [
1362
813
  * Wrapper around the AWS Secrets Manager client providing structured
1363
814
  * Powertools logging and X-Ray tracing by default.
1364
815
  *
816
+ * Where a method's input carries payloads, secret material or PII, the INFO
817
+ * log line omits them; the verbose levels (`POWERTOOLS_LOG_LEVEL=DEBUG` or
818
+ * `TRACE`) log full SDK inputs.
819
+ *
1365
820
  * Write operations (`createSecret`, `updateSecret`, `putSecretValue`,
1366
821
  * `deleteSecret`) are exposed for convenience but should be used with care:
1367
822
  * secret lifecycle is usually managed by IaC (CDK / Terraform). Prefer IaC
@@ -1369,7 +824,9 @@ var DELETE_SECRET_SAFE_FIELDS = [
1369
824
  * dynamically-issued credentials, rotation flows, or other genuinely
1370
825
  * mutable values.
1371
826
  */
1372
- var SecretsManagerService = /** @class */ (function () {
827
+ class SecretsManagerService {
828
+ client;
829
+ logger;
1373
830
  /**
1374
831
  * @param opts.logger - Optional Powertools logger. Defaults to `new Logger()`,
1375
832
  * which picks up `POWERTOOLS_SERVICE_NAME` from the environment.
@@ -1377,10 +834,9 @@ var SecretsManagerService = /** @class */ (function () {
1377
834
  * supplied, the wrapper does not apply X-Ray instrumentation — the caller
1378
835
  * owns that decision.
1379
836
  */
1380
- function SecretsManagerService(opts) {
1381
- var _a, _b;
1382
- this.client = (_a = opts === null || opts === void 0 ? void 0 : opts.client) !== null && _a !== void 0 ? _a : xray.captureAWSv3Client(new clientSecretsManager.SecretsManagerClient());
1383
- this.logger = (_b = opts === null || opts === void 0 ? void 0 : opts.logger) !== null && _b !== void 0 ? _b : new logger.Logger();
837
+ constructor(opts) {
838
+ this.client = opts?.client ?? xray.captureAWSv3Client(new clientSecretsManager.SecretsManagerClient());
839
+ this.logger = opts?.logger ?? new logger.Logger();
1384
840
  }
1385
841
  /**
1386
842
  * Fetch a secret's string value from Secrets Manager.
@@ -1389,14 +845,10 @@ var SecretsManagerService = /** @class */ (function () {
1389
845
  * @throws If the response does not contain a `SecretString` (e.g. the secret
1390
846
  * stores binary data).
1391
847
  */
1392
- SecretsManagerService.prototype.getSecret = function (secretId) {
1393
- return __awaiter(this, void 0, void 0, function () {
1394
- return __generator(this, function (_a) {
1395
- this.logger.info('Fetching secret', { input: { secretId: secretId } });
1396
- return [2 /*return*/, this.fetchSecretString(secretId)];
1397
- });
1398
- });
1399
- };
848
+ async getSecret(secretId) {
849
+ this.logger.info('Fetching secret', { input: { secretId } });
850
+ return this.fetchSecretString(secretId);
851
+ }
1400
852
  /**
1401
853
  * Fetch a secret and parse it as JSON.
1402
854
  * @param secretId - The ARN or friendly name of the secret.
@@ -1404,115 +856,76 @@ var SecretsManagerService = /** @class */ (function () {
1404
856
  * @returns The parsed secret value.
1405
857
  * @throws If the secret has no `SecretString` or the value is not valid JSON.
1406
858
  */
1407
- SecretsManagerService.prototype.getJsonSecret = function (secretId) {
1408
- return __awaiter(this, void 0, void 0, function () {
1409
- var secretString;
1410
- return __generator(this, function (_a) {
1411
- switch (_a.label) {
1412
- case 0:
1413
- this.logger.info('Fetching JSON secret', { input: { secretId: secretId } });
1414
- return [4 /*yield*/, this.fetchSecretString(secretId)];
1415
- case 1:
1416
- secretString = _a.sent();
1417
- return [2 /*return*/, JSON.parse(secretString)];
1418
- }
1419
- });
1420
- });
1421
- };
859
+ async getJsonSecret(secretId) {
860
+ this.logger.info('Fetching JSON secret', { input: { secretId } });
861
+ const secretString = await this.fetchSecretString(secretId);
862
+ return JSON.parse(secretString);
863
+ }
1422
864
  /**
1423
865
  * Create a new secret. At INFO level the log line includes only identity
1424
- * and non-secret metadata; `POWERTOOLS_LOG_LEVEL=DEBUG` unlocks the full
1425
- * input (including `SecretString` / `SecretBinary`).
866
+ * and non-secret metadata.
1426
867
  *
1427
868
  * Prefer IaC (CDK / Terraform) for secret lifecycle — use this for
1428
869
  * dynamically-issued credentials only.
1429
870
  */
1430
- SecretsManagerService.prototype.createSecret = function (input) {
1431
- return __awaiter(this, void 0, void 0, function () {
1432
- return __generator(this, function (_a) {
1433
- this.logger.info('Creating secret', {
1434
- input: filterFieldsForLogLevel(this.logger, input, CREATE_SECRET_SAFE_FIELDS),
1435
- });
1436
- return [2 /*return*/, this.client.send(new clientSecretsManager.CreateSecretCommand(input))];
1437
- });
871
+ async createSecret(input) {
872
+ this.logger.info('Creating secret', {
873
+ input: filterFieldsForLogLevel(this.logger, input, CREATE_SECRET_SAFE_FIELDS),
1438
874
  });
1439
- };
875
+ return this.client.send(new clientSecretsManager.CreateSecretCommand(input));
876
+ }
1440
877
  /**
1441
878
  * Update an existing secret's metadata or value. At INFO level the log
1442
- * line omits `SecretString` / `SecretBinary`; `POWERTOOLS_LOG_LEVEL=DEBUG`
1443
- * unlocks the full input.
879
+ * line omits `SecretString` / `SecretBinary`.
1444
880
  *
1445
881
  * Prefer IaC (CDK / Terraform) for secret lifecycle — use this for
1446
882
  * runtime metadata updates only.
1447
883
  */
1448
- SecretsManagerService.prototype.updateSecret = function (input) {
1449
- return __awaiter(this, void 0, void 0, function () {
1450
- return __generator(this, function (_a) {
1451
- this.logger.info('Updating secret', {
1452
- input: filterFieldsForLogLevel(this.logger, input, UPDATE_SECRET_SAFE_FIELDS),
1453
- });
1454
- return [2 /*return*/, this.client.send(new clientSecretsManager.UpdateSecretCommand(input))];
1455
- });
884
+ async updateSecret(input) {
885
+ this.logger.info('Updating secret', {
886
+ input: filterFieldsForLogLevel(this.logger, input, UPDATE_SECRET_SAFE_FIELDS),
1456
887
  });
1457
- };
888
+ return this.client.send(new clientSecretsManager.UpdateSecretCommand(input));
889
+ }
1458
890
  /**
1459
891
  * Store a new version of a secret's value. At INFO level the log line
1460
- * omits `SecretString` / `SecretBinary`; `POWERTOOLS_LOG_LEVEL=DEBUG`
1461
- * unlocks the full input.
892
+ * omits `SecretString` / `SecretBinary`.
1462
893
  *
1463
894
  * Typically used by rotation flows.
1464
895
  */
1465
- SecretsManagerService.prototype.putSecretValue = function (input) {
1466
- return __awaiter(this, void 0, void 0, function () {
1467
- return __generator(this, function (_a) {
1468
- this.logger.info('Putting secret value', {
1469
- input: filterFieldsForLogLevel(this.logger, input, PUT_SECRET_VALUE_SAFE_FIELDS),
1470
- });
1471
- return [2 /*return*/, this.client.send(new clientSecretsManager.PutSecretValueCommand(input))];
1472
- });
896
+ async putSecretValue(input) {
897
+ this.logger.info('Putting secret value', {
898
+ input: filterFieldsForLogLevel(this.logger, input, PUT_SECRET_VALUE_SAFE_FIELDS),
1473
899
  });
1474
- };
900
+ return this.client.send(new clientSecretsManager.PutSecretValueCommand(input));
901
+ }
1475
902
  /**
1476
903
  * Delete a secret. Pass `ForceDeleteWithoutRecovery: true` to bypass the
1477
904
  * default 7-30 day recovery window (irreversible).
1478
905
  *
1479
906
  * Prefer IaC (CDK / Terraform) for secret lifecycle.
1480
907
  */
1481
- SecretsManagerService.prototype.deleteSecret = function (input) {
1482
- return __awaiter(this, void 0, void 0, function () {
1483
- return __generator(this, function (_a) {
1484
- this.logger.info('Deleting secret', {
1485
- input: filterFieldsForLogLevel(this.logger, input, DELETE_SECRET_SAFE_FIELDS),
1486
- });
1487
- return [2 /*return*/, this.client.send(new clientSecretsManager.DeleteSecretCommand(input))];
1488
- });
1489
- });
1490
- };
1491
- SecretsManagerService.prototype.fetchSecretString = function (secretId) {
1492
- return __awaiter(this, void 0, void 0, function () {
1493
- var response;
1494
- return __generator(this, function (_a) {
1495
- switch (_a.label) {
1496
- case 0: return [4 /*yield*/, this.client.send(new clientSecretsManager.GetSecretValueCommand({ SecretId: secretId }))];
1497
- case 1:
1498
- response = _a.sent();
1499
- if (response.SecretString === undefined) {
1500
- throw new Error("Secret '".concat(secretId, "' does not contain a string value"));
1501
- }
1502
- return [2 /*return*/, response.SecretString];
1503
- }
1504
- });
908
+ async deleteSecret(input) {
909
+ this.logger.info('Deleting secret', {
910
+ input: filterFieldsForLogLevel(this.logger, input, DELETE_SECRET_SAFE_FIELDS),
1505
911
  });
1506
- };
1507
- return SecretsManagerService;
1508
- }());
912
+ return this.client.send(new clientSecretsManager.DeleteSecretCommand(input));
913
+ }
914
+ async fetchSecretString(secretId) {
915
+ const response = await this.client.send(new clientSecretsManager.GetSecretValueCommand({ SecretId: secretId }));
916
+ if (response.SecretString === undefined) {
917
+ throw new Error(`Secret '${secretId}' does not contain a string value`);
918
+ }
919
+ return response.SecretString;
920
+ }
921
+ }
1509
922
 
1510
923
  /**
1511
924
  * Fields safe to log at INFO for `startExecution`. Omits `input` — the SFN
1512
925
  * execution payload, which routinely carries PII (customer IDs, addresses,
1513
- * order contents, etc.). `POWERTOOLS_LOG_LEVEL=DEBUG` unlocks the full input.
926
+ * order contents, etc.).
1514
927
  */
1515
- var START_EXECUTION_SAFE_FIELDS = [
928
+ const START_EXECUTION_SAFE_FIELDS = [
1516
929
  'stateMachineArn',
1517
930
  'name',
1518
931
  'traceHeader',
@@ -1520,110 +933,63 @@ var START_EXECUTION_SAFE_FIELDS = [
1520
933
  /**
1521
934
  * Wrapper around the AWS Step Functions client providing structured
1522
935
  * Powertools logging and X-Ray tracing by default.
936
+ *
937
+ * Where a method's input carries payloads, secret material or PII, the INFO
938
+ * log line omits them; the verbose levels (`POWERTOOLS_LOG_LEVEL=DEBUG` or
939
+ * `TRACE`) log full SDK inputs.
1523
940
  */
1524
- var StepFunctionsService = /** @class */ (function () {
941
+ class StepFunctionsService {
942
+ client;
943
+ logger;
1525
944
  /**
1526
945
  * @param opts.logger - Optional Powertools logger. Defaults to `new Logger()`,
1527
946
  * which picks up `POWERTOOLS_SERVICE_NAME` from the environment.
1528
947
  * @param opts.client - Optional pre-configured `SFNClient`. When supplied,
1529
948
  * the wrapper does not apply X-Ray instrumentation.
1530
949
  */
1531
- function StepFunctionsService(opts) {
1532
- var _a, _b;
1533
- this.client = (_a = opts === null || opts === void 0 ? void 0 : opts.client) !== null && _a !== void 0 ? _a : xray.captureAWSv3Client(new clientSfn.SFNClient());
1534
- this.logger = (_b = opts === null || opts === void 0 ? void 0 : opts.logger) !== null && _b !== void 0 ? _b : new logger.Logger();
950
+ constructor(opts) {
951
+ this.client = opts?.client ?? xray.captureAWSv3Client(new clientSfn.SFNClient());
952
+ this.logger = opts?.logger ?? new logger.Logger();
1535
953
  }
1536
954
  /**
1537
955
  * List all executions for a state machine, auto-paginating across all
1538
956
  * pages. Typically bounded by `statusFilter` and state-machine retention,
1539
957
  * so the flat-array shape is safe in practice.
1540
958
  */
1541
- StepFunctionsService.prototype.listExecutions = function (input) {
1542
- return __awaiter(this, void 0, void 0, function () {
1543
- var paginator, executions, _a, paginator_1, paginator_1_1, page, e_1_1;
1544
- var _b, e_1, _c, _d;
1545
- return __generator(this, function (_e) {
1546
- switch (_e.label) {
1547
- case 0:
1548
- this.logger.info('Listing Step Functions executions', { input: input });
1549
- paginator = clientSfn.paginateListExecutions({ client: this.client }, input);
1550
- executions = [];
1551
- _e.label = 1;
1552
- case 1:
1553
- _e.trys.push([1, 6, 7, 12]);
1554
- _a = true, paginator_1 = __asyncValues(paginator);
1555
- _e.label = 2;
1556
- case 2: return [4 /*yield*/, paginator_1.next()];
1557
- case 3:
1558
- if (!(paginator_1_1 = _e.sent(), _b = paginator_1_1.done, !_b)) return [3 /*break*/, 5];
1559
- _d = paginator_1_1.value;
1560
- _a = false;
1561
- page = _d;
1562
- if (page.executions)
1563
- executions.push.apply(executions, page.executions);
1564
- _e.label = 4;
1565
- case 4:
1566
- _a = true;
1567
- return [3 /*break*/, 2];
1568
- case 5: return [3 /*break*/, 12];
1569
- case 6:
1570
- e_1_1 = _e.sent();
1571
- e_1 = { error: e_1_1 };
1572
- return [3 /*break*/, 12];
1573
- case 7:
1574
- _e.trys.push([7, , 10, 11]);
1575
- if (!(!_a && !_b && (_c = paginator_1.return))) return [3 /*break*/, 9];
1576
- return [4 /*yield*/, _c.call(paginator_1)];
1577
- case 8:
1578
- _e.sent();
1579
- _e.label = 9;
1580
- case 9: return [3 /*break*/, 11];
1581
- case 10:
1582
- if (e_1) throw e_1.error;
1583
- return [7 /*endfinally*/];
1584
- case 11: return [7 /*endfinally*/];
1585
- case 12: return [2 /*return*/, executions];
1586
- }
1587
- });
1588
- });
1589
- };
959
+ async listExecutions(input) {
960
+ this.logger.info('Listing Step Functions executions', { input });
961
+ const paginator = clientSfn.paginateListExecutions({ client: this.client }, input);
962
+ const executions = [];
963
+ for await (const page of paginator) {
964
+ if (page.executions)
965
+ executions.push(...page.executions);
966
+ }
967
+ return executions;
968
+ }
1590
969
  /**
1591
970
  * Start a new Step Functions execution.
1592
971
  */
1593
- StepFunctionsService.prototype.startExecution = function (input) {
1594
- return __awaiter(this, void 0, void 0, function () {
1595
- return __generator(this, function (_a) {
1596
- this.logger.info('Starting Step Functions execution', {
1597
- input: filterFieldsForLogLevel(this.logger, input, START_EXECUTION_SAFE_FIELDS),
1598
- });
1599
- return [2 /*return*/, this.client.send(new clientSfn.StartExecutionCommand(input))];
1600
- });
972
+ async startExecution(input) {
973
+ this.logger.info('Starting Step Functions execution', {
974
+ input: filterFieldsForLogLevel(this.logger, input, START_EXECUTION_SAFE_FIELDS),
1601
975
  });
1602
- };
976
+ return this.client.send(new clientSfn.StartExecutionCommand(input));
977
+ }
1603
978
  /**
1604
979
  * Describe an existing Step Functions execution.
1605
980
  */
1606
- StepFunctionsService.prototype.describeExecution = function (input) {
1607
- return __awaiter(this, void 0, void 0, function () {
1608
- return __generator(this, function (_a) {
1609
- this.logger.info('Describing Step Functions execution', { input: input });
1610
- return [2 /*return*/, this.client.send(new clientSfn.DescribeExecutionCommand(input))];
1611
- });
1612
- });
1613
- };
981
+ async describeExecution(input) {
982
+ this.logger.info('Describing Step Functions execution', { input });
983
+ return this.client.send(new clientSfn.DescribeExecutionCommand(input));
984
+ }
1614
985
  /**
1615
986
  * Stop an in-progress Step Functions execution.
1616
987
  */
1617
- StepFunctionsService.prototype.stopExecution = function (input) {
1618
- return __awaiter(this, void 0, void 0, function () {
1619
- return __generator(this, function (_a) {
1620
- this.logger.info('Stopping Step Functions execution', { input: input });
1621
- return [2 /*return*/, this.client.send(new clientSfn.StopExecutionCommand(input))];
1622
- });
1623
- });
1624
- };
1625
- return StepFunctionsService;
1626
- }());
988
+ async stopExecution(input) {
989
+ this.logger.info('Stopping Step Functions execution', { input });
990
+ return this.client.send(new clientSfn.StopExecutionCommand(input));
991
+ }
992
+ }
1627
993
 
1628
994
  /**
1629
995
  * Truncate a UTF-8 string to fit within `maxBytes` when encoded as UTF-8.
@@ -1633,12 +999,12 @@ var StepFunctionsService = /** @class */ (function () {
1633
999
  * it already fits.
1634
1000
  */
1635
1001
  function truncateUtf8(str, maxBytes) {
1636
- var buf = Buffer.from(str, 'utf8');
1002
+ const buf = Buffer.from(str, 'utf8');
1637
1003
  if (buf.length <= maxBytes)
1638
1004
  return str;
1639
- var end = maxBytes;
1005
+ let end = maxBytes;
1640
1006
  while (end > 0) {
1641
- var byte = buf[end];
1007
+ const byte = buf[end];
1642
1008
  if (byte === undefined || (byte & 0xc0) !== 0x80)
1643
1009
  break;
1644
1010
  end--;
@@ -1652,22 +1018,22 @@ function truncateUtf8(str, maxBytes) {
1652
1018
  * it already fits.
1653
1019
  */
1654
1020
  function truncateCodepoints(str, maxChars) {
1655
- var codepoints = Array.from(str);
1021
+ const codepoints = Array.from(str);
1656
1022
  if (codepoints.length <= maxChars)
1657
1023
  return str;
1658
1024
  return codepoints.slice(0, maxChars).join('');
1659
1025
  }
1660
1026
 
1661
- var PUBLISH_BATCH_LIMIT = 10;
1662
- var SNS_MESSAGE_MAX_BYTES = 256 * 1024;
1663
- var SNS_SUBJECT_MAX_CHARS = 100;
1027
+ const PUBLISH_BATCH_LIMIT = 10;
1028
+ const SNS_MESSAGE_MAX_BYTES = 256 * 1024;
1029
+ const SNS_SUBJECT_MAX_CHARS = 100;
1664
1030
  /**
1665
1031
  * Fields safe to log at INFO level for `publish`. Omits `Message`, `Subject`,
1666
1032
  * `MessageAttributes`, and `PhoneNumber` — payloads, user-visible content
1667
1033
  * (subjects often carry order numbers / customer names), and PII recipient
1668
- * identifiers. `POWERTOOLS_LOG_LEVEL=DEBUG` unlocks the full input.
1034
+ * identifiers.
1669
1035
  */
1670
- var PUBLISH_SAFE_FIELDS = [
1036
+ const PUBLISH_SAFE_FIELDS = [
1671
1037
  'TopicArn',
1672
1038
  'TargetArn',
1673
1039
  'MessageStructure',
@@ -1677,8 +1043,15 @@ var PUBLISH_SAFE_FIELDS = [
1677
1043
  /**
1678
1044
  * Wrapper around the AWS SNS client providing structured Powertools logging
1679
1045
  * and X-Ray tracing by default.
1046
+ *
1047
+ * Where a method's input carries payloads, secret material or PII, the INFO
1048
+ * log line omits them; the verbose levels (`POWERTOOLS_LOG_LEVEL=DEBUG` or
1049
+ * `TRACE`) log full SDK inputs.
1680
1050
  */
1681
- var SNSService = /** @class */ (function () {
1051
+ class SNSService {
1052
+ client;
1053
+ logger;
1054
+ truncate;
1682
1055
  /**
1683
1056
  * @param opts.logger - Optional Powertools logger. Defaults to `new Logger()`,
1684
1057
  * which picks up `POWERTOOLS_SERVICE_NAME` from the environment.
@@ -1690,52 +1063,56 @@ var SNSService = /** @class */ (function () {
1690
1063
  * usually the right failure mode. Each `publish` call can override via
1691
1064
  * its own `truncate` option.
1692
1065
  */
1693
- function SNSService(opts) {
1694
- var _a, _b, _c;
1695
- this.client = (_a = opts === null || opts === void 0 ? void 0 : opts.client) !== null && _a !== void 0 ? _a : xray.captureAWSv3Client(new clientSns.SNSClient());
1696
- this.logger = (_b = opts === null || opts === void 0 ? void 0 : opts.logger) !== null && _b !== void 0 ? _b : new logger.Logger();
1697
- this.truncate = (_c = opts === null || opts === void 0 ? void 0 : opts.truncate) !== null && _c !== void 0 ? _c : false;
1066
+ constructor(opts) {
1067
+ this.client = opts?.client ?? xray.captureAWSv3Client(new clientSns.SNSClient());
1068
+ this.logger = opts?.logger ?? new logger.Logger();
1069
+ this.truncate = opts?.truncate ?? false;
1698
1070
  }
1699
1071
  /**
1700
1072
  * Publish a single message to an SNS topic.
1701
1073
  *
1702
1074
  * At INFO level the log line includes only routing / dedup metadata; see
1703
- * `PUBLISH_SAFE_FIELDS` for the list. Setting `POWERTOOLS_LOG_LEVEL=DEBUG`
1704
- * unlocks the full input.
1075
+ * `PUBLISH_SAFE_FIELDS` for the list.
1705
1076
  *
1706
1077
  * @param input - PublishCommandInput including TopicArn and Message.
1707
1078
  */
1708
- SNSService.prototype.publish = function (input, opts) {
1709
- return __awaiter(this, void 0, void 0, function () {
1710
- var shouldTruncate, effective;
1711
- var _a;
1712
- return __generator(this, function (_b) {
1713
- shouldTruncate = (_a = opts === null || opts === void 0 ? void 0 : opts.truncate) !== null && _a !== void 0 ? _a : this.truncate;
1714
- effective = shouldTruncate ? this.applyTruncation(input) : input;
1715
- this.logger.info('Publishing SNS message', {
1716
- input: filterFieldsForLogLevel(this.logger, effective, PUBLISH_SAFE_FIELDS),
1717
- });
1718
- return [2 /*return*/, this.client.send(new clientSns.PublishCommand(effective))];
1719
- });
1079
+ async publish(input, opts) {
1080
+ const shouldTruncate = opts?.truncate ?? this.truncate;
1081
+ const effective = shouldTruncate ? this.applyTruncation(input) : input;
1082
+ this.logger.info('Publishing SNS message', {
1083
+ input: filterFieldsForLogLevel(this.logger, effective, PUBLISH_SAFE_FIELDS),
1720
1084
  });
1721
- };
1722
- SNSService.prototype.applyTruncation = function (input) {
1723
- var truncated = [];
1724
- var Message = input.Message;
1725
- if (Message !== undefined && Buffer.byteLength(Message, 'utf8') > SNS_MESSAGE_MAX_BYTES) {
1726
- Message = truncateUtf8(Message, SNS_MESSAGE_MAX_BYTES);
1727
- truncated.push('Message');
1085
+ return this.client.send(new clientSns.PublishCommand(effective));
1086
+ }
1087
+ /**
1088
+ * The truncation helpers return the input unchanged when it already fits, so
1089
+ * a `!==` comparison against their result is what decides whether a field
1090
+ * was modified. Don't reintroduce a size guard here: that would state each
1091
+ * limit twice, encode the string to a `Buffer` twice, and let the two
1092
+ * expressions drift into warning without truncating (or the reverse).
1093
+ */
1094
+ applyTruncation(input) {
1095
+ const truncated = [];
1096
+ const out = { ...input };
1097
+ if (out.Message !== undefined) {
1098
+ const next = truncateUtf8(out.Message, SNS_MESSAGE_MAX_BYTES);
1099
+ if (next !== out.Message) {
1100
+ out.Message = next;
1101
+ truncated.push('Message');
1102
+ }
1728
1103
  }
1729
- var Subject = input.Subject;
1730
- if (Subject !== undefined && Array.from(Subject).length > SNS_SUBJECT_MAX_CHARS) {
1731
- Subject = truncateCodepoints(Subject, SNS_SUBJECT_MAX_CHARS);
1732
- truncated.push('Subject');
1104
+ if (out.Subject !== undefined) {
1105
+ const next = truncateCodepoints(out.Subject, SNS_SUBJECT_MAX_CHARS);
1106
+ if (next !== out.Subject) {
1107
+ out.Subject = next;
1108
+ truncated.push('Subject');
1109
+ }
1733
1110
  }
1734
1111
  if (truncated.length > 0) {
1735
1112
  this.logger.warn('Truncated SNS publish input', { fields: truncated });
1736
1113
  }
1737
- return __assign(__assign({}, input), { Message: Message, Subject: Subject });
1738
- };
1114
+ return out;
1115
+ }
1739
1116
  /**
1740
1117
  * Publish a batch of messages to an SNS topic. The SNS API caps
1741
1118
  * PublishBatch at 10 entries per request, so this method auto-chunks
@@ -1743,48 +1120,34 @@ var SNSService = /** @class */ (function () {
1743
1120
  * chunk, returning the array of outputs.
1744
1121
  * @param input - PublishBatchCommandInput including TopicArn and entries.
1745
1122
  */
1746
- SNSService.prototype.publishBatch = function (input) {
1747
- return __awaiter(this, void 0, void 0, function () {
1748
- var entries, isDebug, results, i, chunk, _a, _b;
1749
- var _c;
1750
- return __generator(this, function (_d) {
1751
- switch (_d.label) {
1752
- case 0:
1753
- entries = (_c = input.PublishBatchRequestEntries) !== null && _c !== void 0 ? _c : [];
1754
- isDebug = this.logger.getLevelName() === 'DEBUG';
1755
- this.logger.info('Publishing SNS message batch', {
1756
- input: isDebug ? input : { TopicArn: input.TopicArn, entryCount: entries.length },
1757
- });
1758
- results = [];
1759
- i = 0;
1760
- _d.label = 1;
1761
- case 1:
1762
- if (!(i < entries.length)) return [3 /*break*/, 4];
1763
- chunk = entries.slice(i, i + PUBLISH_BATCH_LIMIT);
1764
- _b = (_a = results).push;
1765
- return [4 /*yield*/, this.client.send(new clientSns.PublishBatchCommand(__assign(__assign({}, input), { PublishBatchRequestEntries: chunk })))];
1766
- case 2:
1767
- _b.apply(_a, [_d.sent()]);
1768
- _d.label = 3;
1769
- case 3:
1770
- i += PUBLISH_BATCH_LIMIT;
1771
- return [3 /*break*/, 1];
1772
- case 4: return [2 /*return*/, results];
1773
- }
1774
- });
1123
+ async publishBatch(input) {
1124
+ const entries = input.PublishBatchRequestEntries ?? [];
1125
+ // Inline verbosity check rather than `filterFieldsForLogLevel` because the
1126
+ // safe log shape includes the computed `entryCount`, which isn't a key
1127
+ // on `PublishBatchCommandInput`.
1128
+ const logFullInput = shouldLogFullInput(this.logger);
1129
+ this.logger.info('Publishing SNS message batch', {
1130
+ input: logFullInput ? input : { TopicArn: input.TopicArn, entryCount: entries.length },
1775
1131
  });
1776
- };
1777
- return SNSService;
1778
- }());
1132
+ const results = [];
1133
+ for (let i = 0; i < entries.length; i += PUBLISH_BATCH_LIMIT) {
1134
+ const chunk = entries.slice(i, i + PUBLISH_BATCH_LIMIT);
1135
+ results.push(await this.client.send(new clientSns.PublishBatchCommand({
1136
+ ...input,
1137
+ PublishBatchRequestEntries: chunk,
1138
+ })));
1139
+ }
1140
+ return results;
1141
+ }
1142
+ }
1779
1143
 
1780
- var SQS_BATCH_LIMIT = 10;
1781
- var SQS_MESSAGE_BODY_MAX_BYTES = 256 * 1024;
1144
+ const SQS_BATCH_LIMIT = 10;
1145
+ const SQS_MESSAGE_BODY_MAX_BYTES = 256 * 1024;
1782
1146
  /**
1783
1147
  * Fields safe to log at INFO level for `sendMessage`. Omits `MessageBody` and
1784
1148
  * `MessageAttributes` — both carry payload content.
1785
- * `POWERTOOLS_LOG_LEVEL=DEBUG` unlocks the full input.
1786
1149
  */
1787
- var SEND_MESSAGE_SAFE_FIELDS = [
1150
+ const SEND_MESSAGE_SAFE_FIELDS = [
1788
1151
  'QueueUrl',
1789
1152
  'DelaySeconds',
1790
1153
  'MessageGroupId',
@@ -1793,8 +1156,15 @@ var SEND_MESSAGE_SAFE_FIELDS = [
1793
1156
  /**
1794
1157
  * Wrapper around the AWS SQS client providing structured Powertools logging
1795
1158
  * and X-Ray tracing by default.
1159
+ *
1160
+ * Where a method's input carries payloads, secret material or PII, the INFO
1161
+ * log line omits them; the verbose levels (`POWERTOOLS_LOG_LEVEL=DEBUG` or
1162
+ * `TRACE`) log full SDK inputs.
1796
1163
  */
1797
- var SQSService = /** @class */ (function () {
1164
+ class SQSService {
1165
+ client;
1166
+ logger;
1167
+ truncate;
1798
1168
  /**
1799
1169
  * @param opts.logger - Optional Powertools logger. Defaults to `new Logger()`,
1800
1170
  * which picks up `POWERTOOLS_SERVICE_NAME` from the environment.
@@ -1805,160 +1175,114 @@ var SQSService = /** @class */ (function () {
1805
1175
  * `false`. Each `sendMessage` call can override via its own `truncate`
1806
1176
  * option.
1807
1177
  */
1808
- function SQSService(opts) {
1809
- var _a, _b, _c;
1810
- this.client = (_a = opts === null || opts === void 0 ? void 0 : opts.client) !== null && _a !== void 0 ? _a : xray.captureAWSv3Client(new clientSqs.SQSClient());
1811
- this.logger = (_b = opts === null || opts === void 0 ? void 0 : opts.logger) !== null && _b !== void 0 ? _b : new logger.Logger();
1812
- this.truncate = (_c = opts === null || opts === void 0 ? void 0 : opts.truncate) !== null && _c !== void 0 ? _c : false;
1178
+ constructor(opts) {
1179
+ this.client = opts?.client ?? xray.captureAWSv3Client(new clientSqs.SQSClient());
1180
+ this.logger = opts?.logger ?? new logger.Logger();
1181
+ this.truncate = opts?.truncate ?? false;
1813
1182
  }
1814
1183
  /**
1815
1184
  * Send a single message to an SQS queue.
1816
1185
  *
1817
1186
  * At INFO level the log line includes only queue routing / FIFO metadata;
1818
- * see `SEND_MESSAGE_SAFE_FIELDS`. `POWERTOOLS_LOG_LEVEL=DEBUG` unlocks the
1819
- * full input.
1820
- */
1821
- SQSService.prototype.sendMessage = function (input, opts) {
1822
- return __awaiter(this, void 0, void 0, function () {
1823
- var shouldTruncate, effective;
1824
- var _a;
1825
- return __generator(this, function (_b) {
1826
- shouldTruncate = (_a = opts === null || opts === void 0 ? void 0 : opts.truncate) !== null && _a !== void 0 ? _a : this.truncate;
1827
- effective = shouldTruncate ? this.applyTruncation(input) : input;
1828
- this.logger.info('Sending SQS message', {
1829
- input: filterFieldsForLogLevel(this.logger, effective, SEND_MESSAGE_SAFE_FIELDS),
1830
- });
1831
- return [2 /*return*/, this.client.send(new clientSqs.SendMessageCommand(effective))];
1832
- });
1187
+ * see `SEND_MESSAGE_SAFE_FIELDS`.
1188
+ */
1189
+ async sendMessage(input, opts) {
1190
+ const shouldTruncate = opts?.truncate ?? this.truncate;
1191
+ const effective = shouldTruncate ? this.applyTruncation(input) : input;
1192
+ this.logger.info('Sending SQS message', {
1193
+ input: filterFieldsForLogLevel(this.logger, effective, SEND_MESSAGE_SAFE_FIELDS),
1833
1194
  });
1834
- };
1835
- SQSService.prototype.applyTruncation = function (input) {
1836
- var truncated = [];
1837
- var MessageBody = input.MessageBody;
1838
- if (MessageBody !== undefined &&
1839
- Buffer.byteLength(MessageBody, 'utf8') > SQS_MESSAGE_BODY_MAX_BYTES) {
1840
- MessageBody = truncateUtf8(MessageBody, SQS_MESSAGE_BODY_MAX_BYTES);
1841
- truncated.push('MessageBody');
1195
+ return this.client.send(new clientSqs.SendMessageCommand(effective));
1196
+ }
1197
+ /**
1198
+ * `truncateUtf8` returns the input unchanged when it already fits, so a
1199
+ * `!==` comparison against its result is what decides whether the body was
1200
+ * modified. Don't reintroduce a size guard here: that would state the limit
1201
+ * twice, encode the string to a `Buffer` twice, and let the two expressions
1202
+ * drift into warning without truncating (or the reverse).
1203
+ */
1204
+ applyTruncation(input) {
1205
+ const truncated = [];
1206
+ const out = { ...input };
1207
+ if (out.MessageBody !== undefined) {
1208
+ const next = truncateUtf8(out.MessageBody, SQS_MESSAGE_BODY_MAX_BYTES);
1209
+ if (next !== out.MessageBody) {
1210
+ out.MessageBody = next;
1211
+ truncated.push('MessageBody');
1212
+ }
1842
1213
  }
1843
1214
  if (truncated.length > 0) {
1844
1215
  this.logger.warn('Truncated SQS sendMessage input', { fields: truncated });
1845
1216
  }
1846
- return __assign(__assign({}, input), { MessageBody: MessageBody });
1847
- };
1217
+ return out;
1218
+ }
1848
1219
  /**
1849
1220
  * Receive messages from an SQS queue. Returns an empty array when no
1850
1221
  * messages are available. No automatic deletion is performed — visibility
1851
1222
  * timeout semantics are the caller's responsibility.
1852
1223
  * @returns The `Messages` array from the response, or `[]` if absent.
1853
1224
  */
1854
- SQSService.prototype.receiveMessages = function (input) {
1855
- return __awaiter(this, void 0, void 0, function () {
1856
- var response;
1857
- var _a;
1858
- return __generator(this, function (_b) {
1859
- switch (_b.label) {
1860
- case 0:
1861
- this.logger.info('Receiving SQS messages', { input: input });
1862
- return [4 /*yield*/, this.client.send(new clientSqs.ReceiveMessageCommand(input))];
1863
- case 1:
1864
- response = _b.sent();
1865
- return [2 /*return*/, (_a = response.Messages) !== null && _a !== void 0 ? _a : []];
1866
- }
1867
- });
1868
- });
1869
- };
1225
+ async receiveMessages(input) {
1226
+ this.logger.info('Receiving SQS messages', { input });
1227
+ const response = await this.client.send(new clientSqs.ReceiveMessageCommand(input));
1228
+ return response.Messages ?? [];
1229
+ }
1870
1230
  /**
1871
1231
  * Delete a single message from an SQS queue.
1872
1232
  */
1873
- SQSService.prototype.deleteMessage = function (input) {
1874
- return __awaiter(this, void 0, void 0, function () {
1875
- return __generator(this, function (_a) {
1876
- this.logger.info('Deleting SQS message', { input: input });
1877
- return [2 /*return*/, this.client.send(new clientSqs.DeleteMessageCommand(input))];
1878
- });
1879
- });
1880
- };
1233
+ async deleteMessage(input) {
1234
+ this.logger.info('Deleting SQS message', { input });
1235
+ return this.client.send(new clientSqs.DeleteMessageCommand(input));
1236
+ }
1881
1237
  /**
1882
1238
  * Send a batch of messages to an SQS queue. The SQS API caps
1883
1239
  * SendMessageBatch at 10 entries per request, so this method auto-chunks
1884
1240
  * the caller's entries and sends one request per chunk.
1885
1241
  */
1886
- SQSService.prototype.sendMessageBatch = function (input) {
1887
- return __awaiter(this, void 0, void 0, function () {
1888
- var entries, isDebug, results, i, chunk, _a, _b;
1889
- var _c;
1890
- return __generator(this, function (_d) {
1891
- switch (_d.label) {
1892
- case 0:
1893
- entries = (_c = input.Entries) !== null && _c !== void 0 ? _c : [];
1894
- isDebug = this.logger.getLevelName() === 'DEBUG';
1895
- this.logger.info('Sending SQS message batch', {
1896
- input: isDebug ? input : { QueueUrl: input.QueueUrl, entryCount: entries.length },
1897
- });
1898
- results = [];
1899
- i = 0;
1900
- _d.label = 1;
1901
- case 1:
1902
- if (!(i < entries.length)) return [3 /*break*/, 4];
1903
- chunk = entries.slice(i, i + SQS_BATCH_LIMIT);
1904
- _b = (_a = results).push;
1905
- return [4 /*yield*/, this.client.send(new clientSqs.SendMessageBatchCommand(__assign(__assign({}, input), { Entries: chunk })))];
1906
- case 2:
1907
- _b.apply(_a, [_d.sent()]);
1908
- _d.label = 3;
1909
- case 3:
1910
- i += SQS_BATCH_LIMIT;
1911
- return [3 /*break*/, 1];
1912
- case 4: return [2 /*return*/, results];
1913
- }
1914
- });
1242
+ async sendMessageBatch(input) {
1243
+ const entries = input.Entries ?? [];
1244
+ // Inline verbosity check rather than `filterFieldsForLogLevel` because the
1245
+ // safe log shape includes the computed `entryCount`, which isn't a key
1246
+ // on `SendMessageBatchCommandInput`.
1247
+ const logFullInput = shouldLogFullInput(this.logger);
1248
+ this.logger.info('Sending SQS message batch', {
1249
+ input: logFullInput ? input : { QueueUrl: input.QueueUrl, entryCount: entries.length },
1915
1250
  });
1916
- };
1251
+ const results = [];
1252
+ for (let i = 0; i < entries.length; i += SQS_BATCH_LIMIT) {
1253
+ const chunk = entries.slice(i, i + SQS_BATCH_LIMIT);
1254
+ results.push(await this.client.send(new clientSqs.SendMessageBatchCommand({ ...input, Entries: chunk })));
1255
+ }
1256
+ return results;
1257
+ }
1917
1258
  /**
1918
1259
  * Delete a batch of messages from an SQS queue. The SQS API caps
1919
1260
  * DeleteMessageBatch at 10 entries per request, so this method auto-chunks
1920
1261
  * the caller's entries and sends one request per chunk.
1921
1262
  */
1922
- SQSService.prototype.deleteMessageBatch = function (input) {
1923
- return __awaiter(this, void 0, void 0, function () {
1924
- var entries, isDebug, results, i, chunk, _a, _b;
1925
- var _c;
1926
- return __generator(this, function (_d) {
1927
- switch (_d.label) {
1928
- case 0:
1929
- entries = (_c = input.Entries) !== null && _c !== void 0 ? _c : [];
1930
- isDebug = this.logger.getLevelName() === 'DEBUG';
1931
- this.logger.info('Deleting SQS message batch', {
1932
- input: isDebug ? input : { QueueUrl: input.QueueUrl, entryCount: entries.length },
1933
- });
1934
- results = [];
1935
- i = 0;
1936
- _d.label = 1;
1937
- case 1:
1938
- if (!(i < entries.length)) return [3 /*break*/, 4];
1939
- chunk = entries.slice(i, i + SQS_BATCH_LIMIT);
1940
- _b = (_a = results).push;
1941
- return [4 /*yield*/, this.client.send(new clientSqs.DeleteMessageBatchCommand(__assign(__assign({}, input), { Entries: chunk })))];
1942
- case 2:
1943
- _b.apply(_a, [_d.sent()]);
1944
- _d.label = 3;
1945
- case 3:
1946
- i += SQS_BATCH_LIMIT;
1947
- return [3 /*break*/, 1];
1948
- case 4: return [2 /*return*/, results];
1949
- }
1950
- });
1263
+ async deleteMessageBatch(input) {
1264
+ const entries = input.Entries ?? [];
1265
+ // Inline verbosity check rather than `filterFieldsForLogLevel` because the
1266
+ // safe log shape includes the computed `entryCount`, which isn't a key
1267
+ // on `DeleteMessageBatchCommandInput`.
1268
+ const logFullInput = shouldLogFullInput(this.logger);
1269
+ this.logger.info('Deleting SQS message batch', {
1270
+ input: logFullInput ? input : { QueueUrl: input.QueueUrl, entryCount: entries.length },
1951
1271
  });
1952
- };
1953
- return SQSService;
1954
- }());
1272
+ const results = [];
1273
+ for (let i = 0; i < entries.length; i += SQS_BATCH_LIMIT) {
1274
+ const chunk = entries.slice(i, i + SQS_BATCH_LIMIT);
1275
+ results.push(await this.client.send(new clientSqs.DeleteMessageBatchCommand({ ...input, Entries: chunk })));
1276
+ }
1277
+ return results;
1278
+ }
1279
+ }
1955
1280
 
1956
1281
  /**
1957
1282
  * Fields safe to log at INFO level for `putParameter`. Omits `Value` (the
1958
- * parameter content itself). `POWERTOOLS_LOG_LEVEL=DEBUG` unlocks the full
1959
- * input.
1283
+ * parameter content itself).
1960
1284
  */
1961
- var PUT_PARAMETER_SAFE_FIELDS = [
1285
+ const PUT_PARAMETER_SAFE_FIELDS = [
1962
1286
  'Name',
1963
1287
  'Type',
1964
1288
  'Description',
@@ -1976,23 +1300,28 @@ var PUT_PARAMETER_SAFE_FIELDS = [
1976
1300
  * `WithDecryption` — callers needing plaintext should use `SSMClient`
1977
1301
  * directly.
1978
1302
  *
1303
+ * Where a method's input carries payloads, secret material or PII, the INFO
1304
+ * log line omits them; the verbose levels (`POWERTOOLS_LOG_LEVEL=DEBUG` or
1305
+ * `TRACE`) log full SDK inputs.
1306
+ *
1979
1307
  * Write operations (`putParameter`, `deleteParameter`) are exposed for
1980
1308
  * convenience but should be used with care: parameter lifecycle is usually
1981
1309
  * managed by IaC (CDK / Terraform). Prefer IaC for anything that exists at
1982
1310
  * deploy time; reserve runtime writes for values that genuinely need to
1983
1311
  * mutate within the application.
1984
1312
  */
1985
- var SSMService = /** @class */ (function () {
1313
+ class SSMService {
1314
+ client;
1315
+ logger;
1986
1316
  /**
1987
1317
  * @param opts.logger - Optional Powertools logger. Defaults to `new Logger()`,
1988
1318
  * which picks up `POWERTOOLS_SERVICE_NAME` from the environment.
1989
1319
  * @param opts.client - Optional pre-configured `SSMClient`. When supplied,
1990
1320
  * the wrapper does not apply X-Ray instrumentation.
1991
1321
  */
1992
- function SSMService(opts) {
1993
- var _a, _b;
1994
- this.client = (_a = opts === null || opts === void 0 ? void 0 : opts.client) !== null && _a !== void 0 ? _a : xray.captureAWSv3Client(new clientSsm.SSMClient());
1995
- this.logger = (_b = opts === null || opts === void 0 ? void 0 : opts.logger) !== null && _b !== void 0 ? _b : new logger.Logger();
1322
+ constructor(opts) {
1323
+ this.client = opts?.client ?? xray.captureAWSv3Client(new clientSsm.SSMClient());
1324
+ this.logger = opts?.logger ?? new logger.Logger();
1996
1325
  }
1997
1326
  /**
1998
1327
  * Fetch a single SSM parameter's value.
@@ -2000,22 +1329,11 @@ var SSMService = /** @class */ (function () {
2000
1329
  * @returns The parameter value, or `undefined` if the parameter has no
2001
1330
  * value set.
2002
1331
  */
2003
- SSMService.prototype.getParameter = function (name) {
2004
- return __awaiter(this, void 0, void 0, function () {
2005
- var response;
2006
- var _a;
2007
- return __generator(this, function (_b) {
2008
- switch (_b.label) {
2009
- case 0:
2010
- this.logger.info('Fetching SSM parameter', { input: { name: name } });
2011
- return [4 /*yield*/, this.client.send(new clientSsm.GetParameterCommand({ Name: name, WithDecryption: true }))];
2012
- case 1:
2013
- response = _b.sent();
2014
- return [2 /*return*/, (_a = response.Parameter) === null || _a === void 0 ? void 0 : _a.Value];
2015
- }
2016
- });
2017
- });
2018
- };
1332
+ async getParameter(name) {
1333
+ this.logger.info('Fetching SSM parameter', { input: { name } });
1334
+ const response = await this.client.send(new clientSsm.GetParameterCommand({ Name: name, WithDecryption: true }));
1335
+ return response.Parameter?.Value;
1336
+ }
2019
1337
  /**
2020
1338
  * Fetch multiple SSM parameters in a single request. Callers supply an
2021
1339
  * alias-to-path record, and the returned record is keyed by the same
@@ -2035,36 +1353,23 @@ var SSMService = /** @class */ (function () {
2035
1353
  * parameter's value, or `undefined` when the parameter is missing or has
2036
1354
  * no value.
2037
1355
  */
2038
- SSMService.prototype.getParameters = function (aliases) {
2039
- return __awaiter(this, void 0, void 0, function () {
2040
- var response, byPath, _i, _a, parameter, result, _b, _c, alias;
2041
- var _d;
2042
- return __generator(this, function (_e) {
2043
- switch (_e.label) {
2044
- case 0:
2045
- this.logger.info('Fetching SSM parameters', { input: { aliases: aliases } });
2046
- return [4 /*yield*/, this.client.send(new clientSsm.GetParametersCommand({
2047
- Names: Object.values(aliases),
2048
- WithDecryption: true,
2049
- }))];
2050
- case 1:
2051
- response = _e.sent();
2052
- byPath = new Map();
2053
- for (_i = 0, _a = (_d = response.Parameters) !== null && _d !== void 0 ? _d : []; _i < _a.length; _i++) {
2054
- parameter = _a[_i];
2055
- if (parameter.Name !== undefined)
2056
- byPath.set(parameter.Name, parameter.Value);
2057
- }
2058
- result = {};
2059
- for (_b = 0, _c = Object.keys(aliases); _b < _c.length; _b++) {
2060
- alias = _c[_b];
2061
- result[alias] = byPath.get(aliases[alias]);
2062
- }
2063
- return [2 /*return*/, result];
2064
- }
2065
- });
2066
- });
2067
- };
1356
+ async getParameters(aliases) {
1357
+ this.logger.info('Fetching SSM parameters', { input: { aliases } });
1358
+ const response = await this.client.send(new clientSsm.GetParametersCommand({
1359
+ Names: Object.values(aliases),
1360
+ WithDecryption: true,
1361
+ }));
1362
+ const byPath = new Map();
1363
+ for (const parameter of response.Parameters ?? []) {
1364
+ if (parameter.Name !== undefined)
1365
+ byPath.set(parameter.Name, parameter.Value);
1366
+ }
1367
+ const result = {};
1368
+ for (const alias of Object.keys(aliases)) {
1369
+ result[alias] = byPath.get(aliases[alias]);
1370
+ }
1371
+ return result;
1372
+ }
2068
1373
  /**
2069
1374
  * Create or update an SSM parameter. The log line omits `Value` to avoid
2070
1375
  * leaking secret material.
@@ -2072,36 +1377,22 @@ var SSMService = /** @class */ (function () {
2072
1377
  * Prefer IaC (CDK / Terraform) for parameter lifecycle — use this for
2073
1378
  * runtime values only.
2074
1379
  */
2075
- SSMService.prototype.putParameter = function (input) {
2076
- return __awaiter(this, void 0, void 0, function () {
2077
- return __generator(this, function (_a) {
2078
- this.logger.info('Putting SSM parameter', {
2079
- input: filterFieldsForLogLevel(this.logger, input, PUT_PARAMETER_SAFE_FIELDS),
2080
- });
2081
- return [2 /*return*/, this.client.send(new clientSsm.PutParameterCommand(input))];
2082
- });
1380
+ async putParameter(input) {
1381
+ this.logger.info('Putting SSM parameter', {
1382
+ input: filterFieldsForLogLevel(this.logger, input, PUT_PARAMETER_SAFE_FIELDS),
2083
1383
  });
2084
- };
1384
+ return this.client.send(new clientSsm.PutParameterCommand(input));
1385
+ }
2085
1386
  /**
2086
1387
  * Delete an SSM parameter by name.
2087
1388
  *
2088
1389
  * Prefer IaC (CDK / Terraform) for parameter lifecycle — use this for
2089
1390
  * runtime cleanup only.
2090
1391
  */
2091
- SSMService.prototype.deleteParameter = function (name) {
2092
- return __awaiter(this, void 0, void 0, function () {
2093
- return __generator(this, function (_a) {
2094
- switch (_a.label) {
2095
- case 0:
2096
- this.logger.info('Deleting SSM parameter', { input: { name: name } });
2097
- return [4 /*yield*/, this.client.send(new clientSsm.DeleteParameterCommand({ Name: name }))];
2098
- case 1:
2099
- _a.sent();
2100
- return [2 /*return*/];
2101
- }
2102
- });
2103
- });
2104
- };
1392
+ async deleteParameter(name) {
1393
+ this.logger.info('Deleting SSM parameter', { input: { name } });
1394
+ await this.client.send(new clientSsm.DeleteParameterCommand({ Name: name }));
1395
+ }
2105
1396
  /**
2106
1397
  * Fetch all parameters under an SSM hierarchy path, auto-paginating across
2107
1398
  * all pages. `Recursive` defaults to `true` (overriding the AWS SDK
@@ -2113,60 +1404,19 @@ var SSMService = /** @class */ (function () {
2113
1404
  * @returns The full `Parameter` objects (including `Version`,
2114
1405
  * `LastModifiedDate`, etc.).
2115
1406
  */
2116
- SSMService.prototype.getParametersByPath = function (path, opts) {
2117
- return __awaiter(this, void 0, void 0, function () {
2118
- var recursive, paginator, parameters, _a, paginator_1, paginator_1_1, page, e_1_1;
2119
- var _b, e_1, _c, _d;
2120
- var _e, _f;
2121
- return __generator(this, function (_g) {
2122
- switch (_g.label) {
2123
- case 0:
2124
- recursive = (_e = opts === null || opts === void 0 ? void 0 : opts.recursive) !== null && _e !== void 0 ? _e : true;
2125
- this.logger.info('Fetching SSM parameters by path', {
2126
- input: { path: path, recursive: recursive },
2127
- });
2128
- paginator = clientSsm.paginateGetParametersByPath({ client: this.client }, { Path: path, Recursive: recursive, WithDecryption: true });
2129
- parameters = [];
2130
- _g.label = 1;
2131
- case 1:
2132
- _g.trys.push([1, 6, 7, 12]);
2133
- _a = true, paginator_1 = __asyncValues(paginator);
2134
- _g.label = 2;
2135
- case 2: return [4 /*yield*/, paginator_1.next()];
2136
- case 3:
2137
- if (!(paginator_1_1 = _g.sent(), _b = paginator_1_1.done, !_b)) return [3 /*break*/, 5];
2138
- _d = paginator_1_1.value;
2139
- _a = false;
2140
- page = _d;
2141
- parameters.push.apply(parameters, ((_f = page.Parameters) !== null && _f !== void 0 ? _f : []));
2142
- _g.label = 4;
2143
- case 4:
2144
- _a = true;
2145
- return [3 /*break*/, 2];
2146
- case 5: return [3 /*break*/, 12];
2147
- case 6:
2148
- e_1_1 = _g.sent();
2149
- e_1 = { error: e_1_1 };
2150
- return [3 /*break*/, 12];
2151
- case 7:
2152
- _g.trys.push([7, , 10, 11]);
2153
- if (!(!_a && !_b && (_c = paginator_1.return))) return [3 /*break*/, 9];
2154
- return [4 /*yield*/, _c.call(paginator_1)];
2155
- case 8:
2156
- _g.sent();
2157
- _g.label = 9;
2158
- case 9: return [3 /*break*/, 11];
2159
- case 10:
2160
- if (e_1) throw e_1.error;
2161
- return [7 /*endfinally*/];
2162
- case 11: return [7 /*endfinally*/];
2163
- case 12: return [2 /*return*/, parameters];
2164
- }
2165
- });
1407
+ async getParametersByPath(path, opts) {
1408
+ const recursive = opts?.recursive ?? true;
1409
+ this.logger.info('Fetching SSM parameters by path', {
1410
+ input: { path, recursive },
2166
1411
  });
2167
- };
2168
- return SSMService;
2169
- }());
1412
+ const paginator = clientSsm.paginateGetParametersByPath({ client: this.client }, { Path: path, Recursive: recursive, WithDecryption: true });
1413
+ const parameters = [];
1414
+ for await (const page of paginator) {
1415
+ parameters.push(...(page.Parameters ?? []));
1416
+ }
1417
+ return parameters;
1418
+ }
1419
+ }
2170
1420
 
2171
1421
  exports.DynamoDBService = DynamoDBService;
2172
1422
  exports.S3Service = S3Service;