@budibase/server 1.0.27-alpha.1 → 1.0.27-alpha.13
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/__mocks__/node-fetch.ts +18 -0
- package/builder/assets/{index.4a13c4cb.css → index.176f00e0.css} +1 -1
- package/builder/assets/index.5776ef20.js +1348 -0
- package/builder/index.html +2 -2
- package/coverage/clover.xml +1193 -1027
- package/coverage/coverage-final.json +72 -72
- package/coverage/lcov-report/api/controllers/analytics.js.html +1 -1
- package/coverage/lcov-report/api/controllers/apikeys.js.html +3 -3
- package/coverage/lcov-report/api/controllers/application.js.html +73 -64
- package/coverage/lcov-report/api/controllers/auth.js.html +2 -2
- 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 +13 -4
- package/coverage/lcov-report/api/controllers/component.js.html +4 -4
- package/coverage/lcov-report/api/controllers/datasource.js.html +150 -48
- package/coverage/lcov-report/api/controllers/dev.js.html +3 -3
- package/coverage/lcov-report/api/controllers/hosting.js.html +3 -3
- package/coverage/lcov-report/api/controllers/index.html +20 -20
- 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 +3 -3
- package/coverage/lcov-report/api/controllers/query/index.html +21 -21
- package/coverage/lcov-report/api/controllers/query/index.js.html +101 -122
- package/coverage/lcov-report/api/controllers/query/validation.js.html +6 -3
- package/coverage/lcov-report/api/controllers/role.js.html +2 -2
- package/coverage/lcov-report/api/controllers/routing.js.html +2 -2
- package/coverage/lcov-report/api/controllers/row/external.js.html +1 -1
- package/coverage/lcov-report/api/controllers/row/index.html +22 -22
- package/coverage/lcov-report/api/controllers/row/index.js.html +1 -1
- package/coverage/lcov-report/api/controllers/row/internal.js.html +38 -11
- package/coverage/lcov-report/api/controllers/row/internalSearch.js.html +8 -5
- package/coverage/lcov-report/api/controllers/row/utils.js.html +29 -20
- package/coverage/lcov-report/api/controllers/screen.js.html +2 -2
- 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 +14 -5
- 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 +2 -2
- package/coverage/lcov-report/api/index.html +1 -1
- package/coverage/lcov-report/api/index.js.html +6 -6
- package/coverage/lcov-report/api/routes/analytics.js.html +1 -1
- package/coverage/lcov-report/api/routes/apikeys.js.html +2 -2
- package/coverage/lcov-report/api/routes/application.js.html +2 -2
- package/coverage/lcov-report/api/routes/auth.js.html +1 -1
- package/coverage/lcov-report/api/routes/automation.js.html +2 -2
- package/coverage/lcov-report/api/routes/backup.js.html +2 -2
- package/coverage/lcov-report/api/routes/cloud.js.html +2 -2
- package/coverage/lcov-report/api/routes/component.js.html +2 -2
- package/coverage/lcov-report/api/routes/datasource.js.html +2 -2
- package/coverage/lcov-report/api/routes/deploy.js.html +2 -2
- package/coverage/lcov-report/api/routes/dev.js.html +2 -2
- package/coverage/lcov-report/api/routes/hosting.js.html +2 -2
- package/coverage/lcov-report/api/routes/index.html +1 -1
- package/coverage/lcov-report/api/routes/index.js.html +1 -1
- package/coverage/lcov-report/api/routes/integration.js.html +2 -2
- package/coverage/lcov-report/api/routes/layout.js.html +2 -2
- package/coverage/lcov-report/api/routes/metadata.js.html +2 -2
- package/coverage/lcov-report/api/routes/permission.js.html +12 -3
- package/coverage/lcov-report/api/routes/query.js.html +25 -4
- package/coverage/lcov-report/api/routes/role.js.html +2 -2
- package/coverage/lcov-report/api/routes/routing.js.html +2 -2
- package/coverage/lcov-report/api/routes/row.js.html +2 -2
- package/coverage/lcov-report/api/routes/screen.js.html +2 -2
- package/coverage/lcov-report/api/routes/script.js.html +2 -2
- package/coverage/lcov-report/api/routes/static.js.html +2 -2
- package/coverage/lcov-report/api/routes/table.js.html +2 -2
- package/coverage/lcov-report/api/routes/templates.js.html +2 -2
- package/coverage/lcov-report/api/routes/user.js.html +2 -2
- package/coverage/lcov-report/api/routes/view.js.html +2 -2
- package/coverage/lcov-report/api/routes/webhook.js.html +2 -2
- 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 +2 -2
- 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 +32 -8
- 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 +11 -11
- 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 +6 -6
- package/coverage/lcov-report/constants/index.html +1 -1
- package/coverage/lcov-report/constants/index.js.html +4 -4
- package/coverage/lcov-report/constants/layouts.js.html +1 -1
- package/coverage/lcov-report/constants/screens.js.html +2 -2
- package/coverage/lcov-report/db/client.js.html +2 -2
- 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 +19 -19
- 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 +64 -64
- 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 +12 -12
- package/coverage/lcov-report/middleware/builder.js.html +10 -10
- package/coverage/lcov-report/middleware/currentapp.js.html +48 -36
- package/coverage/lcov-report/middleware/index.html +1 -1
- package/coverage/lcov-report/middleware/joi-validator.js.html +9 -9
- package/coverage/lcov-report/middleware/resourceId.js.html +18 -18
- package/coverage/lcov-report/middleware/selfhost.js.html +1 -1
- package/coverage/lcov-report/middleware/usageQuota.js.html +2 -2
- package/coverage/lcov-report/middleware/utils.js.html +2 -2
- package/coverage/lcov-report/threads/automation.js.html +3 -3
- package/coverage/lcov-report/threads/index.html +31 -31
- package/coverage/lcov-report/threads/index.js.html +12 -12
- package/coverage/lcov-report/threads/query.js.html +369 -93
- package/coverage/lcov-report/threads/utils.js.html +359 -14
- package/coverage/lcov-report/utilities/bcrypt.js.html +1 -1
- package/coverage/lcov-report/utilities/budibaseDir.js.html +2 -2
- 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 +28 -19
- package/coverage/lcov-report/utilities/index.html +1 -1
- package/coverage/lcov-report/utilities/index.js.html +11 -11
- 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 +19 -19
- package/coverage/lcov-report/utilities/rowProcessor/index.js.html +247 -10
- 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 +13 -4
- package/coverage/lcov-report/utilities/statusCodes.js.html +1 -1
- package/coverage/lcov-report/utilities/users.js.html +1 -1
- package/coverage/lcov-report/utilities/workerRequests.js.html +22 -22
- package/coverage/lcov.info +2027 -1725
- package/dist/api/controllers/apikeys.js +2 -2
- package/dist/api/controllers/application.js +4 -4
- package/dist/api/controllers/auth.js +1 -1
- package/dist/api/controllers/cloud.js +2 -2
- package/dist/api/controllers/datasource.js +29 -0
- package/dist/api/controllers/deploy/index.js +2 -2
- package/dist/api/controllers/dev.js +2 -2
- package/dist/api/controllers/hosting.js +2 -2
- package/dist/api/controllers/permission.js +2 -2
- package/dist/api/controllers/query/import/sources/base/index.js +2 -1
- package/dist/api/controllers/query/import/sources/curl.js +11 -5
- package/dist/api/controllers/query/import/sources/openapi2.js +8 -5
- package/dist/api/controllers/query/index.js +45 -47
- package/dist/api/controllers/query/validation.js +2 -1
- package/dist/api/controllers/role.js +1 -1
- package/dist/api/controllers/routing.js +1 -1
- package/dist/api/controllers/row/internal.js +14 -6
- package/dist/api/controllers/row/internalSearch.js +3 -2
- package/dist/api/controllers/row/utils.js +13 -6
- package/dist/api/controllers/screen.js +1 -1
- package/dist/api/controllers/user.js +3 -3
- package/dist/api/controllers/webhook.js +1 -1
- package/dist/api/index.js +1 -1
- package/dist/api/routes/apikeys.js +1 -1
- package/dist/api/routes/application.js +1 -1
- package/dist/api/routes/automation.js +1 -1
- package/dist/api/routes/backup.js +1 -1
- package/dist/api/routes/cloud.js +1 -1
- package/dist/api/routes/component.js +1 -1
- package/dist/api/routes/datasource.js +1 -1
- package/dist/api/routes/deploy.js +1 -1
- package/dist/api/routes/dev.js +1 -1
- package/dist/api/routes/hosting.js +1 -1
- package/dist/api/routes/integration.js +1 -1
- package/dist/api/routes/layout.js +1 -1
- package/dist/api/routes/metadata.js +1 -1
- package/dist/api/routes/permission.js +1 -1
- package/dist/api/routes/query.js +4 -2
- package/dist/api/routes/role.js +1 -1
- package/dist/api/routes/routing.js +1 -1
- package/dist/api/routes/row.js +1 -1
- package/dist/api/routes/screen.js +1 -1
- package/dist/api/routes/script.js +1 -1
- package/dist/api/routes/static.js +1 -1
- package/dist/api/routes/table.js +1 -1
- package/dist/api/routes/templates.js +1 -1
- package/dist/api/routes/tests/utilities/TestFunctions.js +1 -1
- package/dist/api/routes/user.js +1 -1
- package/dist/api/routes/view.js +1 -1
- package/dist/api/routes/webhook.js +1 -1
- package/dist/app.js +1 -1
- package/dist/automations/bullboard.js +1 -1
- package/dist/automations/steps/executeQuery.js +9 -2
- package/dist/automations/utils.js +1 -1
- package/dist/constants/index.js +3 -3
- package/dist/constants/screens.js +1 -1
- package/dist/db/client.js +1 -1
- package/dist/db/utils.js +1 -1
- package/dist/integrations/base/sqlTable.js +1 -1
- package/dist/integrations/rest.js +3 -3
- package/dist/middleware/authorized.js +2 -2
- package/dist/middleware/builder.js +2 -2
- package/dist/middleware/currentapp.js +6 -6
- package/dist/middleware/usageQuota.js +1 -1
- package/dist/package.json +5 -4
- package/dist/tests/utilities/TestConfiguration.js +55 -8
- package/dist/tests/utilities/structures.js +2 -2
- package/dist/threads/automation.js +2 -2
- package/dist/threads/query.js +148 -52
- package/dist/threads/utils.js +106 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utilities/budibaseDir.js +1 -1
- package/dist/utilities/fileSystem/utilities.js +2 -1
- package/dist/utilities/global.js +5 -5
- package/dist/utilities/index.js +1 -1
- package/dist/utilities/redis.js +1 -1
- package/dist/utilities/rowProcessor/index.js +76 -0
- package/dist/utilities/security.js +2 -2
- package/dist/utilities/usageQuota.js +2 -2
- package/dist/utilities/workerRequests.js +3 -3
- package/package.json +6 -5
- package/scripts/replicateApp.js +1 -1
- package/src/api/controllers/apikeys.js +2 -2
- package/src/api/controllers/application.js +7 -4
- package/src/api/controllers/auth.js +1 -1
- package/src/api/controllers/cloud.js +5 -2
- package/src/api/controllers/datasource.js +34 -0
- package/src/api/controllers/deploy/index.js +2 -2
- package/src/api/controllers/dev.js +2 -2
- package/src/api/controllers/hosting.js +2 -2
- package/src/api/controllers/permission.js +2 -2
- package/src/api/controllers/query/import/sources/base/index.ts +3 -1
- package/src/api/controllers/query/import/sources/curl.ts +12 -4
- package/src/api/controllers/query/import/sources/openapi2.ts +9 -5
- package/src/api/controllers/query/import/sources/tests/curl/curl.spec.js +2 -3
- package/src/api/controllers/query/import/sources/tests/openapi2/openapi2.spec.js +6 -7
- package/src/api/controllers/query/import/tests/index.spec.js +0 -6
- package/src/api/controllers/query/index.js +48 -55
- package/src/api/controllers/query/validation.js +2 -1
- package/src/api/controllers/role.js +1 -1
- package/src/api/controllers/routing.js +1 -1
- package/src/api/controllers/row/internal.js +14 -5
- package/src/api/controllers/row/internalSearch.js +3 -2
- package/src/api/controllers/row/utils.js +11 -8
- package/src/api/controllers/screen.js +1 -1
- package/src/api/controllers/user.js +6 -3
- package/src/api/controllers/webhook.js +1 -1
- package/src/api/index.js +1 -1
- package/src/api/routes/apikeys.js +1 -1
- package/src/api/routes/application.js +1 -1
- package/src/api/routes/automation.js +1 -1
- package/src/api/routes/backup.js +1 -1
- package/src/api/routes/cloud.js +1 -1
- package/src/api/routes/component.js +1 -1
- package/src/api/routes/datasource.js +1 -1
- package/src/api/routes/deploy.js +1 -1
- package/src/api/routes/dev.js +1 -1
- package/src/api/routes/hosting.js +1 -1
- package/src/api/routes/integration.js +1 -1
- package/src/api/routes/layout.js +1 -1
- package/src/api/routes/metadata.js +1 -1
- package/src/api/routes/permission.js +4 -1
- package/src/api/routes/query.js +9 -2
- package/src/api/routes/role.js +1 -1
- package/src/api/routes/routing.js +1 -1
- package/src/api/routes/row.js +1 -1
- package/src/api/routes/screen.js +1 -1
- package/src/api/routes/script.js +1 -1
- package/src/api/routes/static.js +1 -1
- package/src/api/routes/table.js +1 -1
- package/src/api/routes/templates.js +1 -1
- package/src/api/routes/tests/datasource.spec.js +45 -0
- package/src/api/routes/tests/permissions.spec.js +1 -1
- package/src/api/routes/tests/query.spec.js +70 -1
- package/src/api/routes/tests/role.spec.js +2 -2
- package/src/api/routes/tests/routing.spec.js +1 -1
- package/src/api/routes/tests/user.spec.js +1 -1
- package/src/api/routes/tests/utilities/TestFunctions.js +1 -1
- package/src/api/routes/user.js +1 -1
- package/src/api/routes/view.js +1 -1
- package/src/api/routes/webhook.js +1 -1
- package/src/app.ts +1 -1
- package/src/automations/bullboard.js +1 -1
- package/src/automations/steps/executeQuery.js +10 -2
- package/src/automations/utils.js +1 -1
- package/src/constants/index.js +3 -3
- package/src/constants/screens.js +1 -1
- package/src/db/client.js +1 -1
- package/src/db/utils.js +1 -1
- package/src/definitions/datasource.ts +10 -0
- package/src/integrations/base/sqlTable.ts +1 -1
- package/src/integrations/rest.ts +6 -3
- package/src/middleware/authorized.js +2 -2
- package/src/middleware/builder.js +2 -2
- package/src/middleware/currentapp.js +11 -7
- package/src/middleware/tests/authorized.spec.js +2 -2
- package/src/middleware/tests/currentapp.spec.js +35 -41
- package/src/middleware/tests/usageQuota.spec.js +1 -1
- package/src/middleware/usageQuota.js +1 -1
- package/src/tests/utilities/TestConfiguration.js +65 -8
- package/src/tests/utilities/structures.js +2 -2
- package/src/threads/automation.js +2 -2
- package/src/threads/query.js +148 -56
- package/src/threads/utils.js +116 -1
- package/src/utilities/budibaseDir.js +1 -1
- package/src/utilities/fileSystem/utilities.js +3 -1
- package/src/utilities/global.js +8 -5
- package/src/utilities/index.js +1 -1
- package/src/utilities/redis.js +1 -1
- package/src/utilities/rowProcessor/index.js +79 -0
- package/src/utilities/security.js +5 -2
- package/src/utilities/usageQuota.js +2 -2
- package/src/utilities/workerRequests.js +3 -3
- package/builder/assets/index.00c4135e.js +0 -1320
|
@@ -8,8 +8,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
-
const { StaticDatabases } = require("@budibase/
|
|
12
|
-
const { getGlobalDB } = require("@budibase/
|
|
11
|
+
const { StaticDatabases } = require("@budibase/backend-core/db");
|
|
12
|
+
const { getGlobalDB } = require("@budibase/backend-core/tenancy");
|
|
13
13
|
const KEYS_DOC = StaticDatabases.GLOBAL.docs.apiKeys;
|
|
14
14
|
function getBuilderMainDoc() {
|
|
15
15
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -14,19 +14,19 @@ const packageJson = require("../../../package.json");
|
|
|
14
14
|
const { createLinkView, createRoutingView, createAllSearchIndex, } = require("../../db/views/staticViews");
|
|
15
15
|
const { getTemplateStream, createApp, deleteApp, } = require("../../utilities/fileSystem");
|
|
16
16
|
const { generateAppID, getLayoutParams, getScreenParams, generateDevAppID, DocumentTypes, AppStatus, } = require("../../db/utils");
|
|
17
|
-
const { BUILTIN_ROLE_IDS, AccessController } = require("@budibase/
|
|
17
|
+
const { BUILTIN_ROLE_IDS, AccessController, } = require("@budibase/backend-core/roles");
|
|
18
18
|
const { BASE_LAYOUTS } = require("../../constants/layouts");
|
|
19
19
|
const { cloneDeep } = require("lodash/fp");
|
|
20
20
|
const { processObject } = require("@budibase/string-templates");
|
|
21
|
-
const { getAllApps, isDevAppID, getDeployedAppID, Replication, } = require("@budibase/
|
|
21
|
+
const { getAllApps, isDevAppID, getDeployedAppID, Replication, } = require("@budibase/backend-core/db");
|
|
22
22
|
const { USERS_TABLE_SCHEMA } = require("../../constants");
|
|
23
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");
|
|
27
|
-
const { getTenantId, isMultiTenant } = require("@budibase/
|
|
27
|
+
const { getTenantId, isMultiTenant } = require("@budibase/backend-core/tenancy");
|
|
28
28
|
const { syncGlobalUsers } = require("./user");
|
|
29
|
-
const { app: appCache } = require("@budibase/
|
|
29
|
+
const { app: appCache } = require("@budibase/backend-core/cache");
|
|
30
30
|
const { cleanupAutomations } = require("../../automations/utils");
|
|
31
31
|
const URL_REGEX_SLASH = /\/|\\/g;
|
|
32
32
|
// utility function, need to do away with this
|
|
@@ -12,7 +12,7 @@ const CouchDB = require("../../db");
|
|
|
12
12
|
const { outputProcessing } = require("../../utilities/rowProcessor");
|
|
13
13
|
const { InternalTables } = require("../../db/utils");
|
|
14
14
|
const { getFullUser } = require("../../utilities/users");
|
|
15
|
-
const { BUILTIN_ROLE_IDS } = require("@budibase/
|
|
15
|
+
const { BUILTIN_ROLE_IDS } = require("@budibase/backend-core/roles");
|
|
16
16
|
exports.fetchSelf = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
17
17
|
const appId = ctx.appId;
|
|
18
18
|
let userId = ctx.user.userId || ctx.user._id;
|
|
@@ -9,11 +9,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
const env = require("../../environment");
|
|
12
|
-
const { getAllApps } = require("@budibase/
|
|
12
|
+
const { getAllApps } = require("@budibase/backend-core/db");
|
|
13
13
|
const CouchDB = require("../../db");
|
|
14
14
|
const { exportDB, sendTempFile, readFileSync, } = require("../../utilities/fileSystem");
|
|
15
15
|
const { stringToReadStream } = require("../../utilities");
|
|
16
|
-
const { getGlobalDBName, getGlobalDB } = require("@budibase/
|
|
16
|
+
const { getGlobalDBName, getGlobalDB, } = require("@budibase/backend-core/tenancy");
|
|
17
17
|
const { create } = require("./application");
|
|
18
18
|
const { getDocParams, DocumentTypes, isDevAppID } = require("../../db/utils");
|
|
19
19
|
function createApp(appName, appImport) {
|
|
@@ -13,6 +13,7 @@ const { generateDatasourceID, getDatasourceParams, getQueryParams, DocumentTypes
|
|
|
13
13
|
const { BuildSchemaErrors, InvalidColumns } = require("../../constants");
|
|
14
14
|
const { integrations } = require("../../integrations");
|
|
15
15
|
const { getDatasourceAndQuery } = require("./row/utils");
|
|
16
|
+
const { invalidateDynamicVariables } = require("../../threads/utils");
|
|
16
17
|
exports.fetch = function (ctx) {
|
|
17
18
|
return __awaiter(this, void 0, void 0, function* () {
|
|
18
19
|
const database = new CouchDB(ctx.appId);
|
|
@@ -45,11 +46,39 @@ exports.buildSchemaFromDb = function (ctx) {
|
|
|
45
46
|
ctx.body = response;
|
|
46
47
|
});
|
|
47
48
|
};
|
|
49
|
+
/**
|
|
50
|
+
* Check for variables that have been updated or removed and invalidate them.
|
|
51
|
+
*/
|
|
52
|
+
const invalidateVariables = (existingDatasource, updatedDatasource) => __awaiter(void 0, void 0, void 0, function* () {
|
|
53
|
+
const existingVariables = existingDatasource.config.dynamicVariables;
|
|
54
|
+
const updatedVariables = updatedDatasource.config.dynamicVariables;
|
|
55
|
+
const toInvalidate = [];
|
|
56
|
+
if (!existingVariables) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
if (!updatedVariables) {
|
|
60
|
+
// invalidate all
|
|
61
|
+
toInvalidate.push(...existingVariables);
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
// invaldate changed / removed
|
|
65
|
+
existingVariables.forEach(existing => {
|
|
66
|
+
const unchanged = updatedVariables.find(updated => existing.name === updated.name &&
|
|
67
|
+
existing.queryId === updated.queryId &&
|
|
68
|
+
existing.value === updated.value);
|
|
69
|
+
if (!unchanged) {
|
|
70
|
+
toInvalidate.push(existing);
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
yield invalidateDynamicVariables(toInvalidate);
|
|
75
|
+
});
|
|
48
76
|
exports.update = function (ctx) {
|
|
49
77
|
return __awaiter(this, void 0, void 0, function* () {
|
|
50
78
|
const db = new CouchDB(ctx.appId);
|
|
51
79
|
const datasourceId = ctx.params.datasourceId;
|
|
52
80
|
let datasource = yield db.get(datasourceId);
|
|
81
|
+
yield invalidateVariables(datasource, ctx.request.body);
|
|
53
82
|
datasource = Object.assign(Object.assign({}, datasource), ctx.request.body);
|
|
54
83
|
const response = yield db.put(datasource);
|
|
55
84
|
datasource._rev = response.rev;
|
|
@@ -10,10 +10,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
const CouchDB = require("../../../db");
|
|
12
12
|
const Deployment = require("./Deployment");
|
|
13
|
-
const { Replication, getDeployedAppID } = require("@budibase/
|
|
13
|
+
const { Replication, getDeployedAppID } = require("@budibase/backend-core/db");
|
|
14
14
|
const { DocumentTypes, getAutomationParams } = require("../../../db/utils");
|
|
15
15
|
const { disableAllCrons, enableCronTrigger, } = require("../../../automations/utils");
|
|
16
|
-
const { app: appCache } = require("@budibase/
|
|
16
|
+
const { app: appCache } = require("@budibase/backend-core/cache");
|
|
17
17
|
// the max time we can wait for an invalidation to complete before considering it failed
|
|
18
18
|
const MAX_PENDING_TIME_MS = 30 * 60000;
|
|
19
19
|
const DeploymentStatus = {
|
|
@@ -14,9 +14,9 @@ const env = require("../../environment");
|
|
|
14
14
|
const { checkSlashesInUrl } = require("../../utilities");
|
|
15
15
|
const { request } = require("../../utilities/workerRequests");
|
|
16
16
|
const { clearLock } = require("../../utilities/redis");
|
|
17
|
-
const { Replication } = require("@budibase/
|
|
17
|
+
const { Replication } = require("@budibase/backend-core/db");
|
|
18
18
|
const { DocumentTypes } = require("../../db/utils");
|
|
19
|
-
const { app: appCache } = require("@budibase/
|
|
19
|
+
const { app: appCache } = require("@budibase/backend-core/cache");
|
|
20
20
|
function redirect(ctx, method, path = "global") {
|
|
21
21
|
return __awaiter(this, void 0, void 0, function* () {
|
|
22
22
|
const { devPath } = ctx.params;
|
|
@@ -10,8 +10,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
const CouchDB = require("../../db");
|
|
12
12
|
const { getDeployedApps } = require("../../utilities/workerRequests");
|
|
13
|
-
const { getScopedConfig } = require("@budibase/
|
|
14
|
-
const { Configs } = require("@budibase/
|
|
13
|
+
const { getScopedConfig } = require("@budibase/backend-core/db");
|
|
14
|
+
const { Configs } = require("@budibase/backend-core/constants");
|
|
15
15
|
const { checkSlashesInUrl } = require("../../utilities");
|
|
16
16
|
exports.fetchUrls = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
17
17
|
const appId = ctx.appId;
|
|
@@ -8,8 +8,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
-
const { getBuiltinPermissions } = require("@budibase/
|
|
12
|
-
const { isBuiltin, getDBRoleID, getExternalRoleID, getBuiltinRoles, } = require("@budibase/
|
|
11
|
+
const { getBuiltinPermissions } = require("@budibase/backend-core/permissions");
|
|
12
|
+
const { isBuiltin, getDBRoleID, getExternalRoleID, getBuiltinRoles, } = require("@budibase/backend-core/roles");
|
|
13
13
|
const { getRoleParams } = require("../../db/utils");
|
|
14
14
|
const CouchDB = require("../../db");
|
|
15
15
|
const { CURRENTLY_SUPPORTED_LEVELS, getBasePermissions, } = require("../../utilities/security");
|
|
@@ -11,12 +11,13 @@ var MethodToVerb;
|
|
|
11
11
|
})(MethodToVerb || (MethodToVerb = {}));
|
|
12
12
|
class ImportSource {
|
|
13
13
|
constructor() {
|
|
14
|
-
this.constructQuery = (datasourceId, name, method, path, queryString, headers = {}, parameters = [], body = undefined) => {
|
|
14
|
+
this.constructQuery = (datasourceId, name, method, path, url, queryString, headers = {}, parameters = [], body = undefined) => {
|
|
15
15
|
const readable = true;
|
|
16
16
|
const queryVerb = this.verbFromMethod(method);
|
|
17
17
|
const transformer = "return data";
|
|
18
18
|
const schema = {};
|
|
19
19
|
path = this.processPath(path);
|
|
20
|
+
path = `${url.origin}/${path}`;
|
|
20
21
|
queryString = this.processQuery(queryString);
|
|
21
22
|
const requestBody = JSON.stringify(body, null, 2);
|
|
22
23
|
const query = {
|
|
@@ -26,8 +26,12 @@ const parseBody = (curl) => {
|
|
|
26
26
|
if (curl.data) {
|
|
27
27
|
const keys = Object.keys(curl.data);
|
|
28
28
|
if (keys.length) {
|
|
29
|
-
|
|
29
|
+
let key = keys[0];
|
|
30
30
|
try {
|
|
31
|
+
// filter out the dollar syntax used by curl for shell support
|
|
32
|
+
if (key.startsWith("$")) {
|
|
33
|
+
key = key.substring(1);
|
|
34
|
+
}
|
|
31
35
|
return JSON.parse(key);
|
|
32
36
|
}
|
|
33
37
|
catch (e) {
|
|
@@ -63,15 +67,17 @@ class Curl extends base_1.ImportSource {
|
|
|
63
67
|
}
|
|
64
68
|
return true;
|
|
65
69
|
});
|
|
70
|
+
this.getUrl = () => {
|
|
71
|
+
return new url_1.URL(this.curl.raw_url);
|
|
72
|
+
};
|
|
66
73
|
this.getInfo = () => __awaiter(this, void 0, void 0, function* () {
|
|
67
|
-
const url =
|
|
74
|
+
const url = this.getUrl();
|
|
68
75
|
return {
|
|
69
|
-
url: url.origin,
|
|
70
76
|
name: url.hostname,
|
|
71
77
|
};
|
|
72
78
|
});
|
|
73
79
|
this.getQueries = (datasourceId) => __awaiter(this, void 0, void 0, function* () {
|
|
74
|
-
const url =
|
|
80
|
+
const url = this.getUrl();
|
|
75
81
|
const name = url.pathname;
|
|
76
82
|
const path = url.pathname;
|
|
77
83
|
const method = this.curl.method;
|
|
@@ -82,7 +88,7 @@ class Curl extends base_1.ImportSource {
|
|
|
82
88
|
if (cookieHeader) {
|
|
83
89
|
headers["Cookie"] = cookieHeader;
|
|
84
90
|
}
|
|
85
|
-
const query = this.constructQuery(datasourceId, name, method, path, queryString, headers, [], requestBody);
|
|
91
|
+
const query = this.constructQuery(datasourceId, name, method, path, url, queryString, headers, [], requestBody);
|
|
86
92
|
return [query];
|
|
87
93
|
});
|
|
88
94
|
}
|
|
@@ -12,6 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.OpenAPI2 = void 0;
|
|
13
13
|
const openapi_types_1 = require("openapi-types");
|
|
14
14
|
const openapi_1 = require("./base/openapi");
|
|
15
|
+
const url_1 = require("url");
|
|
15
16
|
const parameterNotRef = (param) => {
|
|
16
17
|
// all refs are deferenced by parser library
|
|
17
18
|
return true;
|
|
@@ -53,19 +54,21 @@ class OpenAPI2 extends openapi_1.OpenAPISource {
|
|
|
53
54
|
return false;
|
|
54
55
|
}
|
|
55
56
|
});
|
|
56
|
-
this.
|
|
57
|
+
this.getUrl = () => {
|
|
57
58
|
var _a;
|
|
58
59
|
const scheme = ((_a = this.document.schemes) === null || _a === void 0 ? void 0 : _a.includes("https")) ? "https" : "http";
|
|
59
60
|
const basePath = this.document.basePath || "";
|
|
60
61
|
const host = this.document.host || "<host>";
|
|
61
|
-
|
|
62
|
+
return new url_1.URL(`${scheme}://${host}${basePath}`);
|
|
63
|
+
};
|
|
64
|
+
this.getInfo = () => __awaiter(this, void 0, void 0, function* () {
|
|
62
65
|
const name = this.document.info.title || "Swagger Import";
|
|
63
66
|
return {
|
|
64
|
-
|
|
65
|
-
name: name,
|
|
67
|
+
name,
|
|
66
68
|
};
|
|
67
69
|
});
|
|
68
70
|
this.getQueries = (datasourceId) => __awaiter(this, void 0, void 0, function* () {
|
|
71
|
+
const url = this.getUrl();
|
|
69
72
|
const queries = [];
|
|
70
73
|
for (let [path, pathItem] of Object.entries(this.document.paths)) {
|
|
71
74
|
// parameters that apply to every operation in the path
|
|
@@ -128,7 +131,7 @@ class OpenAPI2 extends openapi_1.OpenAPISource {
|
|
|
128
131
|
}
|
|
129
132
|
}
|
|
130
133
|
}
|
|
131
|
-
const query = this.constructQuery(datasourceId, name, methodName, path, queryString, headers, parameters, requestBody);
|
|
134
|
+
const query = this.constructQuery(datasourceId, name, methodName, path, url, queryString, headers, parameters, requestBody);
|
|
132
135
|
queries.push(query);
|
|
133
136
|
}
|
|
134
137
|
}
|
|
@@ -8,13 +8,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
-
const { processString } = require("@budibase/string-templates");
|
|
12
11
|
const CouchDB = require("../../../db");
|
|
13
12
|
const { generateQueryID, getQueryParams, isProdAppID, } = require("../../../db/utils");
|
|
14
13
|
const { BaseQueryVerbs } = require("../../../constants");
|
|
15
14
|
const { Thread, ThreadType } = require("../../../threads");
|
|
16
15
|
const { save: saveDatasource } = require("../datasource");
|
|
17
16
|
const { RestImporter } = require("./import");
|
|
17
|
+
const { invalidateDynamicVariables } = require("../../../threads/utils");
|
|
18
18
|
const Runner = new Thread(ThreadType.QUERY, { timeoutMs: 10000 });
|
|
19
19
|
// simple function to append "readable" to all read queries
|
|
20
20
|
function enrichQueries(input) {
|
|
@@ -81,44 +81,6 @@ exports.save = function (ctx) {
|
|
|
81
81
|
ctx.message = `Query ${query.name} saved successfully.`;
|
|
82
82
|
});
|
|
83
83
|
};
|
|
84
|
-
function enrichQueryFields(fields, parameters = {}) {
|
|
85
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
86
|
-
const enrichedQuery = {};
|
|
87
|
-
// enrich the fields with dynamic parameters
|
|
88
|
-
for (let key of Object.keys(fields)) {
|
|
89
|
-
if (fields[key] == null) {
|
|
90
|
-
continue;
|
|
91
|
-
}
|
|
92
|
-
if (typeof fields[key] === "object") {
|
|
93
|
-
// enrich nested fields object
|
|
94
|
-
enrichedQuery[key] = yield enrichQueryFields(fields[key], parameters);
|
|
95
|
-
}
|
|
96
|
-
else if (typeof fields[key] === "string") {
|
|
97
|
-
// enrich string value as normal
|
|
98
|
-
enrichedQuery[key] = yield processString(fields[key], parameters, {
|
|
99
|
-
noHelpers: true,
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
else {
|
|
103
|
-
enrichedQuery[key] = fields[key];
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
if (enrichedQuery.json ||
|
|
107
|
-
enrichedQuery.customData ||
|
|
108
|
-
enrichedQuery.requestBody) {
|
|
109
|
-
try {
|
|
110
|
-
enrichedQuery.json = JSON.parse(enrichedQuery.json ||
|
|
111
|
-
enrichedQuery.customData ||
|
|
112
|
-
enrichedQuery.requestBody);
|
|
113
|
-
}
|
|
114
|
-
catch (err) {
|
|
115
|
-
// no json found, ignore
|
|
116
|
-
}
|
|
117
|
-
delete enrichedQuery.customData;
|
|
118
|
-
}
|
|
119
|
-
return enrichedQuery;
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
84
|
exports.find = function (ctx) {
|
|
123
85
|
return __awaiter(this, void 0, void 0, function* () {
|
|
124
86
|
const db = new CouchDB(ctx.appId);
|
|
@@ -135,14 +97,18 @@ exports.preview = function (ctx) {
|
|
|
135
97
|
return __awaiter(this, void 0, void 0, function* () {
|
|
136
98
|
const db = new CouchDB(ctx.appId);
|
|
137
99
|
const datasource = yield db.get(ctx.request.body.datasourceId);
|
|
138
|
-
|
|
139
|
-
|
|
100
|
+
// preview may not have a queryId as it hasn't been saved, but if it does
|
|
101
|
+
// this stops dynamic variables from calling the same query
|
|
102
|
+
const { fields, parameters, queryVerb, transformer, queryId } = ctx.request.body;
|
|
140
103
|
try {
|
|
141
104
|
const { rows, keys, info, extra } = yield Runner.run({
|
|
105
|
+
appId: ctx.appId,
|
|
142
106
|
datasource,
|
|
143
107
|
queryVerb,
|
|
144
|
-
|
|
108
|
+
fields,
|
|
109
|
+
parameters,
|
|
145
110
|
transformer,
|
|
111
|
+
queryId,
|
|
146
112
|
});
|
|
147
113
|
ctx.body = {
|
|
148
114
|
rows,
|
|
@@ -156,30 +122,62 @@ exports.preview = function (ctx) {
|
|
|
156
122
|
}
|
|
157
123
|
});
|
|
158
124
|
};
|
|
159
|
-
|
|
125
|
+
function execute(ctx, opts = { rowsOnly: false }) {
|
|
160
126
|
return __awaiter(this, void 0, void 0, function* () {
|
|
161
127
|
const db = new CouchDB(ctx.appId);
|
|
162
128
|
const query = yield db.get(ctx.params.queryId);
|
|
163
129
|
const datasource = yield db.get(query.datasourceId);
|
|
164
|
-
const enrichedQuery = yield enrichQueryFields(query.fields, ctx.request.body.parameters);
|
|
165
130
|
// call the relevant CRUD method on the integration class
|
|
166
131
|
try {
|
|
167
|
-
const { rows } = yield Runner.run({
|
|
132
|
+
const { rows, extra } = yield Runner.run({
|
|
133
|
+
appId: ctx.appId,
|
|
168
134
|
datasource,
|
|
169
135
|
queryVerb: query.queryVerb,
|
|
170
|
-
|
|
136
|
+
fields: query.fields,
|
|
137
|
+
parameters: ctx.request.body.parameters,
|
|
171
138
|
transformer: query.transformer,
|
|
139
|
+
queryId: ctx.params.queryId,
|
|
172
140
|
});
|
|
173
|
-
|
|
141
|
+
if (opts && opts.rowsOnly) {
|
|
142
|
+
ctx.body = rows;
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
ctx.body = Object.assign({ data: rows }, extra);
|
|
146
|
+
}
|
|
174
147
|
}
|
|
175
148
|
catch (err) {
|
|
176
149
|
ctx.throw(400, err);
|
|
177
150
|
}
|
|
178
151
|
});
|
|
152
|
+
}
|
|
153
|
+
exports.executeV1 = function (ctx) {
|
|
154
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
155
|
+
return execute(ctx, { rowsOnly: true });
|
|
156
|
+
});
|
|
179
157
|
};
|
|
158
|
+
exports.executeV2 = function (ctx) {
|
|
159
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
160
|
+
return execute(ctx, { rowsOnly: false });
|
|
161
|
+
});
|
|
162
|
+
};
|
|
163
|
+
const removeDynamicVariables = (db, queryId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
164
|
+
const query = yield db.get(queryId);
|
|
165
|
+
const datasource = yield db.get(query.datasourceId);
|
|
166
|
+
const dynamicVariables = datasource.config.dynamicVariables;
|
|
167
|
+
if (dynamicVariables) {
|
|
168
|
+
// delete dynamic variables from the datasource
|
|
169
|
+
const newVariables = dynamicVariables.filter(dv => dv.queryId !== queryId);
|
|
170
|
+
datasource.config.dynamicVariables = newVariables;
|
|
171
|
+
yield db.put(datasource);
|
|
172
|
+
// invalidate the deleted variables
|
|
173
|
+
const variablesToDelete = dynamicVariables.filter(dv => dv.queryId === queryId);
|
|
174
|
+
yield invalidateDynamicVariables(variablesToDelete);
|
|
175
|
+
}
|
|
176
|
+
});
|
|
180
177
|
exports.destroy = function (ctx) {
|
|
181
178
|
return __awaiter(this, void 0, void 0, function* () {
|
|
182
179
|
const db = new CouchDB(ctx.appId);
|
|
180
|
+
yield removeDynamicVariables(db, ctx.params.queryId);
|
|
183
181
|
yield db.remove(ctx.params.queryId, ctx.params.revId);
|
|
184
182
|
ctx.message = `Query deleted.`;
|
|
185
183
|
ctx.status = 200;
|
|
@@ -32,6 +32,7 @@ exports.generateQueryPreviewValidation = () => {
|
|
|
32
32
|
extra: Joi.object().optional(),
|
|
33
33
|
datasourceId: Joi.string().required(),
|
|
34
34
|
transformer: Joi.string().optional(),
|
|
35
|
-
parameters: Joi.object({}).required().unknown(true)
|
|
35
|
+
parameters: Joi.object({}).required().unknown(true),
|
|
36
|
+
queryId: Joi.string().optional(),
|
|
36
37
|
}));
|
|
37
38
|
};
|
|
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
const CouchDB = require("../../db");
|
|
12
|
-
const { Role, getRole, isBuiltin, getAllRoles, } = require("@budibase/
|
|
12
|
+
const { Role, getRole, isBuiltin, getAllRoles, } = require("@budibase/backend-core/roles");
|
|
13
13
|
const { generateRoleID, getUserMetadataParams, InternalTables, } = require("../../db/utils");
|
|
14
14
|
const UpdateRolesOptions = {
|
|
15
15
|
CREATED: "created",
|
|
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
const { getRoutingInfo } = require("../../utilities/routing");
|
|
12
|
-
const { getUserRoleHierarchy, BUILTIN_ROLE_IDS, } = require("@budibase/
|
|
12
|
+
const { getUserRoleHierarchy, BUILTIN_ROLE_IDS, } = require("@budibase/backend-core/roles");
|
|
13
13
|
const URL_SEPARATOR = "/";
|
|
14
14
|
function Routing() {
|
|
15
15
|
this.json = {};
|
|
@@ -23,7 +23,7 @@ const CouchDB = require("../../../db");
|
|
|
23
23
|
const linkRows = require("../../../db/linkedRows");
|
|
24
24
|
const { getRowParams, generateRowID, DocumentTypes, InternalTables, } = require("../../../db/utils");
|
|
25
25
|
const userController = require("../user");
|
|
26
|
-
const { inputProcessing, outputProcessing, processAutoColumn, } = require("../../../utilities/rowProcessor");
|
|
26
|
+
const { inputProcessing, outputProcessing, processAutoColumn, cleanupAttachments, } = require("../../../utilities/rowProcessor");
|
|
27
27
|
const { FieldTypes } = require("../../../constants");
|
|
28
28
|
const { isEqual } = require("lodash");
|
|
29
29
|
const { validate, findRow } = require("./utils");
|
|
@@ -32,6 +32,7 @@ const { getGlobalUsersFromMetadata } = require("../../../utilities/global");
|
|
|
32
32
|
const inMemoryViews = require("../../../db/inMemoryView");
|
|
33
33
|
const env = require("../../../environment");
|
|
34
34
|
const { migrateToInMemoryView, migrateToDesignView, getFromDesignDoc, getFromMemoryDoc, } = require("../view/utils");
|
|
35
|
+
const { cloneDeep } = require("lodash/fp");
|
|
35
36
|
const CALCULATION_TYPES = {
|
|
36
37
|
SUM: "sum",
|
|
37
38
|
COUNT: "count",
|
|
@@ -119,15 +120,15 @@ exports.patch = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
119
120
|
const inputs = ctx.request.body;
|
|
120
121
|
const tableId = inputs.tableId;
|
|
121
122
|
const isUserTable = tableId === InternalTables.USER_METADATA;
|
|
122
|
-
let
|
|
123
|
+
let oldRow;
|
|
123
124
|
try {
|
|
124
|
-
|
|
125
|
+
oldRow = yield db.get(inputs._id);
|
|
125
126
|
}
|
|
126
127
|
catch (err) {
|
|
127
128
|
if (isUserTable) {
|
|
128
129
|
// don't include the rev, it'll be the global rev
|
|
129
130
|
// this time
|
|
130
|
-
|
|
131
|
+
oldRow = {
|
|
131
132
|
_id: inputs._id,
|
|
132
133
|
};
|
|
133
134
|
}
|
|
@@ -137,13 +138,14 @@ exports.patch = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
137
138
|
}
|
|
138
139
|
let dbTable = yield db.get(tableId);
|
|
139
140
|
// need to build up full patch fields before coerce
|
|
141
|
+
let combinedRow = cloneDeep(oldRow);
|
|
140
142
|
for (let key of Object.keys(inputs)) {
|
|
141
143
|
if (!dbTable.schema[key])
|
|
142
144
|
continue;
|
|
143
|
-
|
|
145
|
+
combinedRow[key] = inputs[key];
|
|
144
146
|
}
|
|
145
147
|
// this returns the table and row incase they have been updated
|
|
146
|
-
let { table, row } = inputProcessing(ctx.user, dbTable,
|
|
148
|
+
let { table, row } = inputProcessing(ctx.user, dbTable, combinedRow);
|
|
147
149
|
const validateResult = yield validate({
|
|
148
150
|
row,
|
|
149
151
|
table,
|
|
@@ -159,6 +161,8 @@ exports.patch = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
159
161
|
tableId: row.tableId,
|
|
160
162
|
table,
|
|
161
163
|
});
|
|
164
|
+
// check if any attachments removed
|
|
165
|
+
yield cleanupAttachments(appId, table, { oldRow, row });
|
|
162
166
|
if (isUserTable) {
|
|
163
167
|
// the row has been updated, need to put it into the ctx
|
|
164
168
|
ctx.request.body = row;
|
|
@@ -284,6 +288,8 @@ exports.destroy = function (ctx) {
|
|
|
284
288
|
row,
|
|
285
289
|
tableId: row.tableId,
|
|
286
290
|
});
|
|
291
|
+
// remove any attachments that were on the row from object storage
|
|
292
|
+
yield cleanupAttachments(appId, table, { row });
|
|
287
293
|
let response;
|
|
288
294
|
if (ctx.params.tableId === InternalTables.USER_METADATA) {
|
|
289
295
|
ctx.params = {
|
|
@@ -325,6 +331,8 @@ exports.bulkDestroy = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
325
331
|
else {
|
|
326
332
|
yield db.bulkDocs(rows.map(row => (Object.assign(Object.assign({}, row), { _deleted: true }))));
|
|
327
333
|
}
|
|
334
|
+
// remove any attachments that were on the rows from object storage
|
|
335
|
+
yield cleanupAttachments(appId, table, { rows });
|
|
328
336
|
yield Promise.all(updates);
|
|
329
337
|
return { response: { ok: true }, rows };
|
|
330
338
|
});
|
|
@@ -10,7 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
const { SearchIndexes } = require("../../../db/utils");
|
|
12
12
|
const fetch = require("node-fetch");
|
|
13
|
-
const { getCouchUrl } = require("@budibase/
|
|
13
|
+
const { getCouchUrl } = require("@budibase/backend-core/db");
|
|
14
14
|
/**
|
|
15
15
|
* Class to build lucene query URLs.
|
|
16
16
|
* Optionally takes a base lucene query object.
|
|
@@ -172,7 +172,8 @@ class QueryBuilder {
|
|
|
172
172
|
}
|
|
173
173
|
if (this.query.equal) {
|
|
174
174
|
build(this.query.equal, (key, value) => {
|
|
175
|
-
if
|
|
175
|
+
// 0 evaluates to false, which means we would return all rows if we don't check it
|
|
176
|
+
if (!value && value !== 0) {
|
|
176
177
|
return null;
|
|
177
178
|
}
|
|
178
179
|
return `${key}:${builder.preprocess(value, allPreProcessingOpts)}`;
|
|
@@ -57,24 +57,31 @@ exports.validate = ({ appId, tableId, row, table }) => __awaiter(void 0, void 0,
|
|
|
57
57
|
const errors = {};
|
|
58
58
|
for (let fieldName of Object.keys(table.schema)) {
|
|
59
59
|
const constraints = cloneDeep(table.schema[fieldName].constraints);
|
|
60
|
+
const type = table.schema[fieldName].type;
|
|
60
61
|
// special case for options, need to always allow unselected (null)
|
|
61
|
-
if (
|
|
62
|
-
(FieldTypes.OPTIONS || FieldTypes.ARRAY) &&
|
|
62
|
+
if ((type === FieldTypes.OPTIONS || type === FieldTypes.ARRAY) &&
|
|
63
63
|
constraints.inclusion) {
|
|
64
64
|
constraints.inclusion.push(null);
|
|
65
65
|
}
|
|
66
66
|
let res;
|
|
67
67
|
// Validate.js doesn't seem to handle array
|
|
68
|
-
if (
|
|
69
|
-
row[fieldName] &&
|
|
70
|
-
row[fieldName].length) {
|
|
68
|
+
if (type === FieldTypes.ARRAY && row[fieldName] && row[fieldName].length) {
|
|
71
69
|
row[fieldName].map(val => {
|
|
72
70
|
if (!constraints.inclusion.includes(val)) {
|
|
73
71
|
errors[fieldName] = "Field not in list";
|
|
74
72
|
}
|
|
75
73
|
});
|
|
76
74
|
}
|
|
77
|
-
else if (
|
|
75
|
+
else if (type === FieldTypes.JSON && typeof row[fieldName] === "string") {
|
|
76
|
+
// this should only happen if there is an error
|
|
77
|
+
try {
|
|
78
|
+
JSON.parse(row[fieldName]);
|
|
79
|
+
}
|
|
80
|
+
catch (err) {
|
|
81
|
+
errors[fieldName] = [`Contains invalid JSON`];
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
else if (type === FieldTypes.FORMULA) {
|
|
78
85
|
res = validateJs.single(processStringSync(table.schema[fieldName].formula, row), constraints);
|
|
79
86
|
}
|
|
80
87
|
else {
|
|
@@ -10,7 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
const CouchDB = require("../../db");
|
|
12
12
|
const { getScreenParams, generateScreenID } = require("../../db/utils");
|
|
13
|
-
const { AccessController } = require("@budibase/
|
|
13
|
+
const { AccessController } = require("@budibase/backend-core/roles");
|
|
14
14
|
exports.fetch = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
15
15
|
const appId = ctx.appId;
|
|
16
16
|
const db = new CouchDB(appId);
|
|
@@ -14,10 +14,10 @@ const { InternalTables } = require("../../db/utils");
|
|
|
14
14
|
const { getGlobalUsers, getRawGlobalUser } = require("../../utilities/global");
|
|
15
15
|
const { getFullUser } = require("../../utilities/users");
|
|
16
16
|
const { isEqual } = require("lodash");
|
|
17
|
-
const { BUILTIN_ROLE_IDS } = require("@budibase/
|
|
18
|
-
const { getDevelopmentAppID, getDeployedAppIDs } = require("@budibase/
|
|
17
|
+
const { BUILTIN_ROLE_IDS } = require("@budibase/backend-core/roles");
|
|
18
|
+
const { getDevelopmentAppID, getDeployedAppIDs, } = require("@budibase/backend-core/db");
|
|
19
19
|
const { doesDatabaseExist } = require("../../utilities");
|
|
20
|
-
const { UserStatus } = require("@budibase/
|
|
20
|
+
const { UserStatus } = require("@budibase/backend-core/constants");
|
|
21
21
|
function rawMetadata(db) {
|
|
22
22
|
return __awaiter(this, void 0, void 0, function* () {
|
|
23
23
|
return (yield db.allDocs(getUserMetadataParams(null, {
|
|
@@ -13,7 +13,7 @@ const { generateWebhookID, getWebhookParams } = require("../../db/utils");
|
|
|
13
13
|
const toJsonSchema = require("to-json-schema");
|
|
14
14
|
const validate = require("jsonschema").validate;
|
|
15
15
|
const triggers = require("../../automations/triggers");
|
|
16
|
-
const { getDeployedAppID } = require("@budibase/
|
|
16
|
+
const { getDeployedAppID } = require("@budibase/backend-core/db");
|
|
17
17
|
const AUTOMATION_DESCRIPTION = "Generated from Webhook Schema";
|
|
18
18
|
function Webhook(name, type, target) {
|
|
19
19
|
this.live = true;
|
package/dist/api/index.js
CHANGED
|
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
const Router = require("@koa/router");
|
|
12
|
-
const { buildAuthMiddleware, auditLog, buildTenancyMiddleware, buildAppTenancyMiddleware, } = require("@budibase/auth")
|
|
12
|
+
const { buildAuthMiddleware, auditLog, buildTenancyMiddleware, buildAppTenancyMiddleware, } = require("@budibase/backend-core/auth");
|
|
13
13
|
const currentApp = require("../middleware/currentapp");
|
|
14
14
|
const compress = require("koa-compress");
|
|
15
15
|
const zlib = require("zlib");
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
const Router = require("@koa/router");
|
|
3
3
|
const controller = require("../controllers/apikeys");
|
|
4
4
|
const authorized = require("../../middleware/authorized");
|
|
5
|
-
const { BUILDER } = require("@budibase/
|
|
5
|
+
const { BUILDER } = require("@budibase/backend-core/permissions");
|
|
6
6
|
const router = Router();
|
|
7
7
|
router
|
|
8
8
|
.get("/api/keys", authorized(BUILDER), controller.fetch)
|