export type GetApiJudgmentUriLockArgs = {judgmentUri: string}; export type GetApiJudgmentUriLockOptions = {baseUrl?: string | undefined, basic?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; /** * Query lock status for a document * * GET /{judgmentUri}/lock */ export const getApiJudgmentUriLock = async (args: GetApiJudgmentUriLockArgs, options?: GetApiJudgmentUriLockOptions) => { const {baseUrl = "https://api.caselaw.nationalarchives.gov.uk/v1", fetch: fetchFn = fetch, basic} = options ?? {} const query = new URLSearchParams() const headers = new Headers() if (basic !== undefined) headers.set('authorization', `Basic ${btoa(`${basic.username}:${basic.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/${encodeURIComponent(String(args.judgmentUri))}/lock${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return undefined };