sdk-aws-lambda 0.8.0 → 0.8.1
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/LambdaEndpointRefusal.d.ts +25 -0
- package/dist/domain.objects/LambdaEndpointRefusal.js +19 -0
- package/dist/domain.objects/LambdaEndpointRefusal.js.map +1 -0
- package/dist/domain.objects/LambdaEndpointRefusedError.d.ts +25 -0
- package/dist/domain.objects/LambdaEndpointRefusedError.js +28 -0
- package/dist/domain.objects/LambdaEndpointRefusedError.js.map +1 -0
- package/dist/domain.operations/askLambdaEndpoint/askLambdaEndpoint.d.ts +3 -0
- package/dist/domain.operations/askLambdaEndpoint/askLambdaEndpoint.viaApiGateway.d.ts +11 -2
- package/dist/domain.operations/askLambdaEndpoint/askLambdaEndpoint.viaApiGateway.js +7 -2
- package/dist/domain.operations/askLambdaEndpoint/askLambdaEndpoint.viaApiGateway.js.map +1 -1
- package/dist/domain.operations/askLambdaEndpoint/askLambdaEndpoint.viaInvoke.d.ts +10 -0
- package/dist/domain.operations/askLambdaEndpoint/askLambdaEndpoint.viaInvoke.js +17 -5
- package/dist/domain.operations/askLambdaEndpoint/askLambdaEndpoint.viaInvoke.js.map +1 -1
- package/dist/domain.operations/askLambdaEndpoint/cache/asAskLambdaCacheKeyOfRefusal.d.ts +17 -0
- package/dist/domain.operations/askLambdaEndpoint/cache/asAskLambdaCacheKeyOfRefusal.js +22 -0
- package/dist/domain.operations/askLambdaEndpoint/cache/asAskLambdaCacheKeyOfRefusal.js.map +1 -0
- package/dist/domain.operations/askLambdaEndpoint/invoke/executeLambdaInvocation.d.ts +2 -0
- package/dist/domain.operations/askLambdaEndpoint/invoke/executeLambdaInvocation.js +1 -0
- package/dist/domain.operations/askLambdaEndpoint/invoke/executeLambdaInvocation.js.map +1 -1
- package/dist/domain.operations/askLambdaEndpoint/serde/asErrorFromHttpResponse.d.ts +9 -5
- package/dist/domain.operations/askLambdaEndpoint/serde/asErrorFromHttpResponse.js +27 -9
- package/dist/domain.operations/askLambdaEndpoint/serde/asErrorFromHttpResponse.js.map +1 -1
- package/dist/domain.operations/askLambdaEndpoint/serde/asLambdaEndpointRefusal.d.ts +15 -0
- package/dist/domain.operations/askLambdaEndpoint/serde/asLambdaEndpointRefusal.js +43 -0
- package/dist/domain.operations/askLambdaEndpoint/serde/asLambdaEndpointRefusal.js.map +1 -0
- package/dist/domain.operations/askLambdaEndpoint/serde/getIsHttpThrottle.d.ts +11 -0
- package/dist/domain.operations/askLambdaEndpoint/serde/getIsHttpThrottle.js +15 -0
- package/dist/domain.operations/askLambdaEndpoint/serde/getIsHttpThrottle.js.map +1 -0
- package/dist/domain.operations/genLambdaEndpoint/middleware/asLogMethodOfFailure.d.ts +17 -0
- package/dist/domain.operations/genLambdaEndpoint/middleware/asLogMethodOfFailure.js +26 -0
- package/dist/domain.operations/genLambdaEndpoint/middleware/asLogMethodOfFailure.js.map +1 -0
- package/dist/domain.operations/genLambdaEndpoint/middleware/genInternalServiceErrorMiddleware.js +2 -2
- package/dist/domain.operations/genLambdaEndpoint/middleware/genInternalServiceErrorMiddleware.js.map +1 -1
- package/dist/domain.operations/genLambdaEndpoint/middleware/genIoLoggerMiddleware.d.ts +15 -0
- package/dist/domain.operations/genLambdaEndpoint/middleware/genIoLoggerMiddleware.js +34 -13
- package/dist/domain.operations/genLambdaEndpoint/middleware/genIoLoggerMiddleware.js.map +1 -1
- package/dist/domain.operations/genServiceSdk/gen.file/asMechanismsFileSource.js +1 -1
- package/dist/domain.operations/genServiceSdk/gen.file/asMechanismsFileSource.js.map +1 -1
- package/dist/domain.operations/genServiceSdk/gen.mechanism/asMechanismFnSource.d.ts +2 -0
- package/dist/domain.operations/genServiceSdk/gen.mechanism/asMechanismFnSource.js +8 -4
- package/dist/domain.operations/genServiceSdk/gen.mechanism/asMechanismFnSource.js.map +1 -1
- package/dist/domain.operations/lambdaEndpointWire/error/asErrorFromPeerRefusal.d.ts +22 -0
- package/dist/domain.operations/lambdaEndpointWire/error/asErrorFromPeerRefusal.js +34 -0
- package/dist/domain.operations/lambdaEndpointWire/error/asErrorFromPeerRefusal.js.map +1 -0
- package/dist/domain.operations/lambdaEndpointWire/getParsedResponse.d.ts +15 -4
- package/dist/domain.operations/lambdaEndpointWire/getParsedResponse.js +32 -17
- package/dist/domain.operations/lambdaEndpointWire/getParsedResponse.js.map +1 -1
- package/dist/domain.operations/runLambdaEndpoint/runLambdaEndpoint.onSerialized.js +12 -0
- package/dist/domain.operations/runLambdaEndpoint/runLambdaEndpoint.onSerialized.js.map +1 -1
- package/dist/index.d.ts +7 -0
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/readme.md +42 -2
package/readme.md
CHANGED
|
@@ -159,6 +159,8 @@ retried, and an answer the sdk cannot read retries the whole batch. its event so
|
|
|
159
159
|
a caller fault is never retried. a message the schema refuses, or a `ConstraintError` (or
|
|
160
160
|
`BadRequestError`) a `perRecord` handler throws, logs `sqs.record.refused` at warn and is deleted,
|
|
161
161
|
with no dead-letter entry. to retry a fault, throw a `MalfunctionError`; every other throw redrives.
|
|
162
|
+
a peer's refusal of a request the handler composed is the handler's own fault, so it redrives too
|
|
163
|
+
(see [when the endpoint refuses the request](#when-the-endpoint-refuses-the-request)).
|
|
162
164
|
|
|
163
165
|
- `sqs.record.refused` carries the full message as delivered (`message`: body, attributes, queue
|
|
164
166
|
arn), so an operator can requeue it from the log. alarm on its volume: a schema bug of ours
|
|
@@ -256,6 +258,43 @@ const result = await askLambdaEndpoint<TRequest, TResponse>(
|
|
|
256
258
|
|
|
257
259
|
the caller's `trail.exid` rides along, so logs correlate across the call.
|
|
258
260
|
|
|
261
|
+
### when the endpoint refuses the request
|
|
262
|
+
|
|
263
|
+
a peer that answers `ConstraintError` or `BadRequestError` (or an http 4xx) refuses the request **you
|
|
264
|
+
composed**. that is your malfunction, not your caller's fault, so the ask throws
|
|
265
|
+
`LambdaEndpointRefusedError`, a `MalfunctionError`. an api gateway endpoint then answers its caller a
|
|
266
|
+
500 with a `correlationId`, never a 400 the caller cannot fix, and logs the failure at error. the
|
|
267
|
+
message names the peer, its reason, and the fix.
|
|
268
|
+
|
|
269
|
+
where the request forwards your own caller's input verbatim, the refusal is your caller's to fix. opt
|
|
270
|
+
in per call, and the ask throws a `ConstraintError` instead:
|
|
271
|
+
|
|
272
|
+
```ts
|
|
273
|
+
await askLambdaEndpoint(
|
|
274
|
+
{ which, event, refusal: { as: 'ConstraintError' } },
|
|
275
|
+
{ log, env: { access: 'prep' } },
|
|
276
|
+
);
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
⚠️ upgrade from 0.7: a `catch (e) { if (e instanceof ConstraintError) … }` around an ask no longer
|
|
280
|
+
sees a peer refusal, with no compile error. catch `LambdaEndpointRefusedError`, or opt in where the
|
|
281
|
+
call forwards. in a `forSqs.perRecord` handler, a peer refusal now redrives the message, then
|
|
282
|
+
dead-letters it, unless the call opts in. a failed async invoke is retried by aws, and a retry
|
|
283
|
+
wrapper that retries a `MalfunctionError` retries a refusal too.
|
|
284
|
+
|
|
285
|
+
every failure an endpoint's chain observes logs `handler.output` at warn (a caller fault) or error
|
|
286
|
+
(all else), with its message and stack, where 0.7 logged it at debug. a warn-keyed alarm sees more
|
|
287
|
+
volume. one exception: a caller fault a `forSqs.perRecord` handler throws is acknowledged inside
|
|
288
|
+
the leaf, so the chain sees a success and writes `handler.output` at debug. its trace is the
|
|
289
|
+
`sqs.record.refused` warn line above.
|
|
290
|
+
|
|
291
|
+
a function generated by `genServiceSdk` takes the same opt as a third argument:
|
|
292
|
+
`svcJobs.getJob(event, context, { refusal: { as: 'ConstraintError' } })`. regenerate the sdk to get
|
|
293
|
+
the slot.
|
|
294
|
+
|
|
295
|
+
an http 429 is a throttle, not a refusal: it throws a `MalfunctionError` under either opt, with
|
|
296
|
+
`retry-after` in `metadata.headers`.
|
|
297
|
+
|
|
259
298
|
### ask an api gateway endpoint, over http
|
|
260
299
|
|
|
261
300
|
```ts
|
|
@@ -269,8 +308,9 @@ const { status, body } = await askLambdaEndpoint.viaApiGateway<TResponse>(
|
|
|
269
308
|
|
|
270
309
|
takes the standard http request: `{ url, method, headers, body }`. an object `body` is sent as json.
|
|
271
310
|
|
|
272
|
-
it resolves `{ status, headers, text, body }`. a 4xx throws a `
|
|
273
|
-
`
|
|
311
|
+
it resolves `{ status, headers, text, body }`. a 4xx throws a `LambdaEndpointRefusedError` (or a
|
|
312
|
+
`ConstraintError`, with `refusal: { as: 'ConstraintError' }`); a 429 or a 5xx throws a
|
|
313
|
+
`MalfunctionError`, and a 5xx carries the `correlationId`. your trail rides the request, so the endpoint's
|
|
274
314
|
logs join yours.
|
|
275
315
|
|
|
276
316
|
any other http caller spreads the `x-trail-exid` header in to send the trail. the header also opts the
|