sdk-aws-lambda 0.7.1 → 0.7.3

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 (153) hide show
  1. package/dist/domain.objects/TrailCarrier.d.ts +17 -0
  2. package/dist/domain.objects/TrailCarrier.js +3 -0
  3. package/dist/domain.objects/TrailCarrier.js.map +1 -0
  4. package/dist/domain.objects/TrailExidHeader.d.ts +10 -0
  5. package/dist/domain.objects/TrailExidHeader.js +14 -0
  6. package/dist/domain.objects/TrailExidHeader.js.map +1 -0
  7. package/dist/domain.operations/asLambdaEvent/asLambdaEvent.fromApiGateway.js +15 -1
  8. package/dist/domain.operations/asLambdaEvent/asLambdaEvent.fromApiGateway.js.map +1 -1
  9. package/dist/domain.operations/askLambdaEndpoint/askLambdaEndpoint.d.ts +50 -27
  10. package/dist/domain.operations/askLambdaEndpoint/askLambdaEndpoint.js +18 -61
  11. package/dist/domain.operations/askLambdaEndpoint/askLambdaEndpoint.js.map +1 -1
  12. package/dist/domain.operations/askLambdaEndpoint/askLambdaEndpoint.viaApiGateway.d.ts +35 -0
  13. package/dist/domain.operations/askLambdaEndpoint/askLambdaEndpoint.viaApiGateway.js +80 -0
  14. package/dist/domain.operations/askLambdaEndpoint/askLambdaEndpoint.viaApiGateway.js.map +1 -0
  15. package/dist/domain.operations/askLambdaEndpoint/askLambdaEndpoint.viaInvoke.d.ts +37 -0
  16. package/dist/domain.operations/askLambdaEndpoint/askLambdaEndpoint.viaInvoke.js +70 -0
  17. package/dist/domain.operations/askLambdaEndpoint/askLambdaEndpoint.viaInvoke.js.map +1 -0
  18. package/dist/domain.operations/askLambdaEndpoint/invoke/executeHttpRequest.d.ts +17 -0
  19. package/dist/domain.operations/askLambdaEndpoint/invoke/executeHttpRequest.js +34 -0
  20. package/dist/domain.operations/askLambdaEndpoint/invoke/executeHttpRequest.js.map +1 -0
  21. package/dist/domain.operations/askLambdaEndpoint/serde/asErrorFromHttpResponse.d.ts +31 -0
  22. package/dist/domain.operations/askLambdaEndpoint/serde/asErrorFromHttpResponse.js +55 -0
  23. package/dist/domain.operations/askLambdaEndpoint/serde/asErrorFromHttpResponse.js.map +1 -0
  24. package/dist/domain.operations/askLambdaEndpoint/serde/asHeadersRecord.d.ts +13 -0
  25. package/dist/domain.operations/askLambdaEndpoint/serde/asHeadersRecord.js +22 -0
  26. package/dist/domain.operations/askLambdaEndpoint/serde/asHeadersRecord.js.map +1 -0
  27. package/dist/domain.operations/askLambdaEndpoint/serde/asHttpMethod.d.ts +16 -0
  28. package/dist/domain.operations/askLambdaEndpoint/serde/asHttpMethod.js +22 -0
  29. package/dist/domain.operations/askLambdaEndpoint/serde/asHttpMethod.js.map +1 -0
  30. package/dist/domain.operations/askLambdaEndpoint/serde/asHttpRequestBody.d.ts +17 -0
  31. package/dist/domain.operations/askLambdaEndpoint/serde/asHttpRequestBody.js +28 -0
  32. package/dist/domain.operations/askLambdaEndpoint/serde/asHttpRequestBody.js.map +1 -0
  33. package/dist/domain.operations/askLambdaEndpoint/serde/asHttpRequestHeaders.d.ts +23 -0
  34. package/dist/domain.operations/askLambdaEndpoint/serde/asHttpRequestHeaders.js +39 -0
  35. package/dist/domain.operations/askLambdaEndpoint/serde/asHttpRequestHeaders.js.map +1 -0
  36. package/dist/domain.operations/askLambdaEndpoint/serde/getOneBodyFromHttpText.d.ts +10 -0
  37. package/dist/domain.operations/askLambdaEndpoint/serde/getOneBodyFromHttpText.js +19 -0
  38. package/dist/domain.operations/askLambdaEndpoint/serde/getOneBodyFromHttpText.js.map +1 -0
  39. package/dist/domain.operations/askLambdaEndpoint/serde/getOneCorrelationIdFromBody.d.ts +11 -0
  40. package/dist/domain.operations/askLambdaEndpoint/serde/getOneCorrelationIdFromBody.js +19 -0
  41. package/dist/domain.operations/askLambdaEndpoint/serde/getOneCorrelationIdFromBody.js.map +1 -0
  42. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/asCorsHeadersWithTrail.d.ts +12 -0
  43. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/asCorsHeadersWithTrail.js +27 -0
  44. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/asCorsHeadersWithTrail.js.map +1 -0
  45. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/genLambdaEndpoint.forApiGateway.d.ts +3 -0
  46. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/genLambdaEndpoint.forApiGateway.js +32 -7
  47. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/genLambdaEndpoint.forApiGateway.js.map +1 -1
  48. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/middleware/genApiGatewayRequestEventNormalizationMiddleware.js +22 -0
  49. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/middleware/genApiGatewayRequestEventNormalizationMiddleware.js.map +1 -1
  50. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forAsk/genLambdaEndpoint.forAsk.js +13 -2
  51. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forAsk/genLambdaEndpoint.forAsk.js.map +1 -1
  52. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/asCallerFault.d.ts +14 -0
  53. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/asCallerFault.js +20 -0
  54. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/asCallerFault.js.map +1 -0
  55. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/asSqsBatchResponse.d.ts +9 -0
  56. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/asSqsBatchResponse.js +13 -0
  57. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/asSqsBatchResponse.js.map +1 -0
  58. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/asSqsRecordIds.d.ts +10 -0
  59. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/asSqsRecordIds.js +11 -0
  60. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/asSqsRecordIds.js.map +1 -0
  61. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/genLambdaEndpoint.forSqs.perBatch.d.ts +9 -3
  62. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/genLambdaEndpoint.forSqs.perBatch.js +40 -38
  63. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/genLambdaEndpoint.forSqs.perBatch.js.map +1 -1
  64. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/genLambdaEndpoint.forSqs.perRecord.d.ts +12 -6
  65. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/genLambdaEndpoint.forSqs.perRecord.js +59 -35
  66. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/genLambdaEndpoint.forSqs.perRecord.js.map +1 -1
  67. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/genSqsEndpointMiddlewares.d.ts +20 -7
  68. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/genSqsEndpointMiddlewares.js +21 -9
  69. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/genSqsEndpointMiddlewares.js.map +1 -1
  70. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/getAllSqsIdsRetried.d.ts +19 -0
  71. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/getAllSqsIdsRetried.js +22 -0
  72. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/getAllSqsIdsRetried.js.map +1 -0
  73. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/getAllSqsIdsUnclaimable.d.ts +11 -0
  74. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/getAllSqsIdsUnclaimable.js +13 -0
  75. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/getAllSqsIdsUnclaimable.js.map +1 -0
  76. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/getAllSqsSuccessRefsMalformed.d.ts +11 -0
  77. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/getAllSqsSuccessRefsMalformed.js +18 -0
  78. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/getAllSqsSuccessRefsMalformed.js.map +1 -0
  79. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/isSqsSuccessRef.d.ts +8 -0
  80. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/isSqsSuccessRef.js +14 -0
  81. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/isSqsSuccessRef.js.map +1 -0
  82. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/logSqsRecordInvalid.d.ts +15 -0
  83. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/logSqsRecordInvalid.js +22 -0
  84. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/logSqsRecordInvalid.js.map +1 -0
  85. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/logSqsRecordRefused.d.ts +27 -0
  86. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/logSqsRecordRefused.js +33 -0
  87. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/logSqsRecordRefused.js.map +1 -0
  88. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/setSqsRecordValidated.d.ts +6 -5
  89. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/setSqsRecordValidated.js +6 -5
  90. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/setSqsRecordValidated.js.map +1 -1
  91. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/setSqsRecordsValidated.d.ts +31 -0
  92. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/setSqsRecordsValidated.js +46 -0
  93. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/setSqsRecordsValidated.js.map +1 -0
  94. package/dist/domain.operations/genLambdaEndpoint/middleware/genTrailMiddleware.d.ts +15 -8
  95. package/dist/domain.operations/genLambdaEndpoint/middleware/genTrailMiddleware.js +57 -12
  96. package/dist/domain.operations/genLambdaEndpoint/middleware/genTrailMiddleware.js.map +1 -1
  97. package/dist/domain.operations/lambdaEndpointWire/frame/asHeadersWithoutKey.d.ts +11 -0
  98. package/dist/domain.operations/lambdaEndpointWire/frame/asHeadersWithoutKey.js +13 -0
  99. package/dist/domain.operations/lambdaEndpointWire/frame/asHeadersWithoutKey.js.map +1 -0
  100. package/dist/domain.operations/lambdaEndpointWire/frame/asTrailExidHeaders.d.ts +23 -0
  101. package/dist/domain.operations/lambdaEndpointWire/frame/asTrailExidHeaders.js +32 -0
  102. package/dist/domain.operations/lambdaEndpointWire/frame/asTrailExidHeaders.js.map +1 -0
  103. package/dist/domain.operations/lambdaEndpointWire/frame/getOneTrailCarrierOfEvent.d.ts +20 -0
  104. package/dist/domain.operations/lambdaEndpointWire/frame/getOneTrailCarrierOfEvent.js +23 -0
  105. package/dist/domain.operations/lambdaEndpointWire/frame/getOneTrailCarrierOfEvent.js.map +1 -0
  106. package/dist/domain.operations/lambdaEndpointWire/frame/getOneTrailCarrierOfHandler.d.ts +9 -0
  107. package/dist/domain.operations/lambdaEndpointWire/frame/getOneTrailCarrierOfHandler.js +19 -0
  108. package/dist/domain.operations/lambdaEndpointWire/frame/getOneTrailCarrierOfHandler.js.map +1 -0
  109. package/dist/domain.operations/lambdaEndpointWire/frame/getOneTrailExidFromHeaders.d.ts +16 -0
  110. package/dist/domain.operations/lambdaEndpointWire/frame/getOneTrailExidFromHeaders.js +24 -0
  111. package/dist/domain.operations/lambdaEndpointWire/frame/getOneTrailExidFromHeaders.js.map +1 -0
  112. package/dist/domain.operations/lambdaEndpointWire/frame/isEventDeclaredAsApiGateway.d.ts +9 -0
  113. package/dist/domain.operations/lambdaEndpointWire/frame/isEventDeclaredAsApiGateway.js +15 -0
  114. package/dist/domain.operations/lambdaEndpointWire/frame/isEventDeclaredAsApiGateway.js.map +1 -0
  115. package/dist/domain.operations/lambdaEndpointWire/frame/isTrailExid.d.ts +19 -0
  116. package/dist/domain.operations/lambdaEndpointWire/frame/isTrailExid.js +27 -0
  117. package/dist/domain.operations/lambdaEndpointWire/frame/isTrailExid.js.map +1 -0
  118. package/dist/domain.operations/lambdaEndpointWire/frame/isTrailExidHeaderMalformed.d.ts +11 -0
  119. package/dist/domain.operations/lambdaEndpointWire/frame/isTrailExidHeaderMalformed.js +21 -0
  120. package/dist/domain.operations/lambdaEndpointWire/frame/isTrailExidHeaderMalformed.js.map +1 -0
  121. package/dist/domain.operations/lambdaEndpointWire/frame/setEventDeclaredAsApiGateway.d.ts +21 -0
  122. package/dist/domain.operations/lambdaEndpointWire/frame/setEventDeclaredAsApiGateway.js +27 -0
  123. package/dist/domain.operations/lambdaEndpointWire/frame/setEventDeclaredAsApiGateway.js.map +1 -0
  124. package/dist/domain.operations/lambdaEndpointWire/frame/setHandlerTrailCarrier.d.ts +24 -0
  125. package/dist/domain.operations/lambdaEndpointWire/frame/setHandlerTrailCarrier.js +28 -0
  126. package/dist/domain.operations/lambdaEndpointWire/frame/setHandlerTrailCarrier.js.map +1 -0
  127. package/dist/domain.operations/runLambdaEndpoint/error/isErrorLike.d.ts +6 -1
  128. package/dist/domain.operations/runLambdaEndpoint/error/isErrorLike.js +6 -1
  129. package/dist/domain.operations/runLambdaEndpoint/error/isErrorLike.js.map +1 -1
  130. package/dist/domain.operations/runLambdaEndpoint/runLambdaEndpoint.onReferenced.d.ts +7 -0
  131. package/dist/domain.operations/runLambdaEndpoint/runLambdaEndpoint.onReferenced.js +18 -2
  132. package/dist/domain.operations/runLambdaEndpoint/runLambdaEndpoint.onReferenced.js.map +1 -1
  133. package/dist/domain.operations/runLambdaEndpoint/runLambdaEndpoint.onSerialized.js +43 -7
  134. package/dist/domain.operations/runLambdaEndpoint/runLambdaEndpoint.onSerialized.js.map +1 -1
  135. package/dist/domain.operations/runLambdaEndpoint/serde/asCarriedPayload.d.ts +35 -0
  136. package/dist/domain.operations/runLambdaEndpoint/serde/asCarriedPayload.js +81 -0
  137. package/dist/domain.operations/runLambdaEndpoint/serde/asCarriedPayload.js.map +1 -0
  138. package/dist/domain.operations/runLambdaEndpoint/serde/asErrorTypeOfErrorLike.d.ts +41 -0
  139. package/dist/domain.operations/runLambdaEndpoint/serde/asErrorTypeOfErrorLike.js +116 -0
  140. package/dist/domain.operations/runLambdaEndpoint/serde/asErrorTypeOfErrorLike.js.map +1 -0
  141. package/dist/domain.operations/runLambdaEndpoint/serde/asWireFunctionErrorPayload.js +52 -17
  142. package/dist/domain.operations/runLambdaEndpoint/serde/asWireFunctionErrorPayload.js.map +1 -1
  143. package/dist/domain.operations/runLambdaEndpoint/serde/getOneTrailWithExid.d.ts +14 -0
  144. package/dist/domain.operations/runLambdaEndpoint/serde/getOneTrailWithExid.js +18 -0
  145. package/dist/domain.operations/runLambdaEndpoint/serde/getOneTrailWithExid.js.map +1 -0
  146. package/dist/domain.operations/runLambdaEndpoint/serde/isEventWithHeaders.d.ts +17 -0
  147. package/dist/domain.operations/runLambdaEndpoint/serde/isEventWithHeaders.js +19 -0
  148. package/dist/domain.operations/runLambdaEndpoint/serde/isEventWithHeaders.js.map +1 -0
  149. package/dist/index.d.ts +8 -1
  150. package/dist/index.js +10 -2
  151. package/dist/index.js.map +1 -1
  152. package/package.json +6 -6
  153. package/readme.md +65 -4
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.asErrorFromHttpResponse = void 0;
4
+ const helpful_errors_1 = require("helpful-errors");
5
+ const HttpStatusCode_1 = require("../../../domain.objects/HttpStatusCode");
6
+ const getIsLambdaErrorResponse_1 = require("../../lambdaEndpointWire/error/getIsLambdaErrorResponse");
7
+ const asUnprefixedErrorMessage_1 = require("../../lambdaEndpointWire/serde/asUnprefixedErrorMessage");
8
+ const getOneCorrelationIdFromBody_1 = require("./getOneCorrelationIdFromBody");
9
+ const ERROR_TEXT_LENGTH_MAX = 1000;
10
+ /**
11
+ * .what = casts an http response into the error a caller should throw, or null for a success
12
+ * .why = an api gateway endpoint answers a fault as a RETURNED http response, never a lambda error
13
+ * (`invariant.badrequesterror-not-lambda-error`). the caller of `viaApiGateway` still wants
14
+ * the throw `askLambdaEndpoint` gives — one catch block, whichever road it took
15
+ *
16
+ * | status | the error | because |
17
+ * |--------|-----------|---------|
18
+ * | < 400 | none | a success. a redirect is followed by fetch by default, so a 3xx seldom arrives here |
19
+ * | 4xx | `ConstraintError` | the caller must fix the request |
20
+ * | 5xx | `MalfunctionError` | the endpoint must fix itself; its `correlationId` finds the log line |
21
+ *
22
+ * .note = the message comes from the body's contemp envelope when it has one, else from the
23
+ * status alone — a 404 from the gateway's own route match has no body this sdk wrote.
24
+ * a flat ancient body reads as the status alone: an opted-in caller is never answered in
25
+ * that shape, so no arm reads it
26
+ * .note = the raw answer text rides the error metadata, cut to a bound, so a message no arm reads
27
+ * (an old endpoint's flat body, a proxy's html page) is never lost to the caller. it is null
28
+ * where the message came from the contemp envelope, which is the text already. the
29
+ * response headers ride it too, so a deliberate refusal (a 429 and its `retry-after`) can be
30
+ * read from the thrown error
31
+ */
32
+ const asErrorFromHttpResponse = (input) => {
33
+ if (input.status < HttpStatusCode_1.HttpStatusCode.BAD_REQUEST_400)
34
+ return null;
35
+ const message = (0, getIsLambdaErrorResponse_1.getIsContempErrorResponse)(input.body)
36
+ ? (0, asUnprefixedErrorMessage_1.asUnprefixedErrorMessage)({ message: input.body.error.message })
37
+ : `the endpoint answered http ${input.status}`;
38
+ const metadata = {
39
+ url: input.url,
40
+ status: input.status,
41
+ exid: input.exid,
42
+ correlationId: (0, getOneCorrelationIdFromBody_1.getOneCorrelationIdFromBody)({ body: input.body }),
43
+ // the raw text rides only where the message did not come from it: an envelope's message is
44
+ // the text already, and a second copy would bury the fix a person reads first
45
+ text: (0, getIsLambdaErrorResponse_1.getIsContempErrorResponse)(input.body)
46
+ ? null
47
+ : input.text.slice(0, ERROR_TEXT_LENGTH_MAX),
48
+ headers: input.headers,
49
+ };
50
+ if (input.status < HttpStatusCode_1.HttpStatusCode.INTERNAL_SERVER_ERROR_500)
51
+ return new helpful_errors_1.ConstraintError(message, metadata);
52
+ return new helpful_errors_1.MalfunctionError(message, metadata);
53
+ };
54
+ exports.asErrorFromHttpResponse = asErrorFromHttpResponse;
55
+ //# sourceMappingURL=asErrorFromHttpResponse.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"asErrorFromHttpResponse.js","sourceRoot":"","sources":["../../../../src/domain.operations/askLambdaEndpoint/serde/asErrorFromHttpResponse.ts"],"names":[],"mappings":";;;AAAA,mDAAmE;AAEnE,2EAAwE;AACxE,sGAAoG;AACpG,sGAAmG;AACnG,+EAA4E;AAE5E,MAAM,qBAAqB,GAAG,IAAI,CAAC;AAEnC;;;;;;;;;;;;;;;;;;;;;GAqBG;AACI,MAAM,uBAAuB,GAAG,CAAC,KAOvC,EAA6C,EAAE;IAC9C,IAAI,KAAK,CAAC,MAAM,GAAG,+BAAc,CAAC,eAAe;QAAE,OAAO,IAAI,CAAC;IAE/D,MAAM,OAAO,GAAG,IAAA,oDAAyB,EAAC,KAAK,CAAC,IAAI,CAAC;QACnD,CAAC,CAAC,IAAA,mDAAwB,EAAC,EAAE,OAAO,EAAE,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC;QACjE,CAAC,CAAC,8BAA8B,KAAK,CAAC,MAAM,EAAE,CAAC;IAEjD,MAAM,QAAQ,GAAG;QACf,GAAG,EAAE,KAAK,CAAC,GAAG;QACd,MAAM,EAAE,KAAK,CAAC,MAAM;QACpB,IAAI,EAAE,KAAK,CAAC,IAAI;QAChB,aAAa,EAAE,IAAA,yDAA2B,EAAC,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,CAAC;QAChE,2FAA2F;QAC3F,8EAA8E;QAC9E,IAAI,EAAE,IAAA,oDAAyB,EAAC,KAAK,CAAC,IAAI,CAAC;YACzC,CAAC,CAAC,IAAI;YACN,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,qBAAqB,CAAC;QAC9C,OAAO,EAAE,KAAK,CAAC,OAAO;KACvB,CAAC;IAEF,IAAI,KAAK,CAAC,MAAM,GAAG,+BAAc,CAAC,yBAAyB;QACzD,OAAO,IAAI,gCAAe,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IAChD,OAAO,IAAI,iCAAgB,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;AACjD,CAAC,CAAC;AA9BW,QAAA,uBAAuB,2BA8BlC"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * .what = casts a fetch `Headers` into a plain record, keys lowercased by the http client
3
+ * .why = a caller reads a header by name, and a live `Headers` cannot survive a json strip, a spread,
4
+ * or a snapshot
5
+ *
6
+ * .note = DELIBERATE MUTATION — of a record made in this scope, which does not escape until whole.
7
+ * the declared `Headers` type under this tsconfig's lib has no `entries()` and is not
8
+ * iterable, so `forEach` is the only reader (`rule.require.immutable-vars` sanctions an
9
+ * unavoidable mutation that is isolated and annotated)
10
+ */
11
+ export declare const asHeadersRecord: (input: {
12
+ headers: Headers;
13
+ }) => Record<string, string>;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.asHeadersRecord = void 0;
4
+ /**
5
+ * .what = casts a fetch `Headers` into a plain record, keys lowercased by the http client
6
+ * .why = a caller reads a header by name, and a live `Headers` cannot survive a json strip, a spread,
7
+ * or a snapshot
8
+ *
9
+ * .note = DELIBERATE MUTATION — of a record made in this scope, which does not escape until whole.
10
+ * the declared `Headers` type under this tsconfig's lib has no `entries()` and is not
11
+ * iterable, so `forEach` is the only reader (`rule.require.immutable-vars` sanctions an
12
+ * unavoidable mutation that is isolated and annotated)
13
+ */
14
+ const asHeadersRecord = (input) => {
15
+ const record = {};
16
+ input.headers.forEach((value, key) => {
17
+ record[key] = value;
18
+ });
19
+ return record;
20
+ };
21
+ exports.asHeadersRecord = asHeadersRecord;
22
+ //# sourceMappingURL=asHeadersRecord.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"asHeadersRecord.js","sourceRoot":"","sources":["../../../../src/domain.operations/askLambdaEndpoint/serde/asHeadersRecord.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;GASG;AACI,MAAM,eAAe,GAAG,CAAC,KAE/B,EAA0B,EAAE;IAC3B,MAAM,MAAM,GAA2B,EAAE,CAAC;IAC1C,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE;QACnC,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;IACtB,CAAC,CAAC,CAAC;IACH,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AARW,QAAA,eAAe,mBAQ1B"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * .what = the method a request is sent under: the caller's, else the one its body implies
3
+ * .why = a request with a body and no method is a write, and fetch refuses `GET` with a body. so the
4
+ * bare call does the common work: `POST` where there is a body, `GET` where there is none
5
+ * (`rule.prefer.defaults-match-common-case`)
6
+ *
7
+ * | method | body | sent as |
8
+ * |--------|------|---------|
9
+ * | given | any | the given method, as is — a mismatch is the caller's to see |
10
+ * | absent | present | `POST` |
11
+ * | absent | absent | `GET` |
12
+ */
13
+ export declare const asHttpMethod: (input: {
14
+ method: string | undefined;
15
+ body: unknown;
16
+ }) => string;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.asHttpMethod = void 0;
4
+ /**
5
+ * .what = the method a request is sent under: the caller's, else the one its body implies
6
+ * .why = a request with a body and no method is a write, and fetch refuses `GET` with a body. so the
7
+ * bare call does the common work: `POST` where there is a body, `GET` where there is none
8
+ * (`rule.prefer.defaults-match-common-case`)
9
+ *
10
+ * | method | body | sent as |
11
+ * |--------|------|---------|
12
+ * | given | any | the given method, as is — a mismatch is the caller's to see |
13
+ * | absent | present | `POST` |
14
+ * | absent | absent | `GET` |
15
+ */
16
+ const asHttpMethod = (input) => {
17
+ if (input.method)
18
+ return input.method;
19
+ return input.body === undefined ? 'GET' : 'POST';
20
+ };
21
+ exports.asHttpMethod = asHttpMethod;
22
+ //# sourceMappingURL=asHttpMethod.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"asHttpMethod.js","sourceRoot":"","sources":["../../../../src/domain.operations/askLambdaEndpoint/serde/asHttpMethod.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;GAWG;AACI,MAAM,YAAY,GAAG,CAAC,KAG5B,EAAU,EAAE;IACX,IAAI,KAAK,CAAC,MAAM;QAAE,OAAO,KAAK,CAAC,MAAM,CAAC;IACtC,OAAO,KAAK,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC;AACnD,CAAC,CAAC;AANW,QAAA,YAAY,gBAMvB"}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * .what = casts a request body into the bytes fetch sends, and the content type that declares them
3
+ * .why = a caller hands a string or an object, as `asLambdaEvent.fromApiGateway` takes one. a string
4
+ * crosses as is; any other value is json, and says so in its content type
5
+ *
6
+ * | body | text | contentType |
7
+ * |------|------|-------------|
8
+ * | absent | absent | none |
9
+ * | string | the string | none — the caller owns its sense |
10
+ * | other | `JSON.stringify` of it | `application/json` |
11
+ */
12
+ export declare const asHttpRequestBody: (input: {
13
+ body: unknown;
14
+ }) => {
15
+ text: string | undefined;
16
+ contentType: string | null;
17
+ };
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.asHttpRequestBody = void 0;
4
+ /**
5
+ * .what = the content type a json request body is sent under
6
+ * .why = one name for the literal, so the body cast and the header that declares it cannot drift
7
+ */
8
+ const CONTENT_TYPE_JSON = 'application/json';
9
+ /**
10
+ * .what = casts a request body into the bytes fetch sends, and the content type that declares them
11
+ * .why = a caller hands a string or an object, as `asLambdaEvent.fromApiGateway` takes one. a string
12
+ * crosses as is; any other value is json, and says so in its content type
13
+ *
14
+ * | body | text | contentType |
15
+ * |------|------|-------------|
16
+ * | absent | absent | none |
17
+ * | string | the string | none — the caller owns its sense |
18
+ * | other | `JSON.stringify` of it | `application/json` |
19
+ */
20
+ const asHttpRequestBody = (input) => {
21
+ if (input.body === undefined)
22
+ return { text: undefined, contentType: null };
23
+ if (typeof input.body === 'string')
24
+ return { text: input.body, contentType: null };
25
+ return { text: JSON.stringify(input.body), contentType: CONTENT_TYPE_JSON };
26
+ };
27
+ exports.asHttpRequestBody = asHttpRequestBody;
28
+ //# sourceMappingURL=asHttpRequestBody.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"asHttpRequestBody.js","sourceRoot":"","sources":["../../../../src/domain.operations/askLambdaEndpoint/serde/asHttpRequestBody.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,MAAM,iBAAiB,GAAG,kBAAkB,CAAC;AAE7C;;;;;;;;;;GAUG;AACI,MAAM,iBAAiB,GAAG,CAAC,KAEjC,EAA4D,EAAE;IAC7D,IAAI,KAAK,CAAC,IAAI,KAAK,SAAS;QAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC;IAC5E,IAAI,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ;QAChC,OAAO,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC;IACjD,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,WAAW,EAAE,iBAAiB,EAAE,CAAC;AAC9E,CAAC,CAAC;AAPW,QAAA,iBAAiB,qBAO5B"}
@@ -0,0 +1,23 @@
1
+ /**
2
+ * .what = the headers an http request is sent with: the body's content type, the caller's, and the trail's
3
+ * .why = three sources meet and two can collide, so the order is the contract, and it reads here once
4
+ * instead of at each call site
5
+ *
6
+ * | source | wins over |
7
+ * |--------|-----------|
8
+ * | the trail's `x-trail-exid` | any caller header of that name, in any case |
9
+ * | the caller's `headers` | the content type the body implies, in any case |
10
+ * | the content type the body implies | none |
11
+ *
12
+ * .note = a caller header of the trail's name is dropped in every case, since one of that name would
13
+ * silently opt in or out of the dialect the trail declares
14
+ * .note = the implied content type yields to a caller's of any case: a bag that held `Content-Type` and
15
+ * `content-type` would be joined by the http client into one value that names two types
16
+ */
17
+ export declare const asHttpRequestHeaders: (input: {
18
+ contentType: string | null;
19
+ headers: Record<string, string> | undefined;
20
+ trail: {
21
+ exid: string;
22
+ };
23
+ }) => Record<string, string>;
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.asHttpRequestHeaders = void 0;
4
+ const TrailExidHeader_1 = require("../../../domain.objects/TrailExidHeader");
5
+ const asHeadersWithoutKey_1 = require("../../lambdaEndpointWire/frame/asHeadersWithoutKey");
6
+ const asTrailExidHeaders_1 = require("../../lambdaEndpointWire/frame/asTrailExidHeaders");
7
+ const CONTENT_TYPE_HEADER = 'content-type';
8
+ /**
9
+ * .what = the headers an http request is sent with: the body's content type, the caller's, and the trail's
10
+ * .why = three sources meet and two can collide, so the order is the contract, and it reads here once
11
+ * instead of at each call site
12
+ *
13
+ * | source | wins over |
14
+ * |--------|-----------|
15
+ * | the trail's `x-trail-exid` | any caller header of that name, in any case |
16
+ * | the caller's `headers` | the content type the body implies, in any case |
17
+ * | the content type the body implies | none |
18
+ *
19
+ * .note = a caller header of the trail's name is dropped in every case, since one of that name would
20
+ * silently opt in or out of the dialect the trail declares
21
+ * .note = the implied content type yields to a caller's of any case: a bag that held `Content-Type` and
22
+ * `content-type` would be joined by the http client into one value that names two types
23
+ */
24
+ const asHttpRequestHeaders = (input) => {
25
+ const headersOfCaller = (0, asHeadersWithoutKey_1.asHeadersWithoutKey)({
26
+ headers: input.headers,
27
+ key: TrailExidHeader_1.TRAIL_EXID_HEADER,
28
+ });
29
+ const isContentTypeGiven = Object.keys(headersOfCaller).some((name) => name.toLowerCase() === CONTENT_TYPE_HEADER);
30
+ return {
31
+ ...(input.contentType && !isContentTypeGiven
32
+ ? { [CONTENT_TYPE_HEADER]: input.contentType }
33
+ : {}),
34
+ ...headersOfCaller,
35
+ ...(0, asTrailExidHeaders_1.asTrailExidHeaders)({ trail: input.trail }),
36
+ };
37
+ };
38
+ exports.asHttpRequestHeaders = asHttpRequestHeaders;
39
+ //# sourceMappingURL=asHttpRequestHeaders.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"asHttpRequestHeaders.js","sourceRoot":"","sources":["../../../../src/domain.operations/askLambdaEndpoint/serde/asHttpRequestHeaders.ts"],"names":[],"mappings":";;;AAAA,6EAA4E;AAC5E,4FAAyF;AACzF,0FAAuF;AAEvF,MAAM,mBAAmB,GAAG,cAAc,CAAC;AAE3C;;;;;;;;;;;;;;;GAeG;AACI,MAAM,oBAAoB,GAAG,CAAC,KAIpC,EAA0B,EAAE;IAC3B,MAAM,eAAe,GAAG,IAAA,yCAAmB,EAAC;QAC1C,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,GAAG,EAAE,mCAAiB;KACvB,CAAC,CAAC;IACH,MAAM,kBAAkB,GAAG,MAAM,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC,IAAI,CAC1D,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,WAAW,EAAE,KAAK,mBAAmB,CACrD,CAAC;IACF,OAAO;QACL,GAAG,CAAC,KAAK,CAAC,WAAW,IAAI,CAAC,kBAAkB;YAC1C,CAAC,CAAC,EAAE,CAAC,mBAAmB,CAAC,EAAE,KAAK,CAAC,WAAW,EAAE;YAC9C,CAAC,CAAC,EAAE,CAAC;QACP,GAAG,eAAe;QAClB,GAAG,IAAA,uCAAkB,EAAC,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,CAAC;KAC9C,CAAC;AACJ,CAAC,CAAC;AAnBW,QAAA,oBAAoB,wBAmB/B"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * .what = reads a response body's json out of its text, or null when it holds none
3
+ * .why = an endpoint answers json, but a gateway's own 404 or 502 answers html or empty. null says
4
+ * "no json here" without a throw; the raw text travels beside it, so no data is hidden
5
+ *
6
+ * .note = null is not a swallow: the caller of `viaApiGateway` always receives the raw `text` too
7
+ */
8
+ export declare const getOneBodyFromHttpText: (input: {
9
+ text: string;
10
+ }) => unknown;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getOneBodyFromHttpText = void 0;
4
+ const getParsedJson_1 = require("../../lambdaEndpointWire/serde/getParsedJson");
5
+ /**
6
+ * .what = reads a response body's json out of its text, or null when it holds none
7
+ * .why = an endpoint answers json, but a gateway's own 404 or 502 answers html or empty. null says
8
+ * "no json here" without a throw; the raw text travels beside it, so no data is hidden
9
+ *
10
+ * .note = null is not a swallow: the caller of `viaApiGateway` always receives the raw `text` too
11
+ */
12
+ const getOneBodyFromHttpText = (input) => {
13
+ if (!input.text)
14
+ return null;
15
+ const parsed = (0, getParsedJson_1.getParsedJson)({ json: input.text });
16
+ return parsed.success ? parsed.data : null;
17
+ };
18
+ exports.getOneBodyFromHttpText = getOneBodyFromHttpText;
19
+ //# sourceMappingURL=getOneBodyFromHttpText.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getOneBodyFromHttpText.js","sourceRoot":"","sources":["../../../../src/domain.operations/askLambdaEndpoint/serde/getOneBodyFromHttpText.ts"],"names":[],"mappings":";;;AAAA,gFAA6E;AAE7E;;;;;;GAMG;AACI,MAAM,sBAAsB,GAAG,CAAC,KAAuB,EAAW,EAAE;IACzE,IAAI,CAAC,KAAK,CAAC,IAAI;QAAE,OAAO,IAAI,CAAC;IAC7B,MAAM,MAAM,GAAG,IAAA,6BAAa,EAAC,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC;IACnD,OAAO,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC;AAC7C,CAAC,CAAC;AAJW,QAAA,sBAAsB,0BAIjC"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * .what = reads the `correlationId` an endpoint's redacted 500 body holds, or null when it holds none
3
+ * .why = the 500 body is family-blind: `{ errorMessage, errorType, correlationId }`. the id is the key to
4
+ * the real error in the endpoint's logs, so the thrown `MalfunctionError` carries it
5
+ *
6
+ * .note = reads one string field off a body of unknown shape, so the shape is checked here, in one
7
+ * named place, rather than at each reader
8
+ */
9
+ export declare const getOneCorrelationIdFromBody: (input: {
10
+ body: unknown;
11
+ }) => string | null;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getOneCorrelationIdFromBody = void 0;
4
+ /**
5
+ * .what = reads the `correlationId` an endpoint's redacted 500 body holds, or null when it holds none
6
+ * .why = the 500 body is family-blind: `{ errorMessage, errorType, correlationId }`. the id is the key to
7
+ * the real error in the endpoint's logs, so the thrown `MalfunctionError` carries it
8
+ *
9
+ * .note = reads one string field off a body of unknown shape, so the shape is checked here, in one
10
+ * named place, rather than at each reader
11
+ */
12
+ const getOneCorrelationIdFromBody = (input) => {
13
+ if (typeof input.body !== 'object' || input.body === null)
14
+ return null;
15
+ const correlationId = Reflect.get(input.body, 'correlationId');
16
+ return typeof correlationId === 'string' ? correlationId : null;
17
+ };
18
+ exports.getOneCorrelationIdFromBody = getOneCorrelationIdFromBody;
19
+ //# sourceMappingURL=getOneCorrelationIdFromBody.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getOneCorrelationIdFromBody.js","sourceRoot":"","sources":["../../../../src/domain.operations/askLambdaEndpoint/serde/getOneCorrelationIdFromBody.ts"],"names":[],"mappings":";;;AAAA;;;;;;;GAOG;AACI,MAAM,2BAA2B,GAAG,CAAC,KAE3C,EAAiB,EAAE;IAClB,IAAI,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ,IAAI,KAAK,CAAC,IAAI,KAAK,IAAI;QAAE,OAAO,IAAI,CAAC;IACvE,MAAM,aAAa,GAAG,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,EAAE,eAAe,CAAC,CAAC;IAC/D,OAAO,OAAO,aAAa,KAAK,QAAQ,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC;AAClE,CAAC,CAAC;AANW,QAAA,2BAA2B,+BAMtC"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * .what = appends the trail header to a comma-separated list of allowed cors request headers
3
+ * .why = a browser that sends `x-trail-exid` preflights it, and a preflight that does not list it
4
+ * blocks the real request. the sdk expects the header on every endpoint
5
+ * (`domain.terms/x-trail-exid.md`)
6
+ *
7
+ * .note = http header names are case-insensitive (rfc 9110 §5.1), so an author's `X-Trail-Exid` is
8
+ * already listed and is not appended again
9
+ */
10
+ export declare const asCorsHeadersWithTrail: (input: {
11
+ headers: string;
12
+ }) => string;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.asCorsHeadersWithTrail = void 0;
4
+ const TrailExidHeader_1 = require("../../../domain.objects/TrailExidHeader");
5
+ /**
6
+ * .what = appends the trail header to a comma-separated list of allowed cors request headers
7
+ * .why = a browser that sends `x-trail-exid` preflights it, and a preflight that does not list it
8
+ * blocks the real request. the sdk expects the header on every endpoint
9
+ * (`domain.terms/x-trail-exid.md`)
10
+ *
11
+ * .note = http header names are case-insensitive (rfc 9110 §5.1), so an author's `X-Trail-Exid` is
12
+ * already listed and is not appended again
13
+ */
14
+ const asCorsHeadersWithTrail = (input) => {
15
+ const listed = input.headers
16
+ .split(',')
17
+ .map((header) => header.trim().toLowerCase());
18
+ if (listed.includes(TrailExidHeader_1.TRAIL_EXID_HEADER))
19
+ return input.headers;
20
+ // an empty list, or one that ends in a comma, gains the key with no stray comma
21
+ const listedBefore = input.headers.trim().replace(/,+$/, '');
22
+ return listedBefore === ''
23
+ ? TrailExidHeader_1.TRAIL_EXID_HEADER
24
+ : `${listedBefore},${TrailExidHeader_1.TRAIL_EXID_HEADER}`;
25
+ };
26
+ exports.asCorsHeadersWithTrail = asCorsHeadersWithTrail;
27
+ //# sourceMappingURL=asCorsHeadersWithTrail.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"asCorsHeadersWithTrail.js","sourceRoot":"","sources":["../../../../src/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/asCorsHeadersWithTrail.ts"],"names":[],"mappings":";;;AAAA,6EAA4E;AAE5E;;;;;;;;GAQG;AACI,MAAM,sBAAsB,GAAG,CAAC,KAA0B,EAAU,EAAE;IAC3E,MAAM,MAAM,GAAG,KAAK,CAAC,OAAO;SACzB,KAAK,CAAC,GAAG,CAAC;SACV,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC,CAAC;IAChD,IAAI,MAAM,CAAC,QAAQ,CAAC,mCAAiB,CAAC;QAAE,OAAO,KAAK,CAAC,OAAO,CAAC;IAE7D,gFAAgF;IAChF,MAAM,YAAY,GAAG,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IAC7D,OAAO,YAAY,KAAK,EAAE;QACxB,CAAC,CAAC,mCAAiB;QACnB,CAAC,CAAC,GAAG,YAAY,IAAI,mCAAiB,EAAE,CAAC;AAC7C,CAAC,CAAC;AAXW,QAAA,sBAAsB,0BAWjC"}
@@ -51,6 +51,9 @@ export interface CorsConfig {
51
51
  * .why = sets Access-Control-Allow-Headers header
52
52
  *
53
53
  * defaults to 'content-type,authorization'
54
+ *
55
+ * `x-trail-exid` is always appended, default or author-set, so a browser caller that opts into
56
+ * the contemp dialect passes its preflight
54
57
  */
55
58
  headers?: string;
56
59
  }
@@ -9,6 +9,7 @@ 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
11
  const helpful_errors_1 = require("helpful-errors");
12
+ const setHandlerTrailCarrier_1 = require("../../lambdaEndpointWire/frame/setHandlerTrailCarrier");
12
13
  const asContextLogTrail_1 = require("../asContextLogTrail");
13
14
  const genConstraintErrorMiddleware_1 = require("../middleware/genConstraintErrorMiddleware");
14
15
  const genInternalServiceErrorMiddleware_1 = require("../middleware/genInternalServiceErrorMiddleware");
@@ -20,11 +21,18 @@ const setEventFrozen_1 = require("../setEventFrozen");
20
21
  const asApiGatewayRequestEventUnified_1 = require("./asApiGatewayRequestEventUnified");
21
22
  const asApiGatewayResponseOnwire_1 = require("./asApiGatewayResponseOnwire");
22
23
  const asApiGatewayResponseOnwireJson_1 = require("./asApiGatewayResponseOnwireJson");
24
+ const asCorsHeadersWithTrail_1 = require("./asCorsHeadersWithTrail");
23
25
  const getAllResponseOnwireKeysFound_1 = require("./getAllResponseOnwireKeysFound");
24
26
  const isApiGatewayResponse_1 = require("./isApiGatewayResponse");
25
27
  const genApiGatewayRequestEventNormalizationMiddleware_1 = require("./middleware/genApiGatewayRequestEventNormalizationMiddleware");
26
28
  const genContentTypeCoherenceMiddleware_1 = require("./middleware/genContentTypeCoherenceMiddleware");
27
29
  const genZodInputValidationMiddleware_1 = require("./middleware/genZodInputValidationMiddleware");
30
+ /**
31
+ * .what = the carrier this family reads: aws builds the envelope, so the opt-in rides its `headers`
32
+ * .why = one constant feeds the trail middleware that reads it and the stamp that tells
33
+ * `runLambdaEndpoint` which carrier to write, so the two cannot disagree
34
+ */
35
+ const CARRIER_API_GATEWAY = 'headers';
28
36
  /** .what = converts this sdk's cors config into `@middy/http-cors` options */
29
37
  const corsInputToCorsConfig = (cors) => {
30
38
  return {
@@ -38,7 +46,15 @@ const corsInputToCorsConfig = (cors) => {
38
46
  */
39
47
  ...(cors.origins === '*' ? { origin: '*' } : { origins: cors.origins }),
40
48
  credentials: cors.credentials,
41
- headers: cors.headers ?? 'content-type,authorization',
49
+ /**
50
+ * .what = the allowed request headers, with the trail header always appended
51
+ * .why = a browser that sends `x-trail-exid` preflights it, and a preflight that does not
52
+ * list it blocks the real request. the sdk expects the header on every endpoint, so
53
+ * an author-set list gets it too, rather than drop it in silence
54
+ */
55
+ headers: (0, asCorsHeadersWithTrail_1.asCorsHeadersWithTrail)({
56
+ headers: cors.headers ?? 'content-type,authorization',
57
+ }),
42
58
  /**
43
59
  * .absent by choice = `disableBeforePreflightResponse: false` would turn on the vendor's
44
60
  * `OPTIONS` short-circuit — limit 1 on `CorsConfig`. blast radius, probed: one case
@@ -167,10 +183,10 @@ const forApiGateway = (config, context) => {
167
183
  * error (invariant.badrequesterror-not-lambda-error) — and the 500 body carries a
168
184
  * generic message plus the correlation id, never the error's own message
169
185
  *
170
- * .note = this family is always-ancient by construction, so the shared middleware's
171
- * `isContempCaller` branch resolves one way and needs no guard: an http payload is
172
- * an api-gateway envelope, which `getIsWrappedPayload` cannot match, and where trail
173
- * never ran `asContextTrailed` defaults the flag to `false`
186
+ * .note = the dialect follows the caller's opt-in, as in every family. a caller that sends
187
+ * `x-trail-exid` is contemp and gets the nested body; one that sends none — a
188
+ * browser, a legacy caller — is ancient and gets the flat one. where trail never
189
+ * ran, `asContextTrailed` defaults the flag to `false`
174
190
  */
175
191
  (0, genConstraintErrorMiddleware_1.genConstraintErrorMiddleware)({
176
192
  asOutputAfter: (payload) => (0, asApiGatewayResponseOnwireJson_1.asApiGatewayResponseOnwireJson)({ status: 400, payload }),
@@ -209,7 +225,13 @@ const forApiGateway = (config, context) => {
209
225
  (0, genApiGatewayRequestEventNormalizationMiddleware_1.genApiGatewayRequestEventNormalizationMiddleware)({
210
226
  parsePayload: deserialize.payload,
211
227
  }),
212
- (0, genTrailMiddleware_1.genTrailMiddleware)(),
228
+ /**
229
+ * .what = reads the caller's `x-trail-exid` from the headers entry 7 just reconciled
230
+ * .why = aws builds this envelope, so no caller can wrap it in `{ event, trail }`. the
231
+ * opt-in rides the request's own headers, which exist only AFTER normalization — so
232
+ * this stays at 8, below it (`invariant.ancient-vs-contemp-callers.md`)
233
+ */
234
+ (0, genTrailMiddleware_1.genTrailMiddleware)({ carrier: CARRIER_API_GATEWAY }),
213
235
  (0, genIntrospectionMiddleware_1.genIntrospectionMiddleware)({
214
236
  schema: config.schema,
215
237
  env: context?.env,
@@ -234,7 +256,10 @@ const forApiGateway = (config, context) => {
234
256
  * .removal = drops if middy gains typed inference across `.use`; every shape it spans is
235
257
  * already named, so only the cast is owed
236
258
  */
237
- return (0, core_1.default)(logic).use(middlewares);
259
+ return (0, setHandlerTrailCarrier_1.setHandlerTrailCarrier)({
260
+ handler: (0, core_1.default)(logic).use(middlewares),
261
+ carrier: CARRIER_API_GATEWAY,
262
+ });
238
263
  };
239
264
  exports.forApiGateway = forApiGateway;
240
265
  //# sourceMappingURL=genLambdaEndpoint.forApiGateway.js.map
@@ -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;AAE/D,mDAAkD;AASlD,4DAAyD;AACzD,6FAA0F;AAC1F,u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B,GAAE;QACpB,IAAA,uDAA0B,EAAC;YACzB,MAAM,EAAE,MAAM,CAAC,MAAM;YACrB,GAAG,EAAE,OAAO,EAAE,GAAG;YACjB;;;;;;eAMG;YACH,YAAY,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO;YACjD,aAAa,EAAE,CAAC,MAAM,EAAE,EAAE,CACxB,IAAA,+DAA8B,EAAC,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC;SACnE,CAAC;QACF,IAAA,iEAA+B,EAAC,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;KACjE,CAAC;IAEF;;;;;;;;OAQG;IACH,OAAO,IAAA,cAAK,EACV,KAGsC,CACvC,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;AACrB,CAAC,CAAC;AA5NW,QAAA,aAAa,iBA4NxB"}
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;AAUlD,kGAA+F;AAC/F,4DAAyD;AACzD,6FAA0F;AAC1F,uGAAoG;AACpG,yFAAsF;AACtF,+EAA4E;AAC5E,yEAAsE;AACtE,yEAAsE;AACtE,sDAAmD;AAOnD,uFAAwE;AACxE,6EAA0E;AAC1E,qFAAkF;AAClF,qEAAkE;AAClE,mFAAgF;AAChF,iEAA8D;AAC9D,oIAAiI;AACjI,sGAAmG;AACnG,kGAA+F;AAE/F;;;;GAIG;AACH,MAAM,mBAAmB,GAAiB,SAAS,CAAC;AA6LpD,8EAA8E;AAC9E,MAAM,qBAAqB,GAAG,CAAC,IAAgB,EAAE,EAAE;IACjD,OAAO;QACL;;;;;;;WA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AO,CAAC,KAAK,EAAE,OAAO;YACjD,aAAa,EAAE,CAAC,MAAM,EAAE,EAAE,CACxB,IAAA,+DAA8B,EAAC,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC;SACnE,CAAC;QACF,IAAA,iEAA+B,EAAC,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;KACjE,CAAC;IAEF;;;;;;;;OAQG;IACH,OAAO,IAAA,+CAAsB,EAAC;QAC5B,OAAO,EAAE,IAAA,cAAK,EACZ,KAGsC,CACvC,CAAC,GAAG,CAAC,WAAW,CAAC;QAClB,OAAO,EAAE,mBAAmB;KAC7B,CAAC,CAAC;AACL,CAAC,CAAC;AArOW,QAAA,aAAa,iBAqOxB"}
@@ -1,6 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.genApiGatewayRequestEventNormalizationMiddleware = void 0;
4
+ const helpful_errors_1 = require("helpful-errors");
5
+ const TrailExidHeader_1 = require("../../../../domain.objects/TrailExidHeader");
6
+ const getIsWrappedPayload_1 = require("../../../lambdaEndpointWire/frame/getIsWrappedPayload");
4
7
  const asApiGatewayRequestEventUnified_1 = require("../asApiGatewayRequestEventUnified");
5
8
  /**
6
9
  * .what = replaces the event with the v1/v2-reconciled shape
@@ -13,6 +16,25 @@ const asApiGatewayRequestEventUnified_1 = require("../asApiGatewayRequestEventUn
13
16
  */
14
17
  const genApiGatewayRequestEventNormalizationMiddleware = (input) => {
15
18
  const before = async (request) => {
19
+ /**
20
+ * .what = refuses a `{ event, trail }` wrapper, and names the two remedies
21
+ * .why = aws builds every event this family receives and never wraps one, so a wrapper means
22
+ * a caller framed an http event as a direct invoke — the 0.7.1 defect. the opt-in
23
+ * rides the request's `x-trail-exid` header instead (`invariant.ancient-vs-contemp-callers.md`).
24
+ * without this, the throw below says only "neither v1 nor v2" and names no fix
25
+ * .why ConstraintError = a wrapper here is a fault in the frame the caller chose, so the caller
26
+ * fixes it, and its message reaches the response, where its author looks. a public caller
27
+ * cannot send one, since aws builds the event
28
+ */
29
+ if ((0, getIsWrappedPayload_1.getIsWrappedPayload)(request.event))
30
+ helpful_errors_1.ConstraintError.throw('a { event, trail } wrapper reached an api gateway endpoint; aws never sends one', {
31
+ fix: [
32
+ `run the endpoint through runLambdaEndpoint with an event built by asLambdaEvent.fromApiGateway: it sends the opt-in as an ${TrailExidHeader_1.TRAIL_EXID_HEADER} header`,
33
+ 'a copy of that event (spread, structuredClone, json round trip) loses its declaration at the cloud locus: pass the changes to asLambdaEvent.fromApiGateway (headers, requestContext, path, ...) instead of a copy',
34
+ `for a raw event captured from aws, pass struct: { payload: 'ancient' }: it arrives as is, with any ${TrailExidHeader_1.TRAIL_EXID_HEADER} header it holds`,
35
+ 'to ask a deployed http endpoint over the network, use askLambdaEndpoint.viaApiGateway',
36
+ ],
37
+ });
16
38
  /**
17
39
  * .as = both casts exist because this middleware is typed `<any, any>`, so `request.event`
18
40
  * is `any` on the way in and its declared type on the way out. the transform is
@@ -1 +1 @@
1
- {"version":3,"file":"genApiGatewayRequestEventNormalizationMiddleware.js","sourceRoot":"","sources":["../../../../../src/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/middleware/genApiGatewayRequestEventNormalizationMiddleware.ts"],"names":[],"mappings":";;;AAGA,wFAAqF;AAErF;;;;;;;;GAQG;AACI,MAAM,gDAAgD,GAAG,CAAC,KAEhE,EAEC,EAAE;IACF,MAAM,MAAM,GAAiC,KAAK,EAAE,OAAO,EAAE,EAAE;QAC7D;;;;;;;;;WASG;QACH,OAAO,CAAC,KAAK,GAAG,IAAA,iEAA+B,EAC7C,EAAE,IAAI,EAAE,OAAO,CAAC,KAAqC,EAAE,EACvD,EAAE,WAAW,EAAE,EAAE,OAAO,EAAE,KAAK,CAAC,YAAY,EAAE,EAAE,CACd,CAAC;IACvC,CAAC,CAAC;IAEF,OAAO,EAAE,MAAM,EAAE,CAAC;AACpB,CAAC,CAAC;AAvBW,QAAA,gDAAgD,oDAuB3D"}
1
+ {"version":3,"file":"genApiGatewayRequestEventNormalizationMiddleware.js","sourceRoot":"","sources":["../../../../../src/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/middleware/genApiGatewayRequestEventNormalizationMiddleware.ts"],"names":[],"mappings":";;;AACA,mDAAiD;AAGjD,gFAA+E;AAC/E,+FAA4F;AAC5F,wFAAqF;AAErF;;;;;;;;GAQG;AACI,MAAM,gDAAgD,GAAG,CAAC,KAEhE,EAEC,EAAE;IACF,MAAM,MAAM,GAAiC,KAAK,EAAE,OAAO,EAAE,EAAE;QAC7D;;;;;;;;;WASG;QACH,IAAI,IAAA,yCAAmB,EAAC,OAAO,CAAC,KAAK,CAAC;YACpC,gCAAe,CAAC,KAAK,CACnB,iFAAiF,EACjF;gBACE,GAAG,EAAE;oBACH,6HAA6H,mCAAiB,SAAS;oBACvJ,mNAAmN;oBACnN,sGAAsG,mCAAiB,kBAAkB;oBACzI,uFAAuF;iBACxF;aACF,CACF,CAAC;QAEJ;;;;;;;;;WASG;QACH,OAAO,CAAC,KAAK,GAAG,IAAA,iEAA+B,EAC7C,EAAE,IAAI,EAAE,OAAO,CAAC,KAAqC,EAAE,EACvD,EAAE,WAAW,EAAE,EAAE,OAAO,EAAE,KAAK,CAAC,YAAY,EAAE,EAAE,CACd,CAAC;IACvC,CAAC,CAAC;IAEF,OAAO,EAAE,MAAM,EAAE,CAAC;AACpB,CAAC,CAAC;AA9CW,QAAA,gDAAgD,oDA8C3D"}
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.forAsk = void 0;
7
7
  const core_1 = __importDefault(require("@middy/core"));
8
+ const setHandlerTrailCarrier_1 = require("../../lambdaEndpointWire/frame/setHandlerTrailCarrier");
8
9
  const asContextLogTrail_1 = require("../asContextLogTrail");
9
10
  const genConstraintErrorMiddleware_1 = require("../middleware/genConstraintErrorMiddleware");
10
11
  const genInternalServiceErrorMiddleware_1 = require("../middleware/genInternalServiceErrorMiddleware");
@@ -15,6 +16,13 @@ const getValidatedOutput_1 = require("../middleware/getValidatedOutput");
15
16
  const setEventFrozen_1 = require("../setEventFrozen");
16
17
  const genAskEventOnwireCaptureMiddleware_1 = require("./middleware/genAskEventOnwireCaptureMiddleware");
17
18
  const genZodEventValidationMiddleware_1 = require("./middleware/genZodEventValidationMiddleware");
19
+ /**
20
+ * .what = the carrier this family reads: a direct invoke owns its whole payload, so the `{ event, trail }`
21
+ * wrapper stands in for a metadata bag
22
+ * .why = one constant feeds the trail middleware that reads it and the stamp that tells
23
+ * `runLambdaEndpoint` which carrier to write, so the two cannot disagree
24
+ */
25
+ const CARRIER_ASK = 'wrapper';
18
26
  /**
19
27
  * .what = generates a lambda handler with validation and trail context, for a DIRECT invoke
20
28
  * .why = standardizes handler creation with schema validation and observability. the chain:
@@ -61,7 +69,7 @@ input, context) => {
61
69
  (0, genConstraintErrorMiddleware_1.genConstraintErrorMiddleware)({ asOutputAfter: (body) => body }),
62
70
  (0, genInternalServiceErrorMiddleware_1.genInternalServiceErrorMiddleware)({ asOutputAfter: false }),
63
71
  (0, genAskEventOnwireCaptureMiddleware_1.genAskEventOnwireCaptureMiddleware)(),
64
- (0, genTrailMiddleware_1.genTrailMiddleware)(),
72
+ (0, genTrailMiddleware_1.genTrailMiddleware)({ carrier: CARRIER_ASK }),
65
73
  (0, genIoLoggerMiddleware_1.genIoLoggerMiddleware)({ logTranslate: input.logTranslate }),
66
74
  (0, genIntrospectionMiddleware_1.genIntrospectionMiddleware)({
67
75
  schema: input.schema,
@@ -78,7 +86,10 @@ input, context) => {
78
86
  * builds the envelope — but typescript cannot track that through middy
79
87
  * .removal = if middy gains typed middleware inference, remove cast
80
88
  */
81
- return (0, core_1.default)(logic).use(middlewares);
89
+ return (0, setHandlerTrailCarrier_1.setHandlerTrailCarrier)({
90
+ handler: (0, core_1.default)(logic).use(middlewares),
91
+ carrier: CARRIER_ASK,
92
+ });
82
93
  };
83
94
  exports.forAsk = forAsk;
84
95
  //# sourceMappingURL=genLambdaEndpoint.forAsk.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"genLambdaEndpoint.forAsk.js","sourceRoot":"","sources":["../../../../src/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forAsk/genLambdaEndpoint.forAsk.ts"],"names":[],"mappings":";;;;;;AAAA,uDAAgC;AAQhC,4DAAyD;AACzD,6FAA0F;AAC1F,uGAAoG;AACpG,yFAAsF;AACtF,+EAA4E;AAC5E,yEAAsE;AACtE,yEAAsE;AACtE,sDAAmD;AAEnD,wGAAqG;AACrG,kGAA+F;AAqH/F;;;;;;;;;GASG;AACI,MAAM,MAAM,GAAG;AACpB,4FAA4F;AAC5F,KAA4D,EAC5D,OAAgC,EAQhC,EAAE;IACF,6DAA6D;IAC7D,MAAM,KAAK,GAAG,KAAK,EACjB,KAA8B,EAC9B,aAAsB,EACJ,EAAE;QACpB,qFAAqF;QACrF,MAAM,EAAE,GAAG,EAAE,GAAG,IAAA,qCAAiB,EAAC,EAAE,OAAO,EAAE,aAAa,EAAE,CAAC,CAAC;QAE9D;;;;;;WAMG;QACH,MAAM,WAAW,GAAG,IAAA,+BAAc,EAAC,EAAE,KAAK,EAAE,CAAC,CAAC;QAE9C,wFAAwF;QACxF,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,MAAM,CACjC,EAAE,OAAO,EAAE,WAAW,CAAC,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,EACpD,EAAE,GAAG,EAAE,CACR,CAAC;QAEF,0CAA0C;QAC1C,OAAO,IAAA,uCAAkB,EAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC;IACvE,CAAC,CAAC;IAEF,4BAA4B;IAC5B,wFAAwF;IACxF,+EAA+E;IAC/E,2GAA2G;IAC3G,6CAA6C;IAC7C,+EAA+E;IAC/E,+FAA+F;IAC/F,MAAM,WAAW,GAAG;QAClB;;;;WAIG;QACH,IAAA,2DAA4B,EAAC,EAAE,aAAa,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,EAAE,CAAC;QAC/D,IAAA,qEAAiC,EAAC,EAAE,aAAa,EAAE,KAAK,EAAE,CAAC;QAC3D,IAAA,uEAAkC,GAAE;QACpC,IAAA,uCAAkB,GAAE;QACpB,IAAA,6CAAqB,EAAC,EAAE,YAAY,EAAE,KAAK,CAAC,YAAY,EAAE,CAAC;QAC3D,IAAA,uDAA0B,EAAC;YACzB,MAAM,EAAE,KAAK,CAAC,MAAM;YACpB,GAAG,EAAE,OAAO,EAAE,GAAG;YACjB,0FAA0F;YAC1F,YAAY,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK;YACxC,aAAa,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM;SAClC,CAAC;QACF,IAAA,iEAA+B,EAAC,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;KAChE,CAAC;IAEF;;;;;OAKG;IACH,OAAO,IAAA,cAAK,EACV,KAGqB,CACtB,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;AACrB,CAAC,CAAC;AA/EW,QAAA,MAAM,UA+EjB"}
1
+ {"version":3,"file":"genLambdaEndpoint.forAsk.js","sourceRoot":"","sources":["../../../../src/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forAsk/genLambdaEndpoint.forAsk.ts"],"names":[],"mappings":";;;;;;AAAA,uDAAgC;AAShC,kGAA+F;AAC/F,4DAAyD;AACzD,6FAA0F;AAC1F,uGAAoG;AACpG,yFAAsF;AACtF,+EAA4E;AAC5E,yEAAsE;AACtE,yEAAsE;AACtE,sDAAmD;AAEnD,wGAAqG;AACrG,kGAA+F;AAE/F;;;;;GAKG;AACH,MAAM,WAAW,GAAiB,SAAS,CAAC;AAqH5C;;;;;;;;;GASG;AAC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