export type CreateApiPluginsCreateArgs = {name: string, body: BodyInit}; export type CreateApiPluginsCreateOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; /** * Create a plugin * * POST /plugins/create */ export const createApiPluginsCreate = async (args: CreateApiPluginsCreateArgs, options: CreateApiPluginsCreateOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/x-tar") if (args.name != null) query.append("name", String(args.name)) const url = `${baseUrl.replace(/\/+$/, '')}/plugins/create${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: args.body}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return undefined };