@aligent/aws-wrappers 0.5.8 → 0.5.10
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/README.md +130 -3
- package/cjs/index.cjs +424 -11
- package/cjs/package.json +4 -1
- package/cjs/src/eventbridge/eventbridge.d.ts +58 -0
- package/cjs/src/eventbridge/eventbridge.d.ts.map +1 -0
- package/cjs/src/index.d.ts +4 -0
- package/cjs/src/index.d.ts.map +1 -1
- package/cjs/src/lambda/lambda.d.ts +54 -0
- package/cjs/src/lambda/lambda.d.ts.map +1 -0
- package/cjs/src/scheduler/scheduler.d.ts +3 -2
- package/cjs/src/scheduler/scheduler.d.ts.map +1 -1
- package/cjs/src/ses/ses.d.ts +64 -0
- package/cjs/src/ses/ses.d.ts.map +1 -0
- package/cjs/src/ssm/ssm.d.ts +18 -3
- package/cjs/src/ssm/ssm.d.ts.map +1 -1
- package/cjs/src/util/batch-operation-error.d.ts +13 -7
- package/cjs/src/util/batch-operation-error.d.ts.map +1 -1
- package/cjs/src/util/chunk.d.ts +8 -0
- package/cjs/src/util/chunk.d.ts.map +1 -1
- package/cjs/src/util/lambda-function-error.d.ts +36 -0
- package/cjs/src/util/lambda-function-error.d.ts.map +1 -0
- package/docs/index/classes/APIGatewayService.md +6 -6
- package/docs/index/classes/APIGatewayV2Service.md +5 -5
- package/docs/index/classes/BatchOperationError.md +7 -6
- package/docs/index/classes/DynamoDBService.md +12 -12
- package/docs/index/classes/EventBridgeService.md +99 -0
- package/docs/index/classes/LambdaFunctionError.md +283 -0
- package/docs/index/classes/LambdaService.md +95 -0
- package/docs/index/classes/S3Service.md +15 -15
- package/docs/index/classes/SESService.md +123 -0
- package/docs/index/classes/SNSService.md +4 -4
- package/docs/index/classes/SQSService.md +7 -7
- package/docs/index/classes/SSMService.md +33 -10
- package/docs/index/classes/SchedulerService.md +14 -13
- package/docs/index/classes/SecretsManagerService.md +8 -8
- package/docs/index/classes/StepFunctionsService.md +6 -6
- package/docs/index/interfaces/BatchFailedEntry.md +6 -5
- package/docs/index/interfaces/EmptyBucketPageResult.md +2 -2
- package/docs/index/modules.md +4 -0
- package/docs/testing/testing/functions/createMockService.md +1 -1
- package/esm/index.mjs +421 -12
- package/esm/package.json +4 -1
- package/esm/src/eventbridge/eventbridge.d.ts +58 -0
- package/esm/src/eventbridge/eventbridge.d.ts.map +1 -0
- package/esm/src/index.d.ts +4 -0
- package/esm/src/index.d.ts.map +1 -1
- package/esm/src/lambda/lambda.d.ts +54 -0
- package/esm/src/lambda/lambda.d.ts.map +1 -0
- package/esm/src/scheduler/scheduler.d.ts +3 -2
- package/esm/src/scheduler/scheduler.d.ts.map +1 -1
- package/esm/src/ses/ses.d.ts +64 -0
- package/esm/src/ses/ses.d.ts.map +1 -0
- package/esm/src/ssm/ssm.d.ts +18 -3
- package/esm/src/ssm/ssm.d.ts.map +1 -1
- package/esm/src/util/batch-operation-error.d.ts +13 -7
- package/esm/src/util/batch-operation-error.d.ts.map +1 -1
- package/esm/src/util/chunk.d.ts +8 -0
- package/esm/src/util/chunk.d.ts.map +1 -1
- package/esm/src/util/lambda-function-error.d.ts +36 -0
- package/esm/src/util/lambda-function-error.d.ts.map +1 -0
- package/package.json +4 -1
package/README.md
CHANGED
|
@@ -27,9 +27,9 @@ 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`, `S3Service.deleteObjects` and `
|
|
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`.
|
|
31
31
|
|
|
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
|
|
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
|
|
|
34
34
|
```ts
|
|
35
35
|
import { BatchOperationError } from '@aligent/aws-wrappers';
|
|
@@ -39,6 +39,7 @@ 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
43
|
// error.failed — [{ id, code, message }] for every rejected entry
|
|
43
44
|
const failedIds = new Set(error.failed.map(entry => entry.id));
|
|
44
45
|
await retry(entries.filter(entry => failedIds.has(entry.Id)));
|
|
@@ -48,7 +49,8 @@ try {
|
|
|
48
49
|
}
|
|
49
50
|
```
|
|
50
51
|
|
|
51
|
-
- `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.
|
|
52
|
+
- `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
|
+
- `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.
|
|
52
54
|
- 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`.
|
|
53
55
|
- A warning is logged with the failure count and error codes, and no payload, at every log level.
|
|
54
56
|
- 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.
|
|
@@ -306,6 +308,81 @@ const groups = await scheduler.listScheduleGroups();
|
|
|
306
308
|
await scheduler.deleteScheduleGroup({ Name: 'integrations' });
|
|
307
309
|
```
|
|
308
310
|
|
|
311
|
+
## EventBridge
|
|
312
|
+
|
|
313
|
+
Publishes events to an event bus. `putEvents` takes the SDK input unchanged — `Detail` stays a JSON string you serialise yourself.
|
|
314
|
+
|
|
315
|
+
```ts
|
|
316
|
+
import { BatchOperationError, EventBridgeService } from '@aligent/aws-wrappers';
|
|
317
|
+
|
|
318
|
+
const eventBridge = new EventBridgeService();
|
|
319
|
+
|
|
320
|
+
// Auto-chunks Entries to the EventBridge-enforced 10-entry limit and throws a
|
|
321
|
+
// BatchOperationError if EventBridge rejects any entry — see "Batch semantics".
|
|
322
|
+
// Chunking is by count only: a chunk over the 256 KB request limit fails at the
|
|
323
|
+
// SDK as a request-level error.
|
|
324
|
+
try {
|
|
325
|
+
await eventBridge.putEvents({
|
|
326
|
+
Entries: orders.map(order => ({
|
|
327
|
+
Source: 'orders.service',
|
|
328
|
+
DetailType: 'OrderCreated',
|
|
329
|
+
Detail: JSON.stringify(order),
|
|
330
|
+
})),
|
|
331
|
+
});
|
|
332
|
+
} catch (error) {
|
|
333
|
+
if (error instanceof BatchOperationError) {
|
|
334
|
+
// failed[].id is the index in the Entries list you passed in, as a string.
|
|
335
|
+
const failedIndexes = new Set(error.failed.map(entry => Number(entry.id)));
|
|
336
|
+
await retry(orders.filter((_, index) => failedIndexes.has(index)));
|
|
337
|
+
return;
|
|
338
|
+
}
|
|
339
|
+
throw error;
|
|
340
|
+
}
|
|
341
|
+
```
|
|
342
|
+
|
|
343
|
+
The wrapper does not retry. At INFO the log line shows only the endpoint id and the entry count, because `Detail` and `Resources` carry payloads.
|
|
344
|
+
|
|
345
|
+
## Lambda
|
|
346
|
+
|
|
347
|
+
Invokes another Lambda function. `invoke` takes the SDK input unchanged and returns the SDK output unchanged — `Payload` stays a `Uint8Array` you serialise and decode yourself. Choose sync, async or dry-run with `InvocationType`; omitting it means a synchronous call.
|
|
348
|
+
|
|
349
|
+
```ts
|
|
350
|
+
import { LambdaFunctionError, LambdaService } from '@aligent/aws-wrappers';
|
|
351
|
+
|
|
352
|
+
const lambda = new LambdaService();
|
|
353
|
+
|
|
354
|
+
// Lambda answers HTTP 200 even when the invoked function threw, flagging it with
|
|
355
|
+
// FunctionError on the response. invoke() turns that marker into a thrown
|
|
356
|
+
// LambdaFunctionError so a failed invocation can't be mistaken for a success.
|
|
357
|
+
try {
|
|
358
|
+
const { Payload } = await lambda.invoke({
|
|
359
|
+
FunctionName: 'pricing-service',
|
|
360
|
+
Payload: new TextEncoder().encode(JSON.stringify({ sku: 'ABC-123' })),
|
|
361
|
+
});
|
|
362
|
+
const price = JSON.parse(Payload?.transformToString() ?? 'null');
|
|
363
|
+
} catch (error) {
|
|
364
|
+
if (error instanceof LambdaFunctionError) {
|
|
365
|
+
// functionError is 'Handled' or 'Unhandled'; errorType and errorMessage are
|
|
366
|
+
// parsed from the function's error payload, or undefined if it isn't the usual shape.
|
|
367
|
+
console.error(error.functionName, error.functionError, error.errorType, error.errorMessage);
|
|
368
|
+
}
|
|
369
|
+
throw error;
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
// Fire-and-forget: the response only confirms the request was accepted.
|
|
373
|
+
await lambda.invoke({
|
|
374
|
+
FunctionName: 'audit-writer',
|
|
375
|
+
InvocationType: 'Event',
|
|
376
|
+
Payload: new TextEncoder().encode(JSON.stringify(auditRecord)),
|
|
377
|
+
});
|
|
378
|
+
```
|
|
379
|
+
|
|
380
|
+
- `LambdaFunctionError` carries the function name, the SDK's function error value, and the error type and message parsed from the payload. It deliberately excludes the raw SDK output and the stack trace, because either can contain your payload or PII. A warning with only the function name and function error value is logged.
|
|
381
|
+
- The error has a stable `name` of `'LambdaFunctionError'`. If both the CJS and ESM builds of this package can be loaded in one process, check `error.name` instead of `instanceof`.
|
|
382
|
+
- The function error marker only appears on synchronous responses, so async (`Event`) and `DryRun` calls return without throwing. **Failures of asynchronous invocations are not observable by the wrapper** — configure a dead-letter queue or destination on the invoked function.
|
|
383
|
+
- Request-level SDK exceptions (throttling, access denied, network errors) are not wrapped and propagate unchanged.
|
|
384
|
+
- At INFO the log line shows only the function name, invocation type, qualifier, log type and tenant id. `Payload` and `ClientContext` are omitted, and responses are never logged.
|
|
385
|
+
|
|
309
386
|
## SSM Parameter Store
|
|
310
387
|
|
|
311
388
|
```ts
|
|
@@ -329,6 +406,15 @@ const params = await ssm.getParametersByPath('/myapp/');
|
|
|
329
406
|
const shallow = await ssm.getParametersByPath('/myapp/', { recursive: false });
|
|
330
407
|
```
|
|
331
408
|
|
|
409
|
+
`getParameter` throws when the parameter does not exist, but `getParameters` returns `undefined` for a missing one, so a typo'd path only surfaces later as an undefined value. Pass `required: true` to make `getParameters` fail fast instead. Every chunk is still sent, then a single `BatchOperationError` is thrown (see "Batch semantics") naming every missing parameter: `failed[].id` is the path, `failed[].code` is `ParameterNotFound` and `failed[].message` names the alias. `results` is empty, since there is nothing useful in the SDK output of a failed lookup.
|
|
410
|
+
|
|
411
|
+
```ts
|
|
412
|
+
const { host, port } = await ssm.getParameters(
|
|
413
|
+
{ host: '/myapp/host', port: '/myapp/port' },
|
|
414
|
+
{ required: true }
|
|
415
|
+
);
|
|
416
|
+
```
|
|
417
|
+
|
|
332
418
|
All read operations enable `WithDecryption` automatically — there's no opt-out. Callers needing plaintext should use `SSMClient` directly.
|
|
333
419
|
|
|
334
420
|
```ts
|
|
@@ -399,6 +485,47 @@ await truncSns.publish({ TopicArn, Message: huge, Subject: long });
|
|
|
399
485
|
await truncSns.publish({ TopicArn, Message: huge }, { truncate: false });
|
|
400
486
|
```
|
|
401
487
|
|
|
488
|
+
## SES
|
|
489
|
+
|
|
490
|
+
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.
|
|
491
|
+
|
|
492
|
+
```ts
|
|
493
|
+
import { SESService } from '@aligent/aws-wrappers';
|
|
494
|
+
|
|
495
|
+
const ses = new SESService();
|
|
496
|
+
|
|
497
|
+
// Simple, Raw or Template content — pass whichever `Content` shape SES accepts.
|
|
498
|
+
const { MessageId } = await ses.sendEmail({
|
|
499
|
+
FromEmailAddress: 'orders@example.com',
|
|
500
|
+
Destination: { ToAddresses: [customerEmail] },
|
|
501
|
+
Content: {
|
|
502
|
+
Template: {
|
|
503
|
+
TemplateName: 'order-confirmation',
|
|
504
|
+
TemplateData: JSON.stringify({ orderNumber }),
|
|
505
|
+
},
|
|
506
|
+
},
|
|
507
|
+
});
|
|
508
|
+
|
|
509
|
+
// sendBulkEmail auto-chunks BulkEmailEntries to the SES-enforced 50-entry limit and
|
|
510
|
+
// throws a BatchOperationError if SES rejects any entry — see "Batch semantics".
|
|
511
|
+
await ses.sendBulkEmail({
|
|
512
|
+
FromEmailAddress: 'orders@example.com',
|
|
513
|
+
DefaultContent: { Template: { TemplateName: 'order-confirmation', TemplateData: '{}' } },
|
|
514
|
+
BulkEmailEntries: customers.map(({ email, data }) => ({
|
|
515
|
+
Destination: { ToAddresses: [email] },
|
|
516
|
+
ReplacementEmailContent: {
|
|
517
|
+
ReplacementTemplate: { ReplacementTemplateData: JSON.stringify(data) },
|
|
518
|
+
},
|
|
519
|
+
})),
|
|
520
|
+
});
|
|
521
|
+
```
|
|
522
|
+
|
|
523
|
+
- SES answers HTTP 200 for a bulk send even when individual entries fail, so `sendBulkEmail` checks every entry's `Status` after all chunks are sent. Anything other than `SUCCESS` (including an entry SES returned no result for) ends up in `BatchOperationError.failed`, with `id` set to the entry's index in `BulkEmailEntries`, `code` set to the SES status and `message` set to the SES error text. `error.results` holds each chunk's output, so you can retry just the failed indexes.
|
|
524
|
+
- Sending is not idempotent: retrying the whole `sendBulkEmail` call after a `BatchOperationError` re-sends the entries that already succeeded.
|
|
525
|
+
- `sendEmail` is a pure pass-through. SDK exceptions such as `MessageRejected` or `SendingPausedException` propagate unchanged, and so do request-level failures from `sendBulkEmail`.
|
|
526
|
+
- At INFO the log line shows only routing metadata (`FromEmailAddressIdentityArn`, `ConfigurationSetName`, tags, `EndpointId`, `TenantName`), the template name, and a recipient or entry count. Sender, recipient and reply-to addresses, subjects, bodies and template data are omitted.
|
|
527
|
+
- There is no `truncate` option: a silently truncated email is worse than the SDK rejecting an oversized one.
|
|
528
|
+
|
|
402
529
|
## API Gateway
|
|
403
530
|
|
|
404
531
|
Read-only lookups against the control plane. `APIGatewayService` wraps REST APIs (v1); `APIGatewayV2Service` wraps HTTP and WebSocket APIs (v2). List methods are auto-paginated and return flat arrays.
|