import {z} from 'zod' export type Product = {id?: string | undefined, integration?: string | undefined, additionalType?: (string | null) | undefined, alternateName?: (string | null) | undefined, award?: (string | null) | undefined, categories?: (Array | null) | undefined, color?: (string | null) | undefined, description?: (string | null) | undefined, disambiguatingDescription?: (string | null) | undefined, gtin12?: (string | null) | undefined, gtin13s?: (Array | null) | undefined, gtin14s?: (Array | null) | undefined, gtin8s?: (Array | null) | undefined, image?: (string | null) | undefined, isAccessoryOrSparePartFors?: (Array | null) | undefined, isConsumableFors?: (Array | null) | undefined, isRelatedTo?: (unknown | null) | undefined, isSimilarTos?: (Array | null) | undefined, itemCondition?: (string | null) | undefined, model?: (string | null) | undefined, mpns?: (Array | null) | undefined, manufacturer?: (string | null) | undefined, name?: (string | null) | undefined, productID?: (string | null) | undefined, releaseDate?: (string | null) | undefined, sameA?: (string | null) | undefined, skus?: (Array | null) | undefined, url?: (string | null) | undefined, material?: (string | null) | undefined, productionDate?: (string | null) | undefined, purchaseDate?: (string | null) | undefined, identifier?: (string | null) | undefined, srcId?: string | undefined, isActive?: (string | null) | undefined, height?: (number | null) | undefined, width?: (number | null) | undefined, weight?: (number | null) | undefined, quantity?: (number | null) | undefined, availableForPurchase?: (boolean | null) | undefined, updated?: (string | null) | undefined, price?: (number | null) | undefined, weightUnit?: (string | null) | undefined, heightUnit?: (string | null) | undefined, widthUnit?: (string | null) | undefined}; export type UpdateApiProductsIdArgs = {id: string, body: Product}; export type UpdateApiProductsIdOptions = {baseUrl?: string | undefined, BasicAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const product = z.object({id: z.string().optional(), integration: z.string().optional(), additionalType: z.string().nullable().optional(), alternateName: z.string().nullable().optional(), award: z.string().nullable().optional(), categories: z.array(z.string()).nullable().optional(), color: z.string().nullable().optional(), description: z.string().nullable().optional(), disambiguatingDescription: z.string().nullable().optional(), gtin12: z.string().nullable().optional(), gtin13s: z.array(z.string()).nullable().optional(), gtin14s: z.array(z.string()).nullable().optional(), gtin8s: z.array(z.string()).nullable().optional(), image: z.string().nullable().optional(), isAccessoryOrSparePartFors: z.array(z.string()).nullable().optional(), isConsumableFors: z.array(z.string()).nullable().optional(), isRelatedTo: z.string().nullable().optional(), isSimilarTos: z.array(z.string()).nullable().optional(), itemCondition: z.string().nullable().optional(), model: z.string().nullable().optional(), mpns: z.array(z.string()).nullable().optional(), manufacturer: z.string().nullable().optional(), name: z.string().nullable().optional(), productID: z.string().nullable().optional(), releaseDate: z.string().nullable().optional(), sameA: z.string().nullable().optional(), skus: z.array(z.string()).nullable().optional(), url: z.string().nullable().optional(), material: z.string().nullable().optional(), productionDate: z.string().nullable().optional(), purchaseDate: z.string().nullable().optional(), identifier: z.string().nullable().optional(), srcId: z.string().optional(), isActive: z.string().nullable().optional(), height: z.number().int().nullable().optional(), width: z.number().int().nullable().optional(), weight: z.number().int().nullable().optional(), quantity: z.number().int().nullable().optional(), availableForPurchase: z.boolean().nullable().optional(), updated: z.string().nullable().optional(), price: z.number().int().nullable().optional(), weightUnit: z.string().nullable().optional(), heightUnit: z.string().nullable().optional(), widthUnit: z.string().nullable().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 }; /** * Replaces the Product resource. * * PUT /products/{id} */ export const updateApiProductsId = async (args: UpdateApiProductsIdArgs, options?: UpdateApiProductsIdOptions) => { const {baseUrl = "https://example.myintranetapps.com/api", fetch: fetchFn = fetch, BasicAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (BasicAuth !== undefined) headers.set('authorization', `Basic ${btoa(`${BasicAuth.username}:${BasicAuth.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/products/${encodeURIComponent(String(args.id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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()) };