@budibase/server 1.0.105-alpha.21 → 1.0.105-alpha.24

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 (292) hide show
  1. package/builder/assets/{index.8d922c8c.js → index.06b1c616.js} +150 -147
  2. package/builder/assets/{index.b7e0672d.css → index.e3fb1cb4.css} +2 -2
  3. package/builder/index.html +2 -2
  4. package/coverage/clover.xml +517 -1564
  5. package/coverage/coverage-final.json +27 -43
  6. package/coverage/lcov-report/api/controllers/analytics.js.html +8 -3
  7. package/coverage/lcov-report/api/controllers/apikeys.js.html +9 -4
  8. package/coverage/lcov-report/api/controllers/auth.js.html +8 -3
  9. package/coverage/lcov-report/api/controllers/automation.js.html +8 -3
  10. package/coverage/lcov-report/api/controllers/backup.js.html +8 -3
  11. package/coverage/lcov-report/api/controllers/cloud.js.html +8 -3
  12. package/coverage/lcov-report/api/controllers/component.js.html +8 -3
  13. package/coverage/lcov-report/api/controllers/datasource.js.html +11 -6
  14. package/coverage/lcov-report/api/controllers/dev.js.html +8 -3
  15. package/coverage/lcov-report/api/controllers/index.html +16 -26
  16. package/coverage/lcov-report/api/controllers/integration.js.html +8 -3
  17. package/coverage/lcov-report/api/controllers/layout.js.html +8 -3
  18. package/coverage/lcov-report/api/controllers/metadata.js.html +8 -3
  19. package/coverage/lcov-report/api/controllers/migrations.js.html +8 -3
  20. package/coverage/lcov-report/api/controllers/permission.js.html +8 -3
  21. package/coverage/lcov-report/api/controllers/query/index.html +16 -26
  22. package/coverage/lcov-report/api/controllers/query/validation.js.html +8 -3
  23. package/coverage/lcov-report/api/controllers/role.js.html +10 -5
  24. package/coverage/lcov-report/api/controllers/routing.js.html +9 -4
  25. package/coverage/lcov-report/api/controllers/row/external.js.html +8 -3
  26. package/coverage/lcov-report/api/controllers/row/index.html +23 -33
  27. package/coverage/lcov-report/api/controllers/row/internal.js.html +32 -24
  28. package/coverage/lcov-report/api/controllers/row/internalSearch.js.html +21 -16
  29. package/coverage/lcov-report/api/controllers/row/staticFormula.js.html +24 -19
  30. package/coverage/lcov-report/api/controllers/row/utils.js.html +20 -15
  31. package/coverage/lcov-report/api/controllers/screen.js.html +9 -4
  32. package/coverage/lcov-report/api/controllers/script.js.html +8 -3
  33. package/coverage/lcov-report/api/controllers/table/bulkFormula.js.html +52 -47
  34. package/coverage/lcov-report/api/controllers/table/external.js.html +8 -3
  35. package/coverage/lcov-report/api/controllers/table/index.html +17 -42
  36. package/coverage/lcov-report/api/controllers/table/index.js.html +20 -15
  37. package/coverage/lcov-report/api/controllers/templates.js.html +8 -3
  38. package/coverage/lcov-report/api/controllers/user.js.html +8 -3
  39. package/coverage/lcov-report/api/controllers/view/exporters.js.html +8 -3
  40. package/coverage/lcov-report/api/controllers/view/index.html +8 -3
  41. package/coverage/lcov-report/api/controllers/view/index.js.html +10 -5
  42. package/coverage/lcov-report/api/controllers/view/utils.js.html +8 -3
  43. package/coverage/lcov-report/api/controllers/view/viewBuilder.js.html +8 -3
  44. package/coverage/lcov-report/api/controllers/webhook.js.html +10 -5
  45. package/coverage/lcov-report/api/index.html +18 -13
  46. package/coverage/lcov-report/api/index.js.html +28 -8
  47. package/coverage/lcov-report/api/routes/analytics.js.html +8 -3
  48. package/coverage/lcov-report/api/routes/apikeys.js.html +8 -3
  49. package/coverage/lcov-report/api/routes/auth.js.html +8 -3
  50. package/coverage/lcov-report/api/routes/automation.js.html +8 -3
  51. package/coverage/lcov-report/api/routes/backup.js.html +8 -3
  52. package/coverage/lcov-report/api/routes/cloud.js.html +8 -3
  53. package/coverage/lcov-report/api/routes/component.js.html +8 -3
  54. package/coverage/lcov-report/api/routes/datasource.js.html +8 -3
  55. package/coverage/lcov-report/api/routes/deploy.js.html +8 -3
  56. package/coverage/lcov-report/api/routes/dev.js.html +9 -4
  57. package/coverage/lcov-report/api/routes/index.html +13 -68
  58. package/coverage/lcov-report/api/routes/integration.js.html +8 -3
  59. package/coverage/lcov-report/api/routes/layout.js.html +8 -3
  60. package/coverage/lcov-report/api/routes/metadata.js.html +8 -3
  61. package/coverage/lcov-report/api/routes/migrations.js.html +8 -3
  62. package/coverage/lcov-report/api/routes/permission.js.html +8 -3
  63. package/coverage/lcov-report/api/routes/query.js.html +8 -3
  64. package/coverage/lcov-report/api/routes/role.js.html +8 -3
  65. package/coverage/lcov-report/api/routes/routing.js.html +8 -3
  66. package/coverage/lcov-report/api/routes/screen.js.html +8 -3
  67. package/coverage/lcov-report/api/routes/script.js.html +8 -3
  68. package/coverage/lcov-report/api/routes/table.js.html +8 -3
  69. package/coverage/lcov-report/api/routes/templates.js.html +8 -3
  70. package/coverage/lcov-report/api/routes/user.js.html +8 -3
  71. package/coverage/lcov-report/api/routes/utils/index.html +8 -3
  72. package/coverage/lcov-report/api/routes/utils/validators.js.html +8 -3
  73. package/coverage/lcov-report/api/routes/view.js.html +8 -3
  74. package/coverage/lcov-report/api/routes/webhook.js.html +8 -3
  75. package/coverage/lcov-report/automations/actions.js.html +9 -4
  76. package/coverage/lcov-report/automations/automationUtils.js.html +20 -15
  77. package/coverage/lcov-report/automations/bullboard.js.html +8 -3
  78. package/coverage/lcov-report/automations/index.html +16 -26
  79. package/coverage/lcov-report/automations/index.js.html +8 -3
  80. package/coverage/lcov-report/automations/steps/bash.js.html +8 -3
  81. package/coverage/lcov-report/automations/steps/delay.js.html +8 -3
  82. package/coverage/lcov-report/automations/steps/discord.js.html +8 -3
  83. package/coverage/lcov-report/automations/steps/executeQuery.js.html +8 -3
  84. package/coverage/lcov-report/automations/steps/executeScript.js.html +8 -3
  85. package/coverage/lcov-report/automations/steps/filter.js.html +8 -3
  86. package/coverage/lcov-report/automations/steps/index.html +16 -41
  87. package/coverage/lcov-report/automations/steps/integromat.js.html +8 -3
  88. package/coverage/lcov-report/automations/steps/loop.js.html +8 -3
  89. package/coverage/lcov-report/automations/steps/outgoingWebhook.js.html +9 -4
  90. package/coverage/lcov-report/automations/steps/queryRows.js.html +9 -4
  91. package/coverage/lcov-report/automations/steps/sendSmtpEmail.js.html +8 -3
  92. package/coverage/lcov-report/automations/steps/serverLog.js.html +8 -3
  93. package/coverage/lcov-report/automations/steps/slack.js.html +8 -3
  94. package/coverage/lcov-report/automations/steps/updateRow.js.html +8 -3
  95. package/coverage/lcov-report/automations/steps/utils.js.html +14 -9
  96. package/coverage/lcov-report/automations/steps/zapier.js.html +8 -3
  97. package/coverage/lcov-report/automations/triggerInfo/app.js.html +8 -3
  98. package/coverage/lcov-report/automations/triggerInfo/cron.js.html +8 -3
  99. package/coverage/lcov-report/automations/triggerInfo/index.html +8 -3
  100. package/coverage/lcov-report/automations/triggerInfo/index.js.html +8 -3
  101. package/coverage/lcov-report/automations/triggerInfo/rowDeleted.js.html +8 -3
  102. package/coverage/lcov-report/automations/triggerInfo/rowSaved.js.html +8 -3
  103. package/coverage/lcov-report/automations/triggerInfo/rowUpdated.js.html +8 -3
  104. package/coverage/lcov-report/automations/triggerInfo/webhook.js.html +8 -3
  105. package/coverage/lcov-report/automations/triggers.js.html +16 -11
  106. package/coverage/lcov-report/block-navigation.js +8 -0
  107. package/coverage/lcov-report/constants/index.html +8 -3
  108. package/coverage/lcov-report/constants/index.js.html +35 -30
  109. package/coverage/lcov-report/constants/layouts.js.html +8 -3
  110. package/coverage/lcov-report/constants/screens.js.html +8 -3
  111. package/coverage/lcov-report/db/client.js.html +26 -21
  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 +10 -5
  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 +83 -78
  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 +122 -117
  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 +11 -6
  131. package/coverage/lcov-report/middleware/index.html +16 -41
  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 +55 -50
  139. package/coverage/lcov-report/threads/index.html +16 -26
  140. package/coverage/lcov-report/threads/query.js.html +10 -5
  141. package/coverage/lcov-report/threads/utils.js.html +11 -6
  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 +46 -41
  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 +45 -40
  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 +759 -2599
  165. package/dist/api/controllers/application.js +138 -70
  166. package/dist/api/controllers/deploy/index.js +64 -35
  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/table/internal.js +40 -34
  179. package/dist/api/controllers/table/utils.js +271 -229
  180. package/dist/api/index.js +5 -0
  181. package/dist/api/routes/application.js +39 -13
  182. package/dist/api/routes/index.js +61 -56
  183. package/dist/api/routes/public/index.js +6 -9
  184. package/dist/api/routes/public/queries.js +1 -1
  185. package/dist/api/routes/public/rows.js +1 -1
  186. package/dist/api/routes/public/tables.js +3 -3
  187. package/dist/api/routes/public/users.js +1 -1
  188. package/dist/api/routes/row.js +43 -17
  189. package/dist/api/routes/static.js +40 -13
  190. package/dist/api/routes/tests/utilities/TestFunctions.js +62 -26
  191. package/dist/app.js +11 -4
  192. package/dist/automations/steps/createRow.js +12 -12
  193. package/dist/automations/steps/deleteRow.js +13 -16
  194. package/dist/automations/tests/utilities/index.js +0 -2
  195. package/dist/automations/utils.js +187 -132
  196. package/dist/environment.js +0 -2
  197. package/dist/integrations/base/sql.js +2 -2
  198. package/dist/integrations/base/sqlTable.js +2 -2
  199. package/dist/integrations/googlesheets.js +1 -1
  200. package/dist/integrations/microsoftSqlServer.js +8 -8
  201. package/dist/integrations/mysql.js +9 -9
  202. package/dist/integrations/oracle.js +7 -7
  203. package/dist/integrations/postgres.js +7 -7
  204. package/dist/integrations/rest.js +1 -1
  205. package/dist/middleware/authorized.js +51 -51
  206. package/dist/migrations/functions/appUrls.js +1 -1
  207. package/dist/migrations/functions/developerQuota.js +49 -0
  208. package/dist/migrations/functions/publishedAppsQuota.js +47 -0
  209. package/dist/migrations/functions/quotas1.js +6 -2
  210. package/dist/migrations/functions/usageQuotas/index.js +0 -4
  211. package/dist/migrations/functions/usageQuotas/syncApps.js +4 -7
  212. package/dist/migrations/functions/usageQuotas/syncDevelopers.js +24 -0
  213. package/dist/migrations/functions/usageQuotas/syncPublishedApps.js +26 -0
  214. package/dist/migrations/functions/usageQuotas/syncRows.js +5 -8
  215. package/dist/migrations/index.js +17 -1
  216. package/dist/package.json +10 -8
  217. package/dist/threads/index.js +35 -8
  218. package/dist/tsconfig.build.tsbuildinfo +1 -0
  219. package/dist/utilities/queue/inMemoryQueue.js +6 -1
  220. package/nodemon.json +1 -1
  221. package/package.json +11 -9
  222. package/scripts/dev/manage.js +2 -0
  223. package/src/api/controllers/{application.js → application.ts} +103 -44
  224. package/src/api/controllers/deploy/{index.js → index.ts} +45 -28
  225. package/src/api/controllers/public/applications.ts +2 -2
  226. package/src/api/controllers/public/queries.ts +1 -1
  227. package/src/api/controllers/public/rows.ts +1 -1
  228. package/src/api/controllers/query/{index.js → index.ts} +51 -48
  229. package/src/api/controllers/row/ExternalRequest.ts +1 -1
  230. package/src/api/controllers/row/{index.js → index.ts} +24 -17
  231. package/src/api/controllers/row/internal.js +2 -1
  232. package/src/api/controllers/table/{internal.js → internal.ts} +27 -24
  233. package/src/api/controllers/table/{utils.js → utils.ts} +86 -69
  234. package/src/api/index.js +5 -0
  235. package/src/api/routes/{application.js → application.ts} +8 -14
  236. package/src/api/routes/index.ts +60 -0
  237. package/src/api/routes/public/index.ts +1 -4
  238. package/src/api/routes/{row.js → row.ts} +7 -15
  239. package/src/api/routes/{static.js → static.ts} +11 -11
  240. package/src/api/routes/tests/utilities/{TestFunctions.js → TestFunctions.ts} +42 -25
  241. package/src/app.ts +1 -2
  242. package/src/automations/steps/{createRow.js → createRow.ts} +9 -15
  243. package/src/automations/steps/{deleteRow.js → deleteRow.ts} +10 -16
  244. package/src/automations/tests/automation.spec.js +0 -1
  245. package/src/automations/tests/{createRow.spec.js → createRow.spec.ts} +4 -15
  246. package/src/automations/tests/{deleteRow.spec.js → deleteRow.spec.ts} +3 -5
  247. package/src/automations/tests/utilities/index.js +0 -2
  248. package/src/automations/{utils.js → utils.ts} +39 -27
  249. package/src/environment.js +0 -2
  250. package/src/middleware/{authorized.js → authorized.ts} +20 -14
  251. package/src/migrations/functions/developerQuota.ts +15 -0
  252. package/src/migrations/functions/publishedAppsQuota.ts +13 -0
  253. package/src/migrations/functions/tests/quotas1.spec.js +0 -2
  254. package/src/migrations/functions/usageQuotas/index.ts +0 -5
  255. package/src/migrations/functions/usageQuotas/syncApps.ts +3 -6
  256. package/src/migrations/functions/usageQuotas/syncDevelopers.ts +19 -0
  257. package/src/migrations/functions/usageQuotas/syncPublishedApps.ts +21 -0
  258. package/src/migrations/functions/usageQuotas/syncRows.ts +3 -6
  259. package/src/migrations/functions/usageQuotas/tests/syncApps.spec.ts +32 -0
  260. package/src/migrations/functions/usageQuotas/tests/syncRows.spec.ts +38 -0
  261. package/src/migrations/index.ts +13 -1
  262. package/src/module.d.ts +4 -0
  263. package/src/threads/{index.js → index.ts} +14 -12
  264. package/src/utilities/queue/inMemoryQueue.js +7 -1
  265. package/tsconfig.build.json +10 -0
  266. package/tsconfig.json +2 -2
  267. package/coverage/lcov-report/api/controllers/application.js.html +0 -1430
  268. package/coverage/lcov-report/api/controllers/query/index.js.html +0 -713
  269. package/coverage/lcov-report/api/controllers/row/index.js.html +0 -524
  270. package/coverage/lcov-report/api/controllers/table/internal.js.html +0 -548
  271. package/coverage/lcov-report/api/controllers/table/utils.js.html +0 -1331
  272. package/coverage/lcov-report/api/routes/application.js.html +0 -179
  273. package/coverage/lcov-report/api/routes/index.js.html +0 -266
  274. package/coverage/lcov-report/api/routes/row.js.html +0 -908
  275. package/coverage/lcov-report/api/routes/static.js.html +0 -245
  276. package/coverage/lcov-report/automations/steps/createRow.js.html +0 -380
  277. package/coverage/lcov-report/automations/steps/deleteRow.js.html +0 -347
  278. package/coverage/lcov-report/automations/utils.js.html +0 -662
  279. package/coverage/lcov-report/middleware/authorized.js.html +0 -458
  280. package/coverage/lcov-report/middleware/usageQuota.js.html +0 -572
  281. package/coverage/lcov-report/threads/index.js.html +0 -278
  282. package/coverage/lcov-report/utilities/usageQuota/index.js.html +0 -359
  283. package/dist/middleware/usageQuota.js +0 -154
  284. package/dist/tsconfig.tsbuildinfo +0 -1
  285. package/dist/utilities/usageQuota/index.js +0 -86
  286. package/src/api/routes/index.js +0 -62
  287. package/src/middleware/tests/usageQuota.spec.js +0 -134
  288. package/src/middleware/usageQuota.js +0 -164
  289. package/src/migrations/functions/usageQuotas/tests/syncApps.spec.js +0 -37
  290. package/src/migrations/functions/usageQuotas/tests/syncRows.spec.js +0 -43
  291. package/src/utilities/tests/usageQuota/usageQuota.spec.js +0 -72
  292. 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,10 +385,15 @@ exports.revertClient = async ctx => {
349
385
  ctx.body = data
350
386
  }
351
387
 
352
- exports.delete = async ctx => {
388
+ const destroyApp = async (ctx: any) => {
353
389
  const db = getAppDB()
354
390
 
355
391
  const result = await db.destroy()
392
+ if (ctx.query?.unpublish) {
393
+ await quotas.removePublishedApp()
394
+ } else {
395
+ await quotas.removeApp()
396
+ }
356
397
  /* istanbul ignore next */
357
398
  if (!env.isTest() && !ctx.query.unpublish) {
358
399
  await deleteApp(ctx.params.appId)
@@ -363,12 +404,30 @@ exports.delete = async ctx => {
363
404
  // make sure the app/role doesn't stick around after the app has been deleted
364
405
  await removeAppFromUserRoles(ctx, ctx.params.appId)
365
406
  await appCache.invalidateAppMetadata(ctx.params.appId)
407
+ return result
408
+ }
409
+
410
+ const preDestroyApp = async (ctx: any) => {
411
+ const rows = await getUniqueRows([ctx.params.appId])
412
+ ctx.rowCount = rows.length
413
+ }
414
+
415
+ const postDestroyApp = async (ctx: any) => {
416
+ const rowCount = ctx.rowCount
417
+ if (rowCount) {
418
+ await quotas.removeRows(rowCount)
419
+ }
420
+ }
366
421
 
422
+ export const destroy = async (ctx: any) => {
423
+ await preDestroyApp(ctx)
424
+ const result = await destroyApp(ctx)
425
+ await postDestroyApp(ctx)
367
426
  ctx.status = 200
368
427
  ctx.body = result
369
428
  }
370
429
 
371
- exports.sync = async (ctx, next) => {
430
+ export const sync = async (ctx: any, next: any) => {
372
431
  const appId = ctx.params.appId
373
432
  if (!isDevAppID(appId)) {
374
433
  ctx.throw(400, "This action cannot be performed for production apps")
@@ -398,7 +457,7 @@ exports.sync = async (ctx, next) => {
398
457
  let error
399
458
  try {
400
459
  await replication.replicate({
401
- filter: function (doc) {
460
+ filter: function (doc: any) {
402
461
  return doc._id !== DocumentTypes.APP_METADATA
403
462
  },
404
463
  })
@@ -418,7 +477,7 @@ exports.sync = async (ctx, next) => {
418
477
  }
419
478
  }
420
479
 
421
- const updateAppPackage = async (appPackage, appId) => {
480
+ const updateAppPackage = async (appPackage: any, appId: any) => {
422
481
  const db = getAppDB()
423
482
  const application = await db.get(DocumentTypes.APP_METADATA)
424
483
 
@@ -437,7 +496,7 @@ const updateAppPackage = async (appPackage, appId) => {
437
496
  return response
438
497
  }
439
498
 
440
- const createEmptyAppPackage = async (ctx, app) => {
499
+ const createEmptyAppPackage = async (ctx: any, app: any) => {
441
500
  const db = getAppDB()
442
501
 
443
502
  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,16 +92,17 @@ 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
  try {
98
97
  const appId = getAppId()
99
98
  const devAppId = getDevelopmentAppID(appId)
100
99
  const productionAppId = getProdAppID(appId)
101
100
 
102
- const replication = new Replication({
101
+ const config: any = {
103
102
  source: devAppId,
104
103
  target: productionAppId,
105
- })
104
+ }
105
+ const replication = new Replication(config)
106
106
 
107
107
  console.log("Replication object created")
108
108
 
@@ -119,7 +119,7 @@ async function deployApp(deployment) {
119
119
  console.log("Deployed app initialised, setting deployment to successful")
120
120
  deployment.setStatus(DeploymentStatus.SUCCESS)
121
121
  await storeDeploymentHistory(deployment)
122
- } catch (err) {
122
+ } catch (err: any) {
123
123
  deployment.setStatus(DeploymentStatus.FAILURE, err.message)
124
124
  await storeDeploymentHistory(deployment)
125
125
  throw {
@@ -129,14 +129,11 @@ async function deployApp(deployment) {
129
129
  }
130
130
  }
131
131
 
132
- exports.fetchDeployments = async function (ctx) {
132
+ export async function fetchDeployments(ctx: any) {
133
133
  try {
134
134
  const db = getAppDB()
135
135
  const deploymentDoc = await db.get(DocumentTypes.DEPLOYMENTS)
136
- const { updated, deployments } = await checkAllDeployments(
137
- deploymentDoc,
138
- ctx.user
139
- )
136
+ const { updated, deployments } = await checkAllDeployments(deploymentDoc)
140
137
  if (updated) {
141
138
  await db.put(deployments)
142
139
  }
@@ -146,7 +143,7 @@ exports.fetchDeployments = async function (ctx) {
146
143
  }
147
144
  }
148
145
 
149
- exports.deploymentProgress = async function (ctx) {
146
+ export async function deploymentProgress(ctx: any) {
150
147
  try {
151
148
  const db = getAppDB()
152
149
  const deploymentDoc = await db.get(DocumentTypes.DEPLOYMENTS)
@@ -159,7 +156,20 @@ exports.deploymentProgress = async function (ctx) {
159
156
  }
160
157
  }
161
158
 
162
- exports.deployApp = async function (ctx) {
159
+ const isFirstDeploy = async () => {
160
+ try {
161
+ const db = getProdAppDB()
162
+ await db.get(DocumentTypes.APP_METADATA)
163
+ } catch (e: any) {
164
+ if (e.status === 404) {
165
+ return true
166
+ }
167
+ throw e
168
+ }
169
+ return false
170
+ }
171
+
172
+ const _deployApp = async function (ctx: any) {
163
173
  let deployment = new Deployment()
164
174
  console.log("Deployment object created")
165
175
  deployment.setStatus(DeploymentStatus.PENDING)
@@ -168,7 +178,14 @@ exports.deployApp = async function (ctx) {
168
178
  console.log("Stored deployment history")
169
179
 
170
180
  console.log("Deploying app...")
171
- await deployApp(deployment)
181
+
182
+ if (await isFirstDeploy()) {
183
+ await quotas.addPublishedApp(() => deployApp(deployment))
184
+ } else {
185
+ await deployApp(deployment)
186
+ }
172
187
 
173
188
  ctx.body = deployment
174
189
  }
190
+
191
+ 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"