@budibase/server 1.0.34 → 1.0.41

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 (377) hide show
  1. package/__mocks__/node-fetch.ts +21 -0
  2. package/builder/assets/bb-spaceship.8f6e81e1.svg +227 -0
  3. package/builder/assets/{index.4fb3f887.css → index.39e01193.css} +1 -1
  4. package/builder/assets/index.d5158e11.js +1348 -0
  5. package/builder/assets/{vendor.470042a4.js → vendor.f9faf6ab.js} +88 -88
  6. package/builder/index.html +3 -3
  7. package/coverage/clover.xml +1589 -1344
  8. package/coverage/coverage-final.json +75 -74
  9. package/coverage/lcov-report/api/controllers/analytics.js.html +1 -1
  10. package/coverage/lcov-report/api/controllers/apikeys.js.html +3 -3
  11. package/coverage/lcov-report/api/controllers/application.js.html +73 -64
  12. package/coverage/lcov-report/api/controllers/auth.js.html +2 -2
  13. package/coverage/lcov-report/api/controllers/automation.js.html +22 -10
  14. package/coverage/lcov-report/api/controllers/backup.js.html +1 -1
  15. package/coverage/lcov-report/api/controllers/cloud.js.html +13 -4
  16. package/coverage/lcov-report/api/controllers/component.js.html +4 -4
  17. package/coverage/lcov-report/api/controllers/datasource.js.html +170 -68
  18. package/coverage/lcov-report/api/controllers/dev.js.html +3 -3
  19. package/coverage/lcov-report/api/controllers/hosting.js.html +3 -3
  20. package/coverage/lcov-report/api/controllers/index.html +39 -54
  21. package/coverage/lcov-report/api/controllers/integration.js.html +1 -1
  22. package/coverage/lcov-report/api/controllers/layout.js.html +1 -1
  23. package/coverage/lcov-report/api/controllers/metadata.js.html +1 -1
  24. package/coverage/lcov-report/api/controllers/permission.js.html +3 -3
  25. package/coverage/lcov-report/api/controllers/query/index.html +126 -0
  26. package/coverage/lcov-report/api/controllers/{query.js.html → query/index.js.html} +225 -120
  27. package/coverage/lcov-report/api/controllers/query/validation.js.html +206 -0
  28. package/coverage/lcov-report/api/controllers/role.js.html +2 -2
  29. package/coverage/lcov-report/api/controllers/routing.js.html +2 -2
  30. package/coverage/lcov-report/api/controllers/row/external.js.html +1 -1
  31. package/coverage/lcov-report/api/controllers/row/index.html +22 -22
  32. package/coverage/lcov-report/api/controllers/row/index.js.html +1 -1
  33. package/coverage/lcov-report/api/controllers/row/internal.js.html +38 -11
  34. package/coverage/lcov-report/api/controllers/row/internalSearch.js.html +8 -5
  35. package/coverage/lcov-report/api/controllers/row/utils.js.html +29 -20
  36. package/coverage/lcov-report/api/controllers/screen.js.html +2 -2
  37. package/coverage/lcov-report/api/controllers/script.js.html +1 -1
  38. package/coverage/lcov-report/api/controllers/table/external.js.html +1 -1
  39. package/coverage/lcov-report/api/controllers/table/index.html +1 -1
  40. package/coverage/lcov-report/api/controllers/table/index.js.html +1 -1
  41. package/coverage/lcov-report/api/controllers/table/internal.js.html +1 -1
  42. package/coverage/lcov-report/api/controllers/table/utils.js.html +1 -1
  43. package/coverage/lcov-report/api/controllers/templates.js.html +1 -1
  44. package/coverage/lcov-report/api/controllers/user.js.html +120 -12
  45. package/coverage/lcov-report/api/controllers/view/exporters.js.html +1 -1
  46. package/coverage/lcov-report/api/controllers/view/index.html +1 -1
  47. package/coverage/lcov-report/api/controllers/view/index.js.html +1 -1
  48. package/coverage/lcov-report/api/controllers/view/utils.js.html +1 -1
  49. package/coverage/lcov-report/api/controllers/view/viewBuilder.js.html +1 -1
  50. package/coverage/lcov-report/api/controllers/webhook.js.html +19 -7
  51. package/coverage/lcov-report/api/index.html +1 -1
  52. package/coverage/lcov-report/api/index.js.html +6 -6
  53. package/coverage/lcov-report/api/routes/analytics.js.html +1 -1
  54. package/coverage/lcov-report/api/routes/apikeys.js.html +2 -2
  55. package/coverage/lcov-report/api/routes/application.js.html +2 -2
  56. package/coverage/lcov-report/api/routes/auth.js.html +1 -1
  57. package/coverage/lcov-report/api/routes/automation.js.html +2 -2
  58. package/coverage/lcov-report/api/routes/backup.js.html +2 -2
  59. package/coverage/lcov-report/api/routes/cloud.js.html +2 -2
  60. package/coverage/lcov-report/api/routes/component.js.html +2 -2
  61. package/coverage/lcov-report/api/routes/datasource.js.html +2 -2
  62. package/coverage/lcov-report/api/routes/deploy.js.html +2 -2
  63. package/coverage/lcov-report/api/routes/dev.js.html +2 -2
  64. package/coverage/lcov-report/api/routes/hosting.js.html +2 -2
  65. package/coverage/lcov-report/api/routes/index.html +9 -9
  66. package/coverage/lcov-report/api/routes/index.js.html +1 -1
  67. package/coverage/lcov-report/api/routes/integration.js.html +2 -2
  68. package/coverage/lcov-report/api/routes/layout.js.html +2 -2
  69. package/coverage/lcov-report/api/routes/metadata.js.html +2 -2
  70. package/coverage/lcov-report/api/routes/permission.js.html +12 -3
  71. package/coverage/lcov-report/api/routes/query.js.html +20 -86
  72. package/coverage/lcov-report/api/routes/role.js.html +2 -2
  73. package/coverage/lcov-report/api/routes/routing.js.html +2 -2
  74. package/coverage/lcov-report/api/routes/row.js.html +2 -2
  75. package/coverage/lcov-report/api/routes/screen.js.html +2 -2
  76. package/coverage/lcov-report/api/routes/script.js.html +2 -2
  77. package/coverage/lcov-report/api/routes/static.js.html +2 -2
  78. package/coverage/lcov-report/api/routes/table.js.html +2 -2
  79. package/coverage/lcov-report/api/routes/templates.js.html +2 -2
  80. package/coverage/lcov-report/api/routes/user.js.html +33 -3
  81. package/coverage/lcov-report/api/routes/view.js.html +2 -2
  82. package/coverage/lcov-report/api/routes/webhook.js.html +2 -2
  83. package/coverage/lcov-report/automations/actions.js.html +1 -1
  84. package/coverage/lcov-report/automations/automationUtils.js.html +1 -1
  85. package/coverage/lcov-report/automations/bullboard.js.html +2 -2
  86. package/coverage/lcov-report/automations/index.html +20 -20
  87. package/coverage/lcov-report/automations/index.js.html +1 -1
  88. package/coverage/lcov-report/automations/steps/bash.js.html +1 -1
  89. package/coverage/lcov-report/automations/steps/createRow.js.html +1 -1
  90. package/coverage/lcov-report/automations/steps/delay.js.html +1 -1
  91. package/coverage/lcov-report/automations/steps/deleteRow.js.html +1 -1
  92. package/coverage/lcov-report/automations/steps/discord.js.html +1 -1
  93. package/coverage/lcov-report/automations/steps/executeQuery.js.html +32 -8
  94. package/coverage/lcov-report/automations/steps/executeScript.js.html +1 -1
  95. package/coverage/lcov-report/automations/steps/filter.js.html +1 -1
  96. package/coverage/lcov-report/automations/steps/index.html +11 -11
  97. package/coverage/lcov-report/automations/steps/integromat.js.html +1 -1
  98. package/coverage/lcov-report/automations/steps/outgoingWebhook.js.html +5 -8
  99. package/coverage/lcov-report/automations/steps/queryRows.js.html +1 -1
  100. package/coverage/lcov-report/automations/steps/sendSmtpEmail.js.html +1 -1
  101. package/coverage/lcov-report/automations/steps/serverLog.js.html +1 -1
  102. package/coverage/lcov-report/automations/steps/slack.js.html +1 -1
  103. package/coverage/lcov-report/automations/steps/updateRow.js.html +1 -1
  104. package/coverage/lcov-report/automations/steps/utils.js.html +1 -1
  105. package/coverage/lcov-report/automations/steps/zapier.js.html +1 -1
  106. package/coverage/lcov-report/automations/triggerInfo/app.js.html +1 -1
  107. package/coverage/lcov-report/automations/triggerInfo/cron.js.html +1 -1
  108. package/coverage/lcov-report/automations/triggerInfo/index.html +1 -1
  109. package/coverage/lcov-report/automations/triggerInfo/index.js.html +1 -1
  110. package/coverage/lcov-report/automations/triggerInfo/rowDeleted.js.html +1 -1
  111. package/coverage/lcov-report/automations/triggerInfo/rowSaved.js.html +1 -1
  112. package/coverage/lcov-report/automations/triggerInfo/rowUpdated.js.html +1 -1
  113. package/coverage/lcov-report/automations/triggerInfo/webhook.js.html +1 -1
  114. package/coverage/lcov-report/automations/triggers.js.html +1 -1
  115. package/coverage/lcov-report/automations/utils.js.html +49 -16
  116. package/coverage/lcov-report/constants/index.html +1 -1
  117. package/coverage/lcov-report/constants/index.js.html +25 -25
  118. package/coverage/lcov-report/constants/layouts.js.html +1 -1
  119. package/coverage/lcov-report/constants/screens.js.html +2 -2
  120. package/coverage/lcov-report/db/client.js.html +19 -19
  121. package/coverage/lcov-report/db/inMemoryView.js.html +1 -1
  122. package/coverage/lcov-report/db/index.html +15 -15
  123. package/coverage/lcov-report/db/index.js.html +3 -3
  124. package/coverage/lcov-report/db/linkedRows/LinkController.js.html +1 -1
  125. package/coverage/lcov-report/db/linkedRows/index.html +1 -1
  126. package/coverage/lcov-report/db/linkedRows/index.js.html +1 -1
  127. package/coverage/lcov-report/db/linkedRows/linkUtils.js.html +1 -1
  128. package/coverage/lcov-report/db/newid.js.html +4 -4
  129. package/coverage/lcov-report/db/utils.js.html +108 -81
  130. package/coverage/lcov-report/events/AutomationEmitter.js.html +1 -1
  131. package/coverage/lcov-report/events/index.html +1 -1
  132. package/coverage/lcov-report/events/index.js.html +1 -1
  133. package/coverage/lcov-report/events/utils.js.html +1 -1
  134. package/coverage/lcov-report/index.html +99 -84
  135. package/coverage/lcov-report/integrations/tests/TestConfiguration.js.html +1 -1
  136. package/coverage/lcov-report/integrations/tests/index.html +1 -1
  137. package/coverage/lcov-report/middleware/appInfo.js.html +1 -1
  138. package/coverage/lcov-report/middleware/authorized.js.html +12 -12
  139. package/coverage/lcov-report/middleware/builder.js.html +10 -10
  140. package/coverage/lcov-report/middleware/currentapp.js.html +48 -36
  141. package/coverage/lcov-report/middleware/index.html +1 -1
  142. package/coverage/lcov-report/middleware/joi-validator.js.html +11 -11
  143. package/coverage/lcov-report/middleware/resourceId.js.html +18 -18
  144. package/coverage/lcov-report/middleware/selfhost.js.html +1 -1
  145. package/coverage/lcov-report/middleware/usageQuota.js.html +2 -2
  146. package/coverage/lcov-report/middleware/utils.js.html +2 -2
  147. package/coverage/lcov-report/threads/automation.js.html +3 -3
  148. package/coverage/lcov-report/threads/index.html +32 -32
  149. package/coverage/lcov-report/threads/index.js.html +12 -12
  150. package/coverage/lcov-report/threads/query.js.html +560 -65
  151. package/coverage/lcov-report/threads/utils.js.html +210 -15
  152. package/coverage/lcov-report/utilities/bcrypt.js.html +1 -1
  153. package/coverage/lcov-report/utilities/budibaseDir.js.html +2 -2
  154. package/coverage/lcov-report/utilities/centralPath.js.html +1 -1
  155. package/coverage/lcov-report/utilities/csvParser.js.html +1 -1
  156. package/coverage/lcov-report/utilities/global.js.html +28 -19
  157. package/coverage/lcov-report/utilities/index.html +19 -19
  158. package/coverage/lcov-report/utilities/index.js.html +70 -37
  159. package/coverage/lcov-report/utilities/queue/inMemoryQueue.js.html +2 -2
  160. package/coverage/lcov-report/utilities/queue/index.html +1 -1
  161. package/coverage/lcov-report/utilities/routing/index.html +1 -1
  162. package/coverage/lcov-report/utilities/routing/index.js.html +1 -1
  163. package/coverage/lcov-report/utilities/rowProcessor/index.html +19 -19
  164. package/coverage/lcov-report/utilities/rowProcessor/index.js.html +247 -10
  165. package/coverage/lcov-report/utilities/rowProcessor/utils.js.html +1 -1
  166. package/coverage/lcov-report/utilities/scriptRunner.js.html +1 -1
  167. package/coverage/lcov-report/utilities/security.js.html +14 -5
  168. package/coverage/lcov-report/utilities/statusCodes.js.html +1 -1
  169. package/coverage/lcov-report/utilities/users.js.html +1 -1
  170. package/coverage/lcov-report/utilities/workerRequests.js.html +22 -22
  171. package/coverage/lcov.info +2735 -2313
  172. package/dist/api/controllers/apikeys.js +2 -2
  173. package/dist/api/controllers/application.js +4 -4
  174. package/dist/api/controllers/auth.js +1 -1
  175. package/dist/api/controllers/automation.js +7 -5
  176. package/dist/api/controllers/cloud.js +2 -2
  177. package/dist/api/controllers/datasource.js +29 -0
  178. package/dist/api/controllers/deploy/index.js +2 -2
  179. package/dist/api/controllers/dev.js +2 -2
  180. package/dist/api/controllers/hosting.js +2 -2
  181. package/dist/api/controllers/permission.js +2 -2
  182. package/dist/api/controllers/query/import/index.js +79 -0
  183. package/dist/api/controllers/query/import/sources/base/index.js +64 -0
  184. package/dist/api/controllers/query/import/sources/base/openapi.js +42 -0
  185. package/dist/api/controllers/query/import/sources/curl.js +96 -0
  186. package/dist/api/controllers/query/import/sources/openapi2.js +142 -0
  187. package/dist/api/controllers/query/import/sources/tests/openapi2/data/crud/crud.json +253 -0
  188. package/dist/api/controllers/query/import/sources/tests/openapi2/data/petstore/petstore.json +1054 -0
  189. package/dist/api/controllers/{query.js → query/index.js} +88 -56
  190. package/dist/api/controllers/query/validation.js +38 -0
  191. package/dist/api/controllers/role.js +1 -1
  192. package/dist/api/controllers/routing.js +1 -1
  193. package/dist/api/controllers/row/internal.js +14 -6
  194. package/dist/api/controllers/row/internalSearch.js +3 -2
  195. package/dist/api/controllers/row/utils.js +13 -6
  196. package/dist/api/controllers/screen.js +1 -1
  197. package/dist/api/controllers/user.js +40 -4
  198. package/dist/api/controllers/webhook.js +5 -1
  199. package/dist/api/index.js +1 -1
  200. package/dist/api/routes/apikeys.js +1 -1
  201. package/dist/api/routes/application.js +1 -1
  202. package/dist/api/routes/automation.js +1 -1
  203. package/dist/api/routes/backup.js +1 -1
  204. package/dist/api/routes/cloud.js +1 -1
  205. package/dist/api/routes/component.js +1 -1
  206. package/dist/api/routes/datasource.js +1 -1
  207. package/dist/api/routes/deploy.js +1 -1
  208. package/dist/api/routes/dev.js +1 -1
  209. package/dist/api/routes/hosting.js +1 -1
  210. package/dist/api/routes/integration.js +1 -1
  211. package/dist/api/routes/layout.js +1 -1
  212. package/dist/api/routes/metadata.js +1 -1
  213. package/dist/api/routes/permission.js +1 -1
  214. package/dist/api/routes/query.js +6 -34
  215. package/dist/api/routes/role.js +1 -1
  216. package/dist/api/routes/routing.js +1 -1
  217. package/dist/api/routes/row.js +1 -1
  218. package/dist/api/routes/screen.js +1 -1
  219. package/dist/api/routes/script.js +1 -1
  220. package/dist/api/routes/static.js +1 -1
  221. package/dist/api/routes/table.js +1 -1
  222. package/dist/api/routes/templates.js +1 -1
  223. package/dist/api/routes/tests/utilities/TestFunctions.js +1 -1
  224. package/dist/api/routes/user.js +4 -2
  225. package/dist/api/routes/view.js +1 -1
  226. package/dist/api/routes/webhook.js +1 -1
  227. package/dist/app.js +1 -1
  228. package/dist/automations/bullboard.js +1 -1
  229. package/dist/automations/steps/executeQuery.js +9 -2
  230. package/dist/automations/steps/outgoingWebhook.js +2 -3
  231. package/dist/automations/utils.js +11 -1
  232. package/dist/constants/index.js +3 -3
  233. package/dist/constants/screens.js +1 -1
  234. package/dist/db/client.js +1 -1
  235. package/dist/db/utils.js +9 -1
  236. package/dist/definitions/datasource.js +6 -1
  237. package/dist/integrations/base/sqlTable.js +1 -1
  238. package/dist/integrations/rest.js +259 -120
  239. package/dist/integrations/s3.js +1 -1
  240. package/dist/integrations/utils.js +40 -37
  241. package/dist/middleware/authorized.js +2 -2
  242. package/dist/middleware/builder.js +2 -2
  243. package/dist/middleware/currentapp.js +6 -6
  244. package/dist/middleware/usageQuota.js +1 -1
  245. package/dist/package.json +11 -4
  246. package/dist/tests/utilities/TestConfiguration.js +55 -8
  247. package/dist/tests/utilities/structures.js +2 -2
  248. package/dist/threads/automation.js +2 -2
  249. package/dist/threads/query.js +195 -38
  250. package/dist/threads/utils.js +62 -1
  251. package/dist/tsconfig.tsbuildinfo +1 -1
  252. package/dist/utilities/budibaseDir.js +1 -1
  253. package/dist/utilities/fileSystem/utilities.js +2 -1
  254. package/dist/utilities/global.js +5 -5
  255. package/dist/utilities/index.js +11 -1
  256. package/dist/utilities/redis.js +1 -1
  257. package/dist/utilities/rowProcessor/index.js +76 -0
  258. package/dist/utilities/security.js +2 -2
  259. package/dist/utilities/usageQuota.js +2 -2
  260. package/dist/utilities/workerRequests.js +3 -3
  261. package/package.json +12 -5
  262. package/scripts/replicateApp.js +1 -1
  263. package/src/api/controllers/apikeys.js +2 -2
  264. package/src/api/controllers/application.js +7 -4
  265. package/src/api/controllers/auth.js +1 -1
  266. package/src/api/controllers/automation.js +8 -4
  267. package/src/api/controllers/cloud.js +5 -2
  268. package/src/api/controllers/datasource.js +34 -0
  269. package/src/api/controllers/deploy/index.js +2 -2
  270. package/src/api/controllers/dev.js +2 -2
  271. package/src/api/controllers/hosting.js +2 -2
  272. package/src/api/controllers/permission.js +2 -2
  273. package/src/api/controllers/query/import/index.ts +85 -0
  274. package/src/api/controllers/query/import/sources/base/index.ts +87 -0
  275. package/src/api/controllers/query/import/sources/base/openapi.ts +24 -0
  276. package/src/api/controllers/query/import/sources/curl.ts +102 -0
  277. package/src/api/controllers/query/import/sources/openapi2.ts +163 -0
  278. package/src/api/controllers/query/import/sources/tests/curl/curl.spec.js +103 -0
  279. package/src/api/controllers/query/import/sources/tests/curl/data/delete.txt +1 -0
  280. package/src/api/controllers/query/import/sources/tests/curl/data/empty-body.txt +2 -0
  281. package/src/api/controllers/query/import/sources/tests/curl/data/get.txt +1 -0
  282. package/src/api/controllers/query/import/sources/tests/curl/data/headers.txt +3 -0
  283. package/src/api/controllers/query/import/sources/tests/curl/data/patch.txt +2 -0
  284. package/src/api/controllers/query/import/sources/tests/curl/data/path.txt +1 -0
  285. package/src/api/controllers/query/import/sources/tests/curl/data/post.txt +2 -0
  286. package/src/api/controllers/query/import/sources/tests/curl/data/put.txt +2 -0
  287. package/src/api/controllers/query/import/sources/tests/curl/data/query.txt +1 -0
  288. package/src/api/controllers/query/import/sources/tests/openapi2/data/crud/crud.json +253 -0
  289. package/src/api/controllers/query/import/sources/tests/openapi2/data/crud/crud.yaml +160 -0
  290. package/src/api/controllers/query/import/sources/tests/openapi2/data/petstore/petstore.json +1054 -0
  291. package/src/api/controllers/query/import/sources/tests/openapi2/data/petstore/petstore.yaml +711 -0
  292. package/src/api/controllers/query/import/sources/tests/openapi2/openapi2.spec.js +238 -0
  293. package/src/api/controllers/query/import/tests/index.spec.js +109 -0
  294. package/src/api/controllers/query/index.js +196 -0
  295. package/src/api/controllers/query/validation.js +42 -0
  296. package/src/api/controllers/role.js +1 -1
  297. package/src/api/controllers/routing.js +1 -1
  298. package/src/api/controllers/row/internal.js +14 -5
  299. package/src/api/controllers/row/internalSearch.js +3 -2
  300. package/src/api/controllers/row/utils.js +11 -8
  301. package/src/api/controllers/screen.js +1 -1
  302. package/src/api/controllers/user.js +39 -3
  303. package/src/api/controllers/webhook.js +5 -1
  304. package/src/api/index.js +1 -1
  305. package/src/api/routes/apikeys.js +1 -1
  306. package/src/api/routes/application.js +1 -1
  307. package/src/api/routes/automation.js +1 -1
  308. package/src/api/routes/backup.js +1 -1
  309. package/src/api/routes/cloud.js +1 -1
  310. package/src/api/routes/component.js +1 -1
  311. package/src/api/routes/datasource.js +1 -1
  312. package/src/api/routes/deploy.js +1 -1
  313. package/src/api/routes/dev.js +1 -1
  314. package/src/api/routes/hosting.js +1 -1
  315. package/src/api/routes/integration.js +1 -1
  316. package/src/api/routes/layout.js +1 -1
  317. package/src/api/routes/metadata.js +1 -1
  318. package/src/api/routes/permission.js +4 -1
  319. package/src/api/routes/query.js +14 -36
  320. package/src/api/routes/role.js +1 -1
  321. package/src/api/routes/routing.js +1 -1
  322. package/src/api/routes/row.js +1 -1
  323. package/src/api/routes/screen.js +1 -1
  324. package/src/api/routes/script.js +1 -1
  325. package/src/api/routes/static.js +1 -1
  326. package/src/api/routes/table.js +1 -1
  327. package/src/api/routes/templates.js +1 -1
  328. package/src/api/routes/tests/datasource.spec.js +45 -0
  329. package/src/api/routes/tests/permissions.spec.js +1 -1
  330. package/src/api/routes/tests/query.spec.js +70 -1
  331. package/src/api/routes/tests/role.spec.js +2 -2
  332. package/src/api/routes/tests/routing.spec.js +1 -1
  333. package/src/api/routes/tests/user.spec.js +1 -1
  334. package/src/api/routes/tests/utilities/TestFunctions.js +1 -1
  335. package/src/api/routes/user.js +11 -1
  336. package/src/api/routes/view.js +1 -1
  337. package/src/api/routes/webhook.js +1 -1
  338. package/src/app.ts +1 -1
  339. package/src/automations/bullboard.js +1 -1
  340. package/src/automations/steps/executeQuery.js +10 -2
  341. package/src/automations/steps/outgoingWebhook.js +2 -3
  342. package/src/automations/utils.js +12 -1
  343. package/src/constants/index.js +3 -3
  344. package/src/constants/screens.js +1 -1
  345. package/src/db/client.js +1 -1
  346. package/src/db/utils.js +10 -1
  347. package/src/definitions/common.ts +2 -16
  348. package/src/definitions/datasource.ts +98 -1
  349. package/src/integrations/base/IntegrationBase.ts +4 -4
  350. package/src/integrations/base/sqlTable.ts +1 -1
  351. package/src/integrations/rest.ts +311 -138
  352. package/src/integrations/s3.ts +1 -1
  353. package/src/integrations/tests/rest.spec.js +432 -21
  354. package/src/integrations/utils.ts +8 -7
  355. package/src/middleware/authorized.js +2 -2
  356. package/src/middleware/builder.js +2 -2
  357. package/src/middleware/currentapp.js +11 -7
  358. package/src/middleware/tests/authorized.spec.js +2 -2
  359. package/src/middleware/tests/currentapp.spec.js +35 -41
  360. package/src/middleware/tests/usageQuota.spec.js +1 -1
  361. package/src/middleware/usageQuota.js +1 -1
  362. package/src/tests/utilities/TestConfiguration.js +65 -8
  363. package/src/tests/utilities/structures.js +2 -2
  364. package/src/threads/automation.js +2 -2
  365. package/src/threads/query.js +204 -39
  366. package/src/threads/utils.js +66 -1
  367. package/src/utilities/budibaseDir.js +1 -1
  368. package/src/utilities/fileSystem/utilities.js +3 -1
  369. package/src/utilities/global.js +8 -5
  370. package/src/utilities/index.js +12 -1
  371. package/src/utilities/redis.js +1 -1
  372. package/src/utilities/rowProcessor/index.js +79 -0
  373. package/src/utilities/security.js +5 -2
  374. package/src/utilities/usageQuota.js +2 -2
  375. package/src/utilities/workerRequests.js +3 -3
  376. package/builder/assets/index.9b7f029a.js +0 -1316
  377. package/src/api/controllers/query.js +0 -161
@@ -23,7 +23,7 @@ function mockReset() {
23
23
  function mockAuthWithNoCookie() {
24
24
  jest.resetModules()
25
25
  mockWorker()
26
- jest.mock("@budibase/auth/cache", () => ({
26
+ jest.mock("@budibase/backend-core/cache", () => ({
27
27
  user: {
28
28
  getUser: () => {
29
29
  return {
@@ -32,34 +32,30 @@ function mockAuthWithNoCookie() {
32
32
  },
33
33
  },
34
34
  }))
35
- jest.mock("@budibase/auth", () => ({
36
- utils: {
37
- getAppId: jest.fn(),
38
- setCookie: jest.fn(),
39
- getCookie: jest.fn(),
40
- },
41
- constants: {
42
- Cookies: {},
43
- },
35
+ jest.mock("@budibase/backend-core/utils", () => ({
36
+ getAppId: jest.fn(),
37
+ setCookie: jest.fn(),
38
+ getCookie: jest.fn(),
39
+ }))
40
+ jest.mock("@budibase/backend-core/constants", () => ({
41
+ Cookies: {},
44
42
  }))
45
43
  }
46
44
 
47
45
  function mockAuthWithCookie() {
48
46
  jest.resetModules()
49
47
  mockWorker()
50
- jest.mock("@budibase/auth", () => ({
51
- utils: {
52
- getAppId: () => {
53
- return "app_test"
54
- },
55
- setCookie: jest.fn(),
56
- getCookie: () => ({appId: "app_different", roleId: "PUBLIC"}),
48
+ jest.mock("@budibase/backend-core/utils", () => ({
49
+ getAppId: () => {
50
+ return "app_test"
57
51
  },
58
- constants: {
59
- Cookies: {
60
- Auth: "auth",
61
- CurrentApp: "currentapp",
62
- },
52
+ setCookie: jest.fn(),
53
+ getCookie: () => ({appId: "app_different", roleId: "PUBLIC"}),
54
+ }))
55
+ jest.mock("@budibase/backend-core/constants", () => ({
56
+ Cookies: {
57
+ Auth: "auth",
58
+ CurrentApp: "currentapp",
63
59
  },
64
60
  }))
65
61
  }
@@ -121,7 +117,7 @@ describe("Current app middleware", () => {
121
117
  async function checkExpected(setCookie) {
122
118
  config.setUser()
123
119
  await config.executeMiddleware()
124
- const cookieFn = require("@budibase/auth").utils.setCookie
120
+ let { setCookie: cookieFn } = require("@budibase/backend-core/utils")
125
121
  if (setCookie) {
126
122
  expect(cookieFn).toHaveBeenCalled()
127
123
  } else {
@@ -140,32 +136,30 @@ describe("Current app middleware", () => {
140
136
 
141
137
  it("should perform correct when no cookie exists", async () => {
142
138
  mockReset()
143
- jest.mock("@budibase/auth", () => ({
144
- utils: {
145
- getAppId: () => {
146
- return "app_test"
147
- },
148
- setCookie: jest.fn(),
149
- getCookie: jest.fn(),
150
- },
151
- constants: {
152
- Cookies: {},
139
+ jest.mock("@budibase/backend-core/utils", () => ({
140
+ getAppId: () => {
141
+ return "app_test"
153
142
  },
143
+ setCookie: jest.fn(),
144
+ getCookie: jest.fn(),
145
+ }))
146
+ jest.mock("@budibase/backend-core/constants", () => ({
147
+ Cookies: {},
154
148
  }))
155
149
  await checkExpected(true)
156
150
  })
157
151
 
158
152
  it("lastly check what occurs when cookie doesn't need updated", async () => {
159
153
  mockReset()
160
- jest.mock("@budibase/auth", () => ({
161
- utils: {
162
- getAppId: () => {
163
- return "app_test"
164
- },
165
- setCookie: jest.fn(),
166
- getCookie: () => ({appId: "app_test", roleId: "PUBLIC"}),
154
+ jest.mock("@budibase/backend-core/utils", () => ({
155
+ getAppId: () => {
156
+ return "app_test"
167
157
  },
168
- constants: { Cookies: {} },
158
+ setCookie: jest.fn(),
159
+ getCookie: () => ({appId: "app_test", roleId: "PUBLIC"}),
160
+ }))
161
+ jest.mock("@budibase/backend-core/constants", () => ({
162
+ Cookies: {},
169
163
  }))
170
164
  await checkExpected(false)
171
165
  })
@@ -6,7 +6,7 @@ jest.mock("../../environment", () => ({
6
6
  isDev: () => true,
7
7
  _set: () => {},
8
8
  }))
9
- jest.mock("@budibase/auth/tenancy", () => ({
9
+ jest.mock("@budibase/backend-core/tenancy", () => ({
10
10
  getTenantId: () => "testing123"
11
11
  }))
12
12
 
@@ -1,7 +1,7 @@
1
1
  const CouchDB = require("../db")
2
2
  const usageQuota = require("../utilities/usageQuota")
3
3
  const env = require("../environment")
4
- const { getTenantId } = require("@budibase/auth/tenancy")
4
+ const { getTenantId } = require("@budibase/backend-core/tenancy")
5
5
  const {
6
6
  isExternalTable,
7
7
  isRowId: isExternalRowId,
@@ -1,4 +1,4 @@
1
- const { BUILTIN_ROLE_IDS } = require("@budibase/auth/roles")
1
+ const { BUILTIN_ROLE_IDS } = require("@budibase/backend-core/roles")
2
2
  const env = require("../../environment")
3
3
  const {
4
4
  basicTable,
@@ -15,14 +15,14 @@ const {
15
15
  const controllers = require("./controllers")
16
16
  const supertest = require("supertest")
17
17
  const { cleanup } = require("../../utilities/fileSystem")
18
- const { Cookies, Headers } = require("@budibase/auth").constants
19
- const { jwt } = require("@budibase/auth").auth
20
- const auth = require("@budibase/auth")
21
- const { getGlobalDB } = require("@budibase/auth/tenancy")
22
- const { createASession } = require("@budibase/auth/sessions")
23
- const { user: userCache } = require("@budibase/auth/cache")
18
+ const { Cookies, Headers } = require("@budibase/backend-core/constants")
19
+ const { jwt } = require("@budibase/backend-core/auth")
20
+ const core = require("@budibase/backend-core")
21
+ const { getGlobalDB } = require("@budibase/backend-core/tenancy")
22
+ const { createASession } = require("@budibase/backend-core/sessions")
23
+ const { user: userCache } = require("@budibase/backend-core/cache")
24
24
  const CouchDB = require("../../db")
25
- auth.init(CouchDB)
25
+ core.init(CouchDB)
26
26
 
27
27
  const GLOBAL_USER_ID = "us_uuid1"
28
28
  const EMAIL = "babs@babs.com"
@@ -316,6 +316,63 @@ class TestConfiguration {
316
316
  return this.datasource
317
317
  }
318
318
 
319
+ async updateDatasource(datasource) {
320
+ const response = await this._req(
321
+ datasource,
322
+ { datasourceId: datasource._id },
323
+ controllers.datasource.update
324
+ )
325
+ this.datasource = response.datasource
326
+ return this.datasource
327
+ }
328
+
329
+ async restDatasource(cfg) {
330
+ return this.createDatasource({
331
+ datasource: {
332
+ ...basicDatasource().datasource,
333
+ source: "REST",
334
+ config: cfg || {},
335
+ },
336
+ })
337
+ }
338
+
339
+ async dynamicVariableDatasource() {
340
+ let datasource = await this.restDatasource()
341
+ const basedOnQuery = await this.createQuery({
342
+ ...basicQuery(datasource._id),
343
+ fields: {
344
+ path: "www.google.com",
345
+ },
346
+ })
347
+ datasource = await this.updateDatasource({
348
+ ...datasource,
349
+ config: {
350
+ dynamicVariables: [
351
+ {
352
+ queryId: basedOnQuery._id,
353
+ name: "variable3",
354
+ value: "{{ data.0.[value] }}",
355
+ },
356
+ ],
357
+ },
358
+ })
359
+ return { datasource, query: basedOnQuery }
360
+ }
361
+
362
+ async previewQuery(request, config, datasource, fields) {
363
+ return request
364
+ .post(`/api/queries/preview`)
365
+ .send({
366
+ datasourceId: datasource._id,
367
+ parameters: {},
368
+ fields,
369
+ queryVerb: "read",
370
+ })
371
+ .set(config.defaultHeaders())
372
+ .expect("Content-Type", /json/)
373
+ .expect(200)
374
+ }
375
+
319
376
  async createQuery(config = null) {
320
377
  if (!this.datasource && !config) {
321
378
  throw "No data source created for query."
@@ -1,5 +1,5 @@
1
- const { BUILTIN_ROLE_IDS } = require("@budibase/auth/roles")
2
- const { BUILTIN_PERMISSION_IDS } = require("@budibase/auth/permissions")
1
+ const { BUILTIN_ROLE_IDS } = require("@budibase/backend-core/roles")
2
+ const { BUILTIN_PERMISSION_IDS } = require("@budibase/backend-core/permissions")
3
3
  const { createHomeScreen } = require("../../constants/screens")
4
4
  const { EMPTY_LAYOUT } = require("../../constants/layouts")
5
5
  const { cloneDeep } = require("lodash/fp")
@@ -4,10 +4,10 @@ const actions = require("../automations/actions")
4
4
  const automationUtils = require("../automations/automationUtils")
5
5
  const AutomationEmitter = require("../events/AutomationEmitter")
6
6
  const { processObject } = require("@budibase/string-templates")
7
- const { DEFAULT_TENANT_ID } = require("@budibase/auth").constants
7
+ const { DEFAULT_TENANT_ID } = require("@budibase/backend-core/constants")
8
8
  const CouchDB = require("../db")
9
9
  const { DocumentTypes, isDevAppID } = require("../db/utils")
10
- const { doInTenant } = require("@budibase/auth/tenancy")
10
+ const { doInTenant } = require("@budibase/backend-core/tenancy")
11
11
  const usage = require("../utilities/usageQuota")
12
12
  const { definitions: triggerDefs } = require("../automations/triggerInfo")
13
13
 
@@ -1,60 +1,225 @@
1
- require("./utils").threadSetup()
1
+ const threadUtils = require("./utils")
2
+ threadUtils.threadSetup()
2
3
  const ScriptRunner = require("../utilities/scriptRunner")
3
4
  const { integrations } = require("../integrations")
5
+ const { processStringSync } = require("@budibase/string-templates")
6
+ const CouchDB = require("../db")
4
7
 
5
- function formatResponse(resp) {
6
- if (typeof resp === "string") {
7
- try {
8
- resp = JSON.parse(resp)
9
- } catch (err) {
10
- resp = { response: resp }
11
- }
12
- }
13
- return resp
14
- }
8
+ const IS_TRIPLE_BRACE = new RegExp(/^{{3}.*}{3}$/)
9
+ const IS_HANDLEBARS = new RegExp(/^{{2}.*}{2}$/)
15
10
 
16
- async function runAndTransform(datasource, queryVerb, query, transformer) {
17
- const Integration = integrations[datasource.source]
18
- if (!Integration) {
19
- throw "Integration type does not exist."
11
+ class QueryRunner {
12
+ constructor(input, flags = { noRecursiveQuery: false }) {
13
+ this.appId = input.appId
14
+ this.datasource = input.datasource
15
+ this.queryVerb = input.queryVerb
16
+ this.fields = input.fields
17
+ this.parameters = input.parameters
18
+ this.pagination = input.pagination
19
+ this.transformer = input.transformer
20
+ this.queryId = input.queryId
21
+ this.noRecursiveQuery = flags.noRecursiveQuery
22
+ this.cachedVariables = []
23
+ // allows the response from a query to be stored throughout this
24
+ // execution so that if it needs to be re-used for another variable
25
+ // it can be
26
+ this.queryResponse = {}
27
+ this.hasRerun = false
20
28
  }
21
- const integration = new Integration(datasource.config)
22
29
 
23
- let rows = formatResponse(await integration[queryVerb](query))
30
+ async execute() {
31
+ let { datasource, fields, queryVerb, transformer } = this
32
+ // pre-query, make sure datasource variables are added to parameters
33
+ const parameters = await this.addDatasourceVariables()
34
+ let query = this.enrichQueryFields(fields, parameters)
24
35
 
25
- // transform as required
26
- if (transformer) {
27
- const runner = new ScriptRunner(transformer, { data: rows })
28
- rows = runner.execute()
29
- }
36
+ // Add pagination values for REST queries
37
+ if (this.pagination) {
38
+ query.paginationValues = this.pagination
39
+ }
40
+
41
+ const Integration = integrations[datasource.source]
42
+ if (!Integration) {
43
+ throw "Integration type does not exist."
44
+ }
45
+ const integration = new Integration(datasource.config)
46
+
47
+ let output = threadUtils.formatResponse(await integration[queryVerb](query))
48
+ let rows = output,
49
+ info = undefined,
50
+ extra = undefined,
51
+ pagination = undefined
52
+ if (threadUtils.hasExtraData(output)) {
53
+ rows = output.data
54
+ info = output.info
55
+ extra = output.extra
56
+ pagination = output.pagination
57
+ }
58
+
59
+ // transform as required
60
+ if (transformer) {
61
+ const runner = new ScriptRunner(transformer, {
62
+ data: rows,
63
+ params: parameters,
64
+ })
65
+ rows = runner.execute()
66
+ }
67
+
68
+ // if the request fails we retry once, invalidating the cached value
69
+ if (
70
+ info &&
71
+ info.code >= 400 &&
72
+ this.cachedVariables.length > 0 &&
73
+ !this.hasRerun
74
+ ) {
75
+ this.hasRerun = true
76
+ // invalidate the cache value
77
+ await threadUtils.invalidateDynamicVariables(this.cachedVariables)
78
+ return this.execute()
79
+ }
80
+
81
+ // needs to an array for next step
82
+ if (!Array.isArray(rows)) {
83
+ rows = [rows]
84
+ }
30
85
 
31
- // needs to an array for next step
32
- if (!Array.isArray(rows)) {
33
- rows = [rows]
86
+ // map into JSON if just raw primitive here
87
+ if (rows.find(row => typeof row !== "object")) {
88
+ rows = rows.map(value => ({ value }))
89
+ }
90
+
91
+ // get all the potential fields in the schema
92
+ let keys = rows.flatMap(Object.keys)
93
+
94
+ if (integration.end) {
95
+ integration.end()
96
+ }
97
+
98
+ return { rows, keys, info, extra, pagination }
34
99
  }
35
100
 
36
- // map into JSON if just raw primitive here
37
- if (rows.find(row => typeof row !== "object")) {
38
- rows = rows.map(value => ({ value }))
101
+ async runAnotherQuery(queryId, parameters) {
102
+ const db = new CouchDB(this.appId)
103
+ const query = await db.get(queryId)
104
+ const datasource = await db.get(query.datasourceId)
105
+ return new QueryRunner(
106
+ {
107
+ appId: this.appId,
108
+ datasource,
109
+ queryVerb: query.queryVerb,
110
+ fields: query.fields,
111
+ parameters,
112
+ transformer: query.transformer,
113
+ },
114
+ { noRecursiveQuery: true }
115
+ ).execute()
39
116
  }
40
117
 
41
- // get all the potential fields in the schema
42
- let keys = rows.flatMap(Object.keys)
118
+ async getDynamicVariable(variable) {
119
+ let { parameters } = this
120
+ const queryId = variable.queryId,
121
+ name = variable.name
122
+ let value = await threadUtils.checkCacheForDynamicVariable(queryId, name)
123
+ if (!value) {
124
+ value = this.queryResponse[queryId]
125
+ ? this.queryResponse[queryId]
126
+ : await this.runAnotherQuery(queryId, parameters)
127
+ // store incase this query is to be called again
128
+ this.queryResponse[queryId] = value
129
+ await threadUtils.storeDynamicVariable(queryId, name, value)
130
+ } else {
131
+ this.cachedVariables.push({ queryId, name })
132
+ }
133
+ return value
134
+ }
43
135
 
44
- if (integration.end) {
45
- integration.end()
136
+ async addDatasourceVariables() {
137
+ let { datasource, parameters, fields } = this
138
+ if (!datasource || !datasource.config) {
139
+ return parameters
140
+ }
141
+ const staticVars = datasource.config.staticVariables || {}
142
+ const dynamicVars = datasource.config.dynamicVariables || []
143
+ for (let [key, value] of Object.entries(staticVars)) {
144
+ if (!parameters[key]) {
145
+ parameters[key] = value
146
+ }
147
+ }
148
+ if (!this.noRecursiveQuery) {
149
+ // need to see if this uses any variables
150
+ const stringFields = JSON.stringify(fields)
151
+ const foundVars = dynamicVars.filter(variable => {
152
+ // don't allow a query to use its own dynamic variable (loop)
153
+ if (variable.queryId === this.queryId) {
154
+ return false
155
+ }
156
+ // look for {{ variable }} but allow spaces between handlebars
157
+ const regex = new RegExp(`{{[ ]*${variable.name}[ ]*}}`)
158
+ return regex.test(stringFields)
159
+ })
160
+ const dynamics = foundVars.map(dynVar => this.getDynamicVariable(dynVar))
161
+ const responses = await Promise.all(dynamics)
162
+ for (let i = 0; i < foundVars.length; i++) {
163
+ const variable = foundVars[i]
164
+ parameters[variable.name] = processStringSync(variable.value, {
165
+ data: responses[i].rows,
166
+ info: responses[i].extra,
167
+ })
168
+ // make sure its known that this uses dynamic variables in case it fails
169
+ this.hasDynamicVariables = true
170
+ }
171
+ }
172
+ return parameters
46
173
  }
47
174
 
48
- return { rows, keys }
175
+ enrichQueryFields(fields, parameters = {}) {
176
+ const enrichedQuery = {}
177
+
178
+ // enrich the fields with dynamic parameters
179
+ for (let key of Object.keys(fields)) {
180
+ if (fields[key] == null) {
181
+ continue
182
+ }
183
+ if (typeof fields[key] === "object") {
184
+ // enrich nested fields object
185
+ enrichedQuery[key] = this.enrichQueryFields(fields[key], parameters)
186
+ } else if (typeof fields[key] === "string") {
187
+ // enrich string value as normal
188
+ let value = fields[key]
189
+ // add triple brace to avoid escaping e.g. '=' in cookie header
190
+ if (IS_HANDLEBARS.test(value) && !IS_TRIPLE_BRACE.test(value)) {
191
+ value = `{${value}}`
192
+ }
193
+ enrichedQuery[key] = processStringSync(value, parameters, {
194
+ noHelpers: true,
195
+ })
196
+ } else {
197
+ enrichedQuery[key] = fields[key]
198
+ }
199
+ }
200
+ if (
201
+ enrichedQuery.json ||
202
+ enrichedQuery.customData ||
203
+ enrichedQuery.requestBody
204
+ ) {
205
+ try {
206
+ enrichedQuery.json = JSON.parse(
207
+ enrichedQuery.json ||
208
+ enrichedQuery.customData ||
209
+ enrichedQuery.requestBody
210
+ )
211
+ } catch (err) {
212
+ // no json found, ignore
213
+ }
214
+ delete enrichedQuery.customData
215
+ }
216
+ return enrichedQuery
217
+ }
49
218
  }
50
219
 
51
220
  module.exports = (input, callback) => {
52
- runAndTransform(
53
- input.datasource,
54
- input.queryVerb,
55
- input.query,
56
- input.transformer
57
- )
221
+ const Runner = new QueryRunner(input)
222
+ Runner.execute()
58
223
  .then(response => {
59
224
  callback(null, response)
60
225
  })
@@ -1,6 +1,22 @@
1
1
  const env = require("../environment")
2
2
  const CouchDB = require("../db")
3
- const { init } = require("@budibase/auth")
3
+ const { init } = require("@budibase/backend-core")
4
+ const redis = require("@budibase/backend-core/redis")
5
+ const { SEPARATOR } = require("@budibase/backend-core/db")
6
+
7
+ const VARIABLE_TTL_SECONDS = 3600
8
+ let client
9
+
10
+ async function getClient() {
11
+ if (!client) {
12
+ client = await new redis.Client(redis.utils.Databases.QUERY_VARS).init()
13
+ }
14
+ return client
15
+ }
16
+
17
+ process.on("exit", async () => {
18
+ if (client) await client.finish()
19
+ })
4
20
 
5
21
  exports.threadSetup = () => {
6
22
  // don't run this if not threading
@@ -11,3 +27,52 @@ exports.threadSetup = () => {
11
27
  env.setInThread()
12
28
  init(CouchDB)
13
29
  }
30
+
31
+ function makeVariableKey(queryId, variable) {
32
+ return `${queryId}${SEPARATOR}${variable}`
33
+ }
34
+
35
+ exports.checkCacheForDynamicVariable = async (queryId, variable) => {
36
+ const cache = await getClient()
37
+ return cache.get(makeVariableKey(queryId, variable))
38
+ }
39
+
40
+ exports.invalidateDynamicVariables = async cachedVars => {
41
+ const cache = await getClient()
42
+ let promises = []
43
+ for (let variable of cachedVars) {
44
+ promises.push(
45
+ cache.delete(makeVariableKey(variable.queryId, variable.name))
46
+ )
47
+ }
48
+ await Promise.all(promises)
49
+ }
50
+
51
+ exports.storeDynamicVariable = async (queryId, variable, value) => {
52
+ const cache = await getClient()
53
+ await cache.store(
54
+ makeVariableKey(queryId, variable),
55
+ value,
56
+ VARIABLE_TTL_SECONDS
57
+ )
58
+ }
59
+
60
+ exports.formatResponse = resp => {
61
+ if (typeof resp === "string") {
62
+ try {
63
+ resp = JSON.parse(resp)
64
+ } catch (err) {
65
+ resp = { response: resp }
66
+ }
67
+ }
68
+ return resp
69
+ }
70
+
71
+ exports.hasExtraData = response => {
72
+ return (
73
+ typeof response === "object" &&
74
+ !Array.isArray(response) &&
75
+ response.data != null &&
76
+ response.info != null
77
+ )
78
+ }
@@ -1,7 +1,7 @@
1
1
  const { join } = require("./centralPath")
2
2
  const { homedir } = require("os")
3
3
  const env = require("../environment")
4
- const { budibaseTempDir } = require("@budibase/auth").objectStore
4
+ const { budibaseTempDir } = require("@budibase/backend-core/objectStore")
5
5
 
6
6
  module.exports.budibaseAppsDir = function () {
7
7
  return env.BUDIBASE_DIR || join(homedir(), ".budibase")
@@ -2,13 +2,14 @@ const {
2
2
  ObjectStore,
3
3
  makeSureBucketExists,
4
4
  upload,
5
+ deleteFiles,
5
6
  streamUpload,
6
7
  retrieve,
7
8
  retrieveToTmp,
8
9
  deleteFolder,
9
10
  uploadDirectory,
10
11
  downloadTarball,
11
- } = require("@budibase/auth").objectStore
12
+ } = require("@budibase/backend-core/objectStore")
12
13
 
13
14
  /***********************************
14
15
  * NOTE *
@@ -28,3 +29,4 @@ exports.retrieveToTmp = retrieveToTmp
28
29
  exports.deleteFolder = deleteFolder
29
30
  exports.uploadDirectory = uploadDirectory
30
31
  exports.downloadTarball = downloadTarball
32
+ exports.deleteFiles = deleteFiles
@@ -2,11 +2,14 @@ const {
2
2
  getMultiIDParams,
3
3
  getGlobalIDFromUserMetadataID,
4
4
  } = require("../db/utils")
5
- const { BUILTIN_ROLE_IDS } = require("@budibase/auth/roles")
6
- const { getDeployedAppID } = require("@budibase/auth/db")
7
- const { getGlobalUserParams } = require("@budibase/auth/db")
8
- const { user: userCache } = require("@budibase/auth/cache")
9
- const { getGlobalDB, isUserInAppTenant } = require("@budibase/auth/tenancy")
5
+ const { BUILTIN_ROLE_IDS } = require("@budibase/backend-core/roles")
6
+ const { getDeployedAppID } = require("@budibase/backend-core/db")
7
+ const { getGlobalUserParams } = require("@budibase/backend-core/db")
8
+ const { user: userCache } = require("@budibase/backend-core/cache")
9
+ const {
10
+ getGlobalDB,
11
+ isUserInAppTenant,
12
+ } = require("@budibase/backend-core/tenancy")
10
13
  const env = require("../environment")
11
14
 
12
15
  exports.updateAppRole = (appId, user) => {
@@ -1,6 +1,6 @@
1
1
  const env = require("../environment")
2
2
  const { OBJ_STORE_DIRECTORY } = require("../constants")
3
- const { sanitizeKey } = require("@budibase/auth/src/objectStore")
3
+ const { sanitizeKey } = require("@budibase/backend-core/objectStore")
4
4
  const CouchDB = require("../db")
5
5
  const { generateMetadataID } = require("../db/utils")
6
6
  const Readable = require("stream").Readable
@@ -150,3 +150,14 @@ exports.doesDatabaseExist = async dbName => {
150
150
  return false
151
151
  }
152
152
  }
153
+
154
+ exports.formatBytes = bytes => {
155
+ const units = ["B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"]
156
+ const byteIncrements = 1024
157
+ let unit = 0
158
+ let size = parseInt(bytes, 10) || 0
159
+ while (size >= byteIncrements && ++unit) {
160
+ size /= byteIncrements
161
+ }
162
+ return `${size.toFixed(size < 10 && unit > 0 ? 1 : 0)}${units[unit]}`
163
+ }
@@ -1,4 +1,4 @@
1
- const { Client, utils } = require("@budibase/auth/redis")
1
+ const { Client, utils } = require("@budibase/backend-core/redis")
2
2
  const { getGlobalIDFromUserMetadataID } = require("../db/utils")
3
3
 
4
4
  const APP_DEV_LOCK_SECONDS = 600