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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (419) hide show
  1. package/__mocks__/node-fetch.ts +5 -1
  2. package/builder/assets/{index.5ec5f06c.js → index.dba40c82.js} +2 -2
  3. package/builder/index.html +1 -1
  4. package/coverage/clover.xml +1182 -1209
  5. package/coverage/coverage-final.json +35 -35
  6. package/coverage/lcov-report/index.html +94 -94
  7. package/coverage/lcov-report/src/api/controllers/analytics.ts.html +1 -1
  8. package/coverage/lcov-report/src/api/controllers/apikeys.js.html +1 -1
  9. package/coverage/lcov-report/src/api/controllers/application.ts.html +45 -60
  10. package/coverage/lcov-report/src/api/controllers/auth.ts.html +7 -4
  11. package/coverage/lcov-report/src/api/controllers/automation.js.html +1 -1
  12. package/coverage/lcov-report/src/api/controllers/backup.ts.html +1 -1
  13. package/coverage/lcov-report/src/api/controllers/cloud.js.html +1 -1
  14. package/coverage/lcov-report/src/api/controllers/component.ts.html +1 -1
  15. package/coverage/lcov-report/src/api/controllers/datasource.js.html +1 -1
  16. package/coverage/lcov-report/src/api/controllers/deploy/Deployment.js.html +1 -1
  17. package/coverage/lcov-report/src/api/controllers/deploy/index.html +10 -10
  18. package/coverage/lcov-report/src/api/controllers/deploy/index.ts.html +19 -55
  19. package/coverage/lcov-report/src/api/controllers/{dev.js.html → dev.ts.html} +46 -64
  20. package/coverage/lcov-report/src/api/controllers/index.html +25 -25
  21. package/coverage/lcov-report/src/api/controllers/integration.js.html +1 -1
  22. package/coverage/lcov-report/src/api/controllers/layout.js.html +1 -1
  23. package/coverage/lcov-report/src/api/controllers/metadata.js.html +1 -1
  24. package/coverage/lcov-report/src/api/controllers/migrations.js.html +1 -1
  25. package/coverage/lcov-report/src/api/controllers/permission.js.html +1 -1
  26. package/coverage/lcov-report/src/api/controllers/plugin/file.ts.html +1 -1
  27. package/coverage/lcov-report/src/api/controllers/plugin/github.ts.html +1 -1
  28. package/coverage/lcov-report/src/api/controllers/plugin/index.html +1 -1
  29. package/coverage/lcov-report/src/api/controllers/plugin/index.ts.html +1 -1
  30. package/coverage/lcov-report/src/api/controllers/plugin/npm.ts.html +1 -1
  31. package/coverage/lcov-report/src/api/controllers/plugin/uploaders.ts.html +1 -1
  32. package/coverage/lcov-report/src/api/controllers/plugin/url.ts.html +1 -1
  33. package/coverage/lcov-report/src/api/controllers/plugin/utils.ts.html +1 -1
  34. package/coverage/lcov-report/src/api/controllers/public/applications.ts.html +37 -19
  35. package/coverage/lcov-report/src/api/controllers/public/index.html +16 -16
  36. package/coverage/lcov-report/src/api/controllers/public/mapping/applications.ts.html +1 -1
  37. package/coverage/lcov-report/src/api/controllers/public/mapping/index.html +1 -1
  38. package/coverage/lcov-report/src/api/controllers/public/mapping/index.ts.html +1 -1
  39. package/coverage/lcov-report/src/api/controllers/public/mapping/queries.ts.html +1 -1
  40. package/coverage/lcov-report/src/api/controllers/public/mapping/rows.ts.html +1 -1
  41. package/coverage/lcov-report/src/api/controllers/public/mapping/tables.ts.html +1 -1
  42. package/coverage/lcov-report/src/api/controllers/public/mapping/users.ts.html +1 -1
  43. package/coverage/lcov-report/src/api/controllers/public/queries.ts.html +1 -1
  44. package/coverage/lcov-report/src/api/controllers/public/rows.ts.html +1 -1
  45. package/coverage/lcov-report/src/api/controllers/public/tables.ts.html +1 -1
  46. package/coverage/lcov-report/src/api/controllers/public/users.ts.html +1 -1
  47. package/coverage/lcov-report/src/api/controllers/public/utils.ts.html +1 -1
  48. package/coverage/lcov-report/src/api/controllers/query/import/index.html +1 -1
  49. package/coverage/lcov-report/src/api/controllers/query/import/index.ts.html +1 -1
  50. package/coverage/lcov-report/src/api/controllers/query/import/sources/base/index.html +1 -1
  51. package/coverage/lcov-report/src/api/controllers/query/import/sources/base/index.ts.html +1 -1
  52. package/coverage/lcov-report/src/api/controllers/query/import/sources/base/openapi.ts.html +1 -1
  53. package/coverage/lcov-report/src/api/controllers/query/import/sources/curl.ts.html +1 -1
  54. package/coverage/lcov-report/src/api/controllers/query/import/sources/index.html +1 -1
  55. package/coverage/lcov-report/src/api/controllers/query/import/sources/openapi2.ts.html +1 -1
  56. package/coverage/lcov-report/src/api/controllers/query/import/sources/openapi3.ts.html +1 -1
  57. package/coverage/lcov-report/src/api/controllers/query/index.html +10 -10
  58. package/coverage/lcov-report/src/api/controllers/query/index.ts.html +17 -26
  59. package/coverage/lcov-report/src/api/controllers/query/validation.js.html +1 -1
  60. package/coverage/lcov-report/src/api/controllers/role.js.html +1 -1
  61. package/coverage/lcov-report/src/api/controllers/routing.js.html +1 -1
  62. package/coverage/lcov-report/src/api/controllers/row/ExternalRequest.ts.html +1 -1
  63. package/coverage/lcov-report/src/api/controllers/row/external.js.html +1 -1
  64. package/coverage/lcov-report/src/api/controllers/row/index.html +1 -1
  65. package/coverage/lcov-report/src/api/controllers/row/index.ts.html +1 -1
  66. package/coverage/lcov-report/src/api/controllers/row/internal.js.html +3 -3
  67. package/coverage/lcov-report/src/api/controllers/row/internalSearch.js.html +1 -1
  68. package/coverage/lcov-report/src/api/controllers/row/staticFormula.js.html +1 -1
  69. package/coverage/lcov-report/src/api/controllers/row/utils.js.html +1 -1
  70. package/coverage/lcov-report/src/api/controllers/screen.ts.html +1 -1
  71. package/coverage/lcov-report/src/api/controllers/script.js.html +1 -1
  72. package/coverage/lcov-report/src/api/controllers/static/index.html +1 -1
  73. package/coverage/lcov-report/src/api/controllers/static/index.ts.html +1 -1
  74. package/coverage/lcov-report/src/api/controllers/table/bulkFormula.js.html +1 -1
  75. package/coverage/lcov-report/src/api/controllers/table/external.js.html +1 -1
  76. package/coverage/lcov-report/src/api/controllers/table/index.html +1 -1
  77. package/coverage/lcov-report/src/api/controllers/table/index.js.html +1 -1
  78. package/coverage/lcov-report/src/api/controllers/table/internal.ts.html +1 -1
  79. package/coverage/lcov-report/src/api/controllers/table/utils.ts.html +1 -1
  80. package/coverage/lcov-report/src/api/controllers/templates.js.html +1 -1
  81. package/coverage/lcov-report/src/api/controllers/user.js.html +1 -1
  82. package/coverage/lcov-report/src/api/controllers/view/exporters.js.html +1 -1
  83. package/coverage/lcov-report/src/api/controllers/view/index.html +1 -1
  84. package/coverage/lcov-report/src/api/controllers/view/index.js.html +1 -1
  85. package/coverage/lcov-report/src/api/controllers/view/utils.js.html +1 -1
  86. package/coverage/lcov-report/src/api/controllers/view/viewBuilder.js.html +1 -1
  87. package/coverage/lcov-report/src/api/controllers/webhook.ts.html +1 -1
  88. package/coverage/lcov-report/src/api/index.html +1 -1
  89. package/coverage/lcov-report/src/api/index.js.html +1 -1
  90. package/coverage/lcov-report/src/api/routes/analytics.js.html +1 -1
  91. package/coverage/lcov-report/src/api/routes/apikeys.js.html +1 -1
  92. package/coverage/lcov-report/src/api/routes/application.ts.html +1 -1
  93. package/coverage/lcov-report/src/api/routes/auth.ts.html +1 -1
  94. package/coverage/lcov-report/src/api/routes/automation.js.html +5 -5
  95. package/coverage/lcov-report/src/api/routes/backup.ts.html +1 -1
  96. package/coverage/lcov-report/src/api/routes/cloud.js.html +1 -1
  97. package/coverage/lcov-report/src/api/routes/component.js.html +1 -1
  98. package/coverage/lcov-report/src/api/routes/datasource.js.html +6 -6
  99. package/coverage/lcov-report/src/api/routes/deploy.js.html +1 -1
  100. package/coverage/lcov-report/src/api/routes/dev.js.html +1 -1
  101. package/coverage/lcov-report/src/api/routes/index.html +1 -1
  102. package/coverage/lcov-report/src/api/routes/index.ts.html +1 -1
  103. package/coverage/lcov-report/src/api/routes/integration.js.html +1 -1
  104. package/coverage/lcov-report/src/api/routes/layout.js.html +1 -1
  105. package/coverage/lcov-report/src/api/routes/metadata.js.html +1 -1
  106. package/coverage/lcov-report/src/api/routes/migrations.js.html +1 -1
  107. package/coverage/lcov-report/src/api/routes/permission.js.html +1 -1
  108. package/coverage/lcov-report/src/api/routes/plugin.ts.html +1 -1
  109. package/coverage/lcov-report/src/api/routes/public/applications.ts.html +1 -1
  110. package/coverage/lcov-report/src/api/routes/public/index.html +1 -1
  111. package/coverage/lcov-report/src/api/routes/public/index.ts.html +11 -11
  112. package/coverage/lcov-report/src/api/routes/public/middleware/index.html +1 -1
  113. package/coverage/lcov-report/src/api/routes/public/middleware/mapper.ts.html +1 -1
  114. package/coverage/lcov-report/src/api/routes/public/queries.ts.html +1 -1
  115. package/coverage/lcov-report/src/api/routes/public/rows.ts.html +1 -1
  116. package/coverage/lcov-report/src/api/routes/public/tables.ts.html +1 -1
  117. package/coverage/lcov-report/src/api/routes/public/users.ts.html +1 -1
  118. package/coverage/lcov-report/src/api/routes/public/utils/Endpoint.ts.html +1 -1
  119. package/coverage/lcov-report/src/api/routes/public/utils/index.html +1 -1
  120. package/coverage/lcov-report/src/api/routes/query.js.html +6 -6
  121. package/coverage/lcov-report/src/api/routes/role.js.html +1 -1
  122. package/coverage/lcov-report/src/api/routes/routing.js.html +1 -1
  123. package/coverage/lcov-report/src/api/routes/row.ts.html +13 -13
  124. package/coverage/lcov-report/src/api/routes/screen.js.html +1 -1
  125. package/coverage/lcov-report/src/api/routes/script.js.html +1 -1
  126. package/coverage/lcov-report/src/api/routes/static.ts.html +6 -6
  127. package/coverage/lcov-report/src/api/routes/table.js.html +4 -4
  128. package/coverage/lcov-report/src/api/routes/templates.js.html +1 -1
  129. package/coverage/lcov-report/src/api/routes/tests/utilities/TestFunctions.ts.html +1 -1
  130. package/coverage/lcov-report/src/api/routes/tests/utilities/index.html +1 -1
  131. package/coverage/lcov-report/src/api/routes/tests/utilities/index.js.html +1 -1
  132. package/coverage/lcov-report/src/api/routes/user.js.html +11 -11
  133. package/coverage/lcov-report/src/api/routes/utils/index.html +1 -1
  134. package/coverage/lcov-report/src/api/routes/utils/validators.js.html +6 -6
  135. package/coverage/lcov-report/src/api/routes/view.js.html +4 -4
  136. package/coverage/lcov-report/src/api/routes/webhook.ts.html +1 -1
  137. package/coverage/lcov-report/src/app.ts.html +1 -1
  138. package/coverage/lcov-report/src/automations/actions.js.html +1 -1
  139. package/coverage/lcov-report/src/automations/automationUtils.js.html +1 -1
  140. package/coverage/lcov-report/src/automations/bullboard.js.html +1 -1
  141. package/coverage/lcov-report/src/automations/index.html +15 -15
  142. package/coverage/lcov-report/src/automations/index.js.html +1 -1
  143. package/coverage/lcov-report/src/automations/logging/index.html +1 -1
  144. package/coverage/lcov-report/src/automations/logging/index.ts.html +1 -1
  145. package/coverage/lcov-report/src/automations/steps/bash.js.html +1 -1
  146. package/coverage/lcov-report/src/automations/steps/createRow.ts.html +1 -1
  147. package/coverage/lcov-report/src/automations/steps/delay.js.html +1 -1
  148. package/coverage/lcov-report/src/automations/steps/deleteRow.ts.html +1 -1
  149. package/coverage/lcov-report/src/automations/steps/discord.js.html +1 -1
  150. package/coverage/lcov-report/src/automations/steps/executeQuery.js.html +1 -1
  151. package/coverage/lcov-report/src/automations/steps/executeScript.js.html +1 -1
  152. package/coverage/lcov-report/src/automations/steps/filter.js.html +1 -1
  153. package/coverage/lcov-report/src/automations/steps/index.html +1 -1
  154. package/coverage/lcov-report/src/automations/steps/integromat.js.html +1 -1
  155. package/coverage/lcov-report/src/automations/steps/loop.js.html +1 -1
  156. package/coverage/lcov-report/src/automations/steps/outgoingWebhook.js.html +1 -1
  157. package/coverage/lcov-report/src/automations/steps/queryRows.js.html +1 -1
  158. package/coverage/lcov-report/src/automations/steps/sendSmtpEmail.js.html +1 -1
  159. package/coverage/lcov-report/src/automations/steps/serverLog.js.html +1 -1
  160. package/coverage/lcov-report/src/automations/steps/slack.js.html +1 -1
  161. package/coverage/lcov-report/src/automations/steps/updateRow.js.html +1 -1
  162. package/coverage/lcov-report/src/automations/steps/utils.js.html +1 -1
  163. package/coverage/lcov-report/src/automations/steps/zapier.js.html +1 -1
  164. package/coverage/lcov-report/src/automations/tests/utilities/index.html +17 -17
  165. package/coverage/lcov-report/src/automations/tests/utilities/index.js.html +33 -15
  166. package/coverage/lcov-report/src/automations/triggerInfo/app.js.html +1 -1
  167. package/coverage/lcov-report/src/automations/triggerInfo/cron.js.html +1 -1
  168. package/coverage/lcov-report/src/automations/triggerInfo/index.html +1 -1
  169. package/coverage/lcov-report/src/automations/triggerInfo/index.js.html +1 -1
  170. package/coverage/lcov-report/src/automations/triggerInfo/rowDeleted.js.html +1 -1
  171. package/coverage/lcov-report/src/automations/triggerInfo/rowSaved.js.html +1 -1
  172. package/coverage/lcov-report/src/automations/triggerInfo/rowUpdated.js.html +1 -1
  173. package/coverage/lcov-report/src/automations/triggerInfo/webhook.js.html +1 -1
  174. package/coverage/lcov-report/src/automations/triggers.js.html +1 -1
  175. package/coverage/lcov-report/src/automations/utils.ts.html +20 -29
  176. package/coverage/lcov-report/src/constants/index.html +1 -1
  177. package/coverage/lcov-report/src/constants/index.js.html +1 -1
  178. package/coverage/lcov-report/src/constants/layouts.js.html +1 -1
  179. package/coverage/lcov-report/src/constants/screens.js.html +1 -1
  180. package/coverage/lcov-report/src/db/dynamoClient.js.html +1 -1
  181. package/coverage/lcov-report/src/db/inMemoryView.js.html +3 -3
  182. package/coverage/lcov-report/src/db/index.html +16 -16
  183. package/coverage/lcov-report/src/db/index.js.html +9 -9
  184. package/coverage/lcov-report/src/db/linkedRows/LinkController.js.html +1 -1
  185. package/coverage/lcov-report/src/db/linkedRows/index.html +1 -1
  186. package/coverage/lcov-report/src/db/linkedRows/index.js.html +1 -1
  187. package/coverage/lcov-report/src/db/linkedRows/linkUtils.js.html +1 -1
  188. package/coverage/lcov-report/src/db/newid.js.html +1 -1
  189. package/coverage/lcov-report/src/db/{utils.js.html → utils.ts.html} +97 -145
  190. package/coverage/lcov-report/src/definitions/automations.ts.html +1 -1
  191. package/coverage/lcov-report/src/definitions/datasource.ts.html +1 -1
  192. package/coverage/lcov-report/src/definitions/index.html +1 -1
  193. package/coverage/lcov-report/src/environment.js.html +4 -4
  194. package/coverage/lcov-report/src/events/AutomationEmitter.js.html +1 -1
  195. package/coverage/lcov-report/src/events/index.html +1 -1
  196. package/coverage/lcov-report/src/events/index.js.html +1 -1
  197. package/coverage/lcov-report/src/events/utils.js.html +1 -1
  198. package/coverage/lcov-report/src/index.html +1 -1
  199. package/coverage/lcov-report/src/index.ts.html +1 -1
  200. package/coverage/lcov-report/src/integrations/airtable.ts.html +1 -1
  201. package/coverage/lcov-report/src/integrations/arangodb.ts.html +1 -1
  202. package/coverage/lcov-report/src/integrations/base/index.html +1 -1
  203. package/coverage/lcov-report/src/integrations/base/query.ts.html +1 -1
  204. package/coverage/lcov-report/src/integrations/base/sql.ts.html +1 -1
  205. package/coverage/lcov-report/src/integrations/base/sqlTable.ts.html +1 -1
  206. package/coverage/lcov-report/src/integrations/base/utils.ts.html +1 -1
  207. package/coverage/lcov-report/src/integrations/couchdb.ts.html +1 -1
  208. package/coverage/lcov-report/src/integrations/dynamodb.ts.html +1 -1
  209. package/coverage/lcov-report/src/integrations/elasticsearch.ts.html +1 -1
  210. package/coverage/lcov-report/src/integrations/firebase.ts.html +1 -1
  211. package/coverage/lcov-report/src/integrations/googlesheets.ts.html +10 -19
  212. package/coverage/lcov-report/src/integrations/index.html +11 -11
  213. package/coverage/lcov-report/src/integrations/index.ts.html +1 -1
  214. package/coverage/lcov-report/src/integrations/microsoftSqlServer.ts.html +1 -1
  215. package/coverage/lcov-report/src/integrations/mongodb.ts.html +1 -1
  216. package/coverage/lcov-report/src/integrations/mysql.ts.html +1 -1
  217. package/coverage/lcov-report/src/integrations/oracle.ts.html +1 -1
  218. package/coverage/lcov-report/src/integrations/postgres.ts.html +1 -1
  219. package/coverage/lcov-report/src/integrations/queries/index.html +1 -1
  220. package/coverage/lcov-report/src/integrations/queries/sql.ts.html +1 -1
  221. package/coverage/lcov-report/src/integrations/redis.ts.html +1 -1
  222. package/coverage/lcov-report/src/integrations/rest.ts.html +1 -1
  223. package/coverage/lcov-report/src/integrations/s3.ts.html +1 -1
  224. package/coverage/lcov-report/src/integrations/snowflake.ts.html +1 -1
  225. package/coverage/lcov-report/src/integrations/tests/TestConfiguration.js.html +1 -1
  226. package/coverage/lcov-report/src/integrations/tests/index.html +1 -1
  227. package/coverage/lcov-report/src/integrations/utils.ts.html +1 -1
  228. package/coverage/lcov-report/src/middleware/{appInfo.js.html → appInfo.ts.html} +24 -21
  229. package/coverage/lcov-report/src/middleware/authorized.ts.html +7 -7
  230. package/coverage/lcov-report/src/middleware/{builder.js.html → builder.ts.html} +36 -30
  231. package/coverage/lcov-report/src/middleware/{currentapp.js.html → currentapp.ts.html} +70 -61
  232. package/coverage/lcov-report/src/middleware/index.html +55 -55
  233. package/coverage/lcov-report/src/middleware/{joi-validator.js.html → joi-validator.ts.html} +18 -15
  234. package/coverage/lcov-report/src/middleware/{publicApi.js.html → publicApi.ts.html} +17 -17
  235. package/coverage/lcov-report/src/middleware/{resourceId.js.html → resourceId.ts.html} +33 -18
  236. package/coverage/lcov-report/src/middleware/{selfhost.js.html → selfhost.ts.html} +18 -12
  237. package/coverage/lcov-report/src/middleware/{utils.js.html → utils.ts.html} +12 -6
  238. package/coverage/lcov-report/src/migrations/functions/appUrls.ts.html +1 -1
  239. package/coverage/lcov-report/src/migrations/functions/backfill/app/automations.ts.html +1 -1
  240. package/coverage/lcov-report/src/migrations/functions/backfill/app/datasources.ts.html +1 -1
  241. package/coverage/lcov-report/src/migrations/functions/backfill/app/index.html +4 -4
  242. package/coverage/lcov-report/src/migrations/functions/backfill/app/layouts.ts.html +1 -1
  243. package/coverage/lcov-report/src/migrations/functions/backfill/app/queries.ts.html +1 -1
  244. package/coverage/lcov-report/src/migrations/functions/backfill/app/roles.ts.html +1 -1
  245. package/coverage/lcov-report/src/migrations/functions/backfill/app/screens.ts.html +1 -1
  246. package/coverage/lcov-report/src/migrations/functions/backfill/app/tables.ts.html +6 -15
  247. package/coverage/lcov-report/src/migrations/functions/backfill/app.ts.html +1 -1
  248. package/coverage/lcov-report/src/migrations/functions/backfill/global/configs.ts.html +1 -1
  249. package/coverage/lcov-report/src/migrations/functions/backfill/global/index.html +1 -1
  250. package/coverage/lcov-report/src/migrations/functions/backfill/global/quotas.ts.html +1 -1
  251. package/coverage/lcov-report/src/migrations/functions/backfill/global/users.ts.html +1 -1
  252. package/coverage/lcov-report/src/migrations/functions/backfill/global.ts.html +1 -1
  253. package/coverage/lcov-report/src/migrations/functions/backfill/index.html +1 -1
  254. package/coverage/lcov-report/src/migrations/functions/backfill/index.ts.html +1 -1
  255. package/coverage/lcov-report/src/migrations/functions/backfill/installation.ts.html +1 -1
  256. package/coverage/lcov-report/src/migrations/functions/index.html +1 -1
  257. package/coverage/lcov-report/src/migrations/functions/syncQuotas.ts.html +1 -1
  258. package/coverage/lcov-report/src/migrations/functions/usageQuotas/index.html +1 -1
  259. package/coverage/lcov-report/src/migrations/functions/usageQuotas/index.ts.html +1 -1
  260. package/coverage/lcov-report/src/migrations/functions/usageQuotas/syncApps.ts.html +1 -1
  261. package/coverage/lcov-report/src/migrations/functions/usageQuotas/syncPlugins.ts.html +1 -1
  262. package/coverage/lcov-report/src/migrations/functions/usageQuotas/syncRows.ts.html +1 -1
  263. package/coverage/lcov-report/src/migrations/functions/userEmailViewCasing.ts.html +1 -1
  264. package/coverage/lcov-report/src/migrations/index.html +1 -1
  265. package/coverage/lcov-report/src/migrations/index.ts.html +1 -1
  266. package/coverage/lcov-report/src/migrations/tests/helpers.ts.html +1 -1
  267. package/coverage/lcov-report/src/migrations/tests/index.html +1 -1
  268. package/coverage/lcov-report/src/migrations/tests/structures.ts.html +1 -1
  269. package/coverage/lcov-report/src/module.d.ts.html +1 -1
  270. package/coverage/lcov-report/src/sdk/app/automations/index.html +1 -1
  271. package/coverage/lcov-report/src/sdk/app/automations/index.ts.html +1 -1
  272. package/coverage/lcov-report/src/sdk/app/automations/webhook.ts.html +1 -1
  273. package/coverage/lcov-report/src/sdk/app/backups/constants.ts.html +1 -1
  274. package/coverage/lcov-report/src/sdk/app/backups/exports.ts.html +1 -1
  275. package/coverage/lcov-report/src/sdk/app/backups/imports.ts.html +7 -16
  276. package/coverage/lcov-report/src/sdk/app/backups/index.html +1 -1
  277. package/coverage/lcov-report/src/sdk/app/backups/index.ts.html +1 -1
  278. package/coverage/lcov-report/src/sdk/app/backups/statistics.ts.html +12 -39
  279. package/coverage/lcov-report/src/sdk/app/tables/index.html +1 -1
  280. package/coverage/lcov-report/src/sdk/app/tables/index.ts.html +8 -11
  281. package/coverage/lcov-report/src/sdk/index.html +1 -1
  282. package/coverage/lcov-report/src/sdk/index.ts.html +1 -1
  283. package/coverage/lcov-report/src/startup.ts.html +1 -1
  284. package/coverage/lcov-report/src/tests/utilities/TestConfiguration.js.html +24 -24
  285. package/coverage/lcov-report/src/tests/utilities/controllers.js.html +1 -1
  286. package/coverage/lcov-report/src/tests/utilities/index.html +19 -19
  287. package/coverage/lcov-report/src/tests/utilities/index.js.html +1 -1
  288. package/coverage/lcov-report/src/tests/utilities/structures.js.html +3 -3
  289. package/coverage/lcov-report/src/threads/automation.ts.html +2 -2
  290. package/coverage/lcov-report/src/threads/index.html +1 -1
  291. package/coverage/lcov-report/src/threads/index.ts.html +1 -1
  292. package/coverage/lcov-report/src/threads/query.ts.html +1 -1
  293. package/coverage/lcov-report/src/threads/utils.ts.html +1 -1
  294. package/coverage/lcov-report/src/utilities/budibaseDir.js.html +1 -1
  295. package/coverage/lcov-report/src/utilities/centralPath.js.html +1 -1
  296. package/coverage/lcov-report/src/utilities/csvParser.js.html +1 -1
  297. package/coverage/lcov-report/src/utilities/fileSystem/clientLibrary.js.html +1 -1
  298. package/coverage/lcov-report/src/utilities/fileSystem/index.html +1 -1
  299. package/coverage/lcov-report/src/utilities/fileSystem/index.js.html +1 -1
  300. package/coverage/lcov-report/src/utilities/fileSystem/processor.js.html +1 -1
  301. package/coverage/lcov-report/src/utilities/fileSystem/utilities.js.html +1 -1
  302. package/coverage/lcov-report/src/utilities/{global.js.html → global.ts.html} +100 -67
  303. package/coverage/lcov-report/src/utilities/index.html +16 -16
  304. package/coverage/lcov-report/src/utilities/index.js.html +1 -1
  305. package/coverage/lcov-report/src/utilities/plugins.js.html +1 -1
  306. package/coverage/lcov-report/src/utilities/queue/inMemoryQueue.js.html +1 -1
  307. package/coverage/lcov-report/src/utilities/queue/index.html +1 -1
  308. package/coverage/lcov-report/src/utilities/redis.js.html +1 -1
  309. package/coverage/lcov-report/src/utilities/routing/index.html +1 -1
  310. package/coverage/lcov-report/src/utilities/routing/index.js.html +1 -1
  311. package/coverage/lcov-report/src/utilities/rowProcessor/index.html +1 -1
  312. package/coverage/lcov-report/src/utilities/rowProcessor/index.js.html +1 -1
  313. package/coverage/lcov-report/src/utilities/rowProcessor/utils.js.html +1 -1
  314. package/coverage/lcov-report/src/utilities/scriptRunner.js.html +1 -1
  315. package/coverage/lcov-report/src/utilities/security.js.html +13 -13
  316. package/coverage/lcov-report/src/utilities/statusCodes.js.html +1 -1
  317. package/coverage/lcov-report/src/utilities/usageQuota/index.html +1 -1
  318. package/coverage/lcov-report/src/utilities/usageQuota/rows.js.html +1 -1
  319. package/coverage/lcov-report/src/utilities/usageQuota/usageQuoteReset.js.html +1 -1
  320. package/coverage/lcov-report/src/utilities/users.js.html +1 -1
  321. package/coverage/lcov-report/src/utilities/workerRequests.js.html +4 -4
  322. package/coverage/lcov-report/src/watch.ts.html +1 -1
  323. package/coverage/lcov-report/src/websocket.ts.html +1 -1
  324. package/coverage/lcov.info +2052 -2049
  325. package/dist/api/controllers/application.js +35 -43
  326. package/dist/api/controllers/deploy/index.js +13 -16
  327. package/dist/api/controllers/dev.js +96 -81
  328. package/dist/api/controllers/public/applications.js +17 -9
  329. package/dist/api/controllers/query/index.js +10 -13
  330. package/dist/api/controllers/row/internal.js +2 -2
  331. package/dist/api/routes/automation.js +3 -3
  332. package/dist/api/routes/datasource.js +4 -4
  333. package/dist/api/routes/public/index.js +9 -9
  334. package/dist/api/routes/query.js +4 -4
  335. package/dist/api/routes/row.js +11 -11
  336. package/dist/api/routes/static.js +3 -3
  337. package/dist/api/routes/table.js +2 -2
  338. package/dist/api/routes/user.js +9 -9
  339. package/dist/api/routes/utils/validators.js +4 -4
  340. package/dist/api/routes/view.js +2 -2
  341. package/dist/automations/tests/utilities/index.js +21 -12
  342. package/dist/automations/utils.js +9 -8
  343. package/dist/db/inMemoryView.js +2 -2
  344. package/dist/db/utils.js +145 -118
  345. package/dist/integrations/googlesheets.js +4 -6
  346. package/dist/middleware/appInfo.js +14 -9
  347. package/dist/middleware/authorized.js +5 -5
  348. package/dist/middleware/builder.js +41 -40
  349. package/dist/middleware/currentapp.js +39 -37
  350. package/dist/middleware/joi-validator.js +17 -10
  351. package/dist/middleware/publicApi.js +5 -6
  352. package/dist/middleware/resourceId.js +16 -9
  353. package/dist/middleware/selfhost.js +5 -4
  354. package/dist/middleware/utils.js +5 -2
  355. package/dist/package.json +6 -6
  356. package/dist/sdk/app/tables/index.js +4 -4
  357. package/dist/tests/utilities/TestConfiguration.js +9 -9
  358. package/dist/tests/utilities/structures.js +2 -2
  359. package/dist/tsconfig.build.tsbuildinfo +1 -1
  360. package/dist/utilities/global.js +87 -66
  361. package/dist/utilities/security.js +10 -10
  362. package/dist/utilities/workerRequests.js +3 -3
  363. package/jest.config.ts +1 -0
  364. package/package.json +7 -7
  365. package/src/api/controllers/application.ts +34 -39
  366. package/src/api/controllers/auth.ts +3 -2
  367. package/src/api/controllers/deploy/index.ts +13 -25
  368. package/src/api/controllers/{dev.js → dev.ts} +31 -37
  369. package/src/api/controllers/public/applications.ts +15 -9
  370. package/src/api/controllers/query/index.ts +11 -14
  371. package/src/api/controllers/row/internal.js +2 -2
  372. package/src/api/routes/automation.js +4 -4
  373. package/src/api/routes/datasource.js +5 -5
  374. package/src/api/routes/public/index.ts +10 -10
  375. package/src/api/routes/public/tests/compare.spec.js +1 -1
  376. package/src/api/routes/query.js +5 -5
  377. package/src/api/routes/row.ts +12 -12
  378. package/src/api/routes/static.ts +5 -5
  379. package/src/api/routes/table.js +3 -3
  380. package/src/api/routes/tests/analytics.spec.js +1 -1
  381. package/src/api/routes/tests/query.spec.js +15 -10
  382. package/src/api/routes/tests/role.spec.js +5 -5
  383. package/src/api/routes/tests/static.spec.js +2 -2
  384. package/src/api/routes/tests/table.spec.js +38 -35
  385. package/src/api/routes/user.js +10 -10
  386. package/src/api/routes/utils/validators.js +5 -5
  387. package/src/api/routes/view.js +3 -3
  388. package/src/automations/tests/updateRow.spec.js +0 -1
  389. package/src/automations/tests/utilities/index.js +10 -4
  390. package/src/automations/utils.ts +9 -12
  391. package/src/db/inMemoryView.js +2 -2
  392. package/src/db/tests/linkController.spec.js +73 -57
  393. package/src/db/tests/linkTests.spec.js +17 -14
  394. package/src/db/{utils.js → utils.ts} +76 -92
  395. package/src/integrations/googlesheets.ts +4 -7
  396. package/src/middleware/appInfo.ts +20 -0
  397. package/src/middleware/authorized.ts +6 -6
  398. package/src/middleware/{builder.js → builder.ts} +17 -15
  399. package/src/middleware/{currentapp.js → currentapp.ts} +42 -39
  400. package/src/middleware/{joi-validator.js → joi-validator.ts} +9 -8
  401. package/src/middleware/publicApi.ts +21 -0
  402. package/src/middleware/{resourceId.js → resourceId.ts} +16 -11
  403. package/src/middleware/{selfhost.js → selfhost.ts} +4 -2
  404. package/src/middleware/tests/authorized.spec.js +5 -5
  405. package/src/middleware/tests/currentapp.spec.js +118 -63
  406. package/src/middleware/{utils.js → utils.ts} +3 -1
  407. package/src/migrations/functions/backfill/app/tables.ts +2 -5
  408. package/src/sdk/app/backups/imports.ts +4 -7
  409. package/src/sdk/app/backups/statistics.ts +9 -18
  410. package/src/sdk/app/tables/index.ts +6 -7
  411. package/src/tests/utilities/TestConfiguration.js +9 -9
  412. package/src/tests/utilities/structures.js +2 -2
  413. package/src/threads/automation.ts +1 -1
  414. package/src/utilities/global.ts +138 -0
  415. package/src/utilities/security.js +12 -12
  416. package/src/utilities/workerRequests.js +3 -3
  417. package/src/middleware/appInfo.js +0 -19
  418. package/src/middleware/publicApi.js +0 -21
  419. package/src/utilities/global.js +0 -127
@@ -1,30 +1,34 @@
1
1
  const TestConfig = require("../../tests/utilities/TestConfiguration")
2
2
  const { basicTable } = require("../../tests/utilities/structures")
3
3
  const linkUtils = require("../linkedRows/linkUtils")
4
- const { getAppDB } = require("@budibase/backend-core/context")
5
- const { doWithDB } = require("@budibase/backend-core/db")
4
+ const { context } = require("@budibase/backend-core")
6
5
 
7
6
  describe("test link functionality", () => {
8
7
  const config = new TestConfig(false)
8
+ let appId
9
9
 
10
10
  describe("getLinkedTable", () => {
11
- let db, table
11
+ let table
12
12
  beforeEach(async () => {
13
- await config.init()
14
- db = getAppDB()
13
+ const app = await config.init()
14
+ appId = app.appId
15
15
  table = await config.createTable()
16
16
  })
17
17
 
18
18
  it("should be able to retrieve a linked table from a list", async () => {
19
- const retrieved = await linkUtils.getLinkedTable(table._id, [table])
20
- expect(retrieved._id).toBe(table._id)
19
+ await context.doInAppContext(appId, async () => {
20
+ const retrieved = await linkUtils.getLinkedTable(table._id, [table])
21
+ expect(retrieved._id).toBe(table._id)
22
+ })
21
23
  })
22
24
 
23
25
  it("should be able to retrieve a table from DB and update list", async () => {
24
26
  const tables = []
25
- const retrieved = await linkUtils.getLinkedTable(table._id, tables)
26
- expect(retrieved._id).toBe(table._id)
27
- expect(tables[0]).toBeDefined()
27
+ await context.doInAppContext(appId, async () => {
28
+ const retrieved = await linkUtils.getLinkedTable(table._id, tables)
29
+ expect(retrieved._id).toBe(table._id)
30
+ expect(tables[0]).toBeDefined()
31
+ })
28
32
  })
29
33
  })
30
34
 
@@ -48,15 +52,14 @@ describe("test link functionality", () => {
48
52
  describe("getLinkDocuments", () => {
49
53
  it("should create the link view when it doesn't exist", async () => {
50
54
  // create the DB and a very basic app design DB
51
- const output = await doWithDB("test", async db => {
52
- await db.put({ _id: "_design/database", views: {} })
53
- return await linkUtils.getLinkDocuments({
55
+ await context.doInAppContext(appId, async () => {
56
+ const output = await linkUtils.getLinkDocuments({
54
57
  tableId: "test",
55
58
  rowId: "test",
56
59
  includeDocs: false,
57
60
  })
61
+ expect(Array.isArray(output)).toBe(true)
58
62
  })
59
- expect(Array.isArray(output)).toBe(true)
60
63
  })
61
64
  })
62
65
  })
@@ -1,44 +1,19 @@
1
- const newid = require("./newid")
2
- const {
3
- DocumentType: CoreDocType,
4
- InternalTable,
5
- getRoleParams,
6
- generateRoleID,
7
- APP_DEV_PREFIX,
8
- APP_PREFIX,
9
- SEPARATOR,
10
- StaticDatabases,
11
- isDevAppID,
12
- isProdAppID,
13
- getDevelopmentAppID,
14
- generateAppID,
15
- getQueryIndex,
16
- ViewName,
17
- getDocParams,
18
- getRowParams,
19
- generateRowID,
20
- getUserMetadataParams,
21
- generateUserMetadataID,
22
- getGlobalIDFromUserMetadataID,
23
- } = require("@budibase/backend-core/db")
24
-
25
- const UNICODE_MAX = "\ufff0"
26
-
27
- const AppStatus = {
1
+ import newid from "./newid"
2
+ import { db as dbCore } from "@budibase/backend-core"
3
+
4
+ type Optional = string | null
5
+
6
+ export const AppStatus = {
28
7
  DEV: "development",
29
8
  ALL: "all",
30
9
  DEPLOYED: "published",
31
10
  }
32
11
 
33
- const DocumentType = CoreDocType
34
-
35
- const SearchIndexes = {
12
+ export const SearchIndexes = {
36
13
  ROWS: "rows",
37
14
  }
38
15
 
39
- exports.StaticDatabases = StaticDatabases
40
-
41
- const BudibaseInternalDB = {
16
+ export const BudibaseInternalDB = {
42
17
  _id: "bb_internal",
43
18
  type: "budibase",
44
19
  name: "Budibase DB",
@@ -46,37 +21,36 @@ const BudibaseInternalDB = {
46
21
  config: {},
47
22
  }
48
23
 
49
- exports.APP_PREFIX = APP_PREFIX
50
- exports.APP_DEV_PREFIX = APP_DEV_PREFIX
51
- exports.isDevAppID = isDevAppID
52
- exports.isProdAppID = isProdAppID
53
- exports.USER_METDATA_PREFIX = `${DocumentType.ROW}${SEPARATOR}${InternalTable.USER_METADATA}${SEPARATOR}`
54
- exports.LINK_USER_METADATA_PREFIX = `${DocumentType.LINK}${SEPARATOR}${InternalTable.USER_METADATA}${SEPARATOR}`
55
- exports.TABLE_ROW_PREFIX = `${DocumentType.ROW}${SEPARATOR}${DocumentType.TABLE}`
56
- exports.ViewName = ViewName
57
- exports.InternalTables = InternalTable
58
- exports.DocumentType = DocumentType
59
- exports.SEPARATOR = SEPARATOR
60
- exports.UNICODE_MAX = UNICODE_MAX
61
- exports.SearchIndexes = SearchIndexes
62
- exports.AppStatus = AppStatus
63
- exports.BudibaseInternalDB = BudibaseInternalDB
64
- exports.generateAppID = generateAppID
65
- exports.generateDevAppID = getDevelopmentAppID
66
- exports.generateRoleID = generateRoleID
67
- exports.getRoleParams = getRoleParams
68
- exports.getQueryIndex = getQueryIndex
69
- exports.getDocParams = getDocParams
70
- exports.getRowParams = getRowParams
71
- exports.generateRowID = generateRowID
72
- exports.getUserMetadataParams = getUserMetadataParams
73
- exports.generateUserMetadataID = generateUserMetadataID
74
- exports.getGlobalIDFromUserMetadataID = getGlobalIDFromUserMetadataID
24
+ export const SEPARATOR = dbCore.SEPARATOR
25
+ export const StaticDatabases = dbCore.StaticDatabases
26
+ export const DocumentType = dbCore.DocumentType
27
+ export const APP_PREFIX = dbCore.APP_PREFIX
28
+ export const APP_DEV_PREFIX = dbCore.APP_DEV_PREFIX
29
+ export const isDevAppID = dbCore.isDevAppID
30
+ export const isProdAppID = dbCore.isProdAppID
31
+ export const USER_METDATA_PREFIX = `${DocumentType.ROW}${SEPARATOR}${dbCore.InternalTable.USER_METADATA}${SEPARATOR}`
32
+ export const LINK_USER_METADATA_PREFIX = `${DocumentType.LINK}${SEPARATOR}${dbCore.InternalTable.USER_METADATA}${SEPARATOR}`
33
+ export const TABLE_ROW_PREFIX = `${DocumentType.ROW}${SEPARATOR}${DocumentType.TABLE}`
34
+ export const ViewName = dbCore.ViewName
35
+ export const InternalTables = dbCore.InternalTable
36
+ export const UNICODE_MAX = dbCore.UNICODE_MAX
37
+ export const generateAppID = dbCore.generateAppID
38
+ export const generateDevAppID = dbCore.getDevelopmentAppID
39
+ export const generateRoleID = dbCore.generateRoleID
40
+ export const getRoleParams = dbCore.getRoleParams
41
+ export const getQueryIndex = dbCore.getQueryIndex
42
+ export const getDocParams = dbCore.getDocParams
43
+ export const getRowParams = dbCore.getRowParams
44
+ export const generateRowID = dbCore.generateRowID
45
+ export const getUserMetadataParams = dbCore.getUserMetadataParams
46
+ export const generateUserMetadataID = dbCore.generateUserMetadataID
47
+ export const getGlobalIDFromUserMetadataID =
48
+ dbCore.getGlobalIDFromUserMetadataID
75
49
 
76
50
  /**
77
51
  * Gets parameters for retrieving tables, this is a utility function for the getDocParams function.
78
52
  */
79
- exports.getTableParams = (tableId = null, otherProps = {}) => {
53
+ export function getTableParams(tableId?: Optional, otherProps = {}) {
80
54
  return getDocParams(DocumentType.TABLE, tableId, otherProps)
81
55
  }
82
56
 
@@ -84,7 +58,7 @@ exports.getTableParams = (tableId = null, otherProps = {}) => {
84
58
  * Generates a new table ID.
85
59
  * @returns {string} The new table ID which the table doc can be stored under.
86
60
  */
87
- exports.generateTableID = () => {
61
+ export function generateTableID() {
88
62
  return `${DocumentType.TABLE}${SEPARATOR}${newid()}`
89
63
  }
90
64
 
@@ -93,7 +67,7 @@ exports.generateTableID = () => {
93
67
  * @param {string} rowId The ID of the row.
94
68
  * @returns {string} The table ID.
95
69
  */
96
- exports.getTableIDFromRowID = rowId => {
70
+ export function getTableIDFromRowID(rowId: string) {
97
71
  const components = rowId
98
72
  .split(DocumentType.TABLE + SEPARATOR)[1]
99
73
  .split(SEPARATOR)
@@ -103,7 +77,10 @@ exports.getTableIDFromRowID = rowId => {
103
77
  /**
104
78
  * Gets parameters for retrieving automations, this is a utility function for the getDocParams function.
105
79
  */
106
- exports.getAutomationParams = (automationId = null, otherProps = {}) => {
80
+ export function getAutomationParams(
81
+ automationId?: Optional,
82
+ otherProps: any = {}
83
+ ) {
107
84
  return getDocParams(DocumentType.AUTOMATION, automationId, otherProps)
108
85
  }
109
86
 
@@ -111,7 +88,7 @@ exports.getAutomationParams = (automationId = null, otherProps = {}) => {
111
88
  * Generates a new automation ID.
112
89
  * @returns {string} The new automation ID which the automation doc can be stored under.
113
90
  */
114
- exports.generateAutomationID = () => {
91
+ export function generateAutomationID() {
115
92
  return `${DocumentType.AUTOMATION}${SEPARATOR}${newid()}`
116
93
  }
117
94
 
@@ -126,14 +103,14 @@ exports.generateAutomationID = () => {
126
103
  * @param {string} fieldName2 the name of the field in the linked row.
127
104
  * @returns {string} The new link doc ID which the automation doc can be stored under.
128
105
  */
129
- exports.generateLinkID = (
130
- tableId1,
131
- tableId2,
132
- rowId1,
133
- rowId2,
134
- fieldName1,
135
- fieldName2
136
- ) => {
106
+ export function generateLinkID(
107
+ tableId1: string,
108
+ tableId2: string,
109
+ rowId1: string,
110
+ rowId2: string,
111
+ fieldName1: string,
112
+ fieldName2: string
113
+ ) {
137
114
  const tables = `${SEPARATOR}${tableId1}${SEPARATOR}${tableId2}`
138
115
  const rows = `${SEPARATOR}${rowId1}${SEPARATOR}${rowId2}`
139
116
  const fields = `${SEPARATOR}${fieldName1}${SEPARATOR}${fieldName2}`
@@ -143,7 +120,7 @@ exports.generateLinkID = (
143
120
  /**
144
121
  * Gets parameters for retrieving link docs, this is a utility function for the getDocParams function.
145
122
  */
146
- exports.getLinkParams = (otherProps = {}) => {
123
+ export function getLinkParams(otherProps: any = {}) {
147
124
  return getDocParams(DocumentType.LINK, null, otherProps)
148
125
  }
149
126
 
@@ -151,14 +128,14 @@ exports.getLinkParams = (otherProps = {}) => {
151
128
  * Generates a new layout ID.
152
129
  * @returns {string} The new layout ID which the layout doc can be stored under.
153
130
  */
154
- exports.generateLayoutID = id => {
131
+ export function generateLayoutID(id: string) {
155
132
  return `${DocumentType.LAYOUT}${SEPARATOR}${id || newid()}`
156
133
  }
157
134
 
158
135
  /**
159
136
  * Gets parameters for retrieving layout, this is a utility function for the getDocParams function.
160
137
  */
161
- exports.getLayoutParams = (layoutId = null, otherProps = {}) => {
138
+ export function getLayoutParams(layoutId?: Optional, otherProps: any = {}) {
162
139
  return getDocParams(DocumentType.LAYOUT, layoutId, otherProps)
163
140
  }
164
141
 
@@ -166,14 +143,14 @@ exports.getLayoutParams = (layoutId = null, otherProps = {}) => {
166
143
  * Generates a new screen ID.
167
144
  * @returns {string} The new screen ID which the screen doc can be stored under.
168
145
  */
169
- exports.generateScreenID = () => {
146
+ export function generateScreenID() {
170
147
  return `${DocumentType.SCREEN}${SEPARATOR}${newid()}`
171
148
  }
172
149
 
173
150
  /**
174
151
  * Gets parameters for retrieving screens, this is a utility function for the getDocParams function.
175
152
  */
176
- exports.getScreenParams = (screenId = null, otherProps = {}) => {
153
+ export function getScreenParams(screenId?: Optional, otherProps: any = {}) {
177
154
  return getDocParams(DocumentType.SCREEN, screenId, otherProps)
178
155
  }
179
156
 
@@ -181,14 +158,14 @@ exports.getScreenParams = (screenId = null, otherProps = {}) => {
181
158
  * Generates a new webhook ID.
182
159
  * @returns {string} The new webhook ID which the webhook doc can be stored under.
183
160
  */
184
- exports.generateWebhookID = () => {
161
+ export function generateWebhookID() {
185
162
  return `${DocumentType.WEBHOOK}${SEPARATOR}${newid()}`
186
163
  }
187
164
 
188
165
  /**
189
166
  * Gets parameters for retrieving a webhook, this is a utility function for the getDocParams function.
190
167
  */
191
- exports.getWebhookParams = (webhookId = null, otherProps = {}) => {
168
+ export function getWebhookParams(webhookId?: Optional, otherProps: any = {}) {
192
169
  return getDocParams(DocumentType.WEBHOOK, webhookId, otherProps)
193
170
  }
194
171
 
@@ -196,7 +173,7 @@ exports.getWebhookParams = (webhookId = null, otherProps = {}) => {
196
173
  * Generates a new datasource ID.
197
174
  * @returns {string} The new datasource ID which the webhook doc can be stored under.
198
175
  */
199
- exports.generateDatasourceID = ({ plus = false } = {}) => {
176
+ export function generateDatasourceID({ plus = false } = {}) {
200
177
  return `${
201
178
  plus ? DocumentType.DATASOURCE_PLUS : DocumentType.DATASOURCE
202
179
  }${SEPARATOR}${newid()}`
@@ -205,7 +182,10 @@ exports.generateDatasourceID = ({ plus = false } = {}) => {
205
182
  /**
206
183
  * Gets parameters for retrieving a datasource, this is a utility function for the getDocParams function.
207
184
  */
208
- exports.getDatasourceParams = (datasourceId = null, otherProps = {}) => {
185
+ export function getDatasourceParams(
186
+ datasourceId?: Optional,
187
+ otherProps: any = {}
188
+ ) {
209
189
  return getDocParams(DocumentType.DATASOURCE, datasourceId, otherProps)
210
190
  }
211
191
 
@@ -213,7 +193,7 @@ exports.getDatasourceParams = (datasourceId = null, otherProps = {}) => {
213
193
  * Generates a new query ID.
214
194
  * @returns {string} The new query ID which the query doc can be stored under.
215
195
  */
216
- exports.generateQueryID = datasourceId => {
196
+ export function generateQueryID(datasourceId: string) {
217
197
  return `${
218
198
  DocumentType.QUERY
219
199
  }${SEPARATOR}${datasourceId}${SEPARATOR}${newid()}`
@@ -223,21 +203,21 @@ exports.generateQueryID = datasourceId => {
223
203
  * Generates a metadata ID for automations, used to track errors in recurring
224
204
  * automations etc.
225
205
  */
226
- exports.generateAutomationMetadataID = automationId => {
206
+ export function generateAutomationMetadataID(automationId: string) {
227
207
  return `${DocumentType.AUTOMATION_METADATA}${SEPARATOR}${automationId}`
228
208
  }
229
209
 
230
210
  /**
231
211
  * Retrieve all automation metadata in an app database.
232
212
  */
233
- exports.getAutomationMetadataParams = (otherProps = {}) => {
213
+ export function getAutomationMetadataParams(otherProps: any = {}) {
234
214
  return getDocParams(DocumentType.AUTOMATION_METADATA, null, otherProps)
235
215
  }
236
216
 
237
217
  /**
238
218
  * Gets parameters for retrieving a query, this is a utility function for the getDocParams function.
239
219
  */
240
- exports.getQueryParams = (datasourceId = null, otherProps = {}) => {
220
+ export function getQueryParams(datasourceId?: Optional, otherProps: any = {}) {
241
221
  if (datasourceId == null) {
242
222
  return getDocParams(DocumentType.QUERY, null, otherProps)
243
223
  }
@@ -253,15 +233,19 @@ exports.getQueryParams = (datasourceId = null, otherProps = {}) => {
253
233
  * Generates a new flag document ID.
254
234
  * @returns {string} The ID of the flag document that was generated.
255
235
  */
256
- exports.generateUserFlagID = userId => {
236
+ export function generateUserFlagID(userId: string) {
257
237
  return `${DocumentType.USER_FLAG}${SEPARATOR}${userId}`
258
238
  }
259
239
 
260
- exports.generateMetadataID = (type, entityId) => {
240
+ export function generateMetadataID(type: string, entityId: string) {
261
241
  return `${DocumentType.METADATA}${SEPARATOR}${type}${SEPARATOR}${entityId}`
262
242
  }
263
243
 
264
- exports.getMetadataParams = (type, entityId = null, otherProps = {}) => {
244
+ export function getMetadataParams(
245
+ type: string,
246
+ entityId?: Optional,
247
+ otherProps: any = {}
248
+ ) {
265
249
  let docId = `${type}${SEPARATOR}`
266
250
  if (entityId != null) {
267
251
  docId += entityId
@@ -269,22 +253,22 @@ exports.getMetadataParams = (type, entityId = null, otherProps = {}) => {
269
253
  return getDocParams(DocumentType.METADATA, docId, otherProps)
270
254
  }
271
255
 
272
- exports.generateMemoryViewID = viewName => {
256
+ export function generateMemoryViewID(viewName: string) {
273
257
  return `${DocumentType.MEM_VIEW}${SEPARATOR}${viewName}`
274
258
  }
275
259
 
276
- exports.getMemoryViewParams = (otherProps = {}) => {
260
+ export function getMemoryViewParams(otherProps: any = {}) {
277
261
  return getDocParams(DocumentType.MEM_VIEW, null, otherProps)
278
262
  }
279
263
 
280
- exports.generatePluginID = name => {
264
+ export function generatePluginID(name: string) {
281
265
  return `${DocumentType.PLUGIN}${SEPARATOR}${name}`
282
266
  }
283
267
 
284
268
  /**
285
269
  * This can be used with the db.allDocs to get a list of IDs
286
270
  */
287
- exports.getMultiIDParams = ids => {
271
+ export function getMultiIDParams(ids: string[]) {
288
272
  return {
289
273
  keys: ids,
290
274
  include_docs: true,
@@ -12,10 +12,7 @@ import { buildExternalTableId } from "./utils"
12
12
  import { DataSourceOperation, FieldTypes } from "../constants"
13
13
  import { GoogleSpreadsheet } from "google-spreadsheet"
14
14
  import env from "../environment"
15
-
16
- const { getGlobalDB } = require("@budibase/backend-core/tenancy")
17
- const { getScopedConfig } = require("@budibase/backend-core/db")
18
- const { Configs } = require("@budibase/backend-core/constants")
15
+ import { tenancy, db as dbCore, constants } from "@budibase/backend-core"
19
16
  const fetch = require("node-fetch")
20
17
 
21
18
  interface GoogleSheetsConfig {
@@ -176,9 +173,9 @@ class GoogleSheetsIntegration implements DatasourcePlus {
176
173
  async connect() {
177
174
  try {
178
175
  // Initialise oAuth client
179
- const db = getGlobalDB()
180
- let googleConfig = await getScopedConfig(db, {
181
- type: Configs.GOOGLE,
176
+ const db = tenancy.getGlobalDB()
177
+ let googleConfig = await dbCore.getScopedConfig(db, {
178
+ type: constants.Config.GOOGLE,
182
179
  })
183
180
 
184
181
  if (!googleConfig) {
@@ -0,0 +1,20 @@
1
+ import { isDevAppID, isProdAppID } from "../db/utils"
2
+ import { BBContext } from "@budibase/types"
3
+
4
+ export enum AppType {
5
+ DEV = "dev",
6
+ PROD = "prod",
7
+ }
8
+
9
+ export function middleware({ appType }: { appType?: AppType } = {}) {
10
+ return (ctx: BBContext, next: any) => {
11
+ const appId = ctx.appId
12
+ if (appType === AppType.DEV && appId && !isDevAppID(appId)) {
13
+ ctx.throw(400, "Only apps in development support this endpoint")
14
+ }
15
+ if (appType === AppType.PROD && appId && !isProdAppID(appId)) {
16
+ ctx.throw(400, "Only apps in production support this endpoint")
17
+ }
18
+ return next()
19
+ }
20
+ }
@@ -4,8 +4,8 @@ import {
4
4
  BUILTIN_ROLE_IDS,
5
5
  } from "@budibase/backend-core/roles"
6
6
  const {
7
- PermissionTypes,
8
- PermissionLevels,
7
+ PermissionType,
8
+ PermissionLevel,
9
9
  doesHaveBasePermission,
10
10
  } = require("@budibase/backend-core/permissions")
11
11
  const builderMiddleware = require("./builder")
@@ -33,7 +33,7 @@ const checkAuthorized = async (
33
33
  ) => {
34
34
  // check if this is a builder api and the user is not a builder
35
35
  const isBuilder = ctx.user && ctx.user.builder && ctx.user.builder.global
36
- const isBuilderApi = permType === PermissionTypes.BUILDER
36
+ const isBuilderApi = permType === PermissionType.BUILDER
37
37
  if (isBuilderApi && !isBuilder) {
38
38
  return ctx.throw(403, "Not Authorized")
39
39
  }
@@ -91,9 +91,9 @@ export = (permType: any, permLevel: any = null, opts = { schema: false }) =>
91
91
  let resourceRoles: any = []
92
92
  let otherLevelRoles: any = []
93
93
  const otherLevel =
94
- permLevel === PermissionLevels.READ
95
- ? PermissionLevels.WRITE
96
- : PermissionLevels.READ
94
+ permLevel === PermissionLevel.READ
95
+ ? PermissionLevel.WRITE
96
+ : PermissionLevel.READ
97
97
  const appId = getAppId()
98
98
  if (appId && hasResource(ctx)) {
99
99
  resourceRoles = await getRequiredResourceRole(permLevel, ctx)
@@ -1,14 +1,16 @@
1
- const { APP_DEV_PREFIX } = require("../db/utils")
2
- const {
1
+ import {
2
+ APP_DEV_PREFIX,
3
+ DocumentType,
4
+ getGlobalIDFromUserMetadataID,
5
+ } from "../db/utils"
6
+ import {
3
7
  doesUserHaveLock,
4
8
  updateLock,
5
9
  checkDebounce,
6
10
  setDebounce,
7
- } = require("../utilities/redis")
8
- const { doWithDB } = require("@budibase/backend-core/db")
9
- const { DocumentType, getGlobalIDFromUserMetadataID } = require("../db/utils")
10
- const { PermissionTypes } = require("@budibase/backend-core/permissions")
11
- const { app: appCache } = require("@budibase/backend-core/cache")
11
+ } from "../utilities/redis"
12
+ import { db as dbCore, cache, permissions } from "@budibase/backend-core"
13
+ import { BBContext, Database } from "@budibase/types"
12
14
 
13
15
  const DEBOUNCE_TIME_SEC = 30
14
16
 
@@ -21,11 +23,11 @@ const DEBOUNCE_TIME_SEC = 30
21
23
  * through the authorized middleware *
22
24
  ****************************************************/
23
25
 
24
- async function checkDevAppLocks(ctx) {
26
+ async function checkDevAppLocks(ctx: BBContext) {
25
27
  const appId = ctx.appId
26
28
 
27
29
  // if any public usage, don't proceed
28
- if (!ctx.user._id && !ctx.user.userId) {
30
+ if (!ctx.user?._id && !ctx.user?.userId) {
29
31
  return
30
32
  }
31
33
 
@@ -41,34 +43,34 @@ async function checkDevAppLocks(ctx) {
41
43
  await updateLock(appId, ctx.user)
42
44
  }
43
45
 
44
- async function updateAppUpdatedAt(ctx) {
46
+ async function updateAppUpdatedAt(ctx: BBContext) {
45
47
  const appId = ctx.appId
46
48
  // if debouncing skip this update
47
49
  // get methods also aren't updating
48
50
  if (ctx.method === "GET" || (await checkDebounce(appId))) {
49
51
  return
50
52
  }
51
- await doWithDB(appId, async db => {
53
+ await dbCore.doWithDB(appId, async (db: Database) => {
52
54
  const metadata = await db.get(DocumentType.APP_METADATA)
53
55
  metadata.updatedAt = new Date().toISOString()
54
56
 
55
- metadata.updatedBy = getGlobalIDFromUserMetadataID(ctx.user.userId)
57
+ metadata.updatedBy = getGlobalIDFromUserMetadataID(ctx.user?.userId!)
56
58
 
57
59
  const response = await db.put(metadata)
58
60
  metadata._rev = response.rev
59
- await appCache.invalidateAppMetadata(appId, metadata)
61
+ await cache.app.invalidateAppMetadata(appId, metadata)
60
62
  // set a new debounce record with a short TTL
61
63
  await setDebounce(appId, DEBOUNCE_TIME_SEC)
62
64
  })
63
65
  }
64
66
 
65
- module.exports = async (ctx, permType) => {
67
+ export = async function builder(ctx: BBContext, permType: string) {
66
68
  const appId = ctx.appId
67
69
  // this only functions within an app context
68
70
  if (!appId) {
69
71
  return
70
72
  }
71
- const isBuilderApi = permType === PermissionTypes.BUILDER
73
+ const isBuilderApi = permType === permissions.PermissionType.BUILDER
72
74
  const referer = ctx.headers["referer"]
73
75
 
74
76
  const overviewPath = "/builder/portal/overview/"