@gradientedge/cdk-utils 8.165.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 +1 -0
- package/dist/src/lib/aws/services/api-gateway/main.d.ts +3 -2
- package/dist/src/lib/aws/services/api-gateway/main.js +7 -4
- package/package.json +1 -1
- package/src/lib/aws/construct/api-to-any-target/main.ts +2 -1
- package/src/lib/aws/construct/api-to-any-target/types.ts +1 -0
- package/src/lib/aws/services/api-gateway/main.ts +9 -5
|
@@ -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, apiResourceProps.mockIntegration);
|
|
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)
|
|
@@ -37,6 +37,7 @@ export interface ApiToAnyTargetRestApiResource {
|
|
|
37
37
|
proxyIntegration?: Integration;
|
|
38
38
|
enableDefaultCors?: boolean;
|
|
39
39
|
mockIntegration?: MockIntegration;
|
|
40
|
+
mockMethodResponses?: MethodResponse[];
|
|
40
41
|
}
|
|
41
42
|
export interface ApiToAnyTargetRestApiProps {
|
|
42
43
|
certificate: AcmProps;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DomainName, IAuthorizer, IResource, IRestApi, Integration,
|
|
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';
|
|
@@ -53,10 +53,11 @@ export declare class ApiManager {
|
|
|
53
53
|
* @param proxyIntegration
|
|
54
54
|
* @param enableDefaultCors
|
|
55
55
|
* @param mockIntegration
|
|
56
|
+
* @param mockMethodResponses
|
|
56
57
|
*/
|
|
57
58
|
createApiResource(id: string, scope: CommonConstruct, parent: IResource, path: string, integration: Integration, addProxy: boolean, authorizer?: IAuthorizer, allowedOrigins?: string[], allowedMethods?: string[], allowedHeaders?: string[], methodRequestParameters?: {
|
|
58
59
|
[param: string]: boolean;
|
|
59
|
-
}, proxyIntegration?: Integration, enableDefaultCors?: boolean, mockIntegration?:
|
|
60
|
+
}, proxyIntegration?: Integration, enableDefaultCors?: boolean, mockIntegration?: Integration, mockMethodResponses?: MethodResponse[]): import("aws-cdk-lib/aws-apigateway").Resource;
|
|
60
61
|
/**
|
|
61
62
|
* @summary Method to create an api deployment
|
|
62
63
|
* @param id
|
|
@@ -97,11 +97,12 @@ class ApiManager {
|
|
|
97
97
|
* @param proxyIntegration
|
|
98
98
|
* @param enableDefaultCors
|
|
99
99
|
* @param mockIntegration
|
|
100
|
+
* @param mockMethodResponses
|
|
100
101
|
*/
|
|
101
|
-
createApiResource(id, scope, parent, path, integration, addProxy, authorizer, allowedOrigins, allowedMethods, allowedHeaders, methodRequestParameters, proxyIntegration, enableDefaultCors, mockIntegration) {
|
|
102
|
+
createApiResource(id, scope, parent, path, integration, addProxy, authorizer, allowedOrigins, allowedMethods, allowedHeaders, methodRequestParameters, proxyIntegration, enableDefaultCors, mockIntegration, mockMethodResponses) {
|
|
102
103
|
const methods = allowedMethods ?? aws_apigateway_1.Cors.ALL_METHODS;
|
|
103
104
|
let defaultCorsPreflightOptions;
|
|
104
|
-
if (
|
|
105
|
+
if (enableDefaultCors === false) {
|
|
105
106
|
defaultCorsPreflightOptions = undefined;
|
|
106
107
|
}
|
|
107
108
|
else {
|
|
@@ -116,10 +117,11 @@ class ApiManager {
|
|
|
116
117
|
defaultCorsPreflightOptions: defaultCorsPreflightOptions,
|
|
117
118
|
});
|
|
118
119
|
lodash_1.default.forEach(methods, method => {
|
|
119
|
-
if (
|
|
120
|
+
if (enableDefaultCors === false && mockIntegration && method === 'OPTIONS') {
|
|
120
121
|
resource.addMethod(method, mockIntegration, {
|
|
121
122
|
authorizer,
|
|
122
123
|
requestParameters: methodRequestParameters,
|
|
124
|
+
methodResponses: mockMethodResponses,
|
|
123
125
|
});
|
|
124
126
|
}
|
|
125
127
|
else {
|
|
@@ -135,10 +137,11 @@ class ApiManager {
|
|
|
135
137
|
defaultCorsPreflightOptions: defaultCorsPreflightOptions,
|
|
136
138
|
});
|
|
137
139
|
lodash_1.default.forEach(methods, method => {
|
|
138
|
-
if (
|
|
140
|
+
if (enableDefaultCors === false && mockIntegration && method === 'OPTIONS') {
|
|
139
141
|
resourceProxy.addMethod(method, mockIntegration, {
|
|
140
142
|
authorizer,
|
|
141
143
|
requestParameters: methodRequestParameters,
|
|
144
|
+
methodResponses: mockMethodResponses,
|
|
142
145
|
});
|
|
143
146
|
}
|
|
144
147
|
else {
|
package/package.json
CHANGED
|
@@ -185,7 +185,8 @@ export class ApiToAnyTarget extends CommonConstruct {
|
|
|
185
185
|
apiResourceProps.methodRequestParameters,
|
|
186
186
|
apiResourceProps.proxyIntegration,
|
|
187
187
|
apiResourceProps.enableDefaultCors,
|
|
188
|
-
apiResourceProps.mockIntegration
|
|
188
|
+
apiResourceProps.mockIntegration,
|
|
189
|
+
apiResourceProps.mockMethodResponses
|
|
189
190
|
)
|
|
190
191
|
}
|
|
191
192
|
|
|
@@ -8,9 +8,9 @@ import {
|
|
|
8
8
|
IResource,
|
|
9
9
|
IRestApi,
|
|
10
10
|
Integration,
|
|
11
|
-
MockIntegration,
|
|
12
11
|
LambdaRestApi,
|
|
13
12
|
SecurityPolicy,
|
|
13
|
+
MethodResponse,
|
|
14
14
|
} from 'aws-cdk-lib/aws-apigateway'
|
|
15
15
|
import { ICertificate } from 'aws-cdk-lib/aws-certificatemanager'
|
|
16
16
|
import { IFunction } from 'aws-cdk-lib/aws-lambda'
|
|
@@ -114,6 +114,7 @@ export class ApiManager {
|
|
|
114
114
|
* @param proxyIntegration
|
|
115
115
|
* @param enableDefaultCors
|
|
116
116
|
* @param mockIntegration
|
|
117
|
+
* @param mockMethodResponses
|
|
117
118
|
*/
|
|
118
119
|
public createApiResource(
|
|
119
120
|
id: string,
|
|
@@ -129,12 +130,13 @@ export class ApiManager {
|
|
|
129
130
|
methodRequestParameters?: { [param: string]: boolean },
|
|
130
131
|
proxyIntegration?: Integration,
|
|
131
132
|
enableDefaultCors?: boolean,
|
|
132
|
-
mockIntegration?:
|
|
133
|
+
mockIntegration?: Integration,
|
|
134
|
+
mockMethodResponses?: MethodResponse[]
|
|
133
135
|
) {
|
|
134
136
|
const methods = allowedMethods ?? Cors.ALL_METHODS
|
|
135
137
|
|
|
136
138
|
let defaultCorsPreflightOptions
|
|
137
|
-
if (
|
|
139
|
+
if (enableDefaultCors === false) {
|
|
138
140
|
defaultCorsPreflightOptions = undefined
|
|
139
141
|
} else {
|
|
140
142
|
defaultCorsPreflightOptions = {
|
|
@@ -150,10 +152,11 @@ export class ApiManager {
|
|
|
150
152
|
})
|
|
151
153
|
|
|
152
154
|
_.forEach(methods, method => {
|
|
153
|
-
if (
|
|
155
|
+
if (enableDefaultCors === false && mockIntegration && method === 'OPTIONS') {
|
|
154
156
|
resource.addMethod(method, mockIntegration, {
|
|
155
157
|
authorizer,
|
|
156
158
|
requestParameters: methodRequestParameters,
|
|
159
|
+
methodResponses: mockMethodResponses,
|
|
157
160
|
})
|
|
158
161
|
} else {
|
|
159
162
|
resource.addMethod(method, integration, {
|
|
@@ -170,10 +173,11 @@ export class ApiManager {
|
|
|
170
173
|
})
|
|
171
174
|
|
|
172
175
|
_.forEach(methods, method => {
|
|
173
|
-
if (
|
|
176
|
+
if (enableDefaultCors === false && mockIntegration && method === 'OPTIONS') {
|
|
174
177
|
resourceProxy.addMethod(method, mockIntegration, {
|
|
175
178
|
authorizer,
|
|
176
179
|
requestParameters: methodRequestParameters,
|
|
180
|
+
methodResponses: mockMethodResponses,
|
|
177
181
|
})
|
|
178
182
|
} else {
|
|
179
183
|
resourceProxy.addMethod(method, proxyIntegration ?? integration, {
|