@budibase/server 2.1.22-alpha.5 → 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 (425) hide show
  1. package/__mocks__/node-fetch.ts +5 -1
  2. package/builder/assets/{index.ccab8b9a.js → index.22484e23.js} +286 -286
  3. package/builder/assets/{index.1a9c91e2.css → index.624f0ace.css} +1 -1
  4. package/builder/index.html +2 -2
  5. package/coverage/clover.xml +1182 -1209
  6. package/coverage/coverage-final.json +37 -37
  7. package/coverage/lcov-report/index.html +94 -94
  8. package/coverage/lcov-report/src/api/controllers/analytics.ts.html +1 -1
  9. package/coverage/lcov-report/src/api/controllers/apikeys.js.html +1 -1
  10. package/coverage/lcov-report/src/api/controllers/application.ts.html +45 -60
  11. package/coverage/lcov-report/src/api/controllers/auth.ts.html +7 -4
  12. package/coverage/lcov-report/src/api/controllers/automation.js.html +1 -1
  13. package/coverage/lcov-report/src/api/controllers/backup.ts.html +1 -1
  14. package/coverage/lcov-report/src/api/controllers/cloud.js.html +1 -1
  15. package/coverage/lcov-report/src/api/controllers/component.ts.html +1 -1
  16. package/coverage/lcov-report/src/api/controllers/datasource.js.html +1 -1
  17. package/coverage/lcov-report/src/api/controllers/deploy/Deployment.js.html +1 -1
  18. package/coverage/lcov-report/src/api/controllers/deploy/index.html +10 -10
  19. package/coverage/lcov-report/src/api/controllers/deploy/index.ts.html +19 -55
  20. package/coverage/lcov-report/src/api/controllers/{dev.js.html → dev.ts.html} +46 -64
  21. package/coverage/lcov-report/src/api/controllers/index.html +25 -25
  22. package/coverage/lcov-report/src/api/controllers/integration.js.html +1 -1
  23. package/coverage/lcov-report/src/api/controllers/layout.js.html +1 -1
  24. package/coverage/lcov-report/src/api/controllers/metadata.js.html +1 -1
  25. package/coverage/lcov-report/src/api/controllers/migrations.js.html +1 -1
  26. package/coverage/lcov-report/src/api/controllers/permission.js.html +1 -1
  27. package/coverage/lcov-report/src/api/controllers/plugin/file.ts.html +1 -1
  28. package/coverage/lcov-report/src/api/controllers/plugin/github.ts.html +1 -1
  29. package/coverage/lcov-report/src/api/controllers/plugin/index.html +1 -1
  30. package/coverage/lcov-report/src/api/controllers/plugin/index.ts.html +1 -1
  31. package/coverage/lcov-report/src/api/controllers/plugin/npm.ts.html +1 -1
  32. package/coverage/lcov-report/src/api/controllers/plugin/uploaders.ts.html +1 -1
  33. package/coverage/lcov-report/src/api/controllers/plugin/url.ts.html +1 -1
  34. package/coverage/lcov-report/src/api/controllers/plugin/utils.ts.html +1 -1
  35. package/coverage/lcov-report/src/api/controllers/public/applications.ts.html +37 -19
  36. package/coverage/lcov-report/src/api/controllers/public/index.html +16 -16
  37. package/coverage/lcov-report/src/api/controllers/public/mapping/applications.ts.html +1 -1
  38. package/coverage/lcov-report/src/api/controllers/public/mapping/index.html +1 -1
  39. package/coverage/lcov-report/src/api/controllers/public/mapping/index.ts.html +1 -1
  40. package/coverage/lcov-report/src/api/controllers/public/mapping/queries.ts.html +1 -1
  41. package/coverage/lcov-report/src/api/controllers/public/mapping/rows.ts.html +1 -1
  42. package/coverage/lcov-report/src/api/controllers/public/mapping/tables.ts.html +1 -1
  43. package/coverage/lcov-report/src/api/controllers/public/mapping/users.ts.html +1 -1
  44. package/coverage/lcov-report/src/api/controllers/public/queries.ts.html +1 -1
  45. package/coverage/lcov-report/src/api/controllers/public/rows.ts.html +1 -1
  46. package/coverage/lcov-report/src/api/controllers/public/tables.ts.html +1 -1
  47. package/coverage/lcov-report/src/api/controllers/public/users.ts.html +1 -1
  48. package/coverage/lcov-report/src/api/controllers/public/utils.ts.html +1 -1
  49. package/coverage/lcov-report/src/api/controllers/query/import/index.html +1 -1
  50. package/coverage/lcov-report/src/api/controllers/query/import/index.ts.html +1 -1
  51. package/coverage/lcov-report/src/api/controllers/query/import/sources/base/index.html +1 -1
  52. package/coverage/lcov-report/src/api/controllers/query/import/sources/base/index.ts.html +1 -1
  53. package/coverage/lcov-report/src/api/controllers/query/import/sources/base/openapi.ts.html +1 -1
  54. package/coverage/lcov-report/src/api/controllers/query/import/sources/curl.ts.html +1 -1
  55. package/coverage/lcov-report/src/api/controllers/query/import/sources/index.html +1 -1
  56. package/coverage/lcov-report/src/api/controllers/query/import/sources/openapi2.ts.html +1 -1
  57. package/coverage/lcov-report/src/api/controllers/query/import/sources/openapi3.ts.html +1 -1
  58. package/coverage/lcov-report/src/api/controllers/query/index.html +10 -10
  59. package/coverage/lcov-report/src/api/controllers/query/index.ts.html +17 -26
  60. package/coverage/lcov-report/src/api/controllers/query/validation.js.html +1 -1
  61. package/coverage/lcov-report/src/api/controllers/role.js.html +1 -1
  62. package/coverage/lcov-report/src/api/controllers/routing.js.html +1 -1
  63. package/coverage/lcov-report/src/api/controllers/row/ExternalRequest.ts.html +1 -1
  64. package/coverage/lcov-report/src/api/controllers/row/external.js.html +1 -1
  65. package/coverage/lcov-report/src/api/controllers/row/index.html +1 -1
  66. package/coverage/lcov-report/src/api/controllers/row/index.ts.html +1 -1
  67. package/coverage/lcov-report/src/api/controllers/row/internal.js.html +3 -3
  68. package/coverage/lcov-report/src/api/controllers/row/internalSearch.js.html +1 -1
  69. package/coverage/lcov-report/src/api/controllers/row/staticFormula.js.html +1 -1
  70. package/coverage/lcov-report/src/api/controllers/row/utils.js.html +1 -1
  71. package/coverage/lcov-report/src/api/controllers/screen.ts.html +1 -1
  72. package/coverage/lcov-report/src/api/controllers/script.js.html +1 -1
  73. package/coverage/lcov-report/src/api/controllers/static/index.html +1 -1
  74. package/coverage/lcov-report/src/api/controllers/static/index.ts.html +1 -1
  75. package/coverage/lcov-report/src/api/controllers/table/bulkFormula.js.html +1 -1
  76. package/coverage/lcov-report/src/api/controllers/table/external.js.html +1 -1
  77. package/coverage/lcov-report/src/api/controllers/table/index.html +1 -1
  78. package/coverage/lcov-report/src/api/controllers/table/index.js.html +1 -1
  79. package/coverage/lcov-report/src/api/controllers/table/internal.ts.html +1 -1
  80. package/coverage/lcov-report/src/api/controllers/table/utils.ts.html +1 -1
  81. package/coverage/lcov-report/src/api/controllers/templates.js.html +1 -1
  82. package/coverage/lcov-report/src/api/controllers/user.js.html +1 -1
  83. package/coverage/lcov-report/src/api/controllers/view/exporters.js.html +1 -1
  84. package/coverage/lcov-report/src/api/controllers/view/index.html +1 -1
  85. package/coverage/lcov-report/src/api/controllers/view/index.js.html +1 -1
  86. package/coverage/lcov-report/src/api/controllers/view/utils.js.html +1 -1
  87. package/coverage/lcov-report/src/api/controllers/view/viewBuilder.js.html +1 -1
  88. package/coverage/lcov-report/src/api/controllers/webhook.ts.html +1 -1
  89. package/coverage/lcov-report/src/api/index.html +1 -1
  90. package/coverage/lcov-report/src/api/index.js.html +1 -1
  91. package/coverage/lcov-report/src/api/routes/analytics.js.html +1 -1
  92. package/coverage/lcov-report/src/api/routes/apikeys.js.html +1 -1
  93. package/coverage/lcov-report/src/api/routes/application.ts.html +1 -1
  94. package/coverage/lcov-report/src/api/routes/auth.ts.html +1 -1
  95. package/coverage/lcov-report/src/api/routes/automation.js.html +5 -5
  96. package/coverage/lcov-report/src/api/routes/backup.ts.html +1 -1
  97. package/coverage/lcov-report/src/api/routes/cloud.js.html +1 -1
  98. package/coverage/lcov-report/src/api/routes/component.js.html +1 -1
  99. package/coverage/lcov-report/src/api/routes/datasource.js.html +6 -6
  100. package/coverage/lcov-report/src/api/routes/deploy.js.html +1 -1
  101. package/coverage/lcov-report/src/api/routes/dev.js.html +1 -1
  102. package/coverage/lcov-report/src/api/routes/index.html +1 -1
  103. package/coverage/lcov-report/src/api/routes/index.ts.html +1 -1
  104. package/coverage/lcov-report/src/api/routes/integration.js.html +1 -1
  105. package/coverage/lcov-report/src/api/routes/layout.js.html +1 -1
  106. package/coverage/lcov-report/src/api/routes/metadata.js.html +1 -1
  107. package/coverage/lcov-report/src/api/routes/migrations.js.html +1 -1
  108. package/coverage/lcov-report/src/api/routes/permission.js.html +1 -1
  109. package/coverage/lcov-report/src/api/routes/plugin.ts.html +1 -1
  110. package/coverage/lcov-report/src/api/routes/public/applications.ts.html +1 -1
  111. package/coverage/lcov-report/src/api/routes/public/index.html +1 -1
  112. package/coverage/lcov-report/src/api/routes/public/index.ts.html +11 -11
  113. package/coverage/lcov-report/src/api/routes/public/middleware/index.html +1 -1
  114. package/coverage/lcov-report/src/api/routes/public/middleware/mapper.ts.html +1 -1
  115. package/coverage/lcov-report/src/api/routes/public/queries.ts.html +1 -1
  116. package/coverage/lcov-report/src/api/routes/public/rows.ts.html +1 -1
  117. package/coverage/lcov-report/src/api/routes/public/tables.ts.html +1 -1
  118. package/coverage/lcov-report/src/api/routes/public/users.ts.html +1 -1
  119. package/coverage/lcov-report/src/api/routes/public/utils/Endpoint.ts.html +1 -1
  120. package/coverage/lcov-report/src/api/routes/public/utils/index.html +1 -1
  121. package/coverage/lcov-report/src/api/routes/query.js.html +6 -6
  122. package/coverage/lcov-report/src/api/routes/role.js.html +1 -1
  123. package/coverage/lcov-report/src/api/routes/routing.js.html +1 -1
  124. package/coverage/lcov-report/src/api/routes/row.ts.html +13 -13
  125. package/coverage/lcov-report/src/api/routes/screen.js.html +1 -1
  126. package/coverage/lcov-report/src/api/routes/script.js.html +1 -1
  127. package/coverage/lcov-report/src/api/routes/static.ts.html +6 -6
  128. package/coverage/lcov-report/src/api/routes/table.js.html +4 -4
  129. package/coverage/lcov-report/src/api/routes/templates.js.html +1 -1
  130. package/coverage/lcov-report/src/api/routes/tests/utilities/TestFunctions.ts.html +1 -1
  131. package/coverage/lcov-report/src/api/routes/tests/utilities/index.html +1 -1
  132. package/coverage/lcov-report/src/api/routes/tests/utilities/index.js.html +1 -1
  133. package/coverage/lcov-report/src/api/routes/user.js.html +11 -11
  134. package/coverage/lcov-report/src/api/routes/utils/index.html +1 -1
  135. package/coverage/lcov-report/src/api/routes/utils/validators.js.html +6 -6
  136. package/coverage/lcov-report/src/api/routes/view.js.html +4 -4
  137. package/coverage/lcov-report/src/api/routes/webhook.ts.html +1 -1
  138. package/coverage/lcov-report/src/app.ts.html +1 -1
  139. package/coverage/lcov-report/src/automations/actions.js.html +1 -1
  140. package/coverage/lcov-report/src/automations/automationUtils.js.html +1 -1
  141. package/coverage/lcov-report/src/automations/bullboard.js.html +1 -1
  142. package/coverage/lcov-report/src/automations/index.html +15 -15
  143. package/coverage/lcov-report/src/automations/index.js.html +1 -1
  144. package/coverage/lcov-report/src/automations/logging/index.html +1 -1
  145. package/coverage/lcov-report/src/automations/logging/index.ts.html +1 -1
  146. package/coverage/lcov-report/src/automations/steps/bash.js.html +1 -1
  147. package/coverage/lcov-report/src/automations/steps/createRow.ts.html +1 -1
  148. package/coverage/lcov-report/src/automations/steps/delay.js.html +1 -1
  149. package/coverage/lcov-report/src/automations/steps/deleteRow.ts.html +1 -1
  150. package/coverage/lcov-report/src/automations/steps/discord.js.html +1 -1
  151. package/coverage/lcov-report/src/automations/steps/executeQuery.js.html +1 -1
  152. package/coverage/lcov-report/src/automations/steps/executeScript.js.html +1 -1
  153. package/coverage/lcov-report/src/automations/steps/filter.js.html +1 -1
  154. package/coverage/lcov-report/src/automations/steps/index.html +1 -1
  155. package/coverage/lcov-report/src/automations/steps/integromat.js.html +1 -1
  156. package/coverage/lcov-report/src/automations/steps/loop.js.html +1 -1
  157. package/coverage/lcov-report/src/automations/steps/outgoingWebhook.js.html +1 -1
  158. package/coverage/lcov-report/src/automations/steps/queryRows.js.html +1 -1
  159. package/coverage/lcov-report/src/automations/steps/sendSmtpEmail.js.html +1 -1
  160. package/coverage/lcov-report/src/automations/steps/serverLog.js.html +1 -1
  161. package/coverage/lcov-report/src/automations/steps/slack.js.html +1 -1
  162. package/coverage/lcov-report/src/automations/steps/updateRow.js.html +1 -1
  163. package/coverage/lcov-report/src/automations/steps/utils.js.html +1 -1
  164. package/coverage/lcov-report/src/automations/steps/zapier.js.html +1 -1
  165. package/coverage/lcov-report/src/automations/tests/utilities/index.html +17 -17
  166. package/coverage/lcov-report/src/automations/tests/utilities/index.js.html +33 -15
  167. package/coverage/lcov-report/src/automations/triggerInfo/app.js.html +1 -1
  168. package/coverage/lcov-report/src/automations/triggerInfo/cron.js.html +1 -1
  169. package/coverage/lcov-report/src/automations/triggerInfo/index.html +1 -1
  170. package/coverage/lcov-report/src/automations/triggerInfo/index.js.html +1 -1
  171. package/coverage/lcov-report/src/automations/triggerInfo/rowDeleted.js.html +1 -1
  172. package/coverage/lcov-report/src/automations/triggerInfo/rowSaved.js.html +1 -1
  173. package/coverage/lcov-report/src/automations/triggerInfo/rowUpdated.js.html +1 -1
  174. package/coverage/lcov-report/src/automations/triggerInfo/webhook.js.html +1 -1
  175. package/coverage/lcov-report/src/automations/triggers.js.html +1 -1
  176. package/coverage/lcov-report/src/automations/utils.ts.html +20 -29
  177. package/coverage/lcov-report/src/constants/index.html +1 -1
  178. package/coverage/lcov-report/src/constants/index.js.html +1 -1
  179. package/coverage/lcov-report/src/constants/layouts.js.html +1 -1
  180. package/coverage/lcov-report/src/constants/screens.js.html +1 -1
  181. package/coverage/lcov-report/src/db/dynamoClient.js.html +1 -1
  182. package/coverage/lcov-report/src/db/inMemoryView.js.html +3 -3
  183. package/coverage/lcov-report/src/db/index.html +16 -16
  184. package/coverage/lcov-report/src/db/index.js.html +9 -9
  185. package/coverage/lcov-report/src/db/linkedRows/LinkController.js.html +1 -1
  186. package/coverage/lcov-report/src/db/linkedRows/index.html +1 -1
  187. package/coverage/lcov-report/src/db/linkedRows/index.js.html +1 -1
  188. package/coverage/lcov-report/src/db/linkedRows/linkUtils.js.html +1 -1
  189. package/coverage/lcov-report/src/db/newid.js.html +1 -1
  190. package/coverage/lcov-report/src/db/{utils.js.html → utils.ts.html} +97 -145
  191. package/coverage/lcov-report/src/definitions/automations.ts.html +1 -1
  192. package/coverage/lcov-report/src/definitions/datasource.ts.html +1 -1
  193. package/coverage/lcov-report/src/definitions/index.html +1 -1
  194. package/coverage/lcov-report/src/environment.js.html +4 -4
  195. package/coverage/lcov-report/src/events/AutomationEmitter.js.html +1 -1
  196. package/coverage/lcov-report/src/events/index.html +1 -1
  197. package/coverage/lcov-report/src/events/index.js.html +1 -1
  198. package/coverage/lcov-report/src/events/utils.js.html +1 -1
  199. package/coverage/lcov-report/src/index.html +1 -1
  200. package/coverage/lcov-report/src/index.ts.html +1 -1
  201. package/coverage/lcov-report/src/integrations/airtable.ts.html +1 -1
  202. package/coverage/lcov-report/src/integrations/arangodb.ts.html +1 -1
  203. package/coverage/lcov-report/src/integrations/base/index.html +1 -1
  204. package/coverage/lcov-report/src/integrations/base/query.ts.html +1 -1
  205. package/coverage/lcov-report/src/integrations/base/sql.ts.html +1 -1
  206. package/coverage/lcov-report/src/integrations/base/sqlTable.ts.html +1 -1
  207. package/coverage/lcov-report/src/integrations/base/utils.ts.html +1 -1
  208. package/coverage/lcov-report/src/integrations/couchdb.ts.html +1 -1
  209. package/coverage/lcov-report/src/integrations/dynamodb.ts.html +1 -1
  210. package/coverage/lcov-report/src/integrations/elasticsearch.ts.html +1 -1
  211. package/coverage/lcov-report/src/integrations/firebase.ts.html +1 -1
  212. package/coverage/lcov-report/src/integrations/googlesheets.ts.html +10 -19
  213. package/coverage/lcov-report/src/integrations/index.html +11 -11
  214. package/coverage/lcov-report/src/integrations/index.ts.html +1 -1
  215. package/coverage/lcov-report/src/integrations/microsoftSqlServer.ts.html +1 -1
  216. package/coverage/lcov-report/src/integrations/mongodb.ts.html +1 -1
  217. package/coverage/lcov-report/src/integrations/mysql.ts.html +1 -1
  218. package/coverage/lcov-report/src/integrations/oracle.ts.html +1 -1
  219. package/coverage/lcov-report/src/integrations/postgres.ts.html +1 -1
  220. package/coverage/lcov-report/src/integrations/queries/index.html +1 -1
  221. package/coverage/lcov-report/src/integrations/queries/sql.ts.html +1 -1
  222. package/coverage/lcov-report/src/integrations/redis.ts.html +1 -1
  223. package/coverage/lcov-report/src/integrations/rest.ts.html +1 -1
  224. package/coverage/lcov-report/src/integrations/s3.ts.html +1 -1
  225. package/coverage/lcov-report/src/integrations/snowflake.ts.html +1 -1
  226. package/coverage/lcov-report/src/integrations/tests/TestConfiguration.js.html +1 -1
  227. package/coverage/lcov-report/src/integrations/tests/index.html +1 -1
  228. package/coverage/lcov-report/src/integrations/utils.ts.html +1 -1
  229. package/coverage/lcov-report/src/middleware/{appInfo.js.html → appInfo.ts.html} +24 -21
  230. package/coverage/lcov-report/src/middleware/authorized.ts.html +7 -7
  231. package/coverage/lcov-report/src/middleware/{builder.js.html → builder.ts.html} +36 -30
  232. package/coverage/lcov-report/src/middleware/{currentapp.js.html → currentapp.ts.html} +70 -61
  233. package/coverage/lcov-report/src/middleware/index.html +55 -55
  234. package/coverage/lcov-report/src/middleware/{joi-validator.js.html → joi-validator.ts.html} +18 -15
  235. package/coverage/lcov-report/src/middleware/{publicApi.js.html → publicApi.ts.html} +17 -17
  236. package/coverage/lcov-report/src/middleware/{resourceId.js.html → resourceId.ts.html} +33 -18
  237. package/coverage/lcov-report/src/middleware/{selfhost.js.html → selfhost.ts.html} +18 -12
  238. package/coverage/lcov-report/src/middleware/{utils.js.html → utils.ts.html} +12 -6
  239. package/coverage/lcov-report/src/migrations/functions/appUrls.ts.html +1 -1
  240. package/coverage/lcov-report/src/migrations/functions/backfill/app/automations.ts.html +1 -1
  241. package/coverage/lcov-report/src/migrations/functions/backfill/app/datasources.ts.html +1 -1
  242. package/coverage/lcov-report/src/migrations/functions/backfill/app/index.html +4 -4
  243. package/coverage/lcov-report/src/migrations/functions/backfill/app/layouts.ts.html +1 -1
  244. package/coverage/lcov-report/src/migrations/functions/backfill/app/queries.ts.html +1 -1
  245. package/coverage/lcov-report/src/migrations/functions/backfill/app/roles.ts.html +1 -1
  246. package/coverage/lcov-report/src/migrations/functions/backfill/app/screens.ts.html +1 -1
  247. package/coverage/lcov-report/src/migrations/functions/backfill/app/tables.ts.html +6 -15
  248. package/coverage/lcov-report/src/migrations/functions/backfill/app.ts.html +1 -1
  249. package/coverage/lcov-report/src/migrations/functions/backfill/global/configs.ts.html +1 -1
  250. package/coverage/lcov-report/src/migrations/functions/backfill/global/index.html +1 -1
  251. package/coverage/lcov-report/src/migrations/functions/backfill/global/quotas.ts.html +1 -1
  252. package/coverage/lcov-report/src/migrations/functions/backfill/global/users.ts.html +1 -1
  253. package/coverage/lcov-report/src/migrations/functions/backfill/global.ts.html +2 -2
  254. package/coverage/lcov-report/src/migrations/functions/backfill/index.html +1 -1
  255. package/coverage/lcov-report/src/migrations/functions/backfill/index.ts.html +1 -1
  256. package/coverage/lcov-report/src/migrations/functions/backfill/installation.ts.html +1 -1
  257. package/coverage/lcov-report/src/migrations/functions/index.html +1 -1
  258. package/coverage/lcov-report/src/migrations/functions/syncQuotas.ts.html +1 -1
  259. package/coverage/lcov-report/src/migrations/functions/usageQuotas/index.html +1 -1
  260. package/coverage/lcov-report/src/migrations/functions/usageQuotas/index.ts.html +1 -1
  261. package/coverage/lcov-report/src/migrations/functions/usageQuotas/syncApps.ts.html +1 -1
  262. package/coverage/lcov-report/src/migrations/functions/usageQuotas/syncPlugins.ts.html +1 -1
  263. package/coverage/lcov-report/src/migrations/functions/usageQuotas/syncRows.ts.html +3 -3
  264. package/coverage/lcov-report/src/migrations/functions/userEmailViewCasing.ts.html +1 -1
  265. package/coverage/lcov-report/src/migrations/index.html +1 -1
  266. package/coverage/lcov-report/src/migrations/index.ts.html +1 -1
  267. package/coverage/lcov-report/src/migrations/tests/helpers.ts.html +1 -1
  268. package/coverage/lcov-report/src/migrations/tests/index.html +1 -1
  269. package/coverage/lcov-report/src/migrations/tests/structures.ts.html +1 -1
  270. package/coverage/lcov-report/src/module.d.ts.html +1 -1
  271. package/coverage/lcov-report/src/sdk/app/automations/index.html +1 -1
  272. package/coverage/lcov-report/src/sdk/app/automations/index.ts.html +1 -1
  273. package/coverage/lcov-report/src/sdk/app/automations/webhook.ts.html +1 -1
  274. package/coverage/lcov-report/src/sdk/app/backups/constants.ts.html +1 -1
  275. package/coverage/lcov-report/src/sdk/app/backups/exports.ts.html +1 -1
  276. package/coverage/lcov-report/src/sdk/app/backups/imports.ts.html +7 -16
  277. package/coverage/lcov-report/src/sdk/app/backups/index.html +1 -1
  278. package/coverage/lcov-report/src/sdk/app/backups/index.ts.html +1 -1
  279. package/coverage/lcov-report/src/sdk/app/backups/statistics.ts.html +12 -39
  280. package/coverage/lcov-report/src/sdk/app/tables/index.html +1 -1
  281. package/coverage/lcov-report/src/sdk/app/tables/index.ts.html +8 -11
  282. package/coverage/lcov-report/src/sdk/index.html +1 -1
  283. package/coverage/lcov-report/src/sdk/index.ts.html +1 -1
  284. package/coverage/lcov-report/src/startup.ts.html +1 -1
  285. package/coverage/lcov-report/src/tests/utilities/TestConfiguration.js.html +24 -24
  286. package/coverage/lcov-report/src/tests/utilities/controllers.js.html +1 -1
  287. package/coverage/lcov-report/src/tests/utilities/index.html +19 -19
  288. package/coverage/lcov-report/src/tests/utilities/index.js.html +1 -1
  289. package/coverage/lcov-report/src/tests/utilities/structures.js.html +3 -3
  290. package/coverage/lcov-report/src/threads/automation.ts.html +2 -2
  291. package/coverage/lcov-report/src/threads/index.html +1 -1
  292. package/coverage/lcov-report/src/threads/index.ts.html +1 -1
  293. package/coverage/lcov-report/src/threads/query.ts.html +1 -1
  294. package/coverage/lcov-report/src/threads/utils.ts.html +1 -1
  295. package/coverage/lcov-report/src/utilities/budibaseDir.js.html +1 -1
  296. package/coverage/lcov-report/src/utilities/centralPath.js.html +1 -1
  297. package/coverage/lcov-report/src/utilities/csvParser.js.html +1 -1
  298. package/coverage/lcov-report/src/utilities/fileSystem/clientLibrary.js.html +1 -1
  299. package/coverage/lcov-report/src/utilities/fileSystem/index.html +1 -1
  300. package/coverage/lcov-report/src/utilities/fileSystem/index.js.html +1 -1
  301. package/coverage/lcov-report/src/utilities/fileSystem/processor.js.html +1 -1
  302. package/coverage/lcov-report/src/utilities/fileSystem/utilities.js.html +1 -1
  303. package/coverage/lcov-report/src/utilities/{global.js.html → global.ts.html} +100 -67
  304. package/coverage/lcov-report/src/utilities/index.html +16 -16
  305. package/coverage/lcov-report/src/utilities/index.js.html +1 -1
  306. package/coverage/lcov-report/src/utilities/plugins.js.html +1 -1
  307. package/coverage/lcov-report/src/utilities/queue/inMemoryQueue.js.html +1 -1
  308. package/coverage/lcov-report/src/utilities/queue/index.html +1 -1
  309. package/coverage/lcov-report/src/utilities/redis.js.html +1 -1
  310. package/coverage/lcov-report/src/utilities/routing/index.html +1 -1
  311. package/coverage/lcov-report/src/utilities/routing/index.js.html +1 -1
  312. package/coverage/lcov-report/src/utilities/rowProcessor/index.html +1 -1
  313. package/coverage/lcov-report/src/utilities/rowProcessor/index.js.html +1 -1
  314. package/coverage/lcov-report/src/utilities/rowProcessor/utils.js.html +1 -1
  315. package/coverage/lcov-report/src/utilities/scriptRunner.js.html +1 -1
  316. package/coverage/lcov-report/src/utilities/security.js.html +13 -13
  317. package/coverage/lcov-report/src/utilities/statusCodes.js.html +1 -1
  318. package/coverage/lcov-report/src/utilities/usageQuota/index.html +1 -1
  319. package/coverage/lcov-report/src/utilities/usageQuota/rows.js.html +1 -1
  320. package/coverage/lcov-report/src/utilities/usageQuota/usageQuoteReset.js.html +1 -1
  321. package/coverage/lcov-report/src/utilities/users.js.html +1 -1
  322. package/coverage/lcov-report/src/utilities/workerRequests.js.html +4 -4
  323. package/coverage/lcov-report/src/watch.ts.html +1 -1
  324. package/coverage/lcov-report/src/websocket.ts.html +1 -1
  325. package/coverage/lcov.info +2052 -2049
  326. package/dist/api/controllers/application.js +35 -43
  327. package/dist/api/controllers/deploy/index.js +13 -16
  328. package/dist/api/controllers/dev.js +96 -81
  329. package/dist/api/controllers/public/applications.js +17 -9
  330. package/dist/api/controllers/query/index.js +10 -13
  331. package/dist/api/controllers/row/internal.js +2 -2
  332. package/dist/api/routes/automation.js +3 -3
  333. package/dist/api/routes/datasource.js +4 -4
  334. package/dist/api/routes/public/index.js +9 -9
  335. package/dist/api/routes/query.js +4 -4
  336. package/dist/api/routes/row.js +11 -11
  337. package/dist/api/routes/static.js +3 -3
  338. package/dist/api/routes/table.js +2 -2
  339. package/dist/api/routes/user.js +9 -9
  340. package/dist/api/routes/utils/validators.js +4 -4
  341. package/dist/api/routes/view.js +2 -2
  342. package/dist/automations/tests/utilities/index.js +21 -12
  343. package/dist/automations/utils.js +9 -8
  344. package/dist/db/inMemoryView.js +2 -2
  345. package/dist/db/utils.js +145 -118
  346. package/dist/integrations/googlesheets.js +4 -6
  347. package/dist/middleware/appInfo.js +14 -9
  348. package/dist/middleware/authorized.js +5 -5
  349. package/dist/middleware/builder.js +41 -40
  350. package/dist/middleware/currentapp.js +39 -37
  351. package/dist/middleware/joi-validator.js +17 -10
  352. package/dist/middleware/publicApi.js +5 -6
  353. package/dist/middleware/resourceId.js +16 -9
  354. package/dist/middleware/selfhost.js +5 -4
  355. package/dist/middleware/utils.js +5 -2
  356. package/dist/migrations/functions/backfill/global.js +1 -1
  357. package/dist/migrations/functions/usageQuotas/syncRows.js +1 -1
  358. package/dist/package.json +6 -6
  359. package/dist/sdk/app/tables/index.js +4 -4
  360. package/dist/tests/utilities/TestConfiguration.js +9 -9
  361. package/dist/tests/utilities/structures.js +2 -2
  362. package/dist/tsconfig.build.tsbuildinfo +1 -1
  363. package/dist/utilities/global.js +87 -66
  364. package/dist/utilities/security.js +10 -10
  365. package/dist/utilities/workerRequests.js +3 -3
  366. package/jest.config.ts +1 -0
  367. package/package.json +7 -7
  368. package/scripts/localdomain.js +34 -6
  369. package/src/api/controllers/application.ts +34 -39
  370. package/src/api/controllers/auth.ts +3 -2
  371. package/src/api/controllers/deploy/index.ts +13 -25
  372. package/src/api/controllers/{dev.js → dev.ts} +31 -37
  373. package/src/api/controllers/public/applications.ts +15 -9
  374. package/src/api/controllers/query/index.ts +11 -14
  375. package/src/api/controllers/row/internal.js +2 -2
  376. package/src/api/routes/automation.js +4 -4
  377. package/src/api/routes/datasource.js +5 -5
  378. package/src/api/routes/public/index.ts +10 -10
  379. package/src/api/routes/public/tests/compare.spec.js +1 -1
  380. package/src/api/routes/query.js +5 -5
  381. package/src/api/routes/row.ts +12 -12
  382. package/src/api/routes/static.ts +5 -5
  383. package/src/api/routes/table.js +3 -3
  384. package/src/api/routes/tests/analytics.spec.js +1 -1
  385. package/src/api/routes/tests/query.spec.js +15 -10
  386. package/src/api/routes/tests/role.spec.js +5 -5
  387. package/src/api/routes/tests/static.spec.js +2 -2
  388. package/src/api/routes/tests/table.spec.js +38 -35
  389. package/src/api/routes/user.js +10 -10
  390. package/src/api/routes/utils/validators.js +5 -5
  391. package/src/api/routes/view.js +3 -3
  392. package/src/automations/tests/updateRow.spec.js +0 -1
  393. package/src/automations/tests/utilities/index.js +10 -4
  394. package/src/automations/utils.ts +9 -12
  395. package/src/db/inMemoryView.js +2 -2
  396. package/src/db/tests/linkController.spec.js +73 -57
  397. package/src/db/tests/linkTests.spec.js +17 -14
  398. package/src/db/{utils.js → utils.ts} +76 -92
  399. package/src/integrations/googlesheets.ts +4 -7
  400. package/src/middleware/appInfo.ts +20 -0
  401. package/src/middleware/authorized.ts +6 -6
  402. package/src/middleware/{builder.js → builder.ts} +17 -15
  403. package/src/middleware/{currentapp.js → currentapp.ts} +42 -39
  404. package/src/middleware/{joi-validator.js → joi-validator.ts} +9 -8
  405. package/src/middleware/publicApi.ts +21 -0
  406. package/src/middleware/{resourceId.js → resourceId.ts} +16 -11
  407. package/src/middleware/{selfhost.js → selfhost.ts} +4 -2
  408. package/src/middleware/tests/authorized.spec.js +5 -5
  409. package/src/middleware/tests/currentapp.spec.js +118 -63
  410. package/src/middleware/{utils.js → utils.ts} +3 -1
  411. package/src/migrations/functions/backfill/app/tables.ts +2 -5
  412. package/src/migrations/functions/backfill/global.ts +1 -1
  413. package/src/migrations/functions/usageQuotas/syncRows.ts +2 -2
  414. package/src/sdk/app/backups/imports.ts +4 -7
  415. package/src/sdk/app/backups/statistics.ts +9 -18
  416. package/src/sdk/app/tables/index.ts +6 -7
  417. package/src/tests/utilities/TestConfiguration.js +9 -9
  418. package/src/tests/utilities/structures.js +2 -2
  419. package/src/threads/automation.ts +1 -1
  420. package/src/utilities/global.ts +138 -0
  421. package/src/utilities/security.js +12 -12
  422. package/src/utilities/workerRequests.js +3 -3
  423. package/src/middleware/appInfo.js +0 -19
  424. package/src/middleware/publicApi.js +0 -21
  425. package/src/utilities/global.js +0 -127
@@ -1,16 +1,8 @@
1
+ require("../../db").init()
1
2
  mockAuthWithNoCookie()
2
3
  mockWorker()
3
4
  mockUserGroups()
4
5
 
5
- jest.mock("@budibase/backend-core/db", () => {
6
- const coreDb = jest.requireActual("@budibase/backend-core/db")
7
- coreDb.init()
8
- return {
9
- ...coreDb,
10
- dbExists: () => true,
11
- }
12
- })
13
-
14
6
  function mockWorker() {
15
7
  jest.mock("../../utilities/workerRequests", () => ({
16
8
  getGlobalSelf: () => {
@@ -43,42 +35,62 @@ function mockUserGroups() {
43
35
  function mockAuthWithNoCookie() {
44
36
  jest.resetModules()
45
37
  mockWorker()
46
- jest.mock("@budibase/backend-core/cache", () => ({
47
- user: {
48
- getUser: () => {
49
- return {
50
- _id: "us_uuid1",
51
- }
38
+ jest.mock("@budibase/backend-core", () => {
39
+ const core = jest.requireActual("@budibase/backend-core")
40
+ return {
41
+ ...core,
42
+ db: {
43
+ ...core.db,
44
+ dbExists: () => true,
52
45
  },
53
- },
54
- }))
55
- jest.mock("@budibase/backend-core/utils", () => ({
56
- getAppIdFromCtx: jest.fn(),
57
- setCookie: jest.fn(),
58
- getCookie: jest.fn(),
59
- }))
60
- jest.mock("@budibase/backend-core/constants", () => ({
61
- Cookies: {},
62
- }))
46
+ cache: {
47
+ user: {
48
+ getUser: async id => {
49
+ return {
50
+ _id: "us_uuid1",
51
+ }
52
+ },
53
+ },
54
+ },
55
+ utils: {
56
+ getAppIdFromCtx: jest.fn(),
57
+ setCookie: jest.fn(),
58
+ getCookie: jest.fn(),
59
+ },
60
+ }
61
+ })
63
62
  }
64
63
 
65
64
  function mockAuthWithCookie() {
66
65
  jest.resetModules()
67
66
  mockWorker()
68
- jest.mock("@budibase/backend-core/utils", () => ({
69
- getAppIdFromCtx: () => {
70
- return "app_test"
71
- },
72
- setCookie: jest.fn(),
73
- clearCookie: jest.fn(),
74
- getCookie: () => ({appId: "app_different", roleId: "PUBLIC"}),
75
- }))
76
- jest.mock("@budibase/backend-core/constants", () => ({
77
- Cookies: {
78
- Auth: "auth",
79
- CurrentApp: "currentapp",
80
- },
81
- }))
67
+ jest.mock("@budibase/backend-core", () => {
68
+ const core = jest.requireActual("@budibase/backend-core")
69
+ return {
70
+ ...core,
71
+ db: {
72
+ ...core.db,
73
+ dbExists: () => true,
74
+ },
75
+ utils: {
76
+ getAppIdFromCtx: () => {
77
+ return "app_test"
78
+ },
79
+ setCookie: jest.fn(),
80
+ clearCookie: jest.fn(),
81
+ getCookie: () => ({ appId: "app_different", roleId: "PUBLIC" }),
82
+ },
83
+ cache: {
84
+ user: {
85
+ getUser: async id => {
86
+ return {
87
+ _id: "us_uuid1",
88
+ }
89
+ },
90
+ },
91
+ },
92
+ }
93
+ })
82
94
  }
83
95
 
84
96
  class TestConfiguration {
@@ -88,7 +100,16 @@ class TestConfiguration {
88
100
 
89
101
  this.ctx = {
90
102
  next: this.next,
91
- throw: this.throw
103
+ throw: this.throw,
104
+ request: {
105
+ body: {},
106
+ headers: {},
107
+ },
108
+ headers: {},
109
+ path: "",
110
+ cookies: {
111
+ set: jest.fn(),
112
+ }
92
113
  }
93
114
  }
94
115
 
@@ -101,6 +122,8 @@ class TestConfiguration {
101
122
 
102
123
  executeMiddleware() {
103
124
  // import as late as possible for mocks
125
+ jest.resetModules()
126
+ require("../../db").init()
104
127
  const currentAppMiddleware = require("../currentapp")
105
128
  return currentAppMiddleware(this.ctx, this.next)
106
129
  }
@@ -138,11 +161,11 @@ describe("Current app middleware", () => {
138
161
  async function checkExpected(setCookie) {
139
162
  config.setUser()
140
163
  await config.executeMiddleware()
141
- let { setCookie: cookieFn } = require("@budibase/backend-core/utils")
164
+ let { utils } = require("@budibase/backend-core")
142
165
  if (setCookie) {
143
- expect(cookieFn).toHaveBeenCalled()
166
+ expect(utils.setCookie).toHaveBeenCalled()
144
167
  } else {
145
- expect(cookieFn).not.toHaveBeenCalled()
168
+ expect(utils.setCookie).not.toHaveBeenCalled()
146
169
  }
147
170
  expect(config.ctx.roleId).toEqual("PUBLIC")
148
171
  expect(config.ctx.user.role._id).toEqual("PUBLIC")
@@ -157,31 +180,63 @@ describe("Current app middleware", () => {
157
180
 
158
181
  it("should perform correct when no cookie exists", async () => {
159
182
  mockReset()
160
- jest.mock("@budibase/backend-core/utils", () => ({
161
- getAppIdFromCtx: () => {
162
- return "app_test"
163
- },
164
- setCookie: jest.fn(),
165
- getCookie: jest.fn(),
166
- }))
167
- jest.mock("@budibase/backend-core/constants", () => ({
168
- Cookies: {},
169
- }))
183
+ jest.mock("@budibase/backend-core", () => {
184
+ const core = jest.requireActual("@budibase/backend-core")
185
+ return {
186
+ ...core,
187
+ db: {
188
+ ...core.db,
189
+ dbExists: () => true,
190
+ },
191
+ utils: {
192
+ getAppIdFromCtx: () => {
193
+ return "app_test"
194
+ },
195
+ setCookie: jest.fn(),
196
+ getCookie: jest.fn(),
197
+ },
198
+ cache: {
199
+ user: {
200
+ getUser: async id => {
201
+ return {
202
+ _id: "us_uuid1",
203
+ }
204
+ },
205
+ },
206
+ },
207
+ }
208
+ })
170
209
  await checkExpected(true)
171
210
  })
172
211
 
173
212
  it("lastly check what occurs when cookie doesn't need updated", async () => {
174
213
  mockReset()
175
- jest.mock("@budibase/backend-core/utils", () => ({
176
- getAppIdFromCtx: () => {
177
- return "app_test"
178
- },
179
- setCookie: jest.fn(),
180
- getCookie: () => ({appId: "app_test", roleId: "PUBLIC"}),
181
- }))
182
- jest.mock("@budibase/backend-core/constants", () => ({
183
- Cookies: {},
184
- }))
214
+ jest.mock("@budibase/backend-core", () => {
215
+ const core = jest.requireActual("@budibase/backend-core")
216
+ return {
217
+ ...core,
218
+ db: {
219
+ ...core.db,
220
+ dbExists: () => true,
221
+ },
222
+ utils: {
223
+ getAppIdFromCtx: () => {
224
+ return "app_test"
225
+ },
226
+ setCookie: jest.fn(),
227
+ getCookie: () => ({ appId: "app_test", roleId: "PUBLIC" }),
228
+ },
229
+ cache: {
230
+ user: {
231
+ getUser: async id => {
232
+ return {
233
+ _id: "us_uuid1",
234
+ }
235
+ },
236
+ },
237
+ },
238
+ }
239
+ })
185
240
  await checkExpected(false)
186
241
  })
187
242
  })
@@ -1,7 +1,9 @@
1
+ import { BBContext } from "@budibase/types"
2
+
1
3
  const WEBHOOK_ENDPOINTS = new RegExp(
2
4
  ["webhooks/trigger", "webhooks/schema"].join("|")
3
5
  )
4
6
 
5
- exports.isWebhookEndpoint = ctx => {
7
+ export function isWebhookEndpoint(ctx: BBContext) {
6
8
  return WEBHOOK_ENDPOINTS.test(ctx.request.url)
7
9
  }
@@ -1,11 +1,8 @@
1
1
  import { events } from "@budibase/backend-core"
2
+ import { Database } from "@budibase/types"
2
3
  import sdk from "../../../../sdk"
3
- import PouchDB from "pouchdb"
4
4
 
5
- export const backfill = async (
6
- appDb: PouchDB.Database,
7
- timestamp: string | number
8
- ) => {
5
+ export const backfill = async (appDb: Database, timestamp: string | number) => {
9
6
  const tables = await sdk.tables.getAllInternalTables(appDb)
10
7
 
11
8
  for (const table of tables) {
@@ -149,7 +149,7 @@ export const run = async (db: any) => {
149
149
  }
150
150
 
151
151
  try {
152
- const allApps: App[] = await dbUtils.getAllApps({ dev: true })
152
+ const allApps = (await dbUtils.getAllApps({ dev: true })) as App[]
153
153
  totals.apps = allApps.length
154
154
 
155
155
  totals.usage = await quotas.backfill(allApps)
@@ -2,11 +2,11 @@ import { getTenantId } from "@budibase/backend-core/tenancy"
2
2
  import { getAllApps } from "@budibase/backend-core/db"
3
3
  import { getUniqueRows } from "../../../utilities/usageQuota/rows"
4
4
  import { quotas } from "@budibase/pro"
5
- import { StaticQuotaName, QuotaUsageType } from "@budibase/types"
5
+ import { StaticQuotaName, QuotaUsageType, App } from "@budibase/types"
6
6
 
7
7
  export const run = async () => {
8
8
  // get all rows in all apps
9
- const allApps = await getAllApps({ all: true })
9
+ const allApps = (await getAllApps({ all: true })) as App[]
10
10
  const appIds = allApps ? allApps.map((app: { appId: any }) => app.appId) : []
11
11
  const { appRows } = await getUniqueRows(appIds)
12
12
 
@@ -1,4 +1,5 @@
1
1
  import { db as dbCore } from "@budibase/backend-core"
2
+ import { Database } from "@budibase/types"
2
3
  import { getAutomationParams, TABLE_ROW_PREFIX } from "../../../db/utils"
3
4
  import { budibaseTempDir } from "../../../utilities/budibaseDir"
4
5
  import { DB_EXPORT_FILE, GLOBAL_DB_EXPORT_FILE } from "./constants"
@@ -17,7 +18,6 @@ import {
17
18
  CouchFindOptions,
18
19
  RowAttachment,
19
20
  } from "@budibase/types"
20
- import PouchDB from "pouchdb"
21
21
  const uuid = require("uuid/v4")
22
22
  const tar = require("tar")
23
23
 
@@ -29,10 +29,7 @@ type TemplateType = {
29
29
  key?: string
30
30
  }
31
31
 
32
- async function updateAttachmentColumns(
33
- prodAppId: string,
34
- db: PouchDB.Database
35
- ) {
32
+ async function updateAttachmentColumns(prodAppId: string, db: Database) {
36
33
  // iterate through attachment documents and update them
37
34
  const tables = await sdk.tables.getAllInternalTables(db)
38
35
  for (let table of tables) {
@@ -86,7 +83,7 @@ async function updateAttachmentColumns(
86
83
  }
87
84
  }
88
85
 
89
- async function updateAutomations(prodAppId: string, db: PouchDB.Database) {
86
+ async function updateAutomations(prodAppId: string, db: Database) {
90
87
  const automations = (
91
88
  await db.allDocs(
92
89
  getAutomationParams(null, {
@@ -154,7 +151,7 @@ export function getListOfAppsInMulti(tmpPath: string) {
154
151
 
155
152
  export async function importApp(
156
153
  appId: string,
157
- db: PouchDB.Database,
154
+ db: Database,
158
155
  template: TemplateType
159
156
  ) {
160
157
  let prodAppId = dbCore.getProdAppID(appId)
@@ -1,13 +1,13 @@
1
1
  import { context, db as dbCore } from "@budibase/backend-core"
2
+ import { Database } from "@budibase/types"
2
3
  import {
3
4
  getDatasourceParams,
4
5
  getTableParams,
5
6
  getAutomationParams,
6
7
  getScreenParams,
7
8
  } from "../../../db/utils"
8
- import PouchDB from "pouchdb"
9
9
 
10
- async function runInContext(appId: string, cb: any, db?: PouchDB.Database) {
10
+ async function runInContext(appId: string, cb: any, db?: Database) {
11
11
  if (db) {
12
12
  return cb(db)
13
13
  } else {
@@ -19,13 +19,10 @@ async function runInContext(appId: string, cb: any, db?: PouchDB.Database) {
19
19
  }
20
20
  }
21
21
 
22
- export async function calculateDatasourceCount(
23
- appId: string,
24
- db?: PouchDB.Database
25
- ) {
22
+ export async function calculateDatasourceCount(appId: string, db?: Database) {
26
23
  return runInContext(
27
24
  appId,
28
- async (db: PouchDB.Database) => {
25
+ async (db: Database) => {
29
26
  const datasourceList = await db.allDocs(getDatasourceParams())
30
27
  const tableList = await db.allDocs(getTableParams())
31
28
  return datasourceList.rows.length + tableList.rows.length
@@ -34,13 +31,10 @@ export async function calculateDatasourceCount(
34
31
  )
35
32
  }
36
33
 
37
- export async function calculateAutomationCount(
38
- appId: string,
39
- db?: PouchDB.Database
40
- ) {
34
+ export async function calculateAutomationCount(appId: string, db?: Database) {
41
35
  return runInContext(
42
36
  appId,
43
- async (db: PouchDB.Database) => {
37
+ async (db: Database) => {
44
38
  const automationList = await db.allDocs(getAutomationParams())
45
39
  return automationList.rows.length
46
40
  },
@@ -48,13 +42,10 @@ export async function calculateAutomationCount(
48
42
  )
49
43
  }
50
44
 
51
- export async function calculateScreenCount(
52
- appId: string,
53
- db?: PouchDB.Database
54
- ) {
45
+ export async function calculateScreenCount(appId: string, db?: Database) {
55
46
  return runInContext(
56
47
  appId,
57
- async (db: PouchDB.Database) => {
48
+ async (db: Database) => {
58
49
  const screenList = await db.allDocs(getScreenParams())
59
50
  return screenList.rows.length
60
51
  },
@@ -63,7 +54,7 @@ export async function calculateScreenCount(
63
54
  }
64
55
 
65
56
  export async function calculateBackupStats(appId: string) {
66
- return runInContext(appId, async (db: PouchDB.Database) => {
57
+ return runInContext(appId, async (db: Database) => {
67
58
  const promises = []
68
59
  promises.push(calculateDatasourceCount(appId, db))
69
60
  promises.push(calculateAutomationCount(appId, db))
@@ -1,16 +1,15 @@
1
- import { getAppDB } from "@budibase/backend-core/context"
1
+ import { context } from "@budibase/backend-core"
2
2
  import { BudibaseInternalDB, getTableParams } from "../../../db/utils"
3
3
  import {
4
4
  breakExternalTableId,
5
5
  isExternalTable,
6
6
  isSQL,
7
7
  } from "../../../integrations/utils"
8
- import { Table } from "@budibase/types"
9
- import PouchDB from "pouchdb"
8
+ import { Table, Database } from "@budibase/types"
10
9
 
11
- async function getAllInternalTables(db?: PouchDB.Database): Promise<Table[]> {
10
+ async function getAllInternalTables(db?: Database): Promise<Table[]> {
12
11
  if (!db) {
13
- db = getAppDB() as PouchDB.Database
12
+ db = context.getAppDB()
14
13
  }
15
14
  const internalTables = await db.allDocs(
16
15
  getTableParams(null, {
@@ -25,7 +24,7 @@ async function getAllInternalTables(db?: PouchDB.Database): Promise<Table[]> {
25
24
  }
26
25
 
27
26
  async function getAllExternalTables(datasourceId: any): Promise<Table[]> {
28
- const db = getAppDB()
27
+ const db = context.getAppDB()
29
28
  const datasource = await db.get(datasourceId)
30
29
  if (!datasource || !datasource.entities) {
31
30
  throw "Datasource is not configured fully."
@@ -42,7 +41,7 @@ async function getExternalTable(
42
41
  }
43
42
 
44
43
  async function getTable(tableId: any): Promise<Table> {
45
- const db = getAppDB()
44
+ const db = context.getAppDB()
46
45
  if (isExternalTable(tableId)) {
47
46
  let { datasourceId, tableName } = breakExternalTableId(tableId)
48
47
  const datasource = await db.get(datasourceId)
@@ -16,7 +16,7 @@ const {
16
16
  const controllers = require("./controllers")
17
17
  const supertest = require("supertest")
18
18
  const { cleanup } = require("../../utilities/fileSystem")
19
- const { Cookies, Headers } = require("@budibase/backend-core/constants")
19
+ const { Cookie, Header } = require("@budibase/backend-core/constants")
20
20
  const { jwt } = require("@budibase/backend-core/auth")
21
21
  const { doInTenant, doWithGlobalDB } = require("@budibase/backend-core/tenancy")
22
22
  const { createASession } = require("@budibase/backend-core/sessions")
@@ -256,10 +256,10 @@ class TestConfiguration {
256
256
  return {
257
257
  Accept: "application/json",
258
258
  Cookie: [
259
- `${Cookies.Auth}=${authToken}`,
260
- `${Cookies.CurrentApp}=${appToken}`,
259
+ `${Cookie.Auth}=${authToken}`,
260
+ `${Cookie.CurrentApp}=${appToken}`,
261
261
  ],
262
- [Headers.APP_ID]: appId,
262
+ [Header.APP_ID]: appId,
263
263
  }
264
264
  })
265
265
  }
@@ -279,14 +279,14 @@ class TestConfiguration {
279
279
  const headers = {
280
280
  Accept: "application/json",
281
281
  Cookie: [
282
- `${Cookies.Auth}=${authToken}`,
283
- `${Cookies.CurrentApp}=${appToken}`,
282
+ `${Cookie.Auth}=${authToken}`,
283
+ `${Cookie.CurrentApp}=${appToken}`,
284
284
  ],
285
- [Headers.CSRF_TOKEN]: CSRF_TOKEN,
285
+ [Header.CSRF_TOKEN]: CSRF_TOKEN,
286
286
  ...extras,
287
287
  }
288
288
  if (this.appId) {
289
- headers[Headers.APP_ID] = this.appId
289
+ headers[Header.APP_ID] = this.appId
290
290
  }
291
291
  return headers
292
292
  }
@@ -298,7 +298,7 @@ class TestConfiguration {
298
298
  Accept: "application/json",
299
299
  }
300
300
  if (appId) {
301
- headers[Headers.APP_ID] = appId
301
+ headers[Header.APP_ID] = appId
302
302
  }
303
303
  return headers
304
304
  }
@@ -1,5 +1,5 @@
1
1
  const { BUILTIN_ROLE_IDS } = require("@budibase/backend-core/roles")
2
- const { BUILTIN_PERMISSION_IDS } = require("@budibase/backend-core/permissions")
2
+ const { BuiltinPermissionID } = require("@budibase/backend-core/permissions")
3
3
  const { createHomeScreen } = require("../../constants/screens")
4
4
  const { EMPTY_LAYOUT } = require("../../constants/layouts")
5
5
  const { cloneDeep } = require("lodash/fp")
@@ -135,7 +135,7 @@ exports.basicRole = () => {
135
135
  return {
136
136
  name: "NewRole",
137
137
  inherits: BUILTIN_ROLE_IDS.BASIC,
138
- permissionId: BUILTIN_PERMISSION_IDS.READ_ONLY,
138
+ permissionId: BuiltinPermissionID.READ_ONLY,
139
139
  }
140
140
  }
141
141
 
@@ -120,7 +120,7 @@ class Orchestrator {
120
120
  }
121
121
 
122
122
  async getMetadata(): Promise<AutomationMetadata> {
123
- const metadataId = generateAutomationMetadataID(this._automation._id)
123
+ const metadataId = generateAutomationMetadataID(this._automation._id!)
124
124
  const db = getAppDB()
125
125
  let metadata: AutomationMetadata
126
126
  try {
@@ -0,0 +1,138 @@
1
+ import { getMultiIDParams, getGlobalIDFromUserMetadataID } from "../db/utils"
2
+ import {
3
+ roles,
4
+ db as dbCore,
5
+ cache,
6
+ tenancy,
7
+ context,
8
+ } from "@budibase/backend-core"
9
+ import env from "../environment"
10
+ import { groups } from "@budibase/pro"
11
+ import { BBContext, ContextUser, User } from "@budibase/types"
12
+
13
+ export function updateAppRole(
14
+ user: ContextUser,
15
+ { appId }: { appId?: string } = {}
16
+ ) {
17
+ appId = appId || context.getAppId()
18
+
19
+ if (!user || !user.roles) {
20
+ return user
21
+ }
22
+ // if in an multi-tenancy environment make sure roles are never updated
23
+ if (env.MULTI_TENANCY && appId && !tenancy.isUserInAppTenant(appId, user)) {
24
+ delete user.builder
25
+ delete user.admin
26
+ user.roleId = roles.BUILTIN_ROLE_IDS.PUBLIC
27
+ return user
28
+ }
29
+ // always use the deployed app
30
+ if (appId) {
31
+ user.roleId = user.roles[dbCore.getProdAppID(appId)]
32
+ }
33
+ // if a role wasn't found then either set as admin (builder) or public (everyone else)
34
+ if (!user.roleId && user.builder && user.builder.global) {
35
+ user.roleId = roles.BUILTIN_ROLE_IDS.ADMIN
36
+ } else if (!user.roleId && !user?.userGroups?.length) {
37
+ user.roleId = roles.BUILTIN_ROLE_IDS.PUBLIC
38
+ } else if (user?.userGroups?.length) {
39
+ user.roleId = undefined
40
+ }
41
+
42
+ delete user.roles
43
+ return user
44
+ }
45
+
46
+ async function checkGroupRoles(
47
+ user: ContextUser,
48
+ { appId }: { appId?: string } = {}
49
+ ) {
50
+ if (user.roleId && user.roleId !== roles.BUILTIN_ROLE_IDS.PUBLIC) {
51
+ return user
52
+ }
53
+ if (appId) {
54
+ user.roleId = await groups.getGroupRoleId(user as User, appId)
55
+ }
56
+ return user
57
+ }
58
+
59
+ async function processUser(
60
+ user: ContextUser,
61
+ { appId }: { appId?: string } = {}
62
+ ) {
63
+ if (user) {
64
+ delete user.password
65
+ }
66
+ user = await updateAppRole(user, { appId })
67
+ if (!user.roleId && user?.userGroups?.length) {
68
+ user = await checkGroupRoles(user, { appId })
69
+ }
70
+
71
+ return user
72
+ }
73
+
74
+ export async function getCachedSelf(ctx: BBContext, appId: string) {
75
+ // this has to be tenant aware, can't depend on the context to find it out
76
+ // running some middlewares before the tenancy causes context to break
77
+ const user = await cache.user.getUser(ctx.user?._id!)
78
+ return processUser(user, { appId })
79
+ }
80
+
81
+ export async function getRawGlobalUser(userId: string) {
82
+ const db = tenancy.getGlobalDB()
83
+ return db.get(getGlobalIDFromUserMetadataID(userId))
84
+ }
85
+
86
+ export async function getGlobalUser(userId: string) {
87
+ const appId = context.getAppId()
88
+ let user = await getRawGlobalUser(userId)
89
+ return processUser(user, { appId })
90
+ }
91
+
92
+ export async function getGlobalUsers(users?: ContextUser[]) {
93
+ const appId = context.getAppId()
94
+ const db = tenancy.getGlobalDB()
95
+ let globalUsers
96
+ if (users) {
97
+ const globalIds = users.map(user =>
98
+ getGlobalIDFromUserMetadataID(user._id!)
99
+ )
100
+ globalUsers = (await db.allDocs(getMultiIDParams(globalIds))).rows.map(
101
+ row => row.doc
102
+ )
103
+ } else {
104
+ globalUsers = (
105
+ await db.allDocs(
106
+ dbCore.getGlobalUserParams(null, {
107
+ include_docs: true,
108
+ })
109
+ )
110
+ ).rows.map(row => row.doc)
111
+ }
112
+ globalUsers = globalUsers
113
+ .filter(user => user != null)
114
+ .map(user => {
115
+ delete user.password
116
+ delete user.forceResetPassword
117
+ return user
118
+ })
119
+ if (!appId) {
120
+ return globalUsers
121
+ }
122
+
123
+ return globalUsers.map(user => updateAppRole(user))
124
+ }
125
+
126
+ export async function getGlobalUsersFromMetadata(users: ContextUser[]) {
127
+ const globalUsers = await getGlobalUsers(users)
128
+ return users.map(user => {
129
+ const globalUser = globalUsers.find(
130
+ globalUser => globalUser && user._id?.includes(globalUser._id)
131
+ )
132
+ return {
133
+ ...globalUser,
134
+ // doing user second overwrites the id and rev (always metadata)
135
+ ...user,
136
+ }
137
+ })
138
+ }