-
Notifications
You must be signed in to change notification settings - Fork 301
Expand file tree
/
Copy pathindex.ts
More file actions
82 lines (76 loc) · 2.52 KB
/
index.ts
File metadata and controls
82 lines (76 loc) · 2.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import { readYaml, specsToOptions, version2spec } from "../../common/util";
import _ from "lodash";
import path from "path";
import { OpenAPIV3, OpenAPI } from "openapi-types";
import { ConfigToType, DataSourcePlugin } from "lowcoder-sdk/dataSource";
import { runOpenApi } from "../openApi";
import { parseOpenApi, ParseOpenApiOptions } from "../openApi/parse";
import SwaggerParser from "@apidevtools/swagger-parser";
const spec = readYaml(path.join(__dirname, "./github.spec.yaml"));
const specs = {
"v1.0": spec,
}
const dataSourceConfig = {
type: "dataSource",
params: [
{
type: "textInput",
key: "ApiKey.username",
label: "Username",
tooltip: "The username of your GitHub account.",
placeholder: "<Your GitHub username>",
},
{
type: "password",
key: "ApiKey.password",
label: "Password",
tooltip:
"[Document](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token) about how to create a personal access token",
placeholder: "<Your Personal Access Token>",
},
{
label: "Spec Version",
key: "specVersion",
type: "select",
tooltip: "Version of the spec file.",
placeholder: "v1.0",
options: specsToOptions(specs)
},
],
} as const;
const parseOptions: ParseOpenApiOptions = {
actionLabel: (method: string, path: string, operation: OpenAPI.Operation) => {
return _.upperFirst(operation.operationId || "");
},
};
const deRefedSpec = SwaggerParser.dereference(spec);
type DataSourceConfigType = ConfigToType<typeof dataSourceConfig>;
const gitHubPlugin: DataSourcePlugin<any, DataSourceConfigType> = {
id: "github",
name: "GitHub",
icon: "github.svg",
category: "App Development",
dataSourceConfig,
queryConfig: async (data) => {
const { actions, categories } = await parseOpenApi(version2spec(specs, data.specVersion), parseOptions);
return {
type: "query",
label: "Action",
categories: {
label: "Resources",
items: categories,
},
actions,
};
},
run: async function (actionData, dataSourceConfig, ctx): Promise<any> {
const runApiDsConfig = {
url: "",
serverURL: "https://api.github.com",
dynamicParamsConfig: dataSourceConfig,
specVersion: dataSourceConfig.specVersion,
};
return runOpenApi(actionData, runApiDsConfig, version2spec(specs, dataSourceConfig.specVersion) as OpenAPIV3.Document, undefined, await deRefedSpec);
},
};
export default gitHubPlugin;