sdk-aws-lambda 0.7.1 → 0.7.3
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/asCallerFault.d.ts +14 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/asCallerFault.js +20 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/asCallerFault.js.map +1 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/asSqsBatchResponse.d.ts +9 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/asSqsBatchResponse.js +13 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/asSqsBatchResponse.js.map +1 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/asSqsRecordIds.d.ts +10 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/asSqsRecordIds.js +11 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/asSqsRecordIds.js.map +1 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/genLambdaEndpoint.forSqs.perBatch.d.ts +9 -3
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/genLambdaEndpoint.forSqs.perBatch.js +40 -38
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/genLambdaEndpoint.forSqs.perBatch.js.map +1 -1
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/genLambdaEndpoint.forSqs.perRecord.d.ts +12 -6
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/genLambdaEndpoint.forSqs.perRecord.js +59 -35
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/genLambdaEndpoint.forSqs.perRecord.js.map +1 -1
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/genSqsEndpointMiddlewares.d.ts +20 -7
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/genSqsEndpointMiddlewares.js +21 -9
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/genSqsEndpointMiddlewares.js.map +1 -1
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/getAllSqsIdsRetried.d.ts +19 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/getAllSqsIdsRetried.js +22 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/getAllSqsIdsRetried.js.map +1 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/getAllSqsIdsUnclaimable.d.ts +11 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/getAllSqsIdsUnclaimable.js +13 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/getAllSqsIdsUnclaimable.js.map +1 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/getAllSqsSuccessRefsMalformed.d.ts +11 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/getAllSqsSuccessRefsMalformed.js +18 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/getAllSqsSuccessRefsMalformed.js.map +1 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/isSqsSuccessRef.d.ts +8 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/isSqsSuccessRef.js +14 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/isSqsSuccessRef.js.map +1 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/logSqsRecordInvalid.d.ts +15 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/logSqsRecordInvalid.js +22 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/logSqsRecordInvalid.js.map +1 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/logSqsRecordRefused.d.ts +27 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/logSqsRecordRefused.js +33 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/logSqsRecordRefused.js.map +1 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/setSqsRecordValidated.d.ts +6 -5
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/setSqsRecordValidated.js +6 -5
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/setSqsRecordValidated.js.map +1 -1
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/setSqsRecordsValidated.d.ts +31 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/setSqsRecordsValidated.js +46 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/setSqsRecordsValidated.js.map +1 -0
- 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/error/isErrorLike.d.ts +6 -1
- package/dist/domain.operations/runLambdaEndpoint/error/isErrorLike.js +6 -1
- package/dist/domain.operations/runLambdaEndpoint/error/isErrorLike.js.map +1 -1
- 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/asErrorTypeOfErrorLike.d.ts +41 -0
- package/dist/domain.operations/runLambdaEndpoint/serde/asErrorTypeOfErrorLike.js +116 -0
- package/dist/domain.operations/runLambdaEndpoint/serde/asErrorTypeOfErrorLike.js.map +1 -0
- package/dist/domain.operations/runLambdaEndpoint/serde/asWireFunctionErrorPayload.js +52 -17
- package/dist/domain.operations/runLambdaEndpoint/serde/asWireFunctionErrorPayload.js.map +1 -1
- 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 +65 -4
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* .what = where a family's caller puts its trail and its contemp opt-in
|
|
3
|
+
* .why = one opt-in per transport (`invariant.ancient-vs-contemp-callers.md`)
|
|
4
|
+
*
|
|
5
|
+
* | carrier | the caller's trail + opt-in ride | families |
|
|
6
|
+
* |---------|----------------------------------|----------|
|
|
7
|
+
* | `wrapper` | `{ event, trail }` — a direct invoke owns its whole payload and has no metadata bag | `forAsk`, `forSqs.*` |
|
|
8
|
+
* | `headers` | the envelope's own `headers` — aws builds that envelope, so no caller can wrap it | `forApiGateway` |
|
|
9
|
+
*
|
|
10
|
+
* .note = it lives here because two peer operations name it — the endpoint that reads the
|
|
11
|
+
* carrier (`genTrailMiddleware`) and the runner that writes it (`runLambdaEndpoint`)
|
|
12
|
+
* (rule.prefer.most-common-denominator)
|
|
13
|
+
* .note = `forSqs.*` reads the wrapper a test runner frames, as it did before the headers carrier
|
|
14
|
+
* existed. aws never sends one to an sqs handler, so a deployed sqs endpoint reads no trail;
|
|
15
|
+
* the `messageAttributes` lift is recorded as next (`domain.terms/trail.md`)
|
|
16
|
+
*/
|
|
17
|
+
export type TrailCarrier = 'wrapper' | 'headers';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TrailCarrier.js","sourceRoot":"","sources":["../../src/domain.objects/TrailCarrier.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* .what = the key, in a transport's `headers` bag, that carries the caller's `trail.exid`
|
|
3
|
+
* .why = an aws-delivered event arrives in an envelope aws builds, so no caller can wrap it in
|
|
4
|
+
* `{ event, trail }`. the opt-in and the trail ride the envelope's metadata bag instead,
|
|
5
|
+
* under this one key (`domain.terms/x-trail-exid.md`)
|
|
6
|
+
*
|
|
7
|
+
* .note = lowercase always: http keys get lowercased in transit, and sqs keys are case-sensitive,
|
|
8
|
+
* so one lowercase-hyphen form is correct in every bag
|
|
9
|
+
*/
|
|
10
|
+
export declare const TRAIL_EXID_HEADER: "x-trail-exid";
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TRAIL_EXID_HEADER = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* .what = the key, in a transport's `headers` bag, that carries the caller's `trail.exid`
|
|
6
|
+
* .why = an aws-delivered event arrives in an envelope aws builds, so no caller can wrap it in
|
|
7
|
+
* `{ event, trail }`. the opt-in and the trail ride the envelope's metadata bag instead,
|
|
8
|
+
* under this one key (`domain.terms/x-trail-exid.md`)
|
|
9
|
+
*
|
|
10
|
+
* .note = lowercase always: http keys get lowercased in transit, and sqs keys are case-sensitive,
|
|
11
|
+
* so one lowercase-hyphen form is correct in every bag
|
|
12
|
+
*/
|
|
13
|
+
exports.TRAIL_EXID_HEADER = 'x-trail-exid';
|
|
14
|
+
//# sourceMappingURL=TrailExidHeader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TrailExidHeader.js","sourceRoot":"","sources":["../../src/domain.objects/TrailExidHeader.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;GAQG;AACU,QAAA,iBAAiB,GAAG,cAAuB,CAAC"}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.fromApiGateway = void 0;
|
|
4
4
|
const AwsIdentitySynthetic_1 = require("../../domain.objects/AwsIdentitySynthetic");
|
|
5
|
+
const setEventDeclaredAsApiGateway_1 = require("../lambdaEndpointWire/frame/setEventDeclaredAsApiGateway");
|
|
5
6
|
const asLambdaEvent_constants_1 = require("./asLambdaEvent.constants");
|
|
6
7
|
/**
|
|
7
8
|
* .what = the requestContext api gateway sends on EVERY real request
|
|
@@ -125,7 +126,7 @@ const fromApiGateway = (input) => {
|
|
|
125
126
|
...input.headers,
|
|
126
127
|
};
|
|
127
128
|
const queryStringParameters = input.queryStringParameters ?? null;
|
|
128
|
-
|
|
129
|
+
const event = {
|
|
129
130
|
body,
|
|
130
131
|
headers,
|
|
131
132
|
// 🔴 DERIVED, never hardcoded — aws sends the multi-value twin of every header
|
|
@@ -158,6 +159,19 @@ const fromApiGateway = (input) => {
|
|
|
158
159
|
})(),
|
|
159
160
|
resource: path,
|
|
160
161
|
};
|
|
162
|
+
/**
|
|
163
|
+
* .what = declares the event as api gateway, so `runLambdaEndpoint` carries the contemp opt-in in
|
|
164
|
+
* its headers rather than a `{ event, trail }` wrapper aws can never send
|
|
165
|
+
* .why = the sdk never sniffs an event's shape for this; the builder knows what it built
|
|
166
|
+
* (`invariant.ancient-vs-contemp-callers.md`). the mark is non-enumerable, so the event
|
|
167
|
+
* is byte-identical to what this returned before
|
|
168
|
+
*
|
|
169
|
+
* .note = the mark does not survive a copy (a spread, `structuredClone`, a json round trip). it matters
|
|
170
|
+
* at one road: `runLambdaEndpoint.onSerialized({ at: 'cloud' })` holds no endpoint, so the event
|
|
171
|
+
* is its only declaration. `onReferenced` and the local locus read the endpoint's own, so a
|
|
172
|
+
* copy works there. at cloud, pass a change to this builder instead of a copy
|
|
173
|
+
*/
|
|
174
|
+
return (0, setEventDeclaredAsApiGateway_1.setEventDeclaredAsApiGateway)({ event });
|
|
161
175
|
};
|
|
162
176
|
exports.fromApiGateway = fromApiGateway;
|
|
163
177
|
//# sourceMappingURL=asLambdaEvent.fromApiGateway.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"asLambdaEvent.fromApiGateway.js","sourceRoot":"","sources":["../../../src/domain.operations/asLambdaEvent/asLambdaEvent.fromApiGateway.ts"],"names":[],"mappings":";;;AAMA,oFAAkF;AAClF,uEAGmC;AAEnC;;;;;;;;;;;;;;GAcG;AACH,MAAM,gBAAgB,GAAG,CAAC,KAGzB,EAAiC,EAAE,CAAC,CAAC;IACpC,SAAS,EAAE,4CAAqB;IAChC,KAAK,EAAE,aAAa;IACpB,UAAU,EAAE,IAAI;IAChB,QAAQ,EAAE,UAAU;IACpB,UAAU,EAAE,KAAK,CAAC,UAAU;IAC5B,QAAQ,EAAE;QACR,SAAS,EAAE,IAAI;QACf,SAAS,EAAE,IAAI;QACf,MAAM,EAAE,IAAI;QACZ,QAAQ,EAAE,IAAI;QACd,MAAM,EAAE,IAAI;QACZ,UAAU,EAAE,IAAI;QAChB,6BAA6B,EAAE,IAAI;QACnC,yBAAyB,EAAE,IAAI;QAC/B,iBAAiB,EAAE,IAAI;QACvB,qBAAqB,EAAE,IAAI;QAC3B,cAAc,EAAE,IAAI;QACpB,QAAQ,EAAE,WAAW;QACrB,IAAI,EAAE,IAAI;QACV,SAAS,EAAE,eAAe;QAC1B,OAAO,EAAE,IAAI;KACd;IACD,IAAI,EAAE,KAAK,CAAC,IAAI;IAChB,KAAK,EAAE,MAAM;IACb,SAAS,EAAE,sCAAsC;IACjD,yEAAyE;IACzE,gBAAgB,EAAE,+CAAqB;IACvC,WAAW,EAAE,0CAAgB;IAC7B,qFAAqF;IACrF,iBAAiB,EAAE,6BAA6B;IAChD,UAAU,EAAE,kBAAkB;IAC9B,YAAY,EAAE,KAAK,CAAC,IAAI;CACzB,CAAC,CAAC;AAEH;;;;;GAKG;AACH,MAAM,YAAY,GAAG,CACnB,KAA6B,EACH,EAAE,CAC5B,MAAM,CAAC,WAAW,CAChB,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAC5D,CAAC;AAEJ;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,GAAG,CAAC,KAAyB,EAAiB,EAAE;IAC9D,MAAM,SAAS,GAAG,KAAK,CAAC,IAAI,IAAI,IAAI,CAAC;IACrC,IAAI,SAAS,KAAK,IAAI;QAAE,OAAO,IAAI,CAAC;IACpC,IAAI,OAAO,SAAS,KAAK,QAAQ;QAAE,OAAO,SAAS,CAAC;IACpD,OAAO,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;AACnC,CAAC,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACI,MAAM,cAAc,GAAG,CAAC,KAkD9B,EAAwB,EAAE;IACzB,MAAM,UAAU,GAAG,KAAK,CAAC,UAAU,IAAI,KAAK,CAAC;IAC7C,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,IAAI,GAAG,CAAC;IAE/B,MAAM,IAAI,GAAG,UAAU,CAAC,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC;IAE9C,MAAM,OAAO,GAAG;QACd,0EAA0E;QAC1E,gDAAgD;QAChD,MAAM,EAAE,kBAAkB;QAC1B,cAAc,EAAE,kBAAkB;QAClC,IAAI,EAAE,iDAAiD;QACvD,YAAY,EAAE,eAAe;QAC7B,GAAG,KAAK,CAAC,OAAO;KACjB,CAAC;IACF,MAAM,qBAAqB,GAAG,KAAK,CAAC,qBAAqB,IAAI,IAAI,CAAC;IAElE,
|
|
1
|
+
{"version":3,"file":"asLambdaEvent.fromApiGateway.js","sourceRoot":"","sources":["../../../src/domain.operations/asLambdaEvent/asLambdaEvent.fromApiGateway.ts"],"names":[],"mappings":"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"}
|
|
@@ -1,45 +1,68 @@
|
|
|
1
|
-
import
|
|
2
|
-
import type { SimpleCache } from 'with-simple-cache';
|
|
3
|
-
import type { ContextAwsLambdaCaller } from '../../domain.objects/ContextAwsLambdaCaller';
|
|
4
|
-
import type { LambdaEndpointDialect } from '../../domain.objects/LambdaEndpointDialect';
|
|
1
|
+
import { viaInvoke } from './askLambdaEndpoint.viaInvoke';
|
|
5
2
|
/**
|
|
6
|
-
* .what =
|
|
7
|
-
* .why =
|
|
3
|
+
* .what = the `askLambdaEndpoint` family — every road a caller takes to an endpoint, under one name
|
|
4
|
+
* .why = an api gateway endpoint is still a lambda endpoint; only the road differs. so the road
|
|
5
|
+
* qualifies the noun, and no second `ask*` noun is coined
|
|
6
|
+
* (`rule.forbid.unqualified-variant-exports`)
|
|
8
7
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
8
|
+
* askLambdaEndpoint({ … }) // the default: a direct invoke, as always
|
|
9
|
+
* askLambdaEndpoint.viaInvoke({ … }) // the same direct invoke, by name
|
|
10
|
+
* askLambdaEndpoint.viaApiGateway({ … }) // http, to an api gateway endpoint
|
|
11
|
+
*
|
|
12
|
+
* .note = callable, with the default also a key. `askLambdaEndpoint(…)` shipped bare, so the
|
|
13
|
+
* family keeps that call form and extant callers pay zero. the axis is backward
|
|
14
|
+
* compatibility: a family that had shipped no bare name would be a plain object, as
|
|
15
|
+
* `genLambdaEndpoint` is
|
|
11
16
|
*/
|
|
12
|
-
export declare const askLambdaEndpoint: <TRequest, TResponse>(input: {
|
|
17
|
+
export declare const askLambdaEndpoint: (<TRequest, TResponse>(input: {
|
|
13
18
|
which: {
|
|
14
19
|
service: string;
|
|
15
20
|
function: string;
|
|
16
21
|
};
|
|
17
22
|
event: TRequest;
|
|
18
|
-
/**
|
|
19
|
-
* .what = structure options
|
|
20
|
-
* .why = extensible for future structure versions
|
|
21
|
-
*/
|
|
22
23
|
struct?: {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
* .default = 'contemp' (wrapped with trail)
|
|
27
|
-
*/
|
|
28
|
-
payload?: LambdaEndpointDialect;
|
|
29
|
-
};
|
|
30
|
-
}, context: ContextAwsLambdaCaller & {
|
|
24
|
+
payload?: import("../..").LambdaEndpointDialect | undefined;
|
|
25
|
+
} | undefined;
|
|
26
|
+
}, context: import("../..").ContextAwsLambdaCaller & {
|
|
31
27
|
cache?: {
|
|
32
|
-
response?: SimpleCache<TResponse
|
|
33
|
-
dedupe?: SimpleInMemoryCache<TResponse
|
|
34
|
-
};
|
|
35
|
-
}) => Promise<TResponse
|
|
28
|
+
response?: import("with-simple-cache").SimpleCache<TResponse> | undefined;
|
|
29
|
+
dedupe?: import("simple-in-memory-cache").SimpleInMemoryCache<TResponse> | undefined;
|
|
30
|
+
} | undefined;
|
|
31
|
+
}) => Promise<TResponse>) & {
|
|
32
|
+
viaInvoke: <TRequest, TResponse>(input: {
|
|
33
|
+
which: {
|
|
34
|
+
service: string;
|
|
35
|
+
function: string;
|
|
36
|
+
};
|
|
37
|
+
event: TRequest;
|
|
38
|
+
struct?: {
|
|
39
|
+
payload?: import("../..").LambdaEndpointDialect | undefined;
|
|
40
|
+
} | undefined;
|
|
41
|
+
}, context: import("../..").ContextAwsLambdaCaller & {
|
|
42
|
+
cache?: {
|
|
43
|
+
response?: import("with-simple-cache").SimpleCache<TResponse> | undefined;
|
|
44
|
+
dedupe?: import("simple-in-memory-cache").SimpleInMemoryCache<TResponse> | undefined;
|
|
45
|
+
} | undefined;
|
|
46
|
+
}) => Promise<TResponse>;
|
|
47
|
+
viaApiGateway: <TResponse_1 = unknown>(input: {
|
|
48
|
+
url: string;
|
|
49
|
+
method?: string | undefined;
|
|
50
|
+
headers?: Record<string, string> | undefined;
|
|
51
|
+
body?: unknown;
|
|
52
|
+
}, context: import("sdk-logs").ContextLogTrail) => Promise<{
|
|
53
|
+
status: number;
|
|
54
|
+
headers: Record<string, string>;
|
|
55
|
+
text: string;
|
|
56
|
+
body: TResponse_1 | null;
|
|
57
|
+
}>;
|
|
58
|
+
};
|
|
36
59
|
/**
|
|
37
60
|
* .what = input type for askLambdaEndpoint
|
|
38
61
|
* .why = exported for sdk consumers
|
|
39
62
|
*/
|
|
40
|
-
export type AskLambdaEndpointInput<TRequest> = Parameters<typeof
|
|
63
|
+
export type AskLambdaEndpointInput<TRequest> = Parameters<typeof viaInvoke<TRequest, unknown>>[0];
|
|
41
64
|
/**
|
|
42
65
|
* .what = context type for askLambdaEndpoint
|
|
43
66
|
* .why = exported for sdk consumers
|
|
44
67
|
*/
|
|
45
|
-
export type AskLambdaEndpointContext = Parameters<typeof
|
|
68
|
+
export type AskLambdaEndpointContext = Parameters<typeof viaInvoke>[1];
|
|
@@ -1,68 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.askLambdaEndpoint = void 0;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const getOneTrailExid_1 = require("../lambdaEndpointWire/context/getOneTrailExid");
|
|
7
|
-
const asCachedExecutor_1 = require("./cache/asCachedExecutor");
|
|
8
|
-
const getAskLambdaCacheKey_1 = require("./cache/getAskLambdaCacheKey");
|
|
9
|
-
const getLambdaPayload_1 = require("./serde/getLambdaPayload");
|
|
4
|
+
const askLambdaEndpoint_viaApiGateway_1 = require("./askLambdaEndpoint.viaApiGateway");
|
|
5
|
+
const askLambdaEndpoint_viaInvoke_1 = require("./askLambdaEndpoint.viaInvoke");
|
|
10
6
|
/**
|
|
11
|
-
* .what =
|
|
12
|
-
* .why =
|
|
7
|
+
* .what = the `askLambdaEndpoint` family — every road a caller takes to an endpoint, under one name
|
|
8
|
+
* .why = an api gateway endpoint is still a lambda endpoint; only the road differs. so the road
|
|
9
|
+
* qualifies the noun, and no second `ask*` noun is coined
|
|
10
|
+
* (`rule.forbid.unqualified-variant-exports`)
|
|
13
11
|
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
12
|
+
* askLambdaEndpoint({ … }) // the default: a direct invoke, as always
|
|
13
|
+
* askLambdaEndpoint.viaInvoke({ … }) // the same direct invoke, by name
|
|
14
|
+
* askLambdaEndpoint.viaApiGateway({ … }) // http, to an api gateway endpoint
|
|
15
|
+
*
|
|
16
|
+
* .note = callable, with the default also a key. `askLambdaEndpoint(…)` shipped bare, so the
|
|
17
|
+
* family keeps that call form and extant callers pay zero. the axis is backward
|
|
18
|
+
* compatibility: a family that had shipped no bare name would be a plain object, as
|
|
19
|
+
* `genLambdaEndpoint` is
|
|
16
20
|
*/
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
// rather than a comment.
|
|
22
|
-
const exid = (0, getOneTrailExid_1.getOneTrailExid)({ log: context.log });
|
|
23
|
-
// build the endpoint from the selector + ambient access (computes slug)
|
|
24
|
-
const endpoint = (0, asLambdaEndpoint_1.asLambdaEndpoint)({
|
|
25
|
-
service: input.which.service,
|
|
26
|
-
access: context.env.access,
|
|
27
|
-
function: input.which.function,
|
|
28
|
-
});
|
|
29
|
-
// build payload — contemp wraps in `{ event, trail }`, ancient sends it flat
|
|
30
|
-
//
|
|
31
|
-
// 🔴 the branch tests for CONTEMP, so an unrecognized dialect falls to ANCIENT
|
|
32
|
-
// (rule.require.contemp-must-self-identify). we author every contemp caller,
|
|
33
|
-
// so a value we do not recognize was not written by one — and the fallback
|
|
34
|
-
// must be the dialect that assumes less. a fall to contemp would wrap a
|
|
35
|
-
// payload for a handler that never learned to unwrap it.
|
|
36
|
-
//
|
|
37
|
-
// ⚠️ ABSENT is not unrecognized: it is the documented default, and it stays
|
|
38
|
-
// contemp so trail propagation holds for every caller that omits `struct`.
|
|
39
|
-
const structOfPayload = input.struct?.payload ?? 'contemp';
|
|
40
|
-
const payload = structOfPayload === 'contemp'
|
|
41
|
-
? (0, getLambdaPayload_1.getLambdaPayload)({ event: input.event, trail: { exid } })
|
|
42
|
-
: input.event;
|
|
43
|
-
// get or create LambdaClient
|
|
44
|
-
const sdkLambda = (0, genLambdaSdk_1.genLambdaSdk)({
|
|
45
|
-
sdk: context.aws?.lambda?.sdk,
|
|
46
|
-
env: { region: context.env.region },
|
|
47
|
-
});
|
|
48
|
-
// prepare invocation input + context
|
|
49
|
-
const invocationInput = { endpoint, payload, exid };
|
|
50
|
-
const invocationContext = {
|
|
51
|
-
sdkLambda,
|
|
52
|
-
log: context.log,
|
|
53
|
-
};
|
|
54
|
-
// build cache key generator
|
|
55
|
-
const getCacheKey = () => (0, getAskLambdaCacheKey_1.getAskLambdaCacheKey)({
|
|
56
|
-
endpoint,
|
|
57
|
-
event: input.event,
|
|
58
|
-
});
|
|
59
|
-
// get executor with cache wrapper
|
|
60
|
-
const execute = (0, asCachedExecutor_1.asCachedExecutor)({
|
|
61
|
-
...context.cache,
|
|
62
|
-
getCacheKey,
|
|
63
|
-
});
|
|
64
|
-
// execute invocation
|
|
65
|
-
return execute(invocationInput, invocationContext);
|
|
66
|
-
};
|
|
67
|
-
exports.askLambdaEndpoint = askLambdaEndpoint;
|
|
21
|
+
exports.askLambdaEndpoint = Object.assign(askLambdaEndpoint_viaInvoke_1.viaInvoke, {
|
|
22
|
+
viaInvoke: askLambdaEndpoint_viaInvoke_1.viaInvoke,
|
|
23
|
+
viaApiGateway: askLambdaEndpoint_viaApiGateway_1.viaApiGateway,
|
|
24
|
+
});
|
|
68
25
|
//# sourceMappingURL=askLambdaEndpoint.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"askLambdaEndpoint.js","sourceRoot":"","sources":["../../../src/domain.operations/askLambdaEndpoint/askLambdaEndpoint.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"askLambdaEndpoint.js","sourceRoot":"","sources":["../../../src/domain.operations/askLambdaEndpoint/askLambdaEndpoint.ts"],"names":[],"mappings":";;;AAAA,uFAAkE;AAClE,+EAA0D;AAE1D;;;;;;;;;;;;;;GAcG;AACU,QAAA,iBAAiB,GAAG,MAAM,CAAC,MAAM,CAAC,uCAAS,EAAE;IACxD,SAAS,EAAT,uCAAS;IACT,aAAa,EAAb,+CAAa;CACd,CAAC,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { ContextLogTrail } from 'sdk-logs';
|
|
2
|
+
/**
|
|
3
|
+
* .what = asks an api gateway endpoint over http, opted into the contemp dialect with the caller's trail
|
|
4
|
+
* .why = an aws-delivered event cannot hold a `{ event, trail }` wrapper, so the opt-in and the
|
|
5
|
+
* 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
|
+
* (`invariant.ancient-vs-contemp-callers.md`, `domain.terms/x-trail-exid.md`)
|
|
8
|
+
*
|
|
9
|
+
* | answer | the caller gets |
|
|
10
|
+
* |--------|-----------------|
|
|
11
|
+
* | < 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
|
+
* | 5xx | a thrown `MalfunctionError`, with the `correlationId` that finds the log line |
|
|
14
|
+
*
|
|
15
|
+
* .note = takes the standard http request — `{ url, method, headers, body }` — as fetch does, and
|
|
16
|
+
* no `which`: an http endpoint is addressed by its url
|
|
17
|
+
* .note = a body that is not a string is json-stringified, as `asLambdaEvent.fromApiGateway` does
|
|
18
|
+
* .note = the trail header replaces any caller header of that name, in any case, since one of that
|
|
19
|
+
* name would silently opt in or out of the dialect the trail declares
|
|
20
|
+
* .note = with no `method`, a request with a body is a `POST` and one without is a `GET`
|
|
21
|
+
* .note = `text` is always the raw answer, so a body that is not json (xml, html) is read there
|
|
22
|
+
* .note = sends with the runtime's global `fetch`, which node supplies from 18. the sdk adds no http
|
|
23
|
+
* dependency, and sets no timeout: fetch waits as long as the endpoint does
|
|
24
|
+
*/
|
|
25
|
+
export declare const viaApiGateway: <TResponse = unknown>(input: {
|
|
26
|
+
url: string;
|
|
27
|
+
method?: string;
|
|
28
|
+
headers?: Record<string, string>;
|
|
29
|
+
body?: unknown;
|
|
30
|
+
}, context: ContextLogTrail) => Promise<{
|
|
31
|
+
status: number;
|
|
32
|
+
headers: Record<string, string>;
|
|
33
|
+
text: string;
|
|
34
|
+
body: TResponse | null;
|
|
35
|
+
}>;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.viaApiGateway = void 0;
|
|
4
|
+
const getOneTrailExid_1 = require("../lambdaEndpointWire/context/getOneTrailExid");
|
|
5
|
+
const executeHttpRequest_1 = require("./invoke/executeHttpRequest");
|
|
6
|
+
const asErrorFromHttpResponse_1 = require("./serde/asErrorFromHttpResponse");
|
|
7
|
+
const asHeadersRecord_1 = require("./serde/asHeadersRecord");
|
|
8
|
+
const asHttpMethod_1 = require("./serde/asHttpMethod");
|
|
9
|
+
const asHttpRequestBody_1 = require("./serde/asHttpRequestBody");
|
|
10
|
+
const asHttpRequestHeaders_1 = require("./serde/asHttpRequestHeaders");
|
|
11
|
+
const getOneBodyFromHttpText_1 = require("./serde/getOneBodyFromHttpText");
|
|
12
|
+
/**
|
|
13
|
+
* .what = asks an api gateway endpoint over http, opted into the contemp dialect with the caller's trail
|
|
14
|
+
* .why = an aws-delivered event cannot hold a `{ event, trail }` wrapper, so the opt-in and the
|
|
15
|
+
* 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
|
+
* (`invariant.ancient-vs-contemp-callers.md`, `domain.terms/x-trail-exid.md`)
|
|
18
|
+
*
|
|
19
|
+
* | answer | the caller gets |
|
|
20
|
+
* |--------|-----------------|
|
|
21
|
+
* | < 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
|
+
* | 5xx | a thrown `MalfunctionError`, with the `correlationId` that finds the log line |
|
|
24
|
+
*
|
|
25
|
+
* .note = takes the standard http request — `{ url, method, headers, body }` — as fetch does, and
|
|
26
|
+
* no `which`: an http endpoint is addressed by its url
|
|
27
|
+
* .note = a body that is not a string is json-stringified, as `asLambdaEvent.fromApiGateway` does
|
|
28
|
+
* .note = the trail header replaces any caller header of that name, in any case, since one of that
|
|
29
|
+
* name would silently opt in or out of the dialect the trail declares
|
|
30
|
+
* .note = with no `method`, a request with a body is a `POST` and one without is a `GET`
|
|
31
|
+
* .note = `text` is always the raw answer, so a body that is not json (xml, html) is read there
|
|
32
|
+
* .note = sends with the runtime's global `fetch`, which node supplies from 18. the sdk adds no http
|
|
33
|
+
* dependency, and sets no timeout: fetch waits as long as the endpoint does
|
|
34
|
+
*/
|
|
35
|
+
const viaApiGateway = async (input, context) => {
|
|
36
|
+
// the caller's exid, or a generated one — the same call `askLambdaEndpoint` makes
|
|
37
|
+
const exid = (0, getOneTrailExid_1.getOneTrailExid)({ log: context.log });
|
|
38
|
+
// send the request, opted in by the trail header
|
|
39
|
+
const request = (0, asHttpRequestBody_1.asHttpRequestBody)({ body: input.body });
|
|
40
|
+
const response = await (0, executeHttpRequest_1.executeHttpRequest)({
|
|
41
|
+
url: input.url,
|
|
42
|
+
method: (0, asHttpMethod_1.asHttpMethod)({ method: input.method, body: input.body }),
|
|
43
|
+
headers: (0, asHttpRequestHeaders_1.asHttpRequestHeaders)({
|
|
44
|
+
contentType: request.contentType,
|
|
45
|
+
headers: input.headers,
|
|
46
|
+
trail: { exid },
|
|
47
|
+
}),
|
|
48
|
+
body: request.text,
|
|
49
|
+
exid,
|
|
50
|
+
});
|
|
51
|
+
// read the wire into plain data, so no live Response travels past here
|
|
52
|
+
const text = await response.text();
|
|
53
|
+
const body = (0, getOneBodyFromHttpText_1.getOneBodyFromHttpText)({ text });
|
|
54
|
+
// a fault is a thrown error, one catch block for either road
|
|
55
|
+
const headers = (0, asHeadersRecord_1.asHeadersRecord)({ headers: response.headers });
|
|
56
|
+
const error = (0, asErrorFromHttpResponse_1.asErrorFromHttpResponse)({
|
|
57
|
+
status: response.status,
|
|
58
|
+
body,
|
|
59
|
+
text,
|
|
60
|
+
headers,
|
|
61
|
+
url: input.url,
|
|
62
|
+
exid,
|
|
63
|
+
});
|
|
64
|
+
if (error)
|
|
65
|
+
throw error;
|
|
66
|
+
/**
|
|
67
|
+
* .cast = TResponse
|
|
68
|
+
* .why = the caller names the expected body via the generic; the endpoint validates its own
|
|
69
|
+
* output with a zod schema, so this boundary asserts no shape
|
|
70
|
+
* .removal = add a runtime schema option here when a caller needs one
|
|
71
|
+
*/
|
|
72
|
+
return {
|
|
73
|
+
status: response.status,
|
|
74
|
+
headers,
|
|
75
|
+
text,
|
|
76
|
+
body: body,
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
exports.viaApiGateway = viaApiGateway;
|
|
80
|
+
//# sourceMappingURL=askLambdaEndpoint.viaApiGateway.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"askLambdaEndpoint.viaApiGateway.js","sourceRoot":"","sources":["../../../src/domain.operations/askLambdaEndpoint/askLambdaEndpoint.viaApiGateway.ts"],"names":[],"mappings":";;;AAEA,mFAAgF;AAChF,oEAAiE;AACjE,6EAA0E;AAC1E,6DAA0D;AAC1D,uDAAoD;AACpD,iEAA8D;AAC9D,uEAAoE;AACpE,2EAAwE;AAExE;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACI,MAAM,aAAa,GAAG,KAAK,EAChC,KAKC,EACD,OAAwB,EAMvB,EAAE;IACH,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;KACL,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;AA3DW,QAAA,aAAa,iBA2DxB"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { SimpleInMemoryCache } from 'simple-in-memory-cache';
|
|
2
|
+
import type { SimpleCache } from 'with-simple-cache';
|
|
3
|
+
import type { ContextAwsLambdaCaller } from '../../domain.objects/ContextAwsLambdaCaller';
|
|
4
|
+
import type { LambdaEndpointDialect } from '../../domain.objects/LambdaEndpointDialect';
|
|
5
|
+
/**
|
|
6
|
+
* .what = invokes a lambda endpoint with trail propagation, over the aws lambda invoke api
|
|
7
|
+
* .why = enables service-to-service calls with observability
|
|
8
|
+
*
|
|
9
|
+
* .note = the default member of the `askLambdaEndpoint` family, which `askLambdaEndpoint(…)`
|
|
10
|
+
* still calls (`askLambdaEndpoint.ts`)
|
|
11
|
+
* .note = pass context.cache to enable response cache
|
|
12
|
+
* .note = use struct: 'ancient' for handlers that don't understand wrapped payloads
|
|
13
|
+
*/
|
|
14
|
+
export declare const viaInvoke: <TRequest, TResponse>(input: {
|
|
15
|
+
which: {
|
|
16
|
+
service: string;
|
|
17
|
+
function: string;
|
|
18
|
+
};
|
|
19
|
+
event: TRequest;
|
|
20
|
+
/**
|
|
21
|
+
* .what = structure options
|
|
22
|
+
* .why = extensible for future structure versions
|
|
23
|
+
*/
|
|
24
|
+
struct?: {
|
|
25
|
+
/**
|
|
26
|
+
* .what = payload format to send
|
|
27
|
+
* .why = ancient handlers don't understand wrapped { event, trail } structure
|
|
28
|
+
* .default = 'contemp' (wrapped with trail)
|
|
29
|
+
*/
|
|
30
|
+
payload?: LambdaEndpointDialect;
|
|
31
|
+
};
|
|
32
|
+
}, context: ContextAwsLambdaCaller & {
|
|
33
|
+
cache?: {
|
|
34
|
+
response?: SimpleCache<TResponse>;
|
|
35
|
+
dedupe?: SimpleInMemoryCache<TResponse>;
|
|
36
|
+
};
|
|
37
|
+
}) => Promise<TResponse>;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.viaInvoke = void 0;
|
|
4
|
+
const genLambdaSdk_1 = require("../../access/sdks/lambda/genLambdaSdk");
|
|
5
|
+
const asLambdaEndpoint_1 = require("../asLambdaEndpoint/asLambdaEndpoint");
|
|
6
|
+
const getOneTrailExid_1 = require("../lambdaEndpointWire/context/getOneTrailExid");
|
|
7
|
+
const asCachedExecutor_1 = require("./cache/asCachedExecutor");
|
|
8
|
+
const getAskLambdaCacheKey_1 = require("./cache/getAskLambdaCacheKey");
|
|
9
|
+
const getLambdaPayload_1 = require("./serde/getLambdaPayload");
|
|
10
|
+
/**
|
|
11
|
+
* .what = invokes a lambda endpoint with trail propagation, over the aws lambda invoke api
|
|
12
|
+
* .why = enables service-to-service calls with observability
|
|
13
|
+
*
|
|
14
|
+
* .note = the default member of the `askLambdaEndpoint` family, which `askLambdaEndpoint(…)`
|
|
15
|
+
* still calls (`askLambdaEndpoint.ts`)
|
|
16
|
+
* .note = pass context.cache to enable response cache
|
|
17
|
+
* .note = use struct: 'ancient' for handlers that don't understand wrapped payloads
|
|
18
|
+
*/
|
|
19
|
+
const viaInvoke = async (input, context) => {
|
|
20
|
+
// extract or generate the trail exid, and report the fallback if one was made.
|
|
21
|
+
// shared with `runLambdaEndpoint.onSerialized` so the two loci cannot diverge
|
|
22
|
+
// on the diagnostic — see `getOneTrailExid` for why that parity is structural
|
|
23
|
+
// rather than a comment.
|
|
24
|
+
const exid = (0, getOneTrailExid_1.getOneTrailExid)({ log: context.log });
|
|
25
|
+
// build the endpoint from the selector + ambient access (computes slug)
|
|
26
|
+
const endpoint = (0, asLambdaEndpoint_1.asLambdaEndpoint)({
|
|
27
|
+
service: input.which.service,
|
|
28
|
+
access: context.env.access,
|
|
29
|
+
function: input.which.function,
|
|
30
|
+
});
|
|
31
|
+
// build payload — contemp wraps in `{ event, trail }`, ancient sends it flat
|
|
32
|
+
//
|
|
33
|
+
// 🔴 the branch tests for CONTEMP, so an unrecognized dialect falls to ANCIENT
|
|
34
|
+
// (rule.require.contemp-must-self-identify). we author every contemp caller,
|
|
35
|
+
// so a value we do not recognize was not written by one — and the fallback
|
|
36
|
+
// must be the dialect that assumes less. a fall to contemp would wrap a
|
|
37
|
+
// payload for a handler that never learned to unwrap it.
|
|
38
|
+
//
|
|
39
|
+
// ⚠️ ABSENT is not unrecognized: it is the documented default, and it stays
|
|
40
|
+
// contemp so trail propagation holds for every caller that omits `struct`.
|
|
41
|
+
const structOfPayload = input.struct?.payload ?? 'contemp';
|
|
42
|
+
const payload = structOfPayload === 'contemp'
|
|
43
|
+
? (0, getLambdaPayload_1.getLambdaPayload)({ event: input.event, trail: { exid } })
|
|
44
|
+
: input.event;
|
|
45
|
+
// get or create LambdaClient
|
|
46
|
+
const sdkLambda = (0, genLambdaSdk_1.genLambdaSdk)({
|
|
47
|
+
sdk: context.aws?.lambda?.sdk,
|
|
48
|
+
env: { region: context.env.region },
|
|
49
|
+
});
|
|
50
|
+
// prepare invocation input + context
|
|
51
|
+
const invocationInput = { endpoint, payload, exid };
|
|
52
|
+
const invocationContext = {
|
|
53
|
+
sdkLambda,
|
|
54
|
+
log: context.log,
|
|
55
|
+
};
|
|
56
|
+
// build cache key generator
|
|
57
|
+
const getCacheKey = () => (0, getAskLambdaCacheKey_1.getAskLambdaCacheKey)({
|
|
58
|
+
endpoint,
|
|
59
|
+
event: input.event,
|
|
60
|
+
});
|
|
61
|
+
// get executor with cache wrapper
|
|
62
|
+
const execute = (0, asCachedExecutor_1.asCachedExecutor)({
|
|
63
|
+
...context.cache,
|
|
64
|
+
getCacheKey,
|
|
65
|
+
});
|
|
66
|
+
// execute invocation
|
|
67
|
+
return execute(invocationInput, invocationContext);
|
|
68
|
+
};
|
|
69
|
+
exports.viaInvoke = viaInvoke;
|
|
70
|
+
//# sourceMappingURL=askLambdaEndpoint.viaInvoke.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"askLambdaEndpoint.viaInvoke.js","sourceRoot":"","sources":["../../../src/domain.operations/askLambdaEndpoint/askLambdaEndpoint.viaInvoke.ts"],"names":[],"mappings":";;;AAGA,wEAAqE;AAGrE,2EAAwE;AACxE,mFAAgF;AAChF,+DAA4D;AAC5D,uEAAoE;AAKpE,+DAA4D;AAE5D;;;;;;;;GAQG;AACI,MAAM,SAAS,GAAG,KAAK,EAC5B,KAkBC,EACD,OAKC,EACmB,EAAE;IACtB,+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,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;IACrE,MAAM,iBAAiB,GAAsB;QAC3C,SAAS;QACT,GAAG,EAAE,OAAO,CAAC,GAAG;KACjB,CAAC;IAEF,4BAA4B;IAC5B,MAAM,WAAW,GAAG,GAAW,EAAE,CAC/B,IAAA,2CAAoB,EAAC;QACnB,QAAQ;QACR,KAAK,EAAE,KAAK,CAAC,KAAgC;KAC9C,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;AApFW,QAAA,SAAS,aAoFpB"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* .what = sends one http request with the runtime's global fetch, and names the request on a fault
|
|
3
|
+
* .why = a network fault leaves fetch as a bare `TypeError: fetch failed`, which names no url, no
|
|
4
|
+
* method, and no trail exid. the reader at 3am needs all three
|
|
5
|
+
*
|
|
6
|
+
* .note = the peer of `executeLambdaInvocation`: the raw i/o boundary for the http road
|
|
7
|
+
* .note = every fault is caught and re-thrown, never hidden. `cause` rides along where the fault is
|
|
8
|
+
* an `Error` of this realm, and `causeMessage` rides always, since a fault from the runtime's
|
|
9
|
+
* own fetch may come from another realm, where `instanceof Error` is false
|
|
10
|
+
*/
|
|
11
|
+
export declare const executeHttpRequest: (input: {
|
|
12
|
+
url: string;
|
|
13
|
+
method: string;
|
|
14
|
+
headers: Record<string, string>;
|
|
15
|
+
body: string | undefined;
|
|
16
|
+
exid: string;
|
|
17
|
+
}) => Promise<Response>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.executeHttpRequest = void 0;
|
|
4
|
+
const helpful_errors_1 = require("helpful-errors");
|
|
5
|
+
/**
|
|
6
|
+
* .what = sends one http request with the runtime's global fetch, and names the request on a fault
|
|
7
|
+
* .why = a network fault leaves fetch as a bare `TypeError: fetch failed`, which names no url, no
|
|
8
|
+
* method, and no trail exid. the reader at 3am needs all three
|
|
9
|
+
*
|
|
10
|
+
* .note = the peer of `executeLambdaInvocation`: the raw i/o boundary for the http road
|
|
11
|
+
* .note = every fault is caught and re-thrown, never hidden. `cause` rides along where the fault is
|
|
12
|
+
* an `Error` of this realm, and `causeMessage` rides always, since a fault from the runtime's
|
|
13
|
+
* own fetch may come from another realm, where `instanceof Error` is false
|
|
14
|
+
*/
|
|
15
|
+
const executeHttpRequest = async (input) => {
|
|
16
|
+
try {
|
|
17
|
+
return await fetch(input.url, {
|
|
18
|
+
method: input.method,
|
|
19
|
+
headers: input.headers,
|
|
20
|
+
body: input.body,
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
throw new helpful_errors_1.MalfunctionError('askLambdaEndpoint.viaApiGateway.fetch.error', {
|
|
25
|
+
url: input.url,
|
|
26
|
+
method: input.method,
|
|
27
|
+
exid: input.exid,
|
|
28
|
+
causeMessage: String(error),
|
|
29
|
+
...(error instanceof Error ? { cause: error } : {}),
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
exports.executeHttpRequest = executeHttpRequest;
|
|
34
|
+
//# sourceMappingURL=executeHttpRequest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"executeHttpRequest.js","sourceRoot":"","sources":["../../../../src/domain.operations/askLambdaEndpoint/invoke/executeHttpRequest.ts"],"names":[],"mappings":";;;AAAA,mDAAkD;AAElD;;;;;;;;;GASG;AACI,MAAM,kBAAkB,GAAG,KAAK,EAAE,KAMxC,EAAqB,EAAE;IACtB,IAAI,CAAC;QACH,OAAO,MAAM,KAAK,CAAC,KAAK,CAAC,GAAG,EAAE;YAC5B,MAAM,EAAE,KAAK,CAAC,MAAM;YACpB,OAAO,EAAE,KAAK,CAAC,OAAO;YACtB,IAAI,EAAE,KAAK,CAAC,IAAI;SACjB,CAAC,CAAC;IACL,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,iCAAgB,CAAC,6CAA6C,EAAE;YACxE,GAAG,EAAE,KAAK,CAAC,GAAG;YACd,MAAM,EAAE,KAAK,CAAC,MAAM;YACpB,IAAI,EAAE,KAAK,CAAC,IAAI;YAChB,YAAY,EAAE,MAAM,CAAC,KAAK,CAAC;YAC3B,GAAG,CAAC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SACpD,CAAC,CAAC;IACL,CAAC;AACH,CAAC,CAAC;AAtBW,QAAA,kBAAkB,sBAsB7B"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { ConstraintError, MalfunctionError } from 'helpful-errors';
|
|
2
|
+
/**
|
|
3
|
+
* .what = casts an http response into the error a caller should throw, or null for a success
|
|
4
|
+
* .why = an api gateway endpoint answers a fault as a RETURNED http response, never a lambda error
|
|
5
|
+
* (`invariant.badrequesterror-not-lambda-error`). the caller of `viaApiGateway` still wants
|
|
6
|
+
* the throw `askLambdaEndpoint` gives — one catch block, whichever road it took
|
|
7
|
+
*
|
|
8
|
+
* | status | the error | because |
|
|
9
|
+
* |--------|-----------|---------|
|
|
10
|
+
* | < 400 | none | a success. a redirect is followed by fetch by default, so a 3xx seldom arrives here |
|
|
11
|
+
* | 4xx | `ConstraintError` | the caller must fix the request |
|
|
12
|
+
* | 5xx | `MalfunctionError` | the endpoint must fix itself; its `correlationId` finds the log line |
|
|
13
|
+
*
|
|
14
|
+
* .note = the message comes from the body's contemp envelope when it has one, else from the
|
|
15
|
+
* status alone — a 404 from the gateway's own route match has no body this sdk wrote.
|
|
16
|
+
* a flat ancient body reads as the status alone: an opted-in caller is never answered in
|
|
17
|
+
* that shape, so no arm reads it
|
|
18
|
+
* .note = the raw answer text rides the error metadata, cut to a bound, so a message no arm reads
|
|
19
|
+
* (an old endpoint's flat body, a proxy's html page) is never lost to the caller. it is null
|
|
20
|
+
* where the message came from the contemp envelope, which is the text already. the
|
|
21
|
+
* response headers ride it too, so a deliberate refusal (a 429 and its `retry-after`) can be
|
|
22
|
+
* read from the thrown error
|
|
23
|
+
*/
|
|
24
|
+
export declare const asErrorFromHttpResponse: (input: {
|
|
25
|
+
status: number;
|
|
26
|
+
body: unknown;
|
|
27
|
+
text: string;
|
|
28
|
+
headers: Record<string, string>;
|
|
29
|
+
url: string;
|
|
30
|
+
exid: string;
|
|
31
|
+
}) => ConstraintError | MalfunctionError | null;
|