sdk-aws-lambda 0.1.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 (132) hide show
  1. package/dist/domain.objects/HttpStatusCode.d.ts +28 -0
  2. package/dist/domain.objects/HttpStatusCode.js +37 -0
  3. package/dist/domain.objects/HttpStatusCode.js.map +1 -0
  4. package/dist/domain.objects/LambdaEndpointContext.d.ts +6 -0
  5. package/dist/domain.objects/LambdaEndpointContext.js +3 -0
  6. package/dist/domain.objects/LambdaEndpointContext.js.map +1 -0
  7. package/dist/domain.objects/LambdaEndpointError.d.ts +51 -0
  8. package/dist/domain.objects/LambdaEndpointError.js +13 -0
  9. package/dist/domain.objects/LambdaEndpointError.js.map +1 -0
  10. package/dist/domain.operations/askLambdaEndpoint/askLambdaEndpoint.d.ts +54 -0
  11. package/dist/domain.operations/askLambdaEndpoint/askLambdaEndpoint.js +76 -0
  12. package/dist/domain.operations/askLambdaEndpoint/askLambdaEndpoint.js.map +1 -0
  13. package/dist/domain.operations/askLambdaEndpoint/cache/asCacheWithoutSet.d.ts +11 -0
  14. package/dist/domain.operations/askLambdaEndpoint/cache/asCacheWithoutSet.js +18 -0
  15. package/dist/domain.operations/askLambdaEndpoint/cache/asCacheWithoutSet.js.map +1 -0
  16. package/dist/domain.operations/askLambdaEndpoint/cache/asCachedExecutor.d.ts +18 -0
  17. package/dist/domain.operations/askLambdaEndpoint/cache/asCachedExecutor.js +31 -0
  18. package/dist/domain.operations/askLambdaEndpoint/cache/asCachedExecutor.js.map +1 -0
  19. package/dist/domain.operations/askLambdaEndpoint/cache/getAskLambdaCacheKey.d.ts +10 -0
  20. package/dist/domain.operations/askLambdaEndpoint/cache/getAskLambdaCacheKey.js +26 -0
  21. package/dist/domain.operations/askLambdaEndpoint/cache/getAskLambdaCacheKey.js.map +1 -0
  22. package/dist/domain.operations/askLambdaEndpoint/context/getAccessFromContext.d.ts +11 -0
  23. package/dist/domain.operations/askLambdaEndpoint/context/getAccessFromContext.js +21 -0
  24. package/dist/domain.operations/askLambdaEndpoint/context/getAccessFromContext.js.map +1 -0
  25. package/dist/domain.operations/askLambdaEndpoint/context/getExidFromContext.d.ts +16 -0
  26. package/dist/domain.operations/askLambdaEndpoint/context/getExidFromContext.js +20 -0
  27. package/dist/domain.operations/askLambdaEndpoint/context/getExidFromContext.js.map +1 -0
  28. package/dist/domain.operations/askLambdaEndpoint/context/getLogForExidExtraction.d.ts +27 -0
  29. package/dist/domain.operations/askLambdaEndpoint/context/getLogForExidExtraction.js +20 -0
  30. package/dist/domain.operations/askLambdaEndpoint/context/getLogForExidExtraction.js.map +1 -0
  31. package/dist/domain.operations/askLambdaEndpoint/error/getIsLambdaErrorResponse.d.ts +42 -0
  32. package/dist/domain.operations/askLambdaEndpoint/error/getIsLambdaErrorResponse.js +21 -0
  33. package/dist/domain.operations/askLambdaEndpoint/error/getIsLambdaErrorResponse.js.map +1 -0
  34. package/dist/domain.operations/askLambdaEndpoint/error/getLambdaErrorMetadata.d.ts +16 -0
  35. package/dist/domain.operations/askLambdaEndpoint/error/getLambdaErrorMetadata.js +19 -0
  36. package/dist/domain.operations/askLambdaEndpoint/error/getLambdaErrorMetadata.js.map +1 -0
  37. package/dist/domain.operations/askLambdaEndpoint/error/getStackTraceString.d.ts +7 -0
  38. package/dist/domain.operations/askLambdaEndpoint/error/getStackTraceString.js +16 -0
  39. package/dist/domain.operations/askLambdaEndpoint/error/getStackTraceString.js.map +1 -0
  40. package/dist/domain.operations/askLambdaEndpoint/error/getStatusCodeHint.d.ts +5 -0
  41. package/dist/domain.operations/askLambdaEndpoint/error/getStatusCodeHint.js +34 -0
  42. package/dist/domain.operations/askLambdaEndpoint/error/getStatusCodeHint.js.map +1 -0
  43. package/dist/domain.operations/askLambdaEndpoint/invoke/executeLambdaInvocation.d.ts +26 -0
  44. package/dist/domain.operations/askLambdaEndpoint/invoke/executeLambdaInvocation.js +60 -0
  45. package/dist/domain.operations/askLambdaEndpoint/invoke/executeLambdaInvocation.js.map +1 -0
  46. package/dist/domain.operations/askLambdaEndpoint/invoke/genLambdaClient.d.ts +11 -0
  47. package/dist/domain.operations/askLambdaEndpoint/invoke/genLambdaClient.js +17 -0
  48. package/dist/domain.operations/askLambdaEndpoint/invoke/genLambdaClient.js.map +1 -0
  49. package/dist/domain.operations/askLambdaEndpoint/invoke/sdkLambdaInvoke.d.ts +19 -0
  50. package/dist/domain.operations/askLambdaEndpoint/invoke/sdkLambdaInvoke.js +21 -0
  51. package/dist/domain.operations/askLambdaEndpoint/invoke/sdkLambdaInvoke.js.map +1 -0
  52. package/dist/domain.operations/askLambdaEndpoint/serde/getDecodedPayload.d.ts +7 -0
  53. package/dist/domain.operations/askLambdaEndpoint/serde/getDecodedPayload.js +12 -0
  54. package/dist/domain.operations/askLambdaEndpoint/serde/getDecodedPayload.js.map +1 -0
  55. package/dist/domain.operations/askLambdaEndpoint/serde/getLambdaFunctionName.d.ts +9 -0
  56. package/dist/domain.operations/askLambdaEndpoint/serde/getLambdaFunctionName.js +12 -0
  57. package/dist/domain.operations/askLambdaEndpoint/serde/getLambdaFunctionName.js.map +1 -0
  58. package/dist/domain.operations/askLambdaEndpoint/serde/getLambdaPayload.d.ts +15 -0
  59. package/dist/domain.operations/askLambdaEndpoint/serde/getLambdaPayload.js +15 -0
  60. package/dist/domain.operations/askLambdaEndpoint/serde/getLambdaPayload.js.map +1 -0
  61. package/dist/domain.operations/askLambdaEndpoint/serde/getParsedJson.d.ts +18 -0
  62. package/dist/domain.operations/askLambdaEndpoint/serde/getParsedJson.js +22 -0
  63. package/dist/domain.operations/askLambdaEndpoint/serde/getParsedJson.js.map +1 -0
  64. package/dist/domain.operations/askLambdaEndpoint/serde/getParsedResponse.d.ts +15 -0
  65. package/dist/domain.operations/askLambdaEndpoint/serde/getParsedResponse.js +99 -0
  66. package/dist/domain.operations/askLambdaEndpoint/serde/getParsedResponse.js.map +1 -0
  67. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/genLambdaEndpoint.forApiGateway.d.ts +83 -0
  68. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/genLambdaEndpoint.forApiGateway.js +99 -0
  69. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/genLambdaEndpoint.forApiGateway.js.map +1 -0
  70. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/getCorsOrigin.d.ts +14 -0
  71. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/getCorsOrigin.js +44 -0
  72. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/getCorsOrigin.js.map +1 -0
  73. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/getIsV1ApiGatewayEvent.d.ts +6 -0
  74. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/getIsV1ApiGatewayEvent.js +16 -0
  75. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/getIsV1ApiGatewayEvent.js.map +1 -0
  76. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/getIsV2ApiGatewayEvent.d.ts +6 -0
  77. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/getIsV2ApiGatewayEvent.js +16 -0
  78. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/getIsV2ApiGatewayEvent.js.map +1 -0
  79. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/middleware/genApiGatewayEventNormalizationMiddleware.d.ts +32 -0
  80. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/middleware/genApiGatewayEventNormalizationMiddleware.js +90 -0
  81. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/middleware/genApiGatewayEventNormalizationMiddleware.js.map +1 -0
  82. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/middleware/genZodBodyValidationMiddleware.d.ts +11 -0
  83. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/middleware/genZodBodyValidationMiddleware.js +22 -0
  84. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/middleware/genZodBodyValidationMiddleware.js.map +1 -0
  85. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forAskEndpoint/genLambdaEndpoint.forAskEndpoint.d.ts +80 -0
  86. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forAskEndpoint/genLambdaEndpoint.forAskEndpoint.js +59 -0
  87. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forAskEndpoint/genLambdaEndpoint.forAskEndpoint.js.map +1 -0
  88. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forAskEndpoint/middleware/genZodEventValidationMiddleware.d.ts +11 -0
  89. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forAskEndpoint/middleware/genZodEventValidationMiddleware.js +21 -0
  90. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forAskEndpoint/middleware/genZodEventValidationMiddleware.js.map +1 -0
  91. package/dist/domain.operations/genLambdaEndpoint/middleware/genConstraintErrorMiddleware.d.ts +23 -0
  92. package/dist/domain.operations/genLambdaEndpoint/middleware/genConstraintErrorMiddleware.js +57 -0
  93. package/dist/domain.operations/genLambdaEndpoint/middleware/genConstraintErrorMiddleware.js.map +1 -0
  94. package/dist/domain.operations/genLambdaEndpoint/middleware/genInternalServiceErrorMiddleware.d.ts +13 -0
  95. package/dist/domain.operations/genLambdaEndpoint/middleware/genInternalServiceErrorMiddleware.js +56 -0
  96. package/dist/domain.operations/genLambdaEndpoint/middleware/genInternalServiceErrorMiddleware.js.map +1 -0
  97. package/dist/domain.operations/genLambdaEndpoint/middleware/genIoLoggerMiddleware.d.ts +16 -0
  98. package/dist/domain.operations/genLambdaEndpoint/middleware/genIoLoggerMiddleware.js +44 -0
  99. package/dist/domain.operations/genLambdaEndpoint/middleware/genIoLoggerMiddleware.js.map +1 -0
  100. package/dist/domain.operations/genLambdaEndpoint/middleware/genTrailMiddleware.d.ts +12 -0
  101. package/dist/domain.operations/genLambdaEndpoint/middleware/genTrailMiddleware.js +51 -0
  102. package/dist/domain.operations/genLambdaEndpoint/middleware/genTrailMiddleware.js.map +1 -0
  103. package/dist/domain.operations/genLambdaEndpoint/middleware/genZodOutputValidationMiddleware.d.ts +9 -0
  104. package/dist/domain.operations/genLambdaEndpoint/middleware/genZodOutputValidationMiddleware.js +26 -0
  105. package/dist/domain.operations/genLambdaEndpoint/middleware/genZodOutputValidationMiddleware.js.map +1 -0
  106. package/dist/domain.operations/genLambdaEndpoint/middleware/getErrorResponseBody.d.ts +37 -0
  107. package/dist/domain.operations/genLambdaEndpoint/middleware/getErrorResponseBody.js +57 -0
  108. package/dist/domain.operations/genLambdaEndpoint/middleware/getErrorResponseBody.js.map +1 -0
  109. package/dist/domain.operations/genLambdaEndpoint/middleware/getIsConstraintError.d.ts +11 -0
  110. package/dist/domain.operations/genLambdaEndpoint/middleware/getIsConstraintError.js +54 -0
  111. package/dist/domain.operations/genLambdaEndpoint/middleware/getIsConstraintError.js.map +1 -0
  112. package/dist/domain.operations/genLambdaEndpoint/middleware/getIsWrappedPayload.d.ts +15 -0
  113. package/dist/domain.operations/genLambdaEndpoint/middleware/getIsWrappedPayload.js +36 -0
  114. package/dist/domain.operations/genLambdaEndpoint/middleware/getIsWrappedPayload.js.map +1 -0
  115. package/dist/domain.operations/genLambdaEndpoint/middleware/getUnwrappedEventWithExid.d.ts +13 -0
  116. package/dist/domain.operations/genLambdaEndpoint/middleware/getUnwrappedEventWithExid.js +25 -0
  117. package/dist/domain.operations/genLambdaEndpoint/middleware/getUnwrappedEventWithExid.js.map +1 -0
  118. package/dist/domain.operations/genLambdaEndpoint/middleware/getValidatedOutput.d.ts +9 -0
  119. package/dist/domain.operations/genLambdaEndpoint/middleware/getValidatedOutput.js +19 -0
  120. package/dist/domain.operations/genLambdaEndpoint/middleware/getValidatedOutput.js.map +1 -0
  121. package/dist/domain.operations/genLambdaEndpoint/middleware/getValidationError.d.ts +13 -0
  122. package/dist/domain.operations/genLambdaEndpoint/middleware/getValidationError.js +17 -0
  123. package/dist/domain.operations/genLambdaEndpoint/middleware/getValidationError.js.map +1 -0
  124. package/dist/domain.operations/genLambdaEndpoint/middleware/getZodIssuesSummary.d.ts +13 -0
  125. package/dist/domain.operations/genLambdaEndpoint/middleware/getZodIssuesSummary.js +16 -0
  126. package/dist/domain.operations/genLambdaEndpoint/middleware/getZodIssuesSummary.js.map +1 -0
  127. package/dist/index.d.ts +24 -0
  128. package/dist/index.js +41 -0
  129. package/dist/index.js.map +1 -0
  130. package/license.md +21 -0
  131. package/package.json +115 -0
  132. package/readme.md +54 -0
@@ -0,0 +1,99 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.forApiGateway = void 0;
7
+ const core_1 = __importDefault(require("@middy/core"));
8
+ const http_cors_1 = __importDefault(require("@middy/http-cors"));
9
+ const http_response_serializer_1 = __importDefault(require("@middy/http-response-serializer"));
10
+ const http_security_headers_1 = __importDefault(require("@middy/http-security-headers"));
11
+ const genConstraintErrorMiddleware_1 = require("../middleware/genConstraintErrorMiddleware");
12
+ const genInternalServiceErrorMiddleware_1 = require("../middleware/genInternalServiceErrorMiddleware");
13
+ const genIoLoggerMiddleware_1 = require("../middleware/genIoLoggerMiddleware");
14
+ const genTrailMiddleware_1 = require("../middleware/genTrailMiddleware");
15
+ const getValidatedOutput_1 = require("../middleware/getValidatedOutput");
16
+ const genApiGatewayEventNormalizationMiddleware_1 = require("./middleware/genApiGatewayEventNormalizationMiddleware");
17
+ const genZodBodyValidationMiddleware_1 = require("./middleware/genZodBodyValidationMiddleware");
18
+ /**
19
+ * .what = converts cors config to @middy/http-cors format
20
+ * .why = simple-lambda-handlers pattern for cors configuration
21
+ */
22
+ const corsInputToCorsConfig = (cors) => {
23
+ return {
24
+ origin: cors.origins === '*' ? '*' : undefined,
25
+ origins: Array.isArray(cors.origins) ? cors.origins : undefined,
26
+ credentials: cors.credentials,
27
+ headers: cors.headers ?? 'content-type,authorization',
28
+ maxAge: undefined,
29
+ cacheControl: undefined,
30
+ };
31
+ };
32
+ const serializers = [
33
+ {
34
+ regex: /^application\/json$/,
35
+ serializer: ({ body }) => JSON.stringify(body),
36
+ },
37
+ ];
38
+ /**
39
+ * .what = generates API Gateway lambda handler with HTTP features
40
+ * .why = adds CORS, security headers, error handler, body serialization, and validation
41
+ *
42
+ * follows simple-lambda-handlers createApiGatewayHandler pattern:
43
+ * - uses middy middleware chain
44
+ * - uses @middy/http-cors for dynamic origin match
45
+ * - uses @middy/http-security-headers for OWASP security headers
46
+ * - uses @middy/http-json-body-parser for JSON body parse
47
+ * - uses @middy/http-response-serializer for response serialization
48
+ */
49
+ const forApiGateway = (config) => {
50
+ const deserialize = config.deserialize ?? { body: true };
51
+ // build logic wrapper that validates output and invokes user handler
52
+ const logic = async (event, context) => {
53
+ // get log from context (injected by trail middleware)
54
+ const log = context.log;
55
+ // invoke user handler with validated body and raw event
56
+ const response = await config.invoke({ event: event.body, rawEvent: event }, { log });
57
+ // validate output and return typed result
58
+ const validatedOutput = (0, getValidatedOutput_1.getValidatedOutput)({
59
+ response,
60
+ schema: config.schema.output,
61
+ });
62
+ return {
63
+ statusCode: 200,
64
+ body: validatedOutput,
65
+ };
66
+ };
67
+ // middleware order matters:
68
+ // 1. error handlers (onError) - must be first to catch errors from all other middleware
69
+ // 2. io logger - logs input/output for debug
70
+ // 3. response serializer (onAfter) - serializes response body to JSON
71
+ // 4. cors (onAfter) - adds cors headers to response
72
+ // 5. security headers (onAfter) - adds security headers to response
73
+ // 6. event normalization (onBefore) - normalizes v1/v2 API Gateway events
74
+ // 7. trail (onBefore) - injects trail context
75
+ // 8. body validation (onBefore) - validates event.body against schema
76
+ const middlewares = [
77
+ (0, genConstraintErrorMiddleware_1.genConstraintErrorMiddleware)({ apiGateway: true }),
78
+ (0, genInternalServiceErrorMiddleware_1.genInternalServiceErrorMiddleware)({ apiGateway: true }),
79
+ (0, genIoLoggerMiddleware_1.genIoLoggerMiddleware)({ logTranslate: config.logTranslate }),
80
+ (0, http_response_serializer_1.default)({
81
+ serializers,
82
+ defaultContentType: 'application/json',
83
+ }),
84
+ ...(config.cors ? [(0, http_cors_1.default)(corsInputToCorsConfig(config.cors))] : []),
85
+ (0, http_security_headers_1.default)({
86
+ frameOptions: { action: 'DENY' },
87
+ }),
88
+ (0, genApiGatewayEventNormalizationMiddleware_1.genApiGatewayEventNormalizationMiddleware)({ parseBody: deserialize.body }),
89
+ (0, genTrailMiddleware_1.genTrailMiddleware)(),
90
+ (0, genZodBodyValidationMiddleware_1.genZodBodyValidationMiddleware)({ schema: config.schema.input }),
91
+ ];
92
+ // note: type assertion needed because middleware transforms:
93
+ // - input: APIGatewayProxyEvent -> UnifiedApiGatewayEvent (before logic)
94
+ // - output: { statusCode, body } -> APIGatewayProxyResult (after logic)
95
+ // TypeScript can't track these transformations through the middleware chain
96
+ return (0, core_1.default)(logic).use(middlewares);
97
+ };
98
+ exports.forApiGateway = forApiGateway;
99
+ //# sourceMappingURL=genLambdaEndpoint.forApiGateway.js.map
@@ -0,0 +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;AAS/D,6FAA0F;AAC1F,uGAAoG;AAEpG,+EAA4E;AAC5E,yEAAsE;AACtE,yEAAsE;AACtE,sHAGgE;AAChE,gGAA6F;AAyD7F;;;GAGG;AACH,MAAM,qB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allows ONE origin in Access-Control-Allow-Origin header
4
+ *
5
+ * .how = matches request origin against allowed list:
6
+ * - '*' returns '*' (unless credentials, then echoes request origin)
7
+ * - string[] checks if request origin in list, echoes that origin if matched
8
+ * - no match returns null (no CORS header should be set)
9
+ */
10
+ export declare const getCorsOrigin: (input: {
11
+ origins: string | string[];
12
+ requestOrigin?: string | null;
13
+ credentials?: boolean;
14
+ }) => string | null;
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getCorsOrigin = void 0;
4
+ /**
5
+ * .what = transforms CORS origins config to header value with dynamic origin match
6
+ * .why = HTTP spec only allows ONE origin in Access-Control-Allow-Origin header
7
+ *
8
+ * .how = matches request origin against allowed list:
9
+ * - '*' returns '*' (unless credentials, then echoes request origin)
10
+ * - string[] checks if request origin in list, echoes that origin if matched
11
+ * - no match returns null (no CORS header should be set)
12
+ */
13
+ const getCorsOrigin = (input) => {
14
+ const { origins, requestOrigin, credentials } = input;
15
+ // wildcard origin with credentials - browsers require the specific origin to be echoed
16
+ // ref: https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS/Errors/CORSNotSupportingCredentials
17
+ if (origins === '*' && credentials && requestOrigin)
18
+ return requestOrigin;
19
+ // wildcard origin without credentials constraint
20
+ if (origins === '*')
21
+ return '*';
22
+ // single origin string (not wildcard)
23
+ if (!Array.isArray(origins)) {
24
+ // if request origin matches, return it; otherwise return configured origin
25
+ if (requestOrigin && requestOrigin === origins) {
26
+ return origins;
27
+ }
28
+ // no request origin or no match - return configured origin anyway
29
+ // (may cause CORS failure but that's the expected behavior)
30
+ return origins;
31
+ }
32
+ // array of origins: match against request origin
33
+ if (requestOrigin && origins.includes(requestOrigin)) {
34
+ return requestOrigin;
35
+ }
36
+ // no match - don't set CORS header (return null, not empty string)
37
+ // note: if no requestOrigin provided, fall back to first origin for backwards compat
38
+ if (!requestOrigin && origins.length > 0) {
39
+ return origins[0];
40
+ }
41
+ return null;
42
+ };
43
+ exports.getCorsOrigin = getCorsOrigin;
44
+ //# sourceMappingURL=getCorsOrigin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getCorsOrigin.js","sourceRoot":"","sources":["../../../../src/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/getCorsOrigin.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;GAQG;AACI,MAAM,aAAa,GAAG,CAAC,KAI7B,EAAiB,EAAE;IAClB,MAAM,EAAE,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,GAAG,KAAK,CAAC;IAEtD,uFAAuF;IACvF,kGAAkG;IAClG,IAAI,OAAO,KAAK,GAAG,IAAI,WAAW,IAAI,aAAa;QAAE,OAAO,aAAa,CAAC;IAE1E,iDAAiD;IACjD,IAAI,OAAO,KAAK,GAAG;QAAE,OAAO,GAAG,CAAC;IAEhC,sCAAsC;IACtC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;QAC5B,2EAA2E;QAC3E,IAAI,aAAa,IAAI,aAAa,KAAK,OAAO,EAAE,CAAC;YAC/C,OAAO,OAAO,CAAC;QACjB,CAAC;QACD,kEAAkE;QAClE,4DAA4D;QAC5D,OAAO,OAAO,CAAC;IACjB,CAAC;IAED,iDAAiD;IACjD,IAAI,aAAa,IAAI,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAC,EAAE,CAAC;QACrD,OAAO,aAAa,CAAC;IACvB,CAAC;IAED,mEAAmE;IACnE,qFAAqF;IACrF,IAAI,CAAC,aAAa,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACzC,OAAO,OAAO,CAAC,CAAC,CAAE,CAAC;IACrB,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AArCW,QAAA,aAAa,iBAqCxB"}
@@ -0,0 +1,6 @@
1
+ import type { APIGatewayProxyEvent } from 'aws-lambda';
2
+ /**
3
+ * .what = type guard for API Gateway v1 (REST API) events
4
+ * .why = enables detection of event format for middleware
5
+ */
6
+ export declare const getIsV1ApiGatewayEvent: (event: unknown) => event is APIGatewayProxyEvent;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getIsV1ApiGatewayEvent = void 0;
4
+ /**
5
+ * .what = type guard for API Gateway v1 (REST API) events
6
+ * .why = enables detection of event format for middleware
7
+ */
8
+ const getIsV1ApiGatewayEvent = (event) => {
9
+ if (!event || typeof event !== 'object')
10
+ return false;
11
+ const obj = event;
12
+ // v1 events have httpMethod (v2 uses requestContext.http.method)
13
+ return typeof obj.httpMethod === 'string';
14
+ };
15
+ exports.getIsV1ApiGatewayEvent = getIsV1ApiGatewayEvent;
16
+ //# sourceMappingURL=getIsV1ApiGatewayEvent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getIsV1ApiGatewayEvent.js","sourceRoot":"","sources":["../../../../src/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/getIsV1ApiGatewayEvent.ts"],"names":[],"mappings":";;;AAEA;;;GAGG;AACI,MAAM,sBAAsB,GAAG,CACpC,KAAc,EACiB,EAAE;IACjC,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IACtD,MAAM,GAAG,GAAG,KAAgC,CAAC;IAE7C,iEAAiE;IACjE,OAAO,OAAO,GAAG,CAAC,UAAU,KAAK,QAAQ,CAAC;AAC5C,CAAC,CAAC;AARW,QAAA,sBAAsB,0BAQjC"}
@@ -0,0 +1,6 @@
1
+ import type { APIGatewayProxyEventV2 } from 'aws-lambda';
2
+ /**
3
+ * .what = type guard for API Gateway v2 (HTTP API) events
4
+ * .why = enables detection of event format for middleware
5
+ */
6
+ export declare const getIsV2ApiGatewayEvent: (event: unknown) => event is APIGatewayProxyEventV2;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getIsV2ApiGatewayEvent = void 0;
4
+ /**
5
+ * .what = type guard for API Gateway v2 (HTTP API) events
6
+ * .why = enables detection of event format for middleware
7
+ */
8
+ const getIsV2ApiGatewayEvent = (event) => {
9
+ if (!event || typeof event !== 'object')
10
+ return false;
11
+ const obj = event;
12
+ // v2 events have version field set to '2.0'
13
+ return obj.version === '2.0';
14
+ };
15
+ exports.getIsV2ApiGatewayEvent = getIsV2ApiGatewayEvent;
16
+ //# sourceMappingURL=getIsV2ApiGatewayEvent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getIsV2ApiGatewayEvent.js","sourceRoot":"","sources":["../../../../src/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/getIsV2ApiGatewayEvent.ts"],"names":[],"mappings":";;;AAEA;;;GAGG;AACI,MAAM,sBAAsB,GAAG,CACpC,KAAc,EACmB,EAAE;IACnC,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IACtD,MAAM,GAAG,GAAG,KAAgC,CAAC;IAE7C,4CAA4C;IAC5C,OAAO,GAAG,CAAC,OAAO,KAAK,KAAK,CAAC;AAC/B,CAAC,CAAC;AARW,QAAA,sBAAsB,0BAQjC"}
@@ -0,0 +1,32 @@
1
+ import type middy from '@middy/core';
2
+ import type { APIGatewayProxyEvent, APIGatewayProxyEventV2 } from 'aws-lambda';
3
+ /**
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
27
+ */
28
+ export declare const genApiGatewayEventNormalizationMiddleware: (input: {
29
+ parseBody: boolean;
30
+ }) => {
31
+ before: middy.MiddlewareFn<any, any>;
32
+ };
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.genApiGatewayEventNormalizationMiddleware = void 0;
4
+ const helpful_errors_1 = require("helpful-errors");
5
+ const getIsV1ApiGatewayEvent_1 = require("../getIsV1ApiGatewayEvent");
6
+ const getIsV2ApiGatewayEvent_1 = require("../getIsV2ApiGatewayEvent");
7
+ /**
8
+ * .what = converts v1/v2 API Gateway events to unified format
9
+ * .why = handlers work with consistent event shape regardless of API type
10
+ */
11
+ const genApiGatewayEventNormalizationMiddleware = (input) => {
12
+ const before = async (request) => {
13
+ const rawEvent = request.event;
14
+ // detect event version
15
+ if ((0, getIsV2ApiGatewayEvent_1.getIsV2ApiGatewayEvent)(rawEvent)) {
16
+ // v2 (HTTP API) event
17
+ const v2Event = rawEvent;
18
+ const body = input.parseBody
19
+ ? parseBody(v2Event.body, v2Event.isBase64Encoded)
20
+ : v2Event.body;
21
+ request.event = {
22
+ httpMethod: v2Event.requestContext.http.method,
23
+ path: v2Event.requestContext.http.path,
24
+ headers: v2Event.headers,
25
+ queryStringParameters: v2Event.queryStringParameters ?? null,
26
+ pathParameters: v2Event.pathParameters ?? null,
27
+ body,
28
+ rawBody: v2Event.body ?? null,
29
+ isBase64Encoded: v2Event.isBase64Encoded,
30
+ requestContext: {
31
+ requestId: v2Event.requestContext.requestId,
32
+ stage: v2Event.requestContext.stage,
33
+ domainName: v2Event.requestContext.domainName,
34
+ accountId: v2Event.requestContext.accountId,
35
+ },
36
+ rawEvent,
37
+ };
38
+ return;
39
+ }
40
+ if ((0, getIsV1ApiGatewayEvent_1.getIsV1ApiGatewayEvent)(rawEvent)) {
41
+ // v1 (REST API) event
42
+ const v1Event = rawEvent;
43
+ const body = input.parseBody
44
+ ? parseBody(v1Event.body, v1Event.isBase64Encoded)
45
+ : v1Event.body;
46
+ request.event = {
47
+ httpMethod: v1Event.httpMethod,
48
+ path: v1Event.path,
49
+ headers: v1Event.headers,
50
+ queryStringParameters: v1Event.queryStringParameters ?? null,
51
+ pathParameters: v1Event.pathParameters ?? null,
52
+ body,
53
+ rawBody: v1Event.body ?? null,
54
+ isBase64Encoded: v1Event.isBase64Encoded,
55
+ requestContext: {
56
+ requestId: v1Event.requestContext.requestId,
57
+ stage: v1Event.requestContext.stage,
58
+ domainName: v1Event.requestContext.domainName,
59
+ accountId: v1Event.requestContext.accountId,
60
+ },
61
+ rawEvent,
62
+ };
63
+ return;
64
+ }
65
+ throw new helpful_errors_1.MalfunctionError('event is neither v1 nor v2 API Gateway event', {
66
+ rawEvent,
67
+ });
68
+ };
69
+ return { before };
70
+ };
71
+ exports.genApiGatewayEventNormalizationMiddleware = genApiGatewayEventNormalizationMiddleware;
72
+ /**
73
+ * .what = parses JSON body string to object
74
+ * .why = API Gateway sends body as string, handlers need object
75
+ */
76
+ const parseBody = (body, isBase64Encoded) => {
77
+ if (!body)
78
+ return null;
79
+ const decoded = isBase64Encoded
80
+ ? Buffer.from(body, 'base64').toString('utf-8')
81
+ : body;
82
+ try {
83
+ return JSON.parse(decoded);
84
+ }
85
+ catch {
86
+ // return raw string if not valid JSON
87
+ return decoded;
88
+ }
89
+ };
90
+ //# sourceMappingURL=genApiGatewayEventNormalizationMiddleware.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"genApiGatewayEventNormalizationMiddleware.js","sourceRoot":"","sources":["../../../../../src/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/middleware/genApiGatewayEventNormalizationMiddleware.ts"],"names":[],"mappings":";;;AAEA,mDAAkD;AAElD,sEAAmE;AACnE,sEAAmE;AAwBnE;;;GAGG;AACI,MAAM,yCAAyC,GAAG,CA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IAAI,CAAC;QACH,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IAC7B,CAAC;IAAC,MAAM,CAAC;QACP,sCAAsC;QACtC,OAAO,OAAO,CAAC;IACjB,CAAC;AACH,CAAC,CAAC"}
@@ -0,0 +1,11 @@
1
+ import type middy from '@middy/core';
2
+ import type { ZodSchema } from 'zod';
3
+ /**
4
+ * .what = validates event.body against zod schema for API Gateway
5
+ * .why = API Gateway events have body as separate property, validate just the body
6
+ */
7
+ export declare const genZodBodyValidationMiddleware: <TInput>(input: {
8
+ schema: ZodSchema<TInput>;
9
+ }) => {
10
+ before: middy.MiddlewareFn<any, any>;
11
+ };
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.genZodBodyValidationMiddleware = void 0;
4
+ const getValidationError_1 = require("../../middleware/getValidationError");
5
+ /**
6
+ * .what = validates event.body against zod schema for API Gateway
7
+ * .why = API Gateway events have body as separate property, validate just the body
8
+ */
9
+ const genZodBodyValidationMiddleware = (input) => {
10
+ const before = async (request) => {
11
+ const event = request.event;
12
+ const result = input.schema.safeParse(event.body);
13
+ if (!result.success) {
14
+ throw (0, getValidationError_1.getValidationError)({ error: result.error });
15
+ }
16
+ // replace body with parsed (transformed) result
17
+ event.body = result.data;
18
+ };
19
+ return { before };
20
+ };
21
+ exports.genZodBodyValidationMiddleware = genZodBodyValidationMiddleware;
22
+ //# sourceMappingURL=genZodBodyValidationMiddleware.js.map
@@ -0,0 +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"}
@@ -0,0 +1,80 @@
1
+ import middy from '@middy/core';
2
+ import type { Context } from 'aws-lambda';
3
+ import type { ContextLogTrail, LogMethods } from 'sdk-logs';
4
+ import type { ZodSchema } from 'zod';
5
+ import type { IoLogTranslate } from '../middleware/genIoLoggerMiddleware';
6
+ /**
7
+ * .what = wrapped payload format: event nested under `event` key with trail
8
+ * .why = askLambdaEndpoint sends this format for trail propagation
9
+ */
10
+ export type WrappedPayload<TInput> = {
11
+ event: TInput;
12
+ trail: {
13
+ exid?: string;
14
+ };
15
+ };
16
+ /**
17
+ * .what = flat payload format: trail mixed into input
18
+ * .why = direct invocation or legacy callers may send this format
19
+ */
20
+ export type FlatPayload<TInput> = TInput & {
21
+ trail?: {
22
+ exid?: string;
23
+ } | null;
24
+ };
25
+ /**
26
+ * .what = union of all valid lambda handler input formats
27
+ * .why = handler accepts both wrapped and flat formats at runtime
28
+ */
29
+ export type LambdaHandlerInput<TInput> = FlatPayload<TInput> | WrappedPayload<TInput>;
30
+ /**
31
+ * .what = endpoint operation signature type
32
+ * .why = named type for invoke function (replaces HandlerLogic from simple-lambda-handlers)
33
+ */
34
+ export type EndpointOperation<TInput, TOutput> = (input: {
35
+ event: TInput;
36
+ }, context: ContextLogTrail) => Promise<TOutput>;
37
+ /**
38
+ * .what = sdk contract type for genLambdaEndpoint input
39
+ * .why = exported for consumer type inference
40
+ */
41
+ export type GenLambdaEndpointInput<TInput, TOutput> = {
42
+ schema: {
43
+ input: ZodSchema<TInput>;
44
+ output: ZodSchema<TOutput>;
45
+ };
46
+ invoke: EndpointOperation<TInput, TOutput>;
47
+ logTranslate?: IoLogTranslate;
48
+ };
49
+ /**
50
+ * .what = sdk contract type for genLambdaEndpoint context
51
+ * .why = exported for consumer type inference
52
+ */
53
+ export type GenLambdaEndpointContext = {
54
+ log?: LogMethods;
55
+ };
56
+ /**
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
70
+ */
71
+ export declare const genLambdaEndpoint: <TInput, TOutput>(config: {
72
+ schema: {
73
+ input: ZodSchema<TInput>;
74
+ output: ZodSchema<TOutput>;
75
+ };
76
+ invoke: EndpointOperation<TInput, TOutput>;
77
+ logTranslate?: IoLogTranslate;
78
+ }, _genContext?: {
79
+ log?: LogMethods;
80
+ }) => middy.MiddyfiedHandler<LambdaHandlerInput<TInput>, TOutput, Error, Context>;
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.genLambdaEndpoint = void 0;
7
+ const core_1 = __importDefault(require("@middy/core"));
8
+ const genConstraintErrorMiddleware_1 = require("../middleware/genConstraintErrorMiddleware");
9
+ const genInternalServiceErrorMiddleware_1 = require("../middleware/genInternalServiceErrorMiddleware");
10
+ const genIoLoggerMiddleware_1 = require("../middleware/genIoLoggerMiddleware");
11
+ const genTrailMiddleware_1 = require("../middleware/genTrailMiddleware");
12
+ const getValidatedOutput_1 = require("../middleware/getValidatedOutput");
13
+ const genZodEventValidationMiddleware_1 = require("./middleware/genZodEventValidationMiddleware");
14
+ /**
15
+ * .what = generates a lambda handler with validation and trail context
16
+ * .why = standardizes handler creation with schema validation and observability
17
+ *
18
+ * follows simple-lambda-handlers createStandardHandler pattern:
19
+ * - uses middy middleware chain
20
+ * - badRequestError middleware returns error object instead of throw
21
+ * - internalServiceError middleware logs errors loudly
22
+ * - ioLogger middleware logs input/output for debug
23
+ * - validation middleware validates input against schema
24
+ *
25
+ * additions for sdk-aws-lambda:
26
+ * - trail middleware injects log with trail context
27
+ * - output validation via zod schema
28
+ */
29
+ const genLambdaEndpoint = (config, _genContext) => {
30
+ // build logic that invokes user handler and validates output
31
+ const logic = async (event, context) => {
32
+ // get log from context (injected by trail middleware)
33
+ const log = context.log;
34
+ // invoke user handler
35
+ const response = await config.invoke({ event }, { log });
36
+ // validate output and return typed result
37
+ return (0, getValidatedOutput_1.getValidatedOutput)({ response, schema: config.schema.output });
38
+ };
39
+ // middleware order matters:
40
+ // 1. error handlers (onError) - must be first to catch errors from all other middleware
41
+ // 2. io logger - logs input/output for debug
42
+ // 3. trail (onBefore) - injects trail context
43
+ // 4. validation (onBefore) - validates event against schema
44
+ const middlewares = [
45
+ (0, genConstraintErrorMiddleware_1.genConstraintErrorMiddleware)(),
46
+ (0, genInternalServiceErrorMiddleware_1.genInternalServiceErrorMiddleware)(),
47
+ (0, genIoLoggerMiddleware_1.genIoLoggerMiddleware)({ logTranslate: config.logTranslate }),
48
+ (0, genTrailMiddleware_1.genTrailMiddleware)(),
49
+ (0, genZodEventValidationMiddleware_1.genZodEventValidationMiddleware)({ schema: config.schema.input }),
50
+ ];
51
+ /**
52
+ * .as = assertion needed because middleware transforms LambdaHandlerInput<TInput> to TInput
53
+ * before logic runs, but typescript cannot track this transformation through middy
54
+ * .removal = if middy gains typed middleware inference, remove cast
55
+ */
56
+ return (0, core_1.default)(logic).use(middlewares);
57
+ };
58
+ exports.genLambdaEndpoint = genLambdaEndpoint;
59
+ //# sourceMappingURL=genLambdaEndpoint.forAskEndpoint.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"genLambdaEndpoint.forAskEndpoint.js","sourceRoot":"","sources":["../../../../src/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forAskEndpoint/genLambdaEndpoint.forAskEndpoint.ts"],"names":[],"mappings":";;;;;;AAAA,uDAAgC;AAKhC,6FAA0F;AAC1F,uGAAoG;AAEpG,+EAA4E;AAC5E,yEAAsE;AACtE,yEAAsE;AACtE,kGAA+F;AAqD/F;;;;;;;;;;;;;;GAcG;AACI,MAAM,iBAAiB,GAAG,CAC/B,MAOC,EACD,WAAkC,EAMlC,EAAE;IACF,6DAA6D;IAC7D,MAAM,KAAK,GAAG,KAAK,EAAE,KAAa,EAAE,OAAgB,EAAoB,EAAE;QACxE,sDAAsD;QACtD,MAAM,GAAG,GAAI,OAAsC,CAAC,GAAG,CAAC;QAExD,sBAAsB;QACtB,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,GAAG,EAAE,CAAC,CAAC;QAEzD,0CAA0C;QAC1C,OAAO,IAAA,uCAAkB,EAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC;IACxE,CAAC,CAAC;IAEF,4BAA4B;IAC5B,wFAAwF;IACxF,6CAA6C;IAC7C,8CAA8C;IAC9C,4DAA4D;IAC5D,MAAM,WAAW,GAAG;QAClB,IAAA,2DAA4B,GAAE;QAC9B,IAAA,qEAAiC,GAAE;QACnC,IAAA,6CAAqB,EAAC,EAAE,YAAY,EAAE,MAAM,CAAC,YAAY,EAAE,CAAC;QAC5D,IAAA,uCAAkB,GAAE;QACpB,IAAA,iEAA+B,EAAC,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;KACjE,CAAC;IAEF;;;;OAIG;IACH,OAAO,IAAA,cAAK,EACV,KAGqB,CACtB,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;AACrB,CAAC,CAAC;AApDW,QAAA,iBAAiB,qBAoD5B"}
@@ -0,0 +1,11 @@
1
+ import type middy from '@middy/core';
2
+ import type { ZodSchema } from 'zod';
3
+ /**
4
+ * .what = validates entire event against zod schema
5
+ * .why = askLambdaEndpoint sends unwrapped payload, validate full event
6
+ */
7
+ export declare const genZodEventValidationMiddleware: <TInput>(input: {
8
+ schema: ZodSchema<TInput>;
9
+ }) => {
10
+ before: middy.MiddlewareFn<any, any>;
11
+ };
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.genZodEventValidationMiddleware = void 0;
4
+ const getValidationError_1 = require("../../middleware/getValidationError");
5
+ /**
6
+ * .what = validates entire event against zod schema
7
+ * .why = askLambdaEndpoint sends unwrapped payload, validate full event
8
+ */
9
+ const genZodEventValidationMiddleware = (input) => {
10
+ const before = async (request) => {
11
+ const result = input.schema.safeParse(request.event);
12
+ if (!result.success) {
13
+ throw (0, getValidationError_1.getValidationError)({ error: result.error });
14
+ }
15
+ // replace event with parsed (transformed) result
16
+ request.event = result.data;
17
+ };
18
+ return { before };
19
+ };
20
+ exports.genZodEventValidationMiddleware = genZodEventValidationMiddleware;
21
+ //# sourceMappingURL=genZodEventValidationMiddleware.js.map
@@ -0,0 +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"}
@@ -0,0 +1,23 @@
1
+ import type middy from '@middy/core';
2
+ export interface ApiGatewayResponse {
3
+ statusCode: number;
4
+ body: string;
5
+ headers?: Record<string, string>;
6
+ }
7
+ /**
8
+ * .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)
12
+ *
13
+ * note: InternalServiceError is handled by genInternalServiceErrorMiddleware
14
+ *
15
+ * backwards compat: ancient callers (no { event, trail } wrapper) receive
16
+ * flat errorType/errorMessage format
17
+ * contemp callers receive nested { error: { _serde, class, message } }
18
+ */
19
+ export declare const genConstraintErrorMiddleware: (opts?: {
20
+ apiGateway?: boolean;
21
+ }) => {
22
+ onError: middy.MiddlewareFn<any, any>;
23
+ };