@fy-stack/cdn-construct 0.0.143 → 0.0.144

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.
@@ -1,3 +1,4 @@
1
+ import type { Attachable } from '@fy-stack/types';
1
2
  import * as cloudfront from 'aws-cdk-lib/aws-cloudfront';
2
3
  import { Construct } from 'constructs';
3
4
  import { CDNConstructProps } from './types';
@@ -5,9 +6,11 @@ import { CDNConstructProps } from './types';
5
6
  * CDNConstruct is a custom construct that sets up a CloudFront distribution
6
7
  * based on provided routing and resource configurations.
7
8
  */
8
- export declare class CDNConstruct extends Construct {
9
+ export declare class CDNConstruct extends Construct implements Attachable {
9
10
  distribution: cloudfront.Distribution;
11
+ domainName: string | undefined;
10
12
  constructor(scope: Construct, id: string, props: CDNConstructProps);
11
13
  private parseDomain;
14
+ attachable(): Record<string, string>;
12
15
  }
13
16
  //# sourceMappingURL=cdn-construct.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"cdn-construct.d.ts","sourceRoot":"","sources":["../../src/lib/cdn-construct.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,UAAU,MAAM,4BAA4B,CAAC;AAGzD,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC,OAAO,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAE5C;;;GAGG;AACH,qBAAa,YAAa,SAAQ,SAAS;IAClC,YAAY,EAAE,UAAU,CAAC,YAAY,CAAC;gBAEjC,KAAK,EAAE,SAAS,EAAE,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,iBAAiB;IAwHlE,OAAO,CAAC,WAAW;CAIpB"}
1
+ {"version":3,"file":"cdn-construct.d.ts","sourceRoot":"","sources":["../../src/lib/cdn-construct.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAe,MAAM,iBAAiB,CAAC;AAE/D,OAAO,KAAK,UAAU,MAAM,4BAA4B,CAAC;AAGzD,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC,OAAO,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAE5C;;;GAGG;AACH,qBAAa,YAAa,SAAQ,SAAU,YAAW,UAAU;IACxD,YAAY,EAAE,UAAU,CAAC,YAAY,CAAC;IACtC,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC;gBAE1B,KAAK,EAAE,SAAS,EAAE,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,iBAAiB;IAuHlE,OAAO,CAAC,WAAW;IAKnB,UAAU,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;CAKrC"}
@@ -13,6 +13,7 @@ const constructs_1 = require("constructs");
13
13
  */
14
14
  class CDNConstruct extends constructs_1.Construct {
15
15
  distribution;
16
+ domainName;
16
17
  constructor(scope, id, props) {
17
18
  super(scope, id);
18
19
  const routes = {};
@@ -32,16 +33,15 @@ class CDNConstruct extends constructs_1.Construct {
32
33
  Object.assign(additionalBehaviors, otherRoutes[i]?.cloudfront(i));
33
34
  }
34
35
  let certificate;
35
- let defaultDomainName;
36
36
  const subjectAlternativeNames = [];
37
37
  const zones = {};
38
38
  if (props.domains) {
39
39
  const [defaultDomain, ...otherRecords] = props.domains;
40
40
  if (defaultDomain) {
41
41
  const { records: [defaultDomainRecord, ...otherDefaultDomainRecords], } = defaultDomain;
42
- defaultDomainName = this.parseDomain(defaultDomainRecord, defaultDomain.domain);
42
+ this.domainName = this.parseDomain(defaultDomainRecord, defaultDomain.domain);
43
43
  zones[defaultDomain.domain] = route53.HostedZone.fromLookup(this, 'Zone0', { domainName: defaultDomain.domain });
44
- zones[defaultDomainName] = zones[defaultDomain.domain];
44
+ zones[this.domainName] = zones[defaultDomain.domain];
45
45
  for (const i in otherDefaultDomainRecords) {
46
46
  const recordDomain = this.parseDomain(otherDefaultDomainRecords[i], defaultDomain.domain);
47
47
  zones[recordDomain] = zones[defaultDomain.domain];
@@ -56,7 +56,7 @@ class CDNConstruct extends constructs_1.Construct {
56
56
  }
57
57
  }
58
58
  certificate = new acm.Certificate(this, 'DomainCertificate', {
59
- domainName: defaultDomainName,
59
+ domainName: this.domainName,
60
60
  subjectAlternativeNames,
61
61
  validation: acm.CertificateValidation.fromDnsMultiZone(zones),
62
62
  });
@@ -66,8 +66,8 @@ class CDNConstruct extends constructs_1.Construct {
66
66
  defaultBehavior,
67
67
  additionalBehaviors,
68
68
  certificate,
69
- domainNames: defaultDomainName
70
- ? [defaultDomainName, ...subjectAlternativeNames]
69
+ domainNames: this.domainName
70
+ ? [this.domainName, ...subjectAlternativeNames]
71
71
  : undefined,
72
72
  priceClass: cloudfront.PriceClass.PRICE_CLASS_100,
73
73
  });
@@ -92,5 +92,10 @@ class CDNConstruct extends constructs_1.Construct {
92
92
  else
93
93
  return `${record}.${domain}`;
94
94
  }
95
+ attachable() {
96
+ return {
97
+ domain: 'https://' + (this.domainName ?? this.distribution.domainName),
98
+ };
99
+ }
95
100
  }
96
101
  exports.CDNConstruct = CDNConstruct;
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@fy-stack/cdn-construct",
3
- "version": "0.0.143",
3
+ "version": "0.0.144",
4
4
  "repository": "https://github.com/festusyuma/fy-stack",
5
5
  "dependencies": {
6
- "@fy-stack/types": "0.0.143",
6
+ "@fy-stack/types": "0.0.144",
7
7
  "tslib": "^2.3.0"
8
8
  },
9
9
  "peerDependencies": {