@awsless/awsless 0.0.209 → 0.0.211

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.
Files changed (2) hide show
  1. package/dist/bin.js +152 -30
  2. package/package.json +5 -5
package/dist/bin.js CHANGED
@@ -1184,9 +1184,9 @@ var wrap = (lines, options) => {
1184
1184
  return wrapAnsi(typeof lines === "string" ? lines : lines.join("\n"), process.stdout.columns - 8, options);
1185
1185
  };
1186
1186
  var padText = (texts) => {
1187
- const size = Math.max(...texts.map((text2) => text2.length));
1188
- return (text2, padding = 0, fill) => {
1189
- return text2.padEnd(size + padding, fill);
1187
+ const size = Math.max(...texts.map((text3) => text3.length));
1188
+ return (text3, padding = 0, fill) => {
1189
+ return text3.padEnd(size + padding, fill);
1190
1190
  };
1191
1191
  };
1192
1192
  var task = async (message, cb) => {
@@ -1804,14 +1804,9 @@ var cacheFeature = defineFeature({
1804
1804
  ...props
1805
1805
  });
1806
1806
  ctx.onFunction(({ lambda }) => {
1807
- lambda.addEnvironment(
1808
- `CACHE_${constantCase2(ctx.stack.name)}_${constantCase2(id)}_HOST`,
1809
- cluster.address
1810
- );
1811
- lambda.addEnvironment(
1812
- `CACHE_${constantCase2(ctx.stack.name)}_${constantCase2(id)}_PORT`,
1813
- props.port.toString()
1814
- );
1807
+ const prefix = `CACHE_${constantCase2(ctx.stack.name)}_${constantCase2(id)}`;
1808
+ lambda.addEnvironment(`${prefix}_HOST`, cluster.address);
1809
+ lambda.addEnvironment(`${prefix}_PORT`, props.port.toString());
1815
1810
  });
1816
1811
  }
1817
1812
  }
@@ -2056,6 +2051,17 @@ var build = (type, name, builder) => {
2056
2051
  });
2057
2052
  };
2058
2053
 
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
+
2059
2065
  // src/feature/function/util.ts
2060
2066
  var createLambdaFunction = (group, ctx, ns, id, local2) => {
2061
2067
  let name;
@@ -2066,6 +2072,7 @@ var createLambdaFunction = (group, ctx, ns, id, local2) => {
2066
2072
  }
2067
2073
  const props = deepmerge(ctx.appConfig.defaults.function, local2);
2068
2074
  ctx.registerBuild("function", name, async (build3) => {
2075
+ props.file;
2069
2076
  const version = await fingerprintFromFile(props.file);
2070
2077
  return build3(version, async (write) => {
2071
2078
  const bundle = await bundleTypeScript({ file: props.file });
@@ -2117,9 +2124,15 @@ var createLambdaFunction = (group, ctx, ns, id, local2) => {
2117
2124
  }
2118
2125
  new aws2.lambda.EventInvokeConfig(group, "async", {
2119
2126
  functionArn: lambda.arn,
2120
- retryAttempts: props.retryAttempts
2121
- // onFailure: getGlobalOnFailure(ctx),
2127
+ retryAttempts: props.retryAttempts,
2128
+ onFailure: getGlobalOnFailure(ctx)
2122
2129
  });
2130
+ if (hasOnFailure(ctx.stackConfigs)) {
2131
+ policy.addStatement({
2132
+ actions: ["sqs:SendMessage", "sqs:GetQueueUrl"],
2133
+ resources: [getGlobalOnFailure(ctx)]
2134
+ });
2135
+ }
2123
2136
  if (props.log.retention.value > 0n) {
2124
2137
  const logGroup = new aws2.cloudWatch.LogGroup(group, "log", {
2125
2138
  name: lambda.name.apply((name2) => `/aws/lambda/${name2}`),
@@ -2951,17 +2964,6 @@ var graphqlFeature = defineFeature({
2951
2964
  }
2952
2965
  });
2953
2966
 
2954
- // src/feature/on-failure/util.ts
2955
- var getGlobalOnFailure = (ctx) => {
2956
- return hasOnFailure(ctx.stackConfigs) ? ctx.shared.get("on-failure-queue-arn") : void 0;
2957
- };
2958
- var hasOnFailure = (stacks) => {
2959
- const onFailure = stacks.find((stack) => {
2960
- return typeof stack.onFailure !== "undefined";
2961
- });
2962
- return !!onFailure;
2963
- };
2964
-
2965
2967
  // src/feature/on-failure/index.ts
2966
2968
  import { Node as Node7, aws as aws7 } from "@awsless/formation";
2967
2969
  var onFailureFeature = defineFeature({
@@ -2987,11 +2989,12 @@ var onFailureFeature = defineFeature({
2987
2989
  const queueArn = ctx.shared.get("on-failure-queue-arn");
2988
2990
  const group = new Node7(ctx.stack, "on-failure", "failure");
2989
2991
  const { lambda, policy } = createLambdaFunction(group, ctx, "on-failure", "failure", onFailure);
2990
- new aws7.lambda.EventSourceMapping(group, "on-failure", {
2992
+ const source = new aws7.lambda.EventSourceMapping(group, "on-failure", {
2991
2993
  functionArn: lambda.arn,
2992
2994
  sourceArn: queueArn,
2993
2995
  batchSize: 10
2994
2996
  });
2997
+ source.dependsOn(policy);
2995
2998
  policy.addStatement({
2996
2999
  actions: [
2997
3000
  "sqs:SendMessage",
@@ -3200,6 +3203,7 @@ var tableFeature = defineFeature({
3200
3203
  });
3201
3204
  if (props.stream) {
3202
3205
  const { lambda, policy } = createLambdaFunction(group, ctx, "table", id, props.stream.consumer);
3206
+ const onFailure = getGlobalOnFailure(ctx);
3203
3207
  const source = new aws11.lambda.EventSourceMapping(group, id, {
3204
3208
  functionArn: lambda.arn,
3205
3209
  sourceArn: table2.streamArn,
@@ -3208,10 +3212,16 @@ var tableFeature = defineFeature({
3208
3212
  // retryAttempts: props.stream.consumer.retryAttempts ?? -1,
3209
3213
  parallelizationFactor: 1,
3210
3214
  startingPosition: "latest",
3211
- onFailure: getGlobalOnFailure(ctx)
3215
+ onFailure
3212
3216
  });
3213
3217
  policy.addStatement(table2.streamPermissions);
3214
3218
  source.dependsOn(policy);
3219
+ if (onFailure) {
3220
+ policy.addStatement({
3221
+ actions: ["sqs:SendMessage", "sqs:GetQueueUrl"],
3222
+ resources: [onFailure]
3223
+ });
3224
+ }
3215
3225
  }
3216
3226
  ctx.onFunction(({ policy }) => {
3217
3227
  policy.addStatement(...table2.permissions);
@@ -3975,7 +3985,7 @@ var restFeature = defineFeature({
3975
3985
  },
3976
3986
  onStack(ctx) {
3977
3987
  for (const [id, routes] of Object.entries(ctx.stackConfig.rest ?? {})) {
3978
- const restGroup = new Node18(ctx.base, "rest", id);
3988
+ const restGroup = new Node18(ctx.stack, "rest", id);
3979
3989
  for (const [routeKey, props] of Object.entries(routes)) {
3980
3990
  const group = new Node18(restGroup, "route", routeKey);
3981
3991
  const apiId = ctx.shared.get(`rest-${id}-id`);
@@ -4076,6 +4086,8 @@ var createApp = (props, filters = []) => {
4076
4086
  const builders = [];
4077
4087
  const allFunctions = [];
4078
4088
  const globalListeners = [];
4089
+ const allLocalListeners = {};
4090
+ const allLocalFunctions = {};
4079
4091
  for (const feature of features) {
4080
4092
  feature.onApp?.({
4081
4093
  ...props,
@@ -4105,6 +4117,8 @@ var createApp = (props, filters = []) => {
4105
4117
  const localListeners = [];
4106
4118
  const localFunctions = [];
4107
4119
  const stack = new Stack(app, stackConfig.name);
4120
+ allLocalListeners[stack.name] = localListeners;
4121
+ allLocalFunctions[stack.name] = localFunctions;
4108
4122
  for (const feature of features) {
4109
4123
  feature.onStack?.({
4110
4124
  ...props,
@@ -4142,10 +4156,22 @@ var createApp = (props, filters = []) => {
4142
4156
  listener(fn);
4143
4157
  }
4144
4158
  }
4159
+ for (const stackConfig of filterdStacks) {
4160
+ const functions = allLocalFunctions[stackConfig.name];
4161
+ for (const dependency of stackConfig.depends ?? []) {
4162
+ const listeners = allLocalListeners[dependency];
4163
+ for (const fn of functions) {
4164
+ for (const listener of listeners) {
4165
+ listener(fn);
4166
+ }
4167
+ }
4168
+ }
4169
+ }
4145
4170
  return {
4146
4171
  app,
4147
4172
  base,
4148
4173
  tests,
4174
+ shared,
4149
4175
  configs,
4150
4176
  builders
4151
4177
  // deploymentLine,
@@ -4324,7 +4350,7 @@ var commands = [
4324
4350
  list2
4325
4351
  ];
4326
4352
  var config = (program2) => {
4327
- const command = program2.command("config").description(`Manage app config's`);
4353
+ const command = program2.command("config").description(`Manage app config parameters`);
4328
4354
  commands.forEach((cb) => cb(command));
4329
4355
  };
4330
4356
 
@@ -4988,8 +5014,103 @@ var state = (program2) => {
4988
5014
  commands3.forEach((cb) => cb(command));
4989
5015
  };
4990
5016
 
5017
+ // src/cli/command/auth/user/create.ts
5018
+ import { unwrap } from "@awsless/formation";
5019
+ import {
5020
+ AdminCreateUserCommand,
5021
+ AdminSetUserPasswordCommand,
5022
+ CognitoIdentityProviderClient
5023
+ } from "@aws-sdk/client-cognito-identity-provider";
5024
+ import { password, select, text as text2 } from "@clack/prompts";
5025
+ var create = (program2) => {
5026
+ program2.command("create").argument("[name]", "The name of the auth instance").description("Create an user for your userpool").action(async (name) => {
5027
+ await layout("auth user create", async ({ appConfig, stackConfigs }) => {
5028
+ const region = appConfig.region;
5029
+ const credentials = getCredentials(appConfig.profile);
5030
+ const accountId = await getAccountId(credentials, region);
5031
+ if (!name) {
5032
+ name = await select({
5033
+ message: "Select the auth userpool:",
5034
+ options: Object.keys(appConfig.defaults.auth).map((name2) => ({
5035
+ label: name2,
5036
+ value: name2
5037
+ }))
5038
+ });
5039
+ }
5040
+ if (!(name in appConfig.defaults.auth)) {
5041
+ throw new Error(`Provided auth name doesn't exist inside your app config.`);
5042
+ }
5043
+ const { shared, app } = createApp({ appConfig, stackConfigs, accountId });
5044
+ const { workspace } = createWorkSpace({
5045
+ credentials,
5046
+ region
5047
+ });
5048
+ await workspace.hydrate(app);
5049
+ let userPoolId;
5050
+ try {
5051
+ userPoolId = unwrap(shared.get(`auth-${name}-user-pool-id`));
5052
+ } catch (_) {
5053
+ throw new Error(`The auth userpool hasn't been deployed yet.`);
5054
+ }
5055
+ const user2 = await text2({
5056
+ message: "Username:",
5057
+ validate(value) {
5058
+ if (!value) {
5059
+ return "Required";
5060
+ }
5061
+ return;
5062
+ }
5063
+ });
5064
+ const pass = await password({
5065
+ message: "Password:",
5066
+ mask: "*",
5067
+ validate(value) {
5068
+ if (!value) {
5069
+ return "Required";
5070
+ }
5071
+ return;
5072
+ }
5073
+ });
5074
+ const client = new CognitoIdentityProviderClient({
5075
+ region,
5076
+ credentials
5077
+ });
5078
+ await client.send(
5079
+ new AdminCreateUserCommand({
5080
+ UserPoolId: userPoolId,
5081
+ Username: user2.toString(),
5082
+ TemporaryPassword: pass.toString()
5083
+ })
5084
+ );
5085
+ await client.send(
5086
+ new AdminSetUserPasswordCommand({
5087
+ UserPoolId: userPoolId,
5088
+ Username: user2.toString(),
5089
+ Password: pass.toString(),
5090
+ Permanent: true
5091
+ })
5092
+ );
5093
+ return "User created.";
5094
+ });
5095
+ });
5096
+ };
5097
+
5098
+ // src/cli/command/auth/user/index.ts
5099
+ var commands4 = [create];
5100
+ var user = (program2) => {
5101
+ const command = program2.command("user").description(`Manage auth users`);
5102
+ commands4.forEach((cb) => cb(command));
5103
+ };
5104
+
5105
+ // src/cli/command/auth/index.ts
5106
+ var commands5 = [user];
5107
+ var auth = (program2) => {
5108
+ const command = program2.command("auth").description(`Manage auth`);
5109
+ commands5.forEach((cb) => cb(command));
5110
+ };
5111
+
4991
5112
  // src/cli/command/index.ts
4992
- var commands4 = [
5113
+ var commands6 = [
4993
5114
  bootstrap,
4994
5115
  types,
4995
5116
  build2,
@@ -4998,6 +5119,7 @@ var commands4 = [
4998
5119
  del2,
4999
5120
  dev,
5000
5121
  // bind,
5122
+ auth,
5001
5123
  state,
5002
5124
  resource,
5003
5125
  config,
@@ -5024,7 +5146,7 @@ program.on("option:skip-prompt", () => {
5024
5146
  program.on("option:no-cache", () => {
5025
5147
  process.env.NO_CACHE = program.opts().noCache ? "1" : void 0;
5026
5148
  });
5027
- commands4.forEach((fn) => fn(program));
5149
+ commands6.forEach((fn) => fn(program));
5028
5150
 
5029
5151
  // src/bin.ts
5030
5152
  program.parse(process.argv);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@awsless/awsless",
3
- "version": "0.0.209",
3
+ "version": "0.0.211",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -30,13 +30,13 @@
30
30
  "peerDependencies": {
31
31
  "@awsless/lambda": "^0.0.18",
32
32
  "@awsless/open-search": "^0.0.12",
33
- "@awsless/redis": "^0.0.12",
34
33
  "@awsless/s3": "^0.0.10",
34
+ "@awsless/redis": "^0.0.12",
35
35
  "@awsless/sns": "^0.0.7",
36
36
  "@awsless/sqs": "^0.0.7",
37
+ "@awsless/validate": "^0.0.13",
37
38
  "@awsless/ssm": "^0.0.7",
38
- "@awsless/weak-cache": "^0.0.1",
39
- "@awsless/validate": "^0.0.13"
39
+ "@awsless/weak-cache": "^0.0.1"
40
40
  },
41
41
  "dependencies": {
42
42
  "@aws-appsync/utils": "^1.5.0",
@@ -98,8 +98,8 @@
98
98
  "zod": "^3.21.4",
99
99
  "zod-to-json-schema": "^3.22.3",
100
100
  "@awsless/duration": "^0.0.1",
101
+ "@awsless/formation": "^0.0.20",
101
102
  "@awsless/graphql": "^0.0.9",
102
- "@awsless/formation": "^0.0.19",
103
103
  "@awsless/validate": "^0.0.13",
104
104
  "@awsless/size": "^0.0.1",
105
105
  "@awsless/code": "^0.0.10"