@gradientedge/cdk-utils 4.7.1 → 4.8.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.
@@ -23,7 +23,7 @@
23
23
  "glob@^7.1.3": "https://registry.yarnpkg.com/glob/-/glob-7.2.0.tgz#d15535af7732e02e948f4c41628bd910293f6023",
24
24
  "inflight@^1.0.4": "https://registry.yarnpkg.com/inflight/-/inflight-1.0.6.tgz#49bd6331d7d02d0c09bc910a1075ba8165b56df9",
25
25
  "inherits@2": "https://registry.yarnpkg.com/inherits/-/inherits-2.0.4.tgz#0fa2c64f932917c3433a0ded55363aae37416b7c",
26
- "minimatch@^3.0.4": "https://registry.yarnpkg.com/minimatch/-/minimatch-3.1.1.tgz#879ad447200773912898b46cd516a7abbb5e50b0",
26
+ "minimatch@^3.0.4": "https://registry.yarnpkg.com/minimatch/-/minimatch-3.1.2.tgz#19cd194bfd3e428f049a70817c038d89ab4be35b",
27
27
  "mkdirp@^1.0.4": "https://registry.yarnpkg.com/mkdirp/-/mkdirp-1.0.4.tgz#3eb5ed62622756d79a5f0e2a221dfebad75c2f7e",
28
28
  "once@^1.3.0": "https://registry.yarnpkg.com/once/-/once-1.4.0.tgz#583b1aa775961d4b113ac17d9c50baef9dd76bd1",
29
29
  "path-is-absolute@^1.0.0": "https://registry.yarnpkg.com/path-is-absolute/-/path-is-absolute-1.0.1.tgz#174b9268735534ffbc7ace6bf53a5a9e1b5c5f5f",
@@ -30,7 +30,6 @@ export declare class GraphQLApiLambdaWithCache extends GraphQLApiLambda {
30
30
  graphQLVpc: ec2.IVpc;
31
31
  graphQLElastiCache: elasticache.CfnCacheCluster;
32
32
  graphQLSecurityGroup: ec2.ISecurityGroup;
33
- securityGroupStackName: string;
34
33
  securityGroupExportName: string;
35
34
  vpcExportName: string;
36
35
  constructor(parent: Construct, id: string, props: GraphQlApiLambdaWithCacheProps);
@@ -54,7 +54,6 @@ class GraphQLApiLambdaWithCache extends __1.GraphQLApiLambda {
54
54
  graphQLVpc;
55
55
  graphQLElastiCache;
56
56
  graphQLSecurityGroup;
57
- securityGroupStackName;
58
57
  securityGroupExportName;
59
58
  vpcExportName;
60
59
  constructor(parent, id, props) {
@@ -73,8 +72,8 @@ class GraphQLApiLambdaWithCache extends __1.GraphQLApiLambda {
73
72
  * @protected
74
73
  */
75
74
  setVpc() {
76
- if (this.props.vpcExportName) {
77
- this.graphQLVpc = this.vpcManager.retrieveCommonVpc(`${this.id}`, this, this.props.vpcExportName);
75
+ if (this.props.useExistingVpc) {
76
+ this.graphQLVpc = this.vpcManager.retrieveCommonVpc(`${this.id}`, this, this.props.vpcName);
78
77
  }
79
78
  else {
80
79
  this.graphQLVpc = this.vpcManager.createCommonVpc(this, this.props.graphQLVpc, this.props.graphQLVpc.vpcName);
@@ -40,4 +40,17 @@ export declare class ApiManager {
40
40
  * @param certificate the certificate used for custom restApi domain
41
41
  */
42
42
  createApiDomain(id: string, scope: common.CommonConstruct, domainName: string, certificate: acm.ICertificate): apig.DomainName;
43
+ /**
44
+ * @summary Method to create an API gateway resource
45
+ * @param {string} id
46
+ * @param {common.CommonConstruct} scope
47
+ * @param {apig.IResource} parent
48
+ * @param {string} path
49
+ * @param {apig.Integration} integration
50
+ * @param {boolean} addProxy
51
+ * @param {string[]?} allowedOrigins
52
+ * @param {string[]?} allowedMethods
53
+ * @param {string[]?} allowedHeaders
54
+ */
55
+ createApiResource(id: string, scope: common.CommonConstruct, parent: apig.IResource, path: string, integration: apig.Integration, addProxy: boolean, allowedOrigins?: string[], allowedMethods?: string[], allowedHeaders?: string[]): apig.Resource;
43
56
  }
@@ -84,7 +84,7 @@ class ApiManager {
84
84
  restApiName: `${props.restApiName}-${scope.props.stage}`,
85
85
  handler: lambdaFunction,
86
86
  defaultCorsPreflightOptions: props.defaultCorsPreflightOptions,
87
- proxy: props.proxy || true,
87
+ proxy: props.proxy ?? true,
88
88
  });
89
89
  utils.createCfnOutput(`${id}-restApiId`, scope, api.restApiId);
90
90
  utils.createCfnOutput(`${id}-restApiName`, scope, api.restApiName);
@@ -107,5 +107,43 @@ class ApiManager {
107
107
  utils.createCfnOutput(`${id}-customDomainName`, scope, apiDomain.domainName);
108
108
  return apiDomain;
109
109
  }
110
+ /**
111
+ * @summary Method to create an API gateway resource
112
+ * @param {string} id
113
+ * @param {common.CommonConstruct} scope
114
+ * @param {apig.IResource} parent
115
+ * @param {string} path
116
+ * @param {apig.Integration} integration
117
+ * @param {boolean} addProxy
118
+ * @param {string[]?} allowedOrigins
119
+ * @param {string[]?} allowedMethods
120
+ * @param {string[]?} allowedHeaders
121
+ */
122
+ createApiResource(id, scope, parent, path, integration, addProxy, allowedOrigins, allowedMethods, allowedHeaders) {
123
+ const methods = allowedMethods ?? apig.Cors.ALL_METHODS;
124
+ const resource = parent.addResource(path, {
125
+ defaultCorsPreflightOptions: {
126
+ allowOrigins: allowedOrigins ?? apig.Cors.ALL_ORIGINS,
127
+ allowMethods: [...methods, 'OPTIONS'],
128
+ allowHeaders: allowedHeaders ?? apig.Cors.DEFAULT_HEADERS,
129
+ allowCredentials: true,
130
+ },
131
+ });
132
+ methods.forEach(method => resource.addMethod(method, integration));
133
+ utils.createCfnOutput(`${id}-${path}ResourceId`, scope, resource.resourceId);
134
+ if (addProxy) {
135
+ const resourceProxy = resource.addResource(`{${path}+}`, {
136
+ defaultCorsPreflightOptions: {
137
+ allowOrigins: allowedOrigins ?? apig.Cors.ALL_ORIGINS,
138
+ allowMethods: [...methods, 'OPTIONS'],
139
+ allowHeaders: allowedHeaders ?? apig.Cors.DEFAULT_HEADERS,
140
+ allowCredentials: true,
141
+ },
142
+ });
143
+ methods.forEach(method => resourceProxy.addMethod(method, integration));
144
+ utils.createCfnOutput(`${id}-${path}ProxyResourceId`, scope, resourceProxy.resourceId);
145
+ }
146
+ return resource;
147
+ }
110
148
  }
111
149
  exports.ApiManager = ApiManager;
@@ -152,7 +152,8 @@ export interface GraphQlApiLambdaWithCacheProps extends GraphQlApiLambdaProps {
152
152
  graphQLVpc: ec2.VpcProps;
153
153
  graphQLElastiCache: ElastiCacheProps;
154
154
  securityGroupExportName: string;
155
- vpcExportName: string;
155
+ useExistingVpc: boolean;
156
+ vpcName?: string;
156
157
  }
157
158
  /**
158
159
  * @category cdk-utils.api-to-eventbridge-target
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gradientedge/cdk-utils",
3
- "version": "4.7.1",
3
+ "version": "4.8.0",
4
4
  "description": "Utilities for AWS CDK provisioning",
5
5
  "main": "dist/index.js",
6
6
  "engines": {
@@ -37,7 +37,6 @@ export class GraphQLApiLambdaWithCache extends GraphQLApiLambda {
37
37
  graphQLVpc: ec2.IVpc
38
38
  graphQLElastiCache: elasticache.CfnCacheCluster
39
39
  graphQLSecurityGroup: ec2.ISecurityGroup
40
- securityGroupStackName: string
41
40
  securityGroupExportName: string
42
41
  vpcExportName: string
43
42
 
@@ -60,8 +59,8 @@ export class GraphQLApiLambdaWithCache extends GraphQLApiLambda {
60
59
  * @protected
61
60
  */
62
61
  protected setVpc() {
63
- if (this.props.vpcExportName) {
64
- this.graphQLVpc = this.vpcManager.retrieveCommonVpc(`${this.id}`, this, this.props.vpcExportName)
62
+ if (this.props.useExistingVpc) {
63
+ this.graphQLVpc = this.vpcManager.retrieveCommonVpc(`${this.id}`, this, this.props.vpcName)
65
64
  } else {
66
65
  this.graphQLVpc = this.vpcManager.createCommonVpc(this, this.props.graphQLVpc, this.props.graphQLVpc.vpcName)
67
66
  }
@@ -71,7 +71,7 @@ export class ApiManager {
71
71
  restApiName: `${props.restApiName}-${scope.props.stage}`,
72
72
  handler: lambdaFunction,
73
73
  defaultCorsPreflightOptions: props.defaultCorsPreflightOptions,
74
- proxy: props.proxy || true,
74
+ proxy: props.proxy ?? true,
75
75
  })
76
76
 
77
77
  utils.createCfnOutput(`${id}-restApiId`, scope, api.restApiId)
@@ -99,4 +99,55 @@ export class ApiManager {
99
99
 
100
100
  return apiDomain
101
101
  }
102
+
103
+ /**
104
+ * @summary Method to create an API gateway resource
105
+ * @param {string} id
106
+ * @param {common.CommonConstruct} scope
107
+ * @param {apig.IResource} parent
108
+ * @param {string} path
109
+ * @param {apig.Integration} integration
110
+ * @param {boolean} addProxy
111
+ * @param {string[]?} allowedOrigins
112
+ * @param {string[]?} allowedMethods
113
+ * @param {string[]?} allowedHeaders
114
+ */
115
+ public createApiResource(
116
+ id: string,
117
+ scope: common.CommonConstruct,
118
+ parent: apig.IResource,
119
+ path: string,
120
+ integration: apig.Integration,
121
+ addProxy: boolean,
122
+ allowedOrigins?: string[],
123
+ allowedMethods?: string[],
124
+ allowedHeaders?: string[]
125
+ ) {
126
+ const methods = allowedMethods ?? apig.Cors.ALL_METHODS
127
+ const resource = parent.addResource(path, {
128
+ defaultCorsPreflightOptions: {
129
+ allowOrigins: allowedOrigins ?? apig.Cors.ALL_ORIGINS,
130
+ allowMethods: [...methods, 'OPTIONS'],
131
+ allowHeaders: allowedHeaders ?? apig.Cors.DEFAULT_HEADERS,
132
+ allowCredentials: true,
133
+ },
134
+ })
135
+ methods.forEach(method => resource.addMethod(method, integration))
136
+ utils.createCfnOutput(`${id}-${path}ResourceId`, scope, resource.resourceId)
137
+
138
+ if (addProxy) {
139
+ const resourceProxy = resource.addResource(`{${path}+}`, {
140
+ defaultCorsPreflightOptions: {
141
+ allowOrigins: allowedOrigins ?? apig.Cors.ALL_ORIGINS,
142
+ allowMethods: [...methods, 'OPTIONS'],
143
+ allowHeaders: allowedHeaders ?? apig.Cors.DEFAULT_HEADERS,
144
+ allowCredentials: true,
145
+ },
146
+ })
147
+ methods.forEach(method => resourceProxy.addMethod(method, integration))
148
+ utils.createCfnOutput(`${id}-${path}ProxyResourceId`, scope, resourceProxy.resourceId)
149
+ }
150
+
151
+ return resource
152
+ }
102
153
  }
@@ -161,7 +161,8 @@ export interface GraphQlApiLambdaWithCacheProps extends GraphQlApiLambdaProps {
161
161
  graphQLVpc: ec2.VpcProps
162
162
  graphQLElastiCache: ElastiCacheProps
163
163
  securityGroupExportName: string
164
- vpcExportName: string
164
+ useExistingVpc: boolean
165
+ vpcName?: string
165
166
  }
166
167
 
167
168
  /**