export type CreateApiVulnerabilityArgs = {body: {data?: string | undefined}}; export type CreateApiVulnerabilityOptions = {baseUrl: string, apikey?: string | undefined, fetch?: typeof fetch | undefined}; /** * Endpoint for creating and editing vulnerabilities in the local source * * POST /vulnerability/ */ export const createApiVulnerability = async (args: CreateApiVulnerabilityArgs, options: CreateApiVulnerabilityOptions) => { const {baseUrl, fetch: fetchFn = fetch, apikey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (apikey !== undefined) headers.set("X-API-KEY", apikey) const url = `${baseUrl.replace(/\/+$/, '')}/vulnerability/${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return undefined };