@gradientedge/cdk-utils 8.164.0 → 8.165.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.
@@ -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);
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,7 @@ export interface ApiToAnyTargetRestApiResource {
36
36
  parent?: IResource;
37
37
  proxyIntegration?: Integration;
38
38
  enableDefaultCors?: boolean;
39
+ mockIntegration?: MockIntegration;
39
40
  }
40
41
  export interface ApiToAnyTargetRestApiProps {
41
42
  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, MockIntegration, LambdaRestApi } 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,12 @@ export declare class ApiManager {
51
51
  * @param allowedHeaders
52
52
  * @param methodRequestParameters
53
53
  * @param proxyIntegration
54
+ * @param enableDefaultCors
55
+ * @param mockIntegration
54
56
  */
55
57
  createApiResource(id: string, scope: CommonConstruct, parent: IResource, path: string, integration: Integration, addProxy: boolean, authorizer?: IAuthorizer, allowedOrigins?: string[], allowedMethods?: string[], allowedHeaders?: string[], methodRequestParameters?: {
56
58
  [param: string]: boolean;
57
- }, proxyIntegration?: Integration, enableDefaultCors?: boolean): import("aws-cdk-lib/aws-apigateway").Resource;
59
+ }, proxyIntegration?: Integration, enableDefaultCors?: boolean, mockIntegration?: MockIntegration): import("aws-cdk-lib/aws-apigateway").Resource;
58
60
  /**
59
61
  * @summary Method to create an api deployment
60
62
  * @param id
@@ -95,8 +95,10 @@ class ApiManager {
95
95
  * @param allowedHeaders
96
96
  * @param methodRequestParameters
97
97
  * @param proxyIntegration
98
+ * @param enableDefaultCors
99
+ * @param mockIntegration
98
100
  */
99
- createApiResource(id, scope, parent, path, integration, addProxy, authorizer, allowedOrigins, allowedMethods, allowedHeaders, methodRequestParameters, proxyIntegration, enableDefaultCors) {
101
+ createApiResource(id, scope, parent, path, integration, addProxy, authorizer, allowedOrigins, allowedMethods, allowedHeaders, methodRequestParameters, proxyIntegration, enableDefaultCors, mockIntegration) {
100
102
  const methods = allowedMethods ?? aws_apigateway_1.Cors.ALL_METHODS;
101
103
  let defaultCorsPreflightOptions;
102
104
  if (!enableDefaultCors) {
@@ -114,10 +116,18 @@ class ApiManager {
114
116
  defaultCorsPreflightOptions: defaultCorsPreflightOptions,
115
117
  });
116
118
  lodash_1.default.forEach(methods, method => {
117
- resource.addMethod(method, integration, {
118
- authorizer,
119
- requestParameters: methodRequestParameters,
120
- });
119
+ if (!enableDefaultCors && mockIntegration && method === 'OPTIONS') {
120
+ resource.addMethod(method, mockIntegration, {
121
+ authorizer,
122
+ requestParameters: methodRequestParameters,
123
+ });
124
+ }
125
+ else {
126
+ resource.addMethod(method, integration, {
127
+ authorizer,
128
+ requestParameters: methodRequestParameters,
129
+ });
130
+ }
121
131
  });
122
132
  (0, utils_1.createCfnOutput)(`${id}-${path}ResourceId`, scope, resource.resourceId);
123
133
  if (addProxy) {
@@ -125,10 +135,18 @@ class ApiManager {
125
135
  defaultCorsPreflightOptions: defaultCorsPreflightOptions,
126
136
  });
127
137
  lodash_1.default.forEach(methods, method => {
128
- resourceProxy.addMethod(method, proxyIntegration ?? integration, {
129
- authorizer,
130
- requestParameters: methodRequestParameters,
131
- });
138
+ if (!enableDefaultCors && mockIntegration && method === 'OPTIONS') {
139
+ resourceProxy.addMethod(method, mockIntegration, {
140
+ authorizer,
141
+ requestParameters: methodRequestParameters,
142
+ });
143
+ }
144
+ else {
145
+ resourceProxy.addMethod(method, proxyIntegration ?? integration, {
146
+ authorizer,
147
+ requestParameters: methodRequestParameters,
148
+ });
149
+ }
132
150
  });
133
151
  (0, utils_1.createCfnOutput)(`${id}-${path}ProxyResourceId`, scope, resourceProxy.resourceId);
134
152
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gradientedge/cdk-utils",
3
- "version": "8.164.0",
3
+ "version": "8.165.0",
4
4
  "description": "Utilities for AWS CDK provisioning",
5
5
  "main": "dist/index.js",
6
6
  "engines": {
@@ -184,7 +184,8 @@ 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
188
189
  )
189
190
  }
190
191
 
@@ -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,7 @@ export interface ApiToAnyTargetRestApiResource {
43
44
  parent?: IResource
44
45
  proxyIntegration?: Integration
45
46
  enableDefaultCors?: boolean
47
+ mockIntegration?: MockIntegration
46
48
  }
47
49
 
48
50
  export interface ApiToAnyTargetRestApiProps {
@@ -8,6 +8,7 @@ import {
8
8
  IResource,
9
9
  IRestApi,
10
10
  Integration,
11
+ MockIntegration,
11
12
  LambdaRestApi,
12
13
  SecurityPolicy,
13
14
  } from 'aws-cdk-lib/aws-apigateway'
@@ -111,6 +112,8 @@ export class ApiManager {
111
112
  * @param allowedHeaders
112
113
  * @param methodRequestParameters
113
114
  * @param proxyIntegration
115
+ * @param enableDefaultCors
116
+ * @param mockIntegration
114
117
  */
115
118
  public createApiResource(
116
119
  id: string,
@@ -125,7 +128,8 @@ export class ApiManager {
125
128
  allowedHeaders?: string[],
126
129
  methodRequestParameters?: { [param: string]: boolean },
127
130
  proxyIntegration?: Integration,
128
- enableDefaultCors?: boolean
131
+ enableDefaultCors?: boolean,
132
+ mockIntegration?: MockIntegration
129
133
  ) {
130
134
  const methods = allowedMethods ?? Cors.ALL_METHODS
131
135
 
@@ -146,10 +150,17 @@ export class ApiManager {
146
150
  })
147
151
 
148
152
  _.forEach(methods, method => {
149
- resource.addMethod(method, integration, {
150
- authorizer,
151
- requestParameters: methodRequestParameters,
152
- })
153
+ if (!enableDefaultCors && mockIntegration && method === 'OPTIONS') {
154
+ resource.addMethod(method, mockIntegration, {
155
+ authorizer,
156
+ requestParameters: methodRequestParameters,
157
+ })
158
+ } else {
159
+ resource.addMethod(method, integration, {
160
+ authorizer,
161
+ requestParameters: methodRequestParameters,
162
+ })
163
+ }
153
164
  })
154
165
  createCfnOutput(`${id}-${path}ResourceId`, scope, resource.resourceId)
155
166
 
@@ -159,10 +170,17 @@ export class ApiManager {
159
170
  })
160
171
 
161
172
  _.forEach(methods, method => {
162
- resourceProxy.addMethod(method, proxyIntegration ?? integration, {
163
- authorizer,
164
- requestParameters: methodRequestParameters,
165
- })
173
+ if (!enableDefaultCors && mockIntegration && method === 'OPTIONS') {
174
+ resourceProxy.addMethod(method, mockIntegration, {
175
+ authorizer,
176
+ requestParameters: methodRequestParameters,
177
+ })
178
+ } else {
179
+ resourceProxy.addMethod(method, proxyIntegration ?? integration, {
180
+ authorizer,
181
+ requestParameters: methodRequestParameters,
182
+ })
183
+ }
166
184
  })
167
185
  createCfnOutput(`${id}-${path}ProxyResourceId`, scope, resourceProxy.resourceId)
168
186
  }