@budibase/server 1.0.49 → 1.0.50-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (381) hide show
  1. package/__mocks__/arangojs.ts +1 -1
  2. package/__mocks__/aws-sdk.ts +4 -4
  3. package/__mocks__/mongodb.ts +4 -5
  4. package/__mocks__/mssql.ts +3 -3
  5. package/__mocks__/node-fetch.ts +2 -1
  6. package/__mocks__/pg.ts +3 -5
  7. package/builder/assets/index.c0cc369d.css +6 -0
  8. package/builder/assets/{index.2c37968e.js → index.ff2bad21.js} +252 -249
  9. package/builder/assets/{vendor.f9faf6ab.js → vendor.5ad9695a.js} +202 -106
  10. package/builder/index.html +3 -3
  11. package/coverage/clover.xml +3105 -2814
  12. package/coverage/coverage-final.json +106 -101
  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 +257 -152
  16. package/coverage/lcov-report/api/controllers/auth.js.html +22 -13
  17. package/coverage/lcov-report/api/controllers/automation.js.html +39 -69
  18. package/coverage/lcov-report/api/controllers/backup.js.html +1 -1
  19. package/coverage/lcov-report/api/controllers/cloud.js.html +8 -11
  20. package/coverage/lcov-report/api/controllers/component.js.html +13 -16
  21. package/coverage/lcov-report/api/controllers/datasource.js.html +81 -51
  22. package/coverage/lcov-report/api/controllers/dev.js.html +6 -6
  23. package/coverage/lcov-report/api/controllers/index.html +78 -78
  24. package/coverage/lcov-report/api/controllers/integration.js.html +1 -1
  25. package/coverage/lcov-report/api/controllers/layout.js.html +9 -9
  26. package/coverage/lcov-report/api/controllers/metadata.js.html +6 -21
  27. package/coverage/lcov-report/api/controllers/migrations.js.html +119 -0
  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 +38 -35
  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 +7 -10
  34. package/coverage/lcov-report/api/controllers/row/external.js.html +48 -141
  35. package/coverage/lcov-report/api/controllers/row/index.html +55 -40
  36. package/coverage/lcov-report/api/controllers/row/index.js.html +26 -26
  37. package/coverage/lcov-report/api/controllers/row/internal.js.html +118 -226
  38. package/coverage/lcov-report/api/controllers/row/internalSearch.js.html +52 -34
  39. package/coverage/lcov-report/api/controllers/row/staticFormula.js.html +548 -0
  40. package/coverage/lcov-report/api/controllers/row/utils.js.html +47 -62
  41. package/coverage/lcov-report/api/controllers/screen.js.html +15 -21
  42. package/coverage/lcov-report/api/controllers/script.js.html +4 -4
  43. package/coverage/lcov-report/api/controllers/table/bulkFormula.js.html +599 -0
  44. package/coverage/lcov-report/api/controllers/table/external.js.html +25 -34
  45. package/coverage/lcov-report/api/controllers/table/index.html +58 -43
  46. package/coverage/lcov-report/api/controllers/table/index.js.html +58 -82
  47. package/coverage/lcov-report/api/controllers/table/internal.js.html +81 -66
  48. package/coverage/lcov-report/api/controllers/table/utils.js.html +218 -110
  49. package/coverage/lcov-report/api/controllers/templates.js.html +1 -1
  50. package/coverage/lcov-report/api/controllers/user.js.html +79 -76
  51. package/coverage/lcov-report/api/controllers/view/exporters.js.html +4 -4
  52. package/coverage/lcov-report/api/controllers/view/index.html +16 -16
  53. package/coverage/lcov-report/api/controllers/view/index.js.html +27 -33
  54. package/coverage/lcov-report/api/controllers/view/utils.js.html +35 -20
  55. package/coverage/lcov-report/api/controllers/view/viewBuilder.js.html +7 -7
  56. package/coverage/lcov-report/api/controllers/webhook.js.html +34 -28
  57. package/coverage/lcov-report/api/index.html +1 -1
  58. package/coverage/lcov-report/api/index.js.html +8 -8
  59. package/coverage/lcov-report/api/routes/analytics.js.html +1 -1
  60. package/coverage/lcov-report/api/routes/apikeys.js.html +1 -1
  61. package/coverage/lcov-report/api/routes/application.js.html +1 -1
  62. package/coverage/lcov-report/api/routes/auth.js.html +1 -1
  63. package/coverage/lcov-report/api/routes/automation.js.html +1 -1
  64. package/coverage/lcov-report/api/routes/backup.js.html +1 -1
  65. package/coverage/lcov-report/api/routes/cloud.js.html +1 -1
  66. package/coverage/lcov-report/api/routes/component.js.html +1 -1
  67. package/coverage/lcov-report/api/routes/datasource.js.html +1 -1
  68. package/coverage/lcov-report/api/routes/deploy.js.html +1 -1
  69. package/coverage/lcov-report/api/routes/dev.js.html +1 -1
  70. package/coverage/lcov-report/api/routes/index.html +18 -18
  71. package/coverage/lcov-report/api/routes/index.js.html +3 -3
  72. package/coverage/lcov-report/api/routes/integration.js.html +1 -1
  73. package/coverage/lcov-report/api/routes/layout.js.html +1 -1
  74. package/coverage/lcov-report/api/routes/metadata.js.html +1 -1
  75. package/coverage/lcov-report/api/routes/{hosting.js.html → migrations.js.html} +17 -14
  76. package/coverage/lcov-report/api/routes/permission.js.html +1 -1
  77. package/coverage/lcov-report/api/routes/query.js.html +1 -1
  78. package/coverage/lcov-report/api/routes/role.js.html +1 -1
  79. package/coverage/lcov-report/api/routes/routing.js.html +1 -1
  80. package/coverage/lcov-report/api/routes/row.js.html +1 -1
  81. package/coverage/lcov-report/api/routes/screen.js.html +1 -1
  82. package/coverage/lcov-report/api/routes/script.js.html +1 -1
  83. package/coverage/lcov-report/api/routes/static.js.html +17 -2
  84. package/coverage/lcov-report/api/routes/table.js.html +1 -1
  85. package/coverage/lcov-report/api/routes/templates.js.html +1 -1
  86. package/coverage/lcov-report/api/routes/user.js.html +1 -1
  87. package/coverage/lcov-report/api/routes/view.js.html +1 -1
  88. package/coverage/lcov-report/api/routes/webhook.js.html +1 -1
  89. package/coverage/lcov-report/automations/actions.js.html +24 -24
  90. package/coverage/lcov-report/automations/automationUtils.js.html +7 -10
  91. package/coverage/lcov-report/automations/bullboard.js.html +16 -16
  92. package/coverage/lcov-report/automations/index.html +18 -18
  93. package/coverage/lcov-report/automations/index.js.html +1 -1
  94. package/coverage/lcov-report/automations/steps/bash.js.html +6 -6
  95. package/coverage/lcov-report/automations/steps/createRow.js.html +13 -22
  96. package/coverage/lcov-report/automations/steps/delay.js.html +4 -4
  97. package/coverage/lcov-report/automations/steps/deleteRow.js.html +11 -20
  98. package/coverage/lcov-report/automations/steps/discord.js.html +7 -7
  99. package/coverage/lcov-report/automations/steps/executeQuery.js.html +6 -6
  100. package/coverage/lcov-report/automations/steps/executeScript.js.html +6 -6
  101. package/coverage/lcov-report/automations/steps/filter.js.html +7 -7
  102. package/coverage/lcov-report/automations/steps/index.html +13 -13
  103. package/coverage/lcov-report/automations/steps/integromat.js.html +5 -5
  104. package/coverage/lcov-report/automations/steps/outgoingWebhook.js.html +8 -8
  105. package/coverage/lcov-report/automations/steps/queryRows.js.html +10 -10
  106. package/coverage/lcov-report/automations/steps/sendSmtpEmail.js.html +5 -5
  107. package/coverage/lcov-report/automations/steps/serverLog.js.html +3 -3
  108. package/coverage/lcov-report/automations/steps/slack.js.html +5 -5
  109. package/coverage/lcov-report/automations/steps/updateRow.js.html +7 -7
  110. package/coverage/lcov-report/automations/steps/utils.js.html +3 -3
  111. package/coverage/lcov-report/automations/steps/zapier.js.html +5 -5
  112. package/coverage/lcov-report/automations/triggerInfo/app.js.html +2 -2
  113. package/coverage/lcov-report/automations/triggerInfo/cron.js.html +2 -2
  114. package/coverage/lcov-report/automations/triggerInfo/index.html +1 -1
  115. package/coverage/lcov-report/automations/triggerInfo/index.js.html +8 -8
  116. package/coverage/lcov-report/automations/triggerInfo/rowDeleted.js.html +2 -2
  117. package/coverage/lcov-report/automations/triggerInfo/rowSaved.js.html +2 -2
  118. package/coverage/lcov-report/automations/triggerInfo/rowUpdated.js.html +2 -2
  119. package/coverage/lcov-report/automations/triggerInfo/webhook.js.html +2 -2
  120. package/coverage/lcov-report/automations/triggers.js.html +61 -55
  121. package/coverage/lcov-report/automations/utils.js.html +54 -42
  122. package/coverage/lcov-report/constants/index.html +5 -5
  123. package/coverage/lcov-report/constants/index.js.html +53 -26
  124. package/coverage/lcov-report/constants/layouts.js.html +5 -5
  125. package/coverage/lcov-report/constants/screens.js.html +4 -4
  126. package/coverage/lcov-report/db/client.js.html +18 -18
  127. package/coverage/lcov-report/db/inMemoryView.js.html +7 -7
  128. package/coverage/lcov-report/db/index.html +15 -15
  129. package/coverage/lcov-report/db/index.js.html +3 -3
  130. package/coverage/lcov-report/db/linkedRows/LinkController.js.html +25 -37
  131. package/coverage/lcov-report/db/linkedRows/index.html +27 -27
  132. package/coverage/lcov-report/db/linkedRows/index.js.html +51 -96
  133. package/coverage/lcov-report/db/linkedRows/linkUtils.js.html +42 -42
  134. package/coverage/lcov-report/db/newid.js.html +4 -4
  135. package/coverage/lcov-report/db/utils.js.html +87 -87
  136. package/coverage/lcov-report/events/AutomationEmitter.js.html +1 -1
  137. package/coverage/lcov-report/events/index.html +1 -1
  138. package/coverage/lcov-report/events/index.js.html +5 -5
  139. package/coverage/lcov-report/events/utils.js.html +3 -3
  140. package/coverage/lcov-report/index.html +135 -120
  141. package/coverage/lcov-report/integrations/tests/TestConfiguration.js.html +1 -1
  142. package/coverage/lcov-report/integrations/tests/index.html +1 -1
  143. package/coverage/lcov-report/middleware/appInfo.js.html +1 -1
  144. package/coverage/lcov-report/middleware/authorized.js.html +173 -65
  145. package/coverage/lcov-report/middleware/builder.js.html +10 -10
  146. package/coverage/lcov-report/middleware/currentapp.js.html +95 -83
  147. package/coverage/lcov-report/middleware/index.html +38 -38
  148. package/coverage/lcov-report/middleware/joi-validator.js.html +3 -3
  149. package/coverage/lcov-report/middleware/resourceId.js.html +1 -1
  150. package/coverage/lcov-report/middleware/selfhost.js.html +1 -1
  151. package/coverage/lcov-report/middleware/usageQuota.js.html +281 -53
  152. package/coverage/lcov-report/middleware/utils.js.html +2 -2
  153. package/coverage/lcov-report/threads/automation.js.html +30 -24
  154. package/coverage/lcov-report/threads/index.html +26 -26
  155. package/coverage/lcov-report/threads/index.js.html +10 -10
  156. package/coverage/lcov-report/threads/query.js.html +39 -24
  157. package/coverage/lcov-report/threads/utils.js.html +14 -14
  158. package/coverage/lcov-report/utilities/bcrypt.js.html +1 -1
  159. package/coverage/lcov-report/utilities/budibaseDir.js.html +7 -7
  160. package/coverage/lcov-report/utilities/centralPath.js.html +4 -4
  161. package/coverage/lcov-report/utilities/csvParser.js.html +6 -6
  162. package/coverage/lcov-report/utilities/global.js.html +58 -49
  163. package/coverage/lcov-report/utilities/index.html +37 -37
  164. package/coverage/lcov-report/utilities/index.js.html +43 -73
  165. package/coverage/lcov-report/utilities/queue/inMemoryQueue.js.html +8 -8
  166. package/coverage/lcov-report/utilities/queue/index.html +1 -1
  167. package/coverage/lcov-report/utilities/routing/index.html +1 -1
  168. package/coverage/lcov-report/utilities/routing/index.js.html +7 -7
  169. package/coverage/lcov-report/utilities/rowProcessor/index.html +27 -27
  170. package/coverage/lcov-report/utilities/rowProcessor/index.js.html +97 -103
  171. package/coverage/lcov-report/utilities/rowProcessor/utils.js.html +75 -27
  172. package/coverage/lcov-report/utilities/scriptRunner.js.html +5 -5
  173. package/coverage/lcov-report/utilities/security.js.html +8 -8
  174. package/coverage/lcov-report/utilities/statusCodes.js.html +1 -1
  175. package/coverage/lcov-report/utilities/usageQuota/index.html +141 -0
  176. package/coverage/lcov-report/utilities/usageQuota/index.js.html +359 -0
  177. package/coverage/lcov-report/utilities/usageQuota/rows.js.html +305 -0
  178. package/coverage/lcov-report/{api/controllers/hosting.js.html → utilities/usageQuota/usageQuoteReset.js.html} +36 -48
  179. package/coverage/lcov-report/utilities/users.js.html +9 -9
  180. package/coverage/lcov-report/utilities/workerRequests.js.html +43 -112
  181. package/coverage/lcov.info +5010 -4425
  182. package/dist/api/controllers/application.js +90 -60
  183. package/dist/api/controllers/auth.js +8 -5
  184. package/dist/api/controllers/automation.js +14 -19
  185. package/dist/api/controllers/cloud.js +2 -3
  186. package/dist/api/controllers/component.js +3 -4
  187. package/dist/api/controllers/datasource.js +20 -10
  188. package/dist/api/controllers/deploy/Deployment.js +3 -6
  189. package/dist/api/controllers/deploy/index.js +12 -13
  190. package/dist/api/controllers/dev.js +5 -5
  191. package/dist/api/controllers/layout.js +3 -3
  192. package/dist/api/controllers/metadata.js +4 -4
  193. package/dist/api/controllers/migrations.js +21 -0
  194. package/dist/api/controllers/permission.js +4 -4
  195. package/dist/api/controllers/query/import/index.js +4 -6
  196. package/dist/api/controllers/query/index.js +11 -10
  197. package/dist/api/controllers/role.js +5 -5
  198. package/dist/api/controllers/routing.js +5 -6
  199. package/dist/api/controllers/row/ExternalRequest.js +90 -67
  200. package/dist/api/controllers/row/external.js +14 -22
  201. package/dist/api/controllers/row/internal.js +55 -93
  202. package/dist/api/controllers/row/internalSearch.js +23 -17
  203. package/dist/api/controllers/row/staticFormula.js +147 -0
  204. package/dist/api/controllers/row/utils.js +13 -14
  205. package/dist/api/controllers/screen.js +5 -7
  206. package/dist/api/controllers/static/index.js +62 -16
  207. package/dist/api/controllers/table/bulkFormula.js +159 -0
  208. package/dist/api/controllers/table/external.js +7 -10
  209. package/dist/api/controllers/table/index.js +16 -13
  210. package/dist/api/controllers/table/internal.js +22 -16
  211. package/dist/api/controllers/table/utils.js +62 -35
  212. package/dist/api/controllers/user.js +43 -43
  213. package/dist/api/controllers/view/index.js +8 -10
  214. package/dist/api/controllers/view/utils.js +9 -4
  215. package/dist/api/controllers/webhook.js +10 -8
  216. package/dist/api/routes/index.js +2 -2
  217. package/dist/api/routes/migrations.js +9 -0
  218. package/dist/api/routes/static.js +2 -1
  219. package/dist/api/routes/tests/utilities/TestFunctions.js +37 -17
  220. package/dist/app.js +35 -5
  221. package/dist/automations/automationUtils.js +2 -3
  222. package/dist/automations/steps/createRow.js +3 -5
  223. package/dist/automations/steps/deleteRow.js +1 -4
  224. package/dist/automations/steps/updateRow.js +1 -1
  225. package/dist/automations/triggers.js +27 -25
  226. package/dist/automations/utils.js +10 -5
  227. package/dist/constants/index.js +7 -0
  228. package/dist/db/linkedRows/LinkController.js +3 -7
  229. package/dist/db/linkedRows/index.js +16 -27
  230. package/dist/db/linkedRows/linkUtils.js +6 -6
  231. package/dist/db/views/staticViews.js +9 -10
  232. package/dist/definitions/datasource.js +1 -0
  233. package/dist/environment.js +4 -1
  234. package/dist/integrations/base/sql.js +62 -21
  235. package/dist/integrations/googlesheets.js +340 -0
  236. package/dist/integrations/index.js +3 -0
  237. package/dist/integrations/utils.js +60 -9
  238. package/dist/middleware/authorized.js +57 -30
  239. package/dist/middleware/builder.js +2 -2
  240. package/dist/middleware/currentapp.js +41 -37
  241. package/dist/middleware/usageQuota.js +82 -15
  242. package/dist/migrations/functions/appUrls.js +46 -0
  243. package/dist/migrations/functions/quotas1.js +50 -0
  244. package/dist/migrations/functions/usageQuotas/index.js +20 -0
  245. package/dist/migrations/functions/usageQuotas/syncApps.js +29 -0
  246. package/dist/migrations/functions/usageQuotas/syncRows.js +33 -0
  247. package/dist/migrations/functions/userEmailViewCasing.js +24 -0
  248. package/dist/migrations/index.js +62 -0
  249. package/dist/package.json +8 -5
  250. package/dist/tests/utilities/TestConfiguration.js +80 -50
  251. package/dist/threads/automation.js +13 -11
  252. package/dist/threads/query.js +15 -11
  253. package/dist/tsconfig.tsbuildinfo +1 -1
  254. package/dist/utilities/fileSystem/index.js +4 -3
  255. package/dist/utilities/global.js +15 -12
  256. package/dist/utilities/index.js +7 -17
  257. package/dist/utilities/routing/index.js +5 -5
  258. package/dist/utilities/rowProcessor/index.js +23 -17
  259. package/dist/utilities/rowProcessor/utils.js +14 -4
  260. package/dist/utilities/{usageQuota.js → usageQuota/index.js} +45 -31
  261. package/dist/utilities/usageQuota/rows.js +78 -0
  262. package/dist/utilities/usageQuota/usageQuoteReset.js +16 -0
  263. package/dist/utilities/users.js +3 -3
  264. package/dist/utilities/workerRequests.js +4 -24
  265. package/nodemon.json +1 -1
  266. package/package.json +9 -6
  267. package/scripts/integrations/mssql/data/Dockerfile +1 -1
  268. package/scripts/integrations/mssql/data/setup.sql +17 -4
  269. package/scripts/integrations/postgres/init.sql +11 -6
  270. package/scripts/likeCypress.ts +1 -1
  271. package/src/api/controllers/application.js +85 -50
  272. package/src/api/controllers/auth.js +8 -5
  273. package/src/api/controllers/automation.js +13 -23
  274. package/src/api/controllers/cloud.js +2 -3
  275. package/src/api/controllers/component.js +3 -4
  276. package/src/api/controllers/datasource.js +21 -11
  277. package/src/api/controllers/deploy/Deployment.js +3 -7
  278. package/src/api/controllers/deploy/index.js +20 -13
  279. package/src/api/controllers/dev.js +5 -5
  280. package/src/api/controllers/layout.js +3 -3
  281. package/src/api/controllers/metadata.js +4 -9
  282. package/src/api/controllers/migrations.js +13 -0
  283. package/src/api/controllers/permission.js +4 -4
  284. package/src/api/controllers/query/import/index.ts +4 -6
  285. package/src/api/controllers/query/import/tests/index.spec.js +2 -1
  286. package/src/api/controllers/query/index.js +11 -10
  287. package/src/api/controllers/role.js +5 -5
  288. package/src/api/controllers/routing.js +5 -6
  289. package/src/api/controllers/row/ExternalRequest.ts +67 -43
  290. package/src/api/controllers/row/external.js +27 -58
  291. package/src/api/controllers/row/internal.js +54 -90
  292. package/src/api/controllers/row/internalSearch.js +23 -17
  293. package/src/api/controllers/row/staticFormula.js +156 -0
  294. package/src/api/controllers/row/utils.js +13 -18
  295. package/src/api/controllers/screen.js +5 -7
  296. package/src/api/controllers/static/index.js +66 -15
  297. package/src/api/controllers/table/bulkFormula.js +173 -0
  298. package/src/api/controllers/table/external.js +7 -10
  299. package/src/api/controllers/table/index.js +20 -28
  300. package/src/api/controllers/table/internal.js +24 -19
  301. package/src/api/controllers/table/utils.js +78 -42
  302. package/src/api/controllers/user.js +46 -45
  303. package/src/api/controllers/view/index.js +8 -10
  304. package/src/api/controllers/view/utils.js +9 -4
  305. package/src/api/controllers/webhook.js +10 -8
  306. package/src/api/routes/index.js +2 -2
  307. package/src/api/routes/migrations.js +14 -0
  308. package/src/api/routes/static.js +5 -0
  309. package/src/api/routes/tests/application.spec.js +2 -2
  310. package/src/api/routes/tests/auth.spec.js +1 -2
  311. package/src/api/routes/tests/automation.spec.js +1 -0
  312. package/src/api/routes/tests/misc.spec.js +0 -1
  313. package/src/api/routes/tests/routing.spec.js +21 -12
  314. package/src/api/routes/tests/row.spec.js +7 -4
  315. package/src/api/routes/tests/static.spec.js +98 -0
  316. package/src/api/routes/tests/utilities/TestFunctions.js +39 -17
  317. package/src/app.ts +18 -5
  318. package/src/automations/automationUtils.js +2 -3
  319. package/src/automations/steps/createRow.js +2 -5
  320. package/src/automations/steps/deleteRow.js +1 -4
  321. package/src/automations/steps/updateRow.js +1 -1
  322. package/src/automations/triggers.js +33 -31
  323. package/src/automations/utils.js +9 -5
  324. package/src/constants/index.js +9 -0
  325. package/src/db/linkedRows/LinkController.js +3 -7
  326. package/src/db/linkedRows/index.js +16 -31
  327. package/src/db/linkedRows/linkUtils.js +6 -6
  328. package/src/db/tests/linkController.spec.js +0 -1
  329. package/src/db/tests/linkTests.spec.js +5 -6
  330. package/src/db/views/staticViews.js +8 -10
  331. package/src/definitions/common.ts +3 -0
  332. package/src/definitions/datasource.ts +3 -0
  333. package/src/environment.js +4 -1
  334. package/src/integrations/base/sql.ts +75 -29
  335. package/src/integrations/googlesheets.ts +353 -0
  336. package/src/integrations/index.ts +3 -0
  337. package/src/integrations/tests/sql.spec.js +16 -0
  338. package/src/integrations/utils.ts +75 -12
  339. package/src/middleware/authorized.js +66 -30
  340. package/src/middleware/builder.js +2 -2
  341. package/src/middleware/currentapp.js +50 -46
  342. package/src/middleware/tests/authorized.spec.js +13 -6
  343. package/src/middleware/tests/currentapp.spec.js +6 -0
  344. package/src/middleware/tests/usageQuota.spec.js +18 -24
  345. package/src/middleware/usageQuota.js +93 -17
  346. package/src/migrations/functions/appUrls.ts +34 -0
  347. package/src/migrations/functions/quotas1.ts +20 -0
  348. package/src/migrations/functions/tests/appUrls.spec.js +29 -0
  349. package/src/migrations/functions/tests/quotas1.spec.js +27 -0
  350. package/src/migrations/functions/tests/userEmailViewCasing.spec.js +25 -0
  351. package/src/migrations/functions/usageQuotas/index.ts +8 -0
  352. package/src/migrations/functions/usageQuotas/syncApps.ts +18 -0
  353. package/src/migrations/functions/usageQuotas/syncRows.ts +22 -0
  354. package/src/migrations/functions/usageQuotas/tests/syncApps.spec.js +37 -0
  355. package/src/migrations/functions/usageQuotas/tests/syncRows.spec.js +43 -0
  356. package/src/migrations/functions/userEmailViewCasing.ts +13 -0
  357. package/src/migrations/index.ts +56 -0
  358. package/src/module.d.ts +3 -0
  359. package/src/tests/utilities/TestConfiguration.js +82 -55
  360. package/src/threads/automation.js +17 -15
  361. package/src/threads/query.js +17 -12
  362. package/src/utilities/fileSystem/index.js +4 -3
  363. package/src/utilities/global.js +15 -12
  364. package/src/utilities/index.js +7 -17
  365. package/src/utilities/routing/index.js +5 -5
  366. package/src/utilities/rowProcessor/index.js +25 -27
  367. package/src/utilities/rowProcessor/utils.js +23 -7
  368. package/src/utilities/tests/usageQuota/usageQuota.spec.js +72 -0
  369. package/src/utilities/usageQuota/index.js +93 -0
  370. package/src/utilities/usageQuota/rows.js +75 -0
  371. package/src/utilities/usageQuota/usageQuoteReset.js +18 -0
  372. package/src/utilities/users.js +3 -3
  373. package/src/utilities/workerRequests.js +4 -27
  374. package/tsconfig.json +2 -1
  375. package/builder/assets/index.39e01193.css +0 -1
  376. package/dist/api/controllers/hosting.js +0 -30
  377. package/dist/api/routes/hosting.js +0 -11
  378. package/src/api/controllers/hosting.js +0 -22
  379. package/src/api/routes/hosting.js +0 -13
  380. package/src/api/routes/tests/hosting.spec.js +0 -36
  381. package/src/utilities/usageQuota.js +0 -73
@@ -7,10 +7,10 @@ const { deleteFiles } = require("../../utilities/fileSystem/utilities")
7
7
  const { ObjectStoreBuckets } = require("../../constants")
8
8
  const {
9
9
  isProdAppID,
10
- getDeployedAppID,
10
+ getProdAppID,
11
11
  dbExists,
12
12
  } = require("@budibase/backend-core/db")
13
- const CouchDB = require("../../db")
13
+ const { getAppId } = require("@budibase/backend-core/context")
14
14
 
15
15
  const BASE_AUTO_ID = 1
16
16
 
@@ -180,6 +180,8 @@ function processAutoColumn(
180
180
  }
181
181
  exports.processAutoColumn = processAutoColumn
182
182
 
183
+ exports.processFormulas = processFormulas
184
+
183
185
  /**
184
186
  * This will coerce a value to the correct types based on the type transform map
185
187
  * @param {object} row The value to coerce
@@ -229,11 +231,12 @@ exports.inputProcessing = (
229
231
  }
230
232
  continue
231
233
  }
232
- // specific case to delete formula values if they get saved
233
- // type coercion cannot completely remove the field, so have to do it here
234
+ // remove any formula values, they are to be generated
234
235
  if (field.type === FieldTypes.FORMULA) {
235
236
  delete clonedRow[key]
236
- } else {
237
+ }
238
+ // otherwise coerce what is there to correct types
239
+ else {
237
240
  clonedRow[key] = exports.coerce(value, field.type)
238
241
  }
239
242
  }
@@ -250,30 +253,23 @@ exports.inputProcessing = (
250
253
  /**
251
254
  * This function enriches the input rows with anything they are supposed to contain, for example
252
255
  * link records or attachment links.
253
- * @param {object} ctx the request which is looking for enriched rows.
254
256
  * @param {object} table the table from which these rows came from originally, this is used to determine
255
257
  * the schema of the rows and then enrich.
256
258
  * @param {object[]|object} rows the rows which are to be enriched.
257
259
  * @param {object} opts used to set some options for the output, such as disabling relationship squashing.
258
260
  * @returns {object[]|object} the enriched rows will be returned.
259
261
  */
260
- exports.outputProcessing = async (
261
- ctx,
262
- table,
263
- rows,
264
- opts = { squash: true }
265
- ) => {
266
- const appId = ctx.appId
262
+ exports.outputProcessing = async (table, rows, opts = { squash: true }) => {
267
263
  let wasArray = true
268
264
  if (!(rows instanceof Array)) {
269
265
  rows = [rows]
270
266
  wasArray = false
271
267
  }
272
268
  // attach any linked row information
273
- let enriched = await linkRows.attachFullLinkedDocs(ctx, table, rows)
269
+ let enriched = await linkRows.attachFullLinkedDocs(table, rows)
274
270
 
275
271
  // process formulas
276
- enriched = processFormulas(table, enriched)
272
+ enriched = processFormulas(table, enriched, { dynamic: true })
277
273
 
278
274
  // update the attachments URL depending on hosting
279
275
  for (let [property, column] of Object.entries(table.schema)) {
@@ -289,29 +285,27 @@ exports.outputProcessing = async (
289
285
  }
290
286
  }
291
287
  if (opts.squash) {
292
- enriched = await linkRows.squashLinksToPrimaryDisplay(
293
- appId,
294
- table,
295
- enriched
296
- )
288
+ enriched = await linkRows.squashLinksToPrimaryDisplay(table, enriched)
297
289
  }
298
290
  return wasArray ? enriched : enriched[0]
299
291
  }
300
292
 
301
293
  /**
302
294
  * Clean up any attachments that were attached to a row.
303
- * @param {string} appId The ID of the app from which a row is being deleted.
304
295
  * @param {object} table The table from which a row is being removed.
305
296
  * @param {any} row optional - the row being removed.
306
297
  * @param {any} rows optional - if multiple rows being deleted can do this in bulk.
307
298
  * @param {any} oldRow optional - if updating a row this will determine the difference.
299
+ * @param {any} oldTable optional - if updating a table, can supply the old table to look for
300
+ * deleted attachment columns.
308
301
  * @return {Promise<void>} When all attachments have been removed this will return.
309
302
  */
310
- exports.cleanupAttachments = async (appId, table, { row, rows, oldRow }) => {
303
+ exports.cleanupAttachments = async (table, { row, rows, oldRow, oldTable }) => {
304
+ const appId = getAppId()
311
305
  if (!isProdAppID(appId)) {
312
- const prodAppId = getDeployedAppID(appId)
306
+ const prodAppId = getProdAppID(appId)
313
307
  // if prod exists, then don't allow deleting
314
- const exists = await dbExists(CouchDB, prodAppId)
308
+ const exists = await dbExists(prodAppId)
315
309
  if (exists) {
316
310
  return
317
311
  }
@@ -322,12 +316,16 @@ exports.cleanupAttachments = async (appId, table, { row, rows, oldRow }) => {
322
316
  files = files.concat(row[key].map(attachment => attachment.key))
323
317
  }
324
318
  }
325
- for (let [key, schema] of Object.entries(table.schema)) {
319
+ const schemaToUse = oldTable ? oldTable.schema : table.schema
320
+ for (let [key, schema] of Object.entries(schemaToUse)) {
326
321
  if (schema.type !== FieldTypes.ATTACHMENT) {
327
322
  continue
328
323
  }
329
- // if updating, need to manage the differences
330
- if (oldRow && row) {
324
+ // old table had this column, new table doesn't - delete it
325
+ if (oldTable && !table.schema[key]) {
326
+ rows.forEach(row => addFiles(row, key))
327
+ } else if (oldRow && row) {
328
+ // if updating, need to manage the differences
331
329
  files = files.concat(getRemovedAttachmentKeys(oldRow, row, key))
332
330
  } else if (row) {
333
331
  addFiles(row, key)
@@ -1,23 +1,39 @@
1
- const { FieldTypes } = require("../../constants")
1
+ const { FieldTypes, FormulaTypes } = require("../../constants")
2
2
  const { processStringSync } = require("@budibase/string-templates")
3
3
 
4
4
  /**
5
5
  * Looks through the rows provided and finds formulas - which it then processes.
6
6
  */
7
- exports.processFormulas = (table, rows) => {
7
+ exports.processFormulas = (
8
+ table,
9
+ rows,
10
+ { dynamic, contextRows } = { dynamic: true }
11
+ ) => {
8
12
  const single = !Array.isArray(rows)
9
13
  if (single) {
10
14
  rows = [rows]
15
+ contextRows = contextRows ? [contextRows] : contextRows
11
16
  }
12
17
  for (let [column, schema] of Object.entries(table.schema)) {
13
- if (schema.type !== FieldTypes.FORMULA) {
18
+ const isStatic = schema.formulaType === FormulaTypes.STATIC
19
+ if (
20
+ schema.type !== FieldTypes.FORMULA ||
21
+ (dynamic && isStatic) ||
22
+ (!dynamic && !isStatic)
23
+ ) {
14
24
  continue
15
25
  }
16
26
  // iterate through rows and process formula
17
- rows = rows.map(row => ({
18
- ...row,
19
- [column]: processStringSync(schema.formula, row),
20
- }))
27
+ for (let i = 0; i < rows.length; i++) {
28
+ if (schema.formula) {
29
+ let row = rows[i]
30
+ let context = contextRows ? contextRows[i] : row
31
+ rows[i] = {
32
+ ...row,
33
+ [column]: processStringSync(schema.formula, context),
34
+ }
35
+ }
36
+ }
21
37
  }
22
38
  return single ? rows[0] : rows
23
39
  }
@@ -0,0 +1,72 @@
1
+ const getTenantId = jest.fn()
2
+ jest.mock("@budibase/backend-core/tenancy", () => ({
3
+ getTenantId
4
+ }))
5
+ const usageQuota = require("../../usageQuota")
6
+ const env = require("../../../environment")
7
+
8
+ class TestConfiguration {
9
+ constructor() {
10
+ this.enableQuotas()
11
+ }
12
+
13
+ enableQuotas = () => {
14
+ env.USE_QUOTAS = 1
15
+ }
16
+
17
+ disableQuotas = () => {
18
+ env.USE_QUOTAS = null
19
+ }
20
+
21
+ setTenantId = (tenantId) => {
22
+ getTenantId.mockReturnValue(tenantId)
23
+ }
24
+
25
+ setExcludedTenants = (tenants) => {
26
+ env.EXCLUDE_QUOTAS_TENANTS = tenants
27
+ }
28
+
29
+ reset = () => {
30
+ this.disableQuotas()
31
+ this.setExcludedTenants(null)
32
+ }
33
+ }
34
+
35
+ describe("usageQuota", () => {
36
+ let config
37
+
38
+ beforeEach(() => {
39
+ config = new TestConfiguration()
40
+ })
41
+
42
+ afterEach(() => {
43
+ config.reset()
44
+ })
45
+
46
+ describe("useQuotas", () => {
47
+ it("works when no settings have been provided", () => {
48
+ config.reset()
49
+ expect(usageQuota.useQuotas()).toBe(false)
50
+ })
51
+ it("honours USE_QUOTAS setting", () => {
52
+ config.disableQuotas()
53
+ expect(usageQuota.useQuotas()).toBe(false)
54
+
55
+ config.enableQuotas()
56
+ expect(usageQuota.useQuotas()).toBe(true)
57
+ })
58
+ it("honours EXCLUDE_QUOTAS_TENANTS setting", () => {
59
+ config.setTenantId("test")
60
+
61
+ // tenantId is in the list
62
+ config.setExcludedTenants("test, test2, test2")
63
+ expect(usageQuota.useQuotas()).toBe(false)
64
+ config.setExcludedTenants("test,test2,test2")
65
+ expect(usageQuota.useQuotas()).toBe(false)
66
+
67
+ // tenantId is not in the list
68
+ config.setTenantId("other")
69
+ expect(usageQuota.useQuotas()).toBe(true)
70
+ })
71
+ })
72
+ })
@@ -0,0 +1,93 @@
1
+ const env = require("../../environment")
2
+ const { getGlobalDB, getTenantId } = require("@budibase/backend-core/tenancy")
3
+ const {
4
+ StaticDatabases,
5
+ generateNewUsageQuotaDoc,
6
+ } = require("@budibase/backend-core/db")
7
+
8
+ exports.useQuotas = () => {
9
+ // check if quotas are enabled
10
+ if (env.USE_QUOTAS) {
11
+ // check if there are any tenants without limits
12
+ if (env.EXCLUDE_QUOTAS_TENANTS) {
13
+ const excludedTenants = env.EXCLUDE_QUOTAS_TENANTS.replace(
14
+ /\s/g,
15
+ ""
16
+ ).split(",")
17
+ const tenantId = getTenantId()
18
+ if (excludedTenants.includes(tenantId)) {
19
+ return false
20
+ }
21
+ }
22
+ return true
23
+ }
24
+ return false
25
+ }
26
+
27
+ exports.Properties = {
28
+ ROW: "rows",
29
+ UPLOAD: "storage", // doesn't work yet
30
+ VIEW: "views", // doesn't work yet
31
+ USER: "users", // doesn't work yet
32
+ AUTOMATION: "automationRuns", // doesn't work yet
33
+ APPS: "apps",
34
+ EMAILS: "emails", // doesn't work yet
35
+ }
36
+
37
+ exports.getUsageQuotaDoc = async db => {
38
+ let quota
39
+ try {
40
+ quota = await db.get(StaticDatabases.GLOBAL.docs.usageQuota)
41
+ } catch (err) {
42
+ // doc doesn't exist. Create it
43
+ quota = generateNewUsageQuotaDoc()
44
+ const response = await db.put(quota)
45
+ quota._rev = response.rev
46
+ }
47
+
48
+ return quota
49
+ }
50
+
51
+ /**
52
+ * Given a specified tenantId this will add to the usage object for the specified property.
53
+ * @param {string} property The property which is to be added to (within the nested usageQuota object).
54
+ * @param {number} usage The amount (this can be negative) to adjust the number by.
55
+ * @param {object} opts optional - options such as dryRun, to check what update will do.
56
+ * @returns {Promise<void>} When this completes the API key will now be up to date - the quota period may have
57
+ * also been reset after this call.
58
+ */
59
+ exports.update = async (property, usage, opts = { dryRun: false }) => {
60
+ if (!exports.useQuotas()) {
61
+ return
62
+ }
63
+
64
+ try {
65
+ const db = getGlobalDB()
66
+ const quota = await exports.getUsageQuotaDoc(db)
67
+
68
+ // increment the quota
69
+ quota.usageQuota[property] += usage
70
+
71
+ if (
72
+ quota.usageQuota[property] > quota.usageLimits[property] &&
73
+ usage > 0 // allow for decrementing usage when the quota is already exceeded
74
+ ) {
75
+ throw new Error(
76
+ `You have exceeded your usage quota of ${quota.usageLimits[property]} ${property}.`
77
+ )
78
+ }
79
+
80
+ if (quota.usageQuota[property] < 0) {
81
+ // never go negative if the quota has previously been exceeded
82
+ quota.usageQuota[property] = 0
83
+ }
84
+
85
+ // update the usage quotas
86
+ if (!opts.dryRun) {
87
+ await db.put(quota)
88
+ }
89
+ } catch (err) {
90
+ console.error(`Error updating usage quotas for ${property}`, err)
91
+ throw err
92
+ }
93
+ }
@@ -0,0 +1,75 @@
1
+ const { getRowParams, USER_METDATA_PREFIX } = require("../../db/utils")
2
+ const CouchDB = require("../../db")
3
+ const { isDevAppID, getDevelopmentAppID } = require("@budibase/backend-core/db")
4
+
5
+ const ROW_EXCLUSIONS = [USER_METDATA_PREFIX]
6
+
7
+ const getAppPairs = appIds => {
8
+ // collect the app ids into dev / prod pairs
9
+ // keyed by the dev app id
10
+ const pairs = {}
11
+ for (let appId of appIds) {
12
+ const devId = getDevelopmentAppID(appId)
13
+ if (!pairs[devId]) {
14
+ pairs[devId] = {}
15
+ }
16
+ if (isDevAppID(appId)) {
17
+ pairs[devId].devId = appId
18
+ } else {
19
+ pairs[devId].prodId = appId
20
+ }
21
+ }
22
+ return pairs
23
+ }
24
+
25
+ const getAppRows = async appId => {
26
+ // need to specify the app ID, as this is used for different apps in one call
27
+ const appDb = new CouchDB(appId)
28
+ const response = await appDb.allDocs(
29
+ getRowParams(null, null, {
30
+ include_docs: false,
31
+ })
32
+ )
33
+ return response.rows
34
+ .map(r => r.id)
35
+ .filter(id => {
36
+ for (let exclusion of ROW_EXCLUSIONS) {
37
+ if (id.startsWith(exclusion)) {
38
+ return false
39
+ }
40
+ }
41
+ return true
42
+ })
43
+ }
44
+
45
+ /**
46
+ * Return a set of all rows in the given app ids.
47
+ * The returned rows will be unique on a per dev/prod app basis.
48
+ * Rows duplicates may exist across apps due to data import so they are not filtered out.
49
+ */
50
+ exports.getUniqueRows = async appIds => {
51
+ let uniqueRows = []
52
+ const pairs = getAppPairs(appIds)
53
+
54
+ for (let pair of Object.values(pairs)) {
55
+ let appRows = []
56
+ for (let appId of [pair.devId, pair.prodId]) {
57
+ if (!appId) {
58
+ continue
59
+ }
60
+ try {
61
+ appRows.push(await getAppRows(appId))
62
+ } catch (e) {
63
+ console.error(e)
64
+ // don't error out if we can't count the app rows, just continue
65
+ }
66
+ }
67
+
68
+ // ensure uniqueness on a per app pair basis
69
+ // this can't be done on all rows because app import results in
70
+ // duplicate row ids across apps
71
+ uniqueRows = uniqueRows.concat(...new Set(appRows))
72
+ }
73
+
74
+ return uniqueRows
75
+ }
@@ -0,0 +1,18 @@
1
+ // UNUSED CODE
2
+ // Preserved for future use
3
+
4
+ /* eslint-disable no-unused-vars */
5
+
6
+ function getNewQuotaReset() {
7
+ return Date.now() + 2592000000
8
+ }
9
+
10
+ function resetQuotasIfRequired(quota) {
11
+ // Check if the quota needs reset
12
+ if (Date.now() >= quota.quotaReset) {
13
+ quota.quotaReset = getNewQuotaReset()
14
+ for (let prop of Object.keys(quota.usageQuota)) {
15
+ quota.usageQuota[prop] = 0
16
+ }
17
+ }
18
+ }
@@ -1,13 +1,13 @@
1
- const CouchDB = require("../db")
2
1
  const { InternalTables } = require("../db/utils")
3
2
  const { getGlobalUser } = require("../utilities/global")
3
+ const { getAppDB } = require("@budibase/backend-core/context")
4
4
 
5
5
  exports.getFullUser = async (ctx, userId) => {
6
- const global = await getGlobalUser(ctx.appId, userId)
6
+ const global = await getGlobalUser(userId)
7
7
  let metadata
8
8
  try {
9
9
  // this will throw an error if the db doesn't exist, or there is no appId
10
- const db = new CouchDB(ctx.appId)
10
+ const db = getAppDB()
11
11
  metadata = await db.get(userId)
12
12
  } catch (err) {
13
13
  // it is fine if there is no user metadata, just remove global db info
@@ -1,7 +1,7 @@
1
1
  const fetch = require("node-fetch")
2
2
  const env = require("../environment")
3
3
  const { checkSlashesInUrl } = require("./index")
4
- const { getDeployedAppID } = require("@budibase/backend-core/db")
4
+ const { getProdAppID } = require("@budibase/backend-core/db")
5
5
  const { updateAppRole } = require("./global")
6
6
  const { Headers } = require("@budibase/backend-core/constants")
7
7
  const { getTenantId, isTenantIdSet } = require("@budibase/backend-core/tenancy")
@@ -58,29 +58,6 @@ exports.sendSmtpEmail = async (to, from, subject, contents, automation) => {
58
58
  return response.json()
59
59
  }
60
60
 
61
- exports.getDeployedApps = async () => {
62
- try {
63
- const response = await fetch(
64
- checkSlashesInUrl(env.WORKER_URL + `/api/apps`),
65
- request(null, {
66
- method: "GET",
67
- })
68
- )
69
- const json = await response.json()
70
- const apps = {}
71
- for (let [key, value] of Object.entries(json)) {
72
- if (value.url) {
73
- value.url = value.url.toLowerCase()
74
- apps[key.toLowerCase()] = value
75
- }
76
- }
77
- return apps
78
- } catch (err) {
79
- // error, cannot determine deployed apps, don't stop app creation - sort this later
80
- return {}
81
- }
82
- }
83
-
84
61
  exports.getGlobalSelf = async (ctx, appId = null) => {
85
62
  const endpoint = `/api/global/users/self`
86
63
  const response = await fetch(
@@ -93,15 +70,15 @@ exports.getGlobalSelf = async (ctx, appId = null) => {
93
70
  }
94
71
  let json = await response.json()
95
72
  if (appId) {
96
- json = updateAppRole(appId, json)
73
+ json = updateAppRole(json)
97
74
  }
98
75
  return json
99
76
  }
100
77
 
101
78
  exports.removeAppFromUserRoles = async (ctx, appId) => {
102
- const deployedAppId = getDeployedAppID(appId)
79
+ const prodAppId = getProdAppID(appId)
103
80
  const response = await fetch(
104
- checkSlashesInUrl(env.WORKER_URL + `/api/global/roles/${deployedAppId}`),
81
+ checkSlashesInUrl(env.WORKER_URL + `/api/global/roles/${prodAppId}`),
105
82
  request(ctx, {
106
83
  method: "DELETE",
107
84
  })
package/tsconfig.json CHANGED
@@ -12,7 +12,8 @@
12
12
  "incremental": true
13
13
  },
14
14
  "include": [
15
- "./src/**/*"
15
+ "./src/**/*",
16
+ "./src/module.d.ts"
16
17
  ],
17
18
  "exclude": [
18
19
  "node_modules",