export type GetApiDocumentsDownloadArgs = {document_tokens: string}; export type GetApiDocumentsDownloadOptions = {baseUrl?: string | undefined, oauth2?: string | undefined, fetch?: typeof fetch | undefined}; /** * Download One or More Documents * * GET /documents/download * * Also accepts auth: basic */ export const getApiDocumentsDownload = async (args: GetApiDocumentsDownloadArgs, options?: GetApiDocumentsDownloadOptions) => { const {baseUrl = "https://sandbox.alloy.co/v1", fetch: fetchFn = fetch, oauth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/octet-stream") if (args.document_tokens != null) query.append("document_tokens", String(args.document_tokens)) if (oauth2 !== undefined) headers.set('authorization', `Bearer ${oauth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/documents/download${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.blob() };