export type Interface = {name?: string | undefined, ip?: string | undefined, mac?: string | undefined}; export type Key = {key?: string | undefined, keyfile?: string | undefined, until?: string | undefined}; export type Instance = {hash?: string | undefined, interface?: Interface | undefined, port?: string | undefined, key?: Key | undefined}; export type DeleteApiInstanceArgs = {hash: Instance}; export type DeleteApiInstanceOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; /** * Destroy P2P instance * * DELETE /instance */ export const deleteApiInstance = async (args: DeleteApiInstanceArgs, options?: DeleteApiInstanceOptions) => { const {baseUrl = "http://localhost/v1", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() if (args.hash != null) query.append("hash", JSON.stringify(args.hash)) const url = `${baseUrl.replace(/\/+$/, '')}/instance${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "DELETE", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return undefined };