import {z} from 'zod' export type PricingInspirationRequest = {description: string, country: string, currency: string, product_type: string, department: string, condition: string, brand_name: string, size_set_id?: number | undefined, size_id?: number | undefined, colour?: (Array<'black' | 'grey' | 'white' | 'brown' | 'tan' | 'cream' | 'yellow' | 'red' | 'burgundy' | 'orange' | 'pink' | 'purple' | 'blue' | 'navy' | 'green' | 'khaki' | 'multi' | 'silver' | 'gold'>) | undefined, style?: (Array<'streetwear' | 'sportswear' | 'loungewear' | 'goth' | 'retro' | 'boho' | 'western' | 'indie' | 'skater' | 'rave' | 'costume' | 'cosplay' | 'grunge' | 'emo' | 'minimalist' | 'preppy' | 'avant_garde' | 'punk' | 'glam' | 'regency' | 'casual' | 'techwear' | 'futuristic' | 'cottage' | 'fairy' | 'kidcore' | 'y2_k' | 'biker' | 'gorpcore' | 'twee' | 'coquette' | 'whimsygoth'>) | undefined, source?: (Array<'vintage' | 'preloved' | 'reworked' | 'custom' | 'handmade' | 'deadstock' | 'designer' | 'repaired'>) | undefined}; export type CreateApiApiV1PricingInspirationArgs = {body: PricingInspirationRequest}; export type CreateApiApiV1PricingInspirationOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const pricePrediction = z.object({balanced: z.string().optional(), prediction: z.string().optional(), upper_bound: z.string().optional(), lower_bound: z.string().optional()}); export const picture = z.object({url: z.string(), height: z.number(), width: z.number()}); export const similarSoldItem = z.object({picture: picture.optional(), sold_price_amount: z.string().optional(), sold_price_currency: z.string().optional(), condition: z.enum(["brand_new", "used_like_new", "used_excellent", "used_good", "used_fair"]).optional(), brand_name: z.string().optional()}); export const pricingInspirationResponse = z.object({price_prediction: pricePrediction, similar_sold_items: z.array(similarSoldItem)}); 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 pricing inspiration when given product listing details * * POST /api/v1/pricing/inspiration/ */ export const createApiApiV1PricingInspiration = async (args: CreateApiApiV1PricingInspirationArgs, options?: CreateApiApiV1PricingInspirationOptions) => { const {baseUrl = "https://partnerapi-staging.depop.com", 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(/\/+$/, '')}/api/v1/pricing/inspiration/${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(pricingInspirationResponse, await res.json()) };