@budibase/server 2.2.12-alpha.44 → 2.2.12-alpha.45

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 (423) hide show
  1. package/__mocks__/node-fetch.ts +2 -0
  2. package/builder/assets/{index.94c085f6.js → index.353f1284.js} +392 -386
  3. package/builder/assets/{index.80229ab4.css → index.f9c1cb26.css} +2 -2
  4. package/builder/index.html +2 -2
  5. package/coverage/clover.xml +1872 -1762
  6. package/coverage/coverage-final.json +83 -78
  7. package/coverage/lcov-report/index.html +141 -96
  8. package/coverage/lcov-report/src/api/controllers/analytics.ts.html +1 -1
  9. package/coverage/lcov-report/src/api/controllers/apikeys.ts.html +1 -1
  10. package/coverage/lcov-report/src/api/controllers/application.ts.html +158 -137
  11. package/coverage/lcov-report/src/api/controllers/auth.ts.html +1 -1
  12. package/coverage/lcov-report/src/api/controllers/automation.ts.html +1 -1
  13. package/coverage/lcov-report/src/api/controllers/backup.ts.html +1 -1
  14. package/coverage/lcov-report/src/api/controllers/cloud.ts.html +1 -1
  15. package/coverage/lcov-report/src/api/controllers/component.ts.html +1 -1
  16. package/coverage/lcov-report/src/api/controllers/datasource.ts.html +99 -75
  17. package/coverage/lcov-report/src/api/controllers/deploy/Deployment.ts.html +12 -12
  18. package/coverage/lcov-report/src/api/controllers/deploy/index.html +1 -1
  19. package/coverage/lcov-report/src/api/controllers/deploy/index.ts.html +69 -69
  20. package/coverage/lcov-report/src/api/controllers/dev.ts.html +1 -1
  21. package/coverage/lcov-report/src/api/controllers/index.html +24 -24
  22. package/coverage/lcov-report/src/api/controllers/integration.ts.html +1 -1
  23. package/coverage/lcov-report/src/api/controllers/layout.ts.html +1 -1
  24. package/coverage/lcov-report/src/api/controllers/metadata.ts.html +1 -1
  25. package/coverage/lcov-report/src/api/controllers/migrations.ts.html +1 -1
  26. package/coverage/lcov-report/src/api/controllers/permission.ts.html +1 -1
  27. package/coverage/lcov-report/src/api/controllers/plugin/file.ts.html +2 -2
  28. package/coverage/lcov-report/src/api/controllers/plugin/github.ts.html +4 -4
  29. package/coverage/lcov-report/src/api/controllers/plugin/index.html +1 -1
  30. package/coverage/lcov-report/src/api/controllers/plugin/index.ts.html +14 -14
  31. package/coverage/lcov-report/src/api/controllers/plugin/npm.ts.html +5 -5
  32. package/coverage/lcov-report/src/api/controllers/plugin/uploaders.ts.html +5 -5
  33. package/coverage/lcov-report/src/api/controllers/plugin/url.ts.html +3 -3
  34. package/coverage/lcov-report/src/api/controllers/plugin/utils.ts.html +3 -3
  35. package/coverage/lcov-report/src/api/controllers/public/applications.ts.html +1 -1
  36. package/coverage/lcov-report/src/api/controllers/public/index.html +1 -1
  37. package/coverage/lcov-report/src/api/controllers/public/mapping/applications.ts.html +1 -1
  38. package/coverage/lcov-report/src/api/controllers/public/mapping/index.html +1 -1
  39. package/coverage/lcov-report/src/api/controllers/public/mapping/index.ts.html +1 -1
  40. package/coverage/lcov-report/src/api/controllers/public/mapping/queries.ts.html +1 -1
  41. package/coverage/lcov-report/src/api/controllers/public/mapping/rows.ts.html +1 -1
  42. package/coverage/lcov-report/src/api/controllers/public/mapping/tables.ts.html +1 -1
  43. package/coverage/lcov-report/src/api/controllers/public/mapping/users.ts.html +1 -1
  44. package/coverage/lcov-report/src/api/controllers/public/queries.ts.html +1 -1
  45. package/coverage/lcov-report/src/api/controllers/public/rows.ts.html +1 -1
  46. package/coverage/lcov-report/src/api/controllers/public/tables.ts.html +1 -1
  47. package/coverage/lcov-report/src/api/controllers/public/users.ts.html +1 -1
  48. package/coverage/lcov-report/src/api/controllers/public/utils.ts.html +1 -1
  49. package/coverage/lcov-report/src/api/controllers/query/import/index.html +1 -1
  50. package/coverage/lcov-report/src/api/controllers/query/import/index.ts.html +1 -1
  51. package/coverage/lcov-report/src/api/controllers/query/import/sources/base/index.html +1 -1
  52. package/coverage/lcov-report/src/api/controllers/query/import/sources/base/index.ts.html +1 -1
  53. package/coverage/lcov-report/src/api/controllers/query/import/sources/base/openapi.ts.html +1 -1
  54. package/coverage/lcov-report/src/api/controllers/query/import/sources/curl.ts.html +1 -1
  55. package/coverage/lcov-report/src/api/controllers/query/import/sources/index.html +1 -1
  56. package/coverage/lcov-report/src/api/controllers/query/import/sources/openapi2.ts.html +1 -1
  57. package/coverage/lcov-report/src/api/controllers/query/import/sources/openapi3.ts.html +1 -1
  58. package/coverage/lcov-report/src/api/controllers/query/index.html +7 -7
  59. package/coverage/lcov-report/src/api/controllers/query/index.ts.html +70 -46
  60. package/coverage/lcov-report/src/api/controllers/query/validation.ts.html +1 -1
  61. package/coverage/lcov-report/src/api/controllers/role.ts.html +1 -1
  62. package/coverage/lcov-report/src/api/controllers/routing.ts.html +1 -1
  63. package/coverage/lcov-report/src/api/controllers/row/ExternalRequest.ts.html +9 -9
  64. package/coverage/lcov-report/src/api/controllers/row/external.ts.html +11 -14
  65. package/coverage/lcov-report/src/api/controllers/row/index.html +15 -15
  66. package/coverage/lcov-report/src/api/controllers/row/index.ts.html +1 -1
  67. package/coverage/lcov-report/src/api/controllers/row/internal.ts.html +1 -1
  68. package/coverage/lcov-report/src/api/controllers/row/internalSearch.ts.html +1 -1
  69. package/coverage/lcov-report/src/api/controllers/row/staticFormula.ts.html +1 -1
  70. package/coverage/lcov-report/src/api/controllers/row/utils.ts.html +4 -4
  71. package/coverage/lcov-report/src/api/controllers/screen.ts.html +1 -1
  72. package/coverage/lcov-report/src/api/controllers/script.ts.html +1 -1
  73. package/coverage/lcov-report/src/api/controllers/static/index.html +1 -1
  74. package/coverage/lcov-report/src/api/controllers/static/index.ts.html +21 -24
  75. package/coverage/lcov-report/src/api/controllers/table/bulkFormula.ts.html +1 -1
  76. package/coverage/lcov-report/src/api/controllers/table/external.ts.html +21 -15
  77. package/coverage/lcov-report/src/api/controllers/table/index.html +13 -13
  78. package/coverage/lcov-report/src/api/controllers/table/index.ts.html +1 -1
  79. package/coverage/lcov-report/src/api/controllers/table/internal.ts.html +1 -1
  80. package/coverage/lcov-report/src/api/controllers/table/utils.ts.html +1 -1
  81. package/coverage/lcov-report/src/api/controllers/templates.ts.html +1 -1
  82. package/coverage/lcov-report/src/api/controllers/user.ts.html +1 -1
  83. package/coverage/lcov-report/src/api/controllers/view/exporters.ts.html +1 -1
  84. package/coverage/lcov-report/src/api/controllers/view/index.html +1 -1
  85. package/coverage/lcov-report/src/api/controllers/view/index.ts.html +1 -1
  86. package/coverage/lcov-report/src/api/controllers/view/utils.ts.html +1 -1
  87. package/coverage/lcov-report/src/api/controllers/view/viewBuilder.ts.html +1 -1
  88. package/coverage/lcov-report/src/api/controllers/webhook.ts.html +57 -51
  89. package/coverage/lcov-report/src/api/index.html +1 -1
  90. package/coverage/lcov-report/src/api/index.ts.html +7 -7
  91. package/coverage/lcov-report/src/api/routes/analytics.ts.html +1 -1
  92. package/coverage/lcov-report/src/api/routes/apikeys.ts.html +1 -1
  93. package/coverage/lcov-report/src/api/routes/application.ts.html +1 -1
  94. package/coverage/lcov-report/src/api/routes/auth.ts.html +1 -1
  95. package/coverage/lcov-report/src/api/routes/automation.ts.html +1 -1
  96. package/coverage/lcov-report/src/api/routes/backup.ts.html +1 -1
  97. package/coverage/lcov-report/src/api/routes/cloud.ts.html +1 -1
  98. package/coverage/lcov-report/src/api/routes/component.ts.html +1 -1
  99. package/coverage/lcov-report/src/api/routes/datasource.ts.html +1 -1
  100. package/coverage/lcov-report/src/api/routes/deploy.ts.html +1 -1
  101. package/coverage/lcov-report/src/api/routes/dev.ts.html +1 -1
  102. package/coverage/lcov-report/src/api/routes/index.html +5 -5
  103. package/coverage/lcov-report/src/api/routes/index.ts.html +10 -4
  104. package/coverage/lcov-report/src/api/routes/integration.ts.html +1 -1
  105. package/coverage/lcov-report/src/api/routes/layout.ts.html +1 -1
  106. package/coverage/lcov-report/src/api/routes/metadata.ts.html +1 -1
  107. package/coverage/lcov-report/src/api/routes/migrations.ts.html +1 -1
  108. package/coverage/lcov-report/src/api/routes/permission.ts.html +1 -1
  109. package/coverage/lcov-report/src/api/routes/plugin.ts.html +1 -1
  110. package/coverage/lcov-report/src/api/routes/public/applications.ts.html +1 -1
  111. package/coverage/lcov-report/src/api/routes/public/index.html +1 -1
  112. package/coverage/lcov-report/src/api/routes/public/index.ts.html +1 -1
  113. package/coverage/lcov-report/src/api/routes/public/middleware/index.html +1 -1
  114. package/coverage/lcov-report/src/api/routes/public/middleware/mapper.ts.html +1 -1
  115. package/coverage/lcov-report/src/api/routes/public/queries.ts.html +1 -1
  116. package/coverage/lcov-report/src/api/routes/public/rows.ts.html +1 -1
  117. package/coverage/lcov-report/src/api/routes/public/tables.ts.html +1 -1
  118. package/coverage/lcov-report/src/api/routes/public/tests/index.html +1 -1
  119. package/coverage/lcov-report/src/api/routes/public/tests/utils.ts.html +1 -1
  120. package/coverage/lcov-report/src/api/routes/public/users.ts.html +1 -1
  121. package/coverage/lcov-report/src/api/routes/public/utils/Endpoint.ts.html +1 -1
  122. package/coverage/lcov-report/src/api/routes/public/utils/index.html +1 -1
  123. package/coverage/lcov-report/src/api/routes/query.ts.html +1 -1
  124. package/coverage/lcov-report/src/api/routes/role.ts.html +1 -1
  125. package/coverage/lcov-report/src/api/routes/routing.ts.html +1 -1
  126. package/coverage/lcov-report/src/api/routes/row.ts.html +2 -2
  127. package/coverage/lcov-report/src/api/routes/screen.ts.html +1 -1
  128. package/coverage/lcov-report/src/api/routes/script.ts.html +1 -1
  129. package/coverage/lcov-report/src/api/routes/static.ts.html +1 -1
  130. package/coverage/lcov-report/src/api/routes/table.ts.html +1 -1
  131. package/coverage/lcov-report/src/api/routes/templates.ts.html +1 -1
  132. package/coverage/lcov-report/src/api/routes/tests/utilities/TestFunctions.ts.html +1 -1
  133. package/coverage/lcov-report/src/api/routes/tests/utilities/index.html +1 -1
  134. package/coverage/lcov-report/src/api/routes/tests/utilities/index.ts.html +1 -1
  135. package/coverage/lcov-report/src/api/routes/user.ts.html +1 -1
  136. package/coverage/lcov-report/src/api/routes/utils/index.html +1 -1
  137. package/coverage/lcov-report/src/api/routes/utils/validators.ts.html +1 -1
  138. package/coverage/lcov-report/src/api/routes/view.ts.html +1 -1
  139. package/coverage/lcov-report/src/api/routes/webhook.ts.html +1 -1
  140. package/coverage/lcov-report/src/app.ts.html +1 -1
  141. package/coverage/lcov-report/src/automations/actions.ts.html +1 -1
  142. package/coverage/lcov-report/src/automations/automationUtils.ts.html +1 -1
  143. package/coverage/lcov-report/src/automations/bullboard.ts.html +2 -2
  144. package/coverage/lcov-report/src/automations/index.html +15 -15
  145. package/coverage/lcov-report/src/automations/index.ts.html +1 -1
  146. package/coverage/lcov-report/src/automations/logging/index.html +1 -1
  147. package/coverage/lcov-report/src/automations/logging/index.ts.html +4 -4
  148. package/coverage/lcov-report/src/automations/steps/bash.ts.html +1 -1
  149. package/coverage/lcov-report/src/automations/steps/createRow.ts.html +1 -1
  150. package/coverage/lcov-report/src/automations/steps/delay.ts.html +1 -1
  151. package/coverage/lcov-report/src/automations/steps/deleteRow.ts.html +1 -1
  152. package/coverage/lcov-report/src/automations/steps/discord.ts.html +1 -1
  153. package/coverage/lcov-report/src/automations/steps/executeQuery.ts.html +1 -1
  154. package/coverage/lcov-report/src/automations/steps/executeScript.ts.html +1 -1
  155. package/coverage/lcov-report/src/automations/steps/filter.ts.html +1 -1
  156. package/coverage/lcov-report/src/automations/steps/index.html +1 -1
  157. package/coverage/lcov-report/src/automations/steps/integromat.ts.html +1 -1
  158. package/coverage/lcov-report/src/automations/steps/loop.ts.html +1 -1
  159. package/coverage/lcov-report/src/automations/steps/outgoingWebhook.ts.html +1 -1
  160. package/coverage/lcov-report/src/automations/steps/queryRows.ts.html +1 -1
  161. package/coverage/lcov-report/src/automations/steps/sendSmtpEmail.ts.html +1 -1
  162. package/coverage/lcov-report/src/automations/steps/serverLog.ts.html +1 -1
  163. package/coverage/lcov-report/src/automations/steps/slack.ts.html +1 -1
  164. package/coverage/lcov-report/src/automations/steps/updateRow.ts.html +1 -1
  165. package/coverage/lcov-report/src/automations/steps/utils.ts.html +1 -1
  166. package/coverage/lcov-report/src/automations/steps/zapier.ts.html +1 -1
  167. package/coverage/lcov-report/src/automations/tests/utilities/index.html +1 -1
  168. package/coverage/lcov-report/src/automations/tests/utilities/index.ts.html +1 -1
  169. package/coverage/lcov-report/src/automations/triggerInfo/app.ts.html +1 -1
  170. package/coverage/lcov-report/src/automations/triggerInfo/cron.ts.html +1 -1
  171. package/coverage/lcov-report/src/automations/triggerInfo/index.html +1 -1
  172. package/coverage/lcov-report/src/automations/triggerInfo/index.ts.html +2 -2
  173. package/coverage/lcov-report/src/automations/triggerInfo/rowDeleted.ts.html +1 -1
  174. package/coverage/lcov-report/src/automations/triggerInfo/rowSaved.ts.html +1 -1
  175. package/coverage/lcov-report/src/automations/triggerInfo/rowUpdated.ts.html +1 -1
  176. package/coverage/lcov-report/src/automations/triggerInfo/webhook.ts.html +1 -1
  177. package/coverage/lcov-report/src/automations/triggers.ts.html +1 -1
  178. package/coverage/lcov-report/src/automations/utils.ts.html +21 -21
  179. package/coverage/lcov-report/src/constants/index.html +1 -1
  180. package/coverage/lcov-report/src/constants/index.ts.html +2 -2
  181. package/coverage/lcov-report/src/constants/layouts.ts.html +1 -1
  182. package/coverage/lcov-report/src/constants/screens.ts.html +1 -1
  183. package/coverage/lcov-report/src/db/defaultData/datasource_bb_default.ts.html +1 -1
  184. package/coverage/lcov-report/src/db/defaultData/employeeImport.ts.html +1 -1
  185. package/coverage/lcov-report/src/db/defaultData/expensesImport.ts.html +1 -1
  186. package/coverage/lcov-report/src/db/defaultData/index.html +1 -1
  187. package/coverage/lcov-report/src/db/defaultData/inventoryImport.ts.html +1 -1
  188. package/coverage/lcov-report/src/db/defaultData/jobsImport.ts.html +1 -1
  189. package/coverage/lcov-report/src/db/dynamoClient.ts.html +15 -15
  190. package/coverage/lcov-report/src/db/inMemoryView.ts.html +1 -1
  191. package/coverage/lcov-report/src/db/index.html +1 -1
  192. package/coverage/lcov-report/src/db/index.ts.html +1 -1
  193. package/coverage/lcov-report/src/db/linkedRows/LinkController.ts.html +1 -1
  194. package/coverage/lcov-report/src/db/linkedRows/LinkDocument.ts.html +1 -1
  195. package/coverage/lcov-report/src/db/linkedRows/index.html +1 -1
  196. package/coverage/lcov-report/src/db/linkedRows/index.ts.html +1 -1
  197. package/coverage/lcov-report/src/db/linkedRows/linkUtils.ts.html +1 -1
  198. package/coverage/lcov-report/src/db/newid.ts.html +3 -3
  199. package/coverage/lcov-report/src/db/utils.ts.html +17 -17
  200. package/coverage/lcov-report/src/definitions/automations.ts.html +5 -2
  201. package/coverage/lcov-report/src/definitions/datasource.ts.html +2 -2
  202. package/coverage/lcov-report/src/definitions/index.html +1 -1
  203. package/coverage/lcov-report/src/environment.ts.html +9 -9
  204. package/coverage/lcov-report/src/events/AutomationEmitter.ts.html +1 -1
  205. package/coverage/lcov-report/src/events/BudibaseEmitter.ts.html +1 -1
  206. package/coverage/lcov-report/src/events/index.html +1 -1
  207. package/coverage/lcov-report/src/events/index.ts.html +1 -1
  208. package/coverage/lcov-report/src/events/utils.ts.html +1 -1
  209. package/coverage/lcov-report/src/index.html +7 -7
  210. package/coverage/lcov-report/src/index.ts.html +5 -5
  211. package/coverage/lcov-report/src/integrations/airtable.ts.html +5 -5
  212. package/coverage/lcov-report/src/integrations/arangodb.ts.html +5 -5
  213. package/coverage/lcov-report/src/integrations/base/index.html +11 -11
  214. package/coverage/lcov-report/src/integrations/base/query.ts.html +13 -7
  215. package/coverage/lcov-report/src/integrations/base/sql.ts.html +12 -12
  216. package/coverage/lcov-report/src/integrations/base/sqlTable.ts.html +8 -8
  217. package/coverage/lcov-report/src/integrations/base/utils.ts.html +2 -2
  218. package/coverage/lcov-report/src/integrations/couchdb.ts.html +5 -5
  219. package/coverage/lcov-report/src/integrations/dynamodb.ts.html +9 -9
  220. package/coverage/lcov-report/src/integrations/elasticsearch.ts.html +5 -5
  221. package/coverage/lcov-report/src/integrations/firebase.ts.html +5 -5
  222. package/coverage/lcov-report/src/integrations/googlesheets.ts.html +11 -11
  223. package/coverage/lcov-report/src/integrations/index.html +1 -1
  224. package/coverage/lcov-report/src/integrations/index.ts.html +37 -37
  225. package/coverage/lcov-report/src/integrations/microsoftSqlServer.ts.html +8 -8
  226. package/coverage/lcov-report/src/integrations/mongodb.ts.html +11 -11
  227. package/coverage/lcov-report/src/integrations/mysql.ts.html +11 -11
  228. package/coverage/lcov-report/src/integrations/oracle.ts.html +13 -13
  229. package/coverage/lcov-report/src/integrations/postgres.ts.html +10 -10
  230. package/coverage/lcov-report/src/integrations/queries/index.html +19 -19
  231. package/coverage/lcov-report/src/integrations/queries/sql.ts.html +15 -150
  232. package/coverage/lcov-report/src/integrations/redis.ts.html +5 -5
  233. package/coverage/lcov-report/src/integrations/rest.ts.html +24 -24
  234. package/coverage/lcov-report/src/integrations/s3.ts.html +6 -6
  235. package/coverage/lcov-report/src/integrations/snowflake.ts.html +5 -5
  236. package/coverage/lcov-report/src/integrations/tests/TestConfiguration.js.html +1 -1
  237. package/coverage/lcov-report/src/integrations/tests/index.html +1 -1
  238. package/coverage/lcov-report/src/integrations/utils.ts.html +2 -2
  239. package/coverage/lcov-report/src/middleware/appInfo.ts.html +1 -1
  240. package/coverage/lcov-report/src/middleware/authorized.ts.html +19 -19
  241. package/coverage/lcov-report/src/middleware/builder.ts.html +13 -13
  242. package/coverage/lcov-report/src/middleware/currentapp.ts.html +33 -33
  243. package/coverage/lcov-report/src/middleware/index.html +1 -1
  244. package/coverage/lcov-report/src/middleware/joi-validator.ts.html +1 -1
  245. package/coverage/lcov-report/src/middleware/publicApi.ts.html +1 -1
  246. package/coverage/lcov-report/src/middleware/resourceId.ts.html +1 -1
  247. package/coverage/lcov-report/src/middleware/selfhost.ts.html +1 -1
  248. package/coverage/lcov-report/src/middleware/utils.ts.html +3 -3
  249. package/coverage/lcov-report/src/migrations/functions/appUrls.ts.html +1 -1
  250. package/coverage/lcov-report/src/migrations/functions/backfill/app/automations.ts.html +1 -1
  251. package/coverage/lcov-report/src/migrations/functions/backfill/app/datasources.ts.html +1 -1
  252. package/coverage/lcov-report/src/migrations/functions/backfill/app/index.html +1 -1
  253. package/coverage/lcov-report/src/migrations/functions/backfill/app/layouts.ts.html +1 -1
  254. package/coverage/lcov-report/src/migrations/functions/backfill/app/queries.ts.html +1 -1
  255. package/coverage/lcov-report/src/migrations/functions/backfill/app/roles.ts.html +1 -1
  256. package/coverage/lcov-report/src/migrations/functions/backfill/app/screens.ts.html +1 -1
  257. package/coverage/lcov-report/src/migrations/functions/backfill/app/tables.ts.html +1 -1
  258. package/coverage/lcov-report/src/migrations/functions/backfill/app.ts.html +1 -1
  259. package/coverage/lcov-report/src/migrations/functions/backfill/global/configs.ts.html +1 -1
  260. package/coverage/lcov-report/src/migrations/functions/backfill/global/index.html +1 -1
  261. package/coverage/lcov-report/src/migrations/functions/backfill/global/quotas.ts.html +1 -1
  262. package/coverage/lcov-report/src/migrations/functions/backfill/global/users.ts.html +1 -1
  263. package/coverage/lcov-report/src/migrations/functions/backfill/global.ts.html +1 -1
  264. package/coverage/lcov-report/src/migrations/functions/backfill/index.html +1 -1
  265. package/coverage/lcov-report/src/migrations/functions/backfill/index.ts.html +1 -1
  266. package/coverage/lcov-report/src/migrations/functions/backfill/installation.ts.html +1 -1
  267. package/coverage/lcov-report/src/migrations/functions/index.html +1 -1
  268. package/coverage/lcov-report/src/migrations/functions/syncQuotas.ts.html +1 -1
  269. package/coverage/lcov-report/src/migrations/functions/tableSettings.ts.html +1 -1
  270. package/coverage/lcov-report/src/migrations/functions/usageQuotas/index.html +1 -1
  271. package/coverage/lcov-report/src/migrations/functions/usageQuotas/index.ts.html +1 -1
  272. package/coverage/lcov-report/src/migrations/functions/usageQuotas/syncApps.ts.html +1 -1
  273. package/coverage/lcov-report/src/migrations/functions/usageQuotas/syncPlugins.ts.html +1 -1
  274. package/coverage/lcov-report/src/migrations/functions/usageQuotas/syncRows.ts.html +1 -1
  275. package/coverage/lcov-report/src/migrations/functions/userEmailViewCasing.ts.html +1 -1
  276. package/coverage/lcov-report/src/migrations/index.html +1 -1
  277. package/coverage/lcov-report/src/migrations/index.ts.html +1 -1
  278. package/coverage/lcov-report/src/migrations/tests/helpers.ts.html +1 -1
  279. package/coverage/lcov-report/src/migrations/tests/index.html +1 -1
  280. package/coverage/lcov-report/src/migrations/tests/structures.ts.html +1 -1
  281. package/coverage/lcov-report/src/sdk/app/applications/index.html +1 -1
  282. package/coverage/lcov-report/src/sdk/app/applications/index.ts.html +1 -1
  283. package/coverage/lcov-report/src/sdk/app/applications/sync.ts.html +18 -18
  284. package/coverage/lcov-report/src/sdk/app/applications/utils.ts.html +7 -7
  285. package/coverage/lcov-report/src/sdk/app/automations/index.html +1 -1
  286. package/coverage/lcov-report/src/sdk/app/automations/index.ts.html +1 -1
  287. package/coverage/lcov-report/src/sdk/app/automations/webhook.ts.html +1 -1
  288. package/coverage/lcov-report/src/sdk/app/backups/constants.ts.html +1 -1
  289. package/coverage/lcov-report/src/sdk/app/backups/exports.ts.html +1 -1
  290. package/coverage/lcov-report/src/sdk/app/backups/imports.ts.html +1 -1
  291. package/coverage/lcov-report/src/sdk/app/backups/index.html +1 -1
  292. package/coverage/lcov-report/src/sdk/app/backups/index.ts.html +1 -1
  293. package/coverage/lcov-report/src/sdk/app/backups/statistics.ts.html +1 -1
  294. package/coverage/lcov-report/src/sdk/app/datasources/datasources.ts.html +379 -0
  295. package/coverage/lcov-report/src/sdk/app/datasources/index.html +131 -0
  296. package/coverage/lcov-report/src/sdk/app/datasources/index.ts.html +100 -0
  297. package/coverage/lcov-report/src/sdk/app/queries/index.html +131 -0
  298. package/coverage/lcov-report/src/sdk/app/queries/index.ts.html +100 -0
  299. package/coverage/lcov-report/src/sdk/app/queries/queries.ts.html +235 -0
  300. package/coverage/lcov-report/src/sdk/app/rows/attachments.ts.html +1 -1
  301. package/coverage/lcov-report/src/sdk/app/rows/index.html +1 -1
  302. package/coverage/lcov-report/src/sdk/app/rows/index.ts.html +1 -1
  303. package/coverage/lcov-report/src/sdk/app/rows/rows.ts.html +1 -1
  304. package/coverage/lcov-report/src/sdk/app/tables/index.html +11 -11
  305. package/coverage/lcov-report/src/sdk/app/tables/index.ts.html +18 -9
  306. package/coverage/lcov-report/src/sdk/index.html +5 -5
  307. package/coverage/lcov-report/src/sdk/index.ts.html +17 -5
  308. package/coverage/lcov-report/src/sdk/users/index.html +1 -1
  309. package/coverage/lcov-report/src/sdk/users/index.ts.html +1 -1
  310. package/coverage/lcov-report/src/sdk/users/utils.ts.html +20 -20
  311. package/coverage/lcov-report/src/sdk/utils/index.html +116 -0
  312. package/coverage/lcov-report/src/sdk/utils/index.ts.html +133 -0
  313. package/coverage/lcov-report/src/startup.ts.html +1 -1
  314. package/coverage/lcov-report/src/tests/utilities/TestConfiguration.ts.html +89 -80
  315. package/coverage/lcov-report/src/tests/utilities/controllers.ts.html +4 -4
  316. package/coverage/lcov-report/src/tests/utilities/index.html +5 -5
  317. package/coverage/lcov-report/src/tests/utilities/index.ts.html +1 -1
  318. package/coverage/lcov-report/src/tests/utilities/structures.ts.html +4 -4
  319. package/coverage/lcov-report/src/threads/automation.ts.html +42 -24
  320. package/coverage/lcov-report/src/threads/index.html +28 -28
  321. package/coverage/lcov-report/src/threads/index.ts.html +1 -1
  322. package/coverage/lcov-report/src/threads/query.ts.html +68 -29
  323. package/coverage/lcov-report/src/threads/utils.ts.html +1 -1
  324. package/coverage/lcov-report/src/utilities/budibaseDir.ts.html +2 -2
  325. package/coverage/lcov-report/src/utilities/centralPath.ts.html +11 -11
  326. package/coverage/lcov-report/src/utilities/fileSystem/app.ts.html +8 -8
  327. package/coverage/lcov-report/src/utilities/fileSystem/clientLibrary.ts.html +1 -1
  328. package/coverage/lcov-report/src/utilities/fileSystem/filesystem.ts.html +18 -12
  329. package/coverage/lcov-report/src/utilities/fileSystem/index.html +17 -17
  330. package/coverage/lcov-report/src/utilities/fileSystem/index.ts.html +1 -1
  331. package/coverage/lcov-report/src/utilities/fileSystem/plugin.ts.html +5 -8
  332. package/coverage/lcov-report/src/utilities/fileSystem/processor.ts.html +1 -1
  333. package/coverage/lcov-report/src/utilities/fileSystem/template.ts.html +3 -3
  334. package/coverage/lcov-report/src/utilities/global.ts.html +33 -33
  335. package/coverage/lcov-report/src/utilities/index.html +16 -16
  336. package/coverage/lcov-report/src/utilities/index.ts.html +12 -12
  337. package/coverage/lcov-report/src/utilities/redis.ts.html +1 -1
  338. package/coverage/lcov-report/src/utilities/routing/index.html +1 -1
  339. package/coverage/lcov-report/src/utilities/routing/index.ts.html +1 -1
  340. package/coverage/lcov-report/src/utilities/rowProcessor/index.html +1 -1
  341. package/coverage/lcov-report/src/utilities/rowProcessor/index.ts.html +1 -1
  342. package/coverage/lcov-report/src/utilities/rowProcessor/map.ts.html +1 -1
  343. package/coverage/lcov-report/src/utilities/rowProcessor/utils.ts.html +1 -1
  344. package/coverage/lcov-report/src/utilities/schema.ts.html +1 -1
  345. package/coverage/lcov-report/src/utilities/scriptRunner.ts.html +1 -1
  346. package/coverage/lcov-report/src/utilities/security.ts.html +1 -1
  347. package/coverage/lcov-report/src/utilities/usageQuota/index.html +1 -1
  348. package/coverage/lcov-report/src/utilities/usageQuota/rows.ts.html +1 -1
  349. package/coverage/lcov-report/src/utilities/usageQuota/usageQuoteReset.ts.html +1 -1
  350. package/coverage/lcov-report/src/utilities/users.ts.html +1 -1
  351. package/coverage/lcov-report/src/utilities/workerRequests.ts.html +1 -1
  352. package/coverage/lcov-report/src/watch.ts.html +1 -1
  353. package/coverage/lcov-report/src/websocket.ts.html +3 -3
  354. package/coverage/lcov.info +2986 -2796
  355. package/dist/api/controllers/application.js +73 -74
  356. package/dist/api/controllers/datasource.js +24 -15
  357. package/dist/api/controllers/query/index.js +18 -11
  358. package/dist/api/controllers/row/ExternalRequest.js +5 -3
  359. package/dist/api/controllers/row/external.js +6 -5
  360. package/dist/api/controllers/row/utils.js +5 -2
  361. package/dist/api/controllers/static/index.js +38 -38
  362. package/dist/api/controllers/table/external.js +8 -5
  363. package/dist/api/controllers/webhook.js +45 -43
  364. package/dist/api/routes/index.js +2 -0
  365. package/dist/api/routes/row.js +2 -2
  366. package/dist/index.js +2 -2
  367. package/dist/integrations/base/query.js +7 -2
  368. package/dist/integrations/base/sqlTable.js +14 -14
  369. package/dist/integrations/dynamodb.js +8 -5
  370. package/dist/integrations/mysql.js +2 -2
  371. package/dist/integrations/queries/sql.js +73 -100
  372. package/dist/integrations/rest.js +14 -14
  373. package/dist/package.json +6 -6
  374. package/dist/sdk/app/datasources/datasources.js +113 -0
  375. package/dist/sdk/app/datasources/index.js +27 -0
  376. package/dist/sdk/app/queries/index.js +27 -0
  377. package/dist/sdk/app/queries/queries.js +60 -0
  378. package/dist/sdk/app/tables/index.js +6 -2
  379. package/dist/sdk/index.js +4 -0
  380. package/dist/sdk/utils/index.js +29 -0
  381. package/dist/threads/automation.js +9 -2
  382. package/dist/threads/query.js +27 -13
  383. package/dist/tsconfig.build.tsbuildinfo +1 -1
  384. package/dist/utilities/fileSystem/filesystem.js +36 -34
  385. package/dist/utilities/fileSystem/plugin.js +17 -14
  386. package/dist/utilities/fileSystem/template.js +7 -4
  387. package/package.json +7 -7
  388. package/scripts/dev/manage.js +1 -0
  389. package/src/api/controllers/application.ts +81 -74
  390. package/src/api/controllers/datasource.ts +33 -25
  391. package/src/api/controllers/query/index.ts +47 -39
  392. package/src/api/controllers/row/ExternalRequest.ts +2 -2
  393. package/src/api/controllers/row/external.ts +3 -4
  394. package/src/api/controllers/row/utils.ts +2 -2
  395. package/src/api/controllers/static/index.ts +17 -18
  396. package/src/api/controllers/table/external.ts +8 -6
  397. package/src/api/controllers/webhook.ts +48 -46
  398. package/src/api/routes/index.ts +2 -0
  399. package/src/api/routes/row.ts +1 -1
  400. package/src/api/routes/tests/datasource.spec.ts +35 -1
  401. package/src/definitions/automations.ts +1 -0
  402. package/src/index.ts +1 -1
  403. package/src/integrations/base/query.ts +3 -1
  404. package/src/integrations/base/sqlTable.ts +1 -1
  405. package/src/integrations/dynamodb.ts +3 -3
  406. package/src/integrations/mysql.ts +1 -1
  407. package/src/integrations/queries/sql.ts +5 -50
  408. package/src/integrations/rest.ts +8 -8
  409. package/src/migrations/functions/usageQuotas/tests/syncRows.spec.ts +10 -6
  410. package/src/sdk/app/datasources/datasources.ts +98 -0
  411. package/src/sdk/app/datasources/index.ts +5 -0
  412. package/src/sdk/app/queries/index.ts +5 -0
  413. package/src/sdk/app/queries/queries.ts +50 -0
  414. package/src/sdk/app/tables/index.ts +6 -3
  415. package/src/sdk/index.ts +4 -0
  416. package/src/sdk/utils/index.ts +16 -0
  417. package/src/tests/utilities/TestConfiguration.ts +15 -12
  418. package/src/threads/automation.ts +9 -3
  419. package/src/threads/definitions.ts +3 -0
  420. package/src/threads/query.ts +28 -15
  421. package/src/utilities/fileSystem/filesystem.ts +6 -4
  422. package/src/utilities/fileSystem/plugin.ts +3 -4
  423. package/src/utilities/fileSystem/template.ts +2 -2
@@ -1,55 +1,10 @@
1
- import { findHBSBlocks, processStringSync } from "@budibase/string-templates"
1
+ import { findHBSBlocks } from "@budibase/string-templates"
2
2
  import { DatasourcePlus } from "@budibase/types"
3
+ import sdk from "../../sdk"
3
4
 
4
5
  const CONST_CHAR_REGEX = new RegExp("'[^']*'", "g")
5
6
 
6
- export function enrichQueryFields(
7
- fields: { [key: string]: any },
8
- parameters = {}
9
- ) {
10
- const enrichedQuery: { [key: string]: any } = Array.isArray(fields) ? [] : {}
11
- if (!fields || !parameters) {
12
- return enrichedQuery
13
- }
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] = enrichQueryFields(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
- }
51
-
52
- export function interpolateSQL(
7
+ export async function interpolateSQL(
53
8
  fields: { [key: string]: any },
54
9
  parameters: { [key: string]: any },
55
10
  integration: DatasourcePlus
@@ -90,7 +45,7 @@ export function interpolateSQL(
90
45
  else if (listRegexMatch) {
91
46
  arrays.push(binding)
92
47
  // determine the length of the array
93
- const value = enrichQueryFields([binding], parameters)[0]
48
+ const value = (await sdk.queries.enrichContext([binding], parameters))[0]
94
49
  .split(",")
95
50
  .map((val: string) => val.trim())
96
51
  // build a string like ($1, $2, $3)
@@ -109,7 +64,7 @@ export function interpolateSQL(
109
64
  }
110
65
  // replicate the knex structure
111
66
  fields.sql = sql
112
- fields.bindings = enrichQueryFields(variables, parameters)
67
+ fields.bindings = await sdk.queries.enrichContext(variables, parameters)
113
68
  // check for arrays in the data
114
69
  let updated: string[] = []
115
70
  for (let i = 0; i < variables.length; i++) {
@@ -16,11 +16,11 @@ import {
16
16
  import { get } from "lodash"
17
17
  import * as https from "https"
18
18
  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")
19
+ import fetch from "node-fetch"
20
+ import { formatBytes } from "../utilities"
21
+ import { performance } from "perf_hooks"
22
+ import FormData from "form-data"
23
+ import { URLSearchParams } from "url"
24
24
 
25
25
  const BodyTypes = {
26
26
  NONE: "none",
@@ -204,12 +204,12 @@ class RestIntegration implements IntegrationBase {
204
204
 
205
205
  // Append page number or cursor param if configured
206
206
  if (pageParam && paginationValues.page != null) {
207
- params.append(pageParam, paginationValues.page)
207
+ params.append(pageParam, paginationValues.page as string)
208
208
  }
209
209
 
210
210
  // Append page size param if configured
211
211
  if (sizeParam && paginationValues.limit != null) {
212
- params.append(sizeParam, paginationValues.limit)
212
+ params.append(sizeParam, String(paginationValues.limit))
213
213
  }
214
214
 
215
215
  // Prepend query string with pagination params
@@ -280,7 +280,7 @@ class RestIntegration implements IntegrationBase {
280
280
  case BodyTypes.ENCODED:
281
281
  const params = new URLSearchParams()
282
282
  for (let [key, value] of Object.entries(object)) {
283
- params.append(key, value)
283
+ params.append(key, value as string)
284
284
  }
285
285
  addPaginationToBody((key: string, value: any) => {
286
286
  params.append(key, value)
@@ -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,98 @@
1
+ import { context } from "@budibase/backend-core"
2
+ import { processObjectSync, findHBSBlocks } from "@budibase/string-templates"
3
+ import {
4
+ Datasource,
5
+ DatasourceFieldType,
6
+ Integration,
7
+ PASSWORD_REPLACEMENT,
8
+ } from "@budibase/types"
9
+ import { cloneDeep } from "lodash/fp"
10
+ import { getEnvironmentVariables } from "../../utils"
11
+ import { getDefinitions } from "../../../integrations"
12
+
13
+ const ENV_VAR_PREFIX = "env."
14
+ const USER_PREFIX = "user"
15
+
16
+ async function enrichDatasourceWithValues(datasource: Datasource) {
17
+ const cloned = cloneDeep(datasource)
18
+ const env = await getEnvironmentVariables()
19
+ const processed = processObjectSync(cloned, { env }, { onlyFound: true })
20
+ return {
21
+ datasource: processed as Datasource,
22
+ envVars: env as Record<string, string>,
23
+ }
24
+ }
25
+
26
+ export async function enrich(datasource: Datasource) {
27
+ const { datasource: response } = await enrichDatasourceWithValues(datasource)
28
+ return response
29
+ }
30
+
31
+ export async function get(
32
+ datasourceId: string,
33
+ opts?: { enriched: boolean }
34
+ ): Promise<Datasource> {
35
+ const appDb = context.getAppDB()
36
+ const datasource = await appDb.get(datasourceId)
37
+ if (opts?.enriched) {
38
+ return (await enrichDatasourceWithValues(datasource)).datasource
39
+ } else {
40
+ return datasource
41
+ }
42
+ }
43
+
44
+ export async function getWithEnvVars(datasourceId: string) {
45
+ const appDb = context.getAppDB()
46
+ const datasource = await appDb.get(datasourceId)
47
+ return enrichDatasourceWithValues(datasource)
48
+ }
49
+
50
+ export async function removeSecrets(datasources: Datasource[]) {
51
+ const definitions = await getDefinitions()
52
+ for (let datasource of datasources) {
53
+ const schema = definitions[datasource.source]
54
+ if (datasource.config) {
55
+ // strip secrets from response, so they don't show in the network request
56
+ if (datasource.config.auth) {
57
+ delete datasource.config.auth
58
+ }
59
+ // remove passwords
60
+ for (let key of Object.keys(datasource.config)) {
61
+ if (typeof datasource.config[key] !== "string") {
62
+ continue
63
+ }
64
+ const blocks = findHBSBlocks(datasource.config[key] as string)
65
+ const usesEnvVars =
66
+ blocks.find(block => block.includes(ENV_VAR_PREFIX)) != null
67
+ if (
68
+ !usesEnvVars &&
69
+ schema.datasource?.[key]?.type === DatasourceFieldType.PASSWORD
70
+ ) {
71
+ datasource.config[key] = PASSWORD_REPLACEMENT
72
+ }
73
+ }
74
+ }
75
+ }
76
+ return datasources
77
+ }
78
+
79
+ export async function removeSecretSingle(datasource: Datasource) {
80
+ return (await removeSecrets([datasource]))[0]
81
+ }
82
+
83
+ export function mergeConfigs(update: Datasource, old: Datasource) {
84
+ if (!update.config) {
85
+ return update
86
+ }
87
+ for (let [key, value] of Object.entries(update.config)) {
88
+ if (value !== PASSWORD_REPLACEMENT) {
89
+ continue
90
+ }
91
+ if (old.config?.[key]) {
92
+ update.config[key] = old.config?.[key]
93
+ } else {
94
+ delete update.config[key]
95
+ }
96
+ }
97
+ return update
98
+ }
@@ -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() {
@@ -16,7 +16,6 @@ import { storeLog } from "../automations/logging"
16
16
  import { Automation, AutomationStep, AutomationStatus } from "@budibase/types"
17
17
  import {
18
18
  LoopStep,
19
- LoopStepType,
20
19
  LoopInput,
21
20
  TriggerOutput,
22
21
  AutomationContext,
@@ -26,6 +25,7 @@ import { WorkerCallback } from "./definitions"
26
25
  import { context, logging } from "@budibase/backend-core"
27
26
  import { processObject } from "@budibase/string-templates"
28
27
  import { cloneDeep } from "lodash/fp"
28
+ import * as sdkUtils from "../sdk/utils"
29
29
  import env from "../environment"
30
30
  const FILTER_STEP_ID = actions.ACTION_DEFINITIONS.FILTER.stepId
31
31
  const LOOP_STEP_ID = actions.ACTION_DEFINITIONS.LOOP.stepId
@@ -225,6 +225,8 @@ class Orchestrator {
225
225
  }
226
226
 
227
227
  async execute() {
228
+ // this will retrieve from context created at start of thread
229
+ this._context.env = await sdkUtils.getEnvironmentVariables()
228
230
  let automation = this._automation
229
231
  let stopped = false
230
232
  let loopStep: AutomationStep | undefined = undefined
@@ -478,7 +480,11 @@ export const removeStalled = async (job: Job) => {
478
480
  throw new Error("Unable to execute, event doesn't contain app ID.")
479
481
  }
480
482
  await context.doInAppContext(appId, async () => {
481
- const automationOrchestrator = new Orchestrator(job)
482
- await automationOrchestrator.stopCron("stalled")
483
+ const envVars = await sdkUtils.getEnvironmentVariables()
484
+ // put into automation thread for whole context
485
+ await context.doInEnvironmentContext(envVars, async () => {
486
+ const automationOrchestrator = new Orchestrator(job)
487
+ await automationOrchestrator.stopCron("stalled")
488
+ })
483
489
  })
484
490
  }
@@ -1,3 +1,5 @@
1
+ import { EnvironmentVariablesDecrypted } from "@budibase/types"
2
+
1
3
  export type WorkerCallback = (error: any, response?: any) => void
2
4
 
3
5
  export interface QueryEvent {
@@ -9,6 +11,7 @@ export interface QueryEvent {
9
11
  pagination?: any
10
12
  transformer: any
11
13
  queryId: string
14
+ environmentVariables?: Record<string, string>
12
15
  ctx?: any
13
16
  }
14
17
 
@@ -6,13 +6,11 @@ import { getIntegration } from "../integrations"
6
6
  import { processStringSync } from "@budibase/string-templates"
7
7
  import { context, cache, auth } from "@budibase/backend-core"
8
8
  import { getGlobalIDFromUserMetadataID } from "../db/utils"
9
+ import sdk from "../sdk"
9
10
  import { cloneDeep } from "lodash/fp"
10
11
 
11
- const { isSQL } = require("../integrations/utils")
12
- const {
13
- enrichQueryFields,
14
- interpolateSQL,
15
- } = require("../integrations/queries/sql")
12
+ import { isSQL } from "../integrations/utils"
13
+ import { interpolateSQL } from "../integrations/queries/sql"
16
14
 
17
15
  class QueryRunner {
18
16
  datasource: any
@@ -62,10 +60,11 @@ class QueryRunner {
62
60
  }
63
61
 
64
62
  if (datasourceClone.config.authConfigs) {
65
- datasourceClone.config.authConfigs =
66
- datasourceClone.config.authConfigs.map((config: any) => {
67
- return enrichQueryFields(config, this.ctx)
68
- })
63
+ const updatedConfigs = []
64
+ for (let config of datasourceClone.config.authConfigs) {
65
+ updatedConfigs.push(await sdk.queries.enrichContext(config, this.ctx))
66
+ }
67
+ datasourceClone.config.authConfigs = updatedConfigs
69
68
  }
70
69
 
71
70
  const integration = new Integration(datasourceClone.config)
@@ -75,12 +74,15 @@ class QueryRunner {
75
74
 
76
75
  // Enrich the parameters with the addition context items.
77
76
  // 'user' is now a reserved variable key in mapping parameters
78
- const enrichedParameters = enrichQueryFields(parameters, this.ctx)
77
+ const enrichedParameters = await sdk.queries.enrichContext(
78
+ parameters,
79
+ this.ctx
80
+ )
79
81
  const enrichedContext = { ...enrichedParameters, ...this.ctx }
80
82
 
81
83
  // Parse global headers
82
84
  if (datasourceClone.config.defaultHeaders) {
83
- datasourceClone.config.defaultHeaders = enrichQueryFields(
85
+ datasourceClone.config.defaultHeaders = await sdk.queries.enrichContext(
84
86
  datasourceClone.config.defaultHeaders,
85
87
  enrichedContext
86
88
  )
@@ -89,9 +91,9 @@ class QueryRunner {
89
91
  let query
90
92
  // handle SQL injections by interpolating the variables
91
93
  if (isSQL(datasourceClone)) {
92
- query = interpolateSQL(fieldsClone, enrichedParameters, integration)
94
+ query = await interpolateSQL(fieldsClone, enrichedParameters, integration)
93
95
  } else {
94
- query = enrichQueryFields(fieldsClone, enrichedContext)
96
+ query = await sdk.queries.enrichContext(fieldsClone, enrichedContext)
95
97
  }
96
98
 
97
99
  // Add pagination values for REST queries
@@ -166,7 +168,9 @@ class QueryRunner {
166
168
  async runAnotherQuery(queryId: string, parameters: any) {
167
169
  const db = context.getAppDB()
168
170
  const query = await db.get(queryId)
169
- const datasource = await db.get(query.datasourceId)
171
+ const datasource = await sdk.datasources.get(query.datasourceId, {
172
+ enriched: true,
173
+ })
170
174
  return new QueryRunner(
171
175
  {
172
176
  datasource,
@@ -280,7 +284,7 @@ class QueryRunner {
280
284
  }
281
285
 
282
286
  export function execute(input: QueryEvent, callback: WorkerCallback) {
283
- context.doInAppContext(input.appId!, async () => {
287
+ const run = async () => {
284
288
  const Runner = new QueryRunner(input)
285
289
  try {
286
290
  const response = await Runner.execute()
@@ -288,5 +292,14 @@ export function execute(input: QueryEvent, callback: WorkerCallback) {
288
292
  } catch (err) {
289
293
  callback(err)
290
294
  }
295
+ }
296
+ context.doInAppContext(input.appId!, async () => {
297
+ if (input.environmentVariables) {
298
+ return context.doInEnvironmentContext(input.environmentVariables, () => {
299
+ return run()
300
+ })
301
+ } else {
302
+ return run()
303
+ }
291
304
  })
292
305
  }
@@ -1,10 +1,10 @@
1
1
  import { PathLike } from "fs"
2
- const { budibaseTempDir } = require("../budibaseDir")
3
- const fs = require("fs")
4
- const { join } = require("path")
5
- const uuid = require("uuid/v4")
2
+ import fs from "fs"
3
+ import { budibaseTempDir } from "../budibaseDir"
4
+ import { join } from "path"
6
5
  import env from "../../environment"
7
6
  import tar from "tar"
7
+ const uuid = require("uuid/v4")
8
8
 
9
9
  export const TOP_LEVEL_PATH = join(__dirname, "..", "..", "..")
10
10
 
@@ -112,6 +112,7 @@ export const sendTempFile = (fileContents: any) => {
112
112
  * allows a centralised location to check logic is all good.
113
113
  */
114
114
  export const readFileSync = (filepath: PathLike, options = "utf8") => {
115
+ // @ts-ignore
115
116
  return fs.readFileSync(filepath, options)
116
117
  }
117
118
 
@@ -147,6 +148,7 @@ export const findFileRec = (startPath: PathLike, filter: string): any => {
147
148
 
148
149
  const files = fs.readdirSync(startPath)
149
150
  for (let i = 0, len = files.length; i < len; i++) {
151
+ // @ts-ignore
150
152
  const filename = join(startPath, files[i])
151
153
  const stat = fs.lstatSync(filename)
152
154
 
@@ -1,8 +1,7 @@
1
1
  import { Plugin } from "@budibase/types"
2
-
3
- const { budibaseTempDir } = require("../budibaseDir")
4
- const fs = require("fs")
5
- const { join } = require("path")
2
+ import { budibaseTempDir } from "../budibaseDir"
3
+ import fs from "fs"
4
+ import { join } from "path"
6
5
  import { objectStore } from "@budibase/backend-core"
7
6
 
8
7
  const DATASOURCE_PATH = join(budibaseTempDir(), "datasource")
@@ -1,5 +1,5 @@
1
- const fs = require("fs")
2
- const { join } = require("path")
1
+ import fs from "fs"
2
+ import { join } from "path"
3
3
  import { ObjectStoreBuckets } from "../../constants"
4
4
  import { objectStore } from "@budibase/backend-core"
5
5