@fy-stack/cdn-construct 0.0.143 → 0.0.145

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;IA2HlE,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 = {};
@@ -25,23 +26,24 @@ class CDNConstruct extends constructs_1.Construct {
25
26
  const { '/*': base, ...otherRoutes } = routes;
26
27
  if (!base)
27
28
  throw new Error('no base route');
28
- const { '/*': defaultBehavior, ...additionalBehaviors } = base.cloudfront('');
29
+ const { '/*': defaultBehavior, ...additionalDefaultBehaviors } = base.cloudfront('');
29
30
  if (!defaultBehavior)
30
31
  throw new Error('no default behaviour');
32
+ const additionalBehaviors = {};
31
33
  for (const i in otherRoutes) {
32
34
  Object.assign(additionalBehaviors, otherRoutes[i]?.cloudfront(i));
33
35
  }
36
+ Object.assign(additionalBehaviors, additionalDefaultBehaviors);
34
37
  let certificate;
35
- let defaultDomainName;
36
38
  const subjectAlternativeNames = [];
37
39
  const zones = {};
38
40
  if (props.domains) {
39
41
  const [defaultDomain, ...otherRecords] = props.domains;
40
42
  if (defaultDomain) {
41
43
  const { records: [defaultDomainRecord, ...otherDefaultDomainRecords], } = defaultDomain;
42
- defaultDomainName = this.parseDomain(defaultDomainRecord, defaultDomain.domain);
44
+ this.domainName = this.parseDomain(defaultDomainRecord, defaultDomain.domain);
43
45
  zones[defaultDomain.domain] = route53.HostedZone.fromLookup(this, 'Zone0', { domainName: defaultDomain.domain });
44
- zones[defaultDomainName] = zones[defaultDomain.domain];
46
+ zones[this.domainName] = zones[defaultDomain.domain];
45
47
  for (const i in otherDefaultDomainRecords) {
46
48
  const recordDomain = this.parseDomain(otherDefaultDomainRecords[i], defaultDomain.domain);
47
49
  zones[recordDomain] = zones[defaultDomain.domain];
@@ -56,7 +58,7 @@ class CDNConstruct extends constructs_1.Construct {
56
58
  }
57
59
  }
58
60
  certificate = new acm.Certificate(this, 'DomainCertificate', {
59
- domainName: defaultDomainName,
61
+ domainName: this.domainName,
60
62
  subjectAlternativeNames,
61
63
  validation: acm.CertificateValidation.fromDnsMultiZone(zones),
62
64
  });
@@ -66,8 +68,8 @@ class CDNConstruct extends constructs_1.Construct {
66
68
  defaultBehavior,
67
69
  additionalBehaviors,
68
70
  certificate,
69
- domainNames: defaultDomainName
70
- ? [defaultDomainName, ...subjectAlternativeNames]
71
+ domainNames: this.domainName
72
+ ? [this.domainName, ...subjectAlternativeNames]
71
73
  : undefined,
72
74
  priceClass: cloudfront.PriceClass.PRICE_CLASS_100,
73
75
  });
@@ -92,5 +94,10 @@ class CDNConstruct extends constructs_1.Construct {
92
94
  else
93
95
  return `${record}.${domain}`;
94
96
  }
97
+ attachable() {
98
+ return {
99
+ domain: 'https://' + (this.domainName ?? this.distribution.domainName),
100
+ };
101
+ }
95
102
  }
96
103
  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.145",
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.145",
7
7
  "tslib": "^2.3.0"
8
8
  },
9
9
  "peerDependencies": {