@budibase/server 1.0.32 → 1.0.39

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 (382) hide show
  1. package/__mocks__/node-fetch.ts +21 -0
  2. package/builder/assets/bb-spaceship.8f6e81e1.svg +227 -0
  3. package/builder/assets/index.3079d0f9.js +1348 -0
  4. package/builder/assets/{index.4fb3f887.css → index.39e01193.css} +1 -1
  5. package/builder/assets/{vendor.470042a4.js → vendor.f9faf6ab.js} +88 -88
  6. package/builder/index.html +3 -3
  7. package/coverage/clover.xml +1591 -1345
  8. package/coverage/coverage-final.json +75 -74
  9. package/coverage/lcov-report/api/controllers/analytics.js.html +1 -1
  10. package/coverage/lcov-report/api/controllers/apikeys.js.html +3 -3
  11. package/coverage/lcov-report/api/controllers/application.js.html +73 -64
  12. package/coverage/lcov-report/api/controllers/auth.js.html +2 -2
  13. package/coverage/lcov-report/api/controllers/automation.js.html +22 -10
  14. package/coverage/lcov-report/api/controllers/backup.js.html +1 -1
  15. package/coverage/lcov-report/api/controllers/cloud.js.html +13 -4
  16. package/coverage/lcov-report/api/controllers/component.js.html +4 -4
  17. package/coverage/lcov-report/api/controllers/datasource.js.html +170 -68
  18. package/coverage/lcov-report/api/controllers/dev.js.html +3 -3
  19. package/coverage/lcov-report/api/controllers/hosting.js.html +3 -3
  20. package/coverage/lcov-report/api/controllers/index.html +39 -54
  21. package/coverage/lcov-report/api/controllers/integration.js.html +1 -1
  22. package/coverage/lcov-report/api/controllers/layout.js.html +1 -1
  23. package/coverage/lcov-report/api/controllers/metadata.js.html +1 -1
  24. package/coverage/lcov-report/api/controllers/permission.js.html +3 -3
  25. package/coverage/lcov-report/api/controllers/query/index.html +126 -0
  26. package/coverage/lcov-report/api/controllers/{query.js.html → query/index.js.html} +228 -114
  27. package/coverage/lcov-report/api/controllers/query/validation.js.html +206 -0
  28. package/coverage/lcov-report/api/controllers/role.js.html +2 -2
  29. package/coverage/lcov-report/api/controllers/routing.js.html +2 -2
  30. package/coverage/lcov-report/api/controllers/row/external.js.html +1 -1
  31. package/coverage/lcov-report/api/controllers/row/index.html +22 -22
  32. package/coverage/lcov-report/api/controllers/row/index.js.html +1 -1
  33. package/coverage/lcov-report/api/controllers/row/internal.js.html +38 -11
  34. package/coverage/lcov-report/api/controllers/row/internalSearch.js.html +8 -5
  35. package/coverage/lcov-report/api/controllers/row/utils.js.html +29 -20
  36. package/coverage/lcov-report/api/controllers/screen.js.html +2 -2
  37. package/coverage/lcov-report/api/controllers/script.js.html +1 -1
  38. package/coverage/lcov-report/api/controllers/table/external.js.html +1 -1
  39. package/coverage/lcov-report/api/controllers/table/index.html +1 -1
  40. package/coverage/lcov-report/api/controllers/table/index.js.html +1 -1
  41. package/coverage/lcov-report/api/controllers/table/internal.js.html +1 -1
  42. package/coverage/lcov-report/api/controllers/table/utils.js.html +1 -1
  43. package/coverage/lcov-report/api/controllers/templates.js.html +1 -1
  44. package/coverage/lcov-report/api/controllers/user.js.html +120 -12
  45. package/coverage/lcov-report/api/controllers/view/exporters.js.html +1 -1
  46. package/coverage/lcov-report/api/controllers/view/index.html +1 -1
  47. package/coverage/lcov-report/api/controllers/view/index.js.html +1 -1
  48. package/coverage/lcov-report/api/controllers/view/utils.js.html +1 -1
  49. package/coverage/lcov-report/api/controllers/view/viewBuilder.js.html +1 -1
  50. package/coverage/lcov-report/api/controllers/webhook.js.html +19 -7
  51. package/coverage/lcov-report/api/index.html +1 -1
  52. package/coverage/lcov-report/api/index.js.html +6 -6
  53. package/coverage/lcov-report/api/routes/analytics.js.html +1 -1
  54. package/coverage/lcov-report/api/routes/apikeys.js.html +2 -2
  55. package/coverage/lcov-report/api/routes/application.js.html +2 -2
  56. package/coverage/lcov-report/api/routes/auth.js.html +1 -1
  57. package/coverage/lcov-report/api/routes/automation.js.html +2 -2
  58. package/coverage/lcov-report/api/routes/backup.js.html +2 -2
  59. package/coverage/lcov-report/api/routes/cloud.js.html +2 -2
  60. package/coverage/lcov-report/api/routes/component.js.html +2 -2
  61. package/coverage/lcov-report/api/routes/datasource.js.html +2 -2
  62. package/coverage/lcov-report/api/routes/deploy.js.html +2 -2
  63. package/coverage/lcov-report/api/routes/dev.js.html +2 -2
  64. package/coverage/lcov-report/api/routes/hosting.js.html +2 -2
  65. package/coverage/lcov-report/api/routes/index.html +9 -9
  66. package/coverage/lcov-report/api/routes/index.js.html +1 -1
  67. package/coverage/lcov-report/api/routes/integration.js.html +2 -2
  68. package/coverage/lcov-report/api/routes/layout.js.html +2 -2
  69. package/coverage/lcov-report/api/routes/metadata.js.html +2 -2
  70. package/coverage/lcov-report/api/routes/permission.js.html +12 -3
  71. package/coverage/lcov-report/api/routes/query.js.html +20 -86
  72. package/coverage/lcov-report/api/routes/role.js.html +2 -2
  73. package/coverage/lcov-report/api/routes/routing.js.html +2 -2
  74. package/coverage/lcov-report/api/routes/row.js.html +2 -2
  75. package/coverage/lcov-report/api/routes/screen.js.html +2 -2
  76. package/coverage/lcov-report/api/routes/script.js.html +2 -2
  77. package/coverage/lcov-report/api/routes/static.js.html +2 -2
  78. package/coverage/lcov-report/api/routes/table.js.html +2 -2
  79. package/coverage/lcov-report/api/routes/templates.js.html +2 -2
  80. package/coverage/lcov-report/api/routes/user.js.html +33 -3
  81. package/coverage/lcov-report/api/routes/view.js.html +2 -2
  82. package/coverage/lcov-report/api/routes/webhook.js.html +2 -2
  83. package/coverage/lcov-report/automations/actions.js.html +1 -1
  84. package/coverage/lcov-report/automations/automationUtils.js.html +1 -1
  85. package/coverage/lcov-report/automations/bullboard.js.html +2 -2
  86. package/coverage/lcov-report/automations/index.html +20 -20
  87. package/coverage/lcov-report/automations/index.js.html +1 -1
  88. package/coverage/lcov-report/automations/steps/bash.js.html +1 -1
  89. package/coverage/lcov-report/automations/steps/createRow.js.html +1 -1
  90. package/coverage/lcov-report/automations/steps/delay.js.html +1 -1
  91. package/coverage/lcov-report/automations/steps/deleteRow.js.html +1 -1
  92. package/coverage/lcov-report/automations/steps/discord.js.html +1 -1
  93. package/coverage/lcov-report/automations/steps/executeQuery.js.html +32 -8
  94. package/coverage/lcov-report/automations/steps/executeScript.js.html +1 -1
  95. package/coverage/lcov-report/automations/steps/filter.js.html +1 -1
  96. package/coverage/lcov-report/automations/steps/index.html +11 -11
  97. package/coverage/lcov-report/automations/steps/integromat.js.html +1 -1
  98. package/coverage/lcov-report/automations/steps/outgoingWebhook.js.html +5 -8
  99. package/coverage/lcov-report/automations/steps/queryRows.js.html +1 -1
  100. package/coverage/lcov-report/automations/steps/sendSmtpEmail.js.html +1 -1
  101. package/coverage/lcov-report/automations/steps/serverLog.js.html +1 -1
  102. package/coverage/lcov-report/automations/steps/slack.js.html +1 -1
  103. package/coverage/lcov-report/automations/steps/updateRow.js.html +1 -1
  104. package/coverage/lcov-report/automations/steps/utils.js.html +1 -1
  105. package/coverage/lcov-report/automations/steps/zapier.js.html +1 -1
  106. package/coverage/lcov-report/automations/triggerInfo/app.js.html +1 -1
  107. package/coverage/lcov-report/automations/triggerInfo/cron.js.html +1 -1
  108. package/coverage/lcov-report/automations/triggerInfo/index.html +1 -1
  109. package/coverage/lcov-report/automations/triggerInfo/index.js.html +1 -1
  110. package/coverage/lcov-report/automations/triggerInfo/rowDeleted.js.html +1 -1
  111. package/coverage/lcov-report/automations/triggerInfo/rowSaved.js.html +1 -1
  112. package/coverage/lcov-report/automations/triggerInfo/rowUpdated.js.html +1 -1
  113. package/coverage/lcov-report/automations/triggerInfo/webhook.js.html +1 -1
  114. package/coverage/lcov-report/automations/triggers.js.html +1 -1
  115. package/coverage/lcov-report/automations/utils.js.html +49 -16
  116. package/coverage/lcov-report/constants/index.html +1 -1
  117. package/coverage/lcov-report/constants/index.js.html +25 -25
  118. package/coverage/lcov-report/constants/layouts.js.html +1 -1
  119. package/coverage/lcov-report/constants/screens.js.html +2 -2
  120. package/coverage/lcov-report/db/client.js.html +19 -19
  121. package/coverage/lcov-report/db/inMemoryView.js.html +1 -1
  122. package/coverage/lcov-report/db/index.html +15 -15
  123. package/coverage/lcov-report/db/index.js.html +3 -3
  124. package/coverage/lcov-report/db/linkedRows/LinkController.js.html +1 -1
  125. package/coverage/lcov-report/db/linkedRows/index.html +1 -1
  126. package/coverage/lcov-report/db/linkedRows/index.js.html +1 -1
  127. package/coverage/lcov-report/db/linkedRows/linkUtils.js.html +1 -1
  128. package/coverage/lcov-report/db/newid.js.html +4 -4
  129. package/coverage/lcov-report/db/utils.js.html +108 -81
  130. package/coverage/lcov-report/events/AutomationEmitter.js.html +1 -1
  131. package/coverage/lcov-report/events/index.html +1 -1
  132. package/coverage/lcov-report/events/index.js.html +1 -1
  133. package/coverage/lcov-report/events/utils.js.html +1 -1
  134. package/coverage/lcov-report/index.html +99 -84
  135. package/coverage/lcov-report/integrations/tests/TestConfiguration.js.html +1 -1
  136. package/coverage/lcov-report/integrations/tests/index.html +1 -1
  137. package/coverage/lcov-report/middleware/appInfo.js.html +1 -1
  138. package/coverage/lcov-report/middleware/authorized.js.html +12 -12
  139. package/coverage/lcov-report/middleware/builder.js.html +10 -10
  140. package/coverage/lcov-report/middleware/currentapp.js.html +48 -36
  141. package/coverage/lcov-report/middleware/index.html +1 -1
  142. package/coverage/lcov-report/middleware/joi-validator.js.html +11 -11
  143. package/coverage/lcov-report/middleware/resourceId.js.html +18 -18
  144. package/coverage/lcov-report/middleware/selfhost.js.html +1 -1
  145. package/coverage/lcov-report/middleware/usageQuota.js.html +2 -2
  146. package/coverage/lcov-report/middleware/utils.js.html +2 -2
  147. package/coverage/lcov-report/threads/automation.js.html +3 -3
  148. package/coverage/lcov-report/threads/index.html +32 -32
  149. package/coverage/lcov-report/threads/index.js.html +12 -12
  150. package/coverage/lcov-report/threads/query.js.html +560 -65
  151. package/coverage/lcov-report/threads/utils.js.html +210 -15
  152. package/coverage/lcov-report/utilities/bcrypt.js.html +1 -1
  153. package/coverage/lcov-report/utilities/budibaseDir.js.html +2 -2
  154. package/coverage/lcov-report/utilities/centralPath.js.html +1 -1
  155. package/coverage/lcov-report/utilities/csvParser.js.html +1 -1
  156. package/coverage/lcov-report/utilities/global.js.html +28 -19
  157. package/coverage/lcov-report/utilities/index.html +19 -19
  158. package/coverage/lcov-report/utilities/index.js.html +70 -37
  159. package/coverage/lcov-report/utilities/queue/inMemoryQueue.js.html +2 -2
  160. package/coverage/lcov-report/utilities/queue/index.html +1 -1
  161. package/coverage/lcov-report/utilities/routing/index.html +1 -1
  162. package/coverage/lcov-report/utilities/routing/index.js.html +1 -1
  163. package/coverage/lcov-report/utilities/rowProcessor/index.html +19 -19
  164. package/coverage/lcov-report/utilities/rowProcessor/index.js.html +247 -10
  165. package/coverage/lcov-report/utilities/rowProcessor/utils.js.html +1 -1
  166. package/coverage/lcov-report/utilities/scriptRunner.js.html +1 -1
  167. package/coverage/lcov-report/utilities/security.js.html +14 -5
  168. package/coverage/lcov-report/utilities/statusCodes.js.html +1 -1
  169. package/coverage/lcov-report/utilities/users.js.html +1 -1
  170. package/coverage/lcov-report/utilities/workerRequests.js.html +22 -22
  171. package/coverage/lcov.info +2740 -2315
  172. package/dist/api/controllers/apikeys.js +2 -2
  173. package/dist/api/controllers/application.js +4 -4
  174. package/dist/api/controllers/auth.js +1 -1
  175. package/dist/api/controllers/automation.js +7 -5
  176. package/dist/api/controllers/cloud.js +2 -2
  177. package/dist/api/controllers/datasource.js +29 -0
  178. package/dist/api/controllers/deploy/index.js +2 -2
  179. package/dist/api/controllers/dev.js +2 -2
  180. package/dist/api/controllers/hosting.js +2 -2
  181. package/dist/api/controllers/permission.js +2 -2
  182. package/dist/api/controllers/query/import/index.js +79 -0
  183. package/dist/api/controllers/query/import/sources/base/index.js +64 -0
  184. package/dist/api/controllers/query/import/sources/base/openapi.js +42 -0
  185. package/dist/api/controllers/query/import/sources/curl.js +96 -0
  186. package/dist/api/controllers/query/import/sources/openapi2.js +142 -0
  187. package/dist/api/controllers/query/import/sources/tests/openapi2/data/crud/crud.json +253 -0
  188. package/dist/api/controllers/query/import/sources/tests/openapi2/data/petstore/petstore.json +1054 -0
  189. package/dist/api/controllers/{query.js → query/index.js} +87 -52
  190. package/dist/api/controllers/query/validation.js +38 -0
  191. package/dist/api/controllers/role.js +1 -1
  192. package/dist/api/controllers/routing.js +1 -1
  193. package/dist/api/controllers/row/internal.js +14 -6
  194. package/dist/api/controllers/row/internalSearch.js +3 -2
  195. package/dist/api/controllers/row/utils.js +13 -6
  196. package/dist/api/controllers/screen.js +1 -1
  197. package/dist/api/controllers/user.js +40 -4
  198. package/dist/api/controllers/webhook.js +5 -1
  199. package/dist/api/index.js +1 -1
  200. package/dist/api/routes/apikeys.js +1 -1
  201. package/dist/api/routes/application.js +1 -1
  202. package/dist/api/routes/automation.js +1 -1
  203. package/dist/api/routes/backup.js +1 -1
  204. package/dist/api/routes/cloud.js +1 -1
  205. package/dist/api/routes/component.js +1 -1
  206. package/dist/api/routes/datasource.js +1 -1
  207. package/dist/api/routes/deploy.js +1 -1
  208. package/dist/api/routes/dev.js +1 -1
  209. package/dist/api/routes/hosting.js +1 -1
  210. package/dist/api/routes/integration.js +1 -1
  211. package/dist/api/routes/layout.js +1 -1
  212. package/dist/api/routes/metadata.js +1 -1
  213. package/dist/api/routes/permission.js +1 -1
  214. package/dist/api/routes/query.js +6 -34
  215. package/dist/api/routes/role.js +1 -1
  216. package/dist/api/routes/routing.js +1 -1
  217. package/dist/api/routes/row.js +1 -1
  218. package/dist/api/routes/screen.js +1 -1
  219. package/dist/api/routes/script.js +1 -1
  220. package/dist/api/routes/static.js +1 -1
  221. package/dist/api/routes/table.js +1 -1
  222. package/dist/api/routes/templates.js +1 -1
  223. package/dist/api/routes/tests/utilities/TestFunctions.js +1 -1
  224. package/dist/api/routes/user.js +4 -2
  225. package/dist/api/routes/view.js +1 -1
  226. package/dist/api/routes/webhook.js +1 -1
  227. package/dist/app.js +1 -1
  228. package/dist/automations/bullboard.js +1 -1
  229. package/dist/automations/steps/executeQuery.js +9 -2
  230. package/dist/automations/steps/outgoingWebhook.js +2 -3
  231. package/dist/automations/utils.js +11 -1
  232. package/dist/constants/index.js +3 -3
  233. package/dist/constants/screens.js +1 -1
  234. package/dist/db/client.js +1 -1
  235. package/dist/db/utils.js +9 -1
  236. package/dist/definitions/datasource.js +6 -1
  237. package/dist/environment.js +1 -0
  238. package/dist/integrations/base/sqlTable.js +1 -1
  239. package/dist/integrations/dynamodb.js +19 -0
  240. package/dist/integrations/rest.js +259 -120
  241. package/dist/integrations/s3.js +17 -8
  242. package/dist/integrations/utils.js +40 -37
  243. package/dist/middleware/authorized.js +2 -2
  244. package/dist/middleware/builder.js +2 -2
  245. package/dist/middleware/currentapp.js +6 -6
  246. package/dist/middleware/usageQuota.js +1 -1
  247. package/dist/package.json +11 -4
  248. package/dist/tests/utilities/TestConfiguration.js +55 -8
  249. package/dist/tests/utilities/structures.js +2 -2
  250. package/dist/threads/automation.js +2 -2
  251. package/dist/threads/query.js +195 -38
  252. package/dist/threads/utils.js +62 -1
  253. package/dist/tsconfig.tsbuildinfo +1 -1
  254. package/dist/utilities/budibaseDir.js +1 -1
  255. package/dist/utilities/fileSystem/utilities.js +2 -1
  256. package/dist/utilities/global.js +5 -5
  257. package/dist/utilities/index.js +11 -1
  258. package/dist/utilities/redis.js +1 -1
  259. package/dist/utilities/rowProcessor/index.js +76 -0
  260. package/dist/utilities/security.js +2 -2
  261. package/dist/utilities/usageQuota.js +2 -2
  262. package/dist/utilities/workerRequests.js +3 -3
  263. package/package.json +12 -5
  264. package/scripts/replicateApp.js +1 -1
  265. package/src/api/controllers/apikeys.js +2 -2
  266. package/src/api/controllers/application.js +7 -4
  267. package/src/api/controllers/auth.js +1 -1
  268. package/src/api/controllers/automation.js +8 -4
  269. package/src/api/controllers/cloud.js +5 -2
  270. package/src/api/controllers/datasource.js +34 -0
  271. package/src/api/controllers/deploy/index.js +2 -2
  272. package/src/api/controllers/dev.js +2 -2
  273. package/src/api/controllers/hosting.js +2 -2
  274. package/src/api/controllers/permission.js +2 -2
  275. package/src/api/controllers/query/import/index.ts +85 -0
  276. package/src/api/controllers/query/import/sources/base/index.ts +87 -0
  277. package/src/api/controllers/query/import/sources/base/openapi.ts +24 -0
  278. package/src/api/controllers/query/import/sources/curl.ts +102 -0
  279. package/src/api/controllers/query/import/sources/openapi2.ts +163 -0
  280. package/src/api/controllers/query/import/sources/tests/curl/curl.spec.js +103 -0
  281. package/src/api/controllers/query/import/sources/tests/curl/data/delete.txt +1 -0
  282. package/src/api/controllers/query/import/sources/tests/curl/data/empty-body.txt +2 -0
  283. package/src/api/controllers/query/import/sources/tests/curl/data/get.txt +1 -0
  284. package/src/api/controllers/query/import/sources/tests/curl/data/headers.txt +3 -0
  285. package/src/api/controllers/query/import/sources/tests/curl/data/patch.txt +2 -0
  286. package/src/api/controllers/query/import/sources/tests/curl/data/path.txt +1 -0
  287. package/src/api/controllers/query/import/sources/tests/curl/data/post.txt +2 -0
  288. package/src/api/controllers/query/import/sources/tests/curl/data/put.txt +2 -0
  289. package/src/api/controllers/query/import/sources/tests/curl/data/query.txt +1 -0
  290. package/src/api/controllers/query/import/sources/tests/openapi2/data/crud/crud.json +253 -0
  291. package/src/api/controllers/query/import/sources/tests/openapi2/data/crud/crud.yaml +160 -0
  292. package/src/api/controllers/query/import/sources/tests/openapi2/data/petstore/petstore.json +1054 -0
  293. package/src/api/controllers/query/import/sources/tests/openapi2/data/petstore/petstore.yaml +711 -0
  294. package/src/api/controllers/query/import/sources/tests/openapi2/openapi2.spec.js +238 -0
  295. package/src/api/controllers/query/import/tests/index.spec.js +109 -0
  296. package/src/api/controllers/query/index.js +196 -0
  297. package/src/api/controllers/query/validation.js +42 -0
  298. package/src/api/controllers/role.js +1 -1
  299. package/src/api/controllers/routing.js +1 -1
  300. package/src/api/controllers/row/internal.js +14 -5
  301. package/src/api/controllers/row/internalSearch.js +3 -2
  302. package/src/api/controllers/row/utils.js +11 -8
  303. package/src/api/controllers/screen.js +1 -1
  304. package/src/api/controllers/user.js +39 -3
  305. package/src/api/controllers/webhook.js +5 -1
  306. package/src/api/index.js +1 -1
  307. package/src/api/routes/apikeys.js +1 -1
  308. package/src/api/routes/application.js +1 -1
  309. package/src/api/routes/automation.js +1 -1
  310. package/src/api/routes/backup.js +1 -1
  311. package/src/api/routes/cloud.js +1 -1
  312. package/src/api/routes/component.js +1 -1
  313. package/src/api/routes/datasource.js +1 -1
  314. package/src/api/routes/deploy.js +1 -1
  315. package/src/api/routes/dev.js +1 -1
  316. package/src/api/routes/hosting.js +1 -1
  317. package/src/api/routes/integration.js +1 -1
  318. package/src/api/routes/layout.js +1 -1
  319. package/src/api/routes/metadata.js +1 -1
  320. package/src/api/routes/permission.js +4 -1
  321. package/src/api/routes/query.js +14 -36
  322. package/src/api/routes/role.js +1 -1
  323. package/src/api/routes/routing.js +1 -1
  324. package/src/api/routes/row.js +1 -1
  325. package/src/api/routes/screen.js +1 -1
  326. package/src/api/routes/script.js +1 -1
  327. package/src/api/routes/static.js +1 -1
  328. package/src/api/routes/table.js +1 -1
  329. package/src/api/routes/templates.js +1 -1
  330. package/src/api/routes/tests/datasource.spec.js +45 -0
  331. package/src/api/routes/tests/permissions.spec.js +1 -1
  332. package/src/api/routes/tests/query.spec.js +70 -1
  333. package/src/api/routes/tests/role.spec.js +2 -2
  334. package/src/api/routes/tests/routing.spec.js +1 -1
  335. package/src/api/routes/tests/user.spec.js +1 -1
  336. package/src/api/routes/tests/utilities/TestFunctions.js +1 -1
  337. package/src/api/routes/user.js +11 -1
  338. package/src/api/routes/view.js +1 -1
  339. package/src/api/routes/webhook.js +1 -1
  340. package/src/app.ts +1 -1
  341. package/src/automations/bullboard.js +1 -1
  342. package/src/automations/steps/executeQuery.js +10 -2
  343. package/src/automations/steps/outgoingWebhook.js +2 -3
  344. package/src/automations/utils.js +12 -1
  345. package/src/constants/index.js +3 -3
  346. package/src/constants/screens.js +1 -1
  347. package/src/db/client.js +1 -1
  348. package/src/db/utils.js +10 -1
  349. package/src/definitions/common.ts +2 -16
  350. package/src/definitions/datasource.ts +98 -1
  351. package/src/environment.js +1 -0
  352. package/src/integrations/base/IntegrationBase.ts +4 -4
  353. package/src/integrations/base/sqlTable.ts +1 -1
  354. package/src/integrations/dynamodb.ts +18 -0
  355. package/src/integrations/oracle.ts +1 -1
  356. package/src/integrations/rest.ts +311 -138
  357. package/src/integrations/s3.ts +18 -7
  358. package/src/integrations/tests/rest.spec.js +432 -21
  359. package/src/integrations/utils.ts +8 -7
  360. package/src/middleware/authorized.js +2 -2
  361. package/src/middleware/builder.js +2 -2
  362. package/src/middleware/currentapp.js +11 -7
  363. package/src/middleware/tests/authorized.spec.js +2 -2
  364. package/src/middleware/tests/currentapp.spec.js +35 -41
  365. package/src/middleware/tests/usageQuota.spec.js +1 -1
  366. package/src/middleware/usageQuota.js +1 -1
  367. package/src/tests/utilities/TestConfiguration.js +65 -8
  368. package/src/tests/utilities/structures.js +2 -2
  369. package/src/threads/automation.js +2 -2
  370. package/src/threads/query.js +204 -39
  371. package/src/threads/utils.js +66 -1
  372. package/src/utilities/budibaseDir.js +1 -1
  373. package/src/utilities/fileSystem/utilities.js +3 -1
  374. package/src/utilities/global.js +8 -5
  375. package/src/utilities/index.js +12 -1
  376. package/src/utilities/redis.js +1 -1
  377. package/src/utilities/rowProcessor/index.js +79 -0
  378. package/src/utilities/security.js +5 -2
  379. package/src/utilities/usageQuota.js +2 -2
  380. package/src/utilities/workerRequests.js +3 -3
  381. package/builder/assets/index.891d496c.js +0 -1316
  382. package/src/api/controllers/query.js +0 -158
@@ -2,29 +2,73 @@ import {
2
2
  Integration,
3
3
  DatasourceFieldTypes,
4
4
  QueryTypes,
5
+ RestConfig,
6
+ RestQueryFields as RestQuery,
7
+ PaginationConfig,
8
+ AuthType,
9
+ BasicAuthConfig,
10
+ BearerAuthConfig,
11
+ PaginationValues,
5
12
  } from "../definitions/datasource"
6
13
  import { IntegrationBase } from "./base/IntegrationBase"
7
14
 
15
+ const BodyTypes = {
16
+ NONE: "none",
17
+ FORM_DATA: "form",
18
+ XML: "xml",
19
+ ENCODED: "encoded",
20
+ JSON: "json",
21
+ TEXT: "text",
22
+ }
23
+
24
+ const coreFields = {
25
+ path: {
26
+ type: DatasourceFieldTypes.STRING,
27
+ display: "URL",
28
+ },
29
+ queryString: {
30
+ type: DatasourceFieldTypes.STRING,
31
+ },
32
+ headers: {
33
+ type: DatasourceFieldTypes.OBJECT,
34
+ },
35
+ enabledHeaders: {
36
+ type: DatasourceFieldTypes.OBJECT,
37
+ },
38
+ requestBody: {
39
+ type: DatasourceFieldTypes.JSON,
40
+ },
41
+ bodyType: {
42
+ type: DatasourceFieldTypes.STRING,
43
+ enum: Object.values(BodyTypes),
44
+ },
45
+ pagination: {
46
+ type: DatasourceFieldTypes.OBJECT,
47
+ },
48
+ }
49
+
8
50
  module RestModule {
9
51
  const fetch = require("node-fetch")
10
-
11
- interface RestConfig {
12
- url: string
13
- defaultHeaders: {
14
- [key: string]: any
15
- }
16
- }
52
+ const { formatBytes } = require("../utilities")
53
+ const { performance } = require("perf_hooks")
54
+ const FormData = require("form-data")
55
+ const { URLSearchParams } = require("url")
56
+ const {
57
+ parseStringPromise: xmlParser,
58
+ Builder: XmlBuilder,
59
+ } = require("xml2js")
17
60
 
18
61
  const SCHEMA: Integration = {
19
62
  docs: "https://github.com/node-fetch/node-fetch",
20
63
  description:
21
- "Representational state transfer (REST) is a de-facto standard for a software architecture for interactive applications that typically use multiple Web services. ",
64
+ "With the REST API datasource, you can connect, query and pull data from multiple REST APIs. You can then use the retrieved data to build apps.",
22
65
  friendlyName: "REST API",
23
66
  datasource: {
24
67
  url: {
25
68
  type: DatasourceFieldTypes.STRING,
26
- default: "localhost",
27
- required: true,
69
+ default: "",
70
+ required: false,
71
+ deprecated: true,
28
72
  },
29
73
  defaultHeaders: {
30
74
  type: DatasourceFieldTypes.OBJECT,
@@ -37,97 +81,30 @@ module RestModule {
37
81
  readable: true,
38
82
  displayName: "POST",
39
83
  type: QueryTypes.FIELDS,
40
- urlDisplay: true,
41
- fields: {
42
- path: {
43
- type: DatasourceFieldTypes.STRING,
44
- },
45
- queryString: {
46
- type: DatasourceFieldTypes.STRING,
47
- },
48
- headers: {
49
- type: DatasourceFieldTypes.OBJECT,
50
- },
51
- requestBody: {
52
- type: DatasourceFieldTypes.JSON,
53
- },
54
- },
84
+ fields: coreFields,
55
85
  },
56
86
  read: {
57
87
  displayName: "GET",
58
88
  readable: true,
59
89
  type: QueryTypes.FIELDS,
60
- urlDisplay: true,
61
- fields: {
62
- path: {
63
- type: DatasourceFieldTypes.STRING,
64
- },
65
- queryString: {
66
- type: DatasourceFieldTypes.STRING,
67
- },
68
- headers: {
69
- type: DatasourceFieldTypes.OBJECT,
70
- },
71
- },
90
+ fields: coreFields,
72
91
  },
73
92
  update: {
74
93
  displayName: "PUT",
75
94
  readable: true,
76
95
  type: QueryTypes.FIELDS,
77
- urlDisplay: true,
78
- fields: {
79
- path: {
80
- type: DatasourceFieldTypes.STRING,
81
- },
82
- queryString: {
83
- type: DatasourceFieldTypes.STRING,
84
- },
85
- headers: {
86
- type: DatasourceFieldTypes.OBJECT,
87
- },
88
- requestBody: {
89
- type: DatasourceFieldTypes.JSON,
90
- },
91
- },
96
+ fields: coreFields,
92
97
  },
93
98
  patch: {
94
99
  displayName: "PATCH",
95
100
  readable: true,
96
101
  type: QueryTypes.FIELDS,
97
- urlDisplay: true,
98
- fields: {
99
- path: {
100
- type: DatasourceFieldTypes.STRING,
101
- },
102
- queryString: {
103
- type: DatasourceFieldTypes.STRING,
104
- },
105
- headers: {
106
- type: DatasourceFieldTypes.OBJECT,
107
- },
108
- requestBody: {
109
- type: DatasourceFieldTypes.JSON,
110
- },
111
- },
102
+ fields: coreFields,
112
103
  },
113
104
  delete: {
114
105
  displayName: "DELETE",
115
106
  type: QueryTypes.FIELDS,
116
- urlDisplay: true,
117
- fields: {
118
- path: {
119
- type: DatasourceFieldTypes.STRING,
120
- },
121
- queryString: {
122
- type: DatasourceFieldTypes.STRING,
123
- },
124
- headers: {
125
- type: DatasourceFieldTypes.OBJECT,
126
- },
127
- requestBody: {
128
- type: DatasourceFieldTypes.JSON,
129
- },
130
- },
107
+ fields: coreFields,
131
108
  },
132
109
  },
133
110
  }
@@ -137,99 +114,295 @@ module RestModule {
137
114
  private headers: {
138
115
  [key: string]: string
139
116
  } = {}
117
+ private startTimeMs: number = performance.now()
140
118
 
141
119
  constructor(config: RestConfig) {
142
120
  this.config = config
143
121
  }
144
122
 
145
- async parseResponse(response: any) {
146
- const contentType = response.headers.get("content-type")
147
- if (contentType && contentType.indexOf("application/json") !== -1) {
148
- return await response.json()
149
- } else {
150
- return await response.text()
123
+ async parseResponse(response: any, pagination: PaginationConfig | null) {
124
+ let data, raw, headers
125
+ const contentType = response.headers.get("content-type") || ""
126
+ try {
127
+ if (contentType.includes("application/json")) {
128
+ data = await response.json()
129
+ raw = JSON.stringify(data)
130
+ } else if (
131
+ contentType.includes("text/xml") ||
132
+ contentType.includes("application/xml")
133
+ ) {
134
+ const rawXml = await response.text()
135
+ data =
136
+ (await xmlParser(rawXml, {
137
+ explicitArray: false,
138
+ trim: true,
139
+ explicitRoot: false,
140
+ })) || {}
141
+ // there is only one structure, its an array, return the array so it appears as rows
142
+ const keys = Object.keys(data)
143
+ if (keys.length === 1 && Array.isArray(data[keys[0]])) {
144
+ data = data[keys[0]]
145
+ }
146
+ raw = rawXml
147
+ } else {
148
+ data = await response.text()
149
+ raw = data
150
+ }
151
+ } catch (err) {
152
+ throw "Failed to parse response body."
153
+ }
154
+ const size = formatBytes(
155
+ response.headers.get("content-length") || Buffer.byteLength(raw, "utf8")
156
+ )
157
+ const time = `${Math.round(performance.now() - this.startTimeMs)}ms`
158
+ headers = response.headers.raw()
159
+ for (let [key, value] of Object.entries(headers)) {
160
+ headers[key] = Array.isArray(value) ? value[0] : value
151
161
  }
152
- }
153
162
 
154
- getUrl(path: string, queryString: string): string {
155
- return `${this.config.url}/${path}?${queryString}`
156
- }
163
+ // Check if a pagination cursor exists in the response
164
+ let nextCursor = null
165
+ if (pagination?.responseParam) {
166
+ nextCursor = data?.[pagination.responseParam]
167
+ }
157
168
 
158
- async create({ path = "", queryString = "", headers = {}, json = {} }) {
159
- this.headers = {
160
- ...this.config.defaultHeaders,
161
- ...headers,
169
+ return {
170
+ data,
171
+ info: {
172
+ code: response.status,
173
+ size,
174
+ time,
175
+ },
176
+ extra: {
177
+ raw,
178
+ headers,
179
+ },
180
+ pagination: {
181
+ cursor: nextCursor,
182
+ },
162
183
  }
184
+ }
185
+
186
+ getUrl(
187
+ path: string,
188
+ queryString: string,
189
+ pagination: PaginationConfig | null,
190
+ paginationValues: PaginationValues | null
191
+ ): string {
192
+ // Add pagination params to query string if required
193
+ if (pagination?.location === "query" && paginationValues) {
194
+ const { pageParam, sizeParam } = pagination
195
+ const params = new URLSearchParams()
163
196
 
164
- const response = await fetch(this.getUrl(path, queryString), {
165
- method: "POST",
166
- headers: this.headers,
167
- body: JSON.stringify(json),
168
- })
197
+ // Append page number or cursor param if configured
198
+ if (pageParam && paginationValues.page != null) {
199
+ params.append(pageParam, paginationValues.page)
200
+ }
201
+
202
+ // Append page size param if configured
203
+ if (sizeParam && paginationValues.limit != null) {
204
+ params.append(sizeParam, paginationValues.limit)
205
+ }
206
+
207
+ // Prepend query string with pagination params
208
+ let paginationString = params.toString()
209
+ if (paginationString) {
210
+ queryString = `${paginationString}&${queryString}`
211
+ }
212
+ }
169
213
 
170
- return await this.parseResponse(response)
214
+ const main = `${path}?${queryString}`
215
+ let complete = main
216
+ if (this.config.url && !main.startsWith("http")) {
217
+ complete = !this.config.url ? main : `${this.config.url}/${main}`
218
+ }
219
+ if (!complete.startsWith("http")) {
220
+ complete = `http://${complete}`
221
+ }
222
+ return complete
171
223
  }
172
224
 
173
- async read({ path = "", queryString = "", headers = {} }) {
174
- this.headers = {
175
- ...this.config.defaultHeaders,
176
- ...headers,
225
+ addBody(
226
+ bodyType: string,
227
+ body: string | any,
228
+ input: any,
229
+ pagination: PaginationConfig | null,
230
+ paginationValues: PaginationValues | null
231
+ ) {
232
+ if (!input.headers) {
233
+ input.headers = {}
234
+ }
235
+ if (bodyType === BodyTypes.NONE) {
236
+ return input
237
+ }
238
+ let error,
239
+ object: any = {},
240
+ string = ""
241
+ try {
242
+ if (body) {
243
+ string = typeof body !== "string" ? JSON.stringify(body) : body
244
+ object = typeof body === "object" ? body : JSON.parse(body)
245
+ }
246
+ } catch (err) {
247
+ error = err
177
248
  }
178
249
 
179
- const response = await fetch(this.getUrl(path, queryString), {
180
- headers: this.headers,
181
- })
250
+ // Util to add pagination values to a certain body type
251
+ const addPaginationToBody = (insertFn: Function) => {
252
+ if (pagination?.location === "body") {
253
+ if (pagination?.pageParam && paginationValues?.page != null) {
254
+ insertFn(pagination.pageParam, paginationValues.page)
255
+ }
256
+ if (pagination?.sizeParam && paginationValues?.limit != null) {
257
+ insertFn(pagination.sizeParam, paginationValues.limit)
258
+ }
259
+ }
260
+ }
182
261
 
183
- return await this.parseResponse(response)
262
+ switch (bodyType) {
263
+ case BodyTypes.TEXT:
264
+ // content type defaults to plaintext
265
+ input.body = string
266
+ break
267
+ case BodyTypes.ENCODED:
268
+ const params = new URLSearchParams()
269
+ for (let [key, value] of Object.entries(object)) {
270
+ params.append(key, value)
271
+ }
272
+ addPaginationToBody((key: string, value: any) => {
273
+ params.append(key, value)
274
+ })
275
+ input.body = params
276
+ break
277
+ case BodyTypes.FORM_DATA:
278
+ const form = new FormData()
279
+ for (let [key, value] of Object.entries(object)) {
280
+ form.append(key, value)
281
+ }
282
+ addPaginationToBody((key: string, value: any) => {
283
+ form.append(key, value)
284
+ })
285
+ input.body = form
286
+ break
287
+ case BodyTypes.XML:
288
+ if (object != null) {
289
+ string = new XmlBuilder().buildObject(object)
290
+ }
291
+ input.body = string
292
+ input.headers["Content-Type"] = "application/xml"
293
+ break
294
+ case BodyTypes.JSON:
295
+ // if JSON error, throw it
296
+ if (error) {
297
+ throw "Invalid JSON for request body"
298
+ }
299
+ addPaginationToBody((key: string, value: any) => {
300
+ object[key] = value
301
+ })
302
+ input.body = JSON.stringify(object)
303
+ input.headers["Content-Type"] = "application/json"
304
+ break
305
+ }
306
+ return input
184
307
  }
185
308
 
186
- async update({ path = "", queryString = "", headers = {}, json = {} }) {
187
- this.headers = {
188
- ...this.config.defaultHeaders,
189
- ...headers,
190
- }
309
+ getAuthHeaders(authConfigId: string): { [key: string]: any } {
310
+ let headers: any = {}
191
311
 
192
- const response = await fetch(this.getUrl(path, queryString), {
193
- method: "PUT",
194
- headers: this.headers,
195
- body: JSON.stringify(json),
196
- })
312
+ if (this.config.authConfigs && authConfigId) {
313
+ const authConfig = this.config.authConfigs.filter(
314
+ c => c._id === authConfigId
315
+ )[0]
316
+ // check the config still exists before proceeding
317
+ // if not - do nothing
318
+ if (authConfig) {
319
+ let config
320
+ switch (authConfig.type) {
321
+ case AuthType.BASIC:
322
+ config = authConfig.config as BasicAuthConfig
323
+ headers.Authorization = `Basic ${Buffer.from(
324
+ `${config.username}:${config.password}`
325
+ ).toString("base64")}`
326
+ break
327
+ case AuthType.BEARER:
328
+ config = authConfig.config as BearerAuthConfig
329
+ headers.Authorization = `Bearer ${config.token}`
330
+ break
331
+ }
332
+ }
333
+ }
197
334
 
198
- return await this.parseResponse(response)
335
+ return headers
199
336
  }
200
337
 
201
- async patch({ path = "", queryString = "", headers = {}, json = {} }) {
338
+ async _req(query: RestQuery) {
339
+ const {
340
+ path = "",
341
+ queryString = "",
342
+ headers = {},
343
+ method = "GET",
344
+ disabledHeaders,
345
+ bodyType,
346
+ requestBody,
347
+ authConfigId,
348
+ pagination,
349
+ paginationValues,
350
+ } = query
351
+ const authHeaders = this.getAuthHeaders(authConfigId)
352
+
202
353
  this.headers = {
203
354
  ...this.config.defaultHeaders,
204
355
  ...headers,
356
+ ...authHeaders,
357
+ }
358
+
359
+ if (disabledHeaders) {
360
+ for (let headerKey of Object.keys(this.headers)) {
361
+ if (disabledHeaders[headerKey]) {
362
+ delete this.headers[headerKey]
363
+ }
364
+ }
205
365
  }
206
366
 
207
- const response = await fetch(this.getUrl(path, queryString), {
208
- method: "PATCH",
209
- headers: this.headers,
210
- body: JSON.stringify(json),
211
- })
367
+ let input: any = { method, headers: this.headers }
368
+ input = this.addBody(
369
+ bodyType,
370
+ requestBody,
371
+ input,
372
+ pagination,
373
+ paginationValues
374
+ )
212
375
 
213
- return await this.parseResponse(response)
376
+ this.startTimeMs = performance.now()
377
+ const url = this.getUrl(path, queryString, pagination, paginationValues)
378
+ const response = await fetch(url, input)
379
+ return await this.parseResponse(response, pagination)
214
380
  }
215
381
 
216
- async delete({ path = "", queryString = "", headers = {} }) {
217
- this.headers = {
218
- ...this.config.defaultHeaders,
219
- ...headers,
220
- }
382
+ async create(opts: RestQuery) {
383
+ return this._req({ ...opts, method: "POST" })
384
+ }
385
+
386
+ async read(opts: RestQuery) {
387
+ return this._req({ ...opts, method: "GET" })
388
+ }
221
389
 
222
- const response = await fetch(this.getUrl(path, queryString), {
223
- method: "DELETE",
224
- headers: this.headers,
225
- })
390
+ async update(opts: RestQuery) {
391
+ return this._req({ ...opts, method: "PUT" })
392
+ }
393
+
394
+ async patch(opts: RestQuery) {
395
+ return this._req({ ...opts, method: "PATCH" })
396
+ }
226
397
 
227
- return await this.parseResponse(response)
398
+ async delete(opts: RestQuery) {
399
+ return this._req({ ...opts, method: "DELETE" })
228
400
  }
229
401
  }
230
402
 
231
403
  module.exports = {
232
404
  schema: SCHEMA,
233
405
  integration: RestIntegration,
406
+ AuthType,
234
407
  }
235
408
  }
@@ -8,6 +8,8 @@ module S3Module {
8
8
  region: string
9
9
  accessKeyId: string
10
10
  secretAccessKey: string
11
+ s3ForcePathStyle: boolean
12
+ endpoint?: string
11
13
  }
12
14
 
13
15
  const SCHEMA: Integration = {
@@ -18,7 +20,7 @@ module S3Module {
18
20
  datasource: {
19
21
  region: {
20
22
  type: "string",
21
- required: true,
23
+ required: false,
22
24
  default: "us-east-1",
23
25
  },
24
26
  accessKeyId: {
@@ -29,6 +31,15 @@ module S3Module {
29
31
  type: "password",
30
32
  required: true,
31
33
  },
34
+ endpoint: {
35
+ type: "string",
36
+ required: false,
37
+ },
38
+ signatureVersion: {
39
+ type: "string",
40
+ required: false,
41
+ default: "v4"
42
+ },
32
43
  },
33
44
  query: {
34
45
  read: {
@@ -46,16 +57,16 @@ module S3Module {
46
57
  class S3Integration implements IntegrationBase {
47
58
  private readonly config: S3Config
48
59
  private client: any
49
- private connectionPromise: Promise<any>
50
60
 
51
61
  constructor(config: S3Config) {
52
62
  this.config = config
53
- this.connectionPromise = this.connect()
54
- this.client = new AWS.S3()
55
- }
63
+ if (this.config.endpoint) {
64
+ this.config.s3ForcePathStyle = true
65
+ } else {
66
+ delete this.config.endpoint
67
+ }
56
68
 
57
- async connect() {
58
- AWS.config.update(this.config)
69
+ this.client = new AWS.S3(this.config)
59
70
  }
60
71
 
61
72
  async read(query: { bucket: string }) {