import {z} from 'zod' export type OrderRequestInventoryUpdate = {type?: number | undefined, set?: (number | null) | undefined, set_group?: (string | null) | undefined, inventory_group?: (number | null) | undefined, inventory?: (number | null) | undefined, tarif: number | null, tarif_price?: unknown | undefined, tarif_duration?: string | undefined, start_at: string, end_at: string, extra: unknown, warehouse?: (number | null) | undefined, counterparty?: (number | null) | undefined, discount?: (number | null) | undefined, additional_discount?: (unknown | null) | undefined, id: number}; export type OrderRequestInventoryBulkUpdate = {request?: (number | null) | undefined, inventories: Array}; export type CreateApiV1CrmRequestsRequestIdInventoriesBulkUpdateArgs = {request_id: number, body: OrderRequestInventoryBulkUpdate}; export type CreateApiV1CrmRequestsRequestIdInventoriesBulkUpdateOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const orderRequestInventoryUpdate = z.object({type: z.number().int().optional(), set: z.number().int().nullable().optional(), set_group: z.string().nullable().optional(), inventory_group: z.number().int().nullable().optional(), inventory: z.number().int().nullable().optional(), tarif: z.number().int().nullable(), tarif_price: z.string().optional(), tarif_duration: z.string().optional(), start_at: z.string(), end_at: z.string(), extra: z.unknown(), warehouse: z.number().int().nullable().optional(), counterparty: z.number().int().nullable().optional(), discount: z.number().int().nullable().optional(), additional_discount: z.string().nullable().optional(), id: z.number().int()}); export const orderRequestInventoryBulkUpdate = z.object({request: z.number().int().nullable().optional(), inventories: z.array(orderRequestInventoryUpdate)}); 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 }; /** * POST /v1/crm/requests/{request_id}/inventories/bulk_update/ */ export const createApiV1CrmRequestsRequestIdInventoriesBulkUpdate = async (args: CreateApiV1CrmRequestsRequestIdInventoriesBulkUpdateArgs, options?: CreateApiV1CrmRequestsRequestIdInventoriesBulkUpdateOptions) => { 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/crm/requests/${encodeURIComponent(String(args.request_id))}/inventories/bulk_update/${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(orderRequestInventoryBulkUpdate, await res.json()) };