-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathnode.ts
More file actions
41 lines (36 loc) · 1.26 KB
/
node.ts
File metadata and controls
41 lines (36 loc) · 1.26 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
import type { Node } from "~/shared/types";
import type { components } from "~/shared/api/catalogApi.types";
import type { FetchError } from "ofetch";
/**
* use type from auto-generated Hub Catalog OpenAPI types
*/
export type BasicNodeMetaInfo = components["schemas"]["BasicNodeMetaInfo"];
/**
* Fetches details of a single node from KNIME Community Hub, including icon
* preview and Hub URLs. Does return null for deprecated and legacy nodes.
*/
export const fetchNode = async (factoryName: string) => {
try {
const node = await $fetch<BasicNodeMetaInfo>(
"https://corsproxy.io/?url=https://api.hub.knime.com/nodes/" +
factoryName, // corsproxy just to avoid CORS issues on StackBlitz
{
query: {
details: "basic",
},
},
);
// TODO skip deprecated and legacy nodes
// just pick the few props we need & add preview image and Hub URL
const nodeWithPreview: Node = {
id: node.id,
title: node.title,
nodeType: node.nodeType,
preview: "https://hub.knime.com/site/png-icon/Node/" + node.id,
url: "https://hub.knime.com/n/" + node.id.replace("*", ""),
};
return nodeWithPreview;
} catch (error) {
console.error("Failed to fetch node: ", (error as FetchError).data);
}
};