@awsless/awsless 0.0.534 → 0.0.536

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/bin.js CHANGED
@@ -1564,6 +1564,10 @@ var SitesSchema = z32.record(
1564
1564
  origins: z32.string().array().default(["*"]),
1565
1565
  methods: z32.enum(["GET", "DELETE", "HEAD", "OPTIONS", "PATCH", "POST", "PUT", "ALL"]).array().default(["ALL"])
1566
1566
  }).optional().describe("Specify the cors headers."),
1567
+ auth: z32.object({
1568
+ username: z32.string().describe("Basic auth username"),
1569
+ password: z32.string().describe("Basic auth password")
1570
+ }).optional().describe("Enable basic authentication for the site"),
1567
1571
  security: z32.object({
1568
1572
  // contentSecurityPolicy: z.object({
1569
1573
  // override: z.boolean().default(false),
@@ -1678,6 +1682,7 @@ var IconsSchema = z34.record(
1678
1682
  domain: ResourceIdSchema.describe("The domain id to link your site with.").optional(),
1679
1683
  subDomain: z34.string().optional(),
1680
1684
  log: LogSchema.optional(),
1685
+ cacheDuration: DurationSchema.optional().describe("The cache duration of the cached icons."),
1681
1686
  preserveId: z34.boolean().optional().default(false).describe("Preserve the IDs of the icons."),
1682
1687
  symbols: z34.boolean().optional().default(false).describe("Use SVG symbols for icons."),
1683
1688
  origin: z34.union([
@@ -1729,6 +1734,7 @@ var ImagesSchema = z35.record(
1729
1734
  domain: ResourceIdSchema.describe("The domain id to link your site with.").optional(),
1730
1735
  subDomain: z35.string().optional(),
1731
1736
  log: LogSchema.optional(),
1737
+ cacheDuration: DurationSchema.optional().describe("Cache duration of the cached images."),
1732
1738
  presets: z35.record(z35.string(), transformationOptionsSchema).describe("Named presets for image transformations"),
1733
1739
  extensions: z35.object({
1734
1740
  jpeg: z35.object({
@@ -4734,13 +4740,16 @@ var getCacheControl = (file) => {
4734
4740
  var getContentType = (file) => {
4735
4741
  return contentType(extname2(file)) || "text/html; charset=utf-8";
4736
4742
  };
4737
- var getViewerRequestFunctionCode = (domain2, bucket, functionUrl) => {
4743
+ var getViewerRequestFunctionCode = (domain2, bucket, functionUrl, basicAuth) => {
4738
4744
  return $resolve([bucket?.bucketRegionalDomainName, functionUrl?.functionUrl], (bucketDomain, lambdaUrl) => {
4739
4745
  return CF_FUNC_WRAP([
4740
4746
  // --------------------------------------------------------
4741
4747
  // Block direct access to cloudfront.
4742
4748
  domain2 ? BLOCK_DIRECT_ACCESS_TO_CLOUDFRONT : "",
4743
4749
  // --------------------------------------------------------
4750
+ // Basic Authentication
4751
+ basicAuth ? BASIC_AUTH_CHECK(basicAuth.username, basicAuth.password) : "",
4752
+ // --------------------------------------------------------
4744
4753
  // Define functions.
4745
4754
  bucketDomain ? GET_PREFIXES : "",
4746
4755
  bucketDomain ? SET_S3_ORIGIN : "",
@@ -4773,6 +4782,18 @@ if (event.request.headers.host.value.includes('cloudfront.net')) {
4773
4782
  statusDescription: 'Forbidden'
4774
4783
  };
4775
4784
  }`;
4785
+ var BASIC_AUTH_CHECK = (username, password) => `
4786
+ var auth = event.request.headers.authorization && event.request.headers.authorization.value;
4787
+ if (!auth || !auth.startsWith('Basic ') || atob(auth.slice(6)) !== '${username}:${password}') {
4788
+ return {
4789
+ statusCode: 401,
4790
+ headers: {
4791
+ 'www-authenticate': {
4792
+ value: 'Basic realm="Protected"'
4793
+ }
4794
+ }
4795
+ };
4796
+ }`;
4776
4797
  var SET_S3_ORIGIN = `
4777
4798
  function setS3Origin(s3Domain) {
4778
4799
  const origin = {
@@ -4785,8 +4806,8 @@ function setS3Origin(s3Domain) {
4785
4806
  }
4786
4807
  };
4787
4808
 
4788
- console.log("s3 origin")
4789
- console.log(origin)
4809
+ // console.log("s3 origin")
4810
+ // console.log(origin)
4790
4811
  cf.updateRequestOrigin(origin);
4791
4812
  }`;
4792
4813
  var SET_LAMBDA_ORIGIN = `
@@ -5087,7 +5108,7 @@ var siteFeature = defineFeature({
5087
5108
  runtime: `cloudfront-js-2.0`,
5088
5109
  comment: `Viewer Request - ${name}`,
5089
5110
  publish: true,
5090
- code: getViewerRequestFunctionCode(domainName, bucket, functionUrl),
5111
+ code: getViewerRequestFunctionCode(domainName, bucket, functionUrl, props.auth),
5091
5112
  keyValueStoreAssociations: kvs ? [kvs.arn] : void 0
5092
5113
  });
5093
5114
  const distribution = new $15.aws.cloudfront.Distribution(group, "distribution", {
@@ -5998,7 +6019,7 @@ var layerFeature = defineFeature({
5998
6019
  import { $ as $22, Group as Group23 } from "@awsless/formation";
5999
6020
  import { join as join12, dirname as dirname8 } from "path";
6000
6021
  import { mebibytes as mebibytes4 } from "@awsless/size";
6001
- import { days as days6, seconds as seconds9, toSeconds as toSeconds8 } from "@awsless/duration";
6022
+ import { days as days6, seconds as seconds9, toDays as toDays5, toSeconds as toSeconds8 } from "@awsless/duration";
6002
6023
  import { constantCase as constantCase11 } from "change-case";
6003
6024
  import { fileURLToPath as fileURLToPath2 } from "url";
6004
6025
  import { glob as glob3 } from "glob";
@@ -6077,7 +6098,18 @@ var imageFeature = defineFeature({
6077
6098
  tags: {
6078
6099
  cache: "true"
6079
6100
  },
6080
- forceDestroy: true
6101
+ forceDestroy: true,
6102
+ ...props.cacheDuration ? {
6103
+ lifecycleRule: [
6104
+ {
6105
+ enabled: true,
6106
+ id: "image-cache-duration",
6107
+ expiration: {
6108
+ days: toDays5(props.cacheDuration)
6109
+ }
6110
+ }
6111
+ ]
6112
+ } : {}
6081
6113
  });
6082
6114
  const sharpLayerId = formatGlobalResourceName({
6083
6115
  appName: ctx.appConfig.name,
@@ -6184,6 +6216,7 @@ var imageFeature = defineFeature({
6184
6216
  aliases: domainName ? [domainName] : void 0,
6185
6217
  priceClass: "PriceClass_All",
6186
6218
  httpVersion: "http2and3",
6219
+ waitForDeployment: false,
6187
6220
  restrictions: {
6188
6221
  geoRestriction: {
6189
6222
  restrictionType: "none",
@@ -6293,7 +6326,7 @@ var imageFeature = defineFeature({
6293
6326
  import { $ as $23, Group as Group24 } from "@awsless/formation";
6294
6327
  import { join as join13, dirname as dirname9 } from "path";
6295
6328
  import { mebibytes as mebibytes5 } from "@awsless/size";
6296
- import { days as days7, seconds as seconds10, toSeconds as toSeconds9 } from "@awsless/duration";
6329
+ import { days as days7, seconds as seconds10, toDays as toDays6, toSeconds as toSeconds9 } from "@awsless/duration";
6297
6330
  import { constantCase as constantCase12 } from "change-case";
6298
6331
  import { fileURLToPath as fileURLToPath3 } from "url";
6299
6332
  import { glob as glob4 } from "glob";
@@ -6332,7 +6365,21 @@ var iconFeature = defineFeature({
6332
6365
  resourceType: "icon",
6333
6366
  resourceName: shortId(`cache-${id}-${ctx.appId}`)
6334
6367
  }),
6335
- forceDestroy: true
6368
+ tags: {
6369
+ cache: "true"
6370
+ },
6371
+ forceDestroy: true,
6372
+ ...props.cacheDuration ? {
6373
+ lifecycleRule: [
6374
+ {
6375
+ enabled: true,
6376
+ id: "icon-cache-duration",
6377
+ expiration: {
6378
+ days: toDays6(props.cacheDuration)
6379
+ }
6380
+ }
6381
+ ]
6382
+ } : {}
6336
6383
  });
6337
6384
  const serverLambda = createPrebuildLambdaFunction(group, ctx, "icon", id, {
6338
6385
  bundleFile: join13(__dirname3, "/prebuild/icon/bundle.zip"),
@@ -959,6 +959,10 @@ var SitesSchema = z29.record(
959
959
  origins: z29.string().array().default(["*"]),
960
960
  methods: z29.enum(["GET", "DELETE", "HEAD", "OPTIONS", "PATCH", "POST", "PUT", "ALL"]).array().default(["ALL"])
961
961
  }).optional().describe("Specify the cors headers."),
962
+ auth: z29.object({
963
+ username: z29.string().describe("Basic auth username"),
964
+ password: z29.string().describe("Basic auth password")
965
+ }).optional().describe("Enable basic authentication for the site"),
962
966
  security: z29.object({
963
967
  // contentSecurityPolicy: z.object({
964
968
  // override: z.boolean().default(false),
@@ -1073,6 +1077,7 @@ var IconsSchema = z31.record(
1073
1077
  domain: ResourceIdSchema.describe("The domain id to link your site with.").optional(),
1074
1078
  subDomain: z31.string().optional(),
1075
1079
  log: LogSchema.optional(),
1080
+ cacheDuration: DurationSchema.optional().describe("The cache duration of the cached icons."),
1076
1081
  preserveId: z31.boolean().optional().default(false).describe("Preserve the IDs of the icons."),
1077
1082
  symbols: z31.boolean().optional().default(false).describe("Use SVG symbols for icons."),
1078
1083
  origin: z31.union([
@@ -1124,6 +1129,7 @@ var ImagesSchema = z32.record(
1124
1129
  domain: ResourceIdSchema.describe("The domain id to link your site with.").optional(),
1125
1130
  subDomain: z32.string().optional(),
1126
1131
  log: LogSchema.optional(),
1132
+ cacheDuration: DurationSchema.optional().describe("Cache duration of the cached images."),
1127
1133
  presets: z32.record(z32.string(), transformationOptionsSchema).describe("Named presets for image transformations"),
1128
1134
  extensions: z32.object({
1129
1135
  jpeg: z32.object({
Binary file
@@ -1 +1 @@
1
- ec61da9b3cd0cdab7d90e90891cbd4e68058b97b
1
+ 77d5c40c76a204153d51f02737dfbfb9568c0601
Binary file
@@ -1 +1 @@
1
- 067ac22da538619c808461cfb4c14803a7a8917d
1
+ 8446d078f922ef61f32bfa9a1e660975640f784c
Binary file