sdk-aws-lambda 0.1.0 → 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 +45 -41
- 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
|
@@ -4,6 +4,83 @@ exports.genApiGatewayEventNormalizationMiddleware = void 0;
|
|
|
4
4
|
const helpful_errors_1 = require("helpful-errors");
|
|
5
5
|
const getIsV1ApiGatewayEvent_1 = require("../getIsV1ApiGatewayEvent");
|
|
6
6
|
const getIsV2ApiGatewayEvent_1 = require("../getIsV2ApiGatewayEvent");
|
|
7
|
+
/**
|
|
8
|
+
* .what = parses JSON body string to object
|
|
9
|
+
* .why = API Gateway sends body as string, handlers need object
|
|
10
|
+
*/
|
|
11
|
+
const getParsedApiGatewayBody = (input) => {
|
|
12
|
+
if (!input.body)
|
|
13
|
+
return null;
|
|
14
|
+
// decode base64 if needed
|
|
15
|
+
const decoded = input.isBase64Encoded
|
|
16
|
+
? Buffer.from(input.body, 'base64').toString('utf-8')
|
|
17
|
+
: input.body;
|
|
18
|
+
// parse json or return raw string
|
|
19
|
+
try {
|
|
20
|
+
return JSON.parse(decoded);
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
return decoded;
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* .what = convert v2 HTTP API event to unified format
|
|
28
|
+
* .why = isolates transformation logic from orchestrator
|
|
29
|
+
*/
|
|
30
|
+
const asUnifiedEventFromV2 = (input) => {
|
|
31
|
+
const body = input.parseBody
|
|
32
|
+
? getParsedApiGatewayBody({
|
|
33
|
+
body: input.event.body,
|
|
34
|
+
isBase64Encoded: input.event.isBase64Encoded,
|
|
35
|
+
})
|
|
36
|
+
: input.event.body;
|
|
37
|
+
return {
|
|
38
|
+
httpMethod: input.event.requestContext.http.method,
|
|
39
|
+
path: input.event.requestContext.http.path,
|
|
40
|
+
headers: input.event.headers,
|
|
41
|
+
queryStringParameters: input.event.queryStringParameters ?? null,
|
|
42
|
+
pathParameters: input.event.pathParameters ?? null,
|
|
43
|
+
body,
|
|
44
|
+
rawBody: input.event.body ?? null,
|
|
45
|
+
isBase64Encoded: input.event.isBase64Encoded,
|
|
46
|
+
requestContext: {
|
|
47
|
+
requestId: input.event.requestContext.requestId,
|
|
48
|
+
stage: input.event.requestContext.stage,
|
|
49
|
+
domainName: input.event.requestContext.domainName,
|
|
50
|
+
accountId: input.event.requestContext.accountId,
|
|
51
|
+
},
|
|
52
|
+
rawEvent: input.event,
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* .what = convert v1 REST API event to unified format
|
|
57
|
+
* .why = isolates transformation logic from orchestrator
|
|
58
|
+
*/
|
|
59
|
+
const asUnifiedEventFromV1 = (input) => {
|
|
60
|
+
const body = input.parseBody
|
|
61
|
+
? getParsedApiGatewayBody({
|
|
62
|
+
body: input.event.body,
|
|
63
|
+
isBase64Encoded: input.event.isBase64Encoded,
|
|
64
|
+
})
|
|
65
|
+
: input.event.body;
|
|
66
|
+
return {
|
|
67
|
+
httpMethod: input.event.httpMethod,
|
|
68
|
+
path: input.event.path,
|
|
69
|
+
headers: input.event.headers,
|
|
70
|
+
queryStringParameters: input.event.queryStringParameters ?? null,
|
|
71
|
+
pathParameters: input.event.pathParameters ?? null,
|
|
72
|
+
body,
|
|
73
|
+
rawBody: input.event.body ?? null,
|
|
74
|
+
isBase64Encoded: input.event.isBase64Encoded,
|
|
75
|
+
requestContext: {
|
|
76
|
+
requestId: input.event.requestContext.requestId,
|
|
77
|
+
stage: input.event.requestContext.stage,
|
|
78
|
+
domainName: input.event.requestContext.domainName,
|
|
79
|
+
accountId: input.event.requestContext.accountId,
|
|
80
|
+
},
|
|
81
|
+
rawEvent: input.event,
|
|
82
|
+
};
|
|
83
|
+
};
|
|
7
84
|
/**
|
|
8
85
|
* .what = converts v1/v2 API Gateway events to unified format
|
|
9
86
|
* .why = handlers work with consistent event shape regardless of API type
|
|
@@ -11,57 +88,23 @@ const getIsV2ApiGatewayEvent_1 = require("../getIsV2ApiGatewayEvent");
|
|
|
11
88
|
const genApiGatewayEventNormalizationMiddleware = (input) => {
|
|
12
89
|
const before = async (request) => {
|
|
13
90
|
const rawEvent = request.event;
|
|
14
|
-
//
|
|
91
|
+
// convert v2 HTTP API event to unified format
|
|
15
92
|
if ((0, getIsV2ApiGatewayEvent_1.getIsV2ApiGatewayEvent)(rawEvent)) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
: v2Event.body;
|
|
21
|
-
request.event = {
|
|
22
|
-
httpMethod: v2Event.requestContext.http.method,
|
|
23
|
-
path: v2Event.requestContext.http.path,
|
|
24
|
-
headers: v2Event.headers,
|
|
25
|
-
queryStringParameters: v2Event.queryStringParameters ?? null,
|
|
26
|
-
pathParameters: v2Event.pathParameters ?? null,
|
|
27
|
-
body,
|
|
28
|
-
rawBody: v2Event.body ?? null,
|
|
29
|
-
isBase64Encoded: v2Event.isBase64Encoded,
|
|
30
|
-
requestContext: {
|
|
31
|
-
requestId: v2Event.requestContext.requestId,
|
|
32
|
-
stage: v2Event.requestContext.stage,
|
|
33
|
-
domainName: v2Event.requestContext.domainName,
|
|
34
|
-
accountId: v2Event.requestContext.accountId,
|
|
35
|
-
},
|
|
36
|
-
rawEvent,
|
|
37
|
-
};
|
|
93
|
+
request.event = asUnifiedEventFromV2({
|
|
94
|
+
event: rawEvent,
|
|
95
|
+
parseBody: input.parseBody,
|
|
96
|
+
});
|
|
38
97
|
return;
|
|
39
98
|
}
|
|
99
|
+
// convert v1 REST API event to unified format
|
|
40
100
|
if ((0, getIsV1ApiGatewayEvent_1.getIsV1ApiGatewayEvent)(rawEvent)) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
: v1Event.body;
|
|
46
|
-
request.event = {
|
|
47
|
-
httpMethod: v1Event.httpMethod,
|
|
48
|
-
path: v1Event.path,
|
|
49
|
-
headers: v1Event.headers,
|
|
50
|
-
queryStringParameters: v1Event.queryStringParameters ?? null,
|
|
51
|
-
pathParameters: v1Event.pathParameters ?? null,
|
|
52
|
-
body,
|
|
53
|
-
rawBody: v1Event.body ?? null,
|
|
54
|
-
isBase64Encoded: v1Event.isBase64Encoded,
|
|
55
|
-
requestContext: {
|
|
56
|
-
requestId: v1Event.requestContext.requestId,
|
|
57
|
-
stage: v1Event.requestContext.stage,
|
|
58
|
-
domainName: v1Event.requestContext.domainName,
|
|
59
|
-
accountId: v1Event.requestContext.accountId,
|
|
60
|
-
},
|
|
61
|
-
rawEvent,
|
|
62
|
-
};
|
|
101
|
+
request.event = asUnifiedEventFromV1({
|
|
102
|
+
event: rawEvent,
|
|
103
|
+
parseBody: input.parseBody,
|
|
104
|
+
});
|
|
63
105
|
return;
|
|
64
106
|
}
|
|
107
|
+
// fail if neither v1 nor v2
|
|
65
108
|
throw new helpful_errors_1.MalfunctionError('event is neither v1 nor v2 API Gateway event', {
|
|
66
109
|
rawEvent,
|
|
67
110
|
});
|
|
@@ -69,22 +112,4 @@ const genApiGatewayEventNormalizationMiddleware = (input) => {
|
|
|
69
112
|
return { before };
|
|
70
113
|
};
|
|
71
114
|
exports.genApiGatewayEventNormalizationMiddleware = genApiGatewayEventNormalizationMiddleware;
|
|
72
|
-
/**
|
|
73
|
-
* .what = parses JSON body string to object
|
|
74
|
-
* .why = API Gateway sends body as string, handlers need object
|
|
75
|
-
*/
|
|
76
|
-
const parseBody = (body, isBase64Encoded) => {
|
|
77
|
-
if (!body)
|
|
78
|
-
return null;
|
|
79
|
-
const decoded = isBase64Encoded
|
|
80
|
-
? Buffer.from(body, 'base64').toString('utf-8')
|
|
81
|
-
: body;
|
|
82
|
-
try {
|
|
83
|
-
return JSON.parse(decoded);
|
|
84
|
-
}
|
|
85
|
-
catch {
|
|
86
|
-
// return raw string if not valid JSON
|
|
87
|
-
return decoded;
|
|
88
|
-
}
|
|
89
|
-
};
|
|
90
115
|
//# sourceMappingURL=genApiGatewayEventNormalizationMiddleware.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"genApiGatewayEventNormalizationMiddleware.js","sourceRoot":"","sources":["../../../../../src/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/middleware/genApiGatewayEventNormalizationMiddleware.ts"],"names":[],"mappings":";;;AAEA,mDAAkD;AAElD,sEAAmE;AACnE,sEAAmE;AAwBnE;;;GAGG;
|
|
1
|
+
{"version":3,"file":"genApiGatewayEventNormalizationMiddleware.js","sourceRoot":"","sources":["../../../../../src/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/middleware/genApiGatewayEventNormalizationMiddleware.ts"],"names":[],"mappings":"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"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import middy from '@middy/core';
|
|
2
2
|
import type { Context } from 'aws-lambda';
|
|
3
|
-
import type { ContextLogTrail
|
|
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
|
/**
|
|
7
8
|
* .what = wrapped payload format: event nested under `event` key with trail
|
|
@@ -48,11 +49,10 @@ export type GenLambdaEndpointInput<TInput, TOutput> = {
|
|
|
48
49
|
};
|
|
49
50
|
/**
|
|
50
51
|
* .what = sdk contract type for genLambdaEndpoint context
|
|
51
|
-
* .why = exported for consumer type inference
|
|
52
|
+
* .why = exported for consumer type inference; the shared handler-side context
|
|
53
|
+
* ({ env?: EnvConfig; log? }) reused by genLambdaEndpoint + forApiGateway
|
|
52
54
|
*/
|
|
53
|
-
export type GenLambdaEndpointContext =
|
|
54
|
-
log?: LogMethods;
|
|
55
|
-
};
|
|
55
|
+
export type GenLambdaEndpointContext = ContextAwsLambdaServer;
|
|
56
56
|
/**
|
|
57
57
|
* .what = generates a lambda handler with validation and trail context
|
|
58
58
|
* .why = standardizes handler creation with schema validation and observability
|
|
@@ -68,13 +68,11 @@ export type GenLambdaEndpointContext = {
|
|
|
68
68
|
* - trail middleware injects log with trail context
|
|
69
69
|
* - output validation via zod schema
|
|
70
70
|
*/
|
|
71
|
-
export declare const genLambdaEndpoint: <TInput, TOutput>(
|
|
71
|
+
export declare const genLambdaEndpoint: <TInput, TOutput>(input: {
|
|
72
72
|
schema: {
|
|
73
73
|
input: ZodSchema<TInput>;
|
|
74
74
|
output: ZodSchema<TOutput>;
|
|
75
75
|
};
|
|
76
76
|
invoke: EndpointOperation<TInput, TOutput>;
|
|
77
77
|
logTranslate?: IoLogTranslate;
|
|
78
|
-
},
|
|
79
|
-
log?: LogMethods;
|
|
80
|
-
}) => middy.MiddyfiedHandler<LambdaHandlerInput<TInput>, TOutput, Error, Context>;
|
|
78
|
+
}, context?: ContextAwsLambdaServer) => middy.MiddyfiedHandler<LambdaHandlerInput<TInput>, TOutput, Error, Context>;
|
|
@@ -7,6 +7,7 @@ exports.genLambdaEndpoint = void 0;
|
|
|
7
7
|
const core_1 = __importDefault(require("@middy/core"));
|
|
8
8
|
const genConstraintErrorMiddleware_1 = require("../middleware/genConstraintErrorMiddleware");
|
|
9
9
|
const genInternalServiceErrorMiddleware_1 = require("../middleware/genInternalServiceErrorMiddleware");
|
|
10
|
+
const genIntrospectionMiddleware_1 = require("../middleware/genIntrospectionMiddleware");
|
|
10
11
|
const genIoLoggerMiddleware_1 = require("../middleware/genIoLoggerMiddleware");
|
|
11
12
|
const genTrailMiddleware_1 = require("../middleware/genTrailMiddleware");
|
|
12
13
|
const getValidatedOutput_1 = require("../middleware/getValidatedOutput");
|
|
@@ -26,27 +27,29 @@ const genZodEventValidationMiddleware_1 = require("./middleware/genZodEventValid
|
|
|
26
27
|
* - trail middleware injects log with trail context
|
|
27
28
|
* - output validation via zod schema
|
|
28
29
|
*/
|
|
29
|
-
const genLambdaEndpoint = (
|
|
30
|
+
const genLambdaEndpoint = (input, context) => {
|
|
30
31
|
// build logic that invokes user handler and validates output
|
|
31
|
-
const logic = async (event,
|
|
32
|
-
// get log from context (injected by trail middleware)
|
|
33
|
-
const log =
|
|
32
|
+
const logic = async (event, lambdaContext) => {
|
|
33
|
+
// get log from lambda context (injected by trail middleware)
|
|
34
|
+
const log = lambdaContext.log;
|
|
34
35
|
// invoke user handler
|
|
35
|
-
const response = await
|
|
36
|
+
const response = await input.invoke({ event }, { log });
|
|
36
37
|
// validate output and return typed result
|
|
37
|
-
return (0, getValidatedOutput_1.getValidatedOutput)({ response, schema:
|
|
38
|
+
return (0, getValidatedOutput_1.getValidatedOutput)({ response, schema: input.schema.output });
|
|
38
39
|
};
|
|
39
40
|
// middleware order matters:
|
|
40
41
|
// 1. error handlers (onError) - must be first to catch errors from all other middleware
|
|
41
|
-
// 2.
|
|
42
|
-
// 3.
|
|
43
|
-
// 4.
|
|
42
|
+
// 2. trail (onBefore) - injects trail context (must be early so isContempCaller is set for error handlers)
|
|
43
|
+
// 3. io logger - logs input/output for debug
|
|
44
|
+
// 4. introspection (onBefore) - intercepts introspect requests, returns schema
|
|
45
|
+
// 5. validation (onBefore) - validates event against schema
|
|
44
46
|
const middlewares = [
|
|
45
47
|
(0, genConstraintErrorMiddleware_1.genConstraintErrorMiddleware)(),
|
|
46
48
|
(0, genInternalServiceErrorMiddleware_1.genInternalServiceErrorMiddleware)(),
|
|
47
|
-
(0, genIoLoggerMiddleware_1.genIoLoggerMiddleware)({ logTranslate: config.logTranslate }),
|
|
48
49
|
(0, genTrailMiddleware_1.genTrailMiddleware)(),
|
|
49
|
-
(0,
|
|
50
|
+
(0, genIoLoggerMiddleware_1.genIoLoggerMiddleware)({ logTranslate: input.logTranslate }),
|
|
51
|
+
(0, genIntrospectionMiddleware_1.genIntrospectionMiddleware)({ schema: input.schema, env: context?.env }),
|
|
52
|
+
(0, genZodEventValidationMiddleware_1.genZodEventValidationMiddleware)({ schema: input.schema.input }),
|
|
50
53
|
];
|
|
51
54
|
/**
|
|
52
55
|
* .as = assertion needed because middleware transforms LambdaHandlerInput<TInput> to TInput
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"genLambdaEndpoint.forAskEndpoint.js","sourceRoot":"","sources":["../../../../src/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forAskEndpoint/genLambdaEndpoint.forAskEndpoint.ts"],"names":[],"mappings":";;;;;;AAAA,uDAAgC;
|
|
1
|
+
{"version":3,"file":"genLambdaEndpoint.forAskEndpoint.js","sourceRoot":"","sources":["../../../../src/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forAskEndpoint/genLambdaEndpoint.forAskEndpoint.ts"],"names":[],"mappings":";;;;;;AAAA,uDAAgC;AAMhC,6FAA0F;AAC1F,uGAAoG;AACpG,yFAAsF;AAEtF,+EAA4E;AAC5E,yEAAsE;AACtE,yEAAsE;AACtE,kGAA+F;AAsD/F;;;;;;;;;;;;;;GAcG;AACI,MAAM,iBAAiB,GAAG,CAC/B,KAOC,EACD,OAAgC,EAMhC,EAAE;IACF,6DAA6D;IAC7D,MAAM,KAAK,GAAG,KAAK,EACjB,KAAa,EACb,aAAsB,EACJ,EAAE;QACpB,6DAA6D;QAC7D,MAAM,GAAG,GAAI,aAA4C,CAAC,GAAG,CAAC;QAE9D,sBAAsB;QACtB,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,GAAG,EAAE,CAAC,CAAC;QAExD,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,2GAA2G;IAC3G,6CAA6C;IAC7C,+EAA+E;IAC/E,4DAA4D;IAC5D,MAAM,WAAW,GAAG;QAClB,IAAA,2DAA4B,GAAE;QAC9B,IAAA,qEAAiC,GAAE;QACnC,IAAA,uCAAkB,GAAE;QACpB,IAAA,6CAAqB,EAAC,EAAE,YAAY,EAAE,KAAK,CAAC,YAAY,EAAE,CAAC;QAC3D,IAAA,uDAA0B,EAAC,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC;QACvE,IAAA,iEAA+B,EAAC,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;KAChE,CAAC;IAEF;;;;OAIG;IACH,OAAO,IAAA,cAAK,EACV,KAGqB,CACtB,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;AACrB,CAAC,CAAC;AAzDW,QAAA,iBAAiB,qBAyD5B"}
|
|
@@ -32,7 +32,7 @@ const genConstraintErrorMiddleware = (opts) => {
|
|
|
32
32
|
const body = isContempCaller
|
|
33
33
|
? (0, getErrorResponseBody_1.getErrorResponseBodyContemp)({ error, errorClass: 'ConstraintError' })
|
|
34
34
|
: (0, getErrorResponseBody_1.getErrorResponseBodyAncient)({ error, errorType: 'BadRequestError' });
|
|
35
|
-
// for
|
|
35
|
+
// for api gateway: return http response
|
|
36
36
|
if (opts?.apiGateway) {
|
|
37
37
|
/**
|
|
38
38
|
* .as = middy types request.response as unknown, but we set it to ApiGatewayResponse
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type middy from '@middy/core';
|
|
2
|
+
import type { ZodType } from 'zod';
|
|
3
|
+
import type { EnvConfig } from '../../../domain.objects/ContextAwsLambdaServer';
|
|
4
|
+
/**
|
|
5
|
+
* .what = middleware that intercepts introspection requests
|
|
6
|
+
* .why = enables runtime schema discovery for sdk generation
|
|
7
|
+
*
|
|
8
|
+
* behavior:
|
|
9
|
+
* - if payload is { introspect: 'schema' } and env.access === 'prep': return schema
|
|
10
|
+
* - if payload is { introspect: 'schema' } and env.access !== 'prep': fail fast
|
|
11
|
+
* - otherwise: pass through to handler
|
|
12
|
+
*/
|
|
13
|
+
export declare const genIntrospectionMiddleware: <TInput, TOutput>(opts: {
|
|
14
|
+
schema: {
|
|
15
|
+
input: ZodType<TInput>;
|
|
16
|
+
output: ZodType<TOutput>;
|
|
17
|
+
};
|
|
18
|
+
env?: EnvConfig;
|
|
19
|
+
apiGateway?: boolean;
|
|
20
|
+
}) => {
|
|
21
|
+
before: middy.MiddlewareFn<any, any>;
|
|
22
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { JSONSchema } from 'zod/v4/core/json-schema';
|
|
3
|
+
/**
|
|
4
|
+
* .what = convert zod schema to JSON schema
|
|
5
|
+
* .why = encapsulates zod api for future error handler if needed
|
|
6
|
+
*/
|
|
7
|
+
export declare const getJsonSchemaFromZod: <T extends z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>(schema: T) => JSONSchema;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getJsonSchemaFromZod = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
/**
|
|
6
|
+
* .what = convert zod schema to JSON schema
|
|
7
|
+
* .why = encapsulates zod api for future error handler if needed
|
|
8
|
+
*/
|
|
9
|
+
const getJsonSchemaFromZod = (schema) => {
|
|
10
|
+
return zod_1.z.toJSONSchema(schema);
|
|
11
|
+
};
|
|
12
|
+
exports.getJsonSchemaFromZod = getJsonSchemaFromZod;
|
|
13
|
+
//# sourceMappingURL=genIntrospectionMiddleware.getJsonSchemaFromZod.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"genIntrospectionMiddleware.getJsonSchemaFromZod.js","sourceRoot":"","sources":["../../../../src/domain.operations/genLambdaEndpoint/middleware/genIntrospectionMiddleware.getJsonSchemaFromZod.ts"],"names":[],"mappings":";;;AAAA,6BAAwB;AAGxB;;;GAGG;AACI,MAAM,oBAAoB,GAAG,CAClC,MAAS,EACG,EAAE;IACd,OAAO,OAAC,CAAC,YAAY,CAAC,MAAM,CAAe,CAAC;AAC9C,CAAC,CAAC;AAJW,QAAA,oBAAoB,wBAI/B"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isIntrospectionPayload = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* .what = detect if payload requests schema introspection
|
|
6
|
+
* .why = enables middleware to intercept introspection requests before handler
|
|
7
|
+
*/
|
|
8
|
+
const isIntrospectionPayload = (payload) => {
|
|
9
|
+
if (typeof payload !== 'object' || payload === null)
|
|
10
|
+
return false;
|
|
11
|
+
if (!('introspect' in payload))
|
|
12
|
+
return false;
|
|
13
|
+
return payload.introspect === 'schema';
|
|
14
|
+
};
|
|
15
|
+
exports.isIntrospectionPayload = isIntrospectionPayload;
|
|
16
|
+
//# sourceMappingURL=genIntrospectionMiddleware.isIntrospectionPayload.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"genIntrospectionMiddleware.isIntrospectionPayload.js","sourceRoot":"","sources":["../../../../src/domain.operations/genLambdaEndpoint/middleware/genIntrospectionMiddleware.isIntrospectionPayload.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACI,MAAM,sBAAsB,GAAG,CAAC,OAAgB,EAAW,EAAE;IAClE,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,KAAK,IAAI;QAAE,OAAO,KAAK,CAAC;IAClE,IAAI,CAAC,CAAC,YAAY,IAAI,OAAO,CAAC;QAAE,OAAO,KAAK,CAAC;IAC7C,OAAQ,OAAmC,CAAC,UAAU,KAAK,QAAQ,CAAC;AACtE,CAAC,CAAC;AAJW,QAAA,sBAAsB,0BAIjC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.genIntrospectionMiddleware = void 0;
|
|
4
|
+
const helpful_errors_1 = require("helpful-errors");
|
|
5
|
+
const genIntrospectionMiddleware_getJsonSchemaFromZod_1 = require("./genIntrospectionMiddleware.getJsonSchemaFromZod");
|
|
6
|
+
const genIntrospectionMiddleware_isIntrospectionPayload_1 = require("./genIntrospectionMiddleware.isIntrospectionPayload");
|
|
7
|
+
/**
|
|
8
|
+
* .what = middleware that intercepts introspection requests
|
|
9
|
+
* .why = enables runtime schema discovery for sdk generation
|
|
10
|
+
*
|
|
11
|
+
* behavior:
|
|
12
|
+
* - if payload is { introspect: 'schema' } and env.access === 'prep': return schema
|
|
13
|
+
* - if payload is { introspect: 'schema' } and env.access !== 'prep': fail fast
|
|
14
|
+
* - otherwise: pass through to handler
|
|
15
|
+
*/
|
|
16
|
+
const genIntrospectionMiddleware = (opts) => {
|
|
17
|
+
const before = async (request) => {
|
|
18
|
+
// extract payload - for API Gateway, body is already parsed by httpJsonBodyParser
|
|
19
|
+
const payload = opts.apiGateway ? request.event?.body : request.event;
|
|
20
|
+
// check if introspection request
|
|
21
|
+
if (!(0, genIntrospectionMiddleware_isIntrospectionPayload_1.isIntrospectionPayload)(payload))
|
|
22
|
+
return;
|
|
23
|
+
// extract env from config
|
|
24
|
+
const env = typeof opts.env === 'function' ? await opts.env() : opts.env;
|
|
25
|
+
// fail fast if env not provided
|
|
26
|
+
if (!env) {
|
|
27
|
+
throw new helpful_errors_1.ConstraintError('introspection requires env.access context but env was not provided to handler', { hint: 'pass env config to genLambdaEndpoint' });
|
|
28
|
+
}
|
|
29
|
+
// fail fast if not prep
|
|
30
|
+
if (env.access !== 'prep') {
|
|
31
|
+
throw new helpful_errors_1.ConstraintError(`introspection is only available in prep environment, current: ${env.access}`, { env, access: env.access });
|
|
32
|
+
}
|
|
33
|
+
// build schema response
|
|
34
|
+
const schema = {
|
|
35
|
+
input: (0, genIntrospectionMiddleware_getJsonSchemaFromZod_1.getJsonSchemaFromZod)(opts.schema.input),
|
|
36
|
+
output: (0, genIntrospectionMiddleware_getJsonSchemaFromZod_1.getJsonSchemaFromZod)(opts.schema.output),
|
|
37
|
+
};
|
|
38
|
+
// set response to short-circuit middleware chain
|
|
39
|
+
if (opts.apiGateway) {
|
|
40
|
+
request.response = {
|
|
41
|
+
statusCode: 200,
|
|
42
|
+
body: JSON.stringify(schema),
|
|
43
|
+
headers: { 'Content-Type': 'application/json' },
|
|
44
|
+
};
|
|
45
|
+
return request.response;
|
|
46
|
+
}
|
|
47
|
+
request.response = schema;
|
|
48
|
+
return request.response;
|
|
49
|
+
};
|
|
50
|
+
return { before };
|
|
51
|
+
};
|
|
52
|
+
exports.genIntrospectionMiddleware = genIntrospectionMiddleware;
|
|
53
|
+
//# sourceMappingURL=genIntrospectionMiddleware.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"genIntrospectionMiddleware.js","sourceRoot":"","sources":["../../../../src/domain.operations/genLambdaEndpoint/middleware/genIntrospectionMiddleware.ts"],"names":[],"mappings":";;;AACA,mDAAiD;AAMjD,uHAAyF;AACzF,2HAA6F;AAE7F;;;;;;;;GAQG;AACI,MAAM,0BAA0B,GAAG,CAAkB,IAO3D,EAEC,EAAE;IACF,MAAM,MAAM,GAAiC,KAAK,EAAE,OAAO,EAAE,EAAE;QAC7D,kFAAkF;QAClF,MAAM,OAAO,GAAG,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC;QAEtE,iCAAiC;QACjC,IAAI,CAAC,IAAA,0EAAsB,EAAC,OAAO,CAAC;YAAE,OAAO;QAE7C,0BAA0B;QAC1B,MAAM,GAAG,GAAG,OAAO,IAAI,CAAC,GAAG,KAAK,UAAU,CAAC,CAAC,CAAC,MAAM,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC;QAEzE,gCAAgC;QAChC,IAAI,CAAC,GAAG,EAAE,CAAC;YACT,MAAM,IAAI,gCAAe,CACvB,+EAA+E,EAC/E,EAAE,IAAI,EAAE,sCAAsC,EAAE,CACjD,CAAC;QACJ,CAAC;QAED,wBAAwB;QACxB,IAAI,GAAG,CAAC,MAAM,KAAK,MAAM,EAAE,CAAC;YAC1B,MAAM,IAAI,gCAAe,CACvB,iEAAiE,GAAG,CAAC,MAAM,EAAE,EAC7E,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,CAC5B,CAAC;QACJ,CAAC;QAED,wBAAwB;QACxB,MAAM,MAAM,GAAyB;YACnC,KAAK,EAAE,IAAA,sEAAoB,EAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC;YAC9C,MAAM,EAAE,IAAA,sEAAoB,EAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC;SACjD,CAAC;QAEF,iDAAiD;QACjD,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;YACpB,OAAO,CAAC,QAAQ,GAAG;gBACjB,UAAU,EAAE,GAAG;gBACf,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC;gBAC5B,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE;aAC1B,CAAC;YACxB,OAAO,OAAO,CAAC,QAAQ,CAAC;QAC1B,CAAC;QAED,OAAO,CAAC,QAAQ,GAAG,MAAM,CAAC;QAC1B,OAAO,OAAO,CAAC,QAAQ,CAAC;IAC1B,CAAC,CAAC;IAEF,OAAO,EAAE,MAAM,EAAE,CAAC;AACpB,CAAC,CAAC;AAzDW,QAAA,0BAA0B,8BAyDrC"}
|
|
@@ -32,7 +32,7 @@ const genTrailMiddleware = () => {
|
|
|
32
32
|
});
|
|
33
33
|
// unwrap event (if wrapped format)
|
|
34
34
|
request.event = unwrappedEvent;
|
|
35
|
-
// inject log and
|
|
35
|
+
// inject log and caller version flag into context
|
|
36
36
|
const contextBefore = (request.context ?? {});
|
|
37
37
|
/**
|
|
38
38
|
* .as = middy types request.context as aws-lambda Context, but we extend
|
|
@@ -6,7 +6,7 @@ export interface ValidationErrorMetadata {
|
|
|
6
6
|
}
|
|
7
7
|
/**
|
|
8
8
|
* .what = transforms zod validation error into ConstraintError
|
|
9
|
-
* .why =
|
|
9
|
+
* .why = callers need friendly error messages for invalid input
|
|
10
10
|
*/
|
|
11
11
|
export declare const getValidationError: (input: {
|
|
12
12
|
error: ZodError;
|
|
@@ -3,15 +3,23 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.getValidationError = void 0;
|
|
4
4
|
const helpful_errors_1 = require("helpful-errors");
|
|
5
5
|
const getZodIssuesSummary_1 = require("./getZodIssuesSummary");
|
|
6
|
+
/**
|
|
7
|
+
* .what = format issues summary for error message
|
|
8
|
+
* .why = extract message format from orchestrator
|
|
9
|
+
*/
|
|
10
|
+
const getIssuesMessage = (input) => {
|
|
11
|
+
return input.issues
|
|
12
|
+
.map((issue) => `${issue.path}: ${issue.message}`)
|
|
13
|
+
.join('; ');
|
|
14
|
+
};
|
|
6
15
|
/**
|
|
7
16
|
* .what = transforms zod validation error into ConstraintError
|
|
8
|
-
* .why =
|
|
17
|
+
* .why = callers need friendly error messages for invalid input
|
|
9
18
|
*/
|
|
10
19
|
const getValidationError = (input) => {
|
|
11
20
|
const issues = (0, getZodIssuesSummary_1.getZodIssuesSummary)({ issues: input.error.issues });
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
});
|
|
21
|
+
const issuesMessage = getIssuesMessage({ issues });
|
|
22
|
+
return new helpful_errors_1.ConstraintError(`validation failed: ${issuesMessage}`, { issues });
|
|
15
23
|
};
|
|
16
24
|
exports.getValidationError = getValidationError;
|
|
17
25
|
//# sourceMappingURL=getValidationError.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getValidationError.js","sourceRoot":"","sources":["../../../../src/domain.operations/genLambdaEndpoint/middleware/getValidationError.ts"],"names":[],"mappings":";;;AAAA,mDAAiD;AAGjD,+DAG+B;AAM/B;;;GAGG;AACI,MAAM,kBAAkB,GAAG,CAAC,KAElC,EAA4C,EAAE;IAC7C,MAAM,MAAM,GAAG,IAAA,yCAAmB,EAAC,EAAE,MAAM,EAAE,KAAK,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"getValidationError.js","sourceRoot":"","sources":["../../../../src/domain.operations/genLambdaEndpoint/middleware/getValidationError.ts"],"names":[],"mappings":";;;AAAA,mDAAiD;AAGjD,+DAG+B;AAM/B;;;GAGG;AACH,MAAM,gBAAgB,GAAG,CAAC,KAAoC,EAAU,EAAE;IACxE,OAAO,KAAK,CAAC,MAAM;SAChB,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,GAAG,KAAK,CAAC,IAAI,KAAK,KAAK,CAAC,OAAO,EAAE,CAAC;SACjD,IAAI,CAAC,IAAI,CAAC,CAAC;AAChB,CAAC,CAAC;AAEF;;;GAGG;AACI,MAAM,kBAAkB,GAAG,CAAC,KAElC,EAA4C,EAAE;IAC7C,MAAM,MAAM,GAAG,IAAA,yCAAmB,EAAC,EAAE,MAAM,EAAE,KAAK,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC;IACnE,MAAM,aAAa,GAAG,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC;IAEnD,OAAO,IAAI,gCAAe,CACxB,sBAAsB,aAAa,EAAE,EACrC,EAAE,MAAM,EAAE,CACX,CAAC;AACJ,CAAC,CAAC;AAVW,QAAA,kBAAkB,sBAU7B"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { ContextAwsLambdaCaller } from '../../domain.objects/ContextAwsLambdaCaller';
|
|
2
|
+
import type { LambdaEndpointSchema } from '../../domain.objects/LambdaEndpointSchema';
|
|
3
|
+
/**
|
|
4
|
+
* .what = get all lambda contracts for a service
|
|
5
|
+
* .why = enables runtime schema discovery for sdk generation
|
|
6
|
+
*
|
|
7
|
+
* behavior:
|
|
8
|
+
* - lists all lambda endpoints by service+access prefix
|
|
9
|
+
* - introspects each via getOneLambdaContract
|
|
10
|
+
* - all-or-none: if any endpoint does not support introspection, the whole
|
|
11
|
+
* batch fails loud (a partial contract set would generate a broken sdk)
|
|
12
|
+
* - returns as record keyed by bare function name (endpoint.function)
|
|
13
|
+
*
|
|
14
|
+
* .throws LambdaServiceNotFoundError — no endpoints found for service
|
|
15
|
+
* .throws LambdaIntrospectionBlockedError — introspection blocked in prod/test
|
|
16
|
+
* .throws LambdaIntrospectionNotSupportedError — an endpoint in the service does
|
|
17
|
+
* not support introspection (named in the error); the batch is all-or-none
|
|
18
|
+
*/
|
|
19
|
+
export declare const getAllLambdaContracts: (input: {
|
|
20
|
+
which: {
|
|
21
|
+
service: string;
|
|
22
|
+
};
|
|
23
|
+
}, context: ContextAwsLambdaCaller) => Promise<Record<string, LambdaEndpointSchema>>;
|
|
24
|
+
/**
|
|
25
|
+
* .what = input type for getAllLambdaContracts
|
|
26
|
+
* .why = exported for sdk consumers
|
|
27
|
+
*/
|
|
28
|
+
export type GetAllLambdaContractsInput = Parameters<typeof getAllLambdaContracts>[0];
|
|
29
|
+
/**
|
|
30
|
+
* .what = context type for getAllLambdaContracts
|
|
31
|
+
* .why = exported for sdk consumers
|
|
32
|
+
*/
|
|
33
|
+
export type GetAllLambdaContractsContext = Parameters<typeof getAllLambdaContracts>[1];
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.getAllLambdaContracts = void 0;
|
|
27
|
+
const LambdaIntrospectionBlockedError_1 = require("../../domain.objects/LambdaIntrospectionBlockedError");
|
|
28
|
+
const LambdaServiceNotFoundError_1 = require("../../domain.objects/LambdaServiceNotFoundError");
|
|
29
|
+
const asLambdaEndpoint_1 = require("../asLambdaEndpoint/asLambdaEndpoint");
|
|
30
|
+
const getOneLambdaContract_1 = require("../getOneLambdaContract/getOneLambdaContract");
|
|
31
|
+
const asContractRecord_1 = require("./lambdaContract/asContractRecord");
|
|
32
|
+
const getAllLambdaFunctionsByPrefix_1 = require("./lambdaFunction/getAllLambdaFunctionsByPrefix");
|
|
33
|
+
/**
|
|
34
|
+
* .what = get all lambda contracts for a service
|
|
35
|
+
* .why = enables runtime schema discovery for sdk generation
|
|
36
|
+
*
|
|
37
|
+
* behavior:
|
|
38
|
+
* - lists all lambda endpoints by service+access prefix
|
|
39
|
+
* - introspects each via getOneLambdaContract
|
|
40
|
+
* - all-or-none: if any endpoint does not support introspection, the whole
|
|
41
|
+
* batch fails loud (a partial contract set would generate a broken sdk)
|
|
42
|
+
* - returns as record keyed by bare function name (endpoint.function)
|
|
43
|
+
*
|
|
44
|
+
* .throws LambdaServiceNotFoundError — no endpoints found for service
|
|
45
|
+
* .throws LambdaIntrospectionBlockedError — introspection blocked in prod/test
|
|
46
|
+
* .throws LambdaIntrospectionNotSupportedError — an endpoint in the service does
|
|
47
|
+
* not support introspection (named in the error); the batch is all-or-none
|
|
48
|
+
*/
|
|
49
|
+
const getAllLambdaContracts = async (input, context) => {
|
|
50
|
+
// fail fast if introspection is blocked: only prep exposes schemas
|
|
51
|
+
// (gate up front so no request is made and no schema can leak)
|
|
52
|
+
if (context.env.access !== 'prep') {
|
|
53
|
+
throw new LambdaIntrospectionBlockedError_1.LambdaIntrospectionBlockedError(`introspection is only available in prep environment, got: ${context.env.access}`, { service: input.which.service, access: context.env.access });
|
|
54
|
+
}
|
|
55
|
+
// build prefix from service + access
|
|
56
|
+
const prefix = `${input.which.service}-${context.env.access}-`;
|
|
57
|
+
// get or create LambdaClient (genLambdaSdk always returns valid client)
|
|
58
|
+
const sdkLambda = context.aws?.lambda?.sdk ??
|
|
59
|
+
(await Promise.resolve().then(() => __importStar(require('../../access/sdks/lambda/genLambdaSdk'))).then((m) => m.genLambdaSdk({ env: { region: context.env.region } })));
|
|
60
|
+
// get all endpoint slugs by prefix
|
|
61
|
+
const slugs = await (0, getAllLambdaFunctionsByPrefix_1.getAllLambdaFunctionsByPrefix)({ prefix }, { sdkLambda });
|
|
62
|
+
// throw if no endpoints found
|
|
63
|
+
if (slugs.length === 0) {
|
|
64
|
+
throw new LambdaServiceNotFoundError_1.LambdaServiceNotFoundError(`no lambda functions found for service: ${input.which.service}`, { service: input.which.service, prefix });
|
|
65
|
+
}
|
|
66
|
+
// log the discovered endpoints for observability
|
|
67
|
+
context.log.debug('getAllLambdaContracts.discovered', {
|
|
68
|
+
service: input.which.service,
|
|
69
|
+
count: slugs.length,
|
|
70
|
+
});
|
|
71
|
+
// reuse the resolved sdk so getOneLambdaContract does not rebuild it per call
|
|
72
|
+
const contextWithSdk = { ...context, aws: { lambda: { sdk: sdkLambda } } };
|
|
73
|
+
// introspect each endpoint in parallel via getOneLambdaContract (build on getOne)
|
|
74
|
+
// all-or-none: an unsupported endpoint rejects here and aborts the batch
|
|
75
|
+
const entries = await Promise.all(slugs.map(async (slug) => {
|
|
76
|
+
const endpoint = (0, asLambdaEndpoint_1.asLambdaEndpoint)({ slug });
|
|
77
|
+
const schema = await (0, getOneLambdaContract_1.getOneLambdaContract)({
|
|
78
|
+
which: {
|
|
79
|
+
service: endpoint.service,
|
|
80
|
+
function: endpoint.function,
|
|
81
|
+
},
|
|
82
|
+
}, contextWithSdk);
|
|
83
|
+
return [endpoint.function, schema];
|
|
84
|
+
}));
|
|
85
|
+
// assemble record keyed by bare function name
|
|
86
|
+
return (0, asContractRecord_1.asContractRecord)(entries);
|
|
87
|
+
};
|
|
88
|
+
exports.getAllLambdaContracts = getAllLambdaContracts;
|
|
89
|
+
//# sourceMappingURL=getAllLambdaContracts.js.map
|