import {z} from 'zod' export type GetApiInvoiceSubmissionsGuidEvidenceArgs = {guid: string}; export type GetApiInvoiceSubmissionsGuidEvidenceOptions = {baseUrl?: string | undefined, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const invoiceSubmissionActionEvidence = z.object({transmission_datetime: z.string().optional(), transmission_type: z.enum(["ae-fta", "as2", "bpc", "ch-qrbill", "edi", "email", "es-aeat-verifactu", "exact_worker", "finvoice", "fr-dgfip", "fr-dgfip-cdar", "india", "india-b2c", "italy-aruba", "my-lhdnm", "peppol", "pl-ksef", "pt-b2b", "ro-arxia-anaf", "sa", "sandbox", "sg-iras", "snelstart_worker", "spain-face", "spain-faceb2b", "svefaktura", "vatcalc"]).optional(), transmission_result: z.enum(["unknown", "accepted", "rejected", "send_error", "internal_error", "no_clearing_status", "pending_clearance", "sent_pending_confirmation", "cleared", "not_clearable", "clearing_transport_error"]).optional(), transmitted_document: z.string().optional(), receiver_response: z.string().optional()}); export const invoiceSubmissionEvidence = z.object({guid: z.string().optional(), status: z.string().optional(), actions: z.array(invoiceSubmissionActionEvidence).optional()}); 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 }; /** * DEPRECATED. Get InvoiceSubmission Evidence * * GET /invoice_submissions/{guid}/evidence */ export const getApiInvoiceSubmissionsGuidEvidence = async (args: GetApiInvoiceSubmissionsGuidEvidenceArgs, options?: GetApiInvoiceSubmissionsGuidEvidenceOptions) => { const {baseUrl = "https://api.storecove.com/api/v2", fetch: fetchFn = fetch, Bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (Bearer !== undefined) headers.set("Authorization", Bearer) const url = `${baseUrl.replace(/\/+$/, '')}/invoice_submissions/${encodeURIComponent(String(args.guid))}/evidence${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 validateResponse(invoiceSubmissionEvidence, await res.json()) };