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