@budibase/server 1.0.123 → 1.0.125

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 (325) hide show
  1. package/builder/assets/index.3d890df7.js +1299 -0
  2. package/builder/assets/index.89795487.css +6 -0
  3. package/builder/assets/{vendor.8e34a169.js → vendor.5240f480.js} +1 -1
  4. package/builder/index.html +3 -3
  5. package/coverage/clover.xml +695 -1678
  6. package/coverage/coverage-final.json +28 -43
  7. package/coverage/lcov-report/api/controllers/analytics.js.html +8 -3
  8. package/coverage/lcov-report/api/controllers/apikeys.js.html +9 -4
  9. package/coverage/lcov-report/api/controllers/auth.js.html +8 -3
  10. package/coverage/lcov-report/api/controllers/automation.js.html +8 -3
  11. package/coverage/lcov-report/api/controllers/backup.js.html +8 -3
  12. package/coverage/lcov-report/api/controllers/cloud.js.html +8 -3
  13. package/coverage/lcov-report/api/controllers/component.js.html +8 -3
  14. package/coverage/lcov-report/api/controllers/datasource.js.html +11 -6
  15. package/coverage/lcov-report/api/controllers/dev.js.html +8 -3
  16. package/coverage/lcov-report/api/controllers/index.html +16 -26
  17. package/coverage/lcov-report/api/controllers/integration.js.html +8 -3
  18. package/coverage/lcov-report/api/controllers/layout.js.html +8 -3
  19. package/coverage/lcov-report/api/controllers/metadata.js.html +8 -3
  20. package/coverage/lcov-report/api/controllers/migrations.js.html +8 -3
  21. package/coverage/lcov-report/api/controllers/permission.js.html +8 -3
  22. package/coverage/lcov-report/api/controllers/query/index.html +16 -26
  23. package/coverage/lcov-report/api/controllers/query/validation.js.html +8 -3
  24. package/coverage/lcov-report/api/controllers/role.js.html +10 -5
  25. package/coverage/lcov-report/api/controllers/routing.js.html +9 -4
  26. package/coverage/lcov-report/api/controllers/row/external.js.html +8 -3
  27. package/coverage/lcov-report/api/controllers/row/index.html +25 -35
  28. package/coverage/lcov-report/api/controllers/row/internal.js.html +32 -24
  29. package/coverage/lcov-report/api/controllers/row/internalSearch.js.html +21 -16
  30. package/coverage/lcov-report/api/controllers/row/staticFormula.js.html +24 -19
  31. package/coverage/lcov-report/api/controllers/row/utils.js.html +33 -19
  32. package/coverage/lcov-report/api/controllers/screen.js.html +9 -4
  33. package/coverage/lcov-report/api/controllers/script.js.html +8 -3
  34. package/coverage/lcov-report/api/controllers/table/bulkFormula.js.html +55 -50
  35. package/coverage/lcov-report/api/controllers/table/external.js.html +8 -3
  36. package/coverage/lcov-report/api/controllers/table/index.html +19 -44
  37. package/coverage/lcov-report/api/controllers/table/index.js.html +20 -15
  38. package/coverage/lcov-report/api/controllers/templates.js.html +8 -3
  39. package/coverage/lcov-report/api/controllers/user.js.html +8 -3
  40. package/coverage/lcov-report/api/controllers/view/exporters.js.html +8 -3
  41. package/coverage/lcov-report/api/controllers/view/index.html +8 -3
  42. package/coverage/lcov-report/api/controllers/view/index.js.html +10 -5
  43. package/coverage/lcov-report/api/controllers/view/utils.js.html +8 -3
  44. package/coverage/lcov-report/api/controllers/view/viewBuilder.js.html +8 -3
  45. package/coverage/lcov-report/api/controllers/webhook.js.html +10 -5
  46. package/coverage/lcov-report/api/index.html +18 -13
  47. package/coverage/lcov-report/api/index.js.html +28 -8
  48. package/coverage/lcov-report/api/routes/analytics.js.html +8 -3
  49. package/coverage/lcov-report/api/routes/apikeys.js.html +8 -3
  50. package/coverage/lcov-report/api/routes/auth.js.html +8 -3
  51. package/coverage/lcov-report/api/routes/automation.js.html +8 -3
  52. package/coverage/lcov-report/api/routes/backup.js.html +8 -3
  53. package/coverage/lcov-report/api/routes/cloud.js.html +8 -3
  54. package/coverage/lcov-report/api/routes/component.js.html +8 -3
  55. package/coverage/lcov-report/api/routes/datasource.js.html +8 -3
  56. package/coverage/lcov-report/api/routes/deploy.js.html +8 -3
  57. package/coverage/lcov-report/api/routes/dev.js.html +9 -4
  58. package/coverage/lcov-report/api/routes/index.html +13 -68
  59. package/coverage/lcov-report/api/routes/integration.js.html +8 -3
  60. package/coverage/lcov-report/api/routes/layout.js.html +8 -3
  61. package/coverage/lcov-report/api/routes/metadata.js.html +8 -3
  62. package/coverage/lcov-report/api/routes/migrations.js.html +8 -3
  63. package/coverage/lcov-report/api/routes/permission.js.html +8 -3
  64. package/coverage/lcov-report/api/routes/query.js.html +8 -3
  65. package/coverage/lcov-report/api/routes/role.js.html +8 -3
  66. package/coverage/lcov-report/api/routes/routing.js.html +8 -3
  67. package/coverage/lcov-report/api/routes/screen.js.html +8 -3
  68. package/coverage/lcov-report/api/routes/script.js.html +8 -3
  69. package/coverage/lcov-report/api/routes/table.js.html +8 -3
  70. package/coverage/lcov-report/api/routes/templates.js.html +8 -3
  71. package/coverage/lcov-report/api/routes/user.js.html +8 -3
  72. package/coverage/lcov-report/api/routes/utils/index.html +8 -3
  73. package/coverage/lcov-report/api/routes/utils/validators.js.html +8 -3
  74. package/coverage/lcov-report/api/routes/view.js.html +8 -3
  75. package/coverage/lcov-report/api/routes/webhook.js.html +8 -3
  76. package/coverage/lcov-report/automations/actions.js.html +21 -7
  77. package/coverage/lcov-report/automations/automationUtils.js.html +64 -23
  78. package/coverage/lcov-report/automations/bullboard.js.html +8 -3
  79. package/coverage/lcov-report/automations/index.html +27 -37
  80. package/coverage/lcov-report/automations/index.js.html +8 -3
  81. package/coverage/lcov-report/automations/steps/bash.js.html +8 -3
  82. package/coverage/lcov-report/automations/steps/delay.js.html +8 -3
  83. package/coverage/lcov-report/automations/steps/discord.js.html +8 -3
  84. package/coverage/lcov-report/automations/steps/executeQuery.js.html +8 -3
  85. package/coverage/lcov-report/automations/steps/executeScript.js.html +8 -3
  86. package/coverage/lcov-report/automations/steps/filter.js.html +8 -3
  87. package/coverage/lcov-report/automations/steps/index.html +31 -41
  88. package/coverage/lcov-report/automations/steps/integromat.js.html +8 -3
  89. package/coverage/lcov-report/{api/routes/static.js.html → automations/steps/loop.js.html} +70 -80
  90. package/coverage/lcov-report/automations/steps/outgoingWebhook.js.html +9 -4
  91. package/coverage/lcov-report/automations/steps/queryRows.js.html +9 -4
  92. package/coverage/lcov-report/automations/steps/sendSmtpEmail.js.html +8 -3
  93. package/coverage/lcov-report/automations/steps/serverLog.js.html +8 -3
  94. package/coverage/lcov-report/automations/steps/slack.js.html +8 -3
  95. package/coverage/lcov-report/automations/steps/updateRow.js.html +8 -3
  96. package/coverage/lcov-report/automations/steps/utils.js.html +14 -9
  97. package/coverage/lcov-report/automations/steps/zapier.js.html +8 -3
  98. package/coverage/lcov-report/automations/triggerInfo/app.js.html +8 -3
  99. package/coverage/lcov-report/automations/triggerInfo/cron.js.html +8 -3
  100. package/coverage/lcov-report/automations/triggerInfo/index.html +8 -3
  101. package/coverage/lcov-report/automations/triggerInfo/index.js.html +8 -3
  102. package/coverage/lcov-report/automations/triggerInfo/rowDeleted.js.html +8 -3
  103. package/coverage/lcov-report/automations/triggerInfo/rowSaved.js.html +8 -3
  104. package/coverage/lcov-report/automations/triggerInfo/rowUpdated.js.html +8 -3
  105. package/coverage/lcov-report/automations/triggerInfo/webhook.js.html +8 -3
  106. package/coverage/lcov-report/automations/triggers.js.html +16 -11
  107. package/coverage/lcov-report/block-navigation.js +8 -0
  108. package/coverage/lcov-report/constants/index.html +12 -7
  109. package/coverage/lcov-report/constants/index.js.html +55 -32
  110. package/coverage/lcov-report/constants/layouts.js.html +8 -3
  111. package/coverage/lcov-report/constants/screens.js.html +8 -3
  112. package/coverage/lcov-report/db/inMemoryView.js.html +8 -3
  113. package/coverage/lcov-report/db/index.html +8 -3
  114. package/coverage/lcov-report/db/index.js.html +9 -4
  115. package/coverage/lcov-report/db/linkedRows/LinkController.js.html +20 -15
  116. package/coverage/lcov-report/db/linkedRows/index.html +8 -3
  117. package/coverage/lcov-report/db/linkedRows/index.js.html +22 -17
  118. package/coverage/lcov-report/db/linkedRows/linkUtils.js.html +12 -7
  119. package/coverage/lcov-report/db/newid.js.html +11 -6
  120. package/coverage/lcov-report/db/utils.js.html +84 -79
  121. package/coverage/lcov-report/events/AutomationEmitter.js.html +14 -9
  122. package/coverage/lcov-report/events/index.html +8 -3
  123. package/coverage/lcov-report/events/index.js.html +9 -4
  124. package/coverage/lcov-report/events/utils.js.html +18 -13
  125. package/coverage/lcov-report/index.html +125 -120
  126. package/coverage/lcov-report/integrations/tests/TestConfiguration.js.html +8 -3
  127. package/coverage/lcov-report/integrations/tests/index.html +8 -3
  128. package/coverage/lcov-report/middleware/appInfo.js.html +8 -3
  129. package/coverage/lcov-report/middleware/builder.js.html +8 -3
  130. package/coverage/lcov-report/middleware/currentapp.js.html +65 -15
  131. package/coverage/lcov-report/middleware/index.html +25 -50
  132. package/coverage/lcov-report/middleware/joi-validator.js.html +9 -4
  133. package/coverage/lcov-report/middleware/publicApi.js.html +8 -3
  134. package/coverage/lcov-report/middleware/resourceId.js.html +8 -3
  135. package/coverage/lcov-report/middleware/selfhost.js.html +9 -4
  136. package/coverage/lcov-report/middleware/utils.js.html +8 -3
  137. package/coverage/lcov-report/sorter.js +26 -0
  138. package/coverage/lcov-report/threads/automation.js.html +581 -90
  139. package/coverage/lcov-report/threads/index.html +30 -40
  140. package/coverage/lcov-report/threads/query.js.html +9 -4
  141. package/coverage/lcov-report/threads/utils.js.html +17 -9
  142. package/coverage/lcov-report/utilities/bcrypt.js.html +8 -3
  143. package/coverage/lcov-report/utilities/budibaseDir.js.html +8 -3
  144. package/coverage/lcov-report/utilities/centralPath.js.html +8 -3
  145. package/coverage/lcov-report/utilities/csvParser.js.html +10 -5
  146. package/coverage/lcov-report/utilities/global.js.html +9 -4
  147. package/coverage/lcov-report/utilities/index.html +8 -3
  148. package/coverage/lcov-report/utilities/index.js.html +11 -6
  149. package/coverage/lcov-report/utilities/queue/inMemoryQueue.js.html +32 -9
  150. package/coverage/lcov-report/utilities/queue/index.html +12 -7
  151. package/coverage/lcov-report/utilities/routing/index.html +8 -3
  152. package/coverage/lcov-report/utilities/routing/index.js.html +8 -3
  153. package/coverage/lcov-report/utilities/rowProcessor/index.html +8 -3
  154. package/coverage/lcov-report/utilities/rowProcessor/index.js.html +48 -43
  155. package/coverage/lcov-report/utilities/rowProcessor/utils.js.html +18 -13
  156. package/coverage/lcov-report/utilities/scriptRunner.js.html +8 -3
  157. package/coverage/lcov-report/utilities/security.js.html +9 -4
  158. package/coverage/lcov-report/utilities/statusCodes.js.html +8 -3
  159. package/coverage/lcov-report/utilities/usageQuota/index.html +24 -34
  160. package/coverage/lcov-report/utilities/usageQuota/rows.js.html +44 -39
  161. package/coverage/lcov-report/utilities/usageQuota/usageQuoteReset.js.html +8 -3
  162. package/coverage/lcov-report/utilities/users.js.html +8 -3
  163. package/coverage/lcov-report/utilities/workerRequests.js.html +9 -4
  164. package/coverage/lcov.info +1144 -2875
  165. package/dist/api/controllers/application.js +145 -73
  166. package/dist/api/controllers/deploy/index.js +68 -36
  167. package/dist/api/controllers/public/applications.js +29 -9
  168. package/dist/api/controllers/public/queries.js +27 -7
  169. package/dist/api/controllers/public/rows.js +32 -12
  170. package/dist/api/controllers/public/tables.js +2 -2
  171. package/dist/api/controllers/public/users.js +8 -8
  172. package/dist/api/controllers/public/utils.js +1 -1
  173. package/dist/api/controllers/query/import/index.js +3 -3
  174. package/dist/api/controllers/query/index.js +57 -44
  175. package/dist/api/controllers/row/ExternalRequest.js +27 -27
  176. package/dist/api/controllers/row/index.js +83 -60
  177. package/dist/api/controllers/row/internal.js +2 -1
  178. package/dist/api/controllers/row/utils.js +2 -1
  179. package/dist/api/controllers/static/templates/BudibaseApp.svelte +3 -0
  180. package/dist/api/controllers/table/bulkFormula.js +2 -1
  181. package/dist/api/controllers/table/internal.js +41 -35
  182. package/dist/api/controllers/table/utils.js +271 -229
  183. package/dist/api/index.js +5 -0
  184. package/dist/api/routes/application.js +39 -13
  185. package/dist/api/routes/index.js +61 -56
  186. package/dist/api/routes/public/index.js +6 -9
  187. package/dist/api/routes/public/queries.js +1 -1
  188. package/dist/api/routes/public/rows.js +1 -1
  189. package/dist/api/routes/public/tables.js +3 -3
  190. package/dist/api/routes/public/users.js +1 -1
  191. package/dist/api/routes/row.js +43 -17
  192. package/dist/api/routes/static.js +40 -13
  193. package/dist/api/routes/tests/utilities/TestFunctions.js +75 -33
  194. package/dist/app.js +8 -4
  195. package/dist/automations/actions.js +3 -0
  196. package/dist/automations/automationUtils.js +10 -0
  197. package/dist/automations/steps/createRow.js +12 -12
  198. package/dist/automations/steps/deleteRow.js +13 -16
  199. package/dist/automations/steps/loop.js +51 -0
  200. package/dist/automations/tests/utilities/index.js +13 -11
  201. package/dist/automations/utils.js +187 -133
  202. package/dist/constants/index.js +5 -0
  203. package/dist/definitions/datasource.js +1 -0
  204. package/dist/environment.js +2 -3
  205. package/dist/index.js +4 -0
  206. package/dist/integrations/base/sql.js +2 -2
  207. package/dist/integrations/base/sqlTable.js +2 -2
  208. package/dist/integrations/googlesheets.js +1 -1
  209. package/dist/integrations/index.js +4 -0
  210. package/dist/integrations/microsoftSqlServer.js +8 -8
  211. package/dist/integrations/mysql.js +9 -9
  212. package/dist/integrations/oracle.js +7 -7
  213. package/dist/integrations/postgres.js +7 -7
  214. package/dist/integrations/queries/sql.js +2 -2
  215. package/dist/integrations/redis.js +158 -0
  216. package/dist/integrations/rest.js +1 -1
  217. package/dist/middleware/authorized.js +51 -51
  218. package/dist/middleware/currentapp.js +15 -1
  219. package/dist/migrations/functions/appUrls.js +1 -1
  220. package/dist/migrations/functions/developerQuota.js +49 -0
  221. package/dist/migrations/functions/publishedAppsQuota.js +47 -0
  222. package/dist/migrations/functions/quotas1.js +6 -2
  223. package/dist/migrations/functions/usageQuotas/index.js +0 -4
  224. package/dist/migrations/functions/usageQuotas/syncApps.js +4 -7
  225. package/dist/migrations/functions/usageQuotas/syncDevelopers.js +24 -0
  226. package/dist/migrations/functions/usageQuotas/syncPublishedApps.js +26 -0
  227. package/dist/migrations/functions/usageQuotas/syncRows.js +5 -8
  228. package/dist/migrations/index.js +17 -1
  229. package/dist/package.json +14 -8
  230. package/dist/threads/automation.js +149 -27
  231. package/dist/threads/index.js +36 -10
  232. package/dist/threads/utils.js +1 -0
  233. package/dist/tsconfig.build.tsbuildinfo +1 -0
  234. package/dist/utilities/queue/inMemoryQueue.js +6 -1
  235. package/nodemon.json +1 -1
  236. package/package.json +15 -9
  237. package/scripts/dev/manage.js +2 -0
  238. package/src/api/controllers/{application.js → application.ts} +118 -51
  239. package/src/api/controllers/deploy/{index.js → index.ts} +53 -29
  240. package/src/api/controllers/public/applications.ts +2 -2
  241. package/src/api/controllers/public/queries.ts +1 -1
  242. package/src/api/controllers/public/rows.ts +1 -1
  243. package/src/api/controllers/query/{index.js → index.ts} +51 -48
  244. package/src/api/controllers/row/ExternalRequest.ts +1 -1
  245. package/src/api/controllers/row/{index.js → index.ts} +24 -17
  246. package/src/api/controllers/row/internal.js +2 -1
  247. package/src/api/controllers/row/utils.js +4 -1
  248. package/src/api/controllers/static/templates/BudibaseApp.svelte +3 -0
  249. package/src/api/controllers/table/bulkFormula.js +1 -1
  250. package/src/api/controllers/table/{internal.js → internal.ts} +30 -26
  251. package/src/api/controllers/table/{utils.js → utils.ts} +86 -69
  252. package/src/api/index.js +5 -0
  253. package/src/api/routes/{application.js → application.ts} +8 -14
  254. package/src/api/routes/index.ts +60 -0
  255. package/src/api/routes/public/index.ts +1 -4
  256. package/src/api/routes/{row.js → row.ts} +7 -15
  257. package/src/api/routes/{static.js → static.ts} +11 -11
  258. package/src/api/routes/tests/misc.spec.js +39 -37
  259. package/src/api/routes/tests/utilities/{TestFunctions.js → TestFunctions.ts} +57 -33
  260. package/src/app.ts +1 -2
  261. package/src/automations/actions.js +3 -0
  262. package/src/automations/automationUtils.js +12 -0
  263. package/src/automations/steps/{createRow.js → createRow.ts} +9 -15
  264. package/src/automations/steps/{deleteRow.js → deleteRow.ts} +10 -16
  265. package/src/automations/steps/loop.js +50 -0
  266. package/src/automations/tests/automation.spec.js +0 -1
  267. package/src/automations/tests/{createRow.spec.js → createRow.spec.ts} +4 -15
  268. package/src/automations/tests/{deleteRow.spec.js → deleteRow.spec.ts} +3 -5
  269. package/src/automations/tests/utilities/index.js +12 -10
  270. package/src/automations/{utils.js → utils.ts} +39 -28
  271. package/src/constants/index.js +6 -0
  272. package/src/definitions/common.ts +1 -0
  273. package/src/definitions/datasource.ts +1 -0
  274. package/src/environment.js +2 -3
  275. package/src/index.ts +3 -0
  276. package/src/integrations/index.ts +4 -0
  277. package/src/integrations/redis.ts +152 -0
  278. package/src/integrations/tests/redis.spec.js +60 -0
  279. package/src/middleware/{authorized.js → authorized.ts} +20 -14
  280. package/src/middleware/currentapp.js +16 -1
  281. package/src/middleware/tests/currentapp.spec.js +8 -4
  282. package/src/migrations/functions/developerQuota.ts +15 -0
  283. package/src/migrations/functions/publishedAppsQuota.ts +13 -0
  284. package/src/migrations/functions/tests/quotas1.spec.js +0 -2
  285. package/src/migrations/functions/usageQuotas/index.ts +0 -5
  286. package/src/migrations/functions/usageQuotas/syncApps.ts +3 -6
  287. package/src/migrations/functions/usageQuotas/syncDevelopers.ts +19 -0
  288. package/src/migrations/functions/usageQuotas/syncPublishedApps.ts +21 -0
  289. package/src/migrations/functions/usageQuotas/syncRows.ts +3 -6
  290. package/src/migrations/functions/usageQuotas/tests/syncApps.spec.ts +34 -0
  291. package/src/migrations/functions/usageQuotas/tests/syncRows.spec.ts +40 -0
  292. package/src/migrations/index.ts +13 -1
  293. package/src/threads/automation.js +196 -34
  294. package/src/threads/{index.js → index.ts} +18 -14
  295. package/src/threads/utils.js +1 -0
  296. package/src/utilities/queue/inMemoryQueue.js +7 -1
  297. package/tsconfig.build.json +10 -0
  298. package/tsconfig.json +2 -2
  299. package/builder/assets/index.68a7f4e3.css +0 -6
  300. package/builder/assets/index.8d4a5b33.js +0 -1291
  301. package/coverage/lcov-report/api/controllers/application.js.html +0 -1436
  302. package/coverage/lcov-report/api/controllers/query/index.js.html +0 -713
  303. package/coverage/lcov-report/api/controllers/row/index.js.html +0 -524
  304. package/coverage/lcov-report/api/controllers/table/internal.js.html +0 -620
  305. package/coverage/lcov-report/api/controllers/table/utils.js.html +0 -1331
  306. package/coverage/lcov-report/api/routes/application.js.html +0 -179
  307. package/coverage/lcov-report/api/routes/index.js.html +0 -266
  308. package/coverage/lcov-report/api/routes/row.js.html +0 -908
  309. package/coverage/lcov-report/automations/steps/createRow.js.html +0 -380
  310. package/coverage/lcov-report/automations/steps/deleteRow.js.html +0 -347
  311. package/coverage/lcov-report/automations/utils.js.html +0 -665
  312. package/coverage/lcov-report/middleware/authorized.js.html +0 -458
  313. package/coverage/lcov-report/middleware/usageQuota.js.html +0 -572
  314. package/coverage/lcov-report/threads/index.js.html +0 -296
  315. package/coverage/lcov-report/utilities/usageQuota/index.js.html +0 -359
  316. package/dist/middleware/usageQuota.js +0 -154
  317. package/dist/tsconfig.tsbuildinfo +0 -1
  318. package/dist/utilities/usageQuota/index.js +0 -86
  319. package/src/api/routes/index.js +0 -62
  320. package/src/middleware/tests/usageQuota.spec.js +0 -120
  321. package/src/middleware/usageQuota.js +0 -164
  322. package/src/migrations/functions/usageQuotas/tests/syncApps.spec.js +0 -41
  323. package/src/migrations/functions/usageQuotas/tests/syncRows.spec.js +0 -45
  324. package/src/utilities/tests/usageQuota/usageQuota.spec.js +0 -72
  325. package/src/utilities/usageQuota/index.js +0 -93
@@ -1,29 +1,29 @@
1
- const env = require("../../environment")
2
- const packageJson = require("../../../package.json")
3
- const {
1
+ import env from "../../environment"
2
+ import packageJson from "../../../package.json"
3
+ import {
4
4
  createLinkView,
5
5
  createRoutingView,
6
6
  createAllSearchIndex,
7
- } = require("../../db/views/staticViews")
8
- const {
7
+ } from "../../db/views/staticViews"
8
+ import {
9
9
  getTemplateStream,
10
10
  createApp,
11
11
  deleteApp,
12
- } = require("../../utilities/fileSystem")
13
- const {
12
+ } from "../../utilities/fileSystem"
13
+ import {
14
14
  generateAppID,
15
15
  getLayoutParams,
16
16
  getScreenParams,
17
17
  generateDevAppID,
18
18
  DocumentTypes,
19
19
  AppStatus,
20
- } = require("../../db/utils")
20
+ } from "../../db/utils"
21
21
  const {
22
22
  BUILTIN_ROLE_IDS,
23
23
  AccessController,
24
24
  } = require("@budibase/backend-core/roles")
25
- const { BASE_LAYOUTS } = require("../../constants/layouts")
26
- const { cloneDeep } = require("lodash/fp")
25
+ import { BASE_LAYOUTS } from "../../constants/layouts"
26
+ import { cloneDeep } from "lodash/fp"
27
27
  const { processObject } = require("@budibase/string-templates")
28
28
  const {
29
29
  getAllApps,
@@ -31,24 +31,27 @@ const {
31
31
  getProdAppID,
32
32
  Replication,
33
33
  } = require("@budibase/backend-core/db")
34
- const { USERS_TABLE_SCHEMA } = require("../../constants")
35
- const { removeAppFromUserRoles } = require("../../utilities/workerRequests")
36
- const { clientLibraryPath, stringToReadStream } = require("../../utilities")
37
- const { getAllLocks } = require("../../utilities/redis")
38
- const {
34
+ import { USERS_TABLE_SCHEMA } from "../../constants"
35
+ import { removeAppFromUserRoles } from "../../utilities/workerRequests"
36
+ import { clientLibraryPath, stringToReadStream } from "../../utilities"
37
+ import { getAllLocks } from "../../utilities/redis"
38
+ import {
39
39
  updateClientLibrary,
40
40
  backupClientLibrary,
41
41
  revertClientLibrary,
42
- } = require("../../utilities/fileSystem/clientLibrary")
42
+ } from "../../utilities/fileSystem/clientLibrary"
43
43
  const { getTenantId, isMultiTenant } = require("@budibase/backend-core/tenancy")
44
- const { syncGlobalUsers } = require("./user")
44
+ import { syncGlobalUsers } from "./user"
45
45
  const { app: appCache } = require("@budibase/backend-core/cache")
46
- const { cleanupAutomations } = require("../../automations/utils")
46
+ import { cleanupAutomations } from "../../automations/utils"
47
47
  const {
48
48
  getAppDB,
49
49
  getProdAppDB,
50
50
  updateAppId,
51
51
  } = require("@budibase/backend-core/context")
52
+ import { getUniqueRows } from "../../utilities/usageQuota/rows"
53
+ import { quotas } from "@budibase/pro"
54
+ import { errors } from "@budibase/backend-core"
52
55
 
53
56
  const URL_REGEX_SLASH = /\/|\\/g
54
57
 
@@ -61,7 +64,7 @@ async function getLayouts() {
61
64
  include_docs: true,
62
65
  })
63
66
  )
64
- ).rows.map(row => row.doc)
67
+ ).rows.map((row: any) => row.doc)
65
68
  }
66
69
 
67
70
  async function getScreens() {
@@ -72,16 +75,16 @@ async function getScreens() {
72
75
  include_docs: true,
73
76
  })
74
77
  )
75
- ).rows.map(row => row.doc)
78
+ ).rows.map((row: any) => row.doc)
76
79
  }
77
80
 
78
- function getUserRoleId(ctx) {
81
+ function getUserRoleId(ctx: any) {
79
82
  return !ctx.user.role || !ctx.user.role._id
80
83
  ? BUILTIN_ROLE_IDS.PUBLIC
81
84
  : ctx.user.role._id
82
85
  }
83
86
 
84
- exports.getAppUrl = ctx => {
87
+ export const getAppUrl = (ctx: any) => {
85
88
  // construct the url
86
89
  let url
87
90
  if (ctx.request.body.url) {
@@ -97,29 +100,34 @@ exports.getAppUrl = ctx => {
97
100
  return url
98
101
  }
99
102
 
100
- const checkAppUrl = (ctx, apps, url, currentAppId) => {
103
+ const checkAppUrl = (ctx: any, apps: any, url: any, currentAppId?: string) => {
101
104
  if (currentAppId) {
102
- apps = apps.filter(app => app.appId !== currentAppId)
105
+ apps = apps.filter((app: any) => app.appId !== currentAppId)
103
106
  }
104
- if (apps.some(app => app.url === url)) {
107
+ if (apps.some((app: any) => app.url === url)) {
105
108
  ctx.throw(400, "App URL is already in use.")
106
109
  }
107
110
  }
108
111
 
109
- const checkAppName = (ctx, apps, name, currentAppId) => {
112
+ const checkAppName = (
113
+ ctx: any,
114
+ apps: any,
115
+ name: any,
116
+ currentAppId?: string
117
+ ) => {
110
118
  // TODO: Replace with Joi
111
119
  if (!name) {
112
120
  ctx.throw(400, "Name is required")
113
121
  }
114
122
  if (currentAppId) {
115
- apps = apps.filter(app => app.appId !== currentAppId)
123
+ apps = apps.filter((app: any) => app.appId !== currentAppId)
116
124
  }
117
- if (apps.some(app => app.name === name)) {
125
+ if (apps.some((app: any) => app.name === name)) {
118
126
  ctx.throw(400, "App name is already in use.")
119
127
  }
120
128
  }
121
129
 
122
- async function createInstance(template) {
130
+ async function createInstance(template: any) {
123
131
  const tenantId = isMultiTenant() ? getTenantId() : null
124
132
  const baseAppId = generateAppID(tenantId)
125
133
  const appId = generateDevAppID(baseAppId)
@@ -160,7 +168,7 @@ async function createInstance(template) {
160
168
  return { _id: appId }
161
169
  }
162
170
 
163
- exports.fetch = async ctx => {
171
+ export const fetch = async (ctx: any) => {
164
172
  const dev = ctx.query && ctx.query.status === AppStatus.DEV
165
173
  const all = ctx.query && ctx.query.status === AppStatus.ALL
166
174
  const apps = await getAllApps({ dev, all })
@@ -172,7 +180,7 @@ exports.fetch = async ctx => {
172
180
  if (app.status !== "development") {
173
181
  continue
174
182
  }
175
- const lock = locks.find(lock => lock.appId === app.appId)
183
+ const lock = locks.find((lock: any) => lock.appId === app.appId)
176
184
  if (lock) {
177
185
  app.lockedBy = lock.user
178
186
  } else {
@@ -185,7 +193,7 @@ exports.fetch = async ctx => {
185
193
  ctx.body = apps
186
194
  }
187
195
 
188
- exports.fetchAppDefinition = async ctx => {
196
+ export const fetchAppDefinition = async (ctx: any) => {
189
197
  const layouts = await getLayouts()
190
198
  const userRoleId = getUserRoleId(ctx)
191
199
  const accessController = new AccessController()
@@ -200,7 +208,7 @@ exports.fetchAppDefinition = async ctx => {
200
208
  }
201
209
  }
202
210
 
203
- exports.fetchAppPackage = async ctx => {
211
+ export const fetchAppPackage = async (ctx: any) => {
204
212
  const db = getAppDB()
205
213
  const application = await db.get(DocumentTypes.APP_METADATA)
206
214
  const layouts = await getLayouts()
@@ -221,7 +229,7 @@ exports.fetchAppPackage = async ctx => {
221
229
  }
222
230
  }
223
231
 
224
- exports.create = async ctx => {
232
+ const performAppCreate = async (ctx: any) => {
225
233
  const apps = await getAllApps({ dev: true })
226
234
  const name = ctx.request.body.name
227
235
  checkAppName(ctx, apps, name)
@@ -229,7 +237,7 @@ exports.create = async ctx => {
229
237
  checkAppUrl(ctx, apps, url)
230
238
 
231
239
  const { useTemplate, templateKey, templateString } = ctx.request.body
232
- const instanceConfig = {
240
+ const instanceConfig: any = {
233
241
  useTemplate,
234
242
  key: templateKey,
235
243
  templateString,
@@ -280,13 +288,41 @@ exports.create = async ctx => {
280
288
  }
281
289
 
282
290
  await appCache.invalidateAppMetadata(appId, newApplication)
283
- ctx.status = 200
291
+ return newApplication
292
+ }
293
+
294
+ const appPostCreate = async (ctx: any, appId: string) => {
295
+ // app import & template creation
296
+ if (ctx.request.body.useTemplate === "true") {
297
+ const rows = await getUniqueRows([appId])
298
+ const rowCount = rows ? rows.length : 0
299
+ if (rowCount) {
300
+ try {
301
+ await quotas.addRows(rowCount)
302
+ } catch (err: any) {
303
+ if (err.code && err.code === errors.codes.USAGE_LIMIT_EXCEEDED) {
304
+ // this import resulted in row usage exceeding the quota
305
+ // delete the app
306
+ // skip pre and post steps as no rows have been added to quotas yet
307
+ ctx.params.appId = appId
308
+ await destroyApp(ctx)
309
+ }
310
+ throw err
311
+ }
312
+ }
313
+ }
314
+ }
315
+
316
+ export const create = async (ctx: any) => {
317
+ const newApplication = await quotas.addApp(() => performAppCreate(ctx))
318
+ await appPostCreate(ctx, newApplication.appId)
284
319
  ctx.body = newApplication
320
+ ctx.status = 200
285
321
  }
286
322
 
287
323
  // This endpoint currently operates as a PATCH rather than a PUT
288
324
  // Thus name and url fields are handled only if present
289
- exports.update = async ctx => {
325
+ export const update = async (ctx: any) => {
290
326
  const apps = await getAllApps({ dev: true })
291
327
  // validation
292
328
  const name = ctx.request.body.name
@@ -304,7 +340,7 @@ exports.update = async ctx => {
304
340
  ctx.body = data
305
341
  }
306
342
 
307
- exports.updateClient = async ctx => {
343
+ export const updateClient = async (ctx: any) => {
308
344
  // Get current app version
309
345
  const db = getAppDB()
310
346
  const application = await db.get(DocumentTypes.APP_METADATA)
@@ -326,7 +362,7 @@ exports.updateClient = async ctx => {
326
362
  ctx.body = data
327
363
  }
328
364
 
329
- exports.revertClient = async ctx => {
365
+ export const revertClient = async (ctx: any) => {
330
366
  // Check app can be reverted
331
367
  const db = getAppDB()
332
368
  const application = await db.get(DocumentTypes.APP_METADATA)
@@ -349,26 +385,57 @@ exports.revertClient = async ctx => {
349
385
  ctx.body = data
350
386
  }
351
387
 
352
- exports.delete = async ctx => {
353
- const db = getAppDB()
388
+ const destroyApp = async (ctx: any) => {
389
+ let appId = ctx.params.appId
390
+ let isUnpublish = ctx.query && ctx.query.unpublish
354
391
 
392
+ if (isUnpublish) {
393
+ appId = getProdAppID(appId)
394
+ }
395
+
396
+ const db = isUnpublish ? getProdAppDB() : getAppDB()
355
397
  const result = await db.destroy()
398
+
399
+ if (isUnpublish) {
400
+ await quotas.removePublishedApp()
401
+ } else {
402
+ await quotas.removeApp()
403
+ }
404
+
356
405
  /* istanbul ignore next */
357
- if (!env.isTest() && !ctx.query.unpublish) {
358
- await deleteApp(ctx.params.appId)
406
+ if (!env.isTest() && !isUnpublish) {
407
+ await deleteApp(appId)
359
408
  }
360
- if (ctx.query && ctx.query.unpublish) {
361
- await cleanupAutomations(ctx.params.appId)
409
+ if (isUnpublish) {
410
+ await cleanupAutomations(appId)
362
411
  }
363
412
  // make sure the app/role doesn't stick around after the app has been deleted
364
- await removeAppFromUserRoles(ctx, ctx.params.appId)
365
- await appCache.invalidateAppMetadata(ctx.params.appId)
413
+ await removeAppFromUserRoles(ctx, appId)
414
+ await appCache.invalidateAppMetadata(appId)
415
+ return result
416
+ }
417
+
418
+ const preDestroyApp = async (ctx: any) => {
419
+ const rows = await getUniqueRows([ctx.params.appId])
420
+ ctx.rowCount = rows.length
421
+ }
422
+
423
+ const postDestroyApp = async (ctx: any) => {
424
+ const rowCount = ctx.rowCount
425
+ if (rowCount) {
426
+ await quotas.removeRows(rowCount)
427
+ }
428
+ }
366
429
 
430
+ export const destroy = async (ctx: any) => {
431
+ await preDestroyApp(ctx)
432
+ const result = await destroyApp(ctx)
433
+ await postDestroyApp(ctx)
367
434
  ctx.status = 200
368
435
  ctx.body = result
369
436
  }
370
437
 
371
- exports.sync = async (ctx, next) => {
438
+ export const sync = async (ctx: any, next: any) => {
372
439
  const appId = ctx.params.appId
373
440
  if (!isDevAppID(appId)) {
374
441
  ctx.throw(400, "This action cannot be performed for production apps")
@@ -398,7 +465,7 @@ exports.sync = async (ctx, next) => {
398
465
  let error
399
466
  try {
400
467
  await replication.replicate({
401
- filter: function (doc) {
468
+ filter: function (doc: any) {
402
469
  return doc._id !== DocumentTypes.APP_METADATA
403
470
  },
404
471
  })
@@ -420,7 +487,7 @@ exports.sync = async (ctx, next) => {
420
487
  }
421
488
  }
422
489
 
423
- const updateAppPackage = async (appPackage, appId) => {
490
+ const updateAppPackage = async (appPackage: any, appId: any) => {
424
491
  const db = getAppDB()
425
492
  const application = await db.get(DocumentTypes.APP_METADATA)
426
493
 
@@ -439,7 +506,7 @@ const updateAppPackage = async (appPackage, appId) => {
439
506
  return response
440
507
  }
441
508
 
442
- const createEmptyAppPackage = async (ctx, app) => {
509
+ const createEmptyAppPackage = async (ctx: any, app: any) => {
443
510
  const db = getAppDB()
444
511
 
445
512
  let screensAndLayouts = []
@@ -1,20 +1,18 @@
1
- const Deployment = require("./Deployment")
2
- const {
1
+ import Deployment from "./Deployment"
2
+ import {
3
3
  Replication,
4
4
  getProdAppID,
5
5
  getDevelopmentAppID,
6
- } = require("@budibase/backend-core/db")
7
- const { DocumentTypes, getAutomationParams } = require("../../../db/utils")
8
- const {
9
- disableAllCrons,
10
- enableCronTrigger,
11
- } = require("../../../automations/utils")
12
- const { app: appCache } = require("@budibase/backend-core/cache")
13
- const {
6
+ } from "@budibase/backend-core/db"
7
+ import { DocumentTypes, getAutomationParams } from "../../../db/utils"
8
+ import { disableAllCrons, enableCronTrigger } from "../../../automations/utils"
9
+ import { app as appCache } from "@budibase/backend-core/cache"
10
+ import {
14
11
  getAppId,
15
12
  getAppDB,
16
13
  getProdAppDB,
17
- } = require("@budibase/backend-core/context")
14
+ } from "@budibase/backend-core/context"
15
+ import { quotas } from "@budibase/pro"
18
16
 
19
17
  // the max time we can wait for an invalidation to complete before considering it failed
20
18
  const MAX_PENDING_TIME_MS = 30 * 60000
@@ -25,9 +23,10 @@ const DeploymentStatus = {
25
23
  }
26
24
 
27
25
  // checks that deployments are in a good state, any pending will be updated
28
- async function checkAllDeployments(deployments) {
26
+ async function checkAllDeployments(deployments: any) {
29
27
  let updated = false
30
- for (let deployment of Object.values(deployments.history)) {
28
+ let deployment: any
29
+ for (deployment of Object.values(deployments.history)) {
31
30
  // check that no deployments have crashed etc and are now stuck
32
31
  if (
33
32
  deployment.status === DeploymentStatus.PENDING &&
@@ -41,7 +40,7 @@ async function checkAllDeployments(deployments) {
41
40
  return { updated, deployments }
42
41
  }
43
42
 
44
- async function storeDeploymentHistory(deployment) {
43
+ async function storeDeploymentHistory(deployment: any) {
45
44
  const deploymentJSON = deployment.getJSON()
46
45
  const db = getAppDB()
47
46
 
@@ -70,7 +69,7 @@ async function storeDeploymentHistory(deployment) {
70
69
  return deployment
71
70
  }
72
71
 
73
- async function initDeployedApp(prodAppId) {
72
+ async function initDeployedApp(prodAppId: any) {
74
73
  const db = getProdAppDB()
75
74
  console.log("Reading automation docs")
76
75
  const automations = (
@@ -79,7 +78,7 @@ async function initDeployedApp(prodAppId) {
79
78
  include_docs: true,
80
79
  })
81
80
  )
82
- ).rows.map(row => row.doc)
81
+ ).rows.map((row: any) => row.doc)
83
82
  console.log("You have " + automations.length + " automations")
84
83
  const promises = []
85
84
  console.log("Disabling prod crons..")
@@ -93,21 +92,27 @@ async function initDeployedApp(prodAppId) {
93
92
  console.log("Enabled cron triggers for deployed app..")
94
93
  }
95
94
 
96
- async function deployApp(deployment) {
95
+ async function deployApp(deployment: any) {
97
96
  let replication
98
97
  try {
99
98
  const appId = getAppId()
100
99
  const devAppId = getDevelopmentAppID(appId)
101
100
  const productionAppId = getProdAppID(appId)
102
- replication = new Replication({
101
+
102
+ const config: any = {
103
103
  source: devAppId,
104
104
  target: productionAppId,
105
- })
105
+ }
106
+ replication = new Replication(config)
107
+
106
108
  console.log("Replication object created")
107
109
  await replication.replicate()
108
110
  console.log("replication complete.. replacing app meta doc")
109
111
  const db = getProdAppDB()
110
112
  const appDoc = await db.get(DocumentTypes.APP_METADATA)
113
+
114
+ deployment.appUrl = appDoc.url
115
+
111
116
  appDoc.appId = productionAppId
112
117
  appDoc.instance._id = productionAppId
113
118
  await db.put(appDoc)
@@ -117,7 +122,7 @@ async function deployApp(deployment) {
117
122
  console.log("Deployed app initialised, setting deployment to successful")
118
123
  deployment.setStatus(DeploymentStatus.SUCCESS)
119
124
  await storeDeploymentHistory(deployment)
120
- } catch (err) {
125
+ } catch (err: any) {
121
126
  deployment.setStatus(DeploymentStatus.FAILURE, err.message)
122
127
  await storeDeploymentHistory(deployment)
123
128
  throw {
@@ -125,18 +130,17 @@ async function deployApp(deployment) {
125
130
  message: `Deployment Failed: ${err.message}`,
126
131
  }
127
132
  } finally {
128
- await replication.close()
133
+ if (replication) {
134
+ await replication.close()
135
+ }
129
136
  }
130
137
  }
131
138
 
132
- exports.fetchDeployments = async function (ctx) {
139
+ export async function fetchDeployments(ctx: any) {
133
140
  try {
134
141
  const db = getAppDB()
135
142
  const deploymentDoc = await db.get(DocumentTypes.DEPLOYMENTS)
136
- const { updated, deployments } = await checkAllDeployments(
137
- deploymentDoc,
138
- ctx.user
139
- )
143
+ const { updated, deployments } = await checkAllDeployments(deploymentDoc)
140
144
  if (updated) {
141
145
  await db.put(deployments)
142
146
  }
@@ -146,7 +150,7 @@ exports.fetchDeployments = async function (ctx) {
146
150
  }
147
151
  }
148
152
 
149
- exports.deploymentProgress = async function (ctx) {
153
+ export async function deploymentProgress(ctx: any) {
150
154
  try {
151
155
  const db = getAppDB()
152
156
  const deploymentDoc = await db.get(DocumentTypes.DEPLOYMENTS)
@@ -159,7 +163,20 @@ exports.deploymentProgress = async function (ctx) {
159
163
  }
160
164
  }
161
165
 
162
- exports.deployApp = async function (ctx) {
166
+ const isFirstDeploy = async () => {
167
+ try {
168
+ const db = getProdAppDB()
169
+ await db.get(DocumentTypes.APP_METADATA)
170
+ } catch (e: any) {
171
+ if (e.status === 404) {
172
+ return true
173
+ }
174
+ throw e
175
+ }
176
+ return false
177
+ }
178
+
179
+ const _deployApp = async function (ctx: any) {
163
180
  let deployment = new Deployment()
164
181
  console.log("Deployment object created")
165
182
  deployment.setStatus(DeploymentStatus.PENDING)
@@ -168,7 +185,14 @@ exports.deployApp = async function (ctx) {
168
185
  console.log("Stored deployment history")
169
186
 
170
187
  console.log("Deploying app...")
171
- await deployApp(deployment)
188
+
189
+ if (await isFirstDeploy()) {
190
+ await quotas.addPublishedApp(() => deployApp(deployment))
191
+ } else {
192
+ await deployApp(deployment)
193
+ }
172
194
 
173
195
  ctx.body = deployment
174
196
  }
197
+
198
+ export { _deployApp as deployApp }
@@ -1,7 +1,7 @@
1
1
  const { getAllApps } = require("@budibase/backend-core/db")
2
2
  const { updateAppId } = require("@budibase/backend-core/context")
3
3
  import { search as stringSearch } from "./utils"
4
- import { default as controller } from "../application"
4
+ import * as controller from "../application"
5
5
  import { Application } from "../../../definitions/common"
6
6
 
7
7
  function fixAppID(app: Application, params: any) {
@@ -59,7 +59,7 @@ export async function destroy(ctx: any, next: any) {
59
59
  // get the app before deleting it
60
60
  await setResponseApp(ctx)
61
61
  const body = ctx.body
62
- await controller.delete(ctx)
62
+ await controller.destroy(ctx)
63
63
  // overwrite the body again
64
64
  ctx.body = body
65
65
  await next()
@@ -1,5 +1,5 @@
1
1
  import { search as stringSearch } from "./utils"
2
- import { default as queryController } from "../query"
2
+ import * as queryController from "../query"
3
3
 
4
4
  export async function search(ctx: any, next: any) {
5
5
  await queryController.fetch(ctx)
@@ -1,4 +1,4 @@
1
- import { default as rowController } from "../row"
1
+ import * as rowController from "../row"
2
2
  import { addRev } from "./utils"
3
3
  import { Row } from "../../../definitions/common"
4
4
  import { convertBookmark } from "../../../utilities"