@aligent/aws-wrappers 0.5.10 → 0.5.11

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 (56) hide show
  1. package/README.md +36 -9
  2. package/cjs/index.cjs +279 -125
  3. package/cjs/package.json +2 -2
  4. package/cjs/src/dynamodb/dynamodb.d.ts +23 -4
  5. package/cjs/src/dynamodb/dynamodb.d.ts.map +1 -1
  6. package/cjs/src/s3/s3.d.ts +6 -1
  7. package/cjs/src/s3/s3.d.ts.map +1 -1
  8. package/cjs/src/secrets-manager/secrets-manager.d.ts +3 -1
  9. package/cjs/src/secrets-manager/secrets-manager.d.ts.map +1 -1
  10. package/cjs/src/sns/sns.d.ts +8 -5
  11. package/cjs/src/sns/sns.d.ts.map +1 -1
  12. package/cjs/src/sqs/sqs.d.ts +7 -3
  13. package/cjs/src/sqs/sqs.d.ts.map +1 -1
  14. package/cjs/src/ssm/ssm.d.ts +3 -1
  15. package/cjs/src/ssm/ssm.d.ts.map +1 -1
  16. package/cjs/src/util/batch-operation-error.d.ts +19 -2
  17. package/cjs/src/util/batch-operation-error.d.ts.map +1 -1
  18. package/cjs/src/util/json.d.ts +14 -0
  19. package/cjs/src/util/json.d.ts.map +1 -0
  20. package/docs/index/classes/APIGatewayService.md +6 -6
  21. package/docs/index/classes/APIGatewayV2Service.md +5 -5
  22. package/docs/index/classes/BatchOperationError.md +15 -6
  23. package/docs/index/classes/DynamoDBService.md +39 -16
  24. package/docs/index/classes/EventBridgeService.md +3 -3
  25. package/docs/index/classes/LambdaFunctionError.md +7 -7
  26. package/docs/index/classes/LambdaService.md +3 -3
  27. package/docs/index/classes/S3Service.md +24 -16
  28. package/docs/index/classes/SESService.md +4 -4
  29. package/docs/index/classes/SNSService.md +12 -9
  30. package/docs/index/classes/SQSService.md +14 -10
  31. package/docs/index/classes/SSMService.md +10 -8
  32. package/docs/index/classes/SchedulerService.md +11 -11
  33. package/docs/index/classes/SecretsManagerService.md +11 -9
  34. package/docs/index/classes/StepFunctionsService.md +6 -6
  35. package/docs/index/interfaces/BatchFailedEntry.md +6 -5
  36. package/docs/index/interfaces/EmptyBucketPageResult.md +2 -2
  37. package/docs/testing/testing/functions/createMockService.md +1 -1
  38. package/esm/index.mjs +280 -126
  39. package/esm/package.json +2 -2
  40. package/esm/src/dynamodb/dynamodb.d.ts +23 -4
  41. package/esm/src/dynamodb/dynamodb.d.ts.map +1 -1
  42. package/esm/src/s3/s3.d.ts +6 -1
  43. package/esm/src/s3/s3.d.ts.map +1 -1
  44. package/esm/src/secrets-manager/secrets-manager.d.ts +3 -1
  45. package/esm/src/secrets-manager/secrets-manager.d.ts.map +1 -1
  46. package/esm/src/sns/sns.d.ts +8 -5
  47. package/esm/src/sns/sns.d.ts.map +1 -1
  48. package/esm/src/sqs/sqs.d.ts +7 -3
  49. package/esm/src/sqs/sqs.d.ts.map +1 -1
  50. package/esm/src/ssm/ssm.d.ts +3 -1
  51. package/esm/src/ssm/ssm.d.ts.map +1 -1
  52. package/esm/src/util/batch-operation-error.d.ts +19 -2
  53. package/esm/src/util/batch-operation-error.d.ts.map +1 -1
  54. package/esm/src/util/json.d.ts +14 -0
  55. package/esm/src/util/json.d.ts.map +1 -0
  56. package/package.json +2 -2
package/README.md CHANGED
@@ -8,7 +8,7 @@ Opinionated AWS SDK wrappers with Powertools logging and X-Ray tracing baked in.
8
8
  npm install @aligent/aws-wrappers
9
9
  ```
10
10
 
11
- Requires **Node 18 or later**. The package is compiled to ES2022 and ships native `class` declarations, so older runtimes fail at import time with a syntax error rather than degrading gracefully.
11
+ Requires **Node 20 or later**, the minimum the underlying `@aws-sdk/*` v3 clients support. The package is compiled to ES2022 and ships native `class` declarations, so older runtimes fail at import time with a syntax error rather than degrading gracefully.
12
12
 
13
13
  ## Conventions
14
14
 
@@ -27,7 +27,7 @@ Every wrapper emits one `logger.info` line per SDK call with a per-method safe-f
27
27
 
28
28
  ### Batch semantics
29
29
 
30
- Batch methods split your entries into chunks of the size the AWS API allows and send one request per chunk. AWS reports rejected entries inside an otherwise successful response, so a resolved request does not mean every entry was accepted. Currently covered: `SQSService.sendMessageBatch`, `SQSService.deleteMessageBatch`, `SNSService.publishBatch`, `SESService.sendBulkEmail`, `EventBridgeService.putEvents`, `S3Service.deleteObjects`, `S3Service.emptyBucket` and, when `required` is set, `SSMService.getParameters`.
30
+ Batch methods split your entries into chunks of the size the AWS API allows and send one request per chunk. AWS reports rejected entries inside an otherwise successful response, so a resolved request does not mean every entry was accepted. Currently covered: `SQSService.sendMessageBatch`, `SQSService.deleteMessageBatch`, `SNSService.publishBatch`, `SESService.sendBulkEmail`, `EventBridgeService.putEvents`, `S3Service.deleteObjects`, `S3Service.emptyBucket`, `DynamoDBService.batchGet`, `DynamoDBService.batchWrite` and, when `required` is set, `SSMService.getParameters`.
31
31
 
32
32
  Every chunk is sent first. If any entry was rejected, the method then throws a single `BatchOperationError`. A call where nothing was rejected returns exactly what it did before.
33
33
 
@@ -39,7 +39,8 @@ try {
39
39
  } catch (error) {
40
40
  if (error instanceof BatchOperationError) {
41
41
  // error.results — the raw SDK output of every chunk, including what succeeded
42
- // (empty for SSM, per-page deleted keys for S3 emptyBucket)
42
+ // (empty for SSM, per-page deleted keys for S3 emptyBucket,
43
+ // the single last output for DynamoDB)
43
44
  // error.failed — [{ id, code, message }] for every rejected entry
44
45
  const failedIds = new Set(error.failed.map(entry => entry.id));
45
46
  await retry(entries.filter(entry => failedIds.has(entry.Id)));
@@ -51,8 +52,10 @@ try {
51
52
 
52
53
  - `failed` carries only the entry identifier, error code and message — never message bodies, attributes or any other payload. For S3 the identifier is the object key; for SSM it is the parameter path.
53
54
  - `EventBridgeService.putEvents` and `SESService.sendBulkEmail` entries have no identifier of their own, so for those methods `id` is the entry's index in the `Entries` / `BulkEmailEntries` list you passed in, as a string.
55
+ - DynamoDB batch entries have no identifier either, and the key or item is caller data that must stay out of `failed`, so `id` is `<table>[<index>]`, the position within that table's still-unprocessed list — see the DynamoDB section.
54
56
  - The error has a stable `name` of `'BatchOperationError'`. If both the CJS and ESM builds of this package can be loaded in one process, check `error.name` instead of `instanceof`.
55
57
  - A warning is logged with the failure count and error codes, and no payload, at every log level.
58
+ - **Don't log the error object itself.** `results` is an enumerable property, and the Powertools logger serialises every enumerable property of an error it is given, so `logger.error('…', error)` (or `{ error }`) writes `results` to the log. For the DynamoDB batch methods that holds your keys, items and the items you fetched. Log `error.name`, `error.message` and `error.failed` instead, and read `error.results` only to retry or recover.
56
59
  - Request-level SDK exceptions (throttling, access denied, network errors) are **not** wrapped. They propagate unchanged and immediately, so earlier chunks may already have been sent and the caller cannot tell which. Treat those as "outcome unknown" and make the operation safe to repeat.
57
60
 
58
61
  ### X-Ray outside Lambda
@@ -106,6 +109,8 @@ await s3.deleteObjects('my-bucket', ['key1', 'key2']); // auto-chunked to 1000 k
106
109
  await s3.emptyBucket('my-bucket'); // unversioned buckets only — see below
107
110
  ```
108
111
 
112
+ `getJsonObject` and `getAllObjects` throw when an object body is not valid JSON. The error names the object (`s3://bucket/key`) and deliberately carries none of its content, unlike the native `SyntaxError`, which quotes a snippet of the input. `getAllObjects` stops at the first bad object.
113
+
109
114
  `deleteObjects` and `emptyBucket` throw a `BatchOperationError` when S3 reports that it could not delete one or more keys — see "Batch semantics". `failed[].id` is the object key.
110
115
 
111
116
  `emptyBucket` returns only the keys that were actually deleted. A page with failures does not stop the run: every page is attempted, then one aggregated `BatchOperationError` is thrown. Its `results` hold one `{ deletedKeys }` per page, so the caller can tell which keys were deleted and which failed:
@@ -169,7 +174,8 @@ const { Attributes } = await ddb.updateItem<MyKey, { value: number }>({
169
174
  await ddb.deleteItem({ TableName: 'my-table', Key: { pk: 'abc' } });
170
175
 
171
176
  // batchWrite retries UnprocessedItems with jittered exponential backoff
172
- // (5 attempts, 200ms base) and throws if any remain after the final attempt.
177
+ // (5 attempts, 200ms base) and throws a BatchOperationError if any remain
178
+ // after the final attempt — see below.
173
179
  await ddb.batchWrite({
174
180
  RequestItems: {
175
181
  'my-table': [{ PutRequest: { Item: { pk: 'abc' } } }],
@@ -205,7 +211,23 @@ for await (const item of ddb.paginateItems<{ pk: string }>({
205
211
 
206
212
  `Limit` on `paginateItems` / `paginateScan` is applied by DynamoDB per request, and both methods walk every page until `LastEvaluatedKey` is exhausted. Passing `Limit: 10` therefore yields *every* matching item in pages of 10, not the first 10. Because both return an `AsyncGenerator`, `break` calls its `return()`, which unwinds the pagination and issues no further requests — that is how you bound the number of items. `Limit` is still the right knob for tuning per-request consumed capacity and page memory; it just doesn't stop the walk.
207
213
 
208
- `batchGet` is **not** generic — its `Responses` field is a multi-table record whose item shapes can differ per table, so no single generic can soundly describe it. Callers should narrow the result type at the call site. Like `batchWrite`, it retries non-empty `UnprocessedKeys` with jittered exponential backoff (5 attempts, 200ms base), merging `Responses` across attempts and throwing if keys remain unprocessed after the final attempt.
214
+ `batchGet` is **not** generic — its `Responses` field is a multi-table record whose item shapes can differ per table, so no single generic can soundly describe it. Callers should narrow the result type at the call site. Like `batchWrite`, it retries non-empty `UnprocessedKeys` with jittered exponential backoff (5 attempts, 200ms base), merging `Responses` across attempts.
215
+
216
+ When items or keys are still unprocessed after the final attempt, `batchGet` and `batchWrite` throw a `BatchOperationError` (see "Batch semantics") rather than a plain `Error`, so a caller that caught `Error` and matched the old `batchGet failed after 5 attempts` message must match on the error `name` instead. Nothing is lost: `error.results` holds one output, and its `UnprocessedKeys` / `UnprocessedItems` are exactly what is left to retry. For `batchGet` that output also carries the `Responses` merged across every attempt, so the items already retrieved are still available:
217
+
218
+ ```ts
219
+ try {
220
+ return await ddb.batchGet({ RequestItems: { 'my-table': { Keys: keys } } });
221
+ } catch (error) {
222
+ if (error instanceof BatchOperationError) {
223
+ const [partial] = error.results; // { Responses, UnprocessedKeys, ... }
224
+ // retry partial.UnprocessedKeys later, keep partial.Responses
225
+ }
226
+ throw error;
227
+ }
228
+ ```
229
+
230
+ `failed` has one entry per pending key or item, with `code` `UnprocessedKeys` or `UnprocessedItems`. Because the key or item is your data and must stay out of the error message and logs, `failed[].id` is `<table>[<index>]`, the position within `results[0].UnprocessedKeys[table].Keys` (or `results[0].UnprocessedItems[table]`). `results` does carry that data, as it is what you asked for or sent, so don't log `results` or the error object itself: the Powertools logger serialises an error's enumerable properties, `results` included (see [Batch semantics](#batch-semantics)).
209
231
 
210
232
  ## Secrets Manager
211
233
 
@@ -218,7 +240,7 @@ const raw = await secrets.getSecret('my-secret-name');
218
240
  const config = await secrets.getJsonSecret<MySecretShape>('my-secret-name');
219
241
  ```
220
242
 
221
- `getSecret` throws when the response has no `SecretString` (e.g. a binary-only secret). `getJsonSecret` additionally throws if the secret value is not valid JSON. `VersionId` / `VersionStage` aren't exposed — use `SecretsManagerClient` directly if you need version pinning.
243
+ `getSecret` throws when the response has no `SecretString` (e.g. a binary-only secret). `getJsonSecret` additionally throws if the secret value is not valid JSON; that error names the secret and deliberately carries none of its value, unlike the native `SyntaxError`, which quotes a snippet of the input. `VersionId` / `VersionStage` aren't exposed — use `SecretsManagerClient` directly if you need version pinning.
222
244
 
223
245
  ```ts
224
246
  // Write operations. Prefer IaC (CDK / Terraform) for secret lifecycle;
@@ -394,7 +416,8 @@ const apiKey = await ssm.getParameter('/myapp/api-key');
394
416
 
395
417
  // Supply an alias-to-path map — the result is keyed by the aliases so the
396
418
  // SSM path is only mentioned at the call site. Auto-chunks past 10 aliases
397
- // (the SDK's per-request cap on GetParameters).
419
+ // (the SDK's per-request cap on GetParameters). A value may also be a
420
+ // parameter ARN or a `name:version` / `name:label` selector.
398
421
  const { host, port } = await ssm.getParameters({
399
422
  host: '/myapp/host',
400
423
  port: '/myapp/port',
@@ -465,6 +488,8 @@ await sqs.sendMessage({ QueueUrl, MessageBody: huge });
465
488
  await sqs.sendMessage({ QueueUrl, MessageBody: huge }, { truncate: false }); // per-call override
466
489
  ```
467
490
 
491
+ With truncation on, a `MessageBody` above 1 MiB (the SQS maximum) is cut at a UTF-8 codepoint boundary and a warning is logged. A queue can be configured with a lower `MaximumMessageSize`, but the wrapper does not know a queue's setting, so lowering it does not lower this cut-off. Message attributes count toward the SQS limit as well and are never truncated, so a body cut to 1 MiB that also carries attributes can still be rejected. Truncating a structured body such as JSON can leave it invalid, so only enable it where the consumer tolerates that.
492
+
468
493
  ## SNS
469
494
 
470
495
  ```ts
@@ -478,13 +503,15 @@ await sns.publish({ TopicArn, Message: 'hello' });
478
503
  // and throws a BatchOperationError if SNS rejects any entry — see "Batch semantics".
479
504
  await sns.publishBatch({ TopicArn, PublishBatchRequestEntries: bigEntryList });
480
505
 
481
- // Opt-in truncation — same shape as SQS. Truncates Message (256 KB byte-safe)
482
- // and Subject (100 chars codepoint-safe) when enabled.
506
+ // Opt-in truncation — same shape as SQS. Truncates Message (256 KiB byte-safe)
507
+ // and Subject (99 chars codepoint-safe) when enabled.
483
508
  const truncSns = new SNSService({ truncate: true });
484
509
  await truncSns.publish({ TopicArn, Message: huge, Subject: long });
485
510
  await truncSns.publish({ TopicArn, Message: huge }, { truncate: false });
486
511
  ```
487
512
 
513
+ With truncation on, a `Message` above 256 KiB is cut at a UTF-8 codepoint boundary and a `Subject` above 99 characters is cut to 99 (SNS requires fewer than 100), each with a warning. 256 KiB is the default `MaximumMessageSize` of a topic. A topic can be raised to 1 MiB, but the wrapper does not know a topic's setting, so raising it does not raise this cut-off. Message attributes count toward the topic limit as well and are never truncated, so a message cut to 256 KiB that also carries attributes can still be rejected. Truncating a structured `Message` such as JSON can leave it invalid, so only enable it where the subscribers tolerate that.
514
+
488
515
  ## SES
489
516
 
490
517
  Wraps the SES v2 API (`@aws-sdk/client-sesv2`), not the legacy v1 API. Inputs and outputs are the SDK's own types, and no defaults are baked in: `FromEmailAddress`, `ConfigurationSetName` and the rest come from you on every call. Template, identity and suppression-list management is not wrapped — use the SDK client directly or infrastructure as code.