@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.
package/dist/esm/index.js CHANGED
@@ -1,18 +1,18 @@
1
1
  import { Construct } from 'constructs';
2
2
  import * as cdk from 'aws-cdk-lib';
3
- import { Tags, Duration, Stack, RemovalPolicy, Fn, CfnOutput, SecretValue } from 'aws-cdk-lib';
3
+ import { Tags, Stack, Duration, RemovalPolicy, Fn, CfnOutput, SecretValue } from 'aws-cdk-lib';
4
4
  import * as acm from 'aws-cdk-lib/aws-certificatemanager';
5
5
  import * as apiGateway from 'aws-cdk-lib/aws-apigateway';
6
6
  import * as route53 from 'aws-cdk-lib/aws-route53';
7
7
  import { HostedZone } from 'aws-cdk-lib/aws-route53';
8
8
  import * as route53Targets from 'aws-cdk-lib/aws-route53-targets';
9
9
  import { CDK as CDK$2, mergeDomain, isValidSubdomain, ConfigurationError, isValidHostname } from '@jaypie/cdk';
10
- import * as lambda from 'aws-cdk-lib/aws-lambda';
11
- import * as secretsmanager from 'aws-cdk-lib/aws-secretsmanager';
12
10
  import * as s3 from 'aws-cdk-lib/aws-s3';
13
11
  import * as s3n from 'aws-cdk-lib/aws-s3-notifications';
12
+ import * as lambda from 'aws-cdk-lib/aws-lambda';
14
13
  import * as sqs from 'aws-cdk-lib/aws-sqs';
15
14
  import * as lambdaEventSources from 'aws-cdk-lib/aws-lambda-event-sources';
15
+ import * as secretsmanager from 'aws-cdk-lib/aws-secretsmanager';
16
16
  import { ServicePrincipal, Role, FederatedPrincipal, PolicyStatement, Effect } from 'aws-cdk-lib/aws-iam';
17
17
  import { LogGroup, RetentionDays, FilterPattern } from 'aws-cdk-lib/aws-logs';
18
18
  import * as sso from 'aws-cdk-lib/aws-sso';
@@ -106,6 +106,186 @@ function stackTagger(stack, { name } = {}) {
106
106
  return true;
107
107
  }
108
108
 
109
+ class JaypieApiGateway extends Construct {
110
+ constructor(scope, id, props) {
111
+ super(scope, id);
112
+ const { certificate = true, handler, host: propsHost, name, roleTag = CDK$2.ROLE.API, zone: propsZone, } = props;
113
+ // Determine zone from props or environment
114
+ let zone = propsZone;
115
+ if (!zone && process.env.CDK_ENV_API_HOSTED_ZONE) {
116
+ zone = process.env.CDK_ENV_API_HOSTED_ZONE;
117
+ }
118
+ // Determine host from props or environment
119
+ let host = propsHost;
120
+ if (!host) {
121
+ if (process.env.CDK_ENV_API_HOST_NAME) {
122
+ host = process.env.CDK_ENV_API_HOST_NAME;
123
+ }
124
+ else if (process.env.CDK_ENV_API_SUBDOMAIN &&
125
+ process.env.CDK_ENV_API_HOSTED_ZONE) {
126
+ host = mergeDomain(process.env.CDK_ENV_API_SUBDOMAIN, process.env.CDK_ENV_API_HOSTED_ZONE);
127
+ }
128
+ }
129
+ const apiGatewayName = name || constructEnvName("ApiGateway");
130
+ const certificateName = constructEnvName("Certificate");
131
+ const apiDomainName = constructEnvName("ApiDomainName");
132
+ let hostedZone;
133
+ let certificateToUse;
134
+ if (host && zone) {
135
+ if (typeof zone === "string") {
136
+ hostedZone = route53.HostedZone.fromLookup(this, "HostedZone", {
137
+ domainName: zone,
138
+ });
139
+ }
140
+ else {
141
+ hostedZone = zone;
142
+ }
143
+ if (certificate === true) {
144
+ certificateToUse = new acm.Certificate(this, certificateName, {
145
+ domainName: host,
146
+ validation: acm.CertificateValidation.fromDns(hostedZone),
147
+ });
148
+ Tags.of(certificateToUse).add(CDK$2.TAG.ROLE, CDK$2.ROLE.HOSTING);
149
+ }
150
+ else if (typeof certificate === "object") {
151
+ certificateToUse = certificate;
152
+ }
153
+ this._certificate = certificateToUse;
154
+ this._host = host;
155
+ }
156
+ const {
157
+ // * `...lambdaRestApiProps` cannot be moved to the first const destructuring because it needs to exclude the custom properties first.
158
+ // Ignore the variables we already assigned to other properties
159
+ /* eslint-disable @typescript-eslint/no-unused-vars */
160
+ certificate: _certificate, host: _host, name: _name, roleTag: _roleTag, zone: _zone, handler: _handler,
161
+ /* eslint-enable @typescript-eslint/no-unused-vars */
162
+ ...lambdaRestApiProps } = props;
163
+ this._api = new apiGateway.LambdaRestApi(this, apiGatewayName, {
164
+ handler,
165
+ ...lambdaRestApiProps,
166
+ });
167
+ Tags.of(this._api).add(CDK$2.TAG.ROLE, roleTag);
168
+ if (host && certificateToUse && hostedZone) {
169
+ this._domainName = this._api.addDomainName(apiDomainName, {
170
+ domainName: host,
171
+ certificate: certificateToUse,
172
+ });
173
+ Tags.of(this._domainName).add(CDK$2.TAG.ROLE, roleTag);
174
+ const record = new route53.ARecord(this, "AliasRecord", {
175
+ recordName: host,
176
+ target: route53.RecordTarget.fromAlias(new route53Targets.ApiGatewayDomain(this._domainName)),
177
+ zone: hostedZone,
178
+ });
179
+ Tags.of(record).add(CDK$2.TAG.ROLE, CDK$2.ROLE.NETWORKING);
180
+ }
181
+ }
182
+ get api() {
183
+ return this._api;
184
+ }
185
+ get url() {
186
+ return this._api.url;
187
+ }
188
+ get certificateArn() {
189
+ return this._certificate?.certificateArn;
190
+ }
191
+ get domainName() {
192
+ return this._domainName?.domainName;
193
+ }
194
+ get host() {
195
+ return this._host;
196
+ }
197
+ get restApiId() {
198
+ return this._api.restApiId;
199
+ }
200
+ get restApiName() {
201
+ return this._api.restApiName;
202
+ }
203
+ get restApiRootResourceId() {
204
+ return this._api.restApiRootResourceId;
205
+ }
206
+ get deploymentStage() {
207
+ return this._api.deploymentStage;
208
+ }
209
+ get domainNameAliasDomainName() {
210
+ return this._domainName?.domainNameAliasDomainName;
211
+ }
212
+ get domainNameAliasHostedZoneId() {
213
+ return this._domainName?.domainNameAliasHostedZoneId;
214
+ }
215
+ get root() {
216
+ return this._api.root;
217
+ }
218
+ get env() {
219
+ return {
220
+ account: Stack.of(this).account,
221
+ region: Stack.of(this).region,
222
+ };
223
+ }
224
+ get stack() {
225
+ return this._api.stack;
226
+ }
227
+ arnForExecuteApi(method, path, stage) {
228
+ return this._api.arnForExecuteApi(method, path, stage);
229
+ }
230
+ metric(metricName, props) {
231
+ return this._api.metric(metricName, props);
232
+ }
233
+ metricCacheHitCount(props) {
234
+ return this._api.metricCacheHitCount(props);
235
+ }
236
+ metricCacheMissCount(props) {
237
+ return this._api.metricCacheMissCount(props);
238
+ }
239
+ metricClientError(props) {
240
+ return this._api.metricClientError(props);
241
+ }
242
+ metricCount(props) {
243
+ return this._api.metricCount(props);
244
+ }
245
+ metricIntegrationLatency(props) {
246
+ return this._api.metricIntegrationLatency(props);
247
+ }
248
+ metricLatency(props) {
249
+ return this._api.metricLatency(props);
250
+ }
251
+ metricServerError(props) {
252
+ return this._api.metricServerError(props);
253
+ }
254
+ applyRemovalPolicy(policy) {
255
+ this._api.applyRemovalPolicy(policy);
256
+ }
257
+ }
258
+
259
+ class JaypieStack extends Stack {
260
+ constructor(scope, id, props = {}) {
261
+ const { key, ...stackProps } = props;
262
+ // Handle stackName
263
+ if (!stackProps.stackName) {
264
+ stackProps.stackName = constructStackName(key);
265
+ }
266
+ // Handle env
267
+ stackProps.env = {
268
+ account: process.env.CDK_DEFAULT_ACCOUNT,
269
+ region: process.env.CDK_DEFAULT_REGION,
270
+ ...stackProps.env,
271
+ };
272
+ super(scope, id, stackProps);
273
+ // Apply tags
274
+ stackTagger(this, { name: stackProps.stackName });
275
+ }
276
+ }
277
+
278
+ class JaypieAppStack extends JaypieStack {
279
+ constructor(scope, id, props = {}) {
280
+ const { key = "app", ...stackProps } = props;
281
+ // Handle stackName
282
+ if (!stackProps.stackName) {
283
+ stackProps.stackName = constructStackName(key);
284
+ }
285
+ super(scope, id, { key, ...stackProps });
286
+ }
287
+ }
288
+
109
289
  class JaypieLambda extends Construct {
110
290
  constructor(scope, id, props) {
111
291
  super(scope, id);
@@ -385,191 +565,6 @@ class JaypieLambda extends Construct {
385
565
  }
386
566
  }
387
567
 
388
- class JaypieApiGateway extends Construct {
389
- constructor(scope, id, props) {
390
- super(scope, id);
391
- const { certificate = true, handler, host: propsHost, name, roleTag = CDK$2.ROLE.API, zone: propsZone, } = props;
392
- // Determine zone from props or environment
393
- let zone = propsZone;
394
- if (!zone && process.env.CDK_ENV_API_HOSTED_ZONE) {
395
- zone = process.env.CDK_ENV_API_HOSTED_ZONE;
396
- }
397
- // Determine host from props or environment
398
- let host = propsHost;
399
- if (!host) {
400
- if (process.env.CDK_ENV_API_HOST_NAME) {
401
- host = process.env.CDK_ENV_API_HOST_NAME;
402
- }
403
- else if (process.env.CDK_ENV_API_SUBDOMAIN &&
404
- process.env.CDK_ENV_API_HOSTED_ZONE) {
405
- host = mergeDomain(process.env.CDK_ENV_API_SUBDOMAIN, process.env.CDK_ENV_API_HOSTED_ZONE);
406
- }
407
- }
408
- const apiGatewayName = name || constructEnvName("ApiGateway");
409
- const certificateName = constructEnvName("Certificate");
410
- const apiDomainName = constructEnvName("ApiDomainName");
411
- let hostedZone;
412
- let certificateToUse;
413
- if (host && zone) {
414
- if (typeof zone === "string") {
415
- hostedZone = route53.HostedZone.fromLookup(this, "HostedZone", {
416
- domainName: zone,
417
- });
418
- }
419
- else {
420
- hostedZone = zone;
421
- }
422
- if (certificate === true) {
423
- certificateToUse = new acm.Certificate(this, certificateName, {
424
- domainName: host,
425
- validation: acm.CertificateValidation.fromDns(hostedZone),
426
- });
427
- Tags.of(certificateToUse).add(CDK$2.TAG.ROLE, CDK$2.ROLE.HOSTING);
428
- }
429
- else if (typeof certificate === "object") {
430
- certificateToUse = certificate;
431
- }
432
- this._certificate = certificateToUse;
433
- this._host = host;
434
- }
435
- const {
436
- // * `...lambdaRestApiProps` cannot be moved to the first const destructuring because it needs to exclude the custom properties first.
437
- // Ignore the variables we already assigned to other properties
438
- /* eslint-disable @typescript-eslint/no-unused-vars */
439
- certificate: _certificate, host: _host, name: _name, roleTag: _roleTag, zone: _zone, handler: _handler,
440
- /* eslint-enable @typescript-eslint/no-unused-vars */
441
- ...lambdaRestApiProps } = props;
442
- // Check if handler is a JaypieLambda instance and use provisioned alias if available
443
- let handlerToUse = handler;
444
- if (handler instanceof JaypieLambda && handler.provisioned) {
445
- handlerToUse = handler.provisioned;
446
- }
447
- this._api = new apiGateway.LambdaRestApi(this, apiGatewayName, {
448
- handler: handlerToUse,
449
- ...lambdaRestApiProps,
450
- });
451
- Tags.of(this._api).add(CDK$2.TAG.ROLE, roleTag);
452
- if (host && certificateToUse && hostedZone) {
453
- this._domainName = this._api.addDomainName(apiDomainName, {
454
- domainName: host,
455
- certificate: certificateToUse,
456
- });
457
- Tags.of(this._domainName).add(CDK$2.TAG.ROLE, roleTag);
458
- const record = new route53.ARecord(this, "AliasRecord", {
459
- recordName: host,
460
- target: route53.RecordTarget.fromAlias(new route53Targets.ApiGatewayDomain(this._domainName)),
461
- zone: hostedZone,
462
- });
463
- Tags.of(record).add(CDK$2.TAG.ROLE, CDK$2.ROLE.NETWORKING);
464
- }
465
- }
466
- get api() {
467
- return this._api;
468
- }
469
- get url() {
470
- return this._api.url;
471
- }
472
- get certificateArn() {
473
- return this._certificate?.certificateArn;
474
- }
475
- get domainName() {
476
- return this._domainName?.domainName;
477
- }
478
- get host() {
479
- return this._host;
480
- }
481
- get restApiId() {
482
- return this._api.restApiId;
483
- }
484
- get restApiName() {
485
- return this._api.restApiName;
486
- }
487
- get restApiRootResourceId() {
488
- return this._api.restApiRootResourceId;
489
- }
490
- get deploymentStage() {
491
- return this._api.deploymentStage;
492
- }
493
- get domainNameAliasDomainName() {
494
- return this._domainName?.domainNameAliasDomainName;
495
- }
496
- get domainNameAliasHostedZoneId() {
497
- return this._domainName?.domainNameAliasHostedZoneId;
498
- }
499
- get root() {
500
- return this._api.root;
501
- }
502
- get env() {
503
- return {
504
- account: Stack.of(this).account,
505
- region: Stack.of(this).region,
506
- };
507
- }
508
- get stack() {
509
- return this._api.stack;
510
- }
511
- arnForExecuteApi(method, path, stage) {
512
- return this._api.arnForExecuteApi(method, path, stage);
513
- }
514
- metric(metricName, props) {
515
- return this._api.metric(metricName, props);
516
- }
517
- metricCacheHitCount(props) {
518
- return this._api.metricCacheHitCount(props);
519
- }
520
- metricCacheMissCount(props) {
521
- return this._api.metricCacheMissCount(props);
522
- }
523
- metricClientError(props) {
524
- return this._api.metricClientError(props);
525
- }
526
- metricCount(props) {
527
- return this._api.metricCount(props);
528
- }
529
- metricIntegrationLatency(props) {
530
- return this._api.metricIntegrationLatency(props);
531
- }
532
- metricLatency(props) {
533
- return this._api.metricLatency(props);
534
- }
535
- metricServerError(props) {
536
- return this._api.metricServerError(props);
537
- }
538
- applyRemovalPolicy(policy) {
539
- this._api.applyRemovalPolicy(policy);
540
- }
541
- }
542
-
543
- class JaypieStack extends Stack {
544
- constructor(scope, id, props = {}) {
545
- const { key, ...stackProps } = props;
546
- // Handle stackName
547
- if (!stackProps.stackName) {
548
- stackProps.stackName = constructStackName(key);
549
- }
550
- // Handle env
551
- stackProps.env = {
552
- account: process.env.CDK_DEFAULT_ACCOUNT,
553
- region: process.env.CDK_DEFAULT_REGION,
554
- ...stackProps.env,
555
- };
556
- super(scope, id, stackProps);
557
- // Apply tags
558
- stackTagger(this, { name: stackProps.stackName });
559
- }
560
- }
561
-
562
- class JaypieAppStack extends JaypieStack {
563
- constructor(scope, id, props = {}) {
564
- const { key = "app", ...stackProps } = props;
565
- // Handle stackName
566
- if (!stackProps.stackName) {
567
- stackProps.stackName = constructStackName(key);
568
- }
569
- super(scope, id, { key, ...stackProps });
570
- }
571
- }
572
-
573
568
  class JaypieQueuedLambda extends Construct {
574
569
  constructor(scope, id, props) {
575
570
  super(scope, id);