@bitblit/ratchet-epsilon-deployment 4.0.85-alpha

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.
Files changed (31) hide show
  1. package/CHANGELOG.md +177 -0
  2. package/License.txt +13 -0
  3. package/README.md +242 -0
  4. package/dist/cjs/build/ratchet-epsilon-deployment-info.js +18 -0
  5. package/dist/cjs/deployment/cdk/epsilon-api-stack-props.js +2 -0
  6. package/dist/cjs/deployment/cdk/epsilon-api-stack.js +182 -0
  7. package/dist/cjs/deployment/cdk/epsilon-stack-util.js +71 -0
  8. package/dist/cjs/deployment/cdk/epsilon-website-stack-props.js +8 -0
  9. package/dist/cjs/deployment/cdk/epsilon-website-stack.js +157 -0
  10. package/dist/cjs/deployment/cdk/simple-additional-s3-website-mapping.js +2 -0
  11. package/dist/cjs/index.js +10 -0
  12. package/dist/es/build/ratchet-epsilon-deployment-info.js +14 -0
  13. package/dist/es/deployment/cdk/epsilon-api-stack-props.js +1 -0
  14. package/dist/es/deployment/cdk/epsilon-api-stack.js +178 -0
  15. package/dist/es/deployment/cdk/epsilon-stack-util.js +67 -0
  16. package/dist/es/deployment/cdk/epsilon-website-stack-props.js +5 -0
  17. package/dist/es/deployment/cdk/epsilon-website-stack.js +151 -0
  18. package/dist/es/deployment/cdk/simple-additional-s3-website-mapping.js +1 -0
  19. package/dist/es/index.js +7 -0
  20. package/dist/tsconfig.cjs.tsbuildinfo +1 -0
  21. package/dist/tsconfig.es.tsbuildinfo +1 -0
  22. package/dist/tsconfig.types.tsbuildinfo +1 -0
  23. package/dist/types/build/ratchet-epsilon-deployment-info.d.ts +5 -0
  24. package/dist/types/deployment/cdk/epsilon-api-stack-props.d.ts +17 -0
  25. package/dist/types/deployment/cdk/epsilon-api-stack.d.ts +9 -0
  26. package/dist/types/deployment/cdk/epsilon-stack-util.d.ts +13 -0
  27. package/dist/types/deployment/cdk/epsilon-website-stack-props.d.ts +15 -0
  28. package/dist/types/deployment/cdk/epsilon-website-stack.d.ts +13 -0
  29. package/dist/types/deployment/cdk/simple-additional-s3-website-mapping.d.ts +4 -0
  30. package/dist/types/index.d.ts +10 -0
  31. package/package.json +71 -0
@@ -0,0 +1,151 @@
1
+ import { Bucket, BucketEncryption } from 'aws-cdk-lib/aws-s3';
2
+ import { Duration, Stack } from 'aws-cdk-lib';
3
+ import path from 'path';
4
+ import { CloudFrontAllowedCachedMethods, CloudFrontAllowedMethods, CloudFrontWebDistribution, HttpVersion, OriginAccessIdentity, OriginProtocolPolicy, PriceClass, ViewerProtocolPolicy, } from 'aws-cdk-lib/aws-cloudfront';
5
+ import { HostedZone, RecordSet, RecordType } from 'aws-cdk-lib/aws-route53';
6
+ import { CloudFrontTarget } from 'aws-cdk-lib/aws-route53-targets';
7
+ import { BucketDeployment, Source } from 'aws-cdk-lib/aws-s3-deployment';
8
+ import { EpsilonWebsiteStackPropsRoute53Handling } from './epsilon-website-stack-props';
9
+ import { ErrorRatchet, StringRatchet } from '@bitblit/ratchet-common';
10
+ export class EpsilonWebsiteStack extends Stack {
11
+ constructor(scope, id, props) {
12
+ super(scope, id, props);
13
+ const originAccessId = new OriginAccessIdentity(this, id + 'OriginAccessId');
14
+ const websiteBucket = new Bucket(this, id + 'DeployBucket', {
15
+ bucketName: props.targetBucketName,
16
+ versioned: false,
17
+ publicReadAccess: false,
18
+ encryption: BucketEncryption.S3_MANAGED,
19
+ });
20
+ const extraBucketAndSource = (props.simpleAdditionalMappings || []).map((eb) => {
21
+ const nextBucket = new Bucket(this, eb.bucketName + 'DeployBucket', {
22
+ bucketName: eb.bucketName,
23
+ versioned: false,
24
+ publicReadAccess: false,
25
+ encryption: BucketEncryption.S3_MANAGED,
26
+ });
27
+ const nextBS = {
28
+ bucket: nextBucket,
29
+ sourceConfig: {
30
+ s3OriginSource: {
31
+ s3BucketSource: nextBucket,
32
+ originAccessIdentity: originAccessId,
33
+ },
34
+ behaviors: [
35
+ {
36
+ pathPattern: eb.pathPattern,
37
+ isDefaultBehavior: false,
38
+ compress: true,
39
+ defaultTtl: Duration.seconds(1),
40
+ minTtl: Duration.seconds(1),
41
+ maxTtl: Duration.seconds(1),
42
+ forwardedValues: {
43
+ queryString: false,
44
+ },
45
+ },
46
+ ],
47
+ },
48
+ };
49
+ return nextBS;
50
+ });
51
+ const assetSource = {
52
+ s3OriginSource: {
53
+ s3BucketSource: websiteBucket,
54
+ originAccessIdentity: originAccessId,
55
+ },
56
+ behaviors: [
57
+ {
58
+ isDefaultBehavior: true,
59
+ compress: true,
60
+ defaultTtl: Duration.seconds(1),
61
+ minTtl: Duration.seconds(1),
62
+ maxTtl: Duration.seconds(1),
63
+ forwardedValues: {
64
+ queryString: false,
65
+ },
66
+ },
67
+ ],
68
+ };
69
+ const apiSource = {
70
+ customOriginSource: {
71
+ domainName: props.apiDomainName,
72
+ originProtocolPolicy: OriginProtocolPolicy.HTTPS_ONLY,
73
+ },
74
+ behaviors: [
75
+ {
76
+ compress: true,
77
+ forwardedValues: {
78
+ queryString: true,
79
+ cookies: {
80
+ forward: 'whitelist',
81
+ whitelistedNames: ['idToken'],
82
+ },
83
+ headers: ['Accept', 'Referer', 'Authorization', 'Content-Type'],
84
+ },
85
+ pathPattern: 'graphql',
86
+ defaultTtl: Duration.seconds(0),
87
+ maxTtl: Duration.seconds(0),
88
+ minTtl: Duration.seconds(0),
89
+ allowedMethods: CloudFrontAllowedMethods.ALL,
90
+ cachedMethods: CloudFrontAllowedCachedMethods.GET_HEAD,
91
+ },
92
+ ],
93
+ };
94
+ const distributionProps = {
95
+ httpVersion: HttpVersion.HTTP2,
96
+ defaultRootObject: 'index.html',
97
+ originConfigs: [assetSource, apiSource, ...extraBucketAndSource.map((s) => s.sourceConfig)],
98
+ errorConfigurations: [
99
+ {
100
+ errorCode: 404,
101
+ errorCachingMinTtl: 300,
102
+ responseCode: 200,
103
+ responsePagePath: '/index.html',
104
+ },
105
+ {
106
+ errorCode: 403,
107
+ errorCachingMinTtl: 300,
108
+ responseCode: 200,
109
+ responsePagePath: '/index.html',
110
+ },
111
+ ],
112
+ priceClass: PriceClass.PRICE_CLASS_ALL,
113
+ viewerProtocolPolicy: ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
114
+ viewerCertificate: {
115
+ aliases: props.cloudFrontDomainNames,
116
+ props: {
117
+ acmCertificateArn: props.cloudFrontHttpsCertificateArn,
118
+ sslSupportMethod: 'sni-only',
119
+ },
120
+ },
121
+ };
122
+ const cloudfrontDistro = new CloudFrontWebDistribution(this, id + 'CloudfrontDistro', distributionProps);
123
+ if (props?.route53Handling === EpsilonWebsiteStackPropsRoute53Handling.Update) {
124
+ if (props?.cloudFrontDomainNames?.length) {
125
+ for (let i = 0; i < props.cloudFrontDomainNames.length; i++) {
126
+ const domain = new RecordSet(this, id + 'DomainName-' + props.cloudFrontDomainNames[i], {
127
+ recordType: RecordType.A,
128
+ recordName: props.cloudFrontDomainNames[i],
129
+ target: {
130
+ aliasTarget: new CloudFrontTarget(cloudfrontDistro),
131
+ },
132
+ zone: HostedZone.fromLookup(this, id, { domainName: EpsilonWebsiteStack.extractApexDomain(props.cloudFrontDomainNames[i]) }),
133
+ });
134
+ }
135
+ }
136
+ }
137
+ new BucketDeployment(this, id + 'SiteDeploy', {
138
+ sources: props.pathsToAssets.map((inPath) => Source.asset(path.resolve(inPath))),
139
+ destinationBucket: websiteBucket,
140
+ distribution: cloudfrontDistro,
141
+ distributionPaths: ['/*'],
142
+ });
143
+ }
144
+ static extractApexDomain(domainName) {
145
+ const pieces = StringRatchet.trimToEmpty(domainName).split('.');
146
+ if (pieces.length < 2) {
147
+ ErrorRatchet.throwFormattedErr('Not a valid domain name : %s', domainName);
148
+ }
149
+ return pieces[pieces.length - 2] + '.' + pieces[pieces.length - 1];
150
+ }
151
+ }
@@ -0,0 +1,7 @@
1
+ export * from './build/ratchet-epsilon-deployment-info';
2
+ export * from './deployment/cdk/epsilon-api-stack-props';
3
+ export * from './deployment/cdk/epsilon-api-stack';
4
+ export * from './deployment/cdk/epsilon-stack-util';
5
+ export * from './deployment/cdk/epsilon-website-stack-props';
6
+ export * from './deployment/cdk/epsilon-website-stack';
7
+ export * from './deployment/cdk/simple-additional-s3-website-mapping';