@budibase/server 0.9.185-alpha.2 → 0.9.185-alpha.20
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/Dockerfile +7 -1
- package/__mocks__/oracledb.ts +31 -0
- package/builder/assets/bb-space-man.5be51a45.svg +290 -0
- package/builder/assets/index.7d405e74.css +1 -0
- package/builder/assets/index.83e08172.js +1316 -0
- package/builder/assets/oracle.66592424.png +0 -0
- package/builder/assets/vendor.470042a4.js +152 -0
- package/builder/assets/vendor.5e1fe644.css +1 -0
- package/builder/index.html +4 -4
- package/coverage/clover.xml +785 -687
- package/coverage/coverage-final.json +90 -88
- package/coverage/lcov-report/api/controllers/analytics.js.html +2 -2
- package/coverage/lcov-report/api/controllers/apikeys.js.html +2 -2
- package/coverage/lcov-report/api/controllers/application.js.html +43 -13
- package/coverage/lcov-report/api/controllers/auth.js.html +7 -7
- package/coverage/lcov-report/api/controllers/automation.js.html +3 -3
- package/coverage/lcov-report/api/controllers/backup.js.html +1 -1
- package/coverage/lcov-report/api/controllers/cloud.js.html +1 -1
- package/coverage/lcov-report/api/controllers/component.js.html +4 -4
- package/coverage/lcov-report/api/controllers/datasource.js.html +129 -21
- package/coverage/lcov-report/api/controllers/dev.js.html +16 -7
- package/coverage/lcov-report/api/controllers/hosting.js.html +10 -10
- package/coverage/lcov-report/api/controllers/index.html +77 -77
- package/coverage/lcov-report/api/controllers/integration.js.html +1 -1
- package/coverage/lcov-report/api/controllers/layout.js.html +3 -3
- package/coverage/lcov-report/api/controllers/metadata.js.html +3 -3
- package/coverage/lcov-report/api/controllers/permission.js.html +3 -3
- package/coverage/lcov-report/api/controllers/query.js.html +48 -210
- package/coverage/lcov-report/api/controllers/role.js.html +9 -9
- package/coverage/lcov-report/api/controllers/routing.js.html +3 -3
- package/coverage/lcov-report/api/controllers/row/external.js.html +2 -2
- package/coverage/lcov-report/api/controllers/row/index.html +10 -10
- package/coverage/lcov-report/api/controllers/row/index.js.html +2 -2
- package/coverage/lcov-report/api/controllers/row/internal.js.html +9 -9
- package/coverage/lcov-report/api/controllers/row/internalSearch.js.html +2 -2
- package/coverage/lcov-report/api/controllers/row/utils.js.html +2 -2
- package/coverage/lcov-report/api/controllers/screen.js.html +2 -2
- package/coverage/lcov-report/api/controllers/script.js.html +3 -3
- package/coverage/lcov-report/api/controllers/table/external.js.html +29 -8
- package/coverage/lcov-report/api/controllers/table/index.html +20 -20
- package/coverage/lcov-report/api/controllers/table/index.js.html +3 -3
- package/coverage/lcov-report/api/controllers/table/internal.js.html +2 -2
- package/coverage/lcov-report/api/controllers/table/utils.js.html +8 -8
- package/coverage/lcov-report/api/controllers/templates.js.html +4 -4
- package/coverage/lcov-report/api/controllers/user.js.html +2 -2
- package/coverage/lcov-report/api/controllers/view/exporters.js.html +1 -1
- package/coverage/lcov-report/api/controllers/view/index.html +9 -9
- package/coverage/lcov-report/api/controllers/view/index.js.html +5 -5
- package/coverage/lcov-report/api/controllers/view/utils.js.html +11 -11
- package/coverage/lcov-report/api/controllers/view/viewBuilder.js.html +3 -3
- package/coverage/lcov-report/api/controllers/webhook.js.html +4 -4
- package/coverage/lcov-report/api/index.html +1 -1
- package/coverage/lcov-report/api/index.js.html +1 -1
- package/coverage/lcov-report/api/routes/analytics.js.html +1 -1
- package/coverage/lcov-report/api/routes/apikeys.js.html +1 -1
- package/coverage/lcov-report/api/routes/application.js.html +1 -1
- package/coverage/lcov-report/api/routes/auth.js.html +1 -1
- package/coverage/lcov-report/api/routes/automation.js.html +1 -1
- package/coverage/lcov-report/api/routes/backup.js.html +1 -1
- package/coverage/lcov-report/api/routes/cloud.js.html +1 -1
- package/coverage/lcov-report/api/routes/component.js.html +1 -1
- package/coverage/lcov-report/api/routes/datasource.js.html +1 -1
- package/coverage/lcov-report/api/routes/deploy.js.html +1 -1
- package/coverage/lcov-report/api/routes/dev.js.html +2 -2
- package/coverage/lcov-report/api/routes/hosting.js.html +1 -1
- package/coverage/lcov-report/api/routes/index.html +4 -4
- package/coverage/lcov-report/api/routes/index.js.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/permission.js.html +1 -1
- package/coverage/lcov-report/api/routes/query.js.html +5 -2
- package/coverage/lcov-report/api/routes/role.js.html +1 -1
- package/coverage/lcov-report/api/routes/routing.js.html +1 -1
- package/coverage/lcov-report/api/routes/row.js.html +1 -1
- package/coverage/lcov-report/api/routes/screen.js.html +1 -1
- package/coverage/lcov-report/api/routes/script.js.html +1 -1
- package/coverage/lcov-report/api/routes/static.js.html +2 -2
- package/coverage/lcov-report/api/routes/table.js.html +1 -1
- package/coverage/lcov-report/api/routes/templates.js.html +1 -1
- package/coverage/lcov-report/api/routes/user.js.html +1 -1
- package/coverage/lcov-report/api/routes/view.js.html +1 -1
- package/coverage/lcov-report/api/routes/webhook.js.html +1 -1
- package/coverage/lcov-report/automations/actions.js.html +2 -2
- package/coverage/lcov-report/automations/automationUtils.js.html +3 -3
- package/coverage/lcov-report/automations/bullboard.js.html +71 -20
- package/coverage/lcov-report/automations/index.html +33 -48
- package/coverage/lcov-report/automations/index.js.html +2 -2
- 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 +3 -3
- package/coverage/lcov-report/automations/steps/executeQuery.js.html +1 -1
- package/coverage/lcov-report/automations/steps/executeScript.js.html +3 -3
- package/coverage/lcov-report/automations/steps/filter.js.html +1 -1
- package/coverage/lcov-report/automations/steps/index.html +14 -14
- package/coverage/lcov-report/automations/steps/integromat.js.html +1 -1
- package/coverage/lcov-report/automations/steps/outgoingWebhook.js.html +3 -3
- package/coverage/lcov-report/automations/steps/queryRows.js.html +3 -3
- 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 +7 -7
- package/coverage/lcov-report/automations/steps/zapier.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/app.js.html +2 -2
- package/coverage/lcov-report/automations/triggerInfo/cron.js.html +2 -2
- package/coverage/lcov-report/automations/triggerInfo/index.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/index.js.html +8 -8
- package/coverage/lcov-report/automations/triggerInfo/rowDeleted.js.html +2 -2
- package/coverage/lcov-report/automations/triggerInfo/rowSaved.js.html +2 -2
- package/coverage/lcov-report/automations/triggerInfo/rowUpdated.js.html +2 -2
- package/coverage/lcov-report/automations/triggerInfo/webhook.js.html +2 -2
- package/coverage/lcov-report/automations/triggers.js.html +22 -10
- package/coverage/lcov-report/automations/utils.js.html +42 -12
- package/coverage/lcov-report/constants/index.html +5 -5
- package/coverage/lcov-report/constants/index.js.html +44 -23
- package/coverage/lcov-report/constants/layouts.js.html +1 -1
- package/coverage/lcov-report/constants/screens.js.html +1 -1
- package/coverage/lcov-report/db/client.js.html +2 -2
- package/coverage/lcov-report/db/inMemoryView.js.html +2 -2
- package/coverage/lcov-report/db/index.html +2 -2
- package/coverage/lcov-report/db/index.js.html +1 -1
- package/coverage/lcov-report/db/linkedRows/LinkController.js.html +6 -6
- package/coverage/lcov-report/db/linkedRows/index.html +10 -10
- package/coverage/lcov-report/db/linkedRows/index.js.html +5 -5
- package/coverage/lcov-report/db/linkedRows/linkUtils.js.html +6 -6
- package/coverage/lcov-report/db/newid.js.html +3 -3
- package/coverage/lcov-report/db/utils.js.html +57 -57
- package/coverage/lcov-report/events/AutomationEmitter.js.html +6 -6
- package/coverage/lcov-report/events/index.html +6 -6
- package/coverage/lcov-report/events/index.js.html +1 -1
- package/coverage/lcov-report/events/utils.js.html +5 -5
- package/coverage/lcov-report/index.html +86 -71
- 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 +2 -2
- package/coverage/lcov-report/middleware/authorized.js.html +4 -4
- package/coverage/lcov-report/middleware/builder.js.html +16 -7
- package/coverage/lcov-report/middleware/currentapp.js.html +6 -6
- package/coverage/lcov-report/middleware/index.html +21 -21
- package/coverage/lcov-report/middleware/joi-validator.js.html +2 -2
- package/coverage/lcov-report/middleware/resourceId.js.html +18 -18
- package/coverage/lcov-report/middleware/selfhost.js.html +2 -2
- package/coverage/lcov-report/middleware/usageQuota.js.html +4 -4
- package/coverage/lcov-report/middleware/utils.js.html +1 -1
- package/coverage/lcov-report/{automations/thread.js.html → threads/automation.js.html} +90 -33
- package/coverage/lcov-report/threads/index.html +141 -0
- package/coverage/lcov-report/threads/index.js.html +278 -0
- package/coverage/lcov-report/threads/query.js.html +278 -0
- 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 +2 -2
- package/coverage/lcov-report/utilities/global.js.html +2 -2
- package/coverage/lcov-report/utilities/index.html +21 -21
- package/coverage/lcov-report/utilities/index.js.html +12 -9
- package/coverage/lcov-report/utilities/queue/inMemoryQueue.js.html +30 -9
- package/coverage/lcov-report/utilities/queue/index.html +14 -14
- 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 +4 -4
- package/coverage/lcov-report/utilities/rowProcessor/index.js.html +2 -2
- package/coverage/lcov-report/utilities/rowProcessor/utils.js.html +3 -3
- package/coverage/lcov-report/utilities/scriptRunner.js.html +16 -7
- package/coverage/lcov-report/utilities/security.js.html +3 -3
- 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 +5 -5
- package/coverage/lcov.info +1247 -1070
- package/dist/api/controllers/application.js +11 -1
- package/dist/api/controllers/datasource.js +31 -7
- package/dist/api/controllers/deploy/index.js +2 -0
- package/dist/api/controllers/dev.js +4 -1
- package/dist/api/controllers/query.js +27 -57
- package/dist/api/controllers/table/external.js +8 -1
- package/dist/api/routes/query.js +1 -1
- package/dist/app.js +2 -11
- package/dist/automations/bullboard.js +37 -10
- package/dist/automations/triggers.js +7 -3
- package/dist/automations/utils.js +11 -2
- package/dist/constants/index.js +6 -0
- package/dist/definitions/datasource.js +1 -0
- package/dist/environment.js +13 -0
- package/dist/integrations/base/IntegrationBase.js +2 -0
- package/dist/integrations/base/sql.js +40 -8
- package/dist/integrations/index.js +6 -0
- package/dist/integrations/mysql.js +3 -1
- package/dist/integrations/oracle.js +345 -0
- package/dist/integrations/utils.js +17 -2
- package/dist/middleware/builder.js +4 -1
- package/dist/package.json +11 -6
- package/dist/{automations/thread.js → threads/automation.js} +26 -8
- package/dist/threads/index.js +64 -0
- package/dist/threads/query.js +64 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utilities/index.js +1 -0
- package/dist/utilities/queue/inMemoryQueue.js +8 -0
- package/dist/utilities/scriptRunner.js +4 -1
- package/package.json +12 -7
- package/scripts/dev/manage.js +1 -0
- package/scripts/integrations/oracle/docker-compose.yml +19 -0
- package/scripts/integrations/oracle/instantclient/linux/x86-64/basiclite-21.4.zip +0 -0
- package/scripts/integrations/oracle/instantclient/linux/x86-64/install.sh +23 -0
- package/scripts/integrations/oracle/oracle.md +90 -0
- package/scripts/integrations/postgres/docker-compose.yml +3 -3
- package/scripts/likeCypress.ts +33 -0
- package/src/api/controllers/application.js +11 -1
- package/src/api/controllers/datasource.js +45 -9
- package/src/api/controllers/deploy/index.js +2 -0
- package/src/api/controllers/dev.js +4 -1
- package/src/api/controllers/query.js +26 -80
- package/src/api/controllers/table/external.js +8 -1
- package/src/api/routes/query.js +1 -0
- package/src/app.ts +2 -10
- package/src/automations/bullboard.js +28 -11
- package/src/automations/tests/automation.spec.js +3 -4
- package/src/automations/triggers.js +7 -3
- package/src/automations/utils.js +12 -2
- package/src/constants/index.js +7 -0
- package/src/definitions/datasource.ts +1 -0
- package/src/environment.js +15 -0
- package/src/integrations/airtable.ts +2 -1
- package/src/integrations/arangodb.ts +2 -1
- package/src/integrations/base/IntegrationBase.ts +6 -0
- package/src/integrations/base/datasourcePlus.ts +2 -1
- package/src/integrations/base/sql.ts +41 -9
- package/src/integrations/couchdb.ts +2 -1
- package/src/integrations/dynamodb.ts +2 -1
- package/src/integrations/elasticsearch.ts +2 -1
- package/src/integrations/index.ts +7 -0
- package/src/integrations/mongodb.ts +2 -1
- package/src/integrations/mysql.ts +1 -1
- package/src/integrations/oracle.ts +445 -0
- package/src/integrations/rest.ts +2 -1
- package/src/integrations/s3.ts +2 -1
- package/src/integrations/tests/oracle.spec.js +94 -0
- package/src/integrations/utils.ts +16 -2
- package/src/middleware/builder.js +4 -1
- package/src/{automations/thread.js → threads/automation.js} +27 -8
- package/src/threads/index.js +66 -0
- package/src/threads/query.js +66 -0
- package/src/utilities/index.js +1 -0
- package/src/utilities/queue/inMemoryQueue.js +7 -0
- package/src/utilities/scriptRunner.js +4 -1
- package/tsconfig.json +1 -1
- package/builder/assets/index.0eadd2f5.js +0 -201
- package/builder/assets/index.a79ec0ef.css +0 -29
- package/builder/assets/vendor.278a305c.js +0 -9
- package/builder/assets/vendor.d75d5eb7.css +0 -1
|
@@ -1,15 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
const
|
|
1
|
+
// when thread starts, make sure it is recorded
|
|
2
|
+
const env = require("../environment")
|
|
3
|
+
env.setInThread()
|
|
4
|
+
const actions = require("../automations/actions")
|
|
5
|
+
const automationUtils = require("../automations/automationUtils")
|
|
3
6
|
const AutomationEmitter = require("../events/AutomationEmitter")
|
|
4
7
|
const { processObject } = require("@budibase/string-templates")
|
|
5
8
|
const { DEFAULT_TENANT_ID } = require("@budibase/auth").constants
|
|
6
9
|
const CouchDB = require("../db")
|
|
7
10
|
const { DocumentTypes, isDevAppID } = require("../db/utils")
|
|
8
11
|
const { doInTenant } = require("@budibase/auth/tenancy")
|
|
9
|
-
const env = require("../environment")
|
|
10
12
|
const usage = require("../utilities/usageQuota")
|
|
13
|
+
const { definitions: triggerDefs } = require("../automations/triggerInfo")
|
|
11
14
|
|
|
12
15
|
const FILTER_STEP_ID = actions.ACTION_DEFINITIONS.FILTER.stepId
|
|
16
|
+
const CRON_STEP_ID = triggerDefs.CRON.stepId
|
|
13
17
|
const STOPPED_STATUS = { success: false, status: "STOPPED" }
|
|
14
18
|
|
|
15
19
|
/**
|
|
@@ -23,6 +27,8 @@ class Orchestrator {
|
|
|
23
27
|
this._chainCount = this._metadata ? this._metadata.automationChainCount : 0
|
|
24
28
|
this._appId = triggerOutput.appId
|
|
25
29
|
this._app = null
|
|
30
|
+
const triggerStepId = automation.definition.trigger.stepId
|
|
31
|
+
triggerOutput = this.cleanupTriggerOutputs(triggerStepId, triggerOutput)
|
|
26
32
|
// remove from context
|
|
27
33
|
delete triggerOutput.appId
|
|
28
34
|
delete triggerOutput.metadata
|
|
@@ -34,11 +40,17 @@ class Orchestrator {
|
|
|
34
40
|
this._emitter = new AutomationEmitter(this._chainCount + 1)
|
|
35
41
|
this.executionOutput = { trigger: {}, steps: [] }
|
|
36
42
|
// setup the execution output
|
|
37
|
-
const triggerStepId = automation.definition.trigger.stepId
|
|
38
43
|
const triggerId = automation.definition.trigger.id
|
|
39
44
|
this.updateExecutionOutput(triggerId, triggerStepId, null, triggerOutput)
|
|
40
45
|
}
|
|
41
46
|
|
|
47
|
+
cleanupTriggerOutputs(stepId, triggerOutput) {
|
|
48
|
+
if (stepId === CRON_STEP_ID) {
|
|
49
|
+
triggerOutput.timestamp = Date.now()
|
|
50
|
+
}
|
|
51
|
+
return triggerOutput
|
|
52
|
+
}
|
|
53
|
+
|
|
42
54
|
async getStepFunctionality(stepId) {
|
|
43
55
|
let step = await actions.getAction(stepId)
|
|
44
56
|
if (step == null) {
|
|
@@ -119,10 +131,17 @@ class Orchestrator {
|
|
|
119
131
|
}
|
|
120
132
|
}
|
|
121
133
|
|
|
122
|
-
module.exports =
|
|
134
|
+
module.exports = (input, callback) => {
|
|
123
135
|
const automationOrchestrator = new Orchestrator(
|
|
124
|
-
|
|
125
|
-
|
|
136
|
+
input.data.automation,
|
|
137
|
+
input.data.event
|
|
126
138
|
)
|
|
127
|
-
|
|
139
|
+
automationOrchestrator
|
|
140
|
+
.execute()
|
|
141
|
+
.then(response => {
|
|
142
|
+
callback(null, response)
|
|
143
|
+
})
|
|
144
|
+
.catch(err => {
|
|
145
|
+
callback(err)
|
|
146
|
+
})
|
|
128
147
|
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
const workerFarm = require("worker-farm")
|
|
2
|
+
const env = require("../environment")
|
|
3
|
+
|
|
4
|
+
const ThreadType = {
|
|
5
|
+
QUERY: "query",
|
|
6
|
+
AUTOMATION: "automation",
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
function typeToFile(type) {
|
|
10
|
+
let filename = null
|
|
11
|
+
switch (type) {
|
|
12
|
+
case ThreadType.QUERY:
|
|
13
|
+
filename = "./query"
|
|
14
|
+
break
|
|
15
|
+
case ThreadType.AUTOMATION:
|
|
16
|
+
filename = "./automation"
|
|
17
|
+
break
|
|
18
|
+
default:
|
|
19
|
+
throw "Unknown thread type"
|
|
20
|
+
}
|
|
21
|
+
return require.resolve(filename)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
class Thread {
|
|
25
|
+
constructor(type, opts = { timeoutMs: null, count: 1 }) {
|
|
26
|
+
this.type = type
|
|
27
|
+
this.count = opts.count ? opts.count : 1
|
|
28
|
+
this.disableThreading =
|
|
29
|
+
env.isTest() ||
|
|
30
|
+
env.DISABLE_THREADING ||
|
|
31
|
+
this.count === 0 ||
|
|
32
|
+
env.isInThread()
|
|
33
|
+
if (!this.disableThreading) {
|
|
34
|
+
const workerOpts = {
|
|
35
|
+
autoStart: true,
|
|
36
|
+
maxConcurrentWorkers: this.count,
|
|
37
|
+
}
|
|
38
|
+
if (opts.timeoutMs) {
|
|
39
|
+
workerOpts.maxCallTime = opts.timeoutMs
|
|
40
|
+
}
|
|
41
|
+
this.workers = workerFarm(workerOpts, typeToFile(type))
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
run(data) {
|
|
46
|
+
return new Promise((resolve, reject) => {
|
|
47
|
+
let fncToCall
|
|
48
|
+
// if in test then don't use threading
|
|
49
|
+
if (this.disableThreading) {
|
|
50
|
+
fncToCall = require(typeToFile(this.type))
|
|
51
|
+
} else {
|
|
52
|
+
fncToCall = this.workers
|
|
53
|
+
}
|
|
54
|
+
fncToCall(data, (err, response) => {
|
|
55
|
+
if (err) {
|
|
56
|
+
reject(err)
|
|
57
|
+
} else {
|
|
58
|
+
resolve(response)
|
|
59
|
+
}
|
|
60
|
+
})
|
|
61
|
+
})
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
module.exports.Thread = Thread
|
|
66
|
+
module.exports.ThreadType = ThreadType
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// when thread starts, make sure it is recorded
|
|
2
|
+
const env = require("../environment")
|
|
3
|
+
env.setInThread()
|
|
4
|
+
const ScriptRunner = require("../utilities/scriptRunner")
|
|
5
|
+
const { integrations } = require("../integrations")
|
|
6
|
+
|
|
7
|
+
function formatResponse(resp) {
|
|
8
|
+
if (typeof resp === "string") {
|
|
9
|
+
try {
|
|
10
|
+
resp = JSON.parse(resp)
|
|
11
|
+
} catch (err) {
|
|
12
|
+
resp = { response: resp }
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
return resp
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
async function runAndTransform(datasource, queryVerb, query, transformer) {
|
|
19
|
+
const Integration = integrations[datasource.source]
|
|
20
|
+
if (!Integration) {
|
|
21
|
+
throw "Integration type does not exist."
|
|
22
|
+
}
|
|
23
|
+
const integration = new Integration(datasource.config)
|
|
24
|
+
|
|
25
|
+
let rows = formatResponse(await integration[queryVerb](query))
|
|
26
|
+
|
|
27
|
+
// transform as required
|
|
28
|
+
if (transformer) {
|
|
29
|
+
const runner = new ScriptRunner(transformer, { data: rows })
|
|
30
|
+
rows = runner.execute()
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// needs to an array for next step
|
|
34
|
+
if (!Array.isArray(rows)) {
|
|
35
|
+
rows = [rows]
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// map into JSON if just raw primitive here
|
|
39
|
+
if (rows.find(row => typeof row !== "object")) {
|
|
40
|
+
rows = rows.map(value => ({ value }))
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// get all the potential fields in the schema
|
|
44
|
+
let keys = rows.flatMap(Object.keys)
|
|
45
|
+
|
|
46
|
+
if (integration.end) {
|
|
47
|
+
integration.end()
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return { rows, keys }
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
module.exports = (input, callback) => {
|
|
54
|
+
runAndTransform(
|
|
55
|
+
input.datasource,
|
|
56
|
+
input.queryVerb,
|
|
57
|
+
input.query,
|
|
58
|
+
input.transformer
|
|
59
|
+
)
|
|
60
|
+
.then(response => {
|
|
61
|
+
callback(null, response)
|
|
62
|
+
})
|
|
63
|
+
.catch(err => {
|
|
64
|
+
callback(err)
|
|
65
|
+
})
|
|
66
|
+
}
|
package/src/utilities/index.js
CHANGED
|
@@ -48,6 +48,7 @@ exports.objectStoreUrl = () => {
|
|
|
48
48
|
* via a specific endpoint (under /api/assets/client).
|
|
49
49
|
* @param {string} appId In production we need the appId to look up the correct bucket, as the
|
|
50
50
|
* version of the client lib may differ between apps.
|
|
51
|
+
* @param {string} version The version to retrieve.
|
|
51
52
|
* @return {string} The URL to be inserted into appPackage response or server rendered
|
|
52
53
|
* app index file.
|
|
53
54
|
*/
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
const fetch = require("node-fetch")
|
|
2
2
|
const { VM, VMScript } = require("vm2")
|
|
3
|
+
const JS_TIMEOUT_MS = 1000
|
|
3
4
|
|
|
4
5
|
class ScriptRunner {
|
|
5
6
|
constructor(script, context) {
|
|
6
7
|
const code = `let fn = () => {\n${script}\n}; results.out = fn();`
|
|
7
|
-
this.vm = new VM(
|
|
8
|
+
this.vm = new VM({
|
|
9
|
+
timeout: JS_TIMEOUT_MS,
|
|
10
|
+
})
|
|
8
11
|
this.results = { out: "" }
|
|
9
12
|
this.vm.setGlobals(context)
|
|
10
13
|
this.vm.setGlobal("fetch", fetch)
|