@jaypie/constructs 1.1.36-beta.1 → 1.1.36-beta.2

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.
@@ -7,12 +7,12 @@ var apiGateway = require('aws-cdk-lib/aws-apigateway');
7
7
  var route53 = require('aws-cdk-lib/aws-route53');
8
8
  var route53Targets = require('aws-cdk-lib/aws-route53-targets');
9
9
  var cdk = require('@jaypie/cdk');
10
- var lambda = require('aws-cdk-lib/aws-lambda');
11
- var secretsmanager = require('aws-cdk-lib/aws-secretsmanager');
12
10
  var s3 = require('aws-cdk-lib/aws-s3');
13
11
  var s3n = require('aws-cdk-lib/aws-s3-notifications');
12
+ var lambda = require('aws-cdk-lib/aws-lambda');
14
13
  var sqs = require('aws-cdk-lib/aws-sqs');
15
14
  var lambdaEventSources = require('aws-cdk-lib/aws-lambda-event-sources');
15
+ var secretsmanager = require('aws-cdk-lib/aws-secretsmanager');
16
16
  var awsIam = require('aws-cdk-lib/aws-iam');
17
17
  var awsLogs = require('aws-cdk-lib/aws-logs');
18
18
  var sso = require('aws-cdk-lib/aws-sso');
@@ -41,12 +41,12 @@ var acm__namespace = /*#__PURE__*/_interopNamespaceDefault(acm);
41
41
  var apiGateway__namespace = /*#__PURE__*/_interopNamespaceDefault(apiGateway);
42
42
  var route53__namespace = /*#__PURE__*/_interopNamespaceDefault(route53);
43
43
  var route53Targets__namespace = /*#__PURE__*/_interopNamespaceDefault(route53Targets);
44
- var lambda__namespace = /*#__PURE__*/_interopNamespaceDefault(lambda);
45
- var secretsmanager__namespace = /*#__PURE__*/_interopNamespaceDefault(secretsmanager);
46
44
  var s3__namespace = /*#__PURE__*/_interopNamespaceDefault(s3);
47
45
  var s3n__namespace = /*#__PURE__*/_interopNamespaceDefault(s3n);
46
+ var lambda__namespace = /*#__PURE__*/_interopNamespaceDefault(lambda);
48
47
  var sqs__namespace = /*#__PURE__*/_interopNamespaceDefault(sqs);
49
48
  var lambdaEventSources__namespace = /*#__PURE__*/_interopNamespaceDefault(lambdaEventSources);
49
+ var secretsmanager__namespace = /*#__PURE__*/_interopNamespaceDefault(secretsmanager);
50
50
  var sso__namespace = /*#__PURE__*/_interopNamespaceDefault(sso);
51
51
  var cloudfront__namespace = /*#__PURE__*/_interopNamespaceDefault(cloudfront);
52
52
  var origins__namespace = /*#__PURE__*/_interopNamespaceDefault(origins);
@@ -138,6 +138,186 @@ function stackTagger(stack, { name } = {}) {
138
138
  return true;
139
139
  }
140
140
 
141
+ class JaypieApiGateway extends constructs.Construct {
142
+ constructor(scope, id, props) {
143
+ super(scope, id);
144
+ const { certificate = true, handler, host: propsHost, name, roleTag = cdk.CDK.ROLE.API, zone: propsZone, } = props;
145
+ // Determine zone from props or environment
146
+ let zone = propsZone;
147
+ if (!zone && process.env.CDK_ENV_API_HOSTED_ZONE) {
148
+ zone = process.env.CDK_ENV_API_HOSTED_ZONE;
149
+ }
150
+ // Determine host from props or environment
151
+ let host = propsHost;
152
+ if (!host) {
153
+ if (process.env.CDK_ENV_API_HOST_NAME) {
154
+ host = process.env.CDK_ENV_API_HOST_NAME;
155
+ }
156
+ else if (process.env.CDK_ENV_API_SUBDOMAIN &&
157
+ process.env.CDK_ENV_API_HOSTED_ZONE) {
158
+ host = cdk.mergeDomain(process.env.CDK_ENV_API_SUBDOMAIN, process.env.CDK_ENV_API_HOSTED_ZONE);
159
+ }
160
+ }
161
+ const apiGatewayName = name || constructEnvName("ApiGateway");
162
+ const certificateName = constructEnvName("Certificate");
163
+ const apiDomainName = constructEnvName("ApiDomainName");
164
+ let hostedZone;
165
+ let certificateToUse;
166
+ if (host && zone) {
167
+ if (typeof zone === "string") {
168
+ hostedZone = route53__namespace.HostedZone.fromLookup(this, "HostedZone", {
169
+ domainName: zone,
170
+ });
171
+ }
172
+ else {
173
+ hostedZone = zone;
174
+ }
175
+ if (certificate === true) {
176
+ certificateToUse = new acm__namespace.Certificate(this, certificateName, {
177
+ domainName: host,
178
+ validation: acm__namespace.CertificateValidation.fromDns(hostedZone),
179
+ });
180
+ cdk$1.Tags.of(certificateToUse).add(cdk.CDK.TAG.ROLE, cdk.CDK.ROLE.HOSTING);
181
+ }
182
+ else if (typeof certificate === "object") {
183
+ certificateToUse = certificate;
184
+ }
185
+ this._certificate = certificateToUse;
186
+ this._host = host;
187
+ }
188
+ const {
189
+ // * `...lambdaRestApiProps` cannot be moved to the first const destructuring because it needs to exclude the custom properties first.
190
+ // Ignore the variables we already assigned to other properties
191
+ /* eslint-disable @typescript-eslint/no-unused-vars */
192
+ certificate: _certificate, host: _host, name: _name, roleTag: _roleTag, zone: _zone, handler: _handler,
193
+ /* eslint-enable @typescript-eslint/no-unused-vars */
194
+ ...lambdaRestApiProps } = props;
195
+ this._api = new apiGateway__namespace.LambdaRestApi(this, apiGatewayName, {
196
+ handler,
197
+ ...lambdaRestApiProps,
198
+ });
199
+ cdk$1.Tags.of(this._api).add(cdk.CDK.TAG.ROLE, roleTag);
200
+ if (host && certificateToUse && hostedZone) {
201
+ this._domainName = this._api.addDomainName(apiDomainName, {
202
+ domainName: host,
203
+ certificate: certificateToUse,
204
+ });
205
+ cdk$1.Tags.of(this._domainName).add(cdk.CDK.TAG.ROLE, roleTag);
206
+ const record = new route53__namespace.ARecord(this, "AliasRecord", {
207
+ recordName: host,
208
+ target: route53__namespace.RecordTarget.fromAlias(new route53Targets__namespace.ApiGatewayDomain(this._domainName)),
209
+ zone: hostedZone,
210
+ });
211
+ cdk$1.Tags.of(record).add(cdk.CDK.TAG.ROLE, cdk.CDK.ROLE.NETWORKING);
212
+ }
213
+ }
214
+ get api() {
215
+ return this._api;
216
+ }
217
+ get url() {
218
+ return this._api.url;
219
+ }
220
+ get certificateArn() {
221
+ return this._certificate?.certificateArn;
222
+ }
223
+ get domainName() {
224
+ return this._domainName?.domainName;
225
+ }
226
+ get host() {
227
+ return this._host;
228
+ }
229
+ get restApiId() {
230
+ return this._api.restApiId;
231
+ }
232
+ get restApiName() {
233
+ return this._api.restApiName;
234
+ }
235
+ get restApiRootResourceId() {
236
+ return this._api.restApiRootResourceId;
237
+ }
238
+ get deploymentStage() {
239
+ return this._api.deploymentStage;
240
+ }
241
+ get domainNameAliasDomainName() {
242
+ return this._domainName?.domainNameAliasDomainName;
243
+ }
244
+ get domainNameAliasHostedZoneId() {
245
+ return this._domainName?.domainNameAliasHostedZoneId;
246
+ }
247
+ get root() {
248
+ return this._api.root;
249
+ }
250
+ get env() {
251
+ return {
252
+ account: cdk$1.Stack.of(this).account,
253
+ region: cdk$1.Stack.of(this).region,
254
+ };
255
+ }
256
+ get stack() {
257
+ return this._api.stack;
258
+ }
259
+ arnForExecuteApi(method, path, stage) {
260
+ return this._api.arnForExecuteApi(method, path, stage);
261
+ }
262
+ metric(metricName, props) {
263
+ return this._api.metric(metricName, props);
264
+ }
265
+ metricCacheHitCount(props) {
266
+ return this._api.metricCacheHitCount(props);
267
+ }
268
+ metricCacheMissCount(props) {
269
+ return this._api.metricCacheMissCount(props);
270
+ }
271
+ metricClientError(props) {
272
+ return this._api.metricClientError(props);
273
+ }
274
+ metricCount(props) {
275
+ return this._api.metricCount(props);
276
+ }
277
+ metricIntegrationLatency(props) {
278
+ return this._api.metricIntegrationLatency(props);
279
+ }
280
+ metricLatency(props) {
281
+ return this._api.metricLatency(props);
282
+ }
283
+ metricServerError(props) {
284
+ return this._api.metricServerError(props);
285
+ }
286
+ applyRemovalPolicy(policy) {
287
+ this._api.applyRemovalPolicy(policy);
288
+ }
289
+ }
290
+
291
+ class JaypieStack extends cdk$1.Stack {
292
+ constructor(scope, id, props = {}) {
293
+ const { key, ...stackProps } = props;
294
+ // Handle stackName
295
+ if (!stackProps.stackName) {
296
+ stackProps.stackName = constructStackName(key);
297
+ }
298
+ // Handle env
299
+ stackProps.env = {
300
+ account: process.env.CDK_DEFAULT_ACCOUNT,
301
+ region: process.env.CDK_DEFAULT_REGION,
302
+ ...stackProps.env,
303
+ };
304
+ super(scope, id, stackProps);
305
+ // Apply tags
306
+ stackTagger(this, { name: stackProps.stackName });
307
+ }
308
+ }
309
+
310
+ class JaypieAppStack extends JaypieStack {
311
+ constructor(scope, id, props = {}) {
312
+ const { key = "app", ...stackProps } = props;
313
+ // Handle stackName
314
+ if (!stackProps.stackName) {
315
+ stackProps.stackName = constructStackName(key);
316
+ }
317
+ super(scope, id, { key, ...stackProps });
318
+ }
319
+ }
320
+
141
321
  class JaypieLambda extends constructs.Construct {
142
322
  constructor(scope, id, props) {
143
323
  super(scope, id);
@@ -417,191 +597,6 @@ class JaypieLambda extends constructs.Construct {
417
597
  }
418
598
  }
419
599
 
420
- class JaypieApiGateway extends constructs.Construct {
421
- constructor(scope, id, props) {
422
- super(scope, id);
423
- const { certificate = true, handler, host: propsHost, name, roleTag = cdk.CDK.ROLE.API, zone: propsZone, } = props;
424
- // Determine zone from props or environment
425
- let zone = propsZone;
426
- if (!zone && process.env.CDK_ENV_API_HOSTED_ZONE) {
427
- zone = process.env.CDK_ENV_API_HOSTED_ZONE;
428
- }
429
- // Determine host from props or environment
430
- let host = propsHost;
431
- if (!host) {
432
- if (process.env.CDK_ENV_API_HOST_NAME) {
433
- host = process.env.CDK_ENV_API_HOST_NAME;
434
- }
435
- else if (process.env.CDK_ENV_API_SUBDOMAIN &&
436
- process.env.CDK_ENV_API_HOSTED_ZONE) {
437
- host = cdk.mergeDomain(process.env.CDK_ENV_API_SUBDOMAIN, process.env.CDK_ENV_API_HOSTED_ZONE);
438
- }
439
- }
440
- const apiGatewayName = name || constructEnvName("ApiGateway");
441
- const certificateName = constructEnvName("Certificate");
442
- const apiDomainName = constructEnvName("ApiDomainName");
443
- let hostedZone;
444
- let certificateToUse;
445
- if (host && zone) {
446
- if (typeof zone === "string") {
447
- hostedZone = route53__namespace.HostedZone.fromLookup(this, "HostedZone", {
448
- domainName: zone,
449
- });
450
- }
451
- else {
452
- hostedZone = zone;
453
- }
454
- if (certificate === true) {
455
- certificateToUse = new acm__namespace.Certificate(this, certificateName, {
456
- domainName: host,
457
- validation: acm__namespace.CertificateValidation.fromDns(hostedZone),
458
- });
459
- cdk$1.Tags.of(certificateToUse).add(cdk.CDK.TAG.ROLE, cdk.CDK.ROLE.HOSTING);
460
- }
461
- else if (typeof certificate === "object") {
462
- certificateToUse = certificate;
463
- }
464
- this._certificate = certificateToUse;
465
- this._host = host;
466
- }
467
- const {
468
- // * `...lambdaRestApiProps` cannot be moved to the first const destructuring because it needs to exclude the custom properties first.
469
- // Ignore the variables we already assigned to other properties
470
- /* eslint-disable @typescript-eslint/no-unused-vars */
471
- certificate: _certificate, host: _host, name: _name, roleTag: _roleTag, zone: _zone, handler: _handler,
472
- /* eslint-enable @typescript-eslint/no-unused-vars */
473
- ...lambdaRestApiProps } = props;
474
- // Check if handler is a JaypieLambda instance and use provisioned alias if available
475
- let handlerToUse = handler;
476
- if (handler instanceof JaypieLambda && handler.provisioned) {
477
- handlerToUse = handler.provisioned;
478
- }
479
- this._api = new apiGateway__namespace.LambdaRestApi(this, apiGatewayName, {
480
- handler: handlerToUse,
481
- ...lambdaRestApiProps,
482
- });
483
- cdk$1.Tags.of(this._api).add(cdk.CDK.TAG.ROLE, roleTag);
484
- if (host && certificateToUse && hostedZone) {
485
- this._domainName = this._api.addDomainName(apiDomainName, {
486
- domainName: host,
487
- certificate: certificateToUse,
488
- });
489
- cdk$1.Tags.of(this._domainName).add(cdk.CDK.TAG.ROLE, roleTag);
490
- const record = new route53__namespace.ARecord(this, "AliasRecord", {
491
- recordName: host,
492
- target: route53__namespace.RecordTarget.fromAlias(new route53Targets__namespace.ApiGatewayDomain(this._domainName)),
493
- zone: hostedZone,
494
- });
495
- cdk$1.Tags.of(record).add(cdk.CDK.TAG.ROLE, cdk.CDK.ROLE.NETWORKING);
496
- }
497
- }
498
- get api() {
499
- return this._api;
500
- }
501
- get url() {
502
- return this._api.url;
503
- }
504
- get certificateArn() {
505
- return this._certificate?.certificateArn;
506
- }
507
- get domainName() {
508
- return this._domainName?.domainName;
509
- }
510
- get host() {
511
- return this._host;
512
- }
513
- get restApiId() {
514
- return this._api.restApiId;
515
- }
516
- get restApiName() {
517
- return this._api.restApiName;
518
- }
519
- get restApiRootResourceId() {
520
- return this._api.restApiRootResourceId;
521
- }
522
- get deploymentStage() {
523
- return this._api.deploymentStage;
524
- }
525
- get domainNameAliasDomainName() {
526
- return this._domainName?.domainNameAliasDomainName;
527
- }
528
- get domainNameAliasHostedZoneId() {
529
- return this._domainName?.domainNameAliasHostedZoneId;
530
- }
531
- get root() {
532
- return this._api.root;
533
- }
534
- get env() {
535
- return {
536
- account: cdk$1.Stack.of(this).account,
537
- region: cdk$1.Stack.of(this).region,
538
- };
539
- }
540
- get stack() {
541
- return this._api.stack;
542
- }
543
- arnForExecuteApi(method, path, stage) {
544
- return this._api.arnForExecuteApi(method, path, stage);
545
- }
546
- metric(metricName, props) {
547
- return this._api.metric(metricName, props);
548
- }
549
- metricCacheHitCount(props) {
550
- return this._api.metricCacheHitCount(props);
551
- }
552
- metricCacheMissCount(props) {
553
- return this._api.metricCacheMissCount(props);
554
- }
555
- metricClientError(props) {
556
- return this._api.metricClientError(props);
557
- }
558
- metricCount(props) {
559
- return this._api.metricCount(props);
560
- }
561
- metricIntegrationLatency(props) {
562
- return this._api.metricIntegrationLatency(props);
563
- }
564
- metricLatency(props) {
565
- return this._api.metricLatency(props);
566
- }
567
- metricServerError(props) {
568
- return this._api.metricServerError(props);
569
- }
570
- applyRemovalPolicy(policy) {
571
- this._api.applyRemovalPolicy(policy);
572
- }
573
- }
574
-
575
- class JaypieStack extends cdk$1.Stack {
576
- constructor(scope, id, props = {}) {
577
- const { key, ...stackProps } = props;
578
- // Handle stackName
579
- if (!stackProps.stackName) {
580
- stackProps.stackName = constructStackName(key);
581
- }
582
- // Handle env
583
- stackProps.env = {
584
- account: process.env.CDK_DEFAULT_ACCOUNT,
585
- region: process.env.CDK_DEFAULT_REGION,
586
- ...stackProps.env,
587
- };
588
- super(scope, id, stackProps);
589
- // Apply tags
590
- stackTagger(this, { name: stackProps.stackName });
591
- }
592
- }
593
-
594
- class JaypieAppStack extends JaypieStack {
595
- constructor(scope, id, props = {}) {
596
- const { key = "app", ...stackProps } = props;
597
- // Handle stackName
598
- if (!stackProps.stackName) {
599
- stackProps.stackName = constructStackName(key);
600
- }
601
- super(scope, id, { key, ...stackProps });
602
- }
603
- }
604
-
605
600
  class JaypieQueuedLambda extends constructs.Construct {
606
601
  constructor(scope, id, props) {
607
602
  super(scope, id);