Skip to content

Commit 04720e5

Browse files
Esievesunlei
authored andcommitted
feat: SendGrid
1 parent e337fa0 commit 04720e5

File tree

2 files changed

+47966
-667
lines changed

2 files changed

+47966
-667
lines changed

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

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,18 @@ import spec from "./sendGrid.spec.json";
88

99
const dataSourceConfig = {
1010
type: "dataSource",
11-
params: [],
11+
params: [
12+
{
13+
"type": "password",
14+
"key": "Authorization.value",
15+
"label": "API Key",
16+
"tooltip": "[Documentation](https://docs.sendgrid.com/ui/account-and-settings/api-keys#creating-an-api-key)"
17+
}
18+
]
1219
} as const;
1320

1421
const parseOptions: ParseOpenApiOptions = {
15-
actionLabel: (method: string, path: string, operation: OpenAPI.Operation) => {
16-
return _.upperFirst(operation.operationId || "");
17-
},
22+
actionLabel: (method: string, path: string, operation: OpenAPI.Operation) => operation.operationId?.replace('_', ' ') || "",
1823
};
1924

2025
type DataSourceConfigType = ConfigToType<typeof dataSourceConfig>;
@@ -26,15 +31,12 @@ const sendGridPlugin: DataSourcePlugin<any, DataSourceConfigType> = {
2631
category: "api",
2732
dataSourceConfig,
2833
queryConfig: async () => {
29-
const { actions, categories } = await parseOpenApi(
30-
spec as unknown as OpenAPI.Document,
31-
parseOptions
32-
);
34+
const { actions, categories } = await parseOpenApi(spec as unknown as OpenAPI.Document, parseOptions);
3335
return {
3436
type: "query",
3537
label: "Action",
3638
categories: {
37-
label: "Category",
39+
label: "Resources",
3840
items: categories,
3941
},
4042
actions,
@@ -43,10 +45,13 @@ const sendGridPlugin: DataSourcePlugin<any, DataSourceConfigType> = {
4345
run: function (actionData, dataSourceConfig): Promise<any> {
4446
const runApiDsConfig = {
4547
url: "",
46-
serverURL: "",
47-
dynamicParamsConfig: dataSourceConfig,
48+
serverURL: "https://api.sendgrid.com/v3",
49+
dynamicParamsConfig: {
50+
...dataSourceConfig,
51+
'Authorization.value': 'Bearer ' + dataSourceConfig['Authorization.value']
52+
},
4853
};
49-
return runOpenApi(actionData, runApiDsConfig, spec as unknown as OpenAPIV3.Document);
54+
return runOpenApi(actionData, runApiDsConfig, spec as OpenAPIV3.Document);
5055
},
5156
};
5257

0 commit comments

Comments
 (0)