@awsless/awsless 0.0.223 → 0.0.225

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";
@@ -3132,13 +3161,17 @@ var queueFeature = defineFeature({
3132
3161
  // src/feature/store/index.ts
3133
3162
  import { Node as Node10, aws as aws10 } from "@awsless/formation";
3134
3163
  var typeGenCode4 = `
3135
- import { Body, PutObjectProps, BodyStream } from '@awsless/s3'
3164
+ import { Body, PutObjectProps, BodyStream, createPresignedPost } from '@awsless/s3'
3165
+ import { Size } from '@awsless/size'
3166
+ import { Duration } from '@awsless/duration'
3167
+ import { PresignedPost } from '@aws-sdk/s3-presigned-post'
3136
3168
 
3137
3169
  type Store<Name extends string> = {
3138
3170
  readonly name: Name
3139
3171
  readonly put: (key: string, body: Body, options?: Pick<PutObjectProps, 'metadata' | 'storageClass'>) => Promise<void>
3140
3172
  readonly get: (key: string) => Promise<BodyStream | undefined>
3141
3173
  readonly delete: (key: string) => Promise<void>
3174
+ readonly createPresignedPost: key: string, contentLengthRange: [Size, Size], expires?: Duration, fields?: Record<string, string>) => Promise<PresignedPost>
3142
3175
  }
3143
3176
  `;
3144
3177
  var storeFeature = defineFeature({
@@ -3148,9 +3181,9 @@ var storeFeature = defineFeature({
3148
3181
  const resources = new TypeObject(1);
3149
3182
  for (const stack of ctx.stackConfigs) {
3150
3183
  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}'>`);
3184
+ for (const id of Object.keys(stack.stores ?? {})) {
3185
+ const storeName = formatLocalResourceName(ctx.appConfig.name, stack.name, "store", id);
3186
+ list4.addType(id, `Store<'${storeName}'>`);
3154
3187
  }
3155
3188
  resources.addType(stack.name, list4);
3156
3189
  }
@@ -3159,20 +3192,38 @@ var storeFeature = defineFeature({
3159
3192
  await ctx.write("store.d.ts", gen, true);
3160
3193
  },
3161
3194
  onStack(ctx) {
3162
- for (const id of ctx.stackConfig.stores || []) {
3195
+ for (const [id, props] of Object.entries(ctx.stackConfig.stores ?? {})) {
3163
3196
  const group = new Node10(ctx.stack, "store", id);
3197
+ const lambdaConfigs = [];
3198
+ for (const [_, lambdaConfig] of Object.entries(props.lambdaConfigs ?? {})) {
3199
+ const { lambda } = createLambdaFunction(group, ctx, `store`, id, lambdaConfig.consumer);
3200
+ lambda.addEnvironment("LOG_VIEWABLE_ERROR", "1");
3201
+ let event;
3202
+ if (lambdaConfig.event === "created") {
3203
+ event = "s3:ObjectCreated:*";
3204
+ } else if (lambdaConfig.event === "removed") {
3205
+ event = "s3:ObjectRemoved:*";
3206
+ }
3207
+ lambdaConfigs.push({
3208
+ event,
3209
+ function: lambda.arn
3210
+ });
3211
+ }
3164
3212
  const bucket = new aws10.s3.Bucket(group, "store", {
3165
3213
  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
- ]
3214
+ versioning: props.versioning,
3215
+ cors: props.cors,
3216
+ lambdaConfigs
3217
+ // cors: [
3218
+ // // ---------------------------------------------
3219
+ // // Support for presigned post requests
3220
+ // // ---------------------------------------------
3221
+ // {
3222
+ // origins: ['*'],
3223
+ // methods: ['POST'],
3224
+ // },
3225
+ // // ---------------------------------------------
3226
+ // ],
3176
3227
  });
3177
3228
  ctx.onFunction(({ policy }) => {
3178
3229
  policy.addStatement(bucket.permissions);
@@ -3736,7 +3787,7 @@ var searchFeature = defineFeature({
3736
3787
 
3737
3788
  // src/feature/site/index.ts
3738
3789
  import { Asset as Asset3, Node as Node17, aws as aws17 } from "@awsless/formation";
3739
- import { days as days3, seconds as seconds3 } from "@awsless/duration";
3790
+ import { days as days3, seconds as seconds4 } from "@awsless/duration";
3740
3791
  import { glob as glob2 } from "glob";
3741
3792
  import { join as join8 } from "path";
3742
3793
 
@@ -3849,7 +3900,7 @@ var siteFeature = defineFeature({
3849
3900
  }
3850
3901
  const cache = new aws17.cloudFront.CachePolicy(group, "cache", {
3851
3902
  name,
3852
- minTtl: seconds3(1),
3903
+ minTtl: seconds4(1),
3853
3904
  maxTtl: days3(365),
3854
3905
  defaultTtl: days3(1),
3855
3906
  ...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
@@ -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
+ createPresignedPost(key, contentLengthRange, expires, fields) {
230
+ return createPresignedPost({
231
+ bucket,
232
+ key,
233
+ contentLengthRange,
234
+ expires,
235
+ fields
236
+ });
228
237
  }
229
238
  };
230
239
  });