@gradientedge/cdk-utils 8.164.0 → 8.166.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/src/lib/aws/construct/api-to-any-target/main.js +1 -1
- package/dist/src/lib/aws/construct/api-to-any-target/types.d.ts +3 -1
- package/dist/src/lib/aws/services/api-gateway/main.d.ts +5 -2
- package/dist/src/lib/aws/services/api-gateway/main.js +31 -10
- package/package.json +1 -1
- package/src/lib/aws/construct/api-to-any-target/main.ts +3 -1
- package/src/lib/aws/construct/api-to-any-target/types.ts +3 -0
- package/src/lib/aws/services/api-gateway/main.ts +32 -10
|
@@ -129,7 +129,7 @@ class ApiToAnyTarget extends common_1.CommonConstruct {
|
|
|
129
129
|
else {
|
|
130
130
|
rootResource = this.apiToAnyTargetRestApi.api.root;
|
|
131
131
|
}
|
|
132
|
-
return this.apiManager.createApiResource(`${this.id}-resource-${apiResourceProps.path}}`, this, apiResourceProps.parent ?? rootResource, apiResourceProps.path, apiResourceProps.integration, apiResourceProps.addProxy, apiResourceProps.authorizer, apiResourceProps.allowedOrigins, apiResourceProps.allowedMethods, apiResourceProps.allowedHeaders, apiResourceProps.methodRequestParameters, apiResourceProps.proxyIntegration, apiResourceProps.enableDefaultCors);
|
|
132
|
+
return this.apiManager.createApiResource(`${this.id}-resource-${apiResourceProps.path}}`, this, apiResourceProps.parent ?? rootResource, apiResourceProps.path, apiResourceProps.integration, apiResourceProps.addProxy, apiResourceProps.authorizer, apiResourceProps.allowedOrigins, apiResourceProps.allowedMethods, apiResourceProps.allowedHeaders, apiResourceProps.methodRequestParameters, apiResourceProps.proxyIntegration, apiResourceProps.enableDefaultCors, apiResourceProps.mockIntegration, apiResourceProps.mockMethodResponses);
|
|
133
133
|
}
|
|
134
134
|
createApiDomain() {
|
|
135
135
|
if (this.props.api.useExisting)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BasePathMapping, DomainName, IAuthorizer, IResource, IRestApi, Integration, Method, MethodResponse, Resource, RestApiProps } from 'aws-cdk-lib/aws-apigateway';
|
|
1
|
+
import { BasePathMapping, DomainName, IAuthorizer, IResource, IRestApi, Integration, Method, MethodResponse, MockIntegration, Resource, RestApiProps } from 'aws-cdk-lib/aws-apigateway';
|
|
2
2
|
import { ICertificate } from 'aws-cdk-lib/aws-certificatemanager';
|
|
3
3
|
import { LogGroup } from 'aws-cdk-lib/aws-logs';
|
|
4
4
|
import { IHostedZone } from 'aws-cdk-lib/aws-route53';
|
|
@@ -36,6 +36,8 @@ export interface ApiToAnyTargetRestApiResource {
|
|
|
36
36
|
parent?: IResource;
|
|
37
37
|
proxyIntegration?: Integration;
|
|
38
38
|
enableDefaultCors?: boolean;
|
|
39
|
+
mockIntegration?: MockIntegration;
|
|
40
|
+
mockMethodResponses?: MethodResponse[];
|
|
39
41
|
}
|
|
40
42
|
export interface ApiToAnyTargetRestApiProps {
|
|
41
43
|
certificate: AcmProps;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DomainName, IAuthorizer, IResource, IRestApi, Integration, LambdaRestApi } from 'aws-cdk-lib/aws-apigateway';
|
|
1
|
+
import { DomainName, IAuthorizer, IResource, IRestApi, Integration, LambdaRestApi, MethodResponse } from 'aws-cdk-lib/aws-apigateway';
|
|
2
2
|
import { ICertificate } from 'aws-cdk-lib/aws-certificatemanager';
|
|
3
3
|
import { IFunction } from 'aws-cdk-lib/aws-lambda';
|
|
4
4
|
import { CommonConstruct } from '../../common';
|
|
@@ -51,10 +51,13 @@ export declare class ApiManager {
|
|
|
51
51
|
* @param allowedHeaders
|
|
52
52
|
* @param methodRequestParameters
|
|
53
53
|
* @param proxyIntegration
|
|
54
|
+
* @param enableDefaultCors
|
|
55
|
+
* @param mockIntegration
|
|
56
|
+
* @param mockMethodResponses
|
|
54
57
|
*/
|
|
55
58
|
createApiResource(id: string, scope: CommonConstruct, parent: IResource, path: string, integration: Integration, addProxy: boolean, authorizer?: IAuthorizer, allowedOrigins?: string[], allowedMethods?: string[], allowedHeaders?: string[], methodRequestParameters?: {
|
|
56
59
|
[param: string]: boolean;
|
|
57
|
-
}, proxyIntegration?: Integration, enableDefaultCors?: boolean): import("aws-cdk-lib/aws-apigateway").Resource;
|
|
60
|
+
}, proxyIntegration?: Integration, enableDefaultCors?: boolean, mockIntegration?: Integration, mockMethodResponses?: MethodResponse[]): import("aws-cdk-lib/aws-apigateway").Resource;
|
|
58
61
|
/**
|
|
59
62
|
* @summary Method to create an api deployment
|
|
60
63
|
* @param id
|
|
@@ -95,11 +95,14 @@ class ApiManager {
|
|
|
95
95
|
* @param allowedHeaders
|
|
96
96
|
* @param methodRequestParameters
|
|
97
97
|
* @param proxyIntegration
|
|
98
|
+
* @param enableDefaultCors
|
|
99
|
+
* @param mockIntegration
|
|
100
|
+
* @param mockMethodResponses
|
|
98
101
|
*/
|
|
99
|
-
createApiResource(id, scope, parent, path, integration, addProxy, authorizer, allowedOrigins, allowedMethods, allowedHeaders, methodRequestParameters, proxyIntegration, enableDefaultCors) {
|
|
102
|
+
createApiResource(id, scope, parent, path, integration, addProxy, authorizer, allowedOrigins, allowedMethods, allowedHeaders, methodRequestParameters, proxyIntegration, enableDefaultCors, mockIntegration, mockMethodResponses) {
|
|
100
103
|
const methods = allowedMethods ?? aws_apigateway_1.Cors.ALL_METHODS;
|
|
101
104
|
let defaultCorsPreflightOptions;
|
|
102
|
-
if (
|
|
105
|
+
if (enableDefaultCors === false) {
|
|
103
106
|
defaultCorsPreflightOptions = undefined;
|
|
104
107
|
}
|
|
105
108
|
else {
|
|
@@ -114,10 +117,19 @@ class ApiManager {
|
|
|
114
117
|
defaultCorsPreflightOptions: defaultCorsPreflightOptions,
|
|
115
118
|
});
|
|
116
119
|
lodash_1.default.forEach(methods, method => {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
120
|
+
if (enableDefaultCors === false && mockIntegration && method === 'OPTIONS') {
|
|
121
|
+
resource.addMethod(method, mockIntegration, {
|
|
122
|
+
authorizer,
|
|
123
|
+
requestParameters: methodRequestParameters,
|
|
124
|
+
methodResponses: mockMethodResponses,
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
resource.addMethod(method, integration, {
|
|
129
|
+
authorizer,
|
|
130
|
+
requestParameters: methodRequestParameters,
|
|
131
|
+
});
|
|
132
|
+
}
|
|
121
133
|
});
|
|
122
134
|
(0, utils_1.createCfnOutput)(`${id}-${path}ResourceId`, scope, resource.resourceId);
|
|
123
135
|
if (addProxy) {
|
|
@@ -125,10 +137,19 @@ class ApiManager {
|
|
|
125
137
|
defaultCorsPreflightOptions: defaultCorsPreflightOptions,
|
|
126
138
|
});
|
|
127
139
|
lodash_1.default.forEach(methods, method => {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
140
|
+
if (enableDefaultCors === false && mockIntegration && method === 'OPTIONS') {
|
|
141
|
+
resourceProxy.addMethod(method, mockIntegration, {
|
|
142
|
+
authorizer,
|
|
143
|
+
requestParameters: methodRequestParameters,
|
|
144
|
+
methodResponses: mockMethodResponses,
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
resourceProxy.addMethod(method, proxyIntegration ?? integration, {
|
|
149
|
+
authorizer,
|
|
150
|
+
requestParameters: methodRequestParameters,
|
|
151
|
+
});
|
|
152
|
+
}
|
|
132
153
|
});
|
|
133
154
|
(0, utils_1.createCfnOutput)(`${id}-${path}ProxyResourceId`, scope, resourceProxy.resourceId);
|
|
134
155
|
}
|
package/package.json
CHANGED
|
@@ -184,7 +184,9 @@ export class ApiToAnyTarget extends CommonConstruct {
|
|
|
184
184
|
apiResourceProps.allowedHeaders,
|
|
185
185
|
apiResourceProps.methodRequestParameters,
|
|
186
186
|
apiResourceProps.proxyIntegration,
|
|
187
|
-
apiResourceProps.enableDefaultCors
|
|
187
|
+
apiResourceProps.enableDefaultCors,
|
|
188
|
+
apiResourceProps.mockIntegration,
|
|
189
|
+
apiResourceProps.mockMethodResponses
|
|
188
190
|
)
|
|
189
191
|
}
|
|
190
192
|
|
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
Integration,
|
|
8
8
|
Method,
|
|
9
9
|
MethodResponse,
|
|
10
|
+
MockIntegration,
|
|
10
11
|
Resource,
|
|
11
12
|
RestApiProps,
|
|
12
13
|
} from 'aws-cdk-lib/aws-apigateway'
|
|
@@ -43,6 +44,8 @@ export interface ApiToAnyTargetRestApiResource {
|
|
|
43
44
|
parent?: IResource
|
|
44
45
|
proxyIntegration?: Integration
|
|
45
46
|
enableDefaultCors?: boolean
|
|
47
|
+
mockIntegration?: MockIntegration
|
|
48
|
+
mockMethodResponses?: MethodResponse[]
|
|
46
49
|
}
|
|
47
50
|
|
|
48
51
|
export interface ApiToAnyTargetRestApiProps {
|
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
Integration,
|
|
11
11
|
LambdaRestApi,
|
|
12
12
|
SecurityPolicy,
|
|
13
|
+
MethodResponse,
|
|
13
14
|
} from 'aws-cdk-lib/aws-apigateway'
|
|
14
15
|
import { ICertificate } from 'aws-cdk-lib/aws-certificatemanager'
|
|
15
16
|
import { IFunction } from 'aws-cdk-lib/aws-lambda'
|
|
@@ -111,6 +112,9 @@ export class ApiManager {
|
|
|
111
112
|
* @param allowedHeaders
|
|
112
113
|
* @param methodRequestParameters
|
|
113
114
|
* @param proxyIntegration
|
|
115
|
+
* @param enableDefaultCors
|
|
116
|
+
* @param mockIntegration
|
|
117
|
+
* @param mockMethodResponses
|
|
114
118
|
*/
|
|
115
119
|
public createApiResource(
|
|
116
120
|
id: string,
|
|
@@ -125,12 +129,14 @@ export class ApiManager {
|
|
|
125
129
|
allowedHeaders?: string[],
|
|
126
130
|
methodRequestParameters?: { [param: string]: boolean },
|
|
127
131
|
proxyIntegration?: Integration,
|
|
128
|
-
enableDefaultCors?: boolean
|
|
132
|
+
enableDefaultCors?: boolean,
|
|
133
|
+
mockIntegration?: Integration,
|
|
134
|
+
mockMethodResponses?: MethodResponse[]
|
|
129
135
|
) {
|
|
130
136
|
const methods = allowedMethods ?? Cors.ALL_METHODS
|
|
131
137
|
|
|
132
138
|
let defaultCorsPreflightOptions
|
|
133
|
-
if (
|
|
139
|
+
if (enableDefaultCors === false) {
|
|
134
140
|
defaultCorsPreflightOptions = undefined
|
|
135
141
|
} else {
|
|
136
142
|
defaultCorsPreflightOptions = {
|
|
@@ -146,10 +152,18 @@ export class ApiManager {
|
|
|
146
152
|
})
|
|
147
153
|
|
|
148
154
|
_.forEach(methods, method => {
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
155
|
+
if (enableDefaultCors === false && mockIntegration && method === 'OPTIONS') {
|
|
156
|
+
resource.addMethod(method, mockIntegration, {
|
|
157
|
+
authorizer,
|
|
158
|
+
requestParameters: methodRequestParameters,
|
|
159
|
+
methodResponses: mockMethodResponses,
|
|
160
|
+
})
|
|
161
|
+
} else {
|
|
162
|
+
resource.addMethod(method, integration, {
|
|
163
|
+
authorizer,
|
|
164
|
+
requestParameters: methodRequestParameters,
|
|
165
|
+
})
|
|
166
|
+
}
|
|
153
167
|
})
|
|
154
168
|
createCfnOutput(`${id}-${path}ResourceId`, scope, resource.resourceId)
|
|
155
169
|
|
|
@@ -159,10 +173,18 @@ export class ApiManager {
|
|
|
159
173
|
})
|
|
160
174
|
|
|
161
175
|
_.forEach(methods, method => {
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
176
|
+
if (enableDefaultCors === false && mockIntegration && method === 'OPTIONS') {
|
|
177
|
+
resourceProxy.addMethod(method, mockIntegration, {
|
|
178
|
+
authorizer,
|
|
179
|
+
requestParameters: methodRequestParameters,
|
|
180
|
+
methodResponses: mockMethodResponses,
|
|
181
|
+
})
|
|
182
|
+
} else {
|
|
183
|
+
resourceProxy.addMethod(method, proxyIntegration ?? integration, {
|
|
184
|
+
authorizer,
|
|
185
|
+
requestParameters: methodRequestParameters,
|
|
186
|
+
})
|
|
187
|
+
}
|
|
166
188
|
})
|
|
167
189
|
createCfnOutput(`${id}-${path}ProxyResourceId`, scope, resourceProxy.resourceId)
|
|
168
190
|
}
|