@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
|
@@ -12,10 +12,12 @@ const CouchDB = require("../../db");
|
|
|
12
12
|
const actions = require("../../automations/actions");
|
|
13
13
|
const triggers = require("../../automations/triggers");
|
|
14
14
|
const { getAutomationParams, generateAutomationID } = require("../../db/utils");
|
|
15
|
-
const { checkForWebhooks, updateTestHistory, } = require("../../automations/utils");
|
|
15
|
+
const { checkForWebhooks, updateTestHistory, removeDeprecated, } = require("../../automations/utils");
|
|
16
16
|
const { deleteEntityMetadata } = require("../../utilities");
|
|
17
17
|
const { MetadataTypes } = require("../../constants");
|
|
18
18
|
const { setTestFlag, clearTestFlag } = require("../../utilities/redis");
|
|
19
|
+
const ACTION_DEFS = removeDeprecated(actions.ACTION_DEFINITIONS);
|
|
20
|
+
const TRIGGER_DEFS = removeDeprecated(triggers.TRIGGER_DEFINITIONS);
|
|
19
21
|
/*************************
|
|
20
22
|
* *
|
|
21
23
|
* BUILDER FUNCTIONS *
|
|
@@ -137,19 +139,19 @@ exports.destroy = function (ctx) {
|
|
|
137
139
|
};
|
|
138
140
|
exports.getActionList = function (ctx) {
|
|
139
141
|
return __awaiter(this, void 0, void 0, function* () {
|
|
140
|
-
ctx.body =
|
|
142
|
+
ctx.body = ACTION_DEFS;
|
|
141
143
|
});
|
|
142
144
|
};
|
|
143
145
|
exports.getTriggerList = function (ctx) {
|
|
144
146
|
return __awaiter(this, void 0, void 0, function* () {
|
|
145
|
-
ctx.body =
|
|
147
|
+
ctx.body = TRIGGER_DEFS;
|
|
146
148
|
});
|
|
147
149
|
};
|
|
148
150
|
module.exports.getDefinitionList = function (ctx) {
|
|
149
151
|
return __awaiter(this, void 0, void 0, function* () {
|
|
150
152
|
ctx.body = {
|
|
151
|
-
trigger:
|
|
152
|
-
action:
|
|
153
|
+
trigger: TRIGGER_DEFS,
|
|
154
|
+
action: ACTION_DEFS,
|
|
153
155
|
};
|
|
154
156
|
});
|
|
155
157
|
};
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.RestImporter = void 0;
|
|
16
|
+
const db_1 = __importDefault(require("../../../../db"));
|
|
17
|
+
const validation_1 = require("../validation");
|
|
18
|
+
const utils_1 = require("../../../../db/utils");
|
|
19
|
+
const openapi2_1 = require("./sources/openapi2");
|
|
20
|
+
const curl_1 = require("./sources/curl");
|
|
21
|
+
class RestImporter {
|
|
22
|
+
constructor(data) {
|
|
23
|
+
this.init = () => __awaiter(this, void 0, void 0, function* () {
|
|
24
|
+
for (let source of this.sources) {
|
|
25
|
+
if (yield source.isSupported(this.data)) {
|
|
26
|
+
this.source = source;
|
|
27
|
+
break;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
this.getInfo = () => __awaiter(this, void 0, void 0, function* () {
|
|
32
|
+
return this.source.getInfo();
|
|
33
|
+
});
|
|
34
|
+
this.importQueries = (appId, datasourceId) => __awaiter(this, void 0, void 0, function* () {
|
|
35
|
+
// constuct the queries
|
|
36
|
+
let queries = yield this.source.getQueries(datasourceId);
|
|
37
|
+
// validate queries
|
|
38
|
+
const errorQueries = [];
|
|
39
|
+
const schema = validation_1.queryValidation();
|
|
40
|
+
queries = queries
|
|
41
|
+
.filter(query => {
|
|
42
|
+
const validation = schema.validate(query);
|
|
43
|
+
if (validation.error) {
|
|
44
|
+
errorQueries.push(query);
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
return true;
|
|
48
|
+
})
|
|
49
|
+
.map(query => {
|
|
50
|
+
query._id = utils_1.generateQueryID(query.datasourceId);
|
|
51
|
+
return query;
|
|
52
|
+
});
|
|
53
|
+
// persist queries
|
|
54
|
+
const db = new db_1.default(appId);
|
|
55
|
+
const response = yield db.bulkDocs(queries);
|
|
56
|
+
// create index to seperate queries and errors
|
|
57
|
+
const queryIndex = queries.reduce((acc, query) => {
|
|
58
|
+
if (query._id) {
|
|
59
|
+
acc[query._id] = query;
|
|
60
|
+
}
|
|
61
|
+
return acc;
|
|
62
|
+
}, {});
|
|
63
|
+
// check for failed writes
|
|
64
|
+
response.forEach((query) => {
|
|
65
|
+
if (!query.ok) {
|
|
66
|
+
errorQueries.push(queryIndex[query.id]);
|
|
67
|
+
delete queryIndex[query.id];
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
return {
|
|
71
|
+
errorQueries,
|
|
72
|
+
queries: Object.values(queryIndex),
|
|
73
|
+
};
|
|
74
|
+
});
|
|
75
|
+
this.data = data;
|
|
76
|
+
this.sources = [new openapi2_1.OpenAPI2(), new curl_1.Curl()];
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
exports.RestImporter = RestImporter;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ImportSource = void 0;
|
|
4
|
+
var MethodToVerb;
|
|
5
|
+
(function (MethodToVerb) {
|
|
6
|
+
MethodToVerb["get"] = "read";
|
|
7
|
+
MethodToVerb["post"] = "create";
|
|
8
|
+
MethodToVerb["put"] = "update";
|
|
9
|
+
MethodToVerb["patch"] = "patch";
|
|
10
|
+
MethodToVerb["delete"] = "delete";
|
|
11
|
+
})(MethodToVerb || (MethodToVerb = {}));
|
|
12
|
+
class ImportSource {
|
|
13
|
+
constructor() {
|
|
14
|
+
this.constructQuery = (datasourceId, name, method, path, queryString, headers = {}, parameters = [], body = undefined) => {
|
|
15
|
+
const readable = true;
|
|
16
|
+
const queryVerb = this.verbFromMethod(method);
|
|
17
|
+
const transformer = "return data";
|
|
18
|
+
const schema = {};
|
|
19
|
+
path = this.processPath(path);
|
|
20
|
+
queryString = this.processQuery(queryString);
|
|
21
|
+
const requestBody = JSON.stringify(body, null, 2);
|
|
22
|
+
const query = {
|
|
23
|
+
datasourceId,
|
|
24
|
+
name,
|
|
25
|
+
parameters,
|
|
26
|
+
fields: {
|
|
27
|
+
headers,
|
|
28
|
+
queryString,
|
|
29
|
+
path,
|
|
30
|
+
requestBody,
|
|
31
|
+
},
|
|
32
|
+
transformer,
|
|
33
|
+
schema,
|
|
34
|
+
readable,
|
|
35
|
+
queryVerb,
|
|
36
|
+
};
|
|
37
|
+
return query;
|
|
38
|
+
};
|
|
39
|
+
this.verbFromMethod = (method) => {
|
|
40
|
+
const verb = MethodToVerb[method];
|
|
41
|
+
if (!verb) {
|
|
42
|
+
throw new Error(`Unsupported method: ${method}`);
|
|
43
|
+
}
|
|
44
|
+
return verb;
|
|
45
|
+
};
|
|
46
|
+
this.processPath = (path) => {
|
|
47
|
+
if (path === null || path === void 0 ? void 0 : path.startsWith("/")) {
|
|
48
|
+
path = path.substring(1);
|
|
49
|
+
}
|
|
50
|
+
// add extra braces around params for binding
|
|
51
|
+
path = path.replace(/[{]/g, "{{");
|
|
52
|
+
path = path.replace(/[}]/g, "}}");
|
|
53
|
+
return path;
|
|
54
|
+
};
|
|
55
|
+
this.processQuery = (queryString) => {
|
|
56
|
+
if (queryString === null || queryString === void 0 ? void 0 : queryString.startsWith("?")) {
|
|
57
|
+
return queryString.substring(1);
|
|
58
|
+
}
|
|
59
|
+
return queryString;
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
exports.ImportSource = ImportSource;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.OpenAPISource = void 0;
|
|
16
|
+
const _1 = require(".");
|
|
17
|
+
const swagger_parser_1 = __importDefault(require("@apidevtools/swagger-parser"));
|
|
18
|
+
const yaml = require("js-yaml");
|
|
19
|
+
class OpenAPISource extends _1.ImportSource {
|
|
20
|
+
constructor() {
|
|
21
|
+
super(...arguments);
|
|
22
|
+
this.parseData = (data) => __awaiter(this, void 0, void 0, function* () {
|
|
23
|
+
let json;
|
|
24
|
+
try {
|
|
25
|
+
json = JSON.parse(data);
|
|
26
|
+
}
|
|
27
|
+
catch (jsonErr) {
|
|
28
|
+
// couldn't parse json
|
|
29
|
+
// try to convert yaml -> json
|
|
30
|
+
try {
|
|
31
|
+
json = yaml.load(data);
|
|
32
|
+
}
|
|
33
|
+
catch (yamlErr) {
|
|
34
|
+
// couldn't parse yaml
|
|
35
|
+
throw new Error("Could not parse JSON or YAML");
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return swagger_parser_1.default.validate(json, {});
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
exports.OpenAPISource = OpenAPISource;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.Curl = void 0;
|
|
13
|
+
const base_1 = require("./base");
|
|
14
|
+
const url_1 = require("url");
|
|
15
|
+
const curlconverter = require("curlconverter");
|
|
16
|
+
const parseCurl = (data) => {
|
|
17
|
+
const curlJson = curlconverter.toJsonString(data);
|
|
18
|
+
return JSON.parse(curlJson);
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* The curl converter parses the request body into the key field of an object
|
|
22
|
+
* e.g. --d '{"key":"val"}' produces an object { "{"key":"val"}" : "" }
|
|
23
|
+
* This is not what we want, so we need to parse out the key from the object
|
|
24
|
+
*/
|
|
25
|
+
const parseBody = (curl) => {
|
|
26
|
+
if (curl.data) {
|
|
27
|
+
const keys = Object.keys(curl.data);
|
|
28
|
+
if (keys.length) {
|
|
29
|
+
const key = keys[0];
|
|
30
|
+
try {
|
|
31
|
+
return JSON.parse(key);
|
|
32
|
+
}
|
|
33
|
+
catch (e) {
|
|
34
|
+
// do nothing
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return undefined;
|
|
39
|
+
};
|
|
40
|
+
const parseCookie = (curl) => {
|
|
41
|
+
if (curl.cookies) {
|
|
42
|
+
return Object.entries(curl.cookies).reduce((acc, entry) => {
|
|
43
|
+
const [key, value] = entry;
|
|
44
|
+
return acc + `${key}=${value}; `;
|
|
45
|
+
}, "");
|
|
46
|
+
}
|
|
47
|
+
return null;
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Curl
|
|
51
|
+
* https://curl.se/docs/manpage.html
|
|
52
|
+
*/
|
|
53
|
+
class Curl extends base_1.ImportSource {
|
|
54
|
+
constructor() {
|
|
55
|
+
super(...arguments);
|
|
56
|
+
this.isSupported = (data) => __awaiter(this, void 0, void 0, function* () {
|
|
57
|
+
try {
|
|
58
|
+
const curl = parseCurl(data);
|
|
59
|
+
this.curl = curl;
|
|
60
|
+
}
|
|
61
|
+
catch (err) {
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
return true;
|
|
65
|
+
});
|
|
66
|
+
this.getInfo = () => __awaiter(this, void 0, void 0, function* () {
|
|
67
|
+
const url = new url_1.URL(this.curl.url);
|
|
68
|
+
return {
|
|
69
|
+
url: url.origin,
|
|
70
|
+
name: url.hostname,
|
|
71
|
+
};
|
|
72
|
+
});
|
|
73
|
+
this.getQueries = (datasourceId) => __awaiter(this, void 0, void 0, function* () {
|
|
74
|
+
const url = new url_1.URL(this.curl.raw_url);
|
|
75
|
+
const name = url.pathname;
|
|
76
|
+
const path = url.pathname;
|
|
77
|
+
const method = this.curl.method;
|
|
78
|
+
const queryString = url.search;
|
|
79
|
+
const headers = this.curl.headers;
|
|
80
|
+
const requestBody = parseBody(this.curl);
|
|
81
|
+
const cookieHeader = parseCookie(this.curl);
|
|
82
|
+
if (cookieHeader) {
|
|
83
|
+
headers["Cookie"] = cookieHeader;
|
|
84
|
+
}
|
|
85
|
+
const query = this.constructQuery(datasourceId, name, method, path, queryString, headers, [], requestBody);
|
|
86
|
+
return [query];
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
exports.Curl = Curl;
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.OpenAPI2 = void 0;
|
|
13
|
+
const openapi_types_1 = require("openapi-types");
|
|
14
|
+
const openapi_1 = require("./base/openapi");
|
|
15
|
+
const parameterNotRef = (param) => {
|
|
16
|
+
// all refs are deferenced by parser library
|
|
17
|
+
return true;
|
|
18
|
+
};
|
|
19
|
+
const isOpenAPI2 = (document) => {
|
|
20
|
+
if (document.swagger === "2.0") {
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
const methods = Object.values(openapi_types_1.OpenAPIV2.HttpMethods);
|
|
28
|
+
const isOperation = (key, pathItem) => {
|
|
29
|
+
return methods.includes(key);
|
|
30
|
+
};
|
|
31
|
+
const isParameter = (key, pathItem) => {
|
|
32
|
+
return !isOperation(key, pathItem);
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* OpenAPI Version 2.0 - aka "Swagger"
|
|
36
|
+
* https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md
|
|
37
|
+
*/
|
|
38
|
+
class OpenAPI2 extends openapi_1.OpenAPISource {
|
|
39
|
+
constructor() {
|
|
40
|
+
super(...arguments);
|
|
41
|
+
this.isSupported = (data) => __awaiter(this, void 0, void 0, function* () {
|
|
42
|
+
try {
|
|
43
|
+
const document = yield this.parseData(data);
|
|
44
|
+
if (isOpenAPI2(document)) {
|
|
45
|
+
this.document = document;
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
catch (err) {
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
this.getInfo = () => __awaiter(this, void 0, void 0, function* () {
|
|
57
|
+
var _a;
|
|
58
|
+
const scheme = ((_a = this.document.schemes) === null || _a === void 0 ? void 0 : _a.includes("https")) ? "https" : "http";
|
|
59
|
+
const basePath = this.document.basePath || "";
|
|
60
|
+
const host = this.document.host || "<host>";
|
|
61
|
+
const url = `${scheme}://${host}${basePath}`;
|
|
62
|
+
const name = this.document.info.title || "Swagger Import";
|
|
63
|
+
return {
|
|
64
|
+
url: url,
|
|
65
|
+
name: name,
|
|
66
|
+
};
|
|
67
|
+
});
|
|
68
|
+
this.getQueries = (datasourceId) => __awaiter(this, void 0, void 0, function* () {
|
|
69
|
+
const queries = [];
|
|
70
|
+
for (let [path, pathItem] of Object.entries(this.document.paths)) {
|
|
71
|
+
// parameters that apply to every operation in the path
|
|
72
|
+
let pathParams = [];
|
|
73
|
+
for (let [key, opOrParams] of Object.entries(pathItem)) {
|
|
74
|
+
if (isParameter(key, opOrParams)) {
|
|
75
|
+
const pathParameters = opOrParams;
|
|
76
|
+
pathParams.push(...pathParameters);
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
// can not be a parameter, must be an operation
|
|
80
|
+
const operation = opOrParams;
|
|
81
|
+
const methodName = key;
|
|
82
|
+
const name = operation.operationId || path;
|
|
83
|
+
let queryString = "";
|
|
84
|
+
const headers = {};
|
|
85
|
+
let requestBody = undefined;
|
|
86
|
+
const parameters = [];
|
|
87
|
+
if (operation.consumes) {
|
|
88
|
+
headers["Content-Type"] = operation.consumes[0];
|
|
89
|
+
}
|
|
90
|
+
// combine the path parameters with the operation parameters
|
|
91
|
+
const operationParams = operation.parameters || [];
|
|
92
|
+
const allParams = [...pathParams, ...operationParams];
|
|
93
|
+
for (let param of allParams) {
|
|
94
|
+
if (parameterNotRef(param)) {
|
|
95
|
+
switch (param.in) {
|
|
96
|
+
case "query":
|
|
97
|
+
let prefix = "";
|
|
98
|
+
if (queryString) {
|
|
99
|
+
prefix = "&";
|
|
100
|
+
}
|
|
101
|
+
queryString = `${queryString}${prefix}${param.name}={{${param.name}}}`;
|
|
102
|
+
break;
|
|
103
|
+
case "header":
|
|
104
|
+
headers[param.name] = `{{${param.name}}}`;
|
|
105
|
+
break;
|
|
106
|
+
case "path":
|
|
107
|
+
// do nothing: param is already in the path
|
|
108
|
+
break;
|
|
109
|
+
case "formData":
|
|
110
|
+
// future enhancement
|
|
111
|
+
break;
|
|
112
|
+
case "body":
|
|
113
|
+
// set the request body to the example provided
|
|
114
|
+
// future enhancement: generate an example from the schema
|
|
115
|
+
let bodyParam = param;
|
|
116
|
+
if (param.schema.example) {
|
|
117
|
+
const schema = bodyParam.schema;
|
|
118
|
+
requestBody = schema.example;
|
|
119
|
+
}
|
|
120
|
+
break;
|
|
121
|
+
}
|
|
122
|
+
// add the parameter if it can be bound in our config
|
|
123
|
+
if (["query", "header", "path"].includes(param.in)) {
|
|
124
|
+
parameters.push({
|
|
125
|
+
name: param.name,
|
|
126
|
+
default: param.default || "",
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
const query = this.constructQuery(datasourceId, name, methodName, path, queryString, headers, parameters, requestBody);
|
|
132
|
+
queries.push(query);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
return queries;
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
exports.OpenAPI2 = OpenAPI2;
|