export type DocumentKey = string; export type UpdateApiDocumentsDocumentKeyFileArgs = {documentKey: DocumentKey, body: BodyInit}; export type UpdateApiDocumentsDocumentKeyFileOptions = {baseUrl?: string | undefined, ApiKey?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; /** * Upload Document File * * PUT /documents/{documentKey}/file * * Also accepts auth: BearerToken */ export const updateApiDocumentsDocumentKeyFile = async (args: UpdateApiDocumentsDocumentKeyFileArgs, options?: UpdateApiDocumentsDocumentKeyFileOptions) => { const {baseUrl = "https://eu-west-1.api.silverflow.com/v1", fetch: fetchFn = fetch, ApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "image/jpeg") if (ApiKey !== undefined) headers.set('authorization', `Basic ${btoa(`${ApiKey.username}:${ApiKey.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/documents/${encodeURIComponent(String(args.documentKey))}/file${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", headers, body: args.body}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return undefined };