@budibase/server 2.1.31 → 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.6e202eba.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
@@ -18,23 +18,17 @@ const package_json_1 = __importDefault(require("../../../package.json"));
18
18
  const staticViews_1 = require("../../db/views/staticViews");
19
19
  const fileSystem_1 = require("../../utilities/fileSystem");
20
20
  const utils_1 = require("../../db/utils");
21
- const { BUILTIN_ROLE_IDS, AccessController, } = require("@budibase/backend-core/roles");
22
- const { CacheKeys, bustCache } = require("@budibase/backend-core/cache");
23
- const { getAllApps, isDevAppID, getProdAppID, Replication, } = require("@budibase/backend-core/db");
21
+ const backend_core_1 = require("@budibase/backend-core");
24
22
  const constants_1 = require("../../constants");
25
23
  const workerRequests_1 = require("../../utilities/workerRequests");
26
24
  const utilities_1 = require("../../utilities");
27
25
  const redis_1 = require("../../utilities/redis");
28
26
  const clientLibrary_1 = require("../../utilities/fileSystem/clientLibrary");
29
- const { getTenantId, isMultiTenant } = require("@budibase/backend-core/tenancy");
30
27
  const user_1 = require("./user");
31
- const { app: appCache } = require("@budibase/backend-core/cache");
32
28
  const utils_2 = require("../../automations/utils");
33
- const backend_core_1 = require("@budibase/backend-core");
34
29
  const logging_1 = require("../../automations/logging");
35
30
  const rows_1 = require("../../utilities/usageQuota/rows");
36
31
  const pro_1 = require("@budibase/pro");
37
- const backend_core_2 = require("@budibase/backend-core");
38
32
  const types_1 = require("@budibase/types");
39
33
  const layouts_1 = require("../../constants/layouts");
40
34
  const plugins_1 = require("../../utilities/plugins");
@@ -59,7 +53,7 @@ function getScreens() {
59
53
  }
60
54
  function getUserRoleId(ctx) {
61
55
  return !ctx.user.role || !ctx.user.role._id
62
- ? BUILTIN_ROLE_IDS.PUBLIC
56
+ ? backend_core_1.roles.BUILTIN_ROLE_IDS.PUBLIC
63
57
  : ctx.user.role._id;
64
58
  }
65
59
  const getAppUrl = (ctx) => {
@@ -101,7 +95,7 @@ const checkAppName = (ctx, apps, name, currentAppId) => {
101
95
  };
102
96
  function createInstance(template) {
103
97
  return __awaiter(this, void 0, void 0, function* () {
104
- const tenantId = isMultiTenant() ? getTenantId() : null;
98
+ const tenantId = backend_core_1.tenancy.isMultiTenant() ? backend_core_1.tenancy.getTenantId() : null;
105
99
  const baseAppId = (0, utils_1.generateAppID)(tenantId);
106
100
  const appId = (0, utils_1.generateDevAppID)(baseAppId);
107
101
  yield backend_core_1.context.updateAppId(appId);
@@ -138,7 +132,7 @@ function createInstance(template) {
138
132
  const fetch = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
139
133
  const dev = ctx.query && ctx.query.status === utils_1.AppStatus.DEV;
140
134
  const all = ctx.query && ctx.query.status === utils_1.AppStatus.ALL;
141
- const apps = yield getAllApps({ dev, all });
135
+ const apps = (yield backend_core_1.db.getAllApps({ dev, all }));
142
136
  const appIds = apps
143
137
  .filter((app) => app.status === "development")
144
138
  .map((app) => app.appId);
@@ -162,7 +156,7 @@ exports.fetch = fetch;
162
156
  const fetchAppDefinition = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
163
157
  const layouts = yield getLayouts();
164
158
  const userRoleId = getUserRoleId(ctx);
165
- const accessController = new AccessController();
159
+ const accessController = new backend_core_1.roles.AccessController();
166
160
  const screens = yield accessController.checkScreensAccess(yield getScreens(), userRoleId);
167
161
  ctx.body = {
168
162
  layouts,
@@ -181,7 +175,7 @@ const fetchAppPackage = (ctx) => __awaiter(void 0, void 0, void 0, function* ()
181
175
  // Only filter screens if the user is not a builder
182
176
  if (!(ctx.user.builder && ctx.user.builder.global)) {
183
177
  const userRoleId = getUserRoleId(ctx);
184
- const accessController = new AccessController();
178
+ const accessController = new backend_core_1.roles.AccessController();
185
179
  screens = yield accessController.checkScreensAccess(screens, userRoleId);
186
180
  }
187
181
  ctx.body = {
@@ -193,7 +187,7 @@ const fetchAppPackage = (ctx) => __awaiter(void 0, void 0, void 0, function* ()
193
187
  });
194
188
  exports.fetchAppPackage = fetchAppPackage;
195
189
  const performAppCreate = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
196
- const apps = yield getAllApps({ dev: true });
190
+ const apps = yield backend_core_1.db.getAllApps({ dev: true });
197
191
  const name = ctx.request.body.name;
198
192
  checkAppName(ctx, apps, name);
199
193
  const url = (0, exports.getAppUrl)(ctx);
@@ -221,7 +215,7 @@ const performAppCreate = (ctx) => __awaiter(void 0, void 0, void 0, function* ()
221
215
  url: url,
222
216
  template: templateKey,
223
217
  instance,
224
- tenantId: getTenantId(),
218
+ tenantId: backend_core_1.tenancy.getTenantId(),
225
219
  updatedAt: new Date().toISOString(),
226
220
  createdAt: new Date().toISOString(),
227
221
  status: utils_1.AppStatus.DEV,
@@ -276,7 +270,7 @@ const performAppCreate = (ctx) => __awaiter(void 0, void 0, void 0, function* ()
276
270
  if (!environment_1.default.isTest()) {
277
271
  yield (0, fileSystem_1.createApp)(appId);
278
272
  }
279
- yield appCache.invalidateAppMetadata(appId, newApplication);
273
+ yield backend_core_1.cache.app.invalidateAppMetadata(appId, newApplication);
280
274
  return newApplication;
281
275
  });
282
276
  const creationEvents = (request, app) => __awaiter(void 0, void 0, void 0, function* () {
@@ -286,25 +280,25 @@ const creationEvents = (request, app) => __awaiter(void 0, void 0, void 0, funct
286
280
  if (body.useTemplate === "true") {
287
281
  // from template
288
282
  if (body.templateKey && body.templateKey !== "undefined") {
289
- creationFns.push(a => backend_core_2.events.app.templateImported(a, body.templateKey));
283
+ creationFns.push(a => backend_core_1.events.app.templateImported(a, body.templateKey));
290
284
  }
291
285
  // from file
292
286
  else if ((_a = request.files) === null || _a === void 0 ? void 0 : _a.templateFile) {
293
- creationFns.push(a => backend_core_2.events.app.fileImported(a));
287
+ creationFns.push(a => backend_core_1.events.app.fileImported(a));
294
288
  }
295
289
  // unknown
296
290
  else {
297
291
  console.error("Could not determine template creation event");
298
292
  }
299
293
  }
300
- creationFns.push(a => backend_core_2.events.app.created(a));
294
+ creationFns.push(a => backend_core_1.events.app.created(a));
301
295
  for (let fn of creationFns) {
302
296
  yield fn(app);
303
297
  }
304
298
  });
305
299
  const appPostCreate = (ctx, app) => __awaiter(void 0, void 0, void 0, function* () {
306
- const tenantId = getTenantId();
307
- yield backend_core_2.migrations.backPopulateMigrations({
300
+ const tenantId = backend_core_1.tenancy.getTenantId();
301
+ yield backend_core_1.migrations.backPopulateMigrations({
308
302
  type: types_1.MigrationType.APP,
309
303
  tenantId,
310
304
  appId: app.appId,
@@ -316,10 +310,12 @@ const appPostCreate = (ctx, app) => __awaiter(void 0, void 0, void 0, function*
316
310
  const rowCount = rows ? rows.length : 0;
317
311
  if (rowCount) {
318
312
  try {
319
- yield pro_1.quotas.addRows(rowCount);
313
+ yield backend_core_1.context.doInAppContext(app.appId, () => {
314
+ return pro_1.quotas.addRows(rowCount);
315
+ });
320
316
  }
321
317
  catch (err) {
322
- if (err.code && err.code === backend_core_2.errors.codes.USAGE_LIMIT_EXCEEDED) {
318
+ if (err.code && err.code === backend_core_1.errors.codes.USAGE_LIMIT_EXCEEDED) {
323
319
  // this import resulted in row usage exceeding the quota
324
320
  // delete the app
325
321
  // skip pre and post steps as no rows have been added to quotas yet
@@ -334,7 +330,7 @@ const appPostCreate = (ctx, app) => __awaiter(void 0, void 0, void 0, function*
334
330
  const create = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
335
331
  const newApplication = yield pro_1.quotas.addApp(() => performAppCreate(ctx));
336
332
  yield appPostCreate(ctx, newApplication);
337
- yield bustCache(CacheKeys.CHECKLIST);
333
+ yield backend_core_1.cache.bustCache(backend_core_1.cache.CacheKeys.CHECKLIST);
338
334
  ctx.body = newApplication;
339
335
  ctx.status = 200;
340
336
  });
@@ -342,7 +338,7 @@ exports.create = create;
342
338
  // This endpoint currently operates as a PATCH rather than a PUT
343
339
  // Thus name and url fields are handled only if present
344
340
  const update = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
345
- const apps = yield getAllApps({ dev: true });
341
+ const apps = yield backend_core_1.db.getAllApps({ dev: true });
346
342
  // validation
347
343
  const name = ctx.request.body.name;
348
344
  if (name) {
@@ -354,7 +350,7 @@ const update = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
354
350
  ctx.request.body.url = url;
355
351
  }
356
352
  const app = yield (0, exports.updateAppPackage)(ctx.request.body, ctx.params.appId);
357
- yield backend_core_2.events.app.updated(app);
353
+ yield backend_core_1.events.app.updated(app);
358
354
  ctx.status = 200;
359
355
  ctx.body = app;
360
356
  });
@@ -376,7 +372,7 @@ const updateClient = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
376
372
  revertableVersion: currentVersion,
377
373
  };
378
374
  const app = yield (0, exports.updateAppPackage)(appPackageUpdates, ctx.params.appId);
379
- yield backend_core_2.events.app.versionUpdated(app, currentVersion, updatedToVersion);
375
+ yield backend_core_1.events.app.versionUpdated(app, currentVersion, updatedToVersion);
380
376
  ctx.status = 200;
381
377
  ctx.body = app;
382
378
  });
@@ -400,7 +396,7 @@ const revertClient = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
400
396
  revertableVersion: null,
401
397
  };
402
398
  const app = yield (0, exports.updateAppPackage)(appPackageUpdates, ctx.params.appId);
403
- yield backend_core_2.events.app.versionReverted(app, currentVersion, revertedToVersion);
399
+ yield backend_core_1.events.app.versionReverted(app, currentVersion, revertedToVersion);
404
400
  ctx.status = 200;
405
401
  ctx.body = app;
406
402
  });
@@ -409,17 +405,17 @@ const destroyApp = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
409
405
  let appId = ctx.params.appId;
410
406
  let isUnpublish = ctx.query && ctx.query.unpublish;
411
407
  if (isUnpublish) {
412
- appId = getProdAppID(appId);
408
+ appId = backend_core_1.db.getProdAppID(appId);
413
409
  }
414
410
  const db = isUnpublish ? backend_core_1.context.getProdAppDB() : backend_core_1.context.getAppDB();
415
411
  const app = yield db.get(utils_1.DocumentType.APP_METADATA);
416
412
  const result = yield db.destroy();
417
413
  if (isUnpublish) {
418
- yield backend_core_2.events.app.unpublished(app);
414
+ yield backend_core_1.events.app.unpublished(app);
419
415
  }
420
416
  else {
421
417
  yield pro_1.quotas.removeApp();
422
- yield backend_core_2.events.app.deleted(app);
418
+ yield backend_core_1.events.app.deleted(app);
423
419
  }
424
420
  /* istanbul ignore next */
425
421
  if (!environment_1.default.isTest() && !isUnpublish) {
@@ -433,7 +429,7 @@ const destroyApp = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
433
429
  else {
434
430
  yield (0, workerRequests_1.removeAppFromUserRoles)(ctx, appId);
435
431
  }
436
- yield appCache.invalidateAppMetadata(appId);
432
+ yield backend_core_1.cache.app.invalidateAppMetadata(appId);
437
433
  return result;
438
434
  });
439
435
  const preDestroyApp = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
@@ -464,19 +460,15 @@ const sync = (ctx, next) => __awaiter(void 0, void 0, void 0, function* () {
464
460
  return next();
465
461
  }
466
462
  const appId = ctx.params.appId;
467
- if (!isDevAppID(appId)) {
463
+ if (!backend_core_1.db.isDevAppID(appId)) {
468
464
  ctx.throw(400, "This action cannot be performed for production apps");
469
465
  }
470
466
  // replicate prod to dev
471
- const prodAppId = getProdAppID(appId);
472
- try {
473
- // specific case, want to make sure setup is skipped
474
- const prodDb = backend_core_1.context.getProdAppDB({ skip_setup: true });
475
- const info = yield prodDb.info();
476
- if (info.error)
477
- throw info.error;
478
- }
479
- catch (err) {
467
+ const prodAppId = backend_core_1.db.getProdAppID(appId);
468
+ // specific case, want to make sure setup is skipped
469
+ const prodDb = backend_core_1.context.getProdAppDB({ skip_setup: true });
470
+ const exists = yield prodDb.exists();
471
+ if (!exists) {
480
472
  // the database doesn't exist. Don't replicate
481
473
  ctx.status = 200;
482
474
  ctx.body = {
@@ -484,7 +476,7 @@ const sync = (ctx, next) => __awaiter(void 0, void 0, void 0, function* () {
484
476
  };
485
477
  return next();
486
478
  }
487
- const replication = new Replication({
479
+ const replication = new backend_core_1.db.Replication({
488
480
  source: prodAppId,
489
481
  target: appId,
490
482
  });
@@ -523,7 +515,7 @@ const updateAppPackage = (appPackage, appId) => __awaiter(void 0, void 0, void 0
523
515
  delete newAppPackage.lockedBy;
524
516
  yield db.put(newAppPackage);
525
517
  // remove any cached metadata, so that it will be updated
526
- yield appCache.invalidateAppMetadata(appId);
518
+ yield backend_core_1.cache.app.invalidateAppMetadata(appId);
527
519
  return newAppPackage;
528
520
  }));
529
521
  });
@@ -14,12 +14,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.deployApp = exports.deploymentProgress = exports.fetchDeployments = void 0;
16
16
  const Deployment_1 = __importDefault(require("./Deployment"));
17
- const db_1 = require("@budibase/backend-core/db");
17
+ const backend_core_1 = require("@budibase/backend-core");
18
18
  const utils_1 = require("../../../db/utils");
19
19
  const utils_2 = require("../../../automations/utils");
20
- const cache_1 = require("@budibase/backend-core/cache");
21
- const context_1 = require("@budibase/backend-core/context");
22
- const backend_core_1 = require("@budibase/backend-core");
23
20
  const pro_1 = require("@budibase/pro");
24
21
  const types_1 = require("@budibase/types");
25
22
  // the max time we can wait for an invalidation to complete before considering it failed
@@ -49,7 +46,7 @@ function checkAllDeployments(deployments) {
49
46
  function storeDeploymentHistory(deployment) {
50
47
  return __awaiter(this, void 0, void 0, function* () {
51
48
  const deploymentJSON = deployment.getJSON();
52
- const db = (0, context_1.getAppDB)();
49
+ const db = backend_core_1.context.getAppDB();
53
50
  let deploymentDoc;
54
51
  try {
55
52
  // theres only one deployment doc per app database
@@ -70,7 +67,7 @@ function storeDeploymentHistory(deployment) {
70
67
  }
71
68
  function initDeployedApp(prodAppId) {
72
69
  return __awaiter(this, void 0, void 0, function* () {
73
- const db = (0, context_1.getProdAppDB)();
70
+ const db = backend_core_1.context.getProdAppDB();
74
71
  console.log("Reading automation docs");
75
72
  const automations = (yield db.allDocs((0, utils_1.getAutomationParams)(null, {
76
73
  include_docs: true,
@@ -93,9 +90,9 @@ function deployApp(deployment, userId) {
93
90
  return __awaiter(this, void 0, void 0, function* () {
94
91
  let replication;
95
92
  try {
96
- const appId = (0, context_1.getAppId)();
97
- const devAppId = (0, db_1.getDevelopmentAppID)(appId);
98
- const productionAppId = (0, db_1.getProdAppID)(appId);
93
+ const appId = backend_core_1.context.getAppId();
94
+ const devAppId = backend_core_1.db.getDevelopmentAppID(appId);
95
+ const productionAppId = backend_core_1.db.getProdAppID(appId);
99
96
  // don't try this if feature isn't allowed, will error
100
97
  if (yield pro_1.backups.isEnabled()) {
101
98
  // trigger backup initially
@@ -107,8 +104,8 @@ function deployApp(deployment, userId) {
107
104
  source: devAppId,
108
105
  target: productionAppId,
109
106
  };
110
- replication = new db_1.Replication(config);
111
- const devDb = (0, context_1.getDevAppDB)();
107
+ replication = new backend_core_1.db.Replication(config);
108
+ const devDb = backend_core_1.context.getDevAppDB();
112
109
  console.log("Compacting development DB");
113
110
  yield devDb.compact();
114
111
  console.log("Replication object created");
@@ -116,7 +113,7 @@ function deployApp(deployment, userId) {
116
113
  console.log("replication complete.. replacing app meta doc");
117
114
  // app metadata is excluded as it is likely to be in conflict
118
115
  // replicate the app metadata document manually
119
- const db = (0, context_1.getProdAppDB)();
116
+ const db = backend_core_1.context.getProdAppDB();
120
117
  const appDoc = yield devDb.get(utils_1.DocumentType.APP_METADATA);
121
118
  try {
122
119
  const prodAppDoc = yield db.get(utils_1.DocumentType.APP_METADATA);
@@ -132,7 +129,7 @@ function deployApp(deployment, userId) {
132
129
  // remove automation errors if they exist
133
130
  delete appDoc.automationErrors;
134
131
  yield db.put(appDoc);
135
- yield cache_1.app.invalidateAppMetadata(productionAppId);
132
+ yield backend_core_1.cache.app.invalidateAppMetadata(productionAppId);
136
133
  console.log("New app doc written successfully.");
137
134
  yield initDeployedApp(productionAppId);
138
135
  console.log("Deployed app initialised, setting deployment to successful");
@@ -155,7 +152,7 @@ function deployApp(deployment, userId) {
155
152
  function fetchDeployments(ctx) {
156
153
  return __awaiter(this, void 0, void 0, function* () {
157
154
  try {
158
- const db = (0, context_1.getAppDB)();
155
+ const db = backend_core_1.context.getAppDB();
159
156
  const deploymentDoc = yield db.get(utils_1.DocumentType.DEPLOYMENTS);
160
157
  const { updated, deployments } = yield checkAllDeployments(deploymentDoc);
161
158
  if (updated) {
@@ -172,7 +169,7 @@ exports.fetchDeployments = fetchDeployments;
172
169
  function deploymentProgress(ctx) {
173
170
  return __awaiter(this, void 0, void 0, function* () {
174
171
  try {
175
- const db = (0, context_1.getAppDB)();
172
+ const db = backend_core_1.context.getAppDB();
176
173
  const deploymentDoc = yield db.get(utils_1.DocumentType.DEPLOYMENTS);
177
174
  ctx.body = deploymentDoc[ctx.params.deploymentId];
178
175
  }
@@ -184,7 +181,7 @@ function deploymentProgress(ctx) {
184
181
  exports.deploymentProgress = deploymentProgress;
185
182
  const isFirstDeploy = () => __awaiter(void 0, void 0, void 0, function* () {
186
183
  try {
187
- const db = (0, context_1.getProdAppDB)();
184
+ const db = backend_core_1.context.getProdAppDB();
188
185
  yield db.get(utils_1.DocumentType.APP_METADATA);
189
186
  }
190
187
  catch (e) {
@@ -8,24 +8,27 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
- const fetch = require("node-fetch");
12
- const env = require("../../environment");
13
- const { checkSlashesInUrl } = require("../../utilities");
14
- const { request } = require("../../utilities/workerRequests");
15
- const { clearLock } = require("../../utilities/redis");
16
- const { Replication, getProdAppID } = require("@budibase/backend-core/db");
17
- const { DocumentType } = require("../../db/utils");
18
- const { app: appCache } = require("@budibase/backend-core/cache");
19
- const { getProdAppDB, getAppDB } = require("@budibase/backend-core/context");
20
- const { events } = require("@budibase/backend-core");
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.getBudibaseVersion = exports.revert = exports.clearLock = exports.buildRedirectDelete = exports.buildRedirectPost = exports.buildRedirectGet = void 0;
16
+ const node_fetch_1 = __importDefault(require("node-fetch"));
17
+ const environment_1 = __importDefault(require("../../environment"));
18
+ const utilities_1 = require("../../utilities");
19
+ const workerRequests_1 = require("../../utilities/workerRequests");
20
+ const redis_1 = require("../../utilities/redis");
21
+ const utils_1 = require("../../db/utils");
22
+ const backend_core_1 = require("@budibase/backend-core");
23
+ const backend_core_2 = require("@budibase/backend-core");
21
24
  function redirect(ctx, method, path = "global") {
22
25
  return __awaiter(this, void 0, void 0, function* () {
23
26
  const { devPath } = ctx.params;
24
27
  const queryString = ctx.originalUrl.split("?")[1] || "";
25
- const response = yield fetch(checkSlashesInUrl(`${env.WORKER_URL}/api/${path}/${devPath}?${queryString}`), request(ctx, {
28
+ const response = yield (0, node_fetch_1.default)((0, utilities_1.checkSlashesInUrl)(`${environment_1.default.WORKER_URL}/api/${path}/${devPath}?${queryString}`), (0, workerRequests_1.request)(ctx, {
26
29
  method,
27
30
  body: ctx.request.body,
28
- }, true));
31
+ }));
29
32
  if (response.status !== 200) {
30
33
  const err = yield response.text();
31
34
  ctx.throw(400, err);
@@ -48,84 +51,96 @@ function redirect(ctx, method, path = "global") {
48
51
  ctx.cookies;
49
52
  });
50
53
  }
51
- exports.buildRedirectGet = path => {
52
- return (ctx) => __awaiter(void 0, void 0, void 0, function* () {
54
+ function buildRedirectGet(path) {
55
+ return (ctx) => __awaiter(this, void 0, void 0, function* () {
53
56
  yield redirect(ctx, "GET", path);
54
57
  });
55
- };
56
- exports.buildRedirectPost = path => {
57
- return (ctx) => __awaiter(void 0, void 0, void 0, function* () {
58
+ }
59
+ exports.buildRedirectGet = buildRedirectGet;
60
+ function buildRedirectPost(path) {
61
+ return (ctx) => __awaiter(this, void 0, void 0, function* () {
58
62
  yield redirect(ctx, "POST", path);
59
63
  });
60
- };
61
- exports.buildRedirectDelete = path => {
62
- return (ctx) => __awaiter(void 0, void 0, void 0, function* () {
64
+ }
65
+ exports.buildRedirectPost = buildRedirectPost;
66
+ function buildRedirectDelete(path) {
67
+ return (ctx) => __awaiter(this, void 0, void 0, function* () {
63
68
  yield redirect(ctx, "DELETE", path);
64
69
  });
65
- };
66
- exports.clearLock = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
67
- const { appId } = ctx.params;
68
- try {
69
- yield clearLock(appId, ctx.user);
70
- }
71
- catch (err) {
72
- ctx.throw(400, `Unable to remove lock. ${err}`);
73
- }
74
- ctx.body = {
75
- message: "Lock released successfully.",
76
- };
77
- });
78
- exports.revert = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
79
- const { appId } = ctx.params;
80
- const productionAppId = getProdAppID(appId);
81
- // App must have been deployed first
82
- try {
83
- const db = getProdAppDB({ skip_setup: true });
84
- const info = yield db.info();
85
- if (info.error) {
86
- throw info.error;
70
+ }
71
+ exports.buildRedirectDelete = buildRedirectDelete;
72
+ function clearLock(ctx) {
73
+ return __awaiter(this, void 0, void 0, function* () {
74
+ const { appId } = ctx.params;
75
+ try {
76
+ yield (0, redis_1.clearLock)(appId, ctx.user);
87
77
  }
88
- const deploymentDoc = yield db.get(DocumentType.DEPLOYMENTS);
89
- if (!deploymentDoc.history ||
90
- Object.keys(deploymentDoc.history).length === 0) {
91
- throw new Error("No deployments for app");
78
+ catch (err) {
79
+ ctx.throw(400, `Unable to remove lock. ${err}`);
92
80
  }
93
- }
94
- catch (err) {
95
- return ctx.throw(400, "App has not yet been deployed");
96
- }
97
- const replication = new Replication({
98
- source: productionAppId,
99
- target: appId,
81
+ ctx.body = {
82
+ message: "Lock released successfully.",
83
+ };
100
84
  });
101
- try {
102
- if (env.COUCH_DB_URL) {
103
- // in-memory db stalls on rollback
104
- yield replication.rollback();
85
+ }
86
+ exports.clearLock = clearLock;
87
+ function revert(ctx) {
88
+ return __awaiter(this, void 0, void 0, function* () {
89
+ const { appId } = ctx.params;
90
+ const productionAppId = backend_core_2.db.getProdAppID(appId);
91
+ // App must have been deployed first
92
+ try {
93
+ const db = backend_core_1.context.getProdAppDB({ skip_setup: true });
94
+ const exists = yield db.exists();
95
+ if (!exists) {
96
+ throw new Error("App must be deployed to be reverted.");
97
+ }
98
+ const deploymentDoc = yield db.get(utils_1.DocumentType.DEPLOYMENTS);
99
+ if (!deploymentDoc.history ||
100
+ Object.keys(deploymentDoc.history).length === 0) {
101
+ throw new Error("No deployments for app");
102
+ }
103
+ }
104
+ catch (err) {
105
+ return ctx.throw(400, "App has not yet been deployed");
106
+ }
107
+ const replication = new backend_core_2.db.Replication({
108
+ source: productionAppId,
109
+ target: appId,
110
+ });
111
+ try {
112
+ if (environment_1.default.COUCH_DB_URL) {
113
+ // in-memory db stalls on rollback
114
+ yield replication.rollback();
115
+ }
116
+ // update appID in reverted app to be dev version again
117
+ const db = backend_core_1.context.getAppDB();
118
+ const appDoc = yield db.get(utils_1.DocumentType.APP_METADATA);
119
+ appDoc.appId = appId;
120
+ appDoc.instance._id = appId;
121
+ yield db.put(appDoc);
122
+ yield backend_core_2.cache.app.invalidateAppMetadata(appId);
123
+ ctx.body = {
124
+ message: "Reverted changes successfully.",
125
+ };
126
+ yield backend_core_2.events.app.reverted(appDoc);
127
+ }
128
+ catch (err) {
129
+ ctx.throw(400, `Unable to revert. ${err}`);
105
130
  }
106
- // update appID in reverted app to be dev version again
107
- const db = getAppDB();
108
- const appDoc = yield db.get(DocumentType.APP_METADATA);
109
- appDoc.appId = appId;
110
- appDoc.instance._id = appId;
111
- yield db.put(appDoc);
112
- yield appCache.invalidateAppMetadata(appId);
131
+ finally {
132
+ yield replication.close();
133
+ }
134
+ });
135
+ }
136
+ exports.revert = revert;
137
+ function getBudibaseVersion(ctx) {
138
+ return __awaiter(this, void 0, void 0, function* () {
139
+ const version = require("../../../package.json").version;
113
140
  ctx.body = {
114
- message: "Reverted changes successfully.",
141
+ version,
115
142
  };
116
- yield events.app.reverted(appDoc);
117
- }
118
- catch (err) {
119
- ctx.throw(400, `Unable to revert. ${err}`);
120
- }
121
- finally {
122
- yield replication.close();
123
- }
124
- });
125
- exports.getBudibaseVersion = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
126
- const version = require("../../../package.json").version;
127
- ctx.body = {
128
- version,
129
- };
130
- yield events.installation.versionChecked(version);
131
- });
143
+ yield backend_core_2.events.installation.versionChecked(version);
144
+ });
145
+ }
146
+ exports.getBudibaseVersion = getBudibaseVersion;
@@ -33,8 +33,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
33
33
  };
34
34
  Object.defineProperty(exports, "__esModule", { value: true });
35
35
  exports.destroy = exports.update = exports.read = exports.create = exports.search = void 0;
36
- const { getAllApps } = require("@budibase/backend-core/db");
37
- const { doInAppContext } = require("@budibase/backend-core/context");
36
+ const backend_core_1 = require("@budibase/backend-core");
38
37
  const utils_1 = require("./utils");
39
38
  const controller = __importStar(require("../application"));
40
39
  function fixAppID(app, params) {
@@ -47,17 +46,26 @@ function fixAppID(app, params) {
47
46
  return app;
48
47
  }
49
48
  function setResponseApp(ctx) {
49
+ var _a;
50
50
  return __awaiter(this, void 0, void 0, function* () {
51
- if (ctx.body && ctx.body.appId && (!ctx.params || !ctx.params.appId)) {
52
- ctx.params = { appId: ctx.body.appId };
51
+ const appId = (_a = ctx.body) === null || _a === void 0 ? void 0 : _a.appId;
52
+ if (appId && (!ctx.params || !ctx.params.appId)) {
53
+ ctx.params = { appId };
54
+ }
55
+ if (appId) {
56
+ yield backend_core_1.context.doInContext(appId, () => {
57
+ return controller.fetchAppPackage(ctx);
58
+ });
59
+ }
60
+ else {
61
+ return controller.fetchAppPackage(ctx);
53
62
  }
54
- yield controller.fetchAppPackage(ctx);
55
63
  });
56
64
  }
57
65
  function search(ctx, next) {
58
66
  return __awaiter(this, void 0, void 0, function* () {
59
67
  const { name } = ctx.request.body;
60
- const apps = yield getAllApps({ all: true });
68
+ const apps = yield backend_core_1.db.getAllApps({ all: true });
61
69
  ctx.body = (0, utils_1.search)(apps, name);
62
70
  yield next();
63
71
  });
@@ -76,7 +84,7 @@ function create(ctx, next) {
76
84
  exports.create = create;
77
85
  function read(ctx, next) {
78
86
  return __awaiter(this, void 0, void 0, function* () {
79
- yield doInAppContext(ctx.params.appId, () => __awaiter(this, void 0, void 0, function* () {
87
+ yield backend_core_1.context.doInAppContext(ctx.params.appId, () => __awaiter(this, void 0, void 0, function* () {
80
88
  yield setResponseApp(ctx);
81
89
  yield next();
82
90
  }));
@@ -86,7 +94,7 @@ exports.read = read;
86
94
  function update(ctx, next) {
87
95
  return __awaiter(this, void 0, void 0, function* () {
88
96
  ctx.request.body = yield (0, utils_1.addRev)(fixAppID(ctx.request.body, ctx.params));
89
- yield doInAppContext(ctx.params.appId, () => __awaiter(this, void 0, void 0, function* () {
97
+ yield backend_core_1.context.doInAppContext(ctx.params.appId, () => __awaiter(this, void 0, void 0, function* () {
90
98
  yield controller.update(ctx);
91
99
  yield setResponseApp(ctx);
92
100
  yield next();
@@ -96,7 +104,7 @@ function update(ctx, next) {
96
104
  exports.update = update;
97
105
  function destroy(ctx, next) {
98
106
  return __awaiter(this, void 0, void 0, function* () {
99
- yield doInAppContext(ctx.params.appId, () => __awaiter(this, void 0, void 0, function* () {
107
+ yield backend_core_1.context.doInAppContext(ctx.params.appId, () => __awaiter(this, void 0, void 0, function* () {
100
108
  // get the app before deleting it
101
109
  yield setResponseApp(ctx);
102
110
  const body = ctx.body;