export type PluginPrivilege = {Name?: string | undefined, Description?: string | undefined, Value?: Array | undefined}; export type CreateApiPluginsNameUpgradeArgs = {name: string, remote: string, 'X-Registry-Auth'?: string | undefined, body: Array}; export type CreateApiPluginsNameUpgradeOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; /** * Upgrade a plugin * * POST /plugins/{name}/upgrade */ export const createApiPluginsNameUpgrade = async (args: CreateApiPluginsNameUpgradeArgs, options: CreateApiPluginsNameUpgradeOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (args.remote != null) query.append("remote", String(args.remote)) if (args['X-Registry-Auth'] != null) headers.set("X-Registry-Auth", String(args['X-Registry-Auth'])) const url = `${baseUrl.replace(/\/+$/, '')}/plugins/${encodeURIComponent(String(args.name))}/upgrade${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 };