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.
- package/dist/domain.objects/HttpStatusCode.d.ts +28 -0
- package/dist/domain.objects/HttpStatusCode.js +37 -0
- package/dist/domain.objects/HttpStatusCode.js.map +1 -0
- package/dist/domain.objects/LambdaEndpointContext.d.ts +6 -0
- package/dist/domain.objects/LambdaEndpointContext.js +3 -0
- package/dist/domain.objects/LambdaEndpointContext.js.map +1 -0
- package/dist/domain.objects/LambdaEndpointError.d.ts +51 -0
- package/dist/domain.objects/LambdaEndpointError.js +13 -0
- package/dist/domain.objects/LambdaEndpointError.js.map +1 -0
- package/dist/domain.operations/askLambdaEndpoint/askLambdaEndpoint.d.ts +54 -0
- package/dist/domain.operations/askLambdaEndpoint/askLambdaEndpoint.js +76 -0
- package/dist/domain.operations/askLambdaEndpoint/askLambdaEndpoint.js.map +1 -0
- package/dist/domain.operations/askLambdaEndpoint/cache/asCacheWithoutSet.d.ts +11 -0
- package/dist/domain.operations/askLambdaEndpoint/cache/asCacheWithoutSet.js +18 -0
- package/dist/domain.operations/askLambdaEndpoint/cache/asCacheWithoutSet.js.map +1 -0
- package/dist/domain.operations/askLambdaEndpoint/cache/asCachedExecutor.d.ts +18 -0
- package/dist/domain.operations/askLambdaEndpoint/cache/asCachedExecutor.js +31 -0
- package/dist/domain.operations/askLambdaEndpoint/cache/asCachedExecutor.js.map +1 -0
- package/dist/domain.operations/askLambdaEndpoint/cache/getAskLambdaCacheKey.d.ts +10 -0
- package/dist/domain.operations/askLambdaEndpoint/cache/getAskLambdaCacheKey.js +26 -0
- package/dist/domain.operations/askLambdaEndpoint/cache/getAskLambdaCacheKey.js.map +1 -0
- package/dist/domain.operations/askLambdaEndpoint/context/getAccessFromContext.d.ts +11 -0
- package/dist/domain.operations/askLambdaEndpoint/context/getAccessFromContext.js +21 -0
- package/dist/domain.operations/askLambdaEndpoint/context/getAccessFromContext.js.map +1 -0
- package/dist/domain.operations/askLambdaEndpoint/context/getExidFromContext.d.ts +16 -0
- package/dist/domain.operations/askLambdaEndpoint/context/getExidFromContext.js +20 -0
- package/dist/domain.operations/askLambdaEndpoint/context/getExidFromContext.js.map +1 -0
- package/dist/domain.operations/askLambdaEndpoint/context/getLogForExidExtraction.d.ts +27 -0
- package/dist/domain.operations/askLambdaEndpoint/context/getLogForExidExtraction.js +20 -0
- package/dist/domain.operations/askLambdaEndpoint/context/getLogForExidExtraction.js.map +1 -0
- package/dist/domain.operations/askLambdaEndpoint/error/getIsLambdaErrorResponse.d.ts +42 -0
- package/dist/domain.operations/askLambdaEndpoint/error/getIsLambdaErrorResponse.js +21 -0
- package/dist/domain.operations/askLambdaEndpoint/error/getIsLambdaErrorResponse.js.map +1 -0
- package/dist/domain.operations/askLambdaEndpoint/error/getLambdaErrorMetadata.d.ts +16 -0
- package/dist/domain.operations/askLambdaEndpoint/error/getLambdaErrorMetadata.js +19 -0
- package/dist/domain.operations/askLambdaEndpoint/error/getLambdaErrorMetadata.js.map +1 -0
- package/dist/domain.operations/askLambdaEndpoint/error/getStackTraceString.d.ts +7 -0
- package/dist/domain.operations/askLambdaEndpoint/error/getStackTraceString.js +16 -0
- package/dist/domain.operations/askLambdaEndpoint/error/getStackTraceString.js.map +1 -0
- package/dist/domain.operations/askLambdaEndpoint/error/getStatusCodeHint.d.ts +5 -0
- package/dist/domain.operations/askLambdaEndpoint/error/getStatusCodeHint.js +34 -0
- package/dist/domain.operations/askLambdaEndpoint/error/getStatusCodeHint.js.map +1 -0
- package/dist/domain.operations/askLambdaEndpoint/invoke/executeLambdaInvocation.d.ts +26 -0
- package/dist/domain.operations/askLambdaEndpoint/invoke/executeLambdaInvocation.js +60 -0
- package/dist/domain.operations/askLambdaEndpoint/invoke/executeLambdaInvocation.js.map +1 -0
- package/dist/domain.operations/askLambdaEndpoint/invoke/genLambdaClient.d.ts +11 -0
- package/dist/domain.operations/askLambdaEndpoint/invoke/genLambdaClient.js +17 -0
- package/dist/domain.operations/askLambdaEndpoint/invoke/genLambdaClient.js.map +1 -0
- package/dist/domain.operations/askLambdaEndpoint/invoke/sdkLambdaInvoke.d.ts +19 -0
- package/dist/domain.operations/askLambdaEndpoint/invoke/sdkLambdaInvoke.js +21 -0
- package/dist/domain.operations/askLambdaEndpoint/invoke/sdkLambdaInvoke.js.map +1 -0
- package/dist/domain.operations/askLambdaEndpoint/serde/getDecodedPayload.d.ts +7 -0
- package/dist/domain.operations/askLambdaEndpoint/serde/getDecodedPayload.js +12 -0
- package/dist/domain.operations/askLambdaEndpoint/serde/getDecodedPayload.js.map +1 -0
- package/dist/domain.operations/askLambdaEndpoint/serde/getLambdaFunctionName.d.ts +9 -0
- package/dist/domain.operations/askLambdaEndpoint/serde/getLambdaFunctionName.js +12 -0
- package/dist/domain.operations/askLambdaEndpoint/serde/getLambdaFunctionName.js.map +1 -0
- package/dist/domain.operations/askLambdaEndpoint/serde/getLambdaPayload.d.ts +15 -0
- package/dist/domain.operations/askLambdaEndpoint/serde/getLambdaPayload.js +15 -0
- package/dist/domain.operations/askLambdaEndpoint/serde/getLambdaPayload.js.map +1 -0
- package/dist/domain.operations/askLambdaEndpoint/serde/getParsedJson.d.ts +18 -0
- package/dist/domain.operations/askLambdaEndpoint/serde/getParsedJson.js +22 -0
- package/dist/domain.operations/askLambdaEndpoint/serde/getParsedJson.js.map +1 -0
- package/dist/domain.operations/askLambdaEndpoint/serde/getParsedResponse.d.ts +15 -0
- package/dist/domain.operations/askLambdaEndpoint/serde/getParsedResponse.js +99 -0
- package/dist/domain.operations/askLambdaEndpoint/serde/getParsedResponse.js.map +1 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/genLambdaEndpoint.forApiGateway.d.ts +83 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/genLambdaEndpoint.forApiGateway.js +99 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/genLambdaEndpoint.forApiGateway.js.map +1 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/getCorsOrigin.d.ts +14 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/getCorsOrigin.js +44 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/getCorsOrigin.js.map +1 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/getIsV1ApiGatewayEvent.d.ts +6 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/getIsV1ApiGatewayEvent.js +16 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/getIsV1ApiGatewayEvent.js.map +1 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/getIsV2ApiGatewayEvent.d.ts +6 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/getIsV2ApiGatewayEvent.js +16 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/getIsV2ApiGatewayEvent.js.map +1 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/middleware/genApiGatewayEventNormalizationMiddleware.d.ts +32 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/middleware/genApiGatewayEventNormalizationMiddleware.js +90 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/middleware/genApiGatewayEventNormalizationMiddleware.js.map +1 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/middleware/genZodBodyValidationMiddleware.d.ts +11 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/middleware/genZodBodyValidationMiddleware.js +22 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/middleware/genZodBodyValidationMiddleware.js.map +1 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forAskEndpoint/genLambdaEndpoint.forAskEndpoint.d.ts +80 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forAskEndpoint/genLambdaEndpoint.forAskEndpoint.js +59 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forAskEndpoint/genLambdaEndpoint.forAskEndpoint.js.map +1 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forAskEndpoint/middleware/genZodEventValidationMiddleware.d.ts +11 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forAskEndpoint/middleware/genZodEventValidationMiddleware.js +21 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forAskEndpoint/middleware/genZodEventValidationMiddleware.js.map +1 -0
- package/dist/domain.operations/genLambdaEndpoint/middleware/genConstraintErrorMiddleware.d.ts +23 -0
- package/dist/domain.operations/genLambdaEndpoint/middleware/genConstraintErrorMiddleware.js +57 -0
- package/dist/domain.operations/genLambdaEndpoint/middleware/genConstraintErrorMiddleware.js.map +1 -0
- package/dist/domain.operations/genLambdaEndpoint/middleware/genInternalServiceErrorMiddleware.d.ts +13 -0
- package/dist/domain.operations/genLambdaEndpoint/middleware/genInternalServiceErrorMiddleware.js +56 -0
- package/dist/domain.operations/genLambdaEndpoint/middleware/genInternalServiceErrorMiddleware.js.map +1 -0
- package/dist/domain.operations/genLambdaEndpoint/middleware/genIoLoggerMiddleware.d.ts +16 -0
- package/dist/domain.operations/genLambdaEndpoint/middleware/genIoLoggerMiddleware.js +44 -0
- package/dist/domain.operations/genLambdaEndpoint/middleware/genIoLoggerMiddleware.js.map +1 -0
- package/dist/domain.operations/genLambdaEndpoint/middleware/genTrailMiddleware.d.ts +12 -0
- package/dist/domain.operations/genLambdaEndpoint/middleware/genTrailMiddleware.js +51 -0
- package/dist/domain.operations/genLambdaEndpoint/middleware/genTrailMiddleware.js.map +1 -0
- package/dist/domain.operations/genLambdaEndpoint/middleware/genZodOutputValidationMiddleware.d.ts +9 -0
- package/dist/domain.operations/genLambdaEndpoint/middleware/genZodOutputValidationMiddleware.js +26 -0
- package/dist/domain.operations/genLambdaEndpoint/middleware/genZodOutputValidationMiddleware.js.map +1 -0
- package/dist/domain.operations/genLambdaEndpoint/middleware/getErrorResponseBody.d.ts +37 -0
- package/dist/domain.operations/genLambdaEndpoint/middleware/getErrorResponseBody.js +57 -0
- package/dist/domain.operations/genLambdaEndpoint/middleware/getErrorResponseBody.js.map +1 -0
- package/dist/domain.operations/genLambdaEndpoint/middleware/getIsConstraintError.d.ts +11 -0
- package/dist/domain.operations/genLambdaEndpoint/middleware/getIsConstraintError.js +54 -0
- package/dist/domain.operations/genLambdaEndpoint/middleware/getIsConstraintError.js.map +1 -0
- package/dist/domain.operations/genLambdaEndpoint/middleware/getIsWrappedPayload.d.ts +15 -0
- package/dist/domain.operations/genLambdaEndpoint/middleware/getIsWrappedPayload.js +36 -0
- package/dist/domain.operations/genLambdaEndpoint/middleware/getIsWrappedPayload.js.map +1 -0
- package/dist/domain.operations/genLambdaEndpoint/middleware/getUnwrappedEventWithExid.d.ts +13 -0
- package/dist/domain.operations/genLambdaEndpoint/middleware/getUnwrappedEventWithExid.js +25 -0
- package/dist/domain.operations/genLambdaEndpoint/middleware/getUnwrappedEventWithExid.js.map +1 -0
- package/dist/domain.operations/genLambdaEndpoint/middleware/getValidatedOutput.d.ts +9 -0
- package/dist/domain.operations/genLambdaEndpoint/middleware/getValidatedOutput.js +19 -0
- package/dist/domain.operations/genLambdaEndpoint/middleware/getValidatedOutput.js.map +1 -0
- package/dist/domain.operations/genLambdaEndpoint/middleware/getValidationError.d.ts +13 -0
- package/dist/domain.operations/genLambdaEndpoint/middleware/getValidationError.js +17 -0
- package/dist/domain.operations/genLambdaEndpoint/middleware/getValidationError.js.map +1 -0
- package/dist/domain.operations/genLambdaEndpoint/middleware/getZodIssuesSummary.d.ts +13 -0
- package/dist/domain.operations/genLambdaEndpoint/middleware/getZodIssuesSummary.js +16 -0
- package/dist/domain.operations/genLambdaEndpoint/middleware/getZodIssuesSummary.js.map +1 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.js +41 -0
- package/dist/index.js.map +1 -0
- package/license.md +21 -0
- package/package.json +115 -0
- package/readme.md +54 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { LambdaErrorResponseAncient } from './getIsLambdaErrorResponse';
|
|
2
|
+
/**
|
|
3
|
+
* .what = error metadata for lambda error responses
|
|
4
|
+
* .why = typed representation of optional error fields
|
|
5
|
+
*/
|
|
6
|
+
export interface LambdaErrorMetadata {
|
|
7
|
+
details?: unknown;
|
|
8
|
+
causeMessage?: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* .what = extracts optional metadata fields from lambda error response
|
|
12
|
+
* .why = named transformer for clear narrative in getParsedResponse
|
|
13
|
+
*/
|
|
14
|
+
export declare const getLambdaErrorMetadata: (input: {
|
|
15
|
+
errorResponse: LambdaErrorResponseAncient;
|
|
16
|
+
}) => LambdaErrorMetadata;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getLambdaErrorMetadata = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* .what = extracts optional metadata fields from lambda error response
|
|
6
|
+
* .why = named transformer for clear narrative in getParsedResponse
|
|
7
|
+
*/
|
|
8
|
+
const getLambdaErrorMetadata = (input) => {
|
|
9
|
+
return {
|
|
10
|
+
...(input.errorResponse.details !== undefined && {
|
|
11
|
+
details: input.errorResponse.details,
|
|
12
|
+
}),
|
|
13
|
+
...(input.errorResponse.causeMessage !== undefined && {
|
|
14
|
+
causeMessage: input.errorResponse.causeMessage,
|
|
15
|
+
}),
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
exports.getLambdaErrorMetadata = getLambdaErrorMetadata;
|
|
19
|
+
//# sourceMappingURL=getLambdaErrorMetadata.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getLambdaErrorMetadata.js","sourceRoot":"","sources":["../../../../src/domain.operations/askLambdaEndpoint/error/getLambdaErrorMetadata.ts"],"names":[],"mappings":";;;AAWA;;;GAGG;AACI,MAAM,sBAAsB,GAAG,CAAC,KAEtC,EAAuB,EAAE;IACxB,OAAO;QACL,GAAG,CAAC,KAAK,CAAC,aAAa,CAAC,OAAO,KAAK,SAAS,IAAI;YAC/C,OAAO,EAAE,KAAK,CAAC,aAAa,CAAC,OAAO;SACrC,CAAC;QACF,GAAG,CAAC,KAAK,CAAC,aAAa,CAAC,YAAY,KAAK,SAAS,IAAI;YACpD,YAAY,EAAE,KAAK,CAAC,aAAa,CAAC,YAAY;SAC/C,CAAC;KACH,CAAC;AACJ,CAAC,CAAC;AAXW,QAAA,sBAAsB,0BAWjC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getStackTraceString = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* .what = converts stack trace to string format
|
|
6
|
+
* .why = stack trace can be string[] (aws native) or string (genLambdaEndpoint)
|
|
7
|
+
*/
|
|
8
|
+
const getStackTraceString = (input) => {
|
|
9
|
+
if (input.stackTrace === undefined)
|
|
10
|
+
return undefined;
|
|
11
|
+
if (Array.isArray(input.stackTrace))
|
|
12
|
+
return input.stackTrace.join('\n');
|
|
13
|
+
return input.stackTrace;
|
|
14
|
+
};
|
|
15
|
+
exports.getStackTraceString = getStackTraceString;
|
|
16
|
+
//# sourceMappingURL=getStackTraceString.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getStackTraceString.js","sourceRoot":"","sources":["../../../../src/domain.operations/askLambdaEndpoint/error/getStackTraceString.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACI,MAAM,mBAAmB,GAAG,CAAC,KAEnC,EAAsB,EAAE;IACvB,IAAI,KAAK,CAAC,UAAU,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC;IACrD,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC;QAAE,OAAO,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACxE,OAAO,KAAK,CAAC,UAAU,CAAC;AAC1B,CAAC,CAAC;AANW,QAAA,mBAAmB,uBAM9B"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getStatusCodeHint = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* .what = transforms http status code to actionable hint message
|
|
6
|
+
* .why = helps users understand and address lambda invocation failures
|
|
7
|
+
*/
|
|
8
|
+
const getStatusCodeHint = (statusCode) => {
|
|
9
|
+
// check common aws lambda status codes
|
|
10
|
+
if (statusCode === 400)
|
|
11
|
+
return 'bad request — check payload format and size';
|
|
12
|
+
if (statusCode === 403)
|
|
13
|
+
return 'access denied — check IAM permissions for lambda:InvokeFunction';
|
|
14
|
+
if (statusCode === 404)
|
|
15
|
+
return 'function not found — verify service name, access level, and function name are correct';
|
|
16
|
+
if (statusCode === 408)
|
|
17
|
+
return 'request timeout — consider increasing client timeout';
|
|
18
|
+
if (statusCode === 413)
|
|
19
|
+
return 'payload too large — reduce request size (max 6MB sync, 256KB async)';
|
|
20
|
+
if (statusCode === 429)
|
|
21
|
+
return 'rate limit exceeded — implement backoff or request quota increase';
|
|
22
|
+
if (statusCode === 500)
|
|
23
|
+
return 'internal error — check lambda function logs in cloudwatch';
|
|
24
|
+
if (statusCode === 502)
|
|
25
|
+
return 'service error — lambda service unavailable, retry with backoff';
|
|
26
|
+
if (statusCode === 503)
|
|
27
|
+
return 'service unavailable — lambda service temporarily unavailable';
|
|
28
|
+
if (statusCode === 504)
|
|
29
|
+
return 'gateway timeout — lambda execution exceeded timeout';
|
|
30
|
+
// generic fallback with status code
|
|
31
|
+
return `status ${statusCode} — check aws lambda documentation for this status code`;
|
|
32
|
+
};
|
|
33
|
+
exports.getStatusCodeHint = getStatusCodeHint;
|
|
34
|
+
//# sourceMappingURL=getStatusCodeHint.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getStatusCodeHint.js","sourceRoot":"","sources":["../../../../src/domain.operations/askLambdaEndpoint/error/getStatusCodeHint.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACI,MAAM,iBAAiB,GAAG,CAAC,UAAkB,EAAU,EAAE;IAC9D,uCAAuC;IACvC,IAAI,UAAU,KAAK,GAAG;QAAE,OAAO,6CAA6C,CAAC;IAC7E,IAAI,UAAU,KAAK,GAAG;QACpB,OAAO,iEAAiE,CAAC;IAC3E,IAAI,UAAU,KAAK,GAAG;QACpB,OAAO,uFAAuF,CAAC;IACjG,IAAI,UAAU,KAAK,GAAG;QACpB,OAAO,sDAAsD,CAAC;IAChE,IAAI,UAAU,KAAK,GAAG;QACpB,OAAO,qEAAqE,CAAC;IAC/E,IAAI,UAAU,KAAK,GAAG;QACpB,OAAO,mEAAmE,CAAC;IAC7E,IAAI,UAAU,KAAK,GAAG;QACpB,OAAO,2DAA2D,CAAC;IACrE,IAAI,UAAU,KAAK,GAAG;QACpB,OAAO,gEAAgE,CAAC;IAC1E,IAAI,UAAU,KAAK,GAAG;QACpB,OAAO,8DAA8D,CAAC;IACxE,IAAI,UAAU,KAAK,GAAG;QACpB,OAAO,qDAAqD,CAAC;IAE/D,oCAAoC;IACpC,OAAO,UAAU,UAAU,wDAAwD,CAAC;AACtF,CAAC,CAAC;AAxBW,QAAA,iBAAiB,qBAwB5B"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { LambdaClient } from '@aws-sdk/client-lambda';
|
|
2
|
+
/**
|
|
3
|
+
* .what = minimal log interface for lambda invocation
|
|
4
|
+
* .why = accepts console, sdk-logs LogMethods, or any object with debug method
|
|
5
|
+
*/
|
|
6
|
+
export interface MinimalLogMethods {
|
|
7
|
+
debug: (message: string, meta?: Record<string, unknown>) => void;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* .what = invocation args for lambda execution
|
|
11
|
+
* .why = typed input for executor functions
|
|
12
|
+
*/
|
|
13
|
+
export type InvocationArgs = {
|
|
14
|
+
functionName: string;
|
|
15
|
+
payload: unknown;
|
|
16
|
+
exid: string;
|
|
17
|
+
service: string;
|
|
18
|
+
function: string;
|
|
19
|
+
lambdaClient: LambdaClient;
|
|
20
|
+
log: MinimalLogMethods | null;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* .what = the core lambda invocation logic
|
|
24
|
+
* .why = extracted to enable cache wrapper composition
|
|
25
|
+
*/
|
|
26
|
+
export declare const executeLambdaInvocation: <TResponse>(input: InvocationArgs) => Promise<TResponse>;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.executeLambdaInvocation = void 0;
|
|
4
|
+
const LambdaEndpointError_1 = require("../../../domain.objects/LambdaEndpointError");
|
|
5
|
+
const getStatusCodeHint_1 = require("../error/getStatusCodeHint");
|
|
6
|
+
const getParsedResponse_1 = require("../serde/getParsedResponse");
|
|
7
|
+
const sdkLambdaInvoke_1 = require("./sdkLambdaInvoke");
|
|
8
|
+
/**
|
|
9
|
+
* .what = the core lambda invocation logic
|
|
10
|
+
* .why = extracted to enable cache wrapper composition
|
|
11
|
+
*/
|
|
12
|
+
const executeLambdaInvocation = async (input) => {
|
|
13
|
+
// log invocation
|
|
14
|
+
input.log?.debug('askLambdaEndpoint.invoke', {
|
|
15
|
+
functionName: input.functionName,
|
|
16
|
+
exid: input.exid,
|
|
17
|
+
});
|
|
18
|
+
// invoke lambda via communicator
|
|
19
|
+
const result = await (0, sdkLambdaInvoke_1.sdkLambdaInvoke)({
|
|
20
|
+
client: input.lambdaClient,
|
|
21
|
+
functionName: input.functionName,
|
|
22
|
+
payload: input.payload,
|
|
23
|
+
}).catch((error) => {
|
|
24
|
+
throw new LambdaEndpointError_1.LambdaEndpointError(`lambda invocation threw: ${error instanceof Error ? error.message : String(error)}`, {
|
|
25
|
+
service: input.service,
|
|
26
|
+
function: input.function,
|
|
27
|
+
exid: input.exid,
|
|
28
|
+
cause: error instanceof Error ? error : undefined,
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
// check invocation status (200 = invocation succeeded, handler may have thrown)
|
|
32
|
+
// non-200 = invocation itself failed (throttle, permission, not found, etc.)
|
|
33
|
+
const statusCode = result.statusCode ?? 0;
|
|
34
|
+
if (statusCode !== 200) {
|
|
35
|
+
// construct actionable error message based on status code
|
|
36
|
+
const statusHint = (0, getStatusCodeHint_1.getStatusCodeHint)(statusCode);
|
|
37
|
+
throw new LambdaEndpointError_1.LambdaEndpointError(`lambda invocation failed: ${statusHint}`, {
|
|
38
|
+
service: input.service,
|
|
39
|
+
function: input.function,
|
|
40
|
+
exid: input.exid,
|
|
41
|
+
statusCode,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
// parse response
|
|
45
|
+
const response = (0, getParsedResponse_1.getParsedResponse)({
|
|
46
|
+
payload: result.payload,
|
|
47
|
+
functionError: result.functionError,
|
|
48
|
+
service: input.service,
|
|
49
|
+
function: input.function,
|
|
50
|
+
exid: input.exid,
|
|
51
|
+
});
|
|
52
|
+
// log result
|
|
53
|
+
input.log?.debug('askLambdaEndpoint.result', {
|
|
54
|
+
functionName: input.functionName,
|
|
55
|
+
statusCode: result.statusCode,
|
|
56
|
+
});
|
|
57
|
+
return response;
|
|
58
|
+
};
|
|
59
|
+
exports.executeLambdaInvocation = executeLambdaInvocation;
|
|
60
|
+
//# sourceMappingURL=executeLambdaInvocation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"executeLambdaInvocation.js","sourceRoot":"","sources":["../../../../src/domain.operations/askLambdaEndpoint/inv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AE,KAAK,CAAC,OAAO;YACtB,QAAQ,EAAE,KAAK,CAAC,QAAQ;YACxB,IAAI,EAAE,KAAK,CAAC,IAAI;YAChB,UAAU;SACX,CAAC,CAAC;IACL,CAAC;IAED,iBAAiB;IACjB,MAAM,QAAQ,GAAG,IAAA,qCAAiB,EAAY;QAC5C,OAAO,EAAE,MAAM,CAAC,OAAO;QACvB,aAAa,EAAE,MAAM,CAAC,aAAa;QACnC,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,QAAQ,EAAE,KAAK,CAAC,QAAQ;QACxB,IAAI,EAAE,KAAK,CAAC,IAAI;KACjB,CAAC,CAAC;IAEH,aAAa;IACb,KAAK,CAAC,GAAG,EAAE,KAAK,CAAC,0BAA0B,EAAE;QAC3C,YAAY,EAAE,KAAK,CAAC,YAAY;QAChC,UAAU,EAAE,MAAM,CAAC,UAAU;KAC9B,CAAC,CAAC;IAEH,OAAO,QAAQ,CAAC;AAClB,CAAC,CAAC;AAxDW,QAAA,uBAAuB,2BAwDlC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { LambdaClient } from '@aws-sdk/client-lambda';
|
|
2
|
+
/**
|
|
3
|
+
* .what = returns the injected lambda client or creates a new one
|
|
4
|
+
* .why = named transformer for clear narrative in orchestrator
|
|
5
|
+
*/
|
|
6
|
+
export declare const genLambdaClient: (input: {
|
|
7
|
+
sdk?: LambdaClient;
|
|
8
|
+
env?: {
|
|
9
|
+
region?: string;
|
|
10
|
+
};
|
|
11
|
+
}) => LambdaClient;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.genLambdaClient = void 0;
|
|
4
|
+
const client_lambda_1 = require("@aws-sdk/client-lambda");
|
|
5
|
+
/**
|
|
6
|
+
* .what = returns the injected lambda client or creates a new one
|
|
7
|
+
* .why = named transformer for clear narrative in orchestrator
|
|
8
|
+
*/
|
|
9
|
+
const genLambdaClient = (input) => {
|
|
10
|
+
// return injected client if provided
|
|
11
|
+
if (input.sdk)
|
|
12
|
+
return input.sdk;
|
|
13
|
+
// create client, let SDK infer region unless explicitly provided
|
|
14
|
+
return new client_lambda_1.LambdaClient(input.env?.region ? { region: input.env.region } : {});
|
|
15
|
+
};
|
|
16
|
+
exports.genLambdaClient = genLambdaClient;
|
|
17
|
+
//# sourceMappingURL=genLambdaClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"genLambdaClient.js","sourceRoot":"","sources":["../../../../src/domain.operations/askLambdaEndpoint/invoke/genLambdaClient.ts"],"names":[],"mappings":";;;AAAA,0DAAsD;AAEtD;;;GAGG;AACI,MAAM,eAAe,GAAG,CAAC,KAG/B,EAAgB,EAAE;IACjB,qCAAqC;IACrC,IAAI,KAAK,CAAC,GAAG;QAAE,OAAO,KAAK,CAAC,GAAG,CAAC;IAEhC,iEAAiE;IACjE,OAAO,IAAI,4BAAY,CACrB,KAAK,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CACtD,CAAC;AACJ,CAAC,CAAC;AAXW,QAAA,eAAe,mBAW1B"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type LambdaClient } from '@aws-sdk/client-lambda';
|
|
2
|
+
/**
|
|
3
|
+
* .what = raw lambda invocation response
|
|
4
|
+
* .why = typed response from aws lambda invoke
|
|
5
|
+
*/
|
|
6
|
+
export interface LambdaInvokeResponse {
|
|
7
|
+
statusCode: number | undefined;
|
|
8
|
+
functionError: string | undefined;
|
|
9
|
+
payload: Uint8Array | undefined;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* .what = invoke a lambda function via aws sdk
|
|
13
|
+
* .why = communicator encapsulates raw aws sdk i/o at boundary
|
|
14
|
+
*/
|
|
15
|
+
export declare const sdkLambdaInvoke: (input: {
|
|
16
|
+
client: LambdaClient;
|
|
17
|
+
functionName: string;
|
|
18
|
+
payload: unknown;
|
|
19
|
+
}) => Promise<LambdaInvokeResponse>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.sdkLambdaInvoke = void 0;
|
|
4
|
+
const client_lambda_1 = require("@aws-sdk/client-lambda");
|
|
5
|
+
/**
|
|
6
|
+
* .what = invoke a lambda function via aws sdk
|
|
7
|
+
* .why = communicator encapsulates raw aws sdk i/o at boundary
|
|
8
|
+
*/
|
|
9
|
+
const sdkLambdaInvoke = async (input) => {
|
|
10
|
+
const result = await input.client.send(new client_lambda_1.InvokeCommand({
|
|
11
|
+
FunctionName: input.functionName,
|
|
12
|
+
Payload: Buffer.from(JSON.stringify(input.payload)),
|
|
13
|
+
}));
|
|
14
|
+
return {
|
|
15
|
+
statusCode: result.StatusCode,
|
|
16
|
+
functionError: result.FunctionError,
|
|
17
|
+
payload: result.Payload,
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
exports.sdkLambdaInvoke = sdkLambdaInvoke;
|
|
21
|
+
//# sourceMappingURL=sdkLambdaInvoke.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sdkLambdaInvoke.js","sourceRoot":"","sources":["../../../../src/domain.operations/askLambdaEndpoint/invoke/sdkLambdaInvoke.ts"],"names":[],"mappings":";;;AAAA,0DAA0E;AAY1E;;;GAGG;AACI,MAAM,eAAe,GAAG,KAAK,EAAE,KAIrC,EAAiC,EAAE;IAClC,MAAM,MAAM,GAAG,MAAM,KAAK,CAAC,MAAM,CAAC,IAAI,CACpC,IAAI,6BAAa,CAAC;QAChB,YAAY,EAAE,KAAK,CAAC,YAAY;QAChC,OAAO,EAAE,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;KACpD,CAAC,CACH,CAAC;IAEF,OAAO;QACL,UAAU,EAAE,MAAM,CAAC,UAAU;QAC7B,aAAa,EAAE,MAAM,CAAC,aAAa;QACnC,OAAO,EAAE,MAAM,CAAC,OAAO;KACxB,CAAC;AACJ,CAAC,CAAC;AAjBW,QAAA,eAAe,mBAiB1B"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getDecodedPayload = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* .what = decodes Uint8Array payload to string
|
|
6
|
+
* .why = pure transformer for lambda response payload decode
|
|
7
|
+
*/
|
|
8
|
+
const getDecodedPayload = (input) => {
|
|
9
|
+
return new TextDecoder().decode(input.payload);
|
|
10
|
+
};
|
|
11
|
+
exports.getDecodedPayload = getDecodedPayload;
|
|
12
|
+
//# sourceMappingURL=getDecodedPayload.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getDecodedPayload.js","sourceRoot":"","sources":["../../../../src/domain.operations/askLambdaEndpoint/serde/getDecodedPayload.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACI,MAAM,iBAAiB,GAAG,CAAC,KAA8B,EAAU,EAAE;IAC1E,OAAO,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;AACjD,CAAC,CAAC;AAFW,QAAA,iBAAiB,qBAE5B"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* .what = transforms service, access, and function into aws lambda function name
|
|
3
|
+
* .why = aws lambda name convention follows ${service}-${access}-${function} pattern
|
|
4
|
+
*/
|
|
5
|
+
export declare const getLambdaFunctionName: (input: {
|
|
6
|
+
service: string;
|
|
7
|
+
access: string;
|
|
8
|
+
function: string;
|
|
9
|
+
}) => string;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getLambdaFunctionName = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* .what = transforms service, access, and function into aws lambda function name
|
|
6
|
+
* .why = aws lambda name convention follows ${service}-${access}-${function} pattern
|
|
7
|
+
*/
|
|
8
|
+
const getLambdaFunctionName = (input) => {
|
|
9
|
+
return `${input.service}-${input.access}-${input.function}`;
|
|
10
|
+
};
|
|
11
|
+
exports.getLambdaFunctionName = getLambdaFunctionName;
|
|
12
|
+
//# sourceMappingURL=getLambdaFunctionName.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getLambdaFunctionName.js","sourceRoot":"","sources":["../../../../src/domain.operations/askLambdaEndpoint/serde/getLambdaFunctionName.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACI,MAAM,qBAAqB,GAAG,CAAC,KAIrC,EAAU,EAAE;IACX,OAAO,GAAG,KAAK,CAAC,OAAO,IAAI,KAAK,CAAC,MAAM,IAAI,KAAK,CAAC,QAAQ,EAAE,CAAC;AAC9D,CAAC,CAAC;AANW,QAAA,qBAAqB,yBAMhC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* .what = transforms event and trail context into lambda payload
|
|
3
|
+
* .why = lambda invocations need trail context for distributed trace
|
|
4
|
+
*/
|
|
5
|
+
export declare const getLambdaPayload: <TEvent>(input: {
|
|
6
|
+
event: TEvent;
|
|
7
|
+
trail: {
|
|
8
|
+
exid: string;
|
|
9
|
+
};
|
|
10
|
+
}) => {
|
|
11
|
+
event: TEvent;
|
|
12
|
+
trail: {
|
|
13
|
+
exid: string;
|
|
14
|
+
};
|
|
15
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getLambdaPayload = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* .what = transforms event and trail context into lambda payload
|
|
6
|
+
* .why = lambda invocations need trail context for distributed trace
|
|
7
|
+
*/
|
|
8
|
+
const getLambdaPayload = (input) => {
|
|
9
|
+
return {
|
|
10
|
+
event: input.event,
|
|
11
|
+
trail: { exid: input.trail.exid },
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
exports.getLambdaPayload = getLambdaPayload;
|
|
15
|
+
//# sourceMappingURL=getLambdaPayload.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getLambdaPayload.js","sourceRoot":"","sources":["../../../../src/domain.operations/askLambdaEndpoint/serde/getLambdaPayload.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACI,MAAM,gBAAgB,GAAG,CAAS,KAGxC,EAA8C,EAAE;IAC/C,OAAO;QACL,KAAK,EAAE,KAAK,CAAC,KAAK;QAClB,KAAK,EAAE,EAAE,IAAI,EAAE,KAAK,CAAC,KAAK,CAAC,IAAI,EAAE;KAClC,CAAC;AACJ,CAAC,CAAC;AARW,QAAA,gBAAgB,oBAQ3B"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* .what = result of json parse attempt
|
|
3
|
+
* .why = represents either success or failure without throw
|
|
4
|
+
*/
|
|
5
|
+
export type ParsedJsonResult = {
|
|
6
|
+
success: true;
|
|
7
|
+
data: unknown;
|
|
8
|
+
} | {
|
|
9
|
+
success: false;
|
|
10
|
+
error: SyntaxError;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* .what = parse json string without throw
|
|
14
|
+
* .why = pure transformer returns result union instead of throw
|
|
15
|
+
*/
|
|
16
|
+
export declare const getParsedJson: (input: {
|
|
17
|
+
json: string;
|
|
18
|
+
}) => ParsedJsonResult;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getParsedJson = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* .what = parse json string without throw
|
|
6
|
+
* .why = pure transformer returns result union instead of throw
|
|
7
|
+
*/
|
|
8
|
+
const getParsedJson = (input) => {
|
|
9
|
+
try {
|
|
10
|
+
const data = JSON.parse(input.json);
|
|
11
|
+
return { success: true, data };
|
|
12
|
+
}
|
|
13
|
+
catch (error) {
|
|
14
|
+
if (error instanceof SyntaxError) {
|
|
15
|
+
return { success: false, error };
|
|
16
|
+
}
|
|
17
|
+
// non-SyntaxError is unexpected, rethrow
|
|
18
|
+
throw error;
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
exports.getParsedJson = getParsedJson;
|
|
22
|
+
//# sourceMappingURL=getParsedJson.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getParsedJson.js","sourceRoot":"","sources":["../../../../src/domain.operations/askLambdaEndpoint/serde/getParsedJson.ts"],"names":[],"mappings":";;;AAQA;;;GAGG;AACI,MAAM,aAAa,GAAG,CAAC,KAAuB,EAAoB,EAAE;IACzE,IAAI,CAAC;QACH,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACpC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;IACjC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,KAAK,YAAY,WAAW,EAAE,CAAC;YACjC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;QACnC,CAAC;QACD,yCAAyC;QACzC,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC,CAAC;AAXW,QAAA,aAAa,iBAWxB"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* .what = parses lambda response payload and throws on error
|
|
3
|
+
* .why = orchestrator composes decode, parse, and error detection
|
|
4
|
+
*
|
|
5
|
+
* supports both contemp and ancient error response shapes:
|
|
6
|
+
* - contemp: { error: { _serde, class, message, cause?, details? } }
|
|
7
|
+
* - ancient: { errorMessage, errorType?, causeMessage?, details? }
|
|
8
|
+
*/
|
|
9
|
+
export declare const getParsedResponse: <TResponse>(input: {
|
|
10
|
+
payload: Uint8Array | undefined;
|
|
11
|
+
functionError: string | undefined;
|
|
12
|
+
service: string;
|
|
13
|
+
function: string;
|
|
14
|
+
exid: string | null;
|
|
15
|
+
}) => TResponse;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getParsedResponse = void 0;
|
|
4
|
+
const helpful_errors_1 = require("helpful-errors");
|
|
5
|
+
const LambdaEndpointError_1 = require("../../../domain.objects/LambdaEndpointError");
|
|
6
|
+
const getIsLambdaErrorResponse_1 = require("../error/getIsLambdaErrorResponse");
|
|
7
|
+
const getLambdaErrorMetadata_1 = require("../error/getLambdaErrorMetadata");
|
|
8
|
+
const getStackTraceString_1 = require("../error/getStackTraceString");
|
|
9
|
+
const getDecodedPayload_1 = require("./getDecodedPayload");
|
|
10
|
+
const getParsedJson_1 = require("./getParsedJson");
|
|
11
|
+
/**
|
|
12
|
+
* .what = parses lambda response payload and throws on error
|
|
13
|
+
* .why = orchestrator composes decode, parse, and error detection
|
|
14
|
+
*
|
|
15
|
+
* supports both contemp and ancient error response shapes:
|
|
16
|
+
* - contemp: { error: { _serde, class, message, cause?, details? } }
|
|
17
|
+
* - ancient: { errorMessage, errorType?, causeMessage?, details? }
|
|
18
|
+
*/
|
|
19
|
+
const getParsedResponse = (input) => {
|
|
20
|
+
// validate payload exists
|
|
21
|
+
if (!input.payload) {
|
|
22
|
+
throw new LambdaEndpointError_1.LambdaEndpointError('lambda returned empty payload', {
|
|
23
|
+
service: input.service,
|
|
24
|
+
function: input.function,
|
|
25
|
+
exid: input.exid,
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
// decode payload to string
|
|
29
|
+
const payloadString = (0, getDecodedPayload_1.getDecodedPayload)({ payload: input.payload });
|
|
30
|
+
// parse json
|
|
31
|
+
const parseResult = (0, getParsedJson_1.getParsedJson)({ json: payloadString });
|
|
32
|
+
if (!parseResult.success) {
|
|
33
|
+
throw new LambdaEndpointError_1.LambdaEndpointError('lambda returned invalid json', {
|
|
34
|
+
service: input.service,
|
|
35
|
+
function: input.function,
|
|
36
|
+
exid: input.exid,
|
|
37
|
+
cause: parseResult.error,
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
const parsed = parseResult.data;
|
|
41
|
+
// detect contemp error response (preferred, check first)
|
|
42
|
+
if ((0, getIsLambdaErrorResponse_1.getIsContempErrorResponse)(parsed)) {
|
|
43
|
+
const err = parsed.error;
|
|
44
|
+
// ConstraintError = caller's fault, not lambda error (lambda succeeded)
|
|
45
|
+
if (err.class === 'ConstraintError') {
|
|
46
|
+
throw new helpful_errors_1.ConstraintError(err.message, {
|
|
47
|
+
service: input.service,
|
|
48
|
+
function: input.function,
|
|
49
|
+
exid: input.exid,
|
|
50
|
+
causeMessage: err.cause,
|
|
51
|
+
details: err.details,
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
// all other error classes = lambda invocation error
|
|
55
|
+
throw new LambdaEndpointError_1.LambdaEndpointError(err.message, {
|
|
56
|
+
service: input.service,
|
|
57
|
+
function: input.function,
|
|
58
|
+
exid: input.exid,
|
|
59
|
+
errorType: err.class,
|
|
60
|
+
causeMessage: err.cause,
|
|
61
|
+
details: err.details,
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
// detect ancient error response (backwards compat)
|
|
65
|
+
if ((0, getIsLambdaErrorResponse_1.getIsAncientErrorResponse)(parsed)) {
|
|
66
|
+
const stackTrace = (0, getStackTraceString_1.getStackTraceString)({ stackTrace: parsed.stackTrace });
|
|
67
|
+
const errorMeta = (0, getLambdaErrorMetadata_1.getLambdaErrorMetadata)({ errorResponse: parsed });
|
|
68
|
+
// ConstraintError/BadRequestError = caller's fault, not lambda error (lambda succeeded)
|
|
69
|
+
// .note = check both for backwards compat with handlers that use old error types
|
|
70
|
+
if (parsed.errorType === 'ConstraintError' ||
|
|
71
|
+
parsed.errorType === 'BadRequestError') {
|
|
72
|
+
throw new helpful_errors_1.ConstraintError(parsed.errorMessage, {
|
|
73
|
+
service: input.service,
|
|
74
|
+
function: input.function,
|
|
75
|
+
exid: input.exid,
|
|
76
|
+
stackTrace,
|
|
77
|
+
...errorMeta,
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
// all other error types = lambda invocation error
|
|
81
|
+
throw new LambdaEndpointError_1.LambdaEndpointError(parsed.errorMessage, {
|
|
82
|
+
service: input.service,
|
|
83
|
+
function: input.function,
|
|
84
|
+
exid: input.exid,
|
|
85
|
+
errorType: parsed.errorType,
|
|
86
|
+
stackTrace,
|
|
87
|
+
...errorMeta,
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* .cast = TResponse
|
|
92
|
+
* .why = caller specifies expected response type via generic; runtime validation
|
|
93
|
+
* occurs at endpoint via zod schema, not here
|
|
94
|
+
* .removal = add runtime schema validation to askLambdaEndpoint when needed
|
|
95
|
+
*/
|
|
96
|
+
return parsed;
|
|
97
|
+
};
|
|
98
|
+
exports.getParsedResponse = getParsedResponse;
|
|
99
|
+
//# sourceMappingURL=getParsedResponse.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getParsedResponse.js","sourceRoot":"","sources":["../../../../src/domain.operations/askLambdaEndpoint/serde/getParsedResponse.ts"],"names":[],"mappings":";;;AAAA,mDAAiD;AAEjD,qFAAkF;AAClF,gFAG2C;AAC3C,4EAAyE;AACzE,sEAAmE;AACnE,2DAAwD;AACxD,mDAAgD;AAEhD;;;;;;;GAOG;AACI,MAAM,iBAAiB,GAAG,CAAY,KAM5C,EAAa,EAAE;IACd,0BAA0B;IAC1B,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC;QACnB,MAAM,IAAI,yCAAmB,CAAC,+BAA+B,EAAE;YAC7D,OAAO,EAAE,KAAK,CAAC,OAA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APIGatewayProxyEvent, APIGatewayProxyResult, Context } from 'aws-lambda';
|
|
3
|
+
import type { ContextLogTrail } from 'sdk-logs';
|
|
4
|
+
import type { ZodSchema } from 'zod';
|
|
5
|
+
import type { IoLogTranslate } from '../middleware/genIoLoggerMiddleware';
|
|
6
|
+
import { type UnifiedApiGatewayEvent } from './middleware/genApiGatewayEventNormalizationMiddleware';
|
|
7
|
+
export interface CorsConfig {
|
|
8
|
+
/**
|
|
9
|
+
* .what = origins to accept for CORS
|
|
10
|
+
* .why = sets Access-Control-Allow-Origin header
|
|
11
|
+
*
|
|
12
|
+
* special:
|
|
13
|
+
* - '*' = accept all origins (browser will be told server expects requests from all origins)
|
|
14
|
+
* - string[] = accept only listed origins (dynamic match against request origin)
|
|
15
|
+
*/
|
|
16
|
+
origins: '*' | string[];
|
|
17
|
+
/**
|
|
18
|
+
* .what = whether to allow credentials (cookies) in cross-origin requests
|
|
19
|
+
* .why = sets Access-Control-Allow-Credentials header
|
|
20
|
+
*
|
|
21
|
+
* note: if origins is '*' and credentials is true, the actual request origin
|
|
22
|
+
* will be echoed (browsers don't allow '*' with credentials)
|
|
23
|
+
*/
|
|
24
|
+
credentials: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* .what = headers allowed in CORS requests
|
|
27
|
+
* .why = sets Access-Control-Allow-Headers header
|
|
28
|
+
*
|
|
29
|
+
* defaults to 'content-type,authorization'
|
|
30
|
+
*/
|
|
31
|
+
headers?: string;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* .what = input type for forApiGateway
|
|
35
|
+
* .why = sdk contract type, exported for consumer type inference
|
|
36
|
+
*/
|
|
37
|
+
export type ForApiGatewayInput<TInput, TOutput> = {
|
|
38
|
+
schema: {
|
|
39
|
+
input: ZodSchema<TInput>;
|
|
40
|
+
output: ZodSchema<TOutput>;
|
|
41
|
+
};
|
|
42
|
+
invoke: (input: {
|
|
43
|
+
event: TInput;
|
|
44
|
+
rawEvent: UnifiedApiGatewayEvent;
|
|
45
|
+
}, context: ContextLogTrail) => Promise<TOutput>;
|
|
46
|
+
logTranslate?: IoLogTranslate;
|
|
47
|
+
cors?: CorsConfig;
|
|
48
|
+
deserialize?: {
|
|
49
|
+
/**
|
|
50
|
+
* .what = whether to deserialize JSON body
|
|
51
|
+
* .why = converts JSON string body to object when content-type is application/json
|
|
52
|
+
*
|
|
53
|
+
* defaults to true; set to false for raw string input
|
|
54
|
+
*/
|
|
55
|
+
body: boolean;
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* .what = generates API Gateway lambda handler with HTTP features
|
|
60
|
+
* .why = adds CORS, security headers, error handler, body serialization, and validation
|
|
61
|
+
*
|
|
62
|
+
* follows simple-lambda-handlers createApiGatewayHandler pattern:
|
|
63
|
+
* - uses middy middleware chain
|
|
64
|
+
* - uses @middy/http-cors for dynamic origin match
|
|
65
|
+
* - uses @middy/http-security-headers for OWASP security headers
|
|
66
|
+
* - uses @middy/http-json-body-parser for JSON body parse
|
|
67
|
+
* - uses @middy/http-response-serializer for response serialization
|
|
68
|
+
*/
|
|
69
|
+
export declare const forApiGateway: <TInput, TOutput>(config: {
|
|
70
|
+
schema: {
|
|
71
|
+
input: ZodSchema<TInput>;
|
|
72
|
+
output: ZodSchema<TOutput>;
|
|
73
|
+
};
|
|
74
|
+
invoke: (input: {
|
|
75
|
+
event: TInput;
|
|
76
|
+
rawEvent: UnifiedApiGatewayEvent;
|
|
77
|
+
}, context: ContextLogTrail) => Promise<TOutput>;
|
|
78
|
+
logTranslate?: IoLogTranslate;
|
|
79
|
+
cors?: CorsConfig;
|
|
80
|
+
deserialize?: {
|
|
81
|
+
body: boolean;
|
|
82
|
+
};
|
|
83
|
+
}) => middy.MiddyfiedHandler<APIGatewayProxyEvent, APIGatewayProxyResult, Error, Context>;
|