@budibase/server 1.0.6 → 1.0.8-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/builder/assets/{index.4fb3f887.css → index.9337c392.css} +1 -1
- package/builder/assets/{index.8b07ec4f.js → index.db2ce927.js} +160 -160
- package/builder/assets/{vendor.470042a4.js → vendor.a9288856.js} +1 -1
- package/builder/index.html +3 -3
- package/coverage/clover.xml +369 -330
- package/coverage/coverage-final.json +11 -10
- 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 +1 -1
- 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 +9 -24
- 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} +150 -24
- package/coverage/lcov-report/api/controllers/query/validation.js.html +200 -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 +5 -2
- 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 +15 -15
- package/coverage/lcov-report/api/controllers/view/index.js.html +52 -10
- package/coverage/lcov-report/api/controllers/view/utils.js.html +1 -1
- package/coverage/lcov-report/api/controllers/view/viewBuilder.js.html +1 -1
- package/coverage/lcov-report/api/controllers/webhook.js.html +1 -1
- package/coverage/lcov-report/api/index.html +1 -1
- package/coverage/lcov-report/api/index.js.html +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 +1 -1
- package/coverage/lcov-report/api/routes/view.js.html +1 -1
- package/coverage/lcov-report/api/routes/webhook.js.html +1 -1
- package/coverage/lcov-report/automations/actions.js.html +1 -1
- package/coverage/lcov-report/automations/automationUtils.js.html +1 -1
- package/coverage/lcov-report/automations/bullboard.js.html +1 -1
- package/coverage/lcov-report/automations/index.html +1 -1
- 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 +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 +1 -1
- package/coverage/lcov-report/automations/utils.js.html +1 -1
- 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/client.js.html +1 -1
- package/coverage/lcov-report/db/inMemoryView.js.html +1 -1
- package/coverage/lcov-report/db/index.html +1 -1
- package/coverage/lcov-report/db/index.js.html +1 -1
- package/coverage/lcov-report/db/linkedRows/LinkController.js.html +1 -1
- package/coverage/lcov-report/db/linkedRows/index.html +1 -1
- package/coverage/lcov-report/db/linkedRows/index.js.html +1 -1
- package/coverage/lcov-report/db/linkedRows/linkUtils.js.html +1 -1
- package/coverage/lcov-report/db/newid.js.html +4 -4
- package/coverage/lcov-report/db/utils.js.html +58 -58
- 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 +55 -40
- 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 +1 -1
- package/coverage/lcov-report/threads/index.html +1 -1
- package/coverage/lcov-report/threads/index.js.html +1 -1
- package/coverage/lcov-report/threads/query.js.html +1 -1
- 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 +19 -10
- package/coverage/lcov-report/utilities/global.js.html +1 -1
- package/coverage/lcov-report/utilities/index.html +14 -14
- package/coverage/lcov-report/utilities/index.js.html +1 -1
- 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 +1 -1
- 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 +538 -480
- 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} +38 -4
- package/dist/api/controllers/query/validation.js +36 -0
- package/dist/api/controllers/view/index.js +15 -2
- package/dist/api/routes/query.js +2 -32
- package/dist/package.json +8 -4
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utilities/csvParser.js +5 -2
- package/package.json +9 -5
- package/src/api/controllers/query/import/index.ts +85 -0
- package/src/api/controllers/query/import/sources/base/index.ts +86 -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} +46 -4
- package/src/api/controllers/query/validation.js +40 -0
- package/src/api/controllers/table/utils.js +1 -0
- package/src/api/controllers/view/index.js +16 -2
- package/src/api/routes/query.js +5 -34
- package/src/definitions/common.ts +22 -0
- package/src/integrations/oracle.ts +1 -1
- package/src/utilities/csvParser.js +5 -2
|
@@ -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;
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
{
|
|
2
|
+
"swagger": "2.0",
|
|
3
|
+
"info": {
|
|
4
|
+
"description": "A basic swagger file",
|
|
5
|
+
"version": "1.0.0",
|
|
6
|
+
"title": "CRUD"
|
|
7
|
+
},
|
|
8
|
+
"host": "example.com",
|
|
9
|
+
"tags": [
|
|
10
|
+
{
|
|
11
|
+
"name": "entity"
|
|
12
|
+
}
|
|
13
|
+
],
|
|
14
|
+
"schemes": [
|
|
15
|
+
"http"
|
|
16
|
+
],
|
|
17
|
+
"paths": {
|
|
18
|
+
"/entities": {
|
|
19
|
+
"post": {
|
|
20
|
+
"tags": [
|
|
21
|
+
"entity"
|
|
22
|
+
],
|
|
23
|
+
"operationId": "createEntity",
|
|
24
|
+
"consumes": [
|
|
25
|
+
"application/json"
|
|
26
|
+
],
|
|
27
|
+
"produces": [
|
|
28
|
+
"application/json"
|
|
29
|
+
],
|
|
30
|
+
"parameters": [
|
|
31
|
+
{
|
|
32
|
+
"$ref": "#/parameters/CreateEntity"
|
|
33
|
+
}
|
|
34
|
+
],
|
|
35
|
+
"responses": {
|
|
36
|
+
"200": {
|
|
37
|
+
"description": "successful operation",
|
|
38
|
+
"schema": {
|
|
39
|
+
"$ref": "#/definitions/Entity"
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
"get": {
|
|
45
|
+
"tags": [
|
|
46
|
+
"entity"
|
|
47
|
+
],
|
|
48
|
+
"operationId": "getEntities",
|
|
49
|
+
"produces": [
|
|
50
|
+
"application/json"
|
|
51
|
+
],
|
|
52
|
+
"parameters": [
|
|
53
|
+
{
|
|
54
|
+
"$ref": "#/parameters/Page"
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
"$ref": "#/parameters/Size"
|
|
58
|
+
}
|
|
59
|
+
],
|
|
60
|
+
"responses": {
|
|
61
|
+
"200": {
|
|
62
|
+
"description": "successful operation",
|
|
63
|
+
"schema": {
|
|
64
|
+
"$ref": "#/definitions/Entities"
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
"/entities/{entityId}": {
|
|
71
|
+
"parameters": [
|
|
72
|
+
{
|
|
73
|
+
"$ref": "#/parameters/EntityId"
|
|
74
|
+
}
|
|
75
|
+
],
|
|
76
|
+
"get": {
|
|
77
|
+
"tags": [
|
|
78
|
+
"entity"
|
|
79
|
+
],
|
|
80
|
+
"operationId": "getEntity",
|
|
81
|
+
"produces": [
|
|
82
|
+
"application/json"
|
|
83
|
+
],
|
|
84
|
+
"responses": {
|
|
85
|
+
"200": {
|
|
86
|
+
"description": "successful operation",
|
|
87
|
+
"schema": {
|
|
88
|
+
"$ref": "#/definitions/Entity"
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
"put": {
|
|
94
|
+
"tags": [
|
|
95
|
+
"entity"
|
|
96
|
+
],
|
|
97
|
+
"operationId": "updateEntity",
|
|
98
|
+
"consumes": [
|
|
99
|
+
"application/json"
|
|
100
|
+
],
|
|
101
|
+
"produces": [
|
|
102
|
+
"application/json"
|
|
103
|
+
],
|
|
104
|
+
"parameters": [
|
|
105
|
+
{
|
|
106
|
+
"$ref": "#/parameters/Entity"
|
|
107
|
+
}
|
|
108
|
+
],
|
|
109
|
+
"responses": {
|
|
110
|
+
"200": {
|
|
111
|
+
"description": "successful operation",
|
|
112
|
+
"schema": {
|
|
113
|
+
"$ref": "#/definitions/Entity"
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
},
|
|
118
|
+
"patch": {
|
|
119
|
+
"tags": [
|
|
120
|
+
"entity"
|
|
121
|
+
],
|
|
122
|
+
"operationId": "patchEntity",
|
|
123
|
+
"consumes": [
|
|
124
|
+
"application/json"
|
|
125
|
+
],
|
|
126
|
+
"produces": [
|
|
127
|
+
"application/json"
|
|
128
|
+
],
|
|
129
|
+
"parameters": [
|
|
130
|
+
{
|
|
131
|
+
"$ref": "#/parameters/Entity"
|
|
132
|
+
}
|
|
133
|
+
],
|
|
134
|
+
"responses": {
|
|
135
|
+
"200": {
|
|
136
|
+
"description": "successful operation",
|
|
137
|
+
"schema": {
|
|
138
|
+
"$ref": "#/definitions/Entity"
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
},
|
|
143
|
+
"delete": {
|
|
144
|
+
"tags": [
|
|
145
|
+
"entity"
|
|
146
|
+
],
|
|
147
|
+
"parameters": [
|
|
148
|
+
{
|
|
149
|
+
"$ref": "#/parameters/APIKey"
|
|
150
|
+
}
|
|
151
|
+
],
|
|
152
|
+
"operationId": "deleteEntity",
|
|
153
|
+
"produces": [
|
|
154
|
+
"application/json"
|
|
155
|
+
],
|
|
156
|
+
"responses": {
|
|
157
|
+
"204": {
|
|
158
|
+
"description": "successful operation"
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
},
|
|
164
|
+
"parameters": {
|
|
165
|
+
"EntityId": {
|
|
166
|
+
"type": "integer",
|
|
167
|
+
"format": "int64",
|
|
168
|
+
"name": "entityId",
|
|
169
|
+
"in": "path",
|
|
170
|
+
"required": true
|
|
171
|
+
},
|
|
172
|
+
"CreateEntity": {
|
|
173
|
+
"name": "entity",
|
|
174
|
+
"in": "body",
|
|
175
|
+
"required": true,
|
|
176
|
+
"schema": {
|
|
177
|
+
"$ref": "#/definitions/CreateEntity"
|
|
178
|
+
}
|
|
179
|
+
},
|
|
180
|
+
"Entity": {
|
|
181
|
+
"name": "entity",
|
|
182
|
+
"in": "body",
|
|
183
|
+
"required": true,
|
|
184
|
+
"schema": {
|
|
185
|
+
"$ref": "#/definitions/Entity"
|
|
186
|
+
}
|
|
187
|
+
},
|
|
188
|
+
"Page": {
|
|
189
|
+
"type": "integer",
|
|
190
|
+
"format": "int32",
|
|
191
|
+
"name": "page",
|
|
192
|
+
"in": "query",
|
|
193
|
+
"required": false
|
|
194
|
+
},
|
|
195
|
+
"Size": {
|
|
196
|
+
"type": "integer",
|
|
197
|
+
"format": "int32",
|
|
198
|
+
"name": "size",
|
|
199
|
+
"in": "query",
|
|
200
|
+
"required": false
|
|
201
|
+
},
|
|
202
|
+
"APIKey": {
|
|
203
|
+
"type": "string",
|
|
204
|
+
"name": "x-api-key",
|
|
205
|
+
"in": "header",
|
|
206
|
+
"required": false
|
|
207
|
+
}
|
|
208
|
+
},
|
|
209
|
+
"definitions": {
|
|
210
|
+
"CreateEntity": {
|
|
211
|
+
"type": "object",
|
|
212
|
+
"properties": {
|
|
213
|
+
"name": {
|
|
214
|
+
"type": "string"
|
|
215
|
+
},
|
|
216
|
+
"type": {
|
|
217
|
+
"type": "string"
|
|
218
|
+
}
|
|
219
|
+
},
|
|
220
|
+
"example": {
|
|
221
|
+
"name": "name",
|
|
222
|
+
"type": "type"
|
|
223
|
+
}
|
|
224
|
+
},
|
|
225
|
+
"Entity": {
|
|
226
|
+
"allOf": [
|
|
227
|
+
{
|
|
228
|
+
"type": "object",
|
|
229
|
+
"properties": {
|
|
230
|
+
"id": {
|
|
231
|
+
"type": "integer",
|
|
232
|
+
"format": "int64"
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
},
|
|
236
|
+
{
|
|
237
|
+
"$ref": "#/definitions/CreateEntity"
|
|
238
|
+
}
|
|
239
|
+
],
|
|
240
|
+
"example": {
|
|
241
|
+
"id": 1,
|
|
242
|
+
"name": "name",
|
|
243
|
+
"type": "type"
|
|
244
|
+
}
|
|
245
|
+
},
|
|
246
|
+
"Entities" : {
|
|
247
|
+
"type": "array",
|
|
248
|
+
"items": {
|
|
249
|
+
"$ref": "#/definitions/Entity"
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
}
|