@budibase/server 2.2.12-alpha.7 → 2.2.12-alpha.70

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 (484) hide show
  1. package/Dockerfile +1 -1
  2. package/__mocks__/node-fetch.ts +2 -0
  3. package/builder/assets/{bb-emblem.4e4717da.svg → bb-emblem.05f7ae7a.svg} +1 -1
  4. package/builder/assets/bg.29e85dd5.png +0 -0
  5. package/builder/assets/bulgaria.bd68393d.png +0 -0
  6. package/builder/assets/covanta.72c46c1e.png +0 -0
  7. package/builder/assets/index.80bd6b61.css +6 -0
  8. package/builder/assets/index.c1b13e6f.js +1798 -0
  9. package/builder/assets/schnellecke.cf1837a8.png +0 -0
  10. package/builder/index.html +3 -3
  11. package/coverage/clover.xml +5113 -4924
  12. package/coverage/coverage-final.json +268 -264
  13. package/coverage/lcov-report/index.html +202 -157
  14. package/coverage/lcov-report/src/api/controllers/analytics.ts.html +6 -6
  15. package/coverage/lcov-report/src/api/controllers/apikeys.ts.html +5 -5
  16. package/coverage/lcov-report/src/api/controllers/application.ts.html +185 -164
  17. package/coverage/lcov-report/src/api/controllers/auth.ts.html +9 -9
  18. package/coverage/lcov-report/src/api/controllers/automation.ts.html +24 -24
  19. package/coverage/lcov-report/src/api/controllers/backup.ts.html +6 -6
  20. package/coverage/lcov-report/src/api/controllers/cloud.ts.html +15 -15
  21. package/coverage/lcov-report/src/api/controllers/component.ts.html +5 -5
  22. package/coverage/lcov-report/src/api/controllers/datasource.ts.html +112 -88
  23. package/coverage/lcov-report/src/api/controllers/deploy/Deployment.ts.html +14 -14
  24. package/coverage/lcov-report/src/api/controllers/deploy/index.html +1 -1
  25. package/coverage/lcov-report/src/api/controllers/deploy/index.ts.html +80 -80
  26. package/coverage/lcov-report/src/api/controllers/dev.ts.html +17 -17
  27. package/coverage/lcov-report/src/api/controllers/index.html +36 -36
  28. package/coverage/lcov-report/src/api/controllers/integration.ts.html +4 -4
  29. package/coverage/lcov-report/src/api/controllers/layout.ts.html +6 -6
  30. package/coverage/lcov-report/src/api/controllers/metadata.ts.html +9 -9
  31. package/coverage/lcov-report/src/api/controllers/migrations.ts.html +4 -4
  32. package/coverage/lcov-report/src/api/controllers/permission.ts.html +13 -13
  33. package/coverage/lcov-report/src/api/controllers/plugin/file.ts.html +2 -2
  34. package/coverage/lcov-report/src/api/controllers/plugin/github.ts.html +4 -4
  35. package/coverage/lcov-report/src/api/controllers/plugin/index.html +19 -19
  36. package/coverage/lcov-report/src/api/controllers/plugin/index.ts.html +29 -29
  37. package/coverage/lcov-report/src/api/controllers/plugin/npm.ts.html +5 -5
  38. package/coverage/lcov-report/src/api/controllers/plugin/uploaders.ts.html +5 -5
  39. package/coverage/lcov-report/src/api/controllers/plugin/url.ts.html +3 -3
  40. package/coverage/lcov-report/src/api/controllers/plugin/utils.ts.html +3 -3
  41. package/coverage/lcov-report/src/api/controllers/public/applications.ts.html +6 -6
  42. package/coverage/lcov-report/src/api/controllers/public/index.html +1 -1
  43. package/coverage/lcov-report/src/api/controllers/public/mapping/applications.ts.html +2 -2
  44. package/coverage/lcov-report/src/api/controllers/public/mapping/index.html +1 -1
  45. package/coverage/lcov-report/src/api/controllers/public/mapping/index.ts.html +7 -7
  46. package/coverage/lcov-report/src/api/controllers/public/mapping/queries.ts.html +2 -2
  47. package/coverage/lcov-report/src/api/controllers/public/mapping/rows.ts.html +2 -2
  48. package/coverage/lcov-report/src/api/controllers/public/mapping/tables.ts.html +2 -2
  49. package/coverage/lcov-report/src/api/controllers/public/mapping/users.ts.html +2 -2
  50. package/coverage/lcov-report/src/api/controllers/public/queries.ts.html +4 -4
  51. package/coverage/lcov-report/src/api/controllers/public/rows.ts.html +5 -5
  52. package/coverage/lcov-report/src/api/controllers/public/tables.ts.html +4 -4
  53. package/coverage/lcov-report/src/api/controllers/public/users.ts.html +6 -6
  54. package/coverage/lcov-report/src/api/controllers/public/utils.ts.html +4 -4
  55. package/coverage/lcov-report/src/api/controllers/query/import/index.html +1 -1
  56. package/coverage/lcov-report/src/api/controllers/query/import/index.ts.html +7 -7
  57. package/coverage/lcov-report/src/api/controllers/query/import/sources/base/index.html +1 -1
  58. package/coverage/lcov-report/src/api/controllers/query/import/sources/base/index.ts.html +3 -3
  59. package/coverage/lcov-report/src/api/controllers/query/import/sources/base/openapi.ts.html +5 -5
  60. package/coverage/lcov-report/src/api/controllers/query/import/sources/curl.ts.html +7 -7
  61. package/coverage/lcov-report/src/api/controllers/query/import/sources/index.html +1 -1
  62. package/coverage/lcov-report/src/api/controllers/query/import/sources/openapi2.ts.html +9 -9
  63. package/coverage/lcov-report/src/api/controllers/query/import/sources/openapi3.ts.html +13 -13
  64. package/coverage/lcov-report/src/api/controllers/query/index.html +7 -7
  65. package/coverage/lcov-report/src/api/controllers/query/index.ts.html +89 -65
  66. package/coverage/lcov-report/src/api/controllers/query/validation.ts.html +9 -9
  67. package/coverage/lcov-report/src/api/controllers/role.ts.html +8 -8
  68. package/coverage/lcov-report/src/api/controllers/routing.ts.html +6 -6
  69. package/coverage/lcov-report/src/api/controllers/row/ExternalRequest.ts.html +36 -18
  70. package/coverage/lcov-report/src/api/controllers/row/external.ts.html +60 -30
  71. package/coverage/lcov-report/src/api/controllers/row/index.html +40 -40
  72. package/coverage/lcov-report/src/api/controllers/row/index.ts.html +34 -34
  73. package/coverage/lcov-report/src/api/controllers/row/internal.ts.html +142 -70
  74. package/coverage/lcov-report/src/api/controllers/row/internalSearch.ts.html +120 -120
  75. package/coverage/lcov-report/src/api/controllers/row/staticFormula.ts.html +22 -22
  76. package/coverage/lcov-report/src/api/controllers/row/utils.ts.html +152 -38
  77. package/coverage/lcov-report/src/api/controllers/screen.ts.html +7 -7
  78. package/coverage/lcov-report/src/api/controllers/script.ts.html +2 -2
  79. package/coverage/lcov-report/src/api/controllers/static/index.html +1 -1
  80. package/coverage/lcov-report/src/api/controllers/static/index.ts.html +39 -42
  81. package/coverage/lcov-report/src/api/controllers/table/bulkFormula.ts.html +52 -52
  82. package/coverage/lcov-report/src/api/controllers/table/external.ts.html +43 -37
  83. package/coverage/lcov-report/src/api/controllers/table/index.html +34 -34
  84. package/coverage/lcov-report/src/api/controllers/table/index.ts.html +155 -68
  85. package/coverage/lcov-report/src/api/controllers/table/internal.ts.html +47 -47
  86. package/coverage/lcov-report/src/api/controllers/table/utils.ts.html +66 -69
  87. package/coverage/lcov-report/src/api/controllers/templates.ts.html +7 -7
  88. package/coverage/lcov-report/src/api/controllers/user.ts.html +99 -75
  89. package/coverage/lcov-report/src/api/controllers/view/exporters.ts.html +62 -17
  90. package/coverage/lcov-report/src/api/controllers/view/index.html +29 -29
  91. package/coverage/lcov-report/src/api/controllers/view/index.ts.html +53 -92
  92. package/coverage/lcov-report/src/api/controllers/view/utils.ts.html +5 -5
  93. package/coverage/lcov-report/src/api/controllers/view/viewBuilder.ts.html +6 -6
  94. package/coverage/lcov-report/src/api/controllers/webhook.ts.html +69 -63
  95. package/coverage/lcov-report/src/api/index.html +1 -1
  96. package/coverage/lcov-report/src/api/index.ts.html +27 -27
  97. package/coverage/lcov-report/src/api/routes/analytics.ts.html +7 -7
  98. package/coverage/lcov-report/src/api/routes/apikeys.ts.html +8 -8
  99. package/coverage/lcov-report/src/api/routes/application.ts.html +10 -10
  100. package/coverage/lcov-report/src/api/routes/auth.ts.html +6 -6
  101. package/coverage/lcov-report/src/api/routes/automation.ts.html +11 -11
  102. package/coverage/lcov-report/src/api/routes/backup.ts.html +8 -8
  103. package/coverage/lcov-report/src/api/routes/cloud.ts.html +8 -8
  104. package/coverage/lcov-report/src/api/routes/component.ts.html +8 -8
  105. package/coverage/lcov-report/src/api/routes/datasource.ts.html +9 -9
  106. package/coverage/lcov-report/src/api/routes/deploy.ts.html +8 -8
  107. package/coverage/lcov-report/src/api/routes/dev.ts.html +13 -13
  108. package/coverage/lcov-report/src/api/routes/index.html +5 -5
  109. package/coverage/lcov-report/src/api/routes/index.ts.html +42 -36
  110. package/coverage/lcov-report/src/api/routes/integration.ts.html +8 -8
  111. package/coverage/lcov-report/src/api/routes/layout.ts.html +8 -8
  112. package/coverage/lcov-report/src/api/routes/metadata.ts.html +9 -9
  113. package/coverage/lcov-report/src/api/routes/migrations.ts.html +7 -7
  114. package/coverage/lcov-report/src/api/routes/permission.ts.html +9 -9
  115. package/coverage/lcov-report/src/api/routes/plugin.ts.html +8 -8
  116. package/coverage/lcov-report/src/api/routes/public/applications.ts.html +14 -14
  117. package/coverage/lcov-report/src/api/routes/public/index.html +1 -1
  118. package/coverage/lcov-report/src/api/routes/public/index.ts.html +52 -52
  119. package/coverage/lcov-report/src/api/routes/public/middleware/index.html +1 -1
  120. package/coverage/lcov-report/src/api/routes/public/middleware/mapper.ts.html +4 -4
  121. package/coverage/lcov-report/src/api/routes/public/queries.ts.html +9 -9
  122. package/coverage/lcov-report/src/api/routes/public/rows.ts.html +12 -12
  123. package/coverage/lcov-report/src/api/routes/public/tables.ts.html +12 -12
  124. package/coverage/lcov-report/src/api/routes/public/tests/index.html +1 -1
  125. package/coverage/lcov-report/src/api/routes/public/tests/utils.ts.html +1 -1
  126. package/coverage/lcov-report/src/api/routes/public/users.ts.html +12 -12
  127. package/coverage/lcov-report/src/api/routes/public/utils/Endpoint.ts.html +19 -19
  128. package/coverage/lcov-report/src/api/routes/public/utils/index.html +1 -1
  129. package/coverage/lcov-report/src/api/routes/query.ts.html +11 -11
  130. package/coverage/lcov-report/src/api/routes/role.ts.html +9 -9
  131. package/coverage/lcov-report/src/api/routes/routing.ts.html +8 -8
  132. package/coverage/lcov-report/src/api/routes/row.ts.html +12 -12
  133. package/coverage/lcov-report/src/api/routes/screen.ts.html +9 -9
  134. package/coverage/lcov-report/src/api/routes/script.ts.html +1 -1
  135. package/coverage/lcov-report/src/api/routes/static.ts.html +14 -14
  136. package/coverage/lcov-report/src/api/routes/table.ts.html +26 -95
  137. package/coverage/lcov-report/src/api/routes/templates.ts.html +8 -8
  138. package/coverage/lcov-report/src/api/routes/tests/utilities/TestFunctions.ts.html +1 -1
  139. package/coverage/lcov-report/src/api/routes/tests/utilities/index.html +1 -1
  140. package/coverage/lcov-report/src/api/routes/tests/utilities/index.ts.html +1 -1
  141. package/coverage/lcov-report/src/api/routes/user.ts.html +9 -9
  142. package/coverage/lcov-report/src/api/routes/utils/index.html +1 -1
  143. package/coverage/lcov-report/src/api/routes/utils/validators.ts.html +43 -43
  144. package/coverage/lcov-report/src/api/routes/view.ts.html +10 -10
  145. package/coverage/lcov-report/src/api/routes/webhook.ts.html +10 -10
  146. package/coverage/lcov-report/src/app.ts.html +13 -7
  147. package/coverage/lcov-report/src/automations/actions.ts.html +27 -27
  148. package/coverage/lcov-report/src/automations/automationUtils.ts.html +59 -59
  149. package/coverage/lcov-report/src/automations/bullboard.ts.html +9 -9
  150. package/coverage/lcov-report/src/automations/index.html +30 -30
  151. package/coverage/lcov-report/src/automations/index.ts.html +10 -10
  152. package/coverage/lcov-report/src/automations/logging/index.html +1 -1
  153. package/coverage/lcov-report/src/automations/logging/index.ts.html +7 -7
  154. package/coverage/lcov-report/src/automations/steps/bash.ts.html +8 -8
  155. package/coverage/lcov-report/src/automations/steps/createRow.ts.html +7 -7
  156. package/coverage/lcov-report/src/automations/steps/delay.ts.html +5 -5
  157. package/coverage/lcov-report/src/automations/steps/deleteRow.ts.html +7 -7
  158. package/coverage/lcov-report/src/automations/steps/discord.ts.html +8 -8
  159. package/coverage/lcov-report/src/automations/steps/executeQuery.ts.html +7 -7
  160. package/coverage/lcov-report/src/automations/steps/executeScript.ts.html +7 -7
  161. package/coverage/lcov-report/src/automations/steps/filter.ts.html +6 -6
  162. package/coverage/lcov-report/src/automations/steps/index.html +15 -15
  163. package/coverage/lcov-report/src/automations/steps/integromat.ts.html +6 -6
  164. package/coverage/lcov-report/src/automations/steps/loop.ts.html +3 -3
  165. package/coverage/lcov-report/src/automations/steps/outgoingWebhook.ts.html +9 -9
  166. package/coverage/lcov-report/src/automations/steps/queryRows.ts.html +38 -38
  167. package/coverage/lcov-report/src/automations/steps/sendSmtpEmail.ts.html +6 -6
  168. package/coverage/lcov-report/src/automations/steps/serverLog.ts.html +7 -7
  169. package/coverage/lcov-report/src/automations/steps/slack.ts.html +6 -6
  170. package/coverage/lcov-report/src/automations/steps/updateRow.ts.html +7 -7
  171. package/coverage/lcov-report/src/automations/steps/utils.ts.html +10 -10
  172. package/coverage/lcov-report/src/automations/steps/zapier.ts.html +6 -6
  173. package/coverage/lcov-report/src/automations/tests/utilities/index.html +1 -1
  174. package/coverage/lcov-report/src/automations/tests/utilities/index.ts.html +13 -13
  175. package/coverage/lcov-report/src/automations/triggerInfo/app.ts.html +3 -3
  176. package/coverage/lcov-report/src/automations/triggerInfo/cron.ts.html +3 -3
  177. package/coverage/lcov-report/src/automations/triggerInfo/index.html +1 -1
  178. package/coverage/lcov-report/src/automations/triggerInfo/index.ts.html +8 -8
  179. package/coverage/lcov-report/src/automations/triggerInfo/rowDeleted.ts.html +3 -3
  180. package/coverage/lcov-report/src/automations/triggerInfo/rowSaved.ts.html +3 -3
  181. package/coverage/lcov-report/src/automations/triggerInfo/rowUpdated.ts.html +3 -3
  182. package/coverage/lcov-report/src/automations/triggerInfo/webhook.ts.html +3 -3
  183. package/coverage/lcov-report/src/automations/triggers.ts.html +52 -37
  184. package/coverage/lcov-report/src/automations/utils.ts.html +52 -52
  185. package/coverage/lcov-report/src/constants/index.html +1 -1
  186. package/coverage/lcov-report/src/constants/index.ts.html +2 -2
  187. package/coverage/lcov-report/src/constants/layouts.ts.html +4 -4
  188. package/coverage/lcov-report/src/constants/screens.ts.html +3 -3
  189. package/coverage/lcov-report/src/db/defaultData/datasource_bb_default.ts.html +22 -22
  190. package/coverage/lcov-report/src/db/defaultData/employeeImport.ts.html +2 -2
  191. package/coverage/lcov-report/src/db/defaultData/expensesImport.ts.html +2 -2
  192. package/coverage/lcov-report/src/db/defaultData/index.html +1 -1
  193. package/coverage/lcov-report/src/db/defaultData/inventoryImport.ts.html +2 -2
  194. package/coverage/lcov-report/src/db/defaultData/jobsImport.ts.html +2 -2
  195. package/coverage/lcov-report/src/db/dynamoClient.ts.html +15 -15
  196. package/coverage/lcov-report/src/db/inMemoryView.ts.html +4 -4
  197. package/coverage/lcov-report/src/db/index.html +1 -1
  198. package/coverage/lcov-report/src/db/index.ts.html +9 -9
  199. package/coverage/lcov-report/src/db/linkedRows/LinkController.ts.html +18 -18
  200. package/coverage/lcov-report/src/db/linkedRows/LinkDocument.ts.html +4 -4
  201. package/coverage/lcov-report/src/db/linkedRows/index.html +1 -1
  202. package/coverage/lcov-report/src/db/linkedRows/index.ts.html +27 -27
  203. package/coverage/lcov-report/src/db/linkedRows/linkUtils.ts.html +13 -13
  204. package/coverage/lcov-report/src/db/newid.ts.html +4 -4
  205. package/coverage/lcov-report/src/db/utils.ts.html +40 -40
  206. package/coverage/lcov-report/src/definitions/automations.ts.html +6 -3
  207. package/coverage/lcov-report/src/definitions/index.html +5 -20
  208. package/coverage/lcov-report/src/environment.ts.html +10 -10
  209. package/coverage/lcov-report/src/events/AutomationEmitter.ts.html +8 -8
  210. package/coverage/lcov-report/src/events/BudibaseEmitter.ts.html +5 -5
  211. package/coverage/lcov-report/src/events/index.html +1 -1
  212. package/coverage/lcov-report/src/events/index.ts.html +4 -4
  213. package/coverage/lcov-report/src/events/utils.ts.html +1 -1
  214. package/coverage/lcov-report/src/index.html +13 -13
  215. package/coverage/lcov-report/src/index.ts.html +5 -5
  216. package/coverage/lcov-report/src/integrations/airtable.ts.html +5 -5
  217. package/coverage/lcov-report/src/integrations/arangodb.ts.html +5 -5
  218. package/coverage/lcov-report/src/integrations/base/index.html +11 -11
  219. package/coverage/lcov-report/src/integrations/base/query.ts.html +14 -8
  220. package/coverage/lcov-report/src/integrations/base/sql.ts.html +12 -12
  221. package/coverage/lcov-report/src/integrations/base/sqlTable.ts.html +8 -8
  222. package/coverage/lcov-report/src/integrations/base/utils.ts.html +5 -5
  223. package/coverage/lcov-report/src/integrations/couchdb.ts.html +110 -32
  224. package/coverage/lcov-report/src/integrations/dynamodb.ts.html +9 -9
  225. package/coverage/lcov-report/src/integrations/elasticsearch.ts.html +26 -14
  226. package/coverage/lcov-report/src/integrations/firebase.ts.html +5 -5
  227. package/coverage/lcov-report/src/integrations/googlesheets.ts.html +11 -11
  228. package/coverage/lcov-report/src/integrations/index.html +47 -47
  229. package/coverage/lcov-report/src/integrations/index.ts.html +49 -49
  230. package/coverage/lcov-report/src/integrations/microsoftSqlServer.ts.html +8 -8
  231. package/coverage/lcov-report/src/integrations/mongodb.ts.html +417 -285
  232. package/coverage/lcov-report/src/integrations/mysql.ts.html +11 -11
  233. package/coverage/lcov-report/src/integrations/oracle.ts.html +13 -13
  234. package/coverage/lcov-report/src/integrations/postgres.ts.html +10 -10
  235. package/coverage/lcov-report/src/integrations/queries/index.html +19 -19
  236. package/coverage/lcov-report/src/integrations/queries/sql.ts.html +15 -150
  237. package/coverage/lcov-report/src/integrations/redis.ts.html +5 -5
  238. package/coverage/lcov-report/src/integrations/rest.ts.html +36 -45
  239. package/coverage/lcov-report/src/integrations/s3.ts.html +6 -6
  240. package/coverage/lcov-report/src/integrations/snowflake.ts.html +5 -5
  241. package/coverage/lcov-report/src/integrations/tests/TestConfiguration.js.html +1 -1
  242. package/coverage/lcov-report/src/integrations/tests/index.html +1 -1
  243. package/coverage/lcov-report/src/integrations/utils.ts.html +18 -18
  244. package/coverage/lcov-report/src/middleware/appInfo.ts.html +5 -5
  245. package/coverage/lcov-report/src/middleware/authorized.ts.html +27 -27
  246. package/coverage/lcov-report/src/middleware/builder.ts.html +17 -17
  247. package/coverage/lcov-report/src/middleware/currentapp.ts.html +45 -42
  248. package/coverage/lcov-report/src/middleware/index.html +1 -1
  249. package/coverage/lcov-report/src/middleware/joi-validator.ts.html +1 -1
  250. package/coverage/lcov-report/src/middleware/publicApi.ts.html +4 -4
  251. package/coverage/lcov-report/src/middleware/resourceId.ts.html +21 -21
  252. package/coverage/lcov-report/src/middleware/selfhost.ts.html +1 -1
  253. package/coverage/lcov-report/src/middleware/utils.ts.html +4 -4
  254. package/coverage/lcov-report/src/migrations/functions/appUrls.ts.html +4 -4
  255. package/coverage/lcov-report/src/migrations/functions/backfill/app/automations.ts.html +5 -5
  256. package/coverage/lcov-report/src/migrations/functions/backfill/app/datasources.ts.html +5 -5
  257. package/coverage/lcov-report/src/migrations/functions/backfill/app/index.html +1 -1
  258. package/coverage/lcov-report/src/migrations/functions/backfill/app/layouts.ts.html +5 -5
  259. package/coverage/lcov-report/src/migrations/functions/backfill/app/queries.ts.html +7 -7
  260. package/coverage/lcov-report/src/migrations/functions/backfill/app/roles.ts.html +5 -5
  261. package/coverage/lcov-report/src/migrations/functions/backfill/app/screens.ts.html +5 -5
  262. package/coverage/lcov-report/src/migrations/functions/backfill/app/tables.ts.html +4 -4
  263. package/coverage/lcov-report/src/migrations/functions/backfill/app.ts.html +19 -19
  264. package/coverage/lcov-report/src/migrations/functions/backfill/global/configs.ts.html +6 -6
  265. package/coverage/lcov-report/src/migrations/functions/backfill/global/index.html +1 -1
  266. package/coverage/lcov-report/src/migrations/functions/backfill/global/quotas.ts.html +7 -7
  267. package/coverage/lcov-report/src/migrations/functions/backfill/global/users.ts.html +6 -6
  268. package/coverage/lcov-report/src/migrations/functions/backfill/global.ts.html +15 -15
  269. package/coverage/lcov-report/src/migrations/functions/backfill/index.html +1 -1
  270. package/coverage/lcov-report/src/migrations/functions/backfill/index.ts.html +5 -5
  271. package/coverage/lcov-report/src/migrations/functions/backfill/installation.ts.html +8 -8
  272. package/coverage/lcov-report/src/migrations/functions/index.html +1 -1
  273. package/coverage/lcov-report/src/migrations/functions/syncQuotas.ts.html +6 -6
  274. package/coverage/lcov-report/src/migrations/functions/tableSettings.ts.html +6 -6
  275. package/coverage/lcov-report/src/migrations/functions/usageQuotas/index.html +1 -1
  276. package/coverage/lcov-report/src/migrations/functions/usageQuotas/index.ts.html +2 -2
  277. package/coverage/lcov-report/src/migrations/functions/usageQuotas/syncApps.ts.html +5 -5
  278. package/coverage/lcov-report/src/migrations/functions/usageQuotas/syncPlugins.ts.html +4 -4
  279. package/coverage/lcov-report/src/migrations/functions/usageQuotas/syncRows.ts.html +6 -6
  280. package/coverage/lcov-report/src/migrations/functions/userEmailViewCasing.ts.html +3 -3
  281. package/coverage/lcov-report/src/migrations/index.html +1 -1
  282. package/coverage/lcov-report/src/migrations/index.ts.html +32 -32
  283. package/coverage/lcov-report/src/migrations/tests/helpers.ts.html +1 -1
  284. package/coverage/lcov-report/src/migrations/tests/index.html +1 -1
  285. package/coverage/lcov-report/src/migrations/tests/structures.ts.html +1 -1
  286. package/coverage/lcov-report/src/sdk/app/applications/index.html +1 -1
  287. package/coverage/lcov-report/src/sdk/app/applications/index.ts.html +4 -4
  288. package/coverage/lcov-report/src/sdk/app/applications/sync.ts.html +22 -22
  289. package/coverage/lcov-report/src/sdk/app/applications/utils.ts.html +9 -9
  290. package/coverage/lcov-report/src/sdk/app/automations/index.html +1 -1
  291. package/coverage/lcov-report/src/sdk/app/automations/index.ts.html +3 -3
  292. package/coverage/lcov-report/src/sdk/app/automations/webhook.ts.html +3 -3
  293. package/coverage/lcov-report/src/sdk/app/backups/constants.ts.html +3 -3
  294. package/coverage/lcov-report/src/sdk/app/backups/exports.ts.html +17 -17
  295. package/coverage/lcov-report/src/sdk/app/backups/imports.ts.html +18 -18
  296. package/coverage/lcov-report/src/sdk/app/backups/index.html +1 -1
  297. package/coverage/lcov-report/src/sdk/app/backups/index.ts.html +5 -5
  298. package/coverage/lcov-report/src/sdk/app/backups/statistics.ts.html +7 -7
  299. package/coverage/lcov-report/src/sdk/app/datasources/datasources.ts.html +493 -0
  300. package/coverage/lcov-report/src/sdk/app/datasources/index.html +131 -0
  301. package/coverage/lcov-report/src/sdk/app/datasources/index.ts.html +100 -0
  302. package/coverage/lcov-report/src/sdk/app/queries/index.html +131 -0
  303. package/coverage/lcov-report/src/sdk/app/queries/index.ts.html +100 -0
  304. package/coverage/lcov-report/src/{definitions/datasource.ts.html → sdk/app/queries/queries.ts.html} +82 -82
  305. package/coverage/lcov-report/src/sdk/app/rows/attachments.ts.html +6 -6
  306. package/coverage/lcov-report/src/sdk/app/rows/index.html +1 -1
  307. package/coverage/lcov-report/src/sdk/app/rows/index.ts.html +4 -4
  308. package/coverage/lcov-report/src/sdk/app/rows/rows.ts.html +4 -4
  309. package/coverage/lcov-report/src/sdk/app/tables/index.html +11 -11
  310. package/coverage/lcov-report/src/sdk/app/tables/index.ts.html +27 -18
  311. package/coverage/lcov-report/src/sdk/index.html +5 -5
  312. package/coverage/lcov-report/src/sdk/index.ts.html +23 -11
  313. package/coverage/lcov-report/src/sdk/users/index.html +1 -1
  314. package/coverage/lcov-report/src/sdk/users/index.ts.html +3 -3
  315. package/coverage/lcov-report/src/sdk/users/utils.ts.html +28 -28
  316. package/coverage/lcov-report/src/sdk/utils/index.html +116 -0
  317. package/coverage/lcov-report/src/sdk/utils/index.ts.html +133 -0
  318. package/coverage/lcov-report/src/startup.ts.html +34 -34
  319. package/coverage/lcov-report/src/tests/utilities/TestConfiguration.ts.html +134 -125
  320. package/coverage/lcov-report/src/tests/utilities/controllers.ts.html +15 -15
  321. package/coverage/lcov-report/src/tests/utilities/index.html +21 -21
  322. package/coverage/lcov-report/src/tests/utilities/index.ts.html +1 -1
  323. package/coverage/lcov-report/src/tests/utilities/structures.ts.html +213 -24
  324. package/coverage/lcov-report/src/threads/automation.ts.html +216 -186
  325. package/coverage/lcov-report/src/threads/index.html +30 -30
  326. package/coverage/lcov-report/src/threads/index.ts.html +24 -24
  327. package/coverage/lcov-report/src/threads/query.ts.html +68 -29
  328. package/coverage/lcov-report/src/threads/utils.ts.html +9 -9
  329. package/coverage/lcov-report/src/utilities/budibaseDir.ts.html +2 -2
  330. package/coverage/lcov-report/src/utilities/centralPath.ts.html +11 -11
  331. package/coverage/lcov-report/src/utilities/fileSystem/app.ts.html +9 -9
  332. package/coverage/lcov-report/src/utilities/fileSystem/clientLibrary.ts.html +1 -1
  333. package/coverage/lcov-report/src/utilities/fileSystem/filesystem.ts.html +27 -21
  334. package/coverage/lcov-report/src/utilities/fileSystem/index.html +21 -21
  335. package/coverage/lcov-report/src/utilities/fileSystem/index.ts.html +1 -1
  336. package/coverage/lcov-report/src/utilities/fileSystem/plugin.ts.html +5 -8
  337. package/coverage/lcov-report/src/utilities/fileSystem/processor.ts.html +1 -1
  338. package/coverage/lcov-report/src/utilities/fileSystem/template.ts.html +3 -3
  339. package/coverage/lcov-report/src/utilities/global.ts.html +40 -40
  340. package/coverage/lcov-report/src/utilities/index.html +39 -39
  341. package/coverage/lcov-report/src/utilities/index.ts.html +12 -12
  342. package/coverage/lcov-report/src/utilities/redis.ts.html +12 -12
  343. package/coverage/lcov-report/src/utilities/routing/index.html +1 -1
  344. package/coverage/lcov-report/src/utilities/routing/index.ts.html +4 -4
  345. package/coverage/lcov-report/src/utilities/rowProcessor/index.html +1 -1
  346. package/coverage/lcov-report/src/utilities/rowProcessor/index.ts.html +50 -50
  347. package/coverage/lcov-report/src/utilities/rowProcessor/map.ts.html +3 -3
  348. package/coverage/lcov-report/src/utilities/rowProcessor/utils.ts.html +14 -14
  349. package/coverage/lcov-report/src/utilities/{csvParser.ts.html → schema.ts.html} +173 -233
  350. package/coverage/lcov-report/src/utilities/scriptRunner.ts.html +5 -5
  351. package/coverage/lcov-report/src/utilities/security.ts.html +4 -4
  352. package/coverage/lcov-report/src/utilities/usageQuota/index.html +1 -1
  353. package/coverage/lcov-report/src/utilities/usageQuota/rows.ts.html +4 -4
  354. package/coverage/lcov-report/src/utilities/usageQuota/usageQuoteReset.ts.html +1 -1
  355. package/coverage/lcov-report/src/utilities/users.ts.html +4 -4
  356. package/coverage/lcov-report/src/utilities/workerRequests.ts.html +38 -11
  357. package/coverage/lcov-report/src/watch.ts.html +7 -7
  358. package/coverage/lcov-report/src/websocket.ts.html +3 -3
  359. package/coverage/lcov.info +7892 -7532
  360. package/dist/api/controllers/application.js +73 -74
  361. package/dist/api/controllers/cloud.js +1 -1
  362. package/dist/api/controllers/datasource.js +24 -15
  363. package/dist/api/controllers/query/index.js +18 -11
  364. package/dist/api/controllers/row/ExternalRequest.js +12 -3
  365. package/dist/api/controllers/row/external.js +20 -13
  366. package/dist/api/controllers/row/internal.js +40 -15
  367. package/dist/api/controllers/row/utils.js +35 -3
  368. package/dist/api/controllers/static/index.js +38 -38
  369. package/dist/api/controllers/static/templates/BudibaseApp.svelte +0 -1
  370. package/dist/api/controllers/table/external.js +16 -35
  371. package/dist/api/controllers/table/index.js +44 -15
  372. package/dist/api/controllers/table/internal.js +4 -4
  373. package/dist/api/controllers/table/utils.js +9 -9
  374. package/dist/api/controllers/user.js +14 -6
  375. package/dist/api/controllers/view/exporters.js +22 -6
  376. package/dist/api/controllers/view/index.js +20 -56
  377. package/dist/api/controllers/webhook.js +45 -43
  378. package/dist/api/routes/index.js +2 -0
  379. package/dist/api/routes/row.js +2 -2
  380. package/dist/api/routes/table.js +6 -37
  381. package/dist/api/routes/utils/validators.js +1 -1
  382. package/dist/app.js +1 -0
  383. package/dist/automations/triggers.js +1 -0
  384. package/dist/definitions/datasource.js +0 -6
  385. package/dist/index.js +2 -2
  386. package/dist/integrations/base/query.js +7 -2
  387. package/dist/integrations/base/sqlTable.js +14 -14
  388. package/dist/integrations/couchdb.js +34 -8
  389. package/dist/integrations/dynamodb.js +8 -5
  390. package/dist/integrations/elasticsearch.js +7 -3
  391. package/dist/integrations/index.js +5 -5
  392. package/dist/integrations/mongodb.js +311 -271
  393. package/dist/integrations/mysql.js +2 -2
  394. package/dist/integrations/queries/sql.js +73 -100
  395. package/dist/integrations/rest.js +16 -18
  396. package/dist/middleware/currentapp.js +4 -2
  397. package/dist/package.json +7 -7
  398. package/dist/sdk/app/datasources/datasources.js +147 -0
  399. package/dist/sdk/app/datasources/index.js +27 -0
  400. package/dist/sdk/app/queries/index.js +27 -0
  401. package/dist/sdk/app/queries/queries.js +60 -0
  402. package/dist/sdk/app/tables/index.js +6 -2
  403. package/dist/sdk/index.js +4 -0
  404. package/dist/sdk/utils/index.js +29 -0
  405. package/dist/threads/automation.js +18 -7
  406. package/dist/threads/query.js +27 -13
  407. package/dist/tsconfig.build.tsbuildinfo +1 -1
  408. package/dist/utilities/fileSystem/filesystem.js +36 -34
  409. package/dist/utilities/fileSystem/plugin.js +17 -14
  410. package/dist/utilities/fileSystem/template.js +7 -4
  411. package/dist/utilities/schema.js +108 -0
  412. package/dist/utilities/workerRequests.js +2 -0
  413. package/package.json +8 -8
  414. package/scripts/dev/manage.js +3 -2
  415. package/src/api/controllers/application.ts +81 -74
  416. package/src/api/controllers/cloud.ts +1 -1
  417. package/src/api/controllers/datasource.ts +33 -25
  418. package/src/api/controllers/query/index.ts +47 -39
  419. package/src/api/controllers/row/ExternalRequest.ts +8 -2
  420. package/src/api/controllers/row/external.ts +24 -14
  421. package/src/api/controllers/row/internal.ts +42 -18
  422. package/src/api/controllers/row/utils.ts +40 -2
  423. package/src/api/controllers/static/index.ts +17 -18
  424. package/src/api/controllers/static/templates/BudibaseApp.svelte +0 -1
  425. package/src/api/controllers/table/external.ts +18 -16
  426. package/src/api/controllers/table/index.ts +46 -17
  427. package/src/api/controllers/table/internal.ts +4 -4
  428. package/src/api/controllers/table/utils.ts +12 -13
  429. package/src/api/controllers/user.ts +21 -13
  430. package/src/api/controllers/view/exporters.ts +20 -5
  431. package/src/api/controllers/view/index.ts +22 -35
  432. package/src/api/controllers/webhook.ts +48 -46
  433. package/src/api/routes/index.ts +2 -0
  434. package/src/api/routes/row.ts +1 -1
  435. package/src/api/routes/table.ts +15 -38
  436. package/src/api/routes/tests/datasource.spec.ts +35 -1
  437. package/src/api/routes/tests/misc.spec.js +4 -10
  438. package/src/api/routes/tests/table.spec.js +8 -30
  439. package/src/api/routes/tests/user.spec.js +20 -1
  440. package/src/api/routes/utils/validators.ts +1 -1
  441. package/src/app.ts +3 -1
  442. package/src/automations/tests/loop.spec.ts +45 -0
  443. package/src/automations/triggers.ts +6 -1
  444. package/src/definitions/automations.ts +1 -0
  445. package/src/definitions/datasource.ts +0 -41
  446. package/src/index.ts +1 -1
  447. package/src/integrations/base/query.ts +3 -1
  448. package/src/integrations/base/sqlTable.ts +1 -1
  449. package/src/integrations/couchdb.ts +40 -14
  450. package/src/integrations/dynamodb.ts +3 -3
  451. package/src/integrations/elasticsearch.ts +8 -4
  452. package/src/integrations/index.ts +4 -4
  453. package/src/integrations/mongodb.ts +315 -271
  454. package/src/integrations/mysql.ts +1 -1
  455. package/src/integrations/queries/sql.ts +5 -50
  456. package/src/integrations/rest.ts +16 -19
  457. package/src/integrations/tests/couchdb.spec.ts +33 -21
  458. package/src/integrations/tests/rest.spec.ts +4 -2
  459. package/src/middleware/currentapp.ts +3 -2
  460. package/src/migrations/functions/usageQuotas/tests/syncRows.spec.ts +10 -6
  461. package/src/sdk/app/datasources/datasources.ts +136 -0
  462. package/src/sdk/app/datasources/index.ts +5 -0
  463. package/src/sdk/app/queries/index.ts +5 -0
  464. package/src/sdk/app/queries/queries.ts +50 -0
  465. package/src/sdk/app/tables/index.ts +6 -3
  466. package/src/sdk/index.ts +4 -0
  467. package/src/sdk/utils/index.ts +16 -0
  468. package/src/tests/utilities/TestConfiguration.ts +15 -12
  469. package/src/tests/utilities/structures.ts +65 -2
  470. package/src/threads/automation.ts +18 -8
  471. package/src/threads/definitions.ts +3 -0
  472. package/src/threads/query.ts +28 -15
  473. package/src/utilities/fileSystem/filesystem.ts +6 -4
  474. package/src/utilities/fileSystem/plugin.ts +3 -4
  475. package/src/utilities/fileSystem/template.ts +2 -2
  476. package/src/utilities/schema.ts +141 -0
  477. package/src/utilities/workerRequests.ts +10 -1
  478. package/tsconfig.json +2 -1
  479. package/builder/assets/index.e386f2c1.js +0 -1023
  480. package/builder/assets/index.fa480d5b.css +0 -6
  481. package/dist/utilities/csvParser.js +0 -152
  482. package/src/utilities/csvParser.ts +0 -161
  483. package/src/utilities/tests/__snapshots__/csvParser.spec.js.snap +0 -15
  484. package/src/utilities/tests/csvParser.spec.js +0 -112
@@ -6,21 +6,19 @@ import {
6
6
  IntegrationBase,
7
7
  PaginationValues,
8
8
  RestQueryFields as RestQuery,
9
- } from "@budibase/types"
10
- import {
11
9
  RestConfig,
12
- AuthType,
13
- BasicAuthConfig,
14
- BearerAuthConfig,
15
- } from "../definitions/datasource"
10
+ RestAuthType,
11
+ RestBasicAuthConfig,
12
+ RestBearerAuthConfig,
13
+ } from "@budibase/types"
16
14
  import { get } from "lodash"
17
15
  import * as https from "https"
18
16
  import qs from "querystring"
19
- const fetch = require("node-fetch")
20
- const { formatBytes } = require("../utilities")
21
- const { performance } = require("perf_hooks")
22
- const FormData = require("form-data")
23
- const { URLSearchParams } = require("url")
17
+ import fetch from "node-fetch"
18
+ import { formatBytes } from "../utilities"
19
+ import { performance } from "perf_hooks"
20
+ import FormData from "form-data"
21
+ import { URLSearchParams } from "url"
24
22
 
25
23
  const BodyTypes = {
26
24
  NONE: "none",
@@ -204,12 +202,12 @@ class RestIntegration implements IntegrationBase {
204
202
 
205
203
  // Append page number or cursor param if configured
206
204
  if (pageParam && paginationValues.page != null) {
207
- params.append(pageParam, paginationValues.page)
205
+ params.append(pageParam, paginationValues.page as string)
208
206
  }
209
207
 
210
208
  // Append page size param if configured
211
209
  if (sizeParam && paginationValues.limit != null) {
212
- params.append(sizeParam, paginationValues.limit)
210
+ params.append(sizeParam, String(paginationValues.limit))
213
211
  }
214
212
 
215
213
  // Prepend query string with pagination params
@@ -280,7 +278,7 @@ class RestIntegration implements IntegrationBase {
280
278
  case BodyTypes.ENCODED:
281
279
  const params = new URLSearchParams()
282
280
  for (let [key, value] of Object.entries(object)) {
283
- params.append(key, value)
281
+ params.append(key, value as string)
284
282
  }
285
283
  addPaginationToBody((key: string, value: any) => {
286
284
  params.append(key, value)
@@ -331,14 +329,14 @@ class RestIntegration implements IntegrationBase {
331
329
  if (authConfig) {
332
330
  let config
333
331
  switch (authConfig.type) {
334
- case AuthType.BASIC:
335
- config = authConfig.config as BasicAuthConfig
332
+ case RestAuthType.BASIC:
333
+ config = authConfig.config as RestBasicAuthConfig
336
334
  headers.Authorization = `Basic ${Buffer.from(
337
335
  `${config.username}:${config.password}`
338
336
  ).toString("base64")}`
339
337
  break
340
- case AuthType.BEARER:
341
- config = authConfig.config as BearerAuthConfig
338
+ case RestAuthType.BEARER:
339
+ config = authConfig.config as RestBearerAuthConfig
342
340
  headers.Authorization = `Bearer ${config.token}`
343
341
  break
344
342
  }
@@ -428,5 +426,4 @@ class RestIntegration implements IntegrationBase {
428
426
  export default {
429
427
  schema: SCHEMA,
430
428
  integration: RestIntegration,
431
- AuthType,
432
429
  }
@@ -1,23 +1,32 @@
1
- jest.mock(
2
- "pouchdb",
3
- () =>
4
- function CouchDBMock(this: any) {
5
- this.post = jest.fn()
6
- this.allDocs = jest.fn(() => ({ rows: [] }))
7
- this.put = jest.fn()
8
- this.get = jest.fn()
9
- this.remove = jest.fn()
10
- this.plugin = jest.fn()
11
- this.close = jest.fn()
12
- }
13
- )
1
+ import { DatabaseWithConnection } from "@budibase/backend-core/src/db"
2
+
3
+ jest.mock("@budibase/backend-core", () => {
4
+ const core = jest.requireActual("@budibase/backend-core")
5
+ return {
6
+ ...core,
7
+ db: {
8
+ ...core.db,
9
+ DatabaseWithConnection: function () {
10
+ return {
11
+ post: jest.fn(),
12
+ allDocs: jest.fn().mockReturnValue({ rows: [] }),
13
+ put: jest.fn(),
14
+ get: jest.fn().mockReturnValue({ _rev: "a" }),
15
+ remove: jest.fn(),
16
+ }
17
+ },
18
+ },
19
+ }
20
+ })
14
21
 
15
22
  import { default as CouchDBIntegration } from "../couchdb"
16
23
 
17
24
  class TestConfiguration {
18
25
  integration: any
19
26
 
20
- constructor(config: any = {}) {
27
+ constructor(
28
+ config: any = { url: "http://somewhere", database: "something" }
29
+ ) {
21
30
  this.integration = new CouchDBIntegration.integration(config)
22
31
  }
23
32
  }
@@ -33,8 +42,8 @@ describe("CouchDB Integration", () => {
33
42
  const doc = {
34
43
  test: 1,
35
44
  }
36
- const response = await config.integration.create({
37
- json: doc,
45
+ await config.integration.create({
46
+ json: JSON.stringify(doc),
38
47
  })
39
48
  expect(config.integration.client.post).toHaveBeenCalledWith(doc)
40
49
  })
@@ -44,8 +53,8 @@ describe("CouchDB Integration", () => {
44
53
  name: "search",
45
54
  }
46
55
 
47
- const response = await config.integration.read({
48
- json: doc,
56
+ await config.integration.read({
57
+ json: JSON.stringify(doc),
49
58
  })
50
59
 
51
60
  expect(config.integration.client.allDocs).toHaveBeenCalledWith({
@@ -60,11 +69,14 @@ describe("CouchDB Integration", () => {
60
69
  name: "search",
61
70
  }
62
71
 
63
- const response = await config.integration.update({
64
- json: doc,
72
+ await config.integration.update({
73
+ json: JSON.stringify(doc),
65
74
  })
66
75
 
67
- expect(config.integration.client.put).toHaveBeenCalledWith(doc)
76
+ expect(config.integration.client.put).toHaveBeenCalledWith({
77
+ ...doc,
78
+ _rev: "a",
79
+ })
68
80
  })
69
81
 
70
82
  it("calls the delete method with the correct params", async () => {
@@ -15,6 +15,7 @@ jest.mock("node-fetch", () => {
15
15
 
16
16
  import fetch from "node-fetch"
17
17
  import { default as RestIntegration } from "../rest"
18
+ import { RestAuthType } from "@budibase/types"
18
19
  const FormData = require("form-data")
19
20
  const { URLSearchParams } = require("url")
20
21
 
@@ -229,7 +230,7 @@ describe("REST Integration", () => {
229
230
  const basicAuth = {
230
231
  _id: "c59c14bd1898a43baa08da68959b24686",
231
232
  name: "basic-1",
232
- type: RestIntegration.AuthType.BASIC,
233
+ type: RestAuthType.BASIC,
233
234
  config: {
234
235
  username: "user",
235
236
  password: "password",
@@ -239,7 +240,7 @@ describe("REST Integration", () => {
239
240
  const bearerAuth = {
240
241
  _id: "0d91d732f34e4befabeff50b392a8ff3",
241
242
  name: "bearer-1",
242
- type: RestIntegration.AuthType.BEARER,
243
+ type: RestAuthType.BEARER,
243
244
  config: {
244
245
  token: "mytoken",
245
246
  },
@@ -581,6 +582,7 @@ describe("REST Integration", () => {
581
582
  })
582
583
  await config.integration.read({})
583
584
 
585
+ // @ts-ignore
584
586
  const calls: any = fetch.mock.calls[0]
585
587
  const url = calls[0]
586
588
  expect(url).toBe(`${BASE_URL}/`)
@@ -25,6 +25,7 @@ export default async (ctx: BBContext, next: any) => {
25
25
  if (!appCookie && !requestAppId) {
26
26
  return next()
27
27
  }
28
+
28
29
  // check the app exists referenced in cookie
29
30
  if (appCookie) {
30
31
  const appId = appCookie.appId
@@ -51,7 +52,7 @@ export default async (ctx: BBContext, next: any) => {
51
52
 
52
53
  let appId: string | undefined,
53
54
  roleId = roles.BUILTIN_ROLE_IDS.PUBLIC
54
- if (!ctx.user) {
55
+ if (!ctx.user?._id) {
55
56
  // not logged in, try to set a cookie for public apps
56
57
  appId = requestAppId
57
58
  } else if (requestAppId != null) {
@@ -96,7 +97,7 @@ export default async (ctx: BBContext, next: any) => {
96
97
  // need to judge this only based on the request app ID,
97
98
  if (
98
99
  env.MULTI_TENANCY &&
99
- ctx.user &&
100
+ ctx.user?._id &&
100
101
  requestAppId &&
101
102
  !tenancy.isUserInAppTenant(requestAppId, ctx.user)
102
103
  ) {
@@ -2,7 +2,7 @@ import TestConfig from "../../../../tests/utilities/TestConfiguration"
2
2
  import * as syncRows from "../syncRows"
3
3
  import { quotas } from "@budibase/pro"
4
4
  import { QuotaUsageType, StaticQuotaName } from "@budibase/types"
5
- const { db: dbCore } = require("@budibase/backend-core")
5
+ import { db as dbCore, context } from "@budibase/backend-core"
6
6
 
7
7
  describe("syncRows", () => {
8
8
  let config = new TestConfig(false)
@@ -24,13 +24,17 @@ describe("syncRows", () => {
24
24
 
25
25
  // app 1
26
26
  const app1 = config.app
27
- await config.createTable()
28
- await config.createRow()
27
+ await context.doInAppContext(app1.appId, async () => {
28
+ await config.createTable()
29
+ await config.createRow()
30
+ })
29
31
  // app 2
30
32
  const app2 = await config.createApp("second-app")
31
- await config.createTable()
32
- await config.createRow()
33
- await config.createRow()
33
+ await context.doInAppContext(app2.appId, async () => {
34
+ await config.createTable()
35
+ await config.createRow()
36
+ await config.createRow()
37
+ })
34
38
 
35
39
  // migrate
36
40
  await syncRows.run()
@@ -0,0 +1,136 @@
1
+ import { context } from "@budibase/backend-core"
2
+ import { findHBSBlocks, processObjectSync } from "@budibase/string-templates"
3
+ import {
4
+ Datasource,
5
+ DatasourceFieldType,
6
+ PASSWORD_REPLACEMENT,
7
+ RestAuthConfig,
8
+ RestAuthType,
9
+ RestBasicAuthConfig,
10
+ SourceName,
11
+ } from "@budibase/types"
12
+ import { cloneDeep } from "lodash/fp"
13
+ import { getEnvironmentVariables } from "../../utils"
14
+ import { getDefinitions } from "../../../integrations"
15
+
16
+ const ENV_VAR_PREFIX = "env."
17
+
18
+ async function enrichDatasourceWithValues(datasource: Datasource) {
19
+ const cloned = cloneDeep(datasource)
20
+ const env = await getEnvironmentVariables()
21
+ const processed = processObjectSync(cloned, { env }, { onlyFound: true })
22
+ return {
23
+ datasource: processed as Datasource,
24
+ envVars: env as Record<string, string>,
25
+ }
26
+ }
27
+
28
+ export async function enrich(datasource: Datasource) {
29
+ const { datasource: response } = await enrichDatasourceWithValues(datasource)
30
+ return response
31
+ }
32
+
33
+ export async function get(
34
+ datasourceId: string,
35
+ opts?: { enriched: boolean }
36
+ ): Promise<Datasource> {
37
+ const appDb = context.getAppDB()
38
+ const datasource = await appDb.get(datasourceId)
39
+ if (opts?.enriched) {
40
+ return (await enrichDatasourceWithValues(datasource)).datasource
41
+ } else {
42
+ return datasource
43
+ }
44
+ }
45
+
46
+ export async function getWithEnvVars(datasourceId: string) {
47
+ const appDb = context.getAppDB()
48
+ const datasource = await appDb.get(datasourceId)
49
+ return enrichDatasourceWithValues(datasource)
50
+ }
51
+
52
+ function hasAuthConfigs(datasource: Datasource) {
53
+ return datasource.source === SourceName.REST && datasource.config?.authConfigs
54
+ }
55
+
56
+ function useEnvVars(str: any) {
57
+ if (typeof str !== "string") {
58
+ return false
59
+ }
60
+ const blocks = findHBSBlocks(str)
61
+ return blocks.find(block => block.includes(ENV_VAR_PREFIX)) != null
62
+ }
63
+
64
+ export async function removeSecrets(datasources: Datasource[]) {
65
+ const definitions = await getDefinitions()
66
+ for (let datasource of datasources) {
67
+ const schema = definitions[datasource.source]
68
+ if (datasource.config) {
69
+ // strip secrets from response, so they don't show in the network request
70
+ if (datasource.config.auth) {
71
+ delete datasource.config.auth
72
+ }
73
+ // specific to REST datasources, contains passwords
74
+ if (hasAuthConfigs(datasource)) {
75
+ const configs = datasource.config.authConfigs as RestAuthConfig[]
76
+ for (let config of configs) {
77
+ if (config.type !== RestAuthType.BASIC) {
78
+ continue
79
+ }
80
+ const basic = config.config as RestBasicAuthConfig
81
+ if (!useEnvVars(basic.password)) {
82
+ basic.password = PASSWORD_REPLACEMENT
83
+ }
84
+ }
85
+ }
86
+ // remove general passwords
87
+ for (let key of Object.keys(datasource.config)) {
88
+ if (
89
+ schema.datasource?.[key]?.type === DatasourceFieldType.PASSWORD &&
90
+ !useEnvVars(datasource.config[key])
91
+ ) {
92
+ datasource.config[key] = PASSWORD_REPLACEMENT
93
+ }
94
+ }
95
+ }
96
+ }
97
+ return datasources
98
+ }
99
+
100
+ export async function removeSecretSingle(datasource: Datasource) {
101
+ return (await removeSecrets([datasource]))[0]
102
+ }
103
+
104
+ export function mergeConfigs(update: Datasource, old: Datasource) {
105
+ if (!update.config) {
106
+ return update
107
+ }
108
+ // specific to REST datasources, fix the auth configs again if required
109
+ if (hasAuthConfigs(update)) {
110
+ const configs = update.config.authConfigs as RestAuthConfig[]
111
+ const oldConfigs = old.config?.authConfigs as RestAuthConfig[]
112
+ for (let config of configs) {
113
+ if (config.type !== RestAuthType.BASIC) {
114
+ continue
115
+ }
116
+ const basic = config.config as RestBasicAuthConfig
117
+ const oldBasic = oldConfigs.find(old => old.name === config.name)
118
+ ?.config as RestBasicAuthConfig
119
+ if (basic.password === PASSWORD_REPLACEMENT) {
120
+ basic.password = oldBasic.password
121
+ }
122
+ }
123
+ }
124
+ // update back to actual passwords for everything else
125
+ for (let [key, value] of Object.entries(update.config)) {
126
+ if (value !== PASSWORD_REPLACEMENT) {
127
+ continue
128
+ }
129
+ if (old.config?.[key]) {
130
+ update.config[key] = old.config?.[key]
131
+ } else {
132
+ delete update.config[key]
133
+ }
134
+ }
135
+ return update
136
+ }
@@ -0,0 +1,5 @@
1
+ import * as datasources from "./datasources"
2
+
3
+ export default {
4
+ ...datasources,
5
+ }
@@ -0,0 +1,5 @@
1
+ import * as queries from "./queries"
2
+
3
+ export default {
4
+ ...queries,
5
+ }
@@ -0,0 +1,50 @@
1
+ import { getEnvironmentVariables } from "../../utils"
2
+ import { processStringSync } from "@budibase/string-templates"
3
+
4
+ export async function enrichContext(
5
+ fields: Record<string, any>,
6
+ inputs = {}
7
+ ): Promise<Record<string, any>> {
8
+ const enrichedQuery: Record<string, any> = Array.isArray(fields) ? [] : {}
9
+ if (!fields || !inputs) {
10
+ return enrichedQuery
11
+ }
12
+ const env = await getEnvironmentVariables()
13
+ const parameters = { ...inputs, env }
14
+ // enrich the fields with dynamic parameters
15
+ for (let key of Object.keys(fields)) {
16
+ if (fields[key] == null) {
17
+ continue
18
+ }
19
+ if (typeof fields[key] === "object") {
20
+ // enrich nested fields object
21
+ enrichedQuery[key] = await enrichContext(fields[key], parameters)
22
+ } else if (typeof fields[key] === "string") {
23
+ // enrich string value as normal
24
+ enrichedQuery[key] = processStringSync(fields[key], parameters, {
25
+ noEscaping: true,
26
+ noHelpers: true,
27
+ escapeNewlines: true,
28
+ })
29
+ } else {
30
+ enrichedQuery[key] = fields[key]
31
+ }
32
+ }
33
+ if (
34
+ enrichedQuery.json ||
35
+ enrichedQuery.customData ||
36
+ enrichedQuery.requestBody
37
+ ) {
38
+ try {
39
+ enrichedQuery.json = JSON.parse(
40
+ enrichedQuery.json ||
41
+ enrichedQuery.customData ||
42
+ enrichedQuery.requestBody
43
+ )
44
+ } catch (err) {
45
+ // no json found, ignore
46
+ }
47
+ delete enrichedQuery.customData
48
+ }
49
+ return enrichedQuery
50
+ }
@@ -6,6 +6,7 @@ import {
6
6
  isSQL,
7
7
  } from "../../../integrations/utils"
8
8
  import { Table, Database } from "@budibase/types"
9
+ import datasources from "../datasources"
9
10
 
10
11
  async function getAllInternalTables(db?: Database): Promise<Table[]> {
11
12
  if (!db) {
@@ -23,9 +24,11 @@ async function getAllInternalTables(db?: Database): Promise<Table[]> {
23
24
  }))
24
25
  }
25
26
 
26
- async function getAllExternalTables(datasourceId: any): Promise<Table[]> {
27
+ async function getAllExternalTables(
28
+ datasourceId: any
29
+ ): Promise<Record<string, Table>> {
27
30
  const db = context.getAppDB()
28
- const datasource = await db.get(datasourceId)
31
+ const datasource = await datasources.get(datasourceId, { enriched: true })
29
32
  if (!datasource || !datasource.entities) {
30
33
  throw "Datasource is not configured fully."
31
34
  }
@@ -44,7 +47,7 @@ async function getTable(tableId: any): Promise<Table> {
44
47
  const db = context.getAppDB()
45
48
  if (isExternalTable(tableId)) {
46
49
  let { datasourceId, tableName } = breakExternalTableId(tableId)
47
- const datasource = await db.get(datasourceId)
50
+ const datasource = await datasources.get(datasourceId!)
48
51
  const table = await getExternalTable(datasourceId, tableName)
49
52
  return { ...table, sql: isSQL(datasource) }
50
53
  } else {
package/src/sdk/index.ts CHANGED
@@ -2,6 +2,8 @@ import { default as backups } from "./app/backups"
2
2
  import { default as tables } from "./app/tables"
3
3
  import { default as automations } from "./app/automations"
4
4
  import { default as applications } from "./app/applications"
5
+ import { default as datasources } from "./app/datasources"
6
+ import { default as queries } from "./app/queries"
5
7
  import { default as rows } from "./app/rows"
6
8
  import { default as users } from "./users"
7
9
 
@@ -12,6 +14,8 @@ const sdk = {
12
14
  applications,
13
15
  rows,
14
16
  users,
17
+ datasources,
18
+ queries,
15
19
  }
16
20
 
17
21
  // default export for TS
@@ -0,0 +1,16 @@
1
+ import { environmentVariables } from "@budibase/pro"
2
+ import { context, db as dbCore } from "@budibase/backend-core"
3
+ import { AppEnvironment } from "@budibase/types"
4
+
5
+ export async function getEnvironmentVariables() {
6
+ let envVars = context.getEnvironmentVariables()
7
+ if (!envVars) {
8
+ const appId = context.getAppId()
9
+ const appEnv = dbCore.isDevAppID(appId)
10
+ ? AppEnvironment.DEVELOPMENT
11
+ : AppEnvironment.PRODUCTION
12
+
13
+ envVars = await environmentVariables.fetchValues(appEnv)
14
+ }
15
+ return envVars
16
+ }
@@ -364,20 +364,23 @@ class TestConfiguration {
364
364
  // create dev app
365
365
  // clear any old app
366
366
  this.appId = null
367
- // @ts-ignore
368
- await context.updateAppId(null)
369
- this.app = await this._req({ name: appName }, null, controllers.app.create)
370
- this.appId = this.app.appId
371
- // @ts-ignore
372
- await context.updateAppId(this.appId)
373
-
374
- // create production app
375
- this.prodApp = await this.publish()
367
+ await context.doInAppContext(null, async () => {
368
+ this.app = await this._req(
369
+ { name: appName },
370
+ null,
371
+ controllers.app.create
372
+ )
373
+ this.appId = this.app.appId
374
+ })
375
+ return await context.doInAppContext(this.appId, async () => {
376
+ // create production app
377
+ this.prodApp = await this.publish()
376
378
 
377
- this.allApps.push(this.prodApp)
378
- this.allApps.push(this.app)
379
+ this.allApps.push(this.prodApp)
380
+ this.allApps.push(this.app)
379
381
 
380
- return this.app
382
+ return this.app
383
+ })
381
384
  }
382
385
 
383
386
  async publish() {
@@ -1,8 +1,14 @@
1
- import { roles, permissions } from "@budibase/backend-core"
1
+ import { permissions, roles } from "@budibase/backend-core"
2
2
  import { createHomeScreen } from "../../constants/screens"
3
3
  import { EMPTY_LAYOUT } from "../../constants/layouts"
4
4
  import { cloneDeep } from "lodash/fp"
5
- import { TRIGGER_DEFINITIONS, ACTION_DEFINITIONS } from "../../automations"
5
+ import { ACTION_DEFINITIONS, TRIGGER_DEFINITIONS } from "../../automations"
6
+ import {
7
+ Automation,
8
+ AutomationActionStepId,
9
+ AutomationTriggerStepId,
10
+ } from "@budibase/types"
11
+
6
12
  const { v4: uuidv4 } = require("uuid")
7
13
 
8
14
  export const TENANT_ID = "default"
@@ -116,6 +122,63 @@ export function basicAutomation() {
116
122
  }
117
123
  }
118
124
 
125
+ export function loopAutomation(tableId: string, loopOpts?: any): Automation {
126
+ if (!loopOpts) {
127
+ loopOpts = {
128
+ option: "Array",
129
+ binding: "{{ steps.1.rows }}",
130
+ }
131
+ }
132
+ const automation: any = {
133
+ name: "looping",
134
+ type: "automation",
135
+ definition: {
136
+ steps: [
137
+ {
138
+ id: "b",
139
+ type: "ACTION",
140
+ stepId: AutomationActionStepId.QUERY_ROWS,
141
+ internal: true,
142
+ inputs: {
143
+ tableId,
144
+ },
145
+ schema: ACTION_DEFINITIONS.QUERY_ROWS.schema,
146
+ },
147
+ {
148
+ id: "c",
149
+ type: "ACTION",
150
+ stepId: AutomationActionStepId.LOOP,
151
+ internal: true,
152
+ inputs: loopOpts,
153
+ blockToLoop: "d",
154
+ schema: ACTION_DEFINITIONS.LOOP.schema,
155
+ },
156
+ {
157
+ id: "d",
158
+ type: "ACTION",
159
+ internal: true,
160
+ stepId: AutomationActionStepId.SERVER_LOG,
161
+ inputs: {
162
+ text: "log statement",
163
+ },
164
+ schema: ACTION_DEFINITIONS.SERVER_LOG.schema,
165
+ },
166
+ ],
167
+ trigger: {
168
+ id: "a",
169
+ type: "TRIGGER",
170
+ event: "row:save",
171
+ stepId: AutomationTriggerStepId.ROW_SAVED,
172
+ inputs: {
173
+ tableId,
174
+ },
175
+ schema: TRIGGER_DEFINITIONS.ROW_SAVED.schema,
176
+ },
177
+ },
178
+ }
179
+ return automation as Automation
180
+ }
181
+
119
182
  export function basicRow(tableId: string) {
120
183
  return {
121
184
  name: "Test Contact",