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,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.genContentTypeCoherenceMiddleware = void 0;
4
+ /**
5
+ * .what = removes `Content-Type` from a response that carries no body
6
+ * .why = a content-type that contradicts the body is the exact shape that raises twilio 11200 —
7
+ * the defect this whole affordance exists to retire. a 204 and a 308 each reach the wire
8
+ * body-less and would otherwise claim `application/json`
9
+ *
10
+ * ⚠️ .note = MUST be registered FIRST in the chain array. middy `unshift`s `after` and `onError`,
11
+ * so index 0 runs LAST on both — the only position later than the serializer that stamps
12
+ * the header, and later than the error builders that set `request.response`. anywhere
13
+ * else, the `onError` hook meets an absent response and returns early
14
+ *
15
+ * .note = the same function serves both hooks, so one implementation holds the guarantee on
16
+ * either path. no error response is body-less today, so `onError` finds no work yet; it
17
+ * is registered for a future body-less error status (a 304, a 205)
18
+ */
19
+ const genContentTypeCoherenceMiddleware = () => {
20
+ const onResponse = async (request) => {
21
+ // an error path can reach here before any response was set
22
+ if (!request.response)
23
+ return;
24
+ // a body present means the Content-Type describes real bytes, so leave it be
25
+ if (request.response.body !== undefined)
26
+ return;
27
+ /**
28
+ * .as = middy types `request.response` as `unknown`, so `.headers` arrives untyped. the cast
29
+ * declares the shape this chain always puts there — `httpSecurityHeaders`, `httpCors`,
30
+ * and the error builders each write a flat string map
31
+ * .removal = drops when middy gains typed response inference, at which point
32
+ * `ApiGatewayResponsePayload['headers']` types this member directly
33
+ */
34
+ const headers = request.response.headers;
35
+ if (!headers)
36
+ return;
37
+ /**
38
+ * .note = DELIBERATE MUTATION. `request` is middy's ONLY channel to hand a value onward,
39
+ * so a middleware that must alter the response has no immutable form available
40
+ * (rule.require.immutable-vars, the annotated-exception clause). the write is
41
+ * bounded to `headers` and replaces it with a fresh object rather than a splice
42
+ */
43
+ request.response.headers = Object.fromEntries(Object.entries(headers).filter(([key]) => key.toLowerCase() !== 'content-type'));
44
+ };
45
+ return { after: onResponse, onError: onResponse };
46
+ };
47
+ exports.genContentTypeCoherenceMiddleware = genContentTypeCoherenceMiddleware;
48
+ //# sourceMappingURL=genContentTypeCoherenceMiddleware.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"genContentTypeCoherenceMiddleware.js","sourceRoot":"","sources":["../../../../../src/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/middleware/genContentTypeCoherenceMiddleware.ts"],"names":[],"mappings":";;;AAEA;;;;;;;;;;;;;;GAcG;AACI,MAAM,iCAAiC,GAAG,GAG/C,EAAE;IACF,MAAM,UAAU,GAAiC,KAAK,EAAE,OAAO,EAAE,EAAE;QACjE,2DAA2D;QAC3D,IAAI,CAAC,OAAO,CAAC,QAAQ;YAAE,OAAO;QAE9B,6EAA6E;QAC7E,IAAI,OAAO,CAAC,QAAQ,CAAC,IAAI,KAAK,SAAS;YAAE,OAAO;QAEhD;;;;;;WAMG;QACH,MAAM,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,OAEpB,CAAC;QACd,IAAI,CAAC,OAAO;YAAE,OAAO;QAErB;;;;;WAKG;QACH,OAAO,CAAC,QAAQ,CAAC,OAAO,GAAG,MAAM,CAAC,WAAW,CAC3C,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,MAAM,CAC5B,CAAC,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,WAAW,EAAE,KAAK,cAAc,CAChD,CACF,CAAC;IACJ,CAAC,CAAC;IAEF,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,UAAU,EAAE,CAAC;AACpD,CAAC,CAAC;AArCW,QAAA,iCAAiC,qCAqC5C"}
@@ -3,6 +3,22 @@ import type { ZodSchema } from 'zod';
3
3
  /**
4
4
  * .what = validates event.body against zod schema for API Gateway
5
5
  * .why = API Gateway events have body as separate property, validate just the body
6
+ *
7
+ * .note = this family validates `event.body` rather than the whole event because
8
+ * `request.event` must stay http-shaped through the chain: `@middy/http-cors` reads
9
+ * `request.event.headers` and derives the http method from `request.event` in its
10
+ * `after` hook (`@middy/http-cors/index.js:38,83,106`). so the body cannot take the
11
+ * event's place, and this cannot yet collapse into `genZodEventValidationMiddleware`
12
+ *
13
+ * .note = the constraint is SHARPER than "http-shaped", and the precise form is what any
14
+ * future input translate must honor. cors picks its method extractor by
15
+ * `request.event.version ?? '1.0'` (`index.js:38,106`), and `UnifiedApiGatewayEvent`
16
+ * declares no `version` — so cors always falls to its **v1** extractor,
17
+ * `(event) => event.httpMethod`. that works only because the unified shape happens to
18
+ * expose `httpMethod` and `headers` at its top level under v1's own names. so the real
19
+ * requirement is: whatever occupies `request.event` when cors's `after` runs must keep
20
+ * `httpMethod` and `headers` readable at the top level, with v1 names. an arbitrary
21
+ * `TInput` cannot promise that, which is why the input translate has no home here yet
6
22
  */
7
23
  export declare const genZodBodyValidationMiddleware: <TInput>(input: {
8
24
  schema: ZodSchema<TInput>;
@@ -5,6 +5,22 @@ const getValidationError_1 = require("../../middleware/getValidationError");
5
5
  /**
6
6
  * .what = validates event.body against zod schema for API Gateway
7
7
  * .why = API Gateway events have body as separate property, validate just the body
8
+ *
9
+ * .note = this family validates `event.body` rather than the whole event because
10
+ * `request.event` must stay http-shaped through the chain: `@middy/http-cors` reads
11
+ * `request.event.headers` and derives the http method from `request.event` in its
12
+ * `after` hook (`@middy/http-cors/index.js:38,83,106`). so the body cannot take the
13
+ * event's place, and this cannot yet collapse into `genZodEventValidationMiddleware`
14
+ *
15
+ * .note = the constraint is SHARPER than "http-shaped", and the precise form is what any
16
+ * future input translate must honor. cors picks its method extractor by
17
+ * `request.event.version ?? '1.0'` (`index.js:38,106`), and `UnifiedApiGatewayEvent`
18
+ * declares no `version` — so cors always falls to its **v1** extractor,
19
+ * `(event) => event.httpMethod`. that works only because the unified shape happens to
20
+ * expose `httpMethod` and `headers` at its top level under v1's own names. so the real
21
+ * requirement is: whatever occupies `request.event` when cors's `after` runs must keep
22
+ * `httpMethod` and `headers` readable at the top level, with v1 names. an arbitrary
23
+ * `TInput` cannot promise that, which is why the input translate has no home here yet
8
24
  */
9
25
  const genZodBodyValidationMiddleware = (input) => {
10
26
  const before = async (request) => {
@@ -14,6 +30,22 @@ const genZodBodyValidationMiddleware = (input) => {
14
30
  throw (0, getValidationError_1.getValidationError)({ error: result.error });
15
31
  }
16
32
  // replace body with parsed (transformed) result
33
+ /**
34
+ * .note = DELIBERATE MUTATION — `request` is middy's only channel to hand a value onward,
35
+ * and `event` is an ALIAS of `request.event`, so this writes through to the chain
36
+ *
37
+ * ⚠️ .note = this site escaped the first sweep of this class, because that grep anchored on
38
+ * `request.` and an alias hides the receiver. a mutation through a local alias is
39
+ * the same mutation — so the pattern must match the ALIAS too
40
+ * (`^\s*(event|response|payload)\.\w+\s*=`), which finds exactly this one
41
+ *
42
+ * .as = `UnifiedApiGatewayEvent.body` is the PRE-validation shape (a string, or a parsed
43
+ * json value), while `result.data` is `TInput` — the POST-validation domain shape.
44
+ * the two are unrelated by declaration, which is exactly right: this assignment IS
45
+ * the step that changes which of them lives in the slot
46
+ * .removal = drops once the input-side translator lands and the chain carries `inputAfter`
47
+ * in its own slot rather than back in the event's `body` — the 🚧 F31 fulcrum
48
+ */
17
49
  event.body = result.data;
18
50
  };
19
51
  return { before };
@@ -1 +1 @@
1
- {"version":3,"file":"genZodBodyValidationMiddleware.js","sourceRoot":"","sources":["../../../../../src/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/middleware/genZodBodyValidationMiddleware.ts"],"names":[],"mappings":";;;AAGA,4EAAyE;AAGzE;;;GAGG;AACI,MAAM,8BAA8B,GAAG,CAAS,KAEtD,EAEC,EAAE;IACF,MAAM,MAAM,GAAiC,KAAK,EAAE,OAAO,EAAE,EAAE;QAC7D,MAAM,KAAK,GAAG,OAAO,CAAC,KAA+B,CAAC;QACtD,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAClD,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;YACpB,MAAM,IAAA,uCAAkB,EAAC,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC;QACpD,CAAC;QACD,gDAAgD;QAChD,KAAK,CAAC,IAAI,GAAG,MAAM,CAAC,IAAoC,CAAC;IAC3D,CAAC,CAAC;IAEF,OAAO,EAAE,MAAM,EAAE,CAAC;AACpB,CAAC,CAAC;AAhBW,QAAA,8BAA8B,kCAgBzC"}
1
+ {"version":3,"file":"genZodBodyValidationMiddleware.js","sourceRoot":"","sources":["../../../../../src/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/middleware/genZodBodyValidationMiddleware.ts"],"names":[],"mappings":";;;AAGA,4EAAyE;AAGzE;;;;;;;;;;;;;;;;;;;GAmBG;AACI,MAAM,8BAA8B,GAAG,CAAS,KAEtD,EAEC,EAAE;IACF,MAAM,MAAM,GAAiC,KAAK,EAAE,OAAO,EAAE,EAAE;QAC7D,MAAM,KAAK,GAAG,OAAO,CAAC,KAA+B,CAAC;QACtD,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAClD,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;YACpB,MAAM,IAAA,uCAAkB,EAAC,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC;QACpD,CAAC;QACD,gDAAgD;QAChD;;;;;;;;;;;;;;;WAeG;QACH,KAAK,CAAC,IAAI,GAAG,MAAM,CAAC,IAAoC,CAAC;IAC3D,CAAC,CAAC;IAEF,OAAO,EAAE,MAAM,EAAE,CAAC;AACpB,CAAC,CAAC;AAhCW,QAAA,8BAA8B,kCAgCzC"}
@@ -3,7 +3,7 @@ import type { Context } from 'aws-lambda';
3
3
  import type { ContextLogTrail } from 'sdk-logs';
4
4
  import type { ZodSchema } from 'zod';
5
5
  import type { ContextAwsLambdaServer } from '../../../domain.objects/ContextAwsLambdaServer';
6
- import type { IoLogTranslate } from '../middleware/genIoLoggerMiddleware';
6
+ import type { TranslateLog } from '../TranslateLog';
7
7
  /**
8
8
  * .what = wrapped payload format: event nested under `event` key with trail
9
9
  * .why = askLambdaEndpoint sends this format for trail propagation
@@ -45,7 +45,7 @@ export type GenLambdaEndpointInput<TInput, TOutput> = {
45
45
  output: ZodSchema<TOutput>;
46
46
  };
47
47
  invoke: EndpointOperation<TInput, TOutput>;
48
- logTranslate?: IoLogTranslate;
48
+ logTranslate?: TranslateLog;
49
49
  };
50
50
  /**
51
51
  * .what = sdk contract type for genLambdaEndpoint context
@@ -55,24 +55,8 @@ export type GenLambdaEndpointInput<TInput, TOutput> = {
55
55
  export type GenLambdaEndpointContext = ContextAwsLambdaServer;
56
56
  /**
57
57
  * .what = generates a lambda handler with validation and trail context
58
- * .why = standardizes handler creation with schema validation and observability
59
- *
60
- * follows simple-lambda-handlers createStandardHandler pattern:
61
- * - uses middy middleware chain
62
- * - badRequestError middleware returns error object instead of throw
63
- * - internalServiceError middleware logs errors loudly
64
- * - ioLogger middleware logs input/output for debug
65
- * - validation middleware validates input against schema
66
- *
67
- * additions for sdk-aws-lambda:
68
- * - trail middleware injects log with trail context
69
- * - output validation via zod schema
58
+ * .why = standardizes handler creation with schema validation and observability. the chain:
59
+ * constraint error (a caller fault becomes a response object, never a throw), internal
60
+ * service error (logs loudly), io logger, trail, input + output validation
70
61
  */
71
- export declare const genLambdaEndpoint: <TInput, TOutput>(input: {
72
- schema: {
73
- input: ZodSchema<TInput>;
74
- output: ZodSchema<TOutput>;
75
- };
76
- invoke: EndpointOperation<TInput, TOutput>;
77
- logTranslate?: IoLogTranslate;
78
- }, context?: ContextAwsLambdaServer) => middy.MiddyfiedHandler<LambdaHandlerInput<TInput>, TOutput, Error, Context>;
62
+ export declare const genLambdaEndpoint: <TInput, TOutput>(input: GenLambdaEndpointInput<TInput, TOutput>, context?: ContextAwsLambdaServer) => middy.MiddyfiedHandler<LambdaHandlerInput<TInput>, TOutput, Error, Context>;
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.genLambdaEndpoint = void 0;
7
7
  const core_1 = __importDefault(require("@middy/core"));
8
+ const asContextLogTrail_1 = require("../asContextLogTrail");
8
9
  const genConstraintErrorMiddleware_1 = require("../middleware/genConstraintErrorMiddleware");
9
10
  const genInternalServiceErrorMiddleware_1 = require("../middleware/genInternalServiceErrorMiddleware");
10
11
  const genIntrospectionMiddleware_1 = require("../middleware/genIntrospectionMiddleware");
@@ -14,24 +15,18 @@ const getValidatedOutput_1 = require("../middleware/getValidatedOutput");
14
15
  const genZodEventValidationMiddleware_1 = require("./middleware/genZodEventValidationMiddleware");
15
16
  /**
16
17
  * .what = generates a lambda handler with validation and trail context
17
- * .why = standardizes handler creation with schema validation and observability
18
- *
19
- * follows simple-lambda-handlers createStandardHandler pattern:
20
- * - uses middy middleware chain
21
- * - badRequestError middleware returns error object instead of throw
22
- * - internalServiceError middleware logs errors loudly
23
- * - ioLogger middleware logs input/output for debug
24
- * - validation middleware validates input against schema
25
- *
26
- * additions for sdk-aws-lambda:
27
- * - trail middleware injects log with trail context
28
- * - output validation via zod schema
18
+ * .why = standardizes handler creation with schema validation and observability. the chain:
19
+ * constraint error (a caller fault becomes a response object, never a throw), internal
20
+ * service error (logs loudly), io logger, trail, input + output validation
29
21
  */
30
- const genLambdaEndpoint = (input, context) => {
22
+ const genLambdaEndpoint = (
23
+ // typed by the EXPORTED contract rather than an inline restatement — the two were hand-synced
24
+ // before, and a rename that reached only one of them would have compiled
25
+ input, context) => {
31
26
  // build logic that invokes user handler and validates output
32
27
  const logic = async (event, lambdaContext) => {
33
- // get log from lambda context (injected by trail middleware)
34
- const log = lambdaContext.log;
28
+ // read the trail log `genTrailMiddleware` wrote; the cast lives in the shared reader
29
+ const { log } = (0, asContextLogTrail_1.asContextLogTrail)({ context: lambdaContext });
35
30
  // invoke user handler
36
31
  const response = await input.invoke({ event }, { log });
37
32
  // validate output and return typed result
@@ -44,11 +39,22 @@ const genLambdaEndpoint = (input, context) => {
44
39
  // 4. introspection (onBefore) - intercepts introspect requests, returns schema
45
40
  // 5. validation (onBefore) - validates event against schema
46
41
  const middlewares = [
47
- (0, genConstraintErrorMiddleware_1.genConstraintErrorMiddleware)(),
48
- (0, genInternalServiceErrorMiddleware_1.genInternalServiceErrorMiddleware)(),
42
+ /**
43
+ * .note = this family's response IS its payload, so a caller fault renders as the body
44
+ * itself — and a SERVER fault is declined (`false`), which lets the invocation FAIL
45
+ * so cloudwatch records it and the caller may retry
46
+ */
47
+ (0, genConstraintErrorMiddleware_1.genConstraintErrorMiddleware)({ asOutputAfter: (body) => body }),
48
+ (0, genInternalServiceErrorMiddleware_1.genInternalServiceErrorMiddleware)({ asOutputAfter: false }),
49
49
  (0, genTrailMiddleware_1.genTrailMiddleware)(),
50
50
  (0, genIoLoggerMiddleware_1.genIoLoggerMiddleware)({ logTranslate: input.logTranslate }),
51
- (0, genIntrospectionMiddleware_1.genIntrospectionMiddleware)({ schema: input.schema, env: context?.env }),
51
+ (0, genIntrospectionMiddleware_1.genIntrospectionMiddleware)({
52
+ schema: input.schema,
53
+ env: context?.env,
54
+ // this family carries `inputAfter` at `event` itself, and its response IS its payload
55
+ asInputAfter: (request) => request.event,
56
+ asOutputAfter: (schema) => schema,
57
+ }),
52
58
  (0, genZodEventValidationMiddleware_1.genZodEventValidationMiddleware)({ schema: input.schema.input }),
53
59
  ];
54
60
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"genLambdaEndpoint.forAskEndpoint.js","sourceRoot":"","sources":["../../../../src/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forAskEndpoint/genLambdaEndpoint.forAskEndpoint.ts"],"names":[],"mappings":";;;;;;AAAA,uDAAgC;AAMhC,6FAA0F;AAC1F,uGAAoG;AACpG,yFAAsF;AAEtF,+EAA4E;AAC5E,yEAAsE;AACtE,yEAAsE;AACtE,kGAA+F;AAsD/F;;;;;;;;;;;;;;GAcG;AACI,MAAM,iBAAiB,GAAG,CAC/B,KAOC,EACD,OAAgC,EAMhC,EAAE;IACF,6DAA6D;IAC7D,MAAM,KAAK,GAAG,KAAK,EACjB,KAAa,EACb,aAAsB,EACJ,EAAE;QACpB,6DAA6D;QAC7D,MAAM,GAAG,GAAI,aAA4C,CAAC,GAAG,CAAC;QAE9D,sBAAsB;QACtB,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,GAAG,EAAE,CAAC,CAAC;QAExD,0CAA0C;QAC1C,OAAO,IAAA,uCAAkB,EAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC;IACvE,CAAC,CAAC;IAEF,4BAA4B;IAC5B,wFAAwF;IACxF,2GAA2G;IAC3G,6CAA6C;IAC7C,+EAA+E;IAC/E,4DAA4D;IAC5D,MAAM,WAAW,GAAG;QAClB,IAAA,2DAA4B,GAAE;QAC9B,IAAA,qEAAiC,GAAE;QACnC,IAAA,uCAAkB,GAAE;QACpB,IAAA,6CAAqB,EAAC,EAAE,YAAY,EAAE,KAAK,CAAC,YAAY,EAAE,CAAC;QAC3D,IAAA,uDAA0B,EAAC,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC;QACvE,IAAA,iEAA+B,EAAC,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;KAChE,CAAC;IAEF;;;;OAIG;IACH,OAAO,IAAA,cAAK,EACV,KAGqB,CACtB,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;AACrB,CAAC,CAAC;AAzDW,QAAA,iBAAiB,qBAyD5B"}
1
+ {"version":3,"file":"genLambdaEndpoint.forAskEndpoint.js","sourceRoot":"","sources":["../../../../src/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forAskEndpoint/genLambdaEndpoint.forAskEndpoint.ts"],"names":[],"mappings":";;;;;;AAAA,uDAAgC;AAMhC,4DAAyD;AACzD,6FAA0F;AAC1F,uGAAoG;AACpG,yFAAsF;AACtF,+EAA4E;AAC5E,yEAAsE;AACtE,yEAAsE;AAEtE,kGAA+F;AAsD/F;;;;;GAKG;AACI,MAAM,iBAAiB,GAAG;AAC/B,8FAA8F;AAC9F,yEAAyE;AACzE,KAA8C,EAC9C,OAAgC,EAMhC,EAAE;IACF,6DAA6D;IAC7D,MAAM,KAAK,GAAG,KAAK,EACjB,KAAa,EACb,aAAsB,EACJ,EAAE;QACpB,qFAAqF;QACrF,MAAM,EAAE,GAAG,EAAE,GAAG,IAAA,qCAAiB,EAAC,EAAE,OAAO,EAAE,aAAa,EAAE,CAAC,CAAC;QAE9D,sBAAsB;QACtB,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,GAAG,EAAE,CAAC,CAAC;QAExD,0CAA0C;QAC1C,OAAO,IAAA,uCAAkB,EAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC;IACvE,CAAC,CAAC;IAEF,4BAA4B;IAC5B,wFAAwF;IACxF,2GAA2G;IAC3G,6CAA6C;IAC7C,+EAA+E;IAC/E,4DAA4D;IAC5D,MAAM,WAAW,GAAG;QAClB;;;;WAIG;QACH,IAAA,2DAA4B,EAAC,EAAE,aAAa,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,EAAE,CAAC;QAC/D,IAAA,qEAAiC,EAAC,EAAE,aAAa,EAAE,KAAK,EAAE,CAAC;QAC3D,IAAA,uCAAkB,GAAE;QACpB,IAAA,6CAAqB,EAAC,EAAE,YAAY,EAAE,KAAK,CAAC,YAAY,EAAE,CAAC;QAC3D,IAAA,uDAA0B,EAAC;YACzB,MAAM,EAAE,KAAK,CAAC,MAAM;YACpB,GAAG,EAAE,OAAO,EAAE,GAAG;YACjB,sFAAsF;YACtF,YAAY,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK;YACxC,aAAa,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM;SAClC,CAAC;QACF,IAAA,iEAA+B,EAAC,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;KAChE,CAAC;IAEF;;;;OAIG;IACH,OAAO,IAAA,cAAK,EACV,KAGqB,CACtB,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;AACrB,CAAC,CAAC;AA/DW,QAAA,iBAAiB,qBA+D5B"}
@@ -1,8 +1,17 @@
1
1
  import type middy from '@middy/core';
2
2
  import type { ZodSchema } from 'zod';
3
3
  /**
4
- * .what = validates entire event against zod schema
5
- * .why = askLambdaEndpoint sends unwrapped payload, validate full event
4
+ * .what = validates the entire event against a zod schema
5
+ * .why = the ask-endpoint family reaches this step with the caller's value AT `request.event`,
6
+ * so the whole event is what the schema describes
7
+ *
8
+ * .note = its api-gateway peer, `genZodBodyValidationMiddleware`, validates `event.body`
9
+ * instead, because that chain must keep `request.event` http-shaped. the two collapse
10
+ * into one validator at the common ancestor the moment `inputAfter` has ONE home
11
+ * across both chains — see the 🚧 note in
12
+ * `.behavior/v2026_08_03.feat-apigateway-wire-response/5.1.execution.from_vision.yield.md`.
13
+ * this stays at the leaf until then, because a lift with one consumer is speculative
14
+ * (rule.prefer.most-common-denominator)
6
15
  */
7
16
  export declare const genZodEventValidationMiddleware: <TInput>(input: {
8
17
  schema: ZodSchema<TInput>;
@@ -3,8 +3,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.genZodEventValidationMiddleware = void 0;
4
4
  const getValidationError_1 = require("../../middleware/getValidationError");
5
5
  /**
6
- * .what = validates entire event against zod schema
7
- * .why = askLambdaEndpoint sends unwrapped payload, validate full event
6
+ * .what = validates the entire event against a zod schema
7
+ * .why = the ask-endpoint family reaches this step with the caller's value AT `request.event`,
8
+ * so the whole event is what the schema describes
9
+ *
10
+ * .note = its api-gateway peer, `genZodBodyValidationMiddleware`, validates `event.body`
11
+ * instead, because that chain must keep `request.event` http-shaped. the two collapse
12
+ * into one validator at the common ancestor the moment `inputAfter` has ONE home
13
+ * across both chains — see the 🚧 note in
14
+ * `.behavior/v2026_08_03.feat-apigateway-wire-response/5.1.execution.from_vision.yield.md`.
15
+ * this stays at the leaf until then, because a lift with one consumer is speculative
16
+ * (rule.prefer.most-common-denominator)
8
17
  */
9
18
  const genZodEventValidationMiddleware = (input) => {
10
19
  const before = async (request) => {
@@ -13,6 +22,7 @@ const genZodEventValidationMiddleware = (input) => {
13
22
  throw (0, getValidationError_1.getValidationError)({ error: result.error });
14
23
  }
15
24
  // replace event with parsed (transformed) result
25
+ // .note = DELIBERATE MUTATION — `request` is middy's only channel to hand a value onward
16
26
  request.event = result.data;
17
27
  };
18
28
  return { before };
@@ -1 +1 @@
1
- {"version":3,"file":"genZodEventValidationMiddleware.js","sourceRoot":"","sources":["../../../../../src/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forAskEndpoint/middleware/genZodEventValidationMiddleware.ts"],"names":[],"mappings":";;;AAGA,4EAAyE;AAEzE;;;GAGG;AACI,MAAM,+BAA+B,GAAG,CAAS,KAEvD,EAEC,EAAE;IACF,MAAM,MAAM,GAAiC,KAAK,EAAE,OAAO,EAAE,EAAE;QAC7D,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,SAAS,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QACrD,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;YACpB,MAAM,IAAA,uCAAkB,EAAC,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC;QACpD,CAAC;QACD,iDAAiD;QACjD,OAAO,CAAC,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC;IAC9B,CAAC,CAAC;IAEF,OAAO,EAAE,MAAM,EAAE,CAAC;AACpB,CAAC,CAAC;AAfW,QAAA,+BAA+B,mCAe1C"}
1
+ {"version":3,"file":"genZodEventValidationMiddleware.js","sourceRoot":"","sources":["../../../../../src/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forAskEndpoint/middleware/genZodEventValidationMiddleware.ts"],"names":[],"mappings":";;;AAGA,4EAAyE;AAEzE;;;;;;;;;;;;GAYG;AACI,MAAM,+BAA+B,GAAG,CAAS,KAEvD,EAEC,EAAE;IACF,MAAM,MAAM,GAAiC,KAAK,EAAE,OAAO,EAAE,EAAE;QAC7D,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,SAAS,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QACrD,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;YACpB,MAAM,IAAA,uCAAkB,EAAC,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC;QACpD,CAAC;QACD,iDAAiD;QACjD,yFAAyF;QACzF,OAAO,CAAC,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC;IAC9B,CAAC,CAAC;IAEF,OAAO,EAAE,MAAM,EAAE,CAAC;AACpB,CAAC,CAAC;AAhBW,QAAA,+BAA+B,mCAgB1C"}
@@ -0,0 +1,37 @@
1
+ import type { ContextLogTrail } from 'sdk-logs';
2
+ /**
3
+ * .what = the fields THIS SDK adds onto the lambda context, beyond aws's own `Context`
4
+ * .why = `genTrailMiddleware` writes both of these, and six middleware sites read them. each
5
+ * had restated the same inline cast shape, so a change to either field meant six edits
6
+ * (rule.forbid.parallel-codepaths)
7
+ *
8
+ * .note = both are OPTIONAL by honest necessity, never by preference. a middleware's array
9
+ * position decides whether trail has run yet, so a reader placed above trail genuinely
10
+ * sees `undefined` — that is the live `handler.input` defect, and a required type here
11
+ * would state a guarantee the chain does not keep
12
+ */
13
+ export interface ContextTrailed {
14
+ log?: ContextLogTrail['log'];
15
+ isContempCaller?: boolean;
16
+ }
17
+ /**
18
+ * .what = reads the sdk-managed fields off a middy request's context
19
+ * .why = ONE documented cast, in place of the same cast restated at every read site
20
+ * (rule.forbid.as-cast, rule.require.named-transformers)
21
+ *
22
+ * .as = middy types `request.context` as aws-lambda's `Context`, which declares neither `log`
23
+ * nor `isContempCaller`. this sdk puts both there itself, via `genTrailMiddleware`, so the
24
+ * cast asserts what the sdk's own middleware wrote — never an outside claim
25
+ *
26
+ * .removal = removable when middy's `Request` carries a caller-declared context type parameter
27
+ * this chain can bind, such that `MiddyfiedHandler`'s `TContext` reaches a middleware's
28
+ * `request.context`. until then no type-level path exists from what `genTrailMiddleware`
29
+ * writes to what a later middleware reads
30
+ *
31
+ * .note = an absent context yields `{}` rather than a throw. a reader must handle the
32
+ * trail-has-not-run case regardless (see `.note` on `ContextTrailed`), so a throw here
33
+ * would convert a documented fact about array order into a crash
34
+ */
35
+ export declare const asContextTrailed: (input: {
36
+ context: unknown;
37
+ }) => ContextTrailed;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.asContextTrailed = void 0;
4
+ /**
5
+ * .what = reads the sdk-managed fields off a middy request's context
6
+ * .why = ONE documented cast, in place of the same cast restated at every read site
7
+ * (rule.forbid.as-cast, rule.require.named-transformers)
8
+ *
9
+ * .as = middy types `request.context` as aws-lambda's `Context`, which declares neither `log`
10
+ * nor `isContempCaller`. this sdk puts both there itself, via `genTrailMiddleware`, so the
11
+ * cast asserts what the sdk's own middleware wrote — never an outside claim
12
+ *
13
+ * .removal = removable when middy's `Request` carries a caller-declared context type parameter
14
+ * this chain can bind, such that `MiddyfiedHandler`'s `TContext` reaches a middleware's
15
+ * `request.context`. until then no type-level path exists from what `genTrailMiddleware`
16
+ * writes to what a later middleware reads
17
+ *
18
+ * .note = an absent context yields `{}` rather than a throw. a reader must handle the
19
+ * trail-has-not-run case regardless (see `.note` on `ContextTrailed`), so a throw here
20
+ * would convert a documented fact about array order into a crash
21
+ */
22
+ const asContextTrailed = (input) => (input.context ?? {});
23
+ exports.asContextTrailed = asContextTrailed;
24
+ //# sourceMappingURL=asContextTrailed.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"asContextTrailed.js","sourceRoot":"","sources":["../../../../src/domain.operations/genLambdaEndpoint/middleware/asContextTrailed.ts"],"names":[],"mappings":";;;AAkBA;;;;;;;;;;;;;;;;;GAiBG;AACI,MAAM,gBAAgB,GAAG,CAAC,KAA2B,EAAkB,EAAE,CAC9E,CAAC,KAAK,CAAC,OAAO,IAAI,EAAE,CAAmB,CAAC;AAD7B,QAAA,gBAAgB,oBACa"}
@@ -1,14 +1,15 @@
1
1
  import type middy from '@middy/core';
2
- export interface ApiGatewayResponse {
3
- statusCode: number;
4
- body: string;
5
- headers?: Record<string, string>;
6
- }
2
+ import { type LambdaEndpointErrorResponseBodyAncient, type LambdaEndpointErrorResponseBodyContemp } from './getErrorResponseBody';
7
3
  /**
8
4
  * .what = middleware that handles ConstraintError (and legacy BadRequestError)
9
- * .why = ConstraintError = caller fault, not server fault
10
- * - for apiGateway: returns 400 response with error details
11
- * - for standard: returns error response object (lambda succeeds)
5
+ * .why = ConstraintError = caller fault, not server fault, so the invocation SUCCEEDS either
6
+ * way — a caller fault must not emit a cloudwatch error nor signal a retry
7
+ * (invariant.badrequesterror-not-lambda-error)
8
+ *
9
+ * .note = this middleware does NOT know which families exist. it builds the error BODY and
10
+ * hands it to the family's own `asOutputAfter`, so the wire shape is the family's to
11
+ * state. a flag read here would fork one guarantee across two paths
12
+ * (rule.forbid.parallel-codepaths)
12
13
  *
13
14
  * note: InternalServiceError is handled by genInternalServiceErrorMiddleware
14
15
  *
@@ -16,8 +17,15 @@ export interface ApiGatewayResponse {
16
17
  * flat errorType/errorMessage format
17
18
  * contemp callers receive nested { error: { _serde, class, message } }
18
19
  */
19
- export declare const genConstraintErrorMiddleware: (opts?: {
20
- apiGateway?: boolean;
20
+ export declare const genConstraintErrorMiddleware: (opts: {
21
+ /**
22
+ * .what = renders the error body as this family's `outputAfter`
23
+ * .why = the two families owe DIFFERENT shapes for the same fault: api-gateway owes a wire
24
+ * payload with a 400 and a stringified body, while an ask-endpoint response IS its
25
+ * payload. only the family knows which, so the family supplies it — never a flag read
26
+ * here (rule.forbid.parallel-codepaths)
27
+ */
28
+ asOutputAfter: (body: LambdaEndpointErrorResponseBodyContemp | LambdaEndpointErrorResponseBodyAncient) => unknown;
21
29
  }) => {
22
30
  onError: middy.MiddlewareFn<any, any>;
23
31
  };
@@ -1,13 +1,19 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.genConstraintErrorMiddleware = void 0;
4
+ const asContextTrailed_1 = require("./asContextTrailed");
4
5
  const getErrorResponseBody_1 = require("./getErrorResponseBody");
5
6
  const getIsConstraintError_1 = require("./getIsConstraintError");
6
7
  /**
7
8
  * .what = middleware that handles ConstraintError (and legacy BadRequestError)
8
- * .why = ConstraintError = caller fault, not server fault
9
- * - for apiGateway: returns 400 response with error details
10
- * - for standard: returns error response object (lambda succeeds)
9
+ * .why = ConstraintError = caller fault, not server fault, so the invocation SUCCEEDS either
10
+ * way — a caller fault must not emit a cloudwatch error nor signal a retry
11
+ * (invariant.badrequesterror-not-lambda-error)
12
+ *
13
+ * .note = this middleware does NOT know which families exist. it builds the error BODY and
14
+ * hands it to the family's own `asOutputAfter`, so the wire shape is the family's to
15
+ * state. a flag read here would fork one guarantee across two paths
16
+ * (rule.forbid.parallel-codepaths)
11
17
  *
12
18
  * note: InternalServiceError is handled by genInternalServiceErrorMiddleware
13
19
  *
@@ -26,30 +32,21 @@ const genConstraintErrorMiddleware = (opts) => {
26
32
  if (!isConstraintError)
27
33
  return;
28
34
  // detect if caller is contemp (sent wrapped payload) or ancient
29
- const context = request.context;
30
- const isContempCaller = context.isContempCaller ?? false;
35
+ const { isContempCaller = false } = (0, asContextTrailed_1.asContextTrailed)({
36
+ context: request.context,
37
+ });
31
38
  // build error response body via transformer based on caller type
32
39
  const body = isContempCaller
33
40
  ? (0, getErrorResponseBody_1.getErrorResponseBodyContemp)({ error, errorClass: 'ConstraintError' })
34
41
  : (0, getErrorResponseBody_1.getErrorResponseBodyAncient)({ error, errorType: 'BadRequestError' });
35
- // for api gateway: return http response
36
- if (opts?.apiGateway) {
37
- /**
38
- * .as = middy types request.response as unknown, but we set it to ApiGatewayResponse
39
- * .removal = if middy gains typed response inference for API Gateway handlers, remove cast
40
- */
41
- request.response = {
42
- statusCode: 400,
43
- body: JSON.stringify(body),
44
- headers: {
45
- 'Content-Type': 'application/json',
46
- },
47
- };
48
- return;
49
- }
50
- // for standard handler: return error response object
51
- // lambda invocation succeeds, caller detects error shape and throws
52
- request.response = body;
42
+ /**
43
+ * .what = hand the wire whatever shape this family owes for a caller fault
44
+ * .why = the lambda invocation SUCCEEDS either way — a caller fault must not emit a
45
+ * cloudwatch error nor signal a retry (invariant.badrequesterror-not-lambda-error)
46
+ *
47
+ * .note = DELIBERATE MUTATION — `request` is middy's only channel to hand a value onward
48
+ */
49
+ request.response = opts.asOutputAfter(body);
53
50
  };
54
51
  return { onError };
55
52
  };
@@ -1 +1 @@
1
- {"version":3,"file":"genConstraintErrorMiddleware.js","sourceRoot":"","sources":["../../../../src/domain.operations/genLambdaEndpoint/middleware/genConstraintErrorMiddleware.ts"],"names":[],"mappings":";;;AAEA,iEAKgC;AAChC,iEAA8D;AAQ9D;;;;;;;;;;;GAWG;AACI,MAAM,4BAA4B,GAAG,CAAC,IAE5C,EAEC,EAAE;IACF,MAAM,OAAO,GAAiC,KAAK,EAAE,OAAO,EAAE,EAAE;QAC9D,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;QAC5B,IAAI,CAAC,KAAK;YAAE,OAAO;QAEnB,qEAAqE;QACrE,uEAAuE;QACvE,MAAM,iBAAiB,GAAG,IAAA,2CAAoB,EAAC,EAAE,KAAK,EAAE,CAAC,CAAC;QAC1D,IAAI,CAAC,iBAAiB;YAAE,OAAO;QAE/B,gEAAgE;QAChE,MAAM,OAAO,GAAG,OAAO,CAAC,OAAwC,CAAC;QACjE,MAAM,eAAe,GAAG,OAAO,CAAC,eAAe,IAAI,KAAK,CAAC;QAEzD,iEAAiE;QACjE,MAAM,IAAI,GAEmC,eAAe;YAC1D,CAAC,CAAC,IAAA,kDAA2B,EAAC,EAAE,KAAK,EAAE,UAAU,EAAE,iBAAiB,EAAE,CAAC;YACvE,CAAC,CAAC,IAAA,kDAA2B,EAAC,EAAE,KAAK,EAAE,SAAS,EAAE,iBAAiB,EAAE,CAAC,CAAC;QAEzE,wCAAwC;QACxC,IAAI,IAAI,EAAE,UAAU,EAAE,CAAC;YACrB;;;eAGG;YACH,OAAO,CAAC,QAAQ,GAAG;gBACjB,UAAU,EAAE,GAAG;gBACf,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC;gBAC1B,OAAO,EAAE;oBACP,cAAc,EAAE,kBAAkB;iBACnC;aACoB,CAAC;YACxB,OAAO;QACT,CAAC;QAED,qDAAqD;QACrD,oEAAoE;QACpE,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC;IAC1B,CAAC,CAAC;IACF,OAAO,EAAE,OAAO,EAAE,CAAC;AACrB,CAAC,CAAC;AA9CW,QAAA,4BAA4B,gCA8CvC"}
1
+ {"version":3,"file":"genConstraintErrorMiddleware.js","sourceRoot":"","sources":["../../../../src/domain.operations/genLambdaEndpoint/middleware/genConstraintErrorMiddleware.ts"],"names":[],"mappings":";;;AAEA,yDAAsD;AACtD,iEAKgC;AAChC,iEAA8D;AAE9D;;;;;;;;;;;;;;;;GAgBG;AACI,MAAM,4BAA4B,GAAG,CAAC,IAa5C,EAEC,EAAE;IACF,MAAM,OAAO,GAAiC,KAAK,EAAE,OAAO,EAAE,EAAE;QAC9D,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;QAC5B,IAAI,CAAC,KAAK;YAAE,OAAO;QAEnB,qEAAqE;QACrE,uEAAuE;QACvE,MAAM,iBAAiB,GAAG,IAAA,2CAAoB,EAAC,EAAE,KAAK,EAAE,CAAC,CAAC;QAC1D,IAAI,CAAC,iBAAiB;YAAE,OAAO;QAE/B,gEAAgE;QAChE,MAAM,EAAE,eAAe,GAAG,KAAK,EAAE,GAAG,IAAA,mCAAgB,EAAC;YACnD,OAAO,EAAE,OAAO,CAAC,OAAO;SACzB,CAAC,CAAC;QAEH,iEAAiE;QACjE,MAAM,IAAI,GAEmC,eAAe;YAC1D,CAAC,CAAC,IAAA,kDAA2B,EAAC,EAAE,KAAK,EAAE,UAAU,EAAE,iBAAiB,EAAE,CAAC;YACvE,CAAC,CAAC,IAAA,kDAA2B,EAAC,EAAE,KAAK,EAAE,SAAS,EAAE,iBAAiB,EAAE,CAAC,CAAC;QAEzE;;;;;;WAMG;QACH,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;IAC9C,CAAC,CAAC;IACF,OAAO,EAAE,OAAO,EAAE,CAAC;AACrB,CAAC,CAAC;AA/CW,QAAA,4BAA4B,gCA+CvC"}
@@ -1,13 +1,36 @@
1
1
  import type middy from '@middy/core';
2
2
  /**
3
3
  * .what = middleware that logs and handles internal service errors
4
- * .why = all errors that are not BadRequestError are internal service errors
5
- * - logs the error loudly
6
- * - for apiGateway: returns 500 response (no details to avoid leaks)
7
- * - for standard: passes error up the chain
4
+ * .why = all errors that are not a ConstraintError are internal service errors, so each one is
5
+ * logged loudly and never echoed to the wire — no internal detail, no secret
6
+ *
7
+ * .note = this middleware does NOT know which families exist. the family states what a server
8
+ * fault owes the wire via `asOutputAfter` — and that includes the choice to DECLINE and
9
+ * let the invocation fail. a flag read here would fork one guarantee across two paths
10
+ * (rule.forbid.parallel-codepaths)
8
11
  */
9
- export declare const genInternalServiceErrorMiddleware: (opts?: {
10
- apiGateway?: boolean;
12
+ export declare const genInternalServiceErrorMiddleware: (opts: {
13
+ /**
14
+ * .what = renders a server fault as this family's `outputAfter`, or declines to answer
15
+ * .why = the two families make DIFFERENT guarantees for the same fault, so this is not one
16
+ * shape with two renderings (rule.forbid.parallel-codepaths exempts genuinely
17
+ * different guarantees — it forbids only the FLAG that selected between them):
18
+ *
19
+ * function -> answer the wire with this shape; the invocation SUCCEEDS, since http demands
20
+ * a response and a hung request is worse than a 500
21
+ * false -> DISARMED; rethrow, so the invocation FAILS, cloudwatch records the error, and
22
+ * the caller may retry — which is the right contract for a server fault when no
23
+ * http client waits on it
24
+ *
25
+ * .note = the off-state is `false`, never absent. an absent field would disable a guarantee by
26
+ * omission, so a caller who forgot it would be indistinguishable from one who chose it
27
+ * (rule.require.explicit-optout), and `false` differs maximally in form from
28
+ * `undefined` (rule.forbid.opposite-senses-on-undefined-and-null)
29
+ */
30
+ asOutputAfter: ((input: {
31
+ error: Error;
32
+ exid: string | null;
33
+ }) => unknown) | false;
11
34
  }) => {
12
35
  onError: middy.MiddlewareFn<any, any>;
13
36
  };
@@ -1,13 +1,17 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.genInternalServiceErrorMiddleware = void 0;
4
+ const asContextTrailed_1 = require("./asContextTrailed");
4
5
  const getIsConstraintError_1 = require("./getIsConstraintError");
5
6
  /**
6
7
  * .what = middleware that logs and handles internal service errors
7
- * .why = all errors that are not BadRequestError are internal service errors
8
- * - logs the error loudly
9
- * - for apiGateway: returns 500 response (no details to avoid leaks)
10
- * - for standard: passes error up the chain
8
+ * .why = all errors that are not a ConstraintError are internal service errors, so each one is
9
+ * logged loudly and never echoed to the wire — no internal detail, no secret
10
+ *
11
+ * .note = this middleware does NOT know which families exist. the family states what a server
12
+ * fault owes the wire via `asOutputAfter` — and that includes the choice to DECLINE and
13
+ * let the invocation fail. a flag read here would fork one guarantee across two paths
14
+ * (rule.forbid.parallel-codepaths)
11
15
  */
12
16
  const genInternalServiceErrorMiddleware = (opts) => {
13
17
  const onError = async (request) => {
@@ -19,36 +23,27 @@ const genInternalServiceErrorMiddleware = (opts) => {
19
23
  const isBadRequest = (0, getIsConstraintError_1.getIsConstraintError)({ error });
20
24
  if (isBadRequest)
21
25
  return;
22
- // get log from context if available
23
- const log = request.context?.log;
26
+ // read the sdk-managed context once — trail may not have run yet
27
+ const { log } = (0, asContextTrailed_1.asContextTrailed)({ context: request.context });
24
28
  // log the error via context.log or fallback to console
25
29
  const logError = log?.error ?? console.error;
26
30
  logError('handler.error', {
27
31
  errorMessage: error.message,
28
32
  stackTrace: error.stack,
29
33
  });
30
- // if we're in the api gateway context, handle the error and return a standard response
31
- if (opts?.apiGateway) {
32
- // get exid from trail context if available for correlation
33
- const exid = request.context
34
- ?.log?.trail?.exid;
35
- // build the response object with generic message
36
- // note: we include a generic message and correlation id (exid) but no details to avoid leaks
37
- request.response = {
38
- statusCode: 500,
39
- body: JSON.stringify({
40
- errorMessage: 'internal server error',
41
- errorType: 'InternalServiceError',
42
- ...(exid ? { correlationId: exid } : {}),
43
- }),
44
- headers: { 'Content-Type': 'application/json' },
45
- };
46
- // return undefined so that middy knows we handled the error
47
- // prevents cloudWatch from classifying this as a lambda error
48
- return;
49
- }
50
- // if we didn't handle the error above, rethrow it
51
- throw error;
34
+ // a family that declines to answer lets the invocation fail, so cloudwatch records it
35
+ if (opts.asOutputAfter === false)
36
+ throw error;
37
+ // get exid from trail context if available for correlation
38
+ const exid = log?.trail?.exid ?? null;
39
+ /**
40
+ * .what = answer the wire with this family's shape for a server fault
41
+ * .why = middy treats a set `request.response` as "handled", which keeps the invocation a
42
+ * SUCCESS and stops cloudwatch from a lambda-error classification
43
+ *
44
+ * .note = DELIBERATE MUTATION — `request` is middy's only channel to hand a value onward
45
+ */
46
+ request.response = opts.asOutputAfter({ error, exid });
52
47
  };
53
48
  return { onError };
54
49
  };