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.
Files changed (149) hide show
  1. package/dist/contract/cli/asGenArgs.d.ts +21 -0
  2. package/dist/contract/cli/asGenArgs.js +69 -0
  3. package/dist/contract/cli/asGenArgs.js.map +1 -0
  4. package/dist/contract/cli/gen.d.ts +23 -0
  5. package/dist/contract/cli/gen.js +72 -0
  6. package/dist/contract/cli/gen.js.map +1 -0
  7. package/dist/domain.objects/ApiGatewayRequestPayload.d.ts +12 -0
  8. package/dist/domain.objects/ApiGatewayRequestPayload.js +3 -0
  9. package/dist/domain.objects/ApiGatewayRequestPayload.js.map +1 -0
  10. package/dist/domain.objects/ApiGatewayResponse.d.ts +30 -0
  11. package/dist/domain.objects/ApiGatewayResponse.js +3 -0
  12. package/dist/domain.objects/ApiGatewayResponse.js.map +1 -0
  13. package/dist/domain.objects/ApiGatewayResponsePayload.d.ts +30 -0
  14. package/dist/domain.objects/ApiGatewayResponsePayload.js +3 -0
  15. package/dist/domain.objects/ApiGatewayResponsePayload.js.map +1 -0
  16. package/dist/domain.objects/DomainObjectCaptured.d.ts +51 -0
  17. package/dist/domain.objects/DomainObjectCaptured.js +8 -0
  18. package/dist/domain.objects/DomainObjectCaptured.js.map +1 -0
  19. package/dist/domain.objects/GeneratedFile.d.ts +18 -0
  20. package/dist/domain.objects/GeneratedFile.js +8 -0
  21. package/dist/domain.objects/GeneratedFile.js.map +1 -0
  22. package/dist/domain.objects/HttpStatusCode.d.ts +1 -0
  23. package/dist/domain.objects/HttpStatusCode.js +1 -0
  24. package/dist/domain.objects/HttpStatusCode.js.map +1 -1
  25. package/dist/domain.objects/LambdaCredentialsAbsentError.d.ts +11 -0
  26. package/dist/domain.objects/LambdaCredentialsAbsentError.js +16 -0
  27. package/dist/domain.objects/LambdaCredentialsAbsentError.js.map +1 -0
  28. package/dist/domain.objects/LambdaDomainObjectNotCapturableError.d.ts +12 -0
  29. package/dist/domain.objects/LambdaDomainObjectNotCapturableError.js +17 -0
  30. package/dist/domain.objects/LambdaDomainObjectNotCapturableError.js.map +1 -0
  31. package/dist/domain.objects/LambdaDomainObjectRefUnbindableError.d.ts +14 -0
  32. package/dist/domain.objects/LambdaDomainObjectRefUnbindableError.js +19 -0
  33. package/dist/domain.objects/LambdaDomainObjectRefUnbindableError.js.map +1 -0
  34. package/dist/domain.operations/genLambdaEndpoint/TranslateLog.d.ts +29 -0
  35. package/dist/domain.operations/genLambdaEndpoint/TranslateLog.js +3 -0
  36. package/dist/domain.operations/genLambdaEndpoint/TranslateLog.js.map +1 -0
  37. package/dist/domain.operations/genLambdaEndpoint/asContextLogTrail.d.ts +29 -0
  38. package/dist/domain.operations/genLambdaEndpoint/asContextLogTrail.js +30 -0
  39. package/dist/domain.operations/genLambdaEndpoint/asContextLogTrail.js.map +1 -0
  40. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/UnifiedApiGatewayEvent.d.ts +36 -0
  41. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/UnifiedApiGatewayEvent.js +3 -0
  42. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/UnifiedApiGatewayEvent.js.map +1 -0
  43. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/asApiGatewayResponsePayload.d.ts +19 -0
  44. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/asApiGatewayResponsePayload.js +24 -0
  45. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/asApiGatewayResponsePayload.js.map +1 -0
  46. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/asApiGatewayResponsePayloadJson.d.ts +26 -0
  47. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/asApiGatewayResponsePayloadJson.js +31 -0
  48. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/asApiGatewayResponsePayloadJson.js.map +1 -0
  49. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/asApiGatewayResponseSchema.d.ts +33 -0
  50. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/asApiGatewayResponseSchema.js +39 -0
  51. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/asApiGatewayResponseSchema.js.map +1 -0
  52. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/asUnifiedApiGatewayEvent.d.ts +27 -0
  53. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/asUnifiedApiGatewayEvent.js +118 -0
  54. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/asUnifiedApiGatewayEvent.js.map +1 -0
  55. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/genLambdaEndpoint.forApiGateway.d.ts +76 -36
  56. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/genLambdaEndpoint.forApiGateway.js +153 -45
  57. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/genLambdaEndpoint.forApiGateway.js.map +1 -1
  58. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/getAllWirePayloadKeysFound.d.ts +8 -0
  59. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/getAllWirePayloadKeysFound.js +34 -0
  60. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/getAllWirePayloadKeysFound.js.map +1 -0
  61. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/isApiGatewayResponse.d.ts +19 -0
  62. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/isApiGatewayResponse.js +36 -0
  63. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/isApiGatewayResponse.js.map +1 -0
  64. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/middleware/genApiGatewayEventNormalizationMiddleware.d.ts +7 -24
  65. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/middleware/genApiGatewayEventNormalizationMiddleware.js +19 -103
  66. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/middleware/genApiGatewayEventNormalizationMiddleware.js.map +1 -1
  67. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/middleware/genContentTypeCoherenceMiddleware.d.ts +20 -0
  68. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/middleware/genContentTypeCoherenceMiddleware.js +48 -0
  69. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/middleware/genContentTypeCoherenceMiddleware.js.map +1 -0
  70. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/middleware/genZodBodyValidationMiddleware.d.ts +16 -0
  71. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/middleware/genZodBodyValidationMiddleware.js +32 -0
  72. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/middleware/genZodBodyValidationMiddleware.js.map +1 -1
  73. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forAskEndpoint/genLambdaEndpoint.forAskEndpoint.d.ts +6 -22
  74. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forAskEndpoint/genLambdaEndpoint.forAskEndpoint.js +24 -18
  75. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forAskEndpoint/genLambdaEndpoint.forAskEndpoint.js.map +1 -1
  76. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forAskEndpoint/middleware/genZodEventValidationMiddleware.d.ts +11 -2
  77. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forAskEndpoint/middleware/genZodEventValidationMiddleware.js +12 -2
  78. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forAskEndpoint/middleware/genZodEventValidationMiddleware.js.map +1 -1
  79. package/dist/domain.operations/genLambdaEndpoint/middleware/asContextTrailed.d.ts +37 -0
  80. package/dist/domain.operations/genLambdaEndpoint/middleware/asContextTrailed.js +24 -0
  81. package/dist/domain.operations/genLambdaEndpoint/middleware/asContextTrailed.js.map +1 -0
  82. package/dist/domain.operations/genLambdaEndpoint/middleware/genConstraintErrorMiddleware.d.ts +18 -10
  83. package/dist/domain.operations/genLambdaEndpoint/middleware/genConstraintErrorMiddleware.js +20 -23
  84. package/dist/domain.operations/genLambdaEndpoint/middleware/genConstraintErrorMiddleware.js.map +1 -1
  85. package/dist/domain.operations/genLambdaEndpoint/middleware/genInternalServiceErrorMiddleware.d.ts +29 -6
  86. package/dist/domain.operations/genLambdaEndpoint/middleware/genInternalServiceErrorMiddleware.js +23 -28
  87. package/dist/domain.operations/genLambdaEndpoint/middleware/genInternalServiceErrorMiddleware.js.map +1 -1
  88. package/dist/domain.operations/genLambdaEndpoint/middleware/genIntrospectionMiddleware.d.ts +16 -1
  89. package/dist/domain.operations/genLambdaEndpoint/middleware/genIntrospectionMiddleware.js +9 -13
  90. package/dist/domain.operations/genLambdaEndpoint/middleware/genIntrospectionMiddleware.js.map +1 -1
  91. package/dist/domain.operations/genLambdaEndpoint/middleware/genIoLoggerMiddleware.d.ts +27 -6
  92. package/dist/domain.operations/genLambdaEndpoint/middleware/genIoLoggerMiddleware.js +29 -4
  93. package/dist/domain.operations/genLambdaEndpoint/middleware/genIoLoggerMiddleware.js.map +1 -1
  94. package/dist/domain.operations/genLambdaEndpoint/middleware/genTrailMiddleware.js +12 -4
  95. package/dist/domain.operations/genLambdaEndpoint/middleware/genTrailMiddleware.js.map +1 -1
  96. package/dist/domain.operations/genLambdaEndpoint/middleware/genZodOutputValidationMiddleware.d.ts +27 -2
  97. package/dist/domain.operations/genLambdaEndpoint/middleware/genZodOutputValidationMiddleware.js +34 -13
  98. package/dist/domain.operations/genLambdaEndpoint/middleware/genZodOutputValidationMiddleware.js.map +1 -1
  99. package/dist/domain.operations/genLambdaEndpoint/middleware/getErrorResponseBody.js +1 -0
  100. package/dist/domain.operations/genLambdaEndpoint/middleware/getErrorResponseBody.js.map +1 -1
  101. package/dist/domain.operations/genServiceSdk/asServiceSymbols/asServiceSymbols.d.ts +16 -0
  102. package/dist/domain.operations/genServiceSdk/asServiceSymbols/asServiceSymbols.js +36 -0
  103. package/dist/domain.operations/genServiceSdk/asServiceSymbols/asServiceSymbols.js.map +1 -0
  104. package/dist/domain.operations/genServiceSdk/gen.file/asBarrelFileSource.d.ts +10 -0
  105. package/dist/domain.operations/genServiceSdk/gen.file/asBarrelFileSource.js +18 -0
  106. package/dist/domain.operations/genServiceSdk/gen.file/asBarrelFileSource.js.map +1 -0
  107. package/dist/domain.operations/genServiceSdk/gen.file/asMechanismsFileSource.d.ts +14 -0
  108. package/dist/domain.operations/genServiceSdk/gen.file/asMechanismsFileSource.js +44 -0
  109. package/dist/domain.operations/genServiceSdk/gen.file/asMechanismsFileSource.js.map +1 -0
  110. package/dist/domain.operations/genServiceSdk/gen.file/asResourcesFileSource.d.ts +11 -0
  111. package/dist/domain.operations/genServiceSdk/gen.file/asResourcesFileSource.js +42 -0
  112. package/dist/domain.operations/genServiceSdk/gen.file/asResourcesFileSource.js.map +1 -0
  113. package/dist/domain.operations/genServiceSdk/gen.file/banner.d.ts +9 -0
  114. package/dist/domain.operations/genServiceSdk/gen.file/banner.js +16 -0
  115. package/dist/domain.operations/genServiceSdk/gen.file/banner.js.map +1 -0
  116. package/dist/domain.operations/genServiceSdk/gen.file/formatTypescript.d.ts +20 -0
  117. package/dist/domain.operations/genServiceSdk/gen.file/formatTypescript.js +44 -0
  118. package/dist/domain.operations/genServiceSdk/gen.file/formatTypescript.js.map +1 -0
  119. package/dist/domain.operations/genServiceSdk/gen.file/setGeneratedFilesBatch.d.ts +13 -0
  120. package/dist/domain.operations/genServiceSdk/gen.file/setGeneratedFilesBatch.js +49 -0
  121. package/dist/domain.operations/genServiceSdk/gen.file/setGeneratedFilesBatch.js.map +1 -0
  122. package/dist/domain.operations/genServiceSdk/gen.mechanism/asMechanismFnSource.d.ts +16 -0
  123. package/dist/domain.operations/genServiceSdk/gen.mechanism/asMechanismFnSource.js +39 -0
  124. package/dist/domain.operations/genServiceSdk/gen.mechanism/asMechanismFnSource.js.map +1 -0
  125. package/dist/domain.operations/genServiceSdk/gen.mechanism/getTypescriptFromJsonSchema.d.ts +35 -0
  126. package/dist/domain.operations/genServiceSdk/gen.mechanism/getTypescriptFromJsonSchema.js +189 -0
  127. package/dist/domain.operations/genServiceSdk/gen.mechanism/getTypescriptFromJsonSchema.js.map +1 -0
  128. package/dist/domain.operations/genServiceSdk/gen.resource/asDomainObjectPragma.d.ts +15 -0
  129. package/dist/domain.operations/genServiceSdk/gen.resource/asDomainObjectPragma.js +37 -0
  130. package/dist/domain.operations/genServiceSdk/gen.resource/asDomainObjectPragma.js.map +1 -0
  131. package/dist/domain.operations/genServiceSdk/gen.resource/asResourceClassSource.d.ts +26 -0
  132. package/dist/domain.operations/genServiceSdk/gen.resource/asResourceClassSource.js +106 -0
  133. package/dist/domain.operations/genServiceSdk/gen.resource/asResourceClassSource.js.map +1 -0
  134. package/dist/domain.operations/genServiceSdk/gen.resource/assertAllDomainObjectRefsBind.d.ts +15 -0
  135. package/dist/domain.operations/genServiceSdk/gen.resource/assertAllDomainObjectRefsBind.js +51 -0
  136. package/dist/domain.operations/genServiceSdk/gen.resource/assertAllDomainObjectRefsBind.js.map +1 -0
  137. package/dist/domain.operations/genServiceSdk/gen.resource/getAllDomainObjectsFromContracts.d.ts +14 -0
  138. package/dist/domain.operations/genServiceSdk/gen.resource/getAllDomainObjectsFromContracts.js +68 -0
  139. package/dist/domain.operations/genServiceSdk/gen.resource/getAllDomainObjectsFromContracts.js.map +1 -0
  140. package/dist/domain.operations/genServiceSdk/genServiceSdk.d.ts +20 -0
  141. package/dist/domain.operations/genServiceSdk/genServiceSdk.js +88 -0
  142. package/dist/domain.operations/genServiceSdk/genServiceSdk.js.map +1 -0
  143. package/dist/domain.operations/getAllLambdaContracts/getAllLambdaContracts.js +49 -4
  144. package/dist/domain.operations/getAllLambdaContracts/getAllLambdaContracts.js.map +1 -1
  145. package/dist/index.d.ts +38 -2
  146. package/dist/index.js +31 -1
  147. package/dist/index.js.map +1 -1
  148. package/package.json +18 -14
  149. package/readme.md +50 -2
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.asContextLogTrail = void 0;
4
+ /**
5
+ * .what = reads the trail log that `genTrailMiddleware` wrote onto the lambda context
6
+ * .why = BOTH family handlers need it, and each had restated the same cast with its own
7
+ * ~10-line doc block — one of which called itself "the twin of" the other. one
8
+ * declaration, so the two cannot drift (rule.forbid.parallel-codepaths)
9
+ *
10
+ * .as = aws types a handler's second argument as `Context`, which declares no `log`. this
11
+ * sdk's own `genTrailMiddleware` puts it there, so the cast asserts what the sdk's own
12
+ * middleware wrote — never an outside claim
13
+ *
14
+ * .as = `unknown` is the intermediate because `Context` and `ContextLogTrail` overlap on no
15
+ * member, so tsc refuses the direct assertion
16
+ *
17
+ * .why NOT `asContextTrailed` = that reader returns OPTIONAL fields, because a middleware's
18
+ * array position decides whether trail has run yet. a handler has no such doubt: trail is
19
+ * a `before` hook, so it has always run by the time the handler does. so this reader
20
+ * states `log` as PRESENT, and a caller owes no `?.` — the two readers differ in the one
21
+ * guarantee that matters, which is why they are a pair rather than one function
22
+ *
23
+ * .removal = removable when aws-lambda's `Handler` takes a caller-declared context type, or
24
+ * when the families hand their `logic` the middy request rather than the raw arguments —
25
+ * the latter is the cheaper path, and it is why `asContextTrailed` exists for the
26
+ * middleware sites
27
+ */
28
+ const asContextLogTrail = (input) => input.context;
29
+ exports.asContextLogTrail = asContextLogTrail;
30
+ //# sourceMappingURL=asContextLogTrail.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"asContextLogTrail.js","sourceRoot":"","sources":["../../../src/domain.operations/genLambdaEndpoint/asContextLogTrail.ts"],"names":[],"mappings":";;;AAGA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACI,MAAM,iBAAiB,GAAG,CAAC,KAEjC,EAAmB,EAAE,CAAC,KAAK,CAAC,OAAqC,CAAC;AAFtD,QAAA,iBAAiB,qBAEqC"}
@@ -0,0 +1,36 @@
1
+ import type { ApiGatewayRequestPayload } from '../../../domain.objects/ApiGatewayRequestPayload';
2
+ /**
3
+ * .what = an api-gateway request with v1/v2 differences reconciled
4
+ * .why = v1 puts the method at `httpMethod` and v2 at `requestContext.http.method`. a
5
+ * handler that reads either directly is version-locked, so the sdk reconciles them
6
+ * once and hands over one shape
7
+ *
8
+ * .note = `Unified` carries weight, never decoration: this is NOT the wire shape. the wire
9
+ * shape is `ApiGatewayRequestPayload`, the raw v1|v2 union. this is a step the
10
+ * default input translator takes on the way to `inputAfter`
11
+ */
12
+ export interface UnifiedApiGatewayEvent {
13
+ httpMethod: string;
14
+ path: string;
15
+ headers: Record<string, string | undefined>;
16
+ queryStringParameters: Record<string, string | undefined> | null;
17
+ pathParameters: Record<string, string | undefined> | null;
18
+ body: unknown;
19
+ rawBody: string | null;
20
+ isBase64Encoded: boolean;
21
+ requestContext: {
22
+ requestId: string;
23
+ stage: string;
24
+ domainName?: string;
25
+ accountId?: string;
26
+ };
27
+ /**
28
+ * .what = the ejection route — the wire payload, before this shape reconciled it
29
+ * .why = `_` marks it as an escape hatch rather than a paved path. every field above is
30
+ * version-agnostic; reach in here and you are version-locked again, so a reader who
31
+ * sees `_` knows they have left the supported surface
32
+ */
33
+ _: {
34
+ raw: ApiGatewayRequestPayload;
35
+ };
36
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=UnifiedApiGatewayEvent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"UnifiedApiGatewayEvent.js","sourceRoot":"","sources":["../../../../src/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/UnifiedApiGatewayEvent.ts"],"names":[],"mappings":""}
@@ -0,0 +1,19 @@
1
+ import type { ApiGatewayResponse } from '../../../domain.objects/ApiGatewayResponse';
2
+ import type { ApiGatewayResponsePayload } from '../../../domain.objects/ApiGatewayResponsePayload';
3
+ /**
4
+ * .what = the default output translator: what `invoke` returns becomes the wire payload
5
+ *
6
+ * .note = `status` defaults HERE, ahead of every middleware — middy's `normalizeHttpResponse`
7
+ * applies `statusCode ??= 500`, so a later default would put a server-fault on the wire
8
+ * for a handler that meant 200
9
+ *
10
+ * .note = `body` is OMITTED, never `''` — the serializer would encode `''` into `'""'`. it is
11
+ * left as the DOMAIN value for the serializer to encode one step later, which is what
12
+ * lets a handler's own `Content-Type` carry bytes through untouched
13
+ *
14
+ * ⚠️ the omission holds at the WIRE, not mid-chain: the serializer re-adds `body` as an
15
+ * own key with value `undefined`. benign, and visible in the unit snapshots
16
+ */
17
+ export declare const asApiGatewayResponsePayload: <TBody>(input: {
18
+ response: ApiGatewayResponse<TBody>;
19
+ }) => ApiGatewayResponsePayload<TBody>;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.asApiGatewayResponsePayload = void 0;
4
+ /**
5
+ * .what = the default output translator: what `invoke` returns becomes the wire payload
6
+ *
7
+ * .note = `status` defaults HERE, ahead of every middleware — middy's `normalizeHttpResponse`
8
+ * applies `statusCode ??= 500`, so a later default would put a server-fault on the wire
9
+ * for a handler that meant 200
10
+ *
11
+ * .note = `body` is OMITTED, never `''` — the serializer would encode `''` into `'""'`. it is
12
+ * left as the DOMAIN value for the serializer to encode one step later, which is what
13
+ * lets a handler's own `Content-Type` carry bytes through untouched
14
+ *
15
+ * ⚠️ the omission holds at the WIRE, not mid-chain: the serializer re-adds `body` as an
16
+ * own key with value `undefined`. benign, and visible in the unit snapshots
17
+ */
18
+ const asApiGatewayResponsePayload = (input) => ({
19
+ statusCode: input.response.status ?? 200,
20
+ ...(input.response.headers ? { headers: input.response.headers } : {}),
21
+ ...('body' in input.response ? { body: input.response.body } : {}),
22
+ });
23
+ exports.asApiGatewayResponsePayload = asApiGatewayResponsePayload;
24
+ //# sourceMappingURL=asApiGatewayResponsePayload.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"asApiGatewayResponsePayload.js","sourceRoot":"","sources":["../../../../src/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/asApiGatewayResponsePayload.ts"],"names":[],"mappings":";;;AAGA;;;;;;;;;;;;;GAaG;AACI,MAAM,2BAA2B,GAAG,CAAQ,KAElD,EAAoC,EAAE,CAAC,CAAC;IACvC,UAAU,EAAE,KAAK,CAAC,QAAQ,CAAC,MAAM,IAAI,GAAG;IACxC,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,KAAK,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;IACtE,GAAG,CAAC,MAAM,IAAI,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;CACnE,CAAC,CAAC;AANU,QAAA,2BAA2B,+BAMrC"}
@@ -0,0 +1,26 @@
1
+ import type { ApiGatewayResponsePayload } from '../../../domain.objects/ApiGatewayResponsePayload';
2
+ /**
3
+ * .what = the wire payload for a body this family must encode ITSELF, as json
4
+ * .why = three middleware entries short-circuit the chain — the 400 builder, the 500 builder,
5
+ * and the introspection reply — and a short-circuit BYPASSES the response serializer,
6
+ * so each owes the wire an already-encoded body plus its own `Content-Type`. all three
7
+ * route through here; a fourth short-circuit owes the same
8
+ *
9
+ * .note = this is the SIBLING of `asApiGatewayResponsePayload`, never a replacement. the two
10
+ * differ on exactly one axis — WHO encodes the body:
11
+ * - `asApiGatewayResponsePayload` leaves the body a DOMAIN value, for the serializer
12
+ * to encode one step later. that is the handler's path
13
+ * - THIS one encodes here, because no serializer step follows a short-circuit
14
+ *
15
+ * .note = the `Content-Type` is stamped unconditionally, which is also what makes the encode
16
+ * safe to do here: `genContentTypeCoherenceMiddleware` demands a body and a
17
+ * content-type agree, and `httpResponseSerializer` skips a response that already
18
+ * declares one — so a second encode cannot double-wrap this body
19
+ *
20
+ * ⚠️ .note = the test doubles that restate this shape stay independent ON PURPOSE. a test that
21
+ * imported this transformer could no longer prove this transformer's shape
22
+ */
23
+ export declare const asApiGatewayResponsePayloadJson: (input: {
24
+ status: number;
25
+ body: unknown;
26
+ }) => ApiGatewayResponsePayload;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.asApiGatewayResponsePayloadJson = void 0;
4
+ /**
5
+ * .what = the wire payload for a body this family must encode ITSELF, as json
6
+ * .why = three middleware entries short-circuit the chain — the 400 builder, the 500 builder,
7
+ * and the introspection reply — and a short-circuit BYPASSES the response serializer,
8
+ * so each owes the wire an already-encoded body plus its own `Content-Type`. all three
9
+ * route through here; a fourth short-circuit owes the same
10
+ *
11
+ * .note = this is the SIBLING of `asApiGatewayResponsePayload`, never a replacement. the two
12
+ * differ on exactly one axis — WHO encodes the body:
13
+ * - `asApiGatewayResponsePayload` leaves the body a DOMAIN value, for the serializer
14
+ * to encode one step later. that is the handler's path
15
+ * - THIS one encodes here, because no serializer step follows a short-circuit
16
+ *
17
+ * .note = the `Content-Type` is stamped unconditionally, which is also what makes the encode
18
+ * safe to do here: `genContentTypeCoherenceMiddleware` demands a body and a
19
+ * content-type agree, and `httpResponseSerializer` skips a response that already
20
+ * declares one — so a second encode cannot double-wrap this body
21
+ *
22
+ * ⚠️ .note = the test doubles that restate this shape stay independent ON PURPOSE. a test that
23
+ * imported this transformer could no longer prove this transformer's shape
24
+ */
25
+ const asApiGatewayResponsePayloadJson = (input) => ({
26
+ statusCode: input.status,
27
+ body: JSON.stringify(input.body),
28
+ headers: { 'Content-Type': 'application/json' },
29
+ });
30
+ exports.asApiGatewayResponsePayloadJson = asApiGatewayResponsePayloadJson;
31
+ //# sourceMappingURL=asApiGatewayResponsePayloadJson.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"asApiGatewayResponsePayloadJson.js","sourceRoot":"","sources":["../../../../src/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/asApiGatewayResponsePayloadJson.ts"],"names":[],"mappings":";;;AAEA;;;;;;;;;;;;;;;;;;;;GAoBG;AACI,MAAM,+BAA+B,GAAG,CAAC,KAG/C,EAA6B,EAAE,CAAC,CAAC;IAChC,UAAU,EAAE,KAAK,CAAC,MAAM;IACxB,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC;IAChC,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE;CAChD,CAAC,CAAC;AAPU,QAAA,+BAA+B,mCAOzC"}
@@ -0,0 +1,33 @@
1
+ import { type ZodSchema } from 'zod';
2
+ import type { ApiGatewayResponse } from '../../../domain.objects/ApiGatewayResponse';
3
+ /**
4
+ * .what = lifts a body schema into the response-envelope schema
5
+ * .why = `schema.output` describes the whole response (`outputBefore`), never the body
6
+ * inside it — so a reader can line the schema up against the pipeline. this keeps
7
+ * the common case a one-liner instead of a hand-written envelope per call site
8
+ *
9
+ * .note = `body` is NAMED rather than positional because the envelope holds three fields, so
10
+ * the argument must say which one it supplies
11
+ *
12
+ * .note = every field is optional in the schema, since `PickAny` lets a handler supply
13
+ * any non-empty subset. the at-least-one rule is held by the TYPE at compile
14
+ * time; this schema guards the field types
15
+ *
16
+ * .as = zod cannot express "at least one key present", so it infers `{ status?, headers?,
17
+ * body? }` — a superset of `PickAny` by exactly one member, `{}` — and no structural
18
+ * assignment relates the two
19
+ * ⚠️ .note for a DIRECT consumer = this schema is publicly exported, and on its own it ACCEPTS
20
+ * `{}`. inside `forApiGateway` that is unreachable — `isApiGatewayResponse.assure`
21
+ * refuses an empty response before this schema is ever reached — but a consumer who
22
+ * validates against this schema DIRECTLY inherits no such guard. so pair it with the
23
+ * `ApiGatewayResponse` type (which refuses `{}` at compile time) rather than treat a
24
+ * parse as the whole check
25
+ *
26
+ * .removal = drops when zod can express an at-least-one-key refinement that still narrows the
27
+ * inferred type (a `.refine` narrows values, never the type). until then the
28
+ * compile-time guarantee lives in `ApiGatewayResponse` and the runtime guarantee
29
+ * lives here, and this cast is the seam between them
30
+ */
31
+ export declare const asApiGatewayResponseSchema: <TBody>(input: {
32
+ body: ZodSchema<TBody>;
33
+ }) => ZodSchema<ApiGatewayResponse<TBody>>;
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.asApiGatewayResponseSchema = void 0;
4
+ const zod_1 = require("zod");
5
+ /**
6
+ * .what = lifts a body schema into the response-envelope schema
7
+ * .why = `schema.output` describes the whole response (`outputBefore`), never the body
8
+ * inside it — so a reader can line the schema up against the pipeline. this keeps
9
+ * the common case a one-liner instead of a hand-written envelope per call site
10
+ *
11
+ * .note = `body` is NAMED rather than positional because the envelope holds three fields, so
12
+ * the argument must say which one it supplies
13
+ *
14
+ * .note = every field is optional in the schema, since `PickAny` lets a handler supply
15
+ * any non-empty subset. the at-least-one rule is held by the TYPE at compile
16
+ * time; this schema guards the field types
17
+ *
18
+ * .as = zod cannot express "at least one key present", so it infers `{ status?, headers?,
19
+ * body? }` — a superset of `PickAny` by exactly one member, `{}` — and no structural
20
+ * assignment relates the two
21
+ * ⚠️ .note for a DIRECT consumer = this schema is publicly exported, and on its own it ACCEPTS
22
+ * `{}`. inside `forApiGateway` that is unreachable — `isApiGatewayResponse.assure`
23
+ * refuses an empty response before this schema is ever reached — but a consumer who
24
+ * validates against this schema DIRECTLY inherits no such guard. so pair it with the
25
+ * `ApiGatewayResponse` type (which refuses `{}` at compile time) rather than treat a
26
+ * parse as the whole check
27
+ *
28
+ * .removal = drops when zod can express an at-least-one-key refinement that still narrows the
29
+ * inferred type (a `.refine` narrows values, never the type). until then the
30
+ * compile-time guarantee lives in `ApiGatewayResponse` and the runtime guarantee
31
+ * lives here, and this cast is the seam between them
32
+ */
33
+ const asApiGatewayResponseSchema = (input) => zod_1.z.object({
34
+ status: zod_1.z.number().optional(),
35
+ headers: zod_1.z.record(zod_1.z.string(), zod_1.z.string()).optional(),
36
+ body: input.body.optional(),
37
+ });
38
+ exports.asApiGatewayResponseSchema = asApiGatewayResponseSchema;
39
+ //# sourceMappingURL=asApiGatewayResponseSchema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"asApiGatewayResponseSchema.js","sourceRoot":"","sources":["../../../../src/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/asApiGatewayResponseSchema.ts"],"names":[],"mappings":";;;AAAA,6BAAwC;AAIxC;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACI,MAAM,0BAA0B,GAAG,CAAQ,KAEjD,EAAwC,EAAE,CACzC,OAAC,CAAC,MAAM,CAAC;IACP,MAAM,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC7B,OAAO,EAAE,OAAC,CAAC,MAAM,CAAC,OAAC,CAAC,MAAM,EAAE,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,CAAC,QAAQ,EAAE;IACpD,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,QAAQ,EAAE;CAC5B,CAAoD,CAAC;AAP3C,QAAA,0BAA0B,8BAOiB"}
@@ -0,0 +1,27 @@
1
+ import type { ApiGatewayRequestPayload } from '../../../domain.objects/ApiGatewayRequestPayload';
2
+ import type { UnifiedApiGatewayEvent } from './UnifiedApiGatewayEvent';
3
+ /**
4
+ * .what = what `deserialize` means when a caller declares none — ONE declaration, read by both
5
+ * this transformer and `forApiGateway`'s config (rule.forbid.parallel-codepaths)
6
+ * .why body = json is the common case, and a caller who wants the raw string opts out by value:
7
+ * `deserialize: { body: false }`
8
+ */
9
+ export declare const DESERIALIZE_DEFAULT: {
10
+ body: boolean;
11
+ };
12
+ /**
13
+ * .what = reconciles either api-gateway payload version into one shape
14
+ * .why = the chain must read one shape whichever version the trigger delivered, so this runs
15
+ * first and every step after it reads `UnifiedApiGatewayEvent`
16
+ *
17
+ * .note = a named transformer rather than middleware-local logic, so ONE implementation serves
18
+ * both entry points — `genApiGatewayEventNormalizationMiddleware` delegates here
19
+ * (rule.forbid.parallel-codepaths)
20
+ */
21
+ export declare const asUnifiedApiGatewayEvent: (input: {
22
+ payload: ApiGatewayRequestPayload;
23
+ }, options?: {
24
+ deserialize: {
25
+ body: boolean;
26
+ };
27
+ }) => UnifiedApiGatewayEvent;
@@ -0,0 +1,118 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.asUnifiedApiGatewayEvent = exports.DESERIALIZE_DEFAULT = void 0;
4
+ const helpful_errors_1 = require("helpful-errors");
5
+ const getIsV1ApiGatewayEvent_1 = require("./getIsV1ApiGatewayEvent");
6
+ const getIsV2ApiGatewayEvent_1 = require("./getIsV2ApiGatewayEvent");
7
+ /**
8
+ * .what = parses a json body string into an object, base64-decoded first when flagged
9
+ * .why = api gateway hands the body over as a string; most handlers want the object
10
+ *
11
+ * .note = a body that is not json is returned as the decoded string rather than refused —
12
+ * a form-encoded twilio webhook is a legitimate caller, and its own schema (or
13
+ * `z.any()`) is where that shape gets judged
14
+ */
15
+ const asParsedApiGatewayBody = (input) => {
16
+ if (!input.body)
17
+ return null;
18
+ const decoded = input.isBase64Encoded
19
+ ? Buffer.from(input.body, 'base64').toString('utf-8')
20
+ : input.body;
21
+ try {
22
+ return JSON.parse(decoded);
23
+ }
24
+ catch (error) {
25
+ /**
26
+ * .what = allowlists the ONE error a non-json body can raise, and rethrows every other
27
+ * .why = a bare `catch` would swallow a TypeError from a real defect, and the swallowed
28
+ * value would reach the handler as plain text (rule.forbid.failhide). `SyntaxError`
29
+ * is the only class `JSON.parse` throws for malformed input, per ecma-262 §25.5.1,
30
+ * so the allowlist is exhaustive rather than a guess
31
+ */
32
+ if (!(error instanceof SyntaxError))
33
+ throw error;
34
+ return decoded;
35
+ }
36
+ };
37
+ /**
38
+ * .what = reconciles either payload version into the unified shape, given the TWO values the
39
+ * versions disagree about
40
+ * .why = v1 and v2 differ in exactly two places — the method and path, top-level on v1 and
41
+ * under `requestContext.http` on v2. every OTHER field sits at the same path on both, so
42
+ * one function serves both and the unified shape gains a new field in ONE place
43
+ *
44
+ * .note = the two disputed values are handed in as plain strings rather than read through a
45
+ * per-version extractor, which would restore the duplication in a less legible form
46
+ */
47
+ const asUnifiedEvent = (input) => ({
48
+ httpMethod: input.httpMethod,
49
+ path: input.path,
50
+ /**
51
+ * .as = v1 declares `headers` REQUIRED and v2 declares it optional, so the union's member is
52
+ * `… | undefined`, which the unified shape does not carry
53
+ * .removal = drops once `UnifiedApiGatewayEvent.headers` is itself optional. left because
54
+ * every consumer reads `event.headers[x]`, and `@middy/http-cors` reads this slot too
55
+ * (rule.require.read-the-slot-a-dependency-reads) — so the change is not local
56
+ */
57
+ headers: input.payload.headers,
58
+ queryStringParameters: input.payload.queryStringParameters ?? null,
59
+ pathParameters: input.payload.pathParameters ?? null,
60
+ body: input.deserialize.body
61
+ ? asParsedApiGatewayBody({
62
+ body: input.payload.body,
63
+ isBase64Encoded: input.payload.isBase64Encoded,
64
+ })
65
+ : input.payload.body,
66
+ rawBody: input.payload.body ?? null,
67
+ isBase64Encoded: input.payload.isBase64Encoded,
68
+ requestContext: {
69
+ requestId: input.payload.requestContext.requestId,
70
+ stage: input.payload.requestContext.stage,
71
+ domainName: input.payload.requestContext.domainName,
72
+ accountId: input.payload.requestContext.accountId,
73
+ },
74
+ _: { raw: input.payload },
75
+ });
76
+ /**
77
+ * .what = what `deserialize` means when a caller declares none — ONE declaration, read by both
78
+ * this transformer and `forApiGateway`'s config (rule.forbid.parallel-codepaths)
79
+ * .why body = json is the common case, and a caller who wants the raw string opts out by value:
80
+ * `deserialize: { body: false }`
81
+ */
82
+ exports.DESERIALIZE_DEFAULT = { body: true };
83
+ /**
84
+ * .what = reconciles either api-gateway payload version into one shape
85
+ * .why = the chain must read one shape whichever version the trigger delivered, so this runs
86
+ * first and every step after it reads `UnifiedApiGatewayEvent`
87
+ *
88
+ * .note = a named transformer rather than middleware-local logic, so ONE implementation serves
89
+ * both entry points — `genApiGatewayEventNormalizationMiddleware` delegates here
90
+ * (rule.forbid.parallel-codepaths)
91
+ */
92
+ const asUnifiedApiGatewayEvent = (input, options) => {
93
+ const deserialize = options?.deserialize ?? exports.DESERIALIZE_DEFAULT;
94
+ // v2 http-api: the method and path live under `requestContext.http`
95
+ if ((0, getIsV2ApiGatewayEvent_1.getIsV2ApiGatewayEvent)(input.payload)) {
96
+ const payload = input.payload;
97
+ return asUnifiedEvent({
98
+ payload,
99
+ httpMethod: payload.requestContext.http.method,
100
+ path: payload.requestContext.http.path,
101
+ deserialize,
102
+ });
103
+ }
104
+ // v1 rest-api: the method and path live at the top level
105
+ if ((0, getIsV1ApiGatewayEvent_1.getIsV1ApiGatewayEvent)(input.payload)) {
106
+ const payload = input.payload;
107
+ return asUnifiedEvent({
108
+ payload,
109
+ httpMethod: payload.httpMethod,
110
+ path: payload.path,
111
+ deserialize,
112
+ });
113
+ }
114
+ // fail loud rather than hand a handler a shape neither branch produced
115
+ return helpful_errors_1.MalfunctionError.throw('payload is neither v1 nor v2 api gateway event shaped', { payload: input.payload });
116
+ };
117
+ exports.asUnifiedApiGatewayEvent = asUnifiedApiGatewayEvent;
118
+ //# sourceMappingURL=asUnifiedApiGatewayEvent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"asUnifiedApiGatewayEvent.js","sourceRoot":"","sources":["../../../../src/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/asUnifiedApiGatewayEvent.ts"],"names":[],"mappings":"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"}
@@ -1,10 +1,33 @@
1
1
  import middy from '@middy/core';
2
- import type { APIGatewayProxyEvent, APIGatewayProxyResult, Context } from 'aws-lambda';
2
+ import type { Context } from 'aws-lambda';
3
3
  import type { ContextLogTrail } from 'sdk-logs';
4
4
  import type { ZodSchema } from 'zod';
5
+ import type { ApiGatewayRequestPayload } from '../../../domain.objects/ApiGatewayRequestPayload';
6
+ import type { ApiGatewayResponse } from '../../../domain.objects/ApiGatewayResponse';
7
+ import type { ApiGatewayResponsePayload } from '../../../domain.objects/ApiGatewayResponsePayload';
5
8
  import type { ContextAwsLambdaServer } from '../../../domain.objects/ContextAwsLambdaServer';
6
- import type { IoLogTranslate } from '../middleware/genIoLoggerMiddleware';
7
- import { type UnifiedApiGatewayEvent } from './middleware/genApiGatewayEventNormalizationMiddleware';
9
+ import type { TranslateLog } from '../TranslateLog';
10
+ import type { UnifiedApiGatewayEvent } from './UnifiedApiGatewayEvent';
11
+ /**
12
+ * .what = the cors contract for an api-gateway handler
13
+ *
14
+ * ⚠️ .limits = TWO, both LIVE and both INHERITED — `main` and `simple-lambda-handlers` carry
15
+ * the identical pair. `[case11]` and `[case8]` of `local.wireResponse.acceptance.test.ts`
16
+ * assert the limited bytes and are GREEN, so each goes RED when repaired. writeup:
17
+ * `.behavior/…/seeds/issue.cors-and-headers-on-every-non-success-path.md`
18
+ *
19
+ * 1. **a preflight is answered by YOUR HANDLER.** `@middy/http-cors` defaults
20
+ * `disableBeforePreflightResponse: true` (`index.js:16`), so an `OPTIONS` falls through
21
+ * the chain — and succeeds only where `schema.input` accepts a body-less request
22
+ *
23
+ * 2. **no error response carries cors or owasp headers.** both vendors' `onError` hooks open
24
+ * `if (request.response === undefined) return` and sit ABOVE the error builders that set
25
+ * it, so both no-op. every 400 and 500 ships bare
26
+ *
27
+ * ⚠️ .unverified = whether either is reachable in a DEPLOYED api gateway, which commonly answers
28
+ * `OPTIONS` at the gateway with a MOCK integration. both were measured against the LOCAL
29
+ * harness, where every request reaches the handler
30
+ */
8
31
  export interface CorsConfig {
9
32
  /**
10
33
  * .what = origins to accept for cors
@@ -35,16 +58,58 @@ export interface CorsConfig {
35
58
  * .what = input type for forApiGateway
36
59
  * .why = sdk contract type, exported for consumer type inference
37
60
  */
38
- export type ForApiGatewayInput<TInput, TOutput> = {
61
+ export type ForApiGatewayInput<TInput, TBody> = {
39
62
  schema: {
63
+ /**
64
+ * .what = describes `inputAfter` — what `invoke` receives
65
+ * .why = guards the point of consequence on the way in: a caller who sent the wrong
66
+ * shape is refused before the handler runs
67
+ */
40
68
  input: ZodSchema<TInput>;
41
- output: ZodSchema<TOutput>;
69
+ /**
70
+ * .what = describes `outputBefore` — the whole response `invoke` returns
71
+ * .why = guards the point of consequence on the way out: a handler that built the
72
+ * wrong response is refused before the encode turns it into bytes
73
+ *
74
+ * .note = this describes the ENVELOPE, never the body inside it. use
75
+ * `asApiGatewayResponseSchema({ body })` to lift a body schema into one, and
76
+ * `z.any()` to opt out of validation entirely
77
+ */
78
+ output: ZodSchema<ApiGatewayResponse<TBody>>;
42
79
  };
43
80
  invoke: (input: {
81
+ /**
82
+ * .what = `inputAfter` — the validated body
83
+ */
44
84
  event: TInput;
85
+ /**
86
+ * .what = the v1/v2-reconciled request; the wire payload itself is at `._.raw`
87
+ *
88
+ * ⚠️ .misnomer — this is NOT raw, it is normalized. the rename (`rawEvent` -> `payload`)
89
+ * is designed and unapplied, gated behind 🚧 F31
90
+ */
45
91
  rawEvent: UnifiedApiGatewayEvent;
46
- }, context: ContextLogTrail) => Promise<TOutput>;
47
- logTranslate?: IoLogTranslate;
92
+ }, context: ContextLogTrail) => Promise<ApiGatewayResponse<TBody>>;
93
+ /**
94
+ * .what = projections applied to the io before it reaches cloudwatch
95
+ *
96
+ * ⚠️ .defect = LIVE, NOT FIXED — `logTranslate.input` NEVER RUNS for this family; only
97
+ * `.output` fires. so a projection written here to redact request bodies is dead
98
+ * code, and the log it would have shaped is never emitted at all. ⚠️ **redact
99
+ * inside `invoke` instead**
100
+ *
101
+ * .the cause = `genIoLoggerMiddleware`'s `before` reads `context.log`, which
102
+ * `genTrailMiddleware`'s `before` writes — and trail sits at a HIGHER index, so it
103
+ * has not run yet. `before` hooks run in FORWARD array order
104
+ *
105
+ * .proof it is live = `[case16][t1]` asserts the log branch does NOT run, and is GREEN. `[t0]`
106
+ * is its positive control — same middleware, same option, trail at a lower index
107
+ *
108
+ * .repair, UNAPPLIED = move `genTrailMiddleware()` from index 8 to index 3. blast radius,
109
+ * probed: ONE assertion. left because `main` carries the identical order and the
110
+ * move also puts trail ahead of event normalization
111
+ */
112
+ logTranslate?: TranslateLog;
48
113
  cors?: CorsConfig;
49
114
  deserialize?: {
50
115
  /**
@@ -56,35 +121,10 @@ export type ForApiGatewayInput<TInput, TOutput> = {
56
121
  body: boolean;
57
122
  };
58
123
  };
59
- /**
60
- * .what = sdk contract type for forApiGateway context
61
- * .why = exported for consumer type inference; the shared handler-side context
62
- * ({ env?: EnvConfig; log? }) reused by genLambdaEndpoint + forApiGateway
63
- */
124
+ /** .what = sdk contract type for forApiGateway context, exported for consumer inference */
64
125
  export type ForApiGatewayContext = ContextAwsLambdaServer;
65
126
  /**
66
- * .what = generates API Gateway lambda handler with http features
67
- * .why = adds cors, security headers, error handler, body serialization, and validation
68
- *
69
- * follows simple-lambda-handlers createApiGatewayHandler pattern:
70
- * - uses middy middleware chain
71
- * - uses @middy/http-cors for dynamic origin match
72
- * - uses @middy/http-security-headers for OWASP security headers
73
- * - uses @middy/http-json-body-parser for json body parse
74
- * - uses @middy/http-response-serializer for response serialization
127
+ * .what = generates an api-gateway lambda handler with http features
128
+ * .why = adds cors, security headers, error conversion, body serialization, and validation
75
129
  */
76
- export declare const forApiGateway: <TInput, TOutput>(config: {
77
- schema: {
78
- input: ZodSchema<TInput>;
79
- output: ZodSchema<TOutput>;
80
- };
81
- invoke: (input: {
82
- event: TInput;
83
- rawEvent: UnifiedApiGatewayEvent;
84
- }, context: ContextLogTrail) => Promise<TOutput>;
85
- logTranslate?: IoLogTranslate;
86
- cors?: CorsConfig;
87
- deserialize?: {
88
- body: boolean;
89
- };
90
- }, context?: ContextAwsLambdaServer) => middy.MiddyfiedHandler<APIGatewayProxyEvent, APIGatewayProxyResult, Error, Context>;
130
+ export declare const forApiGateway: <TInput, TBody>(config: ForApiGatewayInput<TInput, TBody>, context?: ContextAwsLambdaServer) => middy.MiddyfiedHandler<ApiGatewayRequestPayload, ApiGatewayResponsePayload, Error, Context>;