@openhi/constructs 0.0.25 → 0.0.27

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.d.mts CHANGED
@@ -11,6 +11,8 @@ import { Table, TableProps, ITable } from 'aws-cdk-lib/aws-dynamodb';
11
11
  import { EventBus, EventBusProps, IEventBus } from 'aws-cdk-lib/aws-events';
12
12
  import { HostedZone, HostedZoneProps, IHostedZone, HostedZoneAttributes } from 'aws-cdk-lib/aws-route53';
13
13
  import { StringParameterProps, StringParameter } from 'aws-cdk-lib/aws-ssm';
14
+ import { Distribution, DistributionProps } from 'aws-cdk-lib/aws-cloudfront';
15
+ import { IBucket, BucketProps } from 'aws-cdk-lib/aws-s3';
14
16
  import { IFunction } from 'aws-cdk-lib/aws-lambda';
15
17
  import { Duration } from 'aws-cdk-lib/core';
16
18
 
@@ -584,6 +586,50 @@ declare class DiscoverableStringParameter extends StringParameter {
584
586
  constructor(scope: Construct, id: string, props: DiscoverableStringParameterProps);
585
587
  }
586
588
 
589
+ /**
590
+ * Service type for the website service. Used in SSM parameter paths and by
591
+ * OpenHiWebsiteService for fromConstruct() lookups.
592
+ */
593
+ declare const STATIC_HOSTING_SERVICE_TYPE = "website";
594
+ /**
595
+ * Props for the StaticHosting construct.
596
+ */
597
+ interface StaticHostingProps {
598
+ /**
599
+ * Optional S3 bucket props. Bucket name must not be set statically.
600
+ */
601
+ readonly bucketProps?: Omit<BucketProps, "bucketName">;
602
+ /**
603
+ * Optional CloudFront distribution props. Do not enable invalidation.
604
+ * Default TTL is 10 seconds via a custom cache policy.
605
+ */
606
+ readonly distributionProps?: Omit<DistributionProps, "defaultBehavior" | "defaultRootObject">;
607
+ /**
608
+ * Service type for SSM parameter paths.
609
+ * @default STATIC_HOSTING_SERVICE_TYPE ("website")
610
+ */
611
+ readonly serviceType?: string;
612
+ }
613
+ /**
614
+ * Static hosting: S3 bucket (private) + CloudFront distribution with Origin
615
+ * Access Control (OAC). Stores bucket ARN and distribution ARN in SSM via
616
+ * DiscoverableStringParameter for cross-stack lookup. No cache invalidation;
617
+ * default TTL 10 seconds.
618
+ */
619
+ declare class StaticHosting extends Construct {
620
+ /**
621
+ * SSM parameter name for the S3 bucket ARN.
622
+ */
623
+ static readonly SSM_PARAM_NAME_BUCKET_ARN = "STATIC_HOSTING_BUCKET_ARN";
624
+ /**
625
+ * SSM parameter name for the CloudFront distribution ARN.
626
+ */
627
+ static readonly SSM_PARAM_NAME_DISTRIBUTION_ARN = "STATIC_HOSTING_DISTRIBUTION_ARN";
628
+ readonly bucket: IBucket;
629
+ readonly distribution: Distribution;
630
+ constructor(scope: Construct, id: string, props?: StaticHostingProps);
631
+ }
632
+
587
633
  /**
588
634
  * @see sites/www-docs/content/packages/@openhi/constructs/services/open-hi-auth-service.md
589
635
  */
@@ -907,4 +953,4 @@ declare class OpenHiGraphqlService extends OpenHiService {
907
953
  protected createRootGraphqlApi(): RootGraphqlApi;
908
954
  }
909
955
 
910
- export { type BuildParameterNameProps, ChildHostedZone, type ChildHostedZoneProps, CognitoUserPool, CognitoUserPoolClient, CognitoUserPoolDomain, CognitoUserPoolKmsKey, DataEventBus, DiscoverableStringParameter, type DiscoverableStringParameterProps, DynamoDbDataStore, type DynamoDbDataStoreProps, OpenHiApp, type OpenHiAppProps, OpenHiAuthService, type OpenHiAuthServiceProps, OpenHiDataService, type OpenHiDataServiceProps, OpenHiEnvironment, type OpenHiEnvironmentProps, OpenHiGlobalService, type OpenHiGlobalServiceProps, OpenHiGraphqlService, type OpenHiGraphqlServiceProps, OpenHiRestApiService, type OpenHiRestApiServiceProps, OpenHiService, type OpenHiServiceProps, type OpenHiServiceType, OpenHiStage, type OpenHiStageProps, OpsEventBus, PreTokenGenerationLambda, REST_API_BASE_URL_SSM_NAME, type RestApiCorsOptions, RootGraphqlApi, type RootGraphqlApiProps, RootHostedZone, RootHttpApi, RootWildcardCertificate, getDynamoDbDataStoreTableName };
956
+ export { type BuildParameterNameProps, ChildHostedZone, type ChildHostedZoneProps, CognitoUserPool, CognitoUserPoolClient, CognitoUserPoolDomain, CognitoUserPoolKmsKey, DataEventBus, DiscoverableStringParameter, type DiscoverableStringParameterProps, DynamoDbDataStore, type DynamoDbDataStoreProps, OpenHiApp, type OpenHiAppProps, OpenHiAuthService, type OpenHiAuthServiceProps, OpenHiDataService, type OpenHiDataServiceProps, OpenHiEnvironment, type OpenHiEnvironmentProps, OpenHiGlobalService, type OpenHiGlobalServiceProps, OpenHiGraphqlService, type OpenHiGraphqlServiceProps, OpenHiRestApiService, type OpenHiRestApiServiceProps, OpenHiService, type OpenHiServiceProps, type OpenHiServiceType, OpenHiStage, type OpenHiStageProps, OpsEventBus, PreTokenGenerationLambda, REST_API_BASE_URL_SSM_NAME, type RestApiCorsOptions, RootGraphqlApi, type RootGraphqlApiProps, RootHostedZone, RootHttpApi, RootWildcardCertificate, STATIC_HOSTING_SERVICE_TYPE, StaticHosting, type StaticHostingProps, getDynamoDbDataStoreTableName };
package/lib/index.d.ts CHANGED
@@ -10,6 +10,8 @@ import { Table, TableProps, ITable } from 'aws-cdk-lib/aws-dynamodb';
10
10
  import { EventBus, EventBusProps, IEventBus } from 'aws-cdk-lib/aws-events';
11
11
  import { HostedZone, HostedZoneProps, IHostedZone, HostedZoneAttributes } from 'aws-cdk-lib/aws-route53';
12
12
  import { StringParameterProps, StringParameter } from 'aws-cdk-lib/aws-ssm';
13
+ import { Distribution, DistributionProps } from 'aws-cdk-lib/aws-cloudfront';
14
+ import { IBucket, BucketProps } from 'aws-cdk-lib/aws-s3';
13
15
  import { IFunction } from 'aws-cdk-lib/aws-lambda';
14
16
  import { Duration } from 'aws-cdk-lib/core';
15
17
 
@@ -664,6 +666,50 @@ declare class DiscoverableStringParameter extends StringParameter {
664
666
  constructor(scope: Construct, id: string, props: DiscoverableStringParameterProps);
665
667
  }
666
668
 
669
+ /**
670
+ * Service type for the website service. Used in SSM parameter paths and by
671
+ * OpenHiWebsiteService for fromConstruct() lookups.
672
+ */
673
+ declare const STATIC_HOSTING_SERVICE_TYPE = "website";
674
+ /**
675
+ * Props for the StaticHosting construct.
676
+ */
677
+ interface StaticHostingProps {
678
+ /**
679
+ * Optional S3 bucket props. Bucket name must not be set statically.
680
+ */
681
+ readonly bucketProps?: Omit<BucketProps, "bucketName">;
682
+ /**
683
+ * Optional CloudFront distribution props. Do not enable invalidation.
684
+ * Default TTL is 10 seconds via a custom cache policy.
685
+ */
686
+ readonly distributionProps?: Omit<DistributionProps, "defaultBehavior" | "defaultRootObject">;
687
+ /**
688
+ * Service type for SSM parameter paths.
689
+ * @default STATIC_HOSTING_SERVICE_TYPE ("website")
690
+ */
691
+ readonly serviceType?: string;
692
+ }
693
+ /**
694
+ * Static hosting: S3 bucket (private) + CloudFront distribution with Origin
695
+ * Access Control (OAC). Stores bucket ARN and distribution ARN in SSM via
696
+ * DiscoverableStringParameter for cross-stack lookup. No cache invalidation;
697
+ * default TTL 10 seconds.
698
+ */
699
+ declare class StaticHosting extends Construct {
700
+ /**
701
+ * SSM parameter name for the S3 bucket ARN.
702
+ */
703
+ static readonly SSM_PARAM_NAME_BUCKET_ARN = "STATIC_HOSTING_BUCKET_ARN";
704
+ /**
705
+ * SSM parameter name for the CloudFront distribution ARN.
706
+ */
707
+ static readonly SSM_PARAM_NAME_DISTRIBUTION_ARN = "STATIC_HOSTING_DISTRIBUTION_ARN";
708
+ readonly bucket: IBucket;
709
+ readonly distribution: Distribution;
710
+ constructor(scope: Construct, id: string, props?: StaticHostingProps);
711
+ }
712
+
667
713
  /**
668
714
  * @see sites/www-docs/content/packages/@openhi/constructs/services/open-hi-auth-service.md
669
715
  */
@@ -987,5 +1033,5 @@ declare class OpenHiGraphqlService extends OpenHiService {
987
1033
  protected createRootGraphqlApi(): RootGraphqlApi;
988
1034
  }
989
1035
 
990
- export { ChildHostedZone, CognitoUserPool, CognitoUserPoolClient, CognitoUserPoolDomain, CognitoUserPoolKmsKey, DataEventBus, DiscoverableStringParameter, DynamoDbDataStore, OpenHiApp, OpenHiAuthService, OpenHiDataService, OpenHiEnvironment, OpenHiGlobalService, OpenHiGraphqlService, OpenHiRestApiService, OpenHiService, OpenHiStage, OpsEventBus, PreTokenGenerationLambda, REST_API_BASE_URL_SSM_NAME, RootGraphqlApi, RootHostedZone, RootHttpApi, RootWildcardCertificate, getDynamoDbDataStoreTableName };
991
- export type { BuildParameterNameProps, ChildHostedZoneProps, DiscoverableStringParameterProps, DynamoDbDataStoreProps, OpenHiAppProps, OpenHiAuthServiceProps, OpenHiDataServiceProps, OpenHiEnvironmentProps, OpenHiGlobalServiceProps, OpenHiGraphqlServiceProps, OpenHiRestApiServiceProps, OpenHiServiceProps, OpenHiServiceType, OpenHiStageProps, RestApiCorsOptions, RootGraphqlApiProps };
1036
+ export { ChildHostedZone, CognitoUserPool, CognitoUserPoolClient, CognitoUserPoolDomain, CognitoUserPoolKmsKey, DataEventBus, DiscoverableStringParameter, DynamoDbDataStore, OpenHiApp, OpenHiAuthService, OpenHiDataService, OpenHiEnvironment, OpenHiGlobalService, OpenHiGraphqlService, OpenHiRestApiService, OpenHiService, OpenHiStage, OpsEventBus, PreTokenGenerationLambda, REST_API_BASE_URL_SSM_NAME, RootGraphqlApi, RootHostedZone, RootHttpApi, RootWildcardCertificate, STATIC_HOSTING_SERVICE_TYPE, StaticHosting, getDynamoDbDataStoreTableName };
1037
+ export type { BuildParameterNameProps, ChildHostedZoneProps, DiscoverableStringParameterProps, DynamoDbDataStoreProps, OpenHiAppProps, OpenHiAuthServiceProps, OpenHiDataServiceProps, OpenHiEnvironmentProps, OpenHiGlobalServiceProps, OpenHiGraphqlServiceProps, OpenHiRestApiServiceProps, OpenHiServiceProps, OpenHiServiceType, OpenHiStageProps, RestApiCorsOptions, RootGraphqlApiProps, StaticHostingProps };
package/lib/index.js CHANGED
@@ -117,6 +117,8 @@ __export(src_exports, {
117
117
  RootHostedZone: () => RootHostedZone,
118
118
  RootHttpApi: () => RootHttpApi,
119
119
  RootWildcardCertificate: () => RootWildcardCertificate,
120
+ STATIC_HOSTING_SERVICE_TYPE: () => STATIC_HOSTING_SERVICE_TYPE,
121
+ StaticHosting: () => StaticHosting,
120
122
  getDynamoDbDataStoreTableName: () => getDynamoDbDataStoreTableName
121
123
  });
122
124
  module.exports = __toCommonJS(src_exports);
@@ -838,6 +840,64 @@ var import_constructs2 = require("constructs");
838
840
  var RootHostedZone = class extends import_constructs2.Construct {
839
841
  };
840
842
 
843
+ // src/components/static-hosting/static-hosting.ts
844
+ var import_aws_cloudfront = require("aws-cdk-lib/aws-cloudfront");
845
+ var import_aws_cloudfront_origins = require("aws-cdk-lib/aws-cloudfront-origins");
846
+ var import_aws_s3 = require("aws-cdk-lib/aws-s3");
847
+ var import_core = require("aws-cdk-lib/core");
848
+ var import_constructs3 = require("constructs");
849
+ var STATIC_HOSTING_SERVICE_TYPE = "website";
850
+ var _StaticHosting = class _StaticHosting extends import_constructs3.Construct {
851
+ constructor(scope, id, props = {}) {
852
+ super(scope, id);
853
+ const stack = OpenHiService.of(scope);
854
+ const serviceType = props.serviceType ?? STATIC_HOSTING_SERVICE_TYPE;
855
+ this.bucket = new import_aws_s3.Bucket(this, "bucket", {
856
+ blockPublicAccess: {
857
+ blockPublicAcls: true,
858
+ blockPublicPolicy: true,
859
+ ignorePublicAcls: true,
860
+ restrictPublicBuckets: true
861
+ },
862
+ ...props.bucketProps
863
+ });
864
+ const origin = import_aws_cloudfront_origins.S3BucketOrigin.withOriginAccessControl(this.bucket);
865
+ const cachePolicy = new import_aws_cloudfront.CachePolicy(this, "cache-policy", {
866
+ cachePolicyName: `static-hosting-10s-${stack.branchHash}`,
867
+ comment: "Low TTL (10s) for static hosting; no invalidation",
868
+ defaultTtl: import_core.Duration.seconds(10),
869
+ minTtl: import_core.Duration.seconds(0),
870
+ maxTtl: import_core.Duration.seconds(10)
871
+ });
872
+ this.distribution = new import_aws_cloudfront.Distribution(this, "distribution", {
873
+ defaultBehavior: {
874
+ origin,
875
+ cachePolicy
876
+ },
877
+ ...props.distributionProps
878
+ });
879
+ new DiscoverableStringParameter(this, "bucket-arn-param", {
880
+ ssmParamName: _StaticHosting.SSM_PARAM_NAME_BUCKET_ARN,
881
+ serviceType,
882
+ stringValue: this.bucket.bucketArn
883
+ });
884
+ new DiscoverableStringParameter(this, "distribution-arn-param", {
885
+ ssmParamName: _StaticHosting.SSM_PARAM_NAME_DISTRIBUTION_ARN,
886
+ serviceType,
887
+ stringValue: this.distribution.distributionArn
888
+ });
889
+ }
890
+ };
891
+ /**
892
+ * SSM parameter name for the S3 bucket ARN.
893
+ */
894
+ _StaticHosting.SSM_PARAM_NAME_BUCKET_ARN = "STATIC_HOSTING_BUCKET_ARN";
895
+ /**
896
+ * SSM parameter name for the CloudFront distribution ARN.
897
+ */
898
+ _StaticHosting.SSM_PARAM_NAME_DISTRIBUTION_ARN = "STATIC_HOSTING_DISTRIBUTION_ARN";
899
+ var StaticHosting = _StaticHosting;
900
+
841
901
  // src/services/open-hi-auth-service.ts
842
902
  var import_aws_cognito4 = require("aws-cdk-lib/aws-cognito");
843
903
  var import_aws_kms2 = require("aws-cdk-lib/aws-kms");
@@ -1093,7 +1153,7 @@ var import_aws_apigatewayv2_integrations = require("aws-cdk-lib/aws-apigatewayv2
1093
1153
  var import_aws_iam = require("aws-cdk-lib/aws-iam");
1094
1154
  var import_aws_route533 = require("aws-cdk-lib/aws-route53");
1095
1155
  var import_aws_route53_targets = require("aws-cdk-lib/aws-route53-targets");
1096
- var import_core = require("aws-cdk-lib/core");
1156
+ var import_core2 = require("aws-cdk-lib/core");
1097
1157
 
1098
1158
  // src/services/open-hi-data-service.ts
1099
1159
  var import_aws_dynamodb2 = require("aws-cdk-lib/aws-dynamodb");
@@ -1165,7 +1225,7 @@ var import_node_fs2 = __toESM(require("fs"));
1165
1225
  var import_node_path2 = __toESM(require("path"));
1166
1226
  var import_aws_lambda2 = require("aws-cdk-lib/aws-lambda");
1167
1227
  var import_aws_lambda_nodejs2 = require("aws-cdk-lib/aws-lambda-nodejs");
1168
- var import_constructs3 = require("constructs");
1228
+ var import_constructs4 = require("constructs");
1169
1229
  var HANDLER_NAME2 = "rest-api-lambda.handler.js";
1170
1230
  function resolveHandlerEntry2(dirname) {
1171
1231
  const sameDir = import_node_path2.default.join(dirname, HANDLER_NAME2);
@@ -1175,7 +1235,7 @@ function resolveHandlerEntry2(dirname) {
1175
1235
  const fromLib = import_node_path2.default.join(dirname, "..", "..", "..", "lib", HANDLER_NAME2);
1176
1236
  return fromLib;
1177
1237
  }
1178
- var RestApiLambda = class extends import_constructs3.Construct {
1238
+ var RestApiLambda = class extends import_constructs4.Construct {
1179
1239
  constructor(scope, props) {
1180
1240
  super(scope, "rest-api-lambda");
1181
1241
  this.lambda = new import_aws_lambda_nodejs2.NodejsFunction(this, "handler", {
@@ -1401,7 +1461,7 @@ var _OpenHiRestApiService = class _OpenHiRestApiService extends OpenHiService {
1401
1461
  "Authorization"
1402
1462
  ],
1403
1463
  allowCredentials: cors.allowCredentials ?? true,
1404
- maxAge: cors.maxAge ?? import_core.Duration.days(1)
1464
+ maxAge: cors.maxAge ?? import_core2.Duration.days(1)
1405
1465
  } : void 0;
1406
1466
  const rootHttpApi = new RootHttpApi(this, {
1407
1467
  defaultDomainMapping: {
@@ -1484,6 +1544,8 @@ var OpenHiGraphqlService = _OpenHiGraphqlService;
1484
1544
  RootHostedZone,
1485
1545
  RootHttpApi,
1486
1546
  RootWildcardCertificate,
1547
+ STATIC_HOSTING_SERVICE_TYPE,
1548
+ StaticHosting,
1487
1549
  getDynamoDbDataStoreTableName
1488
1550
  });
1489
1551
  //# sourceMappingURL=index.js.map