@aligent/aws-wrappers 0.5.6 → 0.5.8

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.
Files changed (49) hide show
  1. package/README.md +21 -4
  2. package/cjs/index.cjs +192 -152
  3. package/cjs/package.json +14 -14
  4. package/cjs/src/dynamodb/dynamodb.d.ts.map +1 -1
  5. package/cjs/src/index.d.ts +1 -0
  6. package/cjs/src/index.d.ts.map +1 -1
  7. package/cjs/src/s3/s3.d.ts +26 -4
  8. package/cjs/src/s3/s3.d.ts.map +1 -1
  9. package/cjs/src/scheduler/scheduler.d.ts.map +1 -1
  10. package/cjs/src/sns/sns.d.ts +7 -0
  11. package/cjs/src/sns/sns.d.ts.map +1 -1
  12. package/cjs/src/sqs/sqs.d.ts +0 -7
  13. package/cjs/src/sqs/sqs.d.ts.map +1 -1
  14. package/cjs/src/util/batch-operation-error.d.ts +45 -5
  15. package/cjs/src/util/batch-operation-error.d.ts.map +1 -1
  16. package/cjs/src/util/redact.d.ts +17 -18
  17. package/cjs/src/util/redact.d.ts.map +1 -1
  18. package/docs/index/classes/APIGatewayService.md +6 -6
  19. package/docs/index/classes/APIGatewayV2Service.md +5 -5
  20. package/docs/index/classes/BatchOperationError.md +9 -6
  21. package/docs/index/classes/DynamoDBService.md +34 -12
  22. package/docs/index/classes/S3Service.md +42 -19
  23. package/docs/index/classes/SNSService.md +10 -4
  24. package/docs/index/classes/SQSService.md +7 -7
  25. package/docs/index/classes/SSMService.md +9 -7
  26. package/docs/index/classes/SchedulerService.md +11 -11
  27. package/docs/index/classes/SecretsManagerService.md +10 -8
  28. package/docs/index/classes/StepFunctionsService.md +6 -6
  29. package/docs/index/interfaces/BatchFailedEntry.md +5 -5
  30. package/docs/index/interfaces/EmptyBucketPageResult.md +23 -0
  31. package/docs/index/modules.md +1 -0
  32. package/docs/testing/testing/functions/createMockService.md +5 -1
  33. package/esm/index.mjs +192 -152
  34. package/esm/package.json +14 -14
  35. package/esm/src/dynamodb/dynamodb.d.ts.map +1 -1
  36. package/esm/src/index.d.ts +1 -0
  37. package/esm/src/index.d.ts.map +1 -1
  38. package/esm/src/s3/s3.d.ts +26 -4
  39. package/esm/src/s3/s3.d.ts.map +1 -1
  40. package/esm/src/scheduler/scheduler.d.ts.map +1 -1
  41. package/esm/src/sns/sns.d.ts +7 -0
  42. package/esm/src/sns/sns.d.ts.map +1 -1
  43. package/esm/src/sqs/sqs.d.ts +0 -7
  44. package/esm/src/sqs/sqs.d.ts.map +1 -1
  45. package/esm/src/util/batch-operation-error.d.ts +45 -5
  46. package/esm/src/util/batch-operation-error.d.ts.map +1 -1
  47. package/esm/src/util/redact.d.ts +17 -18
  48. package/esm/src/util/redact.d.ts.map +1 -1
  49. package/package.json +14 -14
package/esm/index.mjs CHANGED
@@ -142,38 +142,22 @@ class APIGatewayService {
142
142
  }
143
143
 
144
144
  /**
145
- * Whether the logger is verbose enough that full SDK inputs — payloads, secret
146
- * material and PII — may be written to the log.
147
- *
148
- * **This is the only place in the package that reads the log level.** Never
149
- * compare `logger.getLevelName()` yourself: Powertools orders `TRACE` as *more*
150
- * verbose than `DEBUG` (thresholds 6 and 8), so the obvious
151
- * `getLevelName() === 'DEBUG'` check silently redacts at the most verbose level
152
- * available. Route every disclosure decision through this predicate instead.
145
+ * Whether the logger is verbose enough that full SDK inputs may be written to
146
+ * the log. The unlock rule is documented on {@link redactInput}.
153
147
  */
154
148
  function shouldLogFullInput(logger) {
155
149
  return LogLevelThreshold[logger.getLevelName()] <= LogLevelThreshold.DEBUG;
156
150
  }
157
- /**
158
- * Return a log-safe projection of `input` based on the logger's configured level.
159
- *
160
- * At the verbose levels — see {@link shouldLogFullInput} — the full input is
161
- * returned unchanged: operators who asked for that verbosity have explicitly
162
- * opted into seeing everything, including payloads, secret material and PII.
163
- *
164
- * At any other level, only the fields listed in `safeFields` are included.
165
- * Missing fields are silently skipped — the result type narrows to
166
- * `Pick<T, K>` accordingly.
167
- *
168
- * Used across the package so that the "what's safe to log at INFO" decision
169
- * lives in one place. See `packages/aws-wrappers/CLAUDE.md` ("Logging") for
170
- * the design rationale and conventions on building the safe-field lists.
171
- */
172
- function filterFieldsForLogLevel(logger, input, safeFields) {
151
+ function redactInput(logger, input, project) {
173
152
  if (shouldLogFullInput(logger))
174
153
  return input;
154
+ if (typeof project === 'function')
155
+ return project(input);
156
+ return pickKeys(input, project);
157
+ }
158
+ function pickKeys(input, keys) {
175
159
  const out = {};
176
- for (const key of safeFields) {
160
+ for (const key of keys) {
177
161
  if (key in input)
178
162
  out[key] = input[key];
179
163
  }
@@ -184,6 +168,14 @@ const BATCH_WRITE_MAX_ATTEMPTS = 5;
184
168
  const BATCH_WRITE_BASE_DELAY_MS = 200;
185
169
  const BATCH_GET_MAX_ATTEMPTS = 5;
186
170
  const BATCH_GET_BASE_DELAY_MS = 200;
171
+ /**
172
+ * Safe log shape for the batch methods. `RequestItems` is keyed by table name
173
+ * with the payload (`Keys`, `Item`) nested inside each value, so it can't be
174
+ * an allowlisted field and is reduced to the table names instead.
175
+ */
176
+ function summariseTables(input) {
177
+ return { tables: Object.keys(input.RequestItems ?? {}) };
178
+ }
187
179
  /**
188
180
  * Fields safe to log at INFO. Omits `Key` (may carry customer IDs / tenant IDs).
189
181
  */
@@ -312,7 +304,7 @@ class DynamoDBService {
312
304
  */
313
305
  async getItem(input) {
314
306
  this.logger.info('Getting DynamoDB item', {
315
- input: filterFieldsForLogLevel(this.logger, input, GET_ITEM_SAFE_FIELDS),
307
+ input: redactInput(this.logger, input, GET_ITEM_SAFE_FIELDS),
316
308
  });
317
309
  const response = await this.client.send(new GetCommand(input));
318
310
  return response.Item;
@@ -324,7 +316,7 @@ class DynamoDBService {
324
316
  */
325
317
  async putItem(input) {
326
318
  this.logger.info('Putting DynamoDB item', {
327
- input: filterFieldsForLogLevel(this.logger, input, PUT_ITEM_SAFE_FIELDS),
319
+ input: redactInput(this.logger, input, PUT_ITEM_SAFE_FIELDS),
328
320
  });
329
321
  return this.client.send(new PutCommand(input));
330
322
  }
@@ -340,7 +332,7 @@ class DynamoDBService {
340
332
  */
341
333
  async updateItem(input) {
342
334
  this.logger.info('Updating DynamoDB item', {
343
- input: filterFieldsForLogLevel(this.logger, input, UPDATE_ITEM_SAFE_FIELDS),
335
+ input: redactInput(this.logger, input, UPDATE_ITEM_SAFE_FIELDS),
344
336
  });
345
337
  const response = await this.client.send(new UpdateCommand(input));
346
338
  return response;
@@ -353,7 +345,7 @@ class DynamoDBService {
353
345
  */
354
346
  async deleteItem(input) {
355
347
  this.logger.info('Deleting DynamoDB item', {
356
- input: filterFieldsForLogLevel(this.logger, input, DELETE_ITEM_SAFE_FIELDS),
348
+ input: redactInput(this.logger, input, DELETE_ITEM_SAFE_FIELDS),
357
349
  });
358
350
  const response = await this.client.send(new DeleteCommand(input));
359
351
  return response;
@@ -366,7 +358,7 @@ class DynamoDBService {
366
358
  */
367
359
  async query(input) {
368
360
  this.logger.info('Querying DynamoDB', {
369
- input: filterFieldsForLogLevel(this.logger, input, QUERY_SAFE_FIELDS),
361
+ input: redactInput(this.logger, input, QUERY_SAFE_FIELDS),
370
362
  });
371
363
  const response = await this.client.send(new QueryCommand(input));
372
364
  return response;
@@ -392,7 +384,7 @@ class DynamoDBService {
392
384
  */
393
385
  async scan(input) {
394
386
  this.logger.info('Scanning DynamoDB', {
395
- input: filterFieldsForLogLevel(this.logger, input, SCAN_SAFE_FIELDS),
387
+ input: redactInput(this.logger, input, SCAN_SAFE_FIELDS),
396
388
  });
397
389
  const response = await this.client.send(new ScanCommand(input));
398
390
  return response;
@@ -409,13 +401,8 @@ class DynamoDBService {
409
401
  * Callers should narrow the result type at the call site.
410
402
  */
411
403
  async batchGet(input) {
412
- // Inline verbosity check rather than `filterFieldsForLogLevel` because
413
- // `RequestItems` is a `Record<tableName, KeysAndAttributes>` — the
414
- // payload (`Keys[]`) lives inside the value, not as a top-level key
415
- // the helper could pick or drop.
416
- const logFullInput = shouldLogFullInput(this.logger);
417
404
  this.logger.info('Batch getting DynamoDB items', {
418
- input: logFullInput ? input : { tables: Object.keys(input.RequestItems ?? {}) },
405
+ input: redactInput(this.logger, input, summariseTables),
419
406
  });
420
407
  let current = input;
421
408
  const mergedResponses = {};
@@ -444,13 +431,8 @@ class DynamoDBService {
444
431
  * items remain unprocessed after the final attempt.
445
432
  */
446
433
  async batchWrite(input) {
447
- // Inline verbosity check rather than `filterFieldsForLogLevel` because
448
- // `RequestItems` is a `Record<tableName, WriteRequest[]>` — the
449
- // payload (`PutRequest.Item` / `DeleteRequest.Key`) lives inside the
450
- // value, not as a top-level key the helper could pick or drop.
451
- const logFullInput = shouldLogFullInput(this.logger);
452
434
  this.logger.info('Batch writing DynamoDB items', {
453
- input: logFullInput ? input : { tables: Object.keys(input.RequestItems ?? {}) },
435
+ input: redactInput(this.logger, input, summariseTables),
454
436
  });
455
437
  let current = input;
456
438
  for (let attempt = 0; attempt < BATCH_WRITE_MAX_ATTEMPTS; attempt++) {
@@ -496,7 +478,7 @@ class DynamoDBService {
496
478
  */
497
479
  async *paginateItems(input) {
498
480
  this.logger.info('Paginating DynamoDB query', {
499
- input: filterFieldsForLogLevel(this.logger, input, QUERY_SAFE_FIELDS),
481
+ input: redactInput(this.logger, input, QUERY_SAFE_FIELDS),
500
482
  });
501
483
  const paginator = paginateQuery({ client: this.client }, input);
502
484
  for await (const page of paginator) {
@@ -517,7 +499,7 @@ class DynamoDBService {
517
499
  */
518
500
  async *paginateScan(input) {
519
501
  this.logger.info('Paginating DynamoDB scan', {
520
- input: filterFieldsForLogLevel(this.logger, input, SCAN_SAFE_FIELDS),
502
+ input: redactInput(this.logger, input, SCAN_SAFE_FIELDS),
521
503
  });
522
504
  const paginator = paginateScan({ client: this.client }, input);
523
505
  for await (const page of paginator) {
@@ -529,6 +511,81 @@ class DynamoDBService {
529
511
  }
530
512
  }
531
513
 
514
+ /**
515
+ * Thrown by the batch methods once every chunk has been sent and at least one
516
+ * entry was rejected.
517
+ *
518
+ * `results` holds the raw SDK output of every chunk, so the outputs of the
519
+ * entries that succeeded (message ids, sequence numbers) stay readable. The
520
+ * one exception is `S3.emptyBucket`, whose `results` are per-page deleted keys.
521
+ * `failed` is the normalised list of rejected entries across all chunks.
522
+ *
523
+ * Match on `name` rather than `instanceof` if both the CJS and ESM builds of
524
+ * this package may be loaded in one process.
525
+ */
526
+ class BatchOperationError extends Error {
527
+ results;
528
+ failed;
529
+ name = 'BatchOperationError';
530
+ constructor(results, failed) {
531
+ super(`Batch operation failed for ${failed.length} entries (${distinctCodes(failed).join(', ')})`);
532
+ this.results = results;
533
+ this.failed = failed;
534
+ }
535
+ }
536
+ /**
537
+ * SQS and SNS report rejected entries under `Failed` on an otherwise
538
+ * successful response, so a resolved chunk does not mean every entry was
539
+ * accepted. Returns `results` untouched when nothing failed; otherwise warns
540
+ * and throws a {@link BatchOperationError}.
541
+ *
542
+ * Only id, code and message are copied out — never the entry itself — so
543
+ * neither the error nor the warning can leak a payload.
544
+ */
545
+ function throwIfAnyFailed(logger, operation, results) {
546
+ const failed = results.flatMap(result => (result.Failed ?? []).map(({ Id, Code, Message }) => ({
547
+ id: Id,
548
+ code: Code,
549
+ message: Message,
550
+ })));
551
+ return throwIfAny(logger, operation, results, failed);
552
+ }
553
+ /**
554
+ * S3 reports undeleted keys under `Errors` on an otherwise successful
555
+ * `DeleteObjects` response. Same contract as {@link throwIfAnyFailed}; the
556
+ * key is carried as the failed entry's `id`, and `VersionId` is dropped.
557
+ */
558
+ function throwIfAnyDeleteErrors(logger, operation, results) {
559
+ const failed = results.flatMap(result => (result.Errors ?? []).map(({ Key, Code, Message }) => ({
560
+ id: Key,
561
+ code: Code,
562
+ message: Message,
563
+ })));
564
+ return throwIfAny(logger, operation, results, failed);
565
+ }
566
+ /**
567
+ * Throws a {@link BatchOperationError} for operations whose `results` aren't a
568
+ * plain list of SDK outputs, such as `S3.emptyBucket`. Returns `results`
569
+ * untouched when `failed` is empty.
570
+ */
571
+ function throwIfAny(logger, operation, results, failed) {
572
+ if (failed.length === 0)
573
+ return results;
574
+ logger.warn(`${operation} had rejected entries`, {
575
+ failedCount: failed.length,
576
+ codes: distinctCodes(failed),
577
+ });
578
+ throw new BatchOperationError(results, failed);
579
+ }
580
+ /**
581
+ * Distinct error codes in first-seen order, for the error message and the
582
+ * warning log line.
583
+ */
584
+ function distinctCodes(failed) {
585
+ const codes = failed.flatMap(entry => (entry.code === undefined ? [] : [entry.code]));
586
+ return [...new Set(codes)];
587
+ }
588
+
532
589
  /**
533
590
  * Split a list into consecutive chunks of at most `size` items, mirroring the
534
591
  * per-request caps the AWS APIs enforce on batch operations.
@@ -592,7 +649,7 @@ class S3Service {
592
649
  */
593
650
  async putObject(input) {
594
651
  this.logger.info('Putting S3 object', {
595
- input: filterFieldsForLogLevel(this.logger, input, PUT_OBJECT_SAFE_FIELDS),
652
+ input: redactInput(this.logger, input, PUT_OBJECT_SAFE_FIELDS),
596
653
  });
597
654
  return this.client.send(new PutObjectCommand(input));
598
655
  }
@@ -607,7 +664,7 @@ class S3Service {
607
664
  */
608
665
  async putJsonObject(input) {
609
666
  this.logger.info('Putting S3 JSON object', {
610
- input: filterFieldsForLogLevel(this.logger, input, PUT_JSON_OBJECT_SAFE_FIELDS),
667
+ input: redactInput(this.logger, input, PUT_JSON_OBJECT_SAFE_FIELDS),
611
668
  });
612
669
  return this.client.send(new PutObjectCommand({
613
670
  Bucket: input.Bucket,
@@ -733,14 +790,19 @@ class S3Service {
733
790
  * Delete multiple objects from S3, auto-chunking the request into batches
734
791
  * of 1000 keys (the S3-enforced DeleteObjects limit). Returns one output
735
792
  * per chunk.
793
+ *
794
+ * Every chunk is sent before the outcome is judged. If S3 reported a
795
+ * per-key delete error, a {@link BatchOperationError} is then thrown
796
+ * carrying the per-chunk results and the failed keys. Request-level SDK
797
+ * exceptions (throttling, access denied) propagate unchanged and
798
+ * immediately, so earlier chunks may already have been deleted.
736
799
  */
737
800
  async deleteObjects(bucket, keys) {
738
- // Inline verbosity check rather than `filterFieldsForLogLevel` because the
739
- // safe log shape includes the computed `keyCount`, which isn't a key
740
- // on any SDK input type.
741
- const logFullInput = shouldLogFullInput(this.logger);
742
801
  this.logger.info('Deleting S3 objects', {
743
- input: logFullInput ? { bucket, keys } : { bucket, keyCount: keys.length },
802
+ input: redactInput(this.logger, { bucket, keys }, input => ({
803
+ bucket: input.bucket,
804
+ keyCount: input.keys.length,
805
+ })),
744
806
  });
745
807
  const results = [];
746
808
  for (const batch of chunk(keys, DELETE_OBJECTS_BATCH_LIMIT)) {
@@ -749,13 +811,20 @@ class S3Service {
749
811
  Delete: { Objects: batch.map(Key => ({ Key })) },
750
812
  })));
751
813
  }
752
- return results;
814
+ return throwIfAnyDeleteErrors(this.logger, 'S3 deleteObjects', results);
753
815
  }
754
816
  /**
755
817
  * Delete every object in an **unversioned** bucket. Streams the listing
756
- * page-by-page and delegates each page's deletion to `deleteObjects`, so
757
- * peak memory stays bounded by one page (~1000 keys) regardless of bucket
758
- * size.
818
+ * page-by-page and delegates each page's deletion to `deleteObjects`, so no
819
+ * more than one page (~1000 keys) of SDK responses is held at a time. The
820
+ * only thing that grows with the bucket is the list of deleted keys this
821
+ * method returns.
822
+ *
823
+ * A page with per-key delete errors does not stop the run: every page is
824
+ * attempted, then one {@link BatchOperationError} is thrown carrying every
825
+ * failed key in `failed` and, per page, the keys that were deleted in
826
+ * `results`. Request-level SDK exceptions propagate unchanged and
827
+ * immediately, so earlier pages may already have been deleted.
759
828
  *
760
829
  * **Versioned buckets are out of scope.** This paginates `ListObjectsV2`,
761
830
  * which reports only current object versions — never noncurrent versions or
@@ -766,20 +835,39 @@ class S3Service {
766
835
  * versioned bucket requires `ListObjectVersions` and per-version deletes;
767
836
  * use `S3Client` directly for that.
768
837
  *
769
- * @returns The keys this call issued deletes for.
838
+ * @returns The keys that were deleted.
839
+ * @throws {BatchOperationError} If S3 could not delete one or more keys.
770
840
  */
771
841
  async emptyBucket(bucket) {
772
842
  this.logger.info('Emptying S3 bucket', { input: { bucket } });
773
843
  const paginator = paginateListObjectsV2({ client: this.client }, { Bucket: bucket });
774
- const deletedKeys = [];
844
+ const pages = [];
845
+ const failed = [];
775
846
  for await (const page of paginator) {
776
847
  const keys = (page.Contents ?? []).flatMap(o => (o.Key ? [o.Key] : []));
777
848
  if (keys.length === 0)
778
849
  continue;
850
+ const outcome = await this.deletePage(bucket, keys);
851
+ pages.push({ deletedKeys: outcome.deletedKeys });
852
+ failed.push(...outcome.failed);
853
+ }
854
+ throwIfAny(this.logger, 'S3 emptyBucket', pages, failed);
855
+ return pages.flatMap(page => page.deletedKeys);
856
+ }
857
+ async deletePage(bucket, keys) {
858
+ try {
779
859
  await this.deleteObjects(bucket, keys);
780
- deletedKeys.push(...keys);
860
+ return { deletedKeys: keys, failed: [] };
861
+ }
862
+ catch (error) {
863
+ if (!(error instanceof BatchOperationError))
864
+ throw error;
865
+ const failedKeys = new Set(error.failed.map(entry => entry.id));
866
+ return {
867
+ deletedKeys: keys.filter(key => !failedKeys.has(key)),
868
+ failed: error.failed,
869
+ };
781
870
  }
782
- return deletedKeys;
783
871
  }
784
872
  }
785
873
 
@@ -789,21 +877,14 @@ class S3Service {
789
877
  * PII (customer IDs, order contents, etc.), the same risk profile as SFN's
790
878
  * execution `input`.
791
879
  *
792
- * This can't go through the package's usual `filterFieldsForLogLevel` helper:
793
- * that helper picks **top-level** keys only, and the sensitive field is nested
794
- * one level down inside `Target`. Allowlisting `Target` would leak `Input`;
795
- * omitting `Target` would lose operationally-useful fields (`Arn`, `RoleArn`,
796
- * `RetryPolicy`, `DeadLetterConfig`, the target-type params). So this is a
797
- * bespoke case: keep every top-level field and shallow-strip only
798
- * `Target.Input`.
799
- *
800
- * At the verbose levels — see {@link shouldLogFullInput} — the input is
801
- * returned unchanged: operators who asked for that verbosity have opted into
802
- * seeing payloads and PII.
880
+ * This can't be a key allowlist for {@link redactInput}: an allowlist picks
881
+ * **top-level** keys only, and the sensitive field is nested one level down
882
+ * inside `Target`. Allowlisting `Target` would leak `Input`; omitting `Target`
883
+ * would lose operationally-useful fields (`Arn`, `RoleArn`, `RetryPolicy`,
884
+ * `DeadLetterConfig`, the target-type params). So this is a projection
885
+ * function: keep every top-level field and shallow-strip only `Target.Input`.
803
886
  */
804
- function redactTargetInput(logger, input) {
805
- if (shouldLogFullInput(logger))
806
- return input;
887
+ function stripTargetInput(input) {
807
888
  if (input.Target?.Input === undefined)
808
889
  return input;
809
890
  const { Input: _input, ...safeTarget } = input.Target;
@@ -843,7 +924,9 @@ class SchedulerService {
843
924
  * target payload, a PII carrier).
844
925
  */
845
926
  async createSchedule(input) {
846
- this.logger.info('Creating schedule', { input: redactTargetInput(this.logger, input) });
927
+ this.logger.info('Creating schedule', {
928
+ input: redactInput(this.logger, input, stripTargetInput),
929
+ });
847
930
  return this.client.send(new CreateScheduleCommand(input));
848
931
  }
849
932
  /**
@@ -867,7 +950,9 @@ class SchedulerService {
867
950
  * At INFO the log line omits `Target.Input`.
868
951
  */
869
952
  async updateSchedule(input) {
870
- this.logger.info('Updating schedule', { input: redactTargetInput(this.logger, input) });
953
+ this.logger.info('Updating schedule', {
954
+ input: redactInput(this.logger, input, stripTargetInput),
955
+ });
871
956
  return this.client.send(new UpdateScheduleCommand(input));
872
957
  }
873
958
  /**
@@ -1017,7 +1102,7 @@ class SecretsManagerService {
1017
1102
  */
1018
1103
  async createSecret(input) {
1019
1104
  this.logger.info('Creating secret', {
1020
- input: filterFieldsForLogLevel(this.logger, input, CREATE_SECRET_SAFE_FIELDS),
1105
+ input: redactInput(this.logger, input, CREATE_SECRET_SAFE_FIELDS),
1021
1106
  });
1022
1107
  return this.client.send(new CreateSecretCommand(input));
1023
1108
  }
@@ -1030,7 +1115,7 @@ class SecretsManagerService {
1030
1115
  */
1031
1116
  async updateSecret(input) {
1032
1117
  this.logger.info('Updating secret', {
1033
- input: filterFieldsForLogLevel(this.logger, input, UPDATE_SECRET_SAFE_FIELDS),
1118
+ input: redactInput(this.logger, input, UPDATE_SECRET_SAFE_FIELDS),
1034
1119
  });
1035
1120
  return this.client.send(new UpdateSecretCommand(input));
1036
1121
  }
@@ -1042,7 +1127,7 @@ class SecretsManagerService {
1042
1127
  */
1043
1128
  async putSecretValue(input) {
1044
1129
  this.logger.info('Putting secret value', {
1045
- input: filterFieldsForLogLevel(this.logger, input, PUT_SECRET_VALUE_SAFE_FIELDS),
1130
+ input: redactInput(this.logger, input, PUT_SECRET_VALUE_SAFE_FIELDS),
1046
1131
  });
1047
1132
  return this.client.send(new PutSecretValueCommand(input));
1048
1133
  }
@@ -1054,7 +1139,7 @@ class SecretsManagerService {
1054
1139
  */
1055
1140
  async deleteSecret(input) {
1056
1141
  this.logger.info('Deleting secret', {
1057
- input: filterFieldsForLogLevel(this.logger, input, DELETE_SECRET_SAFE_FIELDS),
1142
+ input: redactInput(this.logger, input, DELETE_SECRET_SAFE_FIELDS),
1058
1143
  });
1059
1144
  return this.client.send(new DeleteSecretCommand(input));
1060
1145
  }
@@ -1113,7 +1198,7 @@ class StepFunctionsService {
1113
1198
  */
1114
1199
  async startExecution(input) {
1115
1200
  this.logger.info('Starting Step Functions execution', {
1116
- input: filterFieldsForLogLevel(this.logger, input, START_EXECUTION_SAFE_FIELDS),
1201
+ input: redactInput(this.logger, input, START_EXECUTION_SAFE_FIELDS),
1117
1202
  });
1118
1203
  return this.client.send(new StartExecutionCommand(input));
1119
1204
  }
@@ -1222,7 +1307,7 @@ class SNSService {
1222
1307
  const shouldTruncate = opts?.truncate ?? this.truncate;
1223
1308
  const effective = shouldTruncate ? this.applyTruncation(input) : input;
1224
1309
  this.logger.info('Publishing SNS message', {
1225
- input: filterFieldsForLogLevel(this.logger, effective, PUBLISH_SAFE_FIELDS),
1310
+ input: redactInput(this.logger, effective, PUBLISH_SAFE_FIELDS),
1226
1311
  });
1227
1312
  return this.client.send(new PublishCommand(effective));
1228
1313
  }
@@ -1260,16 +1345,22 @@ class SNSService {
1260
1345
  * PublishBatch at 10 entries per request, so this method auto-chunks
1261
1346
  * the caller's `PublishBatchRequestEntries` and sends one request per
1262
1347
  * chunk, returning the array of outputs.
1348
+ *
1349
+ * Every chunk is sent before the outcome is judged. If SNS rejected any
1350
+ * entry, a {@link BatchOperationError} is then thrown carrying the
1351
+ * per-chunk results and the failed entries. Request-level SDK exceptions
1352
+ * (throttling, access denied) propagate unchanged and immediately, so
1353
+ * earlier chunks may already have been published.
1354
+ *
1263
1355
  * @param input - PublishBatchCommandInput including TopicArn and entries.
1264
1356
  */
1265
1357
  async publishBatch(input) {
1266
1358
  const entries = input.PublishBatchRequestEntries ?? [];
1267
- // Inline verbosity check rather than `filterFieldsForLogLevel` because the
1268
- // safe log shape includes the computed `entryCount`, which isn't a key
1269
- // on `PublishBatchCommandInput`.
1270
- const logFullInput = shouldLogFullInput(this.logger);
1271
1359
  this.logger.info('Publishing SNS message batch', {
1272
- input: logFullInput ? input : { TopicArn: input.TopicArn, entryCount: entries.length },
1360
+ input: redactInput(this.logger, input, ({ TopicArn }) => ({
1361
+ TopicArn,
1362
+ entryCount: entries.length,
1363
+ })),
1273
1364
  });
1274
1365
  const results = [];
1275
1366
  for (const batch of chunk(entries, PUBLISH_BATCH_LIMIT)) {
@@ -1278,40 +1369,10 @@ class SNSService {
1278
1369
  PublishBatchRequestEntries: batch,
1279
1370
  })));
1280
1371
  }
1281
- return results;
1372
+ return throwIfAnyFailed(this.logger, 'SNS publishBatch', results);
1282
1373
  }
1283
1374
  }
1284
1375
 
1285
- /**
1286
- * Thrown by the batch methods once every chunk has been sent and at least one
1287
- * entry was rejected.
1288
- *
1289
- * `results` holds the raw SDK output of every chunk, so the outputs of the
1290
- * entries that succeeded (message ids, sequence numbers) stay readable.
1291
- * `failed` is the normalised list of rejected entries across all chunks.
1292
- *
1293
- * Match on `name` rather than `instanceof` if both the CJS and ESM builds of
1294
- * this package may be loaded in one process.
1295
- */
1296
- class BatchOperationError extends Error {
1297
- results;
1298
- failed;
1299
- name = 'BatchOperationError';
1300
- constructor(results, failed) {
1301
- super(`Batch operation failed for ${failed.length} entries (${distinctCodes(failed).join(', ')})`);
1302
- this.results = results;
1303
- this.failed = failed;
1304
- }
1305
- }
1306
- /**
1307
- * Distinct error codes in first-seen order, for the error message and the
1308
- * warning log line.
1309
- */
1310
- function distinctCodes(failed) {
1311
- const codes = failed.flatMap(entry => (entry.code === undefined ? [] : [entry.code]));
1312
- return [...new Set(codes)];
1313
- }
1314
-
1315
1376
  const SQS_BATCH_LIMIT = 10;
1316
1377
  const SQS_MESSAGE_BODY_MAX_BYTES = 256 * 1024;
1317
1378
  /**
@@ -1324,6 +1385,13 @@ const SEND_MESSAGE_SAFE_FIELDS = [
1324
1385
  'MessageGroupId',
1325
1386
  'MessageDeduplicationId',
1326
1387
  ];
1388
+ /**
1389
+ * Safe log shape for the batch methods. The entries carry message bodies and
1390
+ * receipt handles, so they are reduced to a count.
1391
+ */
1392
+ function summariseEntries(input) {
1393
+ return { QueueUrl: input.QueueUrl, entryCount: input.Entries?.length ?? 0 };
1394
+ }
1327
1395
  /**
1328
1396
  * Wrapper around the AWS SQS client providing structured Powertools logging
1329
1397
  * and X-Ray tracing by default.
@@ -1361,7 +1429,7 @@ class SQSService {
1361
1429
  const shouldTruncate = opts?.truncate ?? this.truncate;
1362
1430
  const effective = shouldTruncate ? this.applyTruncation(input) : input;
1363
1431
  this.logger.info('Sending SQS message', {
1364
- input: filterFieldsForLogLevel(this.logger, effective, SEND_MESSAGE_SAFE_FIELDS),
1432
+ input: redactInput(this.logger, effective, SEND_MESSAGE_SAFE_FIELDS),
1365
1433
  });
1366
1434
  return this.client.send(new SendMessageCommand(effective));
1367
1435
  }
@@ -1405,26 +1473,6 @@ class SQSService {
1405
1473
  this.logger.info('Deleting SQS message', { input });
1406
1474
  return this.client.send(new DeleteMessageCommand(input));
1407
1475
  }
1408
- /**
1409
- * SQS reports rejected entries under `Failed` on an otherwise successful
1410
- * response, so a resolved chunk does not mean every entry was accepted.
1411
- * Only id, code and message are copied out — never the entry itself — so
1412
- * neither the error nor the warning can leak a payload.
1413
- */
1414
- throwIfAnyFailed(operation, results) {
1415
- const failed = results.flatMap(result => (result.Failed ?? []).map(({ Id, Code, Message }) => ({
1416
- id: Id,
1417
- code: Code,
1418
- message: Message,
1419
- })));
1420
- if (failed.length === 0)
1421
- return results;
1422
- this.logger.warn(`${operation} had rejected entries`, {
1423
- failedCount: failed.length,
1424
- codes: distinctCodes(failed),
1425
- });
1426
- throw new BatchOperationError(results, failed);
1427
- }
1428
1476
  /**
1429
1477
  * Send a batch of messages to an SQS queue. The SQS API caps
1430
1478
  * SendMessageBatch at 10 entries per request, so this method auto-chunks
@@ -1438,18 +1486,14 @@ class SQSService {
1438
1486
  */
1439
1487
  async sendMessageBatch(input) {
1440
1488
  const entries = input.Entries ?? [];
1441
- // Inline verbosity check rather than `filterFieldsForLogLevel` because the
1442
- // safe log shape includes the computed `entryCount`, which isn't a key
1443
- // on `SendMessageBatchCommandInput`.
1444
- const logFullInput = shouldLogFullInput(this.logger);
1445
1489
  this.logger.info('Sending SQS message batch', {
1446
- input: logFullInput ? input : { QueueUrl: input.QueueUrl, entryCount: entries.length },
1490
+ input: redactInput(this.logger, input, summariseEntries),
1447
1491
  });
1448
1492
  const results = [];
1449
1493
  for (const batch of chunk(entries, SQS_BATCH_LIMIT)) {
1450
1494
  results.push(await this.client.send(new SendMessageBatchCommand({ ...input, Entries: batch })));
1451
1495
  }
1452
- return this.throwIfAnyFailed('SQS sendMessageBatch', results);
1496
+ return throwIfAnyFailed(this.logger, 'SQS sendMessageBatch', results);
1453
1497
  }
1454
1498
  /**
1455
1499
  * Delete a batch of messages from an SQS queue. The SQS API caps
@@ -1465,18 +1509,14 @@ class SQSService {
1465
1509
  */
1466
1510
  async deleteMessageBatch(input) {
1467
1511
  const entries = input.Entries ?? [];
1468
- // Inline verbosity check rather than `filterFieldsForLogLevel` because the
1469
- // safe log shape includes the computed `entryCount`, which isn't a key
1470
- // on `DeleteMessageBatchCommandInput`.
1471
- const logFullInput = shouldLogFullInput(this.logger);
1472
1512
  this.logger.info('Deleting SQS message batch', {
1473
- input: logFullInput ? input : { QueueUrl: input.QueueUrl, entryCount: entries.length },
1513
+ input: redactInput(this.logger, input, summariseEntries),
1474
1514
  });
1475
1515
  const results = [];
1476
1516
  for (const batch of chunk(entries, SQS_BATCH_LIMIT)) {
1477
1517
  results.push(await this.client.send(new DeleteMessageBatchCommand({ ...input, Entries: batch })));
1478
1518
  }
1479
- return this.throwIfAnyFailed('SQS deleteMessageBatch', results);
1519
+ return throwIfAnyFailed(this.logger, 'SQS deleteMessageBatch', results);
1480
1520
  }
1481
1521
  }
1482
1522
 
@@ -1590,7 +1630,7 @@ class SSMService {
1590
1630
  */
1591
1631
  async putParameter(input) {
1592
1632
  this.logger.info('Putting SSM parameter', {
1593
- input: filterFieldsForLogLevel(this.logger, input, PUT_PARAMETER_SAFE_FIELDS),
1633
+ input: redactInput(this.logger, input, PUT_PARAMETER_SAFE_FIELDS),
1594
1634
  });
1595
1635
  return this.client.send(new PutParameterCommand(input));
1596
1636
  }
package/esm/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aligent/aws-wrappers",
3
- "version": "0.5.6",
3
+ "version": "0.5.8",
4
4
  "description": "Opinionated AWS SDK wrappers with Powertools logging and X-Ray tracing",
5
5
  "engines": {
6
6
  "node": ">=18"
@@ -43,19 +43,19 @@
43
43
  "directory": "packages/aws-wrappers"
44
44
  },
45
45
  "dependencies": {
46
- "@aws-lambda-powertools/logger": "^2.33.1",
47
- "@aws-sdk/client-api-gateway": "^3.1127.0",
48
- "@aws-sdk/client-apigatewayv2": "^3.1127.0",
49
- "@aws-sdk/client-dynamodb": "^3.1127.0",
50
- "@aws-sdk/client-s3": "^3.1127.0",
51
- "@aws-sdk/client-scheduler": "^3.1127.0",
52
- "@aws-sdk/client-secrets-manager": "^3.1127.0",
53
- "@aws-sdk/client-sfn": "^3.1127.0",
54
- "@aws-sdk/client-sns": "^3.1127.0",
55
- "@aws-sdk/client-sqs": "^3.1127.0",
56
- "@aws-sdk/client-ssm": "^3.1127.0",
57
- "@aws-sdk/lib-dynamodb": "^3.1127.0",
58
- "@aws-sdk/s3-request-presigner": "^3.1127.0",
46
+ "@aws-lambda-powertools/logger": "^2.36.0",
47
+ "@aws-sdk/client-api-gateway": "^3.1160.0",
48
+ "@aws-sdk/client-apigatewayv2": "^3.1160.0",
49
+ "@aws-sdk/client-dynamodb": "^3.1160.0",
50
+ "@aws-sdk/client-s3": "^3.1160.0",
51
+ "@aws-sdk/client-scheduler": "^3.1160.0",
52
+ "@aws-sdk/client-secrets-manager": "^3.1160.0",
53
+ "@aws-sdk/client-sfn": "^3.1160.0",
54
+ "@aws-sdk/client-sns": "^3.1160.0",
55
+ "@aws-sdk/client-sqs": "^3.1160.0",
56
+ "@aws-sdk/client-ssm": "^3.1160.0",
57
+ "@aws-sdk/lib-dynamodb": "^3.1160.0",
58
+ "@aws-sdk/s3-request-presigner": "^3.1160.0",
59
59
  "aws-xray-sdk-core": "^3.12.0"
60
60
  },
61
61
  "author": "Aligent",