@budibase/server 1.0.46-alpha.3 → 1.0.46-alpha.7
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.
- package/builder/assets/{index.6eae2fa0.js → index.af9e71d8.js} +243 -243
- package/builder/assets/{index.0df4f7ab.css → index.dd9e386f.css} +1 -1
- package/builder/assets/{vendor.10e2ad1b.js → vendor.3bd2f661.js} +1 -1
- package/builder/index.html +3 -3
- package/coverage/clover.xml +542 -551
- package/coverage/coverage-final.json +21 -23
- package/coverage/lcov-report/api/controllers/analytics.js.html +1 -1
- package/coverage/lcov-report/api/controllers/apikeys.js.html +1 -1
- package/coverage/lcov-report/api/controllers/application.js.html +179 -95
- package/coverage/lcov-report/api/controllers/auth.js.html +1 -1
- package/coverage/lcov-report/api/controllers/automation.js.html +1 -1
- package/coverage/lcov-report/api/controllers/backup.js.html +1 -1
- package/coverage/lcov-report/api/controllers/cloud.js.html +1 -1
- package/coverage/lcov-report/api/controllers/component.js.html +4 -4
- package/coverage/lcov-report/api/controllers/datasource.js.html +58 -22
- package/coverage/lcov-report/api/controllers/dev.js.html +1 -1
- package/coverage/lcov-report/api/controllers/index.html +27 -42
- package/coverage/lcov-report/api/controllers/integration.js.html +1 -1
- package/coverage/lcov-report/api/controllers/layout.js.html +1 -1
- package/coverage/lcov-report/api/controllers/metadata.js.html +1 -1
- package/coverage/lcov-report/api/controllers/permission.js.html +1 -1
- package/coverage/lcov-report/api/controllers/query/index.html +15 -15
- package/coverage/lcov-report/api/controllers/query/index.js.html +44 -11
- package/coverage/lcov-report/api/controllers/query/validation.js.html +1 -1
- package/coverage/lcov-report/api/controllers/role.js.html +1 -1
- package/coverage/lcov-report/api/controllers/routing.js.html +1 -1
- package/coverage/lcov-report/api/controllers/row/external.js.html +1 -1
- package/coverage/lcov-report/api/controllers/row/index.html +5 -5
- package/coverage/lcov-report/api/controllers/row/index.js.html +1 -1
- package/coverage/lcov-report/api/controllers/row/internal.js.html +1 -1
- package/coverage/lcov-report/api/controllers/row/internalSearch.js.html +1 -1
- package/coverage/lcov-report/api/controllers/row/utils.js.html +5 -14
- package/coverage/lcov-report/api/controllers/screen.js.html +1 -1
- package/coverage/lcov-report/api/controllers/script.js.html +1 -1
- package/coverage/lcov-report/api/controllers/table/external.js.html +1 -1
- package/coverage/lcov-report/api/controllers/table/index.html +1 -1
- package/coverage/lcov-report/api/controllers/table/index.js.html +1 -1
- package/coverage/lcov-report/api/controllers/table/internal.js.html +1 -1
- package/coverage/lcov-report/api/controllers/table/utils.js.html +1 -1
- package/coverage/lcov-report/api/controllers/templates.js.html +1 -1
- package/coverage/lcov-report/api/controllers/user.js.html +1 -1
- package/coverage/lcov-report/api/controllers/view/exporters.js.html +1 -1
- package/coverage/lcov-report/api/controllers/view/index.html +1 -1
- package/coverage/lcov-report/api/controllers/view/index.js.html +1 -1
- package/coverage/lcov-report/api/controllers/view/utils.js.html +1 -1
- package/coverage/lcov-report/api/controllers/view/viewBuilder.js.html +1 -1
- package/coverage/lcov-report/api/controllers/webhook.js.html +1 -1
- package/coverage/lcov-report/api/index.html +1 -1
- package/coverage/lcov-report/api/index.js.html +10 -10
- package/coverage/lcov-report/api/routes/analytics.js.html +1 -1
- package/coverage/lcov-report/api/routes/apikeys.js.html +1 -1
- package/coverage/lcov-report/api/routes/application.js.html +1 -1
- package/coverage/lcov-report/api/routes/auth.js.html +1 -1
- package/coverage/lcov-report/api/routes/automation.js.html +1 -1
- package/coverage/lcov-report/api/routes/backup.js.html +1 -1
- package/coverage/lcov-report/api/routes/cloud.js.html +1 -1
- package/coverage/lcov-report/api/routes/component.js.html +1 -1
- package/coverage/lcov-report/api/routes/datasource.js.html +1 -1
- package/coverage/lcov-report/api/routes/deploy.js.html +1 -1
- package/coverage/lcov-report/api/routes/dev.js.html +1 -1
- package/coverage/lcov-report/api/routes/index.html +7 -22
- package/coverage/lcov-report/api/routes/index.js.html +4 -10
- package/coverage/lcov-report/api/routes/integration.js.html +1 -1
- package/coverage/lcov-report/api/routes/layout.js.html +1 -1
- package/coverage/lcov-report/api/routes/metadata.js.html +1 -1
- package/coverage/lcov-report/api/routes/permission.js.html +1 -1
- package/coverage/lcov-report/api/routes/query.js.html +1 -1
- package/coverage/lcov-report/api/routes/role.js.html +1 -1
- package/coverage/lcov-report/api/routes/routing.js.html +1 -1
- package/coverage/lcov-report/api/routes/row.js.html +1 -1
- package/coverage/lcov-report/api/routes/screen.js.html +1 -1
- package/coverage/lcov-report/api/routes/script.js.html +1 -1
- package/coverage/lcov-report/api/routes/static.js.html +17 -2
- package/coverage/lcov-report/api/routes/table.js.html +1 -1
- package/coverage/lcov-report/api/routes/templates.js.html +1 -1
- package/coverage/lcov-report/api/routes/user.js.html +1 -1
- package/coverage/lcov-report/api/routes/view.js.html +1 -1
- package/coverage/lcov-report/api/routes/webhook.js.html +1 -1
- package/coverage/lcov-report/automations/actions.js.html +1 -1
- package/coverage/lcov-report/automations/automationUtils.js.html +1 -1
- package/coverage/lcov-report/automations/bullboard.js.html +1 -1
- package/coverage/lcov-report/automations/index.html +1 -1
- package/coverage/lcov-report/automations/index.js.html +1 -1
- package/coverage/lcov-report/automations/steps/bash.js.html +1 -1
- package/coverage/lcov-report/automations/steps/createRow.js.html +1 -1
- package/coverage/lcov-report/automations/steps/delay.js.html +1 -1
- package/coverage/lcov-report/automations/steps/deleteRow.js.html +1 -1
- package/coverage/lcov-report/automations/steps/discord.js.html +1 -1
- package/coverage/lcov-report/automations/steps/executeQuery.js.html +1 -1
- package/coverage/lcov-report/automations/steps/executeScript.js.html +1 -1
- package/coverage/lcov-report/automations/steps/filter.js.html +1 -1
- package/coverage/lcov-report/automations/steps/index.html +1 -1
- package/coverage/lcov-report/automations/steps/integromat.js.html +1 -1
- package/coverage/lcov-report/automations/steps/outgoingWebhook.js.html +1 -1
- package/coverage/lcov-report/automations/steps/queryRows.js.html +1 -1
- package/coverage/lcov-report/automations/steps/sendSmtpEmail.js.html +1 -1
- package/coverage/lcov-report/automations/steps/serverLog.js.html +1 -1
- package/coverage/lcov-report/automations/steps/slack.js.html +1 -1
- package/coverage/lcov-report/automations/steps/updateRow.js.html +1 -1
- package/coverage/lcov-report/automations/steps/utils.js.html +1 -1
- package/coverage/lcov-report/automations/steps/zapier.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/app.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/cron.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/index.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/index.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/rowDeleted.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/rowSaved.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/rowUpdated.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/webhook.js.html +1 -1
- package/coverage/lcov-report/automations/triggers.js.html +1 -1
- package/coverage/lcov-report/automations/utils.js.html +5 -5
- package/coverage/lcov-report/constants/index.html +5 -5
- package/coverage/lcov-report/constants/index.js.html +16 -4
- package/coverage/lcov-report/constants/layouts.js.html +1 -1
- package/coverage/lcov-report/constants/screens.js.html +1 -1
- package/coverage/lcov-report/db/client.js.html +1 -1
- package/coverage/lcov-report/db/inMemoryView.js.html +1 -1
- package/coverage/lcov-report/db/index.html +1 -1
- package/coverage/lcov-report/db/index.js.html +1 -1
- package/coverage/lcov-report/db/linkedRows/LinkController.js.html +1 -1
- package/coverage/lcov-report/db/linkedRows/index.html +1 -1
- package/coverage/lcov-report/db/linkedRows/index.js.html +1 -1
- package/coverage/lcov-report/db/linkedRows/linkUtils.js.html +1 -1
- package/coverage/lcov-report/db/newid.js.html +2 -2
- package/coverage/lcov-report/db/utils.js.html +17 -17
- package/coverage/lcov-report/events/AutomationEmitter.js.html +1 -1
- package/coverage/lcov-report/events/index.html +1 -1
- package/coverage/lcov-report/events/index.js.html +1 -1
- package/coverage/lcov-report/events/utils.js.html +1 -1
- package/coverage/lcov-report/index.html +58 -58
- package/coverage/lcov-report/integrations/tests/TestConfiguration.js.html +1 -1
- package/coverage/lcov-report/integrations/tests/index.html +1 -1
- package/coverage/lcov-report/middleware/appInfo.js.html +1 -1
- package/coverage/lcov-report/middleware/authorized.js.html +11 -11
- package/coverage/lcov-report/middleware/builder.js.html +8 -8
- package/coverage/lcov-report/middleware/currentapp.js.html +34 -61
- package/coverage/lcov-report/middleware/index.html +10 -10
- package/coverage/lcov-report/middleware/joi-validator.js.html +1 -1
- package/coverage/lcov-report/middleware/resourceId.js.html +1 -1
- package/coverage/lcov-report/middleware/selfhost.js.html +1 -1
- package/coverage/lcov-report/middleware/usageQuota.js.html +1 -1
- package/coverage/lcov-report/middleware/utils.js.html +2 -2
- package/coverage/lcov-report/migrations/usageQuotas/index.html +1 -1
- package/coverage/lcov-report/migrations/usageQuotas/index.js.html +1 -1
- package/coverage/lcov-report/migrations/usageQuotas/syncApps.js.html +1 -1
- package/coverage/lcov-report/migrations/usageQuotas/syncRows.js.html +1 -1
- package/coverage/lcov-report/threads/automation.js.html +1 -1
- package/coverage/lcov-report/threads/index.html +15 -15
- package/coverage/lcov-report/threads/index.js.html +1 -1
- package/coverage/lcov-report/threads/query.js.html +23 -8
- package/coverage/lcov-report/threads/utils.js.html +1 -1
- package/coverage/lcov-report/utilities/bcrypt.js.html +1 -1
- package/coverage/lcov-report/utilities/budibaseDir.js.html +1 -1
- package/coverage/lcov-report/utilities/centralPath.js.html +1 -1
- package/coverage/lcov-report/utilities/csvParser.js.html +1 -1
- package/coverage/lcov-report/utilities/global.js.html +13 -13
- package/coverage/lcov-report/utilities/index.html +19 -19
- package/coverage/lcov-report/utilities/index.js.html +4 -4
- package/coverage/lcov-report/utilities/queue/inMemoryQueue.js.html +2 -2
- package/coverage/lcov-report/utilities/queue/index.html +1 -1
- package/coverage/lcov-report/utilities/routing/index.html +1 -1
- package/coverage/lcov-report/utilities/routing/index.js.html +1 -1
- package/coverage/lcov-report/utilities/rowProcessor/index.html +1 -1
- package/coverage/lcov-report/utilities/rowProcessor/index.js.html +1 -1
- package/coverage/lcov-report/utilities/rowProcessor/utils.js.html +1 -1
- package/coverage/lcov-report/utilities/scriptRunner.js.html +1 -1
- package/coverage/lcov-report/utilities/security.js.html +1 -1
- package/coverage/lcov-report/utilities/statusCodes.js.html +1 -1
- package/coverage/lcov-report/utilities/usageQuota/index.html +1 -1
- package/coverage/lcov-report/utilities/usageQuota/index.js.html +1 -1
- package/coverage/lcov-report/utilities/usageQuota/rows.js.html +1 -1
- package/coverage/lcov-report/utilities/usageQuota/usageQuoteReset.js.html +1 -1
- package/coverage/lcov-report/utilities/users.js.html +1 -1
- package/coverage/lcov-report/utilities/workerRequests.js.html +24 -93
- package/coverage/lcov.info +937 -935
- package/dist/api/controllers/application.js +49 -20
- package/dist/api/controllers/datasource.js +11 -0
- package/dist/api/controllers/query/index.js +11 -3
- package/dist/api/controllers/row/utils.js +1 -2
- package/dist/api/controllers/static/index.js +59 -10
- package/dist/api/routes/index.js +0 -2
- package/dist/api/routes/static.js +2 -1
- package/dist/constants/index.js +3 -0
- package/dist/definitions/datasource.js +1 -0
- package/dist/integrations/googlesheets.js +340 -0
- package/dist/integrations/index.js +3 -0
- package/dist/integrations/utils.js +6 -3
- package/dist/middleware/currentapp.js +0 -9
- package/dist/package.json +8 -5
- package/dist/tests/utilities/TestConfiguration.js +3 -1
- package/dist/threads/query.js +4 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utilities/workerRequests.js +0 -20
- package/nodemon.json +1 -1
- package/package.json +9 -6
- package/src/api/controllers/application.js +52 -24
- package/src/api/controllers/datasource.js +12 -0
- package/src/api/controllers/query/index.js +14 -3
- package/src/api/controllers/row/utils.js +1 -4
- package/src/api/controllers/static/index.js +63 -10
- package/src/api/routes/index.js +0 -2
- package/src/api/routes/static.js +5 -0
- package/src/api/routes/tests/application.spec.js +2 -2
- package/src/api/routes/tests/static.spec.js +98 -0
- package/src/constants/index.js +4 -0
- package/src/definitions/datasource.ts +3 -0
- package/src/integrations/googlesheets.ts +353 -0
- package/src/integrations/index.ts +3 -0
- package/src/integrations/utils.ts +18 -5
- package/src/middleware/currentapp.js +0 -9
- package/src/migrations/tests/usageQuotas/syncRows.spec.js +1 -1
- package/src/tests/utilities/TestConfiguration.js +3 -1
- package/src/threads/query.js +5 -0
- package/src/utilities/workerRequests.js +0 -23
- package/coverage/lcov-report/api/controllers/hosting.js.html +0 -146
- package/coverage/lcov-report/api/routes/hosting.js.html +0 -119
- package/dist/api/controllers/hosting.js +0 -30
- package/dist/api/routes/hosting.js +0 -11
- package/src/api/controllers/hosting.js +0 -22
- package/src/api/routes/hosting.js +0 -13
- 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 {
|
|
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,44 @@ function getUserRoleId(ctx) {
|
|
|
49
49
|
? BUILTIN_ROLE_IDS.PUBLIC
|
|
50
50
|
: ctx.user.role._id;
|
|
51
51
|
}
|
|
52
|
-
function
|
|
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
60
|
else if (ctx.request.body.name) {
|
|
61
|
+
// otherwise use the name
|
|
59
62
|
url = encodeURI(`${ctx.request.body.name}`);
|
|
60
63
|
}
|
|
61
64
|
if (url) {
|
|
62
65
|
url = `/${url.replace(URL_REGEX_SLASH, "")}`.toLowerCase();
|
|
63
66
|
}
|
|
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
|
-
}
|
|
74
67
|
return url;
|
|
75
68
|
});
|
|
76
69
|
}
|
|
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
|
+
};
|
|
77
90
|
function createInstance(template) {
|
|
78
91
|
return __awaiter(this, void 0, void 0, function* () {
|
|
79
92
|
const tenantId = isMultiTenant() ? getTenantId() : null;
|
|
@@ -167,6 +180,11 @@ exports.fetchAppPackage = (ctx) => __awaiter(void 0, void 0, void 0, function* (
|
|
|
167
180
|
};
|
|
168
181
|
});
|
|
169
182
|
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);
|
|
170
188
|
const { useTemplate, templateKey, templateString } = ctx.request.body;
|
|
171
189
|
const instanceConfig = {
|
|
172
190
|
useTemplate,
|
|
@@ -178,7 +196,6 @@ exports.create = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
178
196
|
}
|
|
179
197
|
const instance = yield createInstance(instanceConfig);
|
|
180
198
|
const appId = instance._id;
|
|
181
|
-
const url = yield getAppUrlIfNotInUse(ctx);
|
|
182
199
|
const db = new CouchDB(appId);
|
|
183
200
|
let _rev;
|
|
184
201
|
try {
|
|
@@ -196,7 +213,7 @@ exports.create = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
196
213
|
type: "app",
|
|
197
214
|
version: packageJson.version,
|
|
198
215
|
componentLibraries: ["@budibase/standard-components"],
|
|
199
|
-
name:
|
|
216
|
+
name: name,
|
|
200
217
|
url: url,
|
|
201
218
|
template: ctx.request.body.template,
|
|
202
219
|
instance: instance,
|
|
@@ -219,8 +236,21 @@ exports.create = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
219
236
|
ctx.status = 200;
|
|
220
237
|
ctx.body = newApplication;
|
|
221
238
|
});
|
|
239
|
+
// This endpoint currently operates as a PATCH rather than a PUT
|
|
240
|
+
// Thus name and url fields are handled only if present
|
|
222
241
|
exports.update = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
223
|
-
const
|
|
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);
|
|
224
254
|
ctx.status = 200;
|
|
225
255
|
ctx.body = data;
|
|
226
256
|
});
|
|
@@ -239,7 +269,7 @@ exports.updateClient = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
239
269
|
version: packageJson.version,
|
|
240
270
|
revertableVersion: currentVersion,
|
|
241
271
|
};
|
|
242
|
-
const data = yield updateAppPackage(
|
|
272
|
+
const data = yield updateAppPackage(appPackageUpdates, ctx.params.appId);
|
|
243
273
|
ctx.status = 200;
|
|
244
274
|
ctx.body = data;
|
|
245
275
|
});
|
|
@@ -259,7 +289,7 @@ exports.revertClient = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
259
289
|
version: application.revertableVersion,
|
|
260
290
|
revertableVersion: null,
|
|
261
291
|
};
|
|
262
|
-
const data = yield updateAppPackage(
|
|
292
|
+
const data = yield updateAppPackage(appPackageUpdates, ctx.params.appId);
|
|
263
293
|
ctx.status = 200;
|
|
264
294
|
ctx.body = data;
|
|
265
295
|
});
|
|
@@ -326,11 +356,10 @@ exports.sync = (ctx, next) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
326
356
|
};
|
|
327
357
|
}
|
|
328
358
|
});
|
|
329
|
-
const updateAppPackage = (
|
|
330
|
-
const url = yield getAppUrlIfNotInUse(ctx);
|
|
359
|
+
const updateAppPackage = (appPackage, appId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
331
360
|
const db = new CouchDB(appId);
|
|
332
361
|
const application = yield db.get(DocumentTypes.APP_METADATA);
|
|
333
|
-
const newAppPackage = Object.assign(Object.assign(
|
|
362
|
+
const newAppPackage = Object.assign(Object.assign({}, application), appPackage);
|
|
334
363
|
if (appPackage._rev !== application._rev) {
|
|
335
364
|
newAppPackage._rev = application._rev;
|
|
336
365
|
}
|
|
@@ -28,6 +28,12 @@ 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
|
+
}
|
|
31
37
|
ctx.body = [bbInternalDb, ...datasources];
|
|
32
38
|
});
|
|
33
39
|
};
|
|
@@ -78,8 +84,13 @@ exports.update = function (ctx) {
|
|
|
78
84
|
const db = new CouchDB(ctx.appId);
|
|
79
85
|
const datasourceId = ctx.params.datasourceId;
|
|
80
86
|
let datasource = yield db.get(datasourceId);
|
|
87
|
+
const auth = datasource.config.auth;
|
|
81
88
|
yield invalidateVariables(datasource, ctx.request.body);
|
|
82
89
|
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
|
+
}
|
|
83
94
|
const response = yield db.put(datasource);
|
|
84
95
|
datasource._rev = response.rev;
|
|
85
96
|
// Drain connection pools when configuration is changed
|
|
@@ -130,6 +130,15 @@ function execute(ctx, opts = { rowsOnly: false }) {
|
|
|
130
130
|
const db = new CouchDB(ctx.appId);
|
|
131
131
|
const query = yield db.get(ctx.params.queryId);
|
|
132
132
|
const datasource = yield db.get(query.datasourceId);
|
|
133
|
+
const enrichedParameters = ctx.request.body.parameters || {};
|
|
134
|
+
// make sure parameters are fully enriched with defaults
|
|
135
|
+
if (query && query.parameters) {
|
|
136
|
+
for (let parameter of query.parameters) {
|
|
137
|
+
if (!enrichedParameters[parameter.name]) {
|
|
138
|
+
enrichedParameters[parameter.name] = parameter.default;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
133
142
|
// call the relevant CRUD method on the integration class
|
|
134
143
|
try {
|
|
135
144
|
const { rows, pagination, extra } = yield Runner.run({
|
|
@@ -138,7 +147,7 @@ function execute(ctx, opts = { rowsOnly: false }) {
|
|
|
138
147
|
queryVerb: query.queryVerb,
|
|
139
148
|
fields: query.fields,
|
|
140
149
|
pagination: ctx.request.body.pagination,
|
|
141
|
-
parameters:
|
|
150
|
+
parameters: enrichedParameters,
|
|
142
151
|
transformer: query.transformer,
|
|
143
152
|
queryId: ctx.params.queryId,
|
|
144
153
|
});
|
|
@@ -170,8 +179,7 @@ const removeDynamicVariables = (db, queryId) => __awaiter(void 0, void 0, void 0
|
|
|
170
179
|
const dynamicVariables = datasource.config.dynamicVariables;
|
|
171
180
|
if (dynamicVariables) {
|
|
172
181
|
// delete dynamic variables from the datasource
|
|
173
|
-
|
|
174
|
-
datasource.config.dynamicVariables = newVariables;
|
|
182
|
+
datasource.config.dynamicVariables = dynamicVariables.filter(dv => dv.queryId !== queryId);
|
|
175
183
|
yield db.put(datasource);
|
|
176
184
|
// invalidate the deleted variables
|
|
177
185
|
const variablesToDelete = dynamicVariables.filter(dv => dv.queryId === queryId);
|
|
@@ -59,8 +59,7 @@ exports.validate = ({ appId, tableId, row, table }) => __awaiter(void 0, void 0,
|
|
|
59
59
|
const constraints = cloneDeep(table.schema[fieldName].constraints);
|
|
60
60
|
const type = table.schema[fieldName].type;
|
|
61
61
|
// special case for options, need to always allow unselected (null)
|
|
62
|
-
if (
|
|
63
|
-
constraints.inclusion) {
|
|
62
|
+
if (type === FieldTypes.OPTIONS && constraints.inclusion) {
|
|
64
63
|
constraints.inclusion.push(null);
|
|
65
64
|
}
|
|
66
65
|
let res;
|
|
@@ -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 {
|
|
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");
|
|
@@ -22,6 +22,8 @@ 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";
|
|
25
27
|
function prepareUpload({ s3Key, bucket, metadata, file }) {
|
|
26
28
|
return __awaiter(this, void 0, void 0, function* () {
|
|
27
29
|
const response = yield upload({
|
|
@@ -41,13 +43,15 @@ function prepareUpload({ s3Key, bucket, metadata, file }) {
|
|
|
41
43
|
};
|
|
42
44
|
});
|
|
43
45
|
}
|
|
44
|
-
function
|
|
46
|
+
function getAppIdFromUrl(ctx) {
|
|
45
47
|
return __awaiter(this, void 0, void 0, function* () {
|
|
46
|
-
// the "appId" component of the URL
|
|
48
|
+
// the "appId" component of the URL can be the id or the custom url
|
|
47
49
|
let possibleAppUrl = `/${encodeURI(ctx.params.appId).toLowerCase()}`;
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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;
|
|
51
55
|
}
|
|
52
56
|
else {
|
|
53
57
|
return ctx.params.appId;
|
|
@@ -80,10 +84,7 @@ exports.uploadFile = function (ctx) {
|
|
|
80
84
|
};
|
|
81
85
|
exports.serveApp = function (ctx) {
|
|
82
86
|
return __awaiter(this, void 0, void 0, function* () {
|
|
83
|
-
let appId = ctx
|
|
84
|
-
if (env.SELF_HOSTED) {
|
|
85
|
-
appId = yield checkForSelfHostedURL(ctx);
|
|
86
|
-
}
|
|
87
|
+
let appId = yield getAppIdFromUrl(ctx);
|
|
87
88
|
const App = require("./templates/BudibaseApp.svelte").default;
|
|
88
89
|
const db = new CouchDB(appId, { skip_setup: true });
|
|
89
90
|
const appInfo = yield db.get(DocumentTypes.APP_METADATA);
|
|
@@ -109,3 +110,51 @@ exports.serveClientLibrary = function (ctx) {
|
|
|
109
110
|
});
|
|
110
111
|
});
|
|
111
112
|
};
|
|
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
|
+
};
|
package/dist/api/routes/index.js
CHANGED
|
@@ -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,
|
|
@@ -43,5 +43,6 @@ 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)
|
|
46
|
+
.get("/:appId/:path*", controller.serveApp)
|
|
47
|
+
.post("/api/attachments/:datasourceId/url", authorized(PermissionTypes.TABLE, PermissionLevels.READ), controller.getSignedUploadURL);
|
|
47
48
|
module.exports = router;
|
package/dist/constants/index.js
CHANGED
|
@@ -49,6 +49,7 @@ var SourceNames;
|
|
|
49
49
|
SourceNames["ARANGODB"] = "ARANGODB";
|
|
50
50
|
SourceNames["REST"] = "REST";
|
|
51
51
|
SourceNames["ORACLE"] = "ORACLE";
|
|
52
|
+
SourceNames["GOOGLE_SHEETS"] = "GOOGLE_SHEETS";
|
|
52
53
|
})(SourceNames = exports.SourceNames || (exports.SourceNames = {}));
|
|
53
54
|
var IncludeRelationships;
|
|
54
55
|
(function (IncludeRelationships) {
|