@budibase/server 1.3.12-alpha.3 → 1.3.14
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__/mongodb.ts +1 -1
- package/builder/assets/{index.7886c551.css → index.a70e216a.css} +2 -2
- package/builder/assets/index.d8428ac8.js +876 -0
- package/builder/assets/vendor.5e1fe644.css +1 -0
- package/builder/assets/vendor.67dbd8fa.js +248 -0
- package/builder/index.html +4 -2
- package/coverage/clover.xml +335 -355
- package/coverage/coverage-final.json +22 -22
- package/coverage/lcov-report/api/controllers/apikeys.js.html +1 -1
- package/coverage/lcov-report/api/controllers/auth.js.html +1 -1
- package/coverage/lcov-report/api/controllers/automation.js.html +1 -1
- package/coverage/lcov-report/api/controllers/backup.js.html +8 -5
- package/coverage/lcov-report/api/controllers/cloud.js.html +1 -1
- package/coverage/lcov-report/api/controllers/component.js.html +13 -82
- package/coverage/lcov-report/api/controllers/datasource.js.html +20 -20
- package/coverage/lcov-report/api/controllers/dev.js.html +1 -1
- package/coverage/lcov-report/api/controllers/index.html +32 -32
- package/coverage/lcov-report/api/controllers/integration.js.html +6 -6
- 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/migrations.js.html +1 -1
- package/coverage/lcov-report/api/controllers/permission.js.html +1 -1
- package/coverage/lcov-report/api/controllers/query/index.html +1 -1
- package/coverage/lcov-report/api/controllers/query/validation.js.html +1 -1
- package/coverage/lcov-report/api/controllers/role.js.html +1 -1
- package/coverage/lcov-report/api/controllers/routing.js.html +1 -1
- package/coverage/lcov-report/api/controllers/row/external.js.html +1 -1
- package/coverage/lcov-report/api/controllers/row/index.html +1 -1
- package/coverage/lcov-report/api/controllers/row/internal.js.html +1 -1
- package/coverage/lcov-report/api/controllers/row/internalSearch.js.html +1 -1
- package/coverage/lcov-report/api/controllers/row/staticFormula.js.html +1 -1
- package/coverage/lcov-report/api/controllers/row/utils.js.html +1 -1
- package/coverage/lcov-report/api/controllers/screen.js.html +12 -204
- package/coverage/lcov-report/api/controllers/script.js.html +1 -1
- package/coverage/lcov-report/api/controllers/table/bulkFormula.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/templates.js.html +1 -1
- package/coverage/lcov-report/api/controllers/user.js.html +1 -1
- package/coverage/lcov-report/api/controllers/view/exporters.js.html +1 -1
- package/coverage/lcov-report/api/controllers/view/index.html +1 -1
- package/coverage/lcov-report/api/controllers/view/index.js.html +1 -1
- package/coverage/lcov-report/api/controllers/view/utils.js.html +1 -1
- package/coverage/lcov-report/api/controllers/view/viewBuilder.js.html +1 -1
- package/coverage/lcov-report/api/controllers/webhook.js.html +1 -1
- package/coverage/lcov-report/api/index.html +1 -1
- package/coverage/lcov-report/api/index.js.html +12 -12
- package/coverage/lcov-report/api/routes/analytics.js.html +1 -1
- package/coverage/lcov-report/api/routes/apikeys.js.html +1 -1
- package/coverage/lcov-report/api/routes/auth.js.html +1 -1
- package/coverage/lcov-report/api/routes/automation.js.html +1 -1
- package/coverage/lcov-report/api/routes/backup.js.html +1 -1
- package/coverage/lcov-report/api/routes/cloud.js.html +1 -1
- package/coverage/lcov-report/api/routes/component.js.html +1 -1
- package/coverage/lcov-report/api/routes/datasource.js.html +1 -1
- package/coverage/lcov-report/api/routes/deploy.js.html +1 -1
- package/coverage/lcov-report/api/routes/dev.js.html +1 -1
- package/coverage/lcov-report/api/routes/index.html +1 -1
- package/coverage/lcov-report/api/routes/integration.js.html +1 -1
- package/coverage/lcov-report/api/routes/layout.js.html +1 -1
- package/coverage/lcov-report/api/routes/metadata.js.html +1 -1
- package/coverage/lcov-report/api/routes/migrations.js.html +1 -1
- package/coverage/lcov-report/api/routes/permission.js.html +1 -1
- package/coverage/lcov-report/api/routes/query.js.html +1 -1
- package/coverage/lcov-report/api/routes/role.js.html +1 -1
- package/coverage/lcov-report/api/routes/routing.js.html +1 -1
- package/coverage/lcov-report/api/routes/screen.js.html +1 -1
- package/coverage/lcov-report/api/routes/script.js.html +1 -1
- package/coverage/lcov-report/api/routes/table.js.html +1 -1
- package/coverage/lcov-report/api/routes/templates.js.html +1 -1
- package/coverage/lcov-report/api/routes/user.js.html +1 -1
- package/coverage/lcov-report/api/routes/utils/index.html +1 -1
- package/coverage/lcov-report/api/routes/utils/validators.js.html +1 -1
- package/coverage/lcov-report/api/routes/view.js.html +1 -1
- package/coverage/lcov-report/api/routes/webhook.js.html +1 -1
- package/coverage/lcov-report/automations/actions.js.html +1 -1
- package/coverage/lcov-report/automations/automationUtils.js.html +1 -1
- package/coverage/lcov-report/automations/bullboard.js.html +1 -1
- package/coverage/lcov-report/automations/index.html +24 -24
- package/coverage/lcov-report/automations/index.js.html +18 -9
- package/coverage/lcov-report/automations/steps/bash.js.html +1 -1
- package/coverage/lcov-report/automations/steps/delay.js.html +1 -1
- package/coverage/lcov-report/automations/steps/discord.js.html +1 -1
- package/coverage/lcov-report/automations/steps/executeQuery.js.html +1 -1
- package/coverage/lcov-report/automations/steps/executeScript.js.html +1 -1
- package/coverage/lcov-report/automations/steps/filter.js.html +1 -1
- package/coverage/lcov-report/automations/steps/index.html +1 -1
- package/coverage/lcov-report/automations/steps/integromat.js.html +1 -1
- package/coverage/lcov-report/automations/steps/loop.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 +126 -24
- package/coverage/lcov-report/constants/index.html +1 -1
- package/coverage/lcov-report/constants/index.js.html +1 -1
- package/coverage/lcov-report/constants/layouts.js.html +1 -1
- package/coverage/lcov-report/constants/screens.js.html +1 -1
- package/coverage/lcov-report/db/inMemoryView.js.html +1 -1
- package/coverage/lcov-report/db/index.html +18 -18
- 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 +20 -56
- 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 +48 -48
- 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/builder.js.html +12 -12
- package/coverage/lcov-report/middleware/currentapp.js.html +33 -33
- package/coverage/lcov-report/middleware/index.html +1 -1
- package/coverage/lcov-report/middleware/joi-validator.js.html +1 -1
- package/coverage/lcov-report/middleware/publicApi.js.html +1 -1
- package/coverage/lcov-report/middleware/resourceId.js.html +7 -7
- package/coverage/lcov-report/middleware/selfhost.js.html +1 -1
- package/coverage/lcov-report/middleware/utils.js.html +2 -2
- package/coverage/lcov-report/utilities/budibaseDir.js.html +3 -3
- package/coverage/lcov-report/utilities/centralPath.js.html +4 -4
- package/coverage/lcov-report/utilities/csvParser.js.html +1 -1
- package/coverage/lcov-report/utilities/global.js.html +16 -16
- package/coverage/lcov-report/utilities/index.html +19 -19
- package/coverage/lcov-report/utilities/index.js.html +66 -42
- 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 +5 -5
- package/coverage/lcov-report/utilities/rowProcessor/index.js.html +1 -1
- package/coverage/lcov-report/utilities/rowProcessor/utils.js.html +4 -4
- package/coverage/lcov-report/utilities/scriptRunner.js.html +1 -1
- package/coverage/lcov-report/utilities/security.js.html +2 -2
- package/coverage/lcov-report/utilities/statusCodes.js.html +1 -1
- package/coverage/lcov-report/utilities/usageQuota/index.html +1 -1
- package/coverage/lcov-report/utilities/usageQuota/rows.js.html +6 -3
- package/coverage/lcov-report/utilities/usageQuota/usageQuoteReset.js.html +1 -1
- package/coverage/lcov-report/utilities/users.js.html +1 -1
- package/coverage/lcov-report/utilities/workerRequests.js.html +1 -1
- package/coverage/lcov.info +604 -652
- package/dist/api/controllers/application.js +5 -10
- package/dist/api/controllers/backup.js +2 -1
- package/dist/api/controllers/component.js +1 -18
- package/dist/api/controllers/datasource.js +4 -4
- package/dist/api/controllers/deploy/index.js +17 -2
- package/dist/api/controllers/integration.js +4 -4
- package/dist/api/controllers/row/ExternalRequest.js +1 -1
- package/dist/api/controllers/screen.js +2 -51
- package/dist/api/controllers/static/index.js +0 -1
- package/dist/api/controllers/static/templates/BudibaseApp.svelte +0 -10
- package/dist/api/controllers/static/templates/preview.hbs +1 -3
- package/dist/api/routes/index.js +0 -2
- package/dist/api/routes/static.js +1 -1
- package/dist/app.js +0 -9
- package/dist/automations/index.js +10 -5
- package/dist/automations/triggers.js +39 -5
- package/dist/automations/utils.js +16 -7
- package/dist/db/utils.js +1 -10
- package/dist/environment.js +0 -1
- package/dist/integrations/airtable.js +129 -126
- package/dist/integrations/arangodb.js +89 -86
- package/dist/integrations/base/query.js +2 -2
- package/dist/integrations/couchdb.js +83 -80
- package/dist/integrations/dynamodb.js +164 -161
- package/dist/integrations/elasticsearch.js +138 -135
- package/dist/integrations/firebase.js +157 -154
- package/dist/integrations/googlesheets.js +327 -323
- package/dist/integrations/index.js +51 -93
- package/dist/integrations/microsoftSqlServer.js +243 -240
- package/dist/integrations/mongodb.js +242 -239
- package/dist/integrations/mysql.js +219 -215
- package/dist/integrations/oracle.js +322 -318
- package/dist/integrations/postgres.js +265 -262
- package/dist/integrations/redis.js +139 -134
- package/dist/integrations/rest.js +296 -278
- package/dist/integrations/s3.js +64 -61
- package/dist/integrations/snowflake.js +86 -83
- package/dist/package.json +6 -8
- package/dist/threads/automation.js +6 -0
- package/dist/threads/query.js +2 -2
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/utilities/fileSystem/index.js +6 -71
- package/dist/utilities/index.js +8 -0
- package/dist/utilities/rowProcessor/utils.js +1 -1
- package/dist/utilities/usageQuota/rows.js +2 -1
- package/package.json +7 -9
- package/scripts/dev/manage.js +0 -1
- package/src/api/controllers/application.ts +2 -6
- package/src/api/controllers/backup.js +2 -1
- package/src/api/controllers/component.js +2 -25
- package/src/api/controllers/datasource.js +4 -4
- package/src/api/controllers/deploy/index.ts +17 -4
- package/src/api/controllers/integration.js +4 -4
- package/src/api/controllers/row/ExternalRequest.ts +1 -1
- package/src/api/controllers/screen.js +1 -65
- package/src/api/controllers/static/index.ts +0 -1
- package/src/api/controllers/static/templates/BudibaseApp.svelte +0 -10
- package/src/api/controllers/static/templates/preview.hbs +1 -3
- package/src/api/routes/index.ts +0 -2
- package/src/api/routes/static.ts +1 -1
- package/src/api/routes/tests/query.spec.js +28 -11
- package/src/api/routes/tests/static.spec.js +2 -2
- package/src/app.ts +0 -12
- package/src/automations/index.js +6 -3
- package/src/automations/triggers.js +44 -10
- package/src/automations/utils.ts +21 -9
- package/src/db/utils.js +0 -12
- package/src/definitions/datasource.ts +1 -0
- package/src/environment.js +0 -1
- package/src/integrations/airtable.ts +118 -116
- package/src/integrations/arangodb.ts +89 -87
- package/src/integrations/base/query.ts +2 -2
- package/src/integrations/couchdb.ts +89 -83
- package/src/integrations/dynamodb.ts +175 -173
- package/src/integrations/elasticsearch.ts +122 -120
- package/src/integrations/firebase.ts +159 -157
- package/src/integrations/googlesheets.ts +338 -328
- package/src/integrations/index.ts +21 -59
- package/src/integrations/microsoftSqlServer.ts +251 -249
- package/src/integrations/mongodb.ts +258 -261
- package/src/integrations/mysql.ts +234 -229
- package/src/integrations/oracle.ts +380 -373
- package/src/integrations/postgres.ts +268 -264
- package/src/integrations/redis.ts +132 -128
- package/src/integrations/rest.ts +330 -312
- package/src/integrations/s3.ts +71 -68
- package/src/integrations/snowflake.ts +82 -80
- package/src/integrations/tests/{airtable.spec.ts → airtable.spec.js} +18 -21
- package/src/integrations/tests/{arangodb.spec.ts → arangodb.spec.js} +9 -12
- package/src/integrations/tests/{couchdb.spec.ts → couchdb.spec.js} +27 -33
- package/src/integrations/tests/{dynamodb.spec.ts → dynamodb.spec.js} +41 -45
- package/src/integrations/tests/{elasticsearch.spec.ts → elasticsearch.spec.js} +21 -22
- package/src/integrations/tests/{firebase.spec.ts → firebase.spec.js} +28 -33
- package/src/integrations/tests/{microsoftSqlServer.spec.ts → microsoftSqlServer.spec.js} +11 -12
- package/src/integrations/tests/{mongo.spec.ts → mongo.spec.js} +35 -46
- package/src/integrations/tests/{mysql.spec.ts → mysql.spec.js} +15 -17
- package/src/integrations/tests/{oracle.spec.ts → oracle.spec.js} +17 -19
- package/src/integrations/tests/{postgres.spec.ts → postgres.spec.js} +17 -19
- package/src/integrations/tests/{redis.spec.ts → redis.spec.js} +18 -27
- package/src/integrations/tests/{rest.spec.ts → rest.spec.js} +49 -22
- package/src/integrations/tests/{s3.spec.ts → s3.spec.js} +8 -10
- package/src/integrations/tests/{sql.spec.ts → sql.spec.js} +177 -228
- package/src/module.d.ts +0 -1
- package/src/threads/automation.ts +6 -0
- package/src/threads/query.ts +2 -2
- package/src/utilities/fileSystem/index.js +6 -75
- package/src/utilities/index.js +8 -0
- package/src/utilities/rowProcessor/utils.js +1 -1
- package/src/utilities/usageQuota/rows.js +2 -1
- package/builder/assets/index.e759397f.js +0 -994
- package/dist/api/controllers/plugin.js +0 -119
- package/dist/api/routes/plugin.js +0 -38
- package/dist/watch.js +0 -77
- package/src/api/controllers/plugin.ts +0 -110
- package/src/api/routes/plugin.ts +0 -13
- package/src/watch.ts +0 -38
package/src/app.ts
CHANGED
|
@@ -26,12 +26,10 @@ const bullboard = require("./automations/bullboard")
|
|
|
26
26
|
const { logAlert } = require("@budibase/backend-core/logging")
|
|
27
27
|
const { pinoSettings } = require("@budibase/backend-core")
|
|
28
28
|
const { Thread } = require("./threads")
|
|
29
|
-
const fs = require("fs")
|
|
30
29
|
import redis from "./utilities/redis"
|
|
31
30
|
import * as migrations from "./migrations"
|
|
32
31
|
import { events, installation, tenancy } from "@budibase/backend-core"
|
|
33
32
|
import { createAdminUser, getChecklist } from "./utilities/workerRequests"
|
|
34
|
-
import { watch } from "./watch"
|
|
35
33
|
|
|
36
34
|
const app = new Koa()
|
|
37
35
|
|
|
@@ -141,16 +139,6 @@ module.exports = server.listen(env.PORT || 0, async () => {
|
|
|
141
139
|
}
|
|
142
140
|
}
|
|
143
141
|
|
|
144
|
-
// monitor plugin directory if required
|
|
145
|
-
if (
|
|
146
|
-
env.SELF_HOSTED &&
|
|
147
|
-
!env.MULTI_TENANCY &&
|
|
148
|
-
env.PLUGINS_DIR &&
|
|
149
|
-
fs.existsSync(env.PLUGINS_DIR)
|
|
150
|
-
) {
|
|
151
|
-
watch()
|
|
152
|
-
}
|
|
153
|
-
|
|
154
142
|
// check for version updates
|
|
155
143
|
await installation.checkInstallVersion()
|
|
156
144
|
|
package/src/automations/index.js
CHANGED
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
const { processEvent } = require("./utils")
|
|
2
2
|
const { queue, shutdown } = require("./bullboard")
|
|
3
|
-
const { TRIGGER_DEFINITIONS } = require("./triggers")
|
|
3
|
+
const { TRIGGER_DEFINITIONS, rebootTrigger } = require("./triggers")
|
|
4
4
|
const { ACTION_DEFINITIONS } = require("./actions")
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* This module is built purely to kick off the worker farm and manage the inputs/outputs
|
|
8
8
|
*/
|
|
9
|
-
exports.init = function () {
|
|
9
|
+
exports.init = async function () {
|
|
10
10
|
// this promise will not complete
|
|
11
|
-
|
|
11
|
+
const promise = queue.process(async job => {
|
|
12
12
|
await processEvent(job)
|
|
13
13
|
})
|
|
14
|
+
// on init we need to trigger any reboot automations
|
|
15
|
+
await rebootTrigger()
|
|
16
|
+
return promise
|
|
14
17
|
}
|
|
15
18
|
|
|
16
19
|
exports.getQueues = () => {
|
|
@@ -9,6 +9,7 @@ const { checkTestFlag } = require("../utilities/redis")
|
|
|
9
9
|
const utils = require("./utils")
|
|
10
10
|
const env = require("../environment")
|
|
11
11
|
const { doInAppContext, getAppDB } = require("@budibase/backend-core/context")
|
|
12
|
+
const { getAllApps } = require("@budibase/backend-core/db")
|
|
12
13
|
|
|
13
14
|
const TRIGGER_DEFINITIONS = definitions
|
|
14
15
|
const JOB_OPTS = {
|
|
@@ -16,24 +17,27 @@ const JOB_OPTS = {
|
|
|
16
17
|
removeOnFail: true,
|
|
17
18
|
}
|
|
18
19
|
|
|
20
|
+
async function getAllAutomations() {
|
|
21
|
+
const db = getAppDB()
|
|
22
|
+
let automations = await db.allDocs(
|
|
23
|
+
getAutomationParams(null, { include_docs: true })
|
|
24
|
+
)
|
|
25
|
+
return automations.rows.map(row => row.doc)
|
|
26
|
+
}
|
|
27
|
+
|
|
19
28
|
async function queueRelevantRowAutomations(event, eventType) {
|
|
20
29
|
if (event.appId == null) {
|
|
21
30
|
throw `No appId specified for ${eventType} - check event emitters.`
|
|
22
31
|
}
|
|
23
32
|
|
|
24
33
|
doInAppContext(event.appId, async () => {
|
|
25
|
-
|
|
26
|
-
let automations = await db.allDocs(
|
|
27
|
-
getAutomationParams(null, { include_docs: true })
|
|
28
|
-
)
|
|
34
|
+
let automations = await getAllAutomations()
|
|
29
35
|
|
|
30
36
|
// filter down to the correct event type
|
|
31
|
-
automations = automations.
|
|
32
|
-
|
|
33
|
-
.
|
|
34
|
-
|
|
35
|
-
return trigger && trigger.event === eventType
|
|
36
|
-
})
|
|
37
|
+
automations = automations.filter(automation => {
|
|
38
|
+
const trigger = automation.definition.trigger
|
|
39
|
+
return trigger && trigger.event === eventType
|
|
40
|
+
})
|
|
37
41
|
|
|
38
42
|
for (let automation of automations) {
|
|
39
43
|
let automationDef = automation.definition
|
|
@@ -110,4 +114,34 @@ exports.externalTrigger = async function (
|
|
|
110
114
|
}
|
|
111
115
|
}
|
|
112
116
|
|
|
117
|
+
exports.rebootTrigger = async () => {
|
|
118
|
+
// reboot cron option is only available on the main thread at
|
|
119
|
+
// startup and only usable in self host
|
|
120
|
+
if (env.isInThread() || !env.SELF_HOSTED) {
|
|
121
|
+
return
|
|
122
|
+
}
|
|
123
|
+
// iterate through all production apps, find the reboot crons
|
|
124
|
+
// and trigger events for them
|
|
125
|
+
const appIds = await getAllApps({ dev: false, idsOnly: true })
|
|
126
|
+
for (let prodAppId of appIds) {
|
|
127
|
+
await doInAppContext(prodAppId, async () => {
|
|
128
|
+
let automations = await getAllAutomations()
|
|
129
|
+
let rebootEvents = []
|
|
130
|
+
for (let automation of automations) {
|
|
131
|
+
if (utils.isRebootTrigger(automation)) {
|
|
132
|
+
const job = {
|
|
133
|
+
automation,
|
|
134
|
+
event: {
|
|
135
|
+
appId: prodAppId,
|
|
136
|
+
timestamp: Date.now(),
|
|
137
|
+
},
|
|
138
|
+
}
|
|
139
|
+
rebootEvents.push(queue.add(job, JOB_OPTS))
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
await Promise.all(rebootEvents)
|
|
143
|
+
})
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
113
147
|
exports.TRIGGER_DEFINITIONS = TRIGGER_DEFINITIONS
|
package/src/automations/utils.ts
CHANGED
|
@@ -17,6 +17,7 @@ import { tenancy } from "@budibase/backend-core"
|
|
|
17
17
|
import { quotas } from "@budibase/pro"
|
|
18
18
|
import { Automation } from "@budibase/types"
|
|
19
19
|
|
|
20
|
+
const REBOOT_CRON = "@reboot"
|
|
20
21
|
const WH_STEP_ID = definitions.WEBHOOK.stepId
|
|
21
22
|
const CRON_STEP_ID = definitions.CRON.stepId
|
|
22
23
|
const Runner = new Thread(ThreadType.AUTOMATION)
|
|
@@ -109,22 +110,33 @@ export async function clearMetadata() {
|
|
|
109
110
|
await db.bulkDocs(automationMetadata)
|
|
110
111
|
}
|
|
111
112
|
|
|
113
|
+
export function isCronTrigger(auto: Automation) {
|
|
114
|
+
return (
|
|
115
|
+
auto &&
|
|
116
|
+
auto.definition.trigger &&
|
|
117
|
+
auto.definition.trigger.stepId === CRON_STEP_ID
|
|
118
|
+
)
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export function isRebootTrigger(auto: Automation) {
|
|
122
|
+
const trigger = auto ? auto.definition.trigger : null
|
|
123
|
+
return isCronTrigger(auto) && trigger?.inputs.cron === REBOOT_CRON
|
|
124
|
+
}
|
|
125
|
+
|
|
112
126
|
/**
|
|
113
127
|
* This function handles checking of any cron jobs that need to be enabled/updated.
|
|
114
128
|
* @param {string} appId The ID of the app in which we are checking for webhooks
|
|
115
129
|
* @param {object|undefined} automation The automation object to be updated.
|
|
116
130
|
*/
|
|
117
|
-
export async function enableCronTrigger(appId: any, automation:
|
|
131
|
+
export async function enableCronTrigger(appId: any, automation: Automation) {
|
|
118
132
|
const trigger = automation ? automation.definition.trigger : null
|
|
119
|
-
|
|
120
|
-
return (
|
|
121
|
-
auto &&
|
|
122
|
-
auto.definition.trigger &&
|
|
123
|
-
auto.definition.trigger.stepId === CRON_STEP_ID
|
|
124
|
-
)
|
|
125
|
-
}
|
|
133
|
+
|
|
126
134
|
// need to create cron job
|
|
127
|
-
if (
|
|
135
|
+
if (
|
|
136
|
+
isCronTrigger(automation) &&
|
|
137
|
+
!isRebootTrigger(automation) &&
|
|
138
|
+
trigger?.inputs.cron
|
|
139
|
+
) {
|
|
128
140
|
// make a job id rather than letting Bull decide, makes it easier to handle on way out
|
|
129
141
|
const jobId = `${appId}_cron_${newid()}`
|
|
130
142
|
const job: any = await queue.add(
|
package/src/db/utils.js
CHANGED
|
@@ -42,7 +42,6 @@ const DocumentType = {
|
|
|
42
42
|
MEM_VIEW: "view",
|
|
43
43
|
USER_FLAG: "flag",
|
|
44
44
|
AUTOMATION_METADATA: "meta_au",
|
|
45
|
-
PLUGIN: "plg",
|
|
46
45
|
}
|
|
47
46
|
|
|
48
47
|
const InternalTables = {
|
|
@@ -371,10 +370,6 @@ exports.getMemoryViewParams = (otherProps = {}) => {
|
|
|
371
370
|
return getDocParams(DocumentType.MEM_VIEW, null, otherProps)
|
|
372
371
|
}
|
|
373
372
|
|
|
374
|
-
exports.generatePluginID = name => {
|
|
375
|
-
return `${DocumentType.PLUGIN}${SEPARATOR}${name}`
|
|
376
|
-
}
|
|
377
|
-
|
|
378
373
|
/**
|
|
379
374
|
* This can be used with the db.allDocs to get a list of IDs
|
|
380
375
|
*/
|
|
@@ -384,10 +379,3 @@ exports.getMultiIDParams = ids => {
|
|
|
384
379
|
include_docs: true,
|
|
385
380
|
}
|
|
386
381
|
}
|
|
387
|
-
|
|
388
|
-
/**
|
|
389
|
-
* Gets parameters for retrieving automations, this is a utility function for the getDocParams function.
|
|
390
|
-
*/
|
|
391
|
-
exports.getPluginParams = (pluginId = null, otherProps = {}) => {
|
|
392
|
-
return getDocParams(DocumentType.PLUGIN, pluginId, otherProps)
|
|
393
|
-
}
|
package/src/environment.js
CHANGED
|
@@ -74,7 +74,6 @@ module.exports = {
|
|
|
74
74
|
SQL_MAX_ROWS: process.env.SQL_MAX_ROWS,
|
|
75
75
|
BB_ADMIN_USER_EMAIL: process.env.BB_ADMIN_USER_EMAIL,
|
|
76
76
|
BB_ADMIN_USER_PASSWORD: process.env.BB_ADMIN_USER_PASSWORD,
|
|
77
|
-
PLUGINS_DIR: process.env.PLUGINS_DIR || "/plugins",
|
|
78
77
|
// flags
|
|
79
78
|
ALLOW_DEV_AUTOMATIONS: process.env.ALLOW_DEV_AUTOMATIONS,
|
|
80
79
|
DISABLE_THREADING: process.env.DISABLE_THREADING,
|
|
@@ -5,144 +5,146 @@ import {
|
|
|
5
5
|
IntegrationBase,
|
|
6
6
|
} from "@budibase/types"
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
module AirtableModule {
|
|
9
|
+
const Airtable = require("airtable")
|
|
9
10
|
|
|
10
|
-
interface AirtableConfig {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
11
|
+
interface AirtableConfig {
|
|
12
|
+
apiKey: string
|
|
13
|
+
base: string
|
|
14
|
+
}
|
|
14
15
|
|
|
15
|
-
const SCHEMA: Integration = {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
},
|
|
32
|
-
},
|
|
33
|
-
query: {
|
|
34
|
-
create: {
|
|
35
|
-
type: QueryType.FIELDS,
|
|
36
|
-
customisable: true,
|
|
37
|
-
fields: {
|
|
38
|
-
table: {
|
|
39
|
-
type: DatasourceFieldType.STRING,
|
|
40
|
-
required: true,
|
|
41
|
-
},
|
|
16
|
+
const SCHEMA: Integration = {
|
|
17
|
+
docs: "https://airtable.com/api",
|
|
18
|
+
description:
|
|
19
|
+
"Airtable is a spreadsheet-database hybrid, with the features of a database but applied to a spreadsheet.",
|
|
20
|
+
friendlyName: "Airtable",
|
|
21
|
+
type: "Spreadsheet",
|
|
22
|
+
datasource: {
|
|
23
|
+
apiKey: {
|
|
24
|
+
type: DatasourceFieldType.PASSWORD,
|
|
25
|
+
default: "enter api key",
|
|
26
|
+
required: true,
|
|
27
|
+
},
|
|
28
|
+
base: {
|
|
29
|
+
type: DatasourceFieldType.STRING,
|
|
30
|
+
default: "mybase",
|
|
31
|
+
required: true,
|
|
42
32
|
},
|
|
43
33
|
},
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
required: true,
|
|
54
|
-
},
|
|
55
|
-
numRecords: {
|
|
56
|
-
type: DatasourceFieldType.NUMBER,
|
|
57
|
-
default: 10,
|
|
34
|
+
query: {
|
|
35
|
+
create: {
|
|
36
|
+
type: QueryType.FIELDS,
|
|
37
|
+
customisable: true,
|
|
38
|
+
fields: {
|
|
39
|
+
table: {
|
|
40
|
+
type: DatasourceFieldType.STRING,
|
|
41
|
+
required: true,
|
|
42
|
+
},
|
|
58
43
|
},
|
|
59
44
|
},
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
45
|
+
read: {
|
|
46
|
+
type: QueryType.FIELDS,
|
|
47
|
+
fields: {
|
|
48
|
+
table: {
|
|
49
|
+
type: DatasourceFieldType.STRING,
|
|
50
|
+
required: true,
|
|
51
|
+
},
|
|
52
|
+
view: {
|
|
53
|
+
type: DatasourceFieldType.STRING,
|
|
54
|
+
required: true,
|
|
55
|
+
},
|
|
56
|
+
numRecords: {
|
|
57
|
+
type: DatasourceFieldType.NUMBER,
|
|
58
|
+
default: 10,
|
|
59
|
+
},
|
|
69
60
|
},
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
61
|
+
},
|
|
62
|
+
update: {
|
|
63
|
+
type: QueryType.FIELDS,
|
|
64
|
+
customisable: true,
|
|
65
|
+
fields: {
|
|
66
|
+
id: {
|
|
67
|
+
display: "Record ID",
|
|
68
|
+
type: DatasourceFieldType.STRING,
|
|
69
|
+
required: true,
|
|
70
|
+
},
|
|
71
|
+
table: {
|
|
72
|
+
type: DatasourceFieldType.STRING,
|
|
73
|
+
required: true,
|
|
74
|
+
},
|
|
73
75
|
},
|
|
74
76
|
},
|
|
77
|
+
delete: {
|
|
78
|
+
type: QueryType.JSON,
|
|
79
|
+
},
|
|
75
80
|
},
|
|
76
|
-
|
|
77
|
-
type: QueryType.JSON,
|
|
78
|
-
},
|
|
79
|
-
},
|
|
80
|
-
}
|
|
81
|
+
}
|
|
81
82
|
|
|
82
|
-
class AirtableIntegration implements IntegrationBase {
|
|
83
|
-
|
|
84
|
-
|
|
83
|
+
class AirtableIntegration implements IntegrationBase {
|
|
84
|
+
private config: AirtableConfig
|
|
85
|
+
private client: any
|
|
85
86
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
87
|
+
constructor(config: AirtableConfig) {
|
|
88
|
+
this.config = config
|
|
89
|
+
this.client = new Airtable(config).base(config.base)
|
|
90
|
+
}
|
|
90
91
|
|
|
91
|
-
|
|
92
|
-
|
|
92
|
+
async create(query: { table: any; json: any }) {
|
|
93
|
+
const { table, json } = query
|
|
93
94
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
95
|
+
try {
|
|
96
|
+
return await this.client(table).create([
|
|
97
|
+
{
|
|
98
|
+
fields: json,
|
|
99
|
+
},
|
|
100
|
+
])
|
|
101
|
+
} catch (err) {
|
|
102
|
+
console.error("Error writing to airtable", err)
|
|
103
|
+
throw err
|
|
104
|
+
}
|
|
103
105
|
}
|
|
104
|
-
}
|
|
105
106
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
107
|
+
async read(query: { table: any; numRecords: any; view: any }) {
|
|
108
|
+
try {
|
|
109
|
+
const records = await this.client(query.table)
|
|
110
|
+
.select({ maxRecords: query.numRecords || 10, view: query.view })
|
|
111
|
+
.firstPage()
|
|
112
|
+
// @ts-ignore
|
|
113
|
+
return records.map(({ fields }) => fields)
|
|
114
|
+
} catch (err) {
|
|
115
|
+
console.error("Error writing to airtable", err)
|
|
116
|
+
return []
|
|
117
|
+
}
|
|
116
118
|
}
|
|
117
|
-
}
|
|
118
119
|
|
|
119
|
-
|
|
120
|
-
|
|
120
|
+
async update(query: { table: any; id: any; json: any }) {
|
|
121
|
+
const { table, id, json } = query
|
|
121
122
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
123
|
+
try {
|
|
124
|
+
return await this.client(table).update([
|
|
125
|
+
{
|
|
126
|
+
id,
|
|
127
|
+
fields: json,
|
|
128
|
+
},
|
|
129
|
+
])
|
|
130
|
+
} catch (err) {
|
|
131
|
+
console.error("Error writing to airtable", err)
|
|
132
|
+
throw err
|
|
133
|
+
}
|
|
132
134
|
}
|
|
133
|
-
}
|
|
134
135
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
136
|
+
async delete(query: { table: any; ids: any }) {
|
|
137
|
+
try {
|
|
138
|
+
return await this.client(query.table).destroy(query.ids)
|
|
139
|
+
} catch (err) {
|
|
140
|
+
console.error("Error writing to airtable", err)
|
|
141
|
+
throw err
|
|
142
|
+
}
|
|
141
143
|
}
|
|
142
144
|
}
|
|
143
|
-
}
|
|
144
145
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
146
|
+
module.exports = {
|
|
147
|
+
schema: SCHEMA,
|
|
148
|
+
integration: AirtableIntegration,
|
|
149
|
+
}
|
|
148
150
|
}
|