import {z} from 'zod' export type GetApiV1ShopsShopIdInvoicesArgs = {body: {page?: (number | null) | undefined, perPage?: (number | null) | undefined, orderColumn?: ('id' | 'price_usd' | 'paid_usd' | 'created_at' | 'completed_at' | null) | undefined, orderDirection?: ('asc' | 'desc' | null) | undefined, id?: (string | null) | undefined, statuses?: (Array<'pending' | 'confirming' | 'partially_completed' | 'completed' | 'cancelled' | 'expired' | 'failed' | 'refunded' | 'charged_back'>) | undefined, underpaid?: (boolean | null) | undefined, disputed?: (boolean | null) | undefined, late_payment?: (boolean | null) | undefined, fulfillment_statuses?: (Array<'unfulfilled' | 'processing' | 'shipped' | 'delivered'>) | undefined, email?: (string | null) | undefined, gateways?: (Record | null) | undefined, payment_method_ids?: (Record | null) | undefined, created_at_start?: (string | null) | undefined, created_at_end?: (string | null) | undefined, completed_at_start?: (string | null) | undefined, completed_at_end?: (string | null) | undefined, product_name?: (string | null) | undefined, variant_name?: (string | null) | undefined, coupon_code?: (string | null) | undefined, ip?: (string | null) | undefined, utm_source?: (string | null) | undefined, utm_medium?: (string | null) | undefined, utm_campaign?: (string | null) | undefined, utm_term?: (string | null) | undefined, utm_content?: (string | null) | undefined, referrer_host?: (string | null) | undefined, discord_id?: (string | null) | undefined, discord_username?: (string | null) | undefined, deliverable?: (string | null) | undefined, custom_field?: (string | null) | undefined, archived?: (string | null) | undefined, manual?: (string | null) | undefined, external_id_type?: (string | null) | undefined, external_id_value?: (string | null) | undefined, cashapp_note?: (string | null) | undefined, paypalff_note?: (string | null) | undefined, venmo_note?: (string | null) | undefined, zelle_note?: (string | null) | undefined, skrillp2p_note?: (string | null) | undefined, customer_id?: (string | null) | undefined, all?: (boolean | null) | undefined}}; export type GetApiV1ShopsShopIdInvoicesOptions = {baseUrl?: string | undefined, defaultValue?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiV1ShopsShopIdInvoicesResponse = z.object({current_page: z.number().int().optional(), data: z.array(z.object({id: z.number().int().optional(), status: z.string().optional(), price: z.string().optional(), currency: z.string().optional(), paid: z.string().optional(), paid_usd: z.string().optional(), gateway: z.string().nullable().optional(), payment_method_id: z.string().nullable().optional(), email: z.string().optional(), salt: z.string().optional(), manual: z.boolean().optional(), created_at: z.string().optional(), completed_at: z.string().optional(), archived_at: z.string().nullable().optional(), shop_customer_id: z.number().int().optional(), tax_rate: z.string().optional(), ip: z.string().optional(), country_code: z.string().nullable().optional(), user_agent: z.string().optional(), asn: z.string().nullable().optional(), utm_source: z.string().nullable().optional(), utm_medium: z.string().nullable().optional(), utm_campaign: z.string().nullable().optional(), utm_term: z.string().nullable().optional(), utm_content: z.string().nullable().optional(), referrer_host: z.string().nullable().optional(), has_open_dispute: z.boolean().optional(), has_open_late_payment: z.boolean().optional(), unique_id: z.string().optional(), product: z.string().nullable().optional(), variant: z.string().nullable().optional(), items: z.array(z.object({id: z.number().int().optional(), invoice_id: z.number().int().optional(), product_id: z.number().int().optional(), variant_id: z.number().int().optional(), custom_name: z.string().nullable().optional(), quantity: z.number().int().optional(), product: z.object({id: z.number().int().optional(), name: z.string().optional(), images: z.array(z.object({id: z.number().int().optional(), cloudflare_image_id: z.string().nullable().optional(), url: z.string().optional(), pivot: z.object({product_id: z.number().int().optional(), image_id: z.number().int().optional(), order: z.number().int().optional()}).optional()})).optional()}).optional(), variant: z.object({id: z.number().int().optional(), name: z.string().optional()}).optional()})).optional(), payment_method: z.string().nullable().optional()})).optional(), first_page_url: z.string().optional(), from: z.number().int().optional(), last_page: z.number().int().optional(), last_page_url: z.string().optional(), links: z.array(z.object({url: z.string().nullable().optional(), label: z.string().optional(), page: z.string().nullable().optional(), active: z.boolean().optional()})).optional(), next_page_url: z.string().nullable().optional(), path: z.string().optional(), per_page: z.number().int().optional(), prev_page_url: z.string().nullable().optional(), to: z.number().int().optional(), total: z.number().int().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 }; /** * Get Invoices * * GET /v1/shops/{shopId}/invoices */ export const getApiV1ShopsShopIdInvoices = async (args: GetApiV1ShopsShopIdInvoicesArgs, options?: GetApiV1ShopsShopIdInvoicesOptions) => { const {baseUrl = "https://api.sellauth.com", fetch: fetchFn = fetch, defaultValue} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (defaultValue !== undefined) headers.set('authorization', `Bearer ${defaultValue}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/shops/${encodeURIComponent(String(args.shopId))}/invoices${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(getApiV1ShopsShopIdInvoicesResponse, await res.json()) };