@budibase/server 1.0.46-alpha.7 → 1.0.48

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 (251) hide show
  1. package/builder/assets/{index.dd9e386f.css → index.39e01193.css} +1 -1
  2. package/builder/assets/{index.af9e71d8.js → index.e083dcaf.js} +221 -223
  3. package/builder/assets/{vendor.3bd2f661.js → vendor.f9faf6ab.js} +12 -12
  4. package/builder/index.html +3 -3
  5. package/coverage/clover.xml +1637 -1793
  6. package/coverage/coverage-final.json +94 -98
  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 +126 -210
  10. package/coverage/lcov-report/api/controllers/auth.js.html +1 -1
  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 +36 -72
  16. package/coverage/lcov-report/api/controllers/dev.js.html +1 -1
  17. package/coverage/lcov-report/{migrations/usageQuotas/syncRows.js.html → api/controllers/hosting.js.html} +44 -41
  18. package/coverage/lcov-report/api/controllers/index.html +42 -27
  19. package/coverage/lcov-report/api/controllers/integration.js.html +1 -1
  20. package/coverage/lcov-report/api/controllers/layout.js.html +6 -6
  21. package/coverage/lcov-report/api/controllers/metadata.js.html +1 -1
  22. package/coverage/lcov-report/api/controllers/permission.js.html +15 -15
  23. package/coverage/lcov-report/api/controllers/query/index.html +1 -1
  24. package/coverage/lcov-report/api/controllers/query/index.js.html +19 -19
  25. package/coverage/lcov-report/api/controllers/query/validation.js.html +6 -6
  26. package/coverage/lcov-report/api/controllers/role.js.html +9 -9
  27. package/coverage/lcov-report/api/controllers/routing.js.html +1 -1
  28. package/coverage/lcov-report/api/controllers/row/external.js.html +16 -16
  29. package/coverage/lcov-report/api/controllers/row/index.html +15 -15
  30. package/coverage/lcov-report/api/controllers/row/index.js.html +26 -26
  31. package/coverage/lcov-report/api/controllers/row/internal.js.html +44 -44
  32. package/coverage/lcov-report/api/controllers/row/internalSearch.js.html +8 -8
  33. package/coverage/lcov-report/api/controllers/row/utils.js.html +57 -39
  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/external.js.html +12 -12
  37. package/coverage/lcov-report/api/controllers/table/index.html +32 -32
  38. package/coverage/lcov-report/api/controllers/table/index.js.html +39 -57
  39. package/coverage/lcov-report/api/controllers/table/internal.js.html +34 -40
  40. package/coverage/lcov-report/api/controllers/table/utils.js.html +122 -83
  41. package/coverage/lcov-report/api/controllers/templates.js.html +1 -1
  42. package/coverage/lcov-report/api/controllers/user.js.html +20 -20
  43. package/coverage/lcov-report/api/controllers/view/exporters.js.html +4 -4
  44. package/coverage/lcov-report/api/controllers/view/index.html +1 -1
  45. package/coverage/lcov-report/api/controllers/view/index.js.html +14 -14
  46. package/coverage/lcov-report/api/controllers/view/utils.js.html +11 -11
  47. package/coverage/lcov-report/api/controllers/view/viewBuilder.js.html +7 -7
  48. package/coverage/lcov-report/api/controllers/webhook.js.html +15 -15
  49. package/coverage/lcov-report/api/index.html +1 -1
  50. package/coverage/lcov-report/api/index.js.html +10 -10
  51. package/coverage/lcov-report/api/routes/analytics.js.html +1 -1
  52. package/coverage/lcov-report/api/routes/apikeys.js.html +1 -1
  53. package/coverage/lcov-report/api/routes/application.js.html +1 -1
  54. package/coverage/lcov-report/api/routes/auth.js.html +1 -1
  55. package/coverage/lcov-report/api/routes/automation.js.html +1 -1
  56. package/coverage/lcov-report/api/routes/backup.js.html +1 -1
  57. package/coverage/lcov-report/api/routes/cloud.js.html +1 -1
  58. package/coverage/lcov-report/api/routes/component.js.html +1 -1
  59. package/coverage/lcov-report/api/routes/datasource.js.html +1 -1
  60. package/coverage/lcov-report/api/routes/deploy.js.html +1 -1
  61. package/coverage/lcov-report/api/routes/dev.js.html +1 -1
  62. package/coverage/lcov-report/{migrations/usageQuotas/syncApps.js.html → api/routes/hosting.js.html} +27 -42
  63. package/coverage/lcov-report/api/routes/index.html +22 -7
  64. package/coverage/lcov-report/api/routes/index.js.html +10 -4
  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 +2 -17
  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 +19 -13
  88. package/coverage/lcov-report/automations/steps/delay.js.html +4 -4
  89. package/coverage/lcov-report/automations/steps/deleteRow.js.html +20 -11
  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 +37 -40
  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 +1 -1
  124. package/coverage/lcov-report/db/linkedRows/index.js.html +31 -31
  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 +85 -85
  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 +86 -116
  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 +11 -11
  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 +20 -20
  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 +41 -275
  144. package/coverage/lcov-report/middleware/utils.js.html +2 -2
  145. package/coverage/lcov-report/threads/automation.js.html +1 -1
  146. package/coverage/lcov-report/threads/index.html +15 -15
  147. package/coverage/lcov-report/threads/index.js.html +10 -10
  148. package/coverage/lcov-report/threads/query.js.html +8 -23
  149. package/coverage/lcov-report/threads/utils.js.html +14 -14
  150. package/coverage/lcov-report/utilities/bcrypt.js.html +1 -1
  151. package/coverage/lcov-report/utilities/budibaseDir.js.html +7 -7
  152. package/coverage/lcov-report/utilities/centralPath.js.html +4 -4
  153. package/coverage/lcov-report/utilities/csvParser.js.html +6 -6
  154. package/coverage/lcov-report/utilities/global.js.html +26 -26
  155. package/coverage/lcov-report/utilities/index.html +19 -19
  156. package/coverage/lcov-report/utilities/index.js.html +25 -25
  157. package/coverage/lcov-report/utilities/queue/inMemoryQueue.js.html +8 -8
  158. package/coverage/lcov-report/utilities/queue/index.html +1 -1
  159. package/coverage/lcov-report/utilities/routing/index.html +1 -1
  160. package/coverage/lcov-report/utilities/routing/index.js.html +1 -1
  161. package/coverage/lcov-report/utilities/rowProcessor/index.html +1 -1
  162. package/coverage/lcov-report/utilities/rowProcessor/index.js.html +53 -53
  163. package/coverage/lcov-report/utilities/rowProcessor/utils.js.html +10 -10
  164. package/coverage/lcov-report/utilities/scriptRunner.js.html +5 -5
  165. package/coverage/lcov-report/utilities/security.js.html +8 -8
  166. package/coverage/lcov-report/utilities/statusCodes.js.html +1 -1
  167. package/coverage/lcov-report/utilities/users.js.html +5 -5
  168. package/coverage/lcov-report/utilities/workerRequests.js.html +108 -39
  169. package/coverage/lcov.info +2332 -2599
  170. package/dist/api/controllers/application.js +20 -49
  171. package/dist/api/controllers/datasource.js +0 -11
  172. package/dist/api/controllers/hosting.js +30 -0
  173. package/dist/api/controllers/row/ExternalRequest.js +2 -1
  174. package/dist/api/controllers/row/utils.js +8 -6
  175. package/dist/api/controllers/static/index.js +10 -59
  176. package/dist/api/controllers/table/index.js +4 -10
  177. package/dist/api/controllers/table/internal.js +0 -2
  178. package/dist/api/controllers/table/utils.js +17 -11
  179. package/dist/api/routes/hosting.js +11 -0
  180. package/dist/api/routes/index.js +2 -0
  181. package/dist/api/routes/static.js +1 -2
  182. package/dist/automations/steps/createRow.js +4 -2
  183. package/dist/automations/steps/deleteRow.js +4 -1
  184. package/dist/constants/index.js +5 -8
  185. package/dist/definitions/datasource.js +0 -1
  186. package/dist/environment.js +0 -1
  187. package/dist/integrations/base/sql.js +6 -13
  188. package/dist/integrations/index.js +0 -3
  189. package/dist/integrations/utils.js +9 -56
  190. package/dist/middleware/usageQuota.js +13 -82
  191. package/dist/package.json +5 -8
  192. package/dist/tests/utilities/TestConfiguration.js +1 -3
  193. package/dist/threads/query.js +0 -4
  194. package/dist/tsconfig.tsbuildinfo +1 -1
  195. package/dist/utilities/{usageQuota/index.js → usageQuota.js} +31 -44
  196. package/dist/utilities/workerRequests.js +20 -0
  197. package/nodemon.json +1 -1
  198. package/package.json +6 -9
  199. package/src/api/controllers/application.js +24 -52
  200. package/src/api/controllers/datasource.js +0 -12
  201. package/src/api/controllers/hosting.js +22 -0
  202. package/src/api/controllers/row/ExternalRequest.ts +1 -1
  203. package/src/api/controllers/row/utils.js +12 -6
  204. package/src/api/controllers/static/index.js +10 -63
  205. package/src/api/controllers/table/index.js +9 -15
  206. package/src/api/controllers/table/internal.js +0 -2
  207. package/src/api/controllers/table/utils.js +24 -11
  208. package/src/api/routes/hosting.js +13 -0
  209. package/src/api/routes/index.js +2 -0
  210. package/src/api/routes/static.js +0 -5
  211. package/src/api/routes/tests/application.spec.js +2 -2
  212. package/src/api/routes/tests/hosting.spec.js +36 -0
  213. package/src/automations/steps/createRow.js +4 -2
  214. package/src/automations/steps/deleteRow.js +4 -1
  215. package/src/constants/index.js +8 -9
  216. package/src/definitions/datasource.ts +0 -3
  217. package/src/environment.js +0 -1
  218. package/src/integrations/base/sql.ts +7 -14
  219. package/src/integrations/index.ts +0 -3
  220. package/src/integrations/tests/sql.spec.js +0 -16
  221. package/src/integrations/utils.ts +11 -70
  222. package/src/middleware/tests/usageQuota.spec.js +24 -18
  223. package/src/middleware/usageQuota.js +15 -93
  224. package/src/tests/utilities/TestConfiguration.js +1 -3
  225. package/src/threads/query.js +0 -5
  226. package/src/utilities/usageQuota.js +73 -0
  227. package/src/utilities/workerRequests.js +23 -0
  228. package/coverage/lcov-report/migrations/usageQuotas/index.html +0 -141
  229. package/coverage/lcov-report/migrations/usageQuotas/index.js.html +0 -152
  230. package/coverage/lcov-report/utilities/usageQuota/index.html +0 -141
  231. package/coverage/lcov-report/utilities/usageQuota/index.js.html +0 -356
  232. package/coverage/lcov-report/utilities/usageQuota/rows.js.html +0 -302
  233. package/coverage/lcov-report/utilities/usageQuota/usageQuoteReset.js.html +0 -134
  234. package/dist/integrations/googlesheets.js +0 -340
  235. package/dist/migrations/usageQuotas/index.js +0 -24
  236. package/dist/migrations/usageQuotas/syncApps.js +0 -26
  237. package/dist/migrations/usageQuotas/syncRows.js +0 -29
  238. package/dist/utilities/usageQuota/rows.js +0 -77
  239. package/dist/utilities/usageQuota/usageQuoteReset.js +0 -16
  240. package/src/api/routes/tests/static.spec.js +0 -98
  241. package/src/integrations/googlesheets.ts +0 -353
  242. package/src/migrations/tests/usageQuotas/index.spec.js +0 -27
  243. package/src/migrations/tests/usageQuotas/syncApps.spec.js +0 -37
  244. package/src/migrations/tests/usageQuotas/syncRows.spec.js +0 -43
  245. package/src/migrations/usageQuotas/index.js +0 -24
  246. package/src/migrations/usageQuotas/syncApps.js +0 -18
  247. package/src/migrations/usageQuotas/syncRows.js +0 -21
  248. package/src/utilities/tests/usageQuota/usageQuota.spec.js +0 -72
  249. package/src/utilities/usageQuota/index.js +0 -92
  250. package/src/utilities/usageQuota/rows.js +0 -74
  251. package/src/utilities/usageQuota/usageQuoteReset.js +0 -18
@@ -20,7 +20,7 @@ const { cloneDeep } = require("lodash/fp");
20
20
  const { processObject } = require("@budibase/string-templates");
21
21
  const { getAllApps, isDevAppID, getDeployedAppID, Replication, } = require("@budibase/backend-core/db");
22
22
  const { USERS_TABLE_SCHEMA } = require("../../constants");
23
- const { removeAppFromUserRoles } = require("../../utilities/workerRequests");
23
+ const { getDeployedApps, removeAppFromUserRoles, } = require("../../utilities/workerRequests");
24
24
  const { clientLibraryPath, stringToReadStream } = require("../../utilities");
25
25
  const { getAllLocks } = require("../../utilities/redis");
26
26
  const { updateClientLibrary, backupClientLibrary, revertClientLibrary, } = require("../../utilities/fileSystem/clientLibrary");
@@ -49,44 +49,31 @@ function getUserRoleId(ctx) {
49
49
  ? BUILTIN_ROLE_IDS.PUBLIC
50
50
  : ctx.user.role._id;
51
51
  }
52
- function getAppUrl(ctx) {
52
+ function getAppUrlIfNotInUse(ctx) {
53
53
  return __awaiter(this, void 0, void 0, function* () {
54
- // construct the url
55
54
  let url;
56
55
  if (ctx.request.body.url) {
57
- // if the url is provided, use that
58
56
  url = encodeURI(ctx.request.body.url);
59
57
  }
60
58
  else if (ctx.request.body.name) {
61
- // otherwise use the name
62
59
  url = encodeURI(`${ctx.request.body.name}`);
63
60
  }
64
61
  if (url) {
65
62
  url = `/${url.replace(URL_REGEX_SLASH, "")}`.toLowerCase();
66
63
  }
64
+ if (!env.SELF_HOSTED) {
65
+ return url;
66
+ }
67
+ const deployedApps = yield getDeployedApps();
68
+ if (url &&
69
+ deployedApps[url] != null &&
70
+ ctx.params != null &&
71
+ deployedApps[url].appId !== ctx.params.appId) {
72
+ ctx.throw(400, "App name/URL is already in use.");
73
+ }
67
74
  return url;
68
75
  });
69
76
  }
70
- const checkAppUrl = (ctx, apps, url, currentAppId) => {
71
- if (currentAppId) {
72
- apps = apps.filter(app => app.appId !== currentAppId);
73
- }
74
- if (apps.some(app => app.url === url)) {
75
- ctx.throw(400, "App URL is already in use.");
76
- }
77
- };
78
- const checkAppName = (ctx, apps, name, currentAppId) => {
79
- // TODO: Replace with Joi
80
- if (!name) {
81
- ctx.throw(400, "Name is required");
82
- }
83
- if (currentAppId) {
84
- apps = apps.filter(app => app.appId !== currentAppId);
85
- }
86
- if (apps.some(app => app.name === name)) {
87
- ctx.throw(400, "App name is already in use.");
88
- }
89
- };
90
77
  function createInstance(template) {
91
78
  return __awaiter(this, void 0, void 0, function* () {
92
79
  const tenantId = isMultiTenant() ? getTenantId() : null;
@@ -180,11 +167,6 @@ exports.fetchAppPackage = (ctx) => __awaiter(void 0, void 0, void 0, function* (
180
167
  };
181
168
  });
182
169
  exports.create = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
183
- const apps = yield getAllApps(CouchDB, { dev: true });
184
- const name = ctx.request.body.name;
185
- checkAppName(ctx, apps, name);
186
- const url = yield getAppUrl(ctx);
187
- checkAppUrl(ctx, apps, url);
188
170
  const { useTemplate, templateKey, templateString } = ctx.request.body;
189
171
  const instanceConfig = {
190
172
  useTemplate,
@@ -196,6 +178,7 @@ exports.create = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
196
178
  }
197
179
  const instance = yield createInstance(instanceConfig);
198
180
  const appId = instance._id;
181
+ const url = yield getAppUrlIfNotInUse(ctx);
199
182
  const db = new CouchDB(appId);
200
183
  let _rev;
201
184
  try {
@@ -213,7 +196,7 @@ exports.create = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
213
196
  type: "app",
214
197
  version: packageJson.version,
215
198
  componentLibraries: ["@budibase/standard-components"],
216
- name: name,
199
+ name: ctx.request.body.name,
217
200
  url: url,
218
201
  template: ctx.request.body.template,
219
202
  instance: instance,
@@ -236,21 +219,8 @@ exports.create = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
236
219
  ctx.status = 200;
237
220
  ctx.body = newApplication;
238
221
  });
239
- // This endpoint currently operates as a PATCH rather than a PUT
240
- // Thus name and url fields are handled only if present
241
222
  exports.update = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
242
- const apps = yield getAllApps(CouchDB, { dev: true });
243
- // validation
244
- const name = ctx.request.body.name;
245
- if (name) {
246
- checkAppName(ctx, apps, name, ctx.params.appId);
247
- }
248
- const url = yield getAppUrl(ctx);
249
- if (url) {
250
- checkAppUrl(ctx, apps, url, ctx.params.appId);
251
- ctx.request.body.url = url;
252
- }
253
- const data = yield updateAppPackage(ctx.request.body, ctx.params.appId);
223
+ const data = yield updateAppPackage(ctx, ctx.request.body, ctx.params.appId);
254
224
  ctx.status = 200;
255
225
  ctx.body = data;
256
226
  });
@@ -269,7 +239,7 @@ exports.updateClient = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
269
239
  version: packageJson.version,
270
240
  revertableVersion: currentVersion,
271
241
  };
272
- const data = yield updateAppPackage(appPackageUpdates, ctx.params.appId);
242
+ const data = yield updateAppPackage(ctx, appPackageUpdates, ctx.params.appId);
273
243
  ctx.status = 200;
274
244
  ctx.body = data;
275
245
  });
@@ -289,7 +259,7 @@ exports.revertClient = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
289
259
  version: application.revertableVersion,
290
260
  revertableVersion: null,
291
261
  };
292
- const data = yield updateAppPackage(appPackageUpdates, ctx.params.appId);
262
+ const data = yield updateAppPackage(ctx, appPackageUpdates, ctx.params.appId);
293
263
  ctx.status = 200;
294
264
  ctx.body = data;
295
265
  });
@@ -356,10 +326,11 @@ exports.sync = (ctx, next) => __awaiter(void 0, void 0, void 0, function* () {
356
326
  };
357
327
  }
358
328
  });
359
- const updateAppPackage = (appPackage, appId) => __awaiter(void 0, void 0, void 0, function* () {
329
+ const updateAppPackage = (ctx, appPackage, appId) => __awaiter(void 0, void 0, void 0, function* () {
330
+ const url = yield getAppUrlIfNotInUse(ctx);
360
331
  const db = new CouchDB(appId);
361
332
  const application = yield db.get(DocumentTypes.APP_METADATA);
362
- const newAppPackage = Object.assign(Object.assign({}, application), appPackage);
333
+ const newAppPackage = Object.assign(Object.assign(Object.assign({}, application), appPackage), { url });
363
334
  if (appPackage._rev !== application._rev) {
364
335
  newAppPackage._rev = application._rev;
365
336
  }
@@ -28,12 +28,6 @@ exports.fetch = function (ctx) {
28
28
  const datasources = (yield database.allDocs(getDatasourceParams(null, {
29
29
  include_docs: true,
30
30
  }))).rows.map(row => row.doc);
31
- for (let datasource of datasources) {
32
- if (datasource.config && datasource.config.auth) {
33
- // strip secrets from response so they don't show in the network request
34
- delete datasource.config.auth;
35
- }
36
- }
37
31
  ctx.body = [bbInternalDb, ...datasources];
38
32
  });
39
33
  };
@@ -84,13 +78,8 @@ exports.update = function (ctx) {
84
78
  const db = new CouchDB(ctx.appId);
85
79
  const datasourceId = ctx.params.datasourceId;
86
80
  let datasource = yield db.get(datasourceId);
87
- const auth = datasource.config.auth;
88
81
  yield invalidateVariables(datasource, ctx.request.body);
89
82
  datasource = Object.assign(Object.assign({}, datasource), ctx.request.body);
90
- if (auth && !ctx.request.body.auth) {
91
- // don't strip auth config from DB
92
- datasource.config.auth = auth;
93
- }
94
83
  const response = yield db.put(datasource);
95
84
  datasource._rev = response.rev;
96
85
  // Drain connection pools when configuration is changed
@@ -0,0 +1,30 @@
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 CouchDB = require("../../db");
12
+ const { getDeployedApps } = require("../../utilities/workerRequests");
13
+ const { getScopedConfig } = require("@budibase/backend-core/db");
14
+ const { Configs } = require("@budibase/backend-core/constants");
15
+ const { checkSlashesInUrl } = require("../../utilities");
16
+ exports.fetchUrls = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
17
+ const appId = ctx.appId;
18
+ const db = new CouchDB(appId);
19
+ const settings = yield getScopedConfig(db, { type: Configs.SETTINGS });
20
+ let appUrl = "http://localhost:10000/app";
21
+ if (settings && settings["platformUrl"]) {
22
+ appUrl = checkSlashesInUrl(`${settings["platformUrl"]}/app`);
23
+ }
24
+ ctx.body = {
25
+ app: appUrl,
26
+ };
27
+ });
28
+ exports.getDeployedApps = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
29
+ ctx.body = yield getDeployedApps();
30
+ });
@@ -431,6 +431,7 @@ var External;
431
431
  * all and then re-create, as theres no chance of losing data (e.g. delete succeed, but write fail).
432
432
  */
433
433
  handleManyRelationships(mainTableId, row, relationships) {
434
+ var _a;
434
435
  return __awaiter(this, void 0, void 0, function* () {
435
436
  const { appId } = this;
436
437
  // if we're creating (in a through table) need to wipe the existing ones first
@@ -442,7 +443,7 @@ var External;
442
443
  const linkTable = this.getTable(tableId);
443
444
  // @ts-ignore
444
445
  const linkPrimary = linkTable.primary[0];
445
- const rows = related[key].rows || [];
446
+ const rows = ((_a = related[key]) === null || _a === void 0 ? void 0 : _a.rows) || [];
446
447
  const found = rows.find((row) => row[linkPrimary] === relationship.id ||
447
448
  row[linkPrimary] === body[linkPrimary]);
448
449
  const operation = isUpdate
@@ -64,17 +64,19 @@ exports.validate = ({ appId, tableId, row, table }) => __awaiter(void 0, void 0,
64
64
  }
65
65
  let res;
66
66
  // Validate.js doesn't seem to handle array
67
- if (type === FieldTypes.ARRAY && row[fieldName]) {
68
- if (row[fieldName].length) {
67
+ if (type === FieldTypes.ARRAY) {
68
+ const hasValues = Array.isArray(row[fieldName]) && row[fieldName].length > 0;
69
+ // Check values are valid if values are specified
70
+ if (hasValues) {
69
71
  row[fieldName].map(val => {
70
72
  if (!constraints.inclusion.includes(val)) {
71
- errors[fieldName] = "Field not in list";
73
+ errors[fieldName] = "Value not in list";
72
74
  }
73
75
  });
74
76
  }
75
- else if (constraints.presence && row[fieldName].length === 0) {
76
- // non required MultiSelect creates an empty array, which should not throw errors
77
- errors[fieldName] = [`${fieldName} is required`];
77
+ // Check for required constraint
78
+ if (constraints.presence === true && !hasValues) {
79
+ errors[fieldName] = "Required field";
78
80
  }
79
81
  }
80
82
  else if (type === FieldTypes.JSON && typeof row[fieldName] === "string") {
@@ -14,7 +14,7 @@ const { resolve, join } = require("../../../utilities/centralPath");
14
14
  const uuid = require("uuid");
15
15
  const { ObjectStoreBuckets } = require("../../../constants");
16
16
  const { processString } = require("@budibase/string-templates");
17
- const { getAllApps } = require("@budibase/backend-core/db");
17
+ const { getDeployedApps } = require("../../../utilities/workerRequests");
18
18
  const CouchDB = require("../../../db");
19
19
  const { loadHandlebarsFile, NODE_MODULES_PATH, TOP_LEVEL_PATH, } = require("../../../utilities/fileSystem");
20
20
  const env = require("../../../environment");
@@ -22,8 +22,6 @@ const { clientLibraryPath } = require("../../../utilities");
22
22
  const { upload } = require("../../../utilities/fileSystem");
23
23
  const { attachmentsRelativeURL } = require("../../../utilities");
24
24
  const { DocumentTypes } = require("../../../db/utils");
25
- const AWS = require("aws-sdk");
26
- const AWS_REGION = env.AWS_REGION ? env.AWS_REGION : "eu-west-1";
27
25
  function prepareUpload({ s3Key, bucket, metadata, file }) {
28
26
  return __awaiter(this, void 0, void 0, function* () {
29
27
  const response = yield upload({
@@ -43,15 +41,13 @@ function prepareUpload({ s3Key, bucket, metadata, file }) {
43
41
  };
44
42
  });
45
43
  }
46
- function getAppIdFromUrl(ctx) {
44
+ function checkForSelfHostedURL(ctx) {
47
45
  return __awaiter(this, void 0, void 0, function* () {
48
- // the "appId" component of the URL can be the id or the custom url
46
+ // the "appId" component of the URL may actually be a specific self hosted URL
49
47
  let possibleAppUrl = `/${encodeURI(ctx.params.appId).toLowerCase()}`;
50
- // search prod apps for a url that matches, exclude dev where id is always used
51
- const apps = yield getAllApps(CouchDB, { dev: false });
52
- const app = apps.filter(a => a.url && a.url.toLowerCase() === possibleAppUrl)[0];
53
- if (app && app.appId) {
54
- return app.appId;
48
+ const apps = yield getDeployedApps();
49
+ if (apps[possibleAppUrl] && apps[possibleAppUrl].appId) {
50
+ return apps[possibleAppUrl].appId;
55
51
  }
56
52
  else {
57
53
  return ctx.params.appId;
@@ -84,7 +80,10 @@ exports.uploadFile = function (ctx) {
84
80
  };
85
81
  exports.serveApp = function (ctx) {
86
82
  return __awaiter(this, void 0, void 0, function* () {
87
- let appId = yield getAppIdFromUrl(ctx);
83
+ let appId = ctx.params.appId;
84
+ if (env.SELF_HOSTED) {
85
+ appId = yield checkForSelfHostedURL(ctx);
86
+ }
88
87
  const App = require("./templates/BudibaseApp.svelte").default;
89
88
  const db = new CouchDB(appId, { skip_setup: true });
90
89
  const appInfo = yield db.get(DocumentTypes.APP_METADATA);
@@ -110,51 +109,3 @@ exports.serveClientLibrary = function (ctx) {
110
109
  });
111
110
  });
112
111
  };
113
- exports.getSignedUploadURL = function (ctx) {
114
- var _a, _b, _c;
115
- return __awaiter(this, void 0, void 0, function* () {
116
- const database = new CouchDB(ctx.appId);
117
- // Ensure datasource is valid
118
- let datasource;
119
- try {
120
- const { datasourceId } = ctx.params;
121
- datasource = yield database.get(datasourceId);
122
- if (!datasource) {
123
- ctx.throw(400, "The specified datasource could not be found");
124
- }
125
- }
126
- catch (error) {
127
- ctx.throw(400, "The specified datasource could not be found");
128
- }
129
- // Ensure we aren't using a custom endpoint
130
- if ((_a = datasource === null || datasource === void 0 ? void 0 : datasource.config) === null || _a === void 0 ? void 0 : _a.endpoint) {
131
- ctx.throw(400, "S3 datasources with custom endpoints are not supported");
132
- }
133
- // Determine type of datasource and generate signed URL
134
- let signedUrl;
135
- let publicUrl;
136
- if (datasource.source === "S3") {
137
- const { bucket, key } = ctx.request.body || {};
138
- if (!bucket || !key) {
139
- ctx.throw(400, "bucket and key values are required");
140
- return;
141
- }
142
- try {
143
- const s3 = new AWS.S3({
144
- region: AWS_REGION,
145
- accessKeyId: (_b = datasource === null || datasource === void 0 ? void 0 : datasource.config) === null || _b === void 0 ? void 0 : _b.accessKeyId,
146
- secretAccessKey: (_c = datasource === null || datasource === void 0 ? void 0 : datasource.config) === null || _c === void 0 ? void 0 : _c.secretAccessKey,
147
- apiVersion: "2006-03-01",
148
- signatureVersion: "v4",
149
- });
150
- const params = { Bucket: bucket, Key: key };
151
- signedUrl = s3.getSignedUrl("putObject", params);
152
- publicUrl = `https://${bucket}.s3.${AWS_REGION}.amazonaws.com/${key}`;
153
- }
154
- catch (error) {
155
- ctx.throw(400, error);
156
- }
157
- }
158
- ctx.body = { signedUrl, publicUrl };
159
- });
160
- };
@@ -12,7 +12,7 @@ const CouchDB = require("../../../db");
12
12
  const internal = require("./internal");
13
13
  const external = require("./external");
14
14
  const csvParser = require("../../../utilities/csvParser");
15
- const { isExternalTable, isSQL } = require("../../../integrations/utils");
15
+ const { isExternalTable } = require("../../../integrations/utils");
16
16
  const { getTableParams, getDatasourceParams, BudibaseInternalDB, } = require("../../../db/utils");
17
17
  const { getTable } = require("./utils");
18
18
  function pickApi({ tableId, table }) {
@@ -34,18 +34,12 @@ exports.fetch = function (ctx) {
34
34
  const internalTables = yield db.allDocs(getTableParams(null, {
35
35
  include_docs: true,
36
36
  }));
37
- const internal = internalTables.rows.map(tableDoc => (Object.assign(Object.assign({}, tableDoc.doc), { type: "internal", sourceId: BudibaseInternalDB._id })));
37
+ const internal = internalTables.rows.map(row => (Object.assign(Object.assign({}, row.doc), { type: "internal", sourceId: BudibaseInternalDB._id })));
38
38
  const externalTables = yield db.allDocs(getDatasourceParams("plus", {
39
39
  include_docs: true,
40
40
  }));
41
- const external = externalTables.rows.flatMap(tableDoc => {
42
- let entities = tableDoc.doc.entities;
43
- if (entities) {
44
- return Object.values(entities).map(entity => (Object.assign(Object.assign({}, entity), { type: "external", sourceId: tableDoc.doc._id, sql: isSQL(tableDoc.doc) })));
45
- }
46
- else {
47
- return [];
48
- }
41
+ const external = externalTables.rows.flatMap(row => {
42
+ return Object.values(row.doc.entities || {}).map(entity => (Object.assign(Object.assign({}, entity), { type: "external", sourceId: row.doc._id })));
49
43
  });
50
44
  ctx.body = [...internal, ...external];
51
45
  });
@@ -24,7 +24,6 @@ const linkRows = require("../../../db/linkedRows");
24
24
  const { getRowParams, generateTableID } = require("../../../db/utils");
25
25
  const { FieldTypes } = require("../../../constants");
26
26
  const { TableSaveFunctions, hasTypeChanged, getTable, handleDataImport, } = require("./utils");
27
- const usageQuota = require("../../../utilities/usageQuota");
28
27
  exports.save = function (ctx) {
29
28
  return __awaiter(this, void 0, void 0, function* () {
30
29
  const appId = ctx.appId;
@@ -119,7 +118,6 @@ exports.destroy = function (ctx) {
119
118
  include_docs: true,
120
119
  }));
121
120
  yield db.bulkDocs(rows.rows.map(row => (Object.assign(Object.assign({}, row.doc), { _deleted: true }))));
122
- yield usageQuota.update(usageQuota.Properties.ROW, -rows.rows.length);
123
121
  // update linked rows
124
122
  yield linkRows.updateLinks({
125
123
  appId,
@@ -14,11 +14,10 @@ const { getRowParams, generateRowID, InternalTables, } = require("../../../db/ut
14
14
  const { isEqual } = require("lodash/fp");
15
15
  const { AutoFieldSubTypes, FieldTypes } = require("../../../constants");
16
16
  const { inputProcessing } = require("../../../utilities/rowProcessor");
17
- const { USERS_TABLE_SCHEMA, SwitchableTypes } = require("../../../constants");
18
- const { isExternalTable, breakExternalTableId, isSQL, } = require("../../../integrations/utils");
17
+ const { USERS_TABLE_SCHEMA, SwitchableTypes, CanSwitchTypes, } = require("../../../constants");
18
+ const { isExternalTable, breakExternalTableId, } = require("../../../integrations/utils");
19
19
  const { getViews, saveView } = require("../view/utils");
20
20
  const viewTemplate = require("../view/viewBuilder");
21
- const usageQuota = require("../../../utilities/usageQuota");
22
21
  exports.checkForColumnUpdates = (db, oldTable, updatedTable) => __awaiter(void 0, void 0, void 0, function* () {
23
22
  let updatedRows = [];
24
23
  const rename = updatedTable._rename;
@@ -96,11 +95,7 @@ exports.handleDataImport = (appId, user, table, dataImport) => __awaiter(void 0,
96
95
  }
97
96
  finalData.push(row);
98
97
  }
99
- yield usageQuota.update(usageQuota.Properties.ROW, finalData.length, {
100
- dryRun: true,
101
- });
102
98
  yield db.bulkDocs(finalData);
103
- yield usageQuota.update(usageQuota.Properties.ROW, finalData.length);
104
99
  let response = yield db.put(table);
105
100
  table._rev = response._rev;
106
101
  return table;
@@ -212,9 +207,7 @@ exports.getTable = (appId, tableId) => __awaiter(void 0, void 0, void 0, functio
212
207
  const db = new CouchDB(appId);
213
208
  if (isExternalTable(tableId)) {
214
209
  let { datasourceId, tableName } = breakExternalTableId(tableId);
215
- const datasource = yield db.get(datasourceId);
216
- const table = yield exports.getExternalTable(appId, datasourceId, tableName);
217
- return Object.assign(Object.assign({}, table), { sql: isSQL(datasource) });
210
+ return exports.getExternalTable(appId, datasourceId, tableName);
218
211
  }
219
212
  else {
220
213
  return db.get(tableId);
@@ -302,6 +295,19 @@ exports.foreignKeyStructure = (keyName, meta = null) => {
302
295
  }
303
296
  return structure;
304
297
  };
298
+ exports.areSwitchableTypes = (type1, type2) => {
299
+ if (SwitchableTypes.indexOf(type1) === -1 &&
300
+ SwitchableTypes.indexOf(type2) === -1) {
301
+ return false;
302
+ }
303
+ for (let option of CanSwitchTypes) {
304
+ const index1 = option.indexOf(type1), index2 = option.indexOf(type2);
305
+ if (index1 !== -1 && index2 !== -1 && index1 !== index2) {
306
+ return true;
307
+ }
308
+ }
309
+ return false;
310
+ };
305
311
  exports.hasTypeChanged = (table, oldTable) => {
306
312
  if (!oldTable) {
307
313
  return false;
@@ -312,7 +318,7 @@ exports.hasTypeChanged = (table, oldTable) => {
312
318
  continue;
313
319
  }
314
320
  const newType = table.schema[key].type;
315
- if (oldType !== newType && SwitchableTypes.indexOf(oldType) === -1) {
321
+ if (oldType !== newType && !exports.areSwitchableTypes(oldType, newType)) {
316
322
  return true;
317
323
  }
318
324
  }
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ const Router = require("@koa/router");
3
+ const controller = require("../controllers/hosting");
4
+ const authorized = require("../../middleware/authorized");
5
+ const { BUILDER } = require("@budibase/backend-core/permissions");
6
+ const router = Router();
7
+ router
8
+ .get("/api/hosting/urls", authorized(BUILDER), controller.fetchUrls)
9
+ // this isn't risky, doesn't return anything about apps other than names and URLs
10
+ .get("/api/hosting/apps", controller.getDeployedApps);
11
+ module.exports = router;
@@ -21,6 +21,7 @@ const integrationRoutes = require("./integration");
21
21
  const permissionRoutes = require("./permission");
22
22
  const datasourceRoutes = require("./datasource");
23
23
  const queryRoutes = require("./query");
24
+ const hostingRoutes = require("./hosting");
24
25
  const backupRoutes = require("./backup");
25
26
  const metadataRoutes = require("./metadata");
26
27
  const devRoutes = require("./dev");
@@ -45,6 +46,7 @@ exports.mainRoutes = [
45
46
  permissionRoutes,
46
47
  datasourceRoutes,
47
48
  queryRoutes,
49
+ hostingRoutes,
48
50
  backupRoutes,
49
51
  metadataRoutes,
50
52
  devRoutes,
@@ -43,6 +43,5 @@ router
43
43
  .post("/api/attachments/process", authorized(BUILDER), controller.uploadFile)
44
44
  .post("/api/attachments/:tableId/upload", paramResource("tableId"), authorized(PermissionTypes.TABLE, PermissionLevels.WRITE), controller.uploadFile)
45
45
  // TODO: this likely needs to be secured in some way
46
- .get("/:appId/:path*", controller.serveApp)
47
- .post("/api/attachments/:datasourceId/url", authorized(PermissionTypes.TABLE, PermissionLevels.READ), controller.getSignedUploadURL);
46
+ .get("/:appId/:path*", controller.serveApp);
48
47
  module.exports = router;
@@ -10,6 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  const rowController = require("../../api/controllers/row");
12
12
  const automationUtils = require("../automationUtils");
13
+ const env = require("../../environment");
13
14
  const usage = require("../../utilities/usageQuota");
14
15
  const { buildCtx } = require("./utils");
15
16
  exports.definition = {
@@ -86,9 +87,10 @@ exports.run = function ({ inputs, appId, emitter }) {
86
87
  });
87
88
  try {
88
89
  inputs.row = yield automationUtils.cleanUpRow(appId, inputs.row.tableId, inputs.row);
89
- yield usage.update(usage.Properties.ROW, 1, { dryRun: true });
90
+ if (env.USE_QUOTAS) {
91
+ yield usage.update(usage.Properties.ROW, 1);
92
+ }
90
93
  yield rowController.save(ctx);
91
- yield usage.update(usage.Properties.ROW, 1);
92
94
  return {
93
95
  row: inputs.row,
94
96
  response: ctx.body,
@@ -9,6 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  const rowController = require("../../api/controllers/row");
12
+ const env = require("../../environment");
12
13
  const usage = require("../../utilities/usageQuota");
13
14
  const { buildCtx } = require("./utils");
14
15
  const automationUtils = require("../automationUtils");
@@ -80,7 +81,9 @@ exports.run = function ({ inputs, appId, emitter }) {
80
81
  },
81
82
  });
82
83
  try {
83
- yield usage.update(usage.Properties.ROW, -1);
84
+ if (env.isProd()) {
85
+ yield usage.update(usage.Properties.ROW, -1);
86
+ }
84
87
  yield rowController.destroy(ctx);
85
88
  return {
86
89
  response: ctx.body,
@@ -41,12 +41,12 @@ exports.FieldTypes = {
41
41
  JSON: "json",
42
42
  INTERNAL: "internal",
43
43
  };
44
- exports.SwitchableTypes = [
45
- exports.FieldTypes.STRING,
46
- exports.FieldTypes.OPTIONS,
47
- exports.FieldTypes.NUMBER,
48
- exports.FieldTypes.BOOLEAN,
44
+ exports.CanSwitchTypes = [
45
+ [exports.FieldTypes.JSON, exports.FieldTypes.ARRAY],
46
+ [exports.FieldTypes.STRING, exports.FieldTypes.OPTIONS],
47
+ [exports.FieldTypes.BOOLEAN, exports.FieldTypes.NUMBER],
49
48
  ];
49
+ exports.SwitchableTypes = exports.CanSwitchTypes.reduce((prev, current) => prev ? prev.concat(current) : current);
50
50
  exports.RelationshipTypes = {
51
51
  ONE_TO_MANY: "one-to-many",
52
52
  MANY_TO_ONE: "many-to-one",
@@ -67,9 +67,6 @@ exports.DataSourceOperation = {
67
67
  UPDATE_TABLE: "UPDATE_TABLE",
68
68
  DELETE_TABLE: "DELETE_TABLE",
69
69
  };
70
- exports.DatasourceAuthTypes = {
71
- GOOGLE: "google",
72
- };
73
70
  exports.SortDirection = {
74
71
  ASCENDING: "ASCENDING",
75
72
  DESCENDING: "DESCENDING",
@@ -49,7 +49,6 @@ var SourceNames;
49
49
  SourceNames["ARANGODB"] = "ARANGODB";
50
50
  SourceNames["REST"] = "REST";
51
51
  SourceNames["ORACLE"] = "ORACLE";
52
- SourceNames["GOOGLE_SHEETS"] = "GOOGLE_SHEETS";
53
52
  })(SourceNames = exports.SourceNames || (exports.SourceNames = {}));
54
53
  var IncludeRelationships;
55
54
  (function (IncludeRelationships) {
@@ -30,7 +30,6 @@ module.exports = {
30
30
  MINIO_ACCESS_KEY: process.env.MINIO_ACCESS_KEY,
31
31
  MINIO_SECRET_KEY: process.env.MINIO_SECRET_KEY,
32
32
  USE_QUOTAS: process.env.USE_QUOTAS,
33
- EXCLUDE_QUOTAS_TENANTS: process.env.EXCLUDE_QUOTAS_TENANTS,
34
33
  REDIS_URL: process.env.REDIS_URL,
35
34
  REDIS_PASSWORD: process.env.REDIS_PASSWORD,
36
35
  INTERNAL_API_KEY: process.env.INTERNAL_API_KEY,
@@ -69,16 +69,10 @@ class InternalBuilder {
69
69
  this.client = client;
70
70
  }
71
71
  // right now we only do filters on the specific table being queried
72
- addFilters(query, filters, opts) {
72
+ addFilters(tableName, query, filters) {
73
73
  function iterate(structure, fn) {
74
74
  for (let [key, value] of Object.entries(structure)) {
75
- const isRelationshipField = key.includes(".");
76
- if (!opts.relationship && !isRelationshipField) {
77
- fn(`${opts.tableName}.${key}`, value);
78
- }
79
- if (opts.relationship && isRelationshipField) {
80
- fn(key, value);
81
- }
75
+ fn(`${tableName}.${key}`, value);
82
76
  }
83
77
  }
84
78
  if (!filters) {
@@ -254,7 +248,7 @@ class InternalBuilder {
254
248
  if (foundOffset) {
255
249
  query = query.offset(foundOffset);
256
250
  }
257
- query = this.addFilters(query, filters, { tableName });
251
+ query = this.addFilters(tableName, query, filters);
258
252
  // add sorting to pre-query
259
253
  query = this.addSorting(query, json);
260
254
  // @ts-ignore
@@ -267,14 +261,13 @@ class InternalBuilder {
267
261
  preQuery = this.addSorting(preQuery, json);
268
262
  }
269
263
  // handle joins
270
- query = this.addRelationships(knex, preQuery, selectStatement, tableName, relationships);
271
- return this.addFilters(query, filters, { relationship: true });
264
+ return this.addRelationships(knex, preQuery, selectStatement, tableName, relationships);
272
265
  }
273
266
  update(knex, json, opts) {
274
267
  const { endpoint, body, filters } = json;
275
268
  let query = knex(endpoint.entityId);
276
269
  const parsedBody = parseBody(body);
277
- query = this.addFilters(query, filters, { tableName: endpoint.entityId });
270
+ query = this.addFilters(endpoint.entityId, query, filters);
278
271
  // mysql can't use returning
279
272
  if (opts.disableReturning) {
280
273
  return query.update(parsedBody);
@@ -286,7 +279,7 @@ class InternalBuilder {
286
279
  delete(knex, json, opts) {
287
280
  const { endpoint, filters } = json;
288
281
  let query = knex(endpoint.entityId);
289
- query = this.addFilters(query, filters, { tableName: endpoint.entityId });
282
+ query = this.addFilters(endpoint.entityId, query, filters);
290
283
  // mysql can't use returning
291
284
  if (opts.disableReturning) {
292
285
  return query.delete();