import {z} from 'zod' export type ProductCategory = {id?: number | undefined, parent_id?: number | undefined, name?: string | undefined, is_active?: boolean | undefined, created_at?: number | undefined, updated_at?: number | undefined, child_categories?: Array | undefined}; export type MeasurementUnit = {id?: number | undefined, name?: string | undefined, abbr?: string | undefined, is_default?: boolean | undefined}; export type Tax = {id?: number | undefined, name?: string | undefined, rate?: number | undefined, is_active?: boolean | undefined}; export type ProductPrice = {id?: number | undefined, price?: number | undefined, currency?: string | undefined, is_default?: boolean | undefined, tax?: Tax | undefined}; export type Files = Array; export type Product = {id?: number | undefined, product_category_id?: number | undefined, measurement_unit_id?: number | undefined, title?: string | undefined, article?: string | undefined, type?: ('goods' | 'service') | undefined, is_active?: boolean | undefined, availability?: ('available' | 'not_available' | 'pending') | undefined, quantity?: number | undefined, reserved_quantity?: number | undefined, description?: string | undefined, comment?: string | undefined, link?: string | undefined, created_at?: number | undefined, updated_at?: number | undefined, product_category?: ProductCategory | undefined, measurement_unit?: MeasurementUnit | undefined, prices?: Array | undefined, files?: Files | undefined}; export type PatchApiCrmV1StaticProductsItemIdArgs = {body: Product}; export type PatchApiCrmV1StaticProductsItemIdOptions = {baseUrl: string, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const productCategory: z.ZodType = z.object({id: z.number().int().optional(), parent_id: z.number().int().optional(), name: z.string().optional(), is_active: z.boolean().optional(), created_at: z.number().int().optional(), updated_at: z.number().int().optional(), child_categories: z.array(z.lazy(() => productCategory)).optional()}); export const measurementUnit = z.object({id: z.number().int().optional(), name: z.string().optional(), abbr: z.string().optional(), is_default: z.boolean().optional()}); export const tax = z.object({id: z.number().int().optional(), name: z.string().optional(), rate: z.number().optional(), is_active: z.boolean().optional()}); export const productPrice = z.object({id: z.number().int().optional(), price: z.number().int().optional(), currency: z.string().optional(), is_default: z.boolean().optional(), tax: tax.optional()}); export const files = z.array(z.string()); export const product = z.object({id: z.number().int().optional(), product_category_id: z.number().int().optional(), measurement_unit_id: z.number().int().optional(), title: z.string().optional(), article: z.string().optional(), type: z.enum(["goods", "service"]).optional(), is_active: z.boolean().optional(), availability: z.enum(["available", "not_available", "pending"]).optional(), quantity: z.number().optional(), reserved_quantity: z.number().optional(), description: z.string().optional(), comment: z.string().optional(), link: z.string().optional(), created_at: z.number().int().optional(), updated_at: z.number().int().optional(), product_category: productCategory.optional(), measurement_unit: measurementUnit.optional(), prices: z.array(productPrice).optional(), files: files.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 }; /** * Update product * * PATCH /crm/v1/static/products/{itemId} */ export const patchApiCrmV1StaticProductsItemId = async (args: PatchApiCrmV1StaticProductsItemIdArgs, options: PatchApiCrmV1StaticProductsItemIdOptions) => { const {baseUrl, 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(/\/+$/, '')}/crm/v1/static/products/${encodeURIComponent(String(args.itemId))}${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(product, await res.json()) };