@aligent/aws-wrappers 0.5.7 → 0.5.9
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 +106 -4
- package/cjs/index.cjs +393 -66
- package/cjs/package.json +16 -14
- 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/s3/s3.d.ts +26 -4
- package/cjs/src/s3/s3.d.ts.map +1 -1
- package/cjs/src/scheduler/scheduler.d.ts +3 -2
- package/cjs/src/scheduler/scheduler.d.ts.map +1 -1
- 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 +33 -4
- package/cjs/src/util/batch-operation-error.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 +10 -6
- package/docs/index/classes/DynamoDBService.md +34 -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 +42 -19
- package/docs/index/classes/SNSService.md +4 -4
- package/docs/index/classes/SQSService.md +7 -7
- package/docs/index/classes/SSMService.md +35 -10
- package/docs/index/classes/SchedulerService.md +14 -13
- package/docs/index/classes/SecretsManagerService.md +10 -8
- package/docs/index/classes/StepFunctionsService.md +6 -6
- package/docs/index/interfaces/BatchFailedEntry.md +6 -5
- package/docs/index/interfaces/EmptyBucketPageResult.md +23 -0
- package/docs/index/modules.md +4 -0
- package/docs/testing/testing/functions/createMockService.md +5 -1
- package/esm/index.mjs +391 -67
- package/esm/package.json +16 -14
- 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/s3/s3.d.ts +26 -4
- package/esm/src/s3/s3.d.ts.map +1 -1
- package/esm/src/scheduler/scheduler.d.ts +3 -2
- package/esm/src/scheduler/scheduler.d.ts.map +1 -1
- 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 +33 -4
- package/esm/src/util/batch-operation-error.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 +16 -14
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` 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`, `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.
|
|
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` entries have no identifier of their own, so for that method `id` is the entry's index in the `Entries` 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.
|
|
@@ -104,9 +106,25 @@ await s3.deleteObjects('my-bucket', ['key1', 'key2']); // auto-chunked to 1000 k
|
|
|
104
106
|
await s3.emptyBucket('my-bucket'); // unversioned buckets only — see below
|
|
105
107
|
```
|
|
106
108
|
|
|
109
|
+
`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
|
+
|
|
111
|
+
`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:
|
|
112
|
+
|
|
113
|
+
```ts
|
|
114
|
+
try {
|
|
115
|
+
const deleted = await s3.emptyBucket('my-bucket');
|
|
116
|
+
} catch (error) {
|
|
117
|
+
if (error instanceof BatchOperationError) {
|
|
118
|
+
const deleted = error.results.flatMap(page => page.deletedKeys);
|
|
119
|
+
const stuck = error.failed.map(entry => entry.id); // [{ id: key, code, message }]
|
|
120
|
+
}
|
|
121
|
+
throw error;
|
|
122
|
+
}
|
|
123
|
+
```
|
|
124
|
+
|
|
107
125
|
Input shapes are intentionally tight (`Bucket`, `Key`, `Body` and similar). Callers needing SDK-specific options like server-side encryption or tagging should use `S3Client` directly.
|
|
108
126
|
|
|
109
|
-
`emptyBucket` streams the listing page-by-page and delegates each page to `deleteObjects`, so
|
|
127
|
+
`emptyBucket` streams the listing page-by-page and delegates each page to `deleteObjects`, so only one page of SDK responses is held at a time; the list of deleted keys it returns is the one thing that grows with the bucket. It empties **unversioned buckets only**: it paginates `ListObjectsV2`, which reports current object versions and never noncurrent versions or delete markers. Against a versioned bucket the call succeeds and the bucket then *looks* empty to `ListObjectsV2` — but the deletes only added delete markers, so every object version is still stored. You will still be billed for that storage, and `DeleteBucket` will fail with `BucketNotEmpty`. Emptying a versioned bucket needs `ListObjectVersions` plus per-version deletes — use `S3Client` directly.
|
|
110
128
|
|
|
111
129
|
## DynamoDB
|
|
112
130
|
|
|
@@ -290,6 +308,81 @@ const groups = await scheduler.listScheduleGroups();
|
|
|
290
308
|
await scheduler.deleteScheduleGroup({ Name: 'integrations' });
|
|
291
309
|
```
|
|
292
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
|
+
|
|
293
386
|
## SSM Parameter Store
|
|
294
387
|
|
|
295
388
|
```ts
|
|
@@ -313,6 +406,15 @@ const params = await ssm.getParametersByPath('/myapp/');
|
|
|
313
406
|
const shallow = await ssm.getParametersByPath('/myapp/', { recursive: false });
|
|
314
407
|
```
|
|
315
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
|
+
|
|
316
418
|
All read operations enable `WithDecryption` automatically — there's no opt-out. Callers needing plaintext should use `SSMClient` directly.
|
|
317
419
|
|
|
318
420
|
```ts
|