@budibase/server 1.0.79-alpha.7 → 1.0.79

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 (296) hide show
  1. package/__mocks__/mysql2/promise.ts +17 -0
  2. package/__mocks__/node-fetch.ts +0 -1
  3. package/builder/assets/{index.c57242d4.css → index.c8d1e8f0.css} +2 -2
  4. package/builder/assets/index.f28c5d54.js +1352 -0
  5. package/builder/assets/{vendor.6b00a24f.js → vendor.20f80cec.js} +216 -190
  6. package/builder/index.html +3 -3
  7. package/coverage/clover.xml +2229 -2277
  8. package/coverage/coverage-final.json +136 -137
  9. package/coverage/lcov-report/api/controllers/analytics.js.html +6 -6
  10. package/coverage/lcov-report/api/controllers/apikeys.js.html +6 -6
  11. package/coverage/lcov-report/api/controllers/application.js.html +149 -152
  12. package/coverage/lcov-report/api/controllers/auth.js.html +7 -7
  13. package/coverage/lcov-report/api/controllers/automation.js.html +21 -21
  14. package/coverage/lcov-report/api/controllers/backup.js.html +3 -3
  15. package/coverage/lcov-report/api/controllers/cloud.js.html +11 -11
  16. package/coverage/lcov-report/api/controllers/component.js.html +5 -5
  17. package/coverage/lcov-report/api/controllers/datasource.js.html +16 -16
  18. package/coverage/lcov-report/api/controllers/dev.js.html +19 -19
  19. package/coverage/lcov-report/api/controllers/index.html +16 -16
  20. package/coverage/lcov-report/api/controllers/integration.js.html +4 -4
  21. package/coverage/lcov-report/api/controllers/layout.js.html +6 -6
  22. package/coverage/lcov-report/api/controllers/metadata.js.html +9 -9
  23. package/coverage/lcov-report/api/controllers/migrations.js.html +4 -4
  24. package/coverage/lcov-report/api/controllers/permission.js.html +15 -15
  25. package/coverage/lcov-report/api/controllers/query/index.html +1 -1
  26. package/coverage/lcov-report/api/controllers/query/index.js.html +26 -26
  27. package/coverage/lcov-report/api/controllers/query/validation.js.html +10 -10
  28. package/coverage/lcov-report/api/controllers/role.js.html +9 -9
  29. package/coverage/lcov-report/api/controllers/routing.js.html +9 -9
  30. package/coverage/lcov-report/api/controllers/row/external.js.html +16 -16
  31. package/coverage/lcov-report/api/controllers/row/index.html +27 -27
  32. package/coverage/lcov-report/api/controllers/row/index.js.html +46 -46
  33. package/coverage/lcov-report/api/controllers/row/internal.js.html +82 -94
  34. package/coverage/lcov-report/api/controllers/row/internalSearch.js.html +204 -204
  35. package/coverage/lcov-report/api/controllers/row/staticFormula.js.html +24 -24
  36. package/coverage/lcov-report/api/controllers/row/utils.js.html +29 -29
  37. package/coverage/lcov-report/api/controllers/screen.js.html +7 -7
  38. package/coverage/lcov-report/api/controllers/script.js.html +4 -4
  39. package/coverage/lcov-report/api/controllers/table/bulkFormula.js.html +49 -49
  40. package/coverage/lcov-report/api/controllers/table/external.js.html +12 -12
  41. package/coverage/lcov-report/api/controllers/table/index.html +11 -11
  42. package/coverage/lcov-report/api/controllers/table/index.js.html +44 -47
  43. package/coverage/lcov-report/api/controllers/table/internal.js.html +50 -50
  44. package/coverage/lcov-report/api/controllers/table/utils.js.html +80 -80
  45. package/coverage/lcov-report/api/controllers/templates.js.html +5 -5
  46. package/coverage/lcov-report/api/controllers/user.js.html +19 -19
  47. package/coverage/lcov-report/api/controllers/view/exporters.js.html +4 -4
  48. package/coverage/lcov-report/api/controllers/view/index.html +1 -1
  49. package/coverage/lcov-report/api/controllers/view/index.js.html +14 -14
  50. package/coverage/lcov-report/api/controllers/view/utils.js.html +12 -12
  51. package/coverage/lcov-report/api/controllers/view/viewBuilder.js.html +7 -7
  52. package/coverage/lcov-report/api/controllers/webhook.js.html +27 -18
  53. package/coverage/lcov-report/api/index.html +10 -10
  54. package/coverage/lcov-report/api/index.js.html +28 -37
  55. package/coverage/lcov-report/api/routes/analytics.js.html +6 -6
  56. package/coverage/lcov-report/api/routes/apikeys.js.html +8 -8
  57. package/coverage/lcov-report/api/routes/application.js.html +9 -9
  58. package/coverage/lcov-report/api/routes/auth.js.html +6 -6
  59. package/coverage/lcov-report/api/routes/automation.js.html +109 -19
  60. package/coverage/lcov-report/api/routes/backup.js.html +8 -8
  61. package/coverage/lcov-report/api/routes/cloud.js.html +8 -8
  62. package/coverage/lcov-report/api/routes/component.js.html +8 -8
  63. package/coverage/lcov-report/api/routes/datasource.js.html +156 -18
  64. package/coverage/lcov-report/api/routes/deploy.js.html +8 -8
  65. package/coverage/lcov-report/api/routes/dev.js.html +13 -13
  66. package/coverage/lcov-report/api/routes/index.html +35 -35
  67. package/coverage/lcov-report/api/routes/index.js.html +32 -38
  68. package/coverage/lcov-report/api/routes/integration.js.html +8 -8
  69. package/coverage/lcov-report/api/routes/layout.js.html +8 -8
  70. package/coverage/lcov-report/api/routes/metadata.js.html +9 -9
  71. package/coverage/lcov-report/api/routes/migrations.js.html +7 -7
  72. package/coverage/lcov-report/api/routes/permission.js.html +58 -16
  73. package/coverage/lcov-report/api/routes/query.js.html +10 -10
  74. package/coverage/lcov-report/api/routes/role.js.html +78 -15
  75. package/coverage/lcov-report/api/routes/routing.js.html +8 -8
  76. package/coverage/lcov-report/api/routes/row.js.html +14 -17
  77. package/coverage/lcov-report/api/routes/screen.js.html +95 -14
  78. package/coverage/lcov-report/api/routes/script.js.html +1 -1
  79. package/coverage/lcov-report/api/routes/static.js.html +13 -13
  80. package/coverage/lcov-report/api/routes/table.js.html +62 -17
  81. package/coverage/lcov-report/api/routes/templates.js.html +8 -8
  82. package/coverage/lcov-report/api/routes/user.js.html +8 -8
  83. package/coverage/lcov-report/api/routes/view.js.html +10 -10
  84. package/coverage/lcov-report/api/routes/webhook.js.html +62 -14
  85. package/coverage/lcov-report/automations/actions.js.html +24 -24
  86. package/coverage/lcov-report/automations/automationUtils.js.html +5 -5
  87. package/coverage/lcov-report/automations/bullboard.js.html +16 -16
  88. package/coverage/lcov-report/automations/index.html +1 -1
  89. package/coverage/lcov-report/automations/index.js.html +7 -7
  90. package/coverage/lcov-report/automations/steps/bash.js.html +6 -6
  91. package/coverage/lcov-report/automations/steps/createRow.js.html +7 -7
  92. package/coverage/lcov-report/automations/steps/delay.js.html +4 -4
  93. package/coverage/lcov-report/automations/steps/deleteRow.js.html +7 -7
  94. package/coverage/lcov-report/automations/steps/discord.js.html +7 -7
  95. package/coverage/lcov-report/automations/steps/executeQuery.js.html +6 -6
  96. package/coverage/lcov-report/automations/steps/executeScript.js.html +6 -6
  97. package/coverage/lcov-report/automations/steps/filter.js.html +9 -12
  98. package/coverage/lcov-report/automations/steps/index.html +1 -1
  99. package/coverage/lcov-report/automations/steps/integromat.js.html +5 -5
  100. package/coverage/lcov-report/automations/steps/outgoingWebhook.js.html +8 -8
  101. package/coverage/lcov-report/automations/steps/queryRows.js.html +11 -11
  102. package/coverage/lcov-report/automations/steps/sendSmtpEmail.js.html +5 -5
  103. package/coverage/lcov-report/automations/steps/serverLog.js.html +3 -3
  104. package/coverage/lcov-report/automations/steps/slack.js.html +5 -5
  105. package/coverage/lcov-report/automations/steps/updateRow.js.html +6 -6
  106. package/coverage/lcov-report/automations/steps/utils.js.html +3 -3
  107. package/coverage/lcov-report/automations/steps/zapier.js.html +5 -5
  108. package/coverage/lcov-report/automations/triggerInfo/app.js.html +2 -2
  109. package/coverage/lcov-report/automations/triggerInfo/cron.js.html +2 -2
  110. package/coverage/lcov-report/automations/triggerInfo/index.html +1 -1
  111. package/coverage/lcov-report/automations/triggerInfo/index.js.html +8 -8
  112. package/coverage/lcov-report/automations/triggerInfo/rowDeleted.js.html +2 -2
  113. package/coverage/lcov-report/automations/triggerInfo/rowSaved.js.html +2 -2
  114. package/coverage/lcov-report/automations/triggerInfo/rowUpdated.js.html +2 -2
  115. package/coverage/lcov-report/automations/triggerInfo/webhook.js.html +2 -2
  116. package/coverage/lcov-report/automations/triggers.js.html +26 -26
  117. package/coverage/lcov-report/automations/utils.js.html +35 -35
  118. package/coverage/lcov-report/constants/index.html +5 -5
  119. package/coverage/lcov-report/constants/index.js.html +28 -40
  120. package/coverage/lcov-report/constants/layouts.js.html +5 -5
  121. package/coverage/lcov-report/constants/screens.js.html +4 -4
  122. package/coverage/lcov-report/db/client.js.html +18 -18
  123. package/coverage/lcov-report/db/inMemoryView.js.html +7 -7
  124. package/coverage/lcov-report/db/index.html +15 -15
  125. package/coverage/lcov-report/db/index.js.html +3 -3
  126. package/coverage/lcov-report/db/linkedRows/LinkController.js.html +21 -21
  127. package/coverage/lcov-report/db/linkedRows/index.html +1 -1
  128. package/coverage/lcov-report/db/linkedRows/index.js.html +36 -36
  129. package/coverage/lcov-report/db/linkedRows/linkUtils.js.html +30 -30
  130. package/coverage/lcov-report/db/newid.js.html +4 -4
  131. package/coverage/lcov-report/db/utils.js.html +87 -123
  132. package/coverage/lcov-report/events/AutomationEmitter.js.html +1 -1
  133. package/coverage/lcov-report/events/index.html +1 -1
  134. package/coverage/lcov-report/events/index.js.html +8 -8
  135. package/coverage/lcov-report/events/utils.js.html +18 -18
  136. package/coverage/lcov-report/index.html +64 -79
  137. package/coverage/lcov-report/integrations/tests/TestConfiguration.js.html +1 -1
  138. package/coverage/lcov-report/integrations/tests/index.html +1 -1
  139. package/coverage/lcov-report/middleware/appInfo.js.html +5 -5
  140. package/coverage/lcov-report/middleware/authorized.js.html +29 -29
  141. package/coverage/lcov-report/middleware/builder.js.html +16 -16
  142. package/coverage/lcov-report/middleware/currentapp.js.html +44 -44
  143. package/coverage/lcov-report/middleware/index.html +1 -1
  144. package/coverage/lcov-report/middleware/joi-validator.js.html +14 -14
  145. package/coverage/lcov-report/middleware/resourceId.js.html +29 -29
  146. package/coverage/lcov-report/middleware/selfhost.js.html +1 -1
  147. package/coverage/lcov-report/middleware/usageQuota.js.html +17 -17
  148. package/coverage/lcov-report/middleware/utils.js.html +4 -4
  149. package/coverage/lcov-report/threads/automation.js.html +1 -1
  150. package/coverage/lcov-report/threads/index.html +1 -1
  151. package/coverage/lcov-report/threads/index.js.html +10 -10
  152. package/coverage/lcov-report/threads/query.js.html +1 -1
  153. package/coverage/lcov-report/threads/utils.js.html +14 -14
  154. package/coverage/lcov-report/utilities/bcrypt.js.html +1 -1
  155. package/coverage/lcov-report/utilities/budibaseDir.js.html +7 -7
  156. package/coverage/lcov-report/utilities/centralPath.js.html +4 -4
  157. package/coverage/lcov-report/utilities/csvParser.js.html +6 -6
  158. package/coverage/lcov-report/utilities/global.js.html +28 -28
  159. package/coverage/lcov-report/utilities/index.html +18 -18
  160. package/coverage/lcov-report/utilities/index.js.html +24 -24
  161. package/coverage/lcov-report/utilities/queue/inMemoryQueue.js.html +9 -9
  162. package/coverage/lcov-report/utilities/queue/index.html +1 -1
  163. package/coverage/lcov-report/utilities/routing/index.html +1 -1
  164. package/coverage/lcov-report/utilities/routing/index.js.html +6 -6
  165. package/coverage/lcov-report/utilities/rowProcessor/index.html +1 -1
  166. package/coverage/lcov-report/utilities/rowProcessor/index.js.html +60 -60
  167. package/coverage/lcov-report/utilities/rowProcessor/utils.js.html +13 -13
  168. package/coverage/lcov-report/utilities/scriptRunner.js.html +5 -5
  169. package/coverage/lcov-report/utilities/security.js.html +8 -8
  170. package/coverage/lcov-report/utilities/statusCodes.js.html +1 -1
  171. package/coverage/lcov-report/utilities/usageQuota/index.html +1 -1
  172. package/coverage/lcov-report/utilities/usageQuota/index.js.html +12 -12
  173. package/coverage/lcov-report/utilities/usageQuota/rows.js.html +8 -8
  174. package/coverage/lcov-report/utilities/usageQuota/usageQuoteReset.js.html +1 -1
  175. package/coverage/lcov-report/utilities/users.js.html +5 -5
  176. package/coverage/lcov-report/utilities/workerRequests.js.html +53 -200
  177. package/coverage/lcov.info +3039 -3115
  178. package/dist/api/controllers/application.js +0 -1
  179. package/dist/api/controllers/row/internal.js +1 -4
  180. package/dist/api/controllers/table/index.js +1 -2
  181. package/dist/api/controllers/webhook.js +5 -3
  182. package/dist/api/index.js +1 -3
  183. package/dist/api/routes/automation.js +31 -3
  184. package/dist/api/routes/datasource.js +50 -3
  185. package/dist/api/routes/index.js +0 -2
  186. package/dist/api/routes/permission.js +14 -4
  187. package/dist/api/routes/role.js +19 -3
  188. package/dist/api/routes/row.js +4 -3
  189. package/dist/api/routes/screen.js +23 -2
  190. package/dist/api/routes/table.js +17 -3
  191. package/dist/api/routes/tests/utilities/index.js +0 -23
  192. package/dist/api/routes/webhook.js +17 -2
  193. package/dist/automations/steps/filter.js +2 -2
  194. package/dist/automations/steps/queryRows.js +1 -1
  195. package/dist/automations/utils.js +2 -2
  196. package/dist/constants/index.js +0 -3
  197. package/dist/db/utils.js +0 -11
  198. package/dist/integrations/mysql.js +81 -65
  199. package/dist/integrations/utils.js +1 -1
  200. package/dist/package.json +4 -8
  201. package/dist/tests/utilities/TestConfiguration.js +8 -25
  202. package/dist/tsconfig.tsbuildinfo +1 -1
  203. package/dist/utilities/workerRequests.js +15 -50
  204. package/package.json +5 -9
  205. package/scripts/integrations/postgres/init.sql +3 -5
  206. package/scripts/likeCypress.ts +6 -9
  207. package/src/api/controllers/application.js +0 -1
  208. package/src/api/controllers/row/internal.js +0 -4
  209. package/src/api/controllers/table/index.js +1 -2
  210. package/src/api/controllers/webhook.js +6 -3
  211. package/src/api/index.js +1 -4
  212. package/src/api/routes/automation.js +33 -3
  213. package/src/api/routes/datasource.js +52 -6
  214. package/src/api/routes/index.js +0 -2
  215. package/src/api/routes/permission.js +18 -4
  216. package/src/api/routes/role.js +24 -3
  217. package/src/api/routes/row.js +2 -3
  218. package/src/api/routes/screen.js +29 -2
  219. package/src/api/routes/table.js +19 -4
  220. package/src/api/routes/tests/utilities/index.js +0 -24
  221. package/src/api/routes/webhook.js +18 -2
  222. package/src/automations/steps/filter.js +2 -3
  223. package/src/automations/steps/queryRows.js +1 -1
  224. package/src/automations/utils.js +2 -2
  225. package/src/constants/index.js +0 -4
  226. package/src/db/utils.js +0 -12
  227. package/src/definitions/common.ts +0 -4
  228. package/src/integrations/mysql.ts +92 -85
  229. package/src/integrations/tests/mysql.spec.js +4 -4
  230. package/src/integrations/utils.ts +1 -1
  231. package/src/tests/utilities/TestConfiguration.js +2 -23
  232. package/src/utilities/workerRequests.js +16 -65
  233. package/builder/assets/index.ef62c13b.js +0 -1288
  234. package/coverage/lcov-report/api/routes/utils/index.html +0 -111
  235. package/coverage/lcov-report/api/routes/utils/validators.js.html +0 -737
  236. package/dist/api/controllers/public/applications.js +0 -94
  237. package/dist/api/controllers/public/mapping/applications.js +0 -29
  238. package/dist/api/controllers/public/mapping/index.js +0 -11
  239. package/dist/api/controllers/public/mapping/queries.js +0 -36
  240. package/dist/api/controllers/public/mapping/rows.js +0 -24
  241. package/dist/api/controllers/public/mapping/tables.js +0 -23
  242. package/dist/api/controllers/public/mapping/types.js +0 -2
  243. package/dist/api/controllers/public/mapping/users.js +0 -29
  244. package/dist/api/controllers/public/queries.js +0 -38
  245. package/dist/api/controllers/public/rows.js +0 -97
  246. package/dist/api/controllers/public/tables.js +0 -75
  247. package/dist/api/controllers/public/users.js +0 -95
  248. package/dist/api/controllers/public/utils.js +0 -49
  249. package/dist/api/routes/public/applications.js +0 -141
  250. package/dist/api/routes/public/index.js +0 -68
  251. package/dist/api/routes/public/middleware/mapper.js +0 -94
  252. package/dist/api/routes/public/queries.js +0 -77
  253. package/dist/api/routes/public/rows.js +0 -229
  254. package/dist/api/routes/public/tables.js +0 -154
  255. package/dist/api/routes/public/users.js +0 -137
  256. package/dist/api/routes/public/utils/Endpoint.js +0 -36
  257. package/dist/api/routes/utils/validators.js +0 -200
  258. package/dist/definitions/openapi.js +0 -6
  259. package/specs/generate.js +0 -83
  260. package/specs/openapi.json +0 -2222
  261. package/specs/openapi.yaml +0 -1530
  262. package/specs/parameters.js +0 -59
  263. package/specs/resources/application.js +0 -101
  264. package/specs/resources/index.js +0 -24
  265. package/specs/resources/misc.js +0 -12
  266. package/specs/resources/query.js +0 -189
  267. package/specs/resources/row.js +0 -125
  268. package/specs/resources/table.js +0 -191
  269. package/specs/resources/user.js +0 -126
  270. package/specs/resources/utils/Resource.js +0 -26
  271. package/specs/resources/utils/index.js +0 -11
  272. package/specs/security.js +0 -7
  273. package/src/api/controllers/public/applications.ts +0 -74
  274. package/src/api/controllers/public/mapping/applications.ts +0 -32
  275. package/src/api/controllers/public/mapping/index.ts +0 -13
  276. package/src/api/controllers/public/mapping/queries.ts +0 -39
  277. package/src/api/controllers/public/mapping/rows.ts +0 -31
  278. package/src/api/controllers/public/mapping/tables.ts +0 -26
  279. package/src/api/controllers/public/mapping/types.ts +0 -13
  280. package/src/api/controllers/public/mapping/users.ts +0 -32
  281. package/src/api/controllers/public/queries.ts +0 -20
  282. package/src/api/controllers/public/rows.ts +0 -77
  283. package/src/api/controllers/public/tables.ts +0 -56
  284. package/src/api/controllers/public/users.ts +0 -82
  285. package/src/api/controllers/public/utils.ts +0 -38
  286. package/src/api/routes/public/applications.ts +0 -156
  287. package/src/api/routes/public/index.ts +0 -82
  288. package/src/api/routes/public/middleware/mapper.ts +0 -81
  289. package/src/api/routes/public/queries.ts +0 -81
  290. package/src/api/routes/public/rows.ts +0 -242
  291. package/src/api/routes/public/tables.ts +0 -169
  292. package/src/api/routes/public/tests/compare.spec.js +0 -184
  293. package/src/api/routes/public/users.ts +0 -144
  294. package/src/api/routes/public/utils/Endpoint.ts +0 -51
  295. package/src/api/routes/utils/validators.js +0 -219
  296. 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.79-alpha.7",
4
+ "version": "1.0.79",
5
5
  "description": "Budibase Web Server",
6
6
  "main": "src/index.ts",
7
7
  "repository": {
@@ -25,7 +25,6 @@
25
25
  "generate:proxy:preprod": "node scripts/proxy/generateProxyConfig preprod",
26
26
  "generate:proxy:prod": "node scripts/proxy/generateProxyConfig prod",
27
27
  "format": "prettier --config ../../.prettierrc.json 'src/**/*.ts' --write",
28
- "specs": "node specs/generate.js && openapi-typescript specs/openapi.yaml --output src/definitions/openapi.ts",
29
28
  "lint": "eslint --fix src/",
30
29
  "lint:fix": "yarn run format && yarn run lint",
31
30
  "initialise": "node scripts/initialise.js",
@@ -74,9 +73,9 @@
74
73
  "license": "GPL-3.0",
75
74
  "dependencies": {
76
75
  "@apidevtools/swagger-parser": "^10.0.3",
77
- "@budibase/backend-core": "^1.0.79-alpha.7",
78
- "@budibase/client": "^1.0.79-alpha.7",
79
- "@budibase/string-templates": "^1.0.79-alpha.7",
76
+ "@budibase/backend-core": "^1.0.79",
77
+ "@budibase/client": "^1.0.79",
78
+ "@budibase/string-templates": "^1.0.79",
80
79
  "@bull-board/api": "^3.7.0",
81
80
  "@bull-board/koa": "^3.7.0",
82
81
  "@elastic/elasticsearch": "7.10.0",
@@ -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": "29454f2b971da56fcde94cb6cd98a9d88ebaf30a"
174
+ "gitHead": "89e4c59e3cb151e0acb46d5abdb9fd00be0b5809"
179
175
  }
@@ -1,13 +1,11 @@
1
1
  SELECT 'CREATE DATABASE main'
2
2
  WHERE NOT EXISTS (SELECT FROM pg_database WHERE datname = 'main')\gexec
3
- CREATE TYPE person_job AS ENUM ('qa', 'programmer', 'designer');
4
3
  CREATE TABLE Persons (
5
4
  PersonID SERIAL PRIMARY KEY,
6
5
  LastName varchar(255),
7
6
  FirstName varchar(255),
8
7
  Address varchar(255),
9
- City varchar(255) DEFAULT 'Belfast',
10
- Type person_job
8
+ City varchar(255) DEFAULT 'Belfast'
11
9
  );
12
10
  CREATE TABLE Tasks (
13
11
  TaskID SERIAL PRIMARY KEY,
@@ -37,8 +35,8 @@ CREATE TABLE Products_Tasks (
37
35
  REFERENCES Tasks(TaskID),
38
36
  PRIMARY KEY (ProductID, TaskID)
39
37
  );
40
- INSERT INTO Persons (FirstName, LastName, Address, City, Type) VALUES ('Mike', 'Hughes', '123 Fake Street', 'Belfast', 'qa');
41
- 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');
42
40
  INSERT INTO Tasks (ExecutorID, QaID, TaskName, Completed) VALUES (1, 2, 'assembling', TRUE);
43
41
  INSERT INTO Tasks (ExecutorID, QaID, TaskName, Completed) VALUES (2, 1, 'processing', FALSE);
44
42
  INSERT INTO Products (ProductName) VALUES ('Computers');
@@ -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
@@ -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
@@ -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
 
@@ -1,13 +1,34 @@
1
1
  const Router = require("@koa/router")
2
2
  const controller = require("../controllers/role")
3
3
  const authorized = require("../../middleware/authorized")
4
- const { BUILDER } = require("@budibase/backend-core/permissions")
5
- const { roleValidator } = require("./utils/validators")
4
+ const Joi = require("joi")
5
+ const joiValidator = require("../../middleware/joi-validator")
6
+ const {
7
+ BUILTIN_PERMISSION_IDS,
8
+ BUILDER,
9
+ PermissionLevels,
10
+ } = require("@budibase/backend-core/permissions")
6
11
 
7
12
  const router = Router()
8
13
 
14
+ function generateValidator() {
15
+ const permLevelArray = Object.values(PermissionLevels)
16
+ // prettier-ignore
17
+ return joiValidator.body(Joi.object({
18
+ _id: Joi.string().optional(),
19
+ _rev: Joi.string().optional(),
20
+ name: Joi.string().required(),
21
+ // this is the base permission ID (for now a built in)
22
+ permissionId: Joi.string().valid(...Object.values(BUILTIN_PERMISSION_IDS)).required(),
23
+ permissions: Joi.object()
24
+ .pattern(/.*/, [Joi.string().valid(...permLevelArray)])
25
+ .optional(),
26
+ inherits: Joi.string().optional(),
27
+ }).unknown(true))
28
+ }
29
+
9
30
  router
10
- .post("/api/roles", authorized(BUILDER), roleValidator(), controller.save)
31
+ .post("/api/roles", authorized(BUILDER), generateValidator(), controller.save)
11
32
  .get("/api/roles", authorized(BUILDER), controller.fetch)
12
33
  .get("/api/roles/:roleId", authorized(BUILDER), controller.find)
13
34
  .delete("/api/roles/:roleId/:rev", authorized(BUILDER), controller.destroy)
@@ -10,7 +10,6 @@ const {
10
10
  PermissionLevels,
11
11
  PermissionTypes,
12
12
  } = require("@budibase/backend-core/permissions")
13
- const { internalSearchValidator } = require("./utils/validators")
14
13
 
15
14
  const router = Router()
16
15
 
@@ -120,6 +119,8 @@ router
120
119
  * "notEqual": {},
121
120
  * "empty": {},
122
121
  * "notEmpty": {},
122
+ * "contains": {},
123
+ * "notContains": {}
123
124
  * "oneOf": {
124
125
  * "columnName": ["value"]
125
126
  * }
@@ -139,7 +140,6 @@ router
139
140
  */
140
141
  .post(
141
142
  "/api/:tableId/search",
142
- internalSearchValidator(),
143
143
  paramResource("tableId"),
144
144
  authorized(PermissionTypes.TABLE, PermissionLevels.READ),
145
145
  rowController.search
@@ -195,7 +195,6 @@ router
195
195
  "/api/:tableId/rows",
196
196
  paramResource("tableId"),
197
197
  authorized(PermissionTypes.TABLE, PermissionLevels.WRITE),
198
- usage,
199
198
  rowController.patch
200
199
  )
201
200
  /**
@@ -2,13 +2,40 @@ const Router = require("@koa/router")
2
2
  const controller = require("../controllers/screen")
3
3
  const authorized = require("../../middleware/authorized")
4
4
  const { BUILDER } = require("@budibase/backend-core/permissions")
5
- const { screenValidator } = require("./utils/validators")
5
+ const joiValidator = require("../../middleware/joi-validator")
6
+ const Joi = require("joi")
6
7
 
7
8
  const router = Router()
8
9
 
10
+ function generateSaveValidation() {
11
+ // prettier-ignore
12
+ return joiValidator.body(Joi.object({
13
+ name: Joi.string().required(),
14
+ routing: Joi.object({
15
+ route: Joi.string().required(),
16
+ roleId: Joi.string().required().allow(""),
17
+ }).required().unknown(true),
18
+ props: Joi.object({
19
+ _id: Joi.string().required(),
20
+ _component: Joi.string().required(),
21
+ _children: Joi.array().required(),
22
+ _instanceName: Joi.string().required(),
23
+ _styles: Joi.object().required(),
24
+ type: Joi.string().optional(),
25
+ table: Joi.string().optional(),
26
+ layoutId: Joi.string().optional(),
27
+ }).required().unknown(true),
28
+ }).unknown(true))
29
+ }
30
+
9
31
  router
10
32
  .get("/api/screens", authorized(BUILDER), controller.fetch)
11
- .post("/api/screens", authorized(BUILDER), screenValidator(), controller.save)
33
+ .post(
34
+ "/api/screens",
35
+ authorized(BUILDER),
36
+ generateSaveValidation(),
37
+ controller.save
38
+ )
12
39
  .delete(
13
40
  "/api/screens/:screenId/:screenRev",
14
41
  authorized(BUILDER),