import {z} from 'zod' export type ApiPurchaseOrderReceiptRequest = {items: Array<{purchase_order_item_id: string, product_id: string, received_quantity: number}>}; export type CreateApiApiV1PurchaseOrdersPurchaseOrderIdReceiptsArgs = {purchase_order_id: string, 'Idempotency-Key': string, body: ApiPurchaseOrderReceiptRequest}; export type CreateApiApiV1PurchaseOrdersPurchaseOrderIdReceiptsOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const apiSharedEnumf2073aa092 = z.enum(["draft", "sent", "partially_received", "received", "closed", "cancelled"]); export const apiSharedObjectfaafd59b8b = z.object({id: z.string(), name: z.string(), description: z.string().nullable(), email: z.string().nullable(), phone: z.string().nullable(), tax_id_type: z.string().nullable(), tax_id: z.string().nullable(), tax_category: z.string().nullable(), payment_term_id: z.string().nullable(), payment_term_days: z.number().int().gte(0).lte(365).nullable(), address: z.string().nullable(), apartment: z.string().nullable(), city: z.string().nullable(), province: z.string().nullable(), postal_code: z.string().nullable()}); export const apiSharedObject8aeeceaf0f = z.object({id: z.string(), name: z.string()}); export const apiSharedEnum09f8155a9a = z.enum(["customer", "supplier", "product", "sale", "purchase", "purchase_order", "transfer"]); export const apiSharedEnum599647cb76 = z.enum(["slate", "red", "orange", "amber", "yellow", "lime", "green", "teal", "cyan", "blue", "indigo", "violet", "pink"]); export const apiSharedObjected3905a55b = z.object({object: z.literal("tag"), id: z.string(), scope: apiSharedEnum09f8155a9a, name: z.string(), slug: z.string(), color: apiSharedEnum599647cb76.nullable(), description: z.string().nullable(), archived_at: z.string().nullable(), created_at: z.string(), updated_at: z.string()}); export const apiSharedEnumff49232140 = z.enum(["product", "service", "combo", "kit"]); export const apiSharedObject15e53f9372 = z.object({id: z.string(), name: z.string(), sku: z.string().nullable(), product_type: apiSharedEnumff49232140.nullable(), variant_options: z.record(z.string(), z.string()).nullable(), option_names: z.array(z.string()).nullable()}); export const apiSharedObjecta50ed243b8 = z.object({id: z.string(), ordered_quantity: z.number().nullable(), received_quantity: z.number(), expected_unit_cost: z.number().int().gte(0).nullable(), product: apiSharedObject15e53f9372}); export const apiSharedObjecteffe384a18 = z.object({object: z.literal("purchase_order"), id: z.string(), order_number: z.number().int(), formatted_order_number: z.string().nullable(), status: apiSharedEnumf2073aa092, order_date: z.string(), expected_date: z.string().nullable(), currency: z.string(), supplier: apiSharedObjectfaafd59b8b.nullable(), warehouse: apiSharedObject8aeeceaf0f.nullable(), created_at: z.string(), tags: z.array(apiSharedObjected3905a55b), warehouse_id: z.string().nullable(), notes: z.string().nullable(), items: z.array(apiSharedObjecta50ed243b8)}); export const apiPurchaseOrderReceiptResponse = z.object({request_id: z.string(), data: z.object({receipt: z.object({object: z.literal("receipt"), id: z.string(), purchase_order_warehouse_id: z.string().nullable(), affected_products: z.array(z.object({sku: z.string(), warehouse_id: z.string()}))}), purchase_order: apiSharedObjecteffe384a18, idempotent_replay: z.boolean()}), warnings: z.array(z.unknown())}); 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 }; /** * Recibir orden de compra * * POST /api/v1/purchase-orders/{purchase_order_id}/receipts */ export const createApiApiV1PurchaseOrdersPurchaseOrderIdReceipts = async (args: CreateApiApiV1PurchaseOrdersPurchaseOrderIdReceiptsArgs, options?: CreateApiApiV1PurchaseOrdersPurchaseOrderIdReceiptsOptions) => { const {baseUrl = "https://api.lapyme.com.ar", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args['Idempotency-Key'] != null) headers.set("Idempotency-Key", String(args['Idempotency-Key'])) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/purchase-orders/${encodeURIComponent(String(args.purchase_order_id))}/receipts${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", 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(apiPurchaseOrderReceiptResponse, await res.json()) };