@budibase/server 1.0.79 → 1.0.80-alpha.0

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 (308) hide show
  1. package/__mocks__/node-fetch.ts +1 -0
  2. package/builder/assets/index.b37e0ebb.js +1288 -0
  3. package/builder/assets/{index.c8d1e8f0.css → index.c57242d4.css} +2 -2
  4. package/builder/assets/{vendor.20f80cec.js → vendor.a7c6ad0a.js} +190 -216
  5. package/builder/index.html +3 -3
  6. package/coverage/clover.xml +2399 -2336
  7. package/coverage/coverage-final.json +138 -137
  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 +152 -149
  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 +94 -82
  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 +47 -44
  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 +18 -27
  52. package/coverage/lcov-report/api/index.html +10 -10
  53. package/coverage/lcov-report/api/index.js.html +37 -28
  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 +19 -109
  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 +18 -156
  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 +38 -32
  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 +16 -58
  72. package/coverage/lcov-report/api/routes/query.js.html +10 -10
  73. package/coverage/lcov-report/api/routes/role.js.html +15 -78
  74. package/coverage/lcov-report/api/routes/routing.js.html +8 -8
  75. package/coverage/lcov-report/api/routes/row.js.html +17 -14
  76. package/coverage/lcov-report/api/routes/screen.js.html +14 -95
  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 +17 -62
  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/utils/index.html +111 -0
  83. package/coverage/lcov-report/api/routes/utils/validators.js.html +737 -0
  84. package/coverage/lcov-report/api/routes/view.js.html +10 -10
  85. package/coverage/lcov-report/api/routes/webhook.js.html +14 -62
  86. package/coverage/lcov-report/automations/actions.js.html +24 -24
  87. package/coverage/lcov-report/automations/automationUtils.js.html +5 -5
  88. package/coverage/lcov-report/automations/bullboard.js.html +16 -16
  89. package/coverage/lcov-report/automations/index.html +1 -1
  90. package/coverage/lcov-report/automations/index.js.html +7 -7
  91. package/coverage/lcov-report/automations/steps/bash.js.html +6 -6
  92. package/coverage/lcov-report/automations/steps/createRow.js.html +7 -7
  93. package/coverage/lcov-report/automations/steps/delay.js.html +4 -4
  94. package/coverage/lcov-report/automations/steps/deleteRow.js.html +7 -7
  95. package/coverage/lcov-report/automations/steps/discord.js.html +7 -7
  96. package/coverage/lcov-report/automations/steps/executeQuery.js.html +6 -6
  97. package/coverage/lcov-report/automations/steps/executeScript.js.html +6 -6
  98. package/coverage/lcov-report/automations/steps/filter.js.html +12 -9
  99. package/coverage/lcov-report/automations/steps/index.html +1 -1
  100. package/coverage/lcov-report/automations/steps/integromat.js.html +5 -5
  101. package/coverage/lcov-report/automations/steps/outgoingWebhook.js.html +8 -8
  102. package/coverage/lcov-report/automations/steps/queryRows.js.html +11 -11
  103. package/coverage/lcov-report/automations/steps/sendSmtpEmail.js.html +5 -5
  104. package/coverage/lcov-report/automations/steps/serverLog.js.html +3 -3
  105. package/coverage/lcov-report/automations/steps/slack.js.html +5 -5
  106. package/coverage/lcov-report/automations/steps/updateRow.js.html +6 -6
  107. package/coverage/lcov-report/automations/steps/utils.js.html +3 -3
  108. package/coverage/lcov-report/automations/steps/zapier.js.html +5 -5
  109. package/coverage/lcov-report/automations/triggerInfo/app.js.html +2 -2
  110. package/coverage/lcov-report/automations/triggerInfo/cron.js.html +2 -2
  111. package/coverage/lcov-report/automations/triggerInfo/index.html +1 -1
  112. package/coverage/lcov-report/automations/triggerInfo/index.js.html +8 -8
  113. package/coverage/lcov-report/automations/triggerInfo/rowDeleted.js.html +2 -2
  114. package/coverage/lcov-report/automations/triggerInfo/rowSaved.js.html +2 -2
  115. package/coverage/lcov-report/automations/triggerInfo/rowUpdated.js.html +2 -2
  116. package/coverage/lcov-report/automations/triggerInfo/webhook.js.html +2 -2
  117. package/coverage/lcov-report/automations/triggers.js.html +26 -26
  118. package/coverage/lcov-report/automations/utils.js.html +35 -35
  119. package/coverage/lcov-report/constants/index.html +5 -5
  120. package/coverage/lcov-report/constants/index.js.html +40 -28
  121. package/coverage/lcov-report/constants/layouts.js.html +5 -5
  122. package/coverage/lcov-report/constants/screens.js.html +4 -4
  123. package/coverage/lcov-report/db/client.js.html +18 -18
  124. package/coverage/lcov-report/db/inMemoryView.js.html +7 -7
  125. package/coverage/lcov-report/db/index.html +15 -15
  126. package/coverage/lcov-report/db/index.js.html +3 -3
  127. package/coverage/lcov-report/db/linkedRows/LinkController.js.html +21 -21
  128. package/coverage/lcov-report/db/linkedRows/index.html +1 -1
  129. package/coverage/lcov-report/db/linkedRows/index.js.html +36 -36
  130. package/coverage/lcov-report/db/linkedRows/linkUtils.js.html +30 -30
  131. package/coverage/lcov-report/db/newid.js.html +4 -4
  132. package/coverage/lcov-report/db/utils.js.html +123 -87
  133. package/coverage/lcov-report/events/AutomationEmitter.js.html +1 -1
  134. package/coverage/lcov-report/events/index.html +1 -1
  135. package/coverage/lcov-report/events/index.js.html +8 -8
  136. package/coverage/lcov-report/events/utils.js.html +18 -18
  137. package/coverage/lcov-report/index.html +89 -74
  138. package/coverage/lcov-report/integrations/tests/TestConfiguration.js.html +1 -1
  139. package/coverage/lcov-report/integrations/tests/index.html +1 -1
  140. package/coverage/lcov-report/middleware/appInfo.js.html +5 -5
  141. package/coverage/lcov-report/middleware/authorized.js.html +29 -29
  142. package/coverage/lcov-report/middleware/builder.js.html +16 -16
  143. package/coverage/lcov-report/middleware/currentapp.js.html +44 -44
  144. package/coverage/lcov-report/middleware/index.html +1 -1
  145. package/coverage/lcov-report/middleware/joi-validator.js.html +14 -14
  146. package/coverage/lcov-report/middleware/resourceId.js.html +29 -29
  147. package/coverage/lcov-report/middleware/selfhost.js.html +1 -1
  148. package/coverage/lcov-report/middleware/usageQuota.js.html +17 -17
  149. package/coverage/lcov-report/middleware/utils.js.html +4 -4
  150. package/coverage/lcov-report/threads/automation.js.html +1 -1
  151. package/coverage/lcov-report/threads/index.html +19 -19
  152. package/coverage/lcov-report/threads/index.js.html +10 -10
  153. package/coverage/lcov-report/threads/query.js.html +123 -39
  154. package/coverage/lcov-report/threads/utils.js.html +14 -14
  155. package/coverage/lcov-report/utilities/bcrypt.js.html +1 -1
  156. package/coverage/lcov-report/utilities/budibaseDir.js.html +7 -7
  157. package/coverage/lcov-report/utilities/centralPath.js.html +4 -4
  158. package/coverage/lcov-report/utilities/csvParser.js.html +6 -6
  159. package/coverage/lcov-report/utilities/global.js.html +28 -28
  160. package/coverage/lcov-report/utilities/index.html +18 -18
  161. package/coverage/lcov-report/utilities/index.js.html +24 -24
  162. package/coverage/lcov-report/utilities/queue/inMemoryQueue.js.html +9 -9
  163. package/coverage/lcov-report/utilities/queue/index.html +1 -1
  164. package/coverage/lcov-report/utilities/routing/index.html +1 -1
  165. package/coverage/lcov-report/utilities/routing/index.js.html +6 -6
  166. package/coverage/lcov-report/utilities/rowProcessor/index.html +1 -1
  167. package/coverage/lcov-report/utilities/rowProcessor/index.js.html +60 -60
  168. package/coverage/lcov-report/utilities/rowProcessor/utils.js.html +13 -13
  169. package/coverage/lcov-report/utilities/scriptRunner.js.html +5 -5
  170. package/coverage/lcov-report/utilities/security.js.html +8 -8
  171. package/coverage/lcov-report/utilities/statusCodes.js.html +1 -1
  172. package/coverage/lcov-report/utilities/usageQuota/index.html +1 -1
  173. package/coverage/lcov-report/utilities/usageQuota/index.js.html +12 -12
  174. package/coverage/lcov-report/utilities/usageQuota/rows.js.html +8 -8
  175. package/coverage/lcov-report/utilities/usageQuota/usageQuoteReset.js.html +1 -1
  176. package/coverage/lcov-report/utilities/users.js.html +5 -5
  177. package/coverage/lcov-report/utilities/workerRequests.js.html +200 -53
  178. package/coverage/lcov.info +3323 -3224
  179. package/dist/api/controllers/application.js +1 -0
  180. package/dist/api/controllers/public/applications.js +94 -0
  181. package/dist/api/controllers/public/mapping/applications.js +29 -0
  182. package/dist/api/controllers/public/mapping/index.js +11 -0
  183. package/dist/api/controllers/public/mapping/queries.js +36 -0
  184. package/dist/api/controllers/public/mapping/rows.js +24 -0
  185. package/dist/api/controllers/public/mapping/tables.js +23 -0
  186. package/dist/api/controllers/public/mapping/types.js +2 -0
  187. package/dist/api/controllers/public/mapping/users.js +29 -0
  188. package/dist/api/controllers/public/queries.js +38 -0
  189. package/dist/api/controllers/public/rows.js +97 -0
  190. package/dist/api/controllers/public/tables.js +75 -0
  191. package/dist/api/controllers/public/users.js +95 -0
  192. package/dist/api/controllers/public/utils.js +49 -0
  193. package/dist/api/controllers/row/internal.js +4 -1
  194. package/dist/api/controllers/table/index.js +2 -1
  195. package/dist/api/controllers/webhook.js +3 -5
  196. package/dist/api/index.js +3 -1
  197. package/dist/api/routes/automation.js +3 -31
  198. package/dist/api/routes/datasource.js +3 -50
  199. package/dist/api/routes/index.js +2 -0
  200. package/dist/api/routes/permission.js +4 -14
  201. package/dist/api/routes/public/applications.js +141 -0
  202. package/dist/api/routes/public/index.js +101 -0
  203. package/dist/api/routes/public/middleware/mapper.js +94 -0
  204. package/dist/api/routes/public/queries.js +77 -0
  205. package/dist/api/routes/public/rows.js +229 -0
  206. package/dist/api/routes/public/tables.js +154 -0
  207. package/dist/api/routes/public/users.js +137 -0
  208. package/dist/api/routes/public/utils/Endpoint.js +36 -0
  209. package/dist/api/routes/role.js +3 -19
  210. package/dist/api/routes/row.js +3 -4
  211. package/dist/api/routes/screen.js +2 -23
  212. package/dist/api/routes/table.js +3 -17
  213. package/dist/api/routes/tests/utilities/index.js +23 -0
  214. package/dist/api/routes/utils/validators.js +200 -0
  215. package/dist/api/routes/webhook.js +2 -17
  216. package/dist/automations/steps/filter.js +2 -2
  217. package/dist/automations/steps/queryRows.js +1 -1
  218. package/dist/automations/utils.js +2 -2
  219. package/dist/constants/index.js +3 -0
  220. package/dist/db/utils.js +11 -0
  221. package/dist/definitions/openapi.js +6 -0
  222. package/dist/environment.js +1 -0
  223. package/dist/integrations/googlesheets.js +3 -0
  224. package/dist/integrations/microsoftSqlServer.js +35 -29
  225. package/dist/integrations/mysql.js +3 -0
  226. package/dist/integrations/oracle.js +14 -19
  227. package/dist/integrations/postgres.js +34 -28
  228. package/dist/package.json +11 -7
  229. package/dist/tests/utilities/TestConfiguration.js +25 -8
  230. package/dist/threads/query.js +33 -8
  231. package/dist/tsconfig.tsbuildinfo +1 -1
  232. package/dist/utilities/workerRequests.js +50 -15
  233. package/package.json +12 -8
  234. package/scripts/integrations/oracle/oracle.md +2 -2
  235. package/scripts/integrations/postgres/init.sql +5 -3
  236. package/scripts/likeCypress.ts +9 -6
  237. package/specs/generate.js +83 -0
  238. package/specs/openapi.json +2222 -0
  239. package/specs/openapi.yaml +1530 -0
  240. package/specs/parameters.js +59 -0
  241. package/specs/resources/application.js +101 -0
  242. package/specs/resources/index.js +24 -0
  243. package/specs/resources/misc.js +12 -0
  244. package/specs/resources/query.js +189 -0
  245. package/specs/resources/row.js +125 -0
  246. package/specs/resources/table.js +191 -0
  247. package/specs/resources/user.js +126 -0
  248. package/specs/resources/utils/Resource.js +26 -0
  249. package/specs/resources/utils/index.js +11 -0
  250. package/specs/security.js +7 -0
  251. package/src/api/controllers/application.js +1 -0
  252. package/src/api/controllers/public/applications.ts +74 -0
  253. package/src/api/controllers/public/mapping/applications.ts +32 -0
  254. package/src/api/controllers/public/mapping/index.ts +13 -0
  255. package/src/api/controllers/public/mapping/queries.ts +39 -0
  256. package/src/api/controllers/public/mapping/rows.ts +31 -0
  257. package/src/api/controllers/public/mapping/tables.ts +26 -0
  258. package/src/api/controllers/public/mapping/types.ts +13 -0
  259. package/src/api/controllers/public/mapping/users.ts +32 -0
  260. package/src/api/controllers/public/queries.ts +20 -0
  261. package/src/api/controllers/public/rows.ts +77 -0
  262. package/src/api/controllers/public/tables.ts +56 -0
  263. package/src/api/controllers/public/users.ts +82 -0
  264. package/src/api/controllers/public/utils.ts +38 -0
  265. package/src/api/controllers/row/ExternalRequest.ts +1 -1
  266. package/src/api/controllers/row/internal.js +4 -0
  267. package/src/api/controllers/table/index.js +2 -1
  268. package/src/api/controllers/webhook.js +3 -6
  269. package/src/api/index.js +4 -1
  270. package/src/api/routes/automation.js +3 -33
  271. package/src/api/routes/datasource.js +6 -52
  272. package/src/api/routes/index.js +2 -0
  273. package/src/api/routes/permission.js +4 -18
  274. package/src/api/routes/public/applications.ts +156 -0
  275. package/src/api/routes/public/index.ts +118 -0
  276. package/src/api/routes/public/middleware/mapper.ts +81 -0
  277. package/src/api/routes/public/queries.ts +81 -0
  278. package/src/api/routes/public/rows.ts +242 -0
  279. package/src/api/routes/public/tables.ts +169 -0
  280. package/src/api/routes/public/tests/compare.spec.js +184 -0
  281. package/src/api/routes/public/users.ts +144 -0
  282. package/src/api/routes/public/utils/Endpoint.ts +51 -0
  283. package/src/api/routes/role.js +3 -24
  284. package/src/api/routes/row.js +3 -2
  285. package/src/api/routes/screen.js +2 -29
  286. package/src/api/routes/table.js +4 -19
  287. package/src/api/routes/tests/utilities/index.js +24 -0
  288. package/src/api/routes/utils/validators.js +219 -0
  289. package/src/api/routes/webhook.js +2 -18
  290. package/src/automations/steps/filter.js +3 -2
  291. package/src/automations/steps/queryRows.js +1 -1
  292. package/src/automations/utils.js +2 -2
  293. package/src/constants/index.js +4 -0
  294. package/src/db/utils.js +12 -0
  295. package/src/definitions/common.ts +4 -0
  296. package/src/definitions/openapi.ts +943 -0
  297. package/src/environment.js +1 -0
  298. package/src/integrations/base/datasourcePlus.ts +3 -0
  299. package/src/integrations/googlesheets.ts +5 -2
  300. package/src/integrations/microsoftSqlServer.ts +38 -33
  301. package/src/integrations/mysql.ts +4 -0
  302. package/src/integrations/oracle.ts +27 -35
  303. package/src/integrations/postgres.ts +33 -26
  304. package/src/tests/utilities/TestConfiguration.js +23 -2
  305. package/src/threads/query.js +37 -9
  306. package/src/utilities/workerRequests.js +65 -16
  307. package/builder/assets/index.f28c5d54.js +0 -1352
  308. package/scripts/proxy/generateProxyConfig.js +0 -70
@@ -0,0 +1,126 @@
1
+ const { object } = require("./utils")
2
+ const Resource = require("./utils/Resource")
3
+
4
+ const user = {
5
+ _id: "us_693a73206518477283a8d5ae31103252",
6
+ email: "test@test.com",
7
+ roles: {
8
+ app_957b12f943d348faa61db7e18e088d0f: "BASIC",
9
+ },
10
+ builder: {
11
+ global: false,
12
+ },
13
+ admin: {
14
+ global: true,
15
+ },
16
+ tenantId: "default",
17
+ status: "active",
18
+ budibaseAccess: true,
19
+ csrfToken: "9c70291d-7137-48f9-9166-99ab5473a3d4",
20
+ userId: "us_693a73206518477283a8d5ae31103252",
21
+ roleId: "ADMIN",
22
+ role: {
23
+ _id: "ADMIN",
24
+ name: "Admin",
25
+ permissionId: "admin",
26
+ inherits: "POWER",
27
+ },
28
+ }
29
+
30
+ const userSchema = object(
31
+ {
32
+ email: {
33
+ description: "The email address of the user, this must be unique.",
34
+ type: "string",
35
+ },
36
+ password: {
37
+ description:
38
+ "The password of the user if using password based login - this will never be returned. This can be" +
39
+ " left out of subsequent requests (updates) and will be enriched back into the user structure.",
40
+ type: "string",
41
+ },
42
+ status: {
43
+ description: "The status of the user, if they are active.",
44
+ type: "string",
45
+ enum: ["active"],
46
+ },
47
+ firstName: {
48
+ description: "The first name of the user",
49
+ type: "string",
50
+ },
51
+ lastName: {
52
+ description: "The last name of the user",
53
+ type: "string",
54
+ },
55
+ forceResetPassword: {
56
+ description:
57
+ "If set to true forces the user to reset their password on first login.",
58
+ type: "boolean",
59
+ },
60
+ builder: {
61
+ description: "Describes if the user is a builder user or not.",
62
+ type: "object",
63
+ properties: {
64
+ global: {
65
+ description:
66
+ "If set to true the user will be able to build any app in the system.",
67
+ type: "boolean",
68
+ },
69
+ },
70
+ },
71
+ admin: {
72
+ description: "Describes if the user is an admin user or not.",
73
+ type: "object",
74
+ properties: {
75
+ global: {
76
+ description:
77
+ "If set to true the user will be able to administrate the system.",
78
+ type: "boolean",
79
+ },
80
+ },
81
+ },
82
+ roles: {
83
+ description:
84
+ "Contains the roles of the user per app (assuming they are not a builder user).",
85
+ type: "object",
86
+ additionalProperties: {
87
+ type: "string",
88
+ description:
89
+ "A map of app ID (production app ID, minus the _dev component) to a role ID, e.g. ADMIN.",
90
+ },
91
+ },
92
+ },
93
+ { required: ["email", "roles"] }
94
+ )
95
+
96
+ const userOutputSchema = {
97
+ ...userSchema,
98
+ properties: {
99
+ ...userSchema.properties,
100
+ _id: {
101
+ description: "The ID of the user.",
102
+ type: "string",
103
+ },
104
+ },
105
+ required: [...userSchema.required, "_id"],
106
+ }
107
+
108
+ module.exports = new Resource()
109
+ .setExamples({
110
+ user: {
111
+ value: {
112
+ data: user,
113
+ },
114
+ },
115
+ users: {
116
+ value: {
117
+ data: [user],
118
+ },
119
+ },
120
+ })
121
+ .setSchemas({
122
+ user: userSchema,
123
+ userOutput: object({
124
+ data: userOutputSchema,
125
+ }),
126
+ })
@@ -0,0 +1,26 @@
1
+ class Resource {
2
+ constructor() {
3
+ this.examples = {}
4
+ this.schemas = {}
5
+ }
6
+
7
+ setExamples(examples) {
8
+ this.examples = examples
9
+ return this
10
+ }
11
+
12
+ setSchemas(schemas) {
13
+ this.schemas = schemas
14
+ return this
15
+ }
16
+
17
+ getExamples() {
18
+ return this.examples
19
+ }
20
+
21
+ getSchemas() {
22
+ return this.schemas
23
+ }
24
+ }
25
+
26
+ module.exports = Resource
@@ -0,0 +1,11 @@
1
+ exports.object = (props, opts) => {
2
+ const base = {
3
+ type: "object",
4
+ properties: props,
5
+ ...opts,
6
+ }
7
+ if (Object.keys(props).length > 0 && (!opts || !opts.required)) {
8
+ base.required = Object.keys(props)
9
+ }
10
+ return base
11
+ }
@@ -0,0 +1,7 @@
1
+ exports.ApiKeyAuth = {
2
+ type: "apiKey",
3
+ in: "header",
4
+ name: "x-budibase-api-key",
5
+ description:
6
+ "Your individual API key, this will provide access based on the configured RBAC settings of your user.",
7
+ }
@@ -263,6 +263,7 @@ exports.create = async ctx => {
263
263
  tenantId: getTenantId(),
264
264
  updatedAt: new Date().toISOString(),
265
265
  createdAt: new Date().toISOString(),
266
+ status: AppStatus.DEV,
266
267
  }
267
268
  const response = await db.put(newApplication, { force: true })
268
269
  newApplication._rev = response.rev
@@ -0,0 +1,74 @@
1
+ const { getAllApps } = require("@budibase/backend-core/db")
2
+ const { updateAppId } = require("@budibase/backend-core/context")
3
+ import { search as stringSearch } from "./utils"
4
+ import { default as controller } from "../application"
5
+ import { Application } from "../../../definitions/common"
6
+
7
+ function fixAppID(app: Application, params: any) {
8
+ if (!params) {
9
+ return app
10
+ }
11
+ if (!app._id && params.appId) {
12
+ app._id = params.appId
13
+ }
14
+ return app
15
+ }
16
+
17
+ async function setResponseApp(ctx: any) {
18
+ if (ctx.body && ctx.body.appId && (!ctx.params || !ctx.params.appId)) {
19
+ ctx.params = { appId: ctx.body.appId }
20
+ }
21
+ await controller.fetchAppPackage(ctx)
22
+ }
23
+
24
+ export async function search(ctx: any, next: any) {
25
+ const { name } = ctx.request.body
26
+ const apps = await getAllApps({ all: true })
27
+ ctx.body = stringSearch(apps, name)
28
+ await next()
29
+ }
30
+
31
+ export async function create(ctx: any, next: any) {
32
+ if (!ctx.request.body || !ctx.request.body.useTemplate) {
33
+ ctx.request.body = {
34
+ useTemplate: false,
35
+ ...ctx.request.body,
36
+ }
37
+ }
38
+ await controller.create(ctx)
39
+ await setResponseApp(ctx)
40
+ await next()
41
+ }
42
+
43
+ export async function read(ctx: any, next: any) {
44
+ updateAppId(ctx.params.appId)
45
+ await setResponseApp(ctx)
46
+ await next()
47
+ }
48
+
49
+ export async function update(ctx: any, next: any) {
50
+ ctx.request.body = fixAppID(ctx.request.body, ctx.params)
51
+ updateAppId(ctx.params.appId)
52
+ await controller.update(ctx)
53
+ await setResponseApp(ctx)
54
+ await next()
55
+ }
56
+
57
+ export async function destroy(ctx: any, next: any) {
58
+ updateAppId(ctx.params.appId)
59
+ // get the app before deleting it
60
+ await setResponseApp(ctx)
61
+ const body = ctx.body
62
+ await controller.delete(ctx)
63
+ // overwrite the body again
64
+ ctx.body = body
65
+ await next()
66
+ }
67
+
68
+ export default {
69
+ create,
70
+ update,
71
+ read,
72
+ destroy,
73
+ search,
74
+ }
@@ -0,0 +1,32 @@
1
+ import { Application } from "./types"
2
+
3
+ function application(body: any): Application {
4
+ let app = body?.application ? body.application : body
5
+ return {
6
+ _id: app.appId,
7
+ name: app.name,
8
+ url: app.url,
9
+ status: app.status,
10
+ createdAt: app.createdAt,
11
+ updatedAt: app.updatedAt,
12
+ version: app.version,
13
+ tenantId: app.tenantId,
14
+ lockedBy: app.lockedBy,
15
+ }
16
+ }
17
+
18
+ function mapApplication(ctx: any): { data: Application } {
19
+ return {
20
+ data: application(ctx.body),
21
+ }
22
+ }
23
+
24
+ function mapApplications(ctx: any): { data: Application[] } {
25
+ const apps = ctx.body.map((body: any) => application(body))
26
+ return { data: apps }
27
+ }
28
+
29
+ export default {
30
+ mapApplication,
31
+ mapApplications,
32
+ }
@@ -0,0 +1,13 @@
1
+ import tables from "./tables"
2
+ import applications from "./applications"
3
+ import users from "./users"
4
+ import rows from "./rows"
5
+ import queries from "./queries"
6
+
7
+ export default {
8
+ ...tables,
9
+ ...applications,
10
+ ...users,
11
+ ...rows,
12
+ ...queries,
13
+ }
@@ -0,0 +1,39 @@
1
+ import { Query, ExecuteQuery } from "./types"
2
+
3
+ function query(body: any): Query {
4
+ return {
5
+ _id: body._id,
6
+ datasourceId: body.datasourceId,
7
+ parameters: body.parameters,
8
+ fields: body.fields,
9
+ queryVerb: body.queryVerb,
10
+ name: body.name,
11
+ schema: body.schema,
12
+ transformer: body.transformer,
13
+ readable: body.readable,
14
+ }
15
+ }
16
+
17
+ function mapQueries(ctx: any): { data: Query[] } {
18
+ const queries = ctx.body.map((body: any) => query(body))
19
+ return {
20
+ data: queries,
21
+ }
22
+ }
23
+
24
+ function mapQueryExecution(ctx: any): ExecuteQuery {
25
+ // very little we can map here, structure mostly unknown
26
+ return {
27
+ data: ctx.body.data,
28
+ pagination: ctx.body.pagination,
29
+ extra: {
30
+ raw: ctx.body.raw,
31
+ headers: ctx.body.headers,
32
+ },
33
+ }
34
+ }
35
+
36
+ export default {
37
+ mapQueries,
38
+ mapQueryExecution,
39
+ }
@@ -0,0 +1,31 @@
1
+ import { Row, RowSearch } from "./types"
2
+
3
+ function row(body: any): Row {
4
+ delete body._rev
5
+ // have to input everything, since structure unknown
6
+ return {
7
+ ...body,
8
+ _id: body._id,
9
+ tableId: body.tableId,
10
+ }
11
+ }
12
+
13
+ function mapRowSearch(ctx: any): RowSearch {
14
+ const rows = ctx.body.rows.map((body: any) => row(body))
15
+ return {
16
+ data: rows,
17
+ hasNextPage: ctx.body.hasNextPage,
18
+ bookmark: ctx.body.bookmark,
19
+ }
20
+ }
21
+
22
+ function mapRow(ctx: any): { data: Row } {
23
+ return {
24
+ data: row(ctx.body),
25
+ }
26
+ }
27
+
28
+ export default {
29
+ mapRowSearch,
30
+ mapRow,
31
+ }
@@ -0,0 +1,26 @@
1
+ import { Table } from "./types"
2
+
3
+ function table(body: any): Table {
4
+ return {
5
+ _id: body._id,
6
+ name: body.name,
7
+ schema: body.schema,
8
+ primaryDisplay: body.primaryDisplay,
9
+ }
10
+ }
11
+
12
+ function mapTable(ctx: any): { data: Table } {
13
+ return {
14
+ data: table(ctx.body),
15
+ }
16
+ }
17
+
18
+ function mapTables(ctx: any): { data: Table[] } {
19
+ const tables = ctx.body.map((body: any) => table(body))
20
+ return { data: tables }
21
+ }
22
+
23
+ export default {
24
+ mapTable,
25
+ mapTables,
26
+ }
@@ -0,0 +1,13 @@
1
+ import { components } from "../../../../definitions/openapi"
2
+
3
+ export type Query = components["schemas"]["query"]
4
+ export type ExecuteQuery = components["schemas"]["executeQueryOutput"]
5
+
6
+ export type Application = components["schemas"]["applicationOutput"]["data"]
7
+
8
+ export type Table = components["schemas"]["tableOutput"]["data"]
9
+
10
+ export type Row = components["schemas"]["rowOutput"]["data"]
11
+ export type RowSearch = components["schemas"]["searchOutput"]
12
+
13
+ export type User = components["schemas"]["userOutput"]["data"]
@@ -0,0 +1,32 @@
1
+ import { User } from "./types"
2
+
3
+ function user(body: any): User {
4
+ return {
5
+ _id: body._id,
6
+ email: body.email,
7
+ password: body.password,
8
+ status: body.status,
9
+ firstName: body.firstName,
10
+ lastName: body.lastName,
11
+ forceResetPassword: body.forceResetPassword,
12
+ builder: body.builder,
13
+ admin: body.admin,
14
+ roles: body.roles,
15
+ }
16
+ }
17
+
18
+ function mapUser(ctx: any): { data: User } {
19
+ return {
20
+ data: user(ctx.body),
21
+ }
22
+ }
23
+
24
+ function mapUsers(ctx: any): { data: User[] } {
25
+ const users = ctx.body.map((body: any) => user(body))
26
+ return { data: users }
27
+ }
28
+
29
+ export default {
30
+ mapUser,
31
+ mapUsers,
32
+ }
@@ -0,0 +1,20 @@
1
+ import { search as stringSearch } from "./utils"
2
+ import { default as queryController } from "../query"
3
+
4
+ export async function search(ctx: any, next: any) {
5
+ await queryController.fetch(ctx)
6
+ const { name } = ctx.request.body
7
+ ctx.body = stringSearch(ctx.body, name)
8
+ await next()
9
+ }
10
+
11
+ export async function execute(ctx: any, next: any) {
12
+ // don't wrap this, already returns "data"
13
+ await queryController.executeV2(ctx)
14
+ await next()
15
+ }
16
+
17
+ export default {
18
+ search,
19
+ execute,
20
+ }
@@ -0,0 +1,77 @@
1
+ import { default as rowController } from "../row"
2
+ import { addRev } from "./utils"
3
+ import { Row } from "../../../definitions/common"
4
+
5
+ // makes sure that the user doesn't need to pass in the type, tableId or _id params for
6
+ // the call to be correct
7
+ function fixRow(row: Row, params: any) {
8
+ if (!params || !row) {
9
+ return row
10
+ }
11
+ if (params.rowId) {
12
+ row._id = params.rowId
13
+ }
14
+ if (params.tableId) {
15
+ row.tableId = params.tableId
16
+ }
17
+ if (!row.type) {
18
+ row.type = "row"
19
+ }
20
+ return row
21
+ }
22
+
23
+ export async function search(ctx: any, next: any) {
24
+ let { sort, paginate, bookmark, limit, query } = ctx.request.body
25
+ // update the body to the correct format of the internal search
26
+ if (!sort) {
27
+ sort = {}
28
+ }
29
+ ctx.request.body = {
30
+ sort: sort.column,
31
+ sortType: sort.type,
32
+ sortOrder: sort.order,
33
+ bookmark,
34
+ paginate,
35
+ limit,
36
+ query,
37
+ }
38
+ await rowController.search(ctx)
39
+ await next()
40
+ }
41
+
42
+ export async function create(ctx: any, next: any) {
43
+ ctx.request.body = fixRow(ctx.request.body, ctx.params)
44
+ await rowController.save(ctx)
45
+ await next()
46
+ }
47
+
48
+ export async function read(ctx: any, next: any) {
49
+ await rowController.fetchEnrichedRow(ctx)
50
+ await next()
51
+ }
52
+
53
+ export async function update(ctx: any, next: any) {
54
+ ctx.request.body = await addRev(fixRow(ctx.request.body, ctx.params.tableId))
55
+ await rowController.save(ctx)
56
+ await next()
57
+ }
58
+
59
+ export async function destroy(ctx: any, next: any) {
60
+ // set the body as expected, with the _id and _rev fields
61
+ ctx.request.body = await addRev(
62
+ fixRow({ _id: ctx.params.rowId }, ctx.params.tableId)
63
+ )
64
+ await rowController.destroy(ctx)
65
+ // destroy controller doesn't currently return the row as the body, need to adjust this
66
+ // in the public API to be correct
67
+ ctx.body = ctx.row
68
+ await next()
69
+ }
70
+
71
+ export default {
72
+ create,
73
+ read,
74
+ update,
75
+ destroy,
76
+ search,
77
+ }
@@ -0,0 +1,56 @@
1
+ import { search as stringSearch, addRev } from "./utils"
2
+ import { default as controller } from "../table"
3
+ import { Table } from "../../../definitions/common"
4
+
5
+ function fixTable(table: Table, params: any) {
6
+ if (!params || !table) {
7
+ return table
8
+ }
9
+ if (params.tableId) {
10
+ table._id = params.tableId
11
+ }
12
+ if (!table.type) {
13
+ table.type = "table"
14
+ }
15
+ return table
16
+ }
17
+
18
+ export async function search(ctx: any, next: any) {
19
+ const { name } = ctx.request.body
20
+ await controller.fetch(ctx)
21
+ ctx.body = stringSearch(ctx.body, name)
22
+ await next()
23
+ }
24
+
25
+ export async function create(ctx: any, next: any) {
26
+ await controller.save(ctx)
27
+ await next()
28
+ }
29
+
30
+ export async function read(ctx: any, next: any) {
31
+ await controller.find(ctx)
32
+ await next()
33
+ }
34
+
35
+ export async function update(ctx: any, next: any) {
36
+ ctx.request.body = await addRev(
37
+ fixTable(ctx.request.body, ctx.params),
38
+ ctx.params.tableId
39
+ )
40
+ await controller.save(ctx)
41
+ await next()
42
+ }
43
+
44
+ export async function destroy(ctx: any, next: any) {
45
+ await controller.destroy(ctx)
46
+ ctx.body = ctx.table
47
+ await next()
48
+ }
49
+
50
+ export default {
51
+ create,
52
+ read,
53
+ update,
54
+ destroy,
55
+ search,
56
+ }
@@ -0,0 +1,82 @@
1
+ import {
2
+ allGlobalUsers,
3
+ deleteGlobalUser,
4
+ readGlobalUser,
5
+ saveGlobalUser,
6
+ } from "../../../utilities/workerRequests"
7
+ import { search as stringSearch } from "./utils"
8
+
9
+ const { getProdAppID } = require("@budibase/backend-core/db")
10
+
11
+ function fixUser(ctx: any) {
12
+ if (!ctx.request.body) {
13
+ return ctx
14
+ }
15
+ if (!ctx.request.body._id && ctx.params.userId) {
16
+ ctx.request.body._id = ctx.params.userId
17
+ }
18
+ if (!ctx.request.body.roles) {
19
+ ctx.request.body.roles = {}
20
+ } else {
21
+ const newRoles: { [key: string]: string } = {}
22
+ for (let [appId, role] of Object.entries(ctx.request.body.roles)) {
23
+ // @ts-ignore
24
+ newRoles[getProdAppID(appId)] = role
25
+ }
26
+ ctx.request.body.roles = newRoles
27
+ }
28
+ return ctx
29
+ }
30
+
31
+ function getUser(ctx: any, userId?: string) {
32
+ if (userId) {
33
+ ctx.params = { userId }
34
+ } else if (!ctx.params?.userId) {
35
+ throw "No user ID provided for getting"
36
+ }
37
+ return readGlobalUser(ctx)
38
+ }
39
+
40
+ export async function search(ctx: any, next: any) {
41
+ const { name } = ctx.request.body
42
+ const users = await allGlobalUsers(ctx)
43
+ ctx.body = stringSearch(users, name, "email")
44
+ await next()
45
+ }
46
+
47
+ export async function create(ctx: any, next: any) {
48
+ const response = await saveGlobalUser(fixUser(ctx))
49
+ ctx.body = await getUser(ctx, response._id)
50
+ await next()
51
+ }
52
+
53
+ export async function read(ctx: any, next: any) {
54
+ ctx.body = await readGlobalUser(ctx)
55
+ await next()
56
+ }
57
+
58
+ export async function update(ctx: any, next: any) {
59
+ const user = await readGlobalUser(ctx)
60
+ ctx.request.body = {
61
+ ...ctx.request.body,
62
+ _rev: user._rev,
63
+ }
64
+ const response = await saveGlobalUser(fixUser(ctx))
65
+ ctx.body = await getUser(ctx, response._id)
66
+ await next()
67
+ }
68
+
69
+ export async function destroy(ctx: any, next: any) {
70
+ const user = await getUser(ctx)
71
+ await deleteGlobalUser(ctx)
72
+ ctx.body = user
73
+ await next()
74
+ }
75
+
76
+ export default {
77
+ create,
78
+ read,
79
+ update,
80
+ destroy,
81
+ search,
82
+ }