sst 2.1.6 → 2.1.8

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.
@@ -64,7 +64,9 @@ export const update = (program) => program.command("update [version]", "Update y
64
64
  deps[pkg] = desired;
65
65
  }
66
66
  }
67
- await fs.writeFile(file, JSON.stringify(data, null, 2));
67
+ if (results.has(file)) {
68
+ await fs.writeFile(file, JSON.stringify(data, null, 2));
69
+ }
68
70
  });
69
71
  await Promise.all(tasks);
70
72
  if (results.size === 0) {
package/iot.d.ts CHANGED
@@ -2,5 +2,5 @@ export declare const useIOTEndpoint: () => Promise<string>;
2
2
  import { Events } from "./bus.js";
3
3
  export declare const useIOT: () => Promise<{
4
4
  prefix: string;
5
- publish<Type extends keyof Events>(topic: string, type: Type, properties: Events[Type]): void;
5
+ publish<Type extends keyof Events>(topic: string, type: Type, properties: Events[Type]): Promise<void>;
6
6
  }>;
package/iot.js CHANGED
@@ -22,6 +22,35 @@ export const useIOT = Context.memo(async () => {
22
22
  const endpoint = await useIOTEndpoint();
23
23
  const creds = await useAWSCredentials();
24
24
  const project = useProject();
25
+ /*
26
+ console.log(endpoint, creds);
27
+ const config =
28
+ iotsdk.iot.AwsIotMqttConnectionConfigBuilder.new_with_websockets({
29
+ region: project.config.region!,
30
+ credentials_provider: iotsdk.auth.AwsCredentialsProvider.newStatic(
31
+ creds.accessKeyId,
32
+ creds.secretAccessKey,
33
+ creds.sessionToken
34
+ ),
35
+ })
36
+ .with_client_id(randomUUID())
37
+ .with_endpoint(endpoint)
38
+ .build();
39
+ console.log(config);
40
+
41
+ const device2 = new iotsdk.mqtt.MqttClient();
42
+ const conn = device2.new_connection(config);
43
+ conn.on("connect", () => {
44
+ console.log("CONNECTED");
45
+ });
46
+ conn.on("error", console.log);
47
+ conn.on("connect", console.log);
48
+ conn.on("resume", console.log);
49
+ conn.on("message", console.log);
50
+ conn.on("disconnect", console.log);
51
+ conn.connect();
52
+ console.log(device2);
53
+ */
25
54
  const device = new iot.device({
26
55
  protocol: "wss",
27
56
  host: endpoint,
@@ -29,9 +58,10 @@ export const useIOT = Context.memo(async () => {
29
58
  accessKeyId: creds.accessKeyId,
30
59
  secretKey: creds.secretAccessKey,
31
60
  sessionToken: creds.sessionToken,
61
+ reconnectPeriod: 1,
32
62
  });
33
63
  const PREFIX = `/sst/${project.config.name}/${project.config.stage}`;
34
- device.subscribe(`${PREFIX}/events`);
64
+ device.subscribe(`${PREFIX}/events`, { qos: 1 });
35
65
  const fragments = new Map();
36
66
  device.on("connect", () => {
37
67
  Logger.debug("IoT connected");
@@ -39,6 +69,12 @@ export const useIOT = Context.memo(async () => {
39
69
  device.on("error", (err) => {
40
70
  Logger.debug("IoT error", err);
41
71
  });
72
+ device.on("close", () => {
73
+ Logger.debug("IoT closed");
74
+ });
75
+ device.on("reconnect", () => {
76
+ Logger.debug("IoT reconnected");
77
+ });
42
78
  device.on("message", (_topic, buffer) => {
43
79
  const fragment = JSON.parse(buffer.toString());
44
80
  if (!fragment.id) {
@@ -65,17 +101,22 @@ export const useIOT = Context.memo(async () => {
65
101
  });
66
102
  return {
67
103
  prefix: PREFIX,
68
- publish(topic, type, properties) {
104
+ async publish(topic, type, properties) {
69
105
  const payload = {
70
106
  type,
71
107
  properties,
72
108
  sourceID: bus.sourceID,
73
109
  };
74
110
  for (const fragment of encode(payload)) {
75
- device.publish(topic, JSON.stringify(fragment), {
76
- qos: 1,
111
+ await new Promise((r) => {
112
+ device.publish(topic, JSON.stringify(fragment), {
113
+ qos: 1,
114
+ }, () => {
115
+ r();
116
+ });
77
117
  });
78
118
  }
119
+ Logger.debug("IOT Published", topic, type);
79
120
  },
80
121
  };
81
122
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sst",
3
- "version": "2.1.6",
3
+ "version": "2.1.8",
4
4
  "bin": {
5
5
  "sst": "cli/sst.js"
6
6
  },
@@ -54,6 +54,7 @@
54
54
  "aws-cdk": "2.62.2",
55
55
  "aws-cdk-lib": "2.62.2",
56
56
  "aws-iot-device-sdk": "^2.2.12",
57
+ "aws-iot-device-sdk-v2": "^1.9.5",
57
58
  "aws-sdk": "^2.1326.0",
58
59
  "builtin-modules": "3.2.0",
59
60
  "cdk-assets": "2.62.2",
package/sst.mjs CHANGED
@@ -2652,10 +2652,11 @@ var init_iot = __esm({
2652
2652
  region: project.config.region,
2653
2653
  accessKeyId: creds.accessKeyId,
2654
2654
  secretKey: creds.secretAccessKey,
2655
- sessionToken: creds.sessionToken
2655
+ sessionToken: creds.sessionToken,
2656
+ reconnectPeriod: 1
2656
2657
  });
2657
2658
  const PREFIX2 = `/sst/${project.config.name}/${project.config.stage}`;
2658
- device.subscribe(`${PREFIX2}/events`);
2659
+ device.subscribe(`${PREFIX2}/events`, { qos: 1 });
2659
2660
  const fragments = /* @__PURE__ */ new Map();
2660
2661
  device.on("connect", () => {
2661
2662
  Logger.debug("IoT connected");
@@ -2663,6 +2664,12 @@ var init_iot = __esm({
2663
2664
  device.on("error", (err) => {
2664
2665
  Logger.debug("IoT error", err);
2665
2666
  });
2667
+ device.on("close", () => {
2668
+ Logger.debug("IoT closed");
2669
+ });
2670
+ device.on("reconnect", () => {
2671
+ Logger.debug("IoT reconnected");
2672
+ });
2666
2673
  device.on("message", (_topic, buffer) => {
2667
2674
  const fragment = JSON.parse(buffer.toString());
2668
2675
  if (!fragment.id) {
@@ -2686,17 +2693,27 @@ var init_iot = __esm({
2686
2693
  });
2687
2694
  return {
2688
2695
  prefix: PREFIX2,
2689
- publish(topic, type, properties) {
2696
+ async publish(topic, type, properties) {
2690
2697
  const payload = {
2691
2698
  type,
2692
2699
  properties,
2693
2700
  sourceID: bus.sourceID
2694
2701
  };
2695
2702
  for (const fragment of encode(payload)) {
2696
- device.publish(topic, JSON.stringify(fragment), {
2697
- qos: 1
2703
+ await new Promise((r) => {
2704
+ device.publish(
2705
+ topic,
2706
+ JSON.stringify(fragment),
2707
+ {
2708
+ qos: 1
2709
+ },
2710
+ () => {
2711
+ r();
2712
+ }
2713
+ );
2698
2714
  });
2699
2715
  }
2716
+ Logger.debug("IOT Published", topic, type);
2700
2717
  }
2701
2718
  };
2702
2719
  });
@@ -7472,7 +7489,9 @@ var update = (program2) => program2.command(
7472
7489
  deps[pkg] = desired;
7473
7490
  }
7474
7491
  }
7475
- await fs19.writeFile(file, JSON.stringify(data2, null, 2));
7492
+ if (results.has(file)) {
7493
+ await fs19.writeFile(file, JSON.stringify(data2, null, 2));
7494
+ }
7476
7495
  });
7477
7496
  await Promise.all(tasks);
7478
7497
  if (results.size === 0) {