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

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.dba40c82.js} +2 -2
  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
@@ -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
+ }
@@ -1,6 +1,6 @@
1
1
  const {
2
- PermissionLevels,
3
- PermissionTypes,
2
+ PermissionLevel,
3
+ PermissionType,
4
4
  getBuiltinPermissionByID,
5
5
  isPermissionLevelHigherThanRead,
6
6
  } = require("@budibase/backend-core/permissions")
@@ -11,9 +11,9 @@ const {
11
11
  const { DocumentType } = require("../db/utils")
12
12
 
13
13
  const CURRENTLY_SUPPORTED_LEVELS = [
14
- PermissionLevels.WRITE,
15
- PermissionLevels.READ,
16
- PermissionLevels.EXECUTE,
14
+ PermissionLevel.WRITE,
15
+ PermissionLevel.READ,
16
+ PermissionLevel.EXECUTE,
17
17
  ]
18
18
 
19
19
  exports.getPermissionType = resourceId => {
@@ -23,17 +23,17 @@ exports.getPermissionType = resourceId => {
23
23
  switch (docType) {
24
24
  case DocumentType.TABLE:
25
25
  case DocumentType.ROW:
26
- return PermissionTypes.TABLE
26
+ return PermissionType.TABLE
27
27
  case DocumentType.AUTOMATION:
28
- return PermissionTypes.AUTOMATION
28
+ return PermissionType.AUTOMATION
29
29
  case DocumentType.WEBHOOK:
30
- return PermissionTypes.WEBHOOK
30
+ return PermissionType.WEBHOOK
31
31
  case DocumentType.QUERY:
32
32
  case DocumentType.DATASOURCE:
33
- return PermissionTypes.QUERY
33
+ return PermissionType.QUERY
34
34
  default:
35
35
  // views don't have an ID, will end up here
36
- return PermissionTypes.VIEW
36
+ return PermissionType.VIEW
37
37
  }
38
38
  }
39
39
 
@@ -58,8 +58,8 @@ exports.getBasePermissions = resourceId => {
58
58
  const level = typedPermission.level
59
59
  permissions[level] = lowerBuiltinRoleID(permissions[level], roleId)
60
60
  if (isPermissionLevelHigherThanRead(level)) {
61
- permissions[PermissionLevels.READ] = lowerBuiltinRoleID(
62
- permissions[PermissionLevels.READ],
61
+ permissions[PermissionLevel.READ] = lowerBuiltinRoleID(
62
+ permissions[PermissionLevel.READ],
63
63
  roleId
64
64
  )
65
65
  }
@@ -3,7 +3,7 @@ const env = require("../environment")
3
3
  const { checkSlashesInUrl } = require("./index")
4
4
  const { getProdAppID } = require("@budibase/backend-core/db")
5
5
  const { updateAppRole } = require("./global")
6
- const { Headers } = require("@budibase/backend-core/constants")
6
+ const { Header } = require("@budibase/backend-core/constants")
7
7
  const { getTenantId, isTenantIdSet } = require("@budibase/backend-core/tenancy")
8
8
 
9
9
  function request(ctx, request) {
@@ -11,9 +11,9 @@ function request(ctx, request) {
11
11
  request.headers = {}
12
12
  }
13
13
  if (!ctx) {
14
- request.headers[Headers.API_KEY] = env.INTERNAL_API_KEY
14
+ request.headers[Header.API_KEY] = env.INTERNAL_API_KEY
15
15
  if (isTenantIdSet()) {
16
- request.headers[Headers.TENANT_ID] = getTenantId()
16
+ request.headers[Header.TENANT_ID] = getTenantId()
17
17
  }
18
18
  }
19
19
  if (request.body && Object.keys(request.body).length > 0) {
@@ -1,19 +0,0 @@
1
- const { isDevAppID, isProdAppID } = require("../db/utils")
2
-
3
- exports.AppType = {
4
- DEV: "dev",
5
- PROD: "prod",
6
- }
7
-
8
- exports.middleware =
9
- ({ appType } = {}) =>
10
- (ctx, next) => {
11
- const appId = ctx.appId
12
- if (appType === exports.AppType.DEV && appId && !isDevAppID(appId)) {
13
- ctx.throw(400, "Only apps in development support this endpoint")
14
- }
15
- if (appType === exports.AppType.PROD && appId && !isProdAppID(appId)) {
16
- ctx.throw(400, "Only apps in production support this endpoint")
17
- }
18
- return next()
19
- }
@@ -1,21 +0,0 @@
1
- const { Headers } = require("@budibase/backend-core/constants")
2
- const { getAppIdFromCtx } = require("@budibase/backend-core/utils")
3
-
4
- module.exports = function ({ requiresAppId } = {}) {
5
- return async (ctx, next) => {
6
- const appId = await getAppIdFromCtx(ctx)
7
- if (requiresAppId && !appId) {
8
- ctx.throw(
9
- 400,
10
- `Invalid app ID provided, please check the ${Headers.APP_ID} header.`
11
- )
12
- }
13
- if (!ctx.headers[Headers.API_KEY]) {
14
- ctx.throw(
15
- 400,
16
- `Invalid API key provided, please check the ${Headers.API_KEY} header.`
17
- )
18
- }
19
- return next()
20
- }
21
- }
@@ -1,127 +0,0 @@
1
- const {
2
- getMultiIDParams,
3
- getGlobalIDFromUserMetadataID,
4
- } = require("../db/utils")
5
- const { BUILTIN_ROLE_IDS } = require("@budibase/backend-core/roles")
6
- const { getProdAppID } = require("@budibase/backend-core/db")
7
- const { getGlobalUserParams } = require("@budibase/backend-core/db")
8
- const { user: userCache } = require("@budibase/backend-core/cache")
9
- const {
10
- getGlobalDB,
11
- isUserInAppTenant,
12
- } = require("@budibase/backend-core/tenancy")
13
- const env = require("../environment")
14
- const { getAppId } = require("@budibase/backend-core/context")
15
- const { groups } = require("@budibase/pro")
16
-
17
- exports.updateAppRole = (user, { appId } = {}) => {
18
- appId = appId || getAppId()
19
-
20
- if (!user || !user.roles) {
21
- return user
22
- }
23
- // if in an multi-tenancy environment make sure roles are never updated
24
- if (env.MULTI_TENANCY && !isUserInAppTenant(appId, user)) {
25
- delete user.builder
26
- delete user.admin
27
- user.roleId = BUILTIN_ROLE_IDS.PUBLIC
28
- return user
29
- }
30
- // always use the deployed app
31
- user.roleId = user.roles[getProdAppID(appId)]
32
- // if a role wasn't found then either set as admin (builder) or public (everyone else)
33
- if (!user.roleId && user.builder && user.builder.global) {
34
- user.roleId = BUILTIN_ROLE_IDS.ADMIN
35
- } else if (!user.roleId && !user?.userGroups?.length) {
36
- user.roleId = BUILTIN_ROLE_IDS.PUBLIC
37
- } else if (user?.userGroups?.length) {
38
- user.roleId = null
39
- }
40
-
41
- delete user.roles
42
- return user
43
- }
44
-
45
- async function checkGroupRoles(user, { appId } = {}) {
46
- if (user.roleId && user.roleId !== BUILTIN_ROLE_IDS.PUBLIC) {
47
- return user
48
- }
49
- user.roleId = await groups.getGroupRoleId(user, appId)
50
- return user
51
- }
52
-
53
- async function processUser(user, { appId } = {}) {
54
- if (user) {
55
- delete user.password
56
- }
57
- user = await exports.updateAppRole(user, { appId })
58
- if (!user.roleId && user?.userGroups?.length) {
59
- user = await checkGroupRoles(user, { appId })
60
- }
61
-
62
- return user
63
- }
64
-
65
- exports.getCachedSelf = async (ctx, appId) => {
66
- // this has to be tenant aware, can't depend on the context to find it out
67
- // running some middlewares before the tenancy causes context to break
68
- const user = await userCache.getUser(ctx.user._id)
69
- return processUser(user, { appId })
70
- }
71
-
72
- exports.getRawGlobalUser = async userId => {
73
- const db = getGlobalDB()
74
- return db.get(getGlobalIDFromUserMetadataID(userId))
75
- }
76
-
77
- exports.getGlobalUser = async userId => {
78
- const appId = getAppId()
79
- let user = await exports.getRawGlobalUser(userId)
80
- return processUser(user, { appId })
81
- }
82
-
83
- exports.getGlobalUsers = async (users = null) => {
84
- const appId = getAppId()
85
- const db = getGlobalDB()
86
- let globalUsers
87
- if (users) {
88
- const globalIds = users.map(user => getGlobalIDFromUserMetadataID(user._id))
89
- globalUsers = (await db.allDocs(getMultiIDParams(globalIds))).rows.map(
90
- row => row.doc
91
- )
92
- } else {
93
- globalUsers = (
94
- await db.allDocs(
95
- getGlobalUserParams(null, {
96
- include_docs: true,
97
- })
98
- )
99
- ).rows.map(row => row.doc)
100
- }
101
- globalUsers = globalUsers
102
- .filter(user => user != null)
103
- .map(user => {
104
- delete user.password
105
- delete user.forceResetPassword
106
- return user
107
- })
108
- if (!appId) {
109
- return globalUsers
110
- }
111
-
112
- return globalUsers.map(user => exports.updateAppRole(user))
113
- }
114
-
115
- exports.getGlobalUsersFromMetadata = async users => {
116
- const globalUsers = await exports.getGlobalUsers(users)
117
- return users.map(user => {
118
- const globalUser = globalUsers.find(
119
- globalUser => globalUser && user._id.includes(globalUser._id)
120
- )
121
- return {
122
- ...globalUser,
123
- // doing user second overwrites the id and rev (always metadata)
124
- ...user,
125
- }
126
- })
127
- }