sdk-aws-lambda 0.7.1 → 0.7.2
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/dist/domain.objects/TrailCarrier.d.ts +17 -0
- package/dist/domain.objects/TrailCarrier.js +3 -0
- package/dist/domain.objects/TrailCarrier.js.map +1 -0
- package/dist/domain.objects/TrailExidHeader.d.ts +10 -0
- package/dist/domain.objects/TrailExidHeader.js +14 -0
- package/dist/domain.objects/TrailExidHeader.js.map +1 -0
- package/dist/domain.operations/asLambdaEvent/asLambdaEvent.fromApiGateway.js +15 -1
- package/dist/domain.operations/asLambdaEvent/asLambdaEvent.fromApiGateway.js.map +1 -1
- package/dist/domain.operations/askLambdaEndpoint/askLambdaEndpoint.d.ts +50 -27
- package/dist/domain.operations/askLambdaEndpoint/askLambdaEndpoint.js +18 -61
- package/dist/domain.operations/askLambdaEndpoint/askLambdaEndpoint.js.map +1 -1
- package/dist/domain.operations/askLambdaEndpoint/askLambdaEndpoint.viaApiGateway.d.ts +35 -0
- package/dist/domain.operations/askLambdaEndpoint/askLambdaEndpoint.viaApiGateway.js +80 -0
- package/dist/domain.operations/askLambdaEndpoint/askLambdaEndpoint.viaApiGateway.js.map +1 -0
- package/dist/domain.operations/askLambdaEndpoint/askLambdaEndpoint.viaInvoke.d.ts +37 -0
- package/dist/domain.operations/askLambdaEndpoint/askLambdaEndpoint.viaInvoke.js +70 -0
- package/dist/domain.operations/askLambdaEndpoint/askLambdaEndpoint.viaInvoke.js.map +1 -0
- package/dist/domain.operations/askLambdaEndpoint/invoke/executeHttpRequest.d.ts +17 -0
- package/dist/domain.operations/askLambdaEndpoint/invoke/executeHttpRequest.js +34 -0
- package/dist/domain.operations/askLambdaEndpoint/invoke/executeHttpRequest.js.map +1 -0
- package/dist/domain.operations/askLambdaEndpoint/serde/asErrorFromHttpResponse.d.ts +31 -0
- package/dist/domain.operations/askLambdaEndpoint/serde/asErrorFromHttpResponse.js +55 -0
- package/dist/domain.operations/askLambdaEndpoint/serde/asErrorFromHttpResponse.js.map +1 -0
- package/dist/domain.operations/askLambdaEndpoint/serde/asHeadersRecord.d.ts +13 -0
- package/dist/domain.operations/askLambdaEndpoint/serde/asHeadersRecord.js +22 -0
- package/dist/domain.operations/askLambdaEndpoint/serde/asHeadersRecord.js.map +1 -0
- package/dist/domain.operations/askLambdaEndpoint/serde/asHttpMethod.d.ts +16 -0
- package/dist/domain.operations/askLambdaEndpoint/serde/asHttpMethod.js +22 -0
- package/dist/domain.operations/askLambdaEndpoint/serde/asHttpMethod.js.map +1 -0
- package/dist/domain.operations/askLambdaEndpoint/serde/asHttpRequestBody.d.ts +17 -0
- package/dist/domain.operations/askLambdaEndpoint/serde/asHttpRequestBody.js +28 -0
- package/dist/domain.operations/askLambdaEndpoint/serde/asHttpRequestBody.js.map +1 -0
- package/dist/domain.operations/askLambdaEndpoint/serde/asHttpRequestHeaders.d.ts +23 -0
- package/dist/domain.operations/askLambdaEndpoint/serde/asHttpRequestHeaders.js +39 -0
- package/dist/domain.operations/askLambdaEndpoint/serde/asHttpRequestHeaders.js.map +1 -0
- package/dist/domain.operations/askLambdaEndpoint/serde/getOneBodyFromHttpText.d.ts +10 -0
- package/dist/domain.operations/askLambdaEndpoint/serde/getOneBodyFromHttpText.js +19 -0
- package/dist/domain.operations/askLambdaEndpoint/serde/getOneBodyFromHttpText.js.map +1 -0
- package/dist/domain.operations/askLambdaEndpoint/serde/getOneCorrelationIdFromBody.d.ts +11 -0
- package/dist/domain.operations/askLambdaEndpoint/serde/getOneCorrelationIdFromBody.js +19 -0
- package/dist/domain.operations/askLambdaEndpoint/serde/getOneCorrelationIdFromBody.js.map +1 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/asCorsHeadersWithTrail.d.ts +12 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/asCorsHeadersWithTrail.js +27 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/asCorsHeadersWithTrail.js.map +1 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/genLambdaEndpoint.forApiGateway.d.ts +3 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/genLambdaEndpoint.forApiGateway.js +32 -7
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/genLambdaEndpoint.forApiGateway.js.map +1 -1
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/middleware/genApiGatewayRequestEventNormalizationMiddleware.js +22 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/middleware/genApiGatewayRequestEventNormalizationMiddleware.js.map +1 -1
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forAsk/genLambdaEndpoint.forAsk.js +13 -2
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forAsk/genLambdaEndpoint.forAsk.js.map +1 -1
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/genLambdaEndpoint.forSqs.perBatch.js +5 -1
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/genLambdaEndpoint.forSqs.perBatch.js.map +1 -1
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/genLambdaEndpoint.forSqs.perRecord.js +5 -1
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/genLambdaEndpoint.forSqs.perRecord.js.map +1 -1
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/genSqsEndpointMiddlewares.d.ts +9 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/genSqsEndpointMiddlewares.js +10 -2
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/genSqsEndpointMiddlewares.js.map +1 -1
- package/dist/domain.operations/genLambdaEndpoint/middleware/genTrailMiddleware.d.ts +15 -8
- package/dist/domain.operations/genLambdaEndpoint/middleware/genTrailMiddleware.js +57 -12
- package/dist/domain.operations/genLambdaEndpoint/middleware/genTrailMiddleware.js.map +1 -1
- package/dist/domain.operations/lambdaEndpointWire/frame/asHeadersWithoutKey.d.ts +11 -0
- package/dist/domain.operations/lambdaEndpointWire/frame/asHeadersWithoutKey.js +13 -0
- package/dist/domain.operations/lambdaEndpointWire/frame/asHeadersWithoutKey.js.map +1 -0
- package/dist/domain.operations/lambdaEndpointWire/frame/asTrailExidHeaders.d.ts +23 -0
- package/dist/domain.operations/lambdaEndpointWire/frame/asTrailExidHeaders.js +32 -0
- package/dist/domain.operations/lambdaEndpointWire/frame/asTrailExidHeaders.js.map +1 -0
- package/dist/domain.operations/lambdaEndpointWire/frame/getOneTrailCarrierOfEvent.d.ts +20 -0
- package/dist/domain.operations/lambdaEndpointWire/frame/getOneTrailCarrierOfEvent.js +23 -0
- package/dist/domain.operations/lambdaEndpointWire/frame/getOneTrailCarrierOfEvent.js.map +1 -0
- package/dist/domain.operations/lambdaEndpointWire/frame/getOneTrailCarrierOfHandler.d.ts +9 -0
- package/dist/domain.operations/lambdaEndpointWire/frame/getOneTrailCarrierOfHandler.js +19 -0
- package/dist/domain.operations/lambdaEndpointWire/frame/getOneTrailCarrierOfHandler.js.map +1 -0
- package/dist/domain.operations/lambdaEndpointWire/frame/getOneTrailExidFromHeaders.d.ts +16 -0
- package/dist/domain.operations/lambdaEndpointWire/frame/getOneTrailExidFromHeaders.js +24 -0
- package/dist/domain.operations/lambdaEndpointWire/frame/getOneTrailExidFromHeaders.js.map +1 -0
- package/dist/domain.operations/lambdaEndpointWire/frame/isEventDeclaredAsApiGateway.d.ts +9 -0
- package/dist/domain.operations/lambdaEndpointWire/frame/isEventDeclaredAsApiGateway.js +15 -0
- package/dist/domain.operations/lambdaEndpointWire/frame/isEventDeclaredAsApiGateway.js.map +1 -0
- package/dist/domain.operations/lambdaEndpointWire/frame/isTrailExid.d.ts +19 -0
- package/dist/domain.operations/lambdaEndpointWire/frame/isTrailExid.js +27 -0
- package/dist/domain.operations/lambdaEndpointWire/frame/isTrailExid.js.map +1 -0
- package/dist/domain.operations/lambdaEndpointWire/frame/isTrailExidHeaderMalformed.d.ts +11 -0
- package/dist/domain.operations/lambdaEndpointWire/frame/isTrailExidHeaderMalformed.js +21 -0
- package/dist/domain.operations/lambdaEndpointWire/frame/isTrailExidHeaderMalformed.js.map +1 -0
- package/dist/domain.operations/lambdaEndpointWire/frame/setEventDeclaredAsApiGateway.d.ts +21 -0
- package/dist/domain.operations/lambdaEndpointWire/frame/setEventDeclaredAsApiGateway.js +27 -0
- package/dist/domain.operations/lambdaEndpointWire/frame/setEventDeclaredAsApiGateway.js.map +1 -0
- package/dist/domain.operations/lambdaEndpointWire/frame/setHandlerTrailCarrier.d.ts +24 -0
- package/dist/domain.operations/lambdaEndpointWire/frame/setHandlerTrailCarrier.js +28 -0
- package/dist/domain.operations/lambdaEndpointWire/frame/setHandlerTrailCarrier.js.map +1 -0
- package/dist/domain.operations/runLambdaEndpoint/runLambdaEndpoint.onReferenced.d.ts +7 -0
- package/dist/domain.operations/runLambdaEndpoint/runLambdaEndpoint.onReferenced.js +18 -2
- package/dist/domain.operations/runLambdaEndpoint/runLambdaEndpoint.onReferenced.js.map +1 -1
- package/dist/domain.operations/runLambdaEndpoint/runLambdaEndpoint.onSerialized.js +43 -7
- package/dist/domain.operations/runLambdaEndpoint/runLambdaEndpoint.onSerialized.js.map +1 -1
- package/dist/domain.operations/runLambdaEndpoint/serde/asCarriedPayload.d.ts +35 -0
- package/dist/domain.operations/runLambdaEndpoint/serde/asCarriedPayload.js +81 -0
- package/dist/domain.operations/runLambdaEndpoint/serde/asCarriedPayload.js.map +1 -0
- package/dist/domain.operations/runLambdaEndpoint/serde/getOneTrailWithExid.d.ts +14 -0
- package/dist/domain.operations/runLambdaEndpoint/serde/getOneTrailWithExid.js +18 -0
- package/dist/domain.operations/runLambdaEndpoint/serde/getOneTrailWithExid.js.map +1 -0
- package/dist/domain.operations/runLambdaEndpoint/serde/isEventWithHeaders.d.ts +17 -0
- package/dist/domain.operations/runLambdaEndpoint/serde/isEventWithHeaders.js +19 -0
- package/dist/domain.operations/runLambdaEndpoint/serde/isEventWithHeaders.js.map +1 -0
- package/dist/index.d.ts +8 -1
- package/dist/index.js +10 -2
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
- package/readme.md +43 -1
package/readme.md
CHANGED
|
@@ -171,6 +171,33 @@ const result = await askLambdaEndpoint<TRequest, TResponse>(
|
|
|
171
171
|
|
|
172
172
|
the caller's `trail.exid` rides along, so logs correlate across the call.
|
|
173
173
|
|
|
174
|
+
### ask an api gateway endpoint, over http
|
|
175
|
+
|
|
176
|
+
```ts
|
|
177
|
+
import { askLambdaEndpoint } from 'sdk-aws-lambda';
|
|
178
|
+
|
|
179
|
+
const { status, body } = await askLambdaEndpoint.viaApiGateway<TResponse>(
|
|
180
|
+
{ url: 'https://api.example.com/jobs', method: 'POST', body: { uuid } },
|
|
181
|
+
{ log },
|
|
182
|
+
);
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
takes the standard http request: `{ url, method, headers, body }`. an object `body` is sent as json.
|
|
186
|
+
|
|
187
|
+
it resolves `{ status, headers, text, body }`. a 4xx throws a `ConstraintError`; a 5xx throws a
|
|
188
|
+
`MalfunctionError` that carries the `correlationId`. your trail rides the request, so the endpoint's
|
|
189
|
+
logs join yours.
|
|
190
|
+
|
|
191
|
+
any other http client spreads the `x-trail-exid` header in to send the trail. the header also opts the
|
|
192
|
+
caller in to the contemp error body (`{ error: { class, … } }`); without it the endpoint answers the flat
|
|
193
|
+
`{ errorMessage, errorType }`:
|
|
194
|
+
|
|
195
|
+
```ts
|
|
196
|
+
import { asTrailExidHeaders } from 'sdk-aws-lambda';
|
|
197
|
+
|
|
198
|
+
await fetch(url, { headers: { ...asTrailExidHeaders({ trail: { exid } }) } });
|
|
199
|
+
```
|
|
200
|
+
|
|
174
201
|
## run an endpoint, in a test
|
|
175
202
|
|
|
176
203
|
| you call | you hold | a caller fault arrives as |
|
|
@@ -234,12 +261,27 @@ await runLambdaEndpoint.onReferenced({
|
|
|
234
261
|
|
|
235
262
|
| dialect | your handler receives | your handler answers |
|
|
236
263
|
|---|---|---|
|
|
237
|
-
| `contemp` (default) | `{ event, trail }` | the nested `{ error: { class, … } }` |
|
|
264
|
+
| `contemp` (default) | `{ event, trail }` — for an event built with `asLambdaEvent.fromApiGateway`, the event itself with an `x-trail-exid` header | the nested `{ error: { class, … } }` |
|
|
238
265
|
| `ancient` | the event, untouched | the flat `{ errorMessage, errorType }` |
|
|
239
266
|
|
|
240
267
|
a `genLambdaEndpoint` handler never notices — its middleware unwraps the frame first. a plain
|
|
241
268
|
handler does: under the contemp default it reads its own fields off a wrapper and finds them absent.
|
|
242
269
|
|
|
270
|
+
an api gateway endpoint is the exception: aws delivers its event unwrapped, so `runLambdaEndpoint`
|
|
271
|
+
carries the contemp opt-in in the event's `x-trail-exid` header instead of a wrapper. the endpoint a
|
|
272
|
+
`genLambdaEndpoint` builder returned declares which carrier it reads, so any event you hand it is
|
|
273
|
+
framed right: a built event, a spread copy, a hand-built or captured request.
|
|
274
|
+
|
|
275
|
+
the one road that holds no endpoint is `runLambdaEndpoint.onSerialized({ at: 'cloud' })`: it reads a
|
|
276
|
+
mark `asLambdaEvent.fromApiGateway` leaves on the event, so send the event as built. a copy (spread,
|
|
277
|
+
`structuredClone`, a json round trip) loses the mark and fails loud with the fix: pass the change to
|
|
278
|
+
`asLambdaEvent.fromApiGateway` (`headers`, `requestContext`, `path`, …) rather than a copy. a raw event
|
|
279
|
+
captured from aws goes through `struct: { payload: 'ancient' }` and arrives as sent, with any
|
|
280
|
+
`x-trail-exid` header it holds.
|
|
281
|
+
|
|
282
|
+
a `forApiGateway` endpoint adds `x-trail-exid` to its cors `allow-headers`, since a browser caller
|
|
283
|
+
that sends it triggers a preflight.
|
|
284
|
+
|
|
243
285
|
## build an event for a source
|
|
244
286
|
|
|
245
287
|
`asLambdaEvent` casts a payload into the envelope aws actually delivers, wire-faithful by default:
|