|
| 1 | +import{readYaml}from"../../common/util"; |
| 2 | +import_from"lodash"; |
| 3 | +importpathfrom"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 | +importspecfrom'./supabaseApi.spec.json'; |
| 10 | + |
| 11 | +constdataSourceConfig={ |
| 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 | +}asconst; |
| 40 | + |
| 41 | +constparseOptions:ParseOpenApiOptions={ |
| 42 | +actionLabel:(method:string,path:string,operation:OpenAPI.Operation)=>{ |
| 43 | +return_.upperFirst(operation.operationId||""); |
| 44 | +}, |
| 45 | +}; |
| 46 | + |
| 47 | +typeDataSourceConfigType=ConfigToType<typeofdataSourceConfig>; |
| 48 | + |
| 49 | +constsupabaseApiPlugin: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}=awaitparseOpenApi(specasunknownasOpenAPI.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 | +construnApiDsConfig={ |
| 70 | +url:"", |
| 71 | +serverURL:serverURL, |
| 72 | +dynamicParamsConfig:otherDataSourceConfig, |
| 73 | +}; |
| 74 | + |
| 75 | +console.log("runApiDsConfig",runApiDsConfig); |
| 76 | + |
| 77 | +returnrunOpenApi(actionData,runApiDsConfig,specasOpenAPIV3.Document); |
| 78 | +}, |
| 79 | +}; |
| 80 | + |
| 81 | +exportdefaultsupabaseApiPlugin; |