sdk-aws-lambda 0.2.0 → 0.4.0
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/contract/cli/asGenArgs.d.ts +21 -0
- package/dist/contract/cli/asGenArgs.js +69 -0
- package/dist/contract/cli/asGenArgs.js.map +1 -0
- package/dist/contract/cli/gen.d.ts +23 -0
- package/dist/contract/cli/gen.js +72 -0
- package/dist/contract/cli/gen.js.map +1 -0
- package/dist/domain.objects/ApiGatewayRequestPayload.d.ts +12 -0
- package/dist/domain.objects/ApiGatewayRequestPayload.js +3 -0
- package/dist/domain.objects/ApiGatewayRequestPayload.js.map +1 -0
- package/dist/domain.objects/ApiGatewayResponse.d.ts +30 -0
- package/dist/domain.objects/ApiGatewayResponse.js +3 -0
- package/dist/domain.objects/ApiGatewayResponse.js.map +1 -0
- package/dist/domain.objects/ApiGatewayResponsePayload.d.ts +30 -0
- package/dist/domain.objects/ApiGatewayResponsePayload.js +3 -0
- package/dist/domain.objects/ApiGatewayResponsePayload.js.map +1 -0
- package/dist/domain.objects/DomainObjectCaptured.d.ts +51 -0
- package/dist/domain.objects/DomainObjectCaptured.js +8 -0
- package/dist/domain.objects/DomainObjectCaptured.js.map +1 -0
- package/dist/domain.objects/GeneratedFile.d.ts +18 -0
- package/dist/domain.objects/GeneratedFile.js +8 -0
- package/dist/domain.objects/GeneratedFile.js.map +1 -0
- package/dist/domain.objects/HttpStatusCode.d.ts +1 -0
- package/dist/domain.objects/HttpStatusCode.js +1 -0
- package/dist/domain.objects/HttpStatusCode.js.map +1 -1
- package/dist/domain.objects/LambdaCredentialsAbsentError.d.ts +11 -0
- package/dist/domain.objects/LambdaCredentialsAbsentError.js +16 -0
- package/dist/domain.objects/LambdaCredentialsAbsentError.js.map +1 -0
- package/dist/domain.objects/LambdaDomainObjectNotCapturableError.d.ts +12 -0
- package/dist/domain.objects/LambdaDomainObjectNotCapturableError.js +17 -0
- package/dist/domain.objects/LambdaDomainObjectNotCapturableError.js.map +1 -0
- package/dist/domain.objects/LambdaDomainObjectRefUnbindableError.d.ts +14 -0
- package/dist/domain.objects/LambdaDomainObjectRefUnbindableError.js +19 -0
- package/dist/domain.objects/LambdaDomainObjectRefUnbindableError.js.map +1 -0
- package/dist/domain.operations/genLambdaEndpoint/TranslateLog.d.ts +29 -0
- package/dist/domain.operations/genLambdaEndpoint/TranslateLog.js +3 -0
- package/dist/domain.operations/genLambdaEndpoint/TranslateLog.js.map +1 -0
- package/dist/domain.operations/genLambdaEndpoint/asContextLogTrail.d.ts +29 -0
- package/dist/domain.operations/genLambdaEndpoint/asContextLogTrail.js +30 -0
- package/dist/domain.operations/genLambdaEndpoint/asContextLogTrail.js.map +1 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/UnifiedApiGatewayEvent.d.ts +36 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/UnifiedApiGatewayEvent.js +3 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/UnifiedApiGatewayEvent.js.map +1 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/asApiGatewayResponsePayload.d.ts +19 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/asApiGatewayResponsePayload.js +24 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/asApiGatewayResponsePayload.js.map +1 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/asApiGatewayResponsePayloadJson.d.ts +26 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/asApiGatewayResponsePayloadJson.js +31 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/asApiGatewayResponsePayloadJson.js.map +1 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/asApiGatewayResponseSchema.d.ts +33 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/asApiGatewayResponseSchema.js +39 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/asApiGatewayResponseSchema.js.map +1 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/asUnifiedApiGatewayEvent.d.ts +27 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/asUnifiedApiGatewayEvent.js +118 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/asUnifiedApiGatewayEvent.js.map +1 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/genLambdaEndpoint.forApiGateway.d.ts +76 -36
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/genLambdaEndpoint.forApiGateway.js +153 -45
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/genLambdaEndpoint.forApiGateway.js.map +1 -1
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/getAllWirePayloadKeysFound.d.ts +8 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/getAllWirePayloadKeysFound.js +34 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/getAllWirePayloadKeysFound.js.map +1 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/isApiGatewayResponse.d.ts +19 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/isApiGatewayResponse.js +36 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/isApiGatewayResponse.js.map +1 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/middleware/genApiGatewayEventNormalizationMiddleware.d.ts +7 -24
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/middleware/genApiGatewayEventNormalizationMiddleware.js +19 -103
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/middleware/genApiGatewayEventNormalizationMiddleware.js.map +1 -1
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/middleware/genContentTypeCoherenceMiddleware.d.ts +20 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/middleware/genContentTypeCoherenceMiddleware.js +48 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/middleware/genContentTypeCoherenceMiddleware.js.map +1 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/middleware/genZodBodyValidationMiddleware.d.ts +16 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/middleware/genZodBodyValidationMiddleware.js +32 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/middleware/genZodBodyValidationMiddleware.js.map +1 -1
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forAskEndpoint/genLambdaEndpoint.forAskEndpoint.d.ts +6 -22
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forAskEndpoint/genLambdaEndpoint.forAskEndpoint.js +24 -18
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forAskEndpoint/genLambdaEndpoint.forAskEndpoint.js.map +1 -1
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forAskEndpoint/middleware/genZodEventValidationMiddleware.d.ts +11 -2
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forAskEndpoint/middleware/genZodEventValidationMiddleware.js +12 -2
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forAskEndpoint/middleware/genZodEventValidationMiddleware.js.map +1 -1
- package/dist/domain.operations/genLambdaEndpoint/middleware/asContextTrailed.d.ts +37 -0
- package/dist/domain.operations/genLambdaEndpoint/middleware/asContextTrailed.js +24 -0
- package/dist/domain.operations/genLambdaEndpoint/middleware/asContextTrailed.js.map +1 -0
- package/dist/domain.operations/genLambdaEndpoint/middleware/genConstraintErrorMiddleware.d.ts +18 -10
- package/dist/domain.operations/genLambdaEndpoint/middleware/genConstraintErrorMiddleware.js +20 -23
- package/dist/domain.operations/genLambdaEndpoint/middleware/genConstraintErrorMiddleware.js.map +1 -1
- package/dist/domain.operations/genLambdaEndpoint/middleware/genInternalServiceErrorMiddleware.d.ts +29 -6
- package/dist/domain.operations/genLambdaEndpoint/middleware/genInternalServiceErrorMiddleware.js +23 -28
- package/dist/domain.operations/genLambdaEndpoint/middleware/genInternalServiceErrorMiddleware.js.map +1 -1
- package/dist/domain.operations/genLambdaEndpoint/middleware/genIntrospectionMiddleware.d.ts +16 -1
- package/dist/domain.operations/genLambdaEndpoint/middleware/genIntrospectionMiddleware.js +9 -13
- package/dist/domain.operations/genLambdaEndpoint/middleware/genIntrospectionMiddleware.js.map +1 -1
- package/dist/domain.operations/genLambdaEndpoint/middleware/genIoLoggerMiddleware.d.ts +27 -6
- package/dist/domain.operations/genLambdaEndpoint/middleware/genIoLoggerMiddleware.js +29 -4
- package/dist/domain.operations/genLambdaEndpoint/middleware/genIoLoggerMiddleware.js.map +1 -1
- package/dist/domain.operations/genLambdaEndpoint/middleware/genTrailMiddleware.js +12 -4
- package/dist/domain.operations/genLambdaEndpoint/middleware/genTrailMiddleware.js.map +1 -1
- package/dist/domain.operations/genLambdaEndpoint/middleware/genZodOutputValidationMiddleware.d.ts +27 -2
- package/dist/domain.operations/genLambdaEndpoint/middleware/genZodOutputValidationMiddleware.js +34 -13
- package/dist/domain.operations/genLambdaEndpoint/middleware/genZodOutputValidationMiddleware.js.map +1 -1
- package/dist/domain.operations/genLambdaEndpoint/middleware/getErrorResponseBody.js +1 -0
- package/dist/domain.operations/genLambdaEndpoint/middleware/getErrorResponseBody.js.map +1 -1
- package/dist/domain.operations/genServiceSdk/asServiceSymbols/asServiceSymbols.d.ts +16 -0
- package/dist/domain.operations/genServiceSdk/asServiceSymbols/asServiceSymbols.js +36 -0
- package/dist/domain.operations/genServiceSdk/asServiceSymbols/asServiceSymbols.js.map +1 -0
- package/dist/domain.operations/genServiceSdk/gen.file/asBarrelFileSource.d.ts +10 -0
- package/dist/domain.operations/genServiceSdk/gen.file/asBarrelFileSource.js +18 -0
- package/dist/domain.operations/genServiceSdk/gen.file/asBarrelFileSource.js.map +1 -0
- package/dist/domain.operations/genServiceSdk/gen.file/asMechanismsFileSource.d.ts +14 -0
- package/dist/domain.operations/genServiceSdk/gen.file/asMechanismsFileSource.js +44 -0
- package/dist/domain.operations/genServiceSdk/gen.file/asMechanismsFileSource.js.map +1 -0
- package/dist/domain.operations/genServiceSdk/gen.file/asResourcesFileSource.d.ts +11 -0
- package/dist/domain.operations/genServiceSdk/gen.file/asResourcesFileSource.js +42 -0
- package/dist/domain.operations/genServiceSdk/gen.file/asResourcesFileSource.js.map +1 -0
- package/dist/domain.operations/genServiceSdk/gen.file/banner.d.ts +9 -0
- package/dist/domain.operations/genServiceSdk/gen.file/banner.js +16 -0
- package/dist/domain.operations/genServiceSdk/gen.file/banner.js.map +1 -0
- package/dist/domain.operations/genServiceSdk/gen.file/formatTypescript.d.ts +20 -0
- package/dist/domain.operations/genServiceSdk/gen.file/formatTypescript.js +44 -0
- package/dist/domain.operations/genServiceSdk/gen.file/formatTypescript.js.map +1 -0
- package/dist/domain.operations/genServiceSdk/gen.file/setGeneratedFilesBatch.d.ts +13 -0
- package/dist/domain.operations/genServiceSdk/gen.file/setGeneratedFilesBatch.js +49 -0
- package/dist/domain.operations/genServiceSdk/gen.file/setGeneratedFilesBatch.js.map +1 -0
- package/dist/domain.operations/genServiceSdk/gen.mechanism/asMechanismFnSource.d.ts +16 -0
- package/dist/domain.operations/genServiceSdk/gen.mechanism/asMechanismFnSource.js +39 -0
- package/dist/domain.operations/genServiceSdk/gen.mechanism/asMechanismFnSource.js.map +1 -0
- package/dist/domain.operations/genServiceSdk/gen.mechanism/getTypescriptFromJsonSchema.d.ts +35 -0
- package/dist/domain.operations/genServiceSdk/gen.mechanism/getTypescriptFromJsonSchema.js +189 -0
- package/dist/domain.operations/genServiceSdk/gen.mechanism/getTypescriptFromJsonSchema.js.map +1 -0
- package/dist/domain.operations/genServiceSdk/gen.resource/asDomainObjectPragma.d.ts +15 -0
- package/dist/domain.operations/genServiceSdk/gen.resource/asDomainObjectPragma.js +37 -0
- package/dist/domain.operations/genServiceSdk/gen.resource/asDomainObjectPragma.js.map +1 -0
- package/dist/domain.operations/genServiceSdk/gen.resource/asResourceClassSource.d.ts +26 -0
- package/dist/domain.operations/genServiceSdk/gen.resource/asResourceClassSource.js +106 -0
- package/dist/domain.operations/genServiceSdk/gen.resource/asResourceClassSource.js.map +1 -0
- package/dist/domain.operations/genServiceSdk/gen.resource/assertAllDomainObjectRefsBind.d.ts +15 -0
- package/dist/domain.operations/genServiceSdk/gen.resource/assertAllDomainObjectRefsBind.js +51 -0
- package/dist/domain.operations/genServiceSdk/gen.resource/assertAllDomainObjectRefsBind.js.map +1 -0
- package/dist/domain.operations/genServiceSdk/gen.resource/getAllDomainObjectsFromContracts.d.ts +14 -0
- package/dist/domain.operations/genServiceSdk/gen.resource/getAllDomainObjectsFromContracts.js +68 -0
- package/dist/domain.operations/genServiceSdk/gen.resource/getAllDomainObjectsFromContracts.js.map +1 -0
- package/dist/domain.operations/genServiceSdk/genServiceSdk.d.ts +20 -0
- package/dist/domain.operations/genServiceSdk/genServiceSdk.js +88 -0
- package/dist/domain.operations/genServiceSdk/genServiceSdk.js.map +1 -0
- package/dist/domain.operations/getAllLambdaContracts/getAllLambdaContracts.js +49 -4
- package/dist/domain.operations/getAllLambdaContracts/getAllLambdaContracts.js.map +1 -1
- package/dist/index.d.ts +38 -2
- package/dist/index.js +31 -1
- package/dist/index.js.map +1 -1
- package/package.json +18 -14
- package/readme.md +50 -2
|
@@ -8,26 +8,42 @@ const core_1 = __importDefault(require("@middy/core"));
|
|
|
8
8
|
const http_cors_1 = __importDefault(require("@middy/http-cors"));
|
|
9
9
|
const http_response_serializer_1 = __importDefault(require("@middy/http-response-serializer"));
|
|
10
10
|
const http_security_headers_1 = __importDefault(require("@middy/http-security-headers"));
|
|
11
|
+
const helpful_errors_1 = require("helpful-errors");
|
|
12
|
+
const asContextLogTrail_1 = require("../asContextLogTrail");
|
|
11
13
|
const genConstraintErrorMiddleware_1 = require("../middleware/genConstraintErrorMiddleware");
|
|
12
14
|
const genInternalServiceErrorMiddleware_1 = require("../middleware/genInternalServiceErrorMiddleware");
|
|
13
15
|
const genIntrospectionMiddleware_1 = require("../middleware/genIntrospectionMiddleware");
|
|
14
16
|
const genIoLoggerMiddleware_1 = require("../middleware/genIoLoggerMiddleware");
|
|
15
17
|
const genTrailMiddleware_1 = require("../middleware/genTrailMiddleware");
|
|
16
18
|
const getValidatedOutput_1 = require("../middleware/getValidatedOutput");
|
|
19
|
+
const asApiGatewayResponsePayload_1 = require("./asApiGatewayResponsePayload");
|
|
20
|
+
const asApiGatewayResponsePayloadJson_1 = require("./asApiGatewayResponsePayloadJson");
|
|
21
|
+
const asUnifiedApiGatewayEvent_1 = require("./asUnifiedApiGatewayEvent");
|
|
22
|
+
const getAllWirePayloadKeysFound_1 = require("./getAllWirePayloadKeysFound");
|
|
23
|
+
const isApiGatewayResponse_1 = require("./isApiGatewayResponse");
|
|
17
24
|
const genApiGatewayEventNormalizationMiddleware_1 = require("./middleware/genApiGatewayEventNormalizationMiddleware");
|
|
25
|
+
const genContentTypeCoherenceMiddleware_1 = require("./middleware/genContentTypeCoherenceMiddleware");
|
|
18
26
|
const genZodBodyValidationMiddleware_1 = require("./middleware/genZodBodyValidationMiddleware");
|
|
19
|
-
/**
|
|
20
|
-
* .what = converts cors config to @middy/http-cors format
|
|
21
|
-
* .why = simple-lambda-handlers pattern for cors configuration
|
|
22
|
-
*/
|
|
27
|
+
/** .what = converts this sdk's cors config into `@middy/http-cors` options */
|
|
23
28
|
const corsInputToCorsConfig = (cors) => {
|
|
24
29
|
return {
|
|
25
|
-
|
|
26
|
-
|
|
30
|
+
/**
|
|
31
|
+
* ⚠️ .what = supplies EITHER `origin` or `origins`, and OMITS the key it does not supply.
|
|
32
|
+
* NEVER pass a key you do not mean to set — not `maxAge`, not any later addition
|
|
33
|
+
* .why = `@middy/http-cors` merges as `{ ...defaults, ...opts }` (`index.cjs:44-47`), so an
|
|
34
|
+
* explicit `undefined` CLOBBERS the default. its `origins` default is `[]` and
|
|
35
|
+
* `getOrigin` opens with `options.origins.length` (`index.cjs:12-13`), so
|
|
36
|
+
* `origins: undefined` throws from `after` and turns every success into a 500
|
|
37
|
+
*/
|
|
38
|
+
...(cors.origins === '*' ? { origin: '*' } : { origins: cors.origins }),
|
|
27
39
|
credentials: cors.credentials,
|
|
28
40
|
headers: cors.headers ?? 'content-type,authorization',
|
|
29
|
-
|
|
30
|
-
|
|
41
|
+
/**
|
|
42
|
+
* ⚠️ .absent by choice = `disableBeforePreflightResponse: false` would turn on the vendor's
|
|
43
|
+
* `OPTIONS` short-circuit — limit 1 on `CorsConfig`. blast radius, probed: ONE case
|
|
44
|
+
* (`[case11]` moves to a 204). left because it changes `OPTIONS` for every
|
|
45
|
+
* cors-configured handler, and one that answers `OPTIONS` itself would lose the request
|
|
46
|
+
*/
|
|
31
47
|
};
|
|
32
48
|
};
|
|
33
49
|
const serializers = [
|
|
@@ -37,52 +53,132 @@ const serializers = [
|
|
|
37
53
|
},
|
|
38
54
|
];
|
|
39
55
|
/**
|
|
40
|
-
* .what = generates
|
|
41
|
-
* .why = adds cors, security headers, error
|
|
42
|
-
*
|
|
43
|
-
* follows simple-lambda-handlers createApiGatewayHandler pattern:
|
|
44
|
-
* - uses middy middleware chain
|
|
45
|
-
* - uses @middy/http-cors for dynamic origin match
|
|
46
|
-
* - uses @middy/http-security-headers for OWASP security headers
|
|
47
|
-
* - uses @middy/http-json-body-parser for json body parse
|
|
48
|
-
* - uses @middy/http-response-serializer for response serialization
|
|
56
|
+
* .what = generates an api-gateway lambda handler with http features
|
|
57
|
+
* .why = adds cors, security headers, error conversion, body serialization, and validation
|
|
49
58
|
*/
|
|
50
59
|
const forApiGateway = (config, context) => {
|
|
51
|
-
const deserialize = config.deserialize ??
|
|
52
|
-
|
|
60
|
+
const deserialize = config.deserialize ?? asUnifiedApiGatewayEvent_1.DESERIALIZE_DEFAULT;
|
|
61
|
+
/**
|
|
62
|
+
* .what = the handler's own step: invoke, assure, validate, encode
|
|
63
|
+
* .why = by here the chain has reconciled the request and refused a wrong body shape, so
|
|
64
|
+
* this reads as narrative
|
|
65
|
+
*/
|
|
53
66
|
const logic = async (event, lambdaContext) => {
|
|
54
|
-
//
|
|
55
|
-
const log = lambdaContext
|
|
56
|
-
|
|
67
|
+
// read the trail log `genTrailMiddleware` wrote; the cast lives in the shared reader
|
|
68
|
+
const { log } = (0, asContextLogTrail_1.asContextLogTrail)({ context: lambdaContext });
|
|
69
|
+
/**
|
|
70
|
+
* .as = `event.body` is `TInput` by the time this runs, because
|
|
71
|
+
* `genZodBodyValidationMiddleware` has already parsed it against `schema.input`
|
|
72
|
+
* and replaced it with the parsed value
|
|
73
|
+
* .removal = drops when the input translate owns this seam, which needs `inputAfter` to
|
|
74
|
+
* have one home across both chains — see the 🚧 note in the execution yield
|
|
75
|
+
*/
|
|
57
76
|
const response = await config.invoke({ event: event.body, rawEvent: event }, { log });
|
|
58
|
-
|
|
59
|
-
|
|
77
|
+
/**
|
|
78
|
+
* .what = refuses the aws WIRE shape, and names the rename that fixes it
|
|
79
|
+
* .why = `isApiGatewayResponse` rejects it too, but `withAssure` takes a name and no message,
|
|
80
|
+
* so its throw can only say "does not satisfy type.check". the likeliest upgrade
|
|
81
|
+
* mistake earns the fix by name (rule.require.errors-name-the-fix)
|
|
82
|
+
* .why MalfunctionError = the handler author is at fault, not the http caller. a
|
|
83
|
+
* ConstraintError would answer 400 and tell the caller THEY erred, which is false
|
|
84
|
+
* (invariant.badrequesterror-not-lambda-error)
|
|
85
|
+
*/
|
|
86
|
+
const keysOfWirePayload = typeof response === 'object' && response !== null
|
|
87
|
+
? (0, getAllWirePayloadKeysFound_1.getAllWirePayloadKeysFound)({ response })
|
|
88
|
+
: [];
|
|
89
|
+
if (keysOfWirePayload.length)
|
|
90
|
+
helpful_errors_1.MalfunctionError.throw('handler returned the aws wire payload shape rather than an ApiGatewayResponse', {
|
|
91
|
+
keysOfWirePayload,
|
|
92
|
+
fix: 'rename `statusCode` to `status`, and return the body as a value rather than a JSON string',
|
|
93
|
+
response,
|
|
94
|
+
});
|
|
95
|
+
// the throw above took every wire-payload response, so this closes the REST — a string, an
|
|
96
|
+
// array, a null. one names a fix for the likely mistake; this one covers the others
|
|
97
|
+
isApiGatewayResponse_1.isApiGatewayResponse.assure(response);
|
|
98
|
+
// validate the whole response envelope against the declared output schema
|
|
99
|
+
const validatedResponse = (0, getValidatedOutput_1.getValidatedOutput)({
|
|
60
100
|
response,
|
|
61
101
|
schema: config.schema.output,
|
|
62
102
|
});
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
body: validatedOutput,
|
|
66
|
-
};
|
|
103
|
+
// the wire encode — status defaults here, before any middleware observes the response
|
|
104
|
+
return (0, asApiGatewayResponsePayload_1.asApiGatewayResponsePayload)({ response: validatedResponse });
|
|
67
105
|
};
|
|
68
|
-
//
|
|
69
|
-
// 1. error
|
|
70
|
-
// 2.
|
|
71
|
-
// 3.
|
|
72
|
-
// 4.
|
|
73
|
-
// 5.
|
|
74
|
-
// 6.
|
|
75
|
-
// 7.
|
|
76
|
-
// 8.
|
|
77
|
-
// 9.
|
|
106
|
+
// 0. content-type coherence (after + onError) - drops Content-Type when the body is absent
|
|
107
|
+
// 1. constraint error (onError) - a caller fault becomes a 400
|
|
108
|
+
// 2. internal service error (onError) - any other throw becomes a 500
|
|
109
|
+
// 3. io logger (before/after/onError) - debug observability
|
|
110
|
+
// 4. response serializer (after) - encodes the body; skips a preset Content-Type
|
|
111
|
+
// 5. cors (after) - adds cors headers
|
|
112
|
+
// 6. security headers (after) - adds owasp headers
|
|
113
|
+
// 7. event normalization (before) - reconciles a v1/v2 request
|
|
114
|
+
// 8. trail (before) - injects trail context
|
|
115
|
+
// 9. introspection (before) - short-circuits an introspect request
|
|
116
|
+
// 10. body validation (before) - validates event.body against schema.input
|
|
117
|
+
//
|
|
118
|
+
// ⚠️ ORDER IS LOAD-BEARING, ON TWO AXES — middy holds the hook phases in OPPOSITE orders, and
|
|
119
|
+
// a break on either axis no-ops silently: no throw, no log, no type error. state your
|
|
120
|
+
// entry's needs against BOTH before you place it.
|
|
121
|
+
//
|
|
122
|
+
// ── `before` — FORWARD order ── an entry that READS what another `before` PRODUCES sits
|
|
123
|
+
// at a HIGHER index. producers: 7 -> unified `request.event`; 8 -> `request.context.log`
|
|
124
|
+
// + `isContempCaller`; 10 -> the validated `event.body`
|
|
125
|
+
//
|
|
126
|
+
// ── `after` / `onError` — REVERSE order (middy `unshift`s them) ── an entry whose
|
|
127
|
+
// `onError` READS `request.response` sits at a LOWER index than the builders (1,2) that
|
|
128
|
+
// SET it. entry 0 is last on both hooks, which is the only slot that can correct a
|
|
129
|
+
// header the serializer already stamped
|
|
130
|
+
//
|
|
131
|
+
// the `onError` family that reads `request.response` — membership by CAUSE, never by guard
|
|
132
|
+
// syntax (the vendors test `=== undefined`, the io logger tests truthiness):
|
|
133
|
+
// ✅ 0 genContentTypeCoherenceMiddleware -> runs LAST, sees the response
|
|
134
|
+
// ⛔ 3 genIoLoggerMiddleware -> runs EARLY, response undefined
|
|
135
|
+
// ⛔ 5 @middy/http-cors -> so NO cors on a 4xx/5xx
|
|
136
|
+
// ⛔ 6 @middy/http-security-headers -> so NO owasp on a 4xx/5xx
|
|
137
|
+
//
|
|
138
|
+
// the three ⛔ are ONE deferred fix (F32) — the reorder also moves the SUCCESS-path `after`
|
|
139
|
+
// order for every handler. the `before` axis is violated too; see the note on entry 3.
|
|
78
140
|
const middlewares = [
|
|
79
|
-
(0,
|
|
80
|
-
|
|
141
|
+
(0, genContentTypeCoherenceMiddleware_1.genContentTypeCoherenceMiddleware)(),
|
|
142
|
+
/**
|
|
143
|
+
* .note = both keep the invocation a SUCCESS — a caller fault must not emit a cloudwatch
|
|
144
|
+
* error (invariant.badrequesterror-not-lambda-error) — and the 500 body carries a
|
|
145
|
+
* generic message plus the correlation id, never the error's own message
|
|
146
|
+
*
|
|
147
|
+
* .note = this family is ALWAYS-ANCIENT by construction, so the shared middleware's
|
|
148
|
+
* `isContempCaller` branch resolves one way and needs no guard: an http payload is
|
|
149
|
+
* an api-gateway envelope, which `getIsWrappedPayload` cannot match, and where trail
|
|
150
|
+
* never ran `asContextTrailed` defaults the flag to `false`
|
|
151
|
+
*/
|
|
152
|
+
(0, genConstraintErrorMiddleware_1.genConstraintErrorMiddleware)({
|
|
153
|
+
asOutputAfter: (body) => (0, asApiGatewayResponsePayloadJson_1.asApiGatewayResponsePayloadJson)({ status: 400, body }),
|
|
154
|
+
}),
|
|
155
|
+
(0, genInternalServiceErrorMiddleware_1.genInternalServiceErrorMiddleware)({
|
|
156
|
+
asOutputAfter: ({ exid }) => (0, asApiGatewayResponsePayloadJson_1.asApiGatewayResponsePayloadJson)({
|
|
157
|
+
status: 500,
|
|
158
|
+
body: {
|
|
159
|
+
errorMessage: 'internal server error',
|
|
160
|
+
errorType: 'InternalServiceError',
|
|
161
|
+
...(exid ? { correlationId: exid } : {}),
|
|
162
|
+
},
|
|
163
|
+
}),
|
|
164
|
+
}),
|
|
165
|
+
/**
|
|
166
|
+
* ⚠️ .breaks the `before` axis, deliberately — this reads `request.context.log`, which
|
|
167
|
+
* `genTrailMiddleware` (8) produces, so `handler.input` never logs. the record is on
|
|
168
|
+
* `logTranslate`; the repair moves TRAIL to index 3, never this entry — trail declares
|
|
169
|
+
* only a `before`, so its move cannot disturb the `after`/`onError` order
|
|
170
|
+
*/
|
|
81
171
|
(0, genIoLoggerMiddleware_1.genIoLoggerMiddleware)({ logTranslate: config.logTranslate }),
|
|
82
172
|
(0, http_response_serializer_1.default)({
|
|
83
173
|
serializers,
|
|
84
174
|
defaultContentType: 'application/json',
|
|
85
175
|
}),
|
|
176
|
+
/**
|
|
177
|
+
* ⚠️ .breaks the `onError` axis, deliberately — these two sit BELOW the error builders, so
|
|
178
|
+
* their `onError` hooks run first, see no response, and no-op. that is limit 2 on
|
|
179
|
+
* `CorsConfig`. the repair also moves their `after` hooks relative to the serializer,
|
|
180
|
+
* so it changes every SUCCESS response's headers too
|
|
181
|
+
*/
|
|
86
182
|
...(config.cors ? [(0, http_cors_1.default)(corsInputToCorsConfig(config.cors))] : []),
|
|
87
183
|
(0, http_security_headers_1.default)({
|
|
88
184
|
frameOptions: { action: 'DENY' },
|
|
@@ -92,14 +188,26 @@ const forApiGateway = (config, context) => {
|
|
|
92
188
|
(0, genIntrospectionMiddleware_1.genIntrospectionMiddleware)({
|
|
93
189
|
schema: config.schema,
|
|
94
190
|
env: context?.env,
|
|
95
|
-
|
|
191
|
+
/**
|
|
192
|
+
* .what = this family keeps `inputAfter` at `event.body`, and owes a WIRE payload back
|
|
193
|
+
* .why = `request.event` must stay http-shaped for `@middy/http-cors`, so the caller's
|
|
194
|
+
* value rides at `event.body` rather than in the event's place. and the
|
|
195
|
+
* short-circuit bypasses the serializer, so the body is stringified here
|
|
196
|
+
*/
|
|
197
|
+
asInputAfter: (request) => request.event?.body,
|
|
198
|
+
asOutputAfter: (schema) => (0, asApiGatewayResponsePayloadJson_1.asApiGatewayResponsePayloadJson)({ status: 200, body: schema }),
|
|
96
199
|
}),
|
|
97
200
|
(0, genZodBodyValidationMiddleware_1.genZodBodyValidationMiddleware)({ schema: config.schema.input }),
|
|
98
201
|
];
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
202
|
+
/**
|
|
203
|
+
* .as = the chain translates both ends, and typescript cannot track a transform across a
|
|
204
|
+
* middleware chain:
|
|
205
|
+
* - input: ApiGatewayRequestPayload -> TInput (before logic)
|
|
206
|
+
* - output: ApiGatewayResponsePayload<TBody> -> ApiGatewayResponsePayload (after)
|
|
207
|
+
* the second is the serializer's step — it encodes the body to bytes
|
|
208
|
+
* .removal = drops if middy gains typed inference across `.use`; every shape it spans is
|
|
209
|
+
* already named, so only the cast is owed
|
|
210
|
+
*/
|
|
103
211
|
return (0, core_1.default)(logic).use(middlewares);
|
|
104
212
|
};
|
|
105
213
|
exports.forApiGateway = forApiGateway;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"genLambdaEndpoint.forApiGateway.js","sourceRoot":"","sources":["../../../../src/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/genLambdaEndpoint.forApiGateway.ts"],"names":[],"mappings":";;;;;;AAAA,uDAAgC;AAChC,iEAAwC;AACxC,+FAAqE;AACrE,yFAA+D;
|
|
1
|
+
{"version":3,"file":"genLambdaEndpoint.forApiGateway.js","sourceRoot":"","sources":["../../../../src/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/genLambdaEndpoint.forApiGateway.ts"],"names":[],"mappings":";;;;;;AAAA,uDAAgC;AAChC,iEAAwC;AACxC,+FAAqE;AACrE,yFAA+D;AAE/D,mDAAkD;AAQlD,4DAAyD;AACzD,6FAA0F;AAC1F,uGAAoG;AACpG,yFAAsF;AACtF,+EAA4E;AAC5E,yEAAsE;AACtE,yEAAsE;AAEtE,+EAA4E;AAC5E,uFAAoF;AACpF,yEAAiE;AACjE,6EAA0E;AAC1E,iEAA8D;AAC9D,sHAAmH;AACnH,sGAAmG;AACnG,gGAA6F;AAgI7F,8EAA8E;AAC9E,MAAM,qBAAqB,GAAG,CAAC,IAAgB,EAAE,EAAE;IACjD,OAAO;QACL;;;;;;;WAOG;QACH,GAAG,CAAC,IAAI,CAAC,OAAO,KAAK,GAAG,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,CAAC;QACvE,WAAW,EAAE,IAAI,CA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
|
+
* .what = lists which aws wire-payload keys a handler's response carries
|
|
3
|
+
* .why = one detector, so the public type-check and the handler-side guard cannot drift. the
|
|
4
|
+
* check needs a boolean; the guard needs the key NAMES to tell the author the fix
|
|
5
|
+
*/
|
|
6
|
+
export declare const getAllWirePayloadKeysFound: (input: {
|
|
7
|
+
response: object;
|
|
8
|
+
}) => string[];
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getAllWirePayloadKeysFound = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* .what = the wire keys a mid-migration consumer writes from habit, every one of which the
|
|
6
|
+
* encode would drop without a word
|
|
7
|
+
*
|
|
8
|
+
* .note = `statusCode` is the severe one — the one field whose name changed (`status`), so
|
|
9
|
+
* `status ?? 200` replaces a caller's 404 with a 200 AND double-encodes the body they
|
|
10
|
+
* already stringified. the rest are deferred keys (F7), quieter but equally silent
|
|
11
|
+
*
|
|
12
|
+
* .note = a `Record<K, true>` rather than a `string[]`, so the compiler holds it EXHAUSTIVE: a
|
|
13
|
+
* list proves each entry is real and says not one word about one being ABSENT, which is
|
|
14
|
+
* the drift that matters. clamp proven to bite — drop a key and tsc raises TS2741
|
|
15
|
+
*/
|
|
16
|
+
const IS_KEY_OF_WIRE_PAYLOAD_UNREAD = {
|
|
17
|
+
statusCode: true,
|
|
18
|
+
multiValueHeaders: true,
|
|
19
|
+
isBase64Encoded: true,
|
|
20
|
+
cookies: true,
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* .what = the same list, as keys
|
|
24
|
+
* .why = one source of truth, so the exhaustive map and the iterated list cannot drift apart
|
|
25
|
+
*/
|
|
26
|
+
const KEYS_OF_WIRE_PAYLOAD = Object.keys(IS_KEY_OF_WIRE_PAYLOAD_UNREAD);
|
|
27
|
+
/**
|
|
28
|
+
* .what = lists which aws wire-payload keys a handler's response carries
|
|
29
|
+
* .why = one detector, so the public type-check and the handler-side guard cannot drift. the
|
|
30
|
+
* check needs a boolean; the guard needs the key NAMES to tell the author the fix
|
|
31
|
+
*/
|
|
32
|
+
const getAllWirePayloadKeysFound = (input) => KEYS_OF_WIRE_PAYLOAD.filter((key) => key in input.response);
|
|
33
|
+
exports.getAllWirePayloadKeysFound = getAllWirePayloadKeysFound;
|
|
34
|
+
//# sourceMappingURL=getAllWirePayloadKeysFound.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getAllWirePayloadKeysFound.js","sourceRoot":"","sources":["../../../../src/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/getAllWirePayloadKeysFound.ts"],"names":[],"mappings":";;;AAgBA;;;;;;;;;;;GAWG;AACH,MAAM,6BAA6B,GAAyC;IAC1E,UAAU,EAAE,IAAI;IAChB,iBAAiB,EAAE,IAAI;IACvB,eAAe,EAAE,IAAI;IACrB,OAAO,EAAE,IAAI;CACd,CAAC;AAEF;;;GAGG;AACH,MAAM,oBAAoB,GAAa,MAAM,CAAC,IAAI,CAChD,6BAA6B,CAC9B,CAAC;AAEF;;;;GAIG;AACI,MAAM,0BAA0B,GAAG,CAAC,KAE1C,EAAY,EAAE,CAAC,oBAAoB,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,IAAI,KAAK,CAAC,QAAQ,CAAC,CAAC;AAF/D,QAAA,0BAA0B,8BAEqC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { ApiGatewayResponse } from '../../../domain.objects/ApiGatewayResponse';
|
|
2
|
+
/**
|
|
3
|
+
* .what = checks that a value is an ApiGatewayResponse — an object with at least one of
|
|
4
|
+
* status, headers, or body, and none of the aws wire-payload keys
|
|
5
|
+
* .why = the type refuses `{}` at compile time, but a handler's return crosses an
|
|
6
|
+
* `unknown` boundary at run time (a js caller, an `any`, a cast). this is the
|
|
7
|
+
* runtime backstop for the invariants the type holds
|
|
8
|
+
*
|
|
9
|
+
* .note = it checks CARDINALITY and FOREIGN KEYS, not field types. the field types are
|
|
10
|
+
* `schema.output`'s job; this exists so an empty, non-object, or wire-shaped return
|
|
11
|
+
* fails loud HERE rather than reach middy's `statusCode ??= 500` and emit a silent 500
|
|
12
|
+
*
|
|
13
|
+
* .note = the foreign-key half closes a MIGRATION hazard the cardinality half could not see.
|
|
14
|
+
* `{ statusCode: 404, body: JSON.stringify(x) }` — the aws-native shape, and the one
|
|
15
|
+
* the wish's own `.ground` evidence used — satisfies `'body' in input`, so it used to
|
|
16
|
+
* pass. it then lost its 404 to `status ?? 200` and had its body encoded twice
|
|
17
|
+
* (rule.forbid.failhide)
|
|
18
|
+
*/
|
|
19
|
+
export declare const isApiGatewayResponse: import("type-fns").AssessWithAssure<unknown, ApiGatewayResponse<unknown>>;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isApiGatewayResponse = void 0;
|
|
4
|
+
const type_fns_1 = require("type-fns");
|
|
5
|
+
const getAllWirePayloadKeysFound_1 = require("./getAllWirePayloadKeysFound");
|
|
6
|
+
/**
|
|
7
|
+
* .what = checks that a value is an ApiGatewayResponse — an object with at least one of
|
|
8
|
+
* status, headers, or body, and none of the aws wire-payload keys
|
|
9
|
+
* .why = the type refuses `{}` at compile time, but a handler's return crosses an
|
|
10
|
+
* `unknown` boundary at run time (a js caller, an `any`, a cast). this is the
|
|
11
|
+
* runtime backstop for the invariants the type holds
|
|
12
|
+
*
|
|
13
|
+
* .note = it checks CARDINALITY and FOREIGN KEYS, not field types. the field types are
|
|
14
|
+
* `schema.output`'s job; this exists so an empty, non-object, or wire-shaped return
|
|
15
|
+
* fails loud HERE rather than reach middy's `statusCode ??= 500` and emit a silent 500
|
|
16
|
+
*
|
|
17
|
+
* .note = the foreign-key half closes a MIGRATION hazard the cardinality half could not see.
|
|
18
|
+
* `{ statusCode: 404, body: JSON.stringify(x) }` — the aws-native shape, and the one
|
|
19
|
+
* the wish's own `.ground` evidence used — satisfies `'body' in input`, so it used to
|
|
20
|
+
* pass. it then lost its 404 to `status ?? 200` and had its body encoded twice
|
|
21
|
+
* (rule.forbid.failhide)
|
|
22
|
+
*/
|
|
23
|
+
exports.isApiGatewayResponse = (0, type_fns_1.withAssure)((input) => {
|
|
24
|
+
// reject a non-object; a response is always an envelope
|
|
25
|
+
if (typeof input !== 'object' || input === null)
|
|
26
|
+
return false;
|
|
27
|
+
// reject an array; api gateway has no array response shape
|
|
28
|
+
if (Array.isArray(input))
|
|
29
|
+
return false;
|
|
30
|
+
// reject the aws wire shape; no step here reads its keys, so they would vanish
|
|
31
|
+
if ((0, getAllWirePayloadKeysFound_1.getAllWirePayloadKeysFound)({ response: input }).length)
|
|
32
|
+
return false;
|
|
33
|
+
// require at least one of the three fields — this is what PickAny encodes
|
|
34
|
+
return 'status' in input || 'headers' in input || 'body' in input;
|
|
35
|
+
}, { name: 'isApiGatewayResponse' });
|
|
36
|
+
//# sourceMappingURL=isApiGatewayResponse.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isApiGatewayResponse.js","sourceRoot":"","sources":["../../../../src/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/isApiGatewayResponse.ts"],"names":[],"mappings":";;;AAAA,uCAAsC;AAGtC,6EAA0E;AAE1E;;;;;;;;;;;;;;;;GAgBG;AACU,QAAA,oBAAoB,GAAG,IAAA,qBAAU,EAC5C,CAAC,KAAc,EAAwC,EAAE;IACvD,wDAAwD;IACxD,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,KAAK,CAAC;IAE9D,2DAA2D;IAC3D,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IAEvC,+EAA+E;IAC/E,IAAI,IAAA,uDAA0B,EAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC,CAAC,MAAM;QAAE,OAAO,KAAK,CAAC;IAEzE,0EAA0E;IAC1E,OAAO,QAAQ,IAAI,KAAK,IAAI,SAAS,IAAI,KAAK,IAAI,MAAM,IAAI,KAAK,CAAC;AACpE,CAAC,EACD,EAAE,IAAI,EAAE,sBAAsB,EAAE,CACjC,CAAC"}
|
|
@@ -1,29 +1,12 @@
|
|
|
1
1
|
import type middy from '@middy/core';
|
|
2
|
-
import type { APIGatewayProxyEvent, APIGatewayProxyEventV2 } from 'aws-lambda';
|
|
3
2
|
/**
|
|
4
|
-
* .what =
|
|
5
|
-
* .why =
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
queryStringParameters: Record<string, string | undefined> | null;
|
|
12
|
-
pathParameters: Record<string, string | undefined> | null;
|
|
13
|
-
body: unknown;
|
|
14
|
-
rawBody: string | null;
|
|
15
|
-
isBase64Encoded: boolean;
|
|
16
|
-
requestContext: {
|
|
17
|
-
requestId: string;
|
|
18
|
-
stage: string;
|
|
19
|
-
domainName?: string;
|
|
20
|
-
accountId?: string;
|
|
21
|
-
};
|
|
22
|
-
rawEvent: APIGatewayProxyEvent | APIGatewayProxyEventV2;
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* .what = converts v1/v2 API Gateway events to unified format
|
|
26
|
-
* .why = handlers work with consistent event shape regardless of API type
|
|
3
|
+
* .what = replaces the event with the v1/v2-reconciled shape
|
|
4
|
+
* .why = the api-gateway chain must read the same whichever version the trigger delivers, so
|
|
5
|
+
* this runs first and every step after it reads one shape
|
|
6
|
+
*
|
|
7
|
+
* .note = this DELEGATES to `asUnifiedApiGatewayEvent` rather than hold its own copy of the
|
|
8
|
+
* reconcile logic. one guarantee, one implementation, two entry points — a second
|
|
9
|
+
* copy would be the parallel code path (rule.forbid.parallel-codepaths)
|
|
27
10
|
*/
|
|
28
11
|
export declare const genApiGatewayEventNormalizationMiddleware: (input: {
|
|
29
12
|
parseBody: boolean;
|
|
@@ -1,113 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.genApiGatewayEventNormalizationMiddleware = void 0;
|
|
4
|
-
const
|
|
5
|
-
const getIsV1ApiGatewayEvent_1 = require("../getIsV1ApiGatewayEvent");
|
|
6
|
-
const getIsV2ApiGatewayEvent_1 = require("../getIsV2ApiGatewayEvent");
|
|
4
|
+
const asUnifiedApiGatewayEvent_1 = require("../asUnifiedApiGatewayEvent");
|
|
7
5
|
/**
|
|
8
|
-
* .what =
|
|
9
|
-
* .why =
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const decoded = input.isBase64Encoded
|
|
16
|
-
? Buffer.from(input.body, 'base64').toString('utf-8')
|
|
17
|
-
: input.body;
|
|
18
|
-
// parse json or return raw string
|
|
19
|
-
try {
|
|
20
|
-
return JSON.parse(decoded);
|
|
21
|
-
}
|
|
22
|
-
catch {
|
|
23
|
-
return decoded;
|
|
24
|
-
}
|
|
25
|
-
};
|
|
26
|
-
/**
|
|
27
|
-
* .what = convert v2 HTTP API event to unified format
|
|
28
|
-
* .why = isolates transformation logic from orchestrator
|
|
29
|
-
*/
|
|
30
|
-
const asUnifiedEventFromV2 = (input) => {
|
|
31
|
-
const body = input.parseBody
|
|
32
|
-
? getParsedApiGatewayBody({
|
|
33
|
-
body: input.event.body,
|
|
34
|
-
isBase64Encoded: input.event.isBase64Encoded,
|
|
35
|
-
})
|
|
36
|
-
: input.event.body;
|
|
37
|
-
return {
|
|
38
|
-
httpMethod: input.event.requestContext.http.method,
|
|
39
|
-
path: input.event.requestContext.http.path,
|
|
40
|
-
headers: input.event.headers,
|
|
41
|
-
queryStringParameters: input.event.queryStringParameters ?? null,
|
|
42
|
-
pathParameters: input.event.pathParameters ?? null,
|
|
43
|
-
body,
|
|
44
|
-
rawBody: input.event.body ?? null,
|
|
45
|
-
isBase64Encoded: input.event.isBase64Encoded,
|
|
46
|
-
requestContext: {
|
|
47
|
-
requestId: input.event.requestContext.requestId,
|
|
48
|
-
stage: input.event.requestContext.stage,
|
|
49
|
-
domainName: input.event.requestContext.domainName,
|
|
50
|
-
accountId: input.event.requestContext.accountId,
|
|
51
|
-
},
|
|
52
|
-
rawEvent: input.event,
|
|
53
|
-
};
|
|
54
|
-
};
|
|
55
|
-
/**
|
|
56
|
-
* .what = convert v1 REST API event to unified format
|
|
57
|
-
* .why = isolates transformation logic from orchestrator
|
|
58
|
-
*/
|
|
59
|
-
const asUnifiedEventFromV1 = (input) => {
|
|
60
|
-
const body = input.parseBody
|
|
61
|
-
? getParsedApiGatewayBody({
|
|
62
|
-
body: input.event.body,
|
|
63
|
-
isBase64Encoded: input.event.isBase64Encoded,
|
|
64
|
-
})
|
|
65
|
-
: input.event.body;
|
|
66
|
-
return {
|
|
67
|
-
httpMethod: input.event.httpMethod,
|
|
68
|
-
path: input.event.path,
|
|
69
|
-
headers: input.event.headers,
|
|
70
|
-
queryStringParameters: input.event.queryStringParameters ?? null,
|
|
71
|
-
pathParameters: input.event.pathParameters ?? null,
|
|
72
|
-
body,
|
|
73
|
-
rawBody: input.event.body ?? null,
|
|
74
|
-
isBase64Encoded: input.event.isBase64Encoded,
|
|
75
|
-
requestContext: {
|
|
76
|
-
requestId: input.event.requestContext.requestId,
|
|
77
|
-
stage: input.event.requestContext.stage,
|
|
78
|
-
domainName: input.event.requestContext.domainName,
|
|
79
|
-
accountId: input.event.requestContext.accountId,
|
|
80
|
-
},
|
|
81
|
-
rawEvent: input.event,
|
|
82
|
-
};
|
|
83
|
-
};
|
|
84
|
-
/**
|
|
85
|
-
* .what = converts v1/v2 API Gateway events to unified format
|
|
86
|
-
* .why = handlers work with consistent event shape regardless of API type
|
|
6
|
+
* .what = replaces the event with the v1/v2-reconciled shape
|
|
7
|
+
* .why = the api-gateway chain must read the same whichever version the trigger delivers, so
|
|
8
|
+
* this runs first and every step after it reads one shape
|
|
9
|
+
*
|
|
10
|
+
* .note = this DELEGATES to `asUnifiedApiGatewayEvent` rather than hold its own copy of the
|
|
11
|
+
* reconcile logic. one guarantee, one implementation, two entry points — a second
|
|
12
|
+
* copy would be the parallel code path (rule.forbid.parallel-codepaths)
|
|
87
13
|
*/
|
|
88
14
|
const genApiGatewayEventNormalizationMiddleware = (input) => {
|
|
89
15
|
const before = async (request) => {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
request.event = asUnifiedEventFromV1({
|
|
102
|
-
event: rawEvent,
|
|
103
|
-
parseBody: input.parseBody,
|
|
104
|
-
});
|
|
105
|
-
return;
|
|
106
|
-
}
|
|
107
|
-
// fail if neither v1 nor v2
|
|
108
|
-
throw new helpful_errors_1.MalfunctionError('event is neither v1 nor v2 API Gateway event', {
|
|
109
|
-
rawEvent,
|
|
110
|
-
});
|
|
16
|
+
/**
|
|
17
|
+
* .as = both casts exist because this middleware is typed `<any, any>`, so `request.event`
|
|
18
|
+
* is `any` on the way in and its declared type on the way out. the transform is
|
|
19
|
+
* real — `ApiGatewayRequestPayload` becomes `UnifiedApiGatewayEvent` — and middy
|
|
20
|
+
* cannot track a shape change across a `before` hook
|
|
21
|
+
* .removal = drops when middy gains typed inference across `.use`, at which point the
|
|
22
|
+
* middleware's own two type parameters name these shapes and no cast is owed
|
|
23
|
+
*
|
|
24
|
+
* .note = DELIBERATE MUTATION — `request` is middy's only channel to hand a value onward
|
|
25
|
+
*/
|
|
26
|
+
request.event = (0, asUnifiedApiGatewayEvent_1.asUnifiedApiGatewayEvent)({ payload: request.event }, { deserialize: { body: input.parseBody } });
|
|
111
27
|
};
|
|
112
28
|
return { before };
|
|
113
29
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"genApiGatewayEventNormalizationMiddleware.js","sourceRoot":"","sources":["../../../../../src/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/middleware/genApiGatewayEventNormalizationMiddleware.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"genApiGatewayEventNormalizationMiddleware.js","sourceRoot":"","sources":["../../../../../src/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/middleware/genApiGatewayEventNormalizationMiddleware.ts"],"names":[],"mappings":";;;AAGA,0EAAuE;AAEvE;;;;;;;;GAQG;AACI,MAAM,yCAAyC,GAAG,CAAC,KAEzD,EAEC,EAAE;IACF,MAAM,MAAM,GAAiC,KAAK,EAAE,OAAO,EAAE,EAAE;QAC7D;;;;;;;;;WASG;QACH,OAAO,CAAC,KAAK,GAAG,IAAA,mDAAwB,EACtC,EAAE,OAAO,EAAE,OAAO,CAAC,KAAiC,EAAE,EACtD,EAAE,WAAW,EAAE,EAAE,IAAI,EAAE,KAAK,CAAC,SAAS,EAAE,EAAE,CACR,CAAC;IACvC,CAAC,CAAC;IAEF,OAAO,EAAE,MAAM,EAAE,CAAC;AACpB,CAAC,CAAC;AAvBW,QAAA,yCAAyC,6CAuBpD"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type middy from '@middy/core';
|
|
2
|
+
/**
|
|
3
|
+
* .what = removes `Content-Type` from a response that carries no body
|
|
4
|
+
* .why = a content-type that contradicts the body is the exact shape that raises twilio 11200 —
|
|
5
|
+
* the defect this whole affordance exists to retire. a 204 and a 308 each reach the wire
|
|
6
|
+
* body-less and would otherwise claim `application/json`
|
|
7
|
+
*
|
|
8
|
+
* ⚠️ .note = MUST be registered FIRST in the chain array. middy `unshift`s `after` and `onError`,
|
|
9
|
+
* so index 0 runs LAST on both — the only position later than the serializer that stamps
|
|
10
|
+
* the header, and later than the error builders that set `request.response`. anywhere
|
|
11
|
+
* else, the `onError` hook meets an absent response and returns early
|
|
12
|
+
*
|
|
13
|
+
* .note = the same function serves both hooks, so one implementation holds the guarantee on
|
|
14
|
+
* either path. no error response is body-less today, so `onError` finds no work yet; it
|
|
15
|
+
* is registered for a future body-less error status (a 304, a 205)
|
|
16
|
+
*/
|
|
17
|
+
export declare const genContentTypeCoherenceMiddleware: () => {
|
|
18
|
+
after: middy.MiddlewareFn<any, any>;
|
|
19
|
+
onError: middy.MiddlewareFn<any, any>;
|
|
20
|
+
};
|