export type PackingStationCode = 'A' | 'B' | 'C' | 'E' | 'F' | 'G' | 'H' | 'I' | 'J' | 'K' | 'X' | 'Z'; export type GetApiPackingSlipsDateArgs = {date: string, stations?: (Array | null) | undefined, fastTrack?: (boolean | null) | undefined}; export type GetApiPackingSlipsDateOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; /** * {station} expects a comma separated list of packing station codes: A,B,C * * GET /packing-slips/{date} */ export const getApiPackingSlipsDate = async (args: GetApiPackingSlipsDateArgs, options: GetApiPackingSlipsDateOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "text/html") for (const item of args.stations ?? []) query.append("stations", String(item)) if (args.fastTrack != null) query.append("fastTrack", String(args.fastTrack)) const url = `${baseUrl.replace(/\/+$/, '')}/packing-slips/${encodeURIComponent(String(args.date))}${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 res.text() };