@budibase/server 2.1.43-alpha.8 → 2.1.43-alpha.9

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 (360) hide show
  1. package/builder/assets/{index.29f946a8.js → index.1c5913ba.js} +1 -1
  2. package/builder/index.html +1 -1
  3. package/coverage/clover.xml +542 -514
  4. package/coverage/coverage-final.json +20 -15
  5. package/coverage/lcov-report/index.html +64 -34
  6. package/coverage/lcov-report/src/api/controllers/analytics.ts.html +1 -1
  7. package/coverage/lcov-report/src/api/controllers/apikeys.ts.html +1 -1
  8. package/coverage/lcov-report/src/api/controllers/application.ts.html +86 -233
  9. package/coverage/lcov-report/src/api/controllers/auth.ts.html +1 -1
  10. package/coverage/lcov-report/src/api/controllers/automation.ts.html +1 -1
  11. package/coverage/lcov-report/src/api/controllers/backup.ts.html +1 -1
  12. package/coverage/lcov-report/src/api/controllers/cloud.ts.html +5 -2
  13. package/coverage/lcov-report/src/api/controllers/component.ts.html +1 -1
  14. package/coverage/lcov-report/src/api/controllers/datasource.ts.html +1 -1
  15. package/coverage/lcov-report/src/api/controllers/deploy/Deployment.ts.html +1 -1
  16. package/coverage/lcov-report/src/api/controllers/deploy/index.html +1 -1
  17. package/coverage/lcov-report/src/api/controllers/deploy/index.ts.html +1 -1
  18. package/coverage/lcov-report/src/api/controllers/dev.ts.html +1 -1
  19. package/coverage/lcov-report/src/api/controllers/index.html +28 -28
  20. package/coverage/lcov-report/src/api/controllers/integration.ts.html +1 -1
  21. package/coverage/lcov-report/src/api/controllers/layout.ts.html +1 -1
  22. package/coverage/lcov-report/src/api/controllers/metadata.ts.html +1 -1
  23. package/coverage/lcov-report/src/api/controllers/migrations.ts.html +1 -1
  24. package/coverage/lcov-report/src/api/controllers/permission.ts.html +1 -1
  25. package/coverage/lcov-report/src/api/controllers/plugin/file.ts.html +1 -1
  26. package/coverage/lcov-report/src/api/controllers/plugin/github.ts.html +1 -1
  27. package/coverage/lcov-report/src/api/controllers/plugin/index.html +1 -1
  28. package/coverage/lcov-report/src/api/controllers/plugin/index.ts.html +1 -1
  29. package/coverage/lcov-report/src/api/controllers/plugin/npm.ts.html +1 -1
  30. package/coverage/lcov-report/src/api/controllers/plugin/uploaders.ts.html +1 -1
  31. package/coverage/lcov-report/src/api/controllers/plugin/url.ts.html +1 -1
  32. package/coverage/lcov-report/src/api/controllers/plugin/utils.ts.html +1 -1
  33. package/coverage/lcov-report/src/api/controllers/public/applications.ts.html +1 -1
  34. package/coverage/lcov-report/src/api/controllers/public/index.html +1 -1
  35. package/coverage/lcov-report/src/api/controllers/public/mapping/applications.ts.html +1 -1
  36. package/coverage/lcov-report/src/api/controllers/public/mapping/index.html +1 -1
  37. package/coverage/lcov-report/src/api/controllers/public/mapping/index.ts.html +1 -1
  38. package/coverage/lcov-report/src/api/controllers/public/mapping/queries.ts.html +1 -1
  39. package/coverage/lcov-report/src/api/controllers/public/mapping/rows.ts.html +1 -1
  40. package/coverage/lcov-report/src/api/controllers/public/mapping/tables.ts.html +1 -1
  41. package/coverage/lcov-report/src/api/controllers/public/mapping/users.ts.html +1 -1
  42. package/coverage/lcov-report/src/api/controllers/public/queries.ts.html +1 -1
  43. package/coverage/lcov-report/src/api/controllers/public/rows.ts.html +1 -1
  44. package/coverage/lcov-report/src/api/controllers/public/tables.ts.html +1 -1
  45. package/coverage/lcov-report/src/api/controllers/public/users.ts.html +1 -1
  46. package/coverage/lcov-report/src/api/controllers/public/utils.ts.html +1 -1
  47. package/coverage/lcov-report/src/api/controllers/query/import/index.html +1 -1
  48. package/coverage/lcov-report/src/api/controllers/query/import/index.ts.html +1 -1
  49. package/coverage/lcov-report/src/api/controllers/query/import/sources/base/index.html +1 -1
  50. package/coverage/lcov-report/src/api/controllers/query/import/sources/base/index.ts.html +1 -1
  51. package/coverage/lcov-report/src/api/controllers/query/import/sources/base/openapi.ts.html +1 -1
  52. package/coverage/lcov-report/src/api/controllers/query/import/sources/curl.ts.html +1 -1
  53. package/coverage/lcov-report/src/api/controllers/query/import/sources/index.html +1 -1
  54. package/coverage/lcov-report/src/api/controllers/query/import/sources/openapi2.ts.html +1 -1
  55. package/coverage/lcov-report/src/api/controllers/query/import/sources/openapi3.ts.html +1 -1
  56. package/coverage/lcov-report/src/api/controllers/query/index.html +1 -1
  57. package/coverage/lcov-report/src/api/controllers/query/index.ts.html +1 -1
  58. package/coverage/lcov-report/src/api/controllers/query/validation.ts.html +1 -1
  59. package/coverage/lcov-report/src/api/controllers/role.ts.html +1 -1
  60. package/coverage/lcov-report/src/api/controllers/routing.ts.html +1 -1
  61. package/coverage/lcov-report/src/api/controllers/row/ExternalRequest.ts.html +1 -1
  62. package/coverage/lcov-report/src/api/controllers/row/external.ts.html +1 -1
  63. package/coverage/lcov-report/src/api/controllers/row/index.html +1 -1
  64. package/coverage/lcov-report/src/api/controllers/row/index.ts.html +1 -1
  65. package/coverage/lcov-report/src/api/controllers/row/internal.ts.html +1 -1
  66. package/coverage/lcov-report/src/api/controllers/row/internalSearch.ts.html +1 -1
  67. package/coverage/lcov-report/src/api/controllers/row/staticFormula.ts.html +1 -1
  68. package/coverage/lcov-report/src/api/controllers/row/utils.ts.html +1 -1
  69. package/coverage/lcov-report/src/api/controllers/screen.ts.html +1 -1
  70. package/coverage/lcov-report/src/api/controllers/script.ts.html +1 -1
  71. package/coverage/lcov-report/src/api/controllers/static/index.html +1 -1
  72. package/coverage/lcov-report/src/api/controllers/static/index.ts.html +1 -1
  73. package/coverage/lcov-report/src/api/controllers/table/bulkFormula.ts.html +1 -1
  74. package/coverage/lcov-report/src/api/controllers/table/external.ts.html +1 -1
  75. package/coverage/lcov-report/src/api/controllers/table/index.html +1 -1
  76. package/coverage/lcov-report/src/api/controllers/table/index.ts.html +1 -1
  77. package/coverage/lcov-report/src/api/controllers/table/internal.ts.html +1 -1
  78. package/coverage/lcov-report/src/api/controllers/table/utils.ts.html +1 -1
  79. package/coverage/lcov-report/src/api/controllers/templates.ts.html +1 -1
  80. package/coverage/lcov-report/src/api/controllers/user.ts.html +13 -184
  81. package/coverage/lcov-report/src/api/controllers/view/exporters.ts.html +1 -1
  82. package/coverage/lcov-report/src/api/controllers/view/index.html +1 -1
  83. package/coverage/lcov-report/src/api/controllers/view/index.ts.html +1 -1
  84. package/coverage/lcov-report/src/api/controllers/view/utils.ts.html +1 -1
  85. package/coverage/lcov-report/src/api/controllers/view/viewBuilder.ts.html +1 -1
  86. package/coverage/lcov-report/src/api/controllers/webhook.ts.html +1 -1
  87. package/coverage/lcov-report/src/api/index.html +1 -1
  88. package/coverage/lcov-report/src/api/index.ts.html +1 -1
  89. package/coverage/lcov-report/src/api/routes/analytics.ts.html +1 -1
  90. package/coverage/lcov-report/src/api/routes/apikeys.ts.html +1 -1
  91. package/coverage/lcov-report/src/api/routes/application.ts.html +1 -1
  92. package/coverage/lcov-report/src/api/routes/auth.ts.html +1 -1
  93. package/coverage/lcov-report/src/api/routes/automation.ts.html +1 -1
  94. package/coverage/lcov-report/src/api/routes/backup.ts.html +1 -1
  95. package/coverage/lcov-report/src/api/routes/cloud.ts.html +1 -1
  96. package/coverage/lcov-report/src/api/routes/component.ts.html +1 -1
  97. package/coverage/lcov-report/src/api/routes/datasource.ts.html +1 -1
  98. package/coverage/lcov-report/src/api/routes/deploy.ts.html +1 -1
  99. package/coverage/lcov-report/src/api/routes/dev.ts.html +1 -1
  100. package/coverage/lcov-report/src/api/routes/index.html +1 -1
  101. package/coverage/lcov-report/src/api/routes/index.ts.html +1 -1
  102. package/coverage/lcov-report/src/api/routes/integration.ts.html +1 -1
  103. package/coverage/lcov-report/src/api/routes/layout.ts.html +1 -1
  104. package/coverage/lcov-report/src/api/routes/metadata.ts.html +1 -1
  105. package/coverage/lcov-report/src/api/routes/migrations.ts.html +1 -1
  106. package/coverage/lcov-report/src/api/routes/permission.ts.html +1 -1
  107. package/coverage/lcov-report/src/api/routes/plugin.ts.html +1 -1
  108. package/coverage/lcov-report/src/api/routes/public/applications.ts.html +1 -1
  109. package/coverage/lcov-report/src/api/routes/public/index.html +1 -1
  110. package/coverage/lcov-report/src/api/routes/public/index.ts.html +1 -1
  111. package/coverage/lcov-report/src/api/routes/public/middleware/index.html +1 -1
  112. package/coverage/lcov-report/src/api/routes/public/middleware/mapper.ts.html +1 -1
  113. package/coverage/lcov-report/src/api/routes/public/queries.ts.html +1 -1
  114. package/coverage/lcov-report/src/api/routes/public/rows.ts.html +1 -1
  115. package/coverage/lcov-report/src/api/routes/public/tables.ts.html +1 -1
  116. package/coverage/lcov-report/src/api/routes/public/users.ts.html +1 -1
  117. package/coverage/lcov-report/src/api/routes/public/utils/Endpoint.ts.html +1 -1
  118. package/coverage/lcov-report/src/api/routes/public/utils/index.html +1 -1
  119. package/coverage/lcov-report/src/api/routes/query.ts.html +1 -1
  120. package/coverage/lcov-report/src/api/routes/role.ts.html +1 -1
  121. package/coverage/lcov-report/src/api/routes/routing.ts.html +1 -1
  122. package/coverage/lcov-report/src/api/routes/row.ts.html +1 -1
  123. package/coverage/lcov-report/src/api/routes/screen.ts.html +1 -1
  124. package/coverage/lcov-report/src/api/routes/script.ts.html +1 -1
  125. package/coverage/lcov-report/src/api/routes/static.ts.html +1 -1
  126. package/coverage/lcov-report/src/api/routes/table.ts.html +1 -1
  127. package/coverage/lcov-report/src/api/routes/templates.ts.html +1 -1
  128. package/coverage/lcov-report/src/api/routes/tests/utilities/TestFunctions.ts.html +1 -1
  129. package/coverage/lcov-report/src/api/routes/tests/utilities/index.html +1 -1
  130. package/coverage/lcov-report/src/api/routes/tests/utilities/index.ts.html +1 -1
  131. package/coverage/lcov-report/src/api/routes/user.ts.html +1 -1
  132. package/coverage/lcov-report/src/api/routes/utils/index.html +1 -1
  133. package/coverage/lcov-report/src/api/routes/utils/validators.ts.html +1 -1
  134. package/coverage/lcov-report/src/api/routes/view.ts.html +1 -1
  135. package/coverage/lcov-report/src/api/routes/webhook.ts.html +1 -1
  136. package/coverage/lcov-report/src/app.ts.html +1 -1
  137. package/coverage/lcov-report/src/automations/actions.ts.html +1 -1
  138. package/coverage/lcov-report/src/automations/automationUtils.ts.html +1 -1
  139. package/coverage/lcov-report/src/automations/bullboard.ts.html +1 -1
  140. package/coverage/lcov-report/src/automations/index.html +1 -1
  141. package/coverage/lcov-report/src/automations/index.ts.html +1 -1
  142. package/coverage/lcov-report/src/automations/logging/index.html +1 -1
  143. package/coverage/lcov-report/src/automations/logging/index.ts.html +1 -1
  144. package/coverage/lcov-report/src/automations/steps/bash.ts.html +1 -1
  145. package/coverage/lcov-report/src/automations/steps/createRow.ts.html +1 -1
  146. package/coverage/lcov-report/src/automations/steps/delay.ts.html +1 -1
  147. package/coverage/lcov-report/src/automations/steps/deleteRow.ts.html +1 -1
  148. package/coverage/lcov-report/src/automations/steps/discord.ts.html +1 -1
  149. package/coverage/lcov-report/src/automations/steps/executeQuery.ts.html +1 -1
  150. package/coverage/lcov-report/src/automations/steps/executeScript.ts.html +1 -1
  151. package/coverage/lcov-report/src/automations/steps/filter.ts.html +1 -1
  152. package/coverage/lcov-report/src/automations/steps/index.html +1 -1
  153. package/coverage/lcov-report/src/automations/steps/integromat.ts.html +1 -1
  154. package/coverage/lcov-report/src/automations/steps/loop.ts.html +1 -1
  155. package/coverage/lcov-report/src/automations/steps/outgoingWebhook.ts.html +1 -1
  156. package/coverage/lcov-report/src/automations/steps/queryRows.ts.html +1 -1
  157. package/coverage/lcov-report/src/automations/steps/sendSmtpEmail.ts.html +1 -1
  158. package/coverage/lcov-report/src/automations/steps/serverLog.ts.html +1 -1
  159. package/coverage/lcov-report/src/automations/steps/slack.ts.html +1 -1
  160. package/coverage/lcov-report/src/automations/steps/updateRow.ts.html +1 -1
  161. package/coverage/lcov-report/src/automations/steps/utils.ts.html +1 -1
  162. package/coverage/lcov-report/src/automations/steps/zapier.ts.html +1 -1
  163. package/coverage/lcov-report/src/automations/tests/utilities/index.html +1 -1
  164. package/coverage/lcov-report/src/automations/tests/utilities/index.ts.html +1 -1
  165. package/coverage/lcov-report/src/automations/triggerInfo/app.ts.html +1 -1
  166. package/coverage/lcov-report/src/automations/triggerInfo/cron.ts.html +1 -1
  167. package/coverage/lcov-report/src/automations/triggerInfo/index.html +1 -1
  168. package/coverage/lcov-report/src/automations/triggerInfo/index.ts.html +1 -1
  169. package/coverage/lcov-report/src/automations/triggerInfo/rowDeleted.ts.html +1 -1
  170. package/coverage/lcov-report/src/automations/triggerInfo/rowSaved.ts.html +1 -1
  171. package/coverage/lcov-report/src/automations/triggerInfo/rowUpdated.ts.html +1 -1
  172. package/coverage/lcov-report/src/automations/triggerInfo/webhook.ts.html +1 -1
  173. package/coverage/lcov-report/src/automations/triggers.ts.html +1 -1
  174. package/coverage/lcov-report/src/automations/utils.ts.html +1 -1
  175. package/coverage/lcov-report/src/constants/index.html +1 -1
  176. package/coverage/lcov-report/src/constants/index.ts.html +1 -1
  177. package/coverage/lcov-report/src/constants/layouts.ts.html +1 -1
  178. package/coverage/lcov-report/src/constants/screens.ts.html +1 -1
  179. package/coverage/lcov-report/src/db/defaultData/datasource_bb_default.ts.html +1 -1
  180. package/coverage/lcov-report/src/db/defaultData/employeeImport.ts.html +1 -1
  181. package/coverage/lcov-report/src/db/defaultData/expensesImport.ts.html +1 -1
  182. package/coverage/lcov-report/src/db/defaultData/index.html +1 -1
  183. package/coverage/lcov-report/src/db/defaultData/inventoryImport.ts.html +1 -1
  184. package/coverage/lcov-report/src/db/defaultData/jobsImport.ts.html +1 -1
  185. package/coverage/lcov-report/src/db/dynamoClient.ts.html +1 -1
  186. package/coverage/lcov-report/src/db/inMemoryView.ts.html +1 -1
  187. package/coverage/lcov-report/src/db/index.html +1 -1
  188. package/coverage/lcov-report/src/db/index.ts.html +1 -1
  189. package/coverage/lcov-report/src/db/linkedRows/LinkController.ts.html +1 -1
  190. package/coverage/lcov-report/src/db/linkedRows/LinkDocument.ts.html +1 -1
  191. package/coverage/lcov-report/src/db/linkedRows/index.html +1 -1
  192. package/coverage/lcov-report/src/db/linkedRows/index.ts.html +1 -1
  193. package/coverage/lcov-report/src/db/linkedRows/linkUtils.ts.html +1 -1
  194. package/coverage/lcov-report/src/db/newid.ts.html +1 -1
  195. package/coverage/lcov-report/src/db/utils.ts.html +1 -1
  196. package/coverage/lcov-report/src/definitions/automations.ts.html +1 -1
  197. package/coverage/lcov-report/src/definitions/datasource.ts.html +1 -1
  198. package/coverage/lcov-report/src/definitions/index.html +1 -1
  199. package/coverage/lcov-report/src/environment.ts.html +1 -1
  200. package/coverage/lcov-report/src/events/AutomationEmitter.ts.html +1 -1
  201. package/coverage/lcov-report/src/events/BudibaseEmitter.ts.html +1 -1
  202. package/coverage/lcov-report/src/events/index.html +1 -1
  203. package/coverage/lcov-report/src/events/index.ts.html +1 -1
  204. package/coverage/lcov-report/src/events/utils.ts.html +1 -1
  205. package/coverage/lcov-report/src/index.html +1 -1
  206. package/coverage/lcov-report/src/index.ts.html +1 -1
  207. package/coverage/lcov-report/src/integrations/airtable.ts.html +1 -1
  208. package/coverage/lcov-report/src/integrations/arangodb.ts.html +1 -1
  209. package/coverage/lcov-report/src/integrations/base/index.html +1 -1
  210. package/coverage/lcov-report/src/integrations/base/query.ts.html +1 -1
  211. package/coverage/lcov-report/src/integrations/base/sql.ts.html +1 -1
  212. package/coverage/lcov-report/src/integrations/base/sqlTable.ts.html +1 -1
  213. package/coverage/lcov-report/src/integrations/base/utils.ts.html +1 -1
  214. package/coverage/lcov-report/src/integrations/couchdb.ts.html +1 -1
  215. package/coverage/lcov-report/src/integrations/dynamodb.ts.html +1 -1
  216. package/coverage/lcov-report/src/integrations/elasticsearch.ts.html +1 -1
  217. package/coverage/lcov-report/src/integrations/firebase.ts.html +1 -1
  218. package/coverage/lcov-report/src/integrations/googlesheets.ts.html +1 -1
  219. package/coverage/lcov-report/src/integrations/index.html +1 -1
  220. package/coverage/lcov-report/src/integrations/index.ts.html +1 -1
  221. package/coverage/lcov-report/src/integrations/microsoftSqlServer.ts.html +1 -1
  222. package/coverage/lcov-report/src/integrations/mongodb.ts.html +1 -1
  223. package/coverage/lcov-report/src/integrations/mysql.ts.html +1 -1
  224. package/coverage/lcov-report/src/integrations/oracle.ts.html +1 -1
  225. package/coverage/lcov-report/src/integrations/postgres.ts.html +1 -1
  226. package/coverage/lcov-report/src/integrations/queries/index.html +1 -1
  227. package/coverage/lcov-report/src/integrations/queries/sql.ts.html +1 -1
  228. package/coverage/lcov-report/src/integrations/redis.ts.html +1 -1
  229. package/coverage/lcov-report/src/integrations/rest.ts.html +1 -1
  230. package/coverage/lcov-report/src/integrations/s3.ts.html +1 -1
  231. package/coverage/lcov-report/src/integrations/snowflake.ts.html +1 -1
  232. package/coverage/lcov-report/src/integrations/tests/TestConfiguration.js.html +1 -1
  233. package/coverage/lcov-report/src/integrations/tests/index.html +1 -1
  234. package/coverage/lcov-report/src/integrations/utils.ts.html +1 -1
  235. package/coverage/lcov-report/src/middleware/appInfo.ts.html +1 -1
  236. package/coverage/lcov-report/src/middleware/authorized.ts.html +1 -1
  237. package/coverage/lcov-report/src/middleware/builder.ts.html +1 -1
  238. package/coverage/lcov-report/src/middleware/currentapp.ts.html +1 -1
  239. package/coverage/lcov-report/src/middleware/index.html +1 -1
  240. package/coverage/lcov-report/src/middleware/joi-validator.ts.html +1 -1
  241. package/coverage/lcov-report/src/middleware/publicApi.ts.html +1 -1
  242. package/coverage/lcov-report/src/middleware/resourceId.ts.html +1 -1
  243. package/coverage/lcov-report/src/middleware/selfhost.ts.html +1 -1
  244. package/coverage/lcov-report/src/middleware/utils.ts.html +1 -1
  245. package/coverage/lcov-report/src/migrations/functions/appUrls.ts.html +8 -29
  246. package/coverage/lcov-report/src/migrations/functions/backfill/app/automations.ts.html +1 -1
  247. package/coverage/lcov-report/src/migrations/functions/backfill/app/datasources.ts.html +1 -1
  248. package/coverage/lcov-report/src/migrations/functions/backfill/app/index.html +1 -1
  249. package/coverage/lcov-report/src/migrations/functions/backfill/app/layouts.ts.html +1 -1
  250. package/coverage/lcov-report/src/migrations/functions/backfill/app/queries.ts.html +1 -1
  251. package/coverage/lcov-report/src/migrations/functions/backfill/app/roles.ts.html +1 -1
  252. package/coverage/lcov-report/src/migrations/functions/backfill/app/screens.ts.html +1 -1
  253. package/coverage/lcov-report/src/migrations/functions/backfill/app/tables.ts.html +1 -1
  254. package/coverage/lcov-report/src/migrations/functions/backfill/app.ts.html +1 -1
  255. package/coverage/lcov-report/src/migrations/functions/backfill/global/configs.ts.html +1 -1
  256. package/coverage/lcov-report/src/migrations/functions/backfill/global/index.html +1 -1
  257. package/coverage/lcov-report/src/migrations/functions/backfill/global/quotas.ts.html +1 -1
  258. package/coverage/lcov-report/src/migrations/functions/backfill/global/users.ts.html +1 -1
  259. package/coverage/lcov-report/src/migrations/functions/backfill/global.ts.html +1 -1
  260. package/coverage/lcov-report/src/migrations/functions/backfill/index.html +1 -1
  261. package/coverage/lcov-report/src/migrations/functions/backfill/index.ts.html +1 -1
  262. package/coverage/lcov-report/src/migrations/functions/backfill/installation.ts.html +1 -1
  263. package/coverage/lcov-report/src/migrations/functions/index.html +11 -11
  264. package/coverage/lcov-report/src/migrations/functions/syncQuotas.ts.html +1 -1
  265. package/coverage/lcov-report/src/migrations/functions/tableSettings.ts.html +1 -1
  266. package/coverage/lcov-report/src/migrations/functions/usageQuotas/index.html +1 -1
  267. package/coverage/lcov-report/src/migrations/functions/usageQuotas/index.ts.html +1 -1
  268. package/coverage/lcov-report/src/migrations/functions/usageQuotas/syncApps.ts.html +1 -1
  269. package/coverage/lcov-report/src/migrations/functions/usageQuotas/syncPlugins.ts.html +1 -1
  270. package/coverage/lcov-report/src/migrations/functions/usageQuotas/syncRows.ts.html +1 -1
  271. package/coverage/lcov-report/src/migrations/functions/userEmailViewCasing.ts.html +1 -1
  272. package/coverage/lcov-report/src/migrations/index.html +1 -1
  273. package/coverage/lcov-report/src/migrations/index.ts.html +1 -1
  274. package/coverage/lcov-report/src/migrations/tests/helpers.ts.html +1 -1
  275. package/coverage/lcov-report/src/migrations/tests/index.html +1 -1
  276. package/coverage/lcov-report/src/migrations/tests/structures.ts.html +1 -1
  277. package/coverage/lcov-report/src/sdk/app/applications/index.html +146 -0
  278. package/coverage/lcov-report/src/sdk/app/applications/index.ts.html +106 -0
  279. package/coverage/lcov-report/src/sdk/app/applications/sync.ts.html +244 -0
  280. package/coverage/lcov-report/src/sdk/app/applications/utils.ts.html +136 -0
  281. package/coverage/lcov-report/src/sdk/app/automations/index.html +1 -1
  282. package/coverage/lcov-report/src/sdk/app/automations/index.ts.html +3 -3
  283. package/coverage/lcov-report/src/sdk/app/automations/webhook.ts.html +6 -6
  284. package/coverage/lcov-report/src/sdk/app/backups/constants.ts.html +3 -3
  285. package/coverage/lcov-report/src/sdk/app/backups/exports.ts.html +17 -17
  286. package/coverage/lcov-report/src/sdk/app/backups/imports.ts.html +17 -17
  287. package/coverage/lcov-report/src/sdk/app/backups/index.html +1 -1
  288. package/coverage/lcov-report/src/sdk/app/backups/index.ts.html +5 -5
  289. package/coverage/lcov-report/src/sdk/app/backups/statistics.ts.html +7 -7
  290. package/coverage/lcov-report/src/sdk/app/tables/index.html +1 -1
  291. package/coverage/lcov-report/src/sdk/app/tables/index.ts.html +5 -5
  292. package/coverage/lcov-report/src/sdk/index.html +5 -5
  293. package/coverage/lcov-report/src/sdk/index.ts.html +15 -12
  294. package/coverage/lcov-report/src/sdk/users/index.html +131 -0
  295. package/coverage/lcov-report/src/sdk/users/index.ts.html +100 -0
  296. package/coverage/lcov-report/src/sdk/users/utils.ts.html +277 -0
  297. package/coverage/lcov-report/src/startup.ts.html +1 -1
  298. package/coverage/lcov-report/src/tests/utilities/TestConfiguration.ts.html +1 -1
  299. package/coverage/lcov-report/src/tests/utilities/controllers.ts.html +1 -1
  300. package/coverage/lcov-report/src/tests/utilities/index.html +1 -1
  301. package/coverage/lcov-report/src/tests/utilities/index.ts.html +1 -1
  302. package/coverage/lcov-report/src/tests/utilities/structures.ts.html +1 -1
  303. package/coverage/lcov-report/src/threads/automation.ts.html +1 -1
  304. package/coverage/lcov-report/src/threads/index.html +1 -1
  305. package/coverage/lcov-report/src/threads/index.ts.html +1 -1
  306. package/coverage/lcov-report/src/threads/query.ts.html +1 -1
  307. package/coverage/lcov-report/src/threads/utils.ts.html +1 -1
  308. package/coverage/lcov-report/src/utilities/budibaseDir.ts.html +1 -1
  309. package/coverage/lcov-report/src/utilities/centralPath.ts.html +1 -1
  310. package/coverage/lcov-report/src/utilities/csvParser.ts.html +1 -1
  311. package/coverage/lcov-report/src/utilities/fileSystem/clientLibrary.ts.html +1 -1
  312. package/coverage/lcov-report/src/utilities/fileSystem/index.html +1 -1
  313. package/coverage/lcov-report/src/utilities/fileSystem/index.ts.html +1 -1
  314. package/coverage/lcov-report/src/utilities/fileSystem/processor.ts.html +1 -1
  315. package/coverage/lcov-report/src/utilities/global.ts.html +34 -34
  316. package/coverage/lcov-report/src/utilities/index.html +1 -1
  317. package/coverage/lcov-report/src/utilities/index.ts.html +1 -1
  318. package/coverage/lcov-report/src/utilities/plugins.ts.html +1 -1
  319. package/coverage/lcov-report/src/utilities/redis.ts.html +1 -1
  320. package/coverage/lcov-report/src/utilities/routing/index.html +1 -1
  321. package/coverage/lcov-report/src/utilities/routing/index.ts.html +1 -1
  322. package/coverage/lcov-report/src/utilities/rowProcessor/index.html +1 -1
  323. package/coverage/lcov-report/src/utilities/rowProcessor/index.ts.html +1 -1
  324. package/coverage/lcov-report/src/utilities/rowProcessor/map.ts.html +1 -1
  325. package/coverage/lcov-report/src/utilities/rowProcessor/utils.ts.html +1 -1
  326. package/coverage/lcov-report/src/utilities/scriptRunner.ts.html +1 -1
  327. package/coverage/lcov-report/src/utilities/security.ts.html +1 -1
  328. package/coverage/lcov-report/src/utilities/statusCodes.ts.html +1 -1
  329. package/coverage/lcov-report/src/utilities/usageQuota/index.html +15 -15
  330. package/coverage/lcov-report/src/utilities/usageQuota/rows.ts.html +13 -13
  331. package/coverage/lcov-report/src/utilities/usageQuota/usageQuoteReset.ts.html +1 -1
  332. package/coverage/lcov-report/src/utilities/users.ts.html +1 -1
  333. package/coverage/lcov-report/src/utilities/workerRequests.ts.html +1 -1
  334. package/coverage/lcov-report/src/watch.ts.html +1 -1
  335. package/coverage/lcov-report/src/websocket.ts.html +1 -1
  336. package/coverage/lcov.info +886 -842
  337. package/dist/api/controllers/application.js +419 -438
  338. package/dist/api/controllers/cloud.js +1 -0
  339. package/dist/api/controllers/user.js +7 -48
  340. package/dist/migrations/functions/appUrls.js +5 -9
  341. package/dist/package.json +6 -6
  342. package/dist/sdk/app/applications/index.js +28 -0
  343. package/dist/sdk/app/applications/sync.js +66 -0
  344. package/dist/sdk/app/applications/utils.js +21 -0
  345. package/dist/sdk/index.js +4 -2
  346. package/dist/sdk/users/index.js +27 -0
  347. package/dist/sdk/users/utils.js +65 -0
  348. package/dist/tsconfig.build.tsbuildinfo +1 -1
  349. package/package.json +7 -7
  350. package/src/api/controllers/application.ts +55 -104
  351. package/src/api/controllers/cloud.ts +1 -0
  352. package/src/api/controllers/user.ts +4 -61
  353. package/src/api/routes/tests/application.spec.js +0 -1
  354. package/src/migrations/functions/appUrls.ts +2 -9
  355. package/src/sdk/app/applications/index.ts +7 -0
  356. package/src/sdk/app/applications/sync.ts +53 -0
  357. package/src/sdk/app/applications/utils.ts +17 -0
  358. package/src/sdk/index.ts +4 -3
  359. package/src/sdk/users/index.ts +5 -0
  360. package/src/sdk/users/utils.ts +64 -0
@@ -12,7 +12,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.updateAppPackage = exports.sync = exports.destroy = exports.revertClient = exports.updateClient = exports.update = exports.create = exports.fetchAppPackage = exports.fetchAppDefinition = exports.fetch = exports.getAppUrl = void 0;
15
+ exports.updateAppPackage = exports.sync = exports.destroy = exports.revertClient = exports.updateClient = exports.update = exports.create = exports.fetchAppPackage = exports.fetchAppDefinition = exports.fetch = void 0;
16
16
  const environment_1 = __importDefault(require("../../environment"));
17
17
  const package_json_1 = __importDefault(require("../../../package.json"));
18
18
  const staticViews_1 = require("../../db/views/staticViews");
@@ -25,7 +25,6 @@ const workerRequests_1 = require("../../utilities/workerRequests");
25
25
  const utilities_1 = require("../../utilities");
26
26
  const redis_1 = require("../../utilities/redis");
27
27
  const clientLibrary_1 = require("../../utilities/fileSystem/clientLibrary");
28
- const user_1 = require("./user");
29
28
  const utils_2 = require("../../automations/utils");
30
29
  const logging_1 = require("../../automations/logging");
31
30
  const rows_1 = require("../../utilities/usageQuota/rows");
@@ -34,7 +33,6 @@ const types_1 = require("@budibase/types");
34
33
  const layouts_1 = require("../../constants/layouts");
35
34
  const plugins_1 = require("../../utilities/plugins");
36
35
  const sdk_1 = __importDefault(require("../../sdk"));
37
- const URL_REGEX_SLASH = /\/|\\/g;
38
36
  // utility function, need to do away with this
39
37
  function getLayouts() {
40
38
  return __awaiter(this, void 0, void 0, function* () {
@@ -53,36 +51,20 @@ function getScreens() {
53
51
  });
54
52
  }
55
53
  function getUserRoleId(ctx) {
56
- return !ctx.user.role || !ctx.user.role._id
54
+ var _a;
55
+ return !((_a = ctx.user) === null || _a === void 0 ? void 0 : _a.role) || !ctx.user.role._id
57
56
  ? backend_core_1.roles.BUILTIN_ROLE_IDS.PUBLIC
58
57
  : ctx.user.role._id;
59
58
  }
60
- const getAppUrl = (ctx) => {
61
- // construct the url
62
- let url;
63
- if (ctx.request.body.url) {
64
- // if the url is provided, use that
65
- url = encodeURI(ctx.request.body.url);
66
- }
67
- else if (ctx.request.body.name) {
68
- // otherwise use the name
69
- url = encodeURI(`${ctx.request.body.name}`);
70
- }
71
- if (url) {
72
- url = `/${url.replace(URL_REGEX_SLASH, "")}`.toLowerCase();
73
- }
74
- return url;
75
- };
76
- exports.getAppUrl = getAppUrl;
77
- const checkAppUrl = (ctx, apps, url, currentAppId) => {
59
+ function checkAppUrl(ctx, apps, url, currentAppId) {
78
60
  if (currentAppId) {
79
61
  apps = apps.filter((app) => app.appId !== currentAppId);
80
62
  }
81
63
  if (apps.some((app) => app.url === url)) {
82
64
  ctx.throw(400, "App URL is already in use.");
83
65
  }
84
- };
85
- const checkAppName = (ctx, apps, name, currentAppId) => {
66
+ }
67
+ function checkAppName(ctx, apps, name, currentAppId) {
86
68
  // TODO: Replace with Joi
87
69
  if (!name) {
88
70
  ctx.throw(400, "Name is required");
@@ -93,7 +75,7 @@ const checkAppName = (ctx, apps, name, currentAppId) => {
93
75
  if (apps.some((app) => app.name === name)) {
94
76
  ctx.throw(400, "App name is already in use.");
95
77
  }
96
- };
78
+ }
97
79
  function createInstance(template, includeSampleData) {
98
80
  return __awaiter(this, void 0, void 0, function* () {
99
81
  const tenantId = backend_core_1.tenancy.isMultiTenant() ? backend_core_1.tenancy.getTenantId() : null;
@@ -134,446 +116,445 @@ function createInstance(template, includeSampleData) {
134
116
  return { _id: appId };
135
117
  });
136
118
  }
137
- const addDefaultTables = (db) => __awaiter(void 0, void 0, void 0, function* () {
138
- const defaultDbDocs = (0, datasource_bb_default_1.buildDefaultDocs)();
139
- // add in the default db data docs - tables, datasource, rows and links
140
- yield db.bulkDocs([...defaultDbDocs]);
141
- });
142
- const fetch = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
143
- const dev = ctx.query && ctx.query.status === utils_1.AppStatus.DEV;
144
- const all = ctx.query && ctx.query.status === utils_1.AppStatus.ALL;
145
- const apps = (yield backend_core_1.db.getAllApps({ dev, all }));
146
- const appIds = apps
147
- .filter((app) => app.status === "development")
148
- .map((app) => app.appId);
149
- // get the locks for all the dev apps
150
- if (dev || all) {
151
- const locks = yield (0, redis_1.getLocksById)(appIds);
152
- for (let app of apps) {
153
- const lock = locks[app.appId];
154
- if (lock) {
155
- app.lockedBy = lock;
156
- }
157
- else {
158
- // make sure its definitely not present
159
- delete app.lockedBy;
119
+ function addDefaultTables(db) {
120
+ return __awaiter(this, void 0, void 0, function* () {
121
+ const defaultDbDocs = (0, datasource_bb_default_1.buildDefaultDocs)();
122
+ // add in the default db data docs - tables, datasource, rows and links
123
+ yield db.bulkDocs([...defaultDbDocs]);
124
+ });
125
+ }
126
+ function fetch(ctx) {
127
+ return __awaiter(this, void 0, void 0, function* () {
128
+ const dev = ctx.query && ctx.query.status === utils_1.AppStatus.DEV;
129
+ const all = ctx.query && ctx.query.status === utils_1.AppStatus.ALL;
130
+ const apps = (yield backend_core_1.db.getAllApps({ dev, all }));
131
+ const appIds = apps
132
+ .filter((app) => app.status === "development")
133
+ .map((app) => app.appId);
134
+ // get the locks for all the dev apps
135
+ if (dev || all) {
136
+ const locks = yield (0, redis_1.getLocksById)(appIds);
137
+ for (let app of apps) {
138
+ const lock = locks[app.appId];
139
+ if (lock) {
140
+ app.lockedBy = lock;
141
+ }
142
+ else {
143
+ // make sure its definitely not present
144
+ delete app.lockedBy;
145
+ }
160
146
  }
161
147
  }
162
- }
163
- ctx.body = yield (0, logging_1.checkAppMetadata)(apps);
164
- });
148
+ ctx.body = yield (0, logging_1.checkAppMetadata)(apps);
149
+ });
150
+ }
165
151
  exports.fetch = fetch;
166
- const fetchAppDefinition = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
167
- const layouts = yield getLayouts();
168
- const userRoleId = getUserRoleId(ctx);
169
- const accessController = new backend_core_1.roles.AccessController();
170
- const screens = yield accessController.checkScreensAccess(yield getScreens(), userRoleId);
171
- ctx.body = {
172
- layouts,
173
- screens,
174
- libraries: ["@budibase/standard-components"],
175
- };
176
- });
177
- exports.fetchAppDefinition = fetchAppDefinition;
178
- const fetchAppPackage = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
179
- const db = backend_core_1.context.getAppDB();
180
- let application = yield db.get(utils_1.DocumentType.APP_METADATA);
181
- const layouts = yield getLayouts();
182
- let screens = yield getScreens();
183
- // Enrich plugin URLs
184
- application.usedPlugins = (0, plugins_1.enrichPluginURLs)(application.usedPlugins);
185
- // Only filter screens if the user is not a builder
186
- if (!(ctx.user.builder && ctx.user.builder.global)) {
152
+ function fetchAppDefinition(ctx) {
153
+ return __awaiter(this, void 0, void 0, function* () {
154
+ const layouts = yield getLayouts();
187
155
  const userRoleId = getUserRoleId(ctx);
188
156
  const accessController = new backend_core_1.roles.AccessController();
189
- screens = yield accessController.checkScreensAccess(screens, userRoleId);
190
- }
191
- ctx.body = {
192
- application,
193
- screens,
194
- layouts,
195
- clientLibPath: (0, utilities_1.clientLibraryPath)(ctx.params.appId, application.version),
196
- };
197
- });
157
+ const screens = yield accessController.checkScreensAccess(yield getScreens(), userRoleId);
158
+ ctx.body = {
159
+ layouts,
160
+ screens,
161
+ libraries: ["@budibase/standard-components"],
162
+ };
163
+ });
164
+ }
165
+ exports.fetchAppDefinition = fetchAppDefinition;
166
+ function fetchAppPackage(ctx) {
167
+ var _a;
168
+ return __awaiter(this, void 0, void 0, function* () {
169
+ const db = backend_core_1.context.getAppDB();
170
+ let application = yield db.get(utils_1.DocumentType.APP_METADATA);
171
+ const layouts = yield getLayouts();
172
+ let screens = yield getScreens();
173
+ // Enrich plugin URLs
174
+ application.usedPlugins = (0, plugins_1.enrichPluginURLs)(application.usedPlugins);
175
+ // Only filter screens if the user is not a builder
176
+ if (!(((_a = ctx.user) === null || _a === void 0 ? void 0 : _a.builder) && ctx.user.builder.global)) {
177
+ const userRoleId = getUserRoleId(ctx);
178
+ const accessController = new backend_core_1.roles.AccessController();
179
+ screens = yield accessController.checkScreensAccess(screens, userRoleId);
180
+ }
181
+ ctx.body = {
182
+ application,
183
+ screens,
184
+ layouts,
185
+ clientLibPath: (0, utilities_1.clientLibraryPath)(ctx.params.appId, application.version),
186
+ };
187
+ });
188
+ }
198
189
  exports.fetchAppPackage = fetchAppPackage;
199
- const performAppCreate = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
200
- const apps = yield backend_core_1.db.getAllApps({ dev: true });
201
- const name = ctx.request.body.name;
202
- checkAppName(ctx, apps, name);
203
- const url = (0, exports.getAppUrl)(ctx);
204
- checkAppUrl(ctx, apps, url);
205
- const { useTemplate, templateKey, templateString } = ctx.request.body;
206
- const instanceConfig = {
207
- useTemplate,
208
- key: templateKey,
209
- templateString,
210
- };
211
- if (ctx.request.files && ctx.request.files.templateFile) {
212
- instanceConfig.file = ctx.request.files.templateFile;
213
- }
214
- const includeSampleData = (0, utilities_1.isQsTrue)(ctx.request.body.sampleData);
215
- const instance = yield createInstance(instanceConfig, includeSampleData);
216
- const appId = instance._id;
217
- const db = backend_core_1.context.getAppDB();
218
- let newApplication = {
219
- _id: utils_1.DocumentType.APP_METADATA,
220
- _rev: undefined,
221
- appId,
222
- type: "app",
223
- version: package_json_1.default.version,
224
- componentLibraries: ["@budibase/standard-components"],
225
- name: name,
226
- url: url,
227
- template: templateKey,
228
- instance,
229
- tenantId: backend_core_1.tenancy.getTenantId(),
230
- updatedAt: new Date().toISOString(),
231
- createdAt: new Date().toISOString(),
232
- status: utils_1.AppStatus.DEV,
233
- navigation: {
234
- navigation: "Top",
235
- title: name,
236
- navWidth: "Large",
237
- navBackground: "var(--spectrum-global-color-gray-100)",
238
- links: [
239
- {
240
- url: "/home",
241
- text: "Home",
242
- },
243
- ],
244
- },
245
- theme: "spectrum--light",
246
- customTheme: {
247
- buttonBorderRadius: "16px",
248
- },
249
- };
250
- // If we used a template or imported an app there will be an existing doc.
251
- // Fetch and migrate some metadata from the existing app.
252
- try {
253
- const existing = yield db.get(utils_1.DocumentType.APP_METADATA);
254
- const keys = [
255
- "_rev",
256
- "navigation",
257
- "theme",
258
- "customTheme",
259
- "icon",
260
- ];
261
- keys.forEach(key => {
262
- if (existing[key]) {
263
- // @ts-ignore
264
- newApplication[key] = existing[key];
265
- }
266
- });
267
- // Migrate navigation settings and screens if required
268
- if (existing) {
269
- const navigation = yield migrateAppNavigation();
270
- if (navigation) {
271
- newApplication.navigation = navigation;
272
- }
190
+ function performAppCreate(ctx) {
191
+ return __awaiter(this, void 0, void 0, function* () {
192
+ const apps = (yield backend_core_1.db.getAllApps({ dev: true }));
193
+ const name = ctx.request.body.name, possibleUrl = ctx.request.body.url;
194
+ checkAppName(ctx, apps, name);
195
+ const url = sdk_1.default.applications.getAppUrl({ name, url: possibleUrl });
196
+ checkAppUrl(ctx, apps, url);
197
+ const { useTemplate, templateKey, templateString } = ctx.request.body;
198
+ const instanceConfig = {
199
+ useTemplate,
200
+ key: templateKey,
201
+ templateString,
202
+ };
203
+ if (ctx.request.files && ctx.request.files.templateFile) {
204
+ instanceConfig.file = ctx.request.files.templateFile;
273
205
  }
274
- }
275
- catch (err) {
276
- // Nothing to do
277
- }
278
- const response = yield db.put(newApplication, { force: true });
279
- newApplication._rev = response.rev;
280
- /* istanbul ignore next */
281
- if (!environment_1.default.isTest()) {
282
- yield (0, fileSystem_1.createApp)(appId);
283
- }
284
- yield backend_core_1.cache.app.invalidateAppMetadata(appId, newApplication);
285
- return newApplication;
286
- });
287
- const creationEvents = (request, app) => __awaiter(void 0, void 0, void 0, function* () {
288
- var _a;
289
- let creationFns = [];
290
- const body = request.body;
291
- if (body.useTemplate === "true") {
292
- // from template
293
- if (body.templateKey && body.templateKey !== "undefined") {
294
- creationFns.push(a => backend_core_1.events.app.templateImported(a, body.templateKey));
206
+ const includeSampleData = (0, utilities_1.isQsTrue)(ctx.request.body.sampleData);
207
+ const instance = yield createInstance(instanceConfig, includeSampleData);
208
+ const appId = instance._id;
209
+ const db = backend_core_1.context.getAppDB();
210
+ let newApplication = {
211
+ _id: utils_1.DocumentType.APP_METADATA,
212
+ _rev: undefined,
213
+ appId,
214
+ type: "app",
215
+ version: package_json_1.default.version,
216
+ componentLibraries: ["@budibase/standard-components"],
217
+ name: name,
218
+ url: url,
219
+ template: templateKey,
220
+ instance,
221
+ tenantId: backend_core_1.tenancy.getTenantId(),
222
+ updatedAt: new Date().toISOString(),
223
+ createdAt: new Date().toISOString(),
224
+ status: utils_1.AppStatus.DEV,
225
+ navigation: {
226
+ navigation: "Top",
227
+ title: name,
228
+ navWidth: "Large",
229
+ navBackground: "var(--spectrum-global-color-gray-100)",
230
+ links: [
231
+ {
232
+ url: "/home",
233
+ text: "Home",
234
+ },
235
+ ],
236
+ },
237
+ theme: "spectrum--light",
238
+ customTheme: {
239
+ buttonBorderRadius: "16px",
240
+ },
241
+ };
242
+ // If we used a template or imported an app there will be an existing doc.
243
+ // Fetch and migrate some metadata from the existing app.
244
+ try {
245
+ const existing = yield db.get(utils_1.DocumentType.APP_METADATA);
246
+ const keys = [
247
+ "_rev",
248
+ "navigation",
249
+ "theme",
250
+ "customTheme",
251
+ "icon",
252
+ ];
253
+ keys.forEach(key => {
254
+ if (existing[key]) {
255
+ // @ts-ignore
256
+ newApplication[key] = existing[key];
257
+ }
258
+ });
259
+ // Migrate navigation settings and screens if required
260
+ if (existing) {
261
+ const navigation = yield migrateAppNavigation();
262
+ if (navigation) {
263
+ newApplication.navigation = navigation;
264
+ }
265
+ }
295
266
  }
296
- // from file
297
- else if ((_a = request.files) === null || _a === void 0 ? void 0 : _a.templateFile) {
298
- creationFns.push(a => backend_core_1.events.app.fileImported(a));
267
+ catch (err) {
268
+ // Nothing to do
299
269
  }
300
- // unknown
301
- else {
302
- console.error("Could not determine template creation event");
270
+ const response = yield db.put(newApplication, { force: true });
271
+ newApplication._rev = response.rev;
272
+ /* istanbul ignore next */
273
+ if (!environment_1.default.isTest()) {
274
+ yield (0, fileSystem_1.createApp)(appId);
303
275
  }
304
- }
305
- creationFns.push(a => backend_core_1.events.app.created(a));
306
- for (let fn of creationFns) {
307
- yield fn(app);
308
- }
309
- });
310
- const appPostCreate = (ctx, app) => __awaiter(void 0, void 0, void 0, function* () {
311
- const tenantId = backend_core_1.tenancy.getTenantId();
312
- yield backend_core_1.migrations.backPopulateMigrations({
313
- type: types_1.MigrationType.APP,
314
- tenantId,
315
- appId: app.appId,
276
+ yield backend_core_1.cache.app.invalidateAppMetadata(appId, newApplication);
277
+ return newApplication;
316
278
  });
317
- yield creationEvents(ctx.request, app);
318
- // app import & template creation
319
- if (ctx.request.body.useTemplate === "true") {
320
- const { rows } = yield (0, rows_1.getUniqueRows)([app.appId]);
321
- const rowCount = rows ? rows.length : 0;
322
- if (rowCount) {
323
- try {
324
- yield backend_core_1.context.doInAppContext(app.appId, () => {
325
- return pro_1.quotas.addRows(rowCount);
326
- });
279
+ }
280
+ function creationEvents(request, app) {
281
+ var _a;
282
+ return __awaiter(this, void 0, void 0, function* () {
283
+ let creationFns = [];
284
+ const body = request.body;
285
+ if (body.useTemplate === "true") {
286
+ // from template
287
+ if (body.templateKey && body.templateKey !== "undefined") {
288
+ creationFns.push(a => backend_core_1.events.app.templateImported(a, body.templateKey));
289
+ }
290
+ // from file
291
+ else if ((_a = request.files) === null || _a === void 0 ? void 0 : _a.templateFile) {
292
+ creationFns.push(a => backend_core_1.events.app.fileImported(a));
327
293
  }
328
- catch (err) {
329
- if (err.code && err.code === backend_core_1.errors.codes.USAGE_LIMIT_EXCEEDED) {
330
- // this import resulted in row usage exceeding the quota
331
- // delete the app
332
- // skip pre and post steps as no rows have been added to quotas yet
333
- ctx.params.appId = app.appId;
334
- yield destroyApp(ctx);
294
+ // unknown
295
+ else {
296
+ console.error("Could not determine template creation event");
297
+ }
298
+ }
299
+ creationFns.push(a => backend_core_1.events.app.created(a));
300
+ for (let fn of creationFns) {
301
+ yield fn(app);
302
+ }
303
+ });
304
+ }
305
+ function appPostCreate(ctx, app) {
306
+ return __awaiter(this, void 0, void 0, function* () {
307
+ const tenantId = backend_core_1.tenancy.getTenantId();
308
+ yield backend_core_1.migrations.backPopulateMigrations({
309
+ type: types_1.MigrationType.APP,
310
+ tenantId,
311
+ appId: app.appId,
312
+ });
313
+ yield creationEvents(ctx.request, app);
314
+ // app import & template creation
315
+ if (ctx.request.body.useTemplate === "true") {
316
+ const { rows } = yield (0, rows_1.getUniqueRows)([app.appId]);
317
+ const rowCount = rows ? rows.length : 0;
318
+ if (rowCount) {
319
+ try {
320
+ yield backend_core_1.context.doInAppContext(app.appId, () => {
321
+ return pro_1.quotas.addRows(rowCount);
322
+ });
323
+ }
324
+ catch (err) {
325
+ if (err.code && err.code === backend_core_1.errors.codes.USAGE_LIMIT_EXCEEDED) {
326
+ // this import resulted in row usage exceeding the quota
327
+ // delete the app
328
+ // skip pre- and post-steps as no rows have been added to quotas yet
329
+ ctx.params.appId = app.appId;
330
+ yield destroyApp(ctx);
331
+ }
332
+ throw err;
335
333
  }
336
- throw err;
337
334
  }
338
335
  }
339
- }
340
- });
341
- const create = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
342
- const newApplication = yield pro_1.quotas.addApp(() => performAppCreate(ctx));
343
- yield appPostCreate(ctx, newApplication);
344
- yield backend_core_1.cache.bustCache(backend_core_1.cache.CacheKey.CHECKLIST);
345
- ctx.body = newApplication;
346
- ctx.status = 200;
347
- });
336
+ });
337
+ }
338
+ function create(ctx) {
339
+ return __awaiter(this, void 0, void 0, function* () {
340
+ const newApplication = yield pro_1.quotas.addApp(() => performAppCreate(ctx));
341
+ yield appPostCreate(ctx, newApplication);
342
+ yield backend_core_1.cache.bustCache(backend_core_1.cache.CacheKey.CHECKLIST);
343
+ ctx.body = newApplication;
344
+ ctx.status = 200;
345
+ });
346
+ }
348
347
  exports.create = create;
349
348
  // This endpoint currently operates as a PATCH rather than a PUT
350
349
  // Thus name and url fields are handled only if present
351
- const update = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
352
- const apps = yield backend_core_1.db.getAllApps({ dev: true });
353
- // validation
354
- const name = ctx.request.body.name;
355
- if (name) {
356
- checkAppName(ctx, apps, name, ctx.params.appId);
357
- }
358
- const url = (0, exports.getAppUrl)(ctx);
359
- if (url) {
360
- checkAppUrl(ctx, apps, url, ctx.params.appId);
361
- ctx.request.body.url = url;
362
- }
363
- const app = yield (0, exports.updateAppPackage)(ctx.request.body, ctx.params.appId);
364
- yield backend_core_1.events.app.updated(app);
365
- ctx.status = 200;
366
- ctx.body = app;
367
- });
368
- exports.update = update;
369
- const updateClient = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
370
- // Get current app version
371
- const db = backend_core_1.context.getAppDB();
372
- const application = yield db.get(utils_1.DocumentType.APP_METADATA);
373
- const currentVersion = application.version;
374
- // Update client library and manifest
375
- if (!environment_1.default.isTest()) {
376
- yield (0, clientLibrary_1.backupClientLibrary)(ctx.params.appId);
377
- yield (0, clientLibrary_1.updateClientLibrary)(ctx.params.appId);
378
- }
379
- // Update versions in app package
380
- const updatedToVersion = package_json_1.default.version;
381
- const appPackageUpdates = {
382
- version: updatedToVersion,
383
- revertableVersion: currentVersion,
384
- };
385
- const app = yield (0, exports.updateAppPackage)(appPackageUpdates, ctx.params.appId);
386
- yield backend_core_1.events.app.versionUpdated(app, currentVersion, updatedToVersion);
387
- ctx.status = 200;
388
- ctx.body = app;
389
- });
390
- exports.updateClient = updateClient;
391
- const revertClient = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
392
- // Check app can be reverted
393
- const db = backend_core_1.context.getAppDB();
394
- const application = yield db.get(utils_1.DocumentType.APP_METADATA);
395
- if (!application.revertableVersion) {
396
- ctx.throw(400, "There is no version to revert to");
397
- }
398
- // Update client library and manifest
399
- if (!environment_1.default.isTest()) {
400
- yield (0, clientLibrary_1.revertClientLibrary)(ctx.params.appId);
401
- }
402
- // Update versions in app package
403
- const currentVersion = application.version;
404
- const revertedToVersion = application.revertableVersion;
405
- const appPackageUpdates = {
406
- version: revertedToVersion,
407
- revertableVersion: null,
408
- };
409
- const app = yield (0, exports.updateAppPackage)(appPackageUpdates, ctx.params.appId);
410
- yield backend_core_1.events.app.versionReverted(app, currentVersion, revertedToVersion);
411
- ctx.status = 200;
412
- ctx.body = app;
413
- });
414
- exports.revertClient = revertClient;
415
- const destroyApp = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
416
- let appId = ctx.params.appId;
417
- let isUnpublish = ctx.query && ctx.query.unpublish;
418
- if (isUnpublish) {
419
- appId = backend_core_1.db.getProdAppID(appId);
420
- }
421
- const db = isUnpublish ? backend_core_1.context.getProdAppDB() : backend_core_1.context.getAppDB();
422
- const app = yield db.get(utils_1.DocumentType.APP_METADATA);
423
- const result = yield db.destroy();
424
- if (isUnpublish) {
425
- yield backend_core_1.events.app.unpublished(app);
426
- }
427
- else {
428
- yield pro_1.quotas.removeApp();
429
- yield backend_core_1.events.app.deleted(app);
430
- }
431
- /* istanbul ignore next */
432
- if (!environment_1.default.isTest() && !isUnpublish) {
433
- yield (0, fileSystem_1.deleteApp)(appId);
434
- }
435
- // automations only in production
436
- if (isUnpublish) {
437
- yield (0, utils_2.cleanupAutomations)(appId);
438
- }
439
- // remove app role when the dev app is deleted (no trace of app anymore)
440
- else {
441
- yield (0, workerRequests_1.removeAppFromUserRoles)(ctx, appId);
442
- }
443
- yield backend_core_1.cache.app.invalidateAppMetadata(appId);
444
- return result;
445
- });
446
- const preDestroyApp = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
447
- const { rows } = yield (0, rows_1.getUniqueRows)([ctx.params.appId]);
448
- ctx.rowCount = rows.length;
449
- });
450
- const postDestroyApp = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
451
- const rowCount = ctx.rowCount;
452
- yield pro_1.groups.cleanupApp(ctx.params.appId);
453
- if (rowCount) {
454
- yield pro_1.quotas.removeRows(rowCount);
455
- }
456
- });
457
- const destroy = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
458
- yield preDestroyApp(ctx);
459
- const result = yield destroyApp(ctx);
460
- yield postDestroyApp(ctx);
461
- ctx.status = 200;
462
- ctx.body = result;
463
- });
464
- exports.destroy = destroy;
465
- const sync = (ctx, next) => __awaiter(void 0, void 0, void 0, function* () {
466
- if (environment_1.default.DISABLE_AUTO_PROD_APP_SYNC) {
350
+ function update(ctx) {
351
+ return __awaiter(this, void 0, void 0, function* () {
352
+ const apps = (yield backend_core_1.db.getAllApps({ dev: true }));
353
+ // validation
354
+ const name = ctx.request.body.name, possibleUrl = ctx.request.body.url;
355
+ if (name) {
356
+ checkAppName(ctx, apps, name, ctx.params.appId);
357
+ }
358
+ const url = sdk_1.default.applications.getAppUrl({ name, url: possibleUrl });
359
+ if (url) {
360
+ checkAppUrl(ctx, apps, url, ctx.params.appId);
361
+ ctx.request.body.url = url;
362
+ }
363
+ const app = yield updateAppPackage(ctx.request.body, ctx.params.appId);
364
+ yield backend_core_1.events.app.updated(app);
467
365
  ctx.status = 200;
468
- ctx.body = {
469
- message: "App sync disabled. You can reenable with the DISABLE_AUTO_PROD_APP_SYNC environment variable.",
366
+ ctx.body = app;
367
+ });
368
+ }
369
+ exports.update = update;
370
+ function updateClient(ctx) {
371
+ return __awaiter(this, void 0, void 0, function* () {
372
+ // Get current app version
373
+ const db = backend_core_1.context.getAppDB();
374
+ const application = yield db.get(utils_1.DocumentType.APP_METADATA);
375
+ const currentVersion = application.version;
376
+ // Update client library and manifest
377
+ if (!environment_1.default.isTest()) {
378
+ yield (0, clientLibrary_1.backupClientLibrary)(ctx.params.appId);
379
+ yield (0, clientLibrary_1.updateClientLibrary)(ctx.params.appId);
380
+ }
381
+ // Update versions in app package
382
+ const updatedToVersion = package_json_1.default.version;
383
+ const appPackageUpdates = {
384
+ version: updatedToVersion,
385
+ revertableVersion: currentVersion,
470
386
  };
471
- return next();
472
- }
473
- const appId = ctx.params.appId;
474
- if (!backend_core_1.db.isDevAppID(appId)) {
475
- ctx.throw(400, "This action cannot be performed for production apps");
476
- }
477
- // replicate prod to dev
478
- const prodAppId = backend_core_1.db.getProdAppID(appId);
479
- // specific case, want to make sure setup is skipped
480
- const prodDb = backend_core_1.context.getProdAppDB({ skip_setup: true });
481
- const exists = yield prodDb.exists();
482
- if (!exists) {
483
- // the database doesn't exist. Don't replicate
387
+ const app = yield updateAppPackage(appPackageUpdates, ctx.params.appId);
388
+ yield backend_core_1.events.app.versionUpdated(app, currentVersion, updatedToVersion);
484
389
  ctx.status = 200;
485
- ctx.body = {
486
- message: "App sync not required, app not deployed.",
487
- };
488
- return next();
489
- }
490
- const replication = new backend_core_1.db.Replication({
491
- source: prodAppId,
492
- target: appId,
390
+ ctx.body = app;
493
391
  });
494
- let error;
495
- try {
496
- yield replication.replicate(replication.appReplicateOpts());
497
- }
498
- catch (err) {
499
- error = err;
500
- }
501
- finally {
502
- yield replication.close();
503
- }
504
- // sync the users
505
- yield (0, user_1.syncGlobalUsers)();
506
- if (error) {
507
- ctx.throw(400, error);
508
- }
509
- else {
510
- ctx.body = {
511
- message: "App sync completed successfully.",
512
- };
513
- }
514
- });
515
- exports.sync = sync;
516
- const updateAppPackage = (appPackage, appId) => __awaiter(void 0, void 0, void 0, function* () {
517
- return backend_core_1.context.doInAppContext(appId, () => __awaiter(void 0, void 0, void 0, function* () {
392
+ }
393
+ exports.updateClient = updateClient;
394
+ function revertClient(ctx) {
395
+ return __awaiter(this, void 0, void 0, function* () {
396
+ // Check app can be reverted
518
397
  const db = backend_core_1.context.getAppDB();
519
398
  const application = yield db.get(utils_1.DocumentType.APP_METADATA);
520
- const newAppPackage = Object.assign(Object.assign({}, application), appPackage);
521
- if (appPackage._rev !== application._rev) {
522
- newAppPackage._rev = application._rev;
399
+ if (!application.revertableVersion) {
400
+ ctx.throw(400, "There is no version to revert to");
401
+ }
402
+ // Update client library and manifest
403
+ if (!environment_1.default.isTest()) {
404
+ yield (0, clientLibrary_1.revertClientLibrary)(ctx.params.appId);
405
+ }
406
+ // Update versions in app package
407
+ const currentVersion = application.version;
408
+ const revertedToVersion = application.revertableVersion;
409
+ const appPackageUpdates = {
410
+ version: revertedToVersion,
411
+ revertableVersion: null,
412
+ };
413
+ const app = yield updateAppPackage(appPackageUpdates, ctx.params.appId);
414
+ yield backend_core_1.events.app.versionReverted(app, currentVersion, revertedToVersion);
415
+ ctx.status = 200;
416
+ ctx.body = app;
417
+ });
418
+ }
419
+ exports.revertClient = revertClient;
420
+ function destroyApp(ctx) {
421
+ return __awaiter(this, void 0, void 0, function* () {
422
+ let appId = ctx.params.appId;
423
+ let isUnpublish = ctx.query && ctx.query.unpublish;
424
+ if (isUnpublish) {
425
+ appId = backend_core_1.db.getProdAppID(appId);
426
+ const devAppId = backend_core_1.db.getDevAppID(appId);
427
+ // sync before removing the published app
428
+ yield sdk_1.default.applications.syncApp(devAppId);
429
+ }
430
+ const db = isUnpublish ? backend_core_1.context.getProdAppDB() : backend_core_1.context.getAppDB();
431
+ const app = yield db.get(utils_1.DocumentType.APP_METADATA);
432
+ const result = yield db.destroy();
433
+ if (isUnpublish) {
434
+ yield backend_core_1.events.app.unpublished(app);
435
+ }
436
+ else {
437
+ yield pro_1.quotas.removeApp();
438
+ yield backend_core_1.events.app.deleted(app);
439
+ }
440
+ /* istanbul ignore next */
441
+ if (!environment_1.default.isTest() && !isUnpublish) {
442
+ yield (0, fileSystem_1.deleteApp)(appId);
443
+ }
444
+ // automations only in production
445
+ if (isUnpublish) {
446
+ yield (0, utils_2.cleanupAutomations)(appId);
447
+ }
448
+ // remove app role when the dev app is deleted (no trace of app anymore)
449
+ else {
450
+ yield (0, workerRequests_1.removeAppFromUserRoles)(ctx, appId);
523
451
  }
524
- // the locked by property is attached by server but generated from
525
- // Redis, shouldn't ever store it
526
- delete newAppPackage.lockedBy;
527
- yield db.put(newAppPackage);
528
- // remove any cached metadata, so that it will be updated
529
452
  yield backend_core_1.cache.app.invalidateAppMetadata(appId);
530
- return newAppPackage;
531
- }));
532
- });
453
+ return result;
454
+ });
455
+ }
456
+ function preDestroyApp(ctx) {
457
+ return __awaiter(this, void 0, void 0, function* () {
458
+ const { rows } = yield (0, rows_1.getUniqueRows)([ctx.params.appId]);
459
+ ctx.rowCount = rows.length;
460
+ });
461
+ }
462
+ function postDestroyApp(ctx) {
463
+ return __awaiter(this, void 0, void 0, function* () {
464
+ const rowCount = ctx.rowCount;
465
+ yield pro_1.groups.cleanupApp(ctx.params.appId);
466
+ if (rowCount) {
467
+ yield pro_1.quotas.removeRows(rowCount);
468
+ }
469
+ });
470
+ }
471
+ function destroy(ctx) {
472
+ return __awaiter(this, void 0, void 0, function* () {
473
+ yield preDestroyApp(ctx);
474
+ const result = yield destroyApp(ctx);
475
+ yield postDestroyApp(ctx);
476
+ ctx.status = 200;
477
+ ctx.body = result;
478
+ });
479
+ }
480
+ exports.destroy = destroy;
481
+ function sync(ctx) {
482
+ return __awaiter(this, void 0, void 0, function* () {
483
+ const appId = ctx.params.appId;
484
+ try {
485
+ ctx.body = yield sdk_1.default.applications.syncApp(appId);
486
+ }
487
+ catch (err) {
488
+ ctx.throw(err.status || 400, err.message);
489
+ }
490
+ });
491
+ }
492
+ exports.sync = sync;
493
+ function updateAppPackage(appPackage, appId) {
494
+ return __awaiter(this, void 0, void 0, function* () {
495
+ return backend_core_1.context.doInAppContext(appId, () => __awaiter(this, void 0, void 0, function* () {
496
+ const db = backend_core_1.context.getAppDB();
497
+ const application = yield db.get(utils_1.DocumentType.APP_METADATA);
498
+ const newAppPackage = Object.assign(Object.assign({}, application), appPackage);
499
+ if (appPackage._rev !== application._rev) {
500
+ newAppPackage._rev = application._rev;
501
+ }
502
+ // the locked by property is attached by server but generated from
503
+ // Redis, shouldn't ever store it
504
+ delete newAppPackage.lockedBy;
505
+ yield db.put(newAppPackage);
506
+ // remove any cached metadata, so that it will be updated
507
+ yield backend_core_1.cache.app.invalidateAppMetadata(appId);
508
+ return newAppPackage;
509
+ }));
510
+ });
511
+ }
533
512
  exports.updateAppPackage = updateAppPackage;
534
- const migrateAppNavigation = () => __awaiter(void 0, void 0, void 0, function* () {
535
- const db = backend_core_1.context.getAppDB();
536
- const existing = yield db.get(utils_1.DocumentType.APP_METADATA);
537
- const layouts = yield getLayouts();
538
- const screens = yield getScreens();
539
- // Migrate all screens, removing custom layouts
540
- for (let screen of screens) {
541
- if (!screen.layoutId) {
542
- continue;
513
+ function migrateAppNavigation() {
514
+ return __awaiter(this, void 0, void 0, function* () {
515
+ const db = backend_core_1.context.getAppDB();
516
+ const existing = yield db.get(utils_1.DocumentType.APP_METADATA);
517
+ const layouts = yield getLayouts();
518
+ const screens = yield getScreens();
519
+ // Migrate all screens, removing custom layouts
520
+ for (let screen of screens) {
521
+ if (!screen.layoutId) {
522
+ continue;
523
+ }
524
+ const layout = layouts.find(layout => layout._id === screen.layoutId);
525
+ screen.layoutId = undefined;
526
+ screen.showNavigation = (layout === null || layout === void 0 ? void 0 : layout.props.navigation) !== "None";
527
+ screen.width = (layout === null || layout === void 0 ? void 0 : layout.props.width) || "Large";
528
+ yield db.put(screen);
543
529
  }
544
- const layout = layouts.find(layout => layout._id === screen.layoutId);
545
- screen.layoutId = undefined;
546
- screen.showNavigation = (layout === null || layout === void 0 ? void 0 : layout.props.navigation) !== "None";
547
- screen.width = (layout === null || layout === void 0 ? void 0 : layout.props.width) || "Large";
548
- yield db.put(screen);
549
- }
550
- // Migrate layout navigation settings
551
- const { name, customTheme } = existing;
552
- const layout = layouts === null || layouts === void 0 ? void 0 : layouts.find((layout) => layout._id === layouts_1.BASE_LAYOUT_PROP_IDS.PRIVATE);
553
- if (layout && !existing.navigation) {
554
- let navigationSettings = {
555
- navigation: "Top",
556
- title: name,
557
- navWidth: "Large",
558
- navBackground: (customTheme === null || customTheme === void 0 ? void 0 : customTheme.navBackground) || "var(--spectrum-global-color-gray-50)",
559
- navTextColor: (customTheme === null || customTheme === void 0 ? void 0 : customTheme.navTextColor) || "var(--spectrum-global-color-gray-800)",
560
- };
561
- if (layout) {
562
- navigationSettings.hideLogo = layout.props.hideLogo;
563
- navigationSettings.hideTitle = layout.props.hideTitle;
564
- navigationSettings.title = layout.props.title || name;
565
- navigationSettings.logoUrl = layout.props.logoUrl;
566
- navigationSettings.links = layout.props.links;
567
- navigationSettings.navigation = layout.props.navigation || "Top";
568
- navigationSettings.sticky = layout.props.sticky;
569
- navigationSettings.navWidth = layout.props.width || "Large";
570
- if (navigationSettings.navigation === "None") {
571
- navigationSettings.navigation = "Top";
530
+ // Migrate layout navigation settings
531
+ const { name, customTheme } = existing;
532
+ const layout = layouts === null || layouts === void 0 ? void 0 : layouts.find((layout) => layout._id === layouts_1.BASE_LAYOUT_PROP_IDS.PRIVATE);
533
+ if (layout && !existing.navigation) {
534
+ let navigationSettings = {
535
+ navigation: "Top",
536
+ title: name,
537
+ navWidth: "Large",
538
+ navBackground: (customTheme === null || customTheme === void 0 ? void 0 : customTheme.navBackground) || "var(--spectrum-global-color-gray-50)",
539
+ navTextColor: (customTheme === null || customTheme === void 0 ? void 0 : customTheme.navTextColor) || "var(--spectrum-global-color-gray-800)",
540
+ };
541
+ if (layout) {
542
+ navigationSettings.hideLogo = layout.props.hideLogo;
543
+ navigationSettings.hideTitle = layout.props.hideTitle;
544
+ navigationSettings.title = layout.props.title || name;
545
+ navigationSettings.logoUrl = layout.props.logoUrl;
546
+ navigationSettings.links = layout.props.links;
547
+ navigationSettings.navigation = layout.props.navigation || "Top";
548
+ navigationSettings.sticky = layout.props.sticky;
549
+ navigationSettings.navWidth = layout.props.width || "Large";
550
+ if (navigationSettings.navigation === "None") {
551
+ navigationSettings.navigation = "Top";
552
+ }
572
553
  }
554
+ return navigationSettings;
573
555
  }
574
- return navigationSettings;
575
- }
576
- else {
577
- return null;
578
- }
579
- });
556
+ else {
557
+ return null;
558
+ }
559
+ });
560
+ }