@aligent/aws-wrappers 0.3.0 → 0.4.1

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