import {z} from 'zod' export type SaleStatusToEnum = 0 | 1 | 2; export type PatchedOrderSale = {id?: number | undefined, client?: (number | null) | undefined, agent?: (number | null) | undefined, discount?: (number | null) | undefined, additional_discount?: unknown | undefined, discount_amount?: unknown | undefined, price?: unknown | undefined, price_discount?: unknown | undefined, paid_amount?: unknown | undefined, created_by?: number | undefined, rental_point?: (number | null) | undefined, status?: SaleStatusToEnum | undefined}; export type PatchApiV1ShopSalesSaleIdArgs = {sale_id: number, body: PatchedOrderSale}; export type PatchApiV1ShopSalesSaleIdOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const saleStatusToEnum = z.union([z.literal(0), z.literal(1), z.literal(2)]); export const orderSale = z.object({id: z.number().int(), client: z.number().int().nullable().optional(), agent: z.number().int().nullable().optional(), discount: z.number().int().nullable().optional(), additional_discount: z.string().optional(), discount_amount: z.string().optional(), price: z.string(), price_discount: z.string(), paid_amount: z.string(), created_by: z.number().int().optional(), rental_point: z.number().int().nullable(), status: saleStatusToEnum}); 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 }; /** * PATCH /v1/shop/sales/{sale_id}/ */ export const patchApiV1ShopSalesSaleId = async (args: PatchApiV1ShopSalesSaleIdArgs, options?: PatchApiV1ShopSalesSaleIdOptions) => { const {baseUrl = "https://api.yume.cloud", 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 (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/shop/sales/${encodeURIComponent(String(args.sale_id))}/${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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(orderSale, await res.json()) };