sst 2.0.0-rc.37 → 2.0.0-rc.38

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/bootstrap.js CHANGED
@@ -68,7 +68,9 @@ export async function initBootstrap() {
68
68
  }),
69
69
  new PolicyStatement({
70
70
  actions: ["iot:Publish"],
71
- resources: [`arn:${stack.partition}:iot:${stack.region}:${stack.account}:topic//sst/*`],
71
+ resources: [
72
+ `arn:${stack.partition}:iot:${stack.region}:${stack.account}:topic//sst/*`,
73
+ ],
72
74
  }),
73
75
  ],
74
76
  });
@@ -1,11 +1,14 @@
1
+ import { get } from "./get.js";
2
+ import { list } from "./list.js";
3
+ import { remove } from "./remove.js";
1
4
  import { set } from "./set.js";
2
5
  export function secrets(program) {
3
6
  program.command("secrets", "Manage the secrets in your app", (yargs) => {
4
7
  yargs.demandCommand(1);
5
8
  set(yargs);
6
- // get(yargs);
7
- // list(yargs);
8
- // remove(yargs);
9
+ get(yargs);
10
+ list(yargs);
11
+ remove(yargs);
9
12
  return yargs;
10
13
  });
11
14
  }
package/cli/program.js CHANGED
@@ -22,7 +22,7 @@ export const program = yargs(hideBin(process.argv))
22
22
  type: "string",
23
23
  describe: "ARN of the IAM role to use when invoking AWS",
24
24
  })
25
- .group(["stage", "profile", "region", "help"], "Global:")
25
+ .group(["stage", "profile", "region", "help", "verbose", "role"], "Global:")
26
26
  .middleware(async (argv) => {
27
27
  if (argv.verbose) {
28
28
  process.env.SST_VERBOSE = "1";
package/iot.js CHANGED
@@ -37,6 +37,10 @@ export const useIOT = Context.memo(async () => {
37
37
  });
38
38
  device.on("message", (_topic, buffer) => {
39
39
  const fragment = JSON.parse(buffer.toString());
40
+ if (!fragment.id) {
41
+ bus.publish(fragment.type, fragment.properties);
42
+ return;
43
+ }
40
44
  let pending = fragments.get(fragment.id);
41
45
  if (!pending) {
42
46
  pending = new Map();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sst",
3
- "version": "2.0.0-rc.37",
3
+ "version": "2.0.0-rc.38",
4
4
  "bin": {
5
5
  "sst": "cli/sst.js"
6
6
  },
package/sst.mjs CHANGED
@@ -2352,7 +2352,7 @@ async function metadata() {
2352
2352
  credentials
2353
2353
  });
2354
2354
  const key = `stackMetadata/app.${project.config.name}/stage.${project.config.stage}/`;
2355
- const list = await s3.send(
2355
+ const list2 = await s3.send(
2356
2356
  new ListObjectsV2Command({
2357
2357
  Prefix: key,
2358
2358
  Bucket: bootstrap.bucket
@@ -2360,7 +2360,7 @@ async function metadata() {
2360
2360
  );
2361
2361
  const result = Object.fromEntries(
2362
2362
  await Promise.all(
2363
- list.Contents?.map(async (obj) => {
2363
+ list2.Contents?.map(async (obj) => {
2364
2364
  const stackID = obj.Key?.split("/").pop();
2365
2365
  const result2 = await s3.send(
2366
2366
  new GetObjectCommand({
@@ -2372,7 +2372,7 @@ async function metadata() {
2372
2372
  }) || []
2373
2373
  )
2374
2374
  );
2375
- Logger.debug("Fetched metadata from", list.KeyCount, "stacks");
2375
+ Logger.debug("Fetched metadata from", list2.KeyCount, "stacks");
2376
2376
  return result;
2377
2377
  }
2378
2378
  async function metadataForStack(stackID) {
@@ -2409,22 +2409,23 @@ var init_metadata = __esm({
2409
2409
  init_cache();
2410
2410
  init_context();
2411
2411
  init_bus();
2412
- init_stacks();
2413
2412
  init_logger();
2414
2413
  init_project();
2415
2414
  MetadataContext = Context.create(async () => {
2416
2415
  const bus = useBus();
2417
2416
  const cache = await useCache();
2418
2417
  const data2 = await metadata();
2419
- bus.subscribe("stack.status", async (evt) => {
2420
- if (!stacks_exports.isSuccess(evt.properties.status))
2421
- return;
2422
- const meta = await metadataForStack(evt.properties.stackID);
2423
- Logger.debug("Got metadata", meta);
2424
- data2[evt.properties.stackID] = meta;
2425
- await cache.write(`metadata.json`, JSON.stringify(data2));
2426
- bus.publish("stacks.metadata", data2);
2427
- MetadataContext.provide(Promise.resolve(data2));
2418
+ bus.subscribe("stacks.metadata.updated", async () => {
2419
+ const data3 = await metadata();
2420
+ await cache.write(`metadata.json`, JSON.stringify(data3));
2421
+ bus.publish("stacks.metadata", data3);
2422
+ MetadataContext.provide(Promise.resolve(data3));
2423
+ });
2424
+ bus.subscribe("stacks.metadata.deleted", async () => {
2425
+ const data3 = await metadata();
2426
+ await cache.write(`metadata.json`, JSON.stringify(data3));
2427
+ bus.publish("stacks.metadata", data3);
2428
+ MetadataContext.provide(Promise.resolve(data3));
2428
2429
  });
2429
2430
  return data2;
2430
2431
  });
@@ -3851,7 +3852,9 @@ async function initBootstrap() {
3851
3852
  }),
3852
3853
  new PolicyStatement({
3853
3854
  actions: ["iot:Publish"],
3854
- resources: [`arn:${stack.partition}:iot:${stack.region}:${stack.account}:topic//sst/*`]
3855
+ resources: [
3856
+ `arn:${stack.partition}:iot:${stack.region}:${stack.account}:topic//sst/*`
3857
+ ]
3855
3858
  })
3856
3859
  ]
3857
3860
  });
@@ -4484,6 +4487,10 @@ var init_iot = __esm({
4484
4487
  });
4485
4488
  device.on("message", (_topic, buffer) => {
4486
4489
  const fragment = JSON.parse(buffer.toString());
4490
+ if (!fragment.id) {
4491
+ bus.publish(fragment.type, fragment.properties);
4492
+ return;
4493
+ }
4487
4494
  let pending = fragments.get(fragment.id);
4488
4495
  if (!pending) {
4489
4496
  pending = /* @__PURE__ */ new Map();
@@ -5706,7 +5713,7 @@ var program = yargs(hideBin(process.argv)).scriptName("sst").option("stage", {
5706
5713
  }).option("role", {
5707
5714
  type: "string",
5708
5715
  describe: "ARN of the IAM role to use when invoking AWS"
5709
- }).group(["stage", "profile", "region", "help"], "Global:").middleware(async (argv) => {
5716
+ }).group(["stage", "profile", "region", "help", "verbose", "role"], "Global:").middleware(async (argv) => {
5710
5717
  if (argv.verbose) {
5711
5718
  process.env.SST_VERBOSE = "1";
5712
5719
  }
@@ -6181,6 +6188,108 @@ var consoleCommand = async (program2) => program2.command(
6181
6188
  }
6182
6189
  );
6183
6190
 
6191
+ // src/cli/commands/secrets/get.ts
6192
+ var get = (program2) => program2.command(
6193
+ "get <name>",
6194
+ "Get the value of a secret",
6195
+ (yargs2) => yargs2.positional("name", {
6196
+ type: "string",
6197
+ describe: "Name of the secret",
6198
+ demandOption: true
6199
+ }).option("fallback", {
6200
+ type: "boolean",
6201
+ describe: "Get the fallback value"
6202
+ }),
6203
+ async (args) => {
6204
+ const { red: red3 } = await import("colorette");
6205
+ const { Config: Config2 } = await Promise.resolve().then(() => (init_config(), config_exports));
6206
+ const { bold: bold2 } = await import("colorette");
6207
+ try {
6208
+ const result = await Config2.getSecret({
6209
+ key: args.name,
6210
+ fallback: args.fallback === true
6211
+ });
6212
+ console.log(bold2(result));
6213
+ } catch {
6214
+ console.log(red3(`${bold2(args.name)} is not set`));
6215
+ }
6216
+ }
6217
+ );
6218
+
6219
+ // src/cli/commands/secrets/list.ts
6220
+ var list = (program2) => program2.command(
6221
+ "list [format]",
6222
+ "Fetch all the secrets",
6223
+ (yargs2) => yargs2.positional("format", {
6224
+ type: "string",
6225
+ choices: ["table", "env"]
6226
+ }),
6227
+ async (args) => {
6228
+ const { Config: Config2 } = await Promise.resolve().then(() => (init_config(), config_exports));
6229
+ const { gray } = await import("colorette");
6230
+ const secrets2 = await Config2.secrets();
6231
+ switch (args.format || "table") {
6232
+ case "env":
6233
+ for (const [key, value] of Object.entries(secrets2)) {
6234
+ console.log(`${key}=${value.value || value.fallback}`);
6235
+ }
6236
+ break;
6237
+ case "table":
6238
+ const keys2 = Object.keys(secrets2);
6239
+ const keyLen = Math.max(
6240
+ "Secrets".length,
6241
+ ...keys2.map((key) => key.length)
6242
+ );
6243
+ const valueLen = Math.max(
6244
+ "Values".length,
6245
+ ...keys2.map(
6246
+ (key) => secrets2[key].value ? secrets2[key].value.length : `${secrets2[key].fallback} (fallback)`.length
6247
+ )
6248
+ );
6249
+ console.log(
6250
+ "\u250C".padEnd(keyLen + 3, "\u2500") + "\u252C" + "".padEnd(valueLen + 2, "\u2500") + "\u2510"
6251
+ );
6252
+ console.log(
6253
+ `\u2502 ${"Secrets".padEnd(keyLen)} \u2502 ${"Values".padEnd(valueLen)} \u2502`
6254
+ );
6255
+ console.log(
6256
+ "\u251C".padEnd(keyLen + 3, "\u2500") + "\u253C" + "".padEnd(valueLen + 2, "\u2500") + "\u2524"
6257
+ );
6258
+ keys2.sort().forEach((key) => {
6259
+ const value = secrets2[key].value ? secrets2[key].value : `${secrets2[key].fallback} ${gray("(fallback)")}`;
6260
+ console.log(
6261
+ `\u2502 ${key.padEnd(keyLen)} \u2502 ${value.padEnd(valueLen)} \u2502`
6262
+ );
6263
+ });
6264
+ console.log(
6265
+ "\u2514".padEnd(keyLen + 3, "\u2500") + "\u2534" + "".padEnd(valueLen + 2, "\u2500") + "\u2518"
6266
+ );
6267
+ break;
6268
+ }
6269
+ }
6270
+ );
6271
+
6272
+ // src/cli/commands/secrets/remove.ts
6273
+ var remove3 = (program2) => program2.command(
6274
+ "remove <name>",
6275
+ "Remove a secret",
6276
+ (yargs2) => yargs2.positional("name", {
6277
+ describe: "Name of the secret",
6278
+ type: "string",
6279
+ demandOption: true
6280
+ }).option("fallback", {
6281
+ type: "boolean",
6282
+ describe: "Remove the fallback value"
6283
+ }),
6284
+ async (args) => {
6285
+ const { Config: Config2 } = await Promise.resolve().then(() => (init_config(), config_exports));
6286
+ await Config2.removeSecret({
6287
+ key: args.name,
6288
+ fallback: args.fallback === true
6289
+ });
6290
+ }
6291
+ );
6292
+
6184
6293
  // src/cli/commands/secrets/set.ts
6185
6294
  var set = (program2) => program2.command(
6186
6295
  "set <name> <value>",
@@ -6223,6 +6332,9 @@ function secrets(program2) {
6223
6332
  program2.command("secrets", "Manage the secrets in your app", (yargs2) => {
6224
6333
  yargs2.demandCommand(1);
6225
6334
  set(yargs2);
6335
+ get(yargs2);
6336
+ list(yargs2);
6337
+ remove3(yargs2);
6226
6338
  return yargs2;
6227
6339
  });
6228
6340
  }
@@ -5,7 +5,6 @@ import { json } from "stream/consumers";
5
5
  import { useCache } from "../cache.js";
6
6
  import { Context } from "../context/context.js";
7
7
  import { useBus } from "../bus.js";
8
- import { Stacks } from "./index.js";
9
8
  import { Logger } from "../logger.js";
10
9
  import { useProject } from "../project.js";
11
10
  export async function metadata() {
@@ -67,12 +66,14 @@ const MetadataContext = Context.create(async () => {
67
66
  const bus = useBus();
68
67
  const cache = await useCache();
69
68
  const data = await metadata();
70
- bus.subscribe("stack.status", async (evt) => {
71
- if (!Stacks.isSuccess(evt.properties.status))
72
- return;
73
- const meta = await metadataForStack(evt.properties.stackID);
74
- Logger.debug("Got metadata", meta);
75
- data[evt.properties.stackID] = meta;
69
+ bus.subscribe("stacks.metadata.updated", async () => {
70
+ const data = await metadata();
71
+ await cache.write(`metadata.json`, JSON.stringify(data));
72
+ bus.publish("stacks.metadata", data);
73
+ MetadataContext.provide(Promise.resolve(data));
74
+ });
75
+ bus.subscribe("stacks.metadata.deleted", async () => {
76
+ const data = await metadata();
76
77
  await cache.write(`metadata.json`, JSON.stringify(data));
77
78
  bus.publish("stacks.metadata", data);
78
79
  MetadataContext.provide(Promise.resolve(data));