@budibase/server 1.0.21 → 1.0.23-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/__mocks__/node-fetch.ts +3 -0
- package/builder/assets/bb-spaceship.8f6e81e1.svg +227 -0
- package/builder/assets/{index.c2e9e4e2.js → index.26923a83.js} +208 -204
- package/builder/assets/{index.4fb3f887.css → index.4a13c4cb.css} +1 -1
- package/builder/assets/{vendor.470042a4.js → vendor.f9faf6ab.js} +88 -88
- package/builder/index.html +3 -3
- package/coverage/clover.xml +654 -567
- package/coverage/coverage-final.json +22 -20
- package/coverage/lcov-report/api/controllers/analytics.js.html +1 -1
- package/coverage/lcov-report/api/controllers/apikeys.js.html +1 -1
- package/coverage/lcov-report/api/controllers/application.js.html +1 -1
- package/coverage/lcov-report/api/controllers/auth.js.html +1 -1
- package/coverage/lcov-report/api/controllers/automation.js.html +22 -10
- 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 +1 -1
- package/coverage/lcov-report/api/controllers/datasource.js.html +14 -14
- package/coverage/lcov-report/api/controllers/dev.js.html +1 -1
- package/coverage/lcov-report/api/controllers/hosting.js.html +1 -1
- package/coverage/lcov-report/api/controllers/index.html +28 -43
- package/coverage/lcov-report/api/controllers/integration.js.html +1 -1
- package/coverage/lcov-report/api/controllers/layout.js.html +1 -1
- package/coverage/lcov-report/api/controllers/metadata.js.html +1 -1
- package/coverage/lcov-report/api/controllers/permission.js.html +1 -1
- package/coverage/lcov-report/api/controllers/query/index.html +126 -0
- package/coverage/lcov-report/api/controllers/{query.js.html → query/index.js.html} +159 -27
- package/coverage/lcov-report/api/controllers/query/validation.js.html +203 -0
- 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/index.js.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/utils.js.html +1 -1
- 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/external.js.html +1 -1
- package/coverage/lcov-report/api/controllers/table/index.html +1 -1
- package/coverage/lcov-report/api/controllers/table/index.js.html +1 -1
- package/coverage/lcov-report/api/controllers/table/internal.js.html +1 -1
- package/coverage/lcov-report/api/controllers/table/utils.js.html +1 -1
- package/coverage/lcov-report/api/controllers/templates.js.html +1 -1
- package/coverage/lcov-report/api/controllers/user.js.html +108 -9
- 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 +18 -6
- 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 +1 -1
- package/coverage/lcov-report/api/routes/hosting.js.html +1 -1
- package/coverage/lcov-report/api/routes/index.html +9 -9
- 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 +11 -98
- 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 +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 +32 -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 +1 -1
- package/coverage/lcov-report/automations/bullboard.js.html +1 -1
- package/coverage/lcov-report/automations/index.html +20 -20
- package/coverage/lcov-report/automations/index.js.html +1 -1
- package/coverage/lcov-report/automations/steps/bash.js.html +1 -1
- package/coverage/lcov-report/automations/steps/createRow.js.html +1 -1
- package/coverage/lcov-report/automations/steps/delay.js.html +1 -1
- package/coverage/lcov-report/automations/steps/deleteRow.js.html +1 -1
- package/coverage/lcov-report/automations/steps/discord.js.html +1 -1
- package/coverage/lcov-report/automations/steps/executeQuery.js.html +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/outgoingWebhook.js.html +5 -8
- package/coverage/lcov-report/automations/steps/queryRows.js.html +1 -1
- package/coverage/lcov-report/automations/steps/sendSmtpEmail.js.html +1 -1
- package/coverage/lcov-report/automations/steps/serverLog.js.html +1 -1
- package/coverage/lcov-report/automations/steps/slack.js.html +1 -1
- package/coverage/lcov-report/automations/steps/updateRow.js.html +1 -1
- package/coverage/lcov-report/automations/steps/utils.js.html +1 -1
- package/coverage/lcov-report/automations/steps/zapier.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/app.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/cron.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/index.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/index.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/rowDeleted.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/rowSaved.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/rowUpdated.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/webhook.js.html +1 -1
- package/coverage/lcov-report/automations/triggers.js.html +1 -1
- package/coverage/lcov-report/automations/utils.js.html +44 -11
- package/coverage/lcov-report/constants/index.html +1 -1
- package/coverage/lcov-report/constants/index.js.html +22 -22
- 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 +18 -18
- package/coverage/lcov-report/db/inMemoryView.js.html +1 -1
- package/coverage/lcov-report/db/index.html +15 -15
- package/coverage/lcov-report/db/index.js.html +3 -3
- 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 +4 -4
- package/coverage/lcov-report/db/utils.js.html +91 -64
- 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 +76 -61
- package/coverage/lcov-report/integrations/tests/TestConfiguration.js.html +1 -1
- package/coverage/lcov-report/integrations/tests/index.html +1 -1
- package/coverage/lcov-report/middleware/appInfo.js.html +1 -1
- package/coverage/lcov-report/middleware/authorized.js.html +2 -2
- package/coverage/lcov-report/middleware/builder.js.html +1 -1
- package/coverage/lcov-report/middleware/currentapp.js.html +1 -1
- package/coverage/lcov-report/middleware/index.html +1 -1
- package/coverage/lcov-report/middleware/joi-validator.js.html +3 -3
- package/coverage/lcov-report/middleware/resourceId.js.html +1 -1
- package/coverage/lcov-report/middleware/selfhost.js.html +1 -1
- package/coverage/lcov-report/middleware/usageQuota.js.html +1 -1
- package/coverage/lcov-report/middleware/utils.js.html +1 -1
- package/coverage/lcov-report/threads/automation.js.html +3 -6
- package/coverage/lcov-report/threads/index.html +35 -20
- package/coverage/lcov-report/threads/index.js.html +1 -1
- package/coverage/lcov-report/threads/query.js.html +62 -17
- package/coverage/lcov-report/threads/utils.js.html +119 -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 +1 -1
- package/coverage/lcov-report/utilities/global.js.html +1 -1
- package/coverage/lcov-report/utilities/index.html +19 -19
- package/coverage/lcov-report/utilities/index.js.html +66 -33
- package/coverage/lcov-report/utilities/queue/inMemoryQueue.js.html +1 -1
- 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/users.js.html +1 -1
- package/coverage/lcov-report/utilities/workerRequests.js.html +1 -1
- package/coverage/lcov.info +1058 -918
- package/dist/api/controllers/automation.js +7 -5
- package/dist/api/controllers/query/import/index.js +79 -0
- package/dist/api/controllers/query/import/sources/base/index.js +63 -0
- package/dist/api/controllers/query/import/sources/base/openapi.js +42 -0
- package/dist/api/controllers/query/import/sources/curl.js +90 -0
- package/dist/api/controllers/query/import/sources/openapi2.js +139 -0
- package/dist/api/controllers/query/import/sources/tests/openapi2/data/crud/crud.json +253 -0
- package/dist/api/controllers/query/import/sources/tests/openapi2/data/petstore/petstore.json +1054 -0
- package/dist/api/controllers/{query.js → query/index.js} +42 -6
- package/dist/api/controllers/query/validation.js +37 -0
- package/dist/api/controllers/user.js +37 -1
- package/dist/api/controllers/webhook.js +4 -0
- package/dist/api/routes/query.js +2 -32
- package/dist/api/routes/user.js +3 -1
- package/dist/automations/steps/outgoingWebhook.js +2 -3
- package/dist/automations/utils.js +10 -0
- package/dist/db/utils.js +8 -0
- package/dist/definitions/datasource.js +6 -1
- package/dist/integrations/rest.js +207 -117
- package/dist/package.json +10 -4
- package/dist/threads/automation.js +1 -2
- package/dist/threads/query.js +15 -5
- package/dist/threads/utils.js +13 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utilities/index.js +10 -0
- package/package.json +11 -5
- package/src/api/controllers/automation.js +8 -4
- package/src/api/controllers/query/import/index.ts +85 -0
- package/src/api/controllers/query/import/sources/base/index.ts +85 -0
- package/src/api/controllers/query/import/sources/base/openapi.ts +24 -0
- package/src/api/controllers/query/import/sources/curl.ts +94 -0
- package/src/api/controllers/query/import/sources/openapi2.ts +159 -0
- package/src/api/controllers/query/import/sources/tests/curl/curl.spec.js +104 -0
- package/src/api/controllers/query/import/sources/tests/curl/data/delete.txt +1 -0
- package/src/api/controllers/query/import/sources/tests/curl/data/empty-body.txt +2 -0
- package/src/api/controllers/query/import/sources/tests/curl/data/get.txt +1 -0
- package/src/api/controllers/query/import/sources/tests/curl/data/headers.txt +3 -0
- package/src/api/controllers/query/import/sources/tests/curl/data/patch.txt +2 -0
- package/src/api/controllers/query/import/sources/tests/curl/data/path.txt +1 -0
- package/src/api/controllers/query/import/sources/tests/curl/data/post.txt +2 -0
- package/src/api/controllers/query/import/sources/tests/curl/data/put.txt +2 -0
- package/src/api/controllers/query/import/sources/tests/curl/data/query.txt +1 -0
- package/src/api/controllers/query/import/sources/tests/openapi2/data/crud/crud.json +253 -0
- package/src/api/controllers/query/import/sources/tests/openapi2/data/crud/crud.yaml +160 -0
- package/src/api/controllers/query/import/sources/tests/openapi2/data/petstore/petstore.json +1054 -0
- package/src/api/controllers/query/import/sources/tests/openapi2/data/petstore/petstore.yaml +711 -0
- package/src/api/controllers/query/import/sources/tests/openapi2/openapi2.spec.js +239 -0
- package/src/api/controllers/query/import/tests/index.spec.js +115 -0
- package/src/api/controllers/{query.js → query/index.js} +50 -6
- package/src/api/controllers/query/validation.js +41 -0
- package/src/api/controllers/user.js +33 -0
- package/src/api/controllers/webhook.js +4 -0
- package/src/api/routes/query.js +5 -34
- package/src/api/routes/user.js +10 -0
- package/src/automations/steps/outgoingWebhook.js +2 -3
- package/src/automations/utils.js +11 -0
- package/src/db/utils.js +9 -0
- package/src/definitions/common.ts +2 -16
- package/src/definitions/datasource.ts +73 -1
- package/src/integrations/base/IntegrationBase.ts +4 -4
- package/src/integrations/oracle.ts +1 -1
- package/src/integrations/rest.ts +227 -137
- package/src/integrations/tests/rest.spec.js +167 -19
- package/src/threads/automation.js +1 -2
- package/src/threads/query.js +20 -5
- package/src/threads/utils.js +13 -0
- package/src/utilities/index.js +11 -0
|
@@ -10,18 +10,54 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
const datasource_1 = require("../definitions/datasource");
|
|
13
|
+
const BodyTypes = {
|
|
14
|
+
NONE: "none",
|
|
15
|
+
FORM_DATA: "form",
|
|
16
|
+
XML: "xml",
|
|
17
|
+
ENCODED: "encoded",
|
|
18
|
+
JSON: "json",
|
|
19
|
+
TEXT: "text",
|
|
20
|
+
};
|
|
21
|
+
const coreFields = {
|
|
22
|
+
path: {
|
|
23
|
+
type: datasource_1.DatasourceFieldTypes.STRING,
|
|
24
|
+
display: "URL",
|
|
25
|
+
},
|
|
26
|
+
queryString: {
|
|
27
|
+
type: datasource_1.DatasourceFieldTypes.STRING,
|
|
28
|
+
},
|
|
29
|
+
headers: {
|
|
30
|
+
type: datasource_1.DatasourceFieldTypes.OBJECT,
|
|
31
|
+
},
|
|
32
|
+
enabledHeaders: {
|
|
33
|
+
type: datasource_1.DatasourceFieldTypes.OBJECT,
|
|
34
|
+
},
|
|
35
|
+
requestBody: {
|
|
36
|
+
type: datasource_1.DatasourceFieldTypes.JSON,
|
|
37
|
+
},
|
|
38
|
+
bodyType: {
|
|
39
|
+
type: datasource_1.DatasourceFieldTypes.STRING,
|
|
40
|
+
enum: Object.values(BodyTypes),
|
|
41
|
+
},
|
|
42
|
+
};
|
|
13
43
|
var RestModule;
|
|
14
44
|
(function (RestModule) {
|
|
15
45
|
const fetch = require("node-fetch");
|
|
46
|
+
const { formatBytes } = require("../utilities");
|
|
47
|
+
const { performance } = require("perf_hooks");
|
|
48
|
+
const FormData = require("form-data");
|
|
49
|
+
const { URLSearchParams } = require("url");
|
|
50
|
+
const { parseStringPromise: xmlParser, Builder: XmlBuilder } = require("xml2js");
|
|
16
51
|
const SCHEMA = {
|
|
17
52
|
docs: "https://github.com/node-fetch/node-fetch",
|
|
18
|
-
description: "
|
|
53
|
+
description: "With the REST API datasource, you can connect, query and pull data from multiple REST APIs. You can then use the retrieved data to build apps.",
|
|
19
54
|
friendlyName: "REST API",
|
|
20
55
|
datasource: {
|
|
21
56
|
url: {
|
|
22
57
|
type: datasource_1.DatasourceFieldTypes.STRING,
|
|
23
|
-
default: "
|
|
24
|
-
required:
|
|
58
|
+
default: "",
|
|
59
|
+
required: false,
|
|
60
|
+
deprecated: true,
|
|
25
61
|
},
|
|
26
62
|
defaultHeaders: {
|
|
27
63
|
type: datasource_1.DatasourceFieldTypes.OBJECT,
|
|
@@ -34,174 +70,228 @@ var RestModule;
|
|
|
34
70
|
readable: true,
|
|
35
71
|
displayName: "POST",
|
|
36
72
|
type: datasource_1.QueryTypes.FIELDS,
|
|
37
|
-
|
|
38
|
-
fields: {
|
|
39
|
-
path: {
|
|
40
|
-
type: datasource_1.DatasourceFieldTypes.STRING,
|
|
41
|
-
},
|
|
42
|
-
queryString: {
|
|
43
|
-
type: datasource_1.DatasourceFieldTypes.STRING,
|
|
44
|
-
},
|
|
45
|
-
headers: {
|
|
46
|
-
type: datasource_1.DatasourceFieldTypes.OBJECT,
|
|
47
|
-
},
|
|
48
|
-
requestBody: {
|
|
49
|
-
type: datasource_1.DatasourceFieldTypes.JSON,
|
|
50
|
-
},
|
|
51
|
-
},
|
|
73
|
+
fields: coreFields,
|
|
52
74
|
},
|
|
53
75
|
read: {
|
|
54
76
|
displayName: "GET",
|
|
55
77
|
readable: true,
|
|
56
78
|
type: datasource_1.QueryTypes.FIELDS,
|
|
57
|
-
|
|
58
|
-
fields: {
|
|
59
|
-
path: {
|
|
60
|
-
type: datasource_1.DatasourceFieldTypes.STRING,
|
|
61
|
-
},
|
|
62
|
-
queryString: {
|
|
63
|
-
type: datasource_1.DatasourceFieldTypes.STRING,
|
|
64
|
-
},
|
|
65
|
-
headers: {
|
|
66
|
-
type: datasource_1.DatasourceFieldTypes.OBJECT,
|
|
67
|
-
},
|
|
68
|
-
},
|
|
79
|
+
fields: coreFields,
|
|
69
80
|
},
|
|
70
81
|
update: {
|
|
71
82
|
displayName: "PUT",
|
|
72
83
|
readable: true,
|
|
73
84
|
type: datasource_1.QueryTypes.FIELDS,
|
|
74
|
-
|
|
75
|
-
fields: {
|
|
76
|
-
path: {
|
|
77
|
-
type: datasource_1.DatasourceFieldTypes.STRING,
|
|
78
|
-
},
|
|
79
|
-
queryString: {
|
|
80
|
-
type: datasource_1.DatasourceFieldTypes.STRING,
|
|
81
|
-
},
|
|
82
|
-
headers: {
|
|
83
|
-
type: datasource_1.DatasourceFieldTypes.OBJECT,
|
|
84
|
-
},
|
|
85
|
-
requestBody: {
|
|
86
|
-
type: datasource_1.DatasourceFieldTypes.JSON,
|
|
87
|
-
},
|
|
88
|
-
},
|
|
85
|
+
fields: coreFields,
|
|
89
86
|
},
|
|
90
87
|
patch: {
|
|
91
88
|
displayName: "PATCH",
|
|
92
89
|
readable: true,
|
|
93
90
|
type: datasource_1.QueryTypes.FIELDS,
|
|
94
|
-
|
|
95
|
-
fields: {
|
|
96
|
-
path: {
|
|
97
|
-
type: datasource_1.DatasourceFieldTypes.STRING,
|
|
98
|
-
},
|
|
99
|
-
queryString: {
|
|
100
|
-
type: datasource_1.DatasourceFieldTypes.STRING,
|
|
101
|
-
},
|
|
102
|
-
headers: {
|
|
103
|
-
type: datasource_1.DatasourceFieldTypes.OBJECT,
|
|
104
|
-
},
|
|
105
|
-
requestBody: {
|
|
106
|
-
type: datasource_1.DatasourceFieldTypes.JSON,
|
|
107
|
-
},
|
|
108
|
-
},
|
|
91
|
+
fields: coreFields,
|
|
109
92
|
},
|
|
110
93
|
delete: {
|
|
111
94
|
displayName: "DELETE",
|
|
112
95
|
type: datasource_1.QueryTypes.FIELDS,
|
|
113
|
-
|
|
114
|
-
fields: {
|
|
115
|
-
path: {
|
|
116
|
-
type: datasource_1.DatasourceFieldTypes.STRING,
|
|
117
|
-
},
|
|
118
|
-
queryString: {
|
|
119
|
-
type: datasource_1.DatasourceFieldTypes.STRING,
|
|
120
|
-
},
|
|
121
|
-
headers: {
|
|
122
|
-
type: datasource_1.DatasourceFieldTypes.OBJECT,
|
|
123
|
-
},
|
|
124
|
-
requestBody: {
|
|
125
|
-
type: datasource_1.DatasourceFieldTypes.JSON,
|
|
126
|
-
},
|
|
127
|
-
},
|
|
96
|
+
fields: coreFields,
|
|
128
97
|
},
|
|
129
98
|
},
|
|
130
99
|
};
|
|
131
100
|
class RestIntegration {
|
|
132
101
|
constructor(config) {
|
|
133
102
|
this.headers = {};
|
|
103
|
+
this.startTimeMs = performance.now();
|
|
134
104
|
this.config = config;
|
|
135
105
|
}
|
|
136
106
|
parseResponse(response) {
|
|
137
107
|
return __awaiter(this, void 0, void 0, function* () {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
108
|
+
let data, raw, headers;
|
|
109
|
+
const contentType = response.headers.get("content-type") || "";
|
|
110
|
+
try {
|
|
111
|
+
if (contentType.includes("application/json")) {
|
|
112
|
+
data = yield response.json();
|
|
113
|
+
raw = JSON.stringify(data);
|
|
114
|
+
}
|
|
115
|
+
else if (contentType.includes("text/xml") ||
|
|
116
|
+
contentType.includes("application/xml")) {
|
|
117
|
+
const rawXml = yield response.text();
|
|
118
|
+
data =
|
|
119
|
+
(yield xmlParser(rawXml, {
|
|
120
|
+
explicitArray: false,
|
|
121
|
+
trim: true,
|
|
122
|
+
explicitRoot: false,
|
|
123
|
+
})) || {};
|
|
124
|
+
// there is only one structure, its an array, return the array so it appears as rows
|
|
125
|
+
const keys = Object.keys(data);
|
|
126
|
+
if (keys.length === 1 && Array.isArray(data[keys[0]])) {
|
|
127
|
+
data = data[keys[0]];
|
|
128
|
+
}
|
|
129
|
+
raw = rawXml;
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
data = yield response.text();
|
|
133
|
+
raw = data;
|
|
134
|
+
}
|
|
141
135
|
}
|
|
142
|
-
|
|
143
|
-
|
|
136
|
+
catch (err) {
|
|
137
|
+
throw "Failed to parse response body.";
|
|
144
138
|
}
|
|
139
|
+
const size = formatBytes(response.headers.get("content-length") || Buffer.byteLength(raw, "utf8"));
|
|
140
|
+
const time = `${Math.round(performance.now() - this.startTimeMs)}ms`;
|
|
141
|
+
headers = response.headers.raw();
|
|
142
|
+
for (let [key, value] of Object.entries(headers)) {
|
|
143
|
+
headers[key] = Array.isArray(value) ? value[0] : value;
|
|
144
|
+
}
|
|
145
|
+
return {
|
|
146
|
+
data,
|
|
147
|
+
info: {
|
|
148
|
+
code: response.status,
|
|
149
|
+
size,
|
|
150
|
+
time,
|
|
151
|
+
},
|
|
152
|
+
extra: {
|
|
153
|
+
raw,
|
|
154
|
+
headers,
|
|
155
|
+
},
|
|
156
|
+
};
|
|
145
157
|
});
|
|
146
158
|
}
|
|
147
159
|
getUrl(path, queryString) {
|
|
148
|
-
|
|
160
|
+
const main = `${path}?${queryString}`;
|
|
161
|
+
let complete = main;
|
|
162
|
+
if (this.config.url && !main.startsWith(this.config.url)) {
|
|
163
|
+
complete = !this.config.url ? main : `${this.config.url}/${main}`;
|
|
164
|
+
}
|
|
165
|
+
if (!complete.startsWith("http")) {
|
|
166
|
+
complete = `http://${complete}`;
|
|
167
|
+
}
|
|
168
|
+
return complete;
|
|
169
|
+
}
|
|
170
|
+
addBody(bodyType, body, input) {
|
|
171
|
+
let error, object, string;
|
|
172
|
+
try {
|
|
173
|
+
string = typeof body !== "string" ? JSON.stringify(body) : body;
|
|
174
|
+
object = typeof body === "object" ? body : JSON.parse(body);
|
|
175
|
+
}
|
|
176
|
+
catch (err) {
|
|
177
|
+
error = err;
|
|
178
|
+
}
|
|
179
|
+
if (!input.headers) {
|
|
180
|
+
input.headers = {};
|
|
181
|
+
}
|
|
182
|
+
switch (bodyType) {
|
|
183
|
+
case BodyTypes.NONE:
|
|
184
|
+
break;
|
|
185
|
+
case BodyTypes.TEXT:
|
|
186
|
+
// content type defaults to plaintext
|
|
187
|
+
input.body = string;
|
|
188
|
+
break;
|
|
189
|
+
case BodyTypes.ENCODED:
|
|
190
|
+
const params = new URLSearchParams();
|
|
191
|
+
for (let [key, value] of Object.entries(object)) {
|
|
192
|
+
params.append(key, value);
|
|
193
|
+
}
|
|
194
|
+
input.body = params;
|
|
195
|
+
break;
|
|
196
|
+
case BodyTypes.FORM_DATA:
|
|
197
|
+
const form = new FormData();
|
|
198
|
+
for (let [key, value] of Object.entries(object)) {
|
|
199
|
+
form.append(key, value);
|
|
200
|
+
}
|
|
201
|
+
input.body = form;
|
|
202
|
+
break;
|
|
203
|
+
case BodyTypes.XML:
|
|
204
|
+
if (object != null) {
|
|
205
|
+
string = (new XmlBuilder()).buildObject(object);
|
|
206
|
+
}
|
|
207
|
+
input.body = string;
|
|
208
|
+
input.headers["Content-Type"] = "application/xml";
|
|
209
|
+
break;
|
|
210
|
+
default:
|
|
211
|
+
case BodyTypes.JSON:
|
|
212
|
+
// if JSON error, throw it
|
|
213
|
+
if (error) {
|
|
214
|
+
throw "Invalid JSON for request body";
|
|
215
|
+
}
|
|
216
|
+
input.body = string;
|
|
217
|
+
input.headers["Content-Type"] = "application/json";
|
|
218
|
+
break;
|
|
219
|
+
}
|
|
220
|
+
return input;
|
|
221
|
+
}
|
|
222
|
+
getAuthHeaders(authConfigId) {
|
|
223
|
+
let headers = {};
|
|
224
|
+
if (this.config.authConfigs && authConfigId) {
|
|
225
|
+
const authConfig = this.config.authConfigs.filter(c => c._id === authConfigId)[0];
|
|
226
|
+
// check the config still exists before proceeding
|
|
227
|
+
// if not - do nothing
|
|
228
|
+
if (authConfig) {
|
|
229
|
+
let config;
|
|
230
|
+
switch (authConfig.type) {
|
|
231
|
+
case datasource_1.AuthType.BASIC:
|
|
232
|
+
config = authConfig.config;
|
|
233
|
+
headers.Authorization = `Basic ${Buffer.from(`${config.username}:${config.password}`).toString("base64")}`;
|
|
234
|
+
break;
|
|
235
|
+
case datasource_1.AuthType.BEARER:
|
|
236
|
+
config = authConfig.config;
|
|
237
|
+
headers.Authorization = `Bearer ${config.token}`;
|
|
238
|
+
break;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
return headers;
|
|
149
243
|
}
|
|
150
|
-
|
|
244
|
+
_req(query) {
|
|
151
245
|
return __awaiter(this, void 0, void 0, function* () {
|
|
152
|
-
|
|
153
|
-
const
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
246
|
+
const { path = "", queryString = "", headers = {}, method = "GET", disabledHeaders, bodyType, requestBody, authConfigId, } = query;
|
|
247
|
+
const authHeaders = this.getAuthHeaders(authConfigId);
|
|
248
|
+
this.headers = Object.assign(Object.assign(Object.assign({}, this.config.defaultHeaders), headers), authHeaders);
|
|
249
|
+
if (disabledHeaders) {
|
|
250
|
+
for (let headerKey of Object.keys(this.headers)) {
|
|
251
|
+
if (disabledHeaders[headerKey]) {
|
|
252
|
+
delete this.headers[headerKey];
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
let input = { method, headers: this.headers };
|
|
257
|
+
if (requestBody) {
|
|
258
|
+
input = this.addBody(bodyType, requestBody, input);
|
|
259
|
+
}
|
|
260
|
+
this.startTimeMs = performance.now();
|
|
261
|
+
const url = this.getUrl(path, queryString);
|
|
262
|
+
const response = yield fetch(url, input);
|
|
158
263
|
return yield this.parseResponse(response);
|
|
159
264
|
});
|
|
160
265
|
}
|
|
161
|
-
|
|
266
|
+
create(opts) {
|
|
162
267
|
return __awaiter(this, void 0, void 0, function* () {
|
|
163
|
-
this.
|
|
164
|
-
const response = yield fetch(this.getUrl(path, queryString), {
|
|
165
|
-
headers: this.headers,
|
|
166
|
-
});
|
|
167
|
-
return yield this.parseResponse(response);
|
|
268
|
+
return this._req(Object.assign(Object.assign({}, opts), { method: "POST" }));
|
|
168
269
|
});
|
|
169
270
|
}
|
|
170
|
-
|
|
271
|
+
read(opts) {
|
|
171
272
|
return __awaiter(this, void 0, void 0, function* () {
|
|
172
|
-
this.
|
|
173
|
-
const response = yield fetch(this.getUrl(path, queryString), {
|
|
174
|
-
method: "PUT",
|
|
175
|
-
headers: this.headers,
|
|
176
|
-
body: JSON.stringify(json),
|
|
177
|
-
});
|
|
178
|
-
return yield this.parseResponse(response);
|
|
273
|
+
return this._req(Object.assign(Object.assign({}, opts), { method: "GET" }));
|
|
179
274
|
});
|
|
180
275
|
}
|
|
181
|
-
|
|
276
|
+
update(opts) {
|
|
182
277
|
return __awaiter(this, void 0, void 0, function* () {
|
|
183
|
-
this.
|
|
184
|
-
const response = yield fetch(this.getUrl(path, queryString), {
|
|
185
|
-
method: "PATCH",
|
|
186
|
-
headers: this.headers,
|
|
187
|
-
body: JSON.stringify(json),
|
|
188
|
-
});
|
|
189
|
-
return yield this.parseResponse(response);
|
|
278
|
+
return this._req(Object.assign(Object.assign({}, opts), { method: "PUT" }));
|
|
190
279
|
});
|
|
191
280
|
}
|
|
192
|
-
|
|
281
|
+
patch(opts) {
|
|
193
282
|
return __awaiter(this, void 0, void 0, function* () {
|
|
194
|
-
this.
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
return
|
|
283
|
+
return this._req(Object.assign(Object.assign({}, opts), { method: "PATCH" }));
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
delete(opts) {
|
|
287
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
288
|
+
return this._req(Object.assign(Object.assign({}, opts), { method: "DELETE" }));
|
|
200
289
|
});
|
|
201
290
|
}
|
|
202
291
|
}
|
|
203
292
|
module.exports = {
|
|
204
293
|
schema: SCHEMA,
|
|
205
294
|
integration: RestIntegration,
|
|
295
|
+
AuthType: datasource_1.AuthType,
|
|
206
296
|
};
|
|
207
297
|
})(RestModule || (RestModule = {}));
|
package/dist/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@budibase/server",
|
|
3
3
|
"email": "hi@budibase.com",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.23-alpha.1",
|
|
5
5
|
"description": "Budibase Web Server",
|
|
6
6
|
"main": "src/index.ts",
|
|
7
7
|
"repository": {
|
|
@@ -69,9 +69,10 @@
|
|
|
69
69
|
"author": "Budibase",
|
|
70
70
|
"license": "GPL-3.0",
|
|
71
71
|
"dependencies": {
|
|
72
|
-
"@
|
|
73
|
-
"@budibase/
|
|
74
|
-
"@budibase/
|
|
72
|
+
"@apidevtools/swagger-parser": "^10.0.3",
|
|
73
|
+
"@budibase/auth": "^1.0.23-alpha.1",
|
|
74
|
+
"@budibase/client": "^1.0.23-alpha.1",
|
|
75
|
+
"@budibase/string-templates": "^1.0.23-alpha.1",
|
|
75
76
|
"@bull-board/api": "^3.7.0",
|
|
76
77
|
"@bull-board/koa": "^3.7.0",
|
|
77
78
|
"@elastic/elasticsearch": "7.10.0",
|
|
@@ -85,12 +86,15 @@
|
|
|
85
86
|
"bull": "^3.22.4",
|
|
86
87
|
"chmodr": "1.2.0",
|
|
87
88
|
"csvtojson": "2.0.10",
|
|
89
|
+
"curlconverter": "^3.21.0",
|
|
88
90
|
"dotenv": "8.2.0",
|
|
89
91
|
"download": "8.0.0",
|
|
90
92
|
"fix-path": "3.0.0",
|
|
93
|
+
"form-data": "^4.0.0",
|
|
91
94
|
"fs-extra": "8.1.0",
|
|
92
95
|
"jimp": "0.16.1",
|
|
93
96
|
"joi": "17.2.1",
|
|
97
|
+
"js-yaml": "^4.1.0",
|
|
94
98
|
"jsonschema": "1.4.0",
|
|
95
99
|
"knex": "^0.95.6",
|
|
96
100
|
"koa": "2.7.0",
|
|
@@ -123,6 +127,7 @@
|
|
|
123
127
|
"validate.js": "0.13.1",
|
|
124
128
|
"vm2": "^3.9.3",
|
|
125
129
|
"worker-farm": "^1.7.0",
|
|
130
|
+
"xml2js": "^0.4.23",
|
|
126
131
|
"yargs": "13.2.4",
|
|
127
132
|
"zlib": "1.0.5"
|
|
128
133
|
},
|
|
@@ -146,6 +151,7 @@
|
|
|
146
151
|
"eslint": "^6.8.0",
|
|
147
152
|
"jest": "^27.0.5",
|
|
148
153
|
"nodemon": "^2.0.4",
|
|
154
|
+
"openapi-types": "^9.3.1",
|
|
149
155
|
"path-to-regexp": "^6.2.0",
|
|
150
156
|
"prettier": "^2.3.1",
|
|
151
157
|
"rimraf": "^3.0.2",
|
|
@@ -8,9 +8,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
-
|
|
11
|
+
require("./utils").threadSetup();
|
|
12
12
|
const env = require("../environment");
|
|
13
|
-
env.setInThread();
|
|
14
13
|
const actions = require("../automations/actions");
|
|
15
14
|
const automationUtils = require("../automations/automationUtils");
|
|
16
15
|
const AutomationEmitter = require("../events/AutomationEmitter");
|
package/dist/threads/query.js
CHANGED
|
@@ -8,9 +8,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
-
|
|
12
|
-
const env = require("../environment");
|
|
13
|
-
env.setInThread();
|
|
11
|
+
require("./utils").threadSetup();
|
|
14
12
|
const ScriptRunner = require("../utilities/scriptRunner");
|
|
15
13
|
const { integrations } = require("../integrations");
|
|
16
14
|
function formatResponse(resp) {
|
|
@@ -24,6 +22,12 @@ function formatResponse(resp) {
|
|
|
24
22
|
}
|
|
25
23
|
return resp;
|
|
26
24
|
}
|
|
25
|
+
function hasExtraData(response) {
|
|
26
|
+
return (typeof response === "object" &&
|
|
27
|
+
!Array.isArray(response) &&
|
|
28
|
+
response.data != null &&
|
|
29
|
+
response.info != null);
|
|
30
|
+
}
|
|
27
31
|
function runAndTransform(datasource, queryVerb, query, transformer) {
|
|
28
32
|
return __awaiter(this, void 0, void 0, function* () {
|
|
29
33
|
const Integration = integrations[datasource.source];
|
|
@@ -31,7 +35,13 @@ function runAndTransform(datasource, queryVerb, query, transformer) {
|
|
|
31
35
|
throw "Integration type does not exist.";
|
|
32
36
|
}
|
|
33
37
|
const integration = new Integration(datasource.config);
|
|
34
|
-
let
|
|
38
|
+
let output = formatResponse(yield integration[queryVerb](query));
|
|
39
|
+
let rows = output, info = undefined, extra = undefined;
|
|
40
|
+
if (hasExtraData(output)) {
|
|
41
|
+
rows = output.data;
|
|
42
|
+
info = output.info;
|
|
43
|
+
extra = output.extra;
|
|
44
|
+
}
|
|
35
45
|
// transform as required
|
|
36
46
|
if (transformer) {
|
|
37
47
|
const runner = new ScriptRunner(transformer, { data: rows });
|
|
@@ -50,7 +60,7 @@ function runAndTransform(datasource, queryVerb, query, transformer) {
|
|
|
50
60
|
if (integration.end) {
|
|
51
61
|
integration.end();
|
|
52
62
|
}
|
|
53
|
-
return { rows, keys };
|
|
63
|
+
return { rows, keys, info, extra };
|
|
54
64
|
});
|
|
55
65
|
}
|
|
56
66
|
module.exports = (input, callback) => {
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const env = require("../environment");
|
|
3
|
+
const CouchDB = require("../db");
|
|
4
|
+
const { init } = require("@budibase/auth");
|
|
5
|
+
exports.threadSetup = () => {
|
|
6
|
+
// don't run this if not threading
|
|
7
|
+
if (env.isTest() || env.DISABLE_THREADING) {
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
// when thread starts, make sure it is recorded
|
|
11
|
+
env.setInThread();
|
|
12
|
+
init(CouchDB);
|
|
13
|
+
};
|