Skip to content

Commit dfd71b5

Browse files
author
FalkWolsky
committed
Supabase Management API as Data Source
1 parent a62f1f2 commit dfd71b5

File tree

3 files changed

+7603
-0
lines changed

3 files changed

+7603
-0
lines changed

server/node-service/src/plugins/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import appConfigPlugin from "./appconfig";
3636
import tursoPlugin from "./turso";
3737
import postmanEchoPlugin from "./postmanEcho";
3838
import lowcoderPlugin from "./lowcoder";
39+
import supabaseApiPlugin from "./supabaseApi";
3940

4041
let plugins: (DataSourcePlugin | DataSourcePluginFactory)[] = [
4142
s3Plugin,
@@ -75,6 +76,7 @@ let plugins: (DataSourcePlugin | DataSourcePluginFactory)[] = [
7576
tursoPlugin,
7677
postmanEchoPlugin,
7778
lowcoderPlugin,
79+
supabaseApiPlugin,
7880
];
7981

8082
try {
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import { readYaml } from "../../common/util";
2+
import _ from "lodash";
3+
import path from "path";
4+
import { OpenAPIV3, OpenAPI } from "openapi-types";
5+
import { ConfigToType, DataSourcePlugin } from "lowcoder-sdk/dataSource";
6+
import { runOpenApi } from "../openApi";
7+
import { parseOpenApi, ParseOpenApiOptions } from "../openApi/parse";
8+
9+
import spec from './supabaseApi.spec.json';
10+
11+
const dataSourceConfig = {
12+
type: "dataSource",
13+
params: [
14+
{
15+
"type": "groupTitle",
16+
"key": "serverURL",
17+
"label": "Supabase API Url"
18+
},
19+
{
20+
key: "serverURL",
21+
type: "textInput",
22+
label: "Server URL",
23+
rules: [{ required: true, message: "The server url is required" }],
24+
placeholder: "https://<your couchdb server host>",
25+
},
26+
{
27+
"type": "groupTitle",
28+
"key": "bearerAuth",
29+
"label": "Api Token Auth"
30+
},
31+
{
32+
"type": "password",
33+
"key": "bearerAuth.value",
34+
"label": "Token",
35+
"tooltip": "API Key Authentication with a Bearer token. Copy your API Key from Supabase here. (e.g. 'eyJhbGciO...'",
36+
"placeholder": "API Key Authentication with a Bearer token. Copy your API Key from Supabase here. (e.g. 'eyJhbGciO...'"
37+
}
38+
]
39+
} as const;
40+
41+
const parseOptions: ParseOpenApiOptions = {
42+
actionLabel: (method: string, path: string, operation: OpenAPI.Operation) => {
43+
return _.upperFirst(operation.operationId || "");
44+
},
45+
};
46+
47+
type DataSourceConfigType = ConfigToType<typeof dataSourceConfig>;
48+
49+
const supabaseApiPlugin: DataSourcePlugin<any, DataSourceConfigType> = {
50+
id: "supabaseApi",
51+
name: "Supabase Mgmt API",
52+
icon: "supabase.svg",
53+
category: "api",
54+
dataSourceConfig,
55+
queryConfig: async () => {
56+
const { actions, categories } = await parseOpenApi(spec as unknown as OpenAPI.Document, parseOptions);
57+
return {
58+
type: "query",
59+
label: "Action",
60+
categories: {
61+
label: "Resources",
62+
items: categories,
63+
},
64+
actions,
65+
};
66+
},
67+
run: function (actionData, dataSourceConfig): Promise<any> {
68+
const { serverURL, ...otherDataSourceConfig } = dataSourceConfig;
69+
const runApiDsConfig = {
70+
url: "",
71+
serverURL: serverURL,
72+
dynamicParamsConfig: otherDataSourceConfig,
73+
};
74+
75+
console.log("runApiDsConfig", runApiDsConfig);
76+
77+
return runOpenApi(actionData, runApiDsConfig, spec as OpenAPIV3.Document);
78+
},
79+
};
80+
81+
export default supabaseApiPlugin;

0 commit comments

Comments
 (0)