@budibase/server 1.0.49-alpha.6 → 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 (376) 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.1b905242.js → index.2c37968e.js} +231 -234
  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 +2816 -3119
  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 +27 -21
  35. package/coverage/lcov-report/api/controllers/row/index.html +34 -49
  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 +26 -62
  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 +4423 -5022
  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 +63 -76
  194. package/dist/api/controllers/row/external.js +4 -4
  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 +6 -13
  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 +13 -23
  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/likeCypress.ts +1 -1
  250. package/src/api/controllers/application.js +50 -85
  251. package/src/api/controllers/auth.js +5 -8
  252. package/src/api/controllers/automation.js +23 -13
  253. package/src/api/controllers/cloud.js +3 -2
  254. package/src/api/controllers/component.js +4 -3
  255. package/src/api/controllers/datasource.js +11 -21
  256. package/src/api/controllers/deploy/Deployment.js +7 -3
  257. package/src/api/controllers/deploy/index.js +13 -20
  258. package/src/api/controllers/dev.js +5 -5
  259. package/src/api/controllers/hosting.js +22 -0
  260. package/src/api/controllers/layout.js +3 -3
  261. package/src/api/controllers/metadata.js +9 -4
  262. package/src/api/controllers/permission.js +4 -4
  263. package/src/api/controllers/query/import/index.ts +6 -4
  264. package/src/api/controllers/query/import/tests/index.spec.js +1 -2
  265. package/src/api/controllers/query/index.js +10 -11
  266. package/src/api/controllers/role.js +5 -5
  267. package/src/api/controllers/routing.js +6 -5
  268. package/src/api/controllers/row/ExternalRequest.ts +42 -53
  269. package/src/api/controllers/row/external.js +6 -4
  270. package/src/api/controllers/row/internal.js +90 -54
  271. package/src/api/controllers/row/internalSearch.js +17 -23
  272. package/src/api/controllers/row/utils.js +18 -13
  273. package/src/api/controllers/screen.js +7 -5
  274. package/src/api/controllers/static/index.js +12 -65
  275. package/src/api/controllers/table/external.js +10 -7
  276. package/src/api/controllers/table/index.js +28 -20
  277. package/src/api/controllers/table/internal.js +19 -24
  278. package/src/api/controllers/table/utils.js +42 -78
  279. package/src/api/controllers/user.js +20 -19
  280. package/src/api/controllers/view/index.js +10 -8
  281. package/src/api/controllers/view/utils.js +4 -9
  282. package/src/api/controllers/webhook.js +8 -10
  283. package/src/api/routes/hosting.js +13 -0
  284. package/src/api/routes/index.js +2 -2
  285. package/src/api/routes/static.js +0 -5
  286. package/src/api/routes/tests/application.spec.js +2 -2
  287. package/src/api/routes/tests/auth.spec.js +2 -1
  288. package/src/api/routes/tests/automation.spec.js +0 -1
  289. package/src/api/routes/tests/hosting.spec.js +36 -0
  290. package/src/api/routes/tests/misc.spec.js +1 -0
  291. package/src/api/routes/tests/routing.spec.js +12 -21
  292. package/src/api/routes/tests/row.spec.js +4 -7
  293. package/src/api/routes/tests/utilities/TestFunctions.js +17 -39
  294. package/src/app.ts +5 -18
  295. package/src/automations/automationUtils.js +3 -2
  296. package/src/automations/steps/createRow.js +5 -2
  297. package/src/automations/steps/deleteRow.js +4 -1
  298. package/src/automations/steps/updateRow.js +1 -1
  299. package/src/automations/triggers.js +31 -33
  300. package/src/automations/utils.js +5 -9
  301. package/src/constants/index.js +0 -9
  302. package/src/db/linkedRows/LinkController.js +7 -3
  303. package/src/db/linkedRows/index.js +31 -16
  304. package/src/db/linkedRows/linkUtils.js +6 -6
  305. package/src/db/tests/linkController.spec.js +1 -0
  306. package/src/db/tests/linkTests.spec.js +6 -5
  307. package/src/db/views/staticViews.js +10 -8
  308. package/src/definitions/common.ts +0 -3
  309. package/src/definitions/datasource.ts +0 -3
  310. package/src/environment.js +1 -4
  311. package/src/integrations/base/sql.ts +7 -14
  312. package/src/integrations/index.ts +0 -3
  313. package/src/integrations/tests/sql.spec.js +0 -16
  314. package/src/integrations/utils.ts +12 -75
  315. package/src/middleware/authorized.js +30 -66
  316. package/src/middleware/builder.js +2 -2
  317. package/src/middleware/currentapp.js +46 -50
  318. package/src/middleware/tests/authorized.spec.js +6 -13
  319. package/src/middleware/tests/currentapp.spec.js +0 -6
  320. package/src/middleware/tests/usageQuota.spec.js +24 -18
  321. package/src/middleware/usageQuota.js +17 -93
  322. package/src/tests/utilities/TestConfiguration.js +55 -82
  323. package/src/threads/automation.js +15 -17
  324. package/src/threads/query.js +14 -26
  325. package/src/utilities/fileSystem/index.js +3 -4
  326. package/src/utilities/global.js +12 -15
  327. package/src/utilities/index.js +17 -7
  328. package/src/utilities/routing/index.js +5 -5
  329. package/src/utilities/rowProcessor/index.js +27 -25
  330. package/src/utilities/rowProcessor/utils.js +7 -23
  331. package/src/utilities/usageQuota.js +73 -0
  332. package/src/utilities/users.js +3 -3
  333. package/src/utilities/workerRequests.js +27 -4
  334. package/builder/assets/index.83c0944f.css +0 -1
  335. package/coverage/lcov-report/api/controllers/migrations.js.html +0 -119
  336. package/coverage/lcov-report/api/controllers/row/staticFormula.js.html +0 -548
  337. package/coverage/lcov-report/api/controllers/table/bulkFormula.js.html +0 -599
  338. package/coverage/lcov-report/utilities/usageQuota/index.html +0 -141
  339. package/coverage/lcov-report/utilities/usageQuota/index.js.html +0 -359
  340. package/coverage/lcov-report/utilities/usageQuota/rows.js.html +0 -305
  341. package/dist/api/controllers/migrations.js +0 -21
  342. package/dist/api/controllers/row/staticFormula.js +0 -147
  343. package/dist/api/controllers/table/bulkFormula.js +0 -159
  344. package/dist/api/routes/migrations.js +0 -9
  345. package/dist/integrations/googlesheets.js +0 -340
  346. package/dist/migrations/functions/appUrls.js +0 -46
  347. package/dist/migrations/functions/quotas1.js +0 -50
  348. package/dist/migrations/functions/usageQuotas/index.js +0 -20
  349. package/dist/migrations/functions/usageQuotas/syncApps.js +0 -30
  350. package/dist/migrations/functions/usageQuotas/syncRows.js +0 -33
  351. package/dist/migrations/functions/userEmailViewCasing.js +0 -24
  352. package/dist/migrations/index.js +0 -62
  353. package/dist/utilities/usageQuota/rows.js +0 -78
  354. package/dist/utilities/usageQuota/usageQuoteReset.js +0 -16
  355. package/src/api/controllers/migrations.js +0 -13
  356. package/src/api/controllers/row/staticFormula.js +0 -156
  357. package/src/api/controllers/table/bulkFormula.js +0 -173
  358. package/src/api/routes/migrations.js +0 -14
  359. package/src/api/routes/tests/static.spec.js +0 -98
  360. package/src/integrations/googlesheets.ts +0 -353
  361. package/src/migrations/functions/appUrls.ts +0 -34
  362. package/src/migrations/functions/quotas1.ts +0 -20
  363. package/src/migrations/functions/tests/appUrls.spec.js +0 -29
  364. package/src/migrations/functions/tests/quotas1.spec.js +0 -27
  365. package/src/migrations/functions/tests/userEmailViewCasing.spec.js +0 -25
  366. package/src/migrations/functions/usageQuotas/index.ts +0 -8
  367. package/src/migrations/functions/usageQuotas/syncApps.ts +0 -19
  368. package/src/migrations/functions/usageQuotas/syncRows.ts +0 -22
  369. package/src/migrations/functions/usageQuotas/tests/syncApps.spec.js +0 -37
  370. package/src/migrations/functions/usageQuotas/tests/syncRows.spec.js +0 -43
  371. package/src/migrations/functions/userEmailViewCasing.ts +0 -13
  372. package/src/migrations/index.ts +0 -56
  373. package/src/utilities/tests/usageQuota/usageQuota.spec.js +0 -72
  374. package/src/utilities/usageQuota/index.js +0 -93
  375. package/src/utilities/usageQuota/rows.js +0 -75
  376. package/src/utilities/usageQuota/usageQuoteReset.js +0 -18
@@ -5,11 +5,11 @@ const automationUtils = require("../automations/automationUtils")
5
5
  const AutomationEmitter = require("../events/AutomationEmitter")
6
6
  const { processObject } = require("@budibase/string-templates")
7
7
  const { DEFAULT_TENANT_ID } = require("@budibase/backend-core/constants")
8
+ const CouchDB = require("../db")
8
9
  const { DocumentTypes, isDevAppID } = require("../db/utils")
9
10
  const { doInTenant } = require("@budibase/backend-core/tenancy")
10
11
  const usage = require("../utilities/usageQuota")
11
12
  const { definitions: triggerDefs } = require("../automations/triggerInfo")
12
- const { doInAppContext, getAppDB } = require("@budibase/backend-core/context")
13
13
 
14
14
  const FILTER_STEP_ID = actions.ACTION_DEFINITIONS.FILTER.stepId
15
15
  const CRON_STEP_ID = triggerDefs.CRON.stepId
@@ -59,10 +59,11 @@ class Orchestrator {
59
59
  }
60
60
 
61
61
  async getApp() {
62
+ const appId = this._appId
62
63
  if (this._app) {
63
64
  return this._app
64
65
  }
65
- const db = getAppDB()
66
+ const db = new CouchDB(appId)
66
67
  this._app = await db.get(DocumentTypes.APP_METADATA)
67
68
  return this._app
68
69
  }
@@ -130,19 +131,16 @@ class Orchestrator {
130
131
  }
131
132
 
132
133
  module.exports = (input, callback) => {
133
- const appId = input.data.event.appId
134
- doInAppContext(appId, () => {
135
- const automationOrchestrator = new Orchestrator(
136
- input.data.automation,
137
- input.data.event
138
- )
139
- automationOrchestrator
140
- .execute()
141
- .then(response => {
142
- callback(null, response)
143
- })
144
- .catch(err => {
145
- callback(err)
146
- })
147
- })
134
+ const automationOrchestrator = new Orchestrator(
135
+ input.data.automation,
136
+ input.data.event
137
+ )
138
+ automationOrchestrator
139
+ .execute()
140
+ .then(response => {
141
+ callback(null, response)
142
+ })
143
+ .catch(err => {
144
+ callback(err)
145
+ })
148
146
  }
@@ -3,13 +3,11 @@ threadUtils.threadSetup()
3
3
  const ScriptRunner = require("../utilities/scriptRunner")
4
4
  const { integrations } = require("../integrations")
5
5
  const { processStringSync } = require("@budibase/string-templates")
6
- const { doInAppContext, getAppDB } = require("@budibase/backend-core/context")
7
-
8
- const IS_TRIPLE_BRACE = new RegExp(/^{{3}.*}{3}$/)
9
- const IS_HANDLEBARS = new RegExp(/^{{2}.*}{2}$/)
6
+ const CouchDB = require("../db")
10
7
 
11
8
  class QueryRunner {
12
9
  constructor(input, flags = { noRecursiveQuery: false }) {
10
+ this.appId = input.appId
13
11
  this.datasource = input.datasource
14
12
  this.queryVerb = input.queryVerb
15
13
  this.fields = input.fields
@@ -77,11 +75,6 @@ class QueryRunner {
77
75
  return this.execute()
78
76
  }
79
77
 
80
- // check for undefined response
81
- if (!rows) {
82
- rows = []
83
- }
84
-
85
78
  // needs to an array for next step
86
79
  if (!Array.isArray(rows)) {
87
80
  rows = [rows]
@@ -103,11 +96,12 @@ class QueryRunner {
103
96
  }
104
97
 
105
98
  async runAnotherQuery(queryId, parameters) {
106
- const db = getAppDB()
99
+ const db = new CouchDB(this.appId)
107
100
  const query = await db.get(queryId)
108
101
  const datasource = await db.get(query.datasourceId)
109
102
  return new QueryRunner(
110
103
  {
104
+ appId: this.appId,
111
105
  datasource,
112
106
  queryVerb: query.queryVerb,
113
107
  fields: query.fields,
@@ -188,12 +182,8 @@ class QueryRunner {
188
182
  enrichedQuery[key] = this.enrichQueryFields(fields[key], parameters)
189
183
  } else if (typeof fields[key] === "string") {
190
184
  // enrich string value as normal
191
- let value = fields[key]
192
- // add triple brace to avoid escaping e.g. '=' in cookie header
193
- if (IS_HANDLEBARS.test(value) && !IS_TRIPLE_BRACE.test(value)) {
194
- value = `{${value}}`
195
- }
196
- enrichedQuery[key] = processStringSync(value, parameters, {
185
+ enrichedQuery[key] = processStringSync(fields[key], parameters, {
186
+ noEscaping: true,
197
187
  noHelpers: true,
198
188
  })
199
189
  } else {
@@ -221,14 +211,12 @@ class QueryRunner {
221
211
  }
222
212
 
223
213
  module.exports = (input, callback) => {
224
- doInAppContext(input.appId, () => {
225
- const Runner = new QueryRunner(input)
226
- Runner.execute()
227
- .then(response => {
228
- callback(null, response)
229
- })
230
- .catch(err => {
231
- callback(err)
232
- })
233
- })
214
+ const Runner = new QueryRunner(input)
215
+ Runner.execute()
216
+ .then(response => {
217
+ callback(null, response)
218
+ })
219
+ .catch(err => {
220
+ callback(err)
221
+ })
234
222
  }
@@ -1,4 +1,5 @@
1
1
  const { budibaseTempDir } = require("../budibaseDir")
2
+ const { isDev } = require("../index")
2
3
  const fs = require("fs")
3
4
  const { join } = require("path")
4
5
  const uuid = require("uuid/v4")
@@ -19,7 +20,6 @@ const {
19
20
  LINK_USER_METADATA_PREFIX,
20
21
  } = require("../../db/utils")
21
22
  const MemoryStream = require("memorystream")
22
- const { getAppId } = require("@budibase/backend-core/context")
23
23
 
24
24
  const TOP_LEVEL_PATH = join(__dirname, "..", "..", "..")
25
25
  const NODE_MODULES_PATH = join(TOP_LEVEL_PATH, "node_modules")
@@ -51,7 +51,7 @@ exports.init = () => {
51
51
  * everything required to function is ready.
52
52
  */
53
53
  exports.checkDevelopmentEnvironment = () => {
54
- if (!env.isDev() || env.isTest()) {
54
+ if (!isDev()) {
55
55
  return
56
56
  }
57
57
  if (!fs.existsSync(budibaseTempDir())) {
@@ -251,8 +251,7 @@ exports.downloadTemplate = async (type, name) => {
251
251
  /**
252
252
  * Retrieves component libraries from object store (or tmp symlink if in local)
253
253
  */
254
- exports.getComponentLibraryManifest = async library => {
255
- const appId = getAppId()
254
+ exports.getComponentLibraryManifest = async (appId, library) => {
256
255
  const filename = "manifest.json"
257
256
  /* istanbul ignore next */
258
257
  // when testing in cypress and so on we need to get the package
@@ -3,7 +3,7 @@ const {
3
3
  getGlobalIDFromUserMetadataID,
4
4
  } = require("../db/utils")
5
5
  const { BUILTIN_ROLE_IDS } = require("@budibase/backend-core/roles")
6
- const { getProdAppID } = require("@budibase/backend-core/db")
6
+ const { getDeployedAppID } = require("@budibase/backend-core/db")
7
7
  const { getGlobalUserParams } = require("@budibase/backend-core/db")
8
8
  const { user: userCache } = require("@budibase/backend-core/cache")
9
9
  const {
@@ -11,10 +11,8 @@ const {
11
11
  isUserInAppTenant,
12
12
  } = require("@budibase/backend-core/tenancy")
13
13
  const env = require("../environment")
14
- const { getAppId } = require("@budibase/backend-core/context")
15
14
 
16
- exports.updateAppRole = (user, { appId } = {}) => {
17
- appId = appId || getAppId()
15
+ exports.updateAppRole = (appId, user) => {
18
16
  if (!user || !user.roles) {
19
17
  return user
20
18
  }
@@ -26,7 +24,7 @@ exports.updateAppRole = (user, { appId } = {}) => {
26
24
  return user
27
25
  }
28
26
  // always use the deployed app
29
- user.roleId = user.roles[getProdAppID(appId)]
27
+ user.roleId = user.roles[getDeployedAppID(appId)]
30
28
  // if a role wasn't found then either set as admin (builder) or public (everyone else)
31
29
  if (!user.roleId && user.builder && user.builder.global) {
32
30
  user.roleId = BUILTIN_ROLE_IDS.ADMIN
@@ -37,18 +35,18 @@ exports.updateAppRole = (user, { appId } = {}) => {
37
35
  return user
38
36
  }
39
37
 
40
- function processUser(user, { appId } = {}) {
38
+ function processUser(appId, user) {
41
39
  if (user) {
42
40
  delete user.password
43
41
  }
44
- return exports.updateAppRole(user, { appId })
42
+ return exports.updateAppRole(appId, user)
45
43
  }
46
44
 
47
45
  exports.getCachedSelf = async (ctx, appId) => {
48
46
  // this has to be tenant aware, can't depend on the context to find it out
49
47
  // running some middlewares before the tenancy causes context to break
50
48
  const user = await userCache.getUser(ctx.user._id)
51
- return processUser(user, { appId })
49
+ return processUser(appId, user)
52
50
  }
53
51
 
54
52
  exports.getRawGlobalUser = async userId => {
@@ -56,13 +54,12 @@ exports.getRawGlobalUser = async userId => {
56
54
  return db.get(getGlobalIDFromUserMetadataID(userId))
57
55
  }
58
56
 
59
- exports.getGlobalUser = async userId => {
57
+ exports.getGlobalUser = async (appId, userId) => {
60
58
  let user = await exports.getRawGlobalUser(userId)
61
- return processUser(user)
59
+ return processUser(appId, user)
62
60
  }
63
61
 
64
- exports.getGlobalUsers = async (users = null) => {
65
- const appId = getAppId()
62
+ exports.getGlobalUsers = async (appId = null, users = null) => {
66
63
  const db = getGlobalDB()
67
64
  let globalUsers
68
65
  if (users) {
@@ -89,11 +86,11 @@ exports.getGlobalUsers = async (users = null) => {
89
86
  if (!appId) {
90
87
  return globalUsers
91
88
  }
92
- return globalUsers.map(user => exports.updateAppRole(user))
89
+ return globalUsers.map(user => exports.updateAppRole(appId, user))
93
90
  }
94
91
 
95
- exports.getGlobalUsersFromMetadata = async users => {
96
- const globalUsers = await exports.getGlobalUsers(users)
92
+ exports.getGlobalUsersFromMetadata = async (appId, users) => {
93
+ const globalUsers = await exports.getGlobalUsers(appId, users)
97
94
  return users.map(user => {
98
95
  const globalUser = globalUsers.find(
99
96
  globalUser => globalUser && user._id.includes(globalUser._id)
@@ -1,9 +1,9 @@
1
1
  const env = require("../environment")
2
2
  const { OBJ_STORE_DIRECTORY } = require("../constants")
3
3
  const { sanitizeKey } = require("@budibase/backend-core/objectStore")
4
+ const CouchDB = require("../db")
4
5
  const { generateMetadataID } = require("../db/utils")
5
6
  const Readable = require("stream").Readable
6
- const { getAppDB } = require("@budibase/backend-core/context")
7
7
 
8
8
  const BB_CDN = "https://cdn.budi.live"
9
9
 
@@ -73,8 +73,8 @@ exports.attachmentsRelativeURL = attachmentKey => {
73
73
  )
74
74
  }
75
75
 
76
- exports.updateEntityMetadata = async (type, entityId, updateFn) => {
77
- const db = getAppDB()
76
+ exports.updateEntityMetadata = async (appId, type, entityId, updateFn) => {
77
+ const db = new CouchDB(appId)
78
78
  const id = generateMetadataID(type, entityId)
79
79
  // read it to see if it exists, we'll overwrite it no matter what
80
80
  let rev,
@@ -99,14 +99,14 @@ exports.updateEntityMetadata = async (type, entityId, updateFn) => {
99
99
  }
100
100
  }
101
101
 
102
- exports.saveEntityMetadata = async (type, entityId, metadata) => {
103
- return exports.updateEntityMetadata(type, entityId, () => {
102
+ exports.saveEntityMetadata = async (appId, type, entityId, metadata) => {
103
+ return exports.updateEntityMetadata(appId, type, entityId, () => {
104
104
  return metadata
105
105
  })
106
106
  }
107
107
 
108
- exports.deleteEntityMetadata = async (type, entityId) => {
109
- const db = getAppDB()
108
+ exports.deleteEntityMetadata = async (appId, type, entityId) => {
109
+ const db = new CouchDB(appId)
110
110
  const id = generateMetadataID(type, entityId)
111
111
  let rev
112
112
  try {
@@ -141,6 +141,16 @@ exports.stringToReadStream = string => {
141
141
  })
142
142
  }
143
143
 
144
+ exports.doesDatabaseExist = async dbName => {
145
+ try {
146
+ const db = new CouchDB(dbName, { skip_setup: true })
147
+ const info = await db.info()
148
+ return info && !info.error
149
+ } catch (err) {
150
+ return false
151
+ }
152
+ }
153
+
144
154
  exports.formatBytes = bytes => {
145
155
  const units = ["B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"]
146
156
  const byteIncrements = 1024
@@ -1,9 +1,9 @@
1
+ const CouchDB = require("../../db")
1
2
  const { createRoutingView } = require("../../db/views/staticViews")
2
3
  const { ViewNames, getQueryIndex, UNICODE_MAX } = require("../../db/utils")
3
- const { getAppDB } = require("@budibase/backend-core/context")
4
4
 
5
- exports.getRoutingInfo = async () => {
6
- const db = getAppDB()
5
+ exports.getRoutingInfo = async appId => {
6
+ const db = new CouchDB(appId)
7
7
  try {
8
8
  const allRouting = await db.query(getQueryIndex(ViewNames.ROUTING), {
9
9
  startKey: "",
@@ -14,8 +14,8 @@ exports.getRoutingInfo = async () => {
14
14
  // check if the view doesn't exist, it should for all new instances
15
15
  /* istanbul ignore next */
16
16
  if (err != null && err.name === "not_found") {
17
- await createRoutingView()
18
- return exports.getRoutingInfo()
17
+ await createRoutingView(appId)
18
+ return exports.getRoutingInfo(appId)
19
19
  } else {
20
20
  throw err
21
21
  }
@@ -7,10 +7,10 @@ const { deleteFiles } = require("../../utilities/fileSystem/utilities")
7
7
  const { ObjectStoreBuckets } = require("../../constants")
8
8
  const {
9
9
  isProdAppID,
10
- getProdAppID,
10
+ getDeployedAppID,
11
11
  dbExists,
12
12
  } = require("@budibase/backend-core/db")
13
- const { getAppId } = require("@budibase/backend-core/context")
13
+ const CouchDB = require("../../db")
14
14
 
15
15
  const BASE_AUTO_ID = 1
16
16
 
@@ -180,8 +180,6 @@ function processAutoColumn(
180
180
  }
181
181
  exports.processAutoColumn = processAutoColumn
182
182
 
183
- exports.processFormulas = processFormulas
184
-
185
183
  /**
186
184
  * This will coerce a value to the correct types based on the type transform map
187
185
  * @param {object} row The value to coerce
@@ -231,12 +229,11 @@ exports.inputProcessing = (
231
229
  }
232
230
  continue
233
231
  }
234
- // remove any formula values, they are to be generated
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
235
234
  if (field.type === FieldTypes.FORMULA) {
236
235
  delete clonedRow[key]
237
- }
238
- // otherwise coerce what is there to correct types
239
- else {
236
+ } else {
240
237
  clonedRow[key] = exports.coerce(value, field.type)
241
238
  }
242
239
  }
@@ -253,23 +250,30 @@ exports.inputProcessing = (
253
250
  /**
254
251
  * This function enriches the input rows with anything they are supposed to contain, for example
255
252
  * link records or attachment links.
253
+ * @param {object} ctx the request which is looking for enriched rows.
256
254
  * @param {object} table the table from which these rows came from originally, this is used to determine
257
255
  * the schema of the rows and then enrich.
258
256
  * @param {object[]|object} rows the rows which are to be enriched.
259
257
  * @param {object} opts used to set some options for the output, such as disabling relationship squashing.
260
258
  * @returns {object[]|object} the enriched rows will be returned.
261
259
  */
262
- exports.outputProcessing = async (table, rows, opts = { squash: true }) => {
260
+ exports.outputProcessing = async (
261
+ ctx,
262
+ table,
263
+ rows,
264
+ opts = { squash: true }
265
+ ) => {
266
+ const appId = ctx.appId
263
267
  let wasArray = true
264
268
  if (!(rows instanceof Array)) {
265
269
  rows = [rows]
266
270
  wasArray = false
267
271
  }
268
272
  // attach any linked row information
269
- let enriched = await linkRows.attachFullLinkedDocs(table, rows)
273
+ let enriched = await linkRows.attachFullLinkedDocs(ctx, table, rows)
270
274
 
271
275
  // process formulas
272
- enriched = processFormulas(table, enriched, { dynamic: true })
276
+ enriched = processFormulas(table, enriched)
273
277
 
274
278
  // update the attachments URL depending on hosting
275
279
  for (let [property, column] of Object.entries(table.schema)) {
@@ -285,27 +289,29 @@ exports.outputProcessing = async (table, rows, opts = { squash: true }) => {
285
289
  }
286
290
  }
287
291
  if (opts.squash) {
288
- enriched = await linkRows.squashLinksToPrimaryDisplay(table, enriched)
292
+ enriched = await linkRows.squashLinksToPrimaryDisplay(
293
+ appId,
294
+ table,
295
+ enriched
296
+ )
289
297
  }
290
298
  return wasArray ? enriched : enriched[0]
291
299
  }
292
300
 
293
301
  /**
294
302
  * 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.
295
304
  * @param {object} table The table from which a row is being removed.
296
305
  * @param {any} row optional - the row being removed.
297
306
  * @param {any} rows optional - if multiple rows being deleted can do this in bulk.
298
307
  * @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.
301
308
  * @return {Promise<void>} When all attachments have been removed this will return.
302
309
  */
303
- exports.cleanupAttachments = async (table, { row, rows, oldRow, oldTable }) => {
304
- const appId = getAppId()
310
+ exports.cleanupAttachments = async (appId, table, { row, rows, oldRow }) => {
305
311
  if (!isProdAppID(appId)) {
306
- const prodAppId = getProdAppID(appId)
312
+ const prodAppId = getDeployedAppID(appId)
307
313
  // if prod exists, then don't allow deleting
308
- const exists = await dbExists(prodAppId)
314
+ const exists = await dbExists(CouchDB, prodAppId)
309
315
  if (exists) {
310
316
  return
311
317
  }
@@ -316,16 +322,12 @@ exports.cleanupAttachments = async (table, { row, rows, oldRow, oldTable }) => {
316
322
  files = files.concat(row[key].map(attachment => attachment.key))
317
323
  }
318
324
  }
319
- const schemaToUse = oldTable ? oldTable.schema : table.schema
320
- for (let [key, schema] of Object.entries(schemaToUse)) {
325
+ for (let [key, schema] of Object.entries(table.schema)) {
321
326
  if (schema.type !== FieldTypes.ATTACHMENT) {
322
327
  continue
323
328
  }
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
329
+ // if updating, need to manage the differences
330
+ if (oldRow && row) {
329
331
  files = files.concat(getRemovedAttachmentKeys(oldRow, row, key))
330
332
  } else if (row) {
331
333
  addFiles(row, key)
@@ -1,39 +1,23 @@
1
- const { FieldTypes, FormulaTypes } = require("../../constants")
1
+ const { FieldTypes } = 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 = (
8
- table,
9
- rows,
10
- { dynamic, contextRows } = { dynamic: true }
11
- ) => {
7
+ exports.processFormulas = (table, rows) => {
12
8
  const single = !Array.isArray(rows)
13
9
  if (single) {
14
10
  rows = [rows]
15
- contextRows = contextRows ? [contextRows] : contextRows
16
11
  }
17
12
  for (let [column, schema] of Object.entries(table.schema)) {
18
- const isStatic = schema.formulaType === FormulaTypes.STATIC
19
- if (
20
- schema.type !== FieldTypes.FORMULA ||
21
- (dynamic && isStatic) ||
22
- (!dynamic && !isStatic)
23
- ) {
13
+ if (schema.type !== FieldTypes.FORMULA) {
24
14
  continue
25
15
  }
26
16
  // iterate through rows and process formula
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
- }
17
+ rows = rows.map(row => ({
18
+ ...row,
19
+ [column]: processStringSync(schema.formula, row),
20
+ }))
37
21
  }
38
22
  return single ? rows[0] : rows
39
23
  }
@@ -0,0 +1,73 @@
1
+ const env = require("../environment")
2
+ const { getGlobalDB } = require("@budibase/backend-core/tenancy")
3
+ const {
4
+ StaticDatabases,
5
+ generateNewUsageQuotaDoc,
6
+ } = require("@budibase/backend-core/db")
7
+
8
+ function getNewQuotaReset() {
9
+ return Date.now() + 2592000000
10
+ }
11
+
12
+ exports.Properties = {
13
+ ROW: "rows",
14
+ UPLOAD: "storage",
15
+ VIEW: "views",
16
+ USER: "users",
17
+ AUTOMATION: "automationRuns",
18
+ APPS: "apps",
19
+ EMAILS: "emails",
20
+ }
21
+
22
+ async function getUsageQuotaDoc(db) {
23
+ let quota
24
+ try {
25
+ quota = await db.get(StaticDatabases.PLATFORM_INFO.docs.usageQuota)
26
+ } catch (err) {
27
+ // doc doesn't exist. Create it
28
+ quota = await db.post(generateNewUsageQuotaDoc())
29
+ }
30
+
31
+ return quota
32
+ }
33
+
34
+ /**
35
+ * Given a specified tenantId this will add to the usage object for the specified property.
36
+ * @param {string} property The property which is to be added to (within the nested usageQuota object).
37
+ * @param {number} usage The amount (this can be negative) to adjust the number by.
38
+ * @returns {Promise<void>} When this completes the API key will now be up to date - the quota period may have
39
+ * also been reset after this call.
40
+ */
41
+ exports.update = async (property, usage) => {
42
+ if (!env.USE_QUOTAS) {
43
+ return
44
+ }
45
+
46
+ try {
47
+ const db = getGlobalDB()
48
+ const quota = await getUsageQuotaDoc(db)
49
+
50
+ // Check if the quota needs reset
51
+ if (Date.now() >= quota.quotaReset) {
52
+ quota.quotaReset = getNewQuotaReset()
53
+ for (let prop of Object.keys(quota.usageQuota)) {
54
+ quota.usageQuota[prop] = 0
55
+ }
56
+ }
57
+
58
+ // increment the quota
59
+ quota.usageQuota[property] += usage
60
+
61
+ if (quota.usageQuota[property] > quota.usageLimits[property]) {
62
+ throw new Error(
63
+ `You have exceeded your usage quota of ${quota.usageLimits[property]} ${property}.`
64
+ )
65
+ }
66
+
67
+ // update the usage quotas
68
+ await db.put(quota)
69
+ } catch (err) {
70
+ console.error(`Error updating usage quotas for ${property}`, err)
71
+ throw err
72
+ }
73
+ }
@@ -1,13 +1,13 @@
1
+ const CouchDB = require("../db")
1
2
  const { InternalTables } = require("../db/utils")
2
3
  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(userId)
6
+ const global = await getGlobalUser(ctx.appId, 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 = getAppDB()
10
+ const db = new CouchDB(ctx.appId)
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 { getProdAppID } = require("@budibase/backend-core/db")
4
+ const { getDeployedAppID } = 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,6 +58,29 @@ 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
+
61
84
  exports.getGlobalSelf = async (ctx, appId = null) => {
62
85
  const endpoint = `/api/global/users/self`
63
86
  const response = await fetch(
@@ -70,15 +93,15 @@ exports.getGlobalSelf = async (ctx, appId = null) => {
70
93
  }
71
94
  let json = await response.json()
72
95
  if (appId) {
73
- json = updateAppRole(json)
96
+ json = updateAppRole(appId, json)
74
97
  }
75
98
  return json
76
99
  }
77
100
 
78
101
  exports.removeAppFromUserRoles = async (ctx, appId) => {
79
- const prodAppId = getProdAppID(appId)
102
+ const deployedAppId = getDeployedAppID(appId)
80
103
  const response = await fetch(
81
- checkSlashesInUrl(env.WORKER_URL + `/api/global/roles/${prodAppId}`),
104
+ checkSlashesInUrl(env.WORKER_URL + `/api/global/roles/${deployedAppId}`),
82
105
  request(ctx, {
83
106
  method: "DELETE",
84
107
  })