export type UpdateApiJudgmentUriArgs = {judgmentUri: string, 'If-Match': string}; export type UpdateApiJudgmentUriOptions = {baseUrl?: string | undefined, basic?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; /** * Update a judgment * * PUT /{judgmentUri} */ export const updateApiJudgmentUri = async (args: UpdateApiJudgmentUriArgs, options?: UpdateApiJudgmentUriOptions) => { const {baseUrl = "https://api.caselaw.nationalarchives.gov.uk/v1", fetch: fetchFn = fetch, basic} = options ?? {} const query = new URLSearchParams() const headers = new Headers() if (args['If-Match'] != null) headers.set("If-Match", String(args['If-Match'])) if (basic !== undefined) headers.set('authorization', `Basic ${btoa(`${basic.username}:${basic.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/${encodeURIComponent(String(args.judgmentUri))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return undefined };