@budibase/server 1.0.49-alpha.9 → 1.0.49

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 (379) hide show
  1. package/__mocks__/arangojs.ts +1 -1
  2. package/__mocks__/aws-sdk.ts +4 -4
  3. package/__mocks__/mongodb.ts +5 -4
  4. package/__mocks__/mssql.ts +3 -3
  5. package/__mocks__/node-fetch.ts +1 -2
  6. package/__mocks__/pg.ts +5 -3
  7. package/builder/assets/{index.ad5370ae.js → index.2c37968e.js} +246 -249
  8. package/builder/assets/index.39e01193.css +1 -0
  9. package/builder/assets/{vendor.d526bfe8.js → vendor.f9faf6ab.js} +12 -12
  10. package/builder/index.html +3 -3
  11. package/coverage/clover.xml +2827 -3117
  12. package/coverage/coverage-final.json +101 -106
  13. package/coverage/lcov-report/api/controllers/analytics.js.html +1 -1
  14. package/coverage/lcov-report/api/controllers/apikeys.js.html +1 -1
  15. package/coverage/lcov-report/api/controllers/application.js.html +152 -257
  16. package/coverage/lcov-report/api/controllers/auth.js.html +13 -22
  17. package/coverage/lcov-report/api/controllers/automation.js.html +69 -39
  18. package/coverage/lcov-report/api/controllers/backup.js.html +1 -1
  19. package/coverage/lcov-report/api/controllers/cloud.js.html +11 -8
  20. package/coverage/lcov-report/api/controllers/component.js.html +16 -13
  21. package/coverage/lcov-report/api/controllers/datasource.js.html +51 -81
  22. package/coverage/lcov-report/api/controllers/dev.js.html +6 -6
  23. package/coverage/lcov-report/{utilities/usageQuota/usageQuoteReset.js.html → api/controllers/hosting.js.html} +48 -36
  24. package/coverage/lcov-report/api/controllers/index.html +76 -76
  25. package/coverage/lcov-report/api/controllers/integration.js.html +1 -1
  26. package/coverage/lcov-report/api/controllers/layout.js.html +9 -9
  27. package/coverage/lcov-report/api/controllers/metadata.js.html +21 -6
  28. package/coverage/lcov-report/api/controllers/permission.js.html +19 -19
  29. package/coverage/lcov-report/api/controllers/query/index.html +10 -10
  30. package/coverage/lcov-report/api/controllers/query/index.js.html +35 -38
  31. package/coverage/lcov-report/api/controllers/query/validation.js.html +6 -6
  32. package/coverage/lcov-report/api/controllers/role.js.html +16 -16
  33. package/coverage/lcov-report/api/controllers/routing.js.html +10 -7
  34. package/coverage/lcov-report/api/controllers/row/external.js.html +141 -48
  35. package/coverage/lcov-report/api/controllers/row/index.html +40 -55
  36. package/coverage/lcov-report/api/controllers/row/index.js.html +26 -26
  37. package/coverage/lcov-report/api/controllers/row/internal.js.html +226 -118
  38. package/coverage/lcov-report/api/controllers/row/internalSearch.js.html +34 -52
  39. package/coverage/lcov-report/api/controllers/row/utils.js.html +62 -47
  40. package/coverage/lcov-report/api/controllers/screen.js.html +21 -15
  41. package/coverage/lcov-report/api/controllers/script.js.html +4 -4
  42. package/coverage/lcov-report/api/controllers/table/external.js.html +34 -25
  43. package/coverage/lcov-report/api/controllers/table/index.html +43 -58
  44. package/coverage/lcov-report/api/controllers/table/index.js.html +82 -58
  45. package/coverage/lcov-report/api/controllers/table/internal.js.html +66 -81
  46. package/coverage/lcov-report/api/controllers/table/utils.js.html +110 -218
  47. package/coverage/lcov-report/api/controllers/templates.js.html +1 -1
  48. package/coverage/lcov-report/api/controllers/user.js.html +50 -47
  49. package/coverage/lcov-report/api/controllers/view/exporters.js.html +4 -4
  50. package/coverage/lcov-report/api/controllers/view/index.html +16 -16
  51. package/coverage/lcov-report/api/controllers/view/index.js.html +33 -27
  52. package/coverage/lcov-report/api/controllers/view/utils.js.html +20 -35
  53. package/coverage/lcov-report/api/controllers/view/viewBuilder.js.html +7 -7
  54. package/coverage/lcov-report/api/controllers/webhook.js.html +28 -34
  55. package/coverage/lcov-report/api/index.html +1 -1
  56. package/coverage/lcov-report/api/index.js.html +8 -8
  57. package/coverage/lcov-report/api/routes/analytics.js.html +1 -1
  58. package/coverage/lcov-report/api/routes/apikeys.js.html +1 -1
  59. package/coverage/lcov-report/api/routes/application.js.html +1 -1
  60. package/coverage/lcov-report/api/routes/auth.js.html +1 -1
  61. package/coverage/lcov-report/api/routes/automation.js.html +1 -1
  62. package/coverage/lcov-report/api/routes/backup.js.html +1 -1
  63. package/coverage/lcov-report/api/routes/cloud.js.html +1 -1
  64. package/coverage/lcov-report/api/routes/component.js.html +1 -1
  65. package/coverage/lcov-report/api/routes/datasource.js.html +1 -1
  66. package/coverage/lcov-report/api/routes/deploy.js.html +1 -1
  67. package/coverage/lcov-report/api/routes/dev.js.html +1 -1
  68. package/coverage/lcov-report/api/routes/{migrations.js.html → hosting.js.html} +14 -17
  69. package/coverage/lcov-report/api/routes/index.html +18 -18
  70. package/coverage/lcov-report/api/routes/index.js.html +3 -3
  71. package/coverage/lcov-report/api/routes/integration.js.html +1 -1
  72. package/coverage/lcov-report/api/routes/layout.js.html +1 -1
  73. package/coverage/lcov-report/api/routes/metadata.js.html +1 -1
  74. package/coverage/lcov-report/api/routes/permission.js.html +1 -1
  75. package/coverage/lcov-report/api/routes/query.js.html +1 -1
  76. package/coverage/lcov-report/api/routes/role.js.html +1 -1
  77. package/coverage/lcov-report/api/routes/routing.js.html +1 -1
  78. package/coverage/lcov-report/api/routes/row.js.html +1 -1
  79. package/coverage/lcov-report/api/routes/screen.js.html +1 -1
  80. package/coverage/lcov-report/api/routes/script.js.html +1 -1
  81. package/coverage/lcov-report/api/routes/static.js.html +2 -17
  82. package/coverage/lcov-report/api/routes/table.js.html +1 -1
  83. package/coverage/lcov-report/api/routes/templates.js.html +1 -1
  84. package/coverage/lcov-report/api/routes/user.js.html +1 -1
  85. package/coverage/lcov-report/api/routes/view.js.html +1 -1
  86. package/coverage/lcov-report/api/routes/webhook.js.html +1 -1
  87. package/coverage/lcov-report/automations/actions.js.html +24 -24
  88. package/coverage/lcov-report/automations/automationUtils.js.html +10 -7
  89. package/coverage/lcov-report/automations/bullboard.js.html +16 -16
  90. package/coverage/lcov-report/automations/index.html +18 -18
  91. package/coverage/lcov-report/automations/index.js.html +1 -1
  92. package/coverage/lcov-report/automations/steps/bash.js.html +6 -6
  93. package/coverage/lcov-report/automations/steps/createRow.js.html +22 -13
  94. package/coverage/lcov-report/automations/steps/delay.js.html +4 -4
  95. package/coverage/lcov-report/automations/steps/deleteRow.js.html +20 -11
  96. package/coverage/lcov-report/automations/steps/discord.js.html +7 -7
  97. package/coverage/lcov-report/automations/steps/executeQuery.js.html +6 -6
  98. package/coverage/lcov-report/automations/steps/executeScript.js.html +6 -6
  99. package/coverage/lcov-report/automations/steps/filter.js.html +7 -7
  100. package/coverage/lcov-report/automations/steps/index.html +13 -13
  101. package/coverage/lcov-report/automations/steps/integromat.js.html +5 -5
  102. package/coverage/lcov-report/automations/steps/outgoingWebhook.js.html +8 -8
  103. package/coverage/lcov-report/automations/steps/queryRows.js.html +10 -10
  104. package/coverage/lcov-report/automations/steps/sendSmtpEmail.js.html +5 -5
  105. package/coverage/lcov-report/automations/steps/serverLog.js.html +3 -3
  106. package/coverage/lcov-report/automations/steps/slack.js.html +5 -5
  107. package/coverage/lcov-report/automations/steps/updateRow.js.html +7 -7
  108. package/coverage/lcov-report/automations/steps/utils.js.html +3 -3
  109. package/coverage/lcov-report/automations/steps/zapier.js.html +5 -5
  110. package/coverage/lcov-report/automations/triggerInfo/app.js.html +2 -2
  111. package/coverage/lcov-report/automations/triggerInfo/cron.js.html +2 -2
  112. package/coverage/lcov-report/automations/triggerInfo/index.html +1 -1
  113. package/coverage/lcov-report/automations/triggerInfo/index.js.html +8 -8
  114. package/coverage/lcov-report/automations/triggerInfo/rowDeleted.js.html +2 -2
  115. package/coverage/lcov-report/automations/triggerInfo/rowSaved.js.html +2 -2
  116. package/coverage/lcov-report/automations/triggerInfo/rowUpdated.js.html +2 -2
  117. package/coverage/lcov-report/automations/triggerInfo/webhook.js.html +2 -2
  118. package/coverage/lcov-report/automations/triggers.js.html +55 -61
  119. package/coverage/lcov-report/automations/utils.js.html +42 -54
  120. package/coverage/lcov-report/constants/index.html +5 -5
  121. package/coverage/lcov-report/constants/index.js.html +26 -53
  122. package/coverage/lcov-report/constants/layouts.js.html +5 -5
  123. package/coverage/lcov-report/constants/screens.js.html +4 -4
  124. package/coverage/lcov-report/db/client.js.html +18 -18
  125. package/coverage/lcov-report/db/inMemoryView.js.html +7 -7
  126. package/coverage/lcov-report/db/index.html +15 -15
  127. package/coverage/lcov-report/db/index.js.html +3 -3
  128. package/coverage/lcov-report/db/linkedRows/LinkController.js.html +37 -25
  129. package/coverage/lcov-report/db/linkedRows/index.html +27 -27
  130. package/coverage/lcov-report/db/linkedRows/index.js.html +96 -51
  131. package/coverage/lcov-report/db/linkedRows/linkUtils.js.html +42 -42
  132. package/coverage/lcov-report/db/newid.js.html +4 -4
  133. package/coverage/lcov-report/db/utils.js.html +87 -87
  134. package/coverage/lcov-report/events/AutomationEmitter.js.html +1 -1
  135. package/coverage/lcov-report/events/index.html +1 -1
  136. package/coverage/lcov-report/events/index.js.html +5 -5
  137. package/coverage/lcov-report/events/utils.js.html +3 -3
  138. package/coverage/lcov-report/index.html +120 -135
  139. package/coverage/lcov-report/integrations/tests/TestConfiguration.js.html +1 -1
  140. package/coverage/lcov-report/integrations/tests/index.html +1 -1
  141. package/coverage/lcov-report/middleware/appInfo.js.html +1 -1
  142. package/coverage/lcov-report/middleware/authorized.js.html +65 -173
  143. package/coverage/lcov-report/middleware/builder.js.html +10 -10
  144. package/coverage/lcov-report/middleware/currentapp.js.html +83 -95
  145. package/coverage/lcov-report/middleware/index.html +38 -38
  146. package/coverage/lcov-report/middleware/joi-validator.js.html +3 -3
  147. package/coverage/lcov-report/middleware/resourceId.js.html +1 -1
  148. package/coverage/lcov-report/middleware/selfhost.js.html +1 -1
  149. package/coverage/lcov-report/middleware/usageQuota.js.html +53 -281
  150. package/coverage/lcov-report/middleware/utils.js.html +2 -2
  151. package/coverage/lcov-report/threads/automation.js.html +24 -30
  152. package/coverage/lcov-report/threads/index.html +26 -26
  153. package/coverage/lcov-report/threads/index.js.html +10 -10
  154. package/coverage/lcov-report/threads/query.js.html +24 -39
  155. package/coverage/lcov-report/threads/utils.js.html +14 -14
  156. package/coverage/lcov-report/utilities/bcrypt.js.html +1 -1
  157. package/coverage/lcov-report/utilities/budibaseDir.js.html +7 -7
  158. package/coverage/lcov-report/utilities/centralPath.js.html +4 -4
  159. package/coverage/lcov-report/utilities/csvParser.js.html +6 -6
  160. package/coverage/lcov-report/utilities/global.js.html +49 -58
  161. package/coverage/lcov-report/utilities/index.html +37 -37
  162. package/coverage/lcov-report/utilities/index.js.html +73 -43
  163. package/coverage/lcov-report/utilities/queue/inMemoryQueue.js.html +8 -8
  164. package/coverage/lcov-report/utilities/queue/index.html +1 -1
  165. package/coverage/lcov-report/utilities/routing/index.html +1 -1
  166. package/coverage/lcov-report/utilities/routing/index.js.html +7 -7
  167. package/coverage/lcov-report/utilities/rowProcessor/index.html +27 -27
  168. package/coverage/lcov-report/utilities/rowProcessor/index.js.html +103 -97
  169. package/coverage/lcov-report/utilities/rowProcessor/utils.js.html +27 -75
  170. package/coverage/lcov-report/utilities/scriptRunner.js.html +5 -5
  171. package/coverage/lcov-report/utilities/security.js.html +8 -8
  172. package/coverage/lcov-report/utilities/statusCodes.js.html +1 -1
  173. package/coverage/lcov-report/utilities/users.js.html +9 -9
  174. package/coverage/lcov-report/utilities/workerRequests.js.html +112 -43
  175. package/coverage/lcov.info +4431 -5013
  176. package/dist/api/controllers/application.js +60 -90
  177. package/dist/api/controllers/auth.js +5 -8
  178. package/dist/api/controllers/automation.js +19 -14
  179. package/dist/api/controllers/cloud.js +3 -2
  180. package/dist/api/controllers/component.js +4 -3
  181. package/dist/api/controllers/datasource.js +10 -20
  182. package/dist/api/controllers/deploy/Deployment.js +6 -3
  183. package/dist/api/controllers/deploy/index.js +13 -12
  184. package/dist/api/controllers/dev.js +5 -5
  185. package/dist/api/controllers/hosting.js +30 -0
  186. package/dist/api/controllers/layout.js +3 -3
  187. package/dist/api/controllers/metadata.js +4 -4
  188. package/dist/api/controllers/permission.js +4 -4
  189. package/dist/api/controllers/query/import/index.js +6 -4
  190. package/dist/api/controllers/query/index.js +10 -11
  191. package/dist/api/controllers/role.js +5 -5
  192. package/dist/api/controllers/routing.js +6 -5
  193. package/dist/api/controllers/row/ExternalRequest.js +67 -90
  194. package/dist/api/controllers/row/external.js +22 -14
  195. package/dist/api/controllers/row/internal.js +93 -55
  196. package/dist/api/controllers/row/internalSearch.js +17 -23
  197. package/dist/api/controllers/row/utils.js +14 -13
  198. package/dist/api/controllers/screen.js +7 -5
  199. package/dist/api/controllers/static/index.js +12 -61
  200. package/dist/api/controllers/table/external.js +10 -7
  201. package/dist/api/controllers/table/index.js +13 -16
  202. package/dist/api/controllers/table/internal.js +16 -22
  203. package/dist/api/controllers/table/utils.js +35 -62
  204. package/dist/api/controllers/user.js +20 -18
  205. package/dist/api/controllers/view/index.js +10 -8
  206. package/dist/api/controllers/view/utils.js +4 -9
  207. package/dist/api/controllers/webhook.js +8 -10
  208. package/dist/api/routes/hosting.js +11 -0
  209. package/dist/api/routes/index.js +2 -2
  210. package/dist/api/routes/static.js +1 -2
  211. package/dist/api/routes/tests/utilities/TestFunctions.js +17 -37
  212. package/dist/app.js +5 -35
  213. package/dist/automations/automationUtils.js +3 -2
  214. package/dist/automations/steps/createRow.js +5 -3
  215. package/dist/automations/steps/deleteRow.js +4 -1
  216. package/dist/automations/steps/updateRow.js +1 -1
  217. package/dist/automations/triggers.js +25 -27
  218. package/dist/automations/utils.js +5 -10
  219. package/dist/constants/index.js +0 -7
  220. package/dist/db/linkedRows/LinkController.js +7 -3
  221. package/dist/db/linkedRows/index.js +27 -16
  222. package/dist/db/linkedRows/linkUtils.js +6 -6
  223. package/dist/db/views/staticViews.js +10 -9
  224. package/dist/definitions/datasource.js +0 -1
  225. package/dist/environment.js +1 -4
  226. package/dist/integrations/base/sql.js +14 -56
  227. package/dist/integrations/index.js +0 -3
  228. package/dist/integrations/utils.js +9 -60
  229. package/dist/middleware/authorized.js +30 -57
  230. package/dist/middleware/builder.js +2 -2
  231. package/dist/middleware/currentapp.js +37 -41
  232. package/dist/middleware/usageQuota.js +15 -82
  233. package/dist/package.json +5 -8
  234. package/dist/tests/utilities/TestConfiguration.js +50 -80
  235. package/dist/threads/automation.js +11 -13
  236. package/dist/threads/query.js +11 -15
  237. package/dist/tsconfig.tsbuildinfo +1 -1
  238. package/dist/utilities/fileSystem/index.js +3 -4
  239. package/dist/utilities/global.js +12 -15
  240. package/dist/utilities/index.js +17 -7
  241. package/dist/utilities/routing/index.js +5 -5
  242. package/dist/utilities/rowProcessor/index.js +17 -23
  243. package/dist/utilities/rowProcessor/utils.js +4 -14
  244. package/dist/utilities/{usageQuota/index.js → usageQuota.js} +31 -45
  245. package/dist/utilities/users.js +3 -3
  246. package/dist/utilities/workerRequests.js +24 -4
  247. package/nodemon.json +1 -1
  248. package/package.json +6 -9
  249. package/scripts/integrations/postgres/init.sql +6 -11
  250. package/scripts/likeCypress.ts +1 -1
  251. package/src/api/controllers/application.js +50 -85
  252. package/src/api/controllers/auth.js +5 -8
  253. package/src/api/controllers/automation.js +23 -13
  254. package/src/api/controllers/cloud.js +3 -2
  255. package/src/api/controllers/component.js +4 -3
  256. package/src/api/controllers/datasource.js +11 -21
  257. package/src/api/controllers/deploy/Deployment.js +7 -3
  258. package/src/api/controllers/deploy/index.js +13 -20
  259. package/src/api/controllers/dev.js +5 -5
  260. package/src/api/controllers/hosting.js +22 -0
  261. package/src/api/controllers/layout.js +3 -3
  262. package/src/api/controllers/metadata.js +9 -4
  263. package/src/api/controllers/permission.js +4 -4
  264. package/src/api/controllers/query/import/index.ts +6 -4
  265. package/src/api/controllers/query/import/tests/index.spec.js +1 -2
  266. package/src/api/controllers/query/index.js +10 -11
  267. package/src/api/controllers/role.js +5 -5
  268. package/src/api/controllers/routing.js +6 -5
  269. package/src/api/controllers/row/ExternalRequest.ts +43 -67
  270. package/src/api/controllers/row/external.js +58 -27
  271. package/src/api/controllers/row/internal.js +90 -54
  272. package/src/api/controllers/row/internalSearch.js +17 -23
  273. package/src/api/controllers/row/utils.js +18 -13
  274. package/src/api/controllers/screen.js +7 -5
  275. package/src/api/controllers/static/index.js +12 -65
  276. package/src/api/controllers/table/external.js +10 -7
  277. package/src/api/controllers/table/index.js +28 -20
  278. package/src/api/controllers/table/internal.js +19 -24
  279. package/src/api/controllers/table/utils.js +42 -78
  280. package/src/api/controllers/user.js +20 -19
  281. package/src/api/controllers/view/index.js +10 -8
  282. package/src/api/controllers/view/utils.js +4 -9
  283. package/src/api/controllers/webhook.js +8 -10
  284. package/src/api/routes/hosting.js +13 -0
  285. package/src/api/routes/index.js +2 -2
  286. package/src/api/routes/static.js +0 -5
  287. package/src/api/routes/tests/application.spec.js +2 -2
  288. package/src/api/routes/tests/auth.spec.js +2 -1
  289. package/src/api/routes/tests/automation.spec.js +0 -1
  290. package/src/api/routes/tests/hosting.spec.js +36 -0
  291. package/src/api/routes/tests/misc.spec.js +1 -0
  292. package/src/api/routes/tests/routing.spec.js +12 -21
  293. package/src/api/routes/tests/row.spec.js +4 -7
  294. package/src/api/routes/tests/utilities/TestFunctions.js +17 -39
  295. package/src/app.ts +5 -18
  296. package/src/automations/automationUtils.js +3 -2
  297. package/src/automations/steps/createRow.js +5 -2
  298. package/src/automations/steps/deleteRow.js +4 -1
  299. package/src/automations/steps/updateRow.js +1 -1
  300. package/src/automations/triggers.js +31 -33
  301. package/src/automations/utils.js +5 -9
  302. package/src/constants/index.js +0 -9
  303. package/src/db/linkedRows/LinkController.js +7 -3
  304. package/src/db/linkedRows/index.js +31 -16
  305. package/src/db/linkedRows/linkUtils.js +6 -6
  306. package/src/db/tests/linkController.spec.js +1 -0
  307. package/src/db/tests/linkTests.spec.js +6 -5
  308. package/src/db/views/staticViews.js +10 -8
  309. package/src/definitions/common.ts +0 -3
  310. package/src/definitions/datasource.ts +0 -3
  311. package/src/environment.js +1 -4
  312. package/src/integrations/base/sql.ts +21 -69
  313. package/src/integrations/index.ts +0 -3
  314. package/src/integrations/tests/sql.spec.js +0 -16
  315. package/src/integrations/utils.ts +12 -75
  316. package/src/middleware/authorized.js +30 -66
  317. package/src/middleware/builder.js +2 -2
  318. package/src/middleware/currentapp.js +46 -50
  319. package/src/middleware/tests/authorized.spec.js +6 -13
  320. package/src/middleware/tests/currentapp.spec.js +0 -6
  321. package/src/middleware/tests/usageQuota.spec.js +24 -18
  322. package/src/middleware/usageQuota.js +17 -93
  323. package/src/tests/utilities/TestConfiguration.js +55 -82
  324. package/src/threads/automation.js +15 -17
  325. package/src/threads/query.js +12 -17
  326. package/src/utilities/fileSystem/index.js +3 -4
  327. package/src/utilities/global.js +12 -15
  328. package/src/utilities/index.js +17 -7
  329. package/src/utilities/routing/index.js +5 -5
  330. package/src/utilities/rowProcessor/index.js +27 -25
  331. package/src/utilities/rowProcessor/utils.js +7 -23
  332. package/src/utilities/usageQuota.js +73 -0
  333. package/src/utilities/users.js +3 -3
  334. package/src/utilities/workerRequests.js +27 -4
  335. package/tsconfig.json +1 -2
  336. package/builder/assets/index.83c0944f.css +0 -1
  337. package/coverage/lcov-report/api/controllers/migrations.js.html +0 -119
  338. package/coverage/lcov-report/api/controllers/row/staticFormula.js.html +0 -548
  339. package/coverage/lcov-report/api/controllers/table/bulkFormula.js.html +0 -599
  340. package/coverage/lcov-report/utilities/usageQuota/index.html +0 -141
  341. package/coverage/lcov-report/utilities/usageQuota/index.js.html +0 -359
  342. package/coverage/lcov-report/utilities/usageQuota/rows.js.html +0 -305
  343. package/dist/api/controllers/migrations.js +0 -21
  344. package/dist/api/controllers/row/staticFormula.js +0 -147
  345. package/dist/api/controllers/table/bulkFormula.js +0 -159
  346. package/dist/api/routes/migrations.js +0 -9
  347. package/dist/integrations/googlesheets.js +0 -340
  348. package/dist/migrations/functions/appUrls.js +0 -46
  349. package/dist/migrations/functions/quotas1.js +0 -50
  350. package/dist/migrations/functions/usageQuotas/index.js +0 -20
  351. package/dist/migrations/functions/usageQuotas/syncApps.js +0 -29
  352. package/dist/migrations/functions/usageQuotas/syncRows.js +0 -33
  353. package/dist/migrations/functions/userEmailViewCasing.js +0 -24
  354. package/dist/migrations/index.js +0 -62
  355. package/dist/utilities/usageQuota/rows.js +0 -78
  356. package/dist/utilities/usageQuota/usageQuoteReset.js +0 -16
  357. package/src/api/controllers/migrations.js +0 -13
  358. package/src/api/controllers/row/staticFormula.js +0 -156
  359. package/src/api/controllers/table/bulkFormula.js +0 -173
  360. package/src/api/routes/migrations.js +0 -14
  361. package/src/api/routes/tests/static.spec.js +0 -98
  362. package/src/integrations/googlesheets.ts +0 -353
  363. package/src/migrations/functions/appUrls.ts +0 -34
  364. package/src/migrations/functions/quotas1.ts +0 -20
  365. package/src/migrations/functions/tests/appUrls.spec.js +0 -29
  366. package/src/migrations/functions/tests/quotas1.spec.js +0 -27
  367. package/src/migrations/functions/tests/userEmailViewCasing.spec.js +0 -25
  368. package/src/migrations/functions/usageQuotas/index.ts +0 -8
  369. package/src/migrations/functions/usageQuotas/syncApps.ts +0 -18
  370. package/src/migrations/functions/usageQuotas/syncRows.ts +0 -22
  371. package/src/migrations/functions/usageQuotas/tests/syncApps.spec.js +0 -37
  372. package/src/migrations/functions/usageQuotas/tests/syncRows.spec.js +0 -43
  373. package/src/migrations/functions/userEmailViewCasing.ts +0 -13
  374. package/src/migrations/index.ts +0 -56
  375. package/src/module.d.ts +0 -3
  376. package/src/utilities/tests/usageQuota/usageQuota.spec.js +0 -72
  377. package/src/utilities/usageQuota/index.js +0 -93
  378. package/src/utilities/usageQuota/rows.js +0 -75
  379. package/src/utilities/usageQuota/usageQuoteReset.js +0 -18
@@ -1,3 +1,4 @@
1
+ const CouchDB = require("../../db")
1
2
  const env = require("../../environment")
2
3
  const packageJson = require("../../../package.json")
3
4
  const {
@@ -28,11 +29,14 @@ const { processObject } = require("@budibase/string-templates")
28
29
  const {
29
30
  getAllApps,
30
31
  isDevAppID,
31
- getProdAppID,
32
+ getDeployedAppID,
32
33
  Replication,
33
34
  } = require("@budibase/backend-core/db")
34
35
  const { USERS_TABLE_SCHEMA } = require("../../constants")
35
- const { removeAppFromUserRoles } = require("../../utilities/workerRequests")
36
+ const {
37
+ getDeployedApps,
38
+ removeAppFromUserRoles,
39
+ } = require("../../utilities/workerRequests")
36
40
  const { clientLibraryPath, stringToReadStream } = require("../../utilities")
37
41
  const { getAllLocks } = require("../../utilities/redis")
38
42
  const {
@@ -44,17 +48,11 @@ const { getTenantId, isMultiTenant } = require("@budibase/backend-core/tenancy")
44
48
  const { syncGlobalUsers } = require("./user")
45
49
  const { app: appCache } = require("@budibase/backend-core/cache")
46
50
  const { cleanupAutomations } = require("../../automations/utils")
47
- const {
48
- getAppDB,
49
- getProdAppDB,
50
- updateAppId,
51
- } = require("@budibase/backend-core/context")
52
51
 
53
52
  const URL_REGEX_SLASH = /\/|\\/g
54
53
 
55
54
  // utility function, need to do away with this
56
- async function getLayouts() {
57
- const db = getAppDB()
55
+ async function getLayouts(db) {
58
56
  return (
59
57
  await db.allDocs(
60
58
  getLayoutParams(null, {
@@ -64,8 +62,7 @@ async function getLayouts() {
64
62
  ).rows.map(row => row.doc)
65
63
  }
66
64
 
67
- async function getScreens() {
68
- const db = getAppDB()
65
+ async function getScreens(db) {
69
66
  return (
70
67
  await db.allDocs(
71
68
  getScreenParams(null, {
@@ -81,51 +78,37 @@ function getUserRoleId(ctx) {
81
78
  : ctx.user.role._id
82
79
  }
83
80
 
84
- exports.getAppUrl = ctx => {
85
- // construct the url
81
+ async function getAppUrlIfNotInUse(ctx) {
86
82
  let url
87
83
  if (ctx.request.body.url) {
88
- // if the url is provided, use that
89
84
  url = encodeURI(ctx.request.body.url)
90
85
  } else if (ctx.request.body.name) {
91
- // otherwise use the name
92
86
  url = encodeURI(`${ctx.request.body.name}`)
93
87
  }
94
88
  if (url) {
95
89
  url = `/${url.replace(URL_REGEX_SLASH, "")}`.toLowerCase()
96
90
  }
97
- return url
98
- }
99
-
100
- const checkAppUrl = (ctx, apps, url, currentAppId) => {
101
- if (currentAppId) {
102
- apps = apps.filter(app => app.appId !== currentAppId)
103
- }
104
- if (apps.some(app => app.url === url)) {
105
- ctx.throw(400, "App URL is already in use.")
106
- }
107
- }
108
-
109
- const checkAppName = (ctx, apps, name, currentAppId) => {
110
- // TODO: Replace with Joi
111
- if (!name) {
112
- ctx.throw(400, "Name is required")
113
- }
114
- if (currentAppId) {
115
- apps = apps.filter(app => app.appId !== currentAppId)
91
+ if (!env.SELF_HOSTED) {
92
+ return url
116
93
  }
117
- if (apps.some(app => app.name === name)) {
118
- ctx.throw(400, "App name is already in use.")
94
+ const deployedApps = await getDeployedApps()
95
+ if (
96
+ url &&
97
+ deployedApps[url] != null &&
98
+ ctx.params != null &&
99
+ deployedApps[url].appId !== ctx.params.appId
100
+ ) {
101
+ ctx.throw(400, "App name/URL is already in use.")
119
102
  }
103
+ return url
120
104
  }
121
105
 
122
106
  async function createInstance(template) {
123
107
  const tenantId = isMultiTenant() ? getTenantId() : null
124
108
  const baseAppId = generateAppID(tenantId)
125
109
  const appId = generateDevAppID(baseAppId)
126
- updateAppId(appId)
127
110
 
128
- const db = getAppDB()
111
+ const db = new CouchDB(appId)
129
112
  await db.put({
130
113
  _id: "_design/database",
131
114
  // view collation information, read before writing any complex views:
@@ -135,9 +118,9 @@ async function createInstance(template) {
135
118
 
136
119
  // NOTE: indexes need to be created before any tables/templates
137
120
  // add view for linked rows
138
- await createLinkView()
139
- await createRoutingView()
140
- await createAllSearchIndex()
121
+ await createLinkView(appId)
122
+ await createRoutingView(appId)
123
+ await createAllSearchIndex(appId)
141
124
 
142
125
  // replicate the template data to the instance DB
143
126
  // this is currently very hard to test, downloading and importing template files
@@ -163,7 +146,7 @@ async function createInstance(template) {
163
146
  exports.fetch = async ctx => {
164
147
  const dev = ctx.query && ctx.query.status === AppStatus.DEV
165
148
  const all = ctx.query && ctx.query.status === AppStatus.ALL
166
- const apps = await getAllApps({ dev, all })
149
+ const apps = await getAllApps(CouchDB, { dev, all })
167
150
 
168
151
  // get the locks for all the dev apps
169
152
  if (dev || all) {
@@ -186,11 +169,12 @@ exports.fetch = async ctx => {
186
169
  }
187
170
 
188
171
  exports.fetchAppDefinition = async ctx => {
189
- const layouts = await getLayouts()
172
+ const db = new CouchDB(ctx.params.appId)
173
+ const layouts = await getLayouts(db)
190
174
  const userRoleId = getUserRoleId(ctx)
191
- const accessController = new AccessController()
175
+ const accessController = new AccessController(ctx.params.appId)
192
176
  const screens = await accessController.checkScreensAccess(
193
- await getScreens(),
177
+ await getScreens(db),
194
178
  userRoleId
195
179
  )
196
180
  ctx.body = {
@@ -201,15 +185,15 @@ exports.fetchAppDefinition = async ctx => {
201
185
  }
202
186
 
203
187
  exports.fetchAppPackage = async ctx => {
204
- const db = getAppDB()
188
+ const db = new CouchDB(ctx.params.appId)
205
189
  const application = await db.get(DocumentTypes.APP_METADATA)
206
- const layouts = await getLayouts()
207
- let screens = await getScreens()
190
+ const layouts = await getLayouts(db)
191
+ let screens = await getScreens(db)
208
192
 
209
193
  // Only filter screens if the user is not a builder
210
194
  if (!(ctx.user.builder && ctx.user.builder.global)) {
211
195
  const userRoleId = getUserRoleId(ctx)
212
- const accessController = new AccessController()
196
+ const accessController = new AccessController(ctx.params.appId)
213
197
  screens = await accessController.checkScreensAccess(screens, userRoleId)
214
198
  }
215
199
 
@@ -222,12 +206,6 @@ exports.fetchAppPackage = async ctx => {
222
206
  }
223
207
 
224
208
  exports.create = async ctx => {
225
- const apps = await getAllApps({ dev: true })
226
- const name = ctx.request.body.name
227
- checkAppName(ctx, apps, name)
228
- const url = exports.getAppUrl(ctx)
229
- checkAppUrl(ctx, apps, url)
230
-
231
209
  const { useTemplate, templateKey, templateString } = ctx.request.body
232
210
  const instanceConfig = {
233
211
  useTemplate,
@@ -240,7 +218,8 @@ exports.create = async ctx => {
240
218
  const instance = await createInstance(instanceConfig)
241
219
  const appId = instance._id
242
220
 
243
- const db = getAppDB()
221
+ const url = await getAppUrlIfNotInUse(ctx)
222
+ const db = new CouchDB(appId)
244
223
  let _rev
245
224
  try {
246
225
  // if template there will be an existing doc
@@ -256,7 +235,7 @@ exports.create = async ctx => {
256
235
  type: "app",
257
236
  version: packageJson.version,
258
237
  componentLibraries: ["@budibase/standard-components"],
259
- name: name,
238
+ name: ctx.request.body.name,
260
239
  url: url,
261
240
  template: ctx.request.body.template,
262
241
  instance: instance,
@@ -283,29 +262,15 @@ exports.create = async ctx => {
283
262
  ctx.body = newApplication
284
263
  }
285
264
 
286
- // This endpoint currently operates as a PATCH rather than a PUT
287
- // Thus name and url fields are handled only if present
288
265
  exports.update = async ctx => {
289
- const apps = await getAllApps({ dev: true })
290
- // validation
291
- const name = ctx.request.body.name
292
- if (name) {
293
- checkAppName(ctx, apps, name, ctx.params.appId)
294
- }
295
- const url = await exports.getAppUrl(ctx)
296
- if (url) {
297
- checkAppUrl(ctx, apps, url, ctx.params.appId)
298
- ctx.request.body.url = url
299
- }
300
-
301
- const data = await updateAppPackage(ctx.request.body, ctx.params.appId)
266
+ const data = await updateAppPackage(ctx, ctx.request.body, ctx.params.appId)
302
267
  ctx.status = 200
303
268
  ctx.body = data
304
269
  }
305
270
 
306
271
  exports.updateClient = async ctx => {
307
272
  // Get current app version
308
- const db = getAppDB()
273
+ const db = new CouchDB(ctx.params.appId)
309
274
  const application = await db.get(DocumentTypes.APP_METADATA)
310
275
  const currentVersion = application.version
311
276
 
@@ -320,14 +285,14 @@ exports.updateClient = async ctx => {
320
285
  version: packageJson.version,
321
286
  revertableVersion: currentVersion,
322
287
  }
323
- const data = await updateAppPackage(appPackageUpdates, ctx.params.appId)
288
+ const data = await updateAppPackage(ctx, appPackageUpdates, ctx.params.appId)
324
289
  ctx.status = 200
325
290
  ctx.body = data
326
291
  }
327
292
 
328
293
  exports.revertClient = async ctx => {
329
294
  // Check app can be reverted
330
- const db = getAppDB()
295
+ const db = new CouchDB(ctx.params.appId)
331
296
  const application = await db.get(DocumentTypes.APP_METADATA)
332
297
  if (!application.revertableVersion) {
333
298
  ctx.throw(400, "There is no version to revert to")
@@ -343,13 +308,13 @@ exports.revertClient = async ctx => {
343
308
  version: application.revertableVersion,
344
309
  revertableVersion: null,
345
310
  }
346
- const data = await updateAppPackage(appPackageUpdates, ctx.params.appId)
311
+ const data = await updateAppPackage(ctx, appPackageUpdates, ctx.params.appId)
347
312
  ctx.status = 200
348
313
  ctx.body = data
349
314
  }
350
315
 
351
316
  exports.delete = async ctx => {
352
- const db = getAppDB()
317
+ const db = new CouchDB(ctx.params.appId)
353
318
 
354
319
  const result = await db.destroy()
355
320
  /* istanbul ignore next */
@@ -374,11 +339,10 @@ exports.sync = async (ctx, next) => {
374
339
  }
375
340
 
376
341
  // replicate prod to dev
377
- const prodAppId = getProdAppID(appId)
342
+ const prodAppId = getDeployedAppID(appId)
378
343
 
379
344
  try {
380
- // specific case, want to make sure setup is skipped
381
- const prodDb = getProdAppDB({ skip_setup: true })
345
+ const prodDb = new CouchDB(prodAppId, { skip_setup: true })
382
346
  const info = await prodDb.info()
383
347
  if (info.error) throw info.error
384
348
  } catch (err) {
@@ -406,7 +370,7 @@ exports.sync = async (ctx, next) => {
406
370
  }
407
371
 
408
372
  // sync the users
409
- await syncGlobalUsers()
373
+ await syncGlobalUsers(appId)
410
374
 
411
375
  if (error) {
412
376
  ctx.throw(400, error)
@@ -417,11 +381,12 @@ exports.sync = async (ctx, next) => {
417
381
  }
418
382
  }
419
383
 
420
- const updateAppPackage = async (appPackage, appId) => {
421
- const db = getAppDB()
384
+ const updateAppPackage = async (ctx, appPackage, appId) => {
385
+ const url = await getAppUrlIfNotInUse(ctx)
386
+ const db = new CouchDB(appId)
422
387
  const application = await db.get(DocumentTypes.APP_METADATA)
423
388
 
424
- const newAppPackage = { ...application, ...appPackage }
389
+ const newAppPackage = { ...application, ...appPackage, url }
425
390
  if (appPackage._rev !== application._rev) {
426
391
  newAppPackage._rev = application._rev
427
392
  }
@@ -437,7 +402,7 @@ const updateAppPackage = async (appPackage, appId) => {
437
402
  }
438
403
 
439
404
  const createEmptyAppPackage = async (ctx, app) => {
440
- const db = getAppDB()
405
+ const db = new CouchDB(app.appId)
441
406
 
442
407
  let screensAndLayouts = []
443
408
  for (let layout of BASE_LAYOUTS) {
@@ -1,10 +1,11 @@
1
+ const CouchDB = require("../../db")
1
2
  const { outputProcessing } = require("../../utilities/rowProcessor")
2
3
  const { InternalTables } = require("../../db/utils")
3
4
  const { getFullUser } = require("../../utilities/users")
4
5
  const { BUILTIN_ROLE_IDS } = require("@budibase/backend-core/roles")
5
- const { getAppDB, getAppId } = require("@budibase/backend-core/context")
6
6
 
7
7
  exports.fetchSelf = async ctx => {
8
+ const appId = ctx.appId
8
9
  let userId = ctx.user.userId || ctx.user._id
9
10
  /* istanbul ignore next */
10
11
  if (!userId) {
@@ -15,20 +16,16 @@ exports.fetchSelf = async ctx => {
15
16
  const user = await getFullUser(ctx, userId)
16
17
  // this shouldn't be returned by the app self
17
18
  delete user.roles
18
- // forward the csrf token from the session
19
- user.csrfToken = ctx.user.csrfToken
20
19
 
21
- if (getAppId()) {
22
- const db = getAppDB()
20
+ if (appId) {
21
+ const db = new CouchDB(appId)
23
22
  // remove the full roles structure
24
23
  delete user.roles
25
24
  try {
26
25
  const userTable = await db.get(InternalTables.USER_METADATA)
27
26
  const metadata = await db.get(userId)
28
- // make sure there is never a stale csrf token
29
- delete metadata.csrfToken
30
27
  // specifically needs to make sure is enriched
31
- ctx.body = await outputProcessing(userTable, {
28
+ ctx.body = await outputProcessing(ctx, userTable, {
32
29
  ...user,
33
30
  ...metadata,
34
31
  })
@@ -1,3 +1,4 @@
1
+ const CouchDB = require("../../db")
1
2
  const actions = require("../../automations/actions")
2
3
  const triggers = require("../../automations/triggers")
3
4
  const { getAutomationParams, generateAutomationID } = require("../../db/utils")
@@ -9,7 +10,6 @@ const {
9
10
  const { deleteEntityMetadata } = require("../../utilities")
10
11
  const { MetadataTypes } = require("../../constants")
11
12
  const { setTestFlag, clearTestFlag } = require("../../utilities/redis")
12
- const { getAppDB } = require("@budibase/backend-core/context")
13
13
 
14
14
  const ACTION_DEFS = removeDeprecated(actions.ACTION_DEFINITIONS)
15
15
  const TRIGGER_DEFS = removeDeprecated(triggers.TRIGGER_DEFINITIONS)
@@ -20,9 +20,14 @@ const TRIGGER_DEFS = removeDeprecated(triggers.TRIGGER_DEFINITIONS)
20
20
  * *
21
21
  *************************/
22
22
 
23
- async function cleanupAutomationMetadata(automationId) {
24
- await deleteEntityMetadata(MetadataTypes.AUTOMATION_TEST_INPUT, automationId)
23
+ async function cleanupAutomationMetadata(appId, automationId) {
25
24
  await deleteEntityMetadata(
25
+ appId,
26
+ MetadataTypes.AUTOMATION_TEST_INPUT,
27
+ automationId
28
+ )
29
+ await deleteEntityMetadata(
30
+ appId,
26
31
  MetadataTypes.AUTOMATION_TEST_HISTORY,
27
32
  automationId
28
33
  )
@@ -53,7 +58,7 @@ function cleanAutomationInputs(automation) {
53
58
  }
54
59
 
55
60
  exports.create = async function (ctx) {
56
- const db = getAppDB()
61
+ const db = new CouchDB(ctx.appId)
57
62
  let automation = ctx.request.body
58
63
  automation.appId = ctx.appId
59
64
 
@@ -67,6 +72,7 @@ exports.create = async function (ctx) {
67
72
  automation.type = "automation"
68
73
  automation = cleanAutomationInputs(automation)
69
74
  automation = await checkForWebhooks({
75
+ appId: ctx.appId,
70
76
  newAuto: automation,
71
77
  })
72
78
  const response = await db.put(automation)
@@ -83,12 +89,13 @@ exports.create = async function (ctx) {
83
89
  }
84
90
 
85
91
  exports.update = async function (ctx) {
86
- const db = getAppDB()
92
+ const db = new CouchDB(ctx.appId)
87
93
  let automation = ctx.request.body
88
94
  automation.appId = ctx.appId
89
95
  const oldAutomation = await db.get(automation._id)
90
96
  automation = cleanAutomationInputs(automation)
91
97
  automation = await checkForWebhooks({
98
+ appId: ctx.appId,
92
99
  oldAuto: oldAutomation,
93
100
  newAuto: automation,
94
101
  })
@@ -124,7 +131,7 @@ exports.update = async function (ctx) {
124
131
  }
125
132
 
126
133
  exports.fetch = async function (ctx) {
127
- const db = getAppDB()
134
+ const db = new CouchDB(ctx.appId)
128
135
  const response = await db.allDocs(
129
136
  getAutomationParams(null, {
130
137
  include_docs: true,
@@ -134,19 +141,20 @@ exports.fetch = async function (ctx) {
134
141
  }
135
142
 
136
143
  exports.find = async function (ctx) {
137
- const db = getAppDB()
144
+ const db = new CouchDB(ctx.appId)
138
145
  ctx.body = await db.get(ctx.params.id)
139
146
  }
140
147
 
141
148
  exports.destroy = async function (ctx) {
142
- const db = getAppDB()
149
+ const db = new CouchDB(ctx.appId)
143
150
  const automationId = ctx.params.id
144
151
  const oldAutomation = await db.get(automationId)
145
152
  await checkForWebhooks({
153
+ appId: ctx.appId,
146
154
  oldAuto: oldAutomation,
147
155
  })
148
156
  // delete metadata first
149
- await cleanupAutomationMetadata(automationId)
157
+ await cleanupAutomationMetadata(ctx.appId, automationId)
150
158
  ctx.body = await db.remove(automationId, ctx.params.rev)
151
159
  }
152
160
 
@@ -172,11 +180,12 @@ module.exports.getDefinitionList = async function (ctx) {
172
180
  *********************/
173
181
 
174
182
  exports.trigger = async function (ctx) {
175
- const db = getAppDB()
183
+ const appId = ctx.appId
184
+ const db = new CouchDB(appId)
176
185
  let automation = await db.get(ctx.params.id)
177
186
  await triggers.externalTrigger(automation, {
178
187
  ...ctx.request.body,
179
- appId: ctx.appId,
188
+ appId,
180
189
  })
181
190
  ctx.body = {
182
191
  message: `Automation ${automation._id} has been triggered.`,
@@ -196,7 +205,8 @@ function prepareTestInput(input) {
196
205
  }
197
206
 
198
207
  exports.test = async function (ctx) {
199
- const db = getAppDB()
208
+ const appId = ctx.appId
209
+ const db = new CouchDB(appId)
200
210
  let automation = await db.get(ctx.params.id)
201
211
  await setTestFlag(automation._id)
202
212
  const testInput = prepareTestInput(ctx.request.body)
@@ -204,7 +214,7 @@ exports.test = async function (ctx) {
204
214
  automation,
205
215
  {
206
216
  ...testInput,
207
- appId: ctx.appId,
217
+ appId,
208
218
  },
209
219
  { getResponses: true }
210
220
  )
@@ -1,5 +1,6 @@
1
1
  const env = require("../../environment")
2
2
  const { getAllApps } = require("@budibase/backend-core/db")
3
+ const CouchDB = require("../../db")
3
4
  const {
4
5
  exportDB,
5
6
  sendTempFile,
@@ -29,7 +30,7 @@ exports.exportApps = async ctx => {
29
30
  if (env.SELF_HOSTED || !env.MULTI_TENANCY) {
30
31
  ctx.throw(400, "Exporting only allowed in multi-tenant cloud environments.")
31
32
  }
32
- const apps = await getAllApps({ all: true })
33
+ const apps = await getAllApps(CouchDB, { all: true })
33
34
  const globalDBString = await exportDB(getGlobalDBName(), {
34
35
  filter: doc => !doc._id.startsWith(DocumentTypes.USER),
35
36
  })
@@ -62,7 +63,7 @@ async function hasBeenImported() {
62
63
  if (!env.SELF_HOSTED || env.MULTI_TENANCY) {
63
64
  return true
64
65
  }
65
- const apps = await getAllApps({ all: true })
66
+ const apps = await getAllApps(CouchDB, { all: true })
66
67
  return apps.length !== 0
67
68
  }
68
69
 
@@ -1,14 +1,15 @@
1
+ const CouchDB = require("../../db")
1
2
  const { DocumentTypes } = require("../../db/utils")
2
3
  const { getComponentLibraryManifest } = require("../../utilities/fileSystem")
3
- const { getAppDB } = require("@budibase/backend-core/context")
4
4
 
5
5
  exports.fetchAppComponentDefinitions = async function (ctx) {
6
- const db = getAppDB()
6
+ const appId = ctx.params.appId || ctx.appId
7
+ const db = new CouchDB(appId)
7
8
  const app = await db.get(DocumentTypes.APP_METADATA)
8
9
 
9
10
  let componentManifests = await Promise.all(
10
11
  app.componentLibraries.map(async library => {
11
- let manifest = await getComponentLibraryManifest(library)
12
+ let manifest = await getComponentLibraryManifest(appId, library)
12
13
 
13
14
  return {
14
15
  manifest,
@@ -1,3 +1,4 @@
1
+ const CouchDB = require("../../db")
1
2
  const {
2
3
  generateDatasourceID,
3
4
  getDatasourceParams,
@@ -10,11 +11,12 @@ const { BuildSchemaErrors, InvalidColumns } = require("../../constants")
10
11
  const { integrations } = require("../../integrations")
11
12
  const { getDatasourceAndQuery } = require("./row/utils")
12
13
  const { invalidateDynamicVariables } = require("../../threads/utils")
13
- const { getAppDB } = require("@budibase/backend-core/context")
14
14
 
15
15
  exports.fetch = async function (ctx) {
16
+ const database = new CouchDB(ctx.appId)
17
+
16
18
  // Get internal tables
17
- const db = getAppDB()
19
+ const db = new CouchDB(ctx.appId)
18
20
  const internalTables = await db.allDocs(
19
21
  getTableParams(null, {
20
22
  include_docs: true,
@@ -29,25 +31,18 @@ exports.fetch = async function (ctx) {
29
31
 
30
32
  // Get external datasources
31
33
  const datasources = (
32
- await db.allDocs(
34
+ await database.allDocs(
33
35
  getDatasourceParams(null, {
34
36
  include_docs: true,
35
37
  })
36
38
  )
37
39
  ).rows.map(row => row.doc)
38
40
 
39
- for (let datasource of datasources) {
40
- if (datasource.config && datasource.config.auth) {
41
- // strip secrets from response so they don't show in the network request
42
- delete datasource.config.auth
43
- }
44
- }
45
-
46
41
  ctx.body = [bbInternalDb, ...datasources]
47
42
  }
48
43
 
49
44
  exports.buildSchemaFromDb = async function (ctx) {
50
- const db = getAppDB()
45
+ const db = new CouchDB(ctx.appId)
51
46
  const datasource = await db.get(ctx.params.datasourceId)
52
47
 
53
48
  const { tables, error } = await buildSchemaHelper(datasource)
@@ -96,16 +91,11 @@ const invalidateVariables = async (existingDatasource, updatedDatasource) => {
96
91
  }
97
92
 
98
93
  exports.update = async function (ctx) {
99
- const db = getAppDB()
94
+ const db = new CouchDB(ctx.appId)
100
95
  const datasourceId = ctx.params.datasourceId
101
96
  let datasource = await db.get(datasourceId)
102
- const auth = datasource.config.auth
103
97
  await invalidateVariables(datasource, ctx.request.body)
104
98
  datasource = { ...datasource, ...ctx.request.body }
105
- if (auth && !ctx.request.body.auth) {
106
- // don't strip auth config from DB
107
- datasource.config.auth = auth
108
- }
109
99
 
110
100
  const response = await db.put(datasource)
111
101
  datasource._rev = response.rev
@@ -124,7 +114,7 @@ exports.update = async function (ctx) {
124
114
  }
125
115
 
126
116
  exports.save = async function (ctx) {
127
- const db = getAppDB()
117
+ const db = new CouchDB(ctx.appId)
128
118
  const plus = ctx.request.body.datasource.plus
129
119
  const fetchSchema = ctx.request.body.fetchSchema
130
120
 
@@ -160,7 +150,7 @@ exports.save = async function (ctx) {
160
150
  }
161
151
 
162
152
  exports.destroy = async function (ctx) {
163
- const db = getAppDB()
153
+ const db = new CouchDB(ctx.appId)
164
154
 
165
155
  // Delete all queries for the datasource
166
156
  const queries = await db.allDocs(
@@ -182,7 +172,7 @@ exports.destroy = async function (ctx) {
182
172
  }
183
173
 
184
174
  exports.find = async function (ctx) {
185
- const database = getAppDB()
175
+ const database = new CouchDB(ctx.appId)
186
176
  ctx.body = await database.get(ctx.params.datasourceId)
187
177
  }
188
178
 
@@ -190,7 +180,7 @@ exports.find = async function (ctx) {
190
180
  exports.query = async function (ctx) {
191
181
  const queryJson = ctx.request.body
192
182
  try {
193
- ctx.body = await getDatasourceAndQuery(queryJson)
183
+ ctx.body = await getDatasourceAndQuery(ctx.appId, queryJson)
194
184
  } catch (err) {
195
185
  ctx.throw(400, err)
196
186
  }
@@ -1,14 +1,18 @@
1
1
  const newid = require("../../../db/newid")
2
- const { getAppId } = require("@budibase/backend-core/context")
3
2
 
4
3
  /**
5
4
  * This is used to pass around information about the deployment that is occurring
6
5
  */
7
6
  class Deployment {
8
- constructor(id = null) {
7
+ constructor(appId, id = null) {
8
+ this.appId = appId
9
9
  this._id = id || newid()
10
10
  }
11
11
 
12
+ getAppId() {
13
+ return this.appId
14
+ }
15
+
12
16
  setVerification(verification) {
13
17
  if (!verification) {
14
18
  return
@@ -39,7 +43,7 @@ class Deployment {
39
43
  getJSON() {
40
44
  const obj = {
41
45
  _id: this._id,
42
- appId: getAppId(),
46
+ appId: this.appId,
43
47
  status: this.status,
44
48
  }
45
49
  if (this.err) {