import {z} from 'zod' export type DeleteApiApiV1AdminSupplierQuotesQuoteIdAttachmentsArgs = {quote_id: string, r2_key: string}; export type DeleteApiApiV1AdminSupplierQuotesQuoteIdAttachmentsOptions = {baseUrl: string, OAuth2PasswordBearer?: string | undefined, fetch?: typeof fetch | undefined}; export const commercialDocumentExtractionSummary = z.object({id: z.string(), status: z.string(), provider: z.string(), schema_version: z.string(), confidence: z.number().nullable().optional(), aggregate_total_cents: z.number().int().nullable().optional(), currency: z.string().nullable().optional(), max_lead_time_days: z.number().int().nullable().optional(), error_message: z.string().nullable().optional(), started_at: z.string().nullable().optional(), completed_at: z.string().nullable().optional(), created_at: z.string(), updated_at: z.string()}); export const supplierQuoteDocumentRead = z.object({extraction_status: z.string().optional(), latest_extraction_id: z.string().nullable().optional(), last_extracted_at: z.string().nullable().optional(), has_reviewable_suggestion: z.boolean().optional(), extraction_error_message: z.string().nullable().optional(), id: z.string(), project_id: z.string(), supplier_contact_id: z.string(), supplier_quote_id: z.string().nullable().optional(), vendor_thread_state_id: z.string().nullable().optional(), source: z.string(), document_kind: z.string(), r2_key: z.string().nullable().optional(), filename: z.string().nullable().optional(), mime_type: z.string().nullable().optional(), file_size_bytes: z.number().int().nullable().optional(), gmail_thread_id: z.string().nullable().optional(), gmail_message_id: z.string().nullable().optional(), latest_extraction: commercialDocumentExtractionSummary.nullable().optional(), created_at: z.string(), updated_at: z.string()}); export const supplierQuoteRead = z.object({id: z.string(), project_id: z.string(), supplier_contact_id: z.string(), supplier_contact_name: z.string(), supplier_contact_email: z.string(), gmail_thread_id: z.string().nullable().optional(), source: z.string().optional(), total_amount_cents: z.number().int().nullable(), currency: z.string(), lead_time_days: z.number().int().nullable(), valid_until: z.string().nullable(), line_items: z.array(z.record(z.string(), z.unknown())), notes: z.string().nullable(), source_email_body: z.string().nullable().optional(), attachment_r2_keys: z.array(z.string()).optional(), attachment_kinds: z.array(z.string()).optional(), supplier_documents: z.array(supplierQuoteDocumentRead).optional(), document_kind: z.string().nullable().optional(), extraction_confidence: z.number().nullable().optional(), needs_human_review: z.boolean(), reviewed_at: z.string().nullable(), reviewed_by: z.string().nullable(), accepted_at: z.string().nullable().optional(), created_at: z.string(), updated_at: z.string()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Delete Supplier Quote Attachment * * DELETE /api/v1/admin/supplier-quotes/{quote_id}/attachments */ export const deleteApiApiV1AdminSupplierQuotesQuoteIdAttachments = async (args: DeleteApiApiV1AdminSupplierQuotesQuoteIdAttachmentsArgs, options: DeleteApiApiV1AdminSupplierQuotesQuoteIdAttachmentsOptions) => { const {baseUrl, fetch: fetchFn = fetch, OAuth2PasswordBearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.r2_key != null) query.append("r2_key", String(args.r2_key)) if (OAuth2PasswordBearer !== undefined) headers.set('authorization', `Bearer ${OAuth2PasswordBearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/admin/supplier-quotes/${encodeURIComponent(String(args.quote_id))}/attachments${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "DELETE", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(supplierQuoteRead, await res.json()) };