@budibase/server 2.1.22-alpha.6 → 2.1.22-alpha.7

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 (419) hide show
  1. package/__mocks__/node-fetch.ts +5 -1
  2. package/builder/assets/{index.5ec5f06c.js → index.22484e23.js} +1 -1
  3. package/builder/index.html +1 -1
  4. package/coverage/clover.xml +1182 -1209
  5. package/coverage/coverage-final.json +35 -35
  6. package/coverage/lcov-report/index.html +94 -94
  7. package/coverage/lcov-report/src/api/controllers/analytics.ts.html +1 -1
  8. package/coverage/lcov-report/src/api/controllers/apikeys.js.html +1 -1
  9. package/coverage/lcov-report/src/api/controllers/application.ts.html +45 -60
  10. package/coverage/lcov-report/src/api/controllers/auth.ts.html +7 -4
  11. package/coverage/lcov-report/src/api/controllers/automation.js.html +1 -1
  12. package/coverage/lcov-report/src/api/controllers/backup.ts.html +1 -1
  13. package/coverage/lcov-report/src/api/controllers/cloud.js.html +1 -1
  14. package/coverage/lcov-report/src/api/controllers/component.ts.html +1 -1
  15. package/coverage/lcov-report/src/api/controllers/datasource.js.html +1 -1
  16. package/coverage/lcov-report/src/api/controllers/deploy/Deployment.js.html +1 -1
  17. package/coverage/lcov-report/src/api/controllers/deploy/index.html +10 -10
  18. package/coverage/lcov-report/src/api/controllers/deploy/index.ts.html +19 -55
  19. package/coverage/lcov-report/src/api/controllers/{dev.js.html → dev.ts.html} +46 -64
  20. package/coverage/lcov-report/src/api/controllers/index.html +25 -25
  21. package/coverage/lcov-report/src/api/controllers/integration.js.html +1 -1
  22. package/coverage/lcov-report/src/api/controllers/layout.js.html +1 -1
  23. package/coverage/lcov-report/src/api/controllers/metadata.js.html +1 -1
  24. package/coverage/lcov-report/src/api/controllers/migrations.js.html +1 -1
  25. package/coverage/lcov-report/src/api/controllers/permission.js.html +1 -1
  26. package/coverage/lcov-report/src/api/controllers/plugin/file.ts.html +1 -1
  27. package/coverage/lcov-report/src/api/controllers/plugin/github.ts.html +1 -1
  28. package/coverage/lcov-report/src/api/controllers/plugin/index.html +1 -1
  29. package/coverage/lcov-report/src/api/controllers/plugin/index.ts.html +1 -1
  30. package/coverage/lcov-report/src/api/controllers/plugin/npm.ts.html +1 -1
  31. package/coverage/lcov-report/src/api/controllers/plugin/uploaders.ts.html +1 -1
  32. package/coverage/lcov-report/src/api/controllers/plugin/url.ts.html +1 -1
  33. package/coverage/lcov-report/src/api/controllers/plugin/utils.ts.html +1 -1
  34. package/coverage/lcov-report/src/api/controllers/public/applications.ts.html +37 -19
  35. package/coverage/lcov-report/src/api/controllers/public/index.html +16 -16
  36. package/coverage/lcov-report/src/api/controllers/public/mapping/applications.ts.html +1 -1
  37. package/coverage/lcov-report/src/api/controllers/public/mapping/index.html +1 -1
  38. package/coverage/lcov-report/src/api/controllers/public/mapping/index.ts.html +1 -1
  39. package/coverage/lcov-report/src/api/controllers/public/mapping/queries.ts.html +1 -1
  40. package/coverage/lcov-report/src/api/controllers/public/mapping/rows.ts.html +1 -1
  41. package/coverage/lcov-report/src/api/controllers/public/mapping/tables.ts.html +1 -1
  42. package/coverage/lcov-report/src/api/controllers/public/mapping/users.ts.html +1 -1
  43. package/coverage/lcov-report/src/api/controllers/public/queries.ts.html +1 -1
  44. package/coverage/lcov-report/src/api/controllers/public/rows.ts.html +1 -1
  45. package/coverage/lcov-report/src/api/controllers/public/tables.ts.html +1 -1
  46. package/coverage/lcov-report/src/api/controllers/public/users.ts.html +1 -1
  47. package/coverage/lcov-report/src/api/controllers/public/utils.ts.html +1 -1
  48. package/coverage/lcov-report/src/api/controllers/query/import/index.html +1 -1
  49. package/coverage/lcov-report/src/api/controllers/query/import/index.ts.html +1 -1
  50. package/coverage/lcov-report/src/api/controllers/query/import/sources/base/index.html +1 -1
  51. package/coverage/lcov-report/src/api/controllers/query/import/sources/base/index.ts.html +1 -1
  52. package/coverage/lcov-report/src/api/controllers/query/import/sources/base/openapi.ts.html +1 -1
  53. package/coverage/lcov-report/src/api/controllers/query/import/sources/curl.ts.html +1 -1
  54. package/coverage/lcov-report/src/api/controllers/query/import/sources/index.html +1 -1
  55. package/coverage/lcov-report/src/api/controllers/query/import/sources/openapi2.ts.html +1 -1
  56. package/coverage/lcov-report/src/api/controllers/query/import/sources/openapi3.ts.html +1 -1
  57. package/coverage/lcov-report/src/api/controllers/query/index.html +10 -10
  58. package/coverage/lcov-report/src/api/controllers/query/index.ts.html +17 -26
  59. package/coverage/lcov-report/src/api/controllers/query/validation.js.html +1 -1
  60. package/coverage/lcov-report/src/api/controllers/role.js.html +1 -1
  61. package/coverage/lcov-report/src/api/controllers/routing.js.html +1 -1
  62. package/coverage/lcov-report/src/api/controllers/row/ExternalRequest.ts.html +1 -1
  63. package/coverage/lcov-report/src/api/controllers/row/external.js.html +1 -1
  64. package/coverage/lcov-report/src/api/controllers/row/index.html +1 -1
  65. package/coverage/lcov-report/src/api/controllers/row/index.ts.html +1 -1
  66. package/coverage/lcov-report/src/api/controllers/row/internal.js.html +3 -3
  67. package/coverage/lcov-report/src/api/controllers/row/internalSearch.js.html +1 -1
  68. package/coverage/lcov-report/src/api/controllers/row/staticFormula.js.html +1 -1
  69. package/coverage/lcov-report/src/api/controllers/row/utils.js.html +1 -1
  70. package/coverage/lcov-report/src/api/controllers/screen.ts.html +1 -1
  71. package/coverage/lcov-report/src/api/controllers/script.js.html +1 -1
  72. package/coverage/lcov-report/src/api/controllers/static/index.html +1 -1
  73. package/coverage/lcov-report/src/api/controllers/static/index.ts.html +1 -1
  74. package/coverage/lcov-report/src/api/controllers/table/bulkFormula.js.html +1 -1
  75. package/coverage/lcov-report/src/api/controllers/table/external.js.html +1 -1
  76. package/coverage/lcov-report/src/api/controllers/table/index.html +1 -1
  77. package/coverage/lcov-report/src/api/controllers/table/index.js.html +1 -1
  78. package/coverage/lcov-report/src/api/controllers/table/internal.ts.html +1 -1
  79. package/coverage/lcov-report/src/api/controllers/table/utils.ts.html +1 -1
  80. package/coverage/lcov-report/src/api/controllers/templates.js.html +1 -1
  81. package/coverage/lcov-report/src/api/controllers/user.js.html +1 -1
  82. package/coverage/lcov-report/src/api/controllers/view/exporters.js.html +1 -1
  83. package/coverage/lcov-report/src/api/controllers/view/index.html +1 -1
  84. package/coverage/lcov-report/src/api/controllers/view/index.js.html +1 -1
  85. package/coverage/lcov-report/src/api/controllers/view/utils.js.html +1 -1
  86. package/coverage/lcov-report/src/api/controllers/view/viewBuilder.js.html +1 -1
  87. package/coverage/lcov-report/src/api/controllers/webhook.ts.html +1 -1
  88. package/coverage/lcov-report/src/api/index.html +1 -1
  89. package/coverage/lcov-report/src/api/index.js.html +1 -1
  90. package/coverage/lcov-report/src/api/routes/analytics.js.html +1 -1
  91. package/coverage/lcov-report/src/api/routes/apikeys.js.html +1 -1
  92. package/coverage/lcov-report/src/api/routes/application.ts.html +1 -1
  93. package/coverage/lcov-report/src/api/routes/auth.ts.html +1 -1
  94. package/coverage/lcov-report/src/api/routes/automation.js.html +5 -5
  95. package/coverage/lcov-report/src/api/routes/backup.ts.html +1 -1
  96. package/coverage/lcov-report/src/api/routes/cloud.js.html +1 -1
  97. package/coverage/lcov-report/src/api/routes/component.js.html +1 -1
  98. package/coverage/lcov-report/src/api/routes/datasource.js.html +6 -6
  99. package/coverage/lcov-report/src/api/routes/deploy.js.html +1 -1
  100. package/coverage/lcov-report/src/api/routes/dev.js.html +1 -1
  101. package/coverage/lcov-report/src/api/routes/index.html +1 -1
  102. package/coverage/lcov-report/src/api/routes/index.ts.html +1 -1
  103. package/coverage/lcov-report/src/api/routes/integration.js.html +1 -1
  104. package/coverage/lcov-report/src/api/routes/layout.js.html +1 -1
  105. package/coverage/lcov-report/src/api/routes/metadata.js.html +1 -1
  106. package/coverage/lcov-report/src/api/routes/migrations.js.html +1 -1
  107. package/coverage/lcov-report/src/api/routes/permission.js.html +1 -1
  108. package/coverage/lcov-report/src/api/routes/plugin.ts.html +1 -1
  109. package/coverage/lcov-report/src/api/routes/public/applications.ts.html +1 -1
  110. package/coverage/lcov-report/src/api/routes/public/index.html +1 -1
  111. package/coverage/lcov-report/src/api/routes/public/index.ts.html +11 -11
  112. package/coverage/lcov-report/src/api/routes/public/middleware/index.html +1 -1
  113. package/coverage/lcov-report/src/api/routes/public/middleware/mapper.ts.html +1 -1
  114. package/coverage/lcov-report/src/api/routes/public/queries.ts.html +1 -1
  115. package/coverage/lcov-report/src/api/routes/public/rows.ts.html +1 -1
  116. package/coverage/lcov-report/src/api/routes/public/tables.ts.html +1 -1
  117. package/coverage/lcov-report/src/api/routes/public/users.ts.html +1 -1
  118. package/coverage/lcov-report/src/api/routes/public/utils/Endpoint.ts.html +1 -1
  119. package/coverage/lcov-report/src/api/routes/public/utils/index.html +1 -1
  120. package/coverage/lcov-report/src/api/routes/query.js.html +6 -6
  121. package/coverage/lcov-report/src/api/routes/role.js.html +1 -1
  122. package/coverage/lcov-report/src/api/routes/routing.js.html +1 -1
  123. package/coverage/lcov-report/src/api/routes/row.ts.html +13 -13
  124. package/coverage/lcov-report/src/api/routes/screen.js.html +1 -1
  125. package/coverage/lcov-report/src/api/routes/script.js.html +1 -1
  126. package/coverage/lcov-report/src/api/routes/static.ts.html +6 -6
  127. package/coverage/lcov-report/src/api/routes/table.js.html +4 -4
  128. package/coverage/lcov-report/src/api/routes/templates.js.html +1 -1
  129. package/coverage/lcov-report/src/api/routes/tests/utilities/TestFunctions.ts.html +1 -1
  130. package/coverage/lcov-report/src/api/routes/tests/utilities/index.html +1 -1
  131. package/coverage/lcov-report/src/api/routes/tests/utilities/index.js.html +1 -1
  132. package/coverage/lcov-report/src/api/routes/user.js.html +11 -11
  133. package/coverage/lcov-report/src/api/routes/utils/index.html +1 -1
  134. package/coverage/lcov-report/src/api/routes/utils/validators.js.html +6 -6
  135. package/coverage/lcov-report/src/api/routes/view.js.html +4 -4
  136. package/coverage/lcov-report/src/api/routes/webhook.ts.html +1 -1
  137. package/coverage/lcov-report/src/app.ts.html +1 -1
  138. package/coverage/lcov-report/src/automations/actions.js.html +1 -1
  139. package/coverage/lcov-report/src/automations/automationUtils.js.html +1 -1
  140. package/coverage/lcov-report/src/automations/bullboard.js.html +1 -1
  141. package/coverage/lcov-report/src/automations/index.html +15 -15
  142. package/coverage/lcov-report/src/automations/index.js.html +1 -1
  143. package/coverage/lcov-report/src/automations/logging/index.html +1 -1
  144. package/coverage/lcov-report/src/automations/logging/index.ts.html +1 -1
  145. package/coverage/lcov-report/src/automations/steps/bash.js.html +1 -1
  146. package/coverage/lcov-report/src/automations/steps/createRow.ts.html +1 -1
  147. package/coverage/lcov-report/src/automations/steps/delay.js.html +1 -1
  148. package/coverage/lcov-report/src/automations/steps/deleteRow.ts.html +1 -1
  149. package/coverage/lcov-report/src/automations/steps/discord.js.html +1 -1
  150. package/coverage/lcov-report/src/automations/steps/executeQuery.js.html +1 -1
  151. package/coverage/lcov-report/src/automations/steps/executeScript.js.html +1 -1
  152. package/coverage/lcov-report/src/automations/steps/filter.js.html +1 -1
  153. package/coverage/lcov-report/src/automations/steps/index.html +1 -1
  154. package/coverage/lcov-report/src/automations/steps/integromat.js.html +1 -1
  155. package/coverage/lcov-report/src/automations/steps/loop.js.html +1 -1
  156. package/coverage/lcov-report/src/automations/steps/outgoingWebhook.js.html +1 -1
  157. package/coverage/lcov-report/src/automations/steps/queryRows.js.html +1 -1
  158. package/coverage/lcov-report/src/automations/steps/sendSmtpEmail.js.html +1 -1
  159. package/coverage/lcov-report/src/automations/steps/serverLog.js.html +1 -1
  160. package/coverage/lcov-report/src/automations/steps/slack.js.html +1 -1
  161. package/coverage/lcov-report/src/automations/steps/updateRow.js.html +1 -1
  162. package/coverage/lcov-report/src/automations/steps/utils.js.html +1 -1
  163. package/coverage/lcov-report/src/automations/steps/zapier.js.html +1 -1
  164. package/coverage/lcov-report/src/automations/tests/utilities/index.html +17 -17
  165. package/coverage/lcov-report/src/automations/tests/utilities/index.js.html +33 -15
  166. package/coverage/lcov-report/src/automations/triggerInfo/app.js.html +1 -1
  167. package/coverage/lcov-report/src/automations/triggerInfo/cron.js.html +1 -1
  168. package/coverage/lcov-report/src/automations/triggerInfo/index.html +1 -1
  169. package/coverage/lcov-report/src/automations/triggerInfo/index.js.html +1 -1
  170. package/coverage/lcov-report/src/automations/triggerInfo/rowDeleted.js.html +1 -1
  171. package/coverage/lcov-report/src/automations/triggerInfo/rowSaved.js.html +1 -1
  172. package/coverage/lcov-report/src/automations/triggerInfo/rowUpdated.js.html +1 -1
  173. package/coverage/lcov-report/src/automations/triggerInfo/webhook.js.html +1 -1
  174. package/coverage/lcov-report/src/automations/triggers.js.html +1 -1
  175. package/coverage/lcov-report/src/automations/utils.ts.html +20 -29
  176. package/coverage/lcov-report/src/constants/index.html +1 -1
  177. package/coverage/lcov-report/src/constants/index.js.html +1 -1
  178. package/coverage/lcov-report/src/constants/layouts.js.html +1 -1
  179. package/coverage/lcov-report/src/constants/screens.js.html +1 -1
  180. package/coverage/lcov-report/src/db/dynamoClient.js.html +1 -1
  181. package/coverage/lcov-report/src/db/inMemoryView.js.html +3 -3
  182. package/coverage/lcov-report/src/db/index.html +16 -16
  183. package/coverage/lcov-report/src/db/index.js.html +9 -9
  184. package/coverage/lcov-report/src/db/linkedRows/LinkController.js.html +1 -1
  185. package/coverage/lcov-report/src/db/linkedRows/index.html +1 -1
  186. package/coverage/lcov-report/src/db/linkedRows/index.js.html +1 -1
  187. package/coverage/lcov-report/src/db/linkedRows/linkUtils.js.html +1 -1
  188. package/coverage/lcov-report/src/db/newid.js.html +1 -1
  189. package/coverage/lcov-report/src/db/{utils.js.html → utils.ts.html} +97 -145
  190. package/coverage/lcov-report/src/definitions/automations.ts.html +1 -1
  191. package/coverage/lcov-report/src/definitions/datasource.ts.html +1 -1
  192. package/coverage/lcov-report/src/definitions/index.html +1 -1
  193. package/coverage/lcov-report/src/environment.js.html +4 -4
  194. package/coverage/lcov-report/src/events/AutomationEmitter.js.html +1 -1
  195. package/coverage/lcov-report/src/events/index.html +1 -1
  196. package/coverage/lcov-report/src/events/index.js.html +1 -1
  197. package/coverage/lcov-report/src/events/utils.js.html +1 -1
  198. package/coverage/lcov-report/src/index.html +1 -1
  199. package/coverage/lcov-report/src/index.ts.html +1 -1
  200. package/coverage/lcov-report/src/integrations/airtable.ts.html +1 -1
  201. package/coverage/lcov-report/src/integrations/arangodb.ts.html +1 -1
  202. package/coverage/lcov-report/src/integrations/base/index.html +1 -1
  203. package/coverage/lcov-report/src/integrations/base/query.ts.html +1 -1
  204. package/coverage/lcov-report/src/integrations/base/sql.ts.html +1 -1
  205. package/coverage/lcov-report/src/integrations/base/sqlTable.ts.html +1 -1
  206. package/coverage/lcov-report/src/integrations/base/utils.ts.html +1 -1
  207. package/coverage/lcov-report/src/integrations/couchdb.ts.html +1 -1
  208. package/coverage/lcov-report/src/integrations/dynamodb.ts.html +1 -1
  209. package/coverage/lcov-report/src/integrations/elasticsearch.ts.html +1 -1
  210. package/coverage/lcov-report/src/integrations/firebase.ts.html +1 -1
  211. package/coverage/lcov-report/src/integrations/googlesheets.ts.html +10 -19
  212. package/coverage/lcov-report/src/integrations/index.html +11 -11
  213. package/coverage/lcov-report/src/integrations/index.ts.html +1 -1
  214. package/coverage/lcov-report/src/integrations/microsoftSqlServer.ts.html +1 -1
  215. package/coverage/lcov-report/src/integrations/mongodb.ts.html +1 -1
  216. package/coverage/lcov-report/src/integrations/mysql.ts.html +1 -1
  217. package/coverage/lcov-report/src/integrations/oracle.ts.html +1 -1
  218. package/coverage/lcov-report/src/integrations/postgres.ts.html +1 -1
  219. package/coverage/lcov-report/src/integrations/queries/index.html +1 -1
  220. package/coverage/lcov-report/src/integrations/queries/sql.ts.html +1 -1
  221. package/coverage/lcov-report/src/integrations/redis.ts.html +1 -1
  222. package/coverage/lcov-report/src/integrations/rest.ts.html +1 -1
  223. package/coverage/lcov-report/src/integrations/s3.ts.html +1 -1
  224. package/coverage/lcov-report/src/integrations/snowflake.ts.html +1 -1
  225. package/coverage/lcov-report/src/integrations/tests/TestConfiguration.js.html +1 -1
  226. package/coverage/lcov-report/src/integrations/tests/index.html +1 -1
  227. package/coverage/lcov-report/src/integrations/utils.ts.html +1 -1
  228. package/coverage/lcov-report/src/middleware/{appInfo.js.html → appInfo.ts.html} +24 -21
  229. package/coverage/lcov-report/src/middleware/authorized.ts.html +7 -7
  230. package/coverage/lcov-report/src/middleware/{builder.js.html → builder.ts.html} +36 -30
  231. package/coverage/lcov-report/src/middleware/{currentapp.js.html → currentapp.ts.html} +70 -61
  232. package/coverage/lcov-report/src/middleware/index.html +55 -55
  233. package/coverage/lcov-report/src/middleware/{joi-validator.js.html → joi-validator.ts.html} +18 -15
  234. package/coverage/lcov-report/src/middleware/{publicApi.js.html → publicApi.ts.html} +17 -17
  235. package/coverage/lcov-report/src/middleware/{resourceId.js.html → resourceId.ts.html} +33 -18
  236. package/coverage/lcov-report/src/middleware/{selfhost.js.html → selfhost.ts.html} +18 -12
  237. package/coverage/lcov-report/src/middleware/{utils.js.html → utils.ts.html} +12 -6
  238. package/coverage/lcov-report/src/migrations/functions/appUrls.ts.html +1 -1
  239. package/coverage/lcov-report/src/migrations/functions/backfill/app/automations.ts.html +1 -1
  240. package/coverage/lcov-report/src/migrations/functions/backfill/app/datasources.ts.html +1 -1
  241. package/coverage/lcov-report/src/migrations/functions/backfill/app/index.html +4 -4
  242. package/coverage/lcov-report/src/migrations/functions/backfill/app/layouts.ts.html +1 -1
  243. package/coverage/lcov-report/src/migrations/functions/backfill/app/queries.ts.html +1 -1
  244. package/coverage/lcov-report/src/migrations/functions/backfill/app/roles.ts.html +1 -1
  245. package/coverage/lcov-report/src/migrations/functions/backfill/app/screens.ts.html +1 -1
  246. package/coverage/lcov-report/src/migrations/functions/backfill/app/tables.ts.html +6 -15
  247. package/coverage/lcov-report/src/migrations/functions/backfill/app.ts.html +1 -1
  248. package/coverage/lcov-report/src/migrations/functions/backfill/global/configs.ts.html +1 -1
  249. package/coverage/lcov-report/src/migrations/functions/backfill/global/index.html +1 -1
  250. package/coverage/lcov-report/src/migrations/functions/backfill/global/quotas.ts.html +1 -1
  251. package/coverage/lcov-report/src/migrations/functions/backfill/global/users.ts.html +1 -1
  252. package/coverage/lcov-report/src/migrations/functions/backfill/global.ts.html +1 -1
  253. package/coverage/lcov-report/src/migrations/functions/backfill/index.html +1 -1
  254. package/coverage/lcov-report/src/migrations/functions/backfill/index.ts.html +1 -1
  255. package/coverage/lcov-report/src/migrations/functions/backfill/installation.ts.html +1 -1
  256. package/coverage/lcov-report/src/migrations/functions/index.html +1 -1
  257. package/coverage/lcov-report/src/migrations/functions/syncQuotas.ts.html +1 -1
  258. package/coverage/lcov-report/src/migrations/functions/usageQuotas/index.html +1 -1
  259. package/coverage/lcov-report/src/migrations/functions/usageQuotas/index.ts.html +1 -1
  260. package/coverage/lcov-report/src/migrations/functions/usageQuotas/syncApps.ts.html +1 -1
  261. package/coverage/lcov-report/src/migrations/functions/usageQuotas/syncPlugins.ts.html +1 -1
  262. package/coverage/lcov-report/src/migrations/functions/usageQuotas/syncRows.ts.html +1 -1
  263. package/coverage/lcov-report/src/migrations/functions/userEmailViewCasing.ts.html +1 -1
  264. package/coverage/lcov-report/src/migrations/index.html +1 -1
  265. package/coverage/lcov-report/src/migrations/index.ts.html +1 -1
  266. package/coverage/lcov-report/src/migrations/tests/helpers.ts.html +1 -1
  267. package/coverage/lcov-report/src/migrations/tests/index.html +1 -1
  268. package/coverage/lcov-report/src/migrations/tests/structures.ts.html +1 -1
  269. package/coverage/lcov-report/src/module.d.ts.html +1 -1
  270. package/coverage/lcov-report/src/sdk/app/automations/index.html +1 -1
  271. package/coverage/lcov-report/src/sdk/app/automations/index.ts.html +1 -1
  272. package/coverage/lcov-report/src/sdk/app/automations/webhook.ts.html +1 -1
  273. package/coverage/lcov-report/src/sdk/app/backups/constants.ts.html +1 -1
  274. package/coverage/lcov-report/src/sdk/app/backups/exports.ts.html +1 -1
  275. package/coverage/lcov-report/src/sdk/app/backups/imports.ts.html +7 -16
  276. package/coverage/lcov-report/src/sdk/app/backups/index.html +1 -1
  277. package/coverage/lcov-report/src/sdk/app/backups/index.ts.html +1 -1
  278. package/coverage/lcov-report/src/sdk/app/backups/statistics.ts.html +12 -39
  279. package/coverage/lcov-report/src/sdk/app/tables/index.html +1 -1
  280. package/coverage/lcov-report/src/sdk/app/tables/index.ts.html +8 -11
  281. package/coverage/lcov-report/src/sdk/index.html +1 -1
  282. package/coverage/lcov-report/src/sdk/index.ts.html +1 -1
  283. package/coverage/lcov-report/src/startup.ts.html +1 -1
  284. package/coverage/lcov-report/src/tests/utilities/TestConfiguration.js.html +24 -24
  285. package/coverage/lcov-report/src/tests/utilities/controllers.js.html +1 -1
  286. package/coverage/lcov-report/src/tests/utilities/index.html +19 -19
  287. package/coverage/lcov-report/src/tests/utilities/index.js.html +1 -1
  288. package/coverage/lcov-report/src/tests/utilities/structures.js.html +3 -3
  289. package/coverage/lcov-report/src/threads/automation.ts.html +2 -2
  290. package/coverage/lcov-report/src/threads/index.html +1 -1
  291. package/coverage/lcov-report/src/threads/index.ts.html +1 -1
  292. package/coverage/lcov-report/src/threads/query.ts.html +1 -1
  293. package/coverage/lcov-report/src/threads/utils.ts.html +1 -1
  294. package/coverage/lcov-report/src/utilities/budibaseDir.js.html +1 -1
  295. package/coverage/lcov-report/src/utilities/centralPath.js.html +1 -1
  296. package/coverage/lcov-report/src/utilities/csvParser.js.html +1 -1
  297. package/coverage/lcov-report/src/utilities/fileSystem/clientLibrary.js.html +1 -1
  298. package/coverage/lcov-report/src/utilities/fileSystem/index.html +1 -1
  299. package/coverage/lcov-report/src/utilities/fileSystem/index.js.html +1 -1
  300. package/coverage/lcov-report/src/utilities/fileSystem/processor.js.html +1 -1
  301. package/coverage/lcov-report/src/utilities/fileSystem/utilities.js.html +1 -1
  302. package/coverage/lcov-report/src/utilities/{global.js.html → global.ts.html} +100 -67
  303. package/coverage/lcov-report/src/utilities/index.html +16 -16
  304. package/coverage/lcov-report/src/utilities/index.js.html +1 -1
  305. package/coverage/lcov-report/src/utilities/plugins.js.html +1 -1
  306. package/coverage/lcov-report/src/utilities/queue/inMemoryQueue.js.html +1 -1
  307. package/coverage/lcov-report/src/utilities/queue/index.html +1 -1
  308. package/coverage/lcov-report/src/utilities/redis.js.html +1 -1
  309. package/coverage/lcov-report/src/utilities/routing/index.html +1 -1
  310. package/coverage/lcov-report/src/utilities/routing/index.js.html +1 -1
  311. package/coverage/lcov-report/src/utilities/rowProcessor/index.html +1 -1
  312. package/coverage/lcov-report/src/utilities/rowProcessor/index.js.html +1 -1
  313. package/coverage/lcov-report/src/utilities/rowProcessor/utils.js.html +1 -1
  314. package/coverage/lcov-report/src/utilities/scriptRunner.js.html +1 -1
  315. package/coverage/lcov-report/src/utilities/security.js.html +13 -13
  316. package/coverage/lcov-report/src/utilities/statusCodes.js.html +1 -1
  317. package/coverage/lcov-report/src/utilities/usageQuota/index.html +1 -1
  318. package/coverage/lcov-report/src/utilities/usageQuota/rows.js.html +1 -1
  319. package/coverage/lcov-report/src/utilities/usageQuota/usageQuoteReset.js.html +1 -1
  320. package/coverage/lcov-report/src/utilities/users.js.html +1 -1
  321. package/coverage/lcov-report/src/utilities/workerRequests.js.html +4 -4
  322. package/coverage/lcov-report/src/watch.ts.html +1 -1
  323. package/coverage/lcov-report/src/websocket.ts.html +1 -1
  324. package/coverage/lcov.info +2052 -2049
  325. package/dist/api/controllers/application.js +35 -43
  326. package/dist/api/controllers/deploy/index.js +13 -16
  327. package/dist/api/controllers/dev.js +96 -81
  328. package/dist/api/controllers/public/applications.js +17 -9
  329. package/dist/api/controllers/query/index.js +10 -13
  330. package/dist/api/controllers/row/internal.js +2 -2
  331. package/dist/api/routes/automation.js +3 -3
  332. package/dist/api/routes/datasource.js +4 -4
  333. package/dist/api/routes/public/index.js +9 -9
  334. package/dist/api/routes/query.js +4 -4
  335. package/dist/api/routes/row.js +11 -11
  336. package/dist/api/routes/static.js +3 -3
  337. package/dist/api/routes/table.js +2 -2
  338. package/dist/api/routes/user.js +9 -9
  339. package/dist/api/routes/utils/validators.js +4 -4
  340. package/dist/api/routes/view.js +2 -2
  341. package/dist/automations/tests/utilities/index.js +21 -12
  342. package/dist/automations/utils.js +9 -8
  343. package/dist/db/inMemoryView.js +2 -2
  344. package/dist/db/utils.js +145 -118
  345. package/dist/integrations/googlesheets.js +4 -6
  346. package/dist/middleware/appInfo.js +14 -9
  347. package/dist/middleware/authorized.js +5 -5
  348. package/dist/middleware/builder.js +41 -40
  349. package/dist/middleware/currentapp.js +39 -37
  350. package/dist/middleware/joi-validator.js +17 -10
  351. package/dist/middleware/publicApi.js +5 -6
  352. package/dist/middleware/resourceId.js +16 -9
  353. package/dist/middleware/selfhost.js +5 -4
  354. package/dist/middleware/utils.js +5 -2
  355. package/dist/package.json +6 -6
  356. package/dist/sdk/app/tables/index.js +4 -4
  357. package/dist/tests/utilities/TestConfiguration.js +9 -9
  358. package/dist/tests/utilities/structures.js +2 -2
  359. package/dist/tsconfig.build.tsbuildinfo +1 -1
  360. package/dist/utilities/global.js +87 -66
  361. package/dist/utilities/security.js +10 -10
  362. package/dist/utilities/workerRequests.js +3 -3
  363. package/jest.config.ts +1 -0
  364. package/package.json +7 -7
  365. package/src/api/controllers/application.ts +34 -39
  366. package/src/api/controllers/auth.ts +3 -2
  367. package/src/api/controllers/deploy/index.ts +13 -25
  368. package/src/api/controllers/{dev.js → dev.ts} +31 -37
  369. package/src/api/controllers/public/applications.ts +15 -9
  370. package/src/api/controllers/query/index.ts +11 -14
  371. package/src/api/controllers/row/internal.js +2 -2
  372. package/src/api/routes/automation.js +4 -4
  373. package/src/api/routes/datasource.js +5 -5
  374. package/src/api/routes/public/index.ts +10 -10
  375. package/src/api/routes/public/tests/compare.spec.js +1 -1
  376. package/src/api/routes/query.js +5 -5
  377. package/src/api/routes/row.ts +12 -12
  378. package/src/api/routes/static.ts +5 -5
  379. package/src/api/routes/table.js +3 -3
  380. package/src/api/routes/tests/analytics.spec.js +1 -1
  381. package/src/api/routes/tests/query.spec.js +15 -10
  382. package/src/api/routes/tests/role.spec.js +5 -5
  383. package/src/api/routes/tests/static.spec.js +2 -2
  384. package/src/api/routes/tests/table.spec.js +38 -35
  385. package/src/api/routes/user.js +10 -10
  386. package/src/api/routes/utils/validators.js +5 -5
  387. package/src/api/routes/view.js +3 -3
  388. package/src/automations/tests/updateRow.spec.js +0 -1
  389. package/src/automations/tests/utilities/index.js +10 -4
  390. package/src/automations/utils.ts +9 -12
  391. package/src/db/inMemoryView.js +2 -2
  392. package/src/db/tests/linkController.spec.js +73 -57
  393. package/src/db/tests/linkTests.spec.js +17 -14
  394. package/src/db/{utils.js → utils.ts} +76 -92
  395. package/src/integrations/googlesheets.ts +4 -7
  396. package/src/middleware/appInfo.ts +20 -0
  397. package/src/middleware/authorized.ts +6 -6
  398. package/src/middleware/{builder.js → builder.ts} +17 -15
  399. package/src/middleware/{currentapp.js → currentapp.ts} +42 -39
  400. package/src/middleware/{joi-validator.js → joi-validator.ts} +9 -8
  401. package/src/middleware/publicApi.ts +21 -0
  402. package/src/middleware/{resourceId.js → resourceId.ts} +16 -11
  403. package/src/middleware/{selfhost.js → selfhost.ts} +4 -2
  404. package/src/middleware/tests/authorized.spec.js +5 -5
  405. package/src/middleware/tests/currentapp.spec.js +118 -63
  406. package/src/middleware/{utils.js → utils.ts} +3 -1
  407. package/src/migrations/functions/backfill/app/tables.ts +2 -5
  408. package/src/sdk/app/backups/imports.ts +4 -7
  409. package/src/sdk/app/backups/statistics.ts +9 -18
  410. package/src/sdk/app/tables/index.ts +6 -7
  411. package/src/tests/utilities/TestConfiguration.js +9 -9
  412. package/src/tests/utilities/structures.js +2 -2
  413. package/src/threads/automation.ts +1 -1
  414. package/src/utilities/global.ts +138 -0
  415. package/src/utilities/security.js +12 -12
  416. package/src/utilities/workerRequests.js +3 -3
  417. package/src/middleware/appInfo.js +0 -19
  418. package/src/middleware/publicApi.js +0 -21
  419. package/src/utilities/global.js +0 -127
@@ -8,49 +8,54 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
- const { getMultiIDParams, getGlobalIDFromUserMetadataID, } = require("../db/utils");
12
- const { BUILTIN_ROLE_IDS } = require("@budibase/backend-core/roles");
13
- const { getProdAppID } = require("@budibase/backend-core/db");
14
- const { getGlobalUserParams } = require("@budibase/backend-core/db");
15
- const { user: userCache } = require("@budibase/backend-core/cache");
16
- const { getGlobalDB, isUserInAppTenant, } = require("@budibase/backend-core/tenancy");
17
- const env = require("../environment");
18
- const { getAppId } = require("@budibase/backend-core/context");
19
- const { groups } = require("@budibase/pro");
20
- exports.updateAppRole = (user, { appId } = {}) => {
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.getGlobalUsersFromMetadata = exports.getGlobalUsers = exports.getGlobalUser = exports.getRawGlobalUser = exports.getCachedSelf = exports.updateAppRole = void 0;
16
+ const utils_1 = require("../db/utils");
17
+ const backend_core_1 = require("@budibase/backend-core");
18
+ const environment_1 = __importDefault(require("../environment"));
19
+ const pro_1 = require("@budibase/pro");
20
+ function updateAppRole(user, { appId } = {}) {
21
21
  var _a, _b;
22
- appId = appId || getAppId();
22
+ appId = appId || backend_core_1.context.getAppId();
23
23
  if (!user || !user.roles) {
24
24
  return user;
25
25
  }
26
26
  // if in an multi-tenancy environment make sure roles are never updated
27
- if (env.MULTI_TENANCY && !isUserInAppTenant(appId, user)) {
27
+ if (environment_1.default.MULTI_TENANCY && appId && !backend_core_1.tenancy.isUserInAppTenant(appId, user)) {
28
28
  delete user.builder;
29
29
  delete user.admin;
30
- user.roleId = BUILTIN_ROLE_IDS.PUBLIC;
30
+ user.roleId = backend_core_1.roles.BUILTIN_ROLE_IDS.PUBLIC;
31
31
  return user;
32
32
  }
33
33
  // always use the deployed app
34
- user.roleId = user.roles[getProdAppID(appId)];
34
+ if (appId) {
35
+ user.roleId = user.roles[backend_core_1.db.getProdAppID(appId)];
36
+ }
35
37
  // if a role wasn't found then either set as admin (builder) or public (everyone else)
36
38
  if (!user.roleId && user.builder && user.builder.global) {
37
- user.roleId = BUILTIN_ROLE_IDS.ADMIN;
39
+ user.roleId = backend_core_1.roles.BUILTIN_ROLE_IDS.ADMIN;
38
40
  }
39
41
  else if (!user.roleId && !((_a = user === null || user === void 0 ? void 0 : user.userGroups) === null || _a === void 0 ? void 0 : _a.length)) {
40
- user.roleId = BUILTIN_ROLE_IDS.PUBLIC;
42
+ user.roleId = backend_core_1.roles.BUILTIN_ROLE_IDS.PUBLIC;
41
43
  }
42
44
  else if ((_b = user === null || user === void 0 ? void 0 : user.userGroups) === null || _b === void 0 ? void 0 : _b.length) {
43
- user.roleId = null;
45
+ user.roleId = undefined;
44
46
  }
45
47
  delete user.roles;
46
48
  return user;
47
- };
49
+ }
50
+ exports.updateAppRole = updateAppRole;
48
51
  function checkGroupRoles(user, { appId } = {}) {
49
52
  return __awaiter(this, void 0, void 0, function* () {
50
- if (user.roleId && user.roleId !== BUILTIN_ROLE_IDS.PUBLIC) {
53
+ if (user.roleId && user.roleId !== backend_core_1.roles.BUILTIN_ROLE_IDS.PUBLIC) {
51
54
  return user;
52
55
  }
53
- user.roleId = yield groups.getGroupRoleId(user, appId);
56
+ if (appId) {
57
+ user.roleId = yield pro_1.groups.getGroupRoleId(user, appId);
58
+ }
54
59
  return user;
55
60
  });
56
61
  }
@@ -60,57 +65,73 @@ function processUser(user, { appId } = {}) {
60
65
  if (user) {
61
66
  delete user.password;
62
67
  }
63
- user = yield exports.updateAppRole(user, { appId });
68
+ user = yield updateAppRole(user, { appId });
64
69
  if (!user.roleId && ((_a = user === null || user === void 0 ? void 0 : user.userGroups) === null || _a === void 0 ? void 0 : _a.length)) {
65
70
  user = yield checkGroupRoles(user, { appId });
66
71
  }
67
72
  return user;
68
73
  });
69
74
  }
70
- exports.getCachedSelf = (ctx, appId) => __awaiter(void 0, void 0, void 0, function* () {
71
- // this has to be tenant aware, can't depend on the context to find it out
72
- // running some middlewares before the tenancy causes context to break
73
- const user = yield userCache.getUser(ctx.user._id);
74
- return processUser(user, { appId });
75
- });
76
- exports.getRawGlobalUser = (userId) => __awaiter(void 0, void 0, void 0, function* () {
77
- const db = getGlobalDB();
78
- return db.get(getGlobalIDFromUserMetadataID(userId));
79
- });
80
- exports.getGlobalUser = (userId) => __awaiter(void 0, void 0, void 0, function* () {
81
- const appId = getAppId();
82
- let user = yield exports.getRawGlobalUser(userId);
83
- return processUser(user, { appId });
84
- });
85
- exports.getGlobalUsers = (users = null) => __awaiter(void 0, void 0, void 0, function* () {
86
- const appId = getAppId();
87
- const db = getGlobalDB();
88
- let globalUsers;
89
- if (users) {
90
- const globalIds = users.map(user => getGlobalIDFromUserMetadataID(user._id));
91
- globalUsers = (yield db.allDocs(getMultiIDParams(globalIds))).rows.map(row => row.doc);
92
- }
93
- else {
94
- globalUsers = (yield db.allDocs(getGlobalUserParams(null, {
95
- include_docs: true,
96
- }))).rows.map(row => row.doc);
97
- }
98
- globalUsers = globalUsers
99
- .filter(user => user != null)
100
- .map(user => {
101
- delete user.password;
102
- delete user.forceResetPassword;
103
- return user;
75
+ function getCachedSelf(ctx, appId) {
76
+ var _a;
77
+ return __awaiter(this, void 0, void 0, function* () {
78
+ // this has to be tenant aware, can't depend on the context to find it out
79
+ // running some middlewares before the tenancy causes context to break
80
+ const user = yield backend_core_1.cache.user.getUser((_a = ctx.user) === null || _a === void 0 ? void 0 : _a._id);
81
+ return processUser(user, { appId });
104
82
  });
105
- if (!appId) {
106
- return globalUsers;
107
- }
108
- return globalUsers.map(user => exports.updateAppRole(user));
109
- });
110
- exports.getGlobalUsersFromMetadata = (users) => __awaiter(void 0, void 0, void 0, function* () {
111
- const globalUsers = yield exports.getGlobalUsers(users);
112
- return users.map(user => {
113
- const globalUser = globalUsers.find(globalUser => globalUser && user._id.includes(globalUser._id));
114
- return Object.assign(Object.assign({}, globalUser), user);
83
+ }
84
+ exports.getCachedSelf = getCachedSelf;
85
+ function getRawGlobalUser(userId) {
86
+ return __awaiter(this, void 0, void 0, function* () {
87
+ const db = backend_core_1.tenancy.getGlobalDB();
88
+ return db.get((0, utils_1.getGlobalIDFromUserMetadataID)(userId));
89
+ });
90
+ }
91
+ exports.getRawGlobalUser = getRawGlobalUser;
92
+ function getGlobalUser(userId) {
93
+ return __awaiter(this, void 0, void 0, function* () {
94
+ const appId = backend_core_1.context.getAppId();
95
+ let user = yield getRawGlobalUser(userId);
96
+ return processUser(user, { appId });
97
+ });
98
+ }
99
+ exports.getGlobalUser = getGlobalUser;
100
+ function getGlobalUsers(users) {
101
+ return __awaiter(this, void 0, void 0, function* () {
102
+ const appId = backend_core_1.context.getAppId();
103
+ const db = backend_core_1.tenancy.getGlobalDB();
104
+ let globalUsers;
105
+ if (users) {
106
+ const globalIds = users.map(user => (0, utils_1.getGlobalIDFromUserMetadataID)(user._id));
107
+ globalUsers = (yield db.allDocs((0, utils_1.getMultiIDParams)(globalIds))).rows.map(row => row.doc);
108
+ }
109
+ else {
110
+ globalUsers = (yield db.allDocs(backend_core_1.db.getGlobalUserParams(null, {
111
+ include_docs: true,
112
+ }))).rows.map(row => row.doc);
113
+ }
114
+ globalUsers = globalUsers
115
+ .filter(user => user != null)
116
+ .map(user => {
117
+ delete user.password;
118
+ delete user.forceResetPassword;
119
+ return user;
120
+ });
121
+ if (!appId) {
122
+ return globalUsers;
123
+ }
124
+ return globalUsers.map(user => updateAppRole(user));
115
125
  });
116
- });
126
+ }
127
+ exports.getGlobalUsers = getGlobalUsers;
128
+ function getGlobalUsersFromMetadata(users) {
129
+ return __awaiter(this, void 0, void 0, function* () {
130
+ const globalUsers = yield getGlobalUsers(users);
131
+ return users.map(user => {
132
+ const globalUser = globalUsers.find(globalUser => { var _a; return globalUser && ((_a = user._id) === null || _a === void 0 ? void 0 : _a.includes(globalUser._id)); });
133
+ return Object.assign(Object.assign({}, globalUser), user);
134
+ });
135
+ });
136
+ }
137
+ exports.getGlobalUsersFromMetadata = getGlobalUsersFromMetadata;
@@ -1,28 +1,28 @@
1
1
  "use strict";
2
- const { PermissionLevels, PermissionTypes, getBuiltinPermissionByID, isPermissionLevelHigherThanRead, } = require("@budibase/backend-core/permissions");
2
+ const { PermissionLevel, PermissionType, getBuiltinPermissionByID, isPermissionLevelHigherThanRead, } = require("@budibase/backend-core/permissions");
3
3
  const { lowerBuiltinRoleID, getBuiltinRoles, } = require("@budibase/backend-core/roles");
4
4
  const { DocumentType } = require("../db/utils");
5
5
  const CURRENTLY_SUPPORTED_LEVELS = [
6
- PermissionLevels.WRITE,
7
- PermissionLevels.READ,
8
- PermissionLevels.EXECUTE,
6
+ PermissionLevel.WRITE,
7
+ PermissionLevel.READ,
8
+ PermissionLevel.EXECUTE,
9
9
  ];
10
10
  exports.getPermissionType = resourceId => {
11
11
  const docType = Object.values(DocumentType).filter(docType => resourceId.startsWith(docType))[0];
12
12
  switch (docType) {
13
13
  case DocumentType.TABLE:
14
14
  case DocumentType.ROW:
15
- return PermissionTypes.TABLE;
15
+ return PermissionType.TABLE;
16
16
  case DocumentType.AUTOMATION:
17
- return PermissionTypes.AUTOMATION;
17
+ return PermissionType.AUTOMATION;
18
18
  case DocumentType.WEBHOOK:
19
- return PermissionTypes.WEBHOOK;
19
+ return PermissionType.WEBHOOK;
20
20
  case DocumentType.QUERY:
21
21
  case DocumentType.DATASOURCE:
22
- return PermissionTypes.QUERY;
22
+ return PermissionType.QUERY;
23
23
  default:
24
24
  // views don't have an ID, will end up here
25
- return PermissionTypes.VIEW;
25
+ return PermissionType.VIEW;
26
26
  }
27
27
  };
28
28
  /**
@@ -44,7 +44,7 @@ exports.getBasePermissions = resourceId => {
44
44
  const level = typedPermission.level;
45
45
  permissions[level] = lowerBuiltinRoleID(permissions[level], roleId);
46
46
  if (isPermissionLevelHigherThanRead(level)) {
47
- permissions[PermissionLevels.READ] = lowerBuiltinRoleID(permissions[PermissionLevels.READ], roleId);
47
+ permissions[PermissionLevel.READ] = lowerBuiltinRoleID(permissions[PermissionLevel.READ], roleId);
48
48
  }
49
49
  }
50
50
  }
@@ -13,16 +13,16 @@ const env = require("../environment");
13
13
  const { checkSlashesInUrl } = require("./index");
14
14
  const { getProdAppID } = require("@budibase/backend-core/db");
15
15
  const { updateAppRole } = require("./global");
16
- const { Headers } = require("@budibase/backend-core/constants");
16
+ const { Header } = require("@budibase/backend-core/constants");
17
17
  const { getTenantId, isTenantIdSet } = require("@budibase/backend-core/tenancy");
18
18
  function request(ctx, request) {
19
19
  if (!request.headers) {
20
20
  request.headers = {};
21
21
  }
22
22
  if (!ctx) {
23
- request.headers[Headers.API_KEY] = env.INTERNAL_API_KEY;
23
+ request.headers[Header.API_KEY] = env.INTERNAL_API_KEY;
24
24
  if (isTenantIdSet()) {
25
- request.headers[Headers.TENANT_ID] = getTenantId();
25
+ request.headers[Header.TENANT_ID] = getTenantId();
26
26
  }
27
27
  }
28
28
  if (request.body && Object.keys(request.body).length > 0) {
package/jest.config.ts CHANGED
@@ -19,6 +19,7 @@ if (!process.env.CI) {
19
19
  "@budibase/backend-core/(.*)": "<rootDir>/../backend-core/$1",
20
20
  "@budibase/backend-core": "<rootDir>/../backend-core/src",
21
21
  "@budibase/types": "<rootDir>/../types/src",
22
+ "^axios.*$": "<rootDir>/node_modules/axios/lib/axios.js",
22
23
  }
23
24
  // add pro sources if they exist
24
25
  if (fs.existsSync("../../../budibase-pro")) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@budibase/server",
3
3
  "email": "hi@budibase.com",
4
- "version": "2.1.22-alpha.6",
4
+ "version": "2.1.22-alpha.7",
5
5
  "description": "Budibase Web Server",
6
6
  "main": "src/index.ts",
7
7
  "repository": {
@@ -43,11 +43,11 @@
43
43
  "license": "GPL-3.0",
44
44
  "dependencies": {
45
45
  "@apidevtools/swagger-parser": "10.0.3",
46
- "@budibase/backend-core": "2.1.22-alpha.6",
47
- "@budibase/client": "2.1.22-alpha.6",
48
- "@budibase/pro": "2.1.22-alpha.5",
49
- "@budibase/string-templates": "2.1.22-alpha.6",
50
- "@budibase/types": "2.1.22-alpha.6",
46
+ "@budibase/backend-core": "2.1.22-alpha.7",
47
+ "@budibase/client": "2.1.22-alpha.7",
48
+ "@budibase/pro": "2.1.22-alpha.6",
49
+ "@budibase/string-templates": "2.1.22-alpha.7",
50
+ "@budibase/types": "2.1.22-alpha.7",
51
51
  "@bull-board/api": "3.7.0",
52
52
  "@bull-board/koa": "3.9.4",
53
53
  "@elastic/elasticsearch": "7.10.0",
@@ -165,5 +165,5 @@
165
165
  "optionalDependencies": {
166
166
  "oracledb": "5.3.0"
167
167
  },
168
- "gitHead": "395a9a21c27c534fd2b4297f5d0d19a341089993"
168
+ "gitHead": "c90a987eb1fd4c82429fc965f7389f0af6fb48ed"
169
169
  }
@@ -14,17 +14,16 @@ import {
14
14
  DocumentType,
15
15
  AppStatus,
16
16
  } from "../../db/utils"
17
- const {
18
- BUILTIN_ROLE_IDS,
19
- AccessController,
20
- } = require("@budibase/backend-core/roles")
21
- const { CacheKeys, bustCache } = require("@budibase/backend-core/cache")
22
- const {
23
- getAllApps,
24
- isDevAppID,
25
- getProdAppID,
26
- Replication,
27
- } = require("@budibase/backend-core/db")
17
+ import {
18
+ db as dbCore,
19
+ roles,
20
+ cache,
21
+ tenancy,
22
+ context,
23
+ errors,
24
+ events,
25
+ migrations,
26
+ } from "@budibase/backend-core"
28
27
  import { USERS_TABLE_SCHEMA } from "../../constants"
29
28
  import { removeAppFromUserRoles } from "../../utilities/workerRequests"
30
29
  import { clientLibraryPath, stringToReadStream } from "../../utilities"
@@ -34,15 +33,11 @@ import {
34
33
  backupClientLibrary,
35
34
  revertClientLibrary,
36
35
  } from "../../utilities/fileSystem/clientLibrary"
37
- const { getTenantId, isMultiTenant } = require("@budibase/backend-core/tenancy")
38
36
  import { syncGlobalUsers } from "./user"
39
- const { app: appCache } = require("@budibase/backend-core/cache")
40
37
  import { cleanupAutomations } from "../../automations/utils"
41
- import { context } from "@budibase/backend-core"
42
38
  import { checkAppMetadata } from "../../automations/logging"
43
39
  import { getUniqueRows } from "../../utilities/usageQuota/rows"
44
40
  import { quotas, groups } from "@budibase/pro"
45
- import { errors, events, migrations } from "@budibase/backend-core"
46
41
  import { App, Layout, Screen, MigrationType } from "@budibase/types"
47
42
  import { BASE_LAYOUT_PROP_IDS } from "../../constants/layouts"
48
43
  import { enrichPluginURLs } from "../../utilities/plugins"
@@ -75,7 +70,7 @@ async function getScreens() {
75
70
 
76
71
  function getUserRoleId(ctx: any) {
77
72
  return !ctx.user.role || !ctx.user.role._id
78
- ? BUILTIN_ROLE_IDS.PUBLIC
73
+ ? roles.BUILTIN_ROLE_IDS.PUBLIC
79
74
  : ctx.user.role._id
80
75
  }
81
76
 
@@ -123,7 +118,7 @@ const checkAppName = (
123
118
  }
124
119
 
125
120
  async function createInstance(template: any) {
126
- const tenantId = isMultiTenant() ? getTenantId() : null
121
+ const tenantId = tenancy.isMultiTenant() ? tenancy.getTenantId() : null
127
122
  const baseAppId = generateAppID(tenantId)
128
123
  const appId = generateDevAppID(baseAppId)
129
124
  await context.updateAppId(appId)
@@ -162,7 +157,7 @@ async function createInstance(template: any) {
162
157
  export const fetch = async (ctx: any) => {
163
158
  const dev = ctx.query && ctx.query.status === AppStatus.DEV
164
159
  const all = ctx.query && ctx.query.status === AppStatus.ALL
165
- const apps = await getAllApps({ dev, all })
160
+ const apps = (await dbCore.getAllApps({ dev, all })) as App[]
166
161
 
167
162
  const appIds = apps
168
163
  .filter((app: any) => app.status === "development")
@@ -187,7 +182,7 @@ export const fetch = async (ctx: any) => {
187
182
  export const fetchAppDefinition = async (ctx: any) => {
188
183
  const layouts = await getLayouts()
189
184
  const userRoleId = getUserRoleId(ctx)
190
- const accessController = new AccessController()
185
+ const accessController = new roles.AccessController()
191
186
  const screens = await accessController.checkScreensAccess(
192
187
  await getScreens(),
193
188
  userRoleId
@@ -211,7 +206,7 @@ export const fetchAppPackage = async (ctx: any) => {
211
206
  // Only filter screens if the user is not a builder
212
207
  if (!(ctx.user.builder && ctx.user.builder.global)) {
213
208
  const userRoleId = getUserRoleId(ctx)
214
- const accessController = new AccessController()
209
+ const accessController = new roles.AccessController()
215
210
  screens = await accessController.checkScreensAccess(screens, userRoleId)
216
211
  }
217
212
 
@@ -224,7 +219,7 @@ export const fetchAppPackage = async (ctx: any) => {
224
219
  }
225
220
 
226
221
  const performAppCreate = async (ctx: any) => {
227
- const apps = await getAllApps({ dev: true })
222
+ const apps = await dbCore.getAllApps({ dev: true })
228
223
  const name = ctx.request.body.name
229
224
  checkAppName(ctx, apps, name)
230
225
  const url = getAppUrl(ctx)
@@ -254,7 +249,7 @@ const performAppCreate = async (ctx: any) => {
254
249
  url: url,
255
250
  template: templateKey,
256
251
  instance,
257
- tenantId: getTenantId(),
252
+ tenantId: tenancy.getTenantId(),
258
253
  updatedAt: new Date().toISOString(),
259
254
  createdAt: new Date().toISOString(),
260
255
  status: AppStatus.DEV,
@@ -313,7 +308,7 @@ const performAppCreate = async (ctx: any) => {
313
308
  await createApp(appId)
314
309
  }
315
310
 
316
- await appCache.invalidateAppMetadata(appId, newApplication)
311
+ await cache.app.invalidateAppMetadata(appId, newApplication)
317
312
  return newApplication
318
313
  }
319
314
 
@@ -343,7 +338,7 @@ const creationEvents = async (request: any, app: App) => {
343
338
  }
344
339
 
345
340
  const appPostCreate = async (ctx: any, app: App) => {
346
- const tenantId = getTenantId()
341
+ const tenantId = tenancy.getTenantId()
347
342
  await migrations.backPopulateMigrations({
348
343
  type: MigrationType.APP,
349
344
  tenantId,
@@ -356,7 +351,9 @@ const appPostCreate = async (ctx: any, app: App) => {
356
351
  const rowCount = rows ? rows.length : 0
357
352
  if (rowCount) {
358
353
  try {
359
- await quotas.addRows(rowCount)
354
+ await context.doInAppContext(app.appId, () => {
355
+ return quotas.addRows(rowCount)
356
+ })
360
357
  } catch (err: any) {
361
358
  if (err.code && err.code === errors.codes.USAGE_LIMIT_EXCEEDED) {
362
359
  // this import resulted in row usage exceeding the quota
@@ -374,7 +371,7 @@ const appPostCreate = async (ctx: any, app: App) => {
374
371
  export const create = async (ctx: any) => {
375
372
  const newApplication = await quotas.addApp(() => performAppCreate(ctx))
376
373
  await appPostCreate(ctx, newApplication)
377
- await bustCache(CacheKeys.CHECKLIST)
374
+ await cache.bustCache(cache.CacheKeys.CHECKLIST)
378
375
  ctx.body = newApplication
379
376
  ctx.status = 200
380
377
  }
@@ -382,7 +379,7 @@ export const create = async (ctx: any) => {
382
379
  // This endpoint currently operates as a PATCH rather than a PUT
383
380
  // Thus name and url fields are handled only if present
384
381
  export const update = async (ctx: any) => {
385
- const apps = await getAllApps({ dev: true })
382
+ const apps = await dbCore.getAllApps({ dev: true })
386
383
  // validation
387
384
  const name = ctx.request.body.name
388
385
  if (name) {
@@ -455,7 +452,7 @@ const destroyApp = async (ctx: any) => {
455
452
  let isUnpublish = ctx.query && ctx.query.unpublish
456
453
 
457
454
  if (isUnpublish) {
458
- appId = getProdAppID(appId)
455
+ appId = dbCore.getProdAppID(appId)
459
456
  }
460
457
 
461
458
  const db = isUnpublish ? context.getProdAppDB() : context.getAppDB()
@@ -481,7 +478,7 @@ const destroyApp = async (ctx: any) => {
481
478
  else {
482
479
  await removeAppFromUserRoles(ctx, appId)
483
480
  }
484
- await appCache.invalidateAppMetadata(appId)
481
+ await cache.app.invalidateAppMetadata(appId)
485
482
  return result
486
483
  }
487
484
 
@@ -517,19 +514,17 @@ export const sync = async (ctx: any, next: any) => {
517
514
  }
518
515
 
519
516
  const appId = ctx.params.appId
520
- if (!isDevAppID(appId)) {
517
+ if (!dbCore.isDevAppID(appId)) {
521
518
  ctx.throw(400, "This action cannot be performed for production apps")
522
519
  }
523
520
 
524
521
  // replicate prod to dev
525
- const prodAppId = getProdAppID(appId)
522
+ const prodAppId = dbCore.getProdAppID(appId)
526
523
 
527
- try {
528
- // specific case, want to make sure setup is skipped
529
- const prodDb = context.getProdAppDB({ skip_setup: true })
530
- const info = await prodDb.info()
531
- if (info.error) throw info.error
532
- } catch (err) {
524
+ // specific case, want to make sure setup is skipped
525
+ const prodDb = context.getProdAppDB({ skip_setup: true })
526
+ const exists = await prodDb.exists()
527
+ if (!exists) {
533
528
  // the database doesn't exist. Don't replicate
534
529
  ctx.status = 200
535
530
  ctx.body = {
@@ -538,7 +533,7 @@ export const sync = async (ctx: any, next: any) => {
538
533
  return next()
539
534
  }
540
535
 
541
- const replication = new Replication({
536
+ const replication = new dbCore.Replication({
542
537
  source: prodAppId,
543
538
  target: appId,
544
539
  })
@@ -579,7 +574,7 @@ export const updateAppPackage = async (appPackage: any, appId: any) => {
579
574
 
580
575
  await db.put(newAppPackage)
581
576
  // remove any cached metadata, so that it will be updated
582
- await appCache.invalidateAppMetadata(appId)
577
+ await cache.app.invalidateAppMetadata(appId)
583
578
  return newAppPackage
584
579
  })
585
580
  }
@@ -3,6 +3,7 @@ import { InternalTables } from "../../db/utils"
3
3
  import { getFullUser } from "../../utilities/users"
4
4
  import { roles, context } from "@budibase/backend-core"
5
5
  import { groups } from "@budibase/pro"
6
+ import { ContextUser, User } from "@budibase/types"
6
7
 
7
8
  const PUBLIC_ROLE = roles.BUILTIN_ROLE_IDS.PUBLIC
8
9
 
@@ -24,7 +25,7 @@ export async function fetchSelf(ctx: any) {
24
25
  }
25
26
 
26
27
  const appId = context.getAppId()
27
- const user = await getFullUser(ctx, userId)
28
+ const user: ContextUser = await getFullUser(ctx, userId)
28
29
  // this shouldn't be returned by the app self
29
30
  delete user.roles
30
31
  // forward the csrf token from the session
@@ -34,7 +35,7 @@ export async function fetchSelf(ctx: any) {
34
35
  const db = context.getAppDB()
35
36
  // check for group permissions
36
37
  if (!user.roleId || user.roleId === PUBLIC_ROLE) {
37
- const groupRoleId = await groups.getGroupRoleId(user, appId)
38
+ const groupRoleId = await groups.getGroupRoleId(user as User, appId)
38
39
  user.roleId = groupRoleId || user.roleId
39
40
  }
40
41
  // remove the full roles structure
@@ -1,23 +1,11 @@
1
1
  import Deployment from "./Deployment"
2
- import {
3
- getDevelopmentAppID,
4
- getProdAppID,
5
- Replication,
6
- } from "@budibase/backend-core/db"
2
+ import { context, db as dbCore, events, cache } from "@budibase/backend-core"
7
3
  import { DocumentType, getAutomationParams } from "../../../db/utils"
8
4
  import {
9
5
  clearMetadata,
10
6
  disableAllCrons,
11
7
  enableCronTrigger,
12
8
  } from "../../../automations/utils"
13
- import { app as appCache } from "@budibase/backend-core/cache"
14
- import {
15
- getAppDB,
16
- getAppId,
17
- getDevAppDB,
18
- getProdAppDB,
19
- } from "@budibase/backend-core/context"
20
- import { events } from "@budibase/backend-core"
21
9
  import { backups } from "@budibase/pro"
22
10
  import { AppBackupTrigger } from "@budibase/types"
23
11
 
@@ -49,7 +37,7 @@ async function checkAllDeployments(deployments: any) {
49
37
 
50
38
  async function storeDeploymentHistory(deployment: any) {
51
39
  const deploymentJSON = deployment.getJSON()
52
- const db = getAppDB()
40
+ const db = context.getAppDB()
53
41
 
54
42
  let deploymentDoc
55
43
  try {
@@ -77,7 +65,7 @@ async function storeDeploymentHistory(deployment: any) {
77
65
  }
78
66
 
79
67
  async function initDeployedApp(prodAppId: any) {
80
- const db = getProdAppDB()
68
+ const db = context.getProdAppDB()
81
69
  console.log("Reading automation docs")
82
70
  const automations = (
83
71
  await db.allDocs(
@@ -103,9 +91,9 @@ async function initDeployedApp(prodAppId: any) {
103
91
  async function deployApp(deployment: any, userId: string) {
104
92
  let replication
105
93
  try {
106
- const appId = getAppId()
107
- const devAppId = getDevelopmentAppID(appId)
108
- const productionAppId = getProdAppID(appId)
94
+ const appId = context.getAppId()!
95
+ const devAppId = dbCore.getDevelopmentAppID(appId)
96
+ const productionAppId = dbCore.getProdAppID(appId)
109
97
 
110
98
  // don't try this if feature isn't allowed, will error
111
99
  if (await backups.isEnabled()) {
@@ -122,8 +110,8 @@ async function deployApp(deployment: any, userId: string) {
122
110
  source: devAppId,
123
111
  target: productionAppId,
124
112
  }
125
- replication = new Replication(config)
126
- const devDb = getDevAppDB()
113
+ replication = new dbCore.Replication(config)
114
+ const devDb = context.getDevAppDB()
127
115
  console.log("Compacting development DB")
128
116
  await devDb.compact()
129
117
  console.log("Replication object created")
@@ -131,7 +119,7 @@ async function deployApp(deployment: any, userId: string) {
131
119
  console.log("replication complete.. replacing app meta doc")
132
120
  // app metadata is excluded as it is likely to be in conflict
133
121
  // replicate the app metadata document manually
134
- const db = getProdAppDB()
122
+ const db = context.getProdAppDB()
135
123
  const appDoc = await devDb.get(DocumentType.APP_METADATA)
136
124
  try {
137
125
  const prodAppDoc = await db.get(DocumentType.APP_METADATA)
@@ -147,7 +135,7 @@ async function deployApp(deployment: any, userId: string) {
147
135
  // remove automation errors if they exist
148
136
  delete appDoc.automationErrors
149
137
  await db.put(appDoc)
150
- await appCache.invalidateAppMetadata(productionAppId)
138
+ await cache.app.invalidateAppMetadata(productionAppId)
151
139
  console.log("New app doc written successfully.")
152
140
  await initDeployedApp(productionAppId)
153
141
  console.log("Deployed app initialised, setting deployment to successful")
@@ -170,7 +158,7 @@ async function deployApp(deployment: any, userId: string) {
170
158
 
171
159
  export async function fetchDeployments(ctx: any) {
172
160
  try {
173
- const db = getAppDB()
161
+ const db = context.getAppDB()
174
162
  const deploymentDoc = await db.get(DocumentType.DEPLOYMENTS)
175
163
  const { updated, deployments } = await checkAllDeployments(deploymentDoc)
176
164
  if (updated) {
@@ -184,7 +172,7 @@ export async function fetchDeployments(ctx: any) {
184
172
 
185
173
  export async function deploymentProgress(ctx: any) {
186
174
  try {
187
- const db = getAppDB()
175
+ const db = context.getAppDB()
188
176
  const deploymentDoc = await db.get(DocumentType.DEPLOYMENTS)
189
177
  ctx.body = deploymentDoc[ctx.params.deploymentId]
190
178
  } catch (err) {
@@ -197,7 +185,7 @@ export async function deploymentProgress(ctx: any) {
197
185
 
198
186
  const isFirstDeploy = async () => {
199
187
  try {
200
- const db = getProdAppDB()
188
+ const db = context.getProdAppDB()
201
189
  await db.get(DocumentType.APP_METADATA)
202
190
  } catch (e: any) {
203
191
  if (e.status === 404) {