sdk-aws-lambda 0.1.1 → 0.2.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.operations/askLambdaEndpoint/invoke/genLambdaClient.d.ts → access/sdks/lambda/genLambdaSdk.d.ts} +2 -2
- package/dist/{domain.operations/askLambdaEndpoint/invoke/genLambdaClient.js → access/sdks/lambda/genLambdaSdk.js} +7 -7
- package/dist/access/sdks/lambda/genLambdaSdk.js.map +1 -0
- package/dist/{domain.operations/askLambdaEndpoint/invoke → access/sdks/lambda}/sdkLambdaInvoke.d.ts +6 -2
- package/dist/{domain.operations/askLambdaEndpoint/invoke → access/sdks/lambda}/sdkLambdaInvoke.js +6 -3
- package/dist/access/sdks/lambda/sdkLambdaInvoke.js.map +1 -0
- package/dist/domain.objects/ContextAwsLambdaCaller.d.ts +25 -0
- package/dist/domain.objects/ContextAwsLambdaCaller.js +3 -0
- package/dist/domain.objects/ContextAwsLambdaCaller.js.map +1 -0
- package/dist/domain.objects/ContextAwsLambdaServer.d.ts +30 -0
- package/dist/domain.objects/ContextAwsLambdaServer.js +3 -0
- package/dist/domain.objects/ContextAwsLambdaServer.js.map +1 -0
- package/dist/domain.objects/HttpStatusCode.d.ts +2 -2
- package/dist/domain.objects/HttpStatusCode.js +3 -3
- package/dist/domain.objects/LambdaEndpoint.d.ts +35 -0
- package/dist/domain.objects/LambdaEndpoint.js +10 -0
- package/dist/domain.objects/LambdaEndpoint.js.map +1 -0
- package/dist/domain.objects/LambdaEndpointError.d.ts +5 -8
- package/dist/domain.objects/LambdaEndpointError.js.map +1 -1
- package/dist/domain.objects/LambdaEndpointSchema.d.ts +9 -0
- package/dist/domain.objects/LambdaEndpointSchema.js +3 -0
- package/dist/domain.objects/LambdaEndpointSchema.js.map +1 -0
- package/dist/domain.objects/LambdaFunctionNotFoundError.d.ts +10 -0
- package/dist/domain.objects/LambdaFunctionNotFoundError.js +15 -0
- package/dist/domain.objects/LambdaFunctionNotFoundError.js.map +1 -0
- package/dist/domain.objects/LambdaIntrospectionBlockedError.d.ts +10 -0
- package/dist/domain.objects/LambdaIntrospectionBlockedError.js +15 -0
- package/dist/domain.objects/LambdaIntrospectionBlockedError.js.map +1 -0
- package/dist/domain.objects/LambdaIntrospectionNotSupportedError.d.ts +18 -0
- package/dist/domain.objects/LambdaIntrospectionNotSupportedError.js +15 -0
- package/dist/domain.objects/LambdaIntrospectionNotSupportedError.js.map +1 -0
- package/dist/domain.objects/LambdaServiceNotFoundError.d.ts +10 -0
- package/dist/domain.objects/LambdaServiceNotFoundError.js +15 -0
- package/dist/domain.objects/LambdaServiceNotFoundError.js.map +1 -0
- package/dist/domain.operations/asLambdaEndpoint/asLambdaEndpoint.d.ts +20 -0
- package/dist/domain.operations/asLambdaEndpoint/asLambdaEndpoint.js +47 -0
- package/dist/domain.operations/asLambdaEndpoint/asLambdaEndpoint.js.map +1 -0
- package/dist/domain.operations/askLambdaEndpoint/askLambdaEndpoint.d.ts +2 -12
- package/dist/domain.operations/askLambdaEndpoint/askLambdaEndpoint.js +13 -22
- package/dist/domain.operations/askLambdaEndpoint/askLambdaEndpoint.js.map +1 -1
- package/dist/domain.operations/askLambdaEndpoint/cache/asCachedExecutor.d.ts +2 -2
- package/dist/domain.operations/askLambdaEndpoint/cache/asCachedExecutor.js.map +1 -1
- package/dist/domain.operations/askLambdaEndpoint/cache/getAskLambdaCacheKey.d.ts +3 -4
- package/dist/domain.operations/askLambdaEndpoint/cache/getAskLambdaCacheKey.js +17 -5
- package/dist/domain.operations/askLambdaEndpoint/cache/getAskLambdaCacheKey.js.map +1 -1
- package/dist/domain.operations/askLambdaEndpoint/error/getStatusCodeHint.d.ts +1 -1
- package/dist/domain.operations/askLambdaEndpoint/error/getStatusCodeHint.js +3 -3
- package/dist/domain.operations/askLambdaEndpoint/invoke/executeLambdaInvocation.d.ts +13 -8
- package/dist/domain.operations/askLambdaEndpoint/invoke/executeLambdaInvocation.js +20 -19
- package/dist/domain.operations/askLambdaEndpoint/invoke/executeLambdaInvocation.js.map +1 -1
- package/dist/domain.operations/askLambdaEndpoint/serde/asUnprefixedErrorMessage.d.ts +13 -0
- package/dist/domain.operations/askLambdaEndpoint/serde/asUnprefixedErrorMessage.js +26 -0
- package/dist/domain.operations/askLambdaEndpoint/serde/asUnprefixedErrorMessage.js.map +1 -0
- package/dist/domain.operations/askLambdaEndpoint/serde/getParsedResponse.d.ts +2 -2
- package/dist/domain.operations/askLambdaEndpoint/serde/getParsedResponse.js +15 -14
- package/dist/domain.operations/askLambdaEndpoint/serde/getParsedResponse.js.map +1 -1
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/genLambdaEndpoint.forApiGateway.d.ts +15 -8
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/genLambdaEndpoint.forApiGateway.js +16 -9
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/genLambdaEndpoint.forApiGateway.js.map +1 -1
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/getCorsOrigin.d.ts +3 -3
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/getCorsOrigin.js +5 -5
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/getIsV2ApiGatewayEvent.d.ts +1 -1
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/getIsV2ApiGatewayEvent.js +1 -1
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/middleware/genApiGatewayEventNormalizationMiddleware.js +88 -63
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/middleware/genApiGatewayEventNormalizationMiddleware.js.map +1 -1
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forAskEndpoint/genLambdaEndpoint.forAskEndpoint.d.ts +7 -9
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forAskEndpoint/genLambdaEndpoint.forAskEndpoint.js +14 -11
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forAskEndpoint/genLambdaEndpoint.forAskEndpoint.js.map +1 -1
- package/dist/domain.operations/genLambdaEndpoint/middleware/genConstraintErrorMiddleware.js +1 -1
- package/dist/domain.operations/genLambdaEndpoint/middleware/genIntrospectionMiddleware.d.ts +22 -0
- package/dist/domain.operations/genLambdaEndpoint/middleware/genIntrospectionMiddleware.getJsonSchemaFromZod.d.ts +7 -0
- package/dist/domain.operations/genLambdaEndpoint/middleware/genIntrospectionMiddleware.getJsonSchemaFromZod.js +13 -0
- package/dist/domain.operations/genLambdaEndpoint/middleware/genIntrospectionMiddleware.getJsonSchemaFromZod.js.map +1 -0
- package/dist/domain.operations/genLambdaEndpoint/middleware/genIntrospectionMiddleware.isIntrospectionPayload.d.ts +5 -0
- package/dist/domain.operations/genLambdaEndpoint/middleware/genIntrospectionMiddleware.isIntrospectionPayload.js +16 -0
- package/dist/domain.operations/genLambdaEndpoint/middleware/genIntrospectionMiddleware.isIntrospectionPayload.js.map +1 -0
- package/dist/domain.operations/genLambdaEndpoint/middleware/genIntrospectionMiddleware.js +53 -0
- package/dist/domain.operations/genLambdaEndpoint/middleware/genIntrospectionMiddleware.js.map +1 -0
- package/dist/domain.operations/genLambdaEndpoint/middleware/genTrailMiddleware.js +1 -1
- package/dist/domain.operations/genLambdaEndpoint/middleware/getErrorResponseBody.d.ts +1 -1
- package/dist/domain.operations/genLambdaEndpoint/middleware/getValidationError.d.ts +1 -1
- package/dist/domain.operations/genLambdaEndpoint/middleware/getValidationError.js +12 -4
- package/dist/domain.operations/genLambdaEndpoint/middleware/getValidationError.js.map +1 -1
- package/dist/domain.operations/getAllLambdaContracts/getAllLambdaContracts.d.ts +33 -0
- package/dist/domain.operations/getAllLambdaContracts/getAllLambdaContracts.js +89 -0
- package/dist/domain.operations/getAllLambdaContracts/getAllLambdaContracts.js.map +1 -0
- package/dist/domain.operations/getAllLambdaContracts/lambdaContract/asContractRecord.d.ts +6 -0
- package/dist/domain.operations/getAllLambdaContracts/lambdaContract/asContractRecord.js +12 -0
- package/dist/domain.operations/getAllLambdaContracts/lambdaContract/asContractRecord.js.map +1 -0
- package/dist/domain.operations/getAllLambdaContracts/lambdaFunction/getAllLambdaFunctionsByPrefix.d.ts +15 -0
- package/dist/domain.operations/getAllLambdaContracts/lambdaFunction/getAllLambdaFunctionsByPrefix.js +44 -0
- package/dist/domain.operations/getAllLambdaContracts/lambdaFunction/getAllLambdaFunctionsByPrefix.js.map +1 -0
- package/dist/domain.operations/getAllLambdaContracts/lambdaFunction/sdkLambdaGetAllFunctions.d.ts +16 -0
- package/dist/domain.operations/getAllLambdaContracts/lambdaFunction/sdkLambdaGetAllFunctions.js +26 -0
- package/dist/domain.operations/getAllLambdaContracts/lambdaFunction/sdkLambdaGetAllFunctions.js.map +1 -0
- package/dist/domain.operations/getOneLambdaContract/asLambdaEndpointSchema.d.ts +16 -0
- package/dist/domain.operations/getOneLambdaContract/asLambdaEndpointSchema.js +76 -0
- package/dist/domain.operations/getOneLambdaContract/asLambdaEndpointSchema.js.map +1 -0
- package/dist/domain.operations/getOneLambdaContract/getOneLambdaContract.d.ts +32 -0
- package/dist/domain.operations/getOneLambdaContract/getOneLambdaContract.js +112 -0
- package/dist/domain.operations/getOneLambdaContract/getOneLambdaContract.js.map +1 -0
- package/dist/index.d.ts +14 -1
- package/dist/index.js +24 -2
- package/dist/index.js.map +1 -1
- package/package.json +14 -12
- package/readme.md +64 -4
- package/dist/domain.operations/askLambdaEndpoint/context/getAccessFromContext.d.ts +0 -11
- package/dist/domain.operations/askLambdaEndpoint/context/getAccessFromContext.js +0 -21
- package/dist/domain.operations/askLambdaEndpoint/context/getAccessFromContext.js.map +0 -1
- package/dist/domain.operations/askLambdaEndpoint/invoke/genLambdaClient.js.map +0 -1
- package/dist/domain.operations/askLambdaEndpoint/invoke/sdkLambdaInvoke.js.map +0 -1
- package/dist/domain.operations/askLambdaEndpoint/serde/getLambdaFunctionName.d.ts +0 -9
- package/dist/domain.operations/askLambdaEndpoint/serde/getLambdaFunctionName.js +0 -12
- package/dist/domain.operations/askLambdaEndpoint/serde/getLambdaFunctionName.js.map +0 -1
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { SimpleInMemoryCache } from 'simple-in-memory-cache';
|
|
2
2
|
import { type SimpleCache } from 'with-simple-cache';
|
|
3
|
-
import { type
|
|
3
|
+
import { type InvocationContext, type InvocationInput } from '../invoke/executeLambdaInvocation';
|
|
4
4
|
/**
|
|
5
5
|
* .what = executor type for lambda invocation
|
|
6
6
|
* .why = typed for cache wrapper composition
|
|
7
7
|
*/
|
|
8
|
-
type LambdaExecutor<TResponse> = (
|
|
8
|
+
type LambdaExecutor<TResponse> = (input: InvocationInput, context: InvocationContext) => Promise<TResponse>;
|
|
9
9
|
/**
|
|
10
10
|
* .what = wraps executor with cache if caches provided
|
|
11
11
|
* .why = extracts cache selection logic from orchestrator
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"asCachedExecutor.js","sourceRoot":"","sources":["../../../../src/domain.operations/askLambdaEndpoint/cache/asCachedExecutor.ts"],"names":[],"mappings":";;;AACA,yDAA2E;AAE3E,+
|
|
1
|
+
{"version":3,"file":"asCachedExecutor.js","sourceRoot":"","sources":["../../../../src/domain.operations/askLambdaEndpoint/cache/asCachedExecutor.ts"],"names":[],"mappings":";;;AACA,yDAA2E;AAE3E,+EAI2C;AAW3C;;;GAGG;AACI,MAAM,gBAAgB,GAAG,CAAY,KAI3C,EAA6B,EAAE;IAC9B,+CAA+C;IAC/C,IAAI,CAAC,KAAK,CAAC,QAAQ;QACjB,OAAO,iDAAoD,CAAC;IAE9D,+CAA+C;IAC/C,IAAI,KAAK,CAAC,MAAM,EAAE,CAAC;QACjB,OAAO,IAAA,wCAAoB,EAAC,iDAAuB,EAAE;YACnD,KAAK,EAAE;gBACL,MAAM,EAAE,KAAK,CAAC,QAAQ;gBACtB,aAAa,EAAE,KAAK,CAAC,MAAM;aAC5B;YACD,SAAS,EAAE,EAAE,GAAG,EAAE,KAAK,CAAC,WAAW,EAAE;SACtC,CAA8B,CAAC;IAClC,CAAC;IAED,oBAAoB;IACpB,OAAO,IAAA,wCAAoB,EAAC,iDAAuB,EAAE;QACnD,KAAK,EAAE,KAAK,CAAC,QAAQ;QACrB,SAAS,EAAE,EAAE,GAAG,EAAE,KAAK,CAAC,WAAW,EAAE;KACtC,CAA8B,CAAC;AAClC,CAAC,CAAC;AAzBW,QAAA,gBAAgB,oBAyB3B"}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
+
import type { LambdaEndpoint } from '../../../domain.objects/LambdaEndpoint';
|
|
1
2
|
/**
|
|
2
|
-
* .what = generates a unique cache key for
|
|
3
|
+
* .what = generates a unique cache key for LambdaClient requests
|
|
3
4
|
* .why = enables request deduplication and response cache
|
|
4
5
|
*/
|
|
5
6
|
export declare const getAskLambdaCacheKey: (input: {
|
|
6
|
-
|
|
7
|
-
function: string;
|
|
8
|
-
access: string;
|
|
7
|
+
endpoint: LambdaEndpoint;
|
|
9
8
|
event: Record<string, unknown>;
|
|
10
9
|
}) => string;
|
|
@@ -3,14 +3,26 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.getAskLambdaCacheKey = void 0;
|
|
4
4
|
const node_crypto_1 = require("node:crypto");
|
|
5
5
|
/**
|
|
6
|
-
* .what =
|
|
6
|
+
* .what = recursively sorts object keys for deterministic serialization
|
|
7
|
+
* .why = JSON.stringify does not guarantee property order
|
|
8
|
+
*/
|
|
9
|
+
const asStableJson = (value) => {
|
|
10
|
+
if (value === null || typeof value !== 'object') {
|
|
11
|
+
return JSON.stringify(value);
|
|
12
|
+
}
|
|
13
|
+
if (Array.isArray(value)) {
|
|
14
|
+
return '[' + value.map(asStableJson).join(',') + ']';
|
|
15
|
+
}
|
|
16
|
+
const sortedKeys = Object.keys(value).sort();
|
|
17
|
+
const pairs = sortedKeys.map((key) => `${JSON.stringify(key)}:${asStableJson(value[key])}`);
|
|
18
|
+
return '{' + pairs.join(',') + '}';
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* .what = generates a unique cache key for LambdaClient requests
|
|
7
22
|
* .why = enables request deduplication and response cache
|
|
8
23
|
*/
|
|
9
24
|
const getAskLambdaCacheKey = (input) => {
|
|
10
|
-
const idealKey = [
|
|
11
|
-
[input.service, input.access, input.function].join('-'),
|
|
12
|
-
JSON.stringify(input.event),
|
|
13
|
-
].join('.');
|
|
25
|
+
const idealKey = [input.endpoint.slug, asStableJson(input.event)].join('.');
|
|
14
26
|
// create human part for observability
|
|
15
27
|
const humanPart = idealKey
|
|
16
28
|
.replace(/:/g, '.')
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getAskLambdaCacheKey.js","sourceRoot":"","sources":["../../../../src/domain.operations/askLambdaEndpoint/cache/getAskLambdaCacheKey.ts"],"names":[],"mappings":";;;AAAA,6CAAyC;
|
|
1
|
+
{"version":3,"file":"getAskLambdaCacheKey.js","sourceRoot":"","sources":["../../../../src/domain.operations/askLambdaEndpoint/cache/getAskLambdaCacheKey.ts"],"names":[],"mappings":";;;AAAA,6CAAyC;AAGzC;;;GAGG;AACH,MAAM,YAAY,GAAG,CAAC,KAAc,EAAU,EAAE;IAC9C,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAChD,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IAC/B,CAAC;IACD,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACzB,OAAO,GAAG,GAAG,KAAK,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC;IACvD,CAAC;IACD,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,CAAC;IAC7C,MAAM,KAAK,GAAG,UAAU,CAAC,GAAG,CAC1B,CAAC,GAAG,EAAE,EAAE,CACN,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,YAAY,CAAE,KAAiC,CAAC,GAAG,CAAC,CAAC,EAAE,CACpF,CAAC;IACF,OAAO,GAAG,GAAG,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC;AACrC,CAAC,CAAC;AAEF;;;GAGG;AACI,MAAM,oBAAoB,GAAG,CAAC,KAGpC,EAAU,EAAE;IACX,MAAM,QAAQ,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAE5E,sCAAsC;IACtC,MAAM,SAAS,GAAG,QAAQ;SACvB,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC;SAClB,OAAO,CAAC,YAAY,EAAE,EAAE,CAAC;SACzB,OAAO,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;IAEzB,6CAA6C;IAC7C,MAAM,UAAU,GAAG,IAAA,wBAAU,EAAC,QAAQ,CAAC;SACpC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;SAChC,MAAM,CAAC,KAAK,CAAC,CAAC;IAEjB,OAAO,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC3C,CAAC,CAAC;AAlBW,QAAA,oBAAoB,wBAkB/B"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* .what = transforms http status code to actionable hint message
|
|
3
|
-
* .why = helps
|
|
3
|
+
* .why = helps humans understand and address lambda invocation failures
|
|
4
4
|
*/
|
|
5
5
|
export declare const getStatusCodeHint: (statusCode: number) => string;
|
|
@@ -3,18 +3,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.getStatusCodeHint = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* .what = transforms http status code to actionable hint message
|
|
6
|
-
* .why = helps
|
|
6
|
+
* .why = helps humans understand and address lambda invocation failures
|
|
7
7
|
*/
|
|
8
8
|
const getStatusCodeHint = (statusCode) => {
|
|
9
9
|
// check common aws lambda status codes
|
|
10
10
|
if (statusCode === 400)
|
|
11
11
|
return 'bad request — check payload format and size';
|
|
12
12
|
if (statusCode === 403)
|
|
13
|
-
return 'access denied — check
|
|
13
|
+
return 'access denied — check iam permissions for lambda:InvokeFunction';
|
|
14
14
|
if (statusCode === 404)
|
|
15
15
|
return 'function not found — verify service name, access level, and function name are correct';
|
|
16
16
|
if (statusCode === 408)
|
|
17
|
-
return 'request timeout — consider increasing
|
|
17
|
+
return 'request timeout — consider increasing caller timeout';
|
|
18
18
|
if (statusCode === 413)
|
|
19
19
|
return 'payload too large — reduce request size (max 6MB sync, 256KB async)';
|
|
20
20
|
if (statusCode === 429)
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { LambdaClient } from '@aws-sdk/client-lambda';
|
|
2
|
+
import type { LambdaEndpoint } from '../../../domain.objects/LambdaEndpoint';
|
|
2
3
|
/**
|
|
3
4
|
* .what = minimal log interface for lambda invocation
|
|
4
5
|
* .why = accepts console, sdk-logs LogMethods, or any object with debug method
|
|
@@ -7,20 +8,24 @@ export interface MinimalLogMethods {
|
|
|
7
8
|
debug: (message: string, meta?: Record<string, unknown>) => void;
|
|
8
9
|
}
|
|
9
10
|
/**
|
|
10
|
-
* .what = invocation
|
|
11
|
-
* .why =
|
|
11
|
+
* .what = invocation input for lambda execution
|
|
12
|
+
* .why = what to invoke (the endpoint) with which payload + trail exid
|
|
12
13
|
*/
|
|
13
|
-
export type
|
|
14
|
-
|
|
14
|
+
export type InvocationInput = {
|
|
15
|
+
endpoint: LambdaEndpoint;
|
|
15
16
|
payload: unknown;
|
|
16
17
|
exid: string;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* .what = invocation context for lambda execution
|
|
21
|
+
* .why = injected dependencies (sdk client + log), not invocation identity
|
|
22
|
+
*/
|
|
23
|
+
export type InvocationContext = {
|
|
24
|
+
sdkLambda: LambdaClient;
|
|
20
25
|
log: MinimalLogMethods | null;
|
|
21
26
|
};
|
|
22
27
|
/**
|
|
23
28
|
* .what = the core lambda invocation logic
|
|
24
29
|
* .why = extracted to enable cache wrapper composition
|
|
25
30
|
*/
|
|
26
|
-
export declare const executeLambdaInvocation: <TResponse>(input:
|
|
31
|
+
export declare const executeLambdaInvocation: <TResponse>(input: InvocationInput, context: InvocationContext) => Promise<TResponse>;
|
|
@@ -1,31 +1,34 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.executeLambdaInvocation = void 0;
|
|
4
|
+
const sdkLambdaInvoke_1 = require("../../../access/sdks/lambda/sdkLambdaInvoke");
|
|
4
5
|
const LambdaEndpointError_1 = require("../../../domain.objects/LambdaEndpointError");
|
|
5
6
|
const getStatusCodeHint_1 = require("../error/getStatusCodeHint");
|
|
6
7
|
const getParsedResponse_1 = require("../serde/getParsedResponse");
|
|
7
|
-
const sdkLambdaInvoke_1 = require("./sdkLambdaInvoke");
|
|
8
8
|
/**
|
|
9
9
|
* .what = the core lambda invocation logic
|
|
10
10
|
* .why = extracted to enable cache wrapper composition
|
|
11
11
|
*/
|
|
12
|
-
const executeLambdaInvocation = async (input) => {
|
|
12
|
+
const executeLambdaInvocation = async (input, context) => {
|
|
13
13
|
// log invocation
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
context.log?.debug('askLambdaEndpoint.invoke', {
|
|
15
|
+
slug: input.endpoint.slug,
|
|
16
16
|
exid: input.exid,
|
|
17
17
|
});
|
|
18
18
|
// invoke lambda via communicator
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}).catch((error) => {
|
|
24
|
-
throw
|
|
25
|
-
|
|
26
|
-
|
|
19
|
+
// @error-enrichment: all sdkLambdaInvoke errors wrapped with endpoint context
|
|
20
|
+
// - allowlist: all errors (sdk, network, timeout) → wrap with endpoint context
|
|
21
|
+
// - original error preserved via `cause` for full stack trace
|
|
22
|
+
// - throw raw error would lose which endpoint failed
|
|
23
|
+
const result = await (0, sdkLambdaInvoke_1.sdkLambdaInvoke)({ slug: input.endpoint.slug, payload: input.payload }, { sdkLambda: context.sdkLambda }).catch((error) => {
|
|
24
|
+
// throw non-Error values (unexpected)
|
|
25
|
+
if (!(error instanceof Error))
|
|
26
|
+
throw error;
|
|
27
|
+
// wrap Error with endpoint context (error preserved via cause)
|
|
28
|
+
throw new LambdaEndpointError_1.LambdaEndpointError(`lambda invocation threw: ${error.message}`, {
|
|
29
|
+
endpoint: input.endpoint,
|
|
27
30
|
exid: input.exid,
|
|
28
|
-
cause: error
|
|
31
|
+
cause: error,
|
|
29
32
|
});
|
|
30
33
|
});
|
|
31
34
|
// check invocation status (200 = invocation succeeded, handler may have thrown)
|
|
@@ -35,8 +38,7 @@ const executeLambdaInvocation = async (input) => {
|
|
|
35
38
|
// construct actionable error message based on status code
|
|
36
39
|
const statusHint = (0, getStatusCodeHint_1.getStatusCodeHint)(statusCode);
|
|
37
40
|
throw new LambdaEndpointError_1.LambdaEndpointError(`lambda invocation failed: ${statusHint}`, {
|
|
38
|
-
|
|
39
|
-
function: input.function,
|
|
41
|
+
endpoint: input.endpoint,
|
|
40
42
|
exid: input.exid,
|
|
41
43
|
statusCode,
|
|
42
44
|
});
|
|
@@ -45,13 +47,12 @@ const executeLambdaInvocation = async (input) => {
|
|
|
45
47
|
const response = (0, getParsedResponse_1.getParsedResponse)({
|
|
46
48
|
payload: result.payload,
|
|
47
49
|
functionError: result.functionError,
|
|
48
|
-
|
|
49
|
-
function: input.function,
|
|
50
|
+
endpoint: input.endpoint,
|
|
50
51
|
exid: input.exid,
|
|
51
52
|
});
|
|
52
53
|
// log result
|
|
53
|
-
|
|
54
|
-
|
|
54
|
+
context.log?.debug('askLambdaEndpoint.result', {
|
|
55
|
+
slug: input.endpoint.slug,
|
|
55
56
|
statusCode: result.statusCode,
|
|
56
57
|
});
|
|
57
58
|
return response;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"executeLambdaInvocation.js","sourceRoot":"","sources":["../../../../src/domain.operations/askLambdaEndpoint/invoke/executeLambdaInvocation.ts"],"names":[],"mappings":";;;AAEA,qFAAkF;AAClF,kEAA+D;AAC/D,kEAA+D;
|
|
1
|
+
{"version":3,"file":"executeLambdaInvocation.js","sourceRoot":"","sources":["../../../../src/domain.operations/askLambdaEndpoint/invoke/executeLambdaInvocation.ts"],"names":[],"mappings":";;;AAEA,iFAA8E;AAE9E,qFAAkF;AAClF,kEAA+D;AAC/D,kEAA+D;AA6B/D;;;GAGG;AACI,MAAM,uBAAuB,GAAG,KAAK,EAC1C,KAAsB,EACtB,OAA0B,EACN,EAAE;IACtB,iBAAiB;IACjB,OAAO,CAAC,GAAG,EAAE,KAAK,CAAC,0BAA0B,EAAE;QAC7C,IAAI,EAAE,KAAK,CAAC,QAAQ,CAAC,IAAI;QACzB,IAAI,EAAE,KAAK,CAAC,IAAI;KACjB,CAAC,CAAC;IAEH,iCAAiC;IACjC,8EAA8E;IAC9E,iFAAiF;IACjF,gEAAgE;IAChE,uDAAuD;IACvD,MAAM,MAAM,GAAG,MAAM,IAAA,iCAAe,EAClC,EAAE,IAAI,EAAE,KAAK,CAAC,QAAQ,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,EACrD,EAAE,SAAS,EAAE,OAAO,CAAC,SAAS,EAAE,CACjC,CAAC,KAAK,CAAC,CAAC,KAAc,EAAE,EAAE;QACzB,sCAAsC;QACtC,IAAI,CAAC,CAAC,KAAK,YAAY,KAAK,CAAC;YAAE,MAAM,KAAK,CAAC;QAE3C,+DAA+D;QAC/D,MAAM,IAAI,yCAAmB,CAAC,4BAA4B,KAAK,CAAC,OAAO,EAAE,EAAE;YACzE,QAAQ,EAAE,KAAK,CAAC,QAAQ;YACxB,IAAI,EAAE,KAAK,CAAC,IAAI;YAChB,KAAK,EAAE,KAAK;SACb,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,gFAAgF;IAChF,6EAA6E;IAC7E,MAAM,UAAU,GAAG,MAAM,CAAC,UAAU,IAAI,CAAC,CAAC;IAC1C,IAAI,UAAU,KAAK,GAAG,EAAE,CAAC;QACvB,0DAA0D;QAC1D,MAAM,UAAU,GAAG,IAAA,qCAAiB,EAAC,UAAU,CAAC,CAAC;QACjD,MAAM,IAAI,yCAAmB,CAAC,6BAA6B,UAAU,EAAE,EAAE;YACvE,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,QAAQ,EAAE,KAAK,CAAC,QAAQ;QACxB,IAAI,EAAE,KAAK,CAAC,IAAI;KACjB,CAAC,CAAC;IAEH,aAAa;IACb,OAAO,CAAC,GAAG,EAAE,KAAK,CAAC,0BAA0B,EAAE;QAC7C,IAAI,EAAE,KAAK,CAAC,QAAQ,CAAC,IAAI;QACzB,UAAU,EAAE,MAAM,CAAC,UAAU;KAC9B,CAAC,CAAC;IAEH,OAAO,QAAQ,CAAC;AAClB,CAAC,CAAC;AA1DW,QAAA,uBAAuB,2BA0DlC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* .what = strips helpful-errors emoji prefix from error message
|
|
3
|
+
* .why = prevents double prefix when errors cross lambda boundary
|
|
4
|
+
*
|
|
5
|
+
* helpful-errors prefixes messages with pattern: "✋ {ClassName}: {message}"
|
|
6
|
+
* when we create a new ConstraintError with this message, it adds another prefix
|
|
7
|
+
* e.g., "✋ ConstraintError: ✋ ConstraintError: validation failed"
|
|
8
|
+
*
|
|
9
|
+
* this transformer extracts the original message to avoid duplicate prefixes
|
|
10
|
+
*/
|
|
11
|
+
export declare const asUnprefixedErrorMessage: (input: {
|
|
12
|
+
message: string;
|
|
13
|
+
}) => string;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.asUnprefixedErrorMessage = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* .what = strips helpful-errors emoji prefix from error message
|
|
6
|
+
* .why = prevents double prefix when errors cross lambda boundary
|
|
7
|
+
*
|
|
8
|
+
* helpful-errors prefixes messages with pattern: "✋ {ClassName}: {message}"
|
|
9
|
+
* when we create a new ConstraintError with this message, it adds another prefix
|
|
10
|
+
* e.g., "✋ ConstraintError: ✋ ConstraintError: validation failed"
|
|
11
|
+
*
|
|
12
|
+
* this transformer extracts the original message to avoid duplicate prefixes
|
|
13
|
+
*/
|
|
14
|
+
const asUnprefixedErrorMessage = (input) => {
|
|
15
|
+
// match pattern: "✋ {ClassName}: {rest}"
|
|
16
|
+
// .note = class names may have suffixes from bundler deduplication (e.g., ConstraintError5)
|
|
17
|
+
const prefixPattern = /^✋\s+\w+:\s*/;
|
|
18
|
+
const match = input.message.match(prefixPattern);
|
|
19
|
+
if (!match) {
|
|
20
|
+
return input.message;
|
|
21
|
+
}
|
|
22
|
+
// strip the prefix
|
|
23
|
+
return input.message.slice(match[0].length);
|
|
24
|
+
};
|
|
25
|
+
exports.asUnprefixedErrorMessage = asUnprefixedErrorMessage;
|
|
26
|
+
//# sourceMappingURL=asUnprefixedErrorMessage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"asUnprefixedErrorMessage.js","sourceRoot":"","sources":["../../../../src/domain.operations/askLambdaEndpoint/serde/asUnprefixedErrorMessage.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;GASG;AACI,MAAM,wBAAwB,GAAG,CAAC,KAExC,EAAU,EAAE;IACX,yCAAyC;IACzC,4FAA4F;IAC5F,MAAM,aAAa,GAAG,cAAc,CAAC;IACrC,MAAM,KAAK,GAAG,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;IAEjD,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,OAAO,KAAK,CAAC,OAAO,CAAC;IACvB,CAAC;IAED,mBAAmB;IACnB,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;AAC9C,CAAC,CAAC;AAdW,QAAA,wBAAwB,4BAcnC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { LambdaEndpoint } from '../../../domain.objects/LambdaEndpoint';
|
|
1
2
|
/**
|
|
2
3
|
* .what = parses lambda response payload and throws on error
|
|
3
4
|
* .why = orchestrator composes decode, parse, and error detection
|
|
@@ -9,7 +10,6 @@
|
|
|
9
10
|
export declare const getParsedResponse: <TResponse>(input: {
|
|
10
11
|
payload: Uint8Array | undefined;
|
|
11
12
|
functionError: string | undefined;
|
|
12
|
-
|
|
13
|
-
function: string;
|
|
13
|
+
endpoint: LambdaEndpoint;
|
|
14
14
|
exid: string | null;
|
|
15
15
|
}) => TResponse;
|
|
@@ -6,6 +6,7 @@ const LambdaEndpointError_1 = require("../../../domain.objects/LambdaEndpointErr
|
|
|
6
6
|
const getIsLambdaErrorResponse_1 = require("../error/getIsLambdaErrorResponse");
|
|
7
7
|
const getLambdaErrorMetadata_1 = require("../error/getLambdaErrorMetadata");
|
|
8
8
|
const getStackTraceString_1 = require("../error/getStackTraceString");
|
|
9
|
+
const asUnprefixedErrorMessage_1 = require("./asUnprefixedErrorMessage");
|
|
9
10
|
const getDecodedPayload_1 = require("./getDecodedPayload");
|
|
10
11
|
const getParsedJson_1 = require("./getParsedJson");
|
|
11
12
|
/**
|
|
@@ -20,8 +21,7 @@ const getParsedResponse = (input) => {
|
|
|
20
21
|
// validate payload exists
|
|
21
22
|
if (!input.payload) {
|
|
22
23
|
throw new LambdaEndpointError_1.LambdaEndpointError('lambda returned empty payload', {
|
|
23
|
-
|
|
24
|
-
function: input.function,
|
|
24
|
+
endpoint: input.endpoint,
|
|
25
25
|
exid: input.exid,
|
|
26
26
|
});
|
|
27
27
|
}
|
|
@@ -31,8 +31,7 @@ const getParsedResponse = (input) => {
|
|
|
31
31
|
const parseResult = (0, getParsedJson_1.getParsedJson)({ json: payloadString });
|
|
32
32
|
if (!parseResult.success) {
|
|
33
33
|
throw new LambdaEndpointError_1.LambdaEndpointError('lambda returned invalid json', {
|
|
34
|
-
|
|
35
|
-
function: input.function,
|
|
34
|
+
endpoint: input.endpoint,
|
|
36
35
|
exid: input.exid,
|
|
37
36
|
cause: parseResult.error,
|
|
38
37
|
});
|
|
@@ -43,9 +42,10 @@ const getParsedResponse = (input) => {
|
|
|
43
42
|
const err = parsed.error;
|
|
44
43
|
// ConstraintError = caller's fault, not lambda error (lambda succeeded)
|
|
45
44
|
if (err.class === 'ConstraintError') {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
45
|
+
// strip prefix to avoid double prefix (handler already prefixed the message)
|
|
46
|
+
const message = (0, asUnprefixedErrorMessage_1.asUnprefixedErrorMessage)({ message: err.message });
|
|
47
|
+
throw new helpful_errors_1.ConstraintError(message, {
|
|
48
|
+
endpoint: input.endpoint,
|
|
49
49
|
exid: input.exid,
|
|
50
50
|
causeMessage: err.cause,
|
|
51
51
|
details: err.details,
|
|
@@ -53,8 +53,7 @@ const getParsedResponse = (input) => {
|
|
|
53
53
|
}
|
|
54
54
|
// all other error classes = lambda invocation error
|
|
55
55
|
throw new LambdaEndpointError_1.LambdaEndpointError(err.message, {
|
|
56
|
-
|
|
57
|
-
function: input.function,
|
|
56
|
+
endpoint: input.endpoint,
|
|
58
57
|
exid: input.exid,
|
|
59
58
|
errorType: err.class,
|
|
60
59
|
causeMessage: err.cause,
|
|
@@ -69,9 +68,12 @@ const getParsedResponse = (input) => {
|
|
|
69
68
|
// .note = check both for backwards compat with handlers that use old error types
|
|
70
69
|
if (parsed.errorType === 'ConstraintError' ||
|
|
71
70
|
parsed.errorType === 'BadRequestError') {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
71
|
+
// strip prefix to avoid double prefix (handler already prefixed the message)
|
|
72
|
+
const message = (0, asUnprefixedErrorMessage_1.asUnprefixedErrorMessage)({
|
|
73
|
+
message: parsed.errorMessage,
|
|
74
|
+
});
|
|
75
|
+
throw new helpful_errors_1.ConstraintError(message, {
|
|
76
|
+
endpoint: input.endpoint,
|
|
75
77
|
exid: input.exid,
|
|
76
78
|
stackTrace,
|
|
77
79
|
...errorMeta,
|
|
@@ -79,8 +81,7 @@ const getParsedResponse = (input) => {
|
|
|
79
81
|
}
|
|
80
82
|
// all other error types = lambda invocation error
|
|
81
83
|
throw new LambdaEndpointError_1.LambdaEndpointError(parsed.errorMessage, {
|
|
82
|
-
|
|
83
|
-
function: input.function,
|
|
84
|
+
endpoint: input.endpoint,
|
|
84
85
|
exid: input.exid,
|
|
85
86
|
errorType: parsed.errorType,
|
|
86
87
|
stackTrace,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getParsedResponse.js","sourceRoot":"","sources":["../../../../src/domain.operations/askLambdaEndpoint/serde/getParsedResponse.ts"],"names":[],"mappings":";;;AAAA,mDAAiD;
|
|
1
|
+
{"version":3,"file":"getParsedResponse.js","sourceRoot":"","sources":["../../../../src/domain.operations/askLambdaEndpoint/serde/getParsedResponse.ts"],"names":[],"mappings":";;;AAAA,mDAAiD;AAGjD,qFAAkF;AAClF,gFAG2C;AAC3C,4EAAyE;AACzE,sEAAmE;AACnE,yEAAsE;AACtE,2DAAwD;AACxD,mDAAgD;AAEhD;;;;;;;GAOG;AACI,MAAM,iBAAiB,GA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ED;;;;;OAKG;IACH,OAAO,MAAmB,CAAC;AAC7B,CAAC,CAAC;AA9FW,QAAA,iBAAiB,qBA8F5B"}
|
|
@@ -2,11 +2,12 @@ import middy from '@middy/core';
|
|
|
2
2
|
import type { APIGatewayProxyEvent, APIGatewayProxyResult, Context } from 'aws-lambda';
|
|
3
3
|
import type { ContextLogTrail } from 'sdk-logs';
|
|
4
4
|
import type { ZodSchema } from 'zod';
|
|
5
|
+
import type { ContextAwsLambdaServer } from '../../../domain.objects/ContextAwsLambdaServer';
|
|
5
6
|
import type { IoLogTranslate } from '../middleware/genIoLoggerMiddleware';
|
|
6
7
|
import { type UnifiedApiGatewayEvent } from './middleware/genApiGatewayEventNormalizationMiddleware';
|
|
7
8
|
export interface CorsConfig {
|
|
8
9
|
/**
|
|
9
|
-
* .what = origins to accept for
|
|
10
|
+
* .what = origins to accept for cors
|
|
10
11
|
* .why = sets Access-Control-Allow-Origin header
|
|
11
12
|
*
|
|
12
13
|
* special:
|
|
@@ -23,7 +24,7 @@ export interface CorsConfig {
|
|
|
23
24
|
*/
|
|
24
25
|
credentials: boolean;
|
|
25
26
|
/**
|
|
26
|
-
* .what = headers allowed in
|
|
27
|
+
* .what = headers allowed in cors requests
|
|
27
28
|
* .why = sets Access-Control-Allow-Headers header
|
|
28
29
|
*
|
|
29
30
|
* defaults to 'content-type,authorization'
|
|
@@ -47,8 +48,8 @@ export type ForApiGatewayInput<TInput, TOutput> = {
|
|
|
47
48
|
cors?: CorsConfig;
|
|
48
49
|
deserialize?: {
|
|
49
50
|
/**
|
|
50
|
-
* .what = whether to deserialize
|
|
51
|
-
* .why = converts
|
|
51
|
+
* .what = whether to deserialize json body
|
|
52
|
+
* .why = converts json string body to object when content-type is application/json
|
|
52
53
|
*
|
|
53
54
|
* defaults to true; set to false for raw string input
|
|
54
55
|
*/
|
|
@@ -56,14 +57,20 @@ export type ForApiGatewayInput<TInput, TOutput> = {
|
|
|
56
57
|
};
|
|
57
58
|
};
|
|
58
59
|
/**
|
|
59
|
-
* .what =
|
|
60
|
-
* .why =
|
|
60
|
+
* .what = sdk contract type for forApiGateway context
|
|
61
|
+
* .why = exported for consumer type inference; the shared handler-side context
|
|
62
|
+
* ({ env?: EnvConfig; log? }) reused by genLambdaEndpoint + forApiGateway
|
|
63
|
+
*/
|
|
64
|
+
export type ForApiGatewayContext = ContextAwsLambdaServer;
|
|
65
|
+
/**
|
|
66
|
+
* .what = generates API Gateway lambda handler with http features
|
|
67
|
+
* .why = adds cors, security headers, error handler, body serialization, and validation
|
|
61
68
|
*
|
|
62
69
|
* follows simple-lambda-handlers createApiGatewayHandler pattern:
|
|
63
70
|
* - uses middy middleware chain
|
|
64
71
|
* - uses @middy/http-cors for dynamic origin match
|
|
65
72
|
* - uses @middy/http-security-headers for OWASP security headers
|
|
66
|
-
* - uses @middy/http-json-body-parser for
|
|
73
|
+
* - uses @middy/http-json-body-parser for json body parse
|
|
67
74
|
* - uses @middy/http-response-serializer for response serialization
|
|
68
75
|
*/
|
|
69
76
|
export declare const forApiGateway: <TInput, TOutput>(config: {
|
|
@@ -80,4 +87,4 @@ export declare const forApiGateway: <TInput, TOutput>(config: {
|
|
|
80
87
|
deserialize?: {
|
|
81
88
|
body: boolean;
|
|
82
89
|
};
|
|
83
|
-
}) => middy.MiddyfiedHandler<APIGatewayProxyEvent, APIGatewayProxyResult, Error, Context>;
|
|
90
|
+
}, context?: ContextAwsLambdaServer) => middy.MiddyfiedHandler<APIGatewayProxyEvent, APIGatewayProxyResult, Error, Context>;
|
|
@@ -10,6 +10,7 @@ const http_response_serializer_1 = __importDefault(require("@middy/http-response
|
|
|
10
10
|
const http_security_headers_1 = __importDefault(require("@middy/http-security-headers"));
|
|
11
11
|
const genConstraintErrorMiddleware_1 = require("../middleware/genConstraintErrorMiddleware");
|
|
12
12
|
const genInternalServiceErrorMiddleware_1 = require("../middleware/genInternalServiceErrorMiddleware");
|
|
13
|
+
const genIntrospectionMiddleware_1 = require("../middleware/genIntrospectionMiddleware");
|
|
13
14
|
const genIoLoggerMiddleware_1 = require("../middleware/genIoLoggerMiddleware");
|
|
14
15
|
const genTrailMiddleware_1 = require("../middleware/genTrailMiddleware");
|
|
15
16
|
const getValidatedOutput_1 = require("../middleware/getValidatedOutput");
|
|
@@ -36,22 +37,22 @@ const serializers = [
|
|
|
36
37
|
},
|
|
37
38
|
];
|
|
38
39
|
/**
|
|
39
|
-
* .what = generates API Gateway lambda handler with
|
|
40
|
-
* .why = adds
|
|
40
|
+
* .what = generates API Gateway lambda handler with http features
|
|
41
|
+
* .why = adds cors, security headers, error handler, body serialization, and validation
|
|
41
42
|
*
|
|
42
43
|
* follows simple-lambda-handlers createApiGatewayHandler pattern:
|
|
43
44
|
* - uses middy middleware chain
|
|
44
45
|
* - uses @middy/http-cors for dynamic origin match
|
|
45
46
|
* - uses @middy/http-security-headers for OWASP security headers
|
|
46
|
-
* - uses @middy/http-json-body-parser for
|
|
47
|
+
* - uses @middy/http-json-body-parser for json body parse
|
|
47
48
|
* - uses @middy/http-response-serializer for response serialization
|
|
48
49
|
*/
|
|
49
|
-
const forApiGateway = (config) => {
|
|
50
|
+
const forApiGateway = (config, context) => {
|
|
50
51
|
const deserialize = config.deserialize ?? { body: true };
|
|
51
52
|
// build logic wrapper that validates output and invokes user handler
|
|
52
|
-
const logic = async (event,
|
|
53
|
-
// get log from context (injected by trail middleware)
|
|
54
|
-
const log =
|
|
53
|
+
const logic = async (event, lambdaContext) => {
|
|
54
|
+
// get log from lambda context (injected by trail middleware)
|
|
55
|
+
const log = lambdaContext.log;
|
|
55
56
|
// invoke user handler with validated body and raw event
|
|
56
57
|
const response = await config.invoke({ event: event.body, rawEvent: event }, { log });
|
|
57
58
|
// validate output and return typed result
|
|
@@ -67,12 +68,13 @@ const forApiGateway = (config) => {
|
|
|
67
68
|
// middleware order matters:
|
|
68
69
|
// 1. error handlers (onError) - must be first to catch errors from all other middleware
|
|
69
70
|
// 2. io logger - logs input/output for debug
|
|
70
|
-
// 3. response serializer (onAfter) - serializes response body to
|
|
71
|
+
// 3. response serializer (onAfter) - serializes response body to json
|
|
71
72
|
// 4. cors (onAfter) - adds cors headers to response
|
|
72
73
|
// 5. security headers (onAfter) - adds security headers to response
|
|
73
74
|
// 6. event normalization (onBefore) - normalizes v1/v2 API Gateway events
|
|
74
75
|
// 7. trail (onBefore) - injects trail context
|
|
75
|
-
// 8.
|
|
76
|
+
// 8. introspection (onBefore) - intercepts introspect requests, returns schema
|
|
77
|
+
// 9. body validation (onBefore) - validates event.body against schema
|
|
76
78
|
const middlewares = [
|
|
77
79
|
(0, genConstraintErrorMiddleware_1.genConstraintErrorMiddleware)({ apiGateway: true }),
|
|
78
80
|
(0, genInternalServiceErrorMiddleware_1.genInternalServiceErrorMiddleware)({ apiGateway: true }),
|
|
@@ -87,6 +89,11 @@ const forApiGateway = (config) => {
|
|
|
87
89
|
}),
|
|
88
90
|
(0, genApiGatewayEventNormalizationMiddleware_1.genApiGatewayEventNormalizationMiddleware)({ parseBody: deserialize.body }),
|
|
89
91
|
(0, genTrailMiddleware_1.genTrailMiddleware)(),
|
|
92
|
+
(0, genIntrospectionMiddleware_1.genIntrospectionMiddleware)({
|
|
93
|
+
schema: config.schema,
|
|
94
|
+
env: context?.env,
|
|
95
|
+
apiGateway: true,
|
|
96
|
+
}),
|
|
90
97
|
(0, genZodBodyValidationMiddleware_1.genZodBodyValidationMiddleware)({ schema: config.schema.input }),
|
|
91
98
|
];
|
|
92
99
|
// note: type assertion needed because middleware transforms:
|
|
@@ -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;
|
|
1
|
+
{"version":3,"file":"genLambdaEndpoint.forApiGateway.js","sourceRoot":"","sources":["../../../../src/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EAAE,MAAM,CAAC,MAAM;YACrB,GAAG,EAAE,OAAO,EAAE,GAAG;YACjB,UAAU,EAAE,IAAI;SACjB,CAAC;QACF,IAAA,+DAA8B,EAAC,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;KAChE,CAAC;IAEF,6DAA6D;IAC7D,yEAAyE;IACzE,wEAAwE;IACxE,4EAA4E;IAC5E,OAAO,IAAA,cAAK,EACV,KAGmC,CACpC,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;AACrB,CAAC,CAAC;AA9FW,QAAA,aAAa,iBA8FxB"}
|
package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/getCorsOrigin.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* .what = transforms
|
|
3
|
-
* .why =
|
|
2
|
+
* .what = transforms cors origins config to header value with dynamic origin match
|
|
3
|
+
* .why = http spec only allows ONE origin in Access-Control-Allow-Origin header
|
|
4
4
|
*
|
|
5
5
|
* .how = matches request origin against allowed list:
|
|
6
6
|
* - '*' returns '*' (unless credentials, then echoes request origin)
|
|
7
7
|
* - string[] checks if request origin in list, echoes that origin if matched
|
|
8
|
-
* - no match returns null (no
|
|
8
|
+
* - no match returns null (no cors header should be set)
|
|
9
9
|
*/
|
|
10
10
|
export declare const getCorsOrigin: (input: {
|
|
11
11
|
origins: string | string[];
|
package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/getCorsOrigin.js
CHANGED
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getCorsOrigin = void 0;
|
|
4
4
|
/**
|
|
5
|
-
* .what = transforms
|
|
6
|
-
* .why =
|
|
5
|
+
* .what = transforms cors origins config to header value with dynamic origin match
|
|
6
|
+
* .why = http spec only allows ONE origin in Access-Control-Allow-Origin header
|
|
7
7
|
*
|
|
8
8
|
* .how = matches request origin against allowed list:
|
|
9
9
|
* - '*' returns '*' (unless credentials, then echoes request origin)
|
|
10
10
|
* - string[] checks if request origin in list, echoes that origin if matched
|
|
11
|
-
* - no match returns null (no
|
|
11
|
+
* - no match returns null (no cors header should be set)
|
|
12
12
|
*/
|
|
13
13
|
const getCorsOrigin = (input) => {
|
|
14
14
|
const { origins, requestOrigin, credentials } = input;
|
|
@@ -26,14 +26,14 @@ const getCorsOrigin = (input) => {
|
|
|
26
26
|
return origins;
|
|
27
27
|
}
|
|
28
28
|
// no request origin or no match - return configured origin anyway
|
|
29
|
-
// (may cause
|
|
29
|
+
// (may cause cors failure but that's the expected behavior)
|
|
30
30
|
return origins;
|
|
31
31
|
}
|
|
32
32
|
// array of origins: match against request origin
|
|
33
33
|
if (requestOrigin && origins.includes(requestOrigin)) {
|
|
34
34
|
return requestOrigin;
|
|
35
35
|
}
|
|
36
|
-
// no match - don't set
|
|
36
|
+
// no match - don't set cors header (return null, not empty string)
|
|
37
37
|
// note: if no requestOrigin provided, fall back to first origin for backwards compat
|
|
38
38
|
if (!requestOrigin && origins.length > 0) {
|
|
39
39
|
return origins[0];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { APIGatewayProxyEventV2 } from 'aws-lambda';
|
|
2
2
|
/**
|
|
3
|
-
* .what = type guard for
|
|
3
|
+
* .what = type guard for api gateway v2 (http api) events
|
|
4
4
|
* .why = enables detection of event format for middleware
|
|
5
5
|
*/
|
|
6
6
|
export declare const getIsV2ApiGatewayEvent: (event: unknown) => event is APIGatewayProxyEventV2;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getIsV2ApiGatewayEvent = void 0;
|
|
4
4
|
/**
|
|
5
|
-
* .what = type guard for
|
|
5
|
+
* .what = type guard for api gateway v2 (http api) events
|
|
6
6
|
* .why = enables detection of event format for middleware
|
|
7
7
|
*/
|
|
8
8
|
const getIsV2ApiGatewayEvent = (event) => {
|