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,57 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.genConstraintErrorMiddleware = void 0;
4
+ const getErrorResponseBody_1 = require("./getErrorResponseBody");
5
+ const getIsConstraintError_1 = require("./getIsConstraintError");
6
+ /**
7
+ * .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)
11
+ *
12
+ * note: InternalServiceError is handled by genInternalServiceErrorMiddleware
13
+ *
14
+ * backwards compat: ancient callers (no { event, trail } wrapper) receive
15
+ * flat errorType/errorMessage format
16
+ * contemp callers receive nested { error: { _serde, class, message } }
17
+ */
18
+ const genConstraintErrorMiddleware = (opts) => {
19
+ const onError = async (request) => {
20
+ const error = request.error;
21
+ if (!error)
22
+ return;
23
+ // only handle ConstraintError here (includes legacy BadRequestError)
24
+ // InternalServiceError is handled by genInternalServiceErrorMiddleware
25
+ const isConstraintError = (0, getIsConstraintError_1.getIsConstraintError)({ error });
26
+ if (!isConstraintError)
27
+ return;
28
+ // detect if caller is contemp (sent wrapped payload) or ancient
29
+ const context = request.context;
30
+ const isContempCaller = context.isContempCaller ?? false;
31
+ // build error response body via transformer based on caller type
32
+ const body = isContempCaller
33
+ ? (0, getErrorResponseBody_1.getErrorResponseBodyContemp)({ error, errorClass: 'ConstraintError' })
34
+ : (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;
53
+ };
54
+ return { onError };
55
+ };
56
+ exports.genConstraintErrorMiddleware = genConstraintErrorMiddleware;
57
+ //# sourceMappingURL=genConstraintErrorMiddleware.js.map
@@ -0,0 +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"}
@@ -0,0 +1,13 @@
1
+ import type middy from '@middy/core';
2
+ /**
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
8
+ */
9
+ export declare const genInternalServiceErrorMiddleware: (opts?: {
10
+ apiGateway?: boolean;
11
+ }) => {
12
+ onError: middy.MiddlewareFn<any, any>;
13
+ };
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.genInternalServiceErrorMiddleware = void 0;
4
+ const getIsConstraintError_1 = require("./getIsConstraintError");
5
+ /**
6
+ * .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
11
+ */
12
+ const genInternalServiceErrorMiddleware = (opts) => {
13
+ const onError = async (request) => {
14
+ const error = request.error;
15
+ if (!error)
16
+ return;
17
+ // check if the error was due to a bad request from the user
18
+ // if it was, do not handle here - this was not an internal service error
19
+ const isBadRequest = (0, getIsConstraintError_1.getIsConstraintError)({ error });
20
+ if (isBadRequest)
21
+ return;
22
+ // get log from context if available
23
+ const log = request.context?.log;
24
+ // log the error via context.log or fallback to console
25
+ const logError = log?.error ?? console.error;
26
+ logError('handler.error', {
27
+ errorMessage: error.message,
28
+ stackTrace: error.stack,
29
+ });
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;
52
+ };
53
+ return { onError };
54
+ };
55
+ exports.genInternalServiceErrorMiddleware = genInternalServiceErrorMiddleware;
56
+ //# sourceMappingURL=genInternalServiceErrorMiddleware.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"genInternalServiceErrorMiddleware.js","sourceRoot":"","sources":["../../../../src/domain.operations/genLambdaEndpoint/middleware/genInternalServiceErrorMiddleware.ts"],"names":[],"mappings":";;;AAEA,iEAA8D;AAE9D;;;;;;GAMG;AACI,MAAM,iCAAiC,GAAG,CAAC,IAEjD,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,4DAA4D;QAC5D,yEAAyE;QACzE,MAAM,YAAY,GAAG,IAAA,2CAAoB,EAAC,EAAE,KAAK,EAAE,CAAC,CAAC;QACrD,IAAI,YAAY;YAAE,OAAO;QAEzB,oCAAoC;QACpC,MAAM,GAAG,GACP,OAAO,CAAC,OACT,EAAE,GAAG,CAAC;QAEP,uDAAuD;QACvD,MAAM,QAAQ,GAAG,GAAG,EAAE,KAAK,IAAI,OAAO,CAAC,KAAK,CAAC;QAC7C,QAAQ,CAAC,eAAe,EAAE;YACxB,YAAY,EAAE,KAAK,CAAC,OAAO;YAC3B,UAAU,EAAE,KAAK,CAAC,KAAK;SACxB,CAAC,CAAC;QAEH,uFAAuF;QACvF,IAAI,IAAI,EAAE,UAAU,EAAE,CAAC;YACrB,2DAA2D;YAC3D,MAAM,IAAI,GAAI,OAAO,CAAC,OAAmD;gBACvE,EAAE,GAAG,EAAE,KAAK,EAAE,IAAI,CAAC;YAErB,iDAAiD;YACjD,6FAA6F;YAC7F,OAAO,CAAC,QAAQ,GAAG;gBACjB,UAAU,EAAE,GAAG;gBACf,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC;oBACnB,YAAY,EAAE,uBAAuB;oBACrC,SAAS,EAAE,sBAAsB;oBACjC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;iBACzC,CAAC;gBACF,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE;aAChD,CAAC;YAEF,4DAA4D;YAC5D,8DAA8D;YAC9D,OAAO;QACT,CAAC;QAED,kDAAkD;QAClD,MAAM,KAAK,CAAC;IACd,CAAC,CAAC;IACF,OAAO,EAAE,OAAO,EAAE,CAAC;AACrB,CAAC,CAAC;AArDW,QAAA,iCAAiC,qCAqD5C"}
@@ -0,0 +1,16 @@
1
+ import type middy from '@middy/core';
2
+ export interface IoLogTranslate {
3
+ input?: (event: unknown) => unknown;
4
+ output?: (response: unknown) => unknown;
5
+ }
6
+ /**
7
+ * .what = middleware that logs handler input and output
8
+ * .why = enables debug observability with optional redaction via logTranslate
9
+ */
10
+ export declare const genIoLoggerMiddleware: (input?: {
11
+ logTranslate?: IoLogTranslate;
12
+ }) => {
13
+ before: middy.MiddlewareFn<any, any>;
14
+ after: middy.MiddlewareFn<any, any>;
15
+ onError: middy.MiddlewareFn<any, any>;
16
+ };
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.genIoLoggerMiddleware = void 0;
4
+ /**
5
+ * .what = middleware that logs handler input and output
6
+ * .why = enables debug observability with optional redaction via logTranslate
7
+ */
8
+ const genIoLoggerMiddleware = (input) => {
9
+ const translateInput = input?.logTranslate?.input ?? ((event) => event);
10
+ const translateOutput = input?.logTranslate?.output ?? ((response) => response);
11
+ const before = async (request) => {
12
+ const log = request.context?.log;
13
+ if (log) {
14
+ log.debug('handler.input', { event: translateInput(request.event) });
15
+ }
16
+ };
17
+ const after = async (request) => {
18
+ const log = request.context?.log;
19
+ if (log) {
20
+ log.debug('handler.output', {
21
+ response: translateOutput(request.response),
22
+ });
23
+ }
24
+ };
25
+ const onError = async (request) => {
26
+ const log = request.context?.log;
27
+ if (log) {
28
+ if (request.response) {
29
+ log.debug('handler.output', {
30
+ response: translateOutput(request.response),
31
+ });
32
+ }
33
+ else if (request.error) {
34
+ log.debug('handler.output', {
35
+ errorMessage: request.error.message,
36
+ stackTrace: request.error.stack,
37
+ });
38
+ }
39
+ }
40
+ };
41
+ return { before, after, onError };
42
+ };
43
+ exports.genIoLoggerMiddleware = genIoLoggerMiddleware;
44
+ //# sourceMappingURL=genIoLoggerMiddleware.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"genIoLoggerMiddleware.js","sourceRoot":"","sources":["../../../../src/domain.operations/genLambdaEndpoint/middleware/genIoLoggerMiddleware.ts"],"names":[],"mappings":";;;AAWA;;;GAGG;AACI,MAAM,qBAAqB,GAAG,CAAC,KAErC,EAIC,EAAE;IACF,MAAM,cAAc,GAAG,KAAK,EAAE,YAAY,EAAE,KAAK,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC;IACxE,MAAM,eAAe,GACnB,KAAK,EAAE,YAAY,EAAE,MAAM,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,CAAC;IAE1D,MAAM,MAAM,GAAiC,KAAK,EAAE,OAAO,EAAE,EAAE;QAC7D,MAAM,GAAG,GAAI,OAAO,CAAC,OAAgC,EAAE,GAAG,CAAC;QAC3D,IAAI,GAAG,EAAE,CAAC;YACR,GAAG,CAAC,KAAK,CAAC,eAAe,EAAE,EAAE,KAAK,EAAE,cAAc,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QACvE,CAAC;IACH,CAAC,CAAC;IAEF,MAAM,KAAK,GAAiC,KAAK,EAAE,OAAO,EAAE,EAAE;QAC5D,MAAM,GAAG,GAAI,OAAO,CAAC,OAAgC,EAAE,GAAG,CAAC;QAC3D,IAAI,GAAG,EAAE,CAAC;YACR,GAAG,CAAC,KAAK,CAAC,gBAAgB,EAAE;gBAC1B,QAAQ,EAAE,eAAe,CAAC,OAAO,CAAC,QAAQ,CAAC;aAC5C,CAAC,CAAC;QACL,CAAC;IACH,CAAC,CAAC;IAEF,MAAM,OAAO,GAAiC,KAAK,EAAE,OAAO,EAAE,EAAE;QAC9D,MAAM,GAAG,GAAI,OAAO,CAAC,OAAgC,EAAE,GAAG,CAAC;QAC3D,IAAI,GAAG,EAAE,CAAC;YACR,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC;gBACrB,GAAG,CAAC,KAAK,CAAC,gBAAgB,EAAE;oBAC1B,QAAQ,EAAE,eAAe,CAAC,OAAO,CAAC,QAAQ,CAAC;iBAC5C,CAAC,CAAC;YACL,CAAC;iBAAM,IAAI,OAAO,CAAC,KAAK,EAAE,CAAC;gBACzB,GAAG,CAAC,KAAK,CAAC,gBAAgB,EAAE;oBAC1B,YAAY,EAAE,OAAO,CAAC,KAAK,CAAC,OAAO;oBACnC,UAAU,EAAE,OAAO,CAAC,KAAK,CAAC,KAAK;iBAChC,CAAC,CAAC;YACL,CAAC;QACH,CAAC;IACH,CAAC,CAAC;IAEF,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC;AACpC,CAAC,CAAC;AA5CW,QAAA,qBAAqB,yBA4ChC"}
@@ -0,0 +1,12 @@
1
+ import type middy from '@middy/core';
2
+ /**
3
+ * .what = middleware that extracts or generates trail context and unwraps event
4
+ * .why = enables request correlation via trail.exid across lambda invocations
5
+ *
6
+ * payload formats:
7
+ * - wrapped: { event: X, trail: { exid } } → extracts trail, unwraps to X
8
+ * - raw: X → generates trail, uses X as event
9
+ */
10
+ export declare const genTrailMiddleware: () => {
11
+ before: middy.MiddlewareFn<any, any>;
12
+ };
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.genTrailMiddleware = void 0;
4
+ const crypto_1 = require("crypto");
5
+ const sdk_logs_1 = require("sdk-logs");
6
+ const getUnwrappedEventWithExid_1 = require("./getUnwrappedEventWithExid");
7
+ /**
8
+ * .what = middleware that extracts or generates trail context and unwraps event
9
+ * .why = enables request correlation via trail.exid across lambda invocations
10
+ *
11
+ * payload formats:
12
+ * - wrapped: { event: X, trail: { exid } } → extracts trail, unwraps to X
13
+ * - raw: X → generates trail, uses X as event
14
+ */
15
+ const genTrailMiddleware = () => {
16
+ const before = async (request) => {
17
+ // detect payload format and extract trail + event
18
+ const { exidFromPayload, unwrappedEvent, isContempCaller } = (0, getUnwrappedEventWithExid_1.getUnwrappedEventWithExid)({
19
+ payload: request.event,
20
+ });
21
+ // generate exid if not provided
22
+ const exid = exidFromPayload ?? `exid:${(0, crypto_1.randomUUID)()}`;
23
+ // create trail
24
+ const trail = {
25
+ exid,
26
+ stack: [],
27
+ };
28
+ // generate log context with trail
29
+ const contextLogTrail = (0, sdk_logs_1.genContextLogTrail)({
30
+ trail,
31
+ env: null,
32
+ });
33
+ // unwrap event (if wrapped format)
34
+ request.event = unwrappedEvent;
35
+ // inject log and client version flag into context
36
+ const contextBefore = (request.context ?? {});
37
+ /**
38
+ * .as = middy types request.context as aws-lambda Context, but we extend
39
+ * it with ContextLogTrail and isContempCaller
40
+ * .removal = if middy gains typed middleware inference that tracks context extensions, remove cast
41
+ */
42
+ request.context = {
43
+ ...contextBefore,
44
+ log: contextLogTrail.log,
45
+ isContempCaller,
46
+ };
47
+ };
48
+ return { before };
49
+ };
50
+ exports.genTrailMiddleware = genTrailMiddleware;
51
+ //# sourceMappingURL=genTrailMiddleware.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"genTrailMiddleware.js","sourceRoot":"","sources":["../../../../src/domain.operations/genLambdaEndpoint/middleware/genTrailMiddleware.ts"],"names":[],"mappings":";;;AACA,mCAAoC;AACpC,uCAIkB;AAElB,2EAAwE;AAExE;;;;;;;GAOG;AACI,MAAM,kBAAkB,GAAG,GAEhC,EAAE;IACF,MAAM,MAAM,GAAiC,KAAK,EAAE,OAAO,EAAE,EAAE;QAC7D,kDAAkD;QAClD,MAAM,EAAE,eAAe,EAAE,cAAc,EAAE,eAAe,EAAE,GACxD,IAAA,qDAAyB,EAAC;YACxB,OAAO,EAAE,OAAO,CAAC,KAAK;SACvB,CAAC,CAAC;QAEL,gCAAgC;QAChC,MAAM,IAAI,GAAG,eAAe,IAAI,QAAQ,IAAA,mBAAU,GAAE,EAAE,CAAC;QAEvD,eAAe;QACf,MAAM,KAAK,GAAa;YACtB,IAAI;YACJ,KAAK,EAAE,EAAE;SACV,CAAC;QAEF,kCAAkC;QAClC,MAAM,eAAe,GAAG,IAAA,6BAAkB,EAAC;YACzC,KAAK;YACL,GAAG,EAAE,IAAI;SACV,CAAC,CAAC;QAEH,mCAAmC;QACnC,OAAO,CAAC,KAAK,GAAG,cAAc,CAAC;QAE/B,kDAAkD;QAClD,MAAM,aAAa,GAAG,CAAC,OAAO,CAAC,OAAO,IAAI,EAAE,CAG3C,CAAC;QACF;;;;WAIG;QACH,OAAO,CAAC,OAAO,GAAG;YAChB,GAAG,aAAa;YAChB,GAAG,EAAE,eAAe,CAAC,GAAG;YACxB,eAAe;SAE+B,CAAC;IACnD,CAAC,CAAC;IAEF,OAAO,EAAE,MAAM,EAAE,CAAC;AACpB,CAAC,CAAC;AA/CW,QAAA,kBAAkB,sBA+C7B"}
@@ -0,0 +1,9 @@
1
+ import type middy from '@middy/core';
2
+ import type { ZodSchema } from 'zod';
3
+ /**
4
+ * .what = middleware that validates handler output against zod schema
5
+ * .why = ensures type-safe output before response is returned
6
+ */
7
+ export declare const genZodOutputValidationMiddleware: <TOutput>(input: {
8
+ schema: ZodSchema<TOutput>;
9
+ }) => middy.MiddlewareObj<unknown, unknown>;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.genZodOutputValidationMiddleware = void 0;
4
+ const helpful_errors_1 = require("helpful-errors");
5
+ const getZodIssuesSummary_1 = require("./getZodIssuesSummary");
6
+ /**
7
+ * .what = middleware that validates handler output against zod schema
8
+ * .why = ensures type-safe output before response is returned
9
+ */
10
+ const genZodOutputValidationMiddleware = (input) => {
11
+ return {
12
+ after: async (request) => {
13
+ const result = input.schema.safeParse(request.response);
14
+ if (!result.success) {
15
+ const issues = (0, getZodIssuesSummary_1.getZodIssuesSummary)({ issues: result.error.issues });
16
+ throw new helpful_errors_1.MalfunctionError('output validation failed', {
17
+ issues,
18
+ });
19
+ }
20
+ // replace response with validated data (includes defaults, transforms)
21
+ request.response = result.data;
22
+ },
23
+ };
24
+ };
25
+ exports.genZodOutputValidationMiddleware = genZodOutputValidationMiddleware;
26
+ //# sourceMappingURL=genZodOutputValidationMiddleware.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"genZodOutputValidationMiddleware.js","sourceRoot":"","sources":["../../../../src/domain.operations/genLambdaEndpoint/middleware/genZodOutputValidationMiddleware.ts"],"names":[],"mappings":";;;AACA,mDAAkD;AAGlD,+DAA4D;AAE5D;;;GAGG;AACI,MAAM,gCAAgC,GAAG,CAAU,KAEzD,EAAyC,EAAE;IAC1C,OAAO;QACL,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE;YACvB,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,SAAS,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;YAExD,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;gBACpB,MAAM,MAAM,GAAG,IAAA,yCAAmB,EAAC,EAAE,MAAM,EAAE,MAAM,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC;gBAEpE,MAAM,IAAI,iCAAgB,CAAC,0BAA0B,EAAE;oBACrD,MAAM;iBACP,CAAC,CAAC;YACL,CAAC;YAED,uEAAuE;YACvE,OAAO,CAAC,QAAQ,GAAG,MAAM,CAAC,IAAI,CAAC;QACjC,CAAC;KACF,CAAC;AACJ,CAAC,CAAC;AAnBW,QAAA,gCAAgC,oCAmB3C"}
@@ -0,0 +1,37 @@
1
+ /**
2
+ * ancient error response body (flat, for backwards compat)
3
+ */
4
+ export interface LambdaEndpointErrorResponseBodyAncient {
5
+ errorMessage: string;
6
+ errorType: string;
7
+ causeMessage?: string;
8
+ details?: unknown;
9
+ }
10
+ /**
11
+ * contemp error response body (nested under error with explicit serde tag)
12
+ */
13
+ export interface LambdaEndpointErrorResponseBodyContemp {
14
+ error: {
15
+ _serde: 'LambdaEndpointError::contemp';
16
+ class: string;
17
+ message: string;
18
+ cause?: string;
19
+ details?: unknown;
20
+ };
21
+ }
22
+ /**
23
+ * .what = constructs ancient error response body (flat format)
24
+ * .why = backwards compat for ancient callers that expect errorType/errorMessage
25
+ */
26
+ export declare const getErrorResponseBodyAncient: (input: {
27
+ error: Error;
28
+ errorType: string;
29
+ }) => LambdaEndpointErrorResponseBodyAncient;
30
+ /**
31
+ * .what = constructs contemp error response body (nested under error)
32
+ * .why = clean error shape for contemp callers with explicit serde discriminator
33
+ */
34
+ export declare const getErrorResponseBodyContemp: (input: {
35
+ error: Error;
36
+ errorClass: string;
37
+ }) => LambdaEndpointErrorResponseBodyContemp;
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getErrorResponseBodyContemp = exports.getErrorResponseBodyAncient = void 0;
4
+ /**
5
+ * .what = extracts cause message from error if error has error cause
6
+ * .why = named transformer for clear narrative
7
+ */
8
+ const getCauseMessage = (input) => {
9
+ if (input.error.cause instanceof Error) {
10
+ return input.error.cause.message;
11
+ }
12
+ return undefined;
13
+ };
14
+ /**
15
+ * .what = extracts metadata from error if present
16
+ * .why = named transformer for clear narrative
17
+ */
18
+ const getErrorMetadata = (input) => {
19
+ if ('metadata' in input.error) {
20
+ return input.error.metadata;
21
+ }
22
+ return undefined;
23
+ };
24
+ /**
25
+ * .what = constructs ancient error response body (flat format)
26
+ * .why = backwards compat for ancient callers that expect errorType/errorMessage
27
+ */
28
+ const getErrorResponseBodyAncient = (input) => {
29
+ const causeMessage = getCauseMessage({ error: input.error });
30
+ const metadata = getErrorMetadata({ error: input.error });
31
+ return {
32
+ errorMessage: input.error.message,
33
+ errorType: input.errorType,
34
+ ...(causeMessage !== undefined ? { causeMessage } : {}),
35
+ ...(metadata !== undefined ? { details: metadata } : {}),
36
+ };
37
+ };
38
+ exports.getErrorResponseBodyAncient = getErrorResponseBodyAncient;
39
+ /**
40
+ * .what = constructs contemp error response body (nested under error)
41
+ * .why = clean error shape for contemp callers with explicit serde discriminator
42
+ */
43
+ const getErrorResponseBodyContemp = (input) => {
44
+ const cause = getCauseMessage({ error: input.error });
45
+ const details = getErrorMetadata({ error: input.error });
46
+ return {
47
+ error: {
48
+ _serde: 'LambdaEndpointError::contemp',
49
+ class: input.errorClass,
50
+ message: input.error.message,
51
+ ...(cause !== undefined ? { cause } : {}),
52
+ ...(details !== undefined ? { details } : {}),
53
+ },
54
+ };
55
+ };
56
+ exports.getErrorResponseBodyContemp = getErrorResponseBodyContemp;
57
+ //# sourceMappingURL=getErrorResponseBody.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getErrorResponseBody.js","sourceRoot":"","sources":["../../../../src/domain.operations/genLambdaEndpoint/middleware/getErrorResponseBody.ts"],"names":[],"mappings":";;;AAuBA;;;GAGG;AACH,MAAM,eAAe,GAAG,CAAC,KAAuB,EAAsB,EAAE;IACtE,IAAI,KAAK,CAAC,KAAK,CAAC,KAAK,YAAY,KAAK,EAAE,CAAC;QACvC,OAAO,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC;IACnC,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC;AAEF;;;GAGG;AACH,MAAM,gBAAgB,GAAG,CAAC,KAAuB,EAAuB,EAAE;IACxE,IAAI,UAAU,IAAI,KAAK,CAAC,KAAK,EAAE,CAAC;QAC9B,OAAQ,KAAK,CAAC,KAAgC,CAAC,QAAQ,CAAC;IAC1D,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC;AAEF;;;GAGG;AACI,MAAM,2BAA2B,GAAG,CAAC,KAG3C,EAA0C,EAAE;IAC3C,MAAM,YAAY,GAAG,eAAe,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC;IAC7D,MAAM,QAAQ,GAAG,gBAAgB,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC;IAE1D,OAAO;QACL,YAAY,EAAE,KAAK,CAAC,KAAK,CAAC,OAAO;QACjC,SAAS,EAAE,KAAK,CAAC,SAAS;QAC1B,GAAG,CAAC,YAAY,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACvD,GAAG,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KACzD,CAAC;AACJ,CAAC,CAAC;AAbW,QAAA,2BAA2B,+BAatC;AAEF;;;GAGG;AACI,MAAM,2BAA2B,GAAG,CAAC,KAG3C,EAA0C,EAAE;IAC3C,MAAM,KAAK,GAAG,eAAe,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC;IACtD,MAAM,OAAO,GAAG,gBAAgB,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC;IAEzD,OAAO;QACL,KAAK,EAAE;YACL,MAAM,EAAE,8BAA8B;YACtC,KAAK,EAAE,KAAK,CAAC,UAAU;YACvB,OAAO,EAAE,KAAK,CAAC,KAAK,CAAC,OAAO;YAC5B,GAAG,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YACzC,GAAG,CAAC,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SAC9C;KACF,CAAC;AACJ,CAAC,CAAC;AAhBW,QAAA,2BAA2B,+BAgBtC"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * .what = decides if error is a constraint error via thorough check
3
+ * .why = robust detection for cross-boundary error response
4
+ *
5
+ * .note = detects both ConstraintError and BadRequestError for backwards compat
6
+ *
7
+ * checks: instanceof, name, prototype chain
8
+ */
9
+ export declare const getIsConstraintError: (input: {
10
+ error: unknown;
11
+ }) => boolean;
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getIsConstraintError = void 0;
4
+ const helpful_errors_1 = require("helpful-errors");
5
+ /**
6
+ * .what = decides if error is a constraint error via thorough check
7
+ * .why = robust detection for cross-boundary error response
8
+ *
9
+ * .note = detects both ConstraintError and BadRequestError for backwards compat
10
+ *
11
+ * checks: instanceof, name, prototype chain
12
+ */
13
+ const getIsConstraintError = (input) => {
14
+ const error = input.error;
15
+ // not an error at all
16
+ if (!(error instanceof Error))
17
+ return false;
18
+ // direct instanceof check (ConstraintError and BadRequestError for backwards compat)
19
+ if (error instanceof helpful_errors_1.ConstraintError)
20
+ return true;
21
+ if (error instanceof helpful_errors_1.BadRequestError)
22
+ return true;
23
+ // name check (for serialized/deserialized errors)
24
+ if (error.name === 'ConstraintError')
25
+ return true;
26
+ if (error.name === 'BadRequestError')
27
+ return true;
28
+ // prototype chain check (for edge cases with multiple module instances)
29
+ if (decideHasConstraintErrorInPrototypeChain({
30
+ proto: Object.getPrototypeOf(error),
31
+ }))
32
+ return true;
33
+ return false;
34
+ };
35
+ exports.getIsConstraintError = getIsConstraintError;
36
+ /**
37
+ * .what = recursive prototype chain check for constraint errors
38
+ * .why = immutable traversal of prototype chain
39
+ *
40
+ * .note = checks for both ConstraintError and BadRequestError for backwards compat
41
+ */
42
+ const decideHasConstraintErrorInPrototypeChain = (input) => {
43
+ const proto = input.proto;
44
+ if (!proto)
45
+ return false;
46
+ if (proto.constructor?.name === 'ConstraintError')
47
+ return true;
48
+ if (proto.constructor?.name === 'BadRequestError')
49
+ return true;
50
+ return decideHasConstraintErrorInPrototypeChain({
51
+ proto: Object.getPrototypeOf(proto),
52
+ });
53
+ };
54
+ //# sourceMappingURL=getIsConstraintError.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getIsConstraintError.js","sourceRoot":"","sources":["../../../../src/domain.operations/genLambdaEndpoint/middleware/getIsConstraintError.ts"],"names":[],"mappings":";;;AAAA,mDAAkE;AAElE;;;;;;;GAOG;AACI,MAAM,oBAAoB,GAAG,CAAC,KAAyB,EAAW,EAAE;IACzE,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC;IAE1B,sBAAsB;IACtB,IAAI,CAAC,CAAC,KAAK,YAAY,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IAE5C,qFAAqF;IACrF,IAAI,KAAK,YAAY,gCAAe;QAAE,OAAO,IAAI,CAAC;IAClD,IAAI,KAAK,YAAY,gCAAe;QAAE,OAAO,IAAI,CAAC;IAElD,kDAAkD;IAClD,IAAI,KAAK,CAAC,IAAI,KAAK,iBAAiB;QAAE,OAAO,IAAI,CAAC;IAClD,IAAI,KAAK,CAAC,IAAI,KAAK,iBAAiB;QAAE,OAAO,IAAI,CAAC;IAElD,wEAAwE;IACxE,IACE,wCAAwC,CAAC;QACvC,KAAK,EAAE,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC;KACpC,CAAC;QAEF,OAAO,IAAI,CAAC;IAEd,OAAO,KAAK,CAAC;AACf,CAAC,CAAC;AAvBW,QAAA,oBAAoB,wBAuB/B;AAEF;;;;;GAKG;AACH,MAAM,wCAAwC,GAAG,CAAC,KAEjD,EAAW,EAAE;IACZ,MAAM,KAAK,GAAG,KAAK,CAAC,KAAmD,CAAC;IACxE,IAAI,CAAC,KAAK;QAAE,OAAO,KAAK,CAAC;IACzB,IAAI,KAAK,CAAC,WAAW,EAAE,IAAI,KAAK,iBAAiB;QAAE,OAAO,IAAI,CAAC;IAC/D,IAAI,KAAK,CAAC,WAAW,EAAE,IAAI,KAAK,iBAAiB;QAAE,OAAO,IAAI,CAAC;IAC/D,OAAO,wCAAwC,CAAC;QAC9C,KAAK,EAAE,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC;KACpC,CAAC,CAAC;AACL,CAAC,CAAC"}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * .what = wrapped payload format with event and trail
3
+ * .why = askLambdaEndpoint sends this format for trail propagation
4
+ */
5
+ export interface WrappedPayload<TEvent = unknown> {
6
+ event: TEvent;
7
+ trail: {
8
+ exid?: string;
9
+ };
10
+ }
11
+ /**
12
+ * .what = detects if payload is wrapped format { event, trail }
13
+ * .why = wrapped format has exactly two keys: event and trail (valid shape)
14
+ */
15
+ export declare const getIsWrappedPayload: <TEvent = unknown>(payload: unknown) => payload is WrappedPayload<TEvent>;
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getIsWrappedPayload = void 0;
4
+ /**
5
+ * .what = checks if trail has valid shape
6
+ * .why = trail must be object (not array) with optional exid string
7
+ */
8
+ const isValidTrail = (trail) => {
9
+ if (typeof trail !== 'object' || trail === null || Array.isArray(trail))
10
+ return false;
11
+ /**
12
+ * .as = cast from unknown to Record after object checks pass
13
+ * .removal = if typescript gains better type guard inference
14
+ */
15
+ const t = trail;
16
+ return !('exid' in t) || typeof t.exid === 'string';
17
+ };
18
+ /**
19
+ * .what = detects if payload is wrapped format { event, trail }
20
+ * .why = wrapped format has exactly two keys: event and trail (valid shape)
21
+ */
22
+ const getIsWrappedPayload = (payload) => {
23
+ if (typeof payload !== 'object' || payload === null)
24
+ return false;
25
+ const keys = Object.keys(payload);
26
+ if (keys.length !== 2 || !keys.includes('event') || !keys.includes('trail'))
27
+ return false;
28
+ /**
29
+ * .as = cast after verifying keys 'event' and 'trail' exist
30
+ * .removal = if typescript infers key presence from includes() checks
31
+ */
32
+ const p = payload;
33
+ return isValidTrail(p.trail);
34
+ };
35
+ exports.getIsWrappedPayload = getIsWrappedPayload;
36
+ //# sourceMappingURL=getIsWrappedPayload.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getIsWrappedPayload.js","sourceRoot":"","sources":["../../../../src/domain.operations/genLambdaEndpoint/middleware/getIsWrappedPayload.ts"],"names":[],"mappings":";;;AASA;;;GAGG;AACH,MAAM,YAAY,GAAG,CAAC,KAAc,EAA8B,EAAE;IAClE,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QACrE,OAAO,KAAK,CAAC;IACf;;;OAGG;IACH,MAAM,CAAC,GAAG,KAAgC,CAAC;IAC3C,OAAO,CAAC,CAAC,MAAM,IAAI,CAAC,CAAC,IAAI,OAAO,CAAC,CAAC,IAAI,KAAK,QAAQ,CAAC;AACtD,CAAC,CAAC;AAEF;;;GAGG;AACI,MAAM,mBAAmB,GAAG,CACjC,OAAgB,EACmB,EAAE;IACrC,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,KAAK,IAAI;QAAE,OAAO,KAAK,CAAC;IAClE,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAClC,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC;QACzE,OAAO,KAAK,CAAC;IACf;;;OAGG;IACH,MAAM,CAAC,GAAG,OAA6C,CAAC;IACxD,OAAO,YAAY,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;AAC/B,CAAC,CAAC;AAbW,QAAA,mBAAmB,uBAa9B"}
@@ -0,0 +1,13 @@
1
+ import { type WrappedPayload } from './getIsWrappedPayload';
2
+ /**
3
+ * .what = extracts exid and unwrapped event from payload, detects caller version
4
+ * .why = handlers accept wrapped (with trail) or raw (without trail) payloads
5
+ * isContempCaller enables version-appropriate error responses
6
+ */
7
+ export declare const getUnwrappedEventWithExid: <TEvent>(input: {
8
+ payload: TEvent | WrappedPayload<TEvent>;
9
+ }) => {
10
+ exidFromPayload: string | null;
11
+ unwrappedEvent: TEvent;
12
+ isContempCaller: boolean;
13
+ };
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getUnwrappedEventWithExid = void 0;
4
+ const getIsWrappedPayload_1 = require("./getIsWrappedPayload");
5
+ /**
6
+ * .what = extracts exid and unwrapped event from payload, detects caller version
7
+ * .why = handlers accept wrapped (with trail) or raw (without trail) payloads
8
+ * isContempCaller enables version-appropriate error responses
9
+ */
10
+ const getUnwrappedEventWithExid = (input) => {
11
+ if ((0, getIsWrappedPayload_1.getIsWrappedPayload)(input.payload)) {
12
+ return {
13
+ exidFromPayload: input.payload.trail?.exid ?? null,
14
+ unwrappedEvent: input.payload.event,
15
+ isContempCaller: true,
16
+ };
17
+ }
18
+ return {
19
+ exidFromPayload: null,
20
+ unwrappedEvent: input.payload,
21
+ isContempCaller: false,
22
+ };
23
+ };
24
+ exports.getUnwrappedEventWithExid = getUnwrappedEventWithExid;
25
+ //# sourceMappingURL=getUnwrappedEventWithExid.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getUnwrappedEventWithExid.js","sourceRoot":"","sources":["../../../../src/domain.operations/genLambdaEndpoint/middleware/getUnwrappedEventWithExid.ts"],"names":[],"mappings":";;;AAAA,+DAG+B;AAE/B;;;;GAIG;AACI,MAAM,yBAAyB,GAAG,CAAS,KAEjD,EAIC,EAAE;IACF,IAAI,IAAA,yCAAmB,EAAC,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC;QACvC,OAAO;YACL,eAAe,EAAE,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI,IAAI,IAAI;YAClD,cAAc,EAAE,KAAK,CAAC,OAAO,CAAC,KAAK;YACnC,eAAe,EAAE,IAAI;SACtB,CAAC;IACJ,CAAC;IACD,OAAO;QACL,eAAe,EAAE,IAAI;QACrB,cAAc,EAAE,KAAK,CAAC,OAAO;QAC7B,eAAe,EAAE,KAAK;KACvB,CAAC;AACJ,CAAC,CAAC;AAnBW,QAAA,yBAAyB,6BAmBpC"}
@@ -0,0 +1,9 @@
1
+ import type { ZodType } from 'zod';
2
+ /**
3
+ * .what = validates output against schema and returns typed result
4
+ * .why = named transformer for decode-friction-free validation in orchestrators
5
+ */
6
+ export declare const getValidatedOutput: <TOutput>(input: {
7
+ response: unknown;
8
+ schema: ZodType<TOutput>;
9
+ }) => TOutput;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getValidatedOutput = void 0;
4
+ const helpful_errors_1 = require("helpful-errors");
5
+ const getZodIssuesSummary_1 = require("./getZodIssuesSummary");
6
+ /**
7
+ * .what = validates output against schema and returns typed result
8
+ * .why = named transformer for decode-friction-free validation in orchestrators
9
+ */
10
+ const getValidatedOutput = (input) => {
11
+ const result = input.schema.safeParse(input.response);
12
+ if (!result.success) {
13
+ const issues = (0, getZodIssuesSummary_1.getZodIssuesSummary)({ issues: result.error.issues });
14
+ throw new helpful_errors_1.MalfunctionError('output validation failed', { issues });
15
+ }
16
+ return result.data;
17
+ };
18
+ exports.getValidatedOutput = getValidatedOutput;
19
+ //# sourceMappingURL=getValidatedOutput.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getValidatedOutput.js","sourceRoot":"","sources":["../../../../src/domain.operations/genLambdaEndpoint/middleware/getValidatedOutput.ts"],"names":[],"mappings":";;;AAAA,mDAAkD;AAGlD,+DAA4D;AAE5D;;;GAGG;AACI,MAAM,kBAAkB,GAAG,CAAU,KAG3C,EAAW,EAAE;IACZ,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IACtD,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;QACpB,MAAM,MAAM,GAAG,IAAA,yCAAmB,EAAC,EAAE,MAAM,EAAE,MAAM,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC;QACpE,MAAM,IAAI,iCAAgB,CAAC,0BAA0B,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC;IACrE,CAAC;IACD,OAAO,MAAM,CAAC,IAAI,CAAC;AACrB,CAAC,CAAC;AAVW,QAAA,kBAAkB,sBAU7B"}