@awsless/awsless 0.0.535 → 0.0.537

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
@@ -1508,7 +1508,8 @@ var SitesSchema = z32.record(
1508
1508
  ),
1509
1509
  cacheKey: z32.union([LocalEntrySchema.transform((v) => [v]), LocalEntrySchema.array()]).describe(
1510
1510
  `Specifies the files and directories to generate the cache key for your custom build command.`
1511
- )
1511
+ ),
1512
+ configs: z32.string().array().describe("Define the config values for your build command.")
1512
1513
  }).optional().describe(`Specifies the build process for sites that need a build step.`),
1513
1514
  static: z32.union([LocalDirectorySchema, z32.boolean()]).optional().describe(
1514
1515
  "Specifies the path to the static files directory. Additionally you can also pass `true` when you don't have local static files, but still want to make an S3 bucket."
@@ -1564,6 +1565,10 @@ var SitesSchema = z32.record(
1564
1565
  origins: z32.string().array().default(["*"]),
1565
1566
  methods: z32.enum(["GET", "DELETE", "HEAD", "OPTIONS", "PATCH", "POST", "PUT", "ALL"]).array().default(["ALL"])
1566
1567
  }).optional().describe("Specify the cors headers."),
1568
+ auth: z32.object({
1569
+ username: z32.string().describe("Basic auth username"),
1570
+ password: z32.string().describe("Basic auth password")
1571
+ }).optional().describe("Enable basic authentication for the site"),
1567
1572
  security: z32.object({
1568
1573
  // contentSecurityPolicy: z.object({
1569
1574
  // override: z.boolean().default(false),
@@ -2618,6 +2623,11 @@ var configFeature = defineFeature({
2618
2623
  for (const name of stack.configs ?? []) {
2619
2624
  resources2.addConst(name, "string");
2620
2625
  }
2626
+ for (const site of Object.values(stack.sites ?? {})) {
2627
+ for (const name of site.build?.configs ?? []) {
2628
+ resources2.addConst(name, "string");
2629
+ }
2630
+ }
2621
2631
  }
2622
2632
  gen.addInterface("ConfigResources", resources2.toString());
2623
2633
  await ctx.write("config.d.ts", gen, true);
@@ -4736,13 +4746,16 @@ var getCacheControl = (file) => {
4736
4746
  var getContentType = (file) => {
4737
4747
  return contentType(extname2(file)) || "text/html; charset=utf-8";
4738
4748
  };
4739
- var getViewerRequestFunctionCode = (domain2, bucket, functionUrl) => {
4749
+ var getViewerRequestFunctionCode = (domain2, bucket, functionUrl, basicAuth) => {
4740
4750
  return $resolve([bucket?.bucketRegionalDomainName, functionUrl?.functionUrl], (bucketDomain, lambdaUrl) => {
4741
4751
  return CF_FUNC_WRAP([
4742
4752
  // --------------------------------------------------------
4743
4753
  // Block direct access to cloudfront.
4744
4754
  domain2 ? BLOCK_DIRECT_ACCESS_TO_CLOUDFRONT : "",
4745
4755
  // --------------------------------------------------------
4756
+ // Basic Authentication
4757
+ basicAuth ? BASIC_AUTH_CHECK(basicAuth.username, basicAuth.password) : "",
4758
+ // --------------------------------------------------------
4746
4759
  // Define functions.
4747
4760
  bucketDomain ? GET_PREFIXES : "",
4748
4761
  bucketDomain ? SET_S3_ORIGIN : "",
@@ -4775,6 +4788,18 @@ if (event.request.headers.host.value.includes('cloudfront.net')) {
4775
4788
  statusDescription: 'Forbidden'
4776
4789
  };
4777
4790
  }`;
4791
+ var BASIC_AUTH_CHECK = (username, password) => `
4792
+ var auth = event.request.headers.authorization && event.request.headers.authorization.value;
4793
+ if (!auth || !auth.startsWith('Basic ') || atob(auth.slice(6)) !== '${username}:${password}') {
4794
+ return {
4795
+ statusCode: 401,
4796
+ headers: {
4797
+ 'www-authenticate': {
4798
+ value: 'Basic realm="Protected"'
4799
+ }
4800
+ }
4801
+ };
4802
+ }`;
4778
4803
  var SET_S3_ORIGIN = `
4779
4804
  function setS3Origin(s3Domain) {
4780
4805
  const origin = {
@@ -4787,8 +4812,8 @@ function setS3Origin(s3Domain) {
4787
4812
  }
4788
4813
  };
4789
4814
 
4790
- console.log("s3 origin")
4791
- console.log(origin)
4815
+ // console.log("s3 origin")
4816
+ // console.log(origin)
4792
4817
  cf.updateRequestOrigin(origin);
4793
4818
  }`;
4794
4819
  var SET_LAMBDA_ORIGIN = `
@@ -4865,12 +4890,12 @@ if (event.request.headers.host) {
4865
4890
  setLambdaOrigin('${url}');`;
4866
4891
 
4867
4892
  // src/feature/site/index.ts
4868
- import { camelCase as camelCase6 } from "change-case";
4893
+ import { camelCase as camelCase6, constantCase as constantCase10 } from "change-case";
4869
4894
 
4870
4895
  // src/util/exec.ts
4871
4896
  import { exec } from "promisify-child-process";
4872
- var execCommand = async ({ cwd, command }) => {
4873
- await exec(command, { cwd });
4897
+ var execCommand = async ({ cwd, env, command }) => {
4898
+ await exec(command, { cwd, env });
4874
4899
  };
4875
4900
 
4876
4901
  // src/feature/site/index.ts
@@ -4893,9 +4918,14 @@ var siteFeature = defineFeature({
4893
4918
  const fingerprint = await generateCacheKey(buildProps.cacheKey);
4894
4919
  return build3(fingerprint, async (write) => {
4895
4920
  const cwd = join11(directories.root, dirname7(ctx.stackConfig.file));
4921
+ const env = {};
4922
+ for (const name2 of props.build?.configs ?? []) {
4923
+ env[`CONFIG_${constantCase10(name2)}`] = name2;
4924
+ }
4896
4925
  await execCommand({
4897
4926
  cwd,
4898
- command: buildProps.command
4927
+ command: buildProps.command,
4928
+ env
4899
4929
  });
4900
4930
  await write("HASH", fingerprint);
4901
4931
  return {
@@ -5089,7 +5119,7 @@ var siteFeature = defineFeature({
5089
5119
  runtime: `cloudfront-js-2.0`,
5090
5120
  comment: `Viewer Request - ${name}`,
5091
5121
  publish: true,
5092
- code: getViewerRequestFunctionCode(domainName, bucket, functionUrl),
5122
+ code: getViewerRequestFunctionCode(domainName, bucket, functionUrl, props.auth),
5093
5123
  keyValueStoreAssociations: kvs ? [kvs.arn] : void 0
5094
5124
  });
5095
5125
  const distribution = new $15.aws.cloudfront.Distribution(group, "distribution", {
@@ -5368,7 +5398,7 @@ var storeFeature = defineFeature({
5368
5398
 
5369
5399
  // src/feature/table/index.ts
5370
5400
  import { $ as $17, Group as Group17 } from "@awsless/formation";
5371
- import { constantCase as constantCase10 } from "change-case";
5401
+ import { constantCase as constantCase11 } from "change-case";
5372
5402
  import { toSeconds as toSeconds7 } from "@awsless/duration";
5373
5403
  var tableFeature = defineFeature({
5374
5404
  name: "table",
@@ -5450,8 +5480,8 @@ var tableFeature = defineFeature({
5450
5480
  name,
5451
5481
  billingMode: "PAY_PER_REQUEST",
5452
5482
  streamEnabled: !!props.stream,
5453
- streamViewType: props.stream && constantCase10(props.stream?.type),
5454
- tableClass: constantCase10(props.class),
5483
+ streamViewType: props.stream && constantCase11(props.stream?.type),
5484
+ tableClass: constantCase11(props.class),
5455
5485
  hashKey: props.hash,
5456
5486
  rangeKey: props.sort,
5457
5487
  attribute: attributeDefinitions(),
@@ -5466,7 +5496,7 @@ var tableFeature = defineFeature({
5466
5496
  name: name2,
5467
5497
  hashKey: index.hash,
5468
5498
  rangeKey: index.sort,
5469
- projectionType: constantCase10(index.projection)
5499
+ projectionType: constantCase11(index.projection)
5470
5500
  })),
5471
5501
  deletionProtectionEnabled: ctx.appConfig.removal === "retain"
5472
5502
  },
@@ -6001,7 +6031,7 @@ import { $ as $22, Group as Group23 } from "@awsless/formation";
6001
6031
  import { join as join12, dirname as dirname8 } from "path";
6002
6032
  import { mebibytes as mebibytes4 } from "@awsless/size";
6003
6033
  import { days as days6, seconds as seconds9, toDays as toDays5, toSeconds as toSeconds8 } from "@awsless/duration";
6004
- import { constantCase as constantCase11 } from "change-case";
6034
+ import { constantCase as constantCase12 } from "change-case";
6005
6035
  import { fileURLToPath as fileURLToPath2 } from "url";
6006
6036
  import { glob as glob3 } from "glob";
6007
6037
  var __dirname2 = dirname8(fileURLToPath2(import.meta.url));
@@ -6294,7 +6324,7 @@ var imageFeature = defineFeature({
6294
6324
  });
6295
6325
  }
6296
6326
  ctx.bind(
6297
- `IMAGE_${constantCase11(ctx.stack.name)}_${constantCase11(id)}_ENDPOINT`,
6327
+ `IMAGE_${constantCase12(ctx.stack.name)}_${constantCase12(id)}_ENDPOINT`,
6298
6328
  domainName ?? distribution.domainName
6299
6329
  );
6300
6330
  ctx.shared.add("image", "distribution-id", id, distribution.id);
@@ -6308,7 +6338,7 @@ import { $ as $23, Group as Group24 } from "@awsless/formation";
6308
6338
  import { join as join13, dirname as dirname9 } from "path";
6309
6339
  import { mebibytes as mebibytes5 } from "@awsless/size";
6310
6340
  import { days as days7, seconds as seconds10, toDays as toDays6, toSeconds as toSeconds9 } from "@awsless/duration";
6311
- import { constantCase as constantCase12 } from "change-case";
6341
+ import { constantCase as constantCase13 } from "change-case";
6312
6342
  import { fileURLToPath as fileURLToPath3 } from "url";
6313
6343
  import { glob as glob4 } from "glob";
6314
6344
  var __dirname3 = dirname9(fileURLToPath3(import.meta.url));
@@ -6573,7 +6603,7 @@ var iconFeature = defineFeature({
6573
6603
  });
6574
6604
  }
6575
6605
  ctx.bind(
6576
- `ICON_${constantCase12(ctx.stack.name)}_${constantCase12(id)}_ENDPOINT`,
6606
+ `ICON_${constantCase13(ctx.stack.name)}_${constantCase13(id)}_ENDPOINT`,
6577
6607
  domainName ?? distribution.domainName
6578
6608
  );
6579
6609
  ctx.shared.add("icon", "distribution-id", id, distribution.id);
@@ -7977,7 +8007,7 @@ var auth = (program2) => {
7977
8007
 
7978
8008
  // src/cli/command/bind.ts
7979
8009
  import { log as log17 } from "@awsless/clui";
7980
- import { constantCase as constantCase13 } from "change-case";
8010
+ import { constantCase as constantCase14 } from "change-case";
7981
8011
  import { spawn } from "child_process";
7982
8012
  var bind = (program2) => {
7983
8013
  program2.command("bind").argument("[command...]", "The command to execute").option("--config <string...>", "List of config values that will be accessable", (v) => v.split(",")).description(`Bind your site environment variables to a command`).action(async (commands9 = [], opts) => {
@@ -8006,10 +8036,10 @@ var bind = (program2) => {
8006
8036
  const configList = opts.config ?? [];
8007
8037
  const configs = {};
8008
8038
  for (const name of configList) {
8009
- configs[`CONFIG_${constantCase13(name)}`] = name;
8039
+ configs[`CONFIG_${constantCase14(name)}`] = name;
8010
8040
  }
8011
8041
  if (configList.length ?? 0 > 0) {
8012
- log17.note("Bind Config", configList.map((v) => color.label(constantCase13(v))).join("\n"));
8042
+ log17.note("Bind Config", configList.map((v) => color.label(constantCase14(v))).join("\n"));
8013
8043
  }
8014
8044
  if (commands9.length === 0) {
8015
8045
  return "No command to execute.";
@@ -903,7 +903,8 @@ var SitesSchema = z29.record(
903
903
  ),
904
904
  cacheKey: z29.union([LocalEntrySchema.transform((v) => [v]), LocalEntrySchema.array()]).describe(
905
905
  `Specifies the files and directories to generate the cache key for your custom build command.`
906
- )
906
+ ),
907
+ configs: z29.string().array().describe("Define the config values for your build command.")
907
908
  }).optional().describe(`Specifies the build process for sites that need a build step.`),
908
909
  static: z29.union([LocalDirectorySchema, z29.boolean()]).optional().describe(
909
910
  "Specifies the path to the static files directory. Additionally you can also pass `true` when you don't have local static files, but still want to make an S3 bucket."
@@ -959,6 +960,10 @@ var SitesSchema = z29.record(
959
960
  origins: z29.string().array().default(["*"]),
960
961
  methods: z29.enum(["GET", "DELETE", "HEAD", "OPTIONS", "PATCH", "POST", "PUT", "ALL"]).array().default(["ALL"])
961
962
  }).optional().describe("Specify the cors headers."),
963
+ auth: z29.object({
964
+ username: z29.string().describe("Basic auth username"),
965
+ password: z29.string().describe("Basic auth password")
966
+ }).optional().describe("Enable basic authentication for the site"),
962
967
  security: z29.object({
963
968
  // contentSecurityPolicy: z.object({
964
969
  // override: z.boolean().default(false),
Binary file
Binary file
@@ -1 +1 @@
1
- 067ac22da538619c808461cfb4c14803a7a8917d
1
+ 8446d078f922ef61f32bfa9a1e660975640f784c
Binary file