@budibase/server 1.0.80-alpha.3 → 1.0.80

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 (316) hide show
  1. package/__mocks__/node-fetch.ts +0 -1
  2. package/builder/assets/index.22a39cc9.js +1352 -0
  3. package/builder/assets/{index.c57242d4.css → index.c8d1e8f0.css} +2 -2
  4. package/builder/assets/{vendor.a7c6ad0a.js → vendor.20f80cec.js} +216 -190
  5. package/builder/index.html +3 -3
  6. package/coverage/clover.xml +2327 -2390
  7. package/coverage/coverage-final.json +137 -138
  8. package/coverage/lcov-report/api/controllers/analytics.js.html +6 -6
  9. package/coverage/lcov-report/api/controllers/apikeys.js.html +6 -6
  10. package/coverage/lcov-report/api/controllers/application.js.html +149 -152
  11. package/coverage/lcov-report/api/controllers/auth.js.html +7 -7
  12. package/coverage/lcov-report/api/controllers/automation.js.html +21 -21
  13. package/coverage/lcov-report/api/controllers/backup.js.html +3 -3
  14. package/coverage/lcov-report/api/controllers/cloud.js.html +11 -11
  15. package/coverage/lcov-report/api/controllers/component.js.html +5 -5
  16. package/coverage/lcov-report/api/controllers/datasource.js.html +16 -16
  17. package/coverage/lcov-report/api/controllers/dev.js.html +19 -19
  18. package/coverage/lcov-report/api/controllers/index.html +16 -16
  19. package/coverage/lcov-report/api/controllers/integration.js.html +4 -4
  20. package/coverage/lcov-report/api/controllers/layout.js.html +6 -6
  21. package/coverage/lcov-report/api/controllers/metadata.js.html +9 -9
  22. package/coverage/lcov-report/api/controllers/migrations.js.html +4 -4
  23. package/coverage/lcov-report/api/controllers/permission.js.html +15 -15
  24. package/coverage/lcov-report/api/controllers/query/index.html +1 -1
  25. package/coverage/lcov-report/api/controllers/query/index.js.html +26 -26
  26. package/coverage/lcov-report/api/controllers/query/validation.js.html +10 -10
  27. package/coverage/lcov-report/api/controllers/role.js.html +9 -9
  28. package/coverage/lcov-report/api/controllers/routing.js.html +9 -9
  29. package/coverage/lcov-report/api/controllers/row/external.js.html +16 -16
  30. package/coverage/lcov-report/api/controllers/row/index.html +27 -27
  31. package/coverage/lcov-report/api/controllers/row/index.js.html +46 -46
  32. package/coverage/lcov-report/api/controllers/row/internal.js.html +82 -94
  33. package/coverage/lcov-report/api/controllers/row/internalSearch.js.html +204 -204
  34. package/coverage/lcov-report/api/controllers/row/staticFormula.js.html +24 -24
  35. package/coverage/lcov-report/api/controllers/row/utils.js.html +29 -29
  36. package/coverage/lcov-report/api/controllers/screen.js.html +7 -7
  37. package/coverage/lcov-report/api/controllers/script.js.html +4 -4
  38. package/coverage/lcov-report/api/controllers/table/bulkFormula.js.html +49 -49
  39. package/coverage/lcov-report/api/controllers/table/external.js.html +12 -12
  40. package/coverage/lcov-report/api/controllers/table/index.html +11 -11
  41. package/coverage/lcov-report/api/controllers/table/index.js.html +44 -47
  42. package/coverage/lcov-report/api/controllers/table/internal.js.html +50 -50
  43. package/coverage/lcov-report/api/controllers/table/utils.js.html +80 -80
  44. package/coverage/lcov-report/api/controllers/templates.js.html +5 -5
  45. package/coverage/lcov-report/api/controllers/user.js.html +19 -19
  46. package/coverage/lcov-report/api/controllers/view/exporters.js.html +4 -4
  47. package/coverage/lcov-report/api/controllers/view/index.html +1 -1
  48. package/coverage/lcov-report/api/controllers/view/index.js.html +14 -14
  49. package/coverage/lcov-report/api/controllers/view/utils.js.html +12 -12
  50. package/coverage/lcov-report/api/controllers/view/viewBuilder.js.html +7 -7
  51. package/coverage/lcov-report/api/controllers/webhook.js.html +27 -18
  52. package/coverage/lcov-report/api/index.html +10 -10
  53. package/coverage/lcov-report/api/index.js.html +28 -37
  54. package/coverage/lcov-report/api/routes/analytics.js.html +6 -6
  55. package/coverage/lcov-report/api/routes/apikeys.js.html +8 -8
  56. package/coverage/lcov-report/api/routes/application.js.html +9 -9
  57. package/coverage/lcov-report/api/routes/auth.js.html +6 -6
  58. package/coverage/lcov-report/api/routes/automation.js.html +109 -19
  59. package/coverage/lcov-report/api/routes/backup.js.html +8 -8
  60. package/coverage/lcov-report/api/routes/cloud.js.html +8 -8
  61. package/coverage/lcov-report/api/routes/component.js.html +8 -8
  62. package/coverage/lcov-report/api/routes/datasource.js.html +156 -18
  63. package/coverage/lcov-report/api/routes/deploy.js.html +8 -8
  64. package/coverage/lcov-report/api/routes/dev.js.html +13 -13
  65. package/coverage/lcov-report/api/routes/index.html +35 -35
  66. package/coverage/lcov-report/api/routes/index.js.html +32 -38
  67. package/coverage/lcov-report/api/routes/integration.js.html +8 -8
  68. package/coverage/lcov-report/api/routes/layout.js.html +8 -8
  69. package/coverage/lcov-report/api/routes/metadata.js.html +9 -9
  70. package/coverage/lcov-report/api/routes/migrations.js.html +7 -7
  71. package/coverage/lcov-report/api/routes/permission.js.html +58 -16
  72. package/coverage/lcov-report/api/routes/query.js.html +10 -10
  73. package/coverage/lcov-report/api/routes/role.js.html +78 -15
  74. package/coverage/lcov-report/api/routes/routing.js.html +8 -8
  75. package/coverage/lcov-report/api/routes/row.js.html +14 -17
  76. package/coverage/lcov-report/api/routes/screen.js.html +95 -14
  77. package/coverage/lcov-report/api/routes/script.js.html +1 -1
  78. package/coverage/lcov-report/api/routes/static.js.html +13 -13
  79. package/coverage/lcov-report/api/routes/table.js.html +62 -17
  80. package/coverage/lcov-report/api/routes/templates.js.html +8 -8
  81. package/coverage/lcov-report/api/routes/user.js.html +8 -8
  82. package/coverage/lcov-report/api/routes/view.js.html +10 -10
  83. package/coverage/lcov-report/api/routes/webhook.js.html +62 -14
  84. package/coverage/lcov-report/automations/actions.js.html +24 -24
  85. package/coverage/lcov-report/automations/automationUtils.js.html +5 -5
  86. package/coverage/lcov-report/automations/bullboard.js.html +16 -16
  87. package/coverage/lcov-report/automations/index.html +1 -1
  88. package/coverage/lcov-report/automations/index.js.html +7 -7
  89. package/coverage/lcov-report/automations/steps/bash.js.html +6 -6
  90. package/coverage/lcov-report/automations/steps/createRow.js.html +7 -7
  91. package/coverage/lcov-report/automations/steps/delay.js.html +4 -4
  92. package/coverage/lcov-report/automations/steps/deleteRow.js.html +7 -7
  93. package/coverage/lcov-report/automations/steps/discord.js.html +7 -7
  94. package/coverage/lcov-report/automations/steps/executeQuery.js.html +6 -6
  95. package/coverage/lcov-report/automations/steps/executeScript.js.html +6 -6
  96. package/coverage/lcov-report/automations/steps/filter.js.html +9 -12
  97. package/coverage/lcov-report/automations/steps/index.html +1 -1
  98. package/coverage/lcov-report/automations/steps/integromat.js.html +5 -5
  99. package/coverage/lcov-report/automations/steps/outgoingWebhook.js.html +8 -8
  100. package/coverage/lcov-report/automations/steps/queryRows.js.html +11 -11
  101. package/coverage/lcov-report/automations/steps/sendSmtpEmail.js.html +5 -5
  102. package/coverage/lcov-report/automations/steps/serverLog.js.html +3 -3
  103. package/coverage/lcov-report/automations/steps/slack.js.html +5 -5
  104. package/coverage/lcov-report/automations/steps/updateRow.js.html +6 -6
  105. package/coverage/lcov-report/automations/steps/utils.js.html +3 -3
  106. package/coverage/lcov-report/automations/steps/zapier.js.html +5 -5
  107. package/coverage/lcov-report/automations/triggerInfo/app.js.html +2 -2
  108. package/coverage/lcov-report/automations/triggerInfo/cron.js.html +2 -2
  109. package/coverage/lcov-report/automations/triggerInfo/index.html +1 -1
  110. package/coverage/lcov-report/automations/triggerInfo/index.js.html +8 -8
  111. package/coverage/lcov-report/automations/triggerInfo/rowDeleted.js.html +2 -2
  112. package/coverage/lcov-report/automations/triggerInfo/rowSaved.js.html +2 -2
  113. package/coverage/lcov-report/automations/triggerInfo/rowUpdated.js.html +2 -2
  114. package/coverage/lcov-report/automations/triggerInfo/webhook.js.html +2 -2
  115. package/coverage/lcov-report/automations/triggers.js.html +26 -26
  116. package/coverage/lcov-report/automations/utils.js.html +35 -35
  117. package/coverage/lcov-report/constants/index.html +5 -5
  118. package/coverage/lcov-report/constants/index.js.html +28 -40
  119. package/coverage/lcov-report/constants/layouts.js.html +5 -5
  120. package/coverage/lcov-report/constants/screens.js.html +4 -4
  121. package/coverage/lcov-report/db/client.js.html +18 -18
  122. package/coverage/lcov-report/db/inMemoryView.js.html +7 -7
  123. package/coverage/lcov-report/db/index.html +15 -15
  124. package/coverage/lcov-report/db/index.js.html +3 -3
  125. package/coverage/lcov-report/db/linkedRows/LinkController.js.html +21 -21
  126. package/coverage/lcov-report/db/linkedRows/index.html +1 -1
  127. package/coverage/lcov-report/db/linkedRows/index.js.html +36 -36
  128. package/coverage/lcov-report/db/linkedRows/linkUtils.js.html +30 -30
  129. package/coverage/lcov-report/db/newid.js.html +4 -4
  130. package/coverage/lcov-report/db/utils.js.html +87 -123
  131. package/coverage/lcov-report/events/AutomationEmitter.js.html +1 -1
  132. package/coverage/lcov-report/events/index.html +1 -1
  133. package/coverage/lcov-report/events/index.js.html +8 -8
  134. package/coverage/lcov-report/events/utils.js.html +18 -18
  135. package/coverage/lcov-report/index.html +74 -89
  136. package/coverage/lcov-report/integrations/tests/TestConfiguration.js.html +1 -1
  137. package/coverage/lcov-report/integrations/tests/index.html +1 -1
  138. package/coverage/lcov-report/middleware/appInfo.js.html +5 -5
  139. package/coverage/lcov-report/middleware/authorized.js.html +29 -29
  140. package/coverage/lcov-report/middleware/builder.js.html +16 -16
  141. package/coverage/lcov-report/middleware/currentapp.js.html +44 -44
  142. package/coverage/lcov-report/middleware/index.html +1 -1
  143. package/coverage/lcov-report/middleware/joi-validator.js.html +14 -14
  144. package/coverage/lcov-report/middleware/resourceId.js.html +29 -29
  145. package/coverage/lcov-report/middleware/selfhost.js.html +1 -1
  146. package/coverage/lcov-report/middleware/usageQuota.js.html +17 -17
  147. package/coverage/lcov-report/middleware/utils.js.html +4 -4
  148. package/coverage/lcov-report/threads/automation.js.html +1 -1
  149. package/coverage/lcov-report/threads/index.html +19 -19
  150. package/coverage/lcov-report/threads/index.js.html +10 -10
  151. package/coverage/lcov-report/threads/query.js.html +39 -123
  152. package/coverage/lcov-report/threads/utils.js.html +14 -14
  153. package/coverage/lcov-report/utilities/bcrypt.js.html +1 -1
  154. package/coverage/lcov-report/utilities/budibaseDir.js.html +7 -7
  155. package/coverage/lcov-report/utilities/centralPath.js.html +4 -4
  156. package/coverage/lcov-report/utilities/csvParser.js.html +6 -6
  157. package/coverage/lcov-report/utilities/global.js.html +28 -28
  158. package/coverage/lcov-report/utilities/index.html +18 -18
  159. package/coverage/lcov-report/utilities/index.js.html +24 -24
  160. package/coverage/lcov-report/utilities/queue/inMemoryQueue.js.html +9 -9
  161. package/coverage/lcov-report/utilities/queue/index.html +1 -1
  162. package/coverage/lcov-report/utilities/routing/index.html +1 -1
  163. package/coverage/lcov-report/utilities/routing/index.js.html +6 -6
  164. package/coverage/lcov-report/utilities/rowProcessor/index.html +1 -1
  165. package/coverage/lcov-report/utilities/rowProcessor/index.js.html +60 -60
  166. package/coverage/lcov-report/utilities/rowProcessor/utils.js.html +13 -13
  167. package/coverage/lcov-report/utilities/scriptRunner.js.html +5 -5
  168. package/coverage/lcov-report/utilities/security.js.html +8 -8
  169. package/coverage/lcov-report/utilities/statusCodes.js.html +1 -1
  170. package/coverage/lcov-report/utilities/usageQuota/index.html +1 -1
  171. package/coverage/lcov-report/utilities/usageQuota/index.js.html +12 -12
  172. package/coverage/lcov-report/utilities/usageQuota/rows.js.html +8 -8
  173. package/coverage/lcov-report/utilities/usageQuota/usageQuoteReset.js.html +1 -1
  174. package/coverage/lcov-report/utilities/users.js.html +5 -5
  175. package/coverage/lcov-report/utilities/workerRequests.js.html +53 -200
  176. package/coverage/lcov.info +3233 -3332
  177. package/dist/api/controllers/application.js +0 -1
  178. package/dist/api/controllers/row/internal.js +1 -4
  179. package/dist/api/controllers/table/index.js +1 -2
  180. package/dist/api/controllers/webhook.js +5 -3
  181. package/dist/api/index.js +1 -3
  182. package/dist/api/routes/automation.js +31 -3
  183. package/dist/api/routes/datasource.js +50 -3
  184. package/dist/api/routes/index.js +0 -2
  185. package/dist/api/routes/permission.js +14 -4
  186. package/dist/api/routes/role.js +19 -3
  187. package/dist/api/routes/row.js +4 -3
  188. package/dist/api/routes/screen.js +23 -2
  189. package/dist/api/routes/table.js +17 -3
  190. package/dist/api/routes/tests/utilities/index.js +0 -23
  191. package/dist/api/routes/webhook.js +17 -2
  192. package/dist/automations/steps/filter.js +2 -2
  193. package/dist/automations/steps/queryRows.js +1 -1
  194. package/dist/automations/utils.js +2 -2
  195. package/dist/constants/index.js +0 -3
  196. package/dist/db/utils.js +0 -11
  197. package/dist/environment.js +0 -1
  198. package/dist/integrations/base/sql.js +1 -16
  199. package/dist/integrations/base/sqlTable.js +4 -8
  200. package/dist/integrations/googlesheets.js +0 -3
  201. package/dist/integrations/microsoftSqlServer.js +43 -60
  202. package/dist/integrations/mysql.js +0 -3
  203. package/dist/integrations/oracle.js +19 -14
  204. package/dist/integrations/postgres.js +28 -34
  205. package/dist/integrations/utils.js +15 -32
  206. package/dist/package.json +7 -11
  207. package/dist/tests/utilities/TestConfiguration.js +8 -25
  208. package/dist/threads/query.js +8 -33
  209. package/dist/tsconfig.tsbuildinfo +1 -1
  210. package/dist/utilities/workerRequests.js +15 -50
  211. package/package.json +8 -12
  212. package/scripts/integrations/mssql/data/setup.sql +1 -18
  213. package/scripts/integrations/oracle/oracle.md +2 -2
  214. package/scripts/integrations/postgres/init.sql +3 -11
  215. package/scripts/likeCypress.ts +6 -9
  216. package/scripts/proxy/generateProxyConfig.js +70 -0
  217. package/src/api/controllers/application.js +0 -1
  218. package/src/api/controllers/row/ExternalRequest.ts +1 -1
  219. package/src/api/controllers/row/internal.js +0 -4
  220. package/src/api/controllers/table/index.js +1 -2
  221. package/src/api/controllers/webhook.js +6 -3
  222. package/src/api/index.js +1 -4
  223. package/src/api/routes/automation.js +33 -3
  224. package/src/api/routes/datasource.js +52 -6
  225. package/src/api/routes/index.js +0 -2
  226. package/src/api/routes/permission.js +18 -4
  227. package/src/api/routes/role.js +24 -3
  228. package/src/api/routes/row.js +2 -3
  229. package/src/api/routes/screen.js +29 -2
  230. package/src/api/routes/table.js +19 -4
  231. package/src/api/routes/tests/utilities/index.js +0 -24
  232. package/src/api/routes/webhook.js +18 -2
  233. package/src/automations/steps/filter.js +2 -3
  234. package/src/automations/steps/queryRows.js +1 -1
  235. package/src/automations/utils.js +2 -2
  236. package/src/constants/index.js +0 -4
  237. package/src/db/utils.js +0 -12
  238. package/src/definitions/common.ts +0 -4
  239. package/src/definitions/datasource.ts +0 -1
  240. package/src/environment.js +0 -1
  241. package/src/integrations/base/datasourcePlus.ts +0 -3
  242. package/src/integrations/base/sql.ts +1 -16
  243. package/src/integrations/base/sqlTable.ts +7 -11
  244. package/src/integrations/googlesheets.ts +2 -5
  245. package/src/integrations/microsoftSqlServer.ts +61 -86
  246. package/src/integrations/mysql.ts +0 -4
  247. package/src/integrations/oracle.ts +35 -27
  248. package/src/integrations/postgres.ts +26 -33
  249. package/src/integrations/utils.ts +15 -43
  250. package/src/tests/utilities/TestConfiguration.js +2 -23
  251. package/src/threads/query.js +9 -37
  252. package/src/utilities/workerRequests.js +16 -65
  253. package/builder/assets/index.f8c92447.js +0 -1288
  254. package/coverage/lcov-report/api/routes/utils/index.html +0 -111
  255. package/coverage/lcov-report/api/routes/utils/validators.js.html +0 -737
  256. package/dist/api/controllers/public/applications.js +0 -94
  257. package/dist/api/controllers/public/mapping/applications.js +0 -29
  258. package/dist/api/controllers/public/mapping/index.js +0 -11
  259. package/dist/api/controllers/public/mapping/queries.js +0 -36
  260. package/dist/api/controllers/public/mapping/rows.js +0 -24
  261. package/dist/api/controllers/public/mapping/tables.js +0 -23
  262. package/dist/api/controllers/public/mapping/types.js +0 -2
  263. package/dist/api/controllers/public/mapping/users.js +0 -29
  264. package/dist/api/controllers/public/queries.js +0 -38
  265. package/dist/api/controllers/public/rows.js +0 -97
  266. package/dist/api/controllers/public/tables.js +0 -75
  267. package/dist/api/controllers/public/users.js +0 -95
  268. package/dist/api/controllers/public/utils.js +0 -49
  269. package/dist/api/routes/public/applications.js +0 -141
  270. package/dist/api/routes/public/index.js +0 -101
  271. package/dist/api/routes/public/middleware/mapper.js +0 -94
  272. package/dist/api/routes/public/queries.js +0 -77
  273. package/dist/api/routes/public/rows.js +0 -229
  274. package/dist/api/routes/public/tables.js +0 -154
  275. package/dist/api/routes/public/users.js +0 -137
  276. package/dist/api/routes/public/utils/Endpoint.js +0 -36
  277. package/dist/api/routes/utils/validators.js +0 -200
  278. package/dist/definitions/openapi.js +0 -6
  279. package/specs/generate.js +0 -94
  280. package/specs/openapi.json +0 -2232
  281. package/specs/openapi.yaml +0 -1538
  282. package/specs/parameters.js +0 -59
  283. package/specs/resources/application.js +0 -101
  284. package/specs/resources/index.js +0 -24
  285. package/specs/resources/misc.js +0 -12
  286. package/specs/resources/query.js +0 -189
  287. package/specs/resources/row.js +0 -125
  288. package/specs/resources/table.js +0 -191
  289. package/specs/resources/user.js +0 -126
  290. package/specs/resources/utils/Resource.js +0 -26
  291. package/specs/resources/utils/index.js +0 -11
  292. package/specs/security.js +0 -7
  293. package/src/api/controllers/public/applications.ts +0 -74
  294. package/src/api/controllers/public/mapping/applications.ts +0 -32
  295. package/src/api/controllers/public/mapping/index.ts +0 -13
  296. package/src/api/controllers/public/mapping/queries.ts +0 -39
  297. package/src/api/controllers/public/mapping/rows.ts +0 -31
  298. package/src/api/controllers/public/mapping/tables.ts +0 -26
  299. package/src/api/controllers/public/mapping/types.ts +0 -13
  300. package/src/api/controllers/public/mapping/users.ts +0 -32
  301. package/src/api/controllers/public/queries.ts +0 -20
  302. package/src/api/controllers/public/rows.ts +0 -77
  303. package/src/api/controllers/public/tables.ts +0 -56
  304. package/src/api/controllers/public/users.ts +0 -82
  305. package/src/api/controllers/public/utils.ts +0 -38
  306. package/src/api/routes/public/applications.ts +0 -156
  307. package/src/api/routes/public/index.ts +0 -118
  308. package/src/api/routes/public/middleware/mapper.ts +0 -81
  309. package/src/api/routes/public/queries.ts +0 -81
  310. package/src/api/routes/public/rows.ts +0 -242
  311. package/src/api/routes/public/tables.ts +0 -169
  312. package/src/api/routes/public/tests/compare.spec.js +0 -184
  313. package/src/api/routes/public/users.ts +0 -144
  314. package/src/api/routes/public/utils/Endpoint.ts +0 -51
  315. package/src/api/routes/utils/validators.js +0 -219
  316. package/src/definitions/openapi.ts +0 -943
@@ -36,31 +36,10 @@ function request(ctx, request) {
36
36
  delete request.body;
37
37
  }
38
38
  if (ctx && ctx.headers) {
39
- request.headers = ctx.headers;
39
+ request.headers.cookie = ctx.headers.cookie;
40
40
  }
41
41
  return request;
42
42
  }
43
- function checkResponse(response, errorMsg, { ctx } = {}) {
44
- return __awaiter(this, void 0, void 0, function* () {
45
- if (response.status !== 200) {
46
- let error;
47
- try {
48
- error = yield response.json();
49
- }
50
- catch (err) {
51
- error = yield response.text();
52
- }
53
- const msg = `Unable to ${errorMsg} - ${error.message ? error.message : error}`;
54
- if (ctx) {
55
- ctx.throw(400, msg);
56
- }
57
- else {
58
- throw msg;
59
- }
60
- }
61
- return response.json();
62
- });
63
- }
64
43
  exports.request = request;
65
44
  // have to pass in the tenant ID as this could be coming from an automation
66
45
  exports.sendSmtpEmail = (to, from, subject, contents, automation) => __awaiter(void 0, void 0, void 0, function* () {
@@ -76,14 +55,21 @@ exports.sendSmtpEmail = (to, from, subject, contents, automation) => __awaiter(v
76
55
  automation,
77
56
  },
78
57
  }));
79
- return checkResponse(response, "send email");
58
+ if (response.status !== 200) {
59
+ const error = yield response.text();
60
+ throw `Unable to send email - ${error}`;
61
+ }
62
+ return response.json();
80
63
  });
81
64
  exports.getGlobalSelf = (ctx, appId = null) => __awaiter(void 0, void 0, void 0, function* () {
82
- const endpoint = `/api/global/self`;
65
+ const endpoint = `/api/global/users/self`;
83
66
  const response = yield fetch(checkSlashesInUrl(env.WORKER_URL + endpoint),
84
67
  // we don't want to use API key when getting self
85
68
  request(ctx, { method: "GET" }));
86
- let json = yield checkResponse(response, "get self globally", { ctx });
69
+ if (response.status !== 200) {
70
+ ctx.throw(400, "Unable to get self globally.");
71
+ }
72
+ let json = yield response.json();
87
73
  if (appId) {
88
74
  json = updateAppRole(json);
89
75
  }
@@ -94,29 +80,8 @@ exports.removeAppFromUserRoles = (ctx, appId) => __awaiter(void 0, void 0, void
94
80
  const response = yield fetch(checkSlashesInUrl(env.WORKER_URL + `/api/global/roles/${prodAppId}`), request(ctx, {
95
81
  method: "DELETE",
96
82
  }));
97
- return checkResponse(response, "remove app role");
98
- });
99
- exports.allGlobalUsers = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
100
- const response = yield fetch(checkSlashesInUrl(env.WORKER_URL + "/api/global/users"),
101
- // we don't want to use API key when getting self
102
- request(ctx, { method: "GET" }));
103
- return checkResponse(response, "get users", { ctx });
104
- });
105
- exports.saveGlobalUser = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
106
- const response = yield fetch(checkSlashesInUrl(env.WORKER_URL + "/api/global/users"),
107
- // we don't want to use API key when getting self
108
- request(ctx, { method: "POST", body: ctx.request.body }));
109
- return checkResponse(response, "save user", { ctx });
110
- });
111
- exports.deleteGlobalUser = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
112
- const response = yield fetch(checkSlashesInUrl(env.WORKER_URL + `/api/global/users/${ctx.params.userId}`),
113
- // we don't want to use API key when getting self
114
- request(ctx, { method: "DELETE" }));
115
- return checkResponse(response, "delete user", { ctx, body: ctx.request.body });
116
- });
117
- exports.readGlobalUser = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
118
- const response = yield fetch(checkSlashesInUrl(env.WORKER_URL + `/api/global/users/${ctx.params.userId}`),
119
- // we don't want to use API key when getting self
120
- request(ctx, { method: "GET" }));
121
- return checkResponse(response, "get user", { ctx });
83
+ if (response.status !== 200) {
84
+ throw "Unable to remove app role";
85
+ }
86
+ return response.json();
122
87
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@budibase/server",
3
3
  "email": "hi@budibase.com",
4
- "version": "1.0.80-alpha.3",
4
+ "version": "1.0.80",
5
5
  "description": "Budibase Web Server",
6
6
  "main": "src/index.ts",
7
7
  "repository": {
@@ -21,8 +21,10 @@
21
21
  "dev:stack:down": "node scripts/dev/manage.js down",
22
22
  "dev:stack:nuke": "node scripts/dev/manage.js nuke",
23
23
  "dev:builder": "yarn run dev:stack:up && nodemon",
24
+ "generate:proxy:compose": "node scripts/proxy/generateProxyConfig compose",
25
+ "generate:proxy:preprod": "node scripts/proxy/generateProxyConfig preprod",
26
+ "generate:proxy:prod": "node scripts/proxy/generateProxyConfig prod",
24
27
  "format": "prettier --config ../../.prettierrc.json 'src/**/*.ts' --write",
25
- "specs": "node specs/generate.js && openapi-typescript specs/openapi.yaml --output src/definitions/openapi.ts",
26
28
  "lint": "eslint --fix src/",
27
29
  "lint:fix": "yarn run format && yarn run lint",
28
30
  "initialise": "node scripts/initialise.js",
@@ -71,9 +73,9 @@
71
73
  "license": "GPL-3.0",
72
74
  "dependencies": {
73
75
  "@apidevtools/swagger-parser": "^10.0.3",
74
- "@budibase/backend-core": "^1.0.80-alpha.3",
75
- "@budibase/client": "^1.0.80-alpha.3",
76
- "@budibase/string-templates": "^1.0.80-alpha.3",
76
+ "@budibase/backend-core": "^1.0.80",
77
+ "@budibase/client": "^1.0.80",
78
+ "@budibase/string-templates": "^1.0.80",
77
79
  "@bull-board/api": "^3.7.0",
78
80
  "@bull-board/koa": "^3.7.0",
79
81
  "@elastic/elasticsearch": "7.10.0",
@@ -108,7 +110,6 @@
108
110
  "koa-send": "5.0.0",
109
111
  "koa-session": "5.12.0",
110
112
  "koa-static": "5.0.0",
111
- "koa2-ratelimit": "^1.1.0",
112
113
  "lodash": "4.17.21",
113
114
  "memorystream": "^0.3.1",
114
115
  "mongodb": "3.6.3",
@@ -124,7 +125,6 @@
124
125
  "pouchdb-all-dbs": "1.0.2",
125
126
  "pouchdb-find": "^7.2.2",
126
127
  "pouchdb-replication-stream": "1.2.9",
127
- "redis": "4",
128
128
  "server-destroy": "1.0.1",
129
129
  "svelte": "^3.38.2",
130
130
  "swagger-parser": "^10.0.3",
@@ -150,7 +150,6 @@
150
150
  "@types/koa-router": "^7.4.2",
151
151
  "@types/node": "^15.12.4",
152
152
  "@types/oracledb": "^5.2.1",
153
- "@types/redis": "^4.0.11",
154
153
  "@typescript-eslint/parser": "4.28.0",
155
154
  "apidoc": "^0.50.2",
156
155
  "babel-jest": "^27.0.2",
@@ -158,15 +157,12 @@
158
157
  "docker-compose": "^0.23.6",
159
158
  "eslint": "^6.8.0",
160
159
  "jest": "^27.0.5",
161
- "jest-openapi": "^0.14.2",
162
160
  "nodemon": "^2.0.4",
163
161
  "openapi-types": "^9.3.1",
164
- "openapi-typescript": "^5.2.0",
165
162
  "path-to-regexp": "^6.2.0",
166
163
  "prettier": "^2.3.1",
167
164
  "rimraf": "^3.0.2",
168
165
  "supertest": "^4.0.2",
169
- "swagger-jsdoc": "^6.1.0",
170
166
  "ts-jest": "^27.0.3",
171
167
  "ts-node": "^10.0.0",
172
168
  "typescript": "^4.3.5",
@@ -175,5 +171,5 @@
175
171
  "optionalDependencies": {
176
172
  "oracledb": "^5.3.0"
177
173
  },
178
- "gitHead": "f7de7ed349ad3413966e5790a2801d1e7e306142"
174
+ "gitHead": "0295a18622fdb95e1d279a0d54962d9e2762bc75"
179
175
  }
@@ -1,10 +1,5 @@
1
1
  USE master;
2
-
3
- IF NOT EXISTS(SELECT 1 FROM sys.schemas WHERE name = 'Chains')
4
- BEGIN
5
- EXEC sys.sp_executesql N'CREATE SCHEMA Chains;'
6
- END
7
-
2
+
8
3
  IF OBJECT_ID ('dbo.products', 'U') IS NOT NULL
9
4
  DROP TABLE products;
10
5
  GO
@@ -66,15 +61,3 @@ VALUES ('Bob', '30'),
66
61
  ('Bobert', '99'),
67
62
  ('Jan', '22'),
68
63
  ('Megan', '11');
69
-
70
-
71
- IF OBJECT_ID ('Chains.sizes', 'U') IS NOT NULL
72
- DROP TABLE Chains.sizes;
73
- GO
74
- CREATE TABLE Chains.sizes
75
- (
76
- sizeid int IDENTITY(1, 1),
77
- name varchar(30),
78
- CONSTRAINT pk_size PRIMARY KEY NONCLUSTERED (sizeid)
79
- );
80
-
@@ -8,9 +8,9 @@
8
8
 
9
9
  To install oracle express edition simply run `docker-compose up`
10
10
 
11
- - A single instance pluggable database (PDB) will be created named `xepdb1`
11
+ - A single instance pluggable database (PDB) will be created named `xepdb`
12
12
  - The default password is configured in the compose file as `oracle`
13
- - The `system` and `pdbadmin` users share this password
13
+ - The `system`, `sys` and `pdbadmin` users all share this password
14
14
 
15
15
  ## Instant Client
16
16
 
@@ -1,14 +1,11 @@
1
1
  SELECT 'CREATE DATABASE main'
2
2
  WHERE NOT EXISTS (SELECT FROM pg_database WHERE datname = 'main')\gexec
3
- CREATE SCHEMA test;
4
- CREATE TYPE person_job AS ENUM ('qa', 'programmer', 'designer');
5
3
  CREATE TABLE Persons (
6
4
  PersonID SERIAL PRIMARY KEY,
7
5
  LastName varchar(255),
8
6
  FirstName varchar(255),
9
7
  Address varchar(255),
10
- City varchar(255) DEFAULT 'Belfast',
11
- Type person_job
8
+ City varchar(255) DEFAULT 'Belfast'
12
9
  );
13
10
  CREATE TABLE Tasks (
14
11
  TaskID SERIAL PRIMARY KEY,
@@ -38,12 +35,8 @@ CREATE TABLE Products_Tasks (
38
35
  REFERENCES Tasks(TaskID),
39
36
  PRIMARY KEY (ProductID, TaskID)
40
37
  );
41
- CREATE TABLE test.table1 (
42
- id SERIAL PRIMARY KEY,
43
- Name varchar(255)
44
- );
45
- INSERT INTO Persons (FirstName, LastName, Address, City, Type) VALUES ('Mike', 'Hughes', '123 Fake Street', 'Belfast', 'qa');
46
- INSERT INTO Persons (FirstName, LastName, Address, City, Type) VALUES ('John', 'Smith', '64 Updown Road', 'Dublin', 'programmer');
38
+ INSERT INTO Persons (FirstName, LastName, Address, City) VALUES ('Mike', 'Hughes', '123 Fake Street', 'Belfast');
39
+ INSERT INTO Persons (FirstName, LastName, Address, City) Values ('John', 'Smith', '64 Updown Road', 'Dublin');
47
40
  INSERT INTO Tasks (ExecutorID, QaID, TaskName, Completed) VALUES (1, 2, 'assembling', TRUE);
48
41
  INSERT INTO Tasks (ExecutorID, QaID, TaskName, Completed) VALUES (2, 1, 'processing', FALSE);
49
42
  INSERT INTO Products (ProductName) VALUES ('Computers');
@@ -53,4 +46,3 @@ INSERT INTO Products_Tasks (ProductID, TaskID) VALUES (1, 1);
53
46
  INSERT INTO Products_Tasks (ProductID, TaskID) VALUES (2, 1);
54
47
  INSERT INTO Products_Tasks (ProductID, TaskID) VALUES (3, 1);
55
48
  INSERT INTO Products_Tasks (ProductID, TaskID) VALUES (1, 2);
56
- INSERT INTO test.table1 (Name) VALUES ('Test');
@@ -2,13 +2,14 @@
2
2
  * This script just makes it easy to re-create *
3
3
  * a cypress like environment for testing the backend *
4
4
  ******************************************************/
5
- import path from "path"
5
+ const path = require("path")
6
6
  const tmpdir = path.join(require("os").tmpdir(), ".budibase")
7
7
 
8
- const SERVER_PORT = "4100"
9
- const WORKER_PORT = "4200"
8
+ const MAIN_PORT = "10001"
9
+ const WORKER_PORT = "10002"
10
10
 
11
11
  // @ts-ignore
12
+ process.env.PORT = MAIN_PORT
12
13
  process.env.BUDIBASE_API_KEY = "6BE826CB-6B30-4AEC-8777-2E90464633DE"
13
14
  process.env.NODE_ENV = "cypress"
14
15
  process.env.ENABLE_ANALYTICS = "false"
@@ -26,11 +27,7 @@ process.env.ALLOW_DEV_AUTOMATIONS = "1"
26
27
 
27
28
  // don't make this a variable or top level require
28
29
  // it will cause environment module to be loaded prematurely
29
-
30
- // override the port with the worker port temporarily
30
+ const server = require("../src/app")
31
31
  process.env.PORT = WORKER_PORT
32
32
  const worker = require("../../worker/src/index")
33
-
34
- // override the port with the server port
35
- process.env.PORT = SERVER_PORT
36
- const server = require("../src/app")
33
+ process.env.PORT = MAIN_PORT
@@ -0,0 +1,70 @@
1
+ #!/usr/bin/env node
2
+ const path = require("path")
3
+ const fs = require("fs")
4
+ const { processStringSync } = require("@budibase/string-templates")
5
+
6
+ const Configs = {
7
+ prod: {
8
+ k8s: true,
9
+ apps: "app-service.budibase.svc.cluster.local",
10
+ worker: "worker-service.budibase.svc.cluster.local",
11
+ minio: "minio-service.budibase.svc.cluster.local",
12
+ couchdb: "budibase-prod-svc-couchdb",
13
+ },
14
+ preprod: {
15
+ k8s: true,
16
+ apps: "app-service.budibase.svc.cluster.local",
17
+ worker: "worker-service.budibase.svc.cluster.local",
18
+ minio: "minio-service.budibase.svc.cluster.local",
19
+ couchdb: "budibase-preprod-svc-couchdb",
20
+ },
21
+ compose: {
22
+ compose: true,
23
+ apps: "app-service",
24
+ worker: "worker-service",
25
+ minio: "minio-service",
26
+ couchdb: "couchdb-service",
27
+ watchtower: "watchtower-service",
28
+ },
29
+ }
30
+
31
+ const Commands = {
32
+ Prod: "prod",
33
+ Preprod: "preprod",
34
+ Compose: "compose",
35
+ }
36
+
37
+ async function init(managementCommand) {
38
+ const config = Configs[managementCommand]
39
+ const hostingPath = path.join(process.cwd(), "..", "..", "hosting")
40
+ const nginxHbsPath = path.join(hostingPath, "nginx.prod.conf.hbs")
41
+ const nginxOutputPath = path.join(
42
+ hostingPath,
43
+ "proxy",
44
+ ".generated-nginx.prod.conf"
45
+ )
46
+ const contents = fs.readFileSync(nginxHbsPath, "utf8")
47
+ fs.writeFileSync(nginxOutputPath, processStringSync(contents, config))
48
+ }
49
+
50
+ const managementCommand = process.argv.slice(2)[0]
51
+
52
+ if (
53
+ !managementCommand ||
54
+ !Object.values(Commands).some(command => managementCommand === command)
55
+ ) {
56
+ throw new Error(
57
+ "You must supply either a 'compose', 'preprod' or 'prod' commmand to generate an NGINX config."
58
+ )
59
+ }
60
+
61
+ init(managementCommand)
62
+ .then(() => {
63
+ console.log("Done! 🎉")
64
+ })
65
+ .catch(err => {
66
+ console.error(
67
+ "Something went wrong while creating the nginx configuration",
68
+ err.message
69
+ )
70
+ })
@@ -263,7 +263,6 @@ exports.create = async ctx => {
263
263
  tenantId: getTenantId(),
264
264
  updatedAt: new Date().toISOString(),
265
265
  createdAt: new Date().toISOString(),
266
- status: AppStatus.DEV,
267
266
  }
268
267
  const response = await db.put(newApplication, { force: true })
269
268
  newApplication._rev = response.rev
@@ -58,7 +58,7 @@ module External {
58
58
  ) {
59
59
  const primary = table.primary
60
60
  // if passed in array need to copy for shifting etc
61
- let idCopy: undefined | string | any[] = cloneDeep(id)
61
+ let idCopy = cloneDeep(id)
62
62
  if (filters) {
63
63
  // need to map over the filters and make sure the _id field isn't present
64
64
  for (let filter of Object.values(filters)) {
@@ -2,7 +2,6 @@ const linkRows = require("../../../db/linkedRows")
2
2
  const {
3
3
  generateRowID,
4
4
  getRowParams,
5
- getTableIDFromRowID,
6
5
  DocumentTypes,
7
6
  InternalTables,
8
7
  } = require("../../../db/utils")
@@ -387,9 +386,6 @@ exports.fetchEnrichedRow = async ctx => {
387
386
  let groups = {},
388
387
  tables = {}
389
388
  for (let row of response) {
390
- if (!row.tableId) {
391
- row.tableId = getTableIDFromRowID(row._id)
392
- }
393
389
  const linkedTableId = row.tableId
394
390
  if (groups[linkedTableId] == null) {
395
391
  groups[linkedTableId] = [row]
@@ -48,7 +48,7 @@ exports.fetch = async function (ctx) {
48
48
  }
49
49
 
50
50
  exports.find = async function (ctx) {
51
- const tableId = ctx.params.tableId
51
+ const tableId = ctx.params.id
52
52
  ctx.body = await getTable(tableId)
53
53
  }
54
54
 
@@ -70,7 +70,6 @@ exports.destroy = async function (ctx) {
70
70
  ctx.eventEmitter &&
71
71
  ctx.eventEmitter.emitTable(`table:delete`, appId, deletedTable)
72
72
  ctx.status = 200
73
- ctx.table = deletedTable
74
73
  ctx.body = { message: `Table ${tableId} deleted.` }
75
74
  }
76
75
 
@@ -1,7 +1,6 @@
1
1
  const { generateWebhookID, getWebhookParams } = require("../../db/utils")
2
2
  const toJsonSchema = require("to-json-schema")
3
3
  const validate = require("jsonschema").validate
4
- const { WebhookType } = require("../../constants")
5
4
  const triggers = require("../../automations/triggers")
6
5
  const { getProdAppID } = require("@budibase/backend-core/db")
7
6
  const { getAppDB, updateAppId } = require("@budibase/backend-core/context")
@@ -19,6 +18,10 @@ function Webhook(name, type, target) {
19
18
 
20
19
  exports.Webhook = Webhook
21
20
 
21
+ exports.WebhookType = {
22
+ AUTOMATION: "automation",
23
+ }
24
+
22
25
  exports.fetch = async ctx => {
23
26
  const db = getAppDB()
24
27
  const response = await db.allDocs(
@@ -59,7 +62,7 @@ exports.buildSchema = async ctx => {
59
62
  const webhook = await db.get(ctx.params.id)
60
63
  webhook.bodySchema = toJsonSchema(ctx.request.body)
61
64
  // update the automation outputs
62
- if (webhook.action.type === WebhookType.AUTOMATION) {
65
+ if (webhook.action.type === exports.WebhookType.AUTOMATION) {
63
66
  let automation = await db.get(webhook.action.target)
64
67
  const autoOutputs = automation.definition.trigger.schema.outputs
65
68
  let properties = webhook.bodySchema.properties
@@ -89,7 +92,7 @@ exports.trigger = async ctx => {
89
92
  validate(ctx.request.body, webhook.bodySchema)
90
93
  }
91
94
  const target = await db.get(webhook.action.target)
92
- if (webhook.action.type === WebhookType.AUTOMATION) {
95
+ if (webhook.action.type === exports.WebhookType.AUTOMATION) {
93
96
  // trigger with both the pure request and then expand it
94
97
  // incase the user has produced a schema to bind to
95
98
  await triggers.externalTrigger(target, {
package/src/api/index.js CHANGED
@@ -8,7 +8,7 @@ const {
8
8
  const currentApp = require("../middleware/currentapp")
9
9
  const compress = require("koa-compress")
10
10
  const zlib = require("zlib")
11
- const { mainRoutes, staticRoutes, publicRoutes } = require("./routes")
11
+ const { mainRoutes, staticRoutes } = require("./routes")
12
12
  const pkg = require("../../package.json")
13
13
  const env = require("../environment")
14
14
 
@@ -82,9 +82,6 @@ for (let route of mainRoutes) {
82
82
  router.use(route.allowedMethods())
83
83
  }
84
84
 
85
- router.use(publicRoutes.routes())
86
- router.use(publicRoutes.allowedMethods())
87
-
88
85
  // WARNING - static routes will catch everything else after them this must be last
89
86
  router.use(staticRoutes.routes())
90
87
  router.use(staticRoutes.allowedMethods())
@@ -1,20 +1,50 @@
1
1
  const Router = require("@koa/router")
2
2
  const controller = require("../controllers/automation")
3
3
  const authorized = require("../../middleware/authorized")
4
+ const joiValidator = require("../../middleware/joi-validator")
4
5
  const {
5
6
  BUILDER,
6
7
  PermissionLevels,
7
8
  PermissionTypes,
8
9
  } = require("@budibase/backend-core/permissions")
10
+ const Joi = require("joi")
9
11
  const { bodyResource, paramResource } = require("../../middleware/resourceId")
10
12
  const {
11
13
  middleware: appInfoMiddleware,
12
14
  AppType,
13
15
  } = require("../../middleware/appInfo")
14
- const { automationValidator } = require("./utils/validators")
15
16
 
16
17
  const router = Router()
17
18
 
19
+ // prettier-ignore
20
+ function generateStepSchema(allowStepTypes) {
21
+ return Joi.object({
22
+ stepId: Joi.string().required(),
23
+ id: Joi.string().required(),
24
+ description: Joi.string().required(),
25
+ name: Joi.string().required(),
26
+ tagline: Joi.string().required(),
27
+ icon: Joi.string().required(),
28
+ params: Joi.object(),
29
+ args: Joi.object(),
30
+ type: Joi.string().required().valid(...allowStepTypes),
31
+ }).unknown(true)
32
+ }
33
+
34
+ function generateValidator(existing = false) {
35
+ // prettier-ignore
36
+ return joiValidator.body(Joi.object({
37
+ _id: existing ? Joi.string().required() : Joi.string(),
38
+ _rev: existing ? Joi.string().required() : Joi.string(),
39
+ name: Joi.string().required(),
40
+ type: Joi.string().valid("automation").required(),
41
+ definition: Joi.object({
42
+ steps: Joi.array().required().items(generateStepSchema(["ACTION", "LOGIC"])),
43
+ trigger: generateStepSchema(["TRIGGER"]).allow(null),
44
+ }).required().unknown(true),
45
+ }).unknown(true))
46
+ }
47
+
18
48
  router
19
49
  .get(
20
50
  "/api/automations/trigger/list",
@@ -42,13 +72,13 @@ router
42
72
  "/api/automations",
43
73
  bodyResource("_id"),
44
74
  authorized(BUILDER),
45
- automationValidator(true),
75
+ generateValidator(true),
46
76
  controller.update
47
77
  )
48
78
  .post(
49
79
  "/api/automations",
50
80
  authorized(BUILDER),
51
- automationValidator(false),
81
+ generateValidator(false),
52
82
  controller.create
53
83
  )
54
84
  .delete(
@@ -1,18 +1,64 @@
1
1
  const Router = require("@koa/router")
2
2
  const datasourceController = require("../controllers/datasource")
3
3
  const authorized = require("../../middleware/authorized")
4
+ const joiValidator = require("../../middleware/joi-validator")
4
5
  const {
5
6
  BUILDER,
6
7
  PermissionLevels,
7
8
  PermissionTypes,
8
9
  } = require("@budibase/backend-core/permissions")
9
- const {
10
- datasourceValidator,
11
- datasourceQueryValidator,
12
- } = require("./utils/validators")
10
+ const Joi = require("joi")
11
+ const { DataSourceOperation } = require("../../constants")
13
12
 
14
13
  const router = Router()
15
14
 
15
+ function generateDatasourceSchema() {
16
+ // prettier-ignore
17
+ return joiValidator.body(Joi.object({
18
+ _id: Joi.string(),
19
+ _rev: Joi.string(),
20
+ // source: Joi.string().valid("POSTGRES_PLUS"),
21
+ type: Joi.string().allow("datasource_plus"),
22
+ relationships: Joi.array().items(Joi.object({
23
+ from: Joi.string().required(),
24
+ to: Joi.string().required(),
25
+ cardinality: Joi.valid("1:N", "1:1", "N:N").required()
26
+ })),
27
+ // entities: Joi.array().items(Joi.object({
28
+ // type: Joi.string().valid(...Object.values(FieldTypes)).required(),
29
+ // name: Joi.string().required(),
30
+ // })),
31
+ }).unknown(true))
32
+ }
33
+
34
+ function generateQueryDatasourceSchema() {
35
+ // prettier-ignore
36
+ return joiValidator.body(Joi.object({
37
+ endpoint: Joi.object({
38
+ datasourceId: Joi.string().required(),
39
+ operation: Joi.string().required().valid(...Object.values(DataSourceOperation)),
40
+ entityId: Joi.string().required(),
41
+ }).required(),
42
+ resource: Joi.object({
43
+ fields: Joi.array().items(Joi.string()).optional(),
44
+ }).optional(),
45
+ body: Joi.object().optional(),
46
+ sort: Joi.object().optional(),
47
+ filters: Joi.object({
48
+ string: Joi.object().optional(),
49
+ range: Joi.object().optional(),
50
+ equal: Joi.object().optional(),
51
+ notEqual: Joi.object().optional(),
52
+ empty: Joi.object().optional(),
53
+ notEmpty: Joi.object().optional(),
54
+ }).optional(),
55
+ paginate: Joi.object({
56
+ page: Joi.string().alphanum().optional(),
57
+ limit: Joi.number().optional(),
58
+ }).optional(),
59
+ }))
60
+ }
61
+
16
62
  router
17
63
  .get("/api/datasources", authorized(BUILDER), datasourceController.fetch)
18
64
  .get(
@@ -28,7 +74,7 @@ router
28
74
  .post(
29
75
  "/api/datasources/query",
30
76
  authorized(PermissionTypes.TABLE, PermissionLevels.READ),
31
- datasourceQueryValidator(),
77
+ generateQueryDatasourceSchema(),
32
78
  datasourceController.query
33
79
  )
34
80
  .post(
@@ -39,7 +85,7 @@ router
39
85
  .post(
40
86
  "/api/datasources",
41
87
  authorized(BUILDER),
42
- datasourceValidator(),
88
+ generateDatasourceSchema(),
43
89
  datasourceController.save
44
90
  )
45
91
  .delete(
@@ -25,7 +25,6 @@ const metadataRoutes = require("./metadata")
25
25
  const devRoutes = require("./dev")
26
26
  const cloudRoutes = require("./cloud")
27
27
  const migrationRoutes = require("./migrations")
28
- const publicRoutes = require("./public")
29
28
 
30
29
  exports.mainRoutes = [
31
30
  authRoutes,
@@ -58,5 +57,4 @@ exports.mainRoutes = [
58
57
  migrationRoutes,
59
58
  ]
60
59
 
61
- exports.publicRoutes = publicRoutes
62
60
  exports.staticRoutes = staticRoutes
@@ -1,11 +1,25 @@
1
1
  const Router = require("@koa/router")
2
2
  const controller = require("../controllers/permission")
3
3
  const authorized = require("../../middleware/authorized")
4
- const { BUILDER } = require("@budibase/backend-core/permissions")
5
- const { permissionValidator } = require("./utils/validators")
4
+ const {
5
+ BUILDER,
6
+ PermissionLevels,
7
+ } = require("@budibase/backend-core/permissions")
8
+ const Joi = require("joi")
9
+ const joiValidator = require("../../middleware/joi-validator")
6
10
 
7
11
  const router = Router()
8
12
 
13
+ function generateValidator() {
14
+ const permLevelArray = Object.values(PermissionLevels)
15
+ // prettier-ignore
16
+ return joiValidator.params(Joi.object({
17
+ level: Joi.string().valid(...permLevelArray).required(),
18
+ resourceId: Joi.string(),
19
+ roleId: Joi.string(),
20
+ }).unknown(true))
21
+ }
22
+
9
23
  router
10
24
  .get("/api/permission/builtin", authorized(BUILDER), controller.fetchBuiltin)
11
25
  .get("/api/permission/levels", authorized(BUILDER), controller.fetchLevels)
@@ -19,14 +33,14 @@ router
19
33
  .post(
20
34
  "/api/permission/:roleId/:resourceId/:level",
21
35
  authorized(BUILDER),
22
- permissionValidator(),
36
+ generateValidator(),
23
37
  controller.addPermission
24
38
  )
25
39
  // deleting the level defaults it back the underlying access control for the resource
26
40
  .delete(
27
41
  "/api/permission/:roleId/:resourceId/:level",
28
42
  authorized(BUILDER),
29
- permissionValidator(),
43
+ generateValidator(),
30
44
  controller.removePermission
31
45
  )
32
46