@alwaysai/device-agent 2.0.2-0 → 2.0.2

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 (46) hide show
  1. package/lib/application-control/install.d.ts.map +1 -1
  2. package/lib/application-control/install.js +5 -1
  3. package/lib/application-control/install.js.map +1 -1
  4. package/lib/cloud-connection/connection-manager.d.ts +3 -4
  5. package/lib/cloud-connection/connection-manager.d.ts.map +1 -1
  6. package/lib/cloud-connection/connection-manager.js +20 -38
  7. package/lib/cloud-connection/connection-manager.js.map +1 -1
  8. package/lib/cloud-connection/device-agent-cloud-connection.d.ts +3 -1
  9. package/lib/cloud-connection/device-agent-cloud-connection.d.ts.map +1 -1
  10. package/lib/cloud-connection/device-agent-cloud-connection.js +49 -38
  11. package/lib/cloud-connection/device-agent-cloud-connection.js.map +1 -1
  12. package/lib/environment.d.ts +3 -0
  13. package/lib/environment.d.ts.map +1 -1
  14. package/lib/environment.js +12 -1
  15. package/lib/environment.js.map +1 -1
  16. package/lib/jobs/job-handler.d.ts +1 -1
  17. package/lib/jobs/job-handler.d.ts.map +1 -1
  18. package/lib/jobs/job-handler.js +4 -4
  19. package/lib/jobs/job-handler.js.map +1 -1
  20. package/lib/subcommands/app/analytics.d.ts.map +1 -1
  21. package/lib/subcommands/app/analytics.js +2 -3
  22. package/lib/subcommands/app/analytics.js.map +1 -1
  23. package/lib/subcommands/app/env-vars.d.ts.map +1 -1
  24. package/lib/subcommands/app/env-vars.js +4 -6
  25. package/lib/subcommands/app/env-vars.js.map +1 -1
  26. package/lib/subcommands/app/models.d.ts.map +1 -1
  27. package/lib/subcommands/app/models.js +2 -3
  28. package/lib/subcommands/app/models.js.map +1 -1
  29. package/lib/subcommands/app/shadow.d.ts.map +1 -1
  30. package/lib/subcommands/app/shadow.js +4 -6
  31. package/lib/subcommands/app/shadow.js.map +1 -1
  32. package/lib/subcommands/app/version.d.ts.map +1 -1
  33. package/lib/subcommands/app/version.js +6 -9
  34. package/lib/subcommands/app/version.js.map +1 -1
  35. package/package.json +1 -1
  36. package/readme.md +16 -4
  37. package/src/application-control/install.ts +8 -3
  38. package/src/cloud-connection/connection-manager.ts +21 -43
  39. package/src/cloud-connection/device-agent-cloud-connection.ts +91 -79
  40. package/src/environment.ts +18 -0
  41. package/src/jobs/job-handler.ts +4 -4
  42. package/src/subcommands/app/analytics.ts +2 -3
  43. package/src/subcommands/app/env-vars.ts +4 -6
  44. package/src/subcommands/app/models.ts +2 -3
  45. package/src/subcommands/app/shadow.ts +4 -6
  46. package/src/subcommands/app/version.ts +7 -8
@@ -80,6 +80,7 @@ export const setAnalyticsCfgCliLeaf = CliLeaf({
80
80
  appConfig: JSON.stringify(appCfg) // Pack app config as string as dictated by schema
81
81
  }
82
82
  };
83
+ await deviceAgent.waitForConnection();
83
84
  deviceAgent.publisher.publish(
84
85
  getShadowTopic(deviceAgent.getClientId(), 'projects', 'update'),
85
86
  JSON.stringify(
@@ -92,9 +93,7 @@ export const setAnalyticsCfgCliLeaf = CliLeaf({
92
93
  // Sleep for extra time to ensure time for shadow response
93
94
  await sleep(10000);
94
95
 
95
- while (deviceAgent.isCmdInProgress(project)) {
96
- await sleep(1000);
97
- }
96
+ await deviceAgent.waitForCmd(project);
98
97
  await deviceAgent.stop();
99
98
  }
100
99
  });
@@ -66,6 +66,7 @@ export const setEnvCliLeaf = CliLeaf({
66
66
  envVars: JSON.stringify(envVars)
67
67
  }
68
68
  };
69
+ await deviceAgent.waitForConnection();
69
70
  deviceAgent.publisher.publish(
70
71
  getShadowTopic(deviceAgent.getClientId(), 'projects', 'update'),
71
72
  JSON.stringify(
@@ -78,9 +79,7 @@ export const setEnvCliLeaf = CliLeaf({
78
79
  // Sleep for extra time to ensure time for shadow response
79
80
  await sleep(10000);
80
81
 
81
- while (deviceAgent.isCmdInProgress(projectId)) {
82
- await sleep(1000);
83
- }
82
+ await deviceAgent.waitForCmd(projectId);
84
83
  await deviceAgent.stop();
85
84
  }
86
85
  });
@@ -128,6 +127,7 @@ export const rmEnvCliLeaf = CliLeaf({
128
127
  envVars: JSON.stringify(newEnvs)
129
128
  }
130
129
  };
130
+ await deviceAgent.waitForConnection();
131
131
  deviceAgent.publisher.publish(
132
132
  getShadowTopic(deviceAgent.getClientId(), 'projects', 'update'),
133
133
  JSON.stringify(
@@ -140,9 +140,7 @@ export const rmEnvCliLeaf = CliLeaf({
140
140
  // Sleep for extra time to ensure time for shadow response
141
141
  await sleep(10000);
142
142
 
143
- while (deviceAgent.isCmdInProgress(projectId)) {
144
- await sleep(1000);
145
- }
143
+ await deviceAgent.waitForCmd(projectId);
146
144
  await deviceAgent.stop();
147
145
  }
148
146
  });
@@ -54,6 +54,7 @@ export const addModelCliLeaf = CliLeaf({
54
54
  appConfig: JSON.stringify(newAppCfg)
55
55
  }
56
56
  };
57
+ await deviceAgent.waitForConnection();
57
58
  deviceAgent.publisher.publish(
58
59
  getShadowTopic(deviceAgent.getClientId(), 'projects', 'update'),
59
60
  JSON.stringify(
@@ -66,9 +67,7 @@ export const addModelCliLeaf = CliLeaf({
66
67
  // Sleep for extra time to ensure time for shadow response
67
68
  await sleep(10000);
68
69
 
69
- while (deviceAgent.isCmdInProgress(projectId)) {
70
- await sleep(1000);
71
- }
70
+ await deviceAgent.waitForCmd(projectId);
72
71
  await deviceAgent.stop();
73
72
  }
74
73
  });
@@ -14,13 +14,12 @@ export const getShadowCliLeaf = CliLeaf({
14
14
  async action(_, opts) {
15
15
  const { project } = opts;
16
16
  const deviceAgent = new DeviceAgentCloudConnection();
17
+ await deviceAgent.waitForConnection();
17
18
  deviceAgent.shadowHandler.getProjectShadowUpdates();
18
19
 
19
20
  // 5 seconds should cover the response wait time
20
21
  await sleep(5000);
21
- while (deviceAgent.isCmdInProgress(project)) {
22
- await sleep(1000);
23
- }
22
+ await deviceAgent.waitForCmd(project);
24
23
  await deviceAgent.stop();
25
24
  }
26
25
  });
@@ -37,13 +36,12 @@ export const updateShadowCliLeaf = CliLeaf({
37
36
  async action(_, opts) {
38
37
  const { project } = opts;
39
38
  const deviceAgent = new DeviceAgentCloudConnection();
39
+ await deviceAgent.waitForConnection();
40
40
  await deviceAgent.shadowHandler.updateProjectShadow(project);
41
41
 
42
42
  // 5 seconds should cover the response wait time
43
43
  await sleep(5000);
44
- while (deviceAgent.isCmdInProgress(project)) {
45
- await sleep(1000);
46
- }
44
+ await deviceAgent.waitForCmd(project);
47
45
  await deviceAgent.stop();
48
46
  }
49
47
  });
@@ -10,6 +10,7 @@ import { DeviceAgentCloudConnection } from '../../cloud-connection/device-agent-
10
10
  import { AgentConfigFile } from '../../infrastructure/agent-config';
11
11
  import sleep from '../../util/sleep';
12
12
  import { logger } from '../../util/logger';
13
+ import { device } from 'alwaysai/lib/components';
13
14
 
14
15
  export const listAppsCliLeaf = CliLeaf({
15
16
  name: 'list',
@@ -81,10 +82,9 @@ export const installAppCliLeaf = CliLeaf({
81
82
  envVars
82
83
  }
83
84
  };
84
- await deviceAgent.handleMessage(topic, message);
85
- while (deviceAgent.isCmdInProgress(project)) {
86
- await sleep(1000);
87
- }
85
+ await deviceAgent.waitForConnection();
86
+ await deviceAgent.sendCliCmd(topic, message);
87
+ await deviceAgent.waitForCmd(project);
88
88
  await deviceAgent.stop();
89
89
  }
90
90
  });
@@ -112,10 +112,9 @@ export const uninstallAppCliLeaf = CliLeaf({
112
112
  projectId: project
113
113
  }
114
114
  };
115
- await deviceAgent.handleMessage(topic, message);
116
- while (deviceAgent.isCmdInProgress(project)) {
117
- await sleep(1000);
118
- }
115
+ await deviceAgent.waitForConnection();
116
+ await deviceAgent.sendCliCmd(topic, message);
117
+ await deviceAgent.waitForCmd(project);
119
118
  await deviceAgent.stop();
120
119
  }
121
120
  });