@budibase/server 2.2.11-alpha.1 → 2.2.11

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 (469) hide show
  1. package/__mocks__/aws-sdk.ts +0 -19
  2. package/__mocks__/node-fetch.ts +0 -78
  3. package/builder/assets/{index.f0a10c2a.js → index.7481e2b4.js} +359 -362
  4. package/builder/assets/{index.fa480d5b.css → index.9cb087df.css} +2 -2
  5. package/builder/index.html +2 -2
  6. package/coverage/clover.xml +5075 -5062
  7. package/coverage/coverage-final.json +265 -265
  8. package/coverage/lcov-report/index.html +222 -207
  9. package/coverage/lcov-report/src/api/controllers/analytics.ts.html +7 -7
  10. package/coverage/lcov-report/src/api/controllers/apikeys.ts.html +5 -5
  11. package/coverage/lcov-report/src/api/controllers/application.ts.html +183 -258
  12. package/coverage/lcov-report/src/api/controllers/auth.ts.html +11 -11
  13. package/coverage/lcov-report/src/api/controllers/automation.ts.html +51 -51
  14. package/coverage/lcov-report/src/api/controllers/backup.ts.html +6 -6
  15. package/coverage/lcov-report/src/api/controllers/cloud.ts.html +79 -91
  16. package/coverage/lcov-report/src/api/controllers/component.ts.html +5 -5
  17. package/coverage/lcov-report/src/api/controllers/datasource.ts.html +30 -30
  18. package/coverage/lcov-report/src/api/controllers/deploy/Deployment.ts.html +14 -17
  19. package/coverage/lcov-report/src/api/controllers/deploy/index.html +19 -19
  20. package/coverage/lcov-report/src/api/controllers/deploy/index.ts.html +195 -141
  21. package/coverage/lcov-report/src/api/controllers/dev.ts.html +18 -18
  22. package/coverage/lcov-report/src/api/controllers/index.html +51 -51
  23. package/coverage/lcov-report/src/api/controllers/integration.ts.html +4 -4
  24. package/coverage/lcov-report/src/api/controllers/layout.ts.html +6 -6
  25. package/coverage/lcov-report/src/api/controllers/metadata.ts.html +9 -9
  26. package/coverage/lcov-report/src/api/controllers/migrations.ts.html +4 -4
  27. package/coverage/lcov-report/src/api/controllers/permission.ts.html +13 -13
  28. package/coverage/lcov-report/src/api/controllers/plugin/file.ts.html +19 -19
  29. package/coverage/lcov-report/src/api/controllers/plugin/github.ts.html +63 -63
  30. package/coverage/lcov-report/src/api/controllers/plugin/index.html +72 -72
  31. package/coverage/lcov-report/src/api/controllers/plugin/index.ts.html +135 -150
  32. package/coverage/lcov-report/src/api/controllers/plugin/npm.ts.html +55 -55
  33. package/coverage/lcov-report/src/api/controllers/plugin/uploaders.ts.html +11 -11
  34. package/coverage/lcov-report/src/api/controllers/plugin/url.ts.html +18 -18
  35. package/coverage/lcov-report/src/api/controllers/plugin/utils.ts.html +20 -20
  36. package/coverage/lcov-report/src/api/controllers/public/applications.ts.html +16 -67
  37. package/coverage/lcov-report/src/api/controllers/public/index.html +15 -15
  38. package/coverage/lcov-report/src/api/controllers/public/mapping/applications.ts.html +2 -2
  39. package/coverage/lcov-report/src/api/controllers/public/mapping/index.html +1 -1
  40. package/coverage/lcov-report/src/api/controllers/public/mapping/index.ts.html +7 -7
  41. package/coverage/lcov-report/src/api/controllers/public/mapping/queries.ts.html +2 -2
  42. package/coverage/lcov-report/src/api/controllers/public/mapping/rows.ts.html +2 -2
  43. package/coverage/lcov-report/src/api/controllers/public/mapping/tables.ts.html +2 -2
  44. package/coverage/lcov-report/src/api/controllers/public/mapping/users.ts.html +2 -2
  45. package/coverage/lcov-report/src/api/controllers/public/queries.ts.html +6 -6
  46. package/coverage/lcov-report/src/api/controllers/public/rows.ts.html +10 -10
  47. package/coverage/lcov-report/src/api/controllers/public/tables.ts.html +9 -9
  48. package/coverage/lcov-report/src/api/controllers/public/users.ts.html +11 -11
  49. package/coverage/lcov-report/src/api/controllers/public/utils.ts.html +6 -6
  50. package/coverage/lcov-report/src/api/controllers/query/import/index.html +1 -1
  51. package/coverage/lcov-report/src/api/controllers/query/import/index.ts.html +8 -8
  52. package/coverage/lcov-report/src/api/controllers/query/import/sources/base/index.html +1 -1
  53. package/coverage/lcov-report/src/api/controllers/query/import/sources/base/index.ts.html +8 -8
  54. package/coverage/lcov-report/src/api/controllers/query/import/sources/base/openapi.ts.html +5 -5
  55. package/coverage/lcov-report/src/api/controllers/query/import/sources/curl.ts.html +8 -8
  56. package/coverage/lcov-report/src/api/controllers/query/import/sources/index.html +1 -1
  57. package/coverage/lcov-report/src/api/controllers/query/import/sources/openapi2.ts.html +10 -10
  58. package/coverage/lcov-report/src/api/controllers/query/import/sources/openapi3.ts.html +14 -14
  59. package/coverage/lcov-report/src/api/controllers/query/index.html +19 -19
  60. package/coverage/lcov-report/src/api/controllers/query/index.ts.html +60 -60
  61. package/coverage/lcov-report/src/api/controllers/query/validation.ts.html +9 -9
  62. package/coverage/lcov-report/src/api/controllers/role.ts.html +8 -8
  63. package/coverage/lcov-report/src/api/controllers/routing.ts.html +6 -6
  64. package/coverage/lcov-report/src/api/controllers/row/ExternalRequest.ts.html +15 -12
  65. package/coverage/lcov-report/src/api/controllers/row/external.ts.html +20 -20
  66. package/coverage/lcov-report/src/api/controllers/row/index.html +1 -1
  67. package/coverage/lcov-report/src/api/controllers/row/index.ts.html +14 -14
  68. package/coverage/lcov-report/src/api/controllers/row/internal.ts.html +52 -55
  69. package/coverage/lcov-report/src/api/controllers/row/internalSearch.ts.html +9 -9
  70. package/coverage/lcov-report/src/api/controllers/row/staticFormula.ts.html +12 -21
  71. package/coverage/lcov-report/src/api/controllers/row/utils.ts.html +14 -17
  72. package/coverage/lcov-report/src/api/controllers/screen.ts.html +26 -26
  73. package/coverage/lcov-report/src/api/controllers/script.ts.html +18 -18
  74. package/coverage/lcov-report/src/api/controllers/static/index.html +11 -11
  75. package/coverage/lcov-report/src/api/controllers/static/index.ts.html +44 -32
  76. package/coverage/lcov-report/src/api/controllers/table/bulkFormula.ts.html +10 -10
  77. package/coverage/lcov-report/src/api/controllers/table/external.ts.html +14 -14
  78. package/coverage/lcov-report/src/api/controllers/table/index.html +19 -19
  79. package/coverage/lcov-report/src/api/controllers/table/index.ts.html +14 -14
  80. package/coverage/lcov-report/src/api/controllers/table/internal.ts.html +17 -17
  81. package/coverage/lcov-report/src/api/controllers/table/utils.ts.html +51 -51
  82. package/coverage/lcov-report/src/api/controllers/templates.ts.html +7 -7
  83. package/coverage/lcov-report/src/api/controllers/user.ts.html +119 -119
  84. package/coverage/lcov-report/src/api/controllers/view/exporters.ts.html +4 -4
  85. package/coverage/lcov-report/src/api/controllers/view/index.html +1 -1
  86. package/coverage/lcov-report/src/api/controllers/view/index.ts.html +49 -49
  87. package/coverage/lcov-report/src/api/controllers/view/utils.ts.html +22 -22
  88. package/coverage/lcov-report/src/api/controllers/view/viewBuilder.ts.html +33 -33
  89. package/coverage/lcov-report/src/api/controllers/webhook.ts.html +14 -14
  90. package/coverage/lcov-report/src/api/index.html +1 -1
  91. package/coverage/lcov-report/src/api/index.ts.html +33 -33
  92. package/coverage/lcov-report/src/api/routes/analytics.ts.html +7 -7
  93. package/coverage/lcov-report/src/api/routes/apikeys.ts.html +8 -8
  94. package/coverage/lcov-report/src/api/routes/application.ts.html +11 -44
  95. package/coverage/lcov-report/src/api/routes/auth.ts.html +6 -6
  96. package/coverage/lcov-report/src/api/routes/automation.ts.html +11 -11
  97. package/coverage/lcov-report/src/api/routes/backup.ts.html +8 -8
  98. package/coverage/lcov-report/src/api/routes/cloud.ts.html +8 -8
  99. package/coverage/lcov-report/src/api/routes/component.ts.html +8 -8
  100. package/coverage/lcov-report/src/api/routes/datasource.ts.html +9 -9
  101. package/coverage/lcov-report/src/api/routes/deploy.ts.html +11 -8
  102. package/coverage/lcov-report/src/api/routes/dev.ts.html +13 -13
  103. package/coverage/lcov-report/src/api/routes/index.html +7 -7
  104. package/coverage/lcov-report/src/api/routes/index.ts.html +37 -40
  105. package/coverage/lcov-report/src/api/routes/integration.ts.html +8 -8
  106. package/coverage/lcov-report/src/api/routes/layout.ts.html +8 -8
  107. package/coverage/lcov-report/src/api/routes/metadata.ts.html +9 -9
  108. package/coverage/lcov-report/src/api/routes/migrations.ts.html +7 -7
  109. package/coverage/lcov-report/src/api/routes/permission.ts.html +9 -9
  110. package/coverage/lcov-report/src/api/routes/plugin.ts.html +8 -8
  111. package/coverage/lcov-report/src/api/routes/public/applications.ts.html +14 -146
  112. package/coverage/lcov-report/src/api/routes/public/index.html +7 -7
  113. package/coverage/lcov-report/src/api/routes/public/index.ts.html +52 -52
  114. package/coverage/lcov-report/src/api/routes/public/middleware/index.html +15 -15
  115. package/coverage/lcov-report/src/api/routes/public/middleware/mapper.ts.html +16 -28
  116. package/coverage/lcov-report/src/api/routes/public/queries.ts.html +9 -9
  117. package/coverage/lcov-report/src/api/routes/public/rows.ts.html +12 -12
  118. package/coverage/lcov-report/src/api/routes/public/tables.ts.html +12 -12
  119. package/coverage/lcov-report/src/api/routes/public/tests/index.html +1 -1
  120. package/coverage/lcov-report/src/api/routes/public/tests/utils.ts.html +1 -1
  121. package/coverage/lcov-report/src/api/routes/public/users.ts.html +12 -12
  122. package/coverage/lcov-report/src/api/routes/public/utils/Endpoint.ts.html +19 -19
  123. package/coverage/lcov-report/src/api/routes/public/utils/index.html +1 -1
  124. package/coverage/lcov-report/src/api/routes/query.ts.html +11 -11
  125. package/coverage/lcov-report/src/api/routes/role.ts.html +9 -9
  126. package/coverage/lcov-report/src/api/routes/routing.ts.html +8 -8
  127. package/coverage/lcov-report/src/api/routes/row.ts.html +11 -11
  128. package/coverage/lcov-report/src/api/routes/screen.ts.html +9 -9
  129. package/coverage/lcov-report/src/api/routes/script.ts.html +1 -1
  130. package/coverage/lcov-report/src/api/routes/static.ts.html +14 -14
  131. package/coverage/lcov-report/src/api/routes/table.ts.html +11 -11
  132. package/coverage/lcov-report/src/api/routes/templates.ts.html +8 -8
  133. package/coverage/lcov-report/src/api/routes/tests/utilities/TestFunctions.ts.html +15 -15
  134. package/coverage/lcov-report/src/api/routes/tests/utilities/index.html +1 -1
  135. package/coverage/lcov-report/src/api/routes/tests/utilities/index.ts.html +24 -24
  136. package/coverage/lcov-report/src/api/routes/user.ts.html +9 -9
  137. package/coverage/lcov-report/src/api/routes/utils/index.html +1 -1
  138. package/coverage/lcov-report/src/api/routes/utils/validators.ts.html +42 -42
  139. package/coverage/lcov-report/src/api/routes/view.ts.html +10 -10
  140. package/coverage/lcov-report/src/api/routes/webhook.ts.html +10 -10
  141. package/coverage/lcov-report/src/app.ts.html +32 -32
  142. package/coverage/lcov-report/src/automations/actions.ts.html +25 -25
  143. package/coverage/lcov-report/src/automations/automationUtils.ts.html +19 -91
  144. package/coverage/lcov-report/src/automations/bullboard.ts.html +11 -11
  145. package/coverage/lcov-report/src/automations/index.html +19 -19
  146. package/coverage/lcov-report/src/automations/index.ts.html +13 -13
  147. package/coverage/lcov-report/src/automations/logging/index.html +1 -1
  148. package/coverage/lcov-report/src/automations/logging/index.ts.html +11 -11
  149. package/coverage/lcov-report/src/automations/steps/bash.ts.html +34 -34
  150. package/coverage/lcov-report/src/automations/steps/createRow.ts.html +7 -7
  151. package/coverage/lcov-report/src/automations/steps/delay.ts.html +5 -5
  152. package/coverage/lcov-report/src/automations/steps/deleteRow.ts.html +7 -7
  153. package/coverage/lcov-report/src/automations/steps/discord.ts.html +33 -33
  154. package/coverage/lcov-report/src/automations/steps/executeQuery.ts.html +35 -35
  155. package/coverage/lcov-report/src/automations/steps/executeScript.ts.html +31 -31
  156. package/coverage/lcov-report/src/automations/steps/filter.ts.html +6 -6
  157. package/coverage/lcov-report/src/automations/steps/index.html +83 -83
  158. package/coverage/lcov-report/src/automations/steps/integromat.ts.html +6 -6
  159. package/coverage/lcov-report/src/automations/steps/loop.ts.html +3 -3
  160. package/coverage/lcov-report/src/automations/steps/outgoingWebhook.ts.html +14 -14
  161. package/coverage/lcov-report/src/automations/steps/queryRows.ts.html +17 -17
  162. package/coverage/lcov-report/src/automations/steps/sendSmtpEmail.ts.html +28 -28
  163. package/coverage/lcov-report/src/automations/steps/serverLog.ts.html +18 -18
  164. package/coverage/lcov-report/src/automations/steps/slack.ts.html +6 -6
  165. package/coverage/lcov-report/src/automations/steps/updateRow.ts.html +7 -7
  166. package/coverage/lcov-report/src/automations/steps/utils.ts.html +16 -16
  167. package/coverage/lcov-report/src/automations/steps/zapier.ts.html +22 -22
  168. package/coverage/lcov-report/src/automations/tests/utilities/index.html +5 -5
  169. package/coverage/lcov-report/src/automations/tests/utilities/index.ts.html +26 -26
  170. package/coverage/lcov-report/src/automations/triggerInfo/app.ts.html +3 -3
  171. package/coverage/lcov-report/src/automations/triggerInfo/cron.ts.html +3 -3
  172. package/coverage/lcov-report/src/automations/triggerInfo/index.html +1 -1
  173. package/coverage/lcov-report/src/automations/triggerInfo/index.ts.html +8 -8
  174. package/coverage/lcov-report/src/automations/triggerInfo/rowDeleted.ts.html +3 -3
  175. package/coverage/lcov-report/src/automations/triggerInfo/rowSaved.ts.html +3 -3
  176. package/coverage/lcov-report/src/automations/triggerInfo/rowUpdated.ts.html +3 -3
  177. package/coverage/lcov-report/src/automations/triggerInfo/webhook.ts.html +3 -3
  178. package/coverage/lcov-report/src/automations/triggers.ts.html +21 -21
  179. package/coverage/lcov-report/src/automations/utils.ts.html +56 -56
  180. package/coverage/lcov-report/src/constants/index.html +1 -1
  181. package/coverage/lcov-report/src/constants/index.ts.html +92 -92
  182. package/coverage/lcov-report/src/constants/layouts.ts.html +4 -4
  183. package/coverage/lcov-report/src/constants/screens.ts.html +5 -5
  184. package/coverage/lcov-report/src/db/defaultData/datasource_bb_default.ts.html +23 -23
  185. package/coverage/lcov-report/src/db/defaultData/employeeImport.ts.html +2 -2
  186. package/coverage/lcov-report/src/db/defaultData/expensesImport.ts.html +2 -2
  187. package/coverage/lcov-report/src/db/defaultData/index.html +1 -1
  188. package/coverage/lcov-report/src/db/defaultData/inventoryImport.ts.html +2 -2
  189. package/coverage/lcov-report/src/db/defaultData/jobsImport.ts.html +2 -2
  190. package/coverage/lcov-report/src/db/dynamoClient.ts.html +16 -16
  191. package/coverage/lcov-report/src/db/inMemoryView.ts.html +5 -5
  192. package/coverage/lcov-report/src/db/index.html +19 -19
  193. package/coverage/lcov-report/src/db/index.ts.html +9 -9
  194. package/coverage/lcov-report/src/db/linkedRows/LinkController.ts.html +8 -8
  195. package/coverage/lcov-report/src/db/linkedRows/LinkDocument.ts.html +4 -4
  196. package/coverage/lcov-report/src/db/linkedRows/index.html +1 -1
  197. package/coverage/lcov-report/src/db/linkedRows/index.ts.html +15 -15
  198. package/coverage/lcov-report/src/db/linkedRows/linkUtils.ts.html +12 -12
  199. package/coverage/lcov-report/src/db/newid.ts.html +4 -4
  200. package/coverage/lcov-report/src/db/utils.ts.html +79 -79
  201. package/coverage/lcov-report/src/definitions/automations.ts.html +4 -4
  202. package/coverage/lcov-report/src/definitions/datasource.ts.html +4 -4
  203. package/coverage/lcov-report/src/definitions/index.html +1 -1
  204. package/coverage/lcov-report/src/environment.ts.html +28 -40
  205. package/coverage/lcov-report/src/events/AutomationEmitter.ts.html +6 -6
  206. package/coverage/lcov-report/src/events/BudibaseEmitter.ts.html +5 -5
  207. package/coverage/lcov-report/src/events/index.html +1 -1
  208. package/coverage/lcov-report/src/events/index.ts.html +4 -4
  209. package/coverage/lcov-report/src/events/utils.ts.html +3 -3
  210. package/coverage/lcov-report/src/index.html +25 -25
  211. package/coverage/lcov-report/src/index.ts.html +1 -1
  212. package/coverage/lcov-report/src/integrations/airtable.ts.html +5 -5
  213. package/coverage/lcov-report/src/integrations/arangodb.ts.html +5 -5
  214. package/coverage/lcov-report/src/integrations/base/index.html +1 -1
  215. package/coverage/lcov-report/src/integrations/base/query.ts.html +3 -3
  216. package/coverage/lcov-report/src/integrations/base/sql.ts.html +14 -14
  217. package/coverage/lcov-report/src/integrations/base/sqlTable.ts.html +8 -8
  218. package/coverage/lcov-report/src/integrations/base/utils.ts.html +3 -3
  219. package/coverage/lcov-report/src/integrations/couchdb.ts.html +5 -5
  220. package/coverage/lcov-report/src/integrations/dynamodb.ts.html +6 -6
  221. package/coverage/lcov-report/src/integrations/elasticsearch.ts.html +5 -5
  222. package/coverage/lcov-report/src/integrations/firebase.ts.html +5 -5
  223. package/coverage/lcov-report/src/integrations/googlesheets.ts.html +12 -12
  224. package/coverage/lcov-report/src/integrations/index.html +5 -5
  225. package/coverage/lcov-report/src/integrations/index.ts.html +47 -35
  226. package/coverage/lcov-report/src/integrations/microsoftSqlServer.ts.html +8 -8
  227. package/coverage/lcov-report/src/integrations/mongodb.ts.html +5 -5
  228. package/coverage/lcov-report/src/integrations/mysql.ts.html +10 -10
  229. package/coverage/lcov-report/src/integrations/oracle.ts.html +13 -13
  230. package/coverage/lcov-report/src/integrations/postgres.ts.html +42 -42
  231. package/coverage/lcov-report/src/integrations/queries/index.html +1 -1
  232. package/coverage/lcov-report/src/integrations/queries/sql.ts.html +13 -13
  233. package/coverage/lcov-report/src/integrations/redis.ts.html +5 -5
  234. package/coverage/lcov-report/src/integrations/rest.ts.html +16 -16
  235. package/coverage/lcov-report/src/integrations/s3.ts.html +6 -6
  236. package/coverage/lcov-report/src/integrations/snowflake.ts.html +5 -5
  237. package/coverage/lcov-report/src/integrations/tests/TestConfiguration.js.html +1 -1
  238. package/coverage/lcov-report/src/integrations/tests/index.html +1 -1
  239. package/coverage/lcov-report/src/integrations/utils.ts.html +36 -36
  240. package/coverage/lcov-report/src/middleware/appInfo.ts.html +7 -7
  241. package/coverage/lcov-report/src/middleware/authorized.ts.html +28 -28
  242. package/coverage/lcov-report/src/middleware/builder.ts.html +17 -17
  243. package/coverage/lcov-report/src/middleware/currentapp.ts.html +39 -39
  244. package/coverage/lcov-report/src/middleware/index.html +1 -1
  245. package/coverage/lcov-report/src/middleware/joi-validator.ts.html +1 -1
  246. package/coverage/lcov-report/src/middleware/publicApi.ts.html +4 -4
  247. package/coverage/lcov-report/src/middleware/resourceId.ts.html +22 -22
  248. package/coverage/lcov-report/src/middleware/selfhost.ts.html +1 -1
  249. package/coverage/lcov-report/src/middleware/utils.ts.html +4 -4
  250. package/coverage/lcov-report/src/migrations/functions/appUrls.ts.html +4 -4
  251. package/coverage/lcov-report/src/migrations/functions/backfill/app/automations.ts.html +5 -5
  252. package/coverage/lcov-report/src/migrations/functions/backfill/app/datasources.ts.html +5 -5
  253. package/coverage/lcov-report/src/migrations/functions/backfill/app/index.html +1 -1
  254. package/coverage/lcov-report/src/migrations/functions/backfill/app/layouts.ts.html +5 -5
  255. package/coverage/lcov-report/src/migrations/functions/backfill/app/queries.ts.html +7 -7
  256. package/coverage/lcov-report/src/migrations/functions/backfill/app/roles.ts.html +5 -5
  257. package/coverage/lcov-report/src/migrations/functions/backfill/app/screens.ts.html +5 -5
  258. package/coverage/lcov-report/src/migrations/functions/backfill/app/tables.ts.html +4 -4
  259. package/coverage/lcov-report/src/migrations/functions/backfill/app.ts.html +19 -19
  260. package/coverage/lcov-report/src/migrations/functions/backfill/global/configs.ts.html +10 -13
  261. package/coverage/lcov-report/src/migrations/functions/backfill/global/index.html +1 -1
  262. package/coverage/lcov-report/src/migrations/functions/backfill/global/quotas.ts.html +7 -7
  263. package/coverage/lcov-report/src/migrations/functions/backfill/global/users.ts.html +6 -6
  264. package/coverage/lcov-report/src/migrations/functions/backfill/global.ts.html +15 -15
  265. package/coverage/lcov-report/src/migrations/functions/backfill/index.html +1 -1
  266. package/coverage/lcov-report/src/migrations/functions/backfill/index.ts.html +5 -5
  267. package/coverage/lcov-report/src/migrations/functions/backfill/installation.ts.html +8 -8
  268. package/coverage/lcov-report/src/migrations/functions/index.html +1 -1
  269. package/coverage/lcov-report/src/migrations/functions/syncQuotas.ts.html +6 -6
  270. package/coverage/lcov-report/src/migrations/functions/tableSettings.ts.html +6 -6
  271. package/coverage/lcov-report/src/migrations/functions/usageQuotas/index.html +1 -1
  272. package/coverage/lcov-report/src/migrations/functions/usageQuotas/index.ts.html +2 -2
  273. package/coverage/lcov-report/src/migrations/functions/usageQuotas/syncApps.ts.html +5 -5
  274. package/coverage/lcov-report/src/migrations/functions/usageQuotas/syncPlugins.ts.html +4 -4
  275. package/coverage/lcov-report/src/migrations/functions/usageQuotas/syncRows.ts.html +6 -6
  276. package/coverage/lcov-report/src/migrations/functions/userEmailViewCasing.ts.html +3 -3
  277. package/coverage/lcov-report/src/migrations/index.html +1 -1
  278. package/coverage/lcov-report/src/migrations/index.ts.html +32 -32
  279. package/coverage/lcov-report/src/migrations/tests/helpers.ts.html +1 -1
  280. package/coverage/lcov-report/src/migrations/tests/index.html +1 -1
  281. package/coverage/lcov-report/src/migrations/tests/structures.ts.html +1 -1
  282. package/coverage/lcov-report/src/sdk/app/applications/index.html +15 -15
  283. package/coverage/lcov-report/src/sdk/app/applications/index.ts.html +4 -4
  284. package/coverage/lcov-report/src/sdk/app/applications/sync.ts.html +34 -34
  285. package/coverage/lcov-report/src/sdk/app/applications/utils.ts.html +9 -9
  286. package/coverage/lcov-report/src/sdk/app/automations/index.html +1 -1
  287. package/coverage/lcov-report/src/sdk/app/automations/index.ts.html +3 -3
  288. package/coverage/lcov-report/src/sdk/app/automations/webhook.ts.html +6 -6
  289. package/coverage/lcov-report/src/sdk/app/backups/constants.ts.html +3 -3
  290. package/coverage/lcov-report/src/sdk/app/backups/exports.ts.html +17 -17
  291. package/coverage/lcov-report/src/sdk/app/backups/imports.ts.html +99 -117
  292. package/coverage/lcov-report/src/sdk/app/backups/index.html +30 -30
  293. package/coverage/lcov-report/src/sdk/app/backups/index.ts.html +5 -5
  294. package/coverage/lcov-report/src/sdk/app/backups/statistics.ts.html +73 -73
  295. package/coverage/lcov-report/src/sdk/app/rows/attachments.ts.html +265 -0
  296. package/coverage/lcov-report/src/sdk/app/rows/index.html +146 -0
  297. package/coverage/lcov-report/src/sdk/app/rows/index.ts.html +106 -0
  298. package/coverage/lcov-report/src/sdk/app/rows/rows.ts.html +139 -0
  299. package/coverage/lcov-report/src/sdk/app/tables/index.html +1 -1
  300. package/coverage/lcov-report/src/sdk/app/tables/index.ts.html +8 -8
  301. package/coverage/lcov-report/src/sdk/index.html +5 -5
  302. package/coverage/lcov-report/src/sdk/index.ts.html +16 -10
  303. package/coverage/lcov-report/src/sdk/users/index.html +5 -5
  304. package/coverage/lcov-report/src/sdk/users/index.ts.html +3 -3
  305. package/coverage/lcov-report/src/sdk/users/utils.ts.html +34 -34
  306. package/coverage/lcov-report/src/startup.ts.html +42 -42
  307. package/coverage/lcov-report/src/tests/utilities/TestConfiguration.ts.html +125 -182
  308. package/coverage/lcov-report/src/tests/utilities/controllers.ts.html +15 -15
  309. package/coverage/lcov-report/src/tests/utilities/index.html +15 -15
  310. package/coverage/lcov-report/src/tests/utilities/index.ts.html +1 -1
  311. package/coverage/lcov-report/src/tests/utilities/structures.ts.html +30 -30
  312. package/coverage/lcov-report/src/threads/automation.ts.html +103 -34
  313. package/coverage/lcov-report/src/threads/index.html +19 -19
  314. package/coverage/lcov-report/src/threads/index.ts.html +25 -25
  315. package/coverage/lcov-report/src/threads/query.ts.html +71 -71
  316. package/coverage/lcov-report/src/threads/utils.ts.html +18 -18
  317. package/coverage/lcov-report/src/utilities/budibaseDir.ts.html +3 -3
  318. package/coverage/lcov-report/src/utilities/centralPath.ts.html +4 -4
  319. package/coverage/lcov-report/src/utilities/csvParser.ts.html +8 -8
  320. package/coverage/lcov-report/src/utilities/fileSystem/clientLibrary.ts.html +12 -12
  321. package/coverage/lcov-report/src/utilities/fileSystem/index.html +19 -79
  322. package/coverage/lcov-report/src/utilities/fileSystem/index.ts.html +1049 -20
  323. package/coverage/lcov-report/src/utilities/fileSystem/processor.ts.html +1 -1
  324. package/coverage/lcov-report/src/utilities/global.ts.html +43 -43
  325. package/coverage/lcov-report/src/utilities/index.html +63 -48
  326. package/coverage/lcov-report/src/utilities/index.ts.html +168 -36
  327. package/coverage/lcov-report/src/utilities/plugins.ts.html +151 -0
  328. package/coverage/lcov-report/src/utilities/redis.ts.html +32 -32
  329. package/coverage/lcov-report/src/utilities/routing/index.html +1 -1
  330. package/coverage/lcov-report/src/utilities/routing/index.ts.html +5 -5
  331. package/coverage/lcov-report/src/utilities/rowProcessor/index.html +28 -28
  332. package/coverage/lcov-report/src/utilities/rowProcessor/index.ts.html +33 -60
  333. package/coverage/lcov-report/src/utilities/rowProcessor/map.ts.html +3 -3
  334. package/coverage/lcov-report/src/utilities/rowProcessor/utils.ts.html +38 -38
  335. package/coverage/lcov-report/src/utilities/scriptRunner.ts.html +32 -32
  336. package/coverage/lcov-report/src/utilities/security.ts.html +6 -6
  337. package/coverage/lcov-report/src/utilities/statusCodes.ts.html +1 -1
  338. package/coverage/lcov-report/src/utilities/usageQuota/index.html +1 -1
  339. package/coverage/lcov-report/src/utilities/usageQuota/rows.ts.html +35 -35
  340. package/coverage/lcov-report/src/utilities/usageQuota/usageQuoteReset.ts.html +1 -1
  341. package/coverage/lcov-report/src/utilities/users.ts.html +6 -6
  342. package/coverage/lcov-report/src/utilities/workerRequests.ts.html +56 -56
  343. package/coverage/lcov-report/src/watch.ts.html +9 -9
  344. package/coverage/lcov-report/src/websocket.ts.html +15 -15
  345. package/coverage/lcov.info +7220 -7210
  346. package/dist/api/controllers/application.js +35 -47
  347. package/dist/api/controllers/cloud.js +2 -6
  348. package/dist/api/controllers/deploy/index.js +60 -43
  349. package/dist/api/controllers/plugin/index.js +6 -6
  350. package/dist/api/controllers/public/applications.js +1 -22
  351. package/dist/api/controllers/row/ExternalRequest.js +1 -0
  352. package/dist/api/controllers/row/internal.js +12 -12
  353. package/dist/api/controllers/row/staticFormula.js +1 -1
  354. package/dist/api/controllers/static/index.js +11 -8
  355. package/dist/api/controllers/view/index.js +2 -2
  356. package/dist/api/routes/application.js +0 -3
  357. package/dist/api/routes/deploy.js +2 -1
  358. package/dist/api/routes/public/applications.js +0 -37
  359. package/dist/api/routes/public/middleware/mapper.js +0 -3
  360. package/dist/api/routes/tests/utilities/TestFunctions.js +167 -0
  361. package/dist/api/routes/tests/utilities/index.js +131 -0
  362. package/dist/automations/automationUtils.js +1 -26
  363. package/dist/automations/tests/utilities/index.js +81 -0
  364. package/dist/environment.js +1 -5
  365. package/dist/integrations/googlesheets.js +1 -1
  366. package/dist/integrations/index.js +2 -1
  367. package/dist/migrations/functions/backfill/global/configs.js +4 -4
  368. package/dist/package.json +7 -9
  369. package/dist/sdk/app/backups/imports.js +26 -38
  370. package/dist/sdk/app/rows/attachments.js +61 -0
  371. package/dist/sdk/app/rows/index.js +28 -0
  372. package/dist/sdk/app/rows/rows.js +30 -0
  373. package/dist/sdk/index.js +2 -0
  374. package/dist/tests/utilities/TestConfiguration.js +562 -0
  375. package/dist/tests/utilities/controllers.js +40 -0
  376. package/dist/tests/utilities/structures.js +168 -0
  377. package/dist/threads/automation.js +28 -4
  378. package/dist/tsconfig.build.tsbuildinfo +1 -1
  379. package/dist/utilities/fileSystem/clientLibrary.js +3 -3
  380. package/dist/utilities/fileSystem/index.js +342 -18
  381. package/dist/utilities/index.js +44 -1
  382. package/dist/utilities/plugins.js +26 -0
  383. package/dist/utilities/rowProcessor/index.js +4 -12
  384. package/package.json +8 -10
  385. package/scripts/dev/manage.js +16 -0
  386. package/specs/openapi.json +0 -84
  387. package/specs/openapi.yaml +0 -53
  388. package/specs/resources/application.js +0 -19
  389. package/src/api/controllers/application.ts +36 -61
  390. package/src/api/controllers/auth.ts +2 -2
  391. package/src/api/controllers/cloud.ts +6 -10
  392. package/src/api/controllers/deploy/Deployment.ts +0 -1
  393. package/src/api/controllers/deploy/index.ts +58 -40
  394. package/src/api/controllers/plugin/index.ts +9 -14
  395. package/src/api/controllers/public/applications.ts +0 -17
  396. package/src/api/controllers/row/ExternalRequest.ts +1 -0
  397. package/src/api/controllers/row/internal.ts +23 -24
  398. package/src/api/controllers/row/staticFormula.ts +2 -5
  399. package/src/api/controllers/row/utils.ts +1 -2
  400. package/src/api/controllers/static/index.ts +10 -6
  401. package/src/api/controllers/view/index.ts +2 -2
  402. package/src/api/routes/application.ts +0 -11
  403. package/src/api/routes/deploy.ts +1 -0
  404. package/src/api/routes/index.ts +3 -4
  405. package/src/api/routes/public/applications.ts +0 -44
  406. package/src/api/routes/public/middleware/mapper.ts +0 -4
  407. package/src/api/routes/tests/__snapshots__/{datasource.spec.ts.snap → datasource.spec.js.snap} +0 -0
  408. package/src/api/routes/tests/analytics.spec.js +1 -1
  409. package/src/api/routes/tests/{application.spec.ts → application.spec.js} +18 -94
  410. package/src/api/routes/tests/{backup.spec.ts → backup.spec.js} +6 -17
  411. package/src/api/routes/tests/{datasource.spec.ts → datasource.spec.js} +15 -23
  412. package/src/api/routes/tests/deployment.spec.ts +25 -0
  413. package/src/api/routes/tests/permissions.spec.js +1 -1
  414. package/src/api/routes/tests/routing.spec.js +2 -1
  415. package/src/api/routes/tests/row.spec.js +2 -4
  416. package/src/api/routes/tests/static.spec.js +17 -2
  417. package/src/api/routes/tests/table.spec.js +2 -8
  418. package/src/api/routes/tests/user.spec.js +0 -86
  419. package/src/api/routes/tests/utilities/index.ts +2 -2
  420. package/src/api/routes/tests/webhook.spec.js +1 -1
  421. package/src/automations/automationUtils.ts +0 -24
  422. package/src/automations/tests/utilities/index.ts +2 -2
  423. package/src/automations/unitTests/automationUtils.spec.js +17 -0
  424. package/src/definitions/openapi.ts +0 -10
  425. package/src/environment.ts +1 -5
  426. package/src/integrations/googlesheets.ts +1 -1
  427. package/src/integrations/index.ts +5 -1
  428. package/src/migrations/functions/backfill/global/configs.ts +4 -5
  429. package/src/sdk/app/backups/imports.ts +40 -46
  430. package/src/sdk/app/rows/attachments.ts +60 -0
  431. package/src/sdk/app/rows/index.ts +7 -0
  432. package/src/sdk/app/rows/rows.ts +18 -0
  433. package/src/sdk/index.ts +2 -0
  434. package/src/sdk/tests/attachments.spec.ts +79 -0
  435. package/src/tests/jestSetup.ts +1 -4
  436. package/src/tests/utilities/TestConfiguration.ts +4 -23
  437. package/src/threads/automation.ts +27 -4
  438. package/src/utilities/fileSystem/clientLibrary.ts +1 -1
  439. package/src/utilities/fileSystem/index.ts +348 -5
  440. package/src/utilities/index.ts +45 -1
  441. package/src/utilities/plugins.ts +22 -0
  442. package/src/utilities/rowProcessor/index.ts +8 -17
  443. package/tsconfig.build.json +0 -2
  444. package/coverage/lcov-report/src/utilities/fileSystem/app.ts.html +0 -343
  445. package/coverage/lcov-report/src/utilities/fileSystem/filesystem.ts.html +0 -595
  446. package/coverage/lcov-report/src/utilities/fileSystem/plugin.ts.html +0 -280
  447. package/coverage/lcov-report/src/utilities/fileSystem/template.ts.html +0 -193
  448. package/dist/utilities/fileSystem/app.js +0 -97
  449. package/dist/utilities/fileSystem/filesystem.js +0 -182
  450. package/dist/utilities/fileSystem/plugin.js +0 -63
  451. package/dist/utilities/fileSystem/template.js +0 -44
  452. package/src/api/routes/tests/cloud.spec.ts +0 -65
  453. package/src/api/routes/tests/data/budibase-component-1.0.1.tgz +0 -0
  454. package/src/api/routes/tests/data/comment-box-1.0.2.tar.gz +0 -0
  455. package/src/api/routes/tests/data/export-test.tar.gz +0 -0
  456. package/src/api/routes/tests/plugin.spec.ts +0 -179
  457. package/src/automations/tests/bash.spec.js +0 -34
  458. package/src/automations/tests/discord.spec.js +0 -27
  459. package/src/automations/tests/executeQuery.spec.js +0 -49
  460. package/src/automations/tests/executeScript.spec.js +0 -48
  461. package/src/automations/tests/sendSmtpEmail.spec.js +0 -71
  462. package/src/automations/tests/serverLog.spec.js +0 -22
  463. package/src/automations/tests/zapier.spec.js +0 -27
  464. package/src/automations/unitTests/automationUtils.spec.ts +0 -65
  465. package/src/utilities/fileSystem/app.ts +0 -86
  466. package/src/utilities/fileSystem/filesystem.ts +0 -170
  467. package/src/utilities/fileSystem/plugin.ts +0 -65
  468. package/src/utilities/fileSystem/template.ts +0 -36
  469. package/src/utilities/rowProcessor/tests/utils.spec.ts +0 -57
@@ -0,0 +1,60 @@
1
+ import { CouchFindOptions, Table, Row } from "@budibase/types"
2
+ import { db as dbCore } from "@budibase/backend-core"
3
+ import { DocumentType, SEPARATOR } from "../../../db/utils"
4
+ import { FieldTypes } from "../../../constants"
5
+
6
+ // default limit - seems to work well for performance
7
+ export const FIND_LIMIT = 25
8
+
9
+ function generateAttachmentFindParams(
10
+ tableId: string,
11
+ attachmentCols: string[],
12
+ bookmark: null | string
13
+ ) {
14
+ const params: CouchFindOptions = {
15
+ selector: {
16
+ _id: {
17
+ $regex: `^${DocumentType.ROW}${SEPARATOR}${tableId}`,
18
+ },
19
+ },
20
+ limit: FIND_LIMIT,
21
+ }
22
+ attachmentCols.forEach(col => (params.selector[col] = { $exists: true }))
23
+ if (bookmark) {
24
+ params.bookmark = bookmark
25
+ }
26
+ return params
27
+ }
28
+
29
+ export async function getRowsWithAttachments(appId: string, table: Table) {
30
+ // iterate through attachment documents and update them
31
+ const db = dbCore.getDB(appId)
32
+ const attachmentCols: string[] = []
33
+ for (let [key, column] of Object.entries(table.schema)) {
34
+ if (column.type === FieldTypes.ATTACHMENT) {
35
+ attachmentCols.push(key)
36
+ }
37
+ }
38
+ // no attachment columns, nothing to do
39
+ if (attachmentCols.length === 0) {
40
+ return { rows: [], columns: [] }
41
+ }
42
+ let bookmark: null | string = null,
43
+ rowsLength = 0,
44
+ rowList: Row[] = []
45
+ do {
46
+ const params = generateAttachmentFindParams(
47
+ table._id!,
48
+ attachmentCols,
49
+ bookmark
50
+ )
51
+ // use the CouchDB Mango query API to lookup rows that have attachments
52
+ const resp = await dbCore.directCouchFind(db.name, params)
53
+ bookmark = resp.bookmark
54
+ rowsLength = resp.rows.length
55
+ const rows = resp.rows
56
+ rowList = rowList.concat(rows)
57
+ } while (rowsLength === FIND_LIMIT)
58
+ // write back the updated attachments
59
+ return { rows: rowList, columns: attachmentCols }
60
+ }
@@ -0,0 +1,7 @@
1
+ import * as attachments from "./attachments"
2
+ import * as rows from "./rows"
3
+
4
+ export default {
5
+ ...attachments,
6
+ ...rows,
7
+ }
@@ -0,0 +1,18 @@
1
+ import { db as dbCore, context } from "@budibase/backend-core"
2
+ import { Database, Row } from "@budibase/types"
3
+ import { getRowParams } from "../../../db/utils"
4
+
5
+ export async function getAllInternalRows(appId?: string) {
6
+ let db: Database
7
+ if (appId) {
8
+ db = dbCore.getDB(appId)
9
+ } else {
10
+ db = context.getAppDB()
11
+ }
12
+ const response = await db.allDocs(
13
+ getRowParams(null, null, {
14
+ include_docs: true,
15
+ })
16
+ )
17
+ return response.rows.map(row => row.doc) as Row[]
18
+ }
package/src/sdk/index.ts CHANGED
@@ -2,6 +2,7 @@ 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 rows } from "./app/rows"
5
6
  import { default as users } from "./users"
6
7
 
7
8
  const sdk = {
@@ -9,6 +10,7 @@ const sdk = {
9
10
  tables,
10
11
  automations,
11
12
  applications,
13
+ rows,
12
14
  users,
13
15
  }
14
16
 
@@ -0,0 +1,79 @@
1
+ import newid from "../../db/newid"
2
+
3
+ const attachment = {
4
+ size: 73479,
5
+ name: "2022-12-14 11_11_44-.png",
6
+ url: "/prod-budi-app-assets/app_bbb/attachments/a.png",
7
+ extension: "png",
8
+ key: "app_bbb/attachments/a.png",
9
+ }
10
+
11
+ const row = {
12
+ _id: "ro_ta_aaa",
13
+ photo: [attachment],
14
+ otherCol: "string",
15
+ }
16
+
17
+ const table = {
18
+ _id: "ta_aaa",
19
+ name: "photos",
20
+ schema: {
21
+ photo: {
22
+ type: "attachment",
23
+ name: "photo",
24
+ },
25
+ otherCol: {
26
+ type: "string",
27
+ name: "otherCol",
28
+ },
29
+ },
30
+ }
31
+
32
+ jest.mock("@budibase/backend-core", () => {
33
+ const core = jest.requireActual("@budibase/backend-core")
34
+ return {
35
+ ...core,
36
+ db: {
37
+ ...core.db,
38
+ directCouchFind: jest.fn(),
39
+ },
40
+ }
41
+ })
42
+
43
+ import { db as dbCore } from "@budibase/backend-core"
44
+ import sdk from "../index"
45
+
46
+ describe("should be able to re-write attachment URLs", () => {
47
+ it("it should update URLs on a number of rows over the limit", async () => {
48
+ const db = dbCore.getDB("app_aaa")
49
+ await db.put(table)
50
+ const limit = 30
51
+ let rows = []
52
+ for (let i = 0; i < limit; i++) {
53
+ const rowToWrite = {
54
+ ...row,
55
+ _id: `${row._id}_${newid()}`,
56
+ }
57
+ const { rev } = await db.put(rowToWrite)
58
+ rows.push({
59
+ ...rowToWrite,
60
+ _rev: rev,
61
+ })
62
+ }
63
+
64
+ dbCore.directCouchFind
65
+ // @ts-ignore
66
+ .mockReturnValueOnce({ rows: rows.slice(0, 25), bookmark: "aaa" })
67
+ .mockReturnValueOnce({ rows: rows.slice(25, limit), bookmark: "bbb" })
68
+ await sdk.backups.updateAttachmentColumns(db.name, db)
69
+ const finalRows = await sdk.rows.getAllInternalRows(db.name)
70
+ for (let rowToCheck of finalRows) {
71
+ expect(rowToCheck.otherCol).toBe(row.otherCol)
72
+ expect(rowToCheck.photo[0].url).not.toBe(row.photo[0].url)
73
+ expect(rowToCheck.photo[0].url).toBe(
74
+ `/prod-budi-app-assets/${db.name}/attachments/a.png`
75
+ )
76
+ expect(rowToCheck.photo[0].key).toBe(`${db.name}/attachments/a.png`)
77
+ }
78
+ })
79
+ })
@@ -19,10 +19,7 @@ import { mocks } from "@budibase/backend-core/tests"
19
19
  const tk = require("timekeeper")
20
20
  tk.freeze(mocks.date.MOCK_DATE)
21
21
 
22
- if (!process.env.DEBUG) {
23
- global.console.log = jest.fn() // console.log are ignored in tests
24
- global.console.warn = jest.fn() // console.warn are ignored in tests
25
- }
22
+ global.console.log = jest.fn() // console.log are ignored in tests
26
23
 
27
24
  if (!process.env.CI) {
28
25
  // set a longer timeout in dev for debugging
@@ -1,12 +1,3 @@
1
- import { mocks } from "@budibase/backend-core/tests"
2
-
3
- // init the licensing mock
4
- import * as pro from "@budibase/pro"
5
- mocks.licenses.init(pro)
6
-
7
- // use unlimited license by default
8
- mocks.licenses.useUnlimited()
9
-
10
1
  import { init as dbInit } from "../../db"
11
2
  dbInit()
12
3
  import env from "../../environment"
@@ -360,6 +351,7 @@ class TestConfiguration {
360
351
  }
361
352
 
362
353
  // APP
354
+
363
355
  async createApp(appName: string) {
364
356
  // create dev app
365
357
  // clear any old app
@@ -372,7 +364,7 @@ class TestConfiguration {
372
364
  await context.updateAppId(this.appId)
373
365
 
374
366
  // create production app
375
- this.prodApp = await this.publish()
367
+ this.prodApp = await this.deploy()
376
368
 
377
369
  this.allApps.push(this.prodApp)
378
370
  this.allApps.push(this.app)
@@ -380,8 +372,8 @@ class TestConfiguration {
380
372
  return this.app
381
373
  }
382
374
 
383
- async publish() {
384
- await this._req(null, null, controllers.deploy.publishApp)
375
+ async deploy() {
376
+ await this._req(null, null, controllers.deploy.deployApp)
385
377
  // @ts-ignore
386
378
  const prodAppId = this.getAppId().replace("_dev", "")
387
379
  this.prodAppId = prodAppId
@@ -392,17 +384,6 @@ class TestConfiguration {
392
384
  })
393
385
  }
394
386
 
395
- async unpublish() {
396
- const response = await this._req(
397
- null,
398
- { appId: this.appId },
399
- controllers.app.unpublish
400
- )
401
- this.prodAppId = null
402
- this.prodApp = null
403
- return response
404
- }
405
-
406
387
  // TABLE
407
388
 
408
389
  async updateTable(config?: any) {
@@ -32,8 +32,31 @@ const LOOP_STEP_ID = actions.ACTION_DEFINITIONS.LOOP.stepId
32
32
  const CRON_STEP_ID = triggerDefs.CRON.stepId
33
33
  const STOPPED_STATUS = { success: true, status: AutomationStatus.STOPPED }
34
34
 
35
+ function typecastForLooping(loopStep: LoopStep, input: LoopInput) {
36
+ if (!input || !input.binding) {
37
+ return null
38
+ }
39
+ try {
40
+ switch (loopStep.inputs.option) {
41
+ case LoopStepType.ARRAY:
42
+ if (typeof input.binding === "string") {
43
+ return JSON.parse(input.binding)
44
+ }
45
+ break
46
+ case LoopStepType.STRING:
47
+ if (Array.isArray(input.binding)) {
48
+ return input.binding.join(",")
49
+ }
50
+ break
51
+ }
52
+ } catch (err) {
53
+ throw new Error("Unable to cast to correct type")
54
+ }
55
+ return input.binding
56
+ }
57
+
35
58
  function getLoopIterations(loopStep: LoopStep, input: LoopInput) {
36
- const binding = automationUtils.typecastForLooping(loopStep, input)
59
+ const binding = typecastForLooping(loopStep, input)
37
60
  if (!loopStep || !binding) {
38
61
  return 1
39
62
  }
@@ -266,7 +289,7 @@ class Orchestrator {
266
289
 
267
290
  let tempOutput = { items: loopSteps, iterations: iterationCount }
268
291
  try {
269
- newInput.binding = automationUtils.typecastForLooping(
292
+ newInput.binding = typecastForLooping(
270
293
  loopStep as LoopStep,
271
294
  newInput
272
295
  )
@@ -419,7 +442,7 @@ class Orchestrator {
419
442
 
420
443
  // Delete the step after the loop step as it's irrelevant, since information is included
421
444
  // in the loop step
422
- if (wasLoopStep && !loopStep) {
445
+ if (wasLoopStep) {
423
446
  this._context.steps.splice(loopStepNumber + 1, 1)
424
447
  wasLoopStep = false
425
448
  }
@@ -438,8 +461,8 @@ class Orchestrator {
438
461
  })
439
462
  this._context.steps[loopStepNumber] = tempOutput
440
463
 
464
+ loopSteps = undefined
441
465
  wasLoopStep = true
442
- loopSteps = []
443
466
  }
444
467
  }
445
468
 
@@ -4,7 +4,7 @@ import fs from "fs"
4
4
  import { objectStore } from "@budibase/backend-core"
5
5
  import { resolve } from "../centralPath"
6
6
  import env from "../../environment"
7
- import { TOP_LEVEL_PATH } from "./filesystem"
7
+ const TOP_LEVEL_PATH = join(__dirname, "..", "..", "..")
8
8
 
9
9
  /**
10
10
  * Client library paths in the object store:
@@ -1,5 +1,348 @@
1
- export * from "./app"
2
- export * from "./clientLibrary"
3
- export * from "./filesystem"
4
- export * from "./plugin"
5
- export * from "./template"
1
+ import { budibaseTempDir } from "../budibaseDir"
2
+ import fs from "fs"
3
+ import { join } from "path"
4
+ import { context, objectStore } from "@budibase/backend-core"
5
+ import { ObjectStoreBuckets } from "../../constants"
6
+ import { updateClientLibrary } from "./clientLibrary"
7
+ import { checkSlashesInUrl } from "../"
8
+ import env from "../../environment"
9
+ import fetch from "node-fetch"
10
+ const uuid = require("uuid/v4")
11
+ const tar = require("tar")
12
+
13
+ export const TOP_LEVEL_PATH = join(__dirname, "..", "..", "..")
14
+ export const NODE_MODULES_PATH = join(TOP_LEVEL_PATH, "node_modules")
15
+ const DATASOURCE_PATH = join(budibaseTempDir(), "datasource")
16
+
17
+ /**
18
+ * The single stack system (Cloud and Builder) should not make use of the file system where possible,
19
+ * this file handles all of the file access for the system with the intention of limiting it all to one
20
+ * place. Keeping all of this logic in one place means that when we need to do file system access (like
21
+ * downloading a package or opening a temporary file) in can be done in way that we can confirm it shouldn't
22
+ * be done through an object store instead.
23
+ */
24
+
25
+ /**
26
+ * Upon first startup of instance there may not be everything we need in tmp directory, set it up.
27
+ */
28
+ export function init() {
29
+ const tempDir = budibaseTempDir()
30
+ if (!fs.existsSync(tempDir)) {
31
+ // some test cases fire this quickly enough that
32
+ // synchronous cases can end up here at the same time
33
+ try {
34
+ fs.mkdirSync(tempDir)
35
+ } catch (err: any) {
36
+ if (!err || err.code !== "EEXIST") {
37
+ throw err
38
+ }
39
+ }
40
+ }
41
+ const clientLibPath = join(budibaseTempDir(), "budibase-client.js")
42
+ if (env.isTest() && !fs.existsSync(clientLibPath)) {
43
+ fs.copyFileSync(require.resolve("@budibase/client"), clientLibPath)
44
+ }
45
+ }
46
+
47
+ /**
48
+ * Checks if the system is currently in development mode and if it is makes sure
49
+ * everything required to function is ready.
50
+ */
51
+ exports.checkDevelopmentEnvironment = () => {
52
+ if (!env.isDev() || env.isTest()) {
53
+ return
54
+ }
55
+ if (!fs.existsSync(budibaseTempDir())) {
56
+ fs.mkdirSync(budibaseTempDir())
57
+ }
58
+ let error
59
+ if (!fs.existsSync(join(process.cwd(), ".env"))) {
60
+ error = "Must run via yarn once to generate environment."
61
+ }
62
+ if (error) {
63
+ console.error(error)
64
+ process.exit(-1)
65
+ }
66
+ }
67
+
68
+ /**
69
+ * Used to retrieve a handlebars file from the system which will be used as a template.
70
+ * This is allowable as the template handlebars files should be static and identical across
71
+ * the cluster.
72
+ * @param {string} path The path to the handlebars file which is to be loaded.
73
+ * @returns {string} The loaded handlebars file as a string - loaded as utf8.
74
+ */
75
+ export function loadHandlebarsFile(path: string) {
76
+ return fs.readFileSync(path, "utf8")
77
+ }
78
+
79
+ /**
80
+ * When return a file from the API need to write the file to the system temporarily so we
81
+ * can create a read stream to send.
82
+ * @param {string} contents the contents of the file which is to be returned from the API.
83
+ * @param {string} encoding the encoding of the file to return (utf8 default)
84
+ * @return {Object} the read stream which can be put into the koa context body.
85
+ */
86
+ export function apiFileReturn(
87
+ contents: string,
88
+ encoding: BufferEncoding = "utf8"
89
+ ) {
90
+ const path = join(budibaseTempDir(), uuid())
91
+ fs.writeFileSync(path, contents, { encoding })
92
+ return fs.createReadStream(path, { encoding })
93
+ }
94
+
95
+ export function streamFile(path: string) {
96
+ return fs.createReadStream(path)
97
+ }
98
+
99
+ /**
100
+ * Writes the provided contents to a temporary file, which can be used briefly.
101
+ * @param {string} fileContents contents which will be written to a temp file.
102
+ * @return {string} the path to the temp file.
103
+ */
104
+ export function storeTempFile(fileContents: string) {
105
+ const path = join(budibaseTempDir(), uuid())
106
+ fs.writeFileSync(path, fileContents)
107
+ return path
108
+ }
109
+
110
+ /**
111
+ * Utility function for getting a file read stream - a simple in memory buffered read
112
+ * stream doesn't work for pouchdb.
113
+ */
114
+ export function stringToFileStream(contents: string) {
115
+ const path = exports.storeTempFile(contents)
116
+ return fs.createReadStream(path)
117
+ }
118
+
119
+ /**
120
+ * Creates a temp file and returns it from the API.
121
+ * @param {string} fileContents the contents to be returned in file.
122
+ */
123
+ export function sendTempFile(fileContents: string) {
124
+ const path = exports.storeTempFile(fileContents)
125
+ return fs.createReadStream(path)
126
+ }
127
+
128
+ /**
129
+ * Uploads the latest client library to the object store.
130
+ * @param {string} appId The ID of the app which is being created.
131
+ * @return {Promise<void>} once promise completes app resources should be ready in object store.
132
+ */
133
+ export async function createApp(appId: string) {
134
+ await updateClientLibrary(appId)
135
+ }
136
+
137
+ /**
138
+ * Removes all of the assets created for an app in the object store.
139
+ * @param {string} appId The ID of the app which is being deleted.
140
+ * @return {Promise<void>} once promise completes the app resources will be removed from object store.
141
+ */
142
+ export async function deleteApp(appId: string) {
143
+ await objectStore.deleteFolder(ObjectStoreBuckets.APPS, `${appId}/`)
144
+ }
145
+
146
+ /**
147
+ * Retrieves a template and pipes it to minio as well as making it available temporarily.
148
+ * @param {string} type The type of template which is to be retrieved.
149
+ * @param name
150
+ * @return {Promise<*>}
151
+ */
152
+ export async function downloadTemplate(type: string, name: string) {
153
+ const DEFAULT_TEMPLATES_BUCKET =
154
+ "prod-budi-templates.s3-eu-west-1.amazonaws.com"
155
+ const templateUrl = `https://${DEFAULT_TEMPLATES_BUCKET}/templates/${type}/${name}.tar.gz`
156
+ return objectStore.downloadTarball(
157
+ templateUrl,
158
+ ObjectStoreBuckets.TEMPLATES,
159
+ type
160
+ )
161
+ }
162
+
163
+ /**
164
+ * Retrieves component libraries from object store (or tmp symlink if in local)
165
+ */
166
+ export async function getComponentLibraryManifest(library: string) {
167
+ const appId = context.getAppId()
168
+ const filename = "manifest.json"
169
+ /* istanbul ignore next */
170
+ // when testing in cypress and so on we need to get the package
171
+ // as the environment may not be fully fleshed out for dev or prod
172
+ if (env.isTest()) {
173
+ library = library.replace("standard-components", "client")
174
+ const lib = library.split("/")[1]
175
+ const path = require.resolve(library).split(lib)[0]
176
+ return require(join(path, lib, filename))
177
+ } else if (env.isDev()) {
178
+ const path = join(NODE_MODULES_PATH, "@budibase", "client", filename)
179
+ // always load from new so that updates are refreshed
180
+ delete require.cache[require.resolve(path)]
181
+ return require(path)
182
+ }
183
+
184
+ if (!appId) {
185
+ throw new Error("No app ID found - cannot get component libraries")
186
+ }
187
+
188
+ let resp
189
+ let path
190
+ try {
191
+ // Try to load the manifest from the new file location
192
+ path = join(appId, filename)
193
+ resp = await objectStore.retrieve(ObjectStoreBuckets.APPS, path)
194
+ } catch (error) {
195
+ console.error(
196
+ `component-manifest-objectstore=failed appId=${appId} path=${path}`,
197
+ error
198
+ )
199
+ // Fallback to loading it from the old location for old apps
200
+ path = join(appId, "node_modules", library, "package", filename)
201
+ resp = await objectStore.retrieve(ObjectStoreBuckets.APPS, path)
202
+ }
203
+ if (typeof resp !== "string") {
204
+ resp = resp.toString("utf8")
205
+ }
206
+ return JSON.parse(resp)
207
+ }
208
+
209
+ /**
210
+ * All file reads come through here just to make sure all of them make sense
211
+ * allows a centralised location to check logic is all good.
212
+ */
213
+ export function readFileSync(
214
+ filepath: string,
215
+ options: BufferEncoding = "utf8"
216
+ ) {
217
+ return fs.readFileSync(filepath, { encoding: options })
218
+ }
219
+
220
+ /**
221
+ * Given a set of app IDs makes sure file system is cleared of any of their temp info.
222
+ */
223
+ export function cleanup(appIds: string[]) {
224
+ for (let appId of appIds) {
225
+ const path = join(budibaseTempDir(), appId)
226
+ if (fs.existsSync(path)) {
227
+ fs.rmdirSync(path, { recursive: true })
228
+ }
229
+ }
230
+ }
231
+
232
+ export function createTempFolder(item: string) {
233
+ const path = join(budibaseTempDir(), item)
234
+ try {
235
+ // remove old tmp directories automatically - don't combine
236
+ if (fs.existsSync(path)) {
237
+ fs.rmSync(path, { recursive: true, force: true })
238
+ }
239
+ fs.mkdirSync(path)
240
+ } catch (err: any) {
241
+ throw new Error(`Path cannot be created: ${err.message}`)
242
+ }
243
+
244
+ return path
245
+ }
246
+
247
+ export async function extractTarball(fromFilePath: string, toPath: string) {
248
+ await tar.extract({
249
+ file: fromFilePath,
250
+ C: toPath,
251
+ })
252
+ }
253
+
254
+ export async function getPluginMetadata(path: string) {
255
+ let metadata: { schema?: any; package?: any } = {}
256
+ try {
257
+ const pkg = fs.readFileSync(join(path, "package.json"), "utf8")
258
+ const schema = fs.readFileSync(join(path, "schema.json"), "utf8")
259
+
260
+ metadata.schema = JSON.parse(schema)
261
+ metadata.package = JSON.parse(pkg)
262
+
263
+ if (
264
+ !metadata.package.name ||
265
+ !metadata.package.version ||
266
+ !metadata.package.description
267
+ ) {
268
+ throw new Error(
269
+ "package.json is missing one of 'name', 'version' or 'description'."
270
+ )
271
+ }
272
+ } catch (err: any) {
273
+ throw new Error(
274
+ `Unable to process schema.json/package.json in plugin. ${err.message}`
275
+ )
276
+ }
277
+
278
+ return { metadata, directory: path }
279
+ }
280
+
281
+ export async function getDatasourcePlugin(
282
+ name: string,
283
+ url: string,
284
+ hash: string
285
+ ) {
286
+ if (!fs.existsSync(DATASOURCE_PATH)) {
287
+ fs.mkdirSync(DATASOURCE_PATH)
288
+ }
289
+ const filename = join(DATASOURCE_PATH, name)
290
+ const metadataName = `${filename}.bbmetadata`
291
+ if (fs.existsSync(filename)) {
292
+ const currentHash = fs.readFileSync(metadataName, "utf8")
293
+ // if hash is the same return the file, otherwise remove it and re-download
294
+ if (currentHash === hash) {
295
+ return require(filename)
296
+ } else {
297
+ console.log(`Updating plugin: ${name}`)
298
+ delete require.cache[require.resolve(filename)]
299
+ fs.unlinkSync(filename)
300
+ }
301
+ }
302
+ const fullUrl = checkSlashesInUrl(
303
+ `${env.MINIO_URL}/${ObjectStoreBuckets.PLUGINS}/${url}`
304
+ )
305
+ const response = await fetch(fullUrl)
306
+ if (response.status === 200) {
307
+ const content = await response.text()
308
+ fs.writeFileSync(filename, content)
309
+ fs.writeFileSync(metadataName, hash)
310
+ return require(filename)
311
+ } else {
312
+ throw new Error(
313
+ `Unable to retrieve plugin - reason: ${await response.text()}`
314
+ )
315
+ }
316
+ }
317
+
318
+ /**
319
+ * Find for a file recursively from start path applying filter, return first match
320
+ */
321
+ export function findFileRec(startPath: string, filter: any) {
322
+ if (!fs.existsSync(startPath)) {
323
+ return
324
+ }
325
+
326
+ const files = fs.readdirSync(startPath)
327
+ for (let i = 0, len = files.length; i < len; i++) {
328
+ const filename = join(startPath, files[i])
329
+ const stat = fs.lstatSync(filename)
330
+
331
+ if (stat.isDirectory()) {
332
+ return exports.findFileRec(filename, filter)
333
+ } else if (filename.endsWith(filter)) {
334
+ return filename
335
+ }
336
+ }
337
+ }
338
+
339
+ /**
340
+ * Remove a folder which is not empty from the file system
341
+ */
342
+ export function deleteFolderFileSystem(path: string) {
343
+ if (!fs.existsSync(path)) {
344
+ return
345
+ }
346
+
347
+ fs.rmSync(path, { recursive: true, force: true })
348
+ }