@awsless/awsless 0.0.148 → 0.0.150

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
@@ -261,7 +261,7 @@ var InlinePolicy = class {
261
261
  name;
262
262
  statements;
263
263
  constructor(name, props = {}) {
264
- this.statements = props.statements || [];
264
+ this.statements = props.statements ?? [];
265
265
  this.name = formatName(name);
266
266
  }
267
267
  addStatement(...statements) {
@@ -311,13 +311,15 @@ var Role = class extends Resource {
311
311
  ...this.props.assumedBy ? {
312
312
  AssumeRolePolicyDocument: {
313
313
  Version: "2012-10-17",
314
- Statement: [{
315
- Action: "sts:AssumeRole",
316
- Effect: "Allow",
317
- Principal: {
318
- Service: this.props.assumedBy
314
+ Statement: [
315
+ {
316
+ Action: "sts:AssumeRole",
317
+ Effect: "Allow",
318
+ Principal: {
319
+ Service: this.props.assumedBy
320
+ }
319
321
  }
320
- }]
322
+ ]
321
323
  }
322
324
  } : {},
323
325
  ManagedPolicyArns: [...this.managedPolicies].map((policy) => policy.arn),
@@ -1770,8 +1772,28 @@ var authPlugin = definePlugin({
1770
1772
  // }
1771
1773
  // }
1772
1774
  // },
1775
+ onStack({ config: config2, bootstrap: bootstrap2, bind: bind2 }) {
1776
+ for (const [id, props] of Object.entries(config2.app.defaults.auth)) {
1777
+ bind2((lambda) => {
1778
+ const userPoolArn = bootstrap2.import(`auth-${id}-user-pool-arn`);
1779
+ const userPoolId = bootstrap2.import(`auth-${id}-user-pool-id`);
1780
+ const clientId = bootstrap2.import(`auth-${id}-client-id`);
1781
+ const name = constantCase6(id);
1782
+ lambda.addEnvironment(`AUTH_${name}_USER_POOL_ID`, userPoolId);
1783
+ lambda.addEnvironment(`AUTH_${name}_CLIENT_ID`, clientId);
1784
+ if (props.secret) {
1785
+ const clientSecret = bootstrap2.import(`auth-${id}-client-secret`);
1786
+ lambda.addEnvironment(`AUTH_${name}_CLIENT_SECRET`, clientSecret);
1787
+ }
1788
+ lambda.addPermissions({
1789
+ actions: ["cognito:*"],
1790
+ resources: [userPoolArn]
1791
+ });
1792
+ });
1793
+ }
1794
+ },
1773
1795
  onApp(ctx) {
1774
- const { config: config2, bootstrap: bootstrap2, bind: bind2 } = ctx;
1796
+ const { config: config2, bootstrap: bootstrap2 } = ctx;
1775
1797
  if (Object.keys(config2.app.defaults.auth).length === 0) {
1776
1798
  return;
1777
1799
  }
@@ -1857,22 +1879,6 @@ var authPlugin = definePlugin({
1857
1879
  }).dependsOn(lambda);
1858
1880
  bootstrap2.add(lambda, permission);
1859
1881
  }
1860
- bind2((lambda) => {
1861
- const userPoolArn = bootstrap2.import(`auth-${id}-user-pool-arn`);
1862
- const userPoolId = bootstrap2.import(`auth-${id}-user-pool-id`);
1863
- const clientId = bootstrap2.import(`auth-${id}-client-id`);
1864
- const name = constantCase6(id);
1865
- lambda.addEnvironment(`AUTH_${name}_USER_POOL_ID`, userPoolId);
1866
- lambda.addEnvironment(`AUTH_${name}_CLIENT_ID`, clientId);
1867
- if (props.secret) {
1868
- const clientSecret = bootstrap2.import(`auth-${id}-client-secret`);
1869
- lambda.addEnvironment(`AUTH_${name}_CLIENT_SECRET`, clientSecret);
1870
- }
1871
- lambda.addPermissions({
1872
- actions: ["cognito:*"],
1873
- resources: [userPoolArn]
1874
- });
1875
- });
1876
1882
  }
1877
1883
  }
1878
1884
  });
@@ -3327,12 +3333,15 @@ var Listener = class extends Resource {
3327
3333
  Certificates: this.props.certificates.map((arn) => ({
3328
3334
  CertificateArn: arn
3329
3335
  })),
3330
- ...this.attr("DefaultActions", this.props.defaultActions?.map((action, i) => {
3331
- return {
3332
- Order: i + 1,
3333
- ...action.toJSON()
3334
- };
3335
- }))
3336
+ ...this.attr(
3337
+ "DefaultActions",
3338
+ this.props.defaultActions?.map((action, i) => {
3339
+ return {
3340
+ Order: i + 1,
3341
+ ...action.toJSON()
3342
+ };
3343
+ })
3344
+ )
3336
3345
  };
3337
3346
  }
3338
3347
  };
@@ -3698,7 +3707,10 @@ var EventSourceMapping = class extends Resource {
3698
3707
  ...this.attr("ParallelizationFactor", this.props.parallelizationFactor),
3699
3708
  ...this.attr("TumblingWindowInSeconds", this.props.tumblingWindow?.toSeconds()),
3700
3709
  ...this.attr("BisectBatchOnFunctionError", this.props.bisectBatchOnError),
3701
- ...this.attr("StartingPosition", this.props.startingPosition && constantCase10(this.props.startingPosition)),
3710
+ ...this.attr(
3711
+ "StartingPosition",
3712
+ this.props.startingPosition && constantCase10(this.props.startingPosition)
3713
+ ),
3702
3714
  ...this.attr("StartingPositionTimestamp", this.props.startingPositionTimestamp),
3703
3715
  ...this.props.maxConcurrency ? {
3704
3716
  ScalingConfig: {
@@ -3759,12 +3771,7 @@ var Queue = class extends Resource {
3759
3771
  }
3760
3772
  get permissions() {
3761
3773
  return {
3762
- actions: [
3763
- "sqs:SendMessage",
3764
- "sqs:ReceiveMessage",
3765
- "sqs:GetQueueUrl",
3766
- "sqs:GetQueueAttributes"
3767
- ],
3774
+ actions: ["sqs:SendMessage", "sqs:ReceiveMessage", "sqs:GetQueueUrl", "sqs:GetQueueAttributes"],
3768
3775
  resources: [
3769
3776
  formatArn({
3770
3777
  service: "sqs",
@@ -4085,9 +4092,11 @@ var DomainName2 = class extends Resource {
4085
4092
  properties() {
4086
4093
  return {
4087
4094
  DomainName: this.props.name,
4088
- DomainNameConfigurations: [{
4089
- CertificateArn: this.props.certificateArn
4090
- }]
4095
+ DomainNameConfigurations: [
4096
+ {
4097
+ CertificateArn: this.props.certificateArn
4098
+ }
4099
+ ]
4091
4100
  };
4092
4101
  }
4093
4102
  };
@@ -4407,12 +4416,7 @@ var Bucket = class extends Resource {
4407
4416
  }
4408
4417
  get permissions() {
4409
4418
  return {
4410
- actions: [
4411
- "s3:SendMessage",
4412
- "s3:ReceiveMessage",
4413
- "s3:GetQueueUrl",
4414
- "s3:GetQueueAttributes"
4415
- ],
4419
+ actions: ["s3:SendMessage", "s3:ReceiveMessage", "s3:GetQueueUrl", "s3:GetQueueAttributes"],
4416
4420
  resources: [
4417
4421
  formatArn({
4418
4422
  service: "s3",
@@ -4527,7 +4531,7 @@ var Files = class extends Asset {
4527
4531
  hash;
4528
4532
  bundle;
4529
4533
  s3;
4530
- async build({ read, write }) {
4534
+ async build({ write }) {
4531
4535
  const glob2 = new Glob(this.props.pattern ?? "**/*", {
4532
4536
  nodir: true,
4533
4537
  cwd: this.props.directory
@@ -4879,6 +4883,16 @@ var sitePlugin = definePlugin({
4879
4883
  });
4880
4884
 
4881
4885
  // src/plugins/store/index.ts
4886
+ var typeGenCode4 = `
4887
+ import { Body, PutObjectProps, BodyStream } from '@awsless/s3'
4888
+
4889
+ type Store<Name extends string> = {
4890
+ readonly name: Name
4891
+ readonly put: (key: string, body: Body, options?: Pick<PutObjectProps, 'metadata' | 'storageClass'>) => Promise<void>
4892
+ readonly get: (key: string) => Promise<BodyStream>
4893
+ readonly delete: (key: string) => Promise<void>
4894
+ }
4895
+ `;
4882
4896
  var storePlugin = definePlugin({
4883
4897
  name: "store",
4884
4898
  async onTypeGen({ config: config2, write }) {
@@ -4888,10 +4902,11 @@ var storePlugin = definePlugin({
4888
4902
  const list3 = new TypeObject(2);
4889
4903
  for (const name of stack.stores || []) {
4890
4904
  const storeName = formatName(`${config2.app.name}-${stack.name}-${name}`);
4891
- list3.addType(name, `{ readonly name: '${storeName}' }`);
4905
+ list3.addType(name, `Store<'${storeName}'>`);
4892
4906
  }
4893
4907
  resources.addType(stack.name, list3);
4894
4908
  }
4909
+ gen.addCode(typeGenCode4);
4895
4910
  gen.addInterface("StoreResources", resources);
4896
4911
  await write("store.d.ts", gen, true);
4897
4912
  },
@@ -4943,50 +4958,53 @@ var Table = class extends Resource {
4943
4958
  return getAtt(this.logicalId, "StreamArn");
4944
4959
  }
4945
4960
  get permissions() {
4946
- const permissions = [{
4947
- actions: [
4948
- "dynamodb:DescribeTable",
4949
- "dynamodb:PutItem",
4950
- "dynamodb:GetItem",
4951
- "dynamodb:DeleteItem",
4952
- "dynamodb:TransactWrite",
4953
- "dynamodb:BatchWriteItem",
4954
- "dynamodb:BatchGetItem",
4955
- "dynamodb:ConditionCheckItem",
4956
- "dynamodb:Query",
4957
- "dynamodb:Scan"
4958
- ],
4959
- resources: [
4960
- formatArn({
4961
- service: "dynamodb",
4962
- resource: "table",
4963
- resourceName: this.name
4964
- })
4965
- ]
4966
- }];
4961
+ const permissions = [
4962
+ {
4963
+ actions: [
4964
+ "dynamodb:DescribeTable",
4965
+ "dynamodb:PutItem",
4966
+ "dynamodb:GetItem",
4967
+ "dynamodb:DeleteItem",
4968
+ "dynamodb:TransactWrite",
4969
+ "dynamodb:BatchWriteItem",
4970
+ "dynamodb:BatchGetItem",
4971
+ "dynamodb:ConditionCheckItem",
4972
+ "dynamodb:Query",
4973
+ "dynamodb:Scan"
4974
+ ],
4975
+ resources: [
4976
+ formatArn({
4977
+ service: "dynamodb",
4978
+ resource: "table",
4979
+ resourceName: this.name
4980
+ })
4981
+ ]
4982
+ }
4983
+ ];
4967
4984
  const indexNames = Object.keys(this.indexes ?? {});
4968
4985
  if (indexNames.length > 0) {
4969
4986
  permissions.push({
4970
4987
  actions: ["dynamodb:Query"],
4971
- resources: indexNames.map((indexName) => formatArn({
4972
- service: "dynamodb",
4973
- resource: "table",
4974
- resourceName: `${this.name}/index/${indexName}`
4975
- }))
4988
+ resources: indexNames.map(
4989
+ (indexName) => formatArn({
4990
+ service: "dynamodb",
4991
+ resource: "table",
4992
+ resourceName: `${this.name}/index/${indexName}`
4993
+ })
4994
+ )
4976
4995
  });
4977
4996
  }
4978
4997
  return permissions;
4979
4998
  }
4980
4999
  attributeDefinitions() {
4981
5000
  const fields = this.props.fields || {};
4982
- const attributes = new Set([
4983
- this.props.hash,
4984
- this.props.sort,
4985
- ...Object.values(this.props.indexes || {}).map((index) => [
4986
- index.hash,
4987
- index.sort
4988
- ])
4989
- ].flat().filter(Boolean));
5001
+ const attributes = new Set(
5002
+ [
5003
+ this.props.hash,
5004
+ this.props.sort,
5005
+ ...Object.values(this.props.indexes || {}).map((index) => [index.hash, index.sort])
5006
+ ].flat().filter(Boolean)
5007
+ );
4990
5008
  const types2 = {
4991
5009
  string: "S",
4992
5010
  number: "N",
@@ -5200,7 +5218,7 @@ var isEmail = (value) => {
5200
5218
  };
5201
5219
 
5202
5220
  // src/plugins/topic/index.ts
5203
- var typeGenCode4 = `
5221
+ var typeGenCode5 = `
5204
5222
  import type { PublishOptions } from '@awsless/sns'
5205
5223
  import type { Mock } from 'vitest'
5206
5224
 
@@ -5227,7 +5245,7 @@ var topicPlugin = definePlugin({
5227
5245
  mocks.addType(topic, `MockBuilder`);
5228
5246
  }
5229
5247
  }
5230
- gen.addCode(typeGenCode4);
5248
+ gen.addCode(typeGenCode5);
5231
5249
  gen.addInterface("TopicResources", resources);
5232
5250
  gen.addInterface("TopicMock", mocks);
5233
5251
  gen.addInterface("TopicMockResponse", mockResponses);
package/dist/index.d.ts CHANGED
@@ -10904,7 +10904,7 @@ declare abstract class Resource {
10904
10904
  };
10905
10905
  };
10906
10906
  };
10907
- abstract properties(): object;
10907
+ protected abstract properties(): object;
10908
10908
  }
10909
10909
  declare class Group {
10910
10910
  readonly children: Array<Resource | Asset>;
@@ -10987,7 +10987,7 @@ declare class Url extends Resource {
10987
10987
  private props;
10988
10988
  constructor(logicalId: string, props: UrlProps);
10989
10989
  get url(): string;
10990
- properties(): {
10990
+ protected properties(): {
10991
10991
  Cors: {
10992
10992
  [x: string]: unknown;
10993
10993
  };
@@ -11044,7 +11044,7 @@ declare class Function$1 extends Resource {
11044
11044
  actions: string[];
11045
11045
  resources: string[];
11046
11046
  };
11047
- properties(): {
11047
+ protected properties(): {
11048
11048
  Environment: {
11049
11049
  Variables: Record<string, string>;
11050
11050
  };
package/dist/index.js CHANGED
@@ -191,11 +191,31 @@ var Cache = /* @__PURE__ */ createProxy((stack) => {
191
191
  });
192
192
 
193
193
  // src/node/store.ts
194
+ import { putObject, getObject, deleteObject } from "@awsless/s3";
194
195
  var getStoreName = getLocalResourceName;
195
196
  var Store = /* @__PURE__ */ createProxy((stack) => {
196
197
  return createProxy((name) => {
198
+ const bucket = getStoreName(name, stack);
197
199
  return {
198
- name: getStoreName(name, stack)
200
+ name: bucket,
201
+ async put(key, body, options = {}) {
202
+ await putObject({
203
+ bucket,
204
+ key,
205
+ body,
206
+ ...options
207
+ });
208
+ },
209
+ async get(key) {
210
+ const object = await getObject({ bucket, key });
211
+ if (object) {
212
+ return object.body;
213
+ }
214
+ return void 0;
215
+ },
216
+ delete(key) {
217
+ return deleteObject({ bucket, key });
218
+ }
199
219
  };
200
220
  });
201
221
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@awsless/awsless",
3
- "version": "0.0.148",
3
+ "version": "0.0.150",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -31,10 +31,11 @@
31
31
  "@awsless/lambda": "^0.0.15",
32
32
  "@awsless/redis": "^0.0.10",
33
33
  "@awsless/sns": "^0.0.7",
34
- "@awsless/sqs": "^0.0.7",
35
34
  "@awsless/ssm": "^0.0.7",
35
+ "@awsless/sqs": "^0.0.7",
36
36
  "@awsless/validate": "^0.0.10",
37
- "@awsless/weak-cache": "^0.0.1"
37
+ "@awsless/weak-cache": "^0.0.1",
38
+ "@awsless/s3": "^0.0.8"
38
39
  },
39
40
  "dependencies": {
40
41
  "@aws-appsync/utils": "^1.5.0",