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
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* .what = how a caller wants a peer endpoint's refusal thrown
|
|
3
|
+
* .why = a peer's refusal of a request this caller composed is this caller's malfunction, so the
|
|
4
|
+
* default throws `LambdaEndpointRefusedError`. a caller that forwards its own caller's
|
|
5
|
+
* input verbatim may name `ConstraintError` instead, which passes the fault on as its
|
|
6
|
+
* caller's to fix
|
|
7
|
+
*
|
|
8
|
+
* .note = a named value, never a boolean, so the call site states which class it gets
|
|
9
|
+
* (rule.require.explicit-optout)
|
|
10
|
+
* .note = `readonly`, since one default instance is shared by every call that omits the opt
|
|
11
|
+
*/
|
|
12
|
+
export interface LambdaEndpointRefusal {
|
|
13
|
+
readonly as: 'ConstraintError' | 'LambdaEndpointRefusedError';
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* .what = the refusal stance of a caller that composed its request
|
|
17
|
+
* .why = the default of every ask road: a peer's refusal is this caller's own malfunction
|
|
18
|
+
*/
|
|
19
|
+
export declare const REFUSAL_DEFAULT: LambdaEndpointRefusal;
|
|
20
|
+
/**
|
|
21
|
+
* .what = the refusal stance of a caller that forwards its own caller's input verbatim
|
|
22
|
+
* .why = the opt-in of an ask road, and the fixed stance of `runLambdaEndpoint.onSerialized`,
|
|
23
|
+
* whose caller composed the event itself
|
|
24
|
+
*/
|
|
25
|
+
export declare const REFUSAL_PASSTHROUGH: LambdaEndpointRefusal;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.REFUSAL_PASSTHROUGH = exports.REFUSAL_DEFAULT = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* .what = the refusal stance of a caller that composed its request
|
|
6
|
+
* .why = the default of every ask road: a peer's refusal is this caller's own malfunction
|
|
7
|
+
*/
|
|
8
|
+
exports.REFUSAL_DEFAULT = {
|
|
9
|
+
as: 'LambdaEndpointRefusedError',
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* .what = the refusal stance of a caller that forwards its own caller's input verbatim
|
|
13
|
+
* .why = the opt-in of an ask road, and the fixed stance of `runLambdaEndpoint.onSerialized`,
|
|
14
|
+
* whose caller composed the event itself
|
|
15
|
+
*/
|
|
16
|
+
exports.REFUSAL_PASSTHROUGH = {
|
|
17
|
+
as: 'ConstraintError',
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=LambdaEndpointRefusal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LambdaEndpointRefusal.js","sourceRoot":"","sources":["../../src/domain.objects/LambdaEndpointRefusal.ts"],"names":[],"mappings":";;;AAeA;;;GAGG;AACU,QAAA,eAAe,GAA0B;IACpD,EAAE,EAAE,4BAA4B;CACjC,CAAC;AAEF;;;;GAIG;AACU,QAAA,mBAAmB,GAA0B;IACxD,EAAE,EAAE,iBAAiB;CACtB,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { MalfunctionError } from 'helpful-errors';
|
|
2
|
+
/**
|
|
3
|
+
* .what = the metadata a `LambdaEndpointRefusedError` carries
|
|
4
|
+
* .why = helpful-errors exports no name for its metadata shape, so it is read off the parent's
|
|
5
|
+
* own constructor rather than restated
|
|
6
|
+
*/
|
|
7
|
+
export type LambdaEndpointRefusedErrorMetadata = NonNullable<ConstructorParameters<typeof MalfunctionError>[1]>;
|
|
8
|
+
/**
|
|
9
|
+
* .what = a peer endpoint refused a request this caller composed
|
|
10
|
+
* .why = a peer's `ConstraintError` / `BadRequestError` names a fault in the request the PEER
|
|
11
|
+
* received — which this caller built. so it is this caller's malfunction, never a fault
|
|
12
|
+
* its own caller can fix. thrown as the caller's own `ConstraintError`, it became a 400 to
|
|
13
|
+
* an http caller and hid from every alarm (sdk-aws-lambda#77)
|
|
14
|
+
*
|
|
15
|
+
* .note = a `MalfunctionError`, so every consumer family treats it as a server fault: an
|
|
16
|
+
* api-gateway consumer answers 500, a direct-invoke consumer fails its invocation, and an
|
|
17
|
+
* sqs consumer redrives the message. `getIsConstraintError` reads it false
|
|
18
|
+
* .note = metadata is the road's own: the invoke road names the `endpoint`; the http road names
|
|
19
|
+
* the `url` and `status`. both carry `exid` and the peer's verdict as `errorType`
|
|
20
|
+
* .note = a consumer whose call forwards its own caller's input verbatim opts into the old class
|
|
21
|
+
* per call, via `refusal: { as: 'ConstraintError' }`
|
|
22
|
+
*/
|
|
23
|
+
export declare class LambdaEndpointRefusedError extends MalfunctionError {
|
|
24
|
+
constructor(message: string, metadata: LambdaEndpointRefusedErrorMetadata);
|
|
25
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LambdaEndpointRefusedError = void 0;
|
|
4
|
+
const helpful_errors_1 = require("helpful-errors");
|
|
5
|
+
/**
|
|
6
|
+
* .what = a peer endpoint refused a request this caller composed
|
|
7
|
+
* .why = a peer's `ConstraintError` / `BadRequestError` names a fault in the request the PEER
|
|
8
|
+
* received — which this caller built. so it is this caller's malfunction, never a fault
|
|
9
|
+
* its own caller can fix. thrown as the caller's own `ConstraintError`, it became a 400 to
|
|
10
|
+
* an http caller and hid from every alarm (sdk-aws-lambda#77)
|
|
11
|
+
*
|
|
12
|
+
* .note = a `MalfunctionError`, so every consumer family treats it as a server fault: an
|
|
13
|
+
* api-gateway consumer answers 500, a direct-invoke consumer fails its invocation, and an
|
|
14
|
+
* sqs consumer redrives the message. `getIsConstraintError` reads it false
|
|
15
|
+
* .note = metadata is the road's own: the invoke road names the `endpoint`; the http road names
|
|
16
|
+
* the `url` and `status`. both carry `exid` and the peer's verdict as `errorType`
|
|
17
|
+
* .note = a consumer whose call forwards its own caller's input verbatim opts into the old class
|
|
18
|
+
* per call, via `refusal: { as: 'ConstraintError' }`
|
|
19
|
+
*/
|
|
20
|
+
class LambdaEndpointRefusedError extends helpful_errors_1.MalfunctionError {
|
|
21
|
+
constructor(message, metadata) {
|
|
22
|
+
super(message, metadata);
|
|
23
|
+
// name the class, as aws labels an escaped throw by `.name`; helpful-errors sets no name
|
|
24
|
+
this.name = 'LambdaEndpointRefusedError';
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
exports.LambdaEndpointRefusedError = LambdaEndpointRefusedError;
|
|
28
|
+
//# sourceMappingURL=LambdaEndpointRefusedError.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LambdaEndpointRefusedError.js","sourceRoot":"","sources":["../../src/domain.objects/LambdaEndpointRefusedError.ts"],"names":[],"mappings":";;;AAAA,mDAAkD;AAWlD;;;;;;;;;;;;;;GAcG;AACH,MAAa,0BAA2B,SAAQ,iCAAgB;IAC9D,YAAY,OAAe,EAAE,QAA4C;QACvE,KAAK,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;QAEzB,yFAAyF;QACzF,IAAI,CAAC,IAAI,GAAG,4BAA4B,CAAC;IAC3C,CAAC;CACF;AAPD,gEAOC"}
|
|
@@ -23,6 +23,7 @@ export declare const askLambdaEndpoint: (<TRequest, TResponse>(input: {
|
|
|
23
23
|
struct?: {
|
|
24
24
|
payload?: import("../..").LambdaEndpointDialect | undefined;
|
|
25
25
|
} | undefined;
|
|
26
|
+
refusal?: import("../..").LambdaEndpointRefusal | undefined;
|
|
26
27
|
}, context: import("../..").ContextAwsLambdaCaller & {
|
|
27
28
|
cache?: {
|
|
28
29
|
response?: import("with-simple-cache").SimpleCache<TResponse> | undefined;
|
|
@@ -38,6 +39,7 @@ export declare const askLambdaEndpoint: (<TRequest, TResponse>(input: {
|
|
|
38
39
|
struct?: {
|
|
39
40
|
payload?: import("../..").LambdaEndpointDialect | undefined;
|
|
40
41
|
} | undefined;
|
|
42
|
+
refusal?: import("../..").LambdaEndpointRefusal | undefined;
|
|
41
43
|
}, context: import("../..").ContextAwsLambdaCaller & {
|
|
42
44
|
cache?: {
|
|
43
45
|
response?: import("with-simple-cache").SimpleCache<TResponse> | undefined;
|
|
@@ -49,6 +51,7 @@ export declare const askLambdaEndpoint: (<TRequest, TResponse>(input: {
|
|
|
49
51
|
method?: string | undefined;
|
|
50
52
|
headers?: Record<string, string> | undefined;
|
|
51
53
|
body?: unknown;
|
|
54
|
+
refusal?: import("../..").LambdaEndpointRefusal | undefined;
|
|
52
55
|
}, context: import("sdk-logs").ContextLogTrail) => Promise<{
|
|
53
56
|
status: number;
|
|
54
57
|
headers: Record<string, string>;
|
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import type { ContextLogTrail } from 'sdk-logs';
|
|
2
|
+
import type { LambdaEndpointRefusal } from '../../domain.objects/LambdaEndpointRefusal';
|
|
2
3
|
/**
|
|
3
4
|
* .what = asks an api gateway endpoint over http, opted into the contemp dialect with the caller's trail
|
|
4
5
|
* .why = an aws-delivered event cannot hold a `{ event, trail }` wrapper, so the opt-in and the
|
|
5
6
|
* trail ride the request's own `x-trail-exid` header. this sends it, and casts a fault back
|
|
6
|
-
* into the throw `askLambdaEndpoint` gives, so one catch block serves both roads
|
|
7
|
+
* into the throw `askLambdaEndpoint` gives, so one catch block for a refusal serves both roads
|
|
7
8
|
* (`invariant.ancient-vs-contemp-callers.md`, `domain.terms/x-trail-exid.md`)
|
|
8
9
|
*
|
|
9
10
|
* | answer | the caller gets |
|
|
10
11
|
* |--------|-----------------|
|
|
11
12
|
* | < 400 | `{ status, headers, text, body }` — `body` is the json, or null where the answer has none |
|
|
12
|
-
* | 4xx | a thrown `ConstraintError`, with the endpoint's message |
|
|
13
|
+
* | 4xx, save 429 | a thrown `LambdaEndpointRefusedError` (or `ConstraintError`, with `refusal: { as: 'ConstraintError' }`), with the endpoint's message |
|
|
14
|
+
* | 429 | a thrown `MalfunctionError` under either opt: a throttle, not a refusal; `retry-after` rides `metadata.headers` |
|
|
13
15
|
* | 5xx | a thrown `MalfunctionError`, with the `correlationId` that finds the log line |
|
|
14
16
|
*
|
|
15
17
|
* .note = takes the standard http request — `{ url, method, headers, body }` — as fetch does, and
|
|
@@ -27,6 +29,13 @@ export declare const viaApiGateway: <TResponse = unknown>(input: {
|
|
|
27
29
|
method?: string;
|
|
28
30
|
headers?: Record<string, string>;
|
|
29
31
|
body?: unknown;
|
|
32
|
+
/**
|
|
33
|
+
* .what = the class a 4xx answer is thrown as (a 429 excepted: it is a throttle, a `MalfunctionError`)
|
|
34
|
+
* .why = this caller composed the request, so by default a refusal is this caller's own
|
|
35
|
+
* malfunction, as on the invoke road
|
|
36
|
+
* .default = { as: 'LambdaEndpointRefusedError' }
|
|
37
|
+
*/
|
|
38
|
+
refusal?: LambdaEndpointRefusal;
|
|
30
39
|
}, context: ContextLogTrail) => Promise<{
|
|
31
40
|
status: number;
|
|
32
41
|
headers: Record<string, string>;
|
|
@@ -8,18 +8,20 @@ const asHeadersRecord_1 = require("./serde/asHeadersRecord");
|
|
|
8
8
|
const asHttpMethod_1 = require("./serde/asHttpMethod");
|
|
9
9
|
const asHttpRequestBody_1 = require("./serde/asHttpRequestBody");
|
|
10
10
|
const asHttpRequestHeaders_1 = require("./serde/asHttpRequestHeaders");
|
|
11
|
+
const asLambdaEndpointRefusal_1 = require("./serde/asLambdaEndpointRefusal");
|
|
11
12
|
const getOneBodyFromHttpText_1 = require("./serde/getOneBodyFromHttpText");
|
|
12
13
|
/**
|
|
13
14
|
* .what = asks an api gateway endpoint over http, opted into the contemp dialect with the caller's trail
|
|
14
15
|
* .why = an aws-delivered event cannot hold a `{ event, trail }` wrapper, so the opt-in and the
|
|
15
16
|
* trail ride the request's own `x-trail-exid` header. this sends it, and casts a fault back
|
|
16
|
-
* into the throw `askLambdaEndpoint` gives, so one catch block serves both roads
|
|
17
|
+
* into the throw `askLambdaEndpoint` gives, so one catch block for a refusal serves both roads
|
|
17
18
|
* (`invariant.ancient-vs-contemp-callers.md`, `domain.terms/x-trail-exid.md`)
|
|
18
19
|
*
|
|
19
20
|
* | answer | the caller gets |
|
|
20
21
|
* |--------|-----------------|
|
|
21
22
|
* | < 400 | `{ status, headers, text, body }` — `body` is the json, or null where the answer has none |
|
|
22
|
-
* | 4xx | a thrown `ConstraintError`, with the endpoint's message |
|
|
23
|
+
* | 4xx, save 429 | a thrown `LambdaEndpointRefusedError` (or `ConstraintError`, with `refusal: { as: 'ConstraintError' }`), with the endpoint's message |
|
|
24
|
+
* | 429 | a thrown `MalfunctionError` under either opt: a throttle, not a refusal; `retry-after` rides `metadata.headers` |
|
|
23
25
|
* | 5xx | a thrown `MalfunctionError`, with the `correlationId` that finds the log line |
|
|
24
26
|
*
|
|
25
27
|
* .note = takes the standard http request — `{ url, method, headers, body }` — as fetch does, and
|
|
@@ -33,6 +35,8 @@ const getOneBodyFromHttpText_1 = require("./serde/getOneBodyFromHttpText");
|
|
|
33
35
|
* dependency, and sets no timeout: fetch waits as long as the endpoint does
|
|
34
36
|
*/
|
|
35
37
|
const viaApiGateway = async (input, context) => {
|
|
38
|
+
// refuse an unknown refusal opt before any request is sent
|
|
39
|
+
const refusal = (0, asLambdaEndpointRefusal_1.asLambdaEndpointRefusal)({ declared: input.refusal });
|
|
36
40
|
// the caller's exid, or a generated one — the same call `askLambdaEndpoint` makes
|
|
37
41
|
const exid = (0, getOneTrailExid_1.getOneTrailExid)({ log: context.log });
|
|
38
42
|
// send the request, opted in by the trail header
|
|
@@ -60,6 +64,7 @@ const viaApiGateway = async (input, context) => {
|
|
|
60
64
|
headers,
|
|
61
65
|
url: input.url,
|
|
62
66
|
exid,
|
|
67
|
+
refusal,
|
|
63
68
|
});
|
|
64
69
|
if (error)
|
|
65
70
|
throw error;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"askLambdaEndpoint.viaApiGateway.js","sourceRoot":"","sources":["../../../src/domain.operations/askLambdaEndpoint/askLambdaEndpoint.viaApiGateway.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"askLambdaEndpoint.viaApiGateway.js","sourceRoot":"","sources":["../../../src/domain.operations/askLambdaEndpoint/askLambdaEndpoint.viaApiGateway.ts"],"names":[],"mappings":";;;AAGA,mFAAgF;AAChF,oEAAiE;AACjE,6EAA0E;AAC1E,6DAA0D;AAC1D,uDAAoD;AACpD,iEAA8D;AAC9D,uEAAoE;AACpE,6EAA0E;AAC1E,2EAAwE;AAExE;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACI,MAAM,aAAa,GAAG,KAAK,EAChC,KAYC,EACD,OAAwB,EAMvB,EAAE;IACH,2DAA2D;IAC3D,MAAM,OAAO,GAAG,IAAA,iDAAuB,EAAC,EAAE,QAAQ,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;IAErE,kFAAkF;IAClF,MAAM,IAAI,GAAG,IAAA,iCAAe,EAAC,EAAE,GAAG,EAAE,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;IAEnD,iDAAiD;IACjD,MAAM,OAAO,GAAG,IAAA,qCAAiB,EAAC,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC;IACxD,MAAM,QAAQ,GAAG,MAAM,IAAA,uCAAkB,EAAC;QACxC,GAAG,EAAE,KAAK,CAAC,GAAG;QACd,MAAM,EAAE,IAAA,2BAAY,EAAC,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,CAAC;QAChE,OAAO,EAAE,IAAA,2CAAoB,EAAC;YAC5B,WAAW,EAAE,OAAO,CAAC,WAAW;YAChC,OAAO,EAAE,KAAK,CAAC,OAAO;YACtB,KAAK,EAAE,EAAE,IAAI,EAAE;SAChB,CAAC;QACF,IAAI,EAAE,OAAO,CAAC,IAAI;QAClB,IAAI;KACL,CAAC,CAAC;IAEH,uEAAuE;IACvE,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;IACnC,MAAM,IAAI,GAAG,IAAA,+CAAsB,EAAC,EAAE,IAAI,EAAE,CAAC,CAAC;IAE9C,6DAA6D;IAC7D,MAAM,OAAO,GAAG,IAAA,iCAAe,EAAC,EAAE,OAAO,EAAE,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC;IAC/D,MAAM,KAAK,GAAG,IAAA,iDAAuB,EAAC;QACpC,MAAM,EAAE,QAAQ,CAAC,MAAM;QACvB,IAAI;QACJ,IAAI;QACJ,OAAO;QACP,GAAG,EAAE,KAAK,CAAC,GAAG;QACd,IAAI;QACJ,OAAO;KACR,CAAC,CAAC;IACH,IAAI,KAAK;QAAE,MAAM,KAAK,CAAC;IAEvB;;;;;OAKG;IACH,OAAO;QACL,MAAM,EAAE,QAAQ,CAAC,MAAM;QACvB,OAAO;QACP,IAAI;QACJ,IAAI,EAAE,IAAwB;KAC/B,CAAC;AACJ,CAAC,CAAC;AAtEW,QAAA,aAAa,iBAsExB"}
|
|
@@ -2,6 +2,7 @@ import type { SimpleInMemoryCache } from 'simple-in-memory-cache';
|
|
|
2
2
|
import type { SimpleCache } from 'with-simple-cache';
|
|
3
3
|
import type { ContextAwsLambdaCaller } from '../../domain.objects/ContextAwsLambdaCaller';
|
|
4
4
|
import type { LambdaEndpointDialect } from '../../domain.objects/LambdaEndpointDialect';
|
|
5
|
+
import type { LambdaEndpointRefusal } from '../../domain.objects/LambdaEndpointRefusal';
|
|
5
6
|
/**
|
|
6
7
|
* .what = invokes a lambda endpoint with trail propagation, over the aws lambda invoke api
|
|
7
8
|
* .why = enables service-to-service calls with observability
|
|
@@ -29,6 +30,15 @@ export declare const viaInvoke: <TRequest, TResponse>(input: {
|
|
|
29
30
|
*/
|
|
30
31
|
payload?: LambdaEndpointDialect;
|
|
31
32
|
};
|
|
33
|
+
/**
|
|
34
|
+
* .what = the class a peer's refusal (its ConstraintError / BadRequestError) is thrown as
|
|
35
|
+
* .why = this caller composed the request, so by default a refusal is this caller's own
|
|
36
|
+
* malfunction — an api-gateway caller answers 500, never a 400 its caller cannot fix
|
|
37
|
+
* .default = { as: 'LambdaEndpointRefusedError' }
|
|
38
|
+
* .note = name `{ as: 'ConstraintError' }` only where the request forwards your own caller's
|
|
39
|
+
* input verbatim, so the fault truly is theirs to fix
|
|
40
|
+
*/
|
|
41
|
+
refusal?: LambdaEndpointRefusal;
|
|
32
42
|
}, context: ContextAwsLambdaCaller & {
|
|
33
43
|
cache?: {
|
|
34
44
|
response?: SimpleCache<TResponse>;
|
|
@@ -4,8 +4,10 @@ exports.viaInvoke = void 0;
|
|
|
4
4
|
const genLambdaSdk_1 = require("../../access/sdks/lambda/genLambdaSdk");
|
|
5
5
|
const asLambdaEndpoint_1 = require("../asLambdaEndpoint/asLambdaEndpoint");
|
|
6
6
|
const getOneTrailExid_1 = require("../lambdaEndpointWire/context/getOneTrailExid");
|
|
7
|
+
const asAskLambdaCacheKeyOfRefusal_1 = require("./cache/asAskLambdaCacheKeyOfRefusal");
|
|
7
8
|
const asCachedExecutor_1 = require("./cache/asCachedExecutor");
|
|
8
9
|
const getAskLambdaCacheKey_1 = require("./cache/getAskLambdaCacheKey");
|
|
10
|
+
const asLambdaEndpointRefusal_1 = require("./serde/asLambdaEndpointRefusal");
|
|
9
11
|
const getLambdaPayload_1 = require("./serde/getLambdaPayload");
|
|
10
12
|
/**
|
|
11
13
|
* .what = invokes a lambda endpoint with trail propagation, over the aws lambda invoke api
|
|
@@ -17,6 +19,8 @@ const getLambdaPayload_1 = require("./serde/getLambdaPayload");
|
|
|
17
19
|
* .note = use struct: 'ancient' for handlers that don't understand wrapped payloads
|
|
18
20
|
*/
|
|
19
21
|
const viaInvoke = async (input, context) => {
|
|
22
|
+
// refuse an unknown refusal opt before any invoke is sent
|
|
23
|
+
const refusal = (0, asLambdaEndpointRefusal_1.asLambdaEndpointRefusal)({ declared: input.refusal });
|
|
20
24
|
// extract or generate the trail exid, and report the fallback if one was made.
|
|
21
25
|
// shared with `runLambdaEndpoint.onSerialized` so the two loci cannot diverge
|
|
22
26
|
// on the diagnostic — see `getOneTrailExid` for why that parity is structural
|
|
@@ -48,15 +52,23 @@ const viaInvoke = async (input, context) => {
|
|
|
48
52
|
env: { region: context.env.region },
|
|
49
53
|
});
|
|
50
54
|
// prepare invocation input + context
|
|
51
|
-
const invocationInput = {
|
|
55
|
+
const invocationInput = {
|
|
56
|
+
endpoint,
|
|
57
|
+
payload,
|
|
58
|
+
exid,
|
|
59
|
+
refusal,
|
|
60
|
+
};
|
|
52
61
|
const invocationContext = {
|
|
53
62
|
sdkLambda,
|
|
54
63
|
log: context.log,
|
|
55
64
|
};
|
|
56
|
-
// build cache key generator
|
|
57
|
-
const getCacheKey = () => (0,
|
|
58
|
-
|
|
59
|
-
|
|
65
|
+
// build cache key generator; a pass-through ask never shares a key with a default ask
|
|
66
|
+
const getCacheKey = () => (0, asAskLambdaCacheKeyOfRefusal_1.asAskLambdaCacheKeyOfRefusal)({
|
|
67
|
+
key: (0, getAskLambdaCacheKey_1.getAskLambdaCacheKey)({
|
|
68
|
+
endpoint,
|
|
69
|
+
event: input.event,
|
|
70
|
+
}),
|
|
71
|
+
refusal,
|
|
60
72
|
});
|
|
61
73
|
// get executor with cache wrapper
|
|
62
74
|
const execute = (0, asCachedExecutor_1.asCachedExecutor)({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"askLambdaEndpoint.viaInvoke.js","sourceRoot":"","sources":["../../../src/domain.operations/askLambdaEndpoint/askLambdaEndpoint.viaInvoke.ts"],"names":[],"mappings":";;;AAGA,wEAAqE;
|
|
1
|
+
{"version":3,"file":"askLambdaEndpoint.viaInvoke.js","sourceRoot":"","sources":["../../../src/domain.operations/askLambdaEndpoint/askLambdaEndpoint.viaInvoke.ts"],"names":[],"mappings":";;;AAGA,wEAAqE;AAIrE,2EAAwE;AACxE,mFAAgF;AAChF,uFAAoF;AACpF,+DAA4D;AAC5D,uEAAoE;AAKpE,6EAA0E;AAC1E,+DAA4D;AAE5D;;;;;;;;GAQG;AACI,MAAM,SAAS,GAAG,KAAK,EAC5B,KA2BC,EACD,OAKC,EACmB,EAAE;IACtB,0DAA0D;IAC1D,MAAM,OAAO,GAAG,IAAA,iDAAuB,EAAC,EAAE,QAAQ,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;IAErE,+EAA+E;IAC/E,8EAA8E;IAC9E,8EAA8E;IAC9E,yBAAyB;IACzB,MAAM,IAAI,GAAG,IAAA,iCAAe,EAAC,EAAE,GAAG,EAAE,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;IAEnD,wEAAwE;IACxE,MAAM,QAAQ,GAAG,IAAA,mCAAgB,EAAC;QAChC,OAAO,EAAE,KAAK,CAAC,KAAK,CAAC,OAAO;QAC5B,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,MAAM;QAC1B,QAAQ,EAAE,KAAK,CAAC,KAAK,CAAC,QAAQ;KAC/B,CAAC,CAAC;IAEH,6EAA6E;IAC7E,EAAE;IACF,+EAA+E;IAC/E,gFAAgF;IAChF,8EAA8E;IAC9E,2EAA2E;IAC3E,4DAA4D;IAC5D,EAAE;IACF,+EAA+E;IAC/E,iFAAiF;IACjF,MAAM,eAAe,GAAG,KAAK,CAAC,MAAM,EAAE,OAAO,IAAI,SAAS,CAAC;IAC3D,MAAM,OAAO,GACX,eAAe,KAAK,SAAS;QAC3B,CAAC,CAAC,IAAA,mCAAgB,EAAC,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,EAAE,CAAC;QAC3D,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC;IAElB,6BAA6B;IAC7B,MAAM,SAAS,GAAG,IAAA,2BAAY,EAAC;QAC7B,GAAG,EAAE,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG;QAC7B,GAAG,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE;KACpC,CAAC,CAAC;IAEH,qCAAqC;IACrC,MAAM,eAAe,GAAoB;QACvC,QAAQ;QACR,OAAO;QACP,IAAI;QACJ,OAAO;KACR,CAAC;IACF,MAAM,iBAAiB,GAAsB;QAC3C,SAAS;QACT,GAAG,EAAE,OAAO,CAAC,GAAG;KACjB,CAAC;IAEF,sFAAsF;IACtF,MAAM,WAAW,GAAG,GAAW,EAAE,CAC/B,IAAA,2DAA4B,EAAC;QAC3B,GAAG,EAAE,IAAA,2CAAoB,EAAC;YACxB,QAAQ;YACR,KAAK,EAAE,KAAK,CAAC,KAAgC;SAC9C,CAAC;QACF,OAAO;KACR,CAAC,CAAC;IAEL,kCAAkC;IAClC,MAAM,OAAO,GAAG,IAAA,mCAAgB,EAAY;QAC1C,GAAG,OAAO,CAAC,KAAK;QAChB,WAAW;KACZ,CAAC,CAAC;IAEH,qBAAqB;IACrB,OAAO,OAAO,CAAC,eAAe,EAAE,iBAAiB,CAAC,CAAC;AACrD,CAAC,CAAC;AAxGW,QAAA,SAAS,aAwGpB"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { LambdaEndpointRefusal } from '../../../domain.objects/LambdaEndpointRefusal';
|
|
2
|
+
/**
|
|
3
|
+
* .what = the cache key of one ask, under the refusal opt it was asked with
|
|
4
|
+
* .why = the dedupe cache shares one in-flight promise per key, and a rejection's class depends on
|
|
5
|
+
* the opt. so a pass-through ask must never share a key with a default ask, or a caller
|
|
6
|
+
* could catch the class the other caller asked for (sdk-aws-lambda#77)
|
|
7
|
+
*
|
|
8
|
+
* .note = the default opt keeps the key it had before the opt existed, so the public
|
|
9
|
+
* `getAskLambdaCacheKey` and every extant cached entry stay as they were
|
|
10
|
+
* .note = the cost: a pass-through ask no longer shares a cached success with a default ask of
|
|
11
|
+
* the same event. a class-neutral throw cast at the `viaInvoke` boundary would keep those
|
|
12
|
+
* hits, but needs a marker that tells a peer refusal from a local `ConstraintError`
|
|
13
|
+
*/
|
|
14
|
+
export declare const asAskLambdaCacheKeyOfRefusal: (input: {
|
|
15
|
+
key: string;
|
|
16
|
+
refusal: LambdaEndpointRefusal;
|
|
17
|
+
}) => string;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.asAskLambdaCacheKeyOfRefusal = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* .what = the cache key of one ask, under the refusal opt it was asked with
|
|
6
|
+
* .why = the dedupe cache shares one in-flight promise per key, and a rejection's class depends on
|
|
7
|
+
* the opt. so a pass-through ask must never share a key with a default ask, or a caller
|
|
8
|
+
* could catch the class the other caller asked for (sdk-aws-lambda#77)
|
|
9
|
+
*
|
|
10
|
+
* .note = the default opt keeps the key it had before the opt existed, so the public
|
|
11
|
+
* `getAskLambdaCacheKey` and every extant cached entry stay as they were
|
|
12
|
+
* .note = the cost: a pass-through ask no longer shares a cached success with a default ask of
|
|
13
|
+
* the same event. a class-neutral throw cast at the `viaInvoke` boundary would keep those
|
|
14
|
+
* hits, but needs a marker that tells a peer refusal from a local `ConstraintError`
|
|
15
|
+
*/
|
|
16
|
+
const asAskLambdaCacheKeyOfRefusal = (input) => {
|
|
17
|
+
if (input.refusal.as === 'LambdaEndpointRefusedError')
|
|
18
|
+
return input.key;
|
|
19
|
+
return `${input.key}::refusal=${input.refusal.as}`;
|
|
20
|
+
};
|
|
21
|
+
exports.asAskLambdaCacheKeyOfRefusal = asAskLambdaCacheKeyOfRefusal;
|
|
22
|
+
//# sourceMappingURL=asAskLambdaCacheKeyOfRefusal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"asAskLambdaCacheKeyOfRefusal.js","sourceRoot":"","sources":["../../../../src/domain.operations/askLambdaEndpoint/cache/asAskLambdaCacheKeyOfRefusal.ts"],"names":[],"mappings":";;;AAEA;;;;;;;;;;;GAWG;AACI,MAAM,4BAA4B,GAAG,CAAC,KAG5C,EAAU,EAAE;IACX,IAAI,KAAK,CAAC,OAAO,CAAC,EAAE,KAAK,4BAA4B;QAAE,OAAO,KAAK,CAAC,GAAG,CAAC;IACxE,OAAO,GAAG,KAAK,CAAC,GAAG,aAAa,KAAK,CAAC,OAAO,CAAC,EAAE,EAAE,CAAC;AACrD,CAAC,CAAC;AANW,QAAA,4BAA4B,gCAMvC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { LambdaClient } from '@aws-sdk/client-lambda';
|
|
2
2
|
import type { LambdaEndpoint } from '../../../domain.objects/LambdaEndpoint';
|
|
3
|
+
import type { LambdaEndpointRefusal } from '../../../domain.objects/LambdaEndpointRefusal';
|
|
3
4
|
/**
|
|
4
5
|
* .what = minimal log interface for lambda invocation
|
|
5
6
|
* .why = accepts console, sdk-logs LogMethods, or any object with debug method
|
|
@@ -15,6 +16,7 @@ export type InvocationInput = {
|
|
|
15
16
|
endpoint: LambdaEndpoint;
|
|
16
17
|
payload: unknown;
|
|
17
18
|
exid: string;
|
|
19
|
+
refusal: LambdaEndpointRefusal;
|
|
18
20
|
};
|
|
19
21
|
/**
|
|
20
22
|
* .what = invocation context for lambda execution
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"executeLambdaInvocation.js","sourceRoot":"","sources":["../../../../src/domain.operations/askLambdaEndpoint/invoke/executeLambdaInvocation.ts"],"names":[],"mappings":";;;AAEA,iFAA8E;AAE9E,qFAAkF;
|
|
1
|
+
{"version":3,"file":"executeLambdaInvocation.js","sourceRoot":"","sources":["../../../../src/domain.operations/askLambdaEndpoint/invoke/executeLambdaInvocation.ts"],"names":[],"mappings":";;;AAEA,iFAA8E;AAE9E,qFAAkF;AAElF,kFAA+E;AAC/E,kEAA+D;AA8B/D;;;GAGG;AACI,MAAM,uBAAuB,GAAG,KAAK,EAC1C,KAAsB,EACtB,OAA0B,EACN,EAAE;IACtB,iBAAiB;IACjB,OAAO,CAAC,GAAG,EAAE,KAAK,CAAC,0BAA0B,EAAE;QAC7C,IAAI,EAAE,KAAK,CAAC,QAAQ,CAAC,IAAI;QACzB,IAAI,EAAE,KAAK,CAAC,IAAI;KACjB,CAAC,CAAC;IAEH,iCAAiC;IACjC,8EAA8E;IAC9E,iFAAiF;IACjF,gEAAgE;IAChE,uDAAuD;IACvD,MAAM,MAAM,GAAG,MAAM,IAAA,iCAAe,EAClC,EAAE,IAAI,EAAE,KAAK,CAAC,QAAQ,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,EACrD,EAAE,SAAS,EAAE,OAAO,CAAC,SAAS,EAAE,CACjC,CAAC,KAAK,CAAC,CAAC,KAAc,EAAE,EAAE;QACzB,sCAAsC;QACtC,IAAI,CAAC,CAAC,KAAK,YAAY,KAAK,CAAC;YAAE,MAAM,KAAK,CAAC;QAE3C,+DAA+D;QAC/D,MAAM,IAAI,yCAAmB,CAAC,4BAA4B,KAAK,CAAC,OAAO,EAAE,EAAE;YACzE,QAAQ,EAAE,KAAK,CAAC,QAAQ;YACxB,IAAI,EAAE,KAAK,CAAC,IAAI;YAChB,KAAK,EAAE,KAAK;SACb,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,gFAAgF;IAChF,6EAA6E;IAC7E,MAAM,UAAU,GAAG,MAAM,CAAC,UAAU,IAAI,CAAC,CAAC;IAC1C,IAAI,UAAU,KAAK,GAAG,EAAE,CAAC;QACvB,0DAA0D;QAC1D,MAAM,UAAU,GAAG,IAAA,qCAAiB,EAAC,UAAU,CAAC,CAAC;QACjD,MAAM,IAAI,yCAAmB,CAAC,6BAA6B,UAAU,EAAE,EAAE;YACvE,QAAQ,EAAE,KAAK,CAAC,QAAQ;YACxB,IAAI,EAAE,KAAK,CAAC,IAAI;YAChB,UAAU;SACX,CAAC,CAAC;IACL,CAAC;IAED,iBAAiB;IACjB,MAAM,QAAQ,GAAG,IAAA,qCAAiB,EAAY;QAC5C,OAAO,EAAE,MAAM,CAAC,OAAO;QACvB,aAAa,EAAE,MAAM,CAAC,aAAa;QACnC,QAAQ,EAAE,KAAK,CAAC,QAAQ;QACxB,IAAI,EAAE,KAAK,CAAC,IAAI;QAChB,OAAO,EAAE,KAAK,CAAC,OAAO;KACvB,CAAC,CAAC;IAEH,aAAa;IACb,OAAO,CAAC,GAAG,EAAE,KAAK,CAAC,0BAA0B,EAAE;QAC7C,IAAI,EAAE,KAAK,CAAC,QAAQ,CAAC,IAAI;QACzB,UAAU,EAAE,MAAM,CAAC,UAAU;KAC9B,CAAC,CAAC;IAEH,OAAO,QAAQ,CAAC;AAClB,CAAC,CAAC;AA3DW,QAAA,uBAAuB,2BA2DlC"}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import { ConstraintError, MalfunctionError } from 'helpful-errors';
|
|
1
|
+
import { type ConstraintError, MalfunctionError } from 'helpful-errors';
|
|
2
|
+
import type { LambdaEndpointRefusal } from '../../../domain.objects/LambdaEndpointRefusal';
|
|
3
|
+
import type { LambdaEndpointRefusedError } from '../../../domain.objects/LambdaEndpointRefusedError';
|
|
2
4
|
/**
|
|
3
5
|
* .what = casts an http response into the error a caller should throw, or null for a success
|
|
4
6
|
* .why = an api gateway endpoint answers a fault as a RETURNED http response, never a lambda error
|
|
@@ -8,7 +10,8 @@ import { ConstraintError, MalfunctionError } from 'helpful-errors';
|
|
|
8
10
|
* | status | the error | because |
|
|
9
11
|
* |--------|-----------|---------|
|
|
10
12
|
* | < 400 | none | a success. a redirect is followed by fetch by default, so a 3xx seldom arrives here |
|
|
11
|
-
* | 4xx | `ConstraintError` |
|
|
13
|
+
* | 4xx, save 429 | the `refusal` class: `LambdaEndpointRefusedError` by default, `ConstraintError` on opt-in | this caller composed the request, so the refusal is its own malfunction — unless it forwards its own caller's input |
|
|
14
|
+
* | 429 | `MalfunctionError`, under either opt | a throttle, not a refusal: the same request succeeds after `retry-after` |
|
|
12
15
|
* | 5xx | `MalfunctionError` | the endpoint must fix itself; its `correlationId` finds the log line |
|
|
13
16
|
*
|
|
14
17
|
* .note = the message comes from the body's contemp envelope when it has one, else from the
|
|
@@ -18,8 +21,8 @@ import { ConstraintError, MalfunctionError } from 'helpful-errors';
|
|
|
18
21
|
* .note = the raw answer text rides the error metadata, cut to a bound, so a message no arm reads
|
|
19
22
|
* (an old endpoint's flat body, a proxy's html page) is never lost to the caller. it is null
|
|
20
23
|
* where the message came from the contemp envelope, which is the text already. the
|
|
21
|
-
* response headers ride it too, so a
|
|
22
|
-
*
|
|
24
|
+
* response headers ride it too, so a throttle's `retry-after` can be read from the thrown
|
|
25
|
+
* error
|
|
23
26
|
*/
|
|
24
27
|
export declare const asErrorFromHttpResponse: (input: {
|
|
25
28
|
status: number;
|
|
@@ -28,4 +31,5 @@ export declare const asErrorFromHttpResponse: (input: {
|
|
|
28
31
|
headers: Record<string, string>;
|
|
29
32
|
url: string;
|
|
30
33
|
exid: string;
|
|
31
|
-
|
|
34
|
+
refusal: LambdaEndpointRefusal;
|
|
35
|
+
}) => ConstraintError | LambdaEndpointRefusedError | MalfunctionError | null;
|
|
@@ -3,8 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.asErrorFromHttpResponse = void 0;
|
|
4
4
|
const helpful_errors_1 = require("helpful-errors");
|
|
5
5
|
const HttpStatusCode_1 = require("../../../domain.objects/HttpStatusCode");
|
|
6
|
+
const asErrorFromPeerRefusal_1 = require("../../lambdaEndpointWire/error/asErrorFromPeerRefusal");
|
|
6
7
|
const getIsLambdaErrorResponse_1 = require("../../lambdaEndpointWire/error/getIsLambdaErrorResponse");
|
|
7
8
|
const asUnprefixedErrorMessage_1 = require("../../lambdaEndpointWire/serde/asUnprefixedErrorMessage");
|
|
9
|
+
const getIsHttpThrottle_1 = require("./getIsHttpThrottle");
|
|
8
10
|
const getOneCorrelationIdFromBody_1 = require("./getOneCorrelationIdFromBody");
|
|
9
11
|
const ERROR_TEXT_LENGTH_MAX = 1000;
|
|
10
12
|
/**
|
|
@@ -16,7 +18,8 @@ const ERROR_TEXT_LENGTH_MAX = 1000;
|
|
|
16
18
|
* | status | the error | because |
|
|
17
19
|
* |--------|-----------|---------|
|
|
18
20
|
* | < 400 | none | a success. a redirect is followed by fetch by default, so a 3xx seldom arrives here |
|
|
19
|
-
* | 4xx | `ConstraintError` |
|
|
21
|
+
* | 4xx, save 429 | the `refusal` class: `LambdaEndpointRefusedError` by default, `ConstraintError` on opt-in | this caller composed the request, so the refusal is its own malfunction — unless it forwards its own caller's input |
|
|
22
|
+
* | 429 | `MalfunctionError`, under either opt | a throttle, not a refusal: the same request succeeds after `retry-after` |
|
|
20
23
|
* | 5xx | `MalfunctionError` | the endpoint must fix itself; its `correlationId` finds the log line |
|
|
21
24
|
*
|
|
22
25
|
* .note = the message comes from the body's contemp envelope when it has one, else from the
|
|
@@ -26,14 +29,18 @@ const ERROR_TEXT_LENGTH_MAX = 1000;
|
|
|
26
29
|
* .note = the raw answer text rides the error metadata, cut to a bound, so a message no arm reads
|
|
27
30
|
* (an old endpoint's flat body, a proxy's html page) is never lost to the caller. it is null
|
|
28
31
|
* where the message came from the contemp envelope, which is the text already. the
|
|
29
|
-
* response headers ride it too, so a
|
|
30
|
-
*
|
|
32
|
+
* response headers ride it too, so a throttle's `retry-after` can be read from the thrown
|
|
33
|
+
* error
|
|
31
34
|
*/
|
|
32
35
|
const asErrorFromHttpResponse = (input) => {
|
|
33
36
|
if (input.status < HttpStatusCode_1.HttpStatusCode.BAD_REQUEST_400)
|
|
34
37
|
return null;
|
|
35
|
-
|
|
36
|
-
|
|
38
|
+
// the envelope, resolved once: every field below reads it, or the status where there is none
|
|
39
|
+
const envelope = (0, getIsLambdaErrorResponse_1.getIsContempErrorResponse)(input.body)
|
|
40
|
+
? input.body.error
|
|
41
|
+
: null;
|
|
42
|
+
const message = envelope
|
|
43
|
+
? (0, asUnprefixedErrorMessage_1.asUnprefixedErrorMessage)({ message: envelope.message })
|
|
37
44
|
: `the endpoint answered http ${input.status}`;
|
|
38
45
|
const metadata = {
|
|
39
46
|
url: input.url,
|
|
@@ -42,13 +49,24 @@ const asErrorFromHttpResponse = (input) => {
|
|
|
42
49
|
correlationId: (0, getOneCorrelationIdFromBody_1.getOneCorrelationIdFromBody)({ body: input.body }),
|
|
43
50
|
// the raw text rides only where the message did not come from it: an envelope's message is
|
|
44
51
|
// the text already, and a second copy would bury the fix a person reads first
|
|
45
|
-
text: (0,
|
|
46
|
-
? null
|
|
47
|
-
: input.text.slice(0, ERROR_TEXT_LENGTH_MAX),
|
|
52
|
+
text: envelope ? null : input.text.slice(0, ERROR_TEXT_LENGTH_MAX),
|
|
48
53
|
headers: input.headers,
|
|
49
54
|
};
|
|
55
|
+
// a 429: a throttle, not a refusal — the same request succeeds after `retry-after`, so it is a
|
|
56
|
+
// server fault under either opt, its headers kept for the retry (`domain.terms/refusal.md`)
|
|
57
|
+
if ((0, getIsHttpThrottle_1.getIsHttpThrottle)({ status: input.status }))
|
|
58
|
+
return new helpful_errors_1.MalfunctionError(message, metadata);
|
|
59
|
+
// any other 4xx: the endpoint refused the request this caller composed; the opt names the class
|
|
60
|
+
// .note = the peer's verdict is its envelope's class where it sent one, else the status alone
|
|
50
61
|
if (input.status < HttpStatusCode_1.HttpStatusCode.INTERNAL_SERVER_ERROR_500)
|
|
51
|
-
return
|
|
62
|
+
return (0, asErrorFromPeerRefusal_1.asErrorFromPeerRefusal)({
|
|
63
|
+
refusal: input.refusal,
|
|
64
|
+
peer: input.url,
|
|
65
|
+
message,
|
|
66
|
+
errorType: envelope ? envelope.class : `http ${input.status}`,
|
|
67
|
+
metadata,
|
|
68
|
+
});
|
|
69
|
+
// a 5xx: the endpoint must fix itself
|
|
52
70
|
return new helpful_errors_1.MalfunctionError(message, metadata);
|
|
53
71
|
};
|
|
54
72
|
exports.asErrorFromHttpResponse = asErrorFromHttpResponse;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"asErrorFromHttpResponse.js","sourceRoot":"","sources":["../../../../src/domain.operations/askLambdaEndpoint/serde/asErrorFromHttpResponse.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"asErrorFromHttpResponse.js","sourceRoot":"","sources":["../../../../src/domain.operations/askLambdaEndpoint/serde/asErrorFromHttpResponse.ts"],"names":[],"mappings":";;;AAAA,mDAAwE;AAExE,2EAAwE;AAGxE,kGAA+F;AAC/F,sGAAoG;AACpG,sGAAmG;AACnG,2DAAwD;AACxD,+EAA4E;AAE5E,MAAM,qBAAqB,GAAG,IAAI,CAAC;AAEnC;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACI,MAAM,uBAAuB,GAAG,CAAC,KAQvC,EAA0E,EAAE;IAC3E,IAAI,KAAK,CAAC,MAAM,GAAG,+BAAc,CAAC,eAAe;QAAE,OAAO,IAAI,CAAC;IAE/D,6FAA6F;IAC7F,MAAM,QAAQ,GAAG,IAAA,oDAAyB,EAAC,KAAK,CAAC,IAAI,CAAC;QACpD,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK;QAClB,CAAC,CAAC,IAAI,CAAC;IACT,MAAM,OAAO,GAAG,QAAQ;QACtB,CAAC,CAAC,IAAA,mDAAwB,EAAC,EAAE,OAAO,EAAE,QAAQ,CAAC,OAAO,EAAE,CAAC;QACzD,CAAC,CAAC,8BAA8B,KAAK,CAAC,MAAM,EAAE,CAAC;IAEjD,MAAM,QAAQ,GAAG;QACf,GAAG,EAAE,KAAK,CAAC,GAAG;QACd,MAAM,EAAE,KAAK,CAAC,MAAM;QACpB,IAAI,EAAE,KAAK,CAAC,IAAI;QAChB,aAAa,EAAE,IAAA,yDAA2B,EAAC,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,CAAC;QAChE,2FAA2F;QAC3F,8EAA8E;QAC9E,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,qBAAqB,CAAC;QAClE,OAAO,EAAE,KAAK,CAAC,OAAO;KACvB,CAAC;IAEF,+FAA+F;IAC/F,4FAA4F;IAC5F,IAAI,IAAA,qCAAiB,EAAC,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,CAAC;QAC7C,OAAO,IAAI,iCAAgB,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IAEjD,gGAAgG;IAChG,8FAA8F;IAC9F,IAAI,KAAK,CAAC,MAAM,GAAG,+BAAc,CAAC,yBAAyB;QACzD,OAAO,IAAA,+CAAsB,EAAC;YAC5B,OAAO,EAAE,KAAK,CAAC,OAAO;YACtB,IAAI,EAAE,KAAK,CAAC,GAAG;YACf,OAAO;YACP,SAAS,EAAE,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,QAAQ,KAAK,CAAC,MAAM,EAAE;YAC7D,QAAQ;SACT,CAAC,CAAC;IAEL,sCAAsC;IACtC,OAAO,IAAI,iCAAgB,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;AACjD,CAAC,CAAC;AAhDW,QAAA,uBAAuB,2BAgDlC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type LambdaEndpointRefusal } from '../../../domain.objects/LambdaEndpointRefusal';
|
|
2
|
+
/**
|
|
3
|
+
* .what = casts a declared `refusal` opt into one this sdk can honor, and refuses any other
|
|
4
|
+
* .why = the cast branches on one literal, so a typo or a config-driven value
|
|
5
|
+
* (`{ as: 'constraintError' }`) would fall to the default class, and the thrown message
|
|
6
|
+
* would then tell the caller to set the very opt they believe they set. a published sdk
|
|
7
|
+
* boundary is validated at runtime or it is not validated (rule.forbid.unexpected-defaults),
|
|
8
|
+
* as `asLambdaEndpointDialect` does for its peer field
|
|
9
|
+
*
|
|
10
|
+
* .note = refused at the ask, before any request is sent, so a bad opt fails on the first call —
|
|
11
|
+
* never only on the first peer refusal, which may come weeks later
|
|
12
|
+
*/
|
|
13
|
+
export declare const asLambdaEndpointRefusal: (input: {
|
|
14
|
+
declared?: unknown;
|
|
15
|
+
}) => LambdaEndpointRefusal;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.asLambdaEndpointRefusal = void 0;
|
|
4
|
+
const helpful_errors_1 = require("helpful-errors");
|
|
5
|
+
const LambdaEndpointRefusal_1 = require("../../../domain.objects/LambdaEndpointRefusal");
|
|
6
|
+
/**
|
|
7
|
+
* .what = casts a declared `refusal` opt into one this sdk can honor, and refuses any other
|
|
8
|
+
* .why = the cast branches on one literal, so a typo or a config-driven value
|
|
9
|
+
* (`{ as: 'constraintError' }`) would fall to the default class, and the thrown message
|
|
10
|
+
* would then tell the caller to set the very opt they believe they set. a published sdk
|
|
11
|
+
* boundary is validated at runtime or it is not validated (rule.forbid.unexpected-defaults),
|
|
12
|
+
* as `asLambdaEndpointDialect` does for its peer field
|
|
13
|
+
*
|
|
14
|
+
* .note = refused at the ask, before any request is sent, so a bad opt fails on the first call —
|
|
15
|
+
* never only on the first peer refusal, which may come weeks later
|
|
16
|
+
*/
|
|
17
|
+
const asLambdaEndpointRefusal = (input) => {
|
|
18
|
+
// absent is legal: the asker composed the request
|
|
19
|
+
if (input.declared === undefined || input.declared === null)
|
|
20
|
+
return LambdaEndpointRefusal_1.REFUSAL_DEFAULT;
|
|
21
|
+
// a known class is honored as given
|
|
22
|
+
const as = typeof input.declared === 'object' && 'as' in input.declared
|
|
23
|
+
? input.declared.as
|
|
24
|
+
: undefined;
|
|
25
|
+
if (as === 'ConstraintError')
|
|
26
|
+
return LambdaEndpointRefusal_1.REFUSAL_PASSTHROUGH;
|
|
27
|
+
if (as === 'LambdaEndpointRefusedError')
|
|
28
|
+
return LambdaEndpointRefusal_1.REFUSAL_DEFAULT;
|
|
29
|
+
// any other value is refused, with both options named. the asker's own code composed the opt,
|
|
30
|
+
// so it is the asker's defect, never its caller's: a ConstraintError here would answer that
|
|
31
|
+
// caller a 400 it cannot fix (sdk-aws-lambda#77), as `asLambdaEndpoint` refuses a bad slug.
|
|
32
|
+
// MalfunctionError, not its parent UnexpectedCodePathError: only the child prints a `💥` header
|
|
33
|
+
return helpful_errors_1.MalfunctionError.throw('the refusal opt given is not one this sdk can honor', {
|
|
34
|
+
declared: input.declared,
|
|
35
|
+
options: [
|
|
36
|
+
{ as: 'LambdaEndpointRefusedError' },
|
|
37
|
+
{ as: 'ConstraintError' },
|
|
38
|
+
],
|
|
39
|
+
hint: "omit `refusal` when this caller composed the request (a peer refusal is then a LambdaEndpointRefusedError, a server fault). pass `refusal: { as: 'ConstraintError' }` only where the request forwards your own caller's input verbatim.",
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
exports.asLambdaEndpointRefusal = asLambdaEndpointRefusal;
|
|
43
|
+
//# sourceMappingURL=asLambdaEndpointRefusal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"asLambdaEndpointRefusal.js","sourceRoot":"","sources":["../../../../src/domain.operations/askLambdaEndpoint/serde/asLambdaEndpointRefusal.ts"],"names":[],"mappings":";;;AAAA,mDAAkD;AAElD,yFAIuD;AAEvD;;;;;;;;;;GAUG;AACI,MAAM,uBAAuB,GAAG,CAAC,KAEvC,EAAyB,EAAE;IAC1B,kDAAkD;IAClD,IAAI,KAAK,CAAC,QAAQ,KAAK,SAAS,IAAI,KAAK,CAAC,QAAQ,KAAK,IAAI;QACzD,OAAO,uCAAe,CAAC;IAEzB,oCAAoC;IACpC,MAAM,EAAE,GACN,OAAO,KAAK,CAAC,QAAQ,KAAK,QAAQ,IAAI,IAAI,IAAI,KAAK,CAAC,QAAQ;QAC1D,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE;QACnB,CAAC,CAAC,SAAS,CAAC;IAChB,IAAI,EAAE,KAAK,iBAAiB;QAAE,OAAO,2CAAmB,CAAC;IACzD,IAAI,EAAE,KAAK,4BAA4B;QAAE,OAAO,uCAAe,CAAC;IAEhE,8FAA8F;IAC9F,4FAA4F;IAC5F,4FAA4F;IAC5F,gGAAgG;IAChG,OAAO,iCAAgB,CAAC,KAAK,CAC3B,qDAAqD,EACrD;QACE,QAAQ,EAAE,KAAK,CAAC,QAAQ;QACxB,OAAO,EAAE;YACP,EAAE,EAAE,EAAE,4BAA4B,EAAE;YACpC,EAAE,EAAE,EAAE,iBAAiB,EAAE;SAC1B;QACD,IAAI,EAAE,yOAAyO;KAChP,CACF,CAAC;AACJ,CAAC,CAAC;AA9BW,QAAA,uBAAuB,2BA8BlC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* .what = whether an http status asks the caller to wait, never to fix the request
|
|
3
|
+
* .why = a throttle is a 4xx that is not a refusal: the same request succeeds after `retry-after`,
|
|
4
|
+
* so it is a server fault under either refusal opt (`domain.terms/refusal.md`, F8)
|
|
5
|
+
*
|
|
6
|
+
* .note = names one status, 429, the one rfc 9110 defines as "retry later". widen it here, and only
|
|
7
|
+
* here, if a peer is seen to answer another transient 4xx (a 408, say)
|
|
8
|
+
*/
|
|
9
|
+
export declare const getIsHttpThrottle: (input: {
|
|
10
|
+
status: number;
|
|
11
|
+
}) => boolean;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getIsHttpThrottle = void 0;
|
|
4
|
+
const HttpStatusCode_1 = require("../../../domain.objects/HttpStatusCode");
|
|
5
|
+
/**
|
|
6
|
+
* .what = whether an http status asks the caller to wait, never to fix the request
|
|
7
|
+
* .why = a throttle is a 4xx that is not a refusal: the same request succeeds after `retry-after`,
|
|
8
|
+
* so it is a server fault under either refusal opt (`domain.terms/refusal.md`, F8)
|
|
9
|
+
*
|
|
10
|
+
* .note = names one status, 429, the one rfc 9110 defines as "retry later". widen it here, and only
|
|
11
|
+
* here, if a peer is seen to answer another transient 4xx (a 408, say)
|
|
12
|
+
*/
|
|
13
|
+
const getIsHttpThrottle = (input) => input.status === HttpStatusCode_1.HttpStatusCode.TOO_MANY_REQUESTS_429;
|
|
14
|
+
exports.getIsHttpThrottle = getIsHttpThrottle;
|
|
15
|
+
//# sourceMappingURL=getIsHttpThrottle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getIsHttpThrottle.js","sourceRoot":"","sources":["../../../../src/domain.operations/askLambdaEndpoint/serde/getIsHttpThrottle.ts"],"names":[],"mappings":";;;AAAA,2EAAwE;AAExE;;;;;;;GAOG;AACI,MAAM,iBAAiB,GAAG,CAAC,KAAyB,EAAW,EAAE,CACtE,KAAK,CAAC,MAAM,KAAK,+BAAc,CAAC,qBAAqB,CAAC;AAD3C,QAAA,iBAAiB,qBAC0B"}
|