@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,90 @@
1
+ import { pruneDir } from '../../src/util/file';
2
+ import { readdir, stat, rmdir, unlink } from 'fs/promises';
3
+
4
+ jest.mock('fs/promises');
5
+
6
+ describe('pruneDir function', () => {
7
+ afterEach(() => {
8
+ jest.clearAllMocks();
9
+ });
10
+
11
+ it('should return true if directory is successfully pruned', async () => {
12
+ const path = '/path/to/directory';
13
+ const files = ['file1.txt', 'file2.txt'];
14
+ (readdir as jest.Mock).mockResolvedValue(files);
15
+ (stat as jest.Mock).mockResolvedValue({ isDirectory: () => false });
16
+
17
+ const result = await pruneDir({ path });
18
+
19
+ expect(result).toBe(true);
20
+ expect(readdir).toHaveBeenCalledWith(path);
21
+ expect(stat).toHaveBeenCalledTimes(2); // Called for each file
22
+ expect(unlink).toHaveBeenCalledTimes(2); // Called for each file
23
+ });
24
+
25
+ it('should exclude specified files from pruning', async () => {
26
+ const path = '/path/to/directory';
27
+ const files = ['file1.txt', 'file2.txt'];
28
+ const exclude = ['file1.txt']; // Exclude file1.txt
29
+ (readdir as jest.Mock).mockResolvedValue(files);
30
+ (stat as jest.Mock).mockResolvedValue({ isDirectory: () => false });
31
+
32
+ const result = await pruneDir({ path, exclude });
33
+
34
+ expect(result).toBe(false);
35
+ expect(readdir).toHaveBeenCalledWith(path);
36
+ expect(stat).toHaveBeenCalledTimes(1); // Called only for file2.txt
37
+ expect(unlink).toHaveBeenCalledTimes(1); // Called only for file2.txt
38
+ });
39
+
40
+ it('should recursively prune directories if recurse option is true', async () => {
41
+ const rootPath = '/path/to/directory';
42
+ const subDirPath = '/path/to/directory/subdir';
43
+ const files = ['file1.txt', 'subdir'];
44
+ const subDirFiles = ['file2.txt'];
45
+ (readdir as jest.Mock).mockImplementation((path) => {
46
+ if (path === rootPath) return files;
47
+ if (path === subDirPath) return subDirFiles;
48
+ });
49
+ (stat as jest.Mock).mockImplementation((path) => {
50
+ if (path === `${rootPath}/file1.txt`) return { isDirectory: () => false };
51
+ if (path === subDirPath) return { isDirectory: () => true };
52
+ if (path === `${subDirPath}/file2.txt`)
53
+ return { isDirectory: () => false };
54
+ });
55
+
56
+ const result = await pruneDir({ path: rootPath, recurse: true });
57
+
58
+ expect(result).toBe(true);
59
+ expect(readdir).toHaveBeenCalledWith(rootPath);
60
+ expect(readdir).toHaveBeenCalledWith(subDirPath);
61
+ expect(stat).toHaveBeenCalledTimes(3); // Called for file1.txt, subdir, and file2.txt
62
+ expect(unlink).toHaveBeenCalledWith(`${rootPath}/file1.txt`);
63
+ expect(unlink).toHaveBeenCalledWith(`${subDirPath}/file2.txt`);
64
+ expect(rmdir).toHaveBeenCalledWith(subDirPath);
65
+ });
66
+
67
+ it('should not recurse into directories if recurse option is false', async () => {
68
+ const rootPath = '/path/to/directory';
69
+ const subDirPath = '/path/to/directory/subdir';
70
+ const files = ['file1.txt', 'subdir'];
71
+ const subDirFiles = ['file2.txt'];
72
+ (readdir as jest.Mock).mockImplementation((path) => {
73
+ if (path === rootPath) return files;
74
+ if (path === subDirPath) return subDirFiles;
75
+ });
76
+ (stat as jest.Mock).mockImplementation((path) => {
77
+ if (path === `${rootPath}/file1.txt`) return { isDirectory: () => false };
78
+ if (path === subDirPath) return { isDirectory: () => true };
79
+ });
80
+
81
+ const result = await pruneDir({ path: rootPath, recurse: false });
82
+
83
+ expect(result).toBe(true);
84
+ expect(readdir).toHaveBeenCalledWith(rootPath);
85
+ expect(stat).toHaveBeenCalledTimes(2); // Called for file1.txt and subdir
86
+ expect(unlink).toHaveBeenCalledWith(`${rootPath}/file1.txt`);
87
+ expect(unlink).not.toHaveBeenCalledWith(`${subDirPath}/file2.txt`);
88
+ expect(rmdir).not.toHaveBeenCalled();
89
+ });
90
+ });
@@ -0,0 +1,156 @@
1
+ import { rimraf } from 'rimraf';
2
+ import { logger } from '../util/logger';
3
+ import { readdir, stat, unlink, rmdir } from 'fs/promises';
4
+ import { join } from 'path';
5
+ import { stringifyError } from 'alwaysai/lib/util';
6
+ import { writeFileSync } from 'fs';
7
+
8
+ export async function safeRimraf(path: string) {
9
+ logger.debug(`Removing ${path}`);
10
+ try {
11
+ await rimraf(path);
12
+ } catch (e) {
13
+ logger.error(
14
+ `Failed to remove ${path}. Please manually delete the file or directory.`
15
+ );
16
+ logger.debug(`Error removing ${path}:\n${stringifyError(e)}`);
17
+ }
18
+ }
19
+
20
+ export async function pruneDir({
21
+ path,
22
+ exclude,
23
+ recurse
24
+ }: {
25
+ path: string;
26
+ exclude?: string[];
27
+ recurse?: boolean;
28
+ }) {
29
+ /**
30
+ * Deletes all files and directories in a given directory path, excluding specific paths.
31
+ * Will not delete top-level directory
32
+ * @param {string} path path of directory to prune.
33
+ * @param {string[]} exclude list of paths to exclude when pruning
34
+ * @param {boolean} recurse flag to prune recursively into directories
35
+ */
36
+ try {
37
+ const files = await readdir(path);
38
+
39
+ let canPruneParent = true;
40
+
41
+ for (const file of files) {
42
+ const filePath = join(path, file);
43
+
44
+ const isExcluded = exclude?.some((excludePath) =>
45
+ filePath.endsWith(excludePath)
46
+ );
47
+
48
+ if (isExcluded) {
49
+ logger.debug(`Excluding file ${filePath} during pruning.`);
50
+ canPruneParent = false;
51
+ continue;
52
+ }
53
+
54
+ const fileStats = await stat(filePath);
55
+ if (fileStats.isDirectory()) {
56
+ if (recurse) {
57
+ const dirIsEmpty = await pruneDir({
58
+ path: filePath,
59
+ exclude,
60
+ recurse
61
+ });
62
+
63
+ if (dirIsEmpty) {
64
+ await rmdir(filePath);
65
+ } else {
66
+ canPruneParent = false;
67
+ }
68
+ }
69
+ } else {
70
+ await unlink(filePath);
71
+ }
72
+ }
73
+ return canPruneParent;
74
+ } catch (e) {
75
+ logger.error(`Error pruning directory ${path}!\n${stringifyError(e)}`);
76
+ return false;
77
+ }
78
+ }
79
+
80
+ export async function downloadToFile({
81
+ path,
82
+ url
83
+ }: {
84
+ path: string;
85
+ url: string;
86
+ }) {
87
+ const response = await fetch(url);
88
+
89
+ if (!response.ok) {
90
+ throw new Error(`Failed to fetch ${url}: ${response.statusText}`);
91
+ }
92
+
93
+ const contentLength = response.headers.get('content-length');
94
+ const reader = response.body?.getReader();
95
+
96
+ if (reader) {
97
+ const chunks: Uint8Array[] = [];
98
+ const totalSize = contentLength ? parseInt(contentLength) : undefined;
99
+
100
+ const PROGRESS_PERC_LOG_INCREMENT = 5;
101
+ const BYTE_DOWNLOAD_LOG_INCREMENT = 5_000_000;
102
+ const [baseUrl, urlParams] = url.split('?');
103
+ const urlForLog = `${baseUrl}${
104
+ urlParams?.length ? `...(${urlParams.length} more characters)` : ''
105
+ }`;
106
+ let totalDownloadedBytes = 0;
107
+ let downloadedSize = 0;
108
+ let totalProgressPerc = 0;
109
+
110
+ // eslint-disable-next-line
111
+ while (true) {
112
+ const { done, value } = await reader.read();
113
+ if (done) {
114
+ logger.info(`Download complete - ${urlForLog}`);
115
+ break;
116
+ }
117
+ if (value) {
118
+ chunks.push(value);
119
+ downloadedSize += value.length;
120
+ if (totalSize) {
121
+ const progress = (downloadedSize / totalSize) * 100;
122
+ if (progress > totalProgressPerc + PROGRESS_PERC_LOG_INCREMENT) {
123
+ totalProgressPerc += PROGRESS_PERC_LOG_INCREMENT;
124
+ logger.debug(
125
+ `Download progress: ${progress.toFixed(2)}% - ${urlForLog}`
126
+ );
127
+ }
128
+ } else {
129
+ if (
130
+ downloadedSize >
131
+ totalDownloadedBytes + BYTE_DOWNLOAD_LOG_INCREMENT
132
+ ) {
133
+ totalDownloadedBytes += BYTE_DOWNLOAD_LOG_INCREMENT;
134
+ logger.debug(
135
+ `Download progress: ${downloadedSize} total bytes - ${urlForLog}`
136
+ );
137
+ }
138
+ }
139
+ }
140
+ }
141
+
142
+ logger.debug(`Writing downloaded chunks to file ${path}`);
143
+ const combinedSize = chunks.reduce((acc, chunk) => acc + chunk.length, 0);
144
+ const combinedChunks = new Uint8Array(combinedSize);
145
+
146
+ let offset = 0;
147
+ for (const chunk of chunks) {
148
+ combinedChunks.set(chunk, offset);
149
+ offset += chunk.length;
150
+ }
151
+
152
+ writeFileSync(path, combinedChunks);
153
+ } else {
154
+ throw new Error('Unable to access response body when downloading file.');
155
+ }
156
+ }
@@ -1,4 +1,7 @@
1
1
  import { DeviceConfigFile } from 'alwaysai/lib/core/device';
2
+ import { logger } from './logger';
3
+ import { stringifyError } from 'alwaysai/lib/util';
4
+ import AaiError from './aai-error';
2
5
 
3
6
  export function getDeviceUuid() {
4
7
  const deviceCfgFile = DeviceConfigFile();
@@ -9,12 +12,9 @@ export function getDeviceUuid() {
9
12
  const cfg = deviceCfgFile.read();
10
13
  return cfg.deviceUuid;
11
14
  } catch (e) {
12
- throw new Error(
13
- `Failed to read device configuration: ${JSON.stringify(
14
- deviceCfgFile.getErrors(),
15
- null,
16
- 2
17
- )}`
18
- );
15
+ logger.error(`Failed to read device configuration!\n${stringifyError(e)}`);
16
+ throw new AaiError('Failed to read device configuration', {
17
+ cause: deviceCfgFile.getErrors()
18
+ });
19
19
  }
20
20
  }
@@ -1,7 +1,7 @@
1
- import fetch from 'node-fetch';
2
1
  import { serviceEndpointBuilder } from '../endpoints';
3
2
  import { CliAuthenticationClient } from 'alwaysai/lib/infrastructure';
4
3
  import { logger } from '../util/logger';
4
+ import { stringifyError } from 'alwaysai/lib/util';
5
5
 
6
6
  export async function httpClient(
7
7
  url: string,
@@ -23,7 +23,7 @@ export async function httpClient(
23
23
  return await response.text();
24
24
  }
25
25
  } catch (e) {
26
- logger.error(`HTTP Client error for ${url}: ${e.message}`);
26
+ logger.error(`HTTP Client error for ${url}:\n${stringifyError(e)}`);
27
27
  }
28
28
  }
29
29
 
@@ -1,5 +0,0 @@
1
- export declare function runDockerComposeCmd(props: {
2
- args: string[];
3
- dir: string;
4
- }): Promise<string>;
5
- //# sourceMappingURL=docker-compose-cmd.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"docker-compose-cmd.d.ts","sourceRoot":"","sources":["../../src/docker/docker-compose-cmd.ts"],"names":[],"mappings":"AAEA,wBAAsB,mBAAmB,CAAC,KAAK,EAAE;IAC/C,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,GAAG,EAAE,MAAM,CAAC;CACb,mBASA"}
@@ -1,16 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.runDockerComposeCmd = void 0;
4
- const util_1 = require("alwaysai/lib/util");
5
- async function runDockerComposeCmd(props) {
6
- const { args, dir } = props;
7
- const spawner = (0, util_1.JsSpawner)();
8
- const output = await spawner.run({
9
- exe: 'docker-compose',
10
- args,
11
- cwd: dir
12
- });
13
- return output;
14
- }
15
- exports.runDockerComposeCmd = runDockerComposeCmd;
16
- //# sourceMappingURL=docker-compose-cmd.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"docker-compose-cmd.js","sourceRoot":"","sources":["../../src/docker/docker-compose-cmd.ts"],"names":[],"mappings":";;;AAAA,4CAA8C;AAEvC,KAAK,UAAU,mBAAmB,CAAC,KAGzC;IACC,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,KAAK,CAAC;IAC5B,MAAM,OAAO,GAAG,IAAA,gBAAS,GAAE,CAAC;IAC5B,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;QAC/B,GAAG,EAAE,gBAAgB;QACrB,IAAI;QACJ,GAAG,EAAE,GAAG;KACT,CAAC,CAAC;IACH,OAAO,MAAM,CAAC;AAChB,CAAC;AAZD,kDAYC"}
@@ -1,7 +0,0 @@
1
- export declare const initCliLeaf: import("@alwaysai/alwayscli/lib/types").CliLeaf<import("@alwaysai/alwayscli").CliInput<undefined, false>, {
2
- name: import("@alwaysai/alwayscli").CliInput<string | undefined, false>;
3
- description: import("@alwaysai/alwayscli").CliInput<string | undefined, false>;
4
- }, import("@alwaysai/alwayscli").CliInput<undefined, false>>;
5
- export declare const getInfoCliLeaf: import("@alwaysai/alwayscli/lib/types").CliLeaf<import("@alwaysai/alwayscli").CliInput<undefined, false>, {}, import("@alwaysai/alwayscli").CliInput<undefined, false>>;
6
- export declare const restartCliLeaf: import("@alwaysai/alwayscli/lib/types").CliLeaf<import("@alwaysai/alwayscli").CliInput<undefined, false>, {}, import("@alwaysai/alwayscli").CliInput<undefined, false>>;
7
- //# sourceMappingURL=device.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"device.d.ts","sourceRoot":"","sources":["../../../src/subcommands/device/device.ts"],"names":[],"mappings":"AA0BA,eAAO,MAAM,WAAW;;;4DAiFtB,CAAC;AAEH,eAAO,MAAM,cAAc,yKAwCzB,CAAC;AAEH,eAAO,MAAM,cAAc,yKAOzB,CAAC"}
@@ -1 +0,0 @@
1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AC,MAAM,SAClB,UAAU,CAAC,MAAM,GAAG,UAAU,CAAC,MACjC,KAAK;gBACP,CAAC,CAAC,aACN,EAAE;SACH,CAAC;QACF,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QACnB,MAAM,UAAU,GAAG,MAAM,IAAA,qCAAoB,GAAE,CAAC;QAChD,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;QAC7B,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;QAC9B,OAAO,CAAC,KAAK,CAAC,MAAA,UAAU,CAAC,IAAI,0CAAE,MAAM,CAAC,CAAC;QACvC,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;QACjC,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;QAClC,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;IACrC,CAAC;CACF,CAAC,CAAC;AAEU,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,3 +0,0 @@
1
- export declare function isValidAwsRegion(region: string): boolean;
2
- export declare function cloudModeReady(): boolean;
3
- //# sourceMappingURL=cloud-mode-ready.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"cloud-mode-ready.d.ts","sourceRoot":"","sources":["../../src/util/cloud-mode-ready.ts"],"names":[],"mappings":"AAuCA,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAExD;AAED,wBAAgB,cAAc,YAe7B"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"cloud-mode-ready.js","sourceRoot":"","sources":["../../src/util/cloud-mode-ready.ts"],"names":[],"mappings":";;;AAAA,2BAAgC;AAChC,qDAI6B;AAE7B,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;AAED,SAAgB,cAAc;IAC5B,IAAI,KAAK,GAAG,IAAI,CAAC;IACjB,MAAM,aAAa,GAAG;QACpB,0CAA4B;QAC5B,0CAA4B;QAC5B,4CAA8B;KAC/B,CAAC;IAEF,KAAK,MAAM,IAAI,IAAI,aAAa,EAAE;QAChC,IAAI,CAAC,IAAA,eAAU,EAAC,IAAI,CAAC,EAAE;YACrB,KAAK,GAAG,KAAK,CAAC;YACd,MAAM;SACP;KACF;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAfD,wCAeC"}
@@ -1,6 +0,0 @@
1
- export declare function downloadFile(props: {
2
- url: string;
3
- path: string;
4
- errorMessage: string;
5
- }): Promise<void>;
6
- //# sourceMappingURL=download-file.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"download-file.d.ts","sourceRoot":"","sources":["../../src/util/download-file.ts"],"names":[],"mappings":"AAIA,wBAAsB,YAAY,CAAC,KAAK,EAAE;IACxC,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,EAAE,MAAM,CAAC;CACtB,GAAG,OAAO,CAAC,IAAI,CAAC,CAgBhB"}
@@ -1,25 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.downloadFile = void 0;
4
- const fs = require("fs");
5
- const fetch_with_timeout_1 = require("./fetch-with-timeout");
6
- const logger_1 = require("./logger");
7
- async function downloadFile(props) {
8
- const { url, path, errorMessage } = props;
9
- logger_1.logger.debug(`Downloading package from ${url}`);
10
- let response;
11
- try {
12
- response = await (0, fetch_with_timeout_1.fetchWithTimeout)(url);
13
- }
14
- catch (e) {
15
- const errorBody = e.type === 'aborted' ? e : await e.response.text();
16
- throw new Error(`${errorMessage}: Error=${e}\n${errorBody}`);
17
- }
18
- const stream = response.body.pipe(fs.createWriteStream(path));
19
- await new Promise((resolve, reject) => {
20
- stream.on('finish', resolve);
21
- stream.on('error', reject);
22
- });
23
- }
24
- exports.downloadFile = downloadFile;
25
- //# sourceMappingURL=download-file.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"download-file.js","sourceRoot":"","sources":["../../src/util/download-file.ts"],"names":[],"mappings":";;;AAAA,yBAAyB;AACzB,6DAAwD;AACxD,qCAAkC;AAE3B,KAAK,UAAU,YAAY,CAAC,KAIlC;IACC,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,YAAY,EAAE,GAAG,KAAK,CAAC;IAC1C,eAAM,CAAC,KAAK,CAAC,4BAA4B,GAAG,EAAE,CAAC,CAAC;IAChD,IAAI,QAAa,CAAC;IAClB,IAAI;QACF,QAAQ,GAAG,MAAM,IAAA,qCAAgB,EAAC,GAAG,CAAC,CAAC;KACxC;IAAC,OAAO,CAAC,EAAE;QACV,MAAM,SAAS,GAAG,CAAC,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC;QACrE,MAAM,IAAI,KAAK,CAAC,GAAG,YAAY,WAAW,CAAC,KAAK,SAAS,EAAE,CAAC,CAAC;KAC9D;IAED,MAAM,MAAM,GAAG,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC,CAAC;IAC9D,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACpC,MAAM,CAAC,EAAE,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;QAC7B,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IAC7B,CAAC,CAAC,CAAC;AACL,CAAC;AApBD,oCAoBC"}
@@ -1,4 +0,0 @@
1
- export declare function fetchWithTimeout(url: string, options?: {
2
- timeout?: number;
3
- }): Promise<any>;
4
- //# sourceMappingURL=fetch-with-timeout.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"fetch-with-timeout.d.ts","sourceRoot":"","sources":["../../src/util/fetch-with-timeout.ts"],"names":[],"mappings":"AAmBA,wBAAsB,gBAAgB,CACpC,GAAG,EAAE,MAAM,EACX,OAAO,GAAE;IAAE,OAAO,CAAC,EAAE,MAAM,CAAA;CAAO,gBAanC"}
@@ -1,30 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.fetchWithTimeout = void 0;
4
- const node_fetch_1 = require("node-fetch");
5
- class HTTPResponseError extends Error {
6
- constructor(response) {
7
- super(`HTTP Error Response: ${response.status} ${response.statusText}`);
8
- this.response = response;
9
- }
10
- }
11
- const checkStatus = (response) => {
12
- if (response.ok) {
13
- // response.status >= 200 && response.status < 300
14
- return response;
15
- }
16
- else {
17
- throw new HTTPResponseError(response);
18
- }
19
- };
20
- async function fetchWithTimeout(url, options = {}) {
21
- //time (ms)
22
- const { timeout = 60000 } = options;
23
- const controller = new AbortController();
24
- const id = setTimeout(() => controller.abort(), timeout);
25
- const response = await (0, node_fetch_1.default)(url, Object.assign(Object.assign({}, options), { signal: controller.signal }));
26
- clearTimeout(id);
27
- return checkStatus(response);
28
- }
29
- exports.fetchWithTimeout = fetchWithTimeout;
30
- //# sourceMappingURL=fetch-with-timeout.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"fetch-with-timeout.js","sourceRoot":"","sources":["../../src/util/fetch-with-timeout.ts"],"names":[],"mappings":";;;AAAA,2CAAmC;AAEnC,MAAM,iBAAkB,SAAQ,KAAK;IAEnC,YAAY,QAAQ;QAClB,KAAK,CAAC,wBAAwB,QAAQ,CAAC,MAAM,IAAI,QAAQ,CAAC,UAAU,EAAE,CAAC,CAAC;QACxE,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;CACF;AAED,MAAM,WAAW,GAAG,CAAC,QAAQ,EAAE,EAAE;IAC/B,IAAI,QAAQ,CAAC,EAAE,EAAE;QACf,kDAAkD;QAClD,OAAO,QAAQ,CAAC;KACjB;SAAM;QACL,MAAM,IAAI,iBAAiB,CAAC,QAAQ,CAAC,CAAC;KACvC;AACH,CAAC,CAAC;AAEK,KAAK,UAAU,gBAAgB,CACpC,GAAW,EACX,UAAgC,EAAE;IAElC,WAAW;IACX,MAAM,EAAE,OAAO,GAAG,KAAK,EAAE,GAAG,OAAO,CAAC;IAEpC,MAAM,UAAU,GAAG,IAAI,eAAe,EAAE,CAAC;IACzC,MAAM,EAAE,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,UAAU,CAAC,KAAK,EAAE,EAAE,OAAO,CAAC,CAAC;IACzD,MAAM,QAAQ,GAAG,MAAM,IAAA,oBAAS,EAAC,GAAG,kCAC/B,OAAO,KACV,MAAM,EAAE,UAAU,CAAC,MAAM,IACzB,CAAC;IACH,YAAY,CAAC,EAAE,CAAC,CAAC;IACjB,OAAO,WAAW,CAAC,QAAQ,CAAC,CAAC;AAC/B,CAAC;AAfD,4CAeC"}
@@ -1,2 +0,0 @@
1
- export declare function replaceFalseyWithNull(object: object, recurse?: boolean): void;
2
- //# sourceMappingURL=parsing.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"parsing.d.ts","sourceRoot":"","sources":["../../src/util/parsing.ts"],"names":[],"mappings":"AAAA,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,QAUtE"}
@@ -1,17 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.replaceFalseyWithNull = void 0;
4
- function replaceFalseyWithNull(object, recurse) {
5
- if (typeof object === 'string' || object instanceof String)
6
- return;
7
- object &&
8
- Object.keys(object).forEach((key) => {
9
- if (recurse) {
10
- replaceFalseyWithNull(object[key], recurse);
11
- }
12
- if (!object[key])
13
- object[key] = null;
14
- });
15
- }
16
- exports.replaceFalseyWithNull = replaceFalseyWithNull;
17
- //# sourceMappingURL=parsing.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"parsing.js","sourceRoot":"","sources":["../../src/util/parsing.ts"],"names":[],"mappings":";;;AAAA,SAAgB,qBAAqB,CAAC,MAAc,EAAE,OAAiB;IACrE,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,YAAY,MAAM;QAAE,OAAO;IAEnE,MAAM;QACJ,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,GAAW,EAAE,EAAE;YAC1C,IAAI,OAAO,EAAE;gBACX,qBAAqB,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,OAAO,CAAC,CAAC;aAC7C;YACD,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC;gBAAE,MAAM,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC;QACvC,CAAC,CAAC,CAAC;AACP,CAAC;AAVD,sDAUC"}
@@ -1,2 +0,0 @@
1
- export default function safeRimraf(path: string): Promise<void>;
2
- //# sourceMappingURL=safe-rimraf.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"safe-rimraf.d.ts","sourceRoot":"","sources":["../../src/util/safe-rimraf.ts"],"names":[],"mappings":"AAGA,wBAA8B,UAAU,CAAC,IAAI,EAAE,MAAM,iBAUpD"}
@@ -1,16 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const rimraf_1 = require("rimraf");
4
- const logger_1 = require("../util/logger");
5
- async function safeRimraf(path) {
6
- logger_1.logger.debug(`Removing ${path}`);
7
- try {
8
- await (0, rimraf_1.rimraf)(path);
9
- }
10
- catch (e) {
11
- logger_1.logger.error(`Failed to remove ${path}. Please manually delete the file or directory.`);
12
- logger_1.logger.debug(`Error removing ${path}: ${e}`);
13
- }
14
- }
15
- exports.default = safeRimraf;
16
- //# sourceMappingURL=safe-rimraf.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"safe-rimraf.js","sourceRoot":"","sources":["../../src/util/safe-rimraf.ts"],"names":[],"mappings":";;AAAA,mCAAgC;AAChC,2CAAwC;AAEzB,KAAK,UAAU,UAAU,CAAC,IAAY;IACnD,eAAM,CAAC,KAAK,CAAC,YAAY,IAAI,EAAE,CAAC,CAAC;IACjC,IAAI;QACF,MAAM,IAAA,eAAM,EAAC,IAAI,CAAC,CAAC;KACpB;IAAC,OAAO,CAAC,EAAE;QACV,eAAM,CAAC,KAAK,CACV,oBAAoB,IAAI,iDAAiD,CAC1E,CAAC;QACF,eAAM,CAAC,KAAK,CAAC,kBAAkB,IAAI,KAAK,CAAC,EAAE,CAAC,CAAC;KAC9C;AACH,CAAC;AAVD,6BAUC"}
@@ -1,15 +0,0 @@
1
- import { JsSpawner } from 'alwaysai/lib/util';
2
-
3
- export async function runDockerComposeCmd(props: {
4
- args: string[];
5
- dir: string;
6
- }) {
7
- const { args, dir } = props;
8
- const spawner = JsSpawner();
9
- const output = await spawner.run({
10
- exe: 'docker-compose',
11
- args,
12
- cwd: dir
13
- });
14
- return output;
15
- }
@@ -1,25 +0,0 @@
1
- import * as fs from 'fs';
2
- import { fetchWithTimeout } from './fetch-with-timeout';
3
- import { logger } from './logger';
4
-
5
- export async function downloadFile(props: {
6
- url: string;
7
- path: string;
8
- errorMessage: string;
9
- }): Promise<void> {
10
- const { url, path, errorMessage } = props;
11
- logger.debug(`Downloading package from ${url}`);
12
- let response: any;
13
- try {
14
- response = await fetchWithTimeout(url);
15
- } catch (e) {
16
- const errorBody = e.type === 'aborted' ? e : await e.response.text();
17
- throw new Error(`${errorMessage}: Error=${e}\n${errorBody}`);
18
- }
19
-
20
- const stream = response.body.pipe(fs.createWriteStream(path));
21
- await new Promise((resolve, reject) => {
22
- stream.on('finish', resolve);
23
- stream.on('error', reject);
24
- });
25
- }
@@ -1,35 +0,0 @@
1
- import nodeFetch from 'node-fetch';
2
-
3
- class HTTPResponseError extends Error {
4
- public response;
5
- constructor(response) {
6
- super(`HTTP Error Response: ${response.status} ${response.statusText}`);
7
- this.response = response;
8
- }
9
- }
10
-
11
- const checkStatus = (response) => {
12
- if (response.ok) {
13
- // response.status >= 200 && response.status < 300
14
- return response;
15
- } else {
16
- throw new HTTPResponseError(response);
17
- }
18
- };
19
-
20
- export async function fetchWithTimeout(
21
- url: string,
22
- options: { timeout?: number } = {}
23
- ) {
24
- //time (ms)
25
- const { timeout = 60000 } = options;
26
-
27
- const controller = new AbortController();
28
- const id = setTimeout(() => controller.abort(), timeout);
29
- const response = await nodeFetch(url, {
30
- ...options,
31
- signal: controller.signal
32
- });
33
- clearTimeout(id);
34
- return checkStatus(response);
35
- }
@@ -1,11 +0,0 @@
1
- export function replaceFalseyWithNull(object: object, recurse?: boolean) {
2
- if (typeof object === 'string' || object instanceof String) return;
3
-
4
- object &&
5
- Object.keys(object).forEach((key: string) => {
6
- if (recurse) {
7
- replaceFalseyWithNull(object[key], recurse);
8
- }
9
- if (!object[key]) object[key] = null;
10
- });
11
- }
@@ -1,14 +0,0 @@
1
- import { rimraf } from 'rimraf';
2
- import { logger } from '../util/logger';
3
-
4
- export default async function safeRimraf(path: string) {
5
- logger.debug(`Removing ${path}`);
6
- try {
7
- await rimraf(path);
8
- } catch (e) {
9
- logger.error(
10
- `Failed to remove ${path}. Please manually delete the file or directory.`
11
- );
12
- logger.debug(`Error removing ${path}: ${e}`);
13
- }
14
- }