@budibase/server 1.0.219 → 1.0.220-alpha.2
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/.yarnrc +1 -0
- package/__mocks__/node-fetch.ts +9 -0
- package/builder/assets/index.7786f497.css +6 -0
- package/builder/assets/index.e1885c5f.js +974 -0
- package/builder/assets/{vendor.9bf2fcb4.js → vendor.001dcf8c.js} +163 -163
- package/builder/index.html +3 -3
- package/coverage/clover.xml +1018 -950
- package/coverage/coverage-final.json +31 -31
- 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 +111 -12
- package/coverage/lcov-report/api/controllers/backup.js.html +9 -6
- package/coverage/lcov-report/api/controllers/cloud.js.html +1 -1
- package/coverage/lcov-report/api/controllers/component.js.html +1 -1
- package/coverage/lcov-report/api/controllers/datasource.js.html +16 -16
- package/coverage/lcov-report/api/controllers/dev.js.html +13 -166
- package/coverage/lcov-report/api/controllers/index.html +32 -32
- package/coverage/lcov-report/api/controllers/integration.js.html +1 -1
- package/coverage/lcov-report/api/controllers/layout.js.html +1 -1
- package/coverage/lcov-report/api/controllers/metadata.js.html +1 -1
- package/coverage/lcov-report/api/controllers/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 +47 -17
- package/coverage/lcov-report/api/controllers/row/index.html +33 -33
- package/coverage/lcov-report/api/controllers/row/internal.js.html +1 -1
- package/coverage/lcov-report/api/controllers/row/internalSearch.js.html +159 -21
- package/coverage/lcov-report/api/controllers/row/staticFormula.js.html +1 -1
- package/coverage/lcov-report/api/controllers/row/utils.js.html +17 -8
- package/coverage/lcov-report/api/controllers/screen.js.html +1 -1
- package/coverage/lcov-report/api/controllers/script.js.html +1 -1
- package/coverage/lcov-report/api/controllers/table/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 +15 -15
- package/coverage/lcov-report/api/index.js.html +22 -13
- 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 +32 -2
- 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 -5
- 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 +5 -2
- 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 +57 -12
- package/coverage/lcov-report/automations/bullboard.js.html +1 -1
- package/coverage/lcov-report/automations/index.html +17 -17
- package/coverage/lcov-report/automations/index.js.html +1 -1
- package/coverage/lcov-report/automations/steps/bash.js.html +1 -1
- package/coverage/lcov-report/automations/steps/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 +2 -2
- package/coverage/lcov-report/automations/steps/executeScript.js.html +1 -1
- package/coverage/lcov-report/automations/steps/filter.js.html +58 -34
- package/coverage/lcov-report/automations/steps/index.html +11 -11
- package/coverage/lcov-report/automations/steps/integromat.js.html +1 -1
- package/coverage/lcov-report/automations/steps/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 +4 -4
- 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 +14 -14
- 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 +13 -13
- package/coverage/lcov-report/db/linkedRows/index.js.html +10 -7
- 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 +27 -51
- 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 +83 -83
- 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 +10 -10
- 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/threads/automation.js.html +18 -9
- package/coverage/lcov-report/threads/index.html +25 -25
- package/coverage/lcov-report/threads/query.js.html +301 -79
- package/coverage/lcov-report/threads/utils.js.html +4 -4
- package/coverage/lcov-report/utilities/budibaseDir.js.html +1 -1
- package/coverage/lcov-report/utilities/centralPath.js.html +1 -1
- package/coverage/lcov-report/utilities/csvParser.js.html +1 -1
- package/coverage/lcov-report/utilities/global.js.html +14 -14
- package/coverage/lcov-report/utilities/index.html +26 -26
- package/coverage/lcov-report/utilities/index.js.html +17 -32
- package/coverage/lcov-report/utilities/queue/inMemoryQueue.js.html +2 -2
- package/coverage/lcov-report/utilities/queue/index.html +1 -1
- package/coverage/lcov-report/utilities/routing/index.html +1 -1
- package/coverage/lcov-report/utilities/routing/index.js.html +1 -1
- package/coverage/lcov-report/utilities/rowProcessor/index.html +1 -1
- package/coverage/lcov-report/utilities/rowProcessor/index.js.html +1 -1
- package/coverage/lcov-report/utilities/rowProcessor/utils.js.html +1 -1
- package/coverage/lcov-report/utilities/scriptRunner.js.html +1 -1
- package/coverage/lcov-report/utilities/security.js.html +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 +1 -1
- package/coverage/lcov-report/utilities/usageQuota/usageQuoteReset.js.html +1 -1
- package/coverage/lcov-report/utilities/users.js.html +1 -1
- package/coverage/lcov-report/utilities/workerRequests.js.html +57 -9
- package/coverage/lcov.info +1789 -1665
- package/dist/api/controllers/application.js +19 -16
- package/dist/api/controllers/automation.js +28 -2
- package/dist/api/controllers/backup.js +3 -2
- package/dist/api/controllers/dev.js +2 -40
- package/dist/api/controllers/public/applications.js +1 -1
- package/dist/api/controllers/public/utils.js +8 -1
- package/dist/api/controllers/query/index.js +31 -3
- package/dist/api/controllers/row/external.js +19 -7
- package/dist/api/controllers/row/internalSearch.js +47 -10
- package/dist/api/controllers/row/utils.js +3 -0
- package/dist/api/controllers/static/index.js +1 -5
- package/dist/api/index.js +4 -1
- package/dist/api/routes/automation.js +2 -0
- package/dist/api/routes/dev.js +1 -2
- package/dist/api/routes/public/rows.js +7 -2
- package/dist/api/routes/utils/validators.js +1 -0
- package/dist/app.js +20 -0
- package/dist/automations/automationUtils.js +16 -4
- package/dist/automations/logging/index.js +70 -0
- package/dist/automations/steps/executeQuery.js +1 -1
- package/dist/automations/steps/filter.js +38 -29
- package/dist/automations/triggers.js +1 -1
- package/dist/db/linkedRows/index.js +1 -0
- package/dist/db/utils.js +4 -31
- package/dist/definitions/datasource.js +1 -0
- package/dist/environment.js +3 -0
- package/dist/integrations/airtable.js +1 -0
- package/dist/integrations/arangodb.js +1 -0
- package/dist/integrations/base/sql.js +22 -3
- package/dist/integrations/couchdb.js +1 -0
- package/dist/integrations/dynamodb.js +1 -0
- package/dist/integrations/elasticsearch.js +1 -0
- package/dist/integrations/firebase.js +1 -0
- package/dist/integrations/googlesheets.js +1 -0
- package/dist/integrations/index.js +4 -0
- package/dist/integrations/microsoftSqlServer.js +2 -1
- package/dist/integrations/mongodb.js +1 -0
- package/dist/integrations/mysql.js +2 -1
- package/dist/integrations/oracle.js +1 -0
- package/dist/integrations/postgres.js +2 -1
- package/dist/integrations/queries/sql.js +3 -0
- package/dist/integrations/redis.js +1 -0
- package/dist/integrations/rest.js +2 -1
- package/dist/integrations/s3.js +1 -0
- package/dist/integrations/snowflake.js +102 -0
- package/dist/package.json +7 -6
- package/dist/tests/utilities/TestConfiguration.js +19 -6
- package/dist/threads/automation.js +6 -3
- package/dist/threads/index.js +15 -1
- package/dist/threads/query.js +65 -12
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/utilities/fileSystem/index.js +16 -6
- package/dist/utilities/index.js +1 -5
- package/dist/utilities/workerRequests.js +8 -0
- package/package.json +8 -7
- package/scripts/dev/manage.js +2 -0
- package/scripts/integrations/oracle/instantclient/linux/arm64/basiclite-19.10.zip +0 -0
- package/scripts/integrations/oracle/instantclient/linux/arm64/install.sh +23 -0
- package/scripts/integrations/oracle/instantclient/linux/install.sh +10 -0
- package/specs/openapi.json +9 -5
- package/specs/openapi.yaml +10 -4
- package/src/api/controllers/application.ts +19 -19
- package/src/api/controllers/automation.js +35 -2
- package/src/api/controllers/backup.js +3 -2
- package/src/api/controllers/dev.js +2 -53
- package/src/api/controllers/public/applications.ts +2 -2
- package/src/api/controllers/public/utils.ts +8 -1
- package/src/api/controllers/query/index.ts +40 -4
- package/src/api/controllers/row/external.js +19 -9
- package/src/api/controllers/row/internalSearch.js +55 -9
- package/src/api/controllers/row/utils.js +3 -0
- package/src/api/controllers/static/index.js +1 -6
- package/src/api/index.js +4 -1
- package/src/api/routes/automation.js +10 -0
- package/src/api/routes/dev.js +0 -1
- package/src/api/routes/public/rows.ts +7 -2
- package/src/api/routes/tests/query.spec.js +166 -1
- package/src/api/routes/utils/validators.js +1 -0
- package/src/app.ts +30 -1
- package/src/automations/automationUtils.js +19 -4
- package/src/automations/logging/index.ts +35 -0
- package/src/automations/steps/executeQuery.js +1 -1
- package/src/automations/steps/filter.js +36 -28
- package/src/automations/tests/filter.spec.js +2 -1
- package/src/automations/triggers.js +1 -1
- package/src/db/linkedRows/index.js +1 -0
- package/src/db/utils.js +5 -13
- package/src/definitions/common.ts +1 -0
- package/src/definitions/datasource.ts +2 -0
- package/src/definitions/openapi.ts +471 -469
- package/src/environment.js +3 -0
- package/src/integrations/airtable.ts +1 -0
- package/src/integrations/arangodb.ts +1 -0
- package/src/integrations/base/sql.ts +29 -11
- package/src/integrations/couchdb.ts +1 -0
- package/src/integrations/dynamodb.ts +1 -0
- package/src/integrations/elasticsearch.ts +1 -0
- package/src/integrations/firebase.ts +1 -0
- package/src/integrations/googlesheets.ts +1 -0
- package/src/integrations/index.ts +4 -0
- package/src/integrations/microsoftSqlServer.ts +2 -0
- package/src/integrations/mongodb.ts +1 -0
- package/src/integrations/mysql.ts +2 -0
- package/src/integrations/oracle.ts +1 -0
- package/src/integrations/postgres.ts +2 -0
- package/src/integrations/queries/sql.ts +3 -1
- package/src/integrations/redis.ts +1 -0
- package/src/integrations/rest.ts +2 -1
- package/src/integrations/s3.ts +1 -0
- package/src/integrations/snowflake.ts +99 -0
- package/src/integrations/tests/rest.spec.js +16 -1
- package/src/migrations/tests/index.spec.ts +18 -2
- package/src/module.d.ts +2 -0
- package/src/tests/utilities/TestConfiguration.js +22 -3
- package/src/threads/automation.js +6 -3
- package/src/threads/index.ts +5 -1
- package/src/threads/query.js +88 -14
- package/src/utilities/fileSystem/index.js +22 -8
- package/src/utilities/index.js +1 -6
- package/src/utilities/workerRequests.js +16 -0
- package/builder/assets/index.1c640a53.js +0 -1316
- package/builder/assets/index.24307ca0.css +0 -6
package/src/threads/query.js
CHANGED
|
@@ -4,6 +4,14 @@ const ScriptRunner = require("../utilities/scriptRunner")
|
|
|
4
4
|
const { integrations } = require("../integrations")
|
|
5
5
|
const { processStringSync } = require("@budibase/string-templates")
|
|
6
6
|
const { doInAppContext, getAppDB } = require("@budibase/backend-core/context")
|
|
7
|
+
const {
|
|
8
|
+
refreshOAuthToken,
|
|
9
|
+
updateUserOAuth,
|
|
10
|
+
} = require("@budibase/backend-core/auth")
|
|
11
|
+
const { user: userCache } = require("@budibase/backend-core/cache")
|
|
12
|
+
const { getGlobalIDFromUserMetadataID } = require("../db/utils")
|
|
13
|
+
const { cloneDeep } = require("lodash/fp")
|
|
14
|
+
|
|
7
15
|
const { isSQL } = require("../integrations/utils")
|
|
8
16
|
const {
|
|
9
17
|
enrichQueryFields,
|
|
@@ -21,29 +29,58 @@ class QueryRunner {
|
|
|
21
29
|
this.queryId = input.queryId
|
|
22
30
|
this.noRecursiveQuery = flags.noRecursiveQuery
|
|
23
31
|
this.cachedVariables = []
|
|
32
|
+
// Additional context items for enrichment
|
|
33
|
+
this.ctx = input.ctx
|
|
24
34
|
// allows the response from a query to be stored throughout this
|
|
25
35
|
// execution so that if it needs to be re-used for another variable
|
|
26
36
|
// it can be
|
|
27
37
|
this.queryResponse = {}
|
|
28
38
|
this.hasRerun = false
|
|
39
|
+
this.hasRefreshedOAuth = false
|
|
29
40
|
}
|
|
30
41
|
|
|
31
42
|
async execute() {
|
|
32
43
|
let { datasource, fields, queryVerb, transformer } = this
|
|
33
|
-
|
|
44
|
+
|
|
45
|
+
let datasourceClone = cloneDeep(datasource)
|
|
46
|
+
let fieldsClone = cloneDeep(fields)
|
|
47
|
+
|
|
48
|
+
const Integration = integrations[datasourceClone.source]
|
|
34
49
|
if (!Integration) {
|
|
35
50
|
throw "Integration type does not exist."
|
|
36
51
|
}
|
|
37
|
-
|
|
52
|
+
|
|
53
|
+
if (datasourceClone.config.authConfigs) {
|
|
54
|
+
datasourceClone.config.authConfigs =
|
|
55
|
+
datasourceClone.config.authConfigs.map(config => {
|
|
56
|
+
return enrichQueryFields(config, this.ctx)
|
|
57
|
+
})
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const integration = new Integration(datasourceClone.config)
|
|
38
61
|
|
|
39
62
|
// pre-query, make sure datasource variables are added to parameters
|
|
40
63
|
const parameters = await this.addDatasourceVariables()
|
|
64
|
+
|
|
65
|
+
// Enrich the parameters with the addition context items.
|
|
66
|
+
// 'user' is now a reserved variable key in mapping parameters
|
|
67
|
+
const enrichedParameters = enrichQueryFields(parameters, this.ctx)
|
|
68
|
+
const enrichedContext = { ...enrichedParameters, ...this.ctx }
|
|
69
|
+
|
|
70
|
+
// Parse global headers
|
|
71
|
+
if (datasourceClone.config.defaultHeaders) {
|
|
72
|
+
datasourceClone.config.defaultHeaders = enrichQueryFields(
|
|
73
|
+
datasourceClone.config.defaultHeaders,
|
|
74
|
+
enrichedContext
|
|
75
|
+
)
|
|
76
|
+
}
|
|
77
|
+
|
|
41
78
|
let query
|
|
42
79
|
// handle SQL injections by interpolating the variables
|
|
43
|
-
if (isSQL(
|
|
44
|
-
query = interpolateSQL(
|
|
80
|
+
if (isSQL(datasourceClone)) {
|
|
81
|
+
query = interpolateSQL(fieldsClone, enrichedParameters, integration)
|
|
45
82
|
} else {
|
|
46
|
-
query = enrichQueryFields(
|
|
83
|
+
query = enrichQueryFields(fieldsClone, enrichedContext)
|
|
47
84
|
}
|
|
48
85
|
|
|
49
86
|
// Add pagination values for REST queries
|
|
@@ -67,20 +104,25 @@ class QueryRunner {
|
|
|
67
104
|
if (transformer) {
|
|
68
105
|
const runner = new ScriptRunner(transformer, {
|
|
69
106
|
data: rows,
|
|
70
|
-
params:
|
|
107
|
+
params: enrichedParameters,
|
|
71
108
|
})
|
|
72
109
|
rows = runner.execute()
|
|
73
110
|
}
|
|
74
111
|
|
|
75
112
|
// if the request fails we retry once, invalidating the cached value
|
|
76
|
-
if (
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
113
|
+
if (info && info.code >= 400 && !this.hasRerun) {
|
|
114
|
+
if (
|
|
115
|
+
this.ctx.user?.provider &&
|
|
116
|
+
info.code === 401 &&
|
|
117
|
+
!this.hasRefreshedOAuth
|
|
118
|
+
) {
|
|
119
|
+
await this.refreshOAuth2(this.ctx)
|
|
120
|
+
// Attempt to refresh the access token from the provider
|
|
121
|
+
this.hasRefreshedOAuth = true
|
|
122
|
+
} else {
|
|
123
|
+
this.hasRerun = true
|
|
124
|
+
}
|
|
125
|
+
|
|
84
126
|
await threadUtils.invalidateDynamicVariables(this.cachedVariables)
|
|
85
127
|
return this.execute()
|
|
86
128
|
}
|
|
@@ -126,6 +168,38 @@ class QueryRunner {
|
|
|
126
168
|
).execute()
|
|
127
169
|
}
|
|
128
170
|
|
|
171
|
+
async refreshOAuth2(ctx) {
|
|
172
|
+
const { oauth2, providerType, _id } = ctx.user
|
|
173
|
+
const { configId } = ctx.auth
|
|
174
|
+
|
|
175
|
+
if (!providerType || !oauth2?.refreshToken) {
|
|
176
|
+
throw new Error("No refresh token found for authenticated user")
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
const resp = await refreshOAuthToken(
|
|
180
|
+
oauth2.refreshToken,
|
|
181
|
+
providerType,
|
|
182
|
+
configId
|
|
183
|
+
)
|
|
184
|
+
|
|
185
|
+
// Refresh session flow. Should be in same location as refreshOAuthToken
|
|
186
|
+
// There are several other properties available in 'resp'
|
|
187
|
+
if (!resp.err) {
|
|
188
|
+
const globalUserId = getGlobalIDFromUserMetadataID(_id)
|
|
189
|
+
await updateUserOAuth(globalUserId, resp)
|
|
190
|
+
this.ctx.user = await userCache.getUser(globalUserId)
|
|
191
|
+
} else {
|
|
192
|
+
// In this event the user may have oAuth issues that
|
|
193
|
+
// could require re-authenticating with their provider.
|
|
194
|
+
let errorMessage = resp.err.data ? resp.err.data : resp.err.toString()
|
|
195
|
+
throw new Error(
|
|
196
|
+
"OAuth2 access token could not be refreshed: " + errorMessage
|
|
197
|
+
)
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
return resp
|
|
201
|
+
}
|
|
202
|
+
|
|
129
203
|
async getDynamicVariable(variable) {
|
|
130
204
|
let { parameters } = this
|
|
131
205
|
const queryId = variable.queryId,
|
|
@@ -21,6 +21,7 @@ const env = require("../../environment")
|
|
|
21
21
|
const {
|
|
22
22
|
USER_METDATA_PREFIX,
|
|
23
23
|
LINK_USER_METADATA_PREFIX,
|
|
24
|
+
TABLE_ROW_PREFIX,
|
|
24
25
|
} = require("../../db/utils")
|
|
25
26
|
const MemoryStream = require("memorystream")
|
|
26
27
|
const { getAppId } = require("@budibase/backend-core/context")
|
|
@@ -109,6 +110,23 @@ exports.apiFileReturn = contents => {
|
|
|
109
110
|
return fs.createReadStream(path)
|
|
110
111
|
}
|
|
111
112
|
|
|
113
|
+
exports.defineFilter = excludeRows => {
|
|
114
|
+
if (excludeRows) {
|
|
115
|
+
return doc =>
|
|
116
|
+
!(
|
|
117
|
+
doc._id.includes(USER_METDATA_PREFIX) ||
|
|
118
|
+
doc._id.includes(LINK_USER_METADATA_PREFIX) ||
|
|
119
|
+
doc._id.includes(TABLE_ROW_PREFIX)
|
|
120
|
+
)
|
|
121
|
+
} else if (!excludeRows) {
|
|
122
|
+
return doc =>
|
|
123
|
+
!(
|
|
124
|
+
doc._id.includes(USER_METDATA_PREFIX) ||
|
|
125
|
+
doc._id.includes(LINK_USER_METADATA_PREFIX)
|
|
126
|
+
)
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
112
130
|
/**
|
|
113
131
|
* Local utility to back up the database state for an app, excluding global user
|
|
114
132
|
* data or user relationships.
|
|
@@ -116,14 +134,10 @@ exports.apiFileReturn = contents => {
|
|
|
116
134
|
* @param {object} config Config to send to export DB
|
|
117
135
|
* @returns {*} either a string or a stream of the backup
|
|
118
136
|
*/
|
|
119
|
-
const backupAppData = async (appId, config) => {
|
|
137
|
+
const backupAppData = async (appId, config, includeRows) => {
|
|
120
138
|
return await exports.exportDB(appId, {
|
|
121
139
|
...config,
|
|
122
|
-
filter:
|
|
123
|
-
!(
|
|
124
|
-
doc._id.includes(USER_METDATA_PREFIX) ||
|
|
125
|
-
doc._id.includes(LINK_USER_METADATA_PREFIX)
|
|
126
|
-
),
|
|
140
|
+
filter: exports.defineFilter(includeRows),
|
|
127
141
|
})
|
|
128
142
|
}
|
|
129
143
|
|
|
@@ -142,8 +156,8 @@ exports.performBackup = async (appId, backupName) => {
|
|
|
142
156
|
* @param {string} appId The ID of the app which is to be backed up.
|
|
143
157
|
* @returns {*} a readable stream of the backup which is written in real time
|
|
144
158
|
*/
|
|
145
|
-
exports.streamBackup = async appId => {
|
|
146
|
-
return await backupAppData(appId, { stream: true })
|
|
159
|
+
exports.streamBackup = async (appId, includeRows) => {
|
|
160
|
+
return await backupAppData(appId, { stream: true }, includeRows)
|
|
147
161
|
}
|
|
148
162
|
|
|
149
163
|
/**
|
package/src/utilities/index.js
CHANGED
|
@@ -54,13 +54,8 @@ exports.objectStoreUrl = () => {
|
|
|
54
54
|
* @return {string} The URL to be inserted into appPackage response or server rendered
|
|
55
55
|
* app index file.
|
|
56
56
|
*/
|
|
57
|
-
exports.clientLibraryPath = (appId, version
|
|
57
|
+
exports.clientLibraryPath = (appId, version) => {
|
|
58
58
|
if (env.isProd()) {
|
|
59
|
-
// TODO: remove - for beta testing UI
|
|
60
|
-
if (ctx && ctx.cookies.get("beta:design_ui")) {
|
|
61
|
-
return "https://cdn.budi.live/beta:design_ui/budibase-client.js"
|
|
62
|
-
}
|
|
63
|
-
|
|
64
59
|
let url = `${exports.objectStoreUrl()}/${sanitizeKey(
|
|
65
60
|
appId
|
|
66
61
|
)}/budibase-client.js`
|
|
@@ -137,3 +137,19 @@ exports.readGlobalUser = async ctx => {
|
|
|
137
137
|
)
|
|
138
138
|
return checkResponse(response, "get user", { ctx })
|
|
139
139
|
}
|
|
140
|
+
|
|
141
|
+
exports.createAdminUser = async (email, password, tenantId) => {
|
|
142
|
+
const response = await fetch(
|
|
143
|
+
checkSlashesInUrl(env.WORKER_URL + "/api/global/users/init"),
|
|
144
|
+
request(null, { method: "POST", body: { email, password, tenantId } })
|
|
145
|
+
)
|
|
146
|
+
return checkResponse(response, "create admin user")
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
exports.getChecklist = async () => {
|
|
150
|
+
const response = await fetch(
|
|
151
|
+
checkSlashesInUrl(env.WORKER_URL + "/api/global/configs/checklist"),
|
|
152
|
+
request(null, { method: "GET" })
|
|
153
|
+
)
|
|
154
|
+
return checkResponse(response, "get checklist")
|
|
155
|
+
}
|