import axios from "axios"; import { withPrefix } from "@/utils/redirect"; import { rethrowSimple } from "@/utils/simple-error"; export interface Dataset { id: string; hid: string; name: string; } export interface DataSource { model_class?: string; tests: Array; } export interface DataSourceTest { attr?: string; result?: string; type?: string; } export interface Plugin { description: string; embeddable?: boolean; data_sources?: Array; help?: string; href: string; html: string; logo?: string; name: string; params?: Record; target?: string; tags?: Array; tests?: Array; } export interface ParamType { required?: boolean; } export interface PluginData { hdas: Array; } export interface TestParamType { ftype?: string; label?: string; name: string; value: string; } export interface TestType { param: TestParamType; } export async function fetchPlugins(datasetId?: string): Promise> { try { const query = datasetId ? `?dataset_id=${datasetId}` : ""; const { data } = await axios.get(withPrefix(`/api/plugins${query}`)); return data; } catch (error) { rethrowSimple(error); } } export async function fetchPlugin(id: string): Promise { try { const { data } = await axios.get(withPrefix(`/api/plugins/${id}`)); return data; } catch (error) { rethrowSimple(error); } } export async function fetchPluginHistoryItems(id: string, history_id: string): Promise { try { const { data } = await axios.get(withPrefix(`/api/plugins/${id}?history_id=${history_id}`)); return data; } catch (error) { rethrowSimple(error); } }