@awsless/awsless 0.0.222 → 0.0.224

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
@@ -671,7 +671,36 @@ var TablesSchema = z17.record(
671
671
 
672
672
  // src/feature/store/schema.ts
673
673
  import { z as z18 } from "zod";
674
- var StoresSchema = z18.array(ResourceIdSchema).optional().describe("Define the stores in your stack.");
674
+ import { seconds as seconds3 } from "@awsless/duration";
675
+ var CorsSchema = z18.array(
676
+ z18.object({
677
+ maxAge: DurationSchema.refine(durationMin(seconds3(0))).optional().describe(
678
+ "The time in seconds that your browser is to cache the preflight response for the specified resource."
679
+ ),
680
+ origins: z18.array(z18.string()).describe("One or more origins you want customers to be able to access the bucket from."),
681
+ methods: z18.array(z18.enum(["GET", "PUT", "HEAD", "POST", "DELETE"])).describe("An HTTP method that you allow the origin to run."),
682
+ headers: z18.array(z18.string()).optional().describe(
683
+ "Headers that are specified in the Access-Control-Request-Headers header. These headers are allowed in a preflight OPTIONS request. In response to any preflight OPTIONS request, Amazon S3 returns any requested headers that are allowed."
684
+ ),
685
+ exposeHeaders: z18.array(z18.string()).optional().describe(
686
+ "One or more headers in the response that you want customers to be able to access from their applications (for example, from a JavaScript XMLHttpRequest object)."
687
+ )
688
+ })
689
+ ).max(100).optional().describe("Describes the AWS Lambda functions to invoke and the events for which to invoke them.");
690
+ var LambdaConfigsSchema = z18.array(
691
+ z18.object({
692
+ event: z18.enum(["created", "removed"]).describe("The Amazon S3 bucket event for which to invoke the AWS Lambda function."),
693
+ consumer: FunctionSchema.describe("The consuming lambda function properties.")
694
+ })
695
+ ).optional().describe("Describes the AWS Lambda functions to invoke and the events for which to invoke them.");
696
+ var StoresSchema = z18.record(
697
+ ResourceIdSchema,
698
+ z18.object({
699
+ lambdaConfigs: LambdaConfigsSchema,
700
+ cors: CorsSchema,
701
+ versioning: z18.boolean().default(false)
702
+ })
703
+ ).optional().describe("Define the stores in your stack.");
675
704
 
676
705
  // src/feature/pubsub/schema.ts
677
706
  import { z as z19 } from "zod";
@@ -3148,9 +3177,9 @@ var storeFeature = defineFeature({
3148
3177
  const resources = new TypeObject(1);
3149
3178
  for (const stack of ctx.stackConfigs) {
3150
3179
  const list4 = new TypeObject(2);
3151
- for (const name of stack.stores || []) {
3152
- const storeName = formatLocalResourceName(ctx.appConfig.name, stack.name, "store", name);
3153
- list4.addType(name, `Store<'${storeName}'>`);
3180
+ for (const id of Object.keys(stack.stores ?? {})) {
3181
+ const storeName = formatLocalResourceName(ctx.appConfig.name, stack.name, "store", id);
3182
+ list4.addType(id, `Store<'${storeName}'>`);
3154
3183
  }
3155
3184
  resources.addType(stack.name, list4);
3156
3185
  }
@@ -3159,20 +3188,38 @@ var storeFeature = defineFeature({
3159
3188
  await ctx.write("store.d.ts", gen, true);
3160
3189
  },
3161
3190
  onStack(ctx) {
3162
- for (const id of ctx.stackConfig.stores || []) {
3191
+ for (const [id, props] of Object.entries(ctx.stackConfig.stores ?? {})) {
3163
3192
  const group = new Node10(ctx.stack, "store", id);
3193
+ const lambdaConfigs = [];
3194
+ for (const [_, lambdaConfig] of Object.entries(props.lambdaConfigs ?? {})) {
3195
+ const { lambda } = createLambdaFunction(group, ctx, `store`, id, lambdaConfig.consumer);
3196
+ lambda.addEnvironment("LOG_VIEWABLE_ERROR", "1");
3197
+ let event;
3198
+ if (lambdaConfig.event === "created") {
3199
+ event = "s3:ObjectCreated:*";
3200
+ } else if (lambdaConfig.event === "removed") {
3201
+ event = "s3:ObjectRemoved:*";
3202
+ }
3203
+ lambdaConfigs.push({
3204
+ event,
3205
+ function: lambda.arn
3206
+ });
3207
+ }
3164
3208
  const bucket = new aws10.s3.Bucket(group, "store", {
3165
3209
  name: formatLocalResourceName(ctx.appConfig.name, ctx.stack.name, "store", id),
3166
- cors: [
3167
- // ---------------------------------------------
3168
- // Support for presigned post requests
3169
- // ---------------------------------------------
3170
- {
3171
- origins: ["*"],
3172
- methods: ["POST"]
3173
- }
3174
- // ---------------------------------------------
3175
- ]
3210
+ versioning: props.versioning,
3211
+ cors: props.cors,
3212
+ lambdaConfigs
3213
+ // cors: [
3214
+ // // ---------------------------------------------
3215
+ // // Support for presigned post requests
3216
+ // // ---------------------------------------------
3217
+ // {
3218
+ // origins: ['*'],
3219
+ // methods: ['POST'],
3220
+ // },
3221
+ // // ---------------------------------------------
3222
+ // ],
3176
3223
  });
3177
3224
  ctx.onFunction(({ policy }) => {
3178
3225
  policy.addStatement(bucket.permissions);
@@ -3736,7 +3783,7 @@ var searchFeature = defineFeature({
3736
3783
 
3737
3784
  // src/feature/site/index.ts
3738
3785
  import { Asset as Asset3, Node as Node17, aws as aws17 } from "@awsless/formation";
3739
- import { days as days3, seconds as seconds3 } from "@awsless/duration";
3786
+ import { days as days3, seconds as seconds4 } from "@awsless/duration";
3740
3787
  import { glob as glob2 } from "glob";
3741
3788
  import { join as join8 } from "path";
3742
3789
 
@@ -3849,7 +3896,7 @@ var siteFeature = defineFeature({
3849
3896
  }
3850
3897
  const cache = new aws17.cloudFront.CachePolicy(group, "cache", {
3851
3898
  name,
3852
- minTtl: seconds3(1),
3899
+ minTtl: seconds4(1),
3853
3900
  maxTtl: days3(365),
3854
3901
  defaultTtl: days3(1),
3855
3902
  ...props.cache
@@ -309,11 +309,40 @@ var TablesSchema = z8.record(
309
309
 
310
310
  // src/feature/store/schema.ts
311
311
  import { z as z9 } from "zod";
312
- var StoresSchema = z9.array(ResourceIdSchema).optional().describe("Define the stores in your stack.");
312
+ import { seconds as seconds2 } from "@awsless/duration";
313
+ var CorsSchema = z9.array(
314
+ z9.object({
315
+ maxAge: DurationSchema.refine(durationMin(seconds2(0))).optional().describe(
316
+ "The time in seconds that your browser is to cache the preflight response for the specified resource."
317
+ ),
318
+ origins: z9.array(z9.string()).describe("One or more origins you want customers to be able to access the bucket from."),
319
+ methods: z9.array(z9.enum(["GET", "PUT", "HEAD", "POST", "DELETE"])).describe("An HTTP method that you allow the origin to run."),
320
+ headers: z9.array(z9.string()).optional().describe(
321
+ "Headers that are specified in the Access-Control-Request-Headers header. These headers are allowed in a preflight OPTIONS request. In response to any preflight OPTIONS request, Amazon S3 returns any requested headers that are allowed."
322
+ ),
323
+ exposeHeaders: z9.array(z9.string()).optional().describe(
324
+ "One or more headers in the response that you want customers to be able to access from their applications (for example, from a JavaScript XMLHttpRequest object)."
325
+ )
326
+ })
327
+ ).max(100).optional().describe("Describes the AWS Lambda functions to invoke and the events for which to invoke them.");
328
+ var LambdaConfigsSchema = z9.array(
329
+ z9.object({
330
+ event: z9.enum(["created", "removed"]).describe("The Amazon S3 bucket event for which to invoke the AWS Lambda function."),
331
+ consumer: FunctionSchema.describe("The consuming lambda function properties.")
332
+ })
333
+ ).optional().describe("Describes the AWS Lambda functions to invoke and the events for which to invoke them.");
334
+ var StoresSchema = z9.record(
335
+ ResourceIdSchema,
336
+ z9.object({
337
+ lambdaConfigs: LambdaConfigsSchema,
338
+ cors: CorsSchema,
339
+ versioning: z9.boolean().default(false)
340
+ })
341
+ ).optional().describe("Define the stores in your stack.");
313
342
 
314
343
  // src/feature/queue/schema.ts
315
344
  import { z as z10 } from "zod";
316
- import { days as days2, hours, minutes as minutes2, seconds as seconds2 } from "@awsless/duration";
345
+ import { days as days2, hours, minutes as minutes2, seconds as seconds3 } from "@awsless/duration";
317
346
  import { kibibytes } from "@awsless/size";
318
347
  var RetentionPeriodSchema = DurationSchema.refine(
319
348
  durationMin(minutes2(1)),
@@ -334,9 +363,9 @@ var DeliveryDelaySchema = DurationSchema.refine(
334
363
  "The time in seconds for which the delivery of all messages in the queue is delayed. You can specify a duration from 0 to 15 minutes."
335
364
  );
336
365
  var ReceiveMessageWaitTimeSchema = DurationSchema.refine(
337
- durationMin(seconds2(1)),
366
+ durationMin(seconds3(1)),
338
367
  "Minimum receive message wait time is 1 second"
339
- ).refine(durationMax(seconds2(20)), "Maximum receive message wait time is 20 seconds").describe(
368
+ ).refine(durationMax(seconds3(20)), "Maximum receive message wait time is 20 seconds").describe(
340
369
  "Specifies the duration, that the ReceiveMessage action call waits until a message is in the queue in order to include it in the response, rather than returning an empty response if a message isn't yet available. You can specify a duration from 1 to 20 seconds. Short polling is used as the default."
341
370
  );
342
371
  var MaxMessageSizeSchema = SizeSchema.refine(sizeMin(kibibytes(1)), "Minimum max message size is 1 KB").refine(sizeMax(kibibytes(256)), "Maximum max message size is 256 KB").describe(
package/dist/server.js CHANGED
@@ -36,7 +36,7 @@ var cache = new WeakCache();
36
36
  var getFunctionName = bindLocalResourceName("function");
37
37
  var Function = /* @__PURE__ */ createProxy((stackName) => {
38
38
  return createProxy((funcName) => {
39
- const name = getFunctionName(stackName, funcName);
39
+ const name = getFunctionName(funcName, stackName);
40
40
  const ctx = {
41
41
  [name]: (payload, options = {}) => {
42
42
  return invoke({
@@ -69,7 +69,7 @@ import { invoke as invoke2 } from "@awsless/lambda";
69
69
  var getTaskName = bindLocalResourceName("task");
70
70
  var Task = /* @__PURE__ */ createProxy((stackName) => {
71
71
  return createProxy((taskName) => {
72
- const name = getTaskName(stackName, taskName);
72
+ const name = getTaskName(taskName, stackName);
73
73
  const ctx = {
74
74
  [name]: (payload, options = {}) => {
75
75
  return invoke2({
@@ -201,7 +201,7 @@ var Cache = /* @__PURE__ */ createProxy((stack) => {
201
201
  });
202
202
 
203
203
  // src/lib/resource/store.ts
204
- import { putObject, getObject, deleteObject } from "@awsless/s3";
204
+ import { putObject, getObject, deleteObject, createPresignedPost } from "@awsless/s3";
205
205
  var getStoreName = bindLocalResourceName("store");
206
206
  var Store = /* @__PURE__ */ createProxy((stack) => {
207
207
  return createProxy((name) => {
@@ -225,6 +225,15 @@ var Store = /* @__PURE__ */ createProxy((stack) => {
225
225
  },
226
226
  delete(key) {
227
227
  return deleteObject({ bucket, key });
228
+ },
229
+ presignedUrl(key, contentLengthRange, expires, fields) {
230
+ return createPresignedPost({
231
+ bucket,
232
+ key,
233
+ contentLengthRange,
234
+ expires,
235
+ fields
236
+ });
228
237
  }
229
238
  };
230
239
  });
@@ -346,7 +355,7 @@ var mockFunction = (cb) => {
346
355
  return createProxy((name) => {
347
356
  return (handleOrResponse) => {
348
357
  const handle = typeof handleOrResponse === "function" ? handleOrResponse : () => handleOrResponse;
349
- list[getFunctionName(stack, name)] = handle;
358
+ list[getFunctionName(name, stack)] = handle;
350
359
  };
351
360
  });
352
361
  });
@@ -354,7 +363,7 @@ var mockFunction = (cb) => {
354
363
  const result = mockLambda(list);
355
364
  return createProxy((stack) => {
356
365
  return createProxy((name) => {
357
- return result[getFunctionName(stack, name)];
366
+ return result[getFunctionName(name, stack)];
358
367
  });
359
368
  });
360
369
  };
@@ -404,7 +413,7 @@ var mockTask = (cb) => {
404
413
  const mock = createProxy((stack) => {
405
414
  return createProxy((name) => {
406
415
  return (handle) => {
407
- list[getTaskName(stack, name)] = handle;
416
+ list[getTaskName(name, stack)] = handle;
408
417
  };
409
418
  });
410
419
  });
@@ -412,7 +421,7 @@ var mockTask = (cb) => {
412
421
  const result = mockLambda2(list);
413
422
  return createProxy((stack) => {
414
423
  return createProxy((name) => {
415
- return result[getTaskName(stack, name)];
424
+ return result[getTaskName(name, stack)];
416
425
  });
417
426
  });
418
427
  };