ag-common 0.0.184 → 0.0.185
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.
|
@@ -3,17 +3,19 @@ import { Construct } from 'constructs';
|
|
|
3
3
|
import { aws_certificatemanager as certmgr, aws_route53 as route53 } from 'aws-cdk-lib';
|
|
4
4
|
import { TokenAuthorizer } from 'aws-cdk-lib/aws-apigateway/lib/authorizers/lambda';
|
|
5
5
|
export declare const openApiImpl: (p: {
|
|
6
|
-
schema: unknown;
|
|
7
6
|
stack: Construct;
|
|
7
|
+
/**
|
|
8
|
+
* pass in generated openapi file
|
|
9
|
+
* eg schema: require('common/openapi.generated').default;
|
|
10
|
+
*/
|
|
11
|
+
schema: unknown;
|
|
8
12
|
NODE_ENV: string;
|
|
9
|
-
baseUrl: string;
|
|
10
13
|
endpointsBase: string;
|
|
11
14
|
/**
|
|
12
15
|
* 'default' will be applied to all functions
|
|
13
16
|
*/
|
|
14
17
|
lambdaConfig: ILambdaConfigs;
|
|
15
18
|
certificate: certmgr.ICertificate;
|
|
16
|
-
hostedZone: route53.IHostedZone;
|
|
17
19
|
shortStackName: string;
|
|
18
20
|
/**
|
|
19
21
|
* defaults:
|
|
@@ -28,4 +30,10 @@ export declare const openApiImpl: (p: {
|
|
|
28
30
|
* dictionary of named authorizer functions. these names are to be used in the lambdaConfig param
|
|
29
31
|
*/
|
|
30
32
|
authorizers?: Record<string, TokenAuthorizer>;
|
|
33
|
+
hostedZone: route53.IHostedZone;
|
|
34
|
+
/**
|
|
35
|
+
* A record will be created in hosted zone for the apigw on this path. if undefined, record wont be created
|
|
36
|
+
* eg api.mydomain.com
|
|
37
|
+
*/
|
|
38
|
+
apiUrl?: string;
|
|
31
39
|
}) => void;
|
|
@@ -11,26 +11,28 @@ const getPaths = (schema) => Object.entries(schema.paths).map(([fullPath, verbs]
|
|
|
11
11
|
pathList: fullPath.split('/').filter((s) => s),
|
|
12
12
|
verbs: Object.keys(verbs),
|
|
13
13
|
}));
|
|
14
|
-
const setUpApiGw = ({ stack, NODE_ENV,
|
|
14
|
+
const setUpApiGw = ({ stack, NODE_ENV, certificate, hostedZone, shortStackName, apiUrl, cors = {
|
|
15
15
|
allowOrigins: aws_cdk_lib_1.aws_apigateway.Cors.ALL_ORIGINS,
|
|
16
16
|
allowHeaders: aws_cdk_lib_1.aws_apigateway.Cors.DEFAULT_HEADERS,
|
|
17
17
|
}, }) => {
|
|
18
18
|
const api = new aws_cdk_lib_1.aws_apigateway.RestApi(stack, `${shortStackName}-api-${NODE_ENV}`, {
|
|
19
19
|
defaultCorsPreflightOptions: Object.assign({}, (cors || {})),
|
|
20
20
|
});
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
21
|
+
if (apiUrl) {
|
|
22
|
+
const dn = new aws_cdk_lib_1.aws_apigateway.DomainName(stack, 'domain', {
|
|
23
|
+
domainName: apiUrl,
|
|
24
|
+
certificate,
|
|
25
|
+
endpointType: aws_cdk_lib_1.aws_apigateway.EndpointType.EDGE,
|
|
26
|
+
securityPolicy: aws_cdk_lib_1.aws_apigateway.SecurityPolicy.TLS_1_2,
|
|
27
|
+
mapping: api,
|
|
28
|
+
});
|
|
29
|
+
new aws_cdk_lib_1.aws_route53.ARecord(stack, 'ARecord', {
|
|
30
|
+
comment: '(cdk)',
|
|
31
|
+
recordName: apiUrl.substring(0, apiUrl.indexOf('.')),
|
|
32
|
+
zone: hostedZone,
|
|
33
|
+
target: aws_cdk_lib_1.aws_route53.RecordTarget.fromAlias(new aws_cdk_lib_1.aws_route53_targets.ApiGatewayDomain(dn)),
|
|
34
|
+
});
|
|
35
|
+
}
|
|
34
36
|
return api;
|
|
35
37
|
};
|
|
36
38
|
const setupLambda = ({ lambdaConfig, pathV, verb, seenPermissions, authorizers, }) => {
|