@budibase/server 0.9.136 → 0.9.140-alpha.0
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/discord.c14881e9.svg +10 -0
- package/builder/assets/{index.a0ab7774.js → index.0d1fa670.js} +35 -35
- package/builder/assets/{index.121692c9.css → index.79907e5c.css} +5 -5
- package/builder/assets/integromat.42212f11.png +0 -0
- package/builder/assets/slack.1e1f7cfb.svg +33 -0
- package/builder/assets/{vendor.7177f366.js → vendor.d39b3c1e.js} +2 -2
- package/builder/assets/zapier.3fbd8f5c.png +0 -0
- package/builder/index.html +3 -3
- package/coverage/clover.xml +2142 -2095
- package/coverage/coverage-final.json +120 -106
- package/coverage/lcov-report/api/controllers/analytics.js.html +3 -3
- package/coverage/lcov-report/api/controllers/apikeys.js.html +6 -6
- package/coverage/lcov-report/api/controllers/application.js.html +84 -84
- package/coverage/lcov-report/api/controllers/auth.js.html +6 -6
- package/coverage/lcov-report/api/controllers/automation.js.html +182 -356
- package/coverage/lcov-report/api/controllers/backup.js.html +3 -3
- package/coverage/lcov-report/api/controllers/component.js.html +5 -5
- package/coverage/lcov-report/api/controllers/datasource.js.html +12 -12
- package/coverage/lcov-report/api/controllers/dev.js.html +15 -15
- package/coverage/lcov-report/api/controllers/hosting.js.html +8 -8
- package/coverage/lcov-report/api/controllers/index.html +47 -32
- package/coverage/lcov-report/api/controllers/integration.js.html +4 -4
- package/coverage/lcov-report/api/controllers/layout.js.html +6 -6
- package/coverage/lcov-report/api/controllers/metadata.js.html +218 -0
- package/coverage/lcov-report/api/controllers/permission.js.html +14 -14
- package/coverage/lcov-report/api/controllers/query.js.html +17 -23
- package/coverage/lcov-report/api/controllers/role.js.html +9 -9
- package/coverage/lcov-report/api/controllers/routing.js.html +9 -9
- package/coverage/lcov-report/api/controllers/row/external.js.html +15 -15
- package/coverage/lcov-report/api/controllers/row/index.html +29 -44
- package/coverage/lcov-report/api/controllers/row/index.js.html +48 -45
- package/coverage/lcov-report/api/controllers/row/internal.js.html +159 -126
- package/coverage/lcov-report/api/controllers/row/utils.js.html +17 -17
- package/coverage/lcov-report/api/controllers/screen.js.html +7 -7
- package/coverage/lcov-report/api/controllers/script.js.html +5 -5
- package/coverage/lcov-report/api/controllers/table/index.html +1 -1
- package/coverage/lcov-report/api/controllers/table/index.js.html +40 -40
- package/coverage/lcov-report/api/controllers/table/utils.js.html +48 -48
- package/coverage/lcov-report/api/controllers/templates.js.html +5 -5
- package/coverage/lcov-report/api/controllers/user.js.html +14 -11
- package/coverage/lcov-report/api/controllers/view/exporters.js.html +3 -3
- package/coverage/lcov-report/api/controllers/view/index.html +1 -1
- package/coverage/lcov-report/api/controllers/view/index.js.html +9 -9
- package/coverage/lcov-report/api/controllers/view/viewBuilder.js.html +6 -6
- package/coverage/lcov-report/api/controllers/webhook.js.html +14 -14
- package/coverage/lcov-report/api/index.html +1 -1
- package/coverage/lcov-report/api/index.js.html +23 -23
- package/coverage/lcov-report/api/routes/analytics.js.html +6 -6
- package/coverage/lcov-report/api/routes/apikeys.js.html +8 -8
- package/coverage/lcov-report/api/routes/application.js.html +8 -8
- package/coverage/lcov-report/api/routes/auth.js.html +6 -6
- package/coverage/lcov-report/api/routes/automation.js.html +41 -26
- package/coverage/lcov-report/api/routes/backup.js.html +8 -8
- package/coverage/lcov-report/api/routes/component.js.html +8 -8
- package/coverage/lcov-report/api/routes/datasource.js.html +13 -13
- package/coverage/lcov-report/api/routes/deploy.js.html +8 -8
- package/coverage/lcov-report/api/routes/dev.js.html +11 -11
- package/coverage/lcov-report/api/routes/hosting.js.html +8 -8
- package/coverage/lcov-report/api/routes/index.html +24 -9
- package/coverage/lcov-report/api/routes/index.js.html +36 -30
- package/coverage/lcov-report/api/routes/integration.js.html +8 -8
- package/coverage/lcov-report/api/routes/layout.js.html +8 -8
- package/coverage/lcov-report/api/routes/metadata.js.html +194 -0
- package/coverage/lcov-report/api/routes/permission.js.html +12 -12
- package/coverage/lcov-report/api/routes/query.js.html +13 -13
- package/coverage/lcov-report/api/routes/role.js.html +12 -12
- package/coverage/lcov-report/api/routes/routing.js.html +8 -8
- package/coverage/lcov-report/api/routes/row.js.html +10 -10
- package/coverage/lcov-report/api/routes/screen.js.html +11 -11
- package/coverage/lcov-report/api/routes/script.js.html +1 -1
- package/coverage/lcov-report/api/routes/static.js.html +13 -16
- package/coverage/lcov-report/api/routes/table.js.html +12 -12
- package/coverage/lcov-report/api/routes/templates.js.html +8 -8
- package/coverage/lcov-report/api/routes/user.js.html +9 -9
- package/coverage/lcov-report/api/routes/view.js.html +11 -11
- package/coverage/lcov-report/api/routes/webhook.js.html +11 -11
- package/coverage/lcov-report/automations/actions.js.html +57 -117
- package/coverage/lcov-report/automations/automationUtils.js.html +7 -7
- package/coverage/lcov-report/automations/bullboard.js.html +49 -16
- package/coverage/lcov-report/automations/index.html +67 -67
- package/coverage/lcov-report/automations/index.js.html +27 -129
- package/coverage/lcov-report/automations/steps/bash.js.html +37 -16
- package/coverage/lcov-report/automations/steps/createRow.js.html +15 -15
- package/coverage/lcov-report/automations/steps/delay.js.html +48 -9
- package/coverage/lcov-report/automations/steps/deleteRow.js.html +14 -14
- package/coverage/lcov-report/automations/steps/discord.js.html +329 -0
- package/coverage/lcov-report/automations/steps/executeQuery.js.html +22 -34
- package/coverage/lcov-report/automations/steps/executeScript.js.html +21 -33
- package/coverage/lcov-report/automations/steps/filter.js.html +28 -25
- package/coverage/lcov-report/automations/steps/index.html +140 -65
- package/coverage/lcov-report/automations/steps/integromat.js.html +341 -0
- package/coverage/lcov-report/automations/steps/outgoingWebhook.js.html +44 -38
- package/coverage/lcov-report/automations/steps/queryRows.js.html +437 -0
- package/coverage/lcov-report/automations/steps/sendSmtpEmail.js.html +13 -13
- package/coverage/lcov-report/automations/steps/serverLog.js.html +23 -11
- package/coverage/lcov-report/automations/steps/{sendgridEmail.js.html → slack.js.html} +58 -88
- package/coverage/lcov-report/automations/steps/updateRow.js.html +12 -12
- package/coverage/lcov-report/automations/steps/utils.js.html +188 -0
- package/coverage/lcov-report/automations/steps/zapier.js.html +332 -0
- package/coverage/lcov-report/automations/thread.js.html +81 -78
- package/coverage/lcov-report/automations/triggerInfo/app.js.html +173 -0
- package/coverage/lcov-report/automations/triggerInfo/cron.js.html +173 -0
- package/coverage/lcov-report/automations/triggerInfo/index.html +201 -0
- package/coverage/lcov-report/automations/triggerInfo/index.js.html +125 -0
- package/coverage/lcov-report/automations/triggerInfo/rowDeleted.js.html +176 -0
- package/coverage/lcov-report/automations/triggerInfo/rowSaved.js.html +200 -0
- package/coverage/lcov-report/automations/triggerInfo/rowUpdated.js.html +200 -0
- package/coverage/lcov-report/automations/triggerInfo/webhook.js.html +188 -0
- package/coverage/lcov-report/automations/triggers.js.html +67 -838
- package/coverage/lcov-report/automations/utils.js.html +557 -0
- package/coverage/lcov-report/constants/index.html +5 -5
- package/coverage/lcov-report/constants/index.js.html +32 -17
- package/coverage/lcov-report/constants/layouts.js.html +5 -5
- package/coverage/lcov-report/constants/screens.js.html +4 -4
- package/coverage/lcov-report/db/client.js.html +18 -18
- package/coverage/lcov-report/db/index.html +19 -19
- package/coverage/lcov-report/db/index.js.html +3 -3
- package/coverage/lcov-report/db/linkedRows/LinkController.js.html +79 -79
- package/coverage/lcov-report/db/linkedRows/index.html +18 -18
- package/coverage/lcov-report/db/linkedRows/index.js.html +107 -149
- package/coverage/lcov-report/db/linkedRows/linkUtils.js.html +43 -43
- package/coverage/lcov-report/db/newid.js.html +4 -4
- package/coverage/lcov-report/db/utils.js.html +127 -76
- package/coverage/lcov-report/events/AutomationEmitter.js.html +7 -7
- package/coverage/lcov-report/events/index.html +1 -1
- package/coverage/lcov-report/events/index.js.html +6 -6
- package/coverage/lcov-report/events/utils.js.html +3 -3
- package/coverage/lcov-report/index.html +116 -101
- 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/{automations/logic.js.html → middleware/appInfo.js.html} +35 -38
- package/coverage/lcov-report/middleware/authorized.js.html +16 -16
- package/coverage/lcov-report/middleware/builder.js.html +15 -15
- package/coverage/lcov-report/middleware/currentapp.js.html +33 -33
- package/coverage/lcov-report/middleware/index.html +23 -8
- package/coverage/lcov-report/middleware/joi-validator.js.html +6 -6
- package/coverage/lcov-report/middleware/resourceId.js.html +28 -28
- package/coverage/lcov-report/middleware/selfhost.js.html +1 -1
- package/coverage/lcov-report/middleware/usageQuota.js.html +8 -8
- 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 +6 -6
- package/coverage/lcov-report/utilities/global.js.html +33 -33
- package/coverage/lcov-report/utilities/index.html +28 -28
- package/coverage/lcov-report/utilities/index.js.html +178 -25
- package/coverage/lcov-report/utilities/queue/inMemoryQueue.js.html +18 -18
- 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 +6 -6
- package/coverage/lcov-report/utilities/rowProcessor/index.html +14 -14
- package/coverage/lcov-report/utilities/rowProcessor/index.js.html +87 -51
- package/coverage/lcov-report/utilities/rowProcessor/utils.js.html +10 -10
- package/coverage/lcov-report/utilities/security.js.html +9 -9
- package/coverage/lcov-report/utilities/statusCodes.js.html +1 -1
- package/coverage/lcov-report/utilities/users.js.html +5 -5
- package/coverage/lcov-report/utilities/workerRequests.js.html +52 -52
- package/coverage/lcov.info +3250 -3213
- package/dist/api/controllers/automation.js +60 -127
- package/dist/api/controllers/deploy/index.js +17 -1
- package/dist/api/controllers/metadata.js +49 -0
- package/dist/api/controllers/query.js +0 -2
- package/dist/api/controllers/row/ExternalRequest.js +1 -1
- package/dist/api/controllers/row/index.js +1 -0
- package/dist/api/controllers/row/internal.js +33 -23
- package/dist/api/controllers/static/index.js +1 -28
- package/dist/api/controllers/static/templates/BudibaseApp.svelte +4 -1
- package/dist/api/controllers/user.js +1 -1
- package/dist/api/routes/automation.js +4 -5
- package/dist/api/routes/index.js +2 -0
- package/dist/api/routes/metadata.js +13 -0
- package/dist/api/routes/static.js +0 -1
- package/dist/api/routes/tests/utilities/TestFunctions.js +13 -0
- package/dist/app.js +1 -1
- package/dist/automations/actions.js +29 -46
- package/dist/automations/bullboard.js +11 -2
- package/dist/automations/index.js +11 -48
- package/dist/automations/steps/bash.js +12 -6
- package/dist/automations/steps/createRow.js +5 -5
- package/dist/automations/steps/delay.js +16 -3
- package/dist/automations/steps/deleteRow.js +5 -5
- package/dist/automations/steps/discord.js +91 -0
- package/dist/automations/steps/executeQuery.js +12 -15
- package/dist/automations/steps/executeScript.js +12 -15
- package/dist/automations/steps/filter.js +19 -18
- package/dist/automations/steps/integromat.js +94 -0
- package/dist/automations/steps/outgoingWebhook.js +19 -20
- package/dist/automations/steps/queryRows.js +129 -0
- package/dist/automations/steps/sendSmtpEmail.js +4 -4
- package/dist/automations/steps/serverLog.js +7 -3
- package/dist/automations/steps/slack.js +73 -0
- package/dist/automations/steps/updateRow.js +4 -4
- package/dist/automations/steps/utils.js +46 -0
- package/dist/automations/steps/zapier.js +91 -0
- package/dist/automations/tests/utilities/index.js +2 -12
- package/dist/automations/thread.js +23 -25
- package/dist/automations/triggerInfo/app.js +32 -0
- package/dist/automations/triggerInfo/cron.js +32 -0
- package/dist/automations/triggerInfo/index.js +15 -0
- package/dist/automations/triggerInfo/rowDeleted.js +33 -0
- package/dist/automations/triggerInfo/rowSaved.js +41 -0
- package/dist/automations/triggerInfo/rowUpdated.js +41 -0
- package/dist/automations/triggerInfo/webhook.js +37 -0
- package/dist/automations/triggers.js +27 -285
- package/dist/automations/utils.js +143 -0
- package/dist/constants/index.js +4 -0
- package/dist/db/linkedRows/index.js +20 -34
- package/dist/db/utils.js +14 -1
- package/dist/environment.js +2 -1
- package/dist/integrations/mysql.js +14 -2
- package/dist/middleware/appInfo.js +17 -0
- package/dist/middleware/usageQuota.js +1 -1
- package/dist/package.json +12 -11
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utilities/appDirectoryTemplate/package.json +1 -1
- package/dist/utilities/fileSystem/clientLibrary.js +2 -2
- package/dist/utilities/fileSystem/index.js +2 -27
- package/dist/utilities/index.js +54 -0
- package/dist/utilities/redis.js +16 -1
- package/dist/utilities/rowProcessor/index.js +7 -4
- package/package.json +13 -12
- package/scripts/jestSetup.js +1 -0
- package/scripts/selfhost.js +8 -0
- package/src/api/controllers/automation.js +87 -145
- package/src/api/controllers/deploy/index.js +23 -1
- package/src/api/controllers/metadata.js +46 -0
- package/src/api/controllers/query.js +0 -2
- package/src/api/controllers/row/ExternalRequest.ts +1 -1
- package/src/api/controllers/row/index.js +1 -0
- package/src/api/controllers/row/internal.js +34 -23
- package/src/api/controllers/static/index.js +1 -39
- package/src/api/controllers/static/templates/BudibaseApp.svelte +4 -1
- package/src/api/controllers/user.js +1 -0
- package/src/api/routes/automation.js +16 -11
- package/src/api/routes/index.js +2 -0
- package/src/api/routes/metadata.js +38 -0
- package/src/api/routes/static.js +0 -1
- package/src/api/routes/tests/automation.spec.js +4 -26
- package/src/api/routes/tests/metadata.spec.js +65 -0
- package/src/api/routes/tests/utilities/TestFunctions.js +14 -0
- package/src/app.ts +1 -1
- package/src/automations/actions.js +29 -49
- package/src/automations/bullboard.js +13 -2
- package/src/automations/index.js +11 -45
- package/src/automations/steps/bash.js +13 -6
- package/src/automations/steps/createRow.js +5 -5
- package/src/automations/steps/delay.js +16 -3
- package/src/automations/steps/deleteRow.js +5 -5
- package/src/automations/steps/discord.js +83 -0
- package/src/automations/steps/executeQuery.js +12 -16
- package/src/automations/steps/executeScript.js +12 -16
- package/src/automations/steps/filter.js +19 -18
- package/src/automations/steps/integromat.js +87 -0
- package/src/automations/steps/outgoingWebhook.js +20 -18
- package/src/automations/steps/queryRows.js +119 -0
- package/src/automations/steps/sendSmtpEmail.js +4 -4
- package/src/automations/steps/serverLog.js +7 -3
- package/src/automations/steps/slack.js +64 -0
- package/src/automations/steps/updateRow.js +4 -4
- package/src/automations/steps/utils.js +36 -0
- package/src/automations/steps/zapier.js +84 -0
- package/src/automations/tests/automation.spec.js +4 -67
- package/src/automations/tests/delay.spec.js +2 -2
- package/src/automations/tests/filter.spec.js +14 -14
- package/src/automations/tests/queryRows.spec.js +51 -0
- package/src/automations/tests/utilities/index.js +2 -13
- package/src/automations/thread.js +27 -26
- package/src/automations/triggerInfo/app.js +31 -0
- package/src/automations/triggerInfo/cron.js +31 -0
- package/src/automations/triggerInfo/index.js +15 -0
- package/src/automations/triggerInfo/rowDeleted.js +32 -0
- package/src/automations/triggerInfo/rowSaved.js +40 -0
- package/src/automations/triggerInfo/rowUpdated.js +40 -0
- package/src/automations/triggerInfo/webhook.js +36 -0
- package/src/automations/triggers.js +33 -290
- package/src/automations/utils.js +159 -0
- package/src/constants/index.js +5 -0
- package/src/db/linkedRows/index.js +21 -35
- package/src/db/tests/linkTests.spec.js +0 -12
- package/src/db/utils.js +17 -0
- package/src/environment.js +2 -1
- package/src/integrations/mysql.ts +15 -2
- package/src/middleware/appInfo.js +19 -0
- package/src/middleware/usageQuota.js +1 -1
- package/src/utilities/appDirectoryTemplate/package.json +1 -1
- package/src/utilities/fileSystem/clientLibrary.js +2 -2
- package/src/utilities/fileSystem/index.js +2 -36
- package/src/utilities/index.js +51 -0
- package/src/utilities/redis.js +18 -1
- package/src/utilities/rowProcessor/index.js +16 -4
- package/coverage/lcov-report/api/controllers/row/internalSearch.js.html +0 -1244
- package/dist/automations/logic.js +0 -17
- package/dist/automations/steps/sendgridEmail.js +0 -85
- package/src/automations/logic.js +0 -20
- package/src/automations/steps/sendgridEmail.js +0 -74
- package/src/automations/tests/sendEmail.spec.js +0 -36
|
@@ -10,17 +10,23 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
const CouchDB = require("../../db");
|
|
12
12
|
const actions = require("../../automations/actions");
|
|
13
|
-
const logic = require("../../automations/logic");
|
|
14
13
|
const triggers = require("../../automations/triggers");
|
|
15
|
-
const webhooks = require("./webhook");
|
|
16
14
|
const { getAutomationParams, generateAutomationID } = require("../../db/utils");
|
|
17
|
-
const
|
|
18
|
-
const
|
|
15
|
+
const { checkForWebhooks, updateTestHistory, } = require("../../automations/utils");
|
|
16
|
+
const { deleteEntityMetadata } = require("../../utilities");
|
|
17
|
+
const { MetadataTypes } = require("../../constants");
|
|
18
|
+
const { setTestFlag, clearTestFlag } = require("../../utilities/redis");
|
|
19
19
|
/*************************
|
|
20
20
|
* *
|
|
21
21
|
* BUILDER FUNCTIONS *
|
|
22
22
|
* *
|
|
23
23
|
*************************/
|
|
24
|
+
function cleanupAutomationMetadata(appId, automationId) {
|
|
25
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
yield deleteEntityMetadata(appId, MetadataTypes.AUTOMATION_TEST_INPUT, automationId);
|
|
27
|
+
yield deleteEntityMetadata(appId, MetadataTypes.AUTOMATION_TEST_HISTORY, automationId);
|
|
28
|
+
});
|
|
29
|
+
}
|
|
24
30
|
function cleanAutomationInputs(automation) {
|
|
25
31
|
if (automation == null) {
|
|
26
32
|
return automation;
|
|
@@ -28,6 +34,10 @@ function cleanAutomationInputs(automation) {
|
|
|
28
34
|
let steps = automation.definition.steps;
|
|
29
35
|
let trigger = automation.definition.trigger;
|
|
30
36
|
let allSteps = [...steps, trigger];
|
|
37
|
+
// live is not a property used anymore
|
|
38
|
+
if (automation.live != null) {
|
|
39
|
+
delete automation.live;
|
|
40
|
+
}
|
|
31
41
|
for (let step of allSteps) {
|
|
32
42
|
if (step == null) {
|
|
33
43
|
continue;
|
|
@@ -40,101 +50,6 @@ function cleanAutomationInputs(automation) {
|
|
|
40
50
|
}
|
|
41
51
|
return automation;
|
|
42
52
|
}
|
|
43
|
-
/**
|
|
44
|
-
* This function handles checking of any cron jobs need to be created or deleted for automations.
|
|
45
|
-
* @param {string} appId The ID of the app in which we are checking for webhooks
|
|
46
|
-
* @param {object|undefined} oldAuto The old automation object if updating/deleting
|
|
47
|
-
* @param {object|undefined} newAuto The new automation object if creating/updating
|
|
48
|
-
*/
|
|
49
|
-
function checkForCronTriggers({ appId, oldAuto, newAuto }) {
|
|
50
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
51
|
-
const oldTrigger = oldAuto ? oldAuto.definition.trigger : null;
|
|
52
|
-
const newTrigger = newAuto ? newAuto.definition.trigger : null;
|
|
53
|
-
function isCronTrigger(auto) {
|
|
54
|
-
return (auto &&
|
|
55
|
-
auto.definition.trigger &&
|
|
56
|
-
auto.definition.trigger.stepId === CRON_STEP_ID);
|
|
57
|
-
}
|
|
58
|
-
const isLive = auto => auto && auto.live;
|
|
59
|
-
const cronTriggerRemoved = isCronTrigger(oldAuto) && !isCronTrigger(newAuto) && oldTrigger.cronJobId;
|
|
60
|
-
const cronTriggerDeactivated = !isLive(newAuto) && isLive(oldAuto);
|
|
61
|
-
const cronTriggerActivated = isLive(newAuto) && !isLive(oldAuto);
|
|
62
|
-
if (cronTriggerRemoved || (cronTriggerDeactivated && oldTrigger.cronJobId)) {
|
|
63
|
-
yield triggers.automationQueue.removeRepeatableByKey(oldTrigger.cronJobId);
|
|
64
|
-
}
|
|
65
|
-
// need to create cron job
|
|
66
|
-
else if (isCronTrigger(newAuto) && cronTriggerActivated) {
|
|
67
|
-
const job = yield triggers.automationQueue.add({
|
|
68
|
-
automation: newAuto,
|
|
69
|
-
event: { appId, timestamp: Date.now() },
|
|
70
|
-
}, { repeat: { cron: newTrigger.inputs.cron } });
|
|
71
|
-
// Assign cron job ID from bull so we can remove it later if the cron trigger is removed
|
|
72
|
-
newTrigger.cronJobId = job.id;
|
|
73
|
-
}
|
|
74
|
-
return newAuto;
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* This function handles checking if any webhooks need to be created or deleted for automations.
|
|
79
|
-
* @param {string} appId The ID of the app in which we are checking for webhooks
|
|
80
|
-
* @param {object|undefined} oldAuto The old automation object if updating/deleting
|
|
81
|
-
* @param {object|undefined} newAuto The new automation object if creating/updating
|
|
82
|
-
* @returns {Promise<object|undefined>} After this is complete the new automation object may have been updated and should be
|
|
83
|
-
* written to DB (this does not write to DB as it would be wasteful to repeat).
|
|
84
|
-
*/
|
|
85
|
-
function checkForWebhooks({ appId, oldAuto, newAuto }) {
|
|
86
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
87
|
-
const oldTrigger = oldAuto ? oldAuto.definition.trigger : null;
|
|
88
|
-
const newTrigger = newAuto ? newAuto.definition.trigger : null;
|
|
89
|
-
const triggerChanged = oldTrigger && newTrigger && oldTrigger.id !== newTrigger.id;
|
|
90
|
-
function isWebhookTrigger(auto) {
|
|
91
|
-
return (auto &&
|
|
92
|
-
auto.definition.trigger &&
|
|
93
|
-
auto.definition.trigger.stepId === WH_STEP_ID);
|
|
94
|
-
}
|
|
95
|
-
// need to delete webhook
|
|
96
|
-
if (isWebhookTrigger(oldAuto) &&
|
|
97
|
-
(!isWebhookTrigger(newAuto) || triggerChanged) &&
|
|
98
|
-
oldTrigger.webhookId) {
|
|
99
|
-
try {
|
|
100
|
-
let db = new CouchDB(appId);
|
|
101
|
-
// need to get the webhook to get the rev
|
|
102
|
-
const webhook = yield db.get(oldTrigger.webhookId);
|
|
103
|
-
const ctx = {
|
|
104
|
-
appId,
|
|
105
|
-
params: { id: webhook._id, rev: webhook._rev },
|
|
106
|
-
};
|
|
107
|
-
// might be updating - reset the inputs to remove the URLs
|
|
108
|
-
if (newTrigger) {
|
|
109
|
-
delete newTrigger.webhookId;
|
|
110
|
-
newTrigger.inputs = {};
|
|
111
|
-
}
|
|
112
|
-
yield webhooks.destroy(ctx);
|
|
113
|
-
}
|
|
114
|
-
catch (err) {
|
|
115
|
-
// don't worry about not being able to delete, if it doesn't exist all good
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
// need to create webhook
|
|
119
|
-
if ((!isWebhookTrigger(oldAuto) || triggerChanged) &&
|
|
120
|
-
isWebhookTrigger(newAuto)) {
|
|
121
|
-
const ctx = {
|
|
122
|
-
appId,
|
|
123
|
-
request: {
|
|
124
|
-
body: new webhooks.Webhook("Automation webhook", webhooks.WebhookType.AUTOMATION, newAuto._id),
|
|
125
|
-
},
|
|
126
|
-
};
|
|
127
|
-
yield webhooks.save(ctx);
|
|
128
|
-
const id = ctx.body.webhook._id;
|
|
129
|
-
newTrigger.webhookId = id;
|
|
130
|
-
newTrigger.inputs = {
|
|
131
|
-
schemaUrl: `api/webhooks/schema/${appId}/${id}`,
|
|
132
|
-
triggerUrl: `api/webhooks/trigger/${appId}/${id}`,
|
|
133
|
-
};
|
|
134
|
-
}
|
|
135
|
-
return newAuto;
|
|
136
|
-
});
|
|
137
|
-
}
|
|
138
53
|
exports.create = function (ctx) {
|
|
139
54
|
return __awaiter(this, void 0, void 0, function* () {
|
|
140
55
|
const db = new CouchDB(ctx.appId);
|
|
@@ -151,10 +66,6 @@ exports.create = function (ctx) {
|
|
|
151
66
|
appId: ctx.appId,
|
|
152
67
|
newAuto: automation,
|
|
153
68
|
});
|
|
154
|
-
automation = yield checkForCronTriggers({
|
|
155
|
-
appId: ctx.appId,
|
|
156
|
-
newAuto: automation,
|
|
157
|
-
});
|
|
158
69
|
const response = yield db.put(automation);
|
|
159
70
|
automation._rev = response.rev;
|
|
160
71
|
ctx.status = 200;
|
|
@@ -176,13 +87,18 @@ exports.update = function (ctx) {
|
|
|
176
87
|
oldAuto: oldAutomation,
|
|
177
88
|
newAuto: automation,
|
|
178
89
|
});
|
|
179
|
-
automation = yield checkForCronTriggers({
|
|
180
|
-
appId: ctx.appId,
|
|
181
|
-
oldAuto: oldAutomation,
|
|
182
|
-
newAuto: automation,
|
|
183
|
-
});
|
|
184
90
|
const response = yield db.put(automation);
|
|
185
91
|
automation._rev = response.rev;
|
|
92
|
+
const oldAutoTrigger = oldAutomation && oldAutomation.definition.trigger
|
|
93
|
+
? oldAutomation.definition.trigger
|
|
94
|
+
: {};
|
|
95
|
+
const newAutoTrigger = automation && automation.definition.trigger
|
|
96
|
+
? automation.definition.trigger
|
|
97
|
+
: {};
|
|
98
|
+
// trigger has been updated, remove the test inputs
|
|
99
|
+
if (oldAutoTrigger.id !== newAutoTrigger.id) {
|
|
100
|
+
yield deleteEntityMetadata(ctx.appId, MetadataTypes.AUTOMATION_TEST_INPUT, automation._id);
|
|
101
|
+
}
|
|
186
102
|
ctx.status = 200;
|
|
187
103
|
ctx.body = {
|
|
188
104
|
message: `Automation ${automation._id} updated successfully.`,
|
|
@@ -208,39 +124,32 @@ exports.find = function (ctx) {
|
|
|
208
124
|
exports.destroy = function (ctx) {
|
|
209
125
|
return __awaiter(this, void 0, void 0, function* () {
|
|
210
126
|
const db = new CouchDB(ctx.appId);
|
|
211
|
-
const
|
|
127
|
+
const automationId = ctx.params.id;
|
|
128
|
+
const oldAutomation = yield db.get(automationId);
|
|
212
129
|
yield checkForWebhooks({
|
|
213
130
|
appId: ctx.appId,
|
|
214
131
|
oldAuto: oldAutomation,
|
|
215
132
|
});
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
});
|
|
220
|
-
ctx.body = yield db.remove(ctx.params.id, ctx.params.rev);
|
|
133
|
+
// delete metadata first
|
|
134
|
+
yield cleanupAutomationMetadata(ctx.appId, automationId);
|
|
135
|
+
ctx.body = yield db.remove(automationId, ctx.params.rev);
|
|
221
136
|
});
|
|
222
137
|
};
|
|
223
138
|
exports.getActionList = function (ctx) {
|
|
224
139
|
return __awaiter(this, void 0, void 0, function* () {
|
|
225
|
-
ctx.body = actions.
|
|
140
|
+
ctx.body = actions.ACTION_DEFINITIONS;
|
|
226
141
|
});
|
|
227
142
|
};
|
|
228
143
|
exports.getTriggerList = function (ctx) {
|
|
229
144
|
return __awaiter(this, void 0, void 0, function* () {
|
|
230
|
-
ctx.body = triggers.
|
|
231
|
-
});
|
|
232
|
-
};
|
|
233
|
-
exports.getLogicList = function (ctx) {
|
|
234
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
235
|
-
ctx.body = logic.BUILTIN_DEFINITIONS;
|
|
145
|
+
ctx.body = triggers.TRIGGER_DEFINITIONS;
|
|
236
146
|
});
|
|
237
147
|
};
|
|
238
148
|
module.exports.getDefinitionList = function (ctx) {
|
|
239
149
|
return __awaiter(this, void 0, void 0, function* () {
|
|
240
150
|
ctx.body = {
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
action: actions.DEFINITIONS,
|
|
151
|
+
trigger: triggers.TRIGGER_DEFINITIONS,
|
|
152
|
+
action: actions.ACTION_DEFINITIONS,
|
|
244
153
|
};
|
|
245
154
|
});
|
|
246
155
|
};
|
|
@@ -251,13 +160,37 @@ module.exports.getDefinitionList = function (ctx) {
|
|
|
251
160
|
*********************/
|
|
252
161
|
exports.trigger = function (ctx) {
|
|
253
162
|
return __awaiter(this, void 0, void 0, function* () {
|
|
254
|
-
const
|
|
163
|
+
const appId = ctx.appId;
|
|
164
|
+
const db = new CouchDB(appId);
|
|
255
165
|
let automation = yield db.get(ctx.params.id);
|
|
256
|
-
yield triggers.externalTrigger(automation, Object.assign(Object.assign({}, ctx.request.body), { appId
|
|
257
|
-
ctx.status = 200;
|
|
166
|
+
yield triggers.externalTrigger(automation, Object.assign(Object.assign({}, ctx.request.body), { appId }));
|
|
258
167
|
ctx.body = {
|
|
259
168
|
message: `Automation ${automation._id} has been triggered.`,
|
|
260
169
|
automation,
|
|
261
170
|
};
|
|
262
171
|
});
|
|
263
172
|
};
|
|
173
|
+
function prepareTestInput(input) {
|
|
174
|
+
// prepare the test parameters
|
|
175
|
+
if (input.id && input.row) {
|
|
176
|
+
input.row._id = input.id;
|
|
177
|
+
}
|
|
178
|
+
if (input.revision && input.row) {
|
|
179
|
+
input.row._rev = input.revision;
|
|
180
|
+
}
|
|
181
|
+
return input;
|
|
182
|
+
}
|
|
183
|
+
exports.test = function (ctx) {
|
|
184
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
185
|
+
const appId = ctx.appId;
|
|
186
|
+
const db = new CouchDB(appId);
|
|
187
|
+
let automation = yield db.get(ctx.params.id);
|
|
188
|
+
yield setTestFlag(automation._id);
|
|
189
|
+
const testInput = prepareTestInput(ctx.request.body);
|
|
190
|
+
const response = yield triggers.externalTrigger(automation, Object.assign(Object.assign({}, testInput), { appId }), { getResponses: true });
|
|
191
|
+
// save a test history run
|
|
192
|
+
yield updateTestHistory(ctx.appId, automation, Object.assign(Object.assign({}, ctx.request.body), { occurredAt: new Date().getTime() }));
|
|
193
|
+
yield clearTestFlag(automation._id);
|
|
194
|
+
ctx.body = response;
|
|
195
|
+
});
|
|
196
|
+
};
|
|
@@ -11,7 +11,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
const CouchDB = require("../../../db");
|
|
12
12
|
const Deployment = require("./Deployment");
|
|
13
13
|
const { Replication } = require("@budibase/auth/db");
|
|
14
|
-
const { DocumentTypes } = require("../../../db/utils");
|
|
14
|
+
const { DocumentTypes, getAutomationParams } = require("../../../db/utils");
|
|
15
|
+
const { disableAllCrons, enableCronTrigger, } = require("../../../automations/utils");
|
|
15
16
|
// the max time we can wait for an invalidation to complete before considering it failed
|
|
16
17
|
const MAX_PENDING_TIME_MS = 30 * 60000;
|
|
17
18
|
const DeploymentStatus = {
|
|
@@ -58,6 +59,20 @@ function storeDeploymentHistory(deployment) {
|
|
|
58
59
|
return deployment;
|
|
59
60
|
});
|
|
60
61
|
}
|
|
62
|
+
function initDeployedApp(prodAppId) {
|
|
63
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
64
|
+
const db = new CouchDB(prodAppId);
|
|
65
|
+
const automations = (yield db.allDocs(getAutomationParams(null, {
|
|
66
|
+
include_docs: true,
|
|
67
|
+
}))).rows.map(row => row.doc);
|
|
68
|
+
const promises = [];
|
|
69
|
+
yield disableAllCrons(prodAppId);
|
|
70
|
+
for (let automation of automations) {
|
|
71
|
+
promises.push(enableCronTrigger(prodAppId, automation));
|
|
72
|
+
}
|
|
73
|
+
yield Promise.all(promises);
|
|
74
|
+
});
|
|
75
|
+
}
|
|
61
76
|
function deployApp(deployment) {
|
|
62
77
|
return __awaiter(this, void 0, void 0, function* () {
|
|
63
78
|
try {
|
|
@@ -82,6 +97,7 @@ function deployApp(deployment) {
|
|
|
82
97
|
return doc._id !== DocumentTypes.APP_METADATA;
|
|
83
98
|
},
|
|
84
99
|
});
|
|
100
|
+
yield initDeployedApp(productionAppId);
|
|
85
101
|
deployment.setStatus(DeploymentStatus.SUCCESS);
|
|
86
102
|
yield storeDeploymentHistory(deployment);
|
|
87
103
|
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
const { MetadataTypes } = require("../../constants");
|
|
12
|
+
const CouchDB = require("../../db");
|
|
13
|
+
const { generateMetadataID } = require("../../db/utils");
|
|
14
|
+
const { saveEntityMetadata, deleteEntityMetadata } = require("../../utilities");
|
|
15
|
+
exports.getTypes = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
16
|
+
ctx.body = {
|
|
17
|
+
types: MetadataTypes,
|
|
18
|
+
};
|
|
19
|
+
});
|
|
20
|
+
exports.saveMetadata = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
21
|
+
const { type, entityId } = ctx.params;
|
|
22
|
+
if (type === MetadataTypes.AUTOMATION_TEST_HISTORY) {
|
|
23
|
+
ctx.throw(400, "Cannot save automation history type");
|
|
24
|
+
}
|
|
25
|
+
ctx.body = yield saveEntityMetadata(ctx.appId, type, entityId, ctx.request.body);
|
|
26
|
+
});
|
|
27
|
+
exports.deleteMetadata = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
28
|
+
const { type, entityId } = ctx.params;
|
|
29
|
+
yield deleteEntityMetadata(ctx.appId, type, entityId);
|
|
30
|
+
ctx.body = {
|
|
31
|
+
message: "Metadata deleted successfully",
|
|
32
|
+
};
|
|
33
|
+
});
|
|
34
|
+
exports.getMetadata = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
35
|
+
const { type, entityId } = ctx.params;
|
|
36
|
+
const db = new CouchDB(ctx.appId);
|
|
37
|
+
const id = generateMetadataID(type, entityId);
|
|
38
|
+
try {
|
|
39
|
+
ctx.body = yield db.get(id);
|
|
40
|
+
}
|
|
41
|
+
catch (err) {
|
|
42
|
+
if (err.status === 404) {
|
|
43
|
+
ctx.body = {};
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
ctx.throw(err.status, err);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
});
|
|
@@ -146,8 +146,6 @@ exports.execute = function (ctx) {
|
|
|
146
146
|
}
|
|
147
147
|
const enrichedQuery = yield enrichQueryFields(query.fields, ctx.request.body.parameters);
|
|
148
148
|
const integration = new Integration(datasource.config);
|
|
149
|
-
console.log(query);
|
|
150
|
-
// ctx.body = {}
|
|
151
149
|
// call the relevant CRUD method on the integration class
|
|
152
150
|
ctx.body = formatResponse(yield integration[query.queryVerb](enrichedQuery));
|
|
153
151
|
// cleanup
|
|
@@ -130,6 +130,7 @@ exports.destroy = function (ctx) {
|
|
|
130
130
|
exports.search = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
131
131
|
const tableId = getTableId(ctx);
|
|
132
132
|
try {
|
|
133
|
+
ctx.status = 200;
|
|
133
134
|
ctx.body = yield pickApi(tableId).search(ctx);
|
|
134
135
|
}
|
|
135
136
|
catch (err) {
|
|
@@ -34,6 +34,20 @@ const CALCULATION_TYPES = {
|
|
|
34
34
|
COUNT: "count",
|
|
35
35
|
STATS: "stats",
|
|
36
36
|
};
|
|
37
|
+
function storeResponse(ctx, db, row, oldTable, table) {
|
|
38
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
39
|
+
row.type = "row";
|
|
40
|
+
const response = yield db.put(row);
|
|
41
|
+
// don't worry about rev, tables handle rev/lastID updates
|
|
42
|
+
if (!isEqual(oldTable, table)) {
|
|
43
|
+
yield db.put(table);
|
|
44
|
+
}
|
|
45
|
+
row._rev = response.rev;
|
|
46
|
+
// process the row before return, to include relationships
|
|
47
|
+
row = yield outputProcessing(ctx, table, row, { squash: false });
|
|
48
|
+
return { row, table };
|
|
49
|
+
});
|
|
50
|
+
}
|
|
37
51
|
exports.patch = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
38
52
|
const appId = ctx.appId;
|
|
39
53
|
const db = new CouchDB(appId);
|
|
@@ -86,14 +100,7 @@ exports.patch = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
86
100
|
yield userController.updateMetadata(ctx);
|
|
87
101
|
return { row: ctx.body, table };
|
|
88
102
|
}
|
|
89
|
-
|
|
90
|
-
// don't worry about rev, tables handle rev/lastID updates
|
|
91
|
-
if (!isEqual(dbTable, table)) {
|
|
92
|
-
yield db.put(table);
|
|
93
|
-
}
|
|
94
|
-
row._rev = response.rev;
|
|
95
|
-
row.type = "row";
|
|
96
|
-
return { row, table };
|
|
103
|
+
return storeResponse(ctx, db, row, dbTable, table);
|
|
97
104
|
});
|
|
98
105
|
exports.save = function (ctx) {
|
|
99
106
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -122,14 +129,7 @@ exports.save = function (ctx) {
|
|
|
122
129
|
tableId: row.tableId,
|
|
123
130
|
table,
|
|
124
131
|
});
|
|
125
|
-
row
|
|
126
|
-
const response = yield db.put(row);
|
|
127
|
-
// don't worry about rev, tables handle rev/lastID updates
|
|
128
|
-
if (!isEqual(dbTable, table)) {
|
|
129
|
-
yield db.put(table);
|
|
130
|
-
}
|
|
131
|
-
row._rev = response.rev;
|
|
132
|
-
return { row, table };
|
|
132
|
+
return storeResponse(ctx, db, row, dbTable, table);
|
|
133
133
|
});
|
|
134
134
|
};
|
|
135
135
|
exports.fetchView = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -209,41 +209,51 @@ exports.destroy = function (ctx) {
|
|
|
209
209
|
const appId = ctx.appId;
|
|
210
210
|
const db = new CouchDB(appId);
|
|
211
211
|
const { _id, _rev } = ctx.request.body;
|
|
212
|
-
|
|
212
|
+
let row = yield db.get(_id);
|
|
213
213
|
if (row.tableId !== ctx.params.tableId) {
|
|
214
214
|
throw "Supplied tableId doesn't match the row's tableId";
|
|
215
215
|
}
|
|
216
|
+
const table = yield db.get(row.tableId);
|
|
217
|
+
// update the row to include full relationships before deleting them
|
|
218
|
+
row = yield outputProcessing(ctx, table, row, { squash: false });
|
|
219
|
+
// now remove the relationships
|
|
216
220
|
yield linkRows.updateLinks({
|
|
217
221
|
appId,
|
|
218
222
|
eventType: linkRows.EventType.ROW_DELETE,
|
|
219
223
|
row,
|
|
220
224
|
tableId: row.tableId,
|
|
221
225
|
});
|
|
226
|
+
let response;
|
|
222
227
|
if (ctx.params.tableId === InternalTables.USER_METADATA) {
|
|
223
228
|
ctx.params = {
|
|
224
229
|
id: _id,
|
|
225
230
|
};
|
|
226
231
|
yield userController.destroyMetadata(ctx);
|
|
227
|
-
|
|
232
|
+
response = ctx.body;
|
|
228
233
|
}
|
|
229
234
|
else {
|
|
230
|
-
|
|
231
|
-
return { response, row };
|
|
235
|
+
response = yield db.remove(_id, _rev);
|
|
232
236
|
}
|
|
237
|
+
return { response, row };
|
|
233
238
|
});
|
|
234
239
|
};
|
|
235
240
|
exports.bulkDestroy = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
236
241
|
const appId = ctx.appId;
|
|
237
|
-
const { rows } = ctx.request.body;
|
|
238
242
|
const db = new CouchDB(appId);
|
|
243
|
+
const tableId = ctx.params.tableId;
|
|
244
|
+
const table = yield db.get(tableId);
|
|
245
|
+
let { rows } = ctx.request.body;
|
|
246
|
+
// before carrying out any updates, make sure the rows are ready to be returned
|
|
247
|
+
// they need to be the full rows (including previous relationships) for automations
|
|
248
|
+
rows = yield outputProcessing(ctx, table, rows, { squash: false });
|
|
249
|
+
// remove the relationships first
|
|
239
250
|
let updates = rows.map(row => linkRows.updateLinks({
|
|
240
251
|
appId,
|
|
241
252
|
eventType: linkRows.EventType.ROW_DELETE,
|
|
242
253
|
row,
|
|
243
254
|
tableId: row.tableId,
|
|
244
255
|
}));
|
|
245
|
-
|
|
246
|
-
if (ctx.params.tableId === InternalTables.USER_METADATA) {
|
|
256
|
+
if (tableId === InternalTables.USER_METADATA) {
|
|
247
257
|
updates = updates.concat(rows.map(row => {
|
|
248
258
|
ctx.params = {
|
|
249
259
|
id: row._id,
|
|
@@ -11,16 +11,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
require("svelte/register");
|
|
12
12
|
const send = require("koa-send");
|
|
13
13
|
const { resolve, join } = require("../../../utilities/centralPath");
|
|
14
|
-
const fetch = require("node-fetch");
|
|
15
14
|
const uuid = require("uuid");
|
|
16
15
|
const { ObjectStoreBuckets } = require("../../../constants");
|
|
17
16
|
const { processString } = require("@budibase/string-templates");
|
|
18
|
-
const { budibaseTempDir } = require("../../../utilities/budibaseDir");
|
|
19
17
|
const { getDeployedApps } = require("../../../utilities/workerRequests");
|
|
20
18
|
const CouchDB = require("../../../db");
|
|
21
19
|
const { loadHandlebarsFile, NODE_MODULES_PATH, TOP_LEVEL_PATH, } = require("../../../utilities/fileSystem");
|
|
22
20
|
const env = require("../../../environment");
|
|
23
|
-
const {
|
|
21
|
+
const { clientLibraryPath } = require("../../../utilities");
|
|
24
22
|
const { upload } = require("../../../utilities/fileSystem");
|
|
25
23
|
const { attachmentsRelativeURL } = require("../../../utilities");
|
|
26
24
|
const { DocumentTypes } = require("../../../db/utils");
|
|
@@ -56,8 +54,6 @@ function checkForSelfHostedURL(ctx) {
|
|
|
56
54
|
}
|
|
57
55
|
});
|
|
58
56
|
}
|
|
59
|
-
// this was the version before we started versioning the component library
|
|
60
|
-
const COMP_LIB_BASE_APP_VERSION = "0.2.5";
|
|
61
57
|
exports.serveBuilder = function (ctx) {
|
|
62
58
|
return __awaiter(this, void 0, void 0, function* () {
|
|
63
59
|
let builderPath = resolve(TOP_LEVEL_PATH, "builder");
|
|
@@ -113,26 +109,3 @@ exports.serveClientLibrary = function (ctx) {
|
|
|
113
109
|
});
|
|
114
110
|
});
|
|
115
111
|
};
|
|
116
|
-
exports.serveComponentLibrary = function (ctx) {
|
|
117
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
118
|
-
const appId = ctx.query.appId || ctx.appId;
|
|
119
|
-
if (env.isDev() || env.isTest()) {
|
|
120
|
-
const componentLibraryPath = join(budibaseTempDir(), appId, "node_modules", "@budibase", "standard-components", "package", "dist");
|
|
121
|
-
return send(ctx, "/index.js", { root: componentLibraryPath });
|
|
122
|
-
}
|
|
123
|
-
const db = new CouchDB(appId);
|
|
124
|
-
const appInfo = yield db.get(DocumentTypes.APP_METADATA);
|
|
125
|
-
let componentLib = "componentlibrary";
|
|
126
|
-
if (appInfo && appInfo.version) {
|
|
127
|
-
componentLib += `-${appInfo.version}`;
|
|
128
|
-
}
|
|
129
|
-
else {
|
|
130
|
-
componentLib += `-${COMP_LIB_BASE_APP_VERSION}`;
|
|
131
|
-
}
|
|
132
|
-
const S3_URL = encodeURI(join(objectStoreUrl(), componentLib, ctx.query.library, "dist", "index.js"));
|
|
133
|
-
const response = yield fetch(S3_URL);
|
|
134
|
-
const body = yield response.text();
|
|
135
|
-
ctx.type = "application/javascript";
|
|
136
|
-
ctx.body = body;
|
|
137
|
-
});
|
|
138
|
-
};
|
|
@@ -7,7 +7,10 @@
|
|
|
7
7
|
|
|
8
8
|
<svelte:head>
|
|
9
9
|
<meta charset="utf8" />
|
|
10
|
-
<meta
|
|
10
|
+
<meta
|
|
11
|
+
name="viewport"
|
|
12
|
+
content="width=device-width, initial-scale=1.0, viewport-fit=cover"
|
|
13
|
+
/>
|
|
11
14
|
|
|
12
15
|
<title>{title}</title>
|
|
13
16
|
<link rel="icon" type="image/png" href={favicon} />
|
|
@@ -32,7 +32,7 @@ exports.fetchMetadata = function (ctx) {
|
|
|
32
32
|
// find the metadata that matches up to the global ID
|
|
33
33
|
const info = metadata.find(meta => meta._id.includes(user._id));
|
|
34
34
|
// remove these props, not for the correct DB
|
|
35
|
-
users.push(Object.assign(Object.assign(Object.assign({}, user), info), {
|
|
35
|
+
users.push(Object.assign(Object.assign(Object.assign({}, user), info), { tableId: InternalTables.USER_METADATA,
|
|
36
36
|
// make sure the ID is always a local ID, not a global one
|
|
37
37
|
_id: generateUserMetadataID(user._id) }));
|
|
38
38
|
}
|
|
@@ -6,6 +6,7 @@ const joiValidator = require("../../middleware/joi-validator");
|
|
|
6
6
|
const { BUILDER, PermissionLevels, PermissionTypes, } = require("@budibase/auth/permissions");
|
|
7
7
|
const Joi = require("joi");
|
|
8
8
|
const { bodyResource, paramResource } = require("../../middleware/resourceId");
|
|
9
|
+
const { middleware: appInfoMiddleware, AppType, } = require("../../middleware/appInfo");
|
|
9
10
|
const router = Router();
|
|
10
11
|
// prettier-ignore
|
|
11
12
|
function generateStepSchema(allowStepTypes) {
|
|
@@ -17,7 +18,6 @@ function generateStepSchema(allowStepTypes) {
|
|
|
17
18
|
tagline: Joi.string().required(),
|
|
18
19
|
icon: Joi.string().required(),
|
|
19
20
|
params: Joi.object(),
|
|
20
|
-
// TODO: validate args a bit more deeply
|
|
21
21
|
args: Joi.object(),
|
|
22
22
|
type: Joi.string().required().valid(...allowStepTypes),
|
|
23
23
|
}).unknown(true);
|
|
@@ -25,7 +25,6 @@ function generateStepSchema(allowStepTypes) {
|
|
|
25
25
|
function generateValidator(existing = false) {
|
|
26
26
|
// prettier-ignore
|
|
27
27
|
return joiValidator.body(Joi.object({
|
|
28
|
-
live: Joi.bool(),
|
|
29
28
|
_id: existing ? Joi.string().required() : Joi.string(),
|
|
30
29
|
_rev: existing ? Joi.string().required() : Joi.string(),
|
|
31
30
|
name: Joi.string().required(),
|
|
@@ -39,12 +38,12 @@ function generateValidator(existing = false) {
|
|
|
39
38
|
router
|
|
40
39
|
.get("/api/automations/trigger/list", authorized(BUILDER), controller.getTriggerList)
|
|
41
40
|
.get("/api/automations/action/list", authorized(BUILDER), controller.getActionList)
|
|
42
|
-
.get("/api/automations/logic/list", authorized(BUILDER), controller.getLogicList)
|
|
43
41
|
.get("/api/automations/definitions/list", authorized(BUILDER), controller.getDefinitionList)
|
|
44
42
|
.get("/api/automations", authorized(BUILDER), controller.fetch)
|
|
45
43
|
.get("/api/automations/:id", paramResource("id"), authorized(BUILDER), controller.find)
|
|
46
44
|
.put("/api/automations", bodyResource("_id"), authorized(BUILDER), generateValidator(true), controller.update)
|
|
47
45
|
.post("/api/automations", authorized(BUILDER), generateValidator(false), controller.create)
|
|
48
|
-
.
|
|
49
|
-
.
|
|
46
|
+
.delete("/api/automations/:id/:rev", paramResource("id"), authorized(BUILDER), controller.destroy)
|
|
47
|
+
.post("/api/automations/:id/trigger", appInfoMiddleware({ appType: AppType.PROD }), paramResource("id"), authorized(PermissionTypes.AUTOMATION, PermissionLevels.EXECUTE), controller.trigger)
|
|
48
|
+
.post("/api/automations/:id/test", appInfoMiddleware({ appType: AppType.DEV }), paramResource("id"), authorized(PermissionTypes.AUTOMATION, PermissionLevels.EXECUTE), controller.test);
|
|
50
49
|
module.exports = router;
|
package/dist/api/routes/index.js
CHANGED
|
@@ -23,6 +23,7 @@ const datasourceRoutes = require("./datasource");
|
|
|
23
23
|
const queryRoutes = require("./query");
|
|
24
24
|
const hostingRoutes = require("./hosting");
|
|
25
25
|
const backupRoutes = require("./backup");
|
|
26
|
+
const metadataRoutes = require("./metadata");
|
|
26
27
|
const devRoutes = require("./dev");
|
|
27
28
|
exports.mainRoutes = [
|
|
28
29
|
authRoutes,
|
|
@@ -46,6 +47,7 @@ exports.mainRoutes = [
|
|
|
46
47
|
queryRoutes,
|
|
47
48
|
hostingRoutes,
|
|
48
49
|
backupRoutes,
|
|
50
|
+
metadataRoutes,
|
|
49
51
|
devRoutes,
|
|
50
52
|
// these need to be handled last as they still use /api/:tableId
|
|
51
53
|
// this could be breaking as koa may recognise other routes as this
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const Router = require("@koa/router");
|
|
3
|
+
const controller = require("../controllers/metadata");
|
|
4
|
+
const { middleware: appInfoMiddleware, AppType, } = require("../../middleware/appInfo");
|
|
5
|
+
const authorized = require("../../middleware/authorized");
|
|
6
|
+
const { BUILDER } = require("@budibase/auth/permissions");
|
|
7
|
+
const router = Router();
|
|
8
|
+
router
|
|
9
|
+
.post("/api/metadata/:type/:entityId", authorized(BUILDER), appInfoMiddleware({ appType: AppType.DEV }), controller.saveMetadata)
|
|
10
|
+
.delete("/api/metadata/:type/:entityId", authorized(BUILDER), appInfoMiddleware({ appType: AppType.DEV }), controller.deleteMetadata)
|
|
11
|
+
.get("/api/metadata/type", authorized(BUILDER), appInfoMiddleware({ appType: AppType.DEV }), controller.getTypes)
|
|
12
|
+
.get("/api/metadata/:type/:entityId", authorized(BUILDER), appInfoMiddleware({ appType: AppType.DEV }), controller.getMetadata);
|
|
13
|
+
module.exports = router;
|
|
@@ -42,7 +42,6 @@ router
|
|
|
42
42
|
.get("/builder/:file*", controller.serveBuilder)
|
|
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
|
-
.get("/componentlibrary", controller.serveComponentLibrary)
|
|
46
45
|
// TODO: this likely needs to be secured in some way
|
|
47
46
|
.get("/:appId/:path*", controller.serveApp);
|
|
48
47
|
module.exports = router;
|