import {z} from 'zod' export type CreateApiV3PublicWebcomponentDiamondSearchArgs = {apikey: string, body: {shapes?: (Array | null) | undefined, types?: (Array<'EARTH' | 'LAB'> | null) | undefined, labs?: (Array | null) | undefined, cut?: (Array | null) | undefined, color?: (Array | null) | undefined, clarity?: (Array | null) | undefined, carat_min?: (number | null) | undefined, carat_max?: (number | null) | undefined, price_min?: (number | null) | undefined, price_max?: (number | null) | undefined, sort_mode?: ('price-asc' | 'price-desc' | 'date-asc' | 'date-desc' | 'carat-asc' | 'carat-desc' | 'color-asc' | 'color-desc' | null) | undefined, page?: (number | null) | undefined, page_size?: (number | null) | undefined}}; export type CreateApiV3PublicWebcomponentDiamondSearchOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiV3PublicWebcomponentDiamondSearchResponse = z.object({total: z.number().int().optional(), page: z.number().int().optional(), page_size: z.number().int().optional(), items: z.array(z.object({})).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 }; /** * Search the store diamonds of an organization * * POST /v3/public/webcomponent/diamond/search */ export const createApiV3PublicWebcomponentDiamondSearch = async (args: CreateApiV3PublicWebcomponentDiamondSearchArgs, options?: CreateApiV3PublicWebcomponentDiamondSearchOptions) => { const {baseUrl = "https://api.rhinoartisan.com", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.apikey != null) headers.set("apikey", String(args.apikey)) if (ApiKeyAuth !== undefined) headers.set("apikey", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/v3/public/webcomponent/diamond/search${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(createApiV3PublicWebcomponentDiamondSearchResponse, await res.json()) };