@budibase/server 1.0.123-alpha.0 → 1.0.123

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 (330) hide show
  1. package/builder/assets/index.68a7f4e3.css +6 -0
  2. package/builder/assets/index.8d4a5b33.js +1291 -0
  3. package/builder/assets/{vendor.5240f480.js → vendor.8e34a169.js} +1 -1
  4. package/builder/index.html +3 -3
  5. package/coverage/clover.xml +1763 -758
  6. package/coverage/coverage-final.json +43 -28
  7. package/coverage/lcov-report/api/controllers/analytics.js.html +3 -8
  8. package/coverage/lcov-report/api/controllers/apikeys.js.html +4 -9
  9. package/coverage/lcov-report/api/controllers/application.js.html +1436 -0
  10. package/coverage/lcov-report/api/controllers/auth.js.html +3 -8
  11. package/coverage/lcov-report/api/controllers/automation.js.html +3 -8
  12. package/coverage/lcov-report/api/controllers/backup.js.html +3 -8
  13. package/coverage/lcov-report/api/controllers/cloud.js.html +3 -8
  14. package/coverage/lcov-report/api/controllers/component.js.html +3 -8
  15. package/coverage/lcov-report/api/controllers/datasource.js.html +6 -11
  16. package/coverage/lcov-report/api/controllers/dev.js.html +3 -8
  17. package/coverage/lcov-report/api/controllers/index.html +26 -16
  18. package/coverage/lcov-report/api/controllers/integration.js.html +3 -8
  19. package/coverage/lcov-report/api/controllers/layout.js.html +3 -8
  20. package/coverage/lcov-report/api/controllers/metadata.js.html +3 -8
  21. package/coverage/lcov-report/api/controllers/migrations.js.html +3 -8
  22. package/coverage/lcov-report/api/controllers/permission.js.html +3 -8
  23. package/coverage/lcov-report/api/controllers/query/index.html +26 -16
  24. package/coverage/lcov-report/api/controllers/query/index.js.html +713 -0
  25. package/coverage/lcov-report/api/controllers/query/validation.js.html +3 -8
  26. package/coverage/lcov-report/api/controllers/role.js.html +5 -10
  27. package/coverage/lcov-report/api/controllers/routing.js.html +4 -9
  28. package/coverage/lcov-report/api/controllers/row/external.js.html +3 -8
  29. package/coverage/lcov-report/api/controllers/row/index.html +35 -25
  30. package/coverage/lcov-report/api/controllers/row/index.js.html +524 -0
  31. package/coverage/lcov-report/api/controllers/row/internal.js.html +24 -32
  32. package/coverage/lcov-report/api/controllers/row/internalSearch.js.html +16 -21
  33. package/coverage/lcov-report/api/controllers/row/staticFormula.js.html +19 -24
  34. package/coverage/lcov-report/api/controllers/row/utils.js.html +19 -33
  35. package/coverage/lcov-report/api/controllers/screen.js.html +4 -9
  36. package/coverage/lcov-report/api/controllers/script.js.html +3 -8
  37. package/coverage/lcov-report/api/controllers/table/bulkFormula.js.html +50 -55
  38. package/coverage/lcov-report/api/controllers/table/external.js.html +3 -8
  39. package/coverage/lcov-report/api/controllers/table/index.html +44 -19
  40. package/coverage/lcov-report/api/controllers/table/index.js.html +15 -20
  41. package/coverage/lcov-report/api/controllers/table/internal.js.html +620 -0
  42. package/coverage/lcov-report/api/controllers/table/utils.js.html +1331 -0
  43. package/coverage/lcov-report/api/controllers/templates.js.html +3 -8
  44. package/coverage/lcov-report/api/controllers/user.js.html +3 -8
  45. package/coverage/lcov-report/api/controllers/view/exporters.js.html +3 -8
  46. package/coverage/lcov-report/api/controllers/view/index.html +3 -8
  47. package/coverage/lcov-report/api/controllers/view/index.js.html +5 -10
  48. package/coverage/lcov-report/api/controllers/view/utils.js.html +3 -8
  49. package/coverage/lcov-report/api/controllers/view/viewBuilder.js.html +3 -8
  50. package/coverage/lcov-report/api/controllers/webhook.js.html +5 -10
  51. package/coverage/lcov-report/api/index.html +13 -18
  52. package/coverage/lcov-report/api/index.js.html +8 -28
  53. package/coverage/lcov-report/api/routes/analytics.js.html +3 -8
  54. package/coverage/lcov-report/api/routes/apikeys.js.html +3 -8
  55. package/coverage/lcov-report/api/routes/application.js.html +179 -0
  56. package/coverage/lcov-report/api/routes/auth.js.html +3 -8
  57. package/coverage/lcov-report/api/routes/automation.js.html +3 -8
  58. package/coverage/lcov-report/api/routes/backup.js.html +3 -8
  59. package/coverage/lcov-report/api/routes/cloud.js.html +3 -8
  60. package/coverage/lcov-report/api/routes/component.js.html +3 -8
  61. package/coverage/lcov-report/api/routes/datasource.js.html +3 -8
  62. package/coverage/lcov-report/api/routes/deploy.js.html +3 -8
  63. package/coverage/lcov-report/api/routes/dev.js.html +4 -9
  64. package/coverage/lcov-report/api/routes/index.html +68 -13
  65. package/coverage/lcov-report/api/routes/index.js.html +266 -0
  66. package/coverage/lcov-report/api/routes/integration.js.html +3 -8
  67. package/coverage/lcov-report/api/routes/layout.js.html +3 -8
  68. package/coverage/lcov-report/api/routes/metadata.js.html +3 -8
  69. package/coverage/lcov-report/api/routes/migrations.js.html +3 -8
  70. package/coverage/lcov-report/api/routes/permission.js.html +3 -8
  71. package/coverage/lcov-report/api/routes/query.js.html +3 -8
  72. package/coverage/lcov-report/api/routes/role.js.html +3 -8
  73. package/coverage/lcov-report/api/routes/routing.js.html +3 -8
  74. package/coverage/lcov-report/api/routes/row.js.html +908 -0
  75. package/coverage/lcov-report/api/routes/screen.js.html +3 -8
  76. package/coverage/lcov-report/api/routes/script.js.html +3 -8
  77. package/coverage/lcov-report/{automations/steps/loop.js.html → api/routes/static.js.html} +80 -70
  78. package/coverage/lcov-report/api/routes/table.js.html +3 -8
  79. package/coverage/lcov-report/api/routes/templates.js.html +3 -8
  80. package/coverage/lcov-report/api/routes/user.js.html +3 -8
  81. package/coverage/lcov-report/api/routes/utils/index.html +3 -8
  82. package/coverage/lcov-report/api/routes/utils/validators.js.html +3 -8
  83. package/coverage/lcov-report/api/routes/view.js.html +3 -8
  84. package/coverage/lcov-report/api/routes/webhook.js.html +3 -8
  85. package/coverage/lcov-report/automations/actions.js.html +7 -21
  86. package/coverage/lcov-report/automations/automationUtils.js.html +23 -64
  87. package/coverage/lcov-report/automations/bullboard.js.html +3 -8
  88. package/coverage/lcov-report/automations/index.html +37 -27
  89. package/coverage/lcov-report/automations/index.js.html +3 -8
  90. package/coverage/lcov-report/automations/steps/bash.js.html +3 -8
  91. package/coverage/lcov-report/automations/steps/createRow.js.html +380 -0
  92. package/coverage/lcov-report/automations/steps/delay.js.html +3 -8
  93. package/coverage/lcov-report/automations/steps/deleteRow.js.html +347 -0
  94. package/coverage/lcov-report/automations/steps/discord.js.html +3 -8
  95. package/coverage/lcov-report/automations/steps/executeQuery.js.html +3 -8
  96. package/coverage/lcov-report/automations/steps/executeScript.js.html +3 -8
  97. package/coverage/lcov-report/automations/steps/filter.js.html +3 -8
  98. package/coverage/lcov-report/automations/steps/index.html +41 -31
  99. package/coverage/lcov-report/automations/steps/integromat.js.html +3 -8
  100. package/coverage/lcov-report/automations/steps/outgoingWebhook.js.html +4 -9
  101. package/coverage/lcov-report/automations/steps/queryRows.js.html +4 -9
  102. package/coverage/lcov-report/automations/steps/sendSmtpEmail.js.html +3 -8
  103. package/coverage/lcov-report/automations/steps/serverLog.js.html +3 -8
  104. package/coverage/lcov-report/automations/steps/slack.js.html +3 -8
  105. package/coverage/lcov-report/automations/steps/updateRow.js.html +3 -8
  106. package/coverage/lcov-report/automations/steps/utils.js.html +9 -14
  107. package/coverage/lcov-report/automations/steps/zapier.js.html +3 -8
  108. package/coverage/lcov-report/automations/triggerInfo/app.js.html +3 -8
  109. package/coverage/lcov-report/automations/triggerInfo/cron.js.html +3 -8
  110. package/coverage/lcov-report/automations/triggerInfo/index.html +3 -8
  111. package/coverage/lcov-report/automations/triggerInfo/index.js.html +3 -8
  112. package/coverage/lcov-report/automations/triggerInfo/rowDeleted.js.html +3 -8
  113. package/coverage/lcov-report/automations/triggerInfo/rowSaved.js.html +3 -8
  114. package/coverage/lcov-report/automations/triggerInfo/rowUpdated.js.html +3 -8
  115. package/coverage/lcov-report/automations/triggerInfo/webhook.js.html +3 -8
  116. package/coverage/lcov-report/automations/triggers.js.html +11 -16
  117. package/coverage/lcov-report/automations/utils.js.html +665 -0
  118. package/coverage/lcov-report/block-navigation.js +0 -8
  119. package/coverage/lcov-report/constants/index.html +3 -8
  120. package/coverage/lcov-report/constants/index.js.html +42 -41
  121. package/coverage/lcov-report/constants/layouts.js.html +3 -8
  122. package/coverage/lcov-report/constants/screens.js.html +3 -8
  123. package/coverage/lcov-report/db/inMemoryView.js.html +3 -8
  124. package/coverage/lcov-report/db/index.html +3 -8
  125. package/coverage/lcov-report/db/index.js.html +4 -9
  126. package/coverage/lcov-report/db/linkedRows/LinkController.js.html +23 -25
  127. package/coverage/lcov-report/db/linkedRows/index.html +12 -17
  128. package/coverage/lcov-report/db/linkedRows/index.js.html +17 -22
  129. package/coverage/lcov-report/db/linkedRows/linkUtils.js.html +7 -12
  130. package/coverage/lcov-report/db/newid.js.html +6 -11
  131. package/coverage/lcov-report/db/utils.js.html +79 -84
  132. package/coverage/lcov-report/events/AutomationEmitter.js.html +9 -14
  133. package/coverage/lcov-report/events/index.html +3 -8
  134. package/coverage/lcov-report/events/index.js.html +4 -9
  135. package/coverage/lcov-report/events/utils.js.html +13 -18
  136. package/coverage/lcov-report/index.html +132 -137
  137. package/coverage/lcov-report/integrations/tests/TestConfiguration.js.html +3 -8
  138. package/coverage/lcov-report/integrations/tests/index.html +3 -8
  139. package/coverage/lcov-report/middleware/appInfo.js.html +3 -8
  140. package/coverage/lcov-report/middleware/authorized.js.html +458 -0
  141. package/coverage/lcov-report/middleware/builder.js.html +3 -8
  142. package/coverage/lcov-report/middleware/currentapp.js.html +15 -65
  143. package/coverage/lcov-report/middleware/index.html +50 -25
  144. package/coverage/lcov-report/middleware/joi-validator.js.html +4 -9
  145. package/coverage/lcov-report/middleware/publicApi.js.html +3 -8
  146. package/coverage/lcov-report/middleware/resourceId.js.html +3 -8
  147. package/coverage/lcov-report/middleware/selfhost.js.html +4 -9
  148. package/coverage/lcov-report/middleware/usageQuota.js.html +572 -0
  149. package/coverage/lcov-report/middleware/utils.js.html +3 -8
  150. package/coverage/lcov-report/sorter.js +0 -26
  151. package/coverage/lcov-report/threads/automation.js.html +90 -581
  152. package/coverage/lcov-report/threads/index.html +40 -30
  153. package/coverage/lcov-report/threads/index.js.html +296 -0
  154. package/coverage/lcov-report/threads/query.js.html +4 -9
  155. package/coverage/lcov-report/threads/utils.js.html +9 -17
  156. package/coverage/lcov-report/utilities/bcrypt.js.html +3 -8
  157. package/coverage/lcov-report/utilities/budibaseDir.js.html +3 -8
  158. package/coverage/lcov-report/utilities/centralPath.js.html +3 -8
  159. package/coverage/lcov-report/utilities/csvParser.js.html +5 -10
  160. package/coverage/lcov-report/utilities/global.js.html +4 -9
  161. package/coverage/lcov-report/utilities/index.html +3 -8
  162. package/coverage/lcov-report/utilities/index.js.html +6 -11
  163. package/coverage/lcov-report/utilities/queue/inMemoryQueue.js.html +9 -32
  164. package/coverage/lcov-report/utilities/queue/index.html +7 -12
  165. package/coverage/lcov-report/utilities/routing/index.html +3 -8
  166. package/coverage/lcov-report/utilities/routing/index.js.html +3 -8
  167. package/coverage/lcov-report/utilities/rowProcessor/index.html +27 -32
  168. package/coverage/lcov-report/utilities/rowProcessor/index.js.html +71 -67
  169. package/coverage/lcov-report/utilities/rowProcessor/utils.js.html +106 -27
  170. package/coverage/lcov-report/utilities/scriptRunner.js.html +3 -8
  171. package/coverage/lcov-report/utilities/security.js.html +4 -9
  172. package/coverage/lcov-report/utilities/statusCodes.js.html +3 -8
  173. package/coverage/lcov-report/utilities/usageQuota/index.html +34 -24
  174. package/coverage/lcov-report/utilities/usageQuota/index.js.html +359 -0
  175. package/coverage/lcov-report/utilities/usageQuota/rows.js.html +39 -44
  176. package/coverage/lcov-report/utilities/usageQuota/usageQuoteReset.js.html +3 -8
  177. package/coverage/lcov-report/utilities/users.js.html +3 -8
  178. package/coverage/lcov-report/utilities/workerRequests.js.html +4 -9
  179. package/coverage/lcov.info +3061 -1290
  180. package/dist/api/controllers/application.js +73 -145
  181. package/dist/api/controllers/deploy/index.js +36 -68
  182. package/dist/api/controllers/public/applications.js +9 -29
  183. package/dist/api/controllers/public/queries.js +7 -27
  184. package/dist/api/controllers/public/rows.js +12 -32
  185. package/dist/api/controllers/public/tables.js +2 -2
  186. package/dist/api/controllers/public/users.js +8 -8
  187. package/dist/api/controllers/public/utils.js +1 -1
  188. package/dist/api/controllers/query/import/index.js +3 -3
  189. package/dist/api/controllers/query/index.js +44 -57
  190. package/dist/api/controllers/row/ExternalRequest.js +27 -27
  191. package/dist/api/controllers/row/index.js +60 -83
  192. package/dist/api/controllers/row/internal.js +1 -2
  193. package/dist/api/controllers/row/utils.js +1 -2
  194. package/dist/api/controllers/static/templates/BudibaseApp.svelte +0 -3
  195. package/dist/api/controllers/table/bulkFormula.js +1 -2
  196. package/dist/api/controllers/table/internal.js +55 -40
  197. package/dist/api/controllers/table/utils.js +229 -271
  198. package/dist/api/index.js +0 -5
  199. package/dist/api/routes/application.js +13 -39
  200. package/dist/api/routes/index.js +56 -61
  201. package/dist/api/routes/public/index.js +9 -6
  202. package/dist/api/routes/public/queries.js +1 -1
  203. package/dist/api/routes/public/rows.js +1 -1
  204. package/dist/api/routes/public/tables.js +3 -3
  205. package/dist/api/routes/public/users.js +1 -1
  206. package/dist/api/routes/row.js +17 -43
  207. package/dist/api/routes/static.js +13 -40
  208. package/dist/api/routes/tests/utilities/TestFunctions.js +33 -75
  209. package/dist/app.js +4 -8
  210. package/dist/automations/actions.js +0 -3
  211. package/dist/automations/automationUtils.js +0 -10
  212. package/dist/automations/steps/createRow.js +12 -12
  213. package/dist/automations/steps/deleteRow.js +16 -13
  214. package/dist/automations/tests/utilities/index.js +11 -13
  215. package/dist/automations/utils.js +133 -187
  216. package/dist/constants/index.js +7 -5
  217. package/dist/db/linkedRows/LinkController.js +1 -0
  218. package/dist/definitions/datasource.js +0 -1
  219. package/dist/environment.js +3 -2
  220. package/dist/index.js +0 -4
  221. package/dist/integrations/base/sql.js +2 -2
  222. package/dist/integrations/base/sqlTable.js +2 -2
  223. package/dist/integrations/googlesheets.js +1 -1
  224. package/dist/integrations/index.js +0 -4
  225. package/dist/integrations/microsoftSqlServer.js +8 -8
  226. package/dist/integrations/mysql.js +9 -9
  227. package/dist/integrations/oracle.js +7 -7
  228. package/dist/integrations/postgres.js +7 -7
  229. package/dist/integrations/queries/sql.js +2 -2
  230. package/dist/integrations/rest.js +1 -1
  231. package/dist/middleware/authorized.js +51 -51
  232. package/dist/middleware/currentapp.js +1 -15
  233. package/dist/middleware/usageQuota.js +154 -0
  234. package/dist/migrations/functions/appUrls.js +1 -1
  235. package/dist/migrations/functions/quotas1.js +2 -6
  236. package/dist/migrations/functions/usageQuotas/index.js +4 -0
  237. package/dist/migrations/functions/usageQuotas/syncApps.js +7 -4
  238. package/dist/migrations/functions/usageQuotas/syncRows.js +8 -5
  239. package/dist/migrations/index.js +1 -17
  240. package/dist/package.json +4 -10
  241. package/dist/threads/automation.js +27 -149
  242. package/dist/threads/index.js +10 -36
  243. package/dist/threads/utils.js +0 -1
  244. package/dist/tsconfig.tsbuildinfo +1 -0
  245. package/dist/utilities/queue/inMemoryQueue.js +1 -6
  246. package/dist/utilities/rowProcessor/index.js +11 -6
  247. package/dist/utilities/rowProcessor/utils.js +27 -1
  248. package/dist/utilities/usageQuota/index.js +86 -0
  249. package/nodemon.json +1 -1
  250. package/package.json +9 -15
  251. package/scripts/dev/manage.js +0 -2
  252. package/src/api/controllers/{application.ts → application.js} +51 -118
  253. package/src/api/controllers/deploy/{index.ts → index.js} +29 -53
  254. package/src/api/controllers/public/applications.ts +2 -2
  255. package/src/api/controllers/public/queries.ts +1 -1
  256. package/src/api/controllers/public/rows.ts +1 -1
  257. package/src/api/controllers/query/{index.ts → index.js} +48 -51
  258. package/src/api/controllers/row/ExternalRequest.ts +1 -1
  259. package/src/api/controllers/row/{index.ts → index.js} +17 -24
  260. package/src/api/controllers/row/internal.js +1 -2
  261. package/src/api/controllers/row/utils.js +1 -4
  262. package/src/api/controllers/static/templates/BudibaseApp.svelte +0 -3
  263. package/src/api/controllers/table/bulkFormula.js +1 -1
  264. package/src/api/controllers/table/{internal.ts → internal.js} +48 -27
  265. package/src/api/controllers/table/{utils.ts → utils.js} +69 -86
  266. package/src/api/index.js +0 -5
  267. package/src/api/routes/{application.ts → application.js} +14 -8
  268. package/src/api/routes/index.js +62 -0
  269. package/src/api/routes/public/index.ts +4 -1
  270. package/src/api/routes/{row.ts → row.js} +15 -7
  271. package/src/api/routes/{static.ts → static.js} +11 -11
  272. package/src/api/routes/tests/misc.spec.js +37 -39
  273. package/src/api/routes/tests/routing.spec.js +0 -1
  274. package/src/api/routes/tests/utilities/{TestFunctions.ts → TestFunctions.js} +33 -57
  275. package/src/app.ts +2 -1
  276. package/src/automations/actions.js +0 -3
  277. package/src/automations/automationUtils.js +0 -12
  278. package/src/automations/steps/{createRow.ts → createRow.js} +15 -9
  279. package/src/automations/steps/{deleteRow.ts → deleteRow.js} +16 -10
  280. package/src/automations/tests/automation.spec.js +1 -0
  281. package/src/automations/tests/{createRow.spec.ts → createRow.spec.js} +15 -4
  282. package/src/automations/tests/{deleteRow.spec.ts → deleteRow.spec.js} +5 -3
  283. package/src/automations/tests/utilities/index.js +10 -12
  284. package/src/automations/{utils.ts → utils.js} +28 -39
  285. package/src/constants/index.js +8 -6
  286. package/src/db/linkedRows/LinkController.js +1 -0
  287. package/src/definitions/datasource.ts +0 -1
  288. package/src/environment.js +3 -2
  289. package/src/index.ts +0 -3
  290. package/src/integrations/index.ts +0 -4
  291. package/src/middleware/{authorized.ts → authorized.js} +14 -20
  292. package/src/middleware/currentapp.js +1 -16
  293. package/src/middleware/tests/usageQuota.spec.js +120 -0
  294. package/src/middleware/usageQuota.js +164 -0
  295. package/src/migrations/functions/tests/quotas1.spec.js +2 -0
  296. package/src/migrations/functions/usageQuotas/index.ts +5 -0
  297. package/src/migrations/functions/usageQuotas/syncApps.ts +6 -3
  298. package/src/migrations/functions/usageQuotas/syncRows.ts +6 -3
  299. package/src/migrations/functions/usageQuotas/tests/syncApps.spec.js +41 -0
  300. package/src/migrations/functions/usageQuotas/tests/syncRows.spec.js +45 -0
  301. package/src/migrations/index.ts +1 -13
  302. package/src/threads/automation.js +34 -196
  303. package/src/threads/{index.ts → index.js} +14 -18
  304. package/src/threads/utils.js +0 -1
  305. package/src/utilities/queue/inMemoryQueue.js +1 -7
  306. package/src/utilities/rowProcessor/index.js +12 -9
  307. package/src/utilities/rowProcessor/utils.js +29 -1
  308. package/src/utilities/tests/usageQuota/usageQuota.spec.js +72 -0
  309. package/src/utilities/usageQuota/index.js +93 -0
  310. package/tsconfig.json +2 -2
  311. package/builder/assets/index.89795487.css +0 -6
  312. package/builder/assets/index.be9a1b80.js +0 -1299
  313. package/dist/automations/steps/loop.js +0 -51
  314. package/dist/integrations/redis.js +0 -158
  315. package/dist/migrations/functions/developerQuota.js +0 -49
  316. package/dist/migrations/functions/publishedAppsQuota.js +0 -47
  317. package/dist/migrations/functions/usageQuotas/syncDevelopers.js +0 -24
  318. package/dist/migrations/functions/usageQuotas/syncPublishedApps.js +0 -26
  319. package/dist/tsconfig.build.tsbuildinfo +0 -1
  320. package/src/api/routes/index.ts +0 -60
  321. package/src/automations/steps/loop.js +0 -50
  322. package/src/integrations/redis.ts +0 -152
  323. package/src/integrations/tests/redis.spec.js +0 -60
  324. package/src/migrations/functions/developerQuota.ts +0 -15
  325. package/src/migrations/functions/publishedAppsQuota.ts +0 -13
  326. package/src/migrations/functions/usageQuotas/syncDevelopers.ts +0 -19
  327. package/src/migrations/functions/usageQuotas/syncPublishedApps.ts +0 -21
  328. package/src/migrations/functions/usageQuotas/tests/syncApps.spec.ts +0 -34
  329. package/src/migrations/functions/usageQuotas/tests/syncRows.spec.ts +0 -40
  330. package/tsconfig.build.json +0 -10
@@ -88,8 +88,8 @@ var MySQLModule;
88
88
  }
89
89
  // if not a number, see if it is a date - important to do in this order as any
90
90
  // integer will be considered a valid date
91
- else if ((0, dayjs_1.default)(binding).isValid()) {
92
- bindings[i] = (0, dayjs_1.default)(binding).toDate();
91
+ else if (dayjs_1.default(binding).isValid()) {
92
+ bindings[i] = dayjs_1.default(binding).toDate();
93
93
  }
94
94
  }
95
95
  return bindings;
@@ -175,13 +175,13 @@ var MySQLModule;
175
175
  schema[columnName] = {
176
176
  name: columnName,
177
177
  autocolumn: isAuto,
178
- type: (0, utils_1.convertSqlType)(column.Type),
178
+ type: utils_1.convertSqlType(column.Type),
179
179
  constraints,
180
180
  };
181
181
  }
182
182
  if (!tables[tableName]) {
183
183
  tables[tableName] = {
184
- _id: (0, utils_1.buildExternalTableId)(datasourceId, tableName),
184
+ _id: utils_1.buildExternalTableId(datasourceId, tableName),
185
185
  primary: primaryKeys,
186
186
  name: tableName,
187
187
  schema,
@@ -192,31 +192,31 @@ var MySQLModule;
192
192
  finally {
193
193
  yield this.disconnect();
194
194
  }
195
- const final = (0, utils_1.finaliseExternalTables)(tables, entities);
195
+ const final = utils_1.finaliseExternalTables(tables, entities);
196
196
  this.tables = final.tables;
197
197
  this.schemaErrors = final.errors;
198
198
  });
199
199
  }
200
200
  create(query) {
201
201
  return __awaiter(this, void 0, void 0, function* () {
202
- const results = yield this.internalQuery((0, utils_1.getSqlQuery)(query));
202
+ const results = yield this.internalQuery(utils_1.getSqlQuery(query));
203
203
  return results.length ? results : [{ created: true }];
204
204
  });
205
205
  }
206
206
  read(query) {
207
207
  return __awaiter(this, void 0, void 0, function* () {
208
- return this.internalQuery((0, utils_1.getSqlQuery)(query));
208
+ return this.internalQuery(utils_1.getSqlQuery(query));
209
209
  });
210
210
  }
211
211
  update(query) {
212
212
  return __awaiter(this, void 0, void 0, function* () {
213
- const results = yield this.internalQuery((0, utils_1.getSqlQuery)(query));
213
+ const results = yield this.internalQuery(utils_1.getSqlQuery(query));
214
214
  return results.length ? results : [{ updated: true }];
215
215
  });
216
216
  }
217
217
  delete(query) {
218
218
  return __awaiter(this, void 0, void 0, function* () {
219
- const results = yield this.internalQuery((0, utils_1.getSqlQuery)(query));
219
+ const results = yield this.internalQuery(utils_1.getSqlQuery(query));
220
220
  return results.length ? results : [{ deleted: true }];
221
221
  });
222
222
  }
@@ -204,7 +204,7 @@ var OracleModule;
204
204
  if (this.isBooleanType(column)) {
205
205
  return constants_1.FieldTypes.BOOLEAN;
206
206
  }
207
- return (0, utils_1.convertSqlType)(column.type);
207
+ return utils_1.convertSqlType(column.type);
208
208
  }
209
209
  /**
210
210
  * Fetches the tables from the oracle table and assigns them to the datasource.
@@ -223,7 +223,7 @@ var OracleModule;
223
223
  let table = tables[oracleTable.name];
224
224
  if (!table) {
225
225
  table = {
226
- _id: (0, utils_1.buildExternalTableId)(datasourceId, oracleTable.name),
226
+ _id: utils_1.buildExternalTableId(datasourceId, oracleTable.name),
227
227
  primary: [],
228
228
  name: oracleTable.name,
229
229
  schema: {},
@@ -255,7 +255,7 @@ var OracleModule;
255
255
  });
256
256
  });
257
257
  });
258
- const final = (0, utils_1.finaliseExternalTables)(tables, entities);
258
+ const final = utils_1.finaliseExternalTables(tables, entities);
259
259
  this.tables = final.tables;
260
260
  this.schemaErrors = final.errors;
261
261
  });
@@ -284,7 +284,7 @@ var OracleModule;
284
284
  }
285
285
  create(query) {
286
286
  return __awaiter(this, void 0, void 0, function* () {
287
- const response = yield this.internalQuery((0, utils_1.getSqlQuery)(query));
287
+ const response = yield this.internalQuery(utils_1.getSqlQuery(query));
288
288
  return response.rows && response.rows.length
289
289
  ? response.rows
290
290
  : [{ created: true }];
@@ -292,13 +292,13 @@ var OracleModule;
292
292
  }
293
293
  read(query) {
294
294
  return __awaiter(this, void 0, void 0, function* () {
295
- const response = yield this.internalQuery((0, utils_1.getSqlQuery)(query));
295
+ const response = yield this.internalQuery(utils_1.getSqlQuery(query));
296
296
  return response.rows ? response.rows : [];
297
297
  });
298
298
  }
299
299
  update(query) {
300
300
  return __awaiter(this, void 0, void 0, function* () {
301
- const response = yield this.internalQuery((0, utils_1.getSqlQuery)(query));
301
+ const response = yield this.internalQuery(utils_1.getSqlQuery(query));
302
302
  return response.rows && response.rows.length
303
303
  ? response.rows
304
304
  : [{ updated: true }];
@@ -306,7 +306,7 @@ var OracleModule;
306
306
  }
307
307
  delete(query) {
308
308
  return __awaiter(this, void 0, void 0, function* () {
309
- const response = yield this.internalQuery((0, utils_1.getSqlQuery)(query));
309
+ const response = yield this.internalQuery(utils_1.getSqlQuery(query));
310
310
  return response.rows && response.rows.length
311
311
  ? response.rows
312
312
  : [{ deleted: true }];
@@ -184,13 +184,13 @@ var PostgresModule;
184
184
  // table key doesn't exist yet
185
185
  if (!tables[tableName] || !tables[tableName].schema) {
186
186
  tables[tableName] = {
187
- _id: (0, utils_1.buildExternalTableId)(datasourceId, tableName),
187
+ _id: utils_1.buildExternalTableId(datasourceId, tableName),
188
188
  primary: tableKeys[tableName] || [],
189
189
  name: tableName,
190
190
  schema: {},
191
191
  };
192
192
  }
193
- const type = (0, utils_1.convertSqlType)(column.data_type);
193
+ const type = utils_1.convertSqlType(column.data_type);
194
194
  const identity = !!(column.identity_generation ||
195
195
  column.identity_start ||
196
196
  column.identity_increment);
@@ -204,32 +204,32 @@ var PostgresModule;
204
204
  type,
205
205
  };
206
206
  }
207
- const final = (0, utils_1.finaliseExternalTables)(tables, entities);
207
+ const final = utils_1.finaliseExternalTables(tables, entities);
208
208
  this.tables = final.tables;
209
209
  this.schemaErrors = final.errors;
210
210
  });
211
211
  }
212
212
  create(query) {
213
213
  return __awaiter(this, void 0, void 0, function* () {
214
- const response = yield this.internalQuery((0, utils_1.getSqlQuery)(query));
214
+ const response = yield this.internalQuery(utils_1.getSqlQuery(query));
215
215
  return response.rows.length ? response.rows : [{ created: true }];
216
216
  });
217
217
  }
218
218
  read(query) {
219
219
  return __awaiter(this, void 0, void 0, function* () {
220
- const response = yield this.internalQuery((0, utils_1.getSqlQuery)(query));
220
+ const response = yield this.internalQuery(utils_1.getSqlQuery(query));
221
221
  return response.rows;
222
222
  });
223
223
  }
224
224
  update(query) {
225
225
  return __awaiter(this, void 0, void 0, function* () {
226
- const response = yield this.internalQuery((0, utils_1.getSqlQuery)(query));
226
+ const response = yield this.internalQuery(utils_1.getSqlQuery(query));
227
227
  return response.rows.length ? response.rows : [{ updated: true }];
228
228
  });
229
229
  }
230
230
  delete(query) {
231
231
  return __awaiter(this, void 0, void 0, function* () {
232
- const response = yield this.internalQuery((0, utils_1.getSqlQuery)(query));
232
+ const response = yield this.internalQuery(utils_1.getSqlQuery(query));
233
233
  return response.rows.length ? response.rows : [{ deleted: true }];
234
234
  });
235
235
  }
@@ -16,7 +16,7 @@ function enrichQueryFields(fields, parameters = {}) {
16
16
  }
17
17
  else if (typeof fields[key] === "string") {
18
18
  // enrich string value as normal
19
- enrichedQuery[key] = (0, string_templates_1.processStringSync)(fields[key], parameters, {
19
+ enrichedQuery[key] = string_templates_1.processStringSync(fields[key], parameters, {
20
20
  noEscaping: true,
21
21
  noHelpers: true,
22
22
  escapeNewlines: true,
@@ -47,7 +47,7 @@ function interpolateSQL(fields, parameters, integration) {
47
47
  if (!sql || typeof sql !== "string") {
48
48
  return fields;
49
49
  }
50
- const bindings = (0, string_templates_1.findHBSBlocks)(sql);
50
+ const bindings = string_templates_1.findHBSBlocks(sql);
51
51
  let variables = [], arrays = [];
52
52
  for (let binding of bindings) {
53
53
  // look for array/list operations in the SQL statement, which will need handled later
@@ -149,7 +149,7 @@ var RestModule;
149
149
  // Check if a pagination cursor exists in the response
150
150
  let nextCursor = null;
151
151
  if (pagination === null || pagination === void 0 ? void 0 : pagination.responseParam) {
152
- nextCursor = (0, lodash_1.get)(data, pagination.responseParam);
152
+ nextCursor = lodash_1.get(data, pagination.responseParam);
153
153
  }
154
154
  return {
155
155
  data,
@@ -8,7 +8,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
- const roles_1 = require("@budibase/backend-core/roles");
11
+ const { getUserRoleHierarchy, getRequiredResourceRole, BUILTIN_ROLE_IDS, } = require("@budibase/backend-core/roles");
12
12
  const { PermissionTypes, PermissionLevels, doesHaveBasePermission, } = require("@budibase/backend-core/permissions");
13
13
  const builderMiddleware = require("./builder");
14
14
  const { isWebhookEndpoint } = require("./utils");
@@ -38,15 +38,15 @@ const checkAuthorized = (ctx, resourceRoles, permType, permLevel) => __awaiter(v
38
38
  });
39
39
  const checkAuthorizedResource = (ctx, resourceRoles, permType, permLevel) => __awaiter(void 0, void 0, void 0, function* () {
40
40
  // get the user's roles
41
- const roleId = ctx.roleId || roles_1.BUILTIN_ROLE_IDS.PUBLIC;
42
- const userRoles = yield (0, roles_1.getUserRoleHierarchy)(roleId, {
41
+ const roleId = ctx.roleId || BUILTIN_ROLE_IDS.PUBLIC;
42
+ const userRoles = yield getUserRoleHierarchy(roleId, {
43
43
  idOnly: false,
44
44
  });
45
45
  const permError = "User does not have permission";
46
46
  // check if the user has the required role
47
47
  if (resourceRoles.length > 0) {
48
48
  // deny access if the user doesn't have the required resource role
49
- const found = userRoles.find((role) => resourceRoles.indexOf(role._id) !== -1);
49
+ const found = userRoles.find(role => resourceRoles.indexOf(role._id) !== -1);
50
50
  if (!found) {
51
51
  ctx.throw(403, permError);
52
52
  }
@@ -56,53 +56,53 @@ const checkAuthorizedResource = (ctx, resourceRoles, permType, permLevel) => __a
56
56
  ctx.throw(403, permError);
57
57
  }
58
58
  });
59
- module.exports = (permType, permLevel = null, opts = { schema: false }) => (ctx, next) => __awaiter(void 0, void 0, void 0, function* () {
60
- // webhooks don't need authentication, each webhook unique
61
- // also internal requests (between services) don't need authorized
62
- if (isWebhookEndpoint(ctx) || ctx.internal) {
63
- return next();
64
- }
65
- if (!ctx.user) {
66
- return ctx.throw(403, "No user info found");
67
- }
68
- // check general builder stuff, this middleware is a good way
69
- // to find API endpoints which are builder focused
70
- yield builderMiddleware(ctx, permType);
71
- // get the resource roles
72
- let resourceRoles = [];
73
- let otherLevelRoles = [];
74
- const otherLevel = permLevel === PermissionLevels.READ
75
- ? PermissionLevels.WRITE
76
- : PermissionLevels.READ;
77
- const appId = getAppId();
78
- if (appId && hasResource(ctx)) {
79
- resourceRoles = yield (0, roles_1.getRequiredResourceRole)(permLevel, ctx);
80
- if (opts && opts.schema) {
81
- otherLevelRoles = yield (0, roles_1.getRequiredResourceRole)(otherLevel, ctx);
59
+ module.exports =
60
+ (permType, permLevel = null, opts = { schema: false }) => (ctx, next) => __awaiter(void 0, void 0, void 0, function* () {
61
+ // webhooks don't need authentication, each webhook unique
62
+ // also internal requests (between services) don't need authorized
63
+ if (isWebhookEndpoint(ctx) || ctx.internal) {
64
+ return next();
82
65
  }
83
- }
84
- // if the resource is public, proceed
85
- if (resourceRoles.includes(roles_1.BUILTIN_ROLE_IDS.PUBLIC) ||
86
- (otherLevelRoles && otherLevelRoles.includes(roles_1.BUILTIN_ROLE_IDS.PUBLIC))) {
87
- return next();
88
- }
89
- // check authenticated
90
- if (!ctx.isAuthenticated) {
91
- return ctx.throw(403, "Session not authenticated");
92
- }
93
- try {
94
- // check authorized
95
- yield checkAuthorized(ctx, resourceRoles, permType, permLevel);
96
- }
97
- catch (err) {
98
- // this is a schema, check if
99
- if (opts && opts.schema && permLevel) {
100
- yield checkAuthorized(ctx, otherLevelRoles, permType, otherLevel);
66
+ if (!ctx.user) {
67
+ return ctx.throw(403, "No user info found");
101
68
  }
102
- else {
103
- throw err;
69
+ // check general builder stuff, this middleware is a good way
70
+ // to find API endpoints which are builder focused
71
+ yield builderMiddleware(ctx, permType);
72
+ // get the resource roles
73
+ let resourceRoles = [], otherLevelRoles;
74
+ const otherLevel = permLevel === PermissionLevels.READ
75
+ ? PermissionLevels.WRITE
76
+ : PermissionLevels.READ;
77
+ const appId = getAppId();
78
+ if (appId && hasResource(ctx)) {
79
+ resourceRoles = yield getRequiredResourceRole(permLevel, ctx);
80
+ if (opts && opts.schema) {
81
+ otherLevelRoles = yield getRequiredResourceRole(otherLevel, ctx);
82
+ }
104
83
  }
105
- }
106
- // csrf protection
107
- return csrf(ctx, next);
108
- });
84
+ // if the resource is public, proceed
85
+ if (resourceRoles.includes(BUILTIN_ROLE_IDS.PUBLIC) ||
86
+ (otherLevelRoles && otherLevelRoles.includes(BUILTIN_ROLE_IDS.PUBLIC))) {
87
+ return next();
88
+ }
89
+ // check authenticated
90
+ if (!ctx.isAuthenticated) {
91
+ return ctx.throw(403, "Session not authenticated");
92
+ }
93
+ try {
94
+ // check authorized
95
+ yield checkAuthorized(ctx, resourceRoles, permType, permLevel);
96
+ }
97
+ catch (err) {
98
+ // this is a schema, check if
99
+ if (opts && opts.schema && permLevel) {
100
+ yield checkAuthorized(ctx, otherLevelRoles, permType, otherLevel);
101
+ }
102
+ else {
103
+ throw err;
104
+ }
105
+ }
106
+ // csrf protection
107
+ return csrf(ctx, next);
108
+ });
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  const { getAppIdFromCtx, setCookie, getCookie, clearCookie, } = require("@budibase/backend-core/utils");
12
- const { Cookies, Headers } = require("@budibase/backend-core/constants");
12
+ const { Cookies } = require("@budibase/backend-core/constants");
13
13
  const { getRole } = require("@budibase/backend-core/roles");
14
14
  const { BUILTIN_ROLE_IDS } = require("@budibase/backend-core/roles");
15
15
  const { generateUserMetadataID, isDevAppID } = require("../db/utils");
@@ -64,20 +64,6 @@ module.exports = (ctx, next) => __awaiter(void 0, void 0, void 0, function* () {
64
64
  appId = requestAppId;
65
65
  // retrieving global user gets the right role
66
66
  roleId = globalUser.roleId || roleId;
67
- // Allow builders to specify their role via a header
68
- const isBuilder = globalUser && globalUser.builder && globalUser.builder.global;
69
- const isDevApp = appId && isDevAppID(appId);
70
- const roleHeader = ctx.request && ctx.request.headers[Headers.PREVIEW_ROLE];
71
- if (isBuilder && isDevApp && roleHeader) {
72
- // Ensure the role is valid by ensuring a definition exists
73
- try {
74
- yield getRole(roleHeader);
75
- roleId = roleHeader;
76
- }
77
- catch (error) {
78
- // Swallow error and do nothing
79
- }
80
- }
81
67
  }
82
68
  // nothing more to do
83
69
  if (!appId) {
@@ -0,0 +1,154 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ const usageQuota = require("../utilities/usageQuota");
12
+ const { getUniqueRows } = require("../utilities/usageQuota/rows");
13
+ const { isExternalTable, isRowId: isExternalRowId, } = require("../integrations/utils");
14
+ const { getAppDB } = require("@budibase/backend-core/context");
15
+ // currently only counting new writes and deletes
16
+ const METHOD_MAP = {
17
+ POST: 1,
18
+ DELETE: -1,
19
+ };
20
+ const DOMAIN_MAP = {
21
+ rows: usageQuota.Properties.ROW,
22
+ // upload: usageQuota.Properties.UPLOAD, // doesn't work yet
23
+ // views: usageQuota.Properties.VIEW, // doesn't work yet
24
+ // users: usageQuota.Properties.USER, // doesn't work yet
25
+ applications: usageQuota.Properties.APPS,
26
+ // this will not be updated by endpoint calls
27
+ // instead it will be updated by triggerInfo
28
+ // automationRuns: usageQuota.Properties.AUTOMATION, // doesn't work yet
29
+ };
30
+ function getProperty(url) {
31
+ for (let domain of Object.keys(DOMAIN_MAP)) {
32
+ if (url.indexOf(domain) !== -1) {
33
+ return DOMAIN_MAP[domain];
34
+ }
35
+ }
36
+ }
37
+ module.exports = (ctx, next) => __awaiter(void 0, void 0, void 0, function* () {
38
+ if (!usageQuota.useQuotas()) {
39
+ return next();
40
+ }
41
+ let usage = METHOD_MAP[ctx.req.method];
42
+ const property = getProperty(ctx.req.url);
43
+ if (usage == null || property == null) {
44
+ return next();
45
+ }
46
+ // post request could be a save of a pre-existing entry
47
+ if (ctx.request.body && ctx.request.body._id && ctx.request.body._rev) {
48
+ const usageId = ctx.request.body._id;
49
+ try {
50
+ if (ctx.appId) {
51
+ const db = getAppDB();
52
+ yield db.get(usageId);
53
+ }
54
+ return next();
55
+ }
56
+ catch (err) {
57
+ if (isExternalTable(usageId) ||
58
+ (ctx.request.body.tableId &&
59
+ isExternalTable(ctx.request.body.tableId)) ||
60
+ isExternalRowId(usageId)) {
61
+ return next();
62
+ }
63
+ else {
64
+ ctx.throw(404, `${usageId} does not exist`);
65
+ }
66
+ }
67
+ }
68
+ // update usage for uploads to be the total size
69
+ if (property === usageQuota.Properties.UPLOAD) {
70
+ const files = ctx.request.files.file.length > 1
71
+ ? Array.from(ctx.request.files.file)
72
+ : [ctx.request.files.file];
73
+ usage = files.map(file => file.size).reduce((total, size) => total + size);
74
+ }
75
+ try {
76
+ yield performRequest(ctx, next, property, usage);
77
+ }
78
+ catch (err) {
79
+ ctx.throw(400, err);
80
+ }
81
+ });
82
+ const performRequest = (ctx, next, property, usage) => __awaiter(void 0, void 0, void 0, function* () {
83
+ const usageContext = {
84
+ skipNext: false,
85
+ skipUsage: false,
86
+ [usageQuota.Properties.APPS]: {},
87
+ };
88
+ if (usage === -1) {
89
+ if (PRE_DELETE[property]) {
90
+ yield PRE_DELETE[property](ctx, usageContext);
91
+ }
92
+ }
93
+ else {
94
+ if (PRE_CREATE[property]) {
95
+ yield PRE_CREATE[property](ctx, usageContext);
96
+ }
97
+ }
98
+ // run the request
99
+ if (!usageContext.skipNext) {
100
+ yield usageQuota.update(property, usage, { dryRun: true });
101
+ yield next();
102
+ }
103
+ if (usage === -1) {
104
+ if (POST_DELETE[property]) {
105
+ yield POST_DELETE[property](ctx, usageContext);
106
+ }
107
+ }
108
+ else {
109
+ if (POST_CREATE[property]) {
110
+ yield POST_CREATE[property](ctx, usageContext);
111
+ }
112
+ }
113
+ // update the usage
114
+ if (!usageContext.skipUsage) {
115
+ yield usageQuota.update(property, usage);
116
+ }
117
+ });
118
+ const appPreDelete = (ctx, usageContext) => __awaiter(void 0, void 0, void 0, function* () {
119
+ if (ctx.query.unpublish) {
120
+ // don't run usage decrement for unpublish
121
+ usageContext.skipUsage = true;
122
+ return;
123
+ }
124
+ // store the row count to delete
125
+ const rows = yield getUniqueRows([ctx.appId]);
126
+ if (rows.length) {
127
+ usageContext[usageQuota.Properties.APPS] = { rowCount: rows.length };
128
+ }
129
+ });
130
+ const appPostDelete = (ctx, usageContext) => __awaiter(void 0, void 0, void 0, function* () {
131
+ // delete the app rows from usage
132
+ const rowCount = usageContext[usageQuota.Properties.APPS].rowCount;
133
+ if (rowCount) {
134
+ yield usageQuota.update(usageQuota.Properties.ROW, -rowCount);
135
+ }
136
+ });
137
+ const appPostCreate = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
138
+ // app import & template creation
139
+ if (ctx.request.body.useTemplate === "true") {
140
+ const rows = yield getUniqueRows([ctx.response.body.appId]);
141
+ const rowCount = rows ? rows.length : 0;
142
+ yield usageQuota.update(usageQuota.Properties.ROW, rowCount);
143
+ }
144
+ });
145
+ const PRE_DELETE = {
146
+ [usageQuota.Properties.APPS]: appPreDelete,
147
+ };
148
+ const POST_DELETE = {
149
+ [usageQuota.Properties.APPS]: appPostDelete,
150
+ };
151
+ const PRE_CREATE = {};
152
+ const POST_CREATE = {
153
+ [usageQuota.Properties.APPS]: appPostCreate,
154
+ };
@@ -38,7 +38,7 @@ const run = (appDb) => __awaiter(void 0, void 0, void 0, function* () {
38
38
  },
39
39
  },
40
40
  };
41
- metadata.url = (0, application_1.getAppUrl)(context);
41
+ metadata.url = application_1.getAppUrl(context);
42
42
  console.log(`Adding url to app: ${metadata.url}`);
43
43
  yield appDb.put(metadata);
44
44
  }
@@ -1,11 +1,7 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
9
5
  }) : (function(o, m, k, k2) {
10
6
  if (k2 === undefined) k2 = k;
11
7
  o[k2] = m[k];
@@ -46,7 +42,7 @@ const syncRows = __importStar(require("./usageQuotas/syncRows"));
46
42
  * weren't being decremented correctly.
47
43
  */
48
44
  const run = () => __awaiter(void 0, void 0, void 0, function* () {
49
- yield (0, usageQuotas_1.runQuotaMigration)(() => __awaiter(void 0, void 0, void 0, function* () {
45
+ yield usageQuotas_1.runQuotaMigration(() => __awaiter(void 0, void 0, void 0, function* () {
50
46
  yield syncApps.run();
51
47
  yield syncRows.run();
52
48
  }));
@@ -10,7 +10,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.runQuotaMigration = void 0;
13
+ const { useQuotas } = require("../../../utilities/usageQuota");
13
14
  const runQuotaMigration = (migration) => __awaiter(void 0, void 0, void 0, function* () {
15
+ if (!useQuotas()) {
16
+ return;
17
+ }
14
18
  yield migration();
15
19
  });
16
20
  exports.runQuotaMigration = runQuotaMigration;
@@ -12,15 +12,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.run = void 0;
13
13
  const tenancy_1 = require("@budibase/backend-core/tenancy");
14
14
  const db_1 = require("@budibase/backend-core/db");
15
- const pro_1 = require("@budibase/pro");
15
+ const usageQuota_1 = require("../../../utilities/usageQuota");
16
16
  const run = () => __awaiter(void 0, void 0, void 0, function* () {
17
+ const db = tenancy_1.getGlobalDB();
17
18
  // get app count
18
19
  // @ts-ignore
19
- const devApps = yield (0, db_1.getAllApps)({ dev: true });
20
+ const devApps = yield db_1.getAllApps({ dev: true });
20
21
  const appCount = devApps ? devApps.length : 0;
21
22
  // sync app count
22
- const tenantId = (0, tenancy_1.getTenantId)();
23
+ const tenantId = tenancy_1.getTenantId();
23
24
  console.log(`[Tenant: ${tenantId}] Syncing app count: ${appCount}`);
24
- yield pro_1.quotas.setUsage(appCount, pro_1.StaticQuotaName.APPS, pro_1.QuotaUsageType.STATIC);
25
+ const usageDoc = yield usageQuota_1.getUsageQuotaDoc(db);
26
+ usageDoc.usageQuota.apps = appCount;
27
+ yield db.put(usageDoc);
25
28
  });
26
29
  exports.run = run;
@@ -12,19 +12,22 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.run = void 0;
13
13
  const tenancy_1 = require("@budibase/backend-core/tenancy");
14
14
  const db_1 = require("@budibase/backend-core/db");
15
+ const usageQuota_1 = require("../../../utilities/usageQuota");
15
16
  const rows_1 = require("../../../utilities/usageQuota/rows");
16
- const pro_1 = require("@budibase/pro");
17
17
  const run = () => __awaiter(void 0, void 0, void 0, function* () {
18
+ const db = tenancy_1.getGlobalDB();
18
19
  // get all rows in all apps
19
20
  // @ts-ignore
20
- const allApps = yield (0, db_1.getAllApps)({ all: true });
21
+ const allApps = yield db_1.getAllApps({ all: true });
21
22
  // @ts-ignore
22
23
  const appIds = allApps ? allApps.map((app) => app.appId) : [];
23
- const rows = yield (0, rows_1.getUniqueRows)(appIds);
24
+ const rows = yield rows_1.getUniqueRows(appIds);
24
25
  const rowCount = rows ? rows.length : 0;
25
26
  // sync row count
26
- const tenantId = (0, tenancy_1.getTenantId)();
27
+ const tenantId = tenancy_1.getTenantId();
27
28
  console.log(`[Tenant: ${tenantId}] Syncing row count: ${rowCount}`);
28
- yield pro_1.quotas.setUsage(rowCount, pro_1.StaticQuotaName.ROWS, pro_1.QuotaUsageType.STATIC);
29
+ const usageDoc = yield usageQuota_1.getUsageQuotaDoc(db);
30
+ usageDoc.usageQuota.rows = rowCount;
31
+ yield db.put(usageDoc);
29
32
  });
30
33
  exports.run = run;
@@ -1,11 +1,7 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
9
5
  }) : (function(o, m, k, k2) {
10
6
  if (k2 === undefined) k2 = k;
11
7
  o[k2] = m[k];
@@ -38,8 +34,6 @@ const { MIGRATION_TYPES, runMigrations, } = require("@budibase/backend-core/migr
38
34
  const userEmailViewCasing = __importStar(require("./functions/userEmailViewCasing"));
39
35
  const quota1 = __importStar(require("./functions/quotas1"));
40
36
  const appUrls = __importStar(require("./functions/appUrls"));
41
- const developerQuota = __importStar(require("./functions/developerQuota"));
42
- const publishedAppsQuota = __importStar(require("./functions/publishedAppsQuota"));
43
37
  exports.MIGRATIONS = [
44
38
  {
45
39
  type: MIGRATION_TYPES.GLOBAL,
@@ -57,16 +51,6 @@ exports.MIGRATIONS = [
57
51
  opts: { all: true },
58
52
  fn: appUrls.run,
59
53
  },
60
- {
61
- type: MIGRATION_TYPES.GLOBAL,
62
- name: "developer_quota",
63
- fn: developerQuota.run,
64
- },
65
- {
66
- type: MIGRATION_TYPES.GLOBAL,
67
- name: "published_apps_quota",
68
- fn: publishedAppsQuota.run,
69
- },
70
54
  ];
71
55
  const migrate = (options) => __awaiter(void 0, void 0, void 0, function* () {
72
56
  yield runMigrations(exports.MIGRATIONS, options);