@budibase/server 1.0.46-alpha.4 → 1.0.46-alpha.5

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 (207) hide show
  1. package/builder/assets/{index.c21ee1fb.js → index.298ba3d3.js} +183 -183
  2. package/builder/assets/{vendor.10e2ad1b.js → vendor.3bd2f661.js} +1 -1
  3. package/builder/index.html +2 -2
  4. package/coverage/clover.xml +1590 -1615
  5. package/coverage/coverage-final.json +136 -138
  6. package/coverage/lcov-report/api/controllers/analytics.js.html +6 -6
  7. package/coverage/lcov-report/api/controllers/apikeys.js.html +6 -6
  8. package/coverage/lcov-report/api/controllers/application.js.html +190 -127
  9. package/coverage/lcov-report/api/controllers/auth.js.html +7 -7
  10. package/coverage/lcov-report/api/controllers/automation.js.html +21 -21
  11. package/coverage/lcov-report/api/controllers/backup.js.html +3 -3
  12. package/coverage/lcov-report/api/controllers/cloud.js.html +12 -12
  13. package/coverage/lcov-report/api/controllers/component.js.html +5 -5
  14. package/coverage/lcov-report/api/controllers/datasource.js.html +16 -16
  15. package/coverage/lcov-report/api/controllers/dev.js.html +19 -19
  16. package/coverage/lcov-report/api/controllers/index.html +19 -34
  17. package/coverage/lcov-report/api/controllers/integration.js.html +4 -4
  18. package/coverage/lcov-report/api/controllers/layout.js.html +6 -6
  19. package/coverage/lcov-report/api/controllers/metadata.js.html +9 -9
  20. package/coverage/lcov-report/api/controllers/permission.js.html +15 -15
  21. package/coverage/lcov-report/api/controllers/query/index.html +1 -1
  22. package/coverage/lcov-report/api/controllers/query/index.js.html +19 -19
  23. package/coverage/lcov-report/api/controllers/query/validation.js.html +9 -9
  24. package/coverage/lcov-report/api/controllers/role.js.html +9 -9
  25. package/coverage/lcov-report/api/controllers/routing.js.html +9 -9
  26. package/coverage/lcov-report/api/controllers/row/external.js.html +16 -16
  27. package/coverage/lcov-report/api/controllers/row/index.html +1 -1
  28. package/coverage/lcov-report/api/controllers/row/index.js.html +13 -13
  29. package/coverage/lcov-report/api/controllers/row/internal.js.html +26 -26
  30. package/coverage/lcov-report/api/controllers/row/internalSearch.js.html +8 -8
  31. package/coverage/lcov-report/api/controllers/row/utils.js.html +13 -13
  32. package/coverage/lcov-report/api/controllers/screen.js.html +7 -7
  33. package/coverage/lcov-report/api/controllers/script.js.html +4 -4
  34. package/coverage/lcov-report/api/controllers/table/external.js.html +12 -12
  35. package/coverage/lcov-report/api/controllers/table/index.html +1 -1
  36. package/coverage/lcov-report/api/controllers/table/index.js.html +14 -14
  37. package/coverage/lcov-report/api/controllers/table/internal.js.html +10 -10
  38. package/coverage/lcov-report/api/controllers/table/utils.js.html +26 -26
  39. package/coverage/lcov-report/api/controllers/templates.js.html +5 -5
  40. package/coverage/lcov-report/api/controllers/user.js.html +20 -20
  41. package/coverage/lcov-report/api/controllers/view/exporters.js.html +4 -4
  42. package/coverage/lcov-report/api/controllers/view/index.html +1 -1
  43. package/coverage/lcov-report/api/controllers/view/index.js.html +14 -14
  44. package/coverage/lcov-report/api/controllers/view/utils.js.html +11 -11
  45. package/coverage/lcov-report/api/controllers/view/viewBuilder.js.html +7 -7
  46. package/coverage/lcov-report/api/controllers/webhook.js.html +15 -15
  47. package/coverage/lcov-report/api/index.html +1 -1
  48. package/coverage/lcov-report/api/index.js.html +26 -26
  49. package/coverage/lcov-report/api/routes/analytics.js.html +6 -6
  50. package/coverage/lcov-report/api/routes/apikeys.js.html +8 -8
  51. package/coverage/lcov-report/api/routes/application.js.html +9 -9
  52. package/coverage/lcov-report/api/routes/auth.js.html +6 -6
  53. package/coverage/lcov-report/api/routes/automation.js.html +14 -14
  54. package/coverage/lcov-report/api/routes/backup.js.html +8 -8
  55. package/coverage/lcov-report/api/routes/cloud.js.html +8 -8
  56. package/coverage/lcov-report/api/routes/component.js.html +8 -8
  57. package/coverage/lcov-report/api/routes/datasource.js.html +13 -13
  58. package/coverage/lcov-report/api/routes/deploy.js.html +8 -8
  59. package/coverage/lcov-report/api/routes/dev.js.html +13 -13
  60. package/coverage/lcov-report/api/routes/index.html +7 -22
  61. package/coverage/lcov-report/api/routes/index.js.html +31 -37
  62. package/coverage/lcov-report/api/routes/integration.js.html +8 -8
  63. package/coverage/lcov-report/api/routes/layout.js.html +8 -8
  64. package/coverage/lcov-report/api/routes/metadata.js.html +9 -9
  65. package/coverage/lcov-report/api/routes/permission.js.html +12 -12
  66. package/coverage/lcov-report/api/routes/query.js.html +10 -10
  67. package/coverage/lcov-report/api/routes/role.js.html +12 -12
  68. package/coverage/lcov-report/api/routes/routing.js.html +8 -8
  69. package/coverage/lcov-report/api/routes/row.js.html +10 -10
  70. package/coverage/lcov-report/api/routes/screen.js.html +11 -11
  71. package/coverage/lcov-report/api/routes/script.js.html +1 -1
  72. package/coverage/lcov-report/api/routes/static.js.html +13 -13
  73. package/coverage/lcov-report/api/routes/table.js.html +12 -12
  74. package/coverage/lcov-report/api/routes/templates.js.html +8 -8
  75. package/coverage/lcov-report/api/routes/user.js.html +8 -8
  76. package/coverage/lcov-report/api/routes/view.js.html +10 -10
  77. package/coverage/lcov-report/api/routes/webhook.js.html +11 -11
  78. package/coverage/lcov-report/automations/actions.js.html +24 -24
  79. package/coverage/lcov-report/automations/automationUtils.js.html +5 -5
  80. package/coverage/lcov-report/automations/bullboard.js.html +16 -16
  81. package/coverage/lcov-report/automations/index.html +1 -1
  82. package/coverage/lcov-report/automations/index.js.html +7 -7
  83. package/coverage/lcov-report/automations/steps/bash.js.html +6 -6
  84. package/coverage/lcov-report/automations/steps/createRow.js.html +7 -7
  85. package/coverage/lcov-report/automations/steps/delay.js.html +4 -4
  86. package/coverage/lcov-report/automations/steps/deleteRow.js.html +7 -7
  87. package/coverage/lcov-report/automations/steps/discord.js.html +7 -7
  88. package/coverage/lcov-report/automations/steps/executeQuery.js.html +6 -6
  89. package/coverage/lcov-report/automations/steps/executeScript.js.html +6 -6
  90. package/coverage/lcov-report/automations/steps/filter.js.html +7 -7
  91. package/coverage/lcov-report/automations/steps/index.html +1 -1
  92. package/coverage/lcov-report/automations/steps/integromat.js.html +5 -5
  93. package/coverage/lcov-report/automations/steps/outgoingWebhook.js.html +8 -8
  94. package/coverage/lcov-report/automations/steps/queryRows.js.html +10 -10
  95. package/coverage/lcov-report/automations/steps/sendSmtpEmail.js.html +5 -5
  96. package/coverage/lcov-report/automations/steps/serverLog.js.html +3 -3
  97. package/coverage/lcov-report/automations/steps/slack.js.html +5 -5
  98. package/coverage/lcov-report/automations/steps/updateRow.js.html +6 -6
  99. package/coverage/lcov-report/automations/steps/utils.js.html +3 -3
  100. package/coverage/lcov-report/automations/steps/zapier.js.html +5 -5
  101. package/coverage/lcov-report/automations/triggerInfo/app.js.html +2 -2
  102. package/coverage/lcov-report/automations/triggerInfo/cron.js.html +2 -2
  103. package/coverage/lcov-report/automations/triggerInfo/index.html +1 -1
  104. package/coverage/lcov-report/automations/triggerInfo/index.js.html +8 -8
  105. package/coverage/lcov-report/automations/triggerInfo/rowDeleted.js.html +2 -2
  106. package/coverage/lcov-report/automations/triggerInfo/rowSaved.js.html +2 -2
  107. package/coverage/lcov-report/automations/triggerInfo/rowUpdated.js.html +2 -2
  108. package/coverage/lcov-report/automations/triggerInfo/webhook.js.html +2 -2
  109. package/coverage/lcov-report/automations/triggers.js.html +18 -18
  110. package/coverage/lcov-report/automations/utils.js.html +32 -32
  111. package/coverage/lcov-report/constants/index.html +1 -1
  112. package/coverage/lcov-report/constants/index.js.html +22 -22
  113. package/coverage/lcov-report/constants/layouts.js.html +5 -5
  114. package/coverage/lcov-report/constants/screens.js.html +4 -4
  115. package/coverage/lcov-report/db/client.js.html +18 -18
  116. package/coverage/lcov-report/db/inMemoryView.js.html +7 -7
  117. package/coverage/lcov-report/db/index.html +1 -1
  118. package/coverage/lcov-report/db/index.js.html +3 -3
  119. package/coverage/lcov-report/db/linkedRows/LinkController.js.html +7 -7
  120. package/coverage/lcov-report/db/linkedRows/index.html +1 -1
  121. package/coverage/lcov-report/db/linkedRows/index.js.html +18 -18
  122. package/coverage/lcov-report/db/linkedRows/linkUtils.js.html +13 -13
  123. package/coverage/lcov-report/db/newid.js.html +4 -4
  124. package/coverage/lcov-report/db/utils.js.html +73 -73
  125. package/coverage/lcov-report/events/AutomationEmitter.js.html +1 -1
  126. package/coverage/lcov-report/events/index.html +1 -1
  127. package/coverage/lcov-report/events/index.js.html +6 -6
  128. package/coverage/lcov-report/events/utils.js.html +3 -3
  129. package/coverage/lcov-report/index.html +45 -45
  130. package/coverage/lcov-report/integrations/tests/TestConfiguration.js.html +1 -1
  131. package/coverage/lcov-report/integrations/tests/index.html +1 -1
  132. package/coverage/lcov-report/middleware/appInfo.js.html +5 -5
  133. package/coverage/lcov-report/middleware/authorized.js.html +17 -17
  134. package/coverage/lcov-report/middleware/builder.js.html +16 -16
  135. package/coverage/lcov-report/middleware/currentapp.js.html +46 -73
  136. package/coverage/lcov-report/middleware/index.html +10 -10
  137. package/coverage/lcov-report/middleware/joi-validator.js.html +6 -6
  138. package/coverage/lcov-report/middleware/resourceId.js.html +22 -22
  139. package/coverage/lcov-report/middleware/selfhost.js.html +1 -1
  140. package/coverage/lcov-report/middleware/usageQuota.js.html +17 -17
  141. package/coverage/lcov-report/middleware/utils.js.html +4 -4
  142. package/coverage/lcov-report/migrations/usageQuotas/index.html +1 -1
  143. package/coverage/lcov-report/migrations/usageQuotas/index.js.html +6 -6
  144. package/coverage/lcov-report/migrations/usageQuotas/syncApps.js.html +6 -6
  145. package/coverage/lcov-report/migrations/usageQuotas/syncRows.js.html +7 -7
  146. package/coverage/lcov-report/threads/automation.js.html +1 -1
  147. package/coverage/lcov-report/threads/index.html +15 -15
  148. package/coverage/lcov-report/threads/index.js.html +10 -10
  149. package/coverage/lcov-report/threads/query.js.html +23 -8
  150. package/coverage/lcov-report/threads/utils.js.html +14 -14
  151. package/coverage/lcov-report/utilities/bcrypt.js.html +1 -1
  152. package/coverage/lcov-report/utilities/budibaseDir.js.html +7 -7
  153. package/coverage/lcov-report/utilities/centralPath.js.html +4 -4
  154. package/coverage/lcov-report/utilities/csvParser.js.html +6 -6
  155. package/coverage/lcov-report/utilities/global.js.html +26 -26
  156. package/coverage/lcov-report/utilities/index.html +19 -19
  157. package/coverage/lcov-report/utilities/index.js.html +25 -25
  158. package/coverage/lcov-report/utilities/queue/inMemoryQueue.js.html +9 -9
  159. package/coverage/lcov-report/utilities/queue/index.html +1 -1
  160. package/coverage/lcov-report/utilities/routing/index.html +1 -1
  161. package/coverage/lcov-report/utilities/routing/index.js.html +6 -6
  162. package/coverage/lcov-report/utilities/rowProcessor/index.html +1 -1
  163. package/coverage/lcov-report/utilities/rowProcessor/index.js.html +17 -17
  164. package/coverage/lcov-report/utilities/rowProcessor/utils.js.html +4 -4
  165. package/coverage/lcov-report/utilities/scriptRunner.js.html +5 -5
  166. package/coverage/lcov-report/utilities/security.js.html +8 -8
  167. package/coverage/lcov-report/utilities/statusCodes.js.html +1 -1
  168. package/coverage/lcov-report/utilities/usageQuota/index.html +1 -1
  169. package/coverage/lcov-report/utilities/usageQuota/index.js.html +8 -8
  170. package/coverage/lcov-report/utilities/usageQuota/rows.js.html +8 -8
  171. package/coverage/lcov-report/utilities/usageQuota/usageQuoteReset.js.html +1 -1
  172. package/coverage/lcov-report/utilities/users.js.html +5 -5
  173. package/coverage/lcov-report/utilities/workerRequests.js.html +39 -108
  174. package/coverage/lcov.info +1937 -1974
  175. package/dist/api/controllers/application.js +45 -24
  176. package/dist/api/controllers/static/index.js +9 -10
  177. package/dist/api/routes/index.js +0 -2
  178. package/dist/integrations/rest.js +5 -5
  179. package/dist/integrations/s3.js +1 -1
  180. package/dist/integrations/utils.js +6 -3
  181. package/dist/middleware/currentapp.js +0 -9
  182. package/dist/package.json +5 -5
  183. package/dist/tests/utilities/TestConfiguration.js +3 -1
  184. package/dist/threads/query.js +4 -0
  185. package/dist/tsconfig.tsbuildinfo +1 -1
  186. package/dist/utilities/workerRequests.js +0 -20
  187. package/nodemon.json +1 -1
  188. package/package.json +6 -6
  189. package/src/api/controllers/application.js +48 -27
  190. package/src/api/controllers/static/index.js +13 -10
  191. package/src/api/routes/index.js +0 -2
  192. package/src/api/routes/tests/application.spec.js +2 -2
  193. package/src/integrations/rest.ts +9 -28
  194. package/src/integrations/s3.ts +1 -1
  195. package/src/integrations/utils.ts +18 -5
  196. package/src/middleware/currentapp.js +0 -9
  197. package/src/migrations/tests/usageQuotas/syncRows.spec.js +1 -1
  198. package/src/tests/utilities/TestConfiguration.js +3 -1
  199. package/src/threads/query.js +5 -0
  200. package/src/utilities/workerRequests.js +0 -23
  201. package/coverage/lcov-report/api/controllers/hosting.js.html +0 -146
  202. package/coverage/lcov-report/api/routes/hosting.js.html +0 -119
  203. package/dist/api/controllers/hosting.js +0 -30
  204. package/dist/api/routes/hosting.js +0 -11
  205. package/src/api/controllers/hosting.js +0 -22
  206. package/src/api/routes/hosting.js +0 -13
  207. package/src/api/routes/tests/hosting.spec.js +0 -36
@@ -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 { getDeployedApps, removeAppFromUserRoles, } = require("../../utilities/workerRequests");
23
+ const { 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,31 +49,42 @@ function getUserRoleId(ctx) {
49
49
  ? BUILTIN_ROLE_IDS.PUBLIC
50
50
  : ctx.user.role._id;
51
51
  }
52
- function getAppUrlIfNotInUse(ctx) {
52
+ function getAppUrl(ctx) {
53
53
  return __awaiter(this, void 0, void 0, function* () {
54
+ // construct the url
54
55
  let url;
55
56
  if (ctx.request.body.url) {
57
+ // if the url is provided, use that
56
58
  url = encodeURI(ctx.request.body.url);
57
59
  }
58
- else if (ctx.request.body.name) {
60
+ else {
61
+ // otherwise use the name
59
62
  url = encodeURI(`${ctx.request.body.name}`);
60
63
  }
61
- if (url) {
62
- url = `/${url.replace(URL_REGEX_SLASH, "")}`.toLowerCase();
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
- }
64
+ url = `/${url.replace(URL_REGEX_SLASH, "")}`.toLowerCase();
74
65
  return url;
75
66
  });
76
67
  }
68
+ const checkAppUrl = (ctx, apps, url, currentAppId) => {
69
+ if (currentAppId) {
70
+ apps = apps.filter(app => app.appId !== currentAppId);
71
+ }
72
+ if (apps.some(app => app.url === url)) {
73
+ ctx.throw(400, "App URL is already in use.");
74
+ }
75
+ };
76
+ const checkAppName = (ctx, apps, name, currentAppId) => {
77
+ // TODO: Replace with Joi
78
+ if (!name) {
79
+ ctx.throw(400, "Name is required");
80
+ }
81
+ if (currentAppId) {
82
+ apps = apps.filter(app => app.appId !== currentAppId);
83
+ }
84
+ if (apps.some(app => app.name === name)) {
85
+ ctx.throw(400, "App name is already in use.");
86
+ }
87
+ };
77
88
  function createInstance(template) {
78
89
  return __awaiter(this, void 0, void 0, function* () {
79
90
  const tenantId = isMultiTenant() ? getTenantId() : null;
@@ -167,6 +178,11 @@ exports.fetchAppPackage = (ctx) => __awaiter(void 0, void 0, void 0, function* (
167
178
  };
168
179
  });
169
180
  exports.create = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
181
+ const apps = yield getAllApps(CouchDB, { dev: true });
182
+ const name = ctx.request.body.name;
183
+ checkAppName(ctx, apps, name);
184
+ const url = yield getAppUrl(ctx);
185
+ checkAppUrl(ctx, apps, url);
170
186
  const { useTemplate, templateKey, templateString } = ctx.request.body;
171
187
  const instanceConfig = {
172
188
  useTemplate,
@@ -178,7 +194,6 @@ exports.create = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
178
194
  }
179
195
  const instance = yield createInstance(instanceConfig);
180
196
  const appId = instance._id;
181
- const url = yield getAppUrlIfNotInUse(ctx);
182
197
  const db = new CouchDB(appId);
183
198
  let _rev;
184
199
  try {
@@ -196,7 +211,7 @@ exports.create = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
196
211
  type: "app",
197
212
  version: packageJson.version,
198
213
  componentLibraries: ["@budibase/standard-components"],
199
- name: ctx.request.body.name,
214
+ name: name,
200
215
  url: url,
201
216
  template: ctx.request.body.template,
202
217
  instance: instance,
@@ -220,7 +235,14 @@ exports.create = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
220
235
  ctx.body = newApplication;
221
236
  });
222
237
  exports.update = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
223
- const data = yield updateAppPackage(ctx, ctx.request.body, ctx.params.appId);
238
+ const apps = yield getAllApps(CouchDB, { dev: true });
239
+ // validation
240
+ const name = ctx.request.body.name;
241
+ checkAppName(ctx, apps, name, ctx.params.appId);
242
+ const url = yield getAppUrl(ctx);
243
+ checkAppUrl(ctx, apps, url, ctx.params.appId);
244
+ const appPackageUpdates = { name, url };
245
+ const data = yield updateAppPackage(appPackageUpdates, ctx.params.appId);
224
246
  ctx.status = 200;
225
247
  ctx.body = data;
226
248
  });
@@ -239,7 +261,7 @@ exports.updateClient = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
239
261
  version: packageJson.version,
240
262
  revertableVersion: currentVersion,
241
263
  };
242
- const data = yield updateAppPackage(ctx, appPackageUpdates, ctx.params.appId);
264
+ const data = yield updateAppPackage(appPackageUpdates, ctx.params.appId);
243
265
  ctx.status = 200;
244
266
  ctx.body = data;
245
267
  });
@@ -259,7 +281,7 @@ exports.revertClient = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
259
281
  version: application.revertableVersion,
260
282
  revertableVersion: null,
261
283
  };
262
- const data = yield updateAppPackage(ctx, appPackageUpdates, ctx.params.appId);
284
+ const data = yield updateAppPackage(appPackageUpdates, ctx.params.appId);
263
285
  ctx.status = 200;
264
286
  ctx.body = data;
265
287
  });
@@ -326,11 +348,10 @@ exports.sync = (ctx, next) => __awaiter(void 0, void 0, void 0, function* () {
326
348
  };
327
349
  }
328
350
  });
329
- const updateAppPackage = (ctx, appPackage, appId) => __awaiter(void 0, void 0, void 0, function* () {
330
- const url = yield getAppUrlIfNotInUse(ctx);
351
+ const updateAppPackage = (appPackage, appId) => __awaiter(void 0, void 0, void 0, function* () {
331
352
  const db = new CouchDB(appId);
332
353
  const application = yield db.get(DocumentTypes.APP_METADATA);
333
- const newAppPackage = Object.assign(Object.assign(Object.assign({}, application), appPackage), { url });
354
+ const newAppPackage = Object.assign(Object.assign({}, application), appPackage);
334
355
  if (appPackage._rev !== application._rev) {
335
356
  newAppPackage._rev = application._rev;
336
357
  }
@@ -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 { getDeployedApps } = require("../../../utilities/workerRequests");
17
+ const { getAllApps } = require("@budibase/backend-core/db");
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");
@@ -43,13 +43,15 @@ function prepareUpload({ s3Key, bucket, metadata, file }) {
43
43
  };
44
44
  });
45
45
  }
46
- function checkForSelfHostedURL(ctx) {
46
+ function getAppIdFromUrl(ctx) {
47
47
  return __awaiter(this, void 0, void 0, function* () {
48
- // the "appId" component of the URL may actually be a specific self hosted URL
48
+ // the "appId" component of the URL can be the id or the custom url
49
49
  let possibleAppUrl = `/${encodeURI(ctx.params.appId).toLowerCase()}`;
50
- const apps = yield getDeployedApps();
51
- if (apps[possibleAppUrl] && apps[possibleAppUrl].appId) {
52
- return apps[possibleAppUrl].appId;
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;
53
55
  }
54
56
  else {
55
57
  return ctx.params.appId;
@@ -82,10 +84,7 @@ exports.uploadFile = function (ctx) {
82
84
  };
83
85
  exports.serveApp = function (ctx) {
84
86
  return __awaiter(this, void 0, void 0, function* () {
85
- let appId = ctx.params.appId;
86
- if (env.SELF_HOSTED) {
87
- appId = yield checkForSelfHostedURL(ctx);
88
- }
87
+ let appId = yield getAppIdFromUrl(ctx);
89
88
  const App = require("./templates/BudibaseApp.svelte").default;
90
89
  const db = new CouchDB(appId, { skip_setup: true });
91
90
  const appInfo = yield db.get(DocumentTypes.APP_METADATA);
@@ -21,7 +21,6 @@ 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");
25
24
  const backupRoutes = require("./backup");
26
25
  const metadataRoutes = require("./metadata");
27
26
  const devRoutes = require("./dev");
@@ -46,7 +45,6 @@ exports.mainRoutes = [
46
45
  permissionRoutes,
47
46
  datasourceRoutes,
48
47
  queryRoutes,
49
- hostingRoutes,
50
48
  backupRoutes,
51
49
  metadataRoutes,
52
50
  devRoutes,
@@ -40,8 +40,8 @@ const coreFields = {
40
40
  enum: Object.values(BodyTypes),
41
41
  },
42
42
  pagination: {
43
- type: datasource_1.DatasourceFieldTypes.OBJECT,
44
- },
43
+ type: datasource_1.DatasourceFieldTypes.OBJECT
44
+ }
45
45
  };
46
46
  var RestModule;
47
47
  (function (RestModule) {
@@ -162,8 +162,8 @@ var RestModule;
162
162
  headers,
163
163
  },
164
164
  pagination: {
165
- cursor: nextCursor,
166
- },
165
+ cursor: nextCursor
166
+ }
167
167
  };
168
168
  });
169
169
  }
@@ -294,7 +294,7 @@ var RestModule;
294
294
  }
295
295
  _req(query) {
296
296
  return __awaiter(this, void 0, void 0, function* () {
297
- const { path = "", queryString = "", headers = {}, method = "GET", disabledHeaders, bodyType, requestBody, authConfigId, pagination, paginationValues, } = query;
297
+ const { path = "", queryString = "", headers = {}, method = "GET", disabledHeaders, bodyType, requestBody, authConfigId, pagination, paginationValues } = query;
298
298
  const authHeaders = this.getAuthHeaders(authConfigId);
299
299
  this.headers = Object.assign(Object.assign(Object.assign({}, this.config.defaultHeaders), headers), authHeaders);
300
300
  if (disabledHeaders) {
@@ -38,7 +38,7 @@ var S3Module;
38
38
  signatureVersion: {
39
39
  type: "string",
40
40
  required: false,
41
- default: "v4",
41
+ default: "v4"
42
42
  },
43
43
  },
44
44
  query: {
@@ -153,7 +153,9 @@ exports.isIsoDateString = isIsoDateString;
153
153
  * @param tableIds The IDs of the tables which currently exist.
154
154
  */
155
155
  function shouldCopyRelationship(column, tableIds) {
156
- return column.type === constants_1.FieldTypes.LINK && column.tableId && tableIds.includes(column.tableId);
156
+ return (column.type === constants_1.FieldTypes.LINK &&
157
+ column.tableId &&
158
+ tableIds.includes(column.tableId));
157
159
  }
158
160
  /**
159
161
  * Similar function to the shouldCopyRelationship function, but instead this looks for options and boolean
@@ -164,8 +166,9 @@ function shouldCopyRelationship(column, tableIds) {
164
166
  * @param fetchedColumn The fetched column to check for the type in the external database.
165
167
  */
166
168
  function shouldCopySpecialColumn(column, fetchedColumn) {
167
- return column.type === constants_1.FieldTypes.OPTIONS ||
168
- ((!fetchedColumn || fetchedColumn.type === constants_1.FieldTypes.NUMBER) && column.type === constants_1.FieldTypes.BOOLEAN);
169
+ return (column.type === constants_1.FieldTypes.OPTIONS ||
170
+ ((!fetchedColumn || fetchedColumn.type === constants_1.FieldTypes.NUMBER) &&
171
+ column.type === constants_1.FieldTypes.BOOLEAN));
169
172
  }
170
173
  /**
171
174
  * Looks for columns which need to be copied over into the new table definitions, like relationships
@@ -49,15 +49,6 @@ module.exports = (ctx, next) => __awaiter(void 0, void 0, void 0, function* () {
49
49
  !isWebhookEndpoint(ctx) &&
50
50
  (!ctx.user || !ctx.user.builder || !ctx.user.builder.global)) {
51
51
  clearCookie(ctx, Cookies.CurrentApp);
52
- // have to set the return url on the server side as client side is not available
53
- setCookie(ctx, ctx.url, Cookies.RETURN_URL, {
54
- // don't sign so the browser can easily read
55
- sign: false,
56
- // use the request domain to match how ui handles the return url cookie.
57
- // it's important we don't use the shared domain here as the builder
58
- // can't delete from it without awareness of the domain.
59
- requestDomain: true,
60
- });
61
52
  return ctx.redirect("/");
62
53
  }
63
54
  let appId, roleId = BUILTIN_ROLE_IDS.PUBLIC;
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.46-alpha.3",
4
+ "version": "1.0.46-alpha.4",
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.46-alpha.3",
74
- "@budibase/client": "^1.0.46-alpha.3",
75
- "@budibase/string-templates": "^1.0.46-alpha.3",
73
+ "@budibase/backend-core": "^1.0.46-alpha.4",
74
+ "@budibase/client": "^1.0.46-alpha.4",
75
+ "@budibase/string-templates": "^1.0.46-alpha.4",
76
76
  "@bull-board/api": "^3.7.0",
77
77
  "@bull-board/koa": "^3.7.0",
78
78
  "@elastic/elasticsearch": "7.10.0",
@@ -110,7 +110,7 @@
110
110
  "mongodb": "3.6.3",
111
111
  "mssql": "6.2.3",
112
112
  "mysql2": "^2.3.1",
113
- "node-fetch": "2.6.0",
113
+ "node-fetch": "2.6.7",
114
114
  "open": "^8.4.0",
115
115
  "pg": "8.5.1",
116
116
  "pino-pretty": "4.0.0",
@@ -21,6 +21,7 @@ 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";
@@ -83,7 +84,8 @@ class TestConfiguration {
83
84
  return Object.assign({ _rev: resp._rev }, user);
84
85
  });
85
86
  }
86
- init(appName = "test_application") {
87
+ // use a new id as the name to avoid name collisions
88
+ init(appName = newid()) {
87
89
  return __awaiter(this, void 0, void 0, function* () {
88
90
  yield this.globalUser();
89
91
  return this.createApp(appName);
@@ -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];