export type ContributionBody = {contributionId: string, userId: string, actionNotes?: string | undefined, justificationId?: number | undefined}; export type UpdateApiContributionsArgs = {review?: boolean | undefined, body: ContributionBody}; export type UpdateApiContributionsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; /** * Update a contribution. * * PUT /contributions/ */ export const updateApiContributions = async (args: UpdateApiContributionsArgs, options?: UpdateApiContributionsOptions) => { const {baseUrl = "https://catalog.archives.gov/api/v2", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (args.review != null) query.append("review", String(args.review)) const url = `${baseUrl.replace(/\/+$/, '')}/contributions/${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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 };