@budibase/server 2.1.30 → 2.1.32-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (439) hide show
  1. package/__mocks__/aws-sdk.ts +14 -0
  2. package/__mocks__/node-fetch.ts +5 -1
  3. package/builder/assets/{index.bdbc5a13.js → index.3a6f5b99.js} +270 -270
  4. package/builder/assets/{index.534f6c29.css → index.7176fd99.css} +1 -1
  5. package/builder/index.html +2 -2
  6. package/coverage/clover.xml +9664 -2787
  7. package/coverage/coverage-final.json +162 -19
  8. package/coverage/lcov-report/index.html +621 -126
  9. package/coverage/lcov-report/src/api/controllers/analytics.ts.html +190 -0
  10. package/coverage/lcov-report/{api → src/api}/controllers/apikeys.js.html +10 -10
  11. package/coverage/lcov-report/src/api/controllers/application.ts.html +1981 -0
  12. package/coverage/lcov-report/src/api/controllers/auth.ts.html +301 -0
  13. package/coverage/lcov-report/{api → src/api}/controllers/automation.js.html +10 -10
  14. package/coverage/lcov-report/src/api/controllers/backup.ts.html +148 -0
  15. package/coverage/lcov-report/{api → src/api}/controllers/cloud.js.html +10 -10
  16. package/coverage/lcov-report/src/api/controllers/component.ts.html +256 -0
  17. package/coverage/lcov-report/{api → src/api}/controllers/datasource.js.html +10 -10
  18. package/coverage/lcov-report/src/api/controllers/deploy/Deployment.js.html +250 -0
  19. package/coverage/lcov-report/src/api/controllers/deploy/index.html +131 -0
  20. package/coverage/lcov-report/src/api/controllers/deploy/index.ts.html +730 -0
  21. package/coverage/lcov-report/{api/controllers/dev.js.html → src/api/controllers/dev.ts.html} +53 -71
  22. package/coverage/lcov-report/{api → src/api}/controllers/index.html +134 -29
  23. package/coverage/lcov-report/{api → src/api}/controllers/integration.js.html +10 -10
  24. package/coverage/lcov-report/{api → src/api}/controllers/layout.js.html +10 -10
  25. package/coverage/lcov-report/{api → src/api}/controllers/metadata.js.html +10 -10
  26. package/coverage/lcov-report/{api → src/api}/controllers/migrations.js.html +10 -10
  27. package/coverage/lcov-report/{api → src/api}/controllers/permission.js.html +10 -10
  28. package/coverage/lcov-report/src/api/controllers/plugin/file.ts.html +130 -0
  29. package/coverage/lcov-report/src/api/controllers/plugin/github.ts.html +310 -0
  30. package/coverage/lcov-report/src/api/controllers/plugin/index.html +206 -0
  31. package/coverage/lcov-report/src/api/controllers/plugin/index.ts.html +487 -0
  32. package/coverage/lcov-report/src/api/controllers/plugin/npm.ts.html +253 -0
  33. package/coverage/lcov-report/src/api/controllers/plugin/uploaders.ts.html +97 -0
  34. package/coverage/lcov-report/src/api/controllers/plugin/url.ts.html +121 -0
  35. package/coverage/lcov-report/src/api/controllers/plugin/utils.ts.html +142 -0
  36. package/coverage/lcov-report/src/api/controllers/public/applications.ts.html +334 -0
  37. package/coverage/lcov-report/src/api/controllers/public/index.html +191 -0
  38. package/coverage/lcov-report/src/api/controllers/public/mapping/applications.ts.html +181 -0
  39. package/coverage/lcov-report/src/api/controllers/public/mapping/index.html +191 -0
  40. package/coverage/lcov-report/src/api/controllers/public/mapping/index.ts.html +124 -0
  41. package/coverage/lcov-report/src/api/controllers/public/mapping/queries.ts.html +202 -0
  42. package/coverage/lcov-report/src/api/controllers/public/mapping/rows.ts.html +178 -0
  43. package/coverage/lcov-report/src/api/controllers/public/mapping/tables.ts.html +163 -0
  44. package/coverage/lcov-report/src/api/controllers/public/mapping/users.ts.html +181 -0
  45. package/coverage/lcov-report/src/api/controllers/public/queries.ts.html +145 -0
  46. package/coverage/lcov-report/src/api/controllers/public/rows.ts.html +328 -0
  47. package/coverage/lcov-report/src/api/controllers/public/tables.ts.html +253 -0
  48. package/coverage/lcov-report/src/api/controllers/public/users.ts.html +268 -0
  49. package/coverage/lcov-report/src/api/controllers/public/utils.ts.html +220 -0
  50. package/coverage/lcov-report/src/api/controllers/query/import/index.html +116 -0
  51. package/coverage/lcov-report/src/api/controllers/query/import/index.ts.html +376 -0
  52. package/coverage/lcov-report/src/api/controllers/query/import/sources/base/index.html +131 -0
  53. package/coverage/lcov-report/src/api/controllers/query/import/sources/base/index.ts.html +379 -0
  54. package/coverage/lcov-report/src/api/controllers/query/import/sources/base/openapi.ts.html +157 -0
  55. package/coverage/lcov-report/src/api/controllers/query/import/sources/curl.ts.html +403 -0
  56. package/coverage/lcov-report/src/api/controllers/query/import/sources/index.html +146 -0
  57. package/coverage/lcov-report/src/api/controllers/query/import/sources/openapi2.ts.html +586 -0
  58. package/coverage/lcov-report/src/api/controllers/query/import/sources/openapi3.ts.html +712 -0
  59. package/coverage/lcov-report/src/api/controllers/query/index.html +131 -0
  60. package/coverage/lcov-report/src/api/controllers/query/index.ts.html +976 -0
  61. package/coverage/lcov-report/{api → src/api}/controllers/query/validation.js.html +10 -10
  62. package/coverage/lcov-report/{api → src/api}/controllers/role.js.html +10 -10
  63. package/coverage/lcov-report/{api → src/api}/controllers/routing.js.html +10 -10
  64. package/coverage/lcov-report/src/api/controllers/row/ExternalRequest.ts.html +2332 -0
  65. package/coverage/lcov-report/{api → src/api}/controllers/row/external.js.html +10 -10
  66. package/coverage/lcov-report/{api → src/api}/controllers/row/index.html +48 -18
  67. package/coverage/lcov-report/src/api/controllers/row/index.ts.html +541 -0
  68. package/coverage/lcov-report/{api → src/api}/controllers/row/internal.js.html +12 -12
  69. package/coverage/lcov-report/{api → src/api}/controllers/row/internalSearch.js.html +10 -10
  70. package/coverage/lcov-report/{api → src/api}/controllers/row/staticFormula.js.html +10 -10
  71. package/coverage/lcov-report/{api → src/api}/controllers/row/utils.js.html +10 -10
  72. package/coverage/lcov-report/src/api/controllers/screen.ts.html +451 -0
  73. package/coverage/lcov-report/{api → src/api}/controllers/script.js.html +10 -10
  74. package/coverage/lcov-report/src/api/controllers/static/index.html +116 -0
  75. package/coverage/lcov-report/src/api/controllers/static/index.ts.html +700 -0
  76. package/coverage/lcov-report/{api → src/api}/controllers/table/bulkFormula.js.html +10 -10
  77. package/coverage/lcov-report/{api → src/api}/controllers/table/external.js.html +10 -10
  78. package/coverage/lcov-report/{api → src/api}/controllers/table/index.html +49 -19
  79. package/coverage/lcov-report/{api → src/api}/controllers/table/index.js.html +10 -10
  80. package/coverage/lcov-report/src/api/controllers/table/internal.ts.html +664 -0
  81. package/coverage/lcov-report/src/api/controllers/table/utils.ts.html +1240 -0
  82. package/coverage/lcov-report/{api → src/api}/controllers/templates.js.html +10 -10
  83. package/coverage/lcov-report/{api → src/api}/controllers/user.js.html +10 -10
  84. package/coverage/lcov-report/{api → src/api}/controllers/view/exporters.js.html +10 -10
  85. package/coverage/lcov-report/{api → src/api}/controllers/view/index.html +10 -10
  86. package/coverage/lcov-report/{api → src/api}/controllers/view/index.js.html +10 -10
  87. package/coverage/lcov-report/{api → src/api}/controllers/view/utils.js.html +10 -10
  88. package/coverage/lcov-report/{api → src/api}/controllers/view/viewBuilder.js.html +10 -10
  89. package/coverage/lcov-report/src/api/controllers/webhook.ts.html +379 -0
  90. package/coverage/lcov-report/{api → src/api}/index.html +10 -10
  91. package/coverage/lcov-report/{api → src/api}/index.js.html +10 -10
  92. package/coverage/lcov-report/{api → src/api}/routes/analytics.js.html +10 -10
  93. package/coverage/lcov-report/{api → src/api}/routes/apikeys.js.html +10 -10
  94. package/coverage/lcov-report/src/api/routes/application.ts.html +199 -0
  95. package/coverage/lcov-report/src/api/routes/auth.ts.html +109 -0
  96. package/coverage/lcov-report/{api → src/api}/routes/automation.js.html +14 -14
  97. package/coverage/lcov-report/src/api/routes/backup.ts.html +115 -0
  98. package/coverage/lcov-report/{api → src/api}/routes/cloud.js.html +10 -10
  99. package/coverage/lcov-report/{api → src/api}/routes/component.js.html +10 -10
  100. package/coverage/lcov-report/{api → src/api}/routes/datasource.js.html +15 -15
  101. package/coverage/lcov-report/{api → src/api}/routes/deploy.js.html +10 -10
  102. package/coverage/lcov-report/{api → src/api}/routes/dev.js.html +10 -10
  103. package/coverage/lcov-report/{api → src/api}/routes/index.html +137 -17
  104. package/coverage/lcov-report/src/api/routes/index.ts.html +289 -0
  105. package/coverage/lcov-report/{api → src/api}/routes/integration.js.html +10 -10
  106. package/coverage/lcov-report/{api → src/api}/routes/layout.js.html +10 -10
  107. package/coverage/lcov-report/{api → src/api}/routes/metadata.js.html +10 -10
  108. package/coverage/lcov-report/{api → src/api}/routes/migrations.js.html +10 -10
  109. package/coverage/lcov-report/{api → src/api}/routes/permission.js.html +10 -10
  110. package/coverage/lcov-report/src/api/routes/plugin.ts.html +127 -0
  111. package/coverage/lcov-report/src/api/routes/public/applications.ts.html +541 -0
  112. package/coverage/lcov-report/src/api/routes/public/index.html +191 -0
  113. package/coverage/lcov-report/src/api/routes/public/index.ts.html +502 -0
  114. package/coverage/lcov-report/src/api/routes/public/middleware/index.html +116 -0
  115. package/coverage/lcov-report/src/api/routes/public/middleware/mapper.ts.html +328 -0
  116. package/coverage/lcov-report/src/api/routes/public/queries.ts.html +313 -0
  117. package/coverage/lcov-report/src/api/routes/public/rows.ts.html +598 -0
  118. package/coverage/lcov-report/src/api/routes/public/tables.ts.html +586 -0
  119. package/coverage/lcov-report/src/api/routes/public/users.ts.html +511 -0
  120. package/coverage/lcov-report/src/api/routes/public/utils/Endpoint.ts.html +238 -0
  121. package/coverage/lcov-report/src/api/routes/public/utils/index.html +116 -0
  122. package/coverage/lcov-report/{api → src/api}/routes/query.js.html +15 -15
  123. package/coverage/lcov-report/{api → src/api}/routes/role.js.html +10 -10
  124. package/coverage/lcov-report/{api → src/api}/routes/routing.js.html +10 -10
  125. package/coverage/lcov-report/src/api/routes/row.ts.html +889 -0
  126. package/coverage/lcov-report/{api → src/api}/routes/screen.js.html +10 -10
  127. package/coverage/lcov-report/{api → src/api}/routes/script.js.html +10 -10
  128. package/coverage/lcov-report/src/api/routes/static.ts.html +289 -0
  129. package/coverage/lcov-report/{api → src/api}/routes/table.js.html +13 -13
  130. package/coverage/lcov-report/{api → src/api}/routes/templates.js.html +10 -10
  131. package/coverage/lcov-report/src/api/routes/tests/utilities/TestFunctions.ts.html +556 -0
  132. package/coverage/lcov-report/src/api/routes/tests/utilities/index.html +131 -0
  133. package/coverage/lcov-report/src/api/routes/tests/utilities/index.js.html +367 -0
  134. package/coverage/lcov-report/{api → src/api}/routes/user.js.html +20 -20
  135. package/coverage/lcov-report/{api → src/api}/routes/utils/index.html +10 -10
  136. package/coverage/lcov-report/{api → src/api}/routes/utils/validators.js.html +15 -15
  137. package/coverage/lcov-report/{api → src/api}/routes/view.js.html +13 -13
  138. package/coverage/lcov-report/src/api/routes/webhook.ts.html +166 -0
  139. package/coverage/lcov-report/src/app.ts.html +403 -0
  140. package/coverage/lcov-report/{automations → src/automations}/actions.js.html +10 -10
  141. package/coverage/lcov-report/{automations → src/automations}/automationUtils.js.html +10 -10
  142. package/coverage/lcov-report/{automations → src/automations}/bullboard.js.html +10 -10
  143. package/coverage/lcov-report/{automations → src/automations}/index.html +34 -19
  144. package/coverage/lcov-report/{automations → src/automations}/index.js.html +10 -10
  145. package/coverage/lcov-report/src/automations/logging/index.html +116 -0
  146. package/coverage/lcov-report/src/automations/logging/index.ts.html +199 -0
  147. package/coverage/lcov-report/{automations → src/automations}/steps/bash.js.html +10 -10
  148. package/coverage/lcov-report/src/automations/steps/createRow.ts.html +367 -0
  149. package/coverage/lcov-report/{automations → src/automations}/steps/delay.js.html +10 -10
  150. package/coverage/lcov-report/src/automations/steps/deleteRow.ts.html +334 -0
  151. package/coverage/lcov-report/{automations → src/automations}/steps/discord.js.html +10 -10
  152. package/coverage/lcov-report/{automations → src/automations}/steps/executeQuery.js.html +10 -10
  153. package/coverage/lcov-report/{automations → src/automations}/steps/executeScript.js.html +10 -10
  154. package/coverage/lcov-report/{automations → src/automations}/steps/filter.js.html +10 -10
  155. package/coverage/lcov-report/{automations → src/automations}/steps/index.html +56 -26
  156. package/coverage/lcov-report/{automations → src/automations}/steps/integromat.js.html +10 -10
  157. package/coverage/lcov-report/{automations → src/automations}/steps/loop.js.html +10 -10
  158. package/coverage/lcov-report/{automations → src/automations}/steps/outgoingWebhook.js.html +10 -10
  159. package/coverage/lcov-report/{automations → src/automations}/steps/queryRows.js.html +10 -10
  160. package/coverage/lcov-report/{automations → src/automations}/steps/sendSmtpEmail.js.html +10 -10
  161. package/coverage/lcov-report/{automations → src/automations}/steps/serverLog.js.html +10 -10
  162. package/coverage/lcov-report/{automations → src/automations}/steps/slack.js.html +10 -10
  163. package/coverage/lcov-report/{automations → src/automations}/steps/updateRow.js.html +10 -10
  164. package/coverage/lcov-report/{automations → src/automations}/steps/utils.js.html +19 -19
  165. package/coverage/lcov-report/{automations → src/automations}/steps/zapier.js.html +10 -10
  166. package/coverage/lcov-report/src/automations/tests/utilities/index.html +116 -0
  167. package/coverage/lcov-report/src/automations/tests/utilities/index.js.html +256 -0
  168. package/coverage/lcov-report/{automations → src/automations}/triggerInfo/app.js.html +10 -10
  169. package/coverage/lcov-report/{automations → src/automations}/triggerInfo/cron.js.html +10 -10
  170. package/coverage/lcov-report/{automations → src/automations}/triggerInfo/index.html +10 -10
  171. package/coverage/lcov-report/{automations → src/automations}/triggerInfo/index.js.html +10 -10
  172. package/coverage/lcov-report/{automations → src/automations}/triggerInfo/rowDeleted.js.html +10 -10
  173. package/coverage/lcov-report/{automations → src/automations}/triggerInfo/rowSaved.js.html +10 -10
  174. package/coverage/lcov-report/{automations → src/automations}/triggerInfo/rowUpdated.js.html +10 -10
  175. package/coverage/lcov-report/{automations → src/automations}/triggerInfo/webhook.js.html +10 -10
  176. package/coverage/lcov-report/{automations → src/automations}/triggers.js.html +10 -10
  177. package/coverage/lcov-report/src/automations/utils.ts.html +886 -0
  178. package/coverage/lcov-report/{constants → src/constants}/index.html +10 -10
  179. package/coverage/lcov-report/{constants → src/constants}/index.js.html +10 -10
  180. package/coverage/lcov-report/{constants → src/constants}/layouts.js.html +10 -10
  181. package/coverage/lcov-report/{constants → src/constants}/screens.js.html +10 -10
  182. package/coverage/lcov-report/src/db/dynamoClient.js.html +466 -0
  183. package/coverage/lcov-report/{db → src/db}/inMemoryView.js.html +12 -12
  184. package/coverage/lcov-report/{db → src/db}/index.html +42 -27
  185. package/coverage/lcov-report/{db → src/db}/index.js.html +18 -18
  186. package/coverage/lcov-report/{db → src/db}/linkedRows/LinkController.js.html +10 -10
  187. package/coverage/lcov-report/{db → src/db}/linkedRows/index.html +10 -10
  188. package/coverage/lcov-report/{db → src/db}/linkedRows/index.js.html +10 -10
  189. package/coverage/lcov-report/{db → src/db}/linkedRows/linkUtils.js.html +10 -10
  190. package/coverage/lcov-report/{db → src/db}/newid.js.html +10 -10
  191. package/coverage/lcov-report/{db/utils.js.html → src/db/utils.ts.html} +104 -152
  192. package/coverage/lcov-report/src/definitions/automations.ts.html +181 -0
  193. package/coverage/lcov-report/src/definitions/datasource.ts.html +235 -0
  194. package/coverage/lcov-report/src/definitions/index.html +131 -0
  195. package/coverage/lcov-report/src/environment.js.html +445 -0
  196. package/coverage/lcov-report/{events → src/events}/AutomationEmitter.js.html +10 -10
  197. package/coverage/lcov-report/{events → src/events}/index.html +10 -10
  198. package/coverage/lcov-report/{events → src/events}/index.js.html +10 -10
  199. package/coverage/lcov-report/{events → src/events}/utils.js.html +10 -10
  200. package/coverage/lcov-report/src/index.html +206 -0
  201. package/coverage/lcov-report/src/index.ts.html +133 -0
  202. package/coverage/lcov-report/src/integrations/airtable.ts.html +529 -0
  203. package/coverage/lcov-report/src/integrations/arangodb.ts.html +415 -0
  204. package/coverage/lcov-report/src/integrations/base/index.html +161 -0
  205. package/coverage/lcov-report/src/integrations/base/query.ts.html +133 -0
  206. package/coverage/lcov-report/src/integrations/base/sql.ts.html +1951 -0
  207. package/coverage/lcov-report/src/integrations/base/sqlTable.ts.html +691 -0
  208. package/coverage/lcov-report/src/integrations/base/utils.ts.html +121 -0
  209. package/coverage/lcov-report/src/integrations/couchdb.ts.html +406 -0
  210. package/coverage/lcov-report/src/integrations/dynamodb.ts.html +745 -0
  211. package/coverage/lcov-report/src/integrations/elasticsearch.ts.html +634 -0
  212. package/coverage/lcov-report/src/integrations/firebase.ts.html +646 -0
  213. package/coverage/lcov-report/src/integrations/googlesheets.ts.html +1312 -0
  214. package/coverage/lcov-report/src/integrations/index.html +371 -0
  215. package/coverage/lcov-report/src/integrations/index.ts.html +433 -0
  216. package/coverage/lcov-report/src/integrations/microsoftSqlServer.ts.html +1006 -0
  217. package/coverage/lcov-report/src/integrations/mongodb.ts.html +1867 -0
  218. package/coverage/lcov-report/src/integrations/mysql.ts.html +952 -0
  219. package/coverage/lcov-report/src/integrations/oracle.ts.html +1474 -0
  220. package/coverage/lcov-report/src/integrations/postgres.ts.html +1069 -0
  221. package/coverage/lcov-report/src/integrations/queries/index.html +116 -0
  222. package/coverage/lcov-report/src/integrations/queries/sql.ts.html +463 -0
  223. package/coverage/lcov-report/src/integrations/redis.ts.html +550 -0
  224. package/coverage/lcov-report/src/integrations/rest.ts.html +1381 -0
  225. package/coverage/lcov-report/src/integrations/s3.ts.html +862 -0
  226. package/coverage/lcov-report/src/integrations/snowflake.ts.html +376 -0
  227. package/coverage/lcov-report/{integrations → src/integrations}/tests/TestConfiguration.js.html +10 -10
  228. package/coverage/lcov-report/{integrations → src/integrations}/tests/index.html +10 -10
  229. package/coverage/lcov-report/src/integrations/utils.ts.html +1006 -0
  230. package/coverage/lcov-report/{middleware/appInfo.js.html → src/middleware/appInfo.ts.html} +31 -28
  231. package/coverage/lcov-report/src/middleware/authorized.ts.html +481 -0
  232. package/coverage/lcov-report/{middleware/builder.js.html → src/middleware/builder.ts.html} +43 -37
  233. package/coverage/lcov-report/{middleware/currentapp.js.html → src/middleware/currentapp.ts.html} +77 -68
  234. package/coverage/lcov-report/{middleware → src/middleware}/index.html +78 -63
  235. package/coverage/lcov-report/{middleware/joi-validator.js.html → src/middleware/joi-validator.ts.html} +25 -22
  236. package/coverage/lcov-report/{middleware/publicApi.js.html → src/middleware/publicApi.ts.html} +24 -24
  237. package/coverage/lcov-report/{middleware/resourceId.js.html → src/middleware/resourceId.ts.html} +40 -25
  238. package/coverage/lcov-report/{middleware/selfhost.js.html → src/middleware/selfhost.ts.html} +25 -19
  239. package/coverage/lcov-report/{middleware/utils.js.html → src/middleware/utils.ts.html} +19 -13
  240. package/coverage/lcov-report/src/migrations/functions/appUrls.ts.html +187 -0
  241. package/coverage/lcov-report/src/migrations/functions/backfill/app/automations.ts.html +163 -0
  242. package/coverage/lcov-report/src/migrations/functions/backfill/app/datasources.ts.html +151 -0
  243. package/coverage/lcov-report/src/migrations/functions/backfill/app/index.html +206 -0
  244. package/coverage/lcov-report/src/migrations/functions/backfill/app/layouts.ts.html +172 -0
  245. package/coverage/lcov-report/src/migrations/functions/backfill/app/queries.ts.html +226 -0
  246. package/coverage/lcov-report/src/migrations/functions/backfill/app/roles.ts.html +151 -0
  247. package/coverage/lcov-report/src/migrations/functions/backfill/app/screens.ts.html +151 -0
  248. package/coverage/lcov-report/src/migrations/functions/backfill/app/tables.ts.html +166 -0
  249. package/coverage/lcov-report/src/migrations/functions/backfill/app.ts.html +532 -0
  250. package/coverage/lcov-report/src/migrations/functions/backfill/global/configs.ts.html +283 -0
  251. package/coverage/lcov-report/src/migrations/functions/backfill/global/index.html +146 -0
  252. package/coverage/lcov-report/src/migrations/functions/backfill/global/quotas.ts.html +265 -0
  253. package/coverage/lcov-report/src/migrations/functions/backfill/global/users.ts.html +232 -0
  254. package/coverage/lcov-report/src/migrations/functions/backfill/global.ts.html +724 -0
  255. package/coverage/lcov-report/src/migrations/functions/backfill/index.html +161 -0
  256. package/coverage/lcov-report/src/migrations/functions/backfill/index.ts.html +106 -0
  257. package/coverage/lcov-report/src/migrations/functions/backfill/installation.ts.html +235 -0
  258. package/coverage/lcov-report/src/migrations/functions/index.html +146 -0
  259. package/coverage/lcov-report/src/migrations/functions/syncQuotas.ts.html +130 -0
  260. package/coverage/lcov-report/src/migrations/functions/usageQuotas/index.html +161 -0
  261. package/coverage/lcov-report/src/migrations/functions/usageQuotas/index.ts.html +94 -0
  262. package/coverage/lcov-report/src/migrations/functions/usageQuotas/syncApps.ts.html +130 -0
  263. package/coverage/lcov-report/src/migrations/functions/usageQuotas/syncPlugins.ts.html +115 -0
  264. package/coverage/lcov-report/src/migrations/functions/usageQuotas/syncRows.ts.html +172 -0
  265. package/coverage/lcov-report/src/migrations/functions/userEmailViewCasing.ts.html +124 -0
  266. package/coverage/lcov-report/src/migrations/index.html +116 -0
  267. package/coverage/lcov-report/src/migrations/index.ts.html +403 -0
  268. package/coverage/lcov-report/src/migrations/tests/helpers.ts.html +205 -0
  269. package/coverage/lcov-report/src/migrations/tests/index.html +131 -0
  270. package/coverage/lcov-report/src/migrations/tests/structures.ts.html +283 -0
  271. package/coverage/lcov-report/src/module.d.ts.html +127 -0
  272. package/coverage/lcov-report/src/sdk/app/automations/index.html +131 -0
  273. package/coverage/lcov-report/src/sdk/app/automations/index.ts.html +100 -0
  274. package/coverage/lcov-report/src/sdk/app/automations/webhook.ts.html +214 -0
  275. package/coverage/lcov-report/src/sdk/app/backups/constants.ts.html +91 -0
  276. package/coverage/lcov-report/src/sdk/app/backups/exports.ts.html +598 -0
  277. package/coverage/lcov-report/src/sdk/app/backups/imports.ts.html +694 -0
  278. package/coverage/lcov-report/src/sdk/app/backups/index.html +176 -0
  279. package/coverage/lcov-report/src/sdk/app/backups/index.ts.html +112 -0
  280. package/coverage/lcov-report/src/sdk/app/backups/statistics.ts.html +292 -0
  281. package/coverage/lcov-report/src/sdk/app/tables/index.html +116 -0
  282. package/coverage/lcov-report/src/sdk/app/tables/index.ts.html +265 -0
  283. package/coverage/lcov-report/{utilities/routing → src/sdk}/index.html +10 -10
  284. package/coverage/lcov-report/src/sdk/index.ts.html +130 -0
  285. package/coverage/lcov-report/src/startup.ts.html +499 -0
  286. package/coverage/lcov-report/src/tests/utilities/TestConfiguration.js.html +1873 -0
  287. package/coverage/lcov-report/src/tests/utilities/controllers.js.html +133 -0
  288. package/coverage/lcov-report/src/tests/utilities/index.html +161 -0
  289. package/coverage/lcov-report/src/tests/utilities/index.js.html +118 -0
  290. package/coverage/lcov-report/src/tests/utilities/structures.js.html +652 -0
  291. package/coverage/lcov-report/src/threads/automation.ts.html +1597 -0
  292. package/coverage/lcov-report/src/threads/index.html +161 -0
  293. package/coverage/lcov-report/src/threads/index.ts.html +418 -0
  294. package/coverage/lcov-report/src/threads/query.ts.html +976 -0
  295. package/coverage/lcov-report/src/threads/utils.ts.html +376 -0
  296. package/coverage/lcov-report/{utilities → src/utilities}/budibaseDir.js.html +10 -10
  297. package/coverage/lcov-report/{utilities → src/utilities}/centralPath.js.html +10 -10
  298. package/coverage/lcov-report/{utilities → src/utilities}/csvParser.js.html +10 -10
  299. package/coverage/lcov-report/src/utilities/fileSystem/clientLibrary.js.html +547 -0
  300. package/coverage/lcov-report/src/utilities/fileSystem/index.html +161 -0
  301. package/coverage/lcov-report/src/utilities/fileSystem/index.js.html +1141 -0
  302. package/coverage/lcov-report/src/utilities/fileSystem/processor.js.html +148 -0
  303. package/coverage/lcov-report/src/utilities/fileSystem/utilities.js.html +193 -0
  304. package/coverage/lcov-report/{utilities/global.js.html → src/utilities/global.ts.html} +107 -74
  305. package/coverage/lcov-report/{utilities → src/utilities}/index.html +42 -27
  306. package/coverage/lcov-report/{utilities → src/utilities}/index.js.html +10 -10
  307. package/coverage/lcov-report/{utilities → src/utilities}/plugins.js.html +10 -10
  308. package/coverage/lcov-report/{utilities → src/utilities}/queue/inMemoryQueue.js.html +10 -10
  309. package/coverage/lcov-report/{utilities → src/utilities}/queue/index.html +10 -10
  310. package/coverage/lcov-report/src/utilities/redis.js.html +340 -0
  311. package/coverage/lcov-report/{api/controllers/query → src/utilities/routing}/index.html +8 -8
  312. package/coverage/lcov-report/{utilities → src/utilities}/routing/index.js.html +10 -10
  313. package/coverage/lcov-report/{utilities → src/utilities}/rowProcessor/index.html +10 -10
  314. package/coverage/lcov-report/{utilities → src/utilities}/rowProcessor/index.js.html +10 -10
  315. package/coverage/lcov-report/{utilities → src/utilities}/rowProcessor/utils.js.html +10 -10
  316. package/coverage/lcov-report/{utilities → src/utilities}/scriptRunner.js.html +10 -10
  317. package/coverage/lcov-report/{utilities → src/utilities}/security.js.html +22 -22
  318. package/coverage/lcov-report/{utilities → src/utilities}/statusCodes.js.html +10 -10
  319. package/coverage/lcov-report/{utilities → src/utilities}/usageQuota/index.html +10 -10
  320. package/coverage/lcov-report/{utilities → src/utilities}/usageQuota/rows.js.html +10 -10
  321. package/coverage/lcov-report/{utilities → src/utilities}/usageQuota/usageQuoteReset.js.html +10 -10
  322. package/coverage/lcov-report/{utilities → src/utilities}/users.js.html +10 -10
  323. package/coverage/lcov-report/{utilities → src/utilities}/workerRequests.js.html +13 -13
  324. package/coverage/lcov-report/src/watch.ts.html +199 -0
  325. package/coverage/lcov-report/src/websocket.ts.html +163 -0
  326. package/coverage/lcov.info +17589 -5003
  327. package/dist/api/controllers/application.js +35 -43
  328. package/dist/api/controllers/deploy/index.js +13 -16
  329. package/dist/api/controllers/dev.js +96 -81
  330. package/dist/api/controllers/public/applications.js +17 -9
  331. package/dist/api/controllers/query/index.js +10 -13
  332. package/dist/api/controllers/row/ExternalRequest.js +6 -1
  333. package/dist/api/controllers/row/index.js +16 -7
  334. package/dist/api/controllers/row/internal.js +2 -2
  335. package/dist/api/controllers/table/internal.js +4 -4
  336. package/dist/api/routes/automation.js +3 -3
  337. package/dist/api/routes/datasource.js +4 -4
  338. package/dist/api/routes/public/index.js +9 -9
  339. package/dist/api/routes/query.js +4 -4
  340. package/dist/api/routes/row.js +11 -11
  341. package/dist/api/routes/static.js +3 -3
  342. package/dist/api/routes/table.js +2 -2
  343. package/dist/api/routes/user.js +9 -9
  344. package/dist/api/routes/utils/validators.js +4 -4
  345. package/dist/api/routes/view.js +2 -2
  346. package/dist/automations/tests/utilities/index.js +21 -12
  347. package/dist/automations/utils.js +9 -8
  348. package/dist/db/inMemoryView.js +2 -2
  349. package/dist/db/utils.js +145 -118
  350. package/dist/integrations/elasticsearch.js +26 -2
  351. package/dist/integrations/googlesheets.js +4 -6
  352. package/dist/integrations/s3.js +157 -1
  353. package/dist/middleware/appInfo.js +14 -9
  354. package/dist/middleware/authorized.js +5 -5
  355. package/dist/middleware/builder.js +41 -40
  356. package/dist/middleware/currentapp.js +39 -37
  357. package/dist/middleware/joi-validator.js +17 -10
  358. package/dist/middleware/publicApi.js +5 -6
  359. package/dist/middleware/resourceId.js +16 -9
  360. package/dist/middleware/selfhost.js +5 -4
  361. package/dist/middleware/utils.js +5 -2
  362. package/dist/migrations/functions/backfill/global.js +1 -1
  363. package/dist/migrations/functions/usageQuotas/syncRows.js +1 -1
  364. package/dist/package.json +10 -44
  365. package/dist/sdk/app/tables/index.js +4 -4
  366. package/dist/tests/utilities/TestConfiguration.js +12 -10
  367. package/dist/tests/utilities/structures.js +2 -2
  368. package/dist/tsconfig.build.tsbuildinfo +1 -1
  369. package/dist/utilities/global.js +87 -66
  370. package/dist/utilities/security.js +10 -10
  371. package/dist/utilities/workerRequests.js +3 -3
  372. package/jest.config.ts +33 -0
  373. package/package.json +11 -45
  374. package/scripts/localdomain.js +34 -6
  375. package/src/api/controllers/application.ts +34 -39
  376. package/src/api/controllers/auth.ts +3 -2
  377. package/src/api/controllers/deploy/index.ts +13 -25
  378. package/src/api/controllers/{dev.js → dev.ts} +31 -37
  379. package/src/api/controllers/public/applications.ts +15 -9
  380. package/src/api/controllers/query/index.ts +11 -14
  381. package/src/api/controllers/row/ExternalRequest.ts +5 -3
  382. package/src/api/controllers/row/index.ts +17 -9
  383. package/src/api/controllers/row/internal.js +2 -2
  384. package/src/api/controllers/table/internal.ts +4 -4
  385. package/src/api/routes/automation.js +4 -4
  386. package/src/api/routes/datasource.js +5 -5
  387. package/src/api/routes/public/index.ts +10 -10
  388. package/src/api/routes/public/tests/compare.spec.js +1 -1
  389. package/src/api/routes/query.js +5 -5
  390. package/src/api/routes/row.ts +12 -12
  391. package/src/api/routes/static.ts +5 -5
  392. package/src/api/routes/table.js +3 -3
  393. package/src/api/routes/tests/analytics.spec.js +1 -1
  394. package/src/api/routes/tests/query.spec.js +15 -10
  395. package/src/api/routes/tests/role.spec.js +5 -5
  396. package/src/api/routes/tests/static.spec.js +2 -2
  397. package/src/api/routes/tests/table.spec.js +38 -35
  398. package/src/api/routes/user.js +10 -10
  399. package/src/api/routes/utils/validators.js +5 -5
  400. package/src/api/routes/view.js +3 -3
  401. package/src/automations/tests/updateRow.spec.js +0 -1
  402. package/src/automations/tests/utilities/index.js +10 -4
  403. package/src/automations/utils.ts +9 -12
  404. package/src/db/inMemoryView.js +2 -2
  405. package/src/db/tests/linkController.spec.js +73 -57
  406. package/src/db/tests/linkTests.spec.js +17 -14
  407. package/src/db/{utils.js → utils.ts} +76 -92
  408. package/src/integrations/elasticsearch.ts +32 -2
  409. package/src/integrations/googlesheets.ts +4 -7
  410. package/src/integrations/s3.ts +179 -3
  411. package/src/integrations/tests/s3.spec.ts +85 -1
  412. package/src/middleware/appInfo.ts +20 -0
  413. package/src/middleware/authorized.ts +6 -6
  414. package/src/middleware/{builder.js → builder.ts} +17 -15
  415. package/src/middleware/{currentapp.js → currentapp.ts} +42 -39
  416. package/src/middleware/{joi-validator.js → joi-validator.ts} +9 -8
  417. package/src/middleware/publicApi.ts +21 -0
  418. package/src/middleware/{resourceId.js → resourceId.ts} +16 -11
  419. package/src/middleware/{selfhost.js → selfhost.ts} +4 -2
  420. package/src/middleware/tests/authorized.spec.js +5 -5
  421. package/src/middleware/tests/currentapp.spec.js +118 -63
  422. package/src/middleware/{utils.js → utils.ts} +3 -1
  423. package/src/migrations/functions/backfill/app/tables.ts +2 -5
  424. package/src/migrations/functions/backfill/global.ts +1 -1
  425. package/src/migrations/functions/usageQuotas/syncRows.ts +2 -2
  426. package/src/sdk/app/backups/imports.ts +4 -7
  427. package/src/sdk/app/backups/statistics.ts +9 -18
  428. package/src/sdk/app/tables/index.ts +6 -7
  429. package/{scripts/jestSetup.js → src/tests/jestSetup.ts} +11 -2
  430. package/src/tests/utilities/TestConfiguration.js +12 -10
  431. package/src/tests/utilities/structures.js +2 -2
  432. package/src/threads/automation.ts +1 -1
  433. package/src/utilities/global.ts +138 -0
  434. package/src/utilities/security.js +12 -12
  435. package/src/utilities/workerRequests.js +3 -3
  436. package/tsconfig.json +3 -1
  437. package/src/middleware/appInfo.js +0 -19
  438. package/src/middleware/publicApi.js +0 -21
  439. package/src/utilities/global.js +0 -127
@@ -3,6 +3,7 @@ import { InternalTables } from "../../db/utils"
3
3
  import { getFullUser } from "../../utilities/users"
4
4
  import { roles, context } from "@budibase/backend-core"
5
5
  import { groups } from "@budibase/pro"
6
+ import { ContextUser, User } from "@budibase/types"
6
7
 
7
8
  const PUBLIC_ROLE = roles.BUILTIN_ROLE_IDS.PUBLIC
8
9
 
@@ -24,7 +25,7 @@ export async function fetchSelf(ctx: any) {
24
25
  }
25
26
 
26
27
  const appId = context.getAppId()
27
- const user = await getFullUser(ctx, userId)
28
+ const user: ContextUser = await getFullUser(ctx, userId)
28
29
  // this shouldn't be returned by the app self
29
30
  delete user.roles
30
31
  // forward the csrf token from the session
@@ -34,7 +35,7 @@ export async function fetchSelf(ctx: any) {
34
35
  const db = context.getAppDB()
35
36
  // check for group permissions
36
37
  if (!user.roleId || user.roleId === PUBLIC_ROLE) {
37
- const groupRoleId = await groups.getGroupRoleId(user, appId)
38
+ const groupRoleId = await groups.getGroupRoleId(user as User, appId)
38
39
  user.roleId = groupRoleId || user.roleId
39
40
  }
40
41
  // remove the full roles structure
@@ -1,23 +1,11 @@
1
1
  import Deployment from "./Deployment"
2
- import {
3
- getDevelopmentAppID,
4
- getProdAppID,
5
- Replication,
6
- } from "@budibase/backend-core/db"
2
+ import { context, db as dbCore, events, cache } from "@budibase/backend-core"
7
3
  import { DocumentType, getAutomationParams } from "../../../db/utils"
8
4
  import {
9
5
  clearMetadata,
10
6
  disableAllCrons,
11
7
  enableCronTrigger,
12
8
  } from "../../../automations/utils"
13
- import { app as appCache } from "@budibase/backend-core/cache"
14
- import {
15
- getAppDB,
16
- getAppId,
17
- getDevAppDB,
18
- getProdAppDB,
19
- } from "@budibase/backend-core/context"
20
- import { events } from "@budibase/backend-core"
21
9
  import { backups } from "@budibase/pro"
22
10
  import { AppBackupTrigger } from "@budibase/types"
23
11
 
@@ -49,7 +37,7 @@ async function checkAllDeployments(deployments: any) {
49
37
 
50
38
  async function storeDeploymentHistory(deployment: any) {
51
39
  const deploymentJSON = deployment.getJSON()
52
- const db = getAppDB()
40
+ const db = context.getAppDB()
53
41
 
54
42
  let deploymentDoc
55
43
  try {
@@ -77,7 +65,7 @@ async function storeDeploymentHistory(deployment: any) {
77
65
  }
78
66
 
79
67
  async function initDeployedApp(prodAppId: any) {
80
- const db = getProdAppDB()
68
+ const db = context.getProdAppDB()
81
69
  console.log("Reading automation docs")
82
70
  const automations = (
83
71
  await db.allDocs(
@@ -103,9 +91,9 @@ async function initDeployedApp(prodAppId: any) {
103
91
  async function deployApp(deployment: any, userId: string) {
104
92
  let replication
105
93
  try {
106
- const appId = getAppId()
107
- const devAppId = getDevelopmentAppID(appId)
108
- const productionAppId = getProdAppID(appId)
94
+ const appId = context.getAppId()!
95
+ const devAppId = dbCore.getDevelopmentAppID(appId)
96
+ const productionAppId = dbCore.getProdAppID(appId)
109
97
 
110
98
  // don't try this if feature isn't allowed, will error
111
99
  if (await backups.isEnabled()) {
@@ -122,8 +110,8 @@ async function deployApp(deployment: any, userId: string) {
122
110
  source: devAppId,
123
111
  target: productionAppId,
124
112
  }
125
- replication = new Replication(config)
126
- const devDb = getDevAppDB()
113
+ replication = new dbCore.Replication(config)
114
+ const devDb = context.getDevAppDB()
127
115
  console.log("Compacting development DB")
128
116
  await devDb.compact()
129
117
  console.log("Replication object created")
@@ -131,7 +119,7 @@ async function deployApp(deployment: any, userId: string) {
131
119
  console.log("replication complete.. replacing app meta doc")
132
120
  // app metadata is excluded as it is likely to be in conflict
133
121
  // replicate the app metadata document manually
134
- const db = getProdAppDB()
122
+ const db = context.getProdAppDB()
135
123
  const appDoc = await devDb.get(DocumentType.APP_METADATA)
136
124
  try {
137
125
  const prodAppDoc = await db.get(DocumentType.APP_METADATA)
@@ -147,7 +135,7 @@ async function deployApp(deployment: any, userId: string) {
147
135
  // remove automation errors if they exist
148
136
  delete appDoc.automationErrors
149
137
  await db.put(appDoc)
150
- await appCache.invalidateAppMetadata(productionAppId)
138
+ await cache.app.invalidateAppMetadata(productionAppId)
151
139
  console.log("New app doc written successfully.")
152
140
  await initDeployedApp(productionAppId)
153
141
  console.log("Deployed app initialised, setting deployment to successful")
@@ -170,7 +158,7 @@ async function deployApp(deployment: any, userId: string) {
170
158
 
171
159
  export async function fetchDeployments(ctx: any) {
172
160
  try {
173
- const db = getAppDB()
161
+ const db = context.getAppDB()
174
162
  const deploymentDoc = await db.get(DocumentType.DEPLOYMENTS)
175
163
  const { updated, deployments } = await checkAllDeployments(deploymentDoc)
176
164
  if (updated) {
@@ -184,7 +172,7 @@ export async function fetchDeployments(ctx: any) {
184
172
 
185
173
  export async function deploymentProgress(ctx: any) {
186
174
  try {
187
- const db = getAppDB()
175
+ const db = context.getAppDB()
188
176
  const deploymentDoc = await db.get(DocumentType.DEPLOYMENTS)
189
177
  ctx.body = deploymentDoc[ctx.params.deploymentId]
190
178
  } catch (err) {
@@ -197,7 +185,7 @@ export async function deploymentProgress(ctx: any) {
197
185
 
198
186
  const isFirstDeploy = async () => {
199
187
  try {
200
- const db = getProdAppDB()
188
+ const db = context.getProdAppDB()
201
189
  await db.get(DocumentType.APP_METADATA)
202
190
  } catch (e: any) {
203
191
  if (e.status === 404) {
@@ -1,29 +1,23 @@
1
- const fetch = require("node-fetch")
2
- const env = require("../../environment")
3
- const { checkSlashesInUrl } = require("../../utilities")
4
- const { request } = require("../../utilities/workerRequests")
5
- const { clearLock } = require("../../utilities/redis")
6
- const { Replication, getProdAppID } = require("@budibase/backend-core/db")
7
- const { DocumentType } = require("../../db/utils")
8
- const { app: appCache } = require("@budibase/backend-core/cache")
9
- const { getProdAppDB, getAppDB } = require("@budibase/backend-core/context")
10
- const { events } = require("@budibase/backend-core")
1
+ import fetch from "node-fetch"
2
+ import env from "../../environment"
3
+ import { checkSlashesInUrl } from "../../utilities"
4
+ import { request } from "../../utilities/workerRequests"
5
+ import { clearLock as redisClearLock } from "../../utilities/redis"
6
+ import { DocumentType } from "../../db/utils"
7
+ import { context } from "@budibase/backend-core"
8
+ import { events, db as dbCore, cache } from "@budibase/backend-core"
11
9
 
12
- async function redirect(ctx, method, path = "global") {
10
+ async function redirect(ctx: any, method: string, path: string = "global") {
13
11
  const { devPath } = ctx.params
14
12
  const queryString = ctx.originalUrl.split("?")[1] || ""
15
13
  const response = await fetch(
16
14
  checkSlashesInUrl(
17
15
  `${env.WORKER_URL}/api/${path}/${devPath}?${queryString}`
18
16
  ),
19
- request(
20
- ctx,
21
- {
22
- method,
23
- body: ctx.request.body,
24
- },
25
- true
26
- )
17
+ request(ctx, {
18
+ method,
19
+ body: ctx.request.body,
20
+ })
27
21
  )
28
22
  if (response.status !== 200) {
29
23
  const err = await response.text()
@@ -46,28 +40,28 @@ async function redirect(ctx, method, path = "global") {
46
40
  ctx.cookies
47
41
  }
48
42
 
49
- exports.buildRedirectGet = path => {
50
- return async ctx => {
43
+ export function buildRedirectGet(path: string) {
44
+ return async (ctx: any) => {
51
45
  await redirect(ctx, "GET", path)
52
46
  }
53
47
  }
54
48
 
55
- exports.buildRedirectPost = path => {
56
- return async ctx => {
49
+ export function buildRedirectPost(path: string) {
50
+ return async (ctx: any) => {
57
51
  await redirect(ctx, "POST", path)
58
52
  }
59
53
  }
60
54
 
61
- exports.buildRedirectDelete = path => {
62
- return async ctx => {
55
+ export function buildRedirectDelete(path: string) {
56
+ return async (ctx: any) => {
63
57
  await redirect(ctx, "DELETE", path)
64
58
  }
65
59
  }
66
60
 
67
- exports.clearLock = async ctx => {
61
+ export async function clearLock(ctx: any) {
68
62
  const { appId } = ctx.params
69
63
  try {
70
- await clearLock(appId, ctx.user)
64
+ await redisClearLock(appId, ctx.user)
71
65
  } catch (err) {
72
66
  ctx.throw(400, `Unable to remove lock. ${err}`)
73
67
  }
@@ -76,16 +70,16 @@ exports.clearLock = async ctx => {
76
70
  }
77
71
  }
78
72
 
79
- exports.revert = async ctx => {
73
+ export async function revert(ctx: any) {
80
74
  const { appId } = ctx.params
81
- const productionAppId = getProdAppID(appId)
75
+ const productionAppId = dbCore.getProdAppID(appId)
82
76
 
83
77
  // App must have been deployed first
84
78
  try {
85
- const db = getProdAppDB({ skip_setup: true })
86
- const info = await db.info()
87
- if (info.error) {
88
- throw info.error
79
+ const db = context.getProdAppDB({ skip_setup: true })
80
+ const exists = await db.exists()
81
+ if (!exists) {
82
+ throw new Error("App must be deployed to be reverted.")
89
83
  }
90
84
  const deploymentDoc = await db.get(DocumentType.DEPLOYMENTS)
91
85
  if (
@@ -98,7 +92,7 @@ exports.revert = async ctx => {
98
92
  return ctx.throw(400, "App has not yet been deployed")
99
93
  }
100
94
 
101
- const replication = new Replication({
95
+ const replication = new dbCore.Replication({
102
96
  source: productionAppId,
103
97
  target: appId,
104
98
  })
@@ -109,12 +103,12 @@ exports.revert = async ctx => {
109
103
  }
110
104
 
111
105
  // update appID in reverted app to be dev version again
112
- const db = getAppDB()
106
+ const db = context.getAppDB()
113
107
  const appDoc = await db.get(DocumentType.APP_METADATA)
114
108
  appDoc.appId = appId
115
109
  appDoc.instance._id = appId
116
110
  await db.put(appDoc)
117
- await appCache.invalidateAppMetadata(appId)
111
+ await cache.app.invalidateAppMetadata(appId)
118
112
  ctx.body = {
119
113
  message: "Reverted changes successfully.",
120
114
  }
@@ -126,7 +120,7 @@ exports.revert = async ctx => {
126
120
  }
127
121
  }
128
122
 
129
- exports.getBudibaseVersion = async ctx => {
123
+ export async function getBudibaseVersion(ctx: any) {
130
124
  const version = require("../../../package.json").version
131
125
  ctx.body = {
132
126
  version,
@@ -1,5 +1,4 @@
1
- const { getAllApps } = require("@budibase/backend-core/db")
2
- const { doInAppContext } = require("@budibase/backend-core/context")
1
+ import { db as dbCore, context } from "@budibase/backend-core"
3
2
  import { search as stringSearch, addRev } from "./utils"
4
3
  import * as controller from "../application"
5
4
  import { Application } from "../../../definitions/common"
@@ -15,15 +14,22 @@ function fixAppID(app: Application, params: any) {
15
14
  }
16
15
 
17
16
  async function setResponseApp(ctx: any) {
18
- if (ctx.body && ctx.body.appId && (!ctx.params || !ctx.params.appId)) {
19
- ctx.params = { appId: ctx.body.appId }
17
+ const appId = ctx.body?.appId
18
+ if (appId && (!ctx.params || !ctx.params.appId)) {
19
+ ctx.params = { appId }
20
+ }
21
+ if (appId) {
22
+ await context.doInContext(appId, () => {
23
+ return controller.fetchAppPackage(ctx)
24
+ })
25
+ } else {
26
+ return controller.fetchAppPackage(ctx)
20
27
  }
21
- await controller.fetchAppPackage(ctx)
22
28
  }
23
29
 
24
30
  export async function search(ctx: any, next: any) {
25
31
  const { name } = ctx.request.body
26
- const apps = await getAllApps({ all: true })
32
+ const apps = await dbCore.getAllApps({ all: true })
27
33
  ctx.body = stringSearch(apps, name)
28
34
  await next()
29
35
  }
@@ -41,7 +47,7 @@ export async function create(ctx: any, next: any) {
41
47
  }
42
48
 
43
49
  export async function read(ctx: any, next: any) {
44
- await doInAppContext(ctx.params.appId, async () => {
50
+ await context.doInAppContext(ctx.params.appId, async () => {
45
51
  await setResponseApp(ctx)
46
52
  await next()
47
53
  })
@@ -49,7 +55,7 @@ export async function read(ctx: any, next: any) {
49
55
 
50
56
  export async function update(ctx: any, next: any) {
51
57
  ctx.request.body = await addRev(fixAppID(ctx.request.body, ctx.params))
52
- await doInAppContext(ctx.params.appId, async () => {
58
+ await context.doInAppContext(ctx.params.appId, async () => {
53
59
  await controller.update(ctx)
54
60
  await setResponseApp(ctx)
55
61
  await next()
@@ -57,7 +63,7 @@ export async function update(ctx: any, next: any) {
57
63
  }
58
64
 
59
65
  export async function destroy(ctx: any, next: any) {
60
- await doInAppContext(ctx.params.appId, async () => {
66
+ await context.doInAppContext(ctx.params.appId, async () => {
61
67
  // get the app before deleting it
62
68
  await setResponseApp(ctx)
63
69
  const body = ctx.body
@@ -5,11 +5,8 @@ import { save as saveDatasource } from "../datasource"
5
5
  import { RestImporter } from "./import"
6
6
  import { invalidateDynamicVariables } from "../../../threads/utils"
7
7
  import { QUERY_THREAD_TIMEOUT } from "../../../environment"
8
- import { getAppDB } from "@budibase/backend-core/context"
9
8
  import { quotas } from "@budibase/pro"
10
- import { events } from "@budibase/backend-core"
11
- import { getCookie } from "@budibase/backend-core/utils"
12
- import { Cookies, Configs } from "@budibase/backend-core/constants"
9
+ import { events, context, utils, constants } from "@budibase/backend-core"
13
10
 
14
11
  const Runner = new Thread(ThreadType.QUERY, {
15
12
  timeoutMs: QUERY_THREAD_TIMEOUT || 10000,
@@ -28,7 +25,7 @@ function enrichQueries(input: any) {
28
25
  }
29
26
 
30
27
  export async function fetch(ctx: any) {
31
- const db = getAppDB()
28
+ const db = context.getAppDB()
32
29
 
33
30
  const body = await db.allDocs(
34
31
  getQueryParams(null, {
@@ -81,7 +78,7 @@ const _import = async (ctx: any) => {
81
78
  export { _import as import }
82
79
 
83
80
  export async function save(ctx: any) {
84
- const db = getAppDB()
81
+ const db = context.getAppDB()
85
82
  const query = ctx.request.body
86
83
 
87
84
  const datasource = await db.get(query.datasourceId)
@@ -103,7 +100,7 @@ export async function save(ctx: any) {
103
100
  }
104
101
 
105
102
  export async function find(ctx: any) {
106
- const db = getAppDB()
103
+ const db = context.getAppDB()
107
104
  const query = enrichQueries(await db.get(ctx.params.queryId))
108
105
  // remove properties that could be dangerous in real app
109
106
  if (isProdAppID(ctx.appId)) {
@@ -115,13 +112,13 @@ export async function find(ctx: any) {
115
112
 
116
113
  //Required to discern between OIDC OAuth config entries
117
114
  function getOAuthConfigCookieId(ctx: any) {
118
- if (ctx.user.providerType === Configs.OIDC) {
119
- return getCookie(ctx, Cookies.OIDC_CONFIG)
115
+ if (ctx.user.providerType === constants.Config.OIDC) {
116
+ return utils.getCookie(ctx, constants.Cookie.OIDC_CONFIG)
120
117
  }
121
118
  }
122
119
 
123
120
  function getAuthConfig(ctx: any) {
124
- const authCookie = getCookie(ctx, Cookies.Auth)
121
+ const authCookie = utils.getCookie(ctx, constants.Cookie.Auth)
125
122
  let authConfigCtx: any = {}
126
123
  authConfigCtx["configId"] = getOAuthConfigCookieId(ctx)
127
124
  authConfigCtx["sessionId"] = authCookie ? authCookie.sessionId : null
@@ -129,7 +126,7 @@ function getAuthConfig(ctx: any) {
129
126
  }
130
127
 
131
128
  export async function preview(ctx: any) {
132
- const db = getAppDB()
129
+ const db = context.getAppDB()
133
130
 
134
131
  const datasource = await db.get(ctx.request.body.datasourceId)
135
132
  const query = ctx.request.body
@@ -201,7 +198,7 @@ async function execute(
201
198
  ctx: any,
202
199
  opts: any = { rowsOnly: false, isAutomation: false }
203
200
  ) {
204
- const db = getAppDB()
201
+ const db = context.getAppDB()
205
202
 
206
203
  const query = await db.get(ctx.params.queryId)
207
204
  const datasource = await db.get(query.datasourceId)
@@ -267,7 +264,7 @@ export async function executeV2(
267
264
  }
268
265
 
269
266
  const removeDynamicVariables = async (queryId: any) => {
270
- const db = getAppDB()
267
+ const db = context.getAppDB()
271
268
  const query = await db.get(queryId)
272
269
  const datasource = await db.get(query.datasourceId)
273
270
  const dynamicVariables = datasource.config.dynamicVariables
@@ -288,7 +285,7 @@ const removeDynamicVariables = async (queryId: any) => {
288
285
  }
289
286
 
290
287
  export async function destroy(ctx: any) {
291
- const db = getAppDB()
288
+ const db = context.getAppDB()
292
289
  const queryId = ctx.params.queryId
293
290
  await removeDynamicVariables(queryId)
294
291
  const query = await db.get(queryId)
@@ -282,9 +282,11 @@ module External {
282
282
  const linkTablePrimary = linkTable.primary[0]
283
283
  // one to many
284
284
  if (isOneSide(field)) {
285
- newRow[field.foreignKey || linkTablePrimary] = breakRowIdField(
286
- row[key][0]
287
- )[0]
285
+ let id = row[key][0]
286
+ if (typeof row[key] === "string") {
287
+ id = decodeURIComponent(row[key]).match(/\[(.*?)\]/)?.[1]
288
+ }
289
+ newRow[field.foreignKey || linkTablePrimary] = breakRowIdField(id)[0]
288
290
  }
289
291
  // many to many
290
292
  else if (field.through) {
@@ -30,16 +30,24 @@ export async function patch(ctx: any): Promise<any> {
30
30
  if (body && !body._id) {
31
31
  return save(ctx)
32
32
  }
33
- const { row, table } = await quotas.addQuery(
34
- () => pickApi(tableId).patch(ctx),
35
- {
36
- datasourceId: tableId,
33
+ try {
34
+ const { row, table } = await quotas.addQuery(
35
+ () => pickApi(tableId).patch(ctx),
36
+ {
37
+ datasourceId: tableId,
38
+ }
39
+ )
40
+ if (!row) {
41
+ ctx.throw(404, "Row not found")
37
42
  }
38
- )
39
- ctx.status = 200
40
- ctx.eventEmitter && ctx.eventEmitter.emitRow(`row:update`, appId, row, table)
41
- ctx.message = `${table.name} updated successfully.`
42
- ctx.body = row
43
+ ctx.status = 200
44
+ ctx.eventEmitter &&
45
+ ctx.eventEmitter.emitRow(`row:update`, appId, row, table)
46
+ ctx.message = `${table.name} updated successfully.`
47
+ ctx.body = row
48
+ } catch (err) {
49
+ ctx.throw(400, err)
50
+ }
43
51
  }
44
52
 
45
53
  export const save = async (ctx: any) => {
@@ -6,7 +6,7 @@ const {
6
6
  DocumentType,
7
7
  InternalTables,
8
8
  } = require("../../../db/utils")
9
- const { dangerousGetDB } = require("@budibase/backend-core/db")
9
+ const { getDB } = require("@budibase/backend-core/db")
10
10
  const userController = require("../user")
11
11
  const {
12
12
  inputProcessing,
@@ -251,7 +251,7 @@ exports.fetch = async ctx => {
251
251
  }
252
252
 
253
253
  exports.find = async ctx => {
254
- const db = dangerousGetDB(ctx.appId)
254
+ const db = getDB(ctx.appId)
255
255
  const table = await db.get(ctx.params.tableId)
256
256
  let row = await findRow(ctx, ctx.params.tableId, ctx.params.rowId)
257
257
  row = await outputProcessing(table, row)
@@ -2,7 +2,7 @@ import { updateLinks, EventType } from "../../../db/linkedRows"
2
2
  import { getRowParams, generateTableID } from "../../../db/utils"
3
3
  import { FieldTypes } from "../../../constants"
4
4
  import { TableSaveFunctions, hasTypeChanged, handleDataImport } from "./utils"
5
- const { getAppDB } = require("@budibase/backend-core/context")
5
+ import { context } from "@budibase/backend-core"
6
6
  import { isTest } from "../../../environment"
7
7
  import {
8
8
  cleanupAttachments,
@@ -35,7 +35,7 @@ function checkAutoColumns(table: Table, oldTable: Table) {
35
35
  }
36
36
 
37
37
  export async function save(ctx: any) {
38
- const db = getAppDB()
38
+ const db = context.getAppDB()
39
39
  const { dataImport, ...rest } = ctx.request.body
40
40
  let tableToSave = {
41
41
  type: "table",
@@ -138,7 +138,7 @@ export async function save(ctx: any) {
138
138
  }
139
139
 
140
140
  export async function destroy(ctx: any) {
141
- const db = getAppDB()
141
+ const db = context.getAppDB()
142
142
  const tableToDelete = await db.get(ctx.params.tableId)
143
143
 
144
144
  // Delete all rows for that table
@@ -161,7 +161,7 @@ export async function destroy(ctx: any) {
161
161
  })
162
162
 
163
163
  // don't remove the table itself until very end
164
- await db.remove(tableToDelete)
164
+ await db.remove(tableToDelete._id, tableToDelete._rev)
165
165
 
166
166
  // remove table search index
167
167
  if (!isTest() || env.COUCH_DB_URL) {
@@ -3,8 +3,8 @@ const controller = require("../controllers/automation")
3
3
  const authorized = require("../../middleware/authorized")
4
4
  const {
5
5
  BUILDER,
6
- PermissionLevels,
7
- PermissionTypes,
6
+ PermissionLevel,
7
+ PermissionType,
8
8
  } = require("@budibase/backend-core/permissions")
9
9
  const { bodyResource, paramResource } = require("../../middleware/resourceId")
10
10
  const {
@@ -71,14 +71,14 @@ router
71
71
  "/api/automations/:id/trigger",
72
72
  appInfoMiddleware({ appType: AppType.PROD }),
73
73
  paramResource("id"),
74
- authorized(PermissionTypes.AUTOMATION, PermissionLevels.EXECUTE),
74
+ authorized(PermissionType.AUTOMATION, PermissionLevel.EXECUTE),
75
75
  controller.trigger
76
76
  )
77
77
  .post(
78
78
  "/api/automations/:id/test",
79
79
  appInfoMiddleware({ appType: AppType.DEV }),
80
80
  paramResource("id"),
81
- authorized(PermissionTypes.AUTOMATION, PermissionLevels.EXECUTE),
81
+ authorized(PermissionType.AUTOMATION, PermissionLevel.EXECUTE),
82
82
  controller.test
83
83
  )
84
84
 
@@ -3,8 +3,8 @@ const datasourceController = require("../controllers/datasource")
3
3
  const authorized = require("../../middleware/authorized")
4
4
  const {
5
5
  BUILDER,
6
- PermissionLevels,
7
- PermissionTypes,
6
+ PermissionLevel,
7
+ PermissionType,
8
8
  } = require("@budibase/backend-core/permissions")
9
9
  const {
10
10
  datasourceValidator,
@@ -17,17 +17,17 @@ router
17
17
  .get("/api/datasources", authorized(BUILDER), datasourceController.fetch)
18
18
  .get(
19
19
  "/api/datasources/:datasourceId",
20
- authorized(PermissionTypes.TABLE, PermissionLevels.READ),
20
+ authorized(PermissionType.TABLE, PermissionLevel.READ),
21
21
  datasourceController.find
22
22
  )
23
23
  .put(
24
24
  "/api/datasources/:datasourceId",
25
- authorized(PermissionTypes.TABLE, PermissionLevels.READ),
25
+ authorized(PermissionType.TABLE, PermissionLevel.READ),
26
26
  datasourceController.update
27
27
  )
28
28
  .post(
29
29
  "/api/datasources/query",
30
- authorized(PermissionTypes.TABLE, PermissionLevels.READ),
30
+ authorized(PermissionType.TABLE, PermissionLevel.READ),
31
31
  datasourceQueryValidator(),
32
32
  datasourceController.query
33
33
  )
@@ -13,8 +13,8 @@ import env from "../../../environment"
13
13
  const Router = require("@koa/router")
14
14
  const { RateLimit, Stores } = require("koa2-ratelimit")
15
15
  const {
16
- PermissionLevels,
17
- PermissionTypes,
16
+ PermissionLevel,
17
+ PermissionType,
18
18
  } = require("@budibase/backend-core/permissions")
19
19
  const { getRedisOptions } = require("@budibase/backend-core/redis").utils
20
20
 
@@ -105,7 +105,7 @@ function applyRoutes(
105
105
  : paramResource(resource)
106
106
  const publicApiMiddleware = publicApi({
107
107
  requiresAppId:
108
- permType !== PermissionTypes.APP && permType !== PermissionTypes.USER,
108
+ permType !== PermissionType.APP && permType !== PermissionType.USER,
109
109
  })
110
110
  addMiddleware(endpoints.read, publicApiMiddleware)
111
111
  addMiddleware(endpoints.write, publicApiMiddleware)
@@ -113,8 +113,8 @@ function applyRoutes(
113
113
  addMiddleware(endpoints.read, paramMiddleware)
114
114
  addMiddleware(endpoints.write, paramMiddleware)
115
115
  // add the authorization middleware, using the correct perm type
116
- addMiddleware(endpoints.read, authorized(permType, PermissionLevels.READ))
117
- addMiddleware(endpoints.write, authorized(permType, PermissionLevels.WRITE))
116
+ addMiddleware(endpoints.read, authorized(permType, PermissionLevel.READ))
117
+ addMiddleware(endpoints.write, authorized(permType, PermissionLevel.WRITE))
118
118
  // add the output mapper middleware
119
119
  addMiddleware(endpoints.read, mapperMiddleware, { output: true })
120
120
  addMiddleware(endpoints.write, mapperMiddleware, { output: true })
@@ -122,12 +122,12 @@ function applyRoutes(
122
122
  addToRouter(endpoints.write)
123
123
  }
124
124
 
125
- applyRoutes(appEndpoints, PermissionTypes.APP, "appId")
126
- applyRoutes(tableEndpoints, PermissionTypes.TABLE, "tableId")
127
- applyRoutes(userEndpoints, PermissionTypes.USER, "userId")
128
- applyRoutes(queryEndpoints, PermissionTypes.QUERY, "queryId")
125
+ applyRoutes(appEndpoints, PermissionType.APP, "appId")
126
+ applyRoutes(tableEndpoints, PermissionType.TABLE, "tableId")
127
+ applyRoutes(userEndpoints, PermissionType.USER, "userId")
128
+ applyRoutes(queryEndpoints, PermissionType.QUERY, "queryId")
129
129
  // needs to be applied last for routing purposes, don't override other endpoints
130
- applyRoutes(rowEndpoints, PermissionTypes.TABLE, "tableId", "rowId")
130
+ applyRoutes(rowEndpoints, PermissionType.TABLE, "tableId", "rowId")
131
131
 
132
132
  export default publicRouter
133
133
 
@@ -31,7 +31,7 @@ async function makeRequest(method, endpoint, body, appId = config.getAppId()) {
31
31
  if (body) {
32
32
  req.send(body)
33
33
  }
34
- const res = await req.expect("Content-Type", /json/).expect(200)
34
+ const res = await req
35
35
  expect(res.body).toBeDefined()
36
36
  return res
37
37
  }