@awsless/awsless 0.0.213 → 0.0.215

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
@@ -611,7 +611,7 @@ var AppSchema = z15.object({
611
611
  import { glob } from "glob";
612
612
 
613
613
  // src/config/stack.ts
614
- import { z as z28 } from "zod";
614
+ import { z as z29 } from "zod";
615
615
 
616
616
  // src/feature/on-failure/schema.ts
617
617
  var OnFailureSchema = FunctionSchema.optional().describe(
@@ -1035,13 +1035,30 @@ var SitesSchema = z27.record(
1035
1035
  })
1036
1036
  ).optional().describe("Define the sites in your stack.");
1037
1037
 
1038
+ // src/feature/task/schema.ts
1039
+ import { z as z28 } from "zod";
1040
+ var RetryAttemptsSchema2 = z28.number().int().min(0).max(2).describe(
1041
+ "The maximum number of times to retry when the function returns an error. You can specify a number from 0 to 2."
1042
+ );
1043
+ var TaskSchema = z28.union([
1044
+ LocalFileSchema.transform((file) => ({
1045
+ consumer: { file },
1046
+ retryAttempts: void 0
1047
+ })),
1048
+ z28.object({
1049
+ consumer: FunctionSchema,
1050
+ retryAttempts: RetryAttemptsSchema2.optional()
1051
+ })
1052
+ ]);
1053
+ var TasksSchema = z28.record(ResourceIdSchema, TaskSchema).optional().describe("Define the tasks in your stack.");
1054
+
1038
1055
  // src/config/stack.ts
1039
1056
  var DependsSchema = ResourceIdSchema.array().optional().describe("Define the stacks that this stack is depended on.");
1040
1057
  var NameSchema = ResourceIdSchema.refine((name) => !["base"].includes(name), {
1041
1058
  message: `Stack name can't be a reserved name.`
1042
1059
  }).describe("Stack name.");
1043
- var StackSchema = z28.object({
1044
- $schema: z28.string().optional(),
1060
+ var StackSchema = z29.object({
1061
+ $schema: z29.string().optional(),
1045
1062
  name: NameSchema,
1046
1063
  depends: DependsSchema,
1047
1064
  onFailure: OnFailureSchema,
@@ -1055,6 +1072,7 @@ var StackSchema = z28.object({
1055
1072
  topics: TopicsSchema,
1056
1073
  subscribers: SubscribersSchema,
1057
1074
  functions: FunctionsSchema,
1075
+ tasks: TasksSchema,
1058
1076
  tables: TablesSchema,
1059
1077
  stores: StoresSchema,
1060
1078
  queues: QueuesSchema,
@@ -1119,13 +1137,13 @@ var readConfigWithStage = async (file, stage) => {
1119
1137
  };
1120
1138
 
1121
1139
  // src/config/load/validate.ts
1122
- import { z as z29 } from "zod";
1140
+ import { z as z30 } from "zod";
1123
1141
  var validateConfig = async (schema, file, data) => {
1124
1142
  try {
1125
1143
  const result = await schema.parseAsync(data);
1126
1144
  return result;
1127
1145
  } catch (error) {
1128
- if (error instanceof z29.ZodError) {
1146
+ if (error instanceof z30.ZodError) {
1129
1147
  throw new ConfigError(file, error, data);
1130
1148
  }
1131
1149
  throw error;
@@ -2051,17 +2069,6 @@ var build = (type, name, builder) => {
2051
2069
  });
2052
2070
  };
2053
2071
 
2054
- // src/feature/on-failure/util.ts
2055
- var getGlobalOnFailure = (ctx) => {
2056
- return hasOnFailure(ctx.stackConfigs) ? ctx.shared.get("on-failure-queue-arn") : void 0;
2057
- };
2058
- var hasOnFailure = (stacks) => {
2059
- const onFailure = stacks.find((stack) => {
2060
- return typeof stack.onFailure !== "undefined";
2061
- });
2062
- return !!onFailure;
2063
- };
2064
-
2065
2072
  // src/feature/function/util.ts
2066
2073
  var createLambdaFunction = (group, ctx, ns, id, local2) => {
2067
2074
  let name;
@@ -2072,7 +2079,6 @@ var createLambdaFunction = (group, ctx, ns, id, local2) => {
2072
2079
  }
2073
2080
  const props = deepmerge(ctx.appConfig.defaults.function, local2);
2074
2081
  ctx.registerBuild("function", name, async (build3) => {
2075
- props.file;
2076
2082
  const version = await fingerprintFromFile(props.file);
2077
2083
  return build3(version, async (write) => {
2078
2084
  const bundle = await bundleTypeScript({ file: props.file });
@@ -2122,18 +2128,6 @@ var createLambdaFunction = (group, ctx, ns, id, local2) => {
2122
2128
  if ("stackConfig" in ctx) {
2123
2129
  lambda.addEnvironment("STACK", ctx.stackConfig.name);
2124
2130
  }
2125
- const invokeConfig = new aws2.lambda.EventInvokeConfig(group, "async", {
2126
- functionArn: lambda.arn,
2127
- retryAttempts: props.retryAttempts,
2128
- onFailure: getGlobalOnFailure(ctx)
2129
- });
2130
- invokeConfig.dependsOn(policy);
2131
- if (hasOnFailure(ctx.stackConfigs)) {
2132
- policy.addStatement({
2133
- actions: ["sqs:SendMessage", "sqs:GetQueueUrl"],
2134
- resources: [getGlobalOnFailure(ctx)]
2135
- });
2136
- }
2137
2131
  if (props.log.retention.value > 0n) {
2138
2132
  const logGroup = new aws2.cloudWatch.LogGroup(group, "log", {
2139
2133
  name: lambda.name.apply((name2) => `/aws/lambda/${name2}`),
@@ -2183,8 +2177,8 @@ var createLambdaFunction = (group, ctx, ns, id, local2) => {
2183
2177
  lambda.setVpc({
2184
2178
  securityGroupIds: [ctx.shared.get(`vpc-security-group-id`)],
2185
2179
  subnetIds: [
2186
- ctx.shared.get(`vpc-public-subnet-1`),
2187
- ctx.shared.get(`vpc-public-subnet-2`)
2180
+ ctx.shared.get(`vpc-public-subnet-id-1`),
2181
+ ctx.shared.get(`vpc-public-subnet-id-2`)
2188
2182
  ]
2189
2183
  });
2190
2184
  policy.addStatement({
@@ -2212,6 +2206,7 @@ var cronFeature = defineFeature({
2212
2206
  for (const [id, props] of Object.entries(ctx.stackConfig.crons ?? {})) {
2213
2207
  const group = new Node3(ctx.stack, "cron", id);
2214
2208
  const { lambda } = createLambdaFunction(group, ctx, this.name, id, props.consumer);
2209
+ lambda.addEnvironment("LOG_VIEWABLE_ERROR", "1");
2215
2210
  const rule = new aws3.events.Rule(group, "rule", {
2216
2211
  name: formatLocalResourceName(ctx.app.name, ctx.stack.name, this.name, id),
2217
2212
  schedule: props.schedule,
@@ -2520,7 +2515,7 @@ var functionFeature = defineFeature({
2520
2515
  const mockResponse = new TypeObject(2);
2521
2516
  for (const [name, fileOrProps] of Object.entries(stack.functions || {})) {
2522
2517
  const varName = camelCase3(`${stack.name}-${name}`);
2523
- const funcName = formatLocalResourceName(ctx.appConfig.name, stack.name, "fn", name);
2518
+ const funcName = formatLocalResourceName(ctx.appConfig.name, stack.name, "function", name);
2524
2519
  const file = typeof fileOrProps === "string" ? fileOrProps : fileOrProps.file;
2525
2520
  const relFile = relative(directories.types, file);
2526
2521
  types2.addImport(varName, relFile);
@@ -2965,6 +2960,17 @@ var graphqlFeature = defineFeature({
2965
2960
  }
2966
2961
  });
2967
2962
 
2963
+ // src/feature/on-failure/util.ts
2964
+ var getGlobalOnFailure = (ctx) => {
2965
+ return hasOnFailure(ctx.stackConfigs) ? ctx.shared.get("on-failure-queue-arn") : void 0;
2966
+ };
2967
+ var hasOnFailure = (stacks) => {
2968
+ const onFailure = stacks.find((stack) => {
2969
+ return typeof stack.onFailure !== "undefined";
2970
+ });
2971
+ return !!onFailure;
2972
+ };
2973
+
2968
2974
  // src/feature/on-failure/index.ts
2969
2975
  import { Node as Node7, aws as aws7 } from "@awsless/formation";
2970
2976
  var onFailureFeature = defineFeature({
@@ -3105,6 +3111,7 @@ var queueFeature = defineFeature({
3105
3111
  ...props
3106
3112
  });
3107
3113
  const { lambda, policy } = createLambdaFunction(group, ctx, `queue`, id, props.consumer);
3114
+ lambda.addEnvironment("LOG_VIEWABLE_ERROR", "1");
3108
3115
  new aws9.lambda.EventSourceMapping(group, "event", {
3109
3116
  functionArn: lambda.arn,
3110
3117
  sourceArn: queue2.arn,
@@ -3204,6 +3211,7 @@ var tableFeature = defineFeature({
3204
3211
  });
3205
3212
  if (props.stream) {
3206
3213
  const { lambda, policy } = createLambdaFunction(group, ctx, "table", id, props.stream.consumer);
3214
+ lambda.addEnvironment("LOG_VIEWABLE_ERROR", "1");
3207
3215
  const onFailure = getGlobalOnFailure(ctx);
3208
3216
  const source = new aws11.lambda.EventSourceMapping(group, id, {
3209
3217
  functionArn: lambda.arn,
@@ -3307,6 +3315,7 @@ var topicFeature = defineFeature({
3307
3315
  });
3308
3316
  } else if (typeof props === "object") {
3309
3317
  const { lambda } = createLambdaFunction(group, ctx, `topic`, id, props);
3318
+ lambda.addEnvironment("LOG_VIEWABLE_ERROR", "1");
3310
3319
  new aws12.sns.Subscription(group, id, {
3311
3320
  topicArn,
3312
3321
  protocol: "lambda",
@@ -2,7 +2,7 @@
2
2
  import { zodToJsonSchema } from "zod-to-json-schema";
3
3
 
4
4
  // src/config/stack.ts
5
- import { z as z25 } from "zod";
5
+ import { z as z26 } from "zod";
6
6
 
7
7
  // src/config/schema/resource-id.ts
8
8
  import { paramCase } from "change-case";
@@ -852,13 +852,30 @@ var SitesSchema = z24.record(
852
852
  })
853
853
  ).optional().describe("Define the sites in your stack.");
854
854
 
855
+ // src/feature/task/schema.ts
856
+ import { z as z25 } from "zod";
857
+ var RetryAttemptsSchema2 = z25.number().int().min(0).max(2).describe(
858
+ "The maximum number of times to retry when the function returns an error. You can specify a number from 0 to 2."
859
+ );
860
+ var TaskSchema = z25.union([
861
+ LocalFileSchema.transform((file) => ({
862
+ consumer: { file },
863
+ retryAttempts: void 0
864
+ })),
865
+ z25.object({
866
+ consumer: FunctionSchema,
867
+ retryAttempts: RetryAttemptsSchema2.optional()
868
+ })
869
+ ]);
870
+ var TasksSchema = z25.record(ResourceIdSchema, TaskSchema).optional().describe("Define the tasks in your stack.");
871
+
855
872
  // src/config/stack.ts
856
873
  var DependsSchema = ResourceIdSchema.array().optional().describe("Define the stacks that this stack is depended on.");
857
874
  var NameSchema = ResourceIdSchema.refine((name) => !["base"].includes(name), {
858
875
  message: `Stack name can't be a reserved name.`
859
876
  }).describe("Stack name.");
860
- var StackSchema = z25.object({
861
- $schema: z25.string().optional(),
877
+ var StackSchema = z26.object({
878
+ $schema: z26.string().optional(),
862
879
  name: NameSchema,
863
880
  depends: DependsSchema,
864
881
  onFailure: OnFailureSchema,
@@ -872,6 +889,7 @@ var StackSchema = z25.object({
872
889
  topics: TopicsSchema,
873
890
  subscribers: SubscribersSchema,
874
891
  functions: FunctionsSchema,
892
+ tasks: TasksSchema,
875
893
  tables: TablesSchema,
876
894
  stores: StoresSchema,
877
895
  queues: QueuesSchema,
@@ -882,10 +900,10 @@ var StackSchema = z25.object({
882
900
  });
883
901
 
884
902
  // src/config/app.ts
885
- import { z as z28 } from "zod";
903
+ import { z as z29 } from "zod";
886
904
 
887
905
  // src/config/schema/region.ts
888
- import { z as z26 } from "zod";
906
+ import { z as z27 } from "zod";
889
907
  var US = ["us-east-2", "us-east-1", "us-west-1", "us-west-2"];
890
908
  var AF = ["af-south-1"];
891
909
  var AP = [
@@ -914,21 +932,21 @@ var EU = [
914
932
  var ME = ["me-south-1", "me-central-1"];
915
933
  var SA = ["sa-east-1"];
916
934
  var regions = [...US, ...AF, ...AP, ...CA, ...EU, ...ME, ...SA];
917
- var RegionSchema = z26.enum(regions);
935
+ var RegionSchema = z27.enum(regions);
918
936
 
919
937
  // src/feature/domain/schema.ts
920
- import { z as z27 } from "zod";
921
- var DomainNameSchema = z27.string().regex(/[a-z\-\_\.]/g, "Invalid domain name").describe(
938
+ import { z as z28 } from "zod";
939
+ var DomainNameSchema = z28.string().regex(/[a-z\-\_\.]/g, "Invalid domain name").describe(
922
940
  "Enter a fully qualified domain name, for example, www.example.com. You can optionally include a trailing dot. If you omit the trailing dot, Amazon Route 53 assumes that the domain name that you specify is fully qualified. This means that Route 53 treats www.example.com (without a trailing dot) and www.example.com. (with a trailing dot) as identical."
923
941
  );
924
- var DNSTypeSchema = z27.enum(["A", "AAAA", "CAA", "CNAME", "DS", "MX", "NAPTR", "NS", "PTR", "SOA", "SPF", "SRV", "TXT"]).describe("The DNS record type.");
942
+ var DNSTypeSchema = z28.enum(["A", "AAAA", "CAA", "CNAME", "DS", "MX", "NAPTR", "NS", "PTR", "SOA", "SPF", "SRV", "TXT"]).describe("The DNS record type.");
925
943
  var TTLSchema = DurationSchema.describe("The resource record cache time to live (TTL).");
926
- var RecordsSchema = z27.string().array().describe("One or more values that correspond with the value that you specified for the Type property.");
927
- var DomainsDefaultSchema = z27.record(
944
+ var RecordsSchema = z28.string().array().describe("One or more values that correspond with the value that you specified for the Type property.");
945
+ var DomainsDefaultSchema = z28.record(
928
946
  ResourceIdSchema,
929
- z27.object({
947
+ z28.object({
930
948
  domain: DomainNameSchema.describe("Define the domain name"),
931
- dns: z27.object({
949
+ dns: z28.object({
932
950
  name: DomainNameSchema.optional(),
933
951
  type: DNSTypeSchema,
934
952
  ttl: TTLSchema,
@@ -938,17 +956,17 @@ var DomainsDefaultSchema = z27.record(
938
956
  ).optional().describe("Define the domains for your application.");
939
957
 
940
958
  // src/config/app.ts
941
- var AppSchema = z28.object({
942
- $schema: z28.string().optional(),
959
+ var AppSchema = z29.object({
960
+ $schema: z29.string().optional(),
943
961
  name: ResourceIdSchema.describe("App name."),
944
962
  region: RegionSchema.describe("The AWS region to deploy to."),
945
- profile: z28.string().describe("The AWS profile to deploy to."),
963
+ profile: z29.string().describe("The AWS profile to deploy to."),
946
964
  // stage: z
947
965
  // .string()
948
966
  // .regex(/^[a-z]+$/)
949
967
  // .default('prod')
950
968
  // .describe('The deployment stage.'),
951
- defaults: z28.object({
969
+ defaults: z29.object({
952
970
  auth: AuthDefaultSchema,
953
971
  domains: DomainsDefaultSchema,
954
972
  function: FunctionDefaultSchema,