carlin 2.2.1 → 2.2.2
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/dist/index.mjs +25 -60
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -3462,39 +3462,6 @@ const BASELINE_RESPONSE_HEADERS_CONFIG = {
|
|
|
3462
3462
|
}
|
|
3463
3463
|
}
|
|
3464
3464
|
};
|
|
3465
|
-
/**
|
|
3466
|
-
* The headers of `BASELINE_RESPONSE_HEADERS_CONFIG.CorsConfig` expressed as
|
|
3467
|
-
* custom headers.
|
|
3468
|
-
*
|
|
3469
|
-
* CloudFront's CORS handling owns `Vary`: with a `CorsConfig` in the policy it
|
|
3470
|
-
* sends `Vary: Origin` on a plain request and removes `Vary` altogether on a
|
|
3471
|
-
* cross-origin one, so a caller-defined `Vary` only survives when the policy
|
|
3472
|
-
* has no `CorsConfig`. The baseline allows a static `*`, which nothing varies
|
|
3473
|
-
* by, so the same headers can be emitted as custom headers and the caller's
|
|
3474
|
-
* `Vary` becomes both true and stable.
|
|
3475
|
-
*
|
|
3476
|
-
* `Access-Control-Allow-Credentials` is omitted because the baseline sets it
|
|
3477
|
-
* to `false`, which is the absence of the header, and `Access-Control-Max-Age`
|
|
3478
|
-
* because the baseline doesn't set it.
|
|
3479
|
-
*/
|
|
3480
|
-
const CORS_AS_CUSTOM_HEADERS = [
|
|
3481
|
-
{
|
|
3482
|
-
header: "access-control-allow-origin",
|
|
3483
|
-
value: "*"
|
|
3484
|
-
},
|
|
3485
|
-
{
|
|
3486
|
-
header: "access-control-allow-methods",
|
|
3487
|
-
value: "DELETE, GET, HEAD, OPTIONS, PATCH, POST, PUT"
|
|
3488
|
-
},
|
|
3489
|
-
{
|
|
3490
|
-
header: "access-control-allow-headers",
|
|
3491
|
-
value: "*"
|
|
3492
|
-
},
|
|
3493
|
-
{
|
|
3494
|
-
header: "access-control-expose-headers",
|
|
3495
|
-
value: "*"
|
|
3496
|
-
}
|
|
3497
|
-
];
|
|
3498
3465
|
const validateResponseHeaders = (responseHeaders) => {
|
|
3499
3466
|
const seen = /* @__PURE__ */ new Set();
|
|
3500
3467
|
for (const { header } of responseHeaders) {
|
|
@@ -3557,27 +3524,12 @@ const getResponseHeadersPolicyConfig = ({ responseHeaders }) => {
|
|
|
3557
3524
|
const securityHeadersConfigKey = SECURITY_HEADERS_CONFIG_KEYS[header.toLowerCase()];
|
|
3558
3525
|
if (securityHeadersConfigKey) delete securityHeadersConfig[securityHeadersConfigKey];
|
|
3559
3526
|
}
|
|
3560
|
-
/**
|
|
3561
|
-
* A `CorsConfig` makes CloudFront manage `Vary` itself, which silently
|
|
3562
|
-
* discards a user-defined one, so the CORS headers move to
|
|
3563
|
-
* `CustomHeadersConfig` when `vary` is defined. The one behavior lost is the
|
|
3564
|
-
* automatic `OPTIONS` preflight response of `CorsConfig`; simple
|
|
3565
|
-
* cross-origin requests, which is what a static app serves, don't preflight.
|
|
3566
|
-
*/
|
|
3567
|
-
const definesVary = responseHeaders.some(({ header }) => {
|
|
3568
|
-
return header.toLowerCase() === "vary";
|
|
3569
|
-
});
|
|
3570
|
-
const customHeaders = definesVary ? [...responseHeaders, ...CORS_AS_CUSTOM_HEADERS.map(({ header, value }) => {
|
|
3571
|
-
return {
|
|
3572
|
-
header,
|
|
3573
|
-
override: true,
|
|
3574
|
-
value
|
|
3575
|
-
};
|
|
3576
|
-
})] : responseHeaders;
|
|
3577
3527
|
return {
|
|
3578
3528
|
Comment: { "Fn::Sub": ["Response headers policy for ${Project} project.", { Project: { Ref: "Project" } }] },
|
|
3579
|
-
...
|
|
3580
|
-
|
|
3529
|
+
...responseHeaders.some(({ header }) => {
|
|
3530
|
+
return header.toLowerCase() === "vary";
|
|
3531
|
+
}) ? {} : { CorsConfig: BASELINE_RESPONSE_HEADERS_CONFIG.CorsConfig },
|
|
3532
|
+
CustomHeadersConfig: { Items: responseHeaders.map(({ header, value, override }) => {
|
|
3581
3533
|
return {
|
|
3582
3534
|
Header: header,
|
|
3583
3535
|
Override: override,
|
|
@@ -3673,6 +3625,22 @@ const CLOUDFRONT_VIEWER_REQUEST_FUNCTION_LOGICAL_ID = "ViewerRequestFunction";
|
|
|
3673
3625
|
const ROUTE_53_RECORD_SET_GROUP_LOGICAL_ID = "Route53RecordSetGroup";
|
|
3674
3626
|
const ERROR_DOCUMENT = "404/index.html";
|
|
3675
3627
|
/**
|
|
3628
|
+
* CORS of the bucket the distribution serves from.
|
|
3629
|
+
*
|
|
3630
|
+
* The origin is what answers CORS whenever the response headers policy has no
|
|
3631
|
+
* `CorsConfig` — which is the case when the `responseHeaders` option defines
|
|
3632
|
+
* `vary`, since CloudFront's CORS handling owns `Vary`. `AllowedMethods` is
|
|
3633
|
+
* limited to what the bucket can serve; advertising the write methods of the
|
|
3634
|
+
* managed policy would be fiction.
|
|
3635
|
+
*/
|
|
3636
|
+
const BUCKET_CORS_CONFIGURATION = { CorsRules: [{
|
|
3637
|
+
AllowedHeaders: ["*"],
|
|
3638
|
+
AllowedMethods: ["GET", "HEAD"],
|
|
3639
|
+
AllowedOrigins: ["*"],
|
|
3640
|
+
Id: "OpenCors",
|
|
3641
|
+
MaxAge: 600
|
|
3642
|
+
}] };
|
|
3643
|
+
/**
|
|
3676
3644
|
* Name: Managed-CachingDisabled
|
|
3677
3645
|
* ID: 4135ea2d-6df8-44a3-9df3-4b5a84be39ad
|
|
3678
3646
|
* https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/using-managed-cache-policies.html
|
|
@@ -3720,13 +3688,7 @@ const getBucketStaticWebsiteTemplate = ({ spa }) => {
|
|
|
3720
3688
|
[STATIC_APP_BUCKET_LOGICAL_ID]: {
|
|
3721
3689
|
Type: "AWS::S3::Bucket",
|
|
3722
3690
|
Properties: {
|
|
3723
|
-
CorsConfiguration:
|
|
3724
|
-
AllowedHeaders: ["*"],
|
|
3725
|
-
AllowedMethods: ["GET"],
|
|
3726
|
-
AllowedOrigins: ["*"],
|
|
3727
|
-
Id: "OpenCors",
|
|
3728
|
-
MaxAge: 600
|
|
3729
|
-
}] },
|
|
3691
|
+
CorsConfiguration: BUCKET_CORS_CONFIGURATION,
|
|
3730
3692
|
PublicAccessBlockConfiguration: { BlockPublicPolicy: false },
|
|
3731
3693
|
WebsiteConfiguration: {
|
|
3732
3694
|
IndexDocument: `index.html`,
|
|
@@ -3763,7 +3725,10 @@ const getCloudFrontTemplate = ({ acm, aliases = [], appendIndexHtml, responseHea
|
|
|
3763
3725
|
Resources: {
|
|
3764
3726
|
[STATIC_APP_BUCKET_LOGICAL_ID]: {
|
|
3765
3727
|
Type: "AWS::S3::Bucket",
|
|
3766
|
-
Properties: {
|
|
3728
|
+
Properties: {
|
|
3729
|
+
CorsConfiguration: BUCKET_CORS_CONFIGURATION,
|
|
3730
|
+
PublicAccessBlockConfiguration: { BlockPublicPolicy: false }
|
|
3731
|
+
}
|
|
3767
3732
|
},
|
|
3768
3733
|
[`${STATIC_APP_BUCKET_LOGICAL_ID}S3BucketPolicy`]: {
|
|
3769
3734
|
Type: "AWS::S3::BucketPolicy",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "carlin",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"homepage": "https://ttoss.dev/docs/carlin/",
|
|
@@ -57,8 +57,8 @@
|
|
|
57
57
|
"ts-node": "^10.9.2",
|
|
58
58
|
"uglify-js": "^3.19.3",
|
|
59
59
|
"yargs": "^17.7.2",
|
|
60
|
-
"@ttoss/config": "^1.37.17",
|
|
61
60
|
"@ttoss/cloudformation": "^0.13.11",
|
|
61
|
+
"@ttoss/config": "^1.37.17",
|
|
62
62
|
"@ttoss/read-config-file": "^2.2.20"
|
|
63
63
|
},
|
|
64
64
|
"devDependencies": {
|