@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
@@ -8,50 +8,42 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.sync = exports.destroy = exports.revertClient = exports.updateClient = exports.update = exports.create = exports.fetchAppPackage = exports.fetchAppDefinition = exports.fetch = exports.getAppUrl = void 0;
16
- const environment_1 = __importDefault(require("../../environment"));
17
- const package_json_1 = __importDefault(require("../../../package.json"));
18
- const staticViews_1 = require("../../db/views/staticViews");
19
- const fileSystem_1 = require("../../utilities/fileSystem");
20
- const utils_1 = require("../../db/utils");
11
+ const env = require("../../environment");
12
+ const packageJson = require("../../../package.json");
13
+ const { createLinkView, createRoutingView, createAllSearchIndex, } = require("../../db/views/staticViews");
14
+ const { getTemplateStream, createApp, deleteApp, } = require("../../utilities/fileSystem");
15
+ const { generateAppID, getLayoutParams, getScreenParams, generateDevAppID, DocumentTypes, AppStatus, } = require("../../db/utils");
21
16
  const { BUILTIN_ROLE_IDS, AccessController, } = require("@budibase/backend-core/roles");
22
- const layouts_1 = require("../../constants/layouts");
23
- const fp_1 = require("lodash/fp");
17
+ const { BASE_LAYOUTS } = require("../../constants/layouts");
18
+ const { cloneDeep } = require("lodash/fp");
24
19
  const { processObject } = require("@budibase/string-templates");
25
20
  const { getAllApps, isDevAppID, getProdAppID, Replication, } = require("@budibase/backend-core/db");
26
- const constants_1 = require("../../constants");
27
- const workerRequests_1 = require("../../utilities/workerRequests");
28
- const utilities_1 = require("../../utilities");
29
- const redis_1 = require("../../utilities/redis");
30
- const clientLibrary_1 = require("../../utilities/fileSystem/clientLibrary");
21
+ const { USERS_TABLE_SCHEMA } = require("../../constants");
22
+ const { removeAppFromUserRoles } = require("../../utilities/workerRequests");
23
+ const { clientLibraryPath, stringToReadStream } = require("../../utilities");
24
+ const { getAllLocks } = require("../../utilities/redis");
25
+ const { updateClientLibrary, backupClientLibrary, revertClientLibrary, } = require("../../utilities/fileSystem/clientLibrary");
31
26
  const { getTenantId, isMultiTenant } = require("@budibase/backend-core/tenancy");
32
- const user_1 = require("./user");
27
+ const { syncGlobalUsers } = require("./user");
33
28
  const { app: appCache } = require("@budibase/backend-core/cache");
34
- const utils_2 = require("../../automations/utils");
29
+ const { cleanupAutomations } = require("../../automations/utils");
35
30
  const { getAppDB, getProdAppDB, updateAppId, } = require("@budibase/backend-core/context");
36
- const rows_1 = require("../../utilities/usageQuota/rows");
37
- const pro_1 = require("@budibase/pro");
38
- const backend_core_1 = require("@budibase/backend-core");
39
31
  const URL_REGEX_SLASH = /\/|\\/g;
40
32
  // utility function, need to do away with this
41
33
  function getLayouts() {
42
34
  return __awaiter(this, void 0, void 0, function* () {
43
35
  const db = getAppDB();
44
- return (yield db.allDocs((0, utils_1.getLayoutParams)(null, {
36
+ return (yield db.allDocs(getLayoutParams(null, {
45
37
  include_docs: true,
46
- }))).rows.map((row) => row.doc);
38
+ }))).rows.map(row => row.doc);
47
39
  });
48
40
  }
49
41
  function getScreens() {
50
42
  return __awaiter(this, void 0, void 0, function* () {
51
43
  const db = getAppDB();
52
- return (yield db.allDocs((0, utils_1.getScreenParams)(null, {
44
+ return (yield db.allDocs(getScreenParams(null, {
53
45
  include_docs: true,
54
- }))).rows.map((row) => row.doc);
46
+ }))).rows.map(row => row.doc);
55
47
  });
56
48
  }
57
49
  function getUserRoleId(ctx) {
@@ -59,7 +51,7 @@ function getUserRoleId(ctx) {
59
51
  ? BUILTIN_ROLE_IDS.PUBLIC
60
52
  : ctx.user.role._id;
61
53
  }
62
- const getAppUrl = (ctx) => {
54
+ exports.getAppUrl = ctx => {
63
55
  // construct the url
64
56
  let url;
65
57
  if (ctx.request.body.url) {
@@ -75,12 +67,11 @@ const getAppUrl = (ctx) => {
75
67
  }
76
68
  return url;
77
69
  };
78
- exports.getAppUrl = getAppUrl;
79
70
  const checkAppUrl = (ctx, apps, url, currentAppId) => {
80
71
  if (currentAppId) {
81
- apps = apps.filter((app) => app.appId !== currentAppId);
72
+ apps = apps.filter(app => app.appId !== currentAppId);
82
73
  }
83
- if (apps.some((app) => app.url === url)) {
74
+ if (apps.some(app => app.url === url)) {
84
75
  ctx.throw(400, "App URL is already in use.");
85
76
  }
86
77
  };
@@ -90,17 +81,17 @@ const checkAppName = (ctx, apps, name, currentAppId) => {
90
81
  ctx.throw(400, "Name is required");
91
82
  }
92
83
  if (currentAppId) {
93
- apps = apps.filter((app) => app.appId !== currentAppId);
84
+ apps = apps.filter(app => app.appId !== currentAppId);
94
85
  }
95
- if (apps.some((app) => app.name === name)) {
86
+ if (apps.some(app => app.name === name)) {
96
87
  ctx.throw(400, "App name is already in use.");
97
88
  }
98
89
  };
99
90
  function createInstance(template) {
100
91
  return __awaiter(this, void 0, void 0, function* () {
101
92
  const tenantId = isMultiTenant() ? getTenantId() : null;
102
- const baseAppId = (0, utils_1.generateAppID)(tenantId);
103
- const appId = (0, utils_1.generateDevAppID)(baseAppId);
93
+ const baseAppId = generateAppID(tenantId);
94
+ const appId = generateDevAppID(baseAppId);
104
95
  yield updateAppId(appId);
105
96
  const db = getAppDB();
106
97
  yield db.put({
@@ -111,43 +102,43 @@ function createInstance(template) {
111
102
  });
112
103
  // NOTE: indexes need to be created before any tables/templates
113
104
  // add view for linked rows
114
- yield (0, staticViews_1.createLinkView)();
115
- yield (0, staticViews_1.createRoutingView)();
116
- yield (0, staticViews_1.createAllSearchIndex)();
105
+ yield createLinkView();
106
+ yield createRoutingView();
107
+ yield createAllSearchIndex();
117
108
  // replicate the template data to the instance DB
118
109
  // this is currently very hard to test, downloading and importing template files
119
110
  if (template && template.templateString) {
120
- const { ok } = yield db.load((0, utilities_1.stringToReadStream)(template.templateString));
111
+ const { ok } = yield db.load(stringToReadStream(template.templateString));
121
112
  if (!ok) {
122
113
  throw "Error loading database dump from memory.";
123
114
  }
124
115
  }
125
116
  else if (template && template.useTemplate === "true") {
126
117
  /* istanbul ignore next */
127
- const { ok } = yield db.load(yield (0, fileSystem_1.getTemplateStream)(template));
118
+ const { ok } = yield db.load(yield getTemplateStream(template));
128
119
  if (!ok) {
129
120
  throw "Error loading database dump from template.";
130
121
  }
131
122
  }
132
123
  else {
133
124
  // create the users table
134
- yield db.put(constants_1.USERS_TABLE_SCHEMA);
125
+ yield db.put(USERS_TABLE_SCHEMA);
135
126
  }
136
127
  return { _id: appId };
137
128
  });
138
129
  }
139
- const fetch = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
140
- const dev = ctx.query && ctx.query.status === utils_1.AppStatus.DEV;
141
- const all = ctx.query && ctx.query.status === utils_1.AppStatus.ALL;
130
+ exports.fetch = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
131
+ const dev = ctx.query && ctx.query.status === AppStatus.DEV;
132
+ const all = ctx.query && ctx.query.status === AppStatus.ALL;
142
133
  const apps = yield getAllApps({ dev, all });
143
134
  // get the locks for all the dev apps
144
135
  if (dev || all) {
145
- const locks = yield (0, redis_1.getAllLocks)();
136
+ const locks = yield getAllLocks();
146
137
  for (let app of apps) {
147
138
  if (app.status !== "development") {
148
139
  continue;
149
140
  }
150
- const lock = locks.find((lock) => lock.appId === app.appId);
141
+ const lock = locks.find(lock => lock.appId === app.appId);
151
142
  if (lock) {
152
143
  app.lockedBy = lock.user;
153
144
  }
@@ -159,8 +150,7 @@ const fetch = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
159
150
  }
160
151
  ctx.body = apps;
161
152
  });
162
- exports.fetch = fetch;
163
- const fetchAppDefinition = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
153
+ exports.fetchAppDefinition = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
164
154
  const layouts = yield getLayouts();
165
155
  const userRoleId = getUserRoleId(ctx);
166
156
  const accessController = new AccessController();
@@ -171,10 +161,9 @@ const fetchAppDefinition = (ctx) => __awaiter(void 0, void 0, void 0, function*
171
161
  libraries: ["@budibase/standard-components"],
172
162
  };
173
163
  });
174
- exports.fetchAppDefinition = fetchAppDefinition;
175
- const fetchAppPackage = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
164
+ exports.fetchAppPackage = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
176
165
  const db = getAppDB();
177
- const application = yield db.get(utils_1.DocumentTypes.APP_METADATA);
166
+ const application = yield db.get(DocumentTypes.APP_METADATA);
178
167
  const layouts = yield getLayouts();
179
168
  let screens = yield getScreens();
180
169
  // Only filter screens if the user is not a builder
@@ -187,11 +176,10 @@ const fetchAppPackage = (ctx) => __awaiter(void 0, void 0, void 0, function* ()
187
176
  application,
188
177
  screens,
189
178
  layouts,
190
- clientLibPath: (0, utilities_1.clientLibraryPath)(ctx.params.appId, application.version),
179
+ clientLibPath: clientLibraryPath(ctx.params.appId, application.version),
191
180
  };
192
181
  });
193
- exports.fetchAppPackage = fetchAppPackage;
194
- const performAppCreate = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
182
+ exports.create = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
195
183
  const apps = yield getAllApps({ dev: true });
196
184
  const name = ctx.request.body.name;
197
185
  checkAppName(ctx, apps, name);
@@ -212,18 +200,18 @@ const performAppCreate = (ctx) => __awaiter(void 0, void 0, void 0, function* ()
212
200
  let _rev;
213
201
  try {
214
202
  // if template there will be an existing doc
215
- const existing = yield db.get(utils_1.DocumentTypes.APP_METADATA);
203
+ const existing = yield db.get(DocumentTypes.APP_METADATA);
216
204
  _rev = existing._rev;
217
205
  }
218
206
  catch (err) {
219
207
  // nothing to do
220
208
  }
221
209
  const newApplication = {
222
- _id: utils_1.DocumentTypes.APP_METADATA,
210
+ _id: DocumentTypes.APP_METADATA,
223
211
  _rev,
224
212
  appId: instance._id,
225
213
  type: "app",
226
- version: package_json_1.default.version,
214
+ version: packageJson.version,
227
215
  componentLibraries: ["@budibase/standard-components"],
228
216
  name: name,
229
217
  url: url,
@@ -232,7 +220,7 @@ const performAppCreate = (ctx) => __awaiter(void 0, void 0, void 0, function* ()
232
220
  tenantId: getTenantId(),
233
221
  updatedAt: new Date().toISOString(),
234
222
  createdAt: new Date().toISOString(),
235
- status: utils_1.AppStatus.DEV,
223
+ status: AppStatus.DEV,
236
224
  };
237
225
  const response = yield db.put(newApplication, { force: true });
238
226
  newApplication._rev = response.rev;
@@ -242,44 +230,16 @@ const performAppCreate = (ctx) => __awaiter(void 0, void 0, void 0, function* ()
242
230
  yield createEmptyAppPackage(ctx, newApplication);
243
231
  }
244
232
  /* istanbul ignore next */
245
- if (!environment_1.default.isTest()) {
246
- yield (0, fileSystem_1.createApp)(appId);
233
+ if (!env.isTest()) {
234
+ yield createApp(appId);
247
235
  }
248
236
  yield appCache.invalidateAppMetadata(appId, newApplication);
249
- return newApplication;
250
- });
251
- const appPostCreate = (ctx, appId) => __awaiter(void 0, void 0, void 0, function* () {
252
- // app import & template creation
253
- if (ctx.request.body.useTemplate === "true") {
254
- const rows = yield (0, rows_1.getUniqueRows)([appId]);
255
- const rowCount = rows ? rows.length : 0;
256
- if (rowCount) {
257
- try {
258
- yield pro_1.quotas.addRows(rowCount);
259
- }
260
- catch (err) {
261
- if (err.code && err.code === backend_core_1.errors.codes.USAGE_LIMIT_EXCEEDED) {
262
- // this import resulted in row usage exceeding the quota
263
- // delete the app
264
- // skip pre and post steps as no rows have been added to quotas yet
265
- ctx.params.appId = appId;
266
- yield destroyApp(ctx);
267
- }
268
- throw err;
269
- }
270
- }
271
- }
272
- });
273
- const create = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
274
- const newApplication = yield pro_1.quotas.addApp(() => performAppCreate(ctx));
275
- yield appPostCreate(ctx, newApplication.appId);
276
- ctx.body = newApplication;
277
237
  ctx.status = 200;
238
+ ctx.body = newApplication;
278
239
  });
279
- exports.create = create;
280
240
  // This endpoint currently operates as a PATCH rather than a PUT
281
241
  // Thus name and url fields are handled only if present
282
- const update = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
242
+ exports.update = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
283
243
  const apps = yield getAllApps({ dev: true });
284
244
  // validation
285
245
  const name = ctx.request.body.name;
@@ -295,37 +255,35 @@ const update = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
295
255
  ctx.status = 200;
296
256
  ctx.body = data;
297
257
  });
298
- exports.update = update;
299
- const updateClient = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
258
+ exports.updateClient = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
300
259
  // Get current app version
301
260
  const db = getAppDB();
302
- const application = yield db.get(utils_1.DocumentTypes.APP_METADATA);
261
+ const application = yield db.get(DocumentTypes.APP_METADATA);
303
262
  const currentVersion = application.version;
304
263
  // Update client library and manifest
305
- if (!environment_1.default.isTest()) {
306
- yield (0, clientLibrary_1.backupClientLibrary)(ctx.params.appId);
307
- yield (0, clientLibrary_1.updateClientLibrary)(ctx.params.appId);
264
+ if (!env.isTest()) {
265
+ yield backupClientLibrary(ctx.params.appId);
266
+ yield updateClientLibrary(ctx.params.appId);
308
267
  }
309
268
  // Update versions in app package
310
269
  const appPackageUpdates = {
311
- version: package_json_1.default.version,
270
+ version: packageJson.version,
312
271
  revertableVersion: currentVersion,
313
272
  };
314
273
  const data = yield updateAppPackage(appPackageUpdates, ctx.params.appId);
315
274
  ctx.status = 200;
316
275
  ctx.body = data;
317
276
  });
318
- exports.updateClient = updateClient;
319
- const revertClient = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
277
+ exports.revertClient = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
320
278
  // Check app can be reverted
321
279
  const db = getAppDB();
322
- const application = yield db.get(utils_1.DocumentTypes.APP_METADATA);
280
+ const application = yield db.get(DocumentTypes.APP_METADATA);
323
281
  if (!application.revertableVersion) {
324
282
  ctx.throw(400, "There is no version to revert to");
325
283
  }
326
284
  // Update client library and manifest
327
- if (!environment_1.default.isTest()) {
328
- yield (0, clientLibrary_1.revertClientLibrary)(ctx.params.appId);
285
+ if (!env.isTest()) {
286
+ yield revertClientLibrary(ctx.params.appId);
329
287
  }
330
288
  // Update versions in app package
331
289
  const appPackageUpdates = {
@@ -336,52 +294,23 @@ const revertClient = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
336
294
  ctx.status = 200;
337
295
  ctx.body = data;
338
296
  });
339
- exports.revertClient = revertClient;
340
- const destroyApp = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
341
- let appId = ctx.params.appId;
342
- let isUnpublish = ctx.query && ctx.query.unpublish;
343
- if (isUnpublish) {
344
- appId = getProdAppID(appId);
345
- }
346
- const db = isUnpublish ? getProdAppDB() : getAppDB();
297
+ exports.delete = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
298
+ const db = getAppDB();
347
299
  const result = yield db.destroy();
348
- if (isUnpublish) {
349
- yield pro_1.quotas.removePublishedApp();
350
- }
351
- else {
352
- yield pro_1.quotas.removeApp();
353
- }
354
300
  /* istanbul ignore next */
355
- if (!environment_1.default.isTest() && !isUnpublish) {
356
- yield (0, fileSystem_1.deleteApp)(appId);
301
+ if (!env.isTest() && !ctx.query.unpublish) {
302
+ yield deleteApp(ctx.params.appId);
357
303
  }
358
- if (isUnpublish) {
359
- yield (0, utils_2.cleanupAutomations)(appId);
304
+ if (ctx.query && ctx.query.unpublish) {
305
+ yield cleanupAutomations(ctx.params.appId);
360
306
  }
361
307
  // make sure the app/role doesn't stick around after the app has been deleted
362
- yield (0, workerRequests_1.removeAppFromUserRoles)(ctx, appId);
363
- yield appCache.invalidateAppMetadata(appId);
364
- return result;
365
- });
366
- const preDestroyApp = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
367
- const rows = yield (0, rows_1.getUniqueRows)([ctx.params.appId]);
368
- ctx.rowCount = rows.length;
369
- });
370
- const postDestroyApp = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
371
- const rowCount = ctx.rowCount;
372
- if (rowCount) {
373
- yield pro_1.quotas.removeRows(rowCount);
374
- }
375
- });
376
- const destroy = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
377
- yield preDestroyApp(ctx);
378
- const result = yield destroyApp(ctx);
379
- yield postDestroyApp(ctx);
308
+ yield removeAppFromUserRoles(ctx, ctx.params.appId);
309
+ yield appCache.invalidateAppMetadata(ctx.params.appId);
380
310
  ctx.status = 200;
381
311
  ctx.body = result;
382
312
  });
383
- exports.destroy = destroy;
384
- const sync = (ctx, next) => __awaiter(void 0, void 0, void 0, function* () {
313
+ exports.sync = (ctx, next) => __awaiter(void 0, void 0, void 0, function* () {
385
314
  const appId = ctx.params.appId;
386
315
  if (!isDevAppID(appId)) {
387
316
  ctx.throw(400, "This action cannot be performed for production apps");
@@ -411,7 +340,7 @@ const sync = (ctx, next) => __awaiter(void 0, void 0, void 0, function* () {
411
340
  try {
412
341
  yield replication.replicate({
413
342
  filter: function (doc) {
414
- return doc._id !== utils_1.DocumentTypes.APP_METADATA;
343
+ return doc._id !== DocumentTypes.APP_METADATA;
415
344
  },
416
345
  });
417
346
  }
@@ -422,7 +351,7 @@ const sync = (ctx, next) => __awaiter(void 0, void 0, void 0, function* () {
422
351
  yield replication.close();
423
352
  }
424
353
  // sync the users
425
- yield (0, user_1.syncGlobalUsers)();
354
+ yield syncGlobalUsers();
426
355
  if (error) {
427
356
  ctx.throw(400, error);
428
357
  }
@@ -432,10 +361,9 @@ const sync = (ctx, next) => __awaiter(void 0, void 0, void 0, function* () {
432
361
  };
433
362
  }
434
363
  });
435
- exports.sync = sync;
436
364
  const updateAppPackage = (appPackage, appId) => __awaiter(void 0, void 0, void 0, function* () {
437
365
  const db = getAppDB();
438
- const application = yield db.get(utils_1.DocumentTypes.APP_METADATA);
366
+ const application = yield db.get(DocumentTypes.APP_METADATA);
439
367
  const newAppPackage = Object.assign(Object.assign({}, application), appPackage);
440
368
  if (appPackage._rev !== application._rev) {
441
369
  newAppPackage._rev = application._rev;
@@ -451,8 +379,8 @@ const updateAppPackage = (appPackage, appId) => __awaiter(void 0, void 0, void 0
451
379
  const createEmptyAppPackage = (ctx, app) => __awaiter(void 0, void 0, void 0, function* () {
452
380
  const db = getAppDB();
453
381
  let screensAndLayouts = [];
454
- for (let layout of layouts_1.BASE_LAYOUTS) {
455
- const cloned = (0, fp_1.cloneDeep)(layout);
382
+ for (let layout of BASE_LAYOUTS) {
383
+ const cloned = cloneDeep(layout);
456
384
  screensAndLayouts.push(yield processObject(cloned, app));
457
385
  }
458
386
  yield db.bulkDocs(screensAndLayouts);
@@ -8,18 +8,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.deployApp = exports.deploymentProgress = exports.fetchDeployments = void 0;
16
- const Deployment_1 = __importDefault(require("./Deployment"));
17
- const db_1 = require("@budibase/backend-core/db");
18
- const utils_1 = require("../../../db/utils");
19
- const utils_2 = require("../../../automations/utils");
20
- const cache_1 = require("@budibase/backend-core/cache");
21
- const context_1 = require("@budibase/backend-core/context");
22
- const pro_1 = require("@budibase/pro");
11
+ const Deployment = require("./Deployment");
12
+ const { Replication, getProdAppID, getDevelopmentAppID, } = require("@budibase/backend-core/db");
13
+ const { DocumentTypes, getAutomationParams } = require("../../../db/utils");
14
+ const { disableAllCrons, enableCronTrigger, } = require("../../../automations/utils");
15
+ const { app: appCache } = require("@budibase/backend-core/cache");
16
+ const { getAppId, getAppDB, getProdAppDB, } = require("@budibase/backend-core/context");
23
17
  // the max time we can wait for an invalidation to complete before considering it failed
24
18
  const MAX_PENDING_TIME_MS = 30 * 60000;
25
19
  const DeploymentStatus = {
@@ -31,8 +25,7 @@ const DeploymentStatus = {
31
25
  function checkAllDeployments(deployments) {
32
26
  return __awaiter(this, void 0, void 0, function* () {
33
27
  let updated = false;
34
- let deployment;
35
- for (deployment of Object.values(deployments.history)) {
28
+ for (let deployment of Object.values(deployments.history)) {
36
29
  // check that no deployments have crashed etc and are now stuck
37
30
  if (deployment.status === DeploymentStatus.PENDING &&
38
31
  Date.now() - deployment.updatedAt > MAX_PENDING_TIME_MS) {
@@ -47,14 +40,14 @@ function checkAllDeployments(deployments) {
47
40
  function storeDeploymentHistory(deployment) {
48
41
  return __awaiter(this, void 0, void 0, function* () {
49
42
  const deploymentJSON = deployment.getJSON();
50
- const db = (0, context_1.getAppDB)();
43
+ const db = getAppDB();
51
44
  let deploymentDoc;
52
45
  try {
53
46
  // theres only one deployment doc per app database
54
- deploymentDoc = yield db.get(utils_1.DocumentTypes.DEPLOYMENTS);
47
+ deploymentDoc = yield db.get(DocumentTypes.DEPLOYMENTS);
55
48
  }
56
49
  catch (err) {
57
- deploymentDoc = { _id: utils_1.DocumentTypes.DEPLOYMENTS, history: {} };
50
+ deploymentDoc = { _id: DocumentTypes.DEPLOYMENTS, history: {} };
58
51
  }
59
52
  const deploymentId = deploymentJSON._id;
60
53
  // first time deployment
@@ -68,19 +61,19 @@ function storeDeploymentHistory(deployment) {
68
61
  }
69
62
  function initDeployedApp(prodAppId) {
70
63
  return __awaiter(this, void 0, void 0, function* () {
71
- const db = (0, context_1.getProdAppDB)();
64
+ const db = getProdAppDB();
72
65
  console.log("Reading automation docs");
73
- const automations = (yield db.allDocs((0, utils_1.getAutomationParams)(null, {
66
+ const automations = (yield db.allDocs(getAutomationParams(null, {
74
67
  include_docs: true,
75
- }))).rows.map((row) => row.doc);
68
+ }))).rows.map(row => row.doc);
76
69
  console.log("You have " + automations.length + " automations");
77
70
  const promises = [];
78
71
  console.log("Disabling prod crons..");
79
- yield (0, utils_2.disableAllCrons)(prodAppId);
72
+ yield disableAllCrons(prodAppId);
80
73
  console.log("Prod Cron triggers disabled..");
81
74
  console.log("Enabling cron triggers for deployed app..");
82
75
  for (let automation of automations) {
83
- promises.push((0, utils_2.enableCronTrigger)(prodAppId, automation));
76
+ promises.push(enableCronTrigger(prodAppId, automation));
84
77
  }
85
78
  yield Promise.all(promises);
86
79
  console.log("Enabled cron triggers for deployed app..");
@@ -90,24 +83,22 @@ function deployApp(deployment) {
90
83
  return __awaiter(this, void 0, void 0, function* () {
91
84
  let replication;
92
85
  try {
93
- const appId = (0, context_1.getAppId)();
94
- const devAppId = (0, db_1.getDevelopmentAppID)(appId);
95
- const productionAppId = (0, db_1.getProdAppID)(appId);
96
- const config = {
86
+ const appId = getAppId();
87
+ const devAppId = getDevelopmentAppID(appId);
88
+ const productionAppId = getProdAppID(appId);
89
+ replication = new Replication({
97
90
  source: devAppId,
98
91
  target: productionAppId,
99
- };
100
- replication = new db_1.Replication(config);
92
+ });
101
93
  console.log("Replication object created");
102
94
  yield replication.replicate();
103
95
  console.log("replication complete.. replacing app meta doc");
104
- const db = (0, context_1.getProdAppDB)();
105
- const appDoc = yield db.get(utils_1.DocumentTypes.APP_METADATA);
106
- deployment.appUrl = appDoc.url;
96
+ const db = getProdAppDB();
97
+ const appDoc = yield db.get(DocumentTypes.APP_METADATA);
107
98
  appDoc.appId = productionAppId;
108
99
  appDoc.instance._id = productionAppId;
109
100
  yield db.put(appDoc);
110
- yield cache_1.app.invalidateAppMetadata(productionAppId);
101
+ yield appCache.invalidateAppMetadata(productionAppId);
111
102
  console.log("New app doc written successfully.");
112
103
  yield initDeployedApp(productionAppId);
113
104
  console.log("Deployed app initialised, setting deployment to successful");
@@ -120,18 +111,16 @@ function deployApp(deployment) {
120
111
  throw Object.assign(Object.assign({}, err), { message: `Deployment Failed: ${err.message}` });
121
112
  }
122
113
  finally {
123
- if (replication) {
124
- yield replication.close();
125
- }
114
+ yield replication.close();
126
115
  }
127
116
  });
128
117
  }
129
- function fetchDeployments(ctx) {
118
+ exports.fetchDeployments = function (ctx) {
130
119
  return __awaiter(this, void 0, void 0, function* () {
131
120
  try {
132
- const db = (0, context_1.getAppDB)();
133
- const deploymentDoc = yield db.get(utils_1.DocumentTypes.DEPLOYMENTS);
134
- const { updated, deployments } = yield checkAllDeployments(deploymentDoc);
121
+ const db = getAppDB();
122
+ const deploymentDoc = yield db.get(DocumentTypes.DEPLOYMENTS);
123
+ const { updated, deployments } = yield checkAllDeployments(deploymentDoc, ctx.user);
135
124
  if (updated) {
136
125
  yield db.put(deployments);
137
126
  }
@@ -141,50 +130,29 @@ function fetchDeployments(ctx) {
141
130
  ctx.body = [];
142
131
  }
143
132
  });
144
- }
145
- exports.fetchDeployments = fetchDeployments;
146
- function deploymentProgress(ctx) {
133
+ };
134
+ exports.deploymentProgress = function (ctx) {
147
135
  return __awaiter(this, void 0, void 0, function* () {
148
136
  try {
149
- const db = (0, context_1.getAppDB)();
150
- const deploymentDoc = yield db.get(utils_1.DocumentTypes.DEPLOYMENTS);
137
+ const db = getAppDB();
138
+ const deploymentDoc = yield db.get(DocumentTypes.DEPLOYMENTS);
151
139
  ctx.body = deploymentDoc[ctx.params.deploymentId];
152
140
  }
153
141
  catch (err) {
154
142
  ctx.throw(500, `Error fetching data for deployment ${ctx.params.deploymentId}`);
155
143
  }
156
144
  });
157
- }
158
- exports.deploymentProgress = deploymentProgress;
159
- const isFirstDeploy = () => __awaiter(void 0, void 0, void 0, function* () {
160
- try {
161
- const db = (0, context_1.getProdAppDB)();
162
- yield db.get(utils_1.DocumentTypes.APP_METADATA);
163
- }
164
- catch (e) {
165
- if (e.status === 404) {
166
- return true;
167
- }
168
- throw e;
169
- }
170
- return false;
171
- });
172
- const _deployApp = function (ctx) {
145
+ };
146
+ exports.deployApp = function (ctx) {
173
147
  return __awaiter(this, void 0, void 0, function* () {
174
- let deployment = new Deployment_1.default();
148
+ let deployment = new Deployment();
175
149
  console.log("Deployment object created");
176
150
  deployment.setStatus(DeploymentStatus.PENDING);
177
151
  console.log("Deployment object set to pending");
178
152
  deployment = yield storeDeploymentHistory(deployment);
179
153
  console.log("Stored deployment history");
180
154
  console.log("Deploying app...");
181
- if (yield isFirstDeploy()) {
182
- yield pro_1.quotas.addPublishedApp(() => deployApp(deployment));
183
- }
184
- else {
185
- yield deployApp(deployment);
186
- }
155
+ yield deployApp(deployment);
187
156
  ctx.body = deployment;
188
157
  });
189
158
  };
190
- exports.deployApp = _deployApp;