@budibase/server 1.0.46 → 1.0.49-alpha.1

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 (277) hide show
  1. package/builder/assets/index.ba78c49d.css +1 -0
  2. package/builder/assets/{index.e9bff1c6.js → index.ed1cf508.js} +237 -234
  3. package/builder/assets/{vendor.f9faf6ab.js → vendor.d526bfe8.js} +12 -12
  4. package/builder/index.html +3 -3
  5. package/coverage/clover.xml +2368 -2016
  6. package/coverage/coverage-final.json +101 -95
  7. package/coverage/lcov-report/api/controllers/analytics.js.html +1 -1
  8. package/coverage/lcov-report/api/controllers/apikeys.js.html +1 -1
  9. package/coverage/lcov-report/api/controllers/application.js.html +210 -126
  10. package/coverage/lcov-report/api/controllers/auth.js.html +18 -6
  11. package/coverage/lcov-report/api/controllers/automation.js.html +21 -21
  12. package/coverage/lcov-report/api/controllers/backup.js.html +1 -1
  13. package/coverage/lcov-report/api/controllers/cloud.js.html +1 -1
  14. package/coverage/lcov-report/api/controllers/component.js.html +4 -4
  15. package/coverage/lcov-report/api/controllers/datasource.js.html +72 -36
  16. package/coverage/lcov-report/api/controllers/dev.js.html +1 -1
  17. package/coverage/lcov-report/api/controllers/index.html +38 -53
  18. package/coverage/lcov-report/api/controllers/integration.js.html +1 -1
  19. package/coverage/lcov-report/api/controllers/layout.js.html +6 -6
  20. package/coverage/lcov-report/api/controllers/metadata.js.html +1 -1
  21. package/coverage/lcov-report/api/controllers/permission.js.html +15 -15
  22. package/coverage/lcov-report/api/controllers/query/index.html +1 -1
  23. package/coverage/lcov-report/api/controllers/query/index.js.html +19 -19
  24. package/coverage/lcov-report/api/controllers/query/validation.js.html +6 -6
  25. package/coverage/lcov-report/api/controllers/role.js.html +9 -9
  26. package/coverage/lcov-report/api/controllers/routing.js.html +1 -1
  27. package/coverage/lcov-report/api/controllers/row/external.js.html +16 -16
  28. package/coverage/lcov-report/api/controllers/row/index.html +48 -33
  29. package/coverage/lcov-report/api/controllers/row/index.js.html +26 -26
  30. package/coverage/lcov-report/api/controllers/row/internal.js.html +95 -158
  31. package/coverage/lcov-report/api/controllers/row/internalSearch.js.html +41 -17
  32. package/coverage/lcov-report/api/controllers/row/staticFormula.js.html +551 -0
  33. package/coverage/lcov-report/api/controllers/row/utils.js.html +39 -57
  34. package/coverage/lcov-report/api/controllers/screen.js.html +7 -7
  35. package/coverage/lcov-report/api/controllers/script.js.html +4 -4
  36. package/coverage/lcov-report/api/controllers/table/bulkFormula.js.html +629 -0
  37. package/coverage/lcov-report/api/controllers/table/external.js.html +12 -12
  38. package/coverage/lcov-report/api/controllers/table/index.html +49 -34
  39. package/coverage/lcov-report/api/controllers/table/index.js.html +53 -77
  40. package/coverage/lcov-report/api/controllers/table/internal.js.html +59 -35
  41. package/coverage/lcov-report/api/controllers/table/utils.js.html +283 -76
  42. package/coverage/lcov-report/api/controllers/templates.js.html +1 -1
  43. package/coverage/lcov-report/api/controllers/user.js.html +30 -24
  44. package/coverage/lcov-report/api/controllers/view/exporters.js.html +4 -4
  45. package/coverage/lcov-report/api/controllers/view/index.html +1 -1
  46. package/coverage/lcov-report/api/controllers/view/index.js.html +14 -14
  47. package/coverage/lcov-report/api/controllers/view/utils.js.html +11 -11
  48. package/coverage/lcov-report/api/controllers/view/viewBuilder.js.html +7 -7
  49. package/coverage/lcov-report/api/controllers/webhook.js.html +15 -15
  50. package/coverage/lcov-report/api/index.html +1 -1
  51. package/coverage/lcov-report/api/index.js.html +10 -10
  52. package/coverage/lcov-report/api/routes/analytics.js.html +1 -1
  53. package/coverage/lcov-report/api/routes/apikeys.js.html +1 -1
  54. package/coverage/lcov-report/api/routes/application.js.html +1 -1
  55. package/coverage/lcov-report/api/routes/auth.js.html +1 -1
  56. package/coverage/lcov-report/api/routes/automation.js.html +1 -1
  57. package/coverage/lcov-report/api/routes/backup.js.html +1 -1
  58. package/coverage/lcov-report/api/routes/cloud.js.html +1 -1
  59. package/coverage/lcov-report/api/routes/component.js.html +1 -1
  60. package/coverage/lcov-report/api/routes/datasource.js.html +1 -1
  61. package/coverage/lcov-report/api/routes/deploy.js.html +1 -1
  62. package/coverage/lcov-report/api/routes/dev.js.html +1 -1
  63. package/coverage/lcov-report/api/routes/index.html +7 -22
  64. package/coverage/lcov-report/api/routes/index.js.html +4 -10
  65. package/coverage/lcov-report/api/routes/integration.js.html +1 -1
  66. package/coverage/lcov-report/api/routes/layout.js.html +1 -1
  67. package/coverage/lcov-report/api/routes/metadata.js.html +1 -1
  68. package/coverage/lcov-report/api/routes/permission.js.html +1 -1
  69. package/coverage/lcov-report/api/routes/query.js.html +1 -1
  70. package/coverage/lcov-report/api/routes/role.js.html +1 -1
  71. package/coverage/lcov-report/api/routes/routing.js.html +1 -1
  72. package/coverage/lcov-report/api/routes/row.js.html +1 -1
  73. package/coverage/lcov-report/api/routes/screen.js.html +1 -1
  74. package/coverage/lcov-report/api/routes/script.js.html +1 -1
  75. package/coverage/lcov-report/api/routes/static.js.html +17 -2
  76. package/coverage/lcov-report/api/routes/table.js.html +1 -1
  77. package/coverage/lcov-report/api/routes/templates.js.html +1 -1
  78. package/coverage/lcov-report/api/routes/user.js.html +1 -1
  79. package/coverage/lcov-report/api/routes/view.js.html +1 -1
  80. package/coverage/lcov-report/api/routes/webhook.js.html +1 -1
  81. package/coverage/lcov-report/automations/actions.js.html +24 -24
  82. package/coverage/lcov-report/automations/automationUtils.js.html +5 -5
  83. package/coverage/lcov-report/automations/bullboard.js.html +16 -16
  84. package/coverage/lcov-report/automations/index.html +1 -1
  85. package/coverage/lcov-report/automations/index.js.html +1 -1
  86. package/coverage/lcov-report/automations/steps/bash.js.html +6 -6
  87. package/coverage/lcov-report/automations/steps/createRow.js.html +13 -19
  88. package/coverage/lcov-report/automations/steps/delay.js.html +4 -4
  89. package/coverage/lcov-report/automations/steps/deleteRow.js.html +11 -20
  90. package/coverage/lcov-report/automations/steps/discord.js.html +7 -7
  91. package/coverage/lcov-report/automations/steps/executeQuery.js.html +6 -6
  92. package/coverage/lcov-report/automations/steps/executeScript.js.html +6 -6
  93. package/coverage/lcov-report/automations/steps/filter.js.html +7 -7
  94. package/coverage/lcov-report/automations/steps/index.html +13 -13
  95. package/coverage/lcov-report/automations/steps/integromat.js.html +5 -5
  96. package/coverage/lcov-report/automations/steps/outgoingWebhook.js.html +8 -8
  97. package/coverage/lcov-report/automations/steps/queryRows.js.html +10 -10
  98. package/coverage/lcov-report/automations/steps/sendSmtpEmail.js.html +5 -5
  99. package/coverage/lcov-report/automations/steps/serverLog.js.html +3 -3
  100. package/coverage/lcov-report/automations/steps/slack.js.html +5 -5
  101. package/coverage/lcov-report/automations/steps/updateRow.js.html +6 -6
  102. package/coverage/lcov-report/automations/steps/utils.js.html +3 -3
  103. package/coverage/lcov-report/automations/steps/zapier.js.html +5 -5
  104. package/coverage/lcov-report/automations/triggerInfo/app.js.html +2 -2
  105. package/coverage/lcov-report/automations/triggerInfo/cron.js.html +2 -2
  106. package/coverage/lcov-report/automations/triggerInfo/index.html +1 -1
  107. package/coverage/lcov-report/automations/triggerInfo/index.js.html +8 -8
  108. package/coverage/lcov-report/automations/triggerInfo/rowDeleted.js.html +2 -2
  109. package/coverage/lcov-report/automations/triggerInfo/rowSaved.js.html +2 -2
  110. package/coverage/lcov-report/automations/triggerInfo/rowUpdated.js.html +2 -2
  111. package/coverage/lcov-report/automations/triggerInfo/webhook.js.html +2 -2
  112. package/coverage/lcov-report/automations/triggers.js.html +18 -18
  113. package/coverage/lcov-report/automations/utils.js.html +32 -32
  114. package/coverage/lcov-report/constants/index.html +11 -11
  115. package/coverage/lcov-report/constants/index.js.html +68 -32
  116. package/coverage/lcov-report/constants/layouts.js.html +5 -5
  117. package/coverage/lcov-report/constants/screens.js.html +4 -4
  118. package/coverage/lcov-report/db/client.js.html +18 -18
  119. package/coverage/lcov-report/db/inMemoryView.js.html +7 -7
  120. package/coverage/lcov-report/db/index.html +15 -15
  121. package/coverage/lcov-report/db/index.js.html +3 -3
  122. package/coverage/lcov-report/db/linkedRows/LinkController.js.html +18 -18
  123. package/coverage/lcov-report/db/linkedRows/index.html +10 -10
  124. package/coverage/lcov-report/db/linkedRows/index.js.html +38 -41
  125. package/coverage/lcov-report/db/linkedRows/linkUtils.js.html +15 -15
  126. package/coverage/lcov-report/db/newid.js.html +4 -4
  127. package/coverage/lcov-report/db/utils.js.html +86 -86
  128. package/coverage/lcov-report/events/AutomationEmitter.js.html +1 -1
  129. package/coverage/lcov-report/events/index.html +1 -1
  130. package/coverage/lcov-report/events/index.js.html +5 -5
  131. package/coverage/lcov-report/events/utils.js.html +3 -3
  132. package/coverage/lcov-report/index.html +131 -101
  133. package/coverage/lcov-report/integrations/tests/TestConfiguration.js.html +1 -1
  134. package/coverage/lcov-report/integrations/tests/index.html +1 -1
  135. package/coverage/lcov-report/middleware/appInfo.js.html +1 -1
  136. package/coverage/lcov-report/middleware/authorized.js.html +166 -64
  137. package/coverage/lcov-report/middleware/builder.js.html +8 -8
  138. package/coverage/lcov-report/middleware/currentapp.js.html +29 -29
  139. package/coverage/lcov-report/middleware/index.html +30 -30
  140. package/coverage/lcov-report/middleware/joi-validator.js.html +3 -3
  141. package/coverage/lcov-report/middleware/resourceId.js.html +1 -1
  142. package/coverage/lcov-report/middleware/selfhost.js.html +1 -1
  143. package/coverage/lcov-report/middleware/usageQuota.js.html +275 -41
  144. package/coverage/lcov-report/middleware/utils.js.html +2 -2
  145. package/coverage/lcov-report/migrations/usageQuotas/index.html +141 -0
  146. package/coverage/lcov-report/migrations/usageQuotas/index.js.html +152 -0
  147. package/coverage/lcov-report/{api/routes/hosting.js.html → migrations/usageQuotas/syncApps.js.html} +42 -27
  148. package/coverage/lcov-report/{api/controllers/hosting.js.html → migrations/usageQuotas/syncRows.js.html} +41 -44
  149. package/coverage/lcov-report/threads/automation.js.html +1 -1
  150. package/coverage/lcov-report/threads/index.html +15 -15
  151. package/coverage/lcov-report/threads/index.js.html +10 -10
  152. package/coverage/lcov-report/threads/query.js.html +23 -8
  153. package/coverage/lcov-report/threads/utils.js.html +14 -14
  154. package/coverage/lcov-report/utilities/bcrypt.js.html +1 -1
  155. package/coverage/lcov-report/utilities/budibaseDir.js.html +7 -7
  156. package/coverage/lcov-report/utilities/centralPath.js.html +4 -4
  157. package/coverage/lcov-report/utilities/csvParser.js.html +6 -6
  158. package/coverage/lcov-report/utilities/global.js.html +26 -26
  159. package/coverage/lcov-report/utilities/index.html +19 -19
  160. package/coverage/lcov-report/utilities/index.js.html +25 -25
  161. package/coverage/lcov-report/utilities/queue/inMemoryQueue.js.html +8 -8
  162. package/coverage/lcov-report/utilities/queue/index.html +1 -1
  163. package/coverage/lcov-report/utilities/routing/index.html +1 -1
  164. package/coverage/lcov-report/utilities/routing/index.js.html +1 -1
  165. package/coverage/lcov-report/utilities/rowProcessor/index.html +27 -27
  166. package/coverage/lcov-report/utilities/rowProcessor/index.js.html +115 -79
  167. package/coverage/lcov-report/utilities/rowProcessor/utils.js.html +75 -27
  168. package/coverage/lcov-report/utilities/scriptRunner.js.html +5 -5
  169. package/coverage/lcov-report/utilities/security.js.html +8 -8
  170. package/coverage/lcov-report/utilities/statusCodes.js.html +1 -1
  171. package/coverage/lcov-report/utilities/usageQuota/index.html +141 -0
  172. package/coverage/lcov-report/utilities/usageQuota/index.js.html +356 -0
  173. package/coverage/lcov-report/utilities/usageQuota/rows.js.html +302 -0
  174. package/coverage/lcov-report/utilities/usageQuota/usageQuoteReset.js.html +134 -0
  175. package/coverage/lcov-report/utilities/users.js.html +5 -5
  176. package/coverage/lcov-report/utilities/workerRequests.js.html +39 -108
  177. package/coverage/lcov.info +3719 -3046
  178. package/dist/api/controllers/application.js +49 -20
  179. package/dist/api/controllers/auth.js +4 -0
  180. package/dist/api/controllers/datasource.js +11 -0
  181. package/dist/api/controllers/row/ExternalRequest.js +2 -1
  182. package/dist/api/controllers/row/internal.js +30 -53
  183. package/dist/api/controllers/row/internalSearch.js +12 -4
  184. package/dist/api/controllers/row/staticFormula.js +147 -0
  185. package/dist/api/controllers/row/utils.js +6 -8
  186. package/dist/api/controllers/static/index.js +59 -10
  187. package/dist/api/controllers/table/bulkFormula.js +160 -0
  188. package/dist/api/controllers/table/index.js +12 -9
  189. package/dist/api/controllers/table/internal.js +9 -0
  190. package/dist/api/controllers/table/utils.js +56 -14
  191. package/dist/api/controllers/user.js +2 -0
  192. package/dist/api/routes/index.js +0 -2
  193. package/dist/api/routes/static.js +2 -1
  194. package/dist/automations/steps/createRow.js +2 -4
  195. package/dist/automations/steps/deleteRow.js +1 -4
  196. package/dist/constants/index.js +12 -5
  197. package/dist/db/linkedRows/index.js +4 -5
  198. package/dist/definitions/datasource.js +1 -0
  199. package/dist/environment.js +1 -0
  200. package/dist/integrations/base/sql.js +13 -6
  201. package/dist/integrations/googlesheets.js +340 -0
  202. package/dist/integrations/index.js +3 -0
  203. package/dist/integrations/utils.js +57 -8
  204. package/dist/middleware/authorized.js +55 -30
  205. package/dist/middleware/usageQuota.js +82 -13
  206. package/dist/migrations/usageQuotas/index.js +24 -0
  207. package/dist/migrations/usageQuotas/syncApps.js +26 -0
  208. package/dist/migrations/usageQuotas/syncRows.js +29 -0
  209. package/dist/package.json +8 -5
  210. package/dist/tests/utilities/TestConfiguration.js +10 -6
  211. package/dist/threads/query.js +4 -0
  212. package/dist/tsconfig.tsbuildinfo +1 -1
  213. package/dist/utilities/rowProcessor/index.js +18 -11
  214. package/dist/utilities/rowProcessor/utils.js +14 -4
  215. package/dist/utilities/{usageQuota.js → usageQuota/index.js} +44 -31
  216. package/dist/utilities/usageQuota/rows.js +77 -0
  217. package/dist/utilities/usageQuota/usageQuoteReset.js +16 -0
  218. package/dist/utilities/workerRequests.js +0 -20
  219. package/nodemon.json +1 -1
  220. package/package.json +9 -6
  221. package/src/api/controllers/application.js +52 -24
  222. package/src/api/controllers/auth.js +4 -0
  223. package/src/api/controllers/datasource.js +12 -0
  224. package/src/api/controllers/row/ExternalRequest.ts +1 -1
  225. package/src/api/controllers/row/internal.js +29 -50
  226. package/src/api/controllers/row/internalSearch.js +12 -4
  227. package/src/api/controllers/row/staticFormula.js +157 -0
  228. package/src/api/controllers/row/utils.js +6 -12
  229. package/src/api/controllers/static/index.js +63 -10
  230. package/src/api/controllers/table/bulkFormula.js +183 -0
  231. package/src/api/controllers/table/index.js +16 -24
  232. package/src/api/controllers/table/internal.js +9 -1
  233. package/src/api/controllers/table/utils.js +80 -11
  234. package/src/api/controllers/user.js +2 -0
  235. package/src/api/routes/index.js +0 -2
  236. package/src/api/routes/static.js +5 -0
  237. package/src/api/routes/tests/application.spec.js +2 -2
  238. package/src/api/routes/tests/auth.spec.js +1 -2
  239. package/src/api/routes/tests/static.spec.js +98 -0
  240. package/src/automations/steps/createRow.js +2 -4
  241. package/src/automations/steps/deleteRow.js +1 -4
  242. package/src/constants/index.js +17 -5
  243. package/src/db/linkedRows/index.js +4 -5
  244. package/src/definitions/common.ts +3 -0
  245. package/src/definitions/datasource.ts +3 -0
  246. package/src/environment.js +1 -0
  247. package/src/integrations/base/sql.ts +14 -7
  248. package/src/integrations/googlesheets.ts +353 -0
  249. package/src/integrations/index.ts +3 -0
  250. package/src/integrations/tests/sql.spec.js +16 -0
  251. package/src/integrations/utils.ts +71 -10
  252. package/src/middleware/authorized.js +64 -30
  253. package/src/middleware/tests/authorized.spec.js +6 -4
  254. package/src/middleware/tests/usageQuota.spec.js +18 -24
  255. package/src/middleware/usageQuota.js +93 -15
  256. package/src/migrations/tests/usageQuotas/index.spec.js +27 -0
  257. package/src/migrations/tests/usageQuotas/syncApps.spec.js +37 -0
  258. package/src/migrations/tests/usageQuotas/syncRows.spec.js +43 -0
  259. package/src/migrations/usageQuotas/index.js +24 -0
  260. package/src/migrations/usageQuotas/syncApps.js +18 -0
  261. package/src/migrations/usageQuotas/syncRows.js +21 -0
  262. package/src/tests/utilities/TestConfiguration.js +10 -6
  263. package/src/threads/query.js +5 -0
  264. package/src/utilities/rowProcessor/index.js +24 -12
  265. package/src/utilities/rowProcessor/utils.js +23 -7
  266. package/src/utilities/tests/usageQuota/usageQuota.spec.js +72 -0
  267. package/src/utilities/usageQuota/index.js +92 -0
  268. package/src/utilities/usageQuota/rows.js +74 -0
  269. package/src/utilities/usageQuota/usageQuoteReset.js +18 -0
  270. package/src/utilities/workerRequests.js +0 -23
  271. package/builder/assets/index.39e01193.css +0 -1
  272. package/dist/api/controllers/hosting.js +0 -30
  273. package/dist/api/routes/hosting.js +0 -11
  274. package/src/api/controllers/hosting.js +0 -22
  275. package/src/api/routes/hosting.js +0 -13
  276. package/src/api/routes/tests/hosting.spec.js +0 -36
  277. package/src/utilities/usageQuota.js +0 -73
@@ -10,11 +10,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  const CouchDB = require("../db");
12
12
  const usageQuota = require("../utilities/usageQuota");
13
- const env = require("../environment");
14
- const { getTenantId } = require("@budibase/backend-core/tenancy");
13
+ const { getUniqueRows } = require("../utilities/usageQuota/rows");
15
14
  const { isExternalTable, isRowId: isExternalRowId, } = require("../integrations/utils");
16
- // tenants without limits
17
- const EXCLUDED_TENANTS = ["bb", "default", "bbtest", "bbstaging"];
15
+ const migration = require("../migrations/usageQuotas");
18
16
  // currently only counting new writes and deletes
19
17
  const METHOD_MAP = {
20
18
  POST: 1,
@@ -22,13 +20,13 @@ const METHOD_MAP = {
22
20
  };
23
21
  const DOMAIN_MAP = {
24
22
  rows: usageQuota.Properties.ROW,
25
- upload: usageQuota.Properties.UPLOAD,
26
- views: usageQuota.Properties.VIEW,
27
- users: usageQuota.Properties.USER,
23
+ // upload: usageQuota.Properties.UPLOAD, // doesn't work yet
24
+ // views: usageQuota.Properties.VIEW, // doesn't work yet
25
+ // users: usageQuota.Properties.USER, // doesn't work yet
28
26
  applications: usageQuota.Properties.APPS,
29
27
  // this will not be updated by endpoint calls
30
28
  // instead it will be updated by triggerInfo
31
- automationRuns: usageQuota.Properties.AUTOMATION,
29
+ // automationRuns: usageQuota.Properties.AUTOMATION, // doesn't work yet
32
30
  };
33
31
  function getProperty(url) {
34
32
  for (let domain of Object.keys(DOMAIN_MAP)) {
@@ -38,9 +36,7 @@ function getProperty(url) {
38
36
  }
39
37
  }
40
38
  module.exports = (ctx, next) => __awaiter(void 0, void 0, void 0, function* () {
41
- const tenantId = getTenantId();
42
- // if in development or a self hosted cloud usage quotas should not be executed
43
- if (env.isDev() || env.SELF_HOSTED || EXCLUDED_TENANTS.includes(tenantId)) {
39
+ if (!usageQuota.useQuotas()) {
44
40
  return next();
45
41
  }
46
42
  let usage = METHOD_MAP[ctx.req.method];
@@ -78,10 +74,83 @@ module.exports = (ctx, next) => __awaiter(void 0, void 0, void 0, function* () {
78
74
  usage = files.map(file => file.size).reduce((total, size) => total + size);
79
75
  }
80
76
  try {
81
- yield usageQuota.update(property, usage);
82
- return next();
77
+ yield migration.run();
78
+ yield performRequest(ctx, next, property, usage);
83
79
  }
84
80
  catch (err) {
85
81
  ctx.throw(400, err);
86
82
  }
87
83
  });
84
+ const performRequest = (ctx, next, property, usage) => __awaiter(void 0, void 0, void 0, function* () {
85
+ const usageContext = {
86
+ skipNext: false,
87
+ skipUsage: false,
88
+ [usageQuota.Properties.APPS]: {},
89
+ };
90
+ if (usage === -1) {
91
+ if (PRE_DELETE[property]) {
92
+ yield PRE_DELETE[property](ctx, usageContext);
93
+ }
94
+ }
95
+ else {
96
+ if (PRE_CREATE[property]) {
97
+ yield PRE_CREATE[property](ctx, usageContext);
98
+ }
99
+ }
100
+ // run the request
101
+ if (!usageContext.skipNext) {
102
+ yield usageQuota.update(property, usage, { dryRun: true });
103
+ yield next();
104
+ }
105
+ if (usage === -1) {
106
+ if (POST_DELETE[property]) {
107
+ yield POST_DELETE[property](ctx, usageContext);
108
+ }
109
+ }
110
+ else {
111
+ if (POST_CREATE[property]) {
112
+ yield POST_CREATE[property](ctx, usageContext);
113
+ }
114
+ }
115
+ // update the usage
116
+ if (!usageContext.skipUsage) {
117
+ yield usageQuota.update(property, usage);
118
+ }
119
+ });
120
+ const appPreDelete = (ctx, usageContext) => __awaiter(void 0, void 0, void 0, function* () {
121
+ if (ctx.query.unpublish) {
122
+ // don't run usage decrement for unpublish
123
+ usageContext.skipUsage = true;
124
+ return;
125
+ }
126
+ // store the row count to delete
127
+ const rows = yield getUniqueRows([ctx.appId]);
128
+ if (rows.length) {
129
+ usageContext[usageQuota.Properties.APPS] = { rowCount: rows.length };
130
+ }
131
+ });
132
+ const appPostDelete = (ctx, usageContext) => __awaiter(void 0, void 0, void 0, function* () {
133
+ // delete the app rows from usage
134
+ const rowCount = usageContext[usageQuota.Properties.APPS].rowCount;
135
+ if (rowCount) {
136
+ yield usageQuota.update(usageQuota.Properties.ROW, -rowCount);
137
+ }
138
+ });
139
+ const appPostCreate = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
140
+ // app import & template creation
141
+ if (ctx.request.body.useTemplate === "true") {
142
+ const rows = yield getUniqueRows([ctx.response.body.appId]);
143
+ const rowCount = rows ? rows.length : 0;
144
+ yield usageQuota.update(usageQuota.Properties.ROW, rowCount);
145
+ }
146
+ });
147
+ const PRE_DELETE = {
148
+ [usageQuota.Properties.APPS]: appPreDelete,
149
+ };
150
+ const POST_DELETE = {
151
+ [usageQuota.Properties.APPS]: appPostDelete,
152
+ };
153
+ const PRE_CREATE = {};
154
+ const POST_CREATE = {
155
+ [usageQuota.Properties.APPS]: appPostCreate,
156
+ };
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ const { MIGRATIONS, MIGRATION_DBS, migrateIfRequired, } = require("@budibase/backend-core/migrations");
12
+ const { useQuotas } = require("../../utilities/usageQuota");
13
+ const syncApps = require("./syncApps");
14
+ const syncRows = require("./syncRows");
15
+ exports.run = () => __awaiter(void 0, void 0, void 0, function* () {
16
+ if (!useQuotas()) {
17
+ return;
18
+ }
19
+ // Jan 2022
20
+ yield migrateIfRequired(MIGRATION_DBS.GLOBAL_DB, MIGRATIONS.QUOTAS_1, () => __awaiter(void 0, void 0, void 0, function* () {
21
+ yield syncApps.run();
22
+ yield syncRows.run();
23
+ }));
24
+ });
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ const { getGlobalDB, getTenantId } = require("@budibase/backend-core/tenancy");
12
+ const { getAllApps } = require("@budibase/backend-core/db");
13
+ const CouchDB = require("../../db");
14
+ const { getUsageQuotaDoc } = require("../../utilities/usageQuota");
15
+ exports.run = () => __awaiter(void 0, void 0, void 0, function* () {
16
+ const db = getGlobalDB();
17
+ // get app count
18
+ const devApps = yield getAllApps(CouchDB, { dev: true });
19
+ const appCount = devApps ? devApps.length : 0;
20
+ // sync app count
21
+ const tenantId = getTenantId();
22
+ console.log(`[Tenant: ${tenantId}] Syncing app count: ${appCount}`);
23
+ const usageDoc = yield getUsageQuotaDoc(db);
24
+ usageDoc.usageQuota.apps = appCount;
25
+ yield db.put(usageDoc);
26
+ });
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ const { getGlobalDB, getTenantId } = require("@budibase/backend-core/tenancy");
12
+ const { getAllApps } = require("@budibase/backend-core/db");
13
+ const CouchDB = require("../../db");
14
+ const { getUsageQuotaDoc } = require("../../utilities/usageQuota");
15
+ const { getUniqueRows } = require("../../utilities/usageQuota/rows");
16
+ exports.run = () => __awaiter(void 0, void 0, void 0, function* () {
17
+ const db = getGlobalDB();
18
+ // get all rows in all apps
19
+ const allApps = yield getAllApps(CouchDB, { all: true });
20
+ const appIds = allApps ? allApps.map(app => app.appId) : [];
21
+ const rows = yield getUniqueRows(appIds);
22
+ const rowCount = rows ? rows.length : 0;
23
+ // sync row count
24
+ const tenantId = getTenantId();
25
+ console.log(`[Tenant: ${tenantId}] Syncing row count: ${rowCount}`);
26
+ const usageDoc = yield getUsageQuotaDoc(db);
27
+ usageDoc.usageQuota.rows = rowCount;
28
+ yield db.put(usageDoc);
29
+ });
package/dist/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@budibase/server",
3
3
  "email": "hi@budibase.com",
4
- "version": "1.0.45",
4
+ "version": "1.0.49-alpha.0",
5
5
  "description": "Budibase Web Server",
6
6
  "main": "src/index.ts",
7
7
  "repository": {
@@ -70,9 +70,9 @@
70
70
  "license": "GPL-3.0",
71
71
  "dependencies": {
72
72
  "@apidevtools/swagger-parser": "^10.0.3",
73
- "@budibase/backend-core": "^1.0.45",
74
- "@budibase/client": "^1.0.45",
75
- "@budibase/string-templates": "^1.0.45",
73
+ "@budibase/backend-core": "^1.0.49-alpha.0",
74
+ "@budibase/client": "^1.0.49-alpha.0",
75
+ "@budibase/string-templates": "^1.0.49-alpha.0",
76
76
  "@bull-board/api": "^3.7.0",
77
77
  "@bull-board/koa": "^3.7.0",
78
78
  "@elastic/elasticsearch": "7.10.0",
@@ -92,6 +92,8 @@
92
92
  "fix-path": "3.0.0",
93
93
  "form-data": "^4.0.0",
94
94
  "fs-extra": "8.1.0",
95
+ "google-auth-library": "^7.11.0",
96
+ "google-spreadsheet": "^3.2.0",
95
97
  "jimp": "0.16.1",
96
98
  "joi": "17.2.1",
97
99
  "js-yaml": "^4.1.0",
@@ -110,7 +112,7 @@
110
112
  "mongodb": "3.6.3",
111
113
  "mssql": "6.2.3",
112
114
  "mysql2": "^2.3.1",
113
- "node-fetch": "2.6.0",
115
+ "node-fetch": "2.6.7",
114
116
  "open": "^8.4.0",
115
117
  "pg": "8.5.1",
116
118
  "pino-pretty": "4.0.0",
@@ -139,6 +141,7 @@
139
141
  "@jest/test-sequencer": "^24.8.0",
140
142
  "@types/apidoc": "^0.50.0",
141
143
  "@types/bull": "^3.15.1",
144
+ "@types/google-spreadsheet": "^3.1.5",
142
145
  "@types/jest": "^26.0.23",
143
146
  "@types/koa": "^2.13.3",
144
147
  "@types/koa-router": "^7.4.2",
@@ -21,9 +21,11 @@ const { getGlobalDB } = require("@budibase/backend-core/tenancy");
21
21
  const { createASession } = require("@budibase/backend-core/sessions");
22
22
  const { user: userCache } = require("@budibase/backend-core/cache");
23
23
  const CouchDB = require("../../db");
24
+ const newid = require("../../db/newid");
24
25
  core.init(CouchDB);
25
26
  const GLOBAL_USER_ID = "us_uuid1";
26
27
  const EMAIL = "babs@babs.com";
28
+ const CSRF_TOKEN = "e3727778-7af0-4226-b5eb-f43cbe60a306";
27
29
  class TestConfiguration {
28
30
  constructor(openServer = true) {
29
31
  if (openServer) {
@@ -72,7 +74,11 @@ class TestConfiguration {
72
74
  existing = { email };
73
75
  }
74
76
  const user = Object.assign(Object.assign({ _id: id }, existing), { roles: roles || {}, tenantId: TENANT_ID });
75
- yield createASession(id, { sessionId: "sessionid", tenantId: TENANT_ID });
77
+ yield createASession(id, {
78
+ sessionId: "sessionid",
79
+ tenantId: TENANT_ID,
80
+ csrfToken: CSRF_TOKEN,
81
+ });
76
82
  if (builder) {
77
83
  user.builder = { global: true };
78
84
  }
@@ -83,7 +89,8 @@ class TestConfiguration {
83
89
  return Object.assign({ _rev: resp._rev }, user);
84
90
  });
85
91
  }
86
- init(appName = "test_application") {
92
+ // use a new id as the name to avoid name collisions
93
+ init(appName = newid()) {
87
94
  return __awaiter(this, void 0, void 0, function* () {
88
95
  yield this.globalUser();
89
96
  return this.createApp(appName);
@@ -116,6 +123,7 @@ class TestConfiguration {
116
123
  `${Cookies.Auth}=${authToken}`,
117
124
  `${Cookies.CurrentApp}=${appToken}`,
118
125
  ],
126
+ [Headers.CSRF_TOKEN]: CSRF_TOKEN,
119
127
  };
120
128
  if (this.appId) {
121
129
  headers[Headers.APP_ID] = this.appId;
@@ -394,10 +402,6 @@ class TestConfiguration {
394
402
  roles: { [this.prodAppId]: roleId },
395
403
  });
396
404
  }
397
- yield createASession(userId, {
398
- sessionId: "sessionid",
399
- tenantId: TENANT_ID,
400
- });
401
405
  // have to fake this
402
406
  const auth = {
403
407
  userId,
@@ -75,6 +75,10 @@ class QueryRunner {
75
75
  yield threadUtils.invalidateDynamicVariables(this.cachedVariables);
76
76
  return this.execute();
77
77
  }
78
+ // check for undefined response
79
+ if (!rows) {
80
+ rows = [];
81
+ }
78
82
  // needs to an array for next step
79
83
  if (!Array.isArray(rows)) {
80
84
  rows = [rows];