import {z} from 'zod' export type GetApiApiOffersItemItemIdArgs = {'x-site-context': string, itemId: number, priceListId?: number | undefined, limit?: number | undefined, offset?: number | undefined}; export type GetApiApiOffersItemItemIdOptions = {baseUrl?: string | undefined, AuthorizationToken?: string | undefined, fetch?: typeof fetch | undefined}; export const productById = z.object({channel: z.array(z.number()).optional(), startDate: z.string().optional(), endDate: z.string().optional(), group: z.array(z.string()).optional(), title: z.string().optional(), itemId: z.number().optional(), price: z.object({id: z.string().optional(), isSoftDeleted: z.boolean().optional(), itemId: z.number().optional(), offerId: z.number().optional(), createdAt: z.string().optional(), updatedAt: z.string().optional(), offers: z.array(z.object({price: z.object({sale: z.number().optional(), base: z.number().optional(), currency: z.string().optional()}).optional(), channel: z.number().optional(), startDate: z.string().optional(), endDate: z.string().optional(), kind: z.number().optional()})).optional(), query: z.object({limit: z.number().optional(), count: z.number().optional(), offset: z.number().optional()}).optional()}).optional(), isDefault: z.boolean().optional(), isActive: z.boolean().optional(), attributes: z.array(z.object({attributeGroupId: z.string().optional(), id: z.string().optional(), value: z.union([z.string(), z.number(), z.boolean()]).optional(), isDefault: z.boolean().optional()})).optional(), parent: z.string().optional(), itemFamily: z.string().optional(), description: z.string().optional(), variants: z.array(z.string()).optional(), state: z.string().optional(), images: z.array(z.object({id: z.string().optional(), order: z.number().optional(), label: z.string().optional(), source: z.array(z.object({id: z.string().optional(), url: z.string().optional()})).optional()})).optional(), sku: z.string().optional(), isSoftDeleted: z.boolean().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 }; /** * Get price of a specific item * * GET /api-offers/item/{itemId} */ export const getApiApiOffersItemItemId = async (args: GetApiApiOffersItemItemIdArgs, options?: GetApiApiOffersItemItemIdOptions) => { const {baseUrl = "https://live.copilot.fabric.inc", fetch: fetchFn = fetch, AuthorizationToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['x-site-context'] != null) headers.set("x-site-context", String(args['x-site-context'])) if (args.priceListId != null) query.append("priceListId", String(args.priceListId)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.offset != null) query.append("offset", String(args.offset)) if (AuthorizationToken !== undefined) headers.set('authorization', `Bearer ${AuthorizationToken}`) const url = `${baseUrl.replace(/\/+$/, '')}/api-offers/item/${encodeURIComponent(String(args.itemId))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(productById, await res.json()) };