@openhi/constructs 0.0.117 → 0.0.119

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/lib/index.mjs CHANGED
@@ -28,7 +28,7 @@ import {
28
28
  demoScenarioIdentifier,
29
29
  import_workflows,
30
30
  openhiResourceIdentifier
31
- } from "./chunk-AJQUWHFK.mjs";
31
+ } from "./chunk-WXS3PUHR.mjs";
32
32
  import {
33
33
  OWNING_DELETE_CASCADE_CONSUMER_NAME,
34
34
  OWNING_DELETE_CASCADE_DEFAULT_CONCURRENCY,
@@ -62,7 +62,7 @@ import {
62
62
  import {
63
63
  require_lib
64
64
  } from "./chunk-ZM4GDHHC.mjs";
65
- import "./chunk-QWWLM452.mjs";
65
+ import "./chunk-7WDX6GPO.mjs";
66
66
  import "./chunk-HQ67J7BP.mjs";
67
67
  import "./chunk-QJDHVMKT.mjs";
68
68
  import "./chunk-U7L7T4XU.mjs";
@@ -386,6 +386,16 @@ var OpenHiService = class extends Stack {
386
386
  ),
387
387
  6
388
388
  );
389
+ const releaseBranchHash = hashString(
390
+ [
391
+ appName,
392
+ ohEnv.deploymentTargetRole,
393
+ account,
394
+ region,
395
+ defaultReleaseBranch
396
+ ].join("-"),
397
+ 6
398
+ );
389
399
  const stackHash = hashString(
390
400
  [
391
401
  appName,
@@ -416,6 +426,7 @@ var OpenHiService = class extends Stack {
416
426
  this.branchName = branchName;
417
427
  this.environmentHash = environmentHash;
418
428
  this.branchHash = branchHash;
429
+ this.releaseBranchHash = releaseBranchHash;
419
430
  this.stackHash = stackHash;
420
431
  this.node.setContext(
421
432
  `availability-zones:account=${account}:region=${region}`,
@@ -1443,10 +1454,31 @@ var RootHostedZone = class extends Construct7 {
1443
1454
  };
1444
1455
 
1445
1456
  // src/components/static-hosting/static-content.ts
1446
- import { Bucket as Bucket3 } from "aws-cdk-lib/aws-s3";
1447
1457
  import { BucketDeployment, Source } from "aws-cdk-lib/aws-s3-deployment";
1448
1458
  import { paramCase as paramCase2 } from "change-case";
1449
- import { Construct as Construct9 } from "constructs";
1459
+ import { Construct as Construct8 } from "constructs";
1460
+ var StaticContent = class extends Construct8 {
1461
+ constructor(scope, id, props) {
1462
+ super(scope, id);
1463
+ const stack = OpenHiService.of(scope);
1464
+ const {
1465
+ bucket,
1466
+ contentSourceDirectory,
1467
+ contentDestinationDirectory = "/",
1468
+ subDomain = stack.branchName,
1469
+ fullDomain
1470
+ } = props;
1471
+ const keyPrefix = [paramCase2(subDomain), fullDomain].join(".");
1472
+ const isTestEnv = process.env.JEST_WORKER_ID !== void 0;
1473
+ const sources = isTestEnv ? [] : [Source.asset(contentSourceDirectory)];
1474
+ new BucketDeployment(this, "deploy", {
1475
+ sources,
1476
+ destinationBucket: bucket,
1477
+ retainOnDelete: false,
1478
+ destinationKeyPrefix: `${keyPrefix}${contentDestinationDirectory}`
1479
+ });
1480
+ }
1481
+ };
1450
1482
 
1451
1483
  // src/components/static-hosting/static-hosting.ts
1452
1484
  import * as fs6 from "fs";
@@ -1475,9 +1507,9 @@ import {
1475
1507
  } from "aws-cdk-lib/aws-route53";
1476
1508
  import { CloudFrontTarget } from "aws-cdk-lib/aws-route53-targets";
1477
1509
  import { Bucket as Bucket2 } from "aws-cdk-lib/aws-s3";
1478
- import { Construct as Construct8 } from "constructs";
1510
+ import { Construct as Construct9 } from "constructs";
1479
1511
  var STATIC_HOSTING_SERVICE_TYPE = "website";
1480
- var _StaticHosting = class _StaticHosting extends Construct8 {
1512
+ var _StaticHosting = class _StaticHosting extends Construct9 {
1481
1513
  constructor(scope, id, props = {}) {
1482
1514
  super(scope, id);
1483
1515
  const stack = OpenHiService.of(scope);
@@ -1613,35 +1645,6 @@ _StaticHosting.SSM_PARAM_NAME_DISTRIBUTION_DOMAIN = "STATIC_HOSTING_DISTRIBUTION
1613
1645
  _StaticHosting.SSM_PARAM_NAME_DISTRIBUTION_ID = "STATIC_HOSTING_DISTRIBUTION_ID";
1614
1646
  var StaticHosting = _StaticHosting;
1615
1647
 
1616
- // src/components/static-hosting/static-content.ts
1617
- var StaticContent = class extends Construct9 {
1618
- constructor(scope, id, props) {
1619
- super(scope, id);
1620
- const stack = OpenHiService.of(scope);
1621
- const {
1622
- contentSourceDirectory,
1623
- contentDestinationDirectory = "/",
1624
- subDomain = stack.branchName,
1625
- fullDomain,
1626
- serviceType = STATIC_HOSTING_SERVICE_TYPE
1627
- } = props;
1628
- const keyPrefix = [paramCase2(subDomain), fullDomain].join(".");
1629
- const bucketArn = DiscoverableStringParameter.valueForLookupName(this, {
1630
- ssmParamName: StaticHosting.SSM_PARAM_NAME_BUCKET_ARN,
1631
- serviceType
1632
- });
1633
- const bucket = Bucket3.fromBucketArn(this, "bucket", bucketArn);
1634
- const isTestEnv = process.env.JEST_WORKER_ID !== void 0;
1635
- const sources = isTestEnv ? [] : [Source.asset(contentSourceDirectory)];
1636
- new BucketDeployment(this, "deploy", {
1637
- sources,
1638
- destinationBucket: bucket,
1639
- retainOnDelete: false,
1640
- destinationKeyPrefix: `${keyPrefix}${contentDestinationDirectory}`
1641
- });
1642
- }
1643
- };
1644
-
1645
1648
  // src/services/open-hi-auth-service.ts
1646
1649
  import {
1647
1650
  LambdaVersion,
@@ -2956,6 +2959,7 @@ _OpenHiGraphqlService.SERVICE_TYPE = "graphql-api";
2956
2959
  var OpenHiGraphqlService = _OpenHiGraphqlService;
2957
2960
 
2958
2961
  // src/services/open-hi-website-service.ts
2962
+ import { Bucket as Bucket3 } from "aws-cdk-lib/aws-s3";
2959
2963
  var SSM_PARAM_NAME_FULL_DOMAIN = "WEBSITE_FULL_DOMAIN";
2960
2964
  var _OpenHiWebsiteService = class _OpenHiWebsiteService extends OpenHiService {
2961
2965
  /**
@@ -3026,7 +3030,9 @@ var _OpenHiWebsiteService = class _OpenHiWebsiteService extends OpenHiService {
3026
3030
  });
3027
3031
  this.createFullDomainParameter();
3028
3032
  }
3029
- this.staticContent = this.createStaticContent();
3033
+ if (props.createStaticContent !== false) {
3034
+ this.staticContent = this.createStaticContent();
3035
+ }
3030
3036
  }
3031
3037
  /**
3032
3038
  * Validates that config required for the website stack is present.
@@ -3039,14 +3045,21 @@ var _OpenHiWebsiteService = class _OpenHiWebsiteService extends OpenHiService {
3039
3045
  if (!config.zoneName) {
3040
3046
  throw new Error("Zone name is required");
3041
3047
  }
3048
+ if (!config.hostedZoneId) {
3049
+ throw new Error("Hosted zone ID is required to import the website zone");
3050
+ }
3042
3051
  }
3043
3052
  /**
3044
- * Looks up the child hosted zone published by the Global service.
3053
+ * Imports the website's hosted zone from config attributes (no SSM lookup).
3054
+ * The website attaches DNS records here on the release-branch deploy and
3055
+ * the same zone is imported on feature-branch deploys for any sub-domain
3056
+ * routing.
3045
3057
  * Override to customize.
3046
3058
  */
3047
3059
  createHostedZone() {
3048
- return OpenHiGlobalService.childHostedZoneFromConstruct(this, {
3049
- zoneName: this.config.zoneName
3060
+ return OpenHiGlobalService.rootHostedZoneFromConstruct(this, {
3061
+ zoneName: this.config.zoneName,
3062
+ hostedZoneId: this.config.hostedZoneId
3050
3063
  });
3051
3064
  }
3052
3065
  /**
@@ -3093,15 +3106,40 @@ var _OpenHiWebsiteService = class _OpenHiWebsiteService extends OpenHiService {
3093
3106
  * Creates the StaticContent uploader. Always created so feature-branch
3094
3107
  * deploys can publish content to their own sub-domain folder against the
3095
3108
  * release-branch bucket.
3109
+ *
3110
+ * The destination bucket is resolved here so the construct never has to
3111
+ * branch on release-vs-feature: on the release branch we pass the
3112
+ * just-created {@link staticHosting} bucket directly (no SSM round-trip
3113
+ * within a single stack); on every other branch we look up the bucket
3114
+ * ARN published by the release-branch deploy, addressed against
3115
+ * {@link OpenHiService.releaseBranchHash}.
3096
3116
  */
3097
3117
  createStaticContent() {
3098
3118
  const { contentSourceDirectory, contentDestinationDirectory } = this.props;
3099
3119
  return new StaticContent(this, "static-content", {
3120
+ bucket: this.resolveStaticHostingBucket(),
3100
3121
  contentSourceDirectory,
3101
3122
  contentDestinationDirectory,
3102
- fullDomain: this.fullDomain,
3103
- serviceType: _OpenHiWebsiteService.SERVICE_TYPE
3123
+ fullDomain: this.fullDomain
3124
+ });
3125
+ }
3126
+ /**
3127
+ * Returns an {@link IBucket} pointing at the static-hosting bucket the
3128
+ * uploader writes to. On the release-branch deploy this is the bucket
3129
+ * just provisioned by {@link staticHosting}; on every other deploy it's
3130
+ * imported from the bucket ARN the release-branch deploy publishes to
3131
+ * SSM, addressed against {@link OpenHiService.releaseBranchHash}.
3132
+ */
3133
+ resolveStaticHostingBucket() {
3134
+ if (this.staticHosting) {
3135
+ return this.staticHosting.bucket;
3136
+ }
3137
+ const bucketArn = DiscoverableStringParameter.valueForLookupName(this, {
3138
+ ssmParamName: StaticHosting.SSM_PARAM_NAME_BUCKET_ARN,
3139
+ serviceType: _OpenHiWebsiteService.SERVICE_TYPE,
3140
+ branchHash: this.releaseBranchHash
3104
3141
  });
3142
+ return Bucket3.fromBucketArn(this, "shared-bucket", bucketArn);
3105
3143
  }
3106
3144
  };
3107
3145
  _OpenHiWebsiteService.SERVICE_TYPE = "website";