@alwaysai/device-agent 1.4.0 → 2.0.0

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 (313) hide show
  1. package/lib/application-control/config.d.ts.map +1 -1
  2. package/lib/application-control/config.js +10 -5
  3. package/lib/application-control/config.js.map +1 -1
  4. package/lib/application-control/environment-variables.d.ts +1 -5
  5. package/lib/application-control/environment-variables.d.ts.map +1 -1
  6. package/lib/application-control/environment-variables.js +9 -26
  7. package/lib/application-control/environment-variables.js.map +1 -1
  8. package/lib/application-control/environment-variables.test.js +27 -7
  9. package/lib/application-control/environment-variables.test.js.map +1 -1
  10. package/lib/application-control/index.d.ts +4 -4
  11. package/lib/application-control/index.d.ts.map +1 -1
  12. package/lib/application-control/index.js +1 -4
  13. package/lib/application-control/index.js.map +1 -1
  14. package/lib/application-control/install.d.ts.map +1 -1
  15. package/lib/application-control/install.js +9 -7
  16. package/lib/application-control/install.js.map +1 -1
  17. package/lib/application-control/models.d.ts +5 -11
  18. package/lib/application-control/models.d.ts.map +1 -1
  19. package/lib/application-control/models.js +27 -64
  20. package/lib/application-control/models.js.map +1 -1
  21. package/lib/application-control/status.d.ts.map +1 -1
  22. package/lib/application-control/status.js +10 -12
  23. package/lib/application-control/status.js.map +1 -1
  24. package/lib/application-control/utils.d.ts +0 -4
  25. package/lib/application-control/utils.d.ts.map +1 -1
  26. package/lib/application-control/utils.js +3 -26
  27. package/lib/application-control/utils.js.map +1 -1
  28. package/lib/cloud-connection/bootstrap-provision.js +3 -2
  29. package/lib/cloud-connection/bootstrap-provision.js.map +1 -1
  30. package/lib/cloud-connection/device-agent-cloud-connection.d.ts +11 -16
  31. package/lib/cloud-connection/device-agent-cloud-connection.d.ts.map +1 -1
  32. package/lib/cloud-connection/device-agent-cloud-connection.js +295 -246
  33. package/lib/cloud-connection/device-agent-cloud-connection.js.map +1 -1
  34. package/lib/cloud-connection/device-agent.d.ts.map +1 -1
  35. package/lib/cloud-connection/device-agent.js +11 -9
  36. package/lib/cloud-connection/device-agent.js.map +1 -1
  37. package/lib/cloud-connection/live-updates-handler.d.ts +18 -27
  38. package/lib/cloud-connection/live-updates-handler.d.ts.map +1 -1
  39. package/lib/cloud-connection/live-updates-handler.js +58 -170
  40. package/lib/cloud-connection/live-updates-handler.js.map +1 -1
  41. package/lib/cloud-connection/live-updates-handler.test.js +76 -54
  42. package/lib/cloud-connection/live-updates-handler.test.js.map +1 -1
  43. package/lib/cloud-connection/passthrough-handler.d.ts +9 -4
  44. package/lib/cloud-connection/passthrough-handler.d.ts.map +1 -1
  45. package/lib/cloud-connection/passthrough-handler.js +95 -62
  46. package/lib/cloud-connection/passthrough-handler.js.map +1 -1
  47. package/lib/cloud-connection/shadow-handler.d.ts +5 -1
  48. package/lib/cloud-connection/shadow-handler.d.ts.map +1 -1
  49. package/lib/cloud-connection/shadow-handler.js +63 -31
  50. package/lib/cloud-connection/shadow-handler.js.map +1 -1
  51. package/lib/cloud-connection/shadow-handler.test.js +45 -57
  52. package/lib/cloud-connection/shadow-handler.test.js.map +1 -1
  53. package/lib/cloud-connection/shadow.d.ts.map +1 -1
  54. package/lib/cloud-connection/shadow.js +2 -1
  55. package/lib/cloud-connection/shadow.js.map +1 -1
  56. package/lib/cloud-connection/transaction-manager.d.ts +7 -2
  57. package/lib/cloud-connection/transaction-manager.d.ts.map +1 -1
  58. package/lib/cloud-connection/transaction-manager.js +29 -29
  59. package/lib/cloud-connection/transaction-manager.js.map +1 -1
  60. package/lib/cloud-connection/transaction-manager.test.js +105 -3
  61. package/lib/cloud-connection/transaction-manager.test.js.map +1 -1
  62. package/lib/device-control/device-control.d.ts +14 -6
  63. package/lib/device-control/device-control.d.ts.map +1 -1
  64. package/lib/device-control/device-control.js +172 -72
  65. package/lib/device-control/device-control.js.map +1 -1
  66. package/lib/docker/docker-compose.d.ts +14 -0
  67. package/lib/docker/docker-compose.d.ts.map +1 -0
  68. package/lib/docker/docker-compose.js +57 -0
  69. package/lib/docker/docker-compose.js.map +1 -0
  70. package/lib/index.js +2 -5
  71. package/lib/index.js.map +1 -1
  72. package/lib/infrastructure/agent-config.d.ts +46 -14
  73. package/lib/infrastructure/agent-config.d.ts.map +1 -1
  74. package/lib/infrastructure/agent-config.js +36 -21
  75. package/lib/infrastructure/agent-config.js.map +1 -1
  76. package/lib/infrastructure/agent-config.test.js +6 -1
  77. package/lib/infrastructure/agent-config.test.js.map +1 -1
  78. package/lib/infrastructure/config-check-utility.d.ts +6 -0
  79. package/lib/infrastructure/config-check-utility.d.ts.map +1 -0
  80. package/lib/infrastructure/config-check-utility.js +67 -0
  81. package/lib/infrastructure/config-check-utility.js.map +1 -0
  82. package/lib/infrastructure/config-check-utility.test.d.ts +2 -0
  83. package/lib/infrastructure/config-check-utility.test.d.ts.map +1 -0
  84. package/lib/infrastructure/config-check-utility.test.js +109 -0
  85. package/lib/infrastructure/config-check-utility.test.js.map +1 -0
  86. package/lib/infrastructure/device-certificate.d.ts +10 -0
  87. package/lib/infrastructure/device-certificate.d.ts.map +1 -0
  88. package/lib/infrastructure/device-certificate.js +47 -0
  89. package/lib/infrastructure/device-certificate.js.map +1 -0
  90. package/lib/infrastructure/device-certificate.test.d.ts +2 -0
  91. package/lib/infrastructure/device-certificate.test.d.ts.map +1 -0
  92. package/lib/infrastructure/device-certificate.test.js +24 -0
  93. package/lib/infrastructure/device-certificate.test.js.map +1 -0
  94. package/lib/infrastructure/legacy-migration/legacy-file.test.d.ts +2 -0
  95. package/lib/infrastructure/legacy-migration/legacy-file.test.d.ts.map +1 -0
  96. package/lib/infrastructure/legacy-migration/legacy-file.test.js +61 -0
  97. package/lib/infrastructure/legacy-migration/legacy-file.test.js.map +1 -0
  98. package/lib/infrastructure/legacy-migration/legacy-files.d.ts +75 -0
  99. package/lib/infrastructure/legacy-migration/legacy-files.d.ts.map +1 -0
  100. package/lib/infrastructure/legacy-migration/legacy-files.js +75 -0
  101. package/lib/infrastructure/legacy-migration/legacy-files.js.map +1 -0
  102. package/lib/infrastructure/legacy-migration/legacy-migration.d.ts +6 -0
  103. package/lib/infrastructure/legacy-migration/legacy-migration.d.ts.map +1 -0
  104. package/lib/infrastructure/legacy-migration/legacy-migration.js +149 -0
  105. package/lib/infrastructure/legacy-migration/legacy-migration.js.map +1 -0
  106. package/lib/infrastructure/legacy-migration/legacy-migration.test.d.ts +2 -0
  107. package/lib/infrastructure/legacy-migration/legacy-migration.test.d.ts.map +1 -0
  108. package/lib/infrastructure/legacy-migration/legacy-migration.test.js +226 -0
  109. package/lib/infrastructure/legacy-migration/legacy-migration.test.js.map +1 -0
  110. package/lib/infrastructure/require-files-present-ready.test.d.ts +2 -0
  111. package/lib/infrastructure/require-files-present-ready.test.d.ts.map +1 -0
  112. package/lib/infrastructure/require-files-present-ready.test.js +44 -0
  113. package/lib/infrastructure/require-files-present-ready.test.js.map +1 -0
  114. package/lib/infrastructure/required-config-checks.d.ts +2 -0
  115. package/lib/infrastructure/required-config-checks.d.ts.map +1 -0
  116. package/lib/infrastructure/required-config-checks.js +30 -0
  117. package/lib/infrastructure/required-config-checks.js.map +1 -0
  118. package/lib/infrastructure/tokens-and-device-cfg.d.ts.map +1 -1
  119. package/lib/infrastructure/tokens-and-device-cfg.js +11 -8
  120. package/lib/infrastructure/tokens-and-device-cfg.js.map +1 -1
  121. package/lib/local-connection/rabbitmq-connection.d.ts.map +1 -1
  122. package/lib/local-connection/rabbitmq-connection.js +21 -21
  123. package/lib/local-connection/rabbitmq-connection.js.map +1 -1
  124. package/lib/secure-tunneling/secure-tunneling.d.ts +15 -23
  125. package/lib/secure-tunneling/secure-tunneling.d.ts.map +1 -1
  126. package/lib/secure-tunneling/secure-tunneling.js +52 -47
  127. package/lib/secure-tunneling/secure-tunneling.js.map +1 -1
  128. package/lib/secure-tunneling/secure-tunneling.test.js +29 -31
  129. package/lib/secure-tunneling/secure-tunneling.test.js.map +1 -1
  130. package/lib/subcommands/app/analytics.d.ts.map +1 -1
  131. package/lib/subcommands/app/analytics.js +1 -2
  132. package/lib/subcommands/app/analytics.js.map +1 -1
  133. package/lib/subcommands/app/env-vars.d.ts +4 -0
  134. package/lib/subcommands/app/env-vars.d.ts.map +1 -1
  135. package/lib/subcommands/app/env-vars.js +52 -6
  136. package/lib/subcommands/app/env-vars.js.map +1 -1
  137. package/lib/subcommands/app/index.d.ts.map +1 -1
  138. package/lib/subcommands/app/index.js +1 -3
  139. package/lib/subcommands/app/index.js.map +1 -1
  140. package/lib/subcommands/app/models.d.ts +0 -11
  141. package/lib/subcommands/app/models.d.ts.map +1 -1
  142. package/lib/subcommands/app/models.js +2 -58
  143. package/lib/subcommands/app/models.js.map +1 -1
  144. package/lib/subcommands/app/shadow.d.ts.map +1 -1
  145. package/lib/subcommands/app/shadow.js +6 -5
  146. package/lib/subcommands/app/shadow.js.map +1 -1
  147. package/lib/subcommands/app/version.d.ts.map +1 -1
  148. package/lib/subcommands/app/version.js +2 -4
  149. package/lib/subcommands/app/version.js.map +1 -1
  150. package/lib/subcommands/config.d.ts +2 -0
  151. package/lib/subcommands/config.d.ts.map +1 -0
  152. package/lib/subcommands/config.js +39 -0
  153. package/lib/subcommands/config.js.map +1 -0
  154. package/lib/subcommands/device/clean.d.ts +1 -1
  155. package/lib/subcommands/device/clean.d.ts.map +1 -1
  156. package/lib/subcommands/device/clean.js +25 -15
  157. package/lib/subcommands/device/clean.js.map +1 -1
  158. package/lib/subcommands/device/get-info.d.ts +2 -0
  159. package/lib/subcommands/device/get-info.d.ts.map +1 -0
  160. package/lib/subcommands/device/get-info.js +36 -0
  161. package/lib/subcommands/device/get-info.js.map +1 -0
  162. package/lib/subcommands/device/index.d.ts.map +1 -1
  163. package/lib/subcommands/device/index.js +13 -2
  164. package/lib/subcommands/device/index.js.map +1 -1
  165. package/lib/subcommands/device/init.d.ts +5 -0
  166. package/lib/subcommands/device/init.d.ts.map +1 -0
  167. package/lib/subcommands/device/{device.js → init.js} +10 -49
  168. package/lib/subcommands/device/init.js.map +1 -0
  169. package/lib/subcommands/device/migrate.d.ts +2 -0
  170. package/lib/subcommands/device/migrate.d.ts.map +1 -0
  171. package/lib/subcommands/device/migrate.js +24 -0
  172. package/lib/subcommands/device/migrate.js.map +1 -0
  173. package/lib/subcommands/device/refresh.d.ts +2 -0
  174. package/lib/subcommands/device/refresh.d.ts.map +1 -0
  175. package/lib/subcommands/device/refresh.js +25 -0
  176. package/lib/subcommands/device/refresh.js.map +1 -0
  177. package/lib/subcommands/device/restart.d.ts +2 -0
  178. package/lib/subcommands/device/restart.d.ts.map +1 -0
  179. package/lib/subcommands/device/restart.js +14 -0
  180. package/lib/subcommands/device/restart.js.map +1 -0
  181. package/lib/subcommands/index.d.ts +1 -1
  182. package/lib/subcommands/index.d.ts.map +1 -1
  183. package/lib/subcommands/index.js +3 -1
  184. package/lib/subcommands/index.js.map +1 -1
  185. package/lib/subcommands/rabbitmq-connection.d.ts +1 -1
  186. package/lib/subcommands/rabbitmq-connection.d.ts.map +1 -1
  187. package/lib/util/aai-error.d.ts +12 -0
  188. package/lib/util/aai-error.d.ts.map +1 -0
  189. package/lib/util/aai-error.js +11 -0
  190. package/lib/util/aai-error.js.map +1 -0
  191. package/lib/util/aws-regions.d.ts +2 -0
  192. package/lib/util/aws-regions.d.ts.map +1 -0
  193. package/lib/util/{cloud-mode-ready.js → aws-regions.js} +2 -20
  194. package/lib/util/aws-regions.js.map +1 -0
  195. package/lib/util/check-for-updates.d.ts +3 -0
  196. package/lib/util/check-for-updates.d.ts.map +1 -0
  197. package/lib/util/check-for-updates.js +46 -0
  198. package/lib/util/check-for-updates.js.map +1 -0
  199. package/lib/util/clean-certs.d.ts.map +1 -1
  200. package/lib/util/clean-certs.js +5 -4
  201. package/lib/util/clean-certs.js.map +1 -1
  202. package/lib/util/directories.d.ts +4 -18
  203. package/lib/util/directories.d.ts.map +1 -1
  204. package/lib/util/directories.js +18 -32
  205. package/lib/util/directories.js.map +1 -1
  206. package/lib/util/file.d.ts +11 -0
  207. package/lib/util/file.d.ts.map +1 -0
  208. package/lib/util/file.js +127 -0
  209. package/lib/util/file.js.map +1 -0
  210. package/lib/util/file.test.d.ts +2 -0
  211. package/lib/util/file.test.d.ts.map +1 -0
  212. package/lib/util/file.test.js +87 -0
  213. package/lib/util/file.test.js.map +1 -0
  214. package/lib/util/get-device-id.d.ts.map +1 -1
  215. package/lib/util/get-device-id.js +7 -1
  216. package/lib/util/get-device-id.js.map +1 -1
  217. package/lib/util/http-client.js +3 -3
  218. package/lib/util/http-client.js.map +1 -1
  219. package/package.json +22 -19
  220. package/readme.md +15 -35
  221. package/src/application-control/config.ts +10 -13
  222. package/src/application-control/environment-variables.test.ts +28 -7
  223. package/src/application-control/environment-variables.ts +13 -40
  224. package/src/application-control/index.ts +3 -16
  225. package/src/application-control/install.ts +16 -10
  226. package/src/application-control/models.ts +40 -98
  227. package/src/application-control/status.ts +9 -7
  228. package/src/application-control/utils.ts +1 -29
  229. package/src/cloud-connection/bootstrap-provision.ts +7 -7
  230. package/src/cloud-connection/device-agent-cloud-connection.ts +647 -509
  231. package/src/cloud-connection/device-agent.ts +16 -7
  232. package/src/cloud-connection/live-updates-handler.test.ts +137 -64
  233. package/src/cloud-connection/live-updates-handler.ts +103 -234
  234. package/src/cloud-connection/passthrough-handler.ts +134 -75
  235. package/src/cloud-connection/shadow-handler.test.ts +45 -57
  236. package/src/cloud-connection/shadow-handler.ts +114 -56
  237. package/src/cloud-connection/shadow.ts +4 -1
  238. package/src/cloud-connection/transaction-manager.test.ts +127 -3
  239. package/src/cloud-connection/transaction-manager.ts +68 -39
  240. package/src/device-control/device-control.ts +179 -72
  241. package/src/docker/docker-compose.ts +61 -0
  242. package/src/index.ts +2 -6
  243. package/src/infrastructure/agent-config.test.ts +9 -2
  244. package/src/infrastructure/agent-config.ts +45 -46
  245. package/src/infrastructure/config-check-utility.test.ts +154 -0
  246. package/src/infrastructure/config-check-utility.ts +77 -0
  247. package/src/infrastructure/device-certificate.test.ts +40 -0
  248. package/src/infrastructure/device-certificate.ts +58 -0
  249. package/src/infrastructure/legacy-migration/legacy-file.test.ts +88 -0
  250. package/src/infrastructure/legacy-migration/legacy-files.ts +101 -0
  251. package/src/infrastructure/legacy-migration/legacy-migration.test.ts +396 -0
  252. package/src/infrastructure/legacy-migration/legacy-migration.ts +229 -0
  253. package/src/infrastructure/require-files-present-ready.test.ts +53 -0
  254. package/src/infrastructure/required-config-checks.ts +33 -0
  255. package/src/infrastructure/tokens-and-device-cfg.ts +12 -10
  256. package/src/local-connection/rabbitmq-connection.ts +28 -23
  257. package/src/secure-tunneling/secure-tunneling.test.ts +37 -39
  258. package/src/secure-tunneling/secure-tunneling.ts +74 -69
  259. package/src/subcommands/app/analytics.ts +2 -4
  260. package/src/subcommands/app/env-vars.ts +72 -9
  261. package/src/subcommands/app/index.ts +3 -11
  262. package/src/subcommands/app/models.ts +5 -81
  263. package/src/subcommands/app/shadow.ts +6 -5
  264. package/src/subcommands/app/version.ts +3 -4
  265. package/src/subcommands/config.ts +42 -0
  266. package/src/subcommands/device/clean.ts +32 -18
  267. package/src/subcommands/device/get-info.ts +49 -0
  268. package/src/subcommands/device/index.ts +13 -2
  269. package/src/subcommands/device/{device.ts → init.ts} +11 -69
  270. package/src/subcommands/device/migrate.ts +20 -0
  271. package/src/subcommands/device/refresh.ts +23 -0
  272. package/src/subcommands/device/restart.ts +11 -0
  273. package/src/subcommands/index.ts +3 -1
  274. package/src/util/aai-error.ts +20 -0
  275. package/src/util/{cloud-mode-ready.ts → aws-regions.ts} +0 -24
  276. package/src/util/check-for-updates.ts +53 -0
  277. package/src/util/clean-certs.ts +8 -4
  278. package/src/util/directories.ts +23 -67
  279. package/src/util/file.test.ts +90 -0
  280. package/src/util/file.ts +156 -0
  281. package/src/util/get-device-id.ts +7 -7
  282. package/src/util/http-client.ts +2 -2
  283. package/lib/docker/docker-compose-cmd.d.ts +0 -5
  284. package/lib/docker/docker-compose-cmd.d.ts.map +0 -1
  285. package/lib/docker/docker-compose-cmd.js +0 -16
  286. package/lib/docker/docker-compose-cmd.js.map +0 -1
  287. package/lib/subcommands/device/device.d.ts +0 -7
  288. package/lib/subcommands/device/device.d.ts.map +0 -1
  289. package/lib/subcommands/device/device.js.map +0 -1
  290. package/lib/util/cloud-mode-ready.d.ts +0 -3
  291. package/lib/util/cloud-mode-ready.d.ts.map +0 -1
  292. package/lib/util/cloud-mode-ready.js.map +0 -1
  293. package/lib/util/download-file.d.ts +0 -6
  294. package/lib/util/download-file.d.ts.map +0 -1
  295. package/lib/util/download-file.js +0 -25
  296. package/lib/util/download-file.js.map +0 -1
  297. package/lib/util/fetch-with-timeout.d.ts +0 -4
  298. package/lib/util/fetch-with-timeout.d.ts.map +0 -1
  299. package/lib/util/fetch-with-timeout.js +0 -30
  300. package/lib/util/fetch-with-timeout.js.map +0 -1
  301. package/lib/util/parsing.d.ts +0 -2
  302. package/lib/util/parsing.d.ts.map +0 -1
  303. package/lib/util/parsing.js +0 -17
  304. package/lib/util/parsing.js.map +0 -1
  305. package/lib/util/safe-rimraf.d.ts +0 -2
  306. package/lib/util/safe-rimraf.d.ts.map +0 -1
  307. package/lib/util/safe-rimraf.js +0 -16
  308. package/lib/util/safe-rimraf.js.map +0 -1
  309. package/src/docker/docker-compose-cmd.ts +0 -15
  310. package/src/util/download-file.ts +0 -25
  311. package/src/util/fetch-with-timeout.ts +0 -35
  312. package/src/util/parsing.ts +0 -11
  313. package/src/util/safe-rimraf.ts +0 -14
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.restartCliLeaf = void 0;
4
+ const alwayscli_1 = require("@alwaysai/alwayscli");
5
+ const device_control_1 = require("../../device-control/device-control");
6
+ exports.restartCliLeaf = (0, alwayscli_1.CliLeaf)({
7
+ name: 'restart',
8
+ description: 'Restart the device',
9
+ namedInputs: {},
10
+ async action(_, opts) {
11
+ await (0, device_control_1.reboot)();
12
+ }
13
+ });
14
+ //# sourceMappingURL=restart.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"restart.js","sourceRoot":"","sources":["../../../src/subcommands/device/restart.ts"],"names":[],"mappings":";;;AAAA,mDAA8C;AAC9C,wEAA6D;AAEhD,QAAA,cAAc,GAAG,IAAA,mBAAO,EAAC;IACpC,IAAI,EAAE,SAAS;IACf,WAAW,EAAE,oBAAoB;IACjC,WAAW,EAAE,EAAE;IACf,KAAK,CAAC,MAAM,CAAC,CAAC,EAAE,IAAI;QAClB,MAAM,IAAA,uBAAM,GAAE,CAAC;IACjB,CAAC;CACF,CAAC,CAAC"}
@@ -1,4 +1,4 @@
1
- export declare const subcommands: (import("@alwaysai/alwayscli/lib/types").CliBranch | import("@alwaysai/alwayscli/lib/types").CliLeaf<import("@alwaysai/alwayscli").CliInput<undefined, false>, {}, import("@alwaysai/alwayscli").CliInput<undefined, false>> | import("@alwaysai/alwayscli/lib/types").CliLeaf<import("@alwaysai/alwayscli").CliInput<string, true>, {
1
+ export declare const subcommands: (import("@alwaysai/alwayscli/lib/types").CliBranch | import("@alwaysai/alwayscli/lib/types").CliLeaf<import("@alwaysai/alwayscli").CliInput<undefined, false>, import("@alwaysai/alwayscli/lib/types").AnyNamedInputs, import("@alwaysai/alwayscli").CliInput<undefined, false>> | import("@alwaysai/alwayscli/lib/types").CliLeaf<import("@alwaysai/alwayscli").CliInput<string, true>, {
2
2
  version: import("@alwaysai/alwayscli").CliInput<number | undefined, boolean>;
3
3
  path: import("@alwaysai/alwayscli").CliInput<string | undefined, false>;
4
4
  }, import("@alwaysai/alwayscli").CliInput<undefined, false>>)[];
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/subcommands/index.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,WAAW;;;+DAMvB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/subcommands/index.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,WAAW;;;+DAOvB,CAAC"}
@@ -2,12 +2,14 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.subcommands = void 0;
4
4
  const app_1 = require("./app");
5
+ const config_1 = require("./config");
5
6
  const device_1 = require("./device");
6
- const login_1 = require("./login");
7
7
  const get_model_package_1 = require("./get-model-package");
8
+ const login_1 = require("./login");
8
9
  const rabbitmq_connection_1 = require("./rabbitmq-connection");
9
10
  exports.subcommands = [
10
11
  login_1.loginCliLeaf,
12
+ config_1.configBranch,
11
13
  app_1.appCliBranch,
12
14
  device_1.deviceCliBranch,
13
15
  get_model_package_1.getModelPackageCliLeaf,
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/subcommands/index.ts"],"names":[],"mappings":";;;AAAA,+BAAqC;AACrC,qCAA2C;AAC3C,mCAAuC;AACvC,2DAA6D;AAC7D,+DAAqE;AAExD,QAAA,WAAW,GAAG;IACzB,oBAAY;IACZ,kBAAY;IACZ,wBAAe;IACf,0CAAsB;IACtB,kDAA4B;CAC7B,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/subcommands/index.ts"],"names":[],"mappings":";;;AAAA,+BAAqC;AACrC,qCAAwC;AACxC,qCAA2C;AAC3C,2DAA6D;AAC7D,mCAAuC;AACvC,+DAAqE;AAExD,QAAA,WAAW,GAAG;IACzB,oBAAY;IACZ,qBAAY;IACZ,kBAAY;IACZ,wBAAe;IACf,0CAAsB;IACtB,kDAA4B;CAC7B,CAAC"}
@@ -1,2 +1,2 @@
1
- export declare const stopRabbitMQContainerCliLeaf: import("@alwaysai/alwayscli/lib/types").CliLeaf<import("@alwaysai/alwayscli").CliInput<undefined, false>, {}, import("@alwaysai/alwayscli").CliInput<undefined, false>>;
1
+ export declare const stopRabbitMQContainerCliLeaf: import("@alwaysai/alwayscli/lib/types").CliLeaf<import("@alwaysai/alwayscli").CliInput<undefined, false>, import("@alwaysai/alwayscli/lib/types").AnyNamedInputs, import("@alwaysai/alwayscli").CliInput<undefined, false>>;
2
2
  //# sourceMappingURL=rabbitmq-connection.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"rabbitmq-connection.d.ts","sourceRoot":"","sources":["../../src/subcommands/rabbitmq-connection.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,4BAA4B,yKAOvC,CAAC"}
1
+ {"version":3,"file":"rabbitmq-connection.d.ts","sourceRoot":"","sources":["../../src/subcommands/rabbitmq-connection.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,4BAA4B,6NAOvC,CAAC"}
@@ -0,0 +1,12 @@
1
+ import { ErrorObject } from 'ajv';
2
+ declare type ErrorOption = ErrorObject<string, Record<string, any>, unknown>;
3
+ declare type Details = ErrorOption | ErrorOption[] | Error | null;
4
+ interface Options {
5
+ cause?: Details;
6
+ }
7
+ declare class AaiError extends Error {
8
+ detailed?: Details;
9
+ constructor(message: string, options?: Options);
10
+ }
11
+ export default AaiError;
12
+ //# sourceMappingURL=aai-error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"aai-error.d.ts","sourceRoot":"","sources":["../../src/util/aai-error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,KAAK,CAAC;AAElC,aAAK,WAAW,GAAG,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,OAAO,CAAC,CAAC;AAErE,aAAK,OAAO,GAAG,WAAW,GAAG,WAAW,EAAE,GAAG,KAAK,GAAG,IAAI,CAAC;AAE1D,UAAU,OAAO;IACf,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED,cAAM,QAAS,SAAQ,KAAK;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;gBACd,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO;CAK/C;AAED,eAAe,QAAQ,CAAC"}
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ class AaiError extends Error {
4
+ constructor(message, options) {
5
+ super(message);
6
+ this.name = 'AaiError';
7
+ this.detailed = options === null || options === void 0 ? void 0 : options.cause;
8
+ }
9
+ }
10
+ exports.default = AaiError;
11
+ //# sourceMappingURL=aai-error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"aai-error.js","sourceRoot":"","sources":["../../src/util/aai-error.ts"],"names":[],"mappings":";;AAUA,MAAM,QAAS,SAAQ,KAAK;IAE1B,YAAY,OAAe,EAAE,OAAiB;QAC5C,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,UAAU,CAAC;QACvB,IAAI,CAAC,QAAQ,GAAG,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,KAAK,CAAC;IACjC,CAAC;CACF;AAED,kBAAe,QAAQ,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare function isValidAwsRegion(region: string): boolean;
2
+ //# sourceMappingURL=aws-regions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"aws-regions.d.ts","sourceRoot":"","sources":["../../src/util/aws-regions.ts"],"names":[],"mappings":"AAgCA,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAExD"}
@@ -1,8 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.cloudModeReady = exports.isValidAwsRegion = void 0;
4
- const fs_1 = require("fs");
5
- const directories_1 = require("../util/directories");
3
+ exports.isValidAwsRegion = void 0;
6
4
  const VALID_AWS_REGIONS = [
7
5
  // 'af-south-1', // Africa (Cape Town)
8
6
  // 'ap-east-1', // Asia Pacific (Hong Kong)
@@ -38,20 +36,4 @@ function isValidAwsRegion(region) {
38
36
  return VALID_AWS_REGIONS.includes(region);
39
37
  }
40
38
  exports.isValidAwsRegion = isValidAwsRegion;
41
- function cloudModeReady() {
42
- let ready = true;
43
- const requiredFiles = [
44
- directories_1.DEVICE_CERTIFICATE_FILE_PATH,
45
- directories_1.DEVICE_PRIVATE_KEY_FILE_PATH,
46
- directories_1.AWS_ROOT_CERTIFICATE_FILE_PATH
47
- ];
48
- for (const path of requiredFiles) {
49
- if (!(0, fs_1.existsSync)(path)) {
50
- ready = false;
51
- break;
52
- }
53
- }
54
- return ready;
55
- }
56
- exports.cloudModeReady = cloudModeReady;
57
- //# sourceMappingURL=cloud-mode-ready.js.map
39
+ //# sourceMappingURL=aws-regions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"aws-regions.js","sourceRoot":"","sources":["../../src/util/aws-regions.ts"],"names":[],"mappings":";;;AAAA,MAAM,iBAAiB,GAAG;IACxB,sCAAsC;IACtC,2CAA2C;IAC3C,4CAA4C;IAC5C,4CAA4C;IAC5C,4CAA4C;IAC5C,4CAA4C;IAC5C,yCAAyC;IACzC,gDAAgD;IAChD,6CAA6C;IAC7C,8CAA8C;IAC9C,gDAAgD;IAChD,sCAAsC;IACtC,wCAAwC;IACxC,kCAAkC;IAClC,iCAAiC;IACjC,wCAAwC;IACxC,qCAAqC;IACrC,sCAAsC;IACtC,kCAAkC;IAClC,kCAAkC;IAClC,mCAAmC;IACnC,uCAAuC;IACvC,yCAAyC;IACzC,uCAAuC;IACvC,2CAA2C;IAC3C,iCAAiC;IACjC,qCAAqC;IACrC,0CAA0C;IAC1C,WAAW,CAAC,mBAAmB;CAChC,CAAC;AAEF,SAAgB,gBAAgB,CAAC,MAAc;IAC7C,OAAO,iBAAiB,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;AAC5C,CAAC;AAFD,4CAEC"}
@@ -0,0 +1,3 @@
1
+ export declare function getDeviceAgentVersion(): Promise<string>;
2
+ export declare function checkForUpdatesAndPrompt(): Promise<void>;
3
+ //# sourceMappingURL=check-for-updates.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"check-for-updates.d.ts","sourceRoot":"","sources":["../../src/util/check-for-updates.ts"],"names":[],"mappings":"AAYA,wBAAsB,qBAAqB,IAAI,OAAO,CAAC,MAAM,CAAC,CAc7D;AAQD,wBAAsB,wBAAwB,kBAkB7C"}
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.checkForUpdatesAndPrompt = exports.getDeviceAgentVersion = void 0;
4
+ const logger_1 = require("../util/logger");
5
+ const util_1 = require("alwaysai/lib/util");
6
+ const path = require("path");
7
+ const appPrompt = 'Please restart the Device Agent or reboot the device to update. ';
8
+ const updatePrompt = `A new version of the Device Agent is available! \n\n`;
9
+ async function getDeviceAgentVersion() {
10
+ let daVersion = '';
11
+ try {
12
+ const packagePath = path.join(__dirname, '../../');
13
+ const spawner = (0, util_1.JsSpawner)({ path: packagePath });
14
+ const output = await spawner.readFile('package.json');
15
+ const parsed = JSON.parse(output);
16
+ daVersion = parsed.version;
17
+ }
18
+ catch (e) {
19
+ logger_1.logger.error(`Could not retrieve the Device Agent version!\n${(0, util_1.stringifyError)(e)}`);
20
+ }
21
+ return daVersion;
22
+ }
23
+ exports.getDeviceAgentVersion = getDeviceAgentVersion;
24
+ function constructPrompt(props) {
25
+ const { currentVer, latestVer } = props;
26
+ const prompt = `${updatePrompt}${appPrompt}\nYour version: ${currentVer}. Newest version: ${latestVer}`;
27
+ return prompt;
28
+ }
29
+ async function checkForUpdatesAndPrompt() {
30
+ try {
31
+ logger_1.logger.debug('Checking for available Device Agent updates...');
32
+ const latestVersion = await (0, util_1.getLatestVersionFromNpm)('@alwaysai/device-agent');
33
+ const version = await getDeviceAgentVersion();
34
+ if (version !== latestVersion) {
35
+ logger_1.logger.warn(constructPrompt({
36
+ currentVer: version,
37
+ latestVer: latestVersion
38
+ }));
39
+ }
40
+ }
41
+ catch (e) {
42
+ logger_1.logger.error(`Could not check for updates!\n${(0, util_1.stringifyError)(e)}`);
43
+ }
44
+ }
45
+ exports.checkForUpdatesAndPrompt = checkForUpdatesAndPrompt;
46
+ //# sourceMappingURL=check-for-updates.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"check-for-updates.js","sourceRoot":"","sources":["../../src/util/check-for-updates.ts"],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gBACd,UAAU,EAAE,OAAO;gBACnB,SAAS,EAAE,aAAa;aACzB,CAAC,CACH,CAAC;SACH;KACF;IAAC,OAAO,CAAC,EAAE;QACV,eAAM,CAAC,KAAK,CAAC,iCAAiC,IAAA,qBAAc,EAAC,CAAC,CAAC,EAAE,CAAC,CAAC;KACpE;AACH,CAAC;AAlBD,4DAkBC"}
@@ -1 +1 @@
1
- {"version":3,"file":"clean-certs.d.ts","sourceRoot":"","sources":["../../src/util/clean-certs.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,wBAAwB,sBAMpC,CAAC"}
1
+ {"version":3,"file":"clean-certs.d.ts","sourceRoot":"","sources":["../../src/util/clean-certs.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,wBAAwB,sBAOpC,CAAC"}
@@ -1,14 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.rmBootstrapCertsAndClose = void 0;
4
+ const infrastructure_1 = require("alwaysai/lib/infrastructure");
4
5
  const util_1 = require("alwaysai/lib/util");
6
+ const device_certificate_1 = require("../infrastructure/device-certificate");
5
7
  const logger_1 = require("../util/logger");
6
- const paths_1 = require("alwaysai/lib/paths");
7
- const directories_1 = require("../util/directories");
8
8
  const rmBootstrapCertsAndClose = async () => {
9
+ const deviceCertificates = new infrastructure_1.LocalDeviceCertificates();
9
10
  const spawner = (0, util_1.JsSpawner)();
10
- await spawner.rimraf((0, directories_1.BOOTSTRAP_CERTIFICATES_DIR_PATH)());
11
- await spawner.rimraf(paths_1.LOCAL_CERT_AND_KEY_DIR);
11
+ await spawner.rimraf((0, device_certificate_1.getBootstrapCertificateDirectoryPath)());
12
+ await spawner.rimraf(deviceCertificates.getCertificateDirectoryPath());
12
13
  logger_1.logger.error('Could not provision device. Try again.');
13
14
  process.exit(1);
14
15
  };
@@ -1 +1 @@
1
- {"version":3,"file":"clean-certs.js","sourceRoot":"","sources":["../../src/util/clean-certs.ts"],"names":[],"mappings":";;;AAAA,4CAA8C;AAC9C,2CAAwC;AACxC,8CAA4D;AAC5D,qDAAsE;AAE/D,MAAM,wBAAwB,GAAG,KAAK,IAAI,EAAE;IACjD,MAAM,OAAO,GAAG,IAAA,gBAAS,GAAE,CAAC;IAC5B,MAAM,OAAO,CAAC,MAAM,CAAC,IAAA,6CAA+B,GAAE,CAAC,CAAC;IACxD,MAAM,OAAO,CAAC,MAAM,CAAC,8BAAsB,CAAC,CAAC;IAC7C,eAAM,CAAC,KAAK,CAAC,wCAAwC,CAAC,CAAC;IACvD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC;AANW,QAAA,wBAAwB,4BAMnC"}
1
+ {"version":3,"file":"clean-certs.js","sourceRoot":"","sources":["../../src/util/clean-certs.ts"],"names":[],"mappings":";;;AAAA,gEAGqC;AACrC,4CAA8C;AAC9C,6EAA4F;AAC5F,2CAAwC;AAEjC,MAAM,wBAAwB,GAAG,KAAK,IAAI,EAAE;IACjD,MAAM,kBAAkB,GAAG,IAAI,wCAAuB,EAAE,CAAC;IACzD,MAAM,OAAO,GAAG,IAAA,gBAAS,GAAE,CAAC;IAC5B,MAAM,OAAO,CAAC,MAAM,CAAC,IAAA,yDAAoC,GAAE,CAAC,CAAC;IAC7D,MAAM,OAAO,CAAC,MAAM,CAAC,kBAAkB,CAAC,2BAA2B,EAAE,CAAC,CAAC;IACvE,eAAM,CAAC,KAAK,CAAC,wCAAwC,CAAC,CAAC;IACvD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC;AAPW,QAAA,wBAAwB,4BAOnC"}
@@ -1,25 +1,11 @@
1
1
  export declare const APP_ROOT: string;
2
2
  export declare const DEVICE_AGENT_CFG_DIR = "device-agent";
3
- export declare const DEVICE_AGENT_CFG_PATH: string;
4
- export declare const DEVICE_AGENT_DOCKER_COMPOSE_PATH: string;
3
+ export declare function getDeviceAgentConfigPath(baseDir?: any): string;
4
+ export declare function getDeviceAgentDockerComposePath(baseDir?: any): string;
5
5
  export declare const CREDENTIALS_FILE_PATH: string;
6
- export declare const AWS_ROOT_CERTIFICATE_FILE_NAME = "AmazonRootCA1.pem";
7
6
  export declare const AWS_ROOT_CERTIFICATE_FILE_PATH: string;
8
- export declare const shortenSystemId: () => "qa" | "dev" | "prod" | undefined;
9
- export declare const BOOTSTRAP_DIR_NAME = "bootstrap-certificates";
10
- export declare const BOOTSTRAP_PRIVATE_KEY_FILE_NAME: () => string;
11
- export declare const BOOTSTRAP_CERTIFICATE_FILE_NAME: () => string;
12
- export declare const BOOTSTRAP_ID_FILE_NAME: () => string;
13
- export declare const CERTIFICATE_OWNERSHIP_TOKEN_FILE_NAME = "certificate-ownership-token.txt";
14
- export declare const BOOTSTRAP_CERTIFICATES_DIR_PATH: () => string;
15
- export declare const BOOTSTRAP_PRIVATE_KEY_FILE_PATH: () => string;
16
- export declare const BOOTSTRAP_CERTIFICATE_FILE_PATH: () => string;
17
- export declare const BOOTSTRAP_ID_FILE_PATH: () => string;
18
- export declare const DEVICE_PRIVATE_KEY_FILE_NAME = "aai-device-private-key.pem.key";
19
- export declare const DEVICE_CERTIFICATE_FILE_NAME = "aai-device-cert.pem.crt";
20
- export declare const DEVICE_ID_FILE_NAME = "aai-device-cert-id.txt";
21
- export declare const DEVICE_PRIVATE_KEY_FILE_PATH: string;
22
- export declare const DEVICE_CERTIFICATE_FILE_PATH: string;
7
+ export declare const AWS_ROOT_CERTIFICATE_FILE_NAME: string;
8
+ export declare const shortenSystemId: () => "qa" | "dev" | "prod";
23
9
  export declare const SECURE_TUNNEL_BIN_NAME = "localproxy";
24
10
  export declare const SECURE_TUNNEL_BIN_DIR = "secure-tunnel";
25
11
  export declare const SECURE_TUNNEL_BIN_PATH: string;
@@ -1 +1 @@
1
- {"version":3,"file":"directories.d.ts","sourceRoot":"","sources":["../../src/util/directories.ts"],"names":[],"mappings":"AAUA,eAAO,MAAM,QAAQ,QAAgC,CAAC;AAEtD,eAAO,MAAM,oBAAo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;AAGF,eAAO,MAAM,8BAA8B,QACW,CAAC;AACvD,eAAO,MAAM,8BAA8B,QACW,CAAC;AAEvD,eAAO,MAAM,eAAe,6BAY3B,CAAC;AAKF,eAAO,MAAM,sBAAsB,eAAe,CAAC;AACnD,eAAO,MAAM,qBAAqB,kBAAkB,CAAC;AACrD,eAAO,MAAM,sBAAsB,QAIlC,CAAC"}
@@ -1,16 +1,27 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SECURE_TUNNEL_BIN_PATH = exports.SECURE_TUNNEL_BIN_DIR = exports.SECURE_TUNNEL_BIN_NAME = exports.DEVICE_CERTIFICATE_FILE_PATH = exports.DEVICE_PRIVATE_KEY_FILE_PATH = exports.DEVICE_ID_FILE_NAME = exports.DEVICE_CERTIFICATE_FILE_NAME = exports.DEVICE_PRIVATE_KEY_FILE_NAME = exports.BOOTSTRAP_ID_FILE_PATH = exports.BOOTSTRAP_CERTIFICATE_FILE_PATH = exports.BOOTSTRAP_PRIVATE_KEY_FILE_PATH = exports.BOOTSTRAP_CERTIFICATES_DIR_PATH = exports.CERTIFICATE_OWNERSHIP_TOKEN_FILE_NAME = exports.BOOTSTRAP_ID_FILE_NAME = exports.BOOTSTRAP_CERTIFICATE_FILE_NAME = exports.BOOTSTRAP_PRIVATE_KEY_FILE_NAME = exports.BOOTSTRAP_DIR_NAME = exports.shortenSystemId = exports.AWS_ROOT_CERTIFICATE_FILE_PATH = exports.AWS_ROOT_CERTIFICATE_FILE_NAME = exports.CREDENTIALS_FILE_PATH = exports.DEVICE_AGENT_DOCKER_COMPOSE_PATH = exports.DEVICE_AGENT_CFG_PATH = exports.DEVICE_AGENT_CFG_DIR = exports.APP_ROOT = void 0;
3
+ exports.SECURE_TUNNEL_BIN_PATH = exports.SECURE_TUNNEL_BIN_DIR = exports.SECURE_TUNNEL_BIN_NAME = exports.shortenSystemId = exports.AWS_ROOT_CERTIFICATE_FILE_NAME = exports.AWS_ROOT_CERTIFICATE_FILE_PATH = exports.CREDENTIALS_FILE_PATH = exports.getDeviceAgentDockerComposePath = exports.getDeviceAgentConfigPath = exports.DEVICE_AGENT_CFG_DIR = exports.APP_ROOT = void 0;
4
+ const infrastructure_1 = require("alwaysai/lib/infrastructure");
4
5
  const paths_1 = require("alwaysai/lib/paths");
5
6
  const path_1 = require("path");
6
7
  const system_id_1 = require("../infrastructure/system-id");
7
8
  exports.APP_ROOT = (0, path_1.join)(paths_1.AAI_DIR, 'applications');
8
9
  exports.DEVICE_AGENT_CFG_DIR = 'device-agent';
9
- exports.DEVICE_AGENT_CFG_PATH = (0, path_1.join)(paths_1.LOCAL_AAI_CFG_DIR, exports.DEVICE_AGENT_CFG_DIR);
10
- exports.DEVICE_AGENT_DOCKER_COMPOSE_PATH = (0, path_1.join)(exports.DEVICE_AGENT_CFG_PATH, paths_1.DOCKER_COMPOSE_FILE);
10
+ function getDeviceAgentConfigPath(baseDir) {
11
+ if (baseDir) {
12
+ return (0, path_1.join)(baseDir, (0, infrastructure_1.getDeviceConfigPath)(), exports.DEVICE_AGENT_CFG_DIR);
13
+ }
14
+ return (0, path_1.join)(paths_1.LOCAL_AAI_CFG_DIR, (0, infrastructure_1.getDeviceConfigPath)(), exports.DEVICE_AGENT_CFG_DIR);
15
+ }
16
+ exports.getDeviceAgentConfigPath = getDeviceAgentConfigPath;
17
+ function getDeviceAgentDockerComposePath(baseDir) {
18
+ return (0, path_1.join)(getDeviceAgentConfigPath(baseDir), paths_1.DOCKER_COMPOSE_FILE);
19
+ }
20
+ exports.getDeviceAgentDockerComposePath = getDeviceAgentDockerComposePath;
11
21
  exports.CREDENTIALS_FILE_PATH = (0, path_1.join)(paths_1.LOCAL_AAI_CFG_DIR, paths_1.DEVICE_TOKEN_FILE_NAME);
12
- exports.AWS_ROOT_CERTIFICATE_FILE_NAME = 'AmazonRootCA1.pem';
13
- exports.AWS_ROOT_CERTIFICATE_FILE_PATH = (0, path_1.join)(paths_1.LOCAL_CERT_AND_KEY_DIR, exports.AWS_ROOT_CERTIFICATE_FILE_NAME);
22
+ const localDeviceCertificates = new infrastructure_1.LocalDeviceCertificates();
23
+ exports.AWS_ROOT_CERTIFICATE_FILE_PATH = localDeviceCertificates.getRootCertificateFilePath();
24
+ exports.AWS_ROOT_CERTIFICATE_FILE_NAME = localDeviceCertificates.getRootCertificateFileName();
14
25
  const shortenSystemId = () => {
15
26
  const id = (0, system_id_1.getSystemId)();
16
27
  switch (id) {
@@ -20,36 +31,11 @@ const shortenSystemId = () => {
20
31
  return 'qa';
21
32
  case 'production':
22
33
  return 'prod';
34
+ default:
35
+ return 'prod';
23
36
  }
24
37
  };
25
38
  exports.shortenSystemId = shortenSystemId;
26
- /*===================================================================
27
- Bootstrap Certificates
28
- ===================================================================*/
29
- exports.BOOTSTRAP_DIR_NAME = 'bootstrap-certificates';
30
- const BOOTSTRAP_PRIVATE_KEY_FILE_NAME = () => `aai-claim-private-key_${(0, exports.shortenSystemId)()}.pem.key`;
31
- exports.BOOTSTRAP_PRIVATE_KEY_FILE_NAME = BOOTSTRAP_PRIVATE_KEY_FILE_NAME;
32
- const BOOTSTRAP_CERTIFICATE_FILE_NAME = () => `aai-claim-cert_${(0, exports.shortenSystemId)()}.pem.crt`;
33
- exports.BOOTSTRAP_CERTIFICATE_FILE_NAME = BOOTSTRAP_CERTIFICATE_FILE_NAME;
34
- const BOOTSTRAP_ID_FILE_NAME = () => `aai-claim-cert-id_${(0, exports.shortenSystemId)()}.txt`;
35
- exports.BOOTSTRAP_ID_FILE_NAME = BOOTSTRAP_ID_FILE_NAME;
36
- exports.CERTIFICATE_OWNERSHIP_TOKEN_FILE_NAME = 'certificate-ownership-token.txt';
37
- const BOOTSTRAP_CERTIFICATES_DIR_PATH = () => (0, path_1.join)(paths_1.LOCAL_CERT_AND_KEY_DIR, exports.BOOTSTRAP_DIR_NAME);
38
- exports.BOOTSTRAP_CERTIFICATES_DIR_PATH = BOOTSTRAP_CERTIFICATES_DIR_PATH;
39
- const BOOTSTRAP_PRIVATE_KEY_FILE_PATH = () => (0, path_1.join)(paths_1.LOCAL_CERT_AND_KEY_DIR, exports.BOOTSTRAP_DIR_NAME, (0, exports.BOOTSTRAP_PRIVATE_KEY_FILE_NAME)());
40
- exports.BOOTSTRAP_PRIVATE_KEY_FILE_PATH = BOOTSTRAP_PRIVATE_KEY_FILE_PATH;
41
- const BOOTSTRAP_CERTIFICATE_FILE_PATH = () => (0, path_1.join)(paths_1.LOCAL_CERT_AND_KEY_DIR, exports.BOOTSTRAP_DIR_NAME, (0, exports.BOOTSTRAP_CERTIFICATE_FILE_NAME)());
42
- exports.BOOTSTRAP_CERTIFICATE_FILE_PATH = BOOTSTRAP_CERTIFICATE_FILE_PATH;
43
- const BOOTSTRAP_ID_FILE_PATH = () => (0, path_1.join)(paths_1.LOCAL_CERT_AND_KEY_DIR, exports.BOOTSTRAP_DIR_NAME, (0, exports.BOOTSTRAP_ID_FILE_NAME)());
44
- exports.BOOTSTRAP_ID_FILE_PATH = BOOTSTRAP_ID_FILE_PATH;
45
- /*===================================================================
46
- Device Certificates
47
- ===================================================================*/
48
- exports.DEVICE_PRIVATE_KEY_FILE_NAME = 'aai-device-private-key.pem.key';
49
- exports.DEVICE_CERTIFICATE_FILE_NAME = 'aai-device-cert.pem.crt';
50
- exports.DEVICE_ID_FILE_NAME = 'aai-device-cert-id.txt';
51
- exports.DEVICE_PRIVATE_KEY_FILE_PATH = (0, path_1.join)(paths_1.LOCAL_CERT_AND_KEY_DIR, exports.DEVICE_PRIVATE_KEY_FILE_NAME);
52
- exports.DEVICE_CERTIFICATE_FILE_PATH = (0, path_1.join)(paths_1.LOCAL_CERT_AND_KEY_DIR, exports.DEVICE_CERTIFICATE_FILE_NAME);
53
39
  /*===================================================================
54
40
  Secure Tunnel bin directory
55
41
  ===================================================================*/
@@ -1 +1 @@
1
- {"version":3,"file":"directories.js","sourceRoot":"","sources":["../../src/util/directories.ts"],"names":[],"mappings":";;;AAAA,8CAM4B;AAC5B,+BAA4B;A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1
+ export declare function safeRimraf(path: string): Promise<void>;
2
+ export declare function pruneDir({ path, exclude, recurse }: {
3
+ path: string;
4
+ exclude?: string[];
5
+ recurse?: boolean;
6
+ }): Promise<boolean>;
7
+ export declare function downloadToFile({ path, url }: {
8
+ path: string;
9
+ url: string;
10
+ }): Promise<void>;
11
+ //# sourceMappingURL=file.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file.d.ts","sourceRoot":"","sources":["../../src/util/file.ts"],"names":[],"mappings":"AAOA,wBAAsB,UAAU,CAAC,IAAI,EAAE,MAAM,iBAU5C;AAED,wBAAsB,QAAQ,CAAC,EAC7B,IAAI,EACJ,OAAO,EACP,OAAO,EACR,EAAE;IACD,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,oBAkDA;AAED,wBAAsB,cAAc,CAAC,EACnC,IAAI,EACJ,GAAG,EACJ,EAAE;IACD,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;CACb,iBAsEA"}
@@ -0,0 +1,127 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.downloadToFile = exports.pruneDir = exports.safeRimraf = void 0;
4
+ const rimraf_1 = require("rimraf");
5
+ const logger_1 = require("../util/logger");
6
+ const promises_1 = require("fs/promises");
7
+ const path_1 = require("path");
8
+ const util_1 = require("alwaysai/lib/util");
9
+ const fs_1 = require("fs");
10
+ async function safeRimraf(path) {
11
+ logger_1.logger.debug(`Removing ${path}`);
12
+ try {
13
+ await (0, rimraf_1.rimraf)(path);
14
+ }
15
+ catch (e) {
16
+ logger_1.logger.error(`Failed to remove ${path}. Please manually delete the file or directory.`);
17
+ logger_1.logger.debug(`Error removing ${path}:\n${(0, util_1.stringifyError)(e)}`);
18
+ }
19
+ }
20
+ exports.safeRimraf = safeRimraf;
21
+ async function pruneDir({ path, exclude, recurse }) {
22
+ /**
23
+ * Deletes all files and directories in a given directory path, excluding specific paths.
24
+ * Will not delete top-level directory
25
+ * @param {string} path path of directory to prune.
26
+ * @param {string[]} exclude list of paths to exclude when pruning
27
+ * @param {boolean} recurse flag to prune recursively into directories
28
+ */
29
+ try {
30
+ const files = await (0, promises_1.readdir)(path);
31
+ let canPruneParent = true;
32
+ for (const file of files) {
33
+ const filePath = (0, path_1.join)(path, file);
34
+ const isExcluded = exclude === null || exclude === void 0 ? void 0 : exclude.some((excludePath) => filePath.endsWith(excludePath));
35
+ if (isExcluded) {
36
+ logger_1.logger.debug(`Excluding file ${filePath} during pruning.`);
37
+ canPruneParent = false;
38
+ continue;
39
+ }
40
+ const fileStats = await (0, promises_1.stat)(filePath);
41
+ if (fileStats.isDirectory()) {
42
+ if (recurse) {
43
+ const dirIsEmpty = await pruneDir({
44
+ path: filePath,
45
+ exclude,
46
+ recurse
47
+ });
48
+ if (dirIsEmpty) {
49
+ await (0, promises_1.rmdir)(filePath);
50
+ }
51
+ else {
52
+ canPruneParent = false;
53
+ }
54
+ }
55
+ }
56
+ else {
57
+ await (0, promises_1.unlink)(filePath);
58
+ }
59
+ }
60
+ return canPruneParent;
61
+ }
62
+ catch (e) {
63
+ logger_1.logger.error(`Error pruning directory ${path}!\n${(0, util_1.stringifyError)(e)}`);
64
+ return false;
65
+ }
66
+ }
67
+ exports.pruneDir = pruneDir;
68
+ async function downloadToFile({ path, url }) {
69
+ var _a;
70
+ const response = await fetch(url);
71
+ if (!response.ok) {
72
+ throw new Error(`Failed to fetch ${url}: ${response.statusText}`);
73
+ }
74
+ const contentLength = response.headers.get('content-length');
75
+ const reader = (_a = response.body) === null || _a === void 0 ? void 0 : _a.getReader();
76
+ if (reader) {
77
+ const chunks = [];
78
+ const totalSize = contentLength ? parseInt(contentLength) : undefined;
79
+ const PROGRESS_PERC_LOG_INCREMENT = 5;
80
+ const BYTE_DOWNLOAD_LOG_INCREMENT = 5000000;
81
+ const [baseUrl, urlParams] = url.split('?');
82
+ const urlForLog = `${baseUrl}${(urlParams === null || urlParams === void 0 ? void 0 : urlParams.length) ? `...(${urlParams.length} more characters)` : ''}`;
83
+ let totalDownloadedBytes = 0;
84
+ let downloadedSize = 0;
85
+ let totalProgressPerc = 0;
86
+ // eslint-disable-next-line
87
+ while (true) {
88
+ const { done, value } = await reader.read();
89
+ if (done) {
90
+ logger_1.logger.info(`Download complete - ${urlForLog}`);
91
+ break;
92
+ }
93
+ if (value) {
94
+ chunks.push(value);
95
+ downloadedSize += value.length;
96
+ if (totalSize) {
97
+ const progress = (downloadedSize / totalSize) * 100;
98
+ if (progress > totalProgressPerc + PROGRESS_PERC_LOG_INCREMENT) {
99
+ totalProgressPerc += PROGRESS_PERC_LOG_INCREMENT;
100
+ logger_1.logger.debug(`Download progress: ${progress.toFixed(2)}% - ${urlForLog}`);
101
+ }
102
+ }
103
+ else {
104
+ if (downloadedSize >
105
+ totalDownloadedBytes + BYTE_DOWNLOAD_LOG_INCREMENT) {
106
+ totalDownloadedBytes += BYTE_DOWNLOAD_LOG_INCREMENT;
107
+ logger_1.logger.debug(`Download progress: ${downloadedSize} total bytes - ${urlForLog}`);
108
+ }
109
+ }
110
+ }
111
+ }
112
+ logger_1.logger.debug(`Writing downloaded chunks to file ${path}`);
113
+ const combinedSize = chunks.reduce((acc, chunk) => acc + chunk.length, 0);
114
+ const combinedChunks = new Uint8Array(combinedSize);
115
+ let offset = 0;
116
+ for (const chunk of chunks) {
117
+ combinedChunks.set(chunk, offset);
118
+ offset += chunk.length;
119
+ }
120
+ (0, fs_1.writeFileSync)(path, combinedChunks);
121
+ }
122
+ else {
123
+ throw new Error('Unable to access response body when downloading file.');
124
+ }
125
+ }
126
+ exports.downloadToFile = downloadToFile;
127
+ //# sourceMappingURL=file.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file.js","sourceRoot":"","sources":["../../src/util/file.ts"],"names":[],"mappings":";;;AAAA,mCAAgC;AAChC,2CAAwC;AACxC,0CAA2D;AAC3D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CAAC,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE,CAAC,GAAG,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;QAC1E,MAAM,cAAc,GAAG,IAAI,UAAU,CAAC,YAAY,CAAC,CAAC;QAEpD,IAAI,MAAM,GAAG,CAAC,CAAC;QACf,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE;YAC1B,cAAc,CAAC,GAAG,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;YAClC,MAAM,IAAI,KAAK,CAAC,MAAM,CAAC;SACxB;QAED,IAAA,kBAAa,EAAC,IAAI,EAAE,cAAc,CAAC,CAAC;KACrC;SAAM;QACL,MAAM,IAAI,KAAK,CAAC,uDAAuD,CAAC,CAAC;KAC1E;AACH,CAAC;AA5ED,wCA4EC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=file.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file.test.d.ts","sourceRoot":"","sources":["../../src/util/file.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,87 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const file_1 = require("../../src/util/file");
4
+ const promises_1 = require("fs/promises");
5
+ jest.mock('fs/promises');
6
+ describe('pruneDir function', () => {
7
+ afterEach(() => {
8
+ jest.clearAllMocks();
9
+ });
10
+ it('should return true if directory is successfully pruned', async () => {
11
+ const path = '/path/to/directory';
12
+ const files = ['file1.txt', 'file2.txt'];
13
+ promises_1.readdir.mockResolvedValue(files);
14
+ promises_1.stat.mockResolvedValue({ isDirectory: () => false });
15
+ const result = await (0, file_1.pruneDir)({ path });
16
+ expect(result).toBe(true);
17
+ expect(promises_1.readdir).toHaveBeenCalledWith(path);
18
+ expect(promises_1.stat).toHaveBeenCalledTimes(2); // Called for each file
19
+ expect(promises_1.unlink).toHaveBeenCalledTimes(2); // Called for each file
20
+ });
21
+ it('should exclude specified files from pruning', async () => {
22
+ const path = '/path/to/directory';
23
+ const files = ['file1.txt', 'file2.txt'];
24
+ const exclude = ['file1.txt']; // Exclude file1.txt
25
+ promises_1.readdir.mockResolvedValue(files);
26
+ promises_1.stat.mockResolvedValue({ isDirectory: () => false });
27
+ const result = await (0, file_1.pruneDir)({ path, exclude });
28
+ expect(result).toBe(false);
29
+ expect(promises_1.readdir).toHaveBeenCalledWith(path);
30
+ expect(promises_1.stat).toHaveBeenCalledTimes(1); // Called only for file2.txt
31
+ expect(promises_1.unlink).toHaveBeenCalledTimes(1); // Called only for file2.txt
32
+ });
33
+ it('should recursively prune directories if recurse option is true', async () => {
34
+ const rootPath = '/path/to/directory';
35
+ const subDirPath = '/path/to/directory/subdir';
36
+ const files = ['file1.txt', 'subdir'];
37
+ const subDirFiles = ['file2.txt'];
38
+ promises_1.readdir.mockImplementation((path) => {
39
+ if (path === rootPath)
40
+ return files;
41
+ if (path === subDirPath)
42
+ return subDirFiles;
43
+ });
44
+ promises_1.stat.mockImplementation((path) => {
45
+ if (path === `${rootPath}/file1.txt`)
46
+ return { isDirectory: () => false };
47
+ if (path === subDirPath)
48
+ return { isDirectory: () => true };
49
+ if (path === `${subDirPath}/file2.txt`)
50
+ return { isDirectory: () => false };
51
+ });
52
+ const result = await (0, file_1.pruneDir)({ path: rootPath, recurse: true });
53
+ expect(result).toBe(true);
54
+ expect(promises_1.readdir).toHaveBeenCalledWith(rootPath);
55
+ expect(promises_1.readdir).toHaveBeenCalledWith(subDirPath);
56
+ expect(promises_1.stat).toHaveBeenCalledTimes(3); // Called for file1.txt, subdir, and file2.txt
57
+ expect(promises_1.unlink).toHaveBeenCalledWith(`${rootPath}/file1.txt`);
58
+ expect(promises_1.unlink).toHaveBeenCalledWith(`${subDirPath}/file2.txt`);
59
+ expect(promises_1.rmdir).toHaveBeenCalledWith(subDirPath);
60
+ });
61
+ it('should not recurse into directories if recurse option is false', async () => {
62
+ const rootPath = '/path/to/directory';
63
+ const subDirPath = '/path/to/directory/subdir';
64
+ const files = ['file1.txt', 'subdir'];
65
+ const subDirFiles = ['file2.txt'];
66
+ promises_1.readdir.mockImplementation((path) => {
67
+ if (path === rootPath)
68
+ return files;
69
+ if (path === subDirPath)
70
+ return subDirFiles;
71
+ });
72
+ promises_1.stat.mockImplementation((path) => {
73
+ if (path === `${rootPath}/file1.txt`)
74
+ return { isDirectory: () => false };
75
+ if (path === subDirPath)
76
+ return { isDirectory: () => true };
77
+ });
78
+ const result = await (0, file_1.pruneDir)({ path: rootPath, recurse: false });
79
+ expect(result).toBe(true);
80
+ expect(promises_1.readdir).toHaveBeenCalledWith(rootPath);
81
+ expect(promises_1.stat).toHaveBeenCalledTimes(2); // Called for file1.txt and subdir
82
+ expect(promises_1.unlink).toHaveBeenCalledWith(`${rootPath}/file1.txt`);
83
+ expect(promises_1.unlink).not.toHaveBeenCalledWith(`${subDirPath}/file2.txt`);
84
+ expect(promises_1.rmdir).not.toHaveBeenCalled();
85
+ });
86
+ });
87
+ //# sourceMappingURL=file.test.js.map