export type LoadPatchOperation = {op: 'remove', path: string} | {op: 'add' | 'replace' | 'append', path: string, value: unknown} | {op: 'upsert', path: string, value: unknown, where: {[key: string]: unknown}}; export type LoadPatchRequest = {loadReference: string, operations: Array}; export type PatchApiV2LoadsArgs = {body: LoadPatchRequest}; export type PatchApiV2LoadsOptions = {baseUrl?: string | undefined, httpBasic?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; /** * Patch a load * * PATCH /v2/loads */ export const patchApiV2Loads = async (args: PatchApiV2LoadsArgs, options?: PatchApiV2LoadsOptions) => { const {baseUrl = "https://api.prod.goaugment.com", fetch: fetchFn = fetch, httpBasic} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (httpBasic !== undefined) headers.set('authorization', `Basic ${btoa(`${httpBasic.username}:${httpBasic.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/v2/loads${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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 };