import {z} from 'zod' export type Shipper = 'Allied Express' | 'Aramex Australia' | 'Australia Post' | 'Australia Post Express' | 'Austrian Post' | 'BPost' | 'BRT' | 'Chronopost' | 'Chronopost Express' | 'ColisPrivé' | 'Colissimo' | 'Correos' | 'Correos Express' | 'Couriers Please' | 'CTT' | 'Cubyn' | 'Cubyn Express' | 'DB Schenker' | 'Deutsche Post' | 'DHL' | 'DHL DE' | 'DHL Express' | 'DHL EXPRESS' | 'DHL NL' | 'DHL Parcel Spain' | 'DHL SP' | 'DPD' | 'DPD Benelux' | 'DPD DE' | 'DPD FR' | 'DPD International' | 'DPD UK' | 'DPD UK Express' | 'DTDC Australia' | 'FedEx' | 'FedEx - 2Days' | 'FedEx Express' | 'FedEx International' | 'FedEx - Overnight' | 'Geodis' | 'Girard Agediss - Livraison dans la pièce de votre choix sur RDV' | 'GLS' | 'GLS - DE' | 'GLS - FR' | 'GLS International' | 'GLS - IT' | 'GLS-SPAIN' | 'GLS Spain Express' | 'Hermes - DE' | 'Hermes - UK' | 'Japan Post' | 'Livraison au pied du camion' | 'Livraison dans la pièce de votre choix' | 'Logoix' | 'MRW' | 'Murfy transporteur' | 'NACEX' | 'ParcelForce Express' | 'Parcelforce (Worldwide)' | 'Parcelpoint Pty Ltd' | 'Poste Italiane' | 'Post NL' | 'Private Transporter' | 'Royal Mail' | 'Royal Mail Express' | 'Sagawa' | 'Seino' | 'Sendle' | 'Seur' | 'Socolissimo' | 'Star Track Express' | 'TIPSA' | 'TIPSA Express' | 'TNT' | 'TNT Australia' | 'TNT Express' | 'Tourline' | 'UPS' | 'UPS 2 days' | 'UPS 2nd Day Air' | 'UPS Express' | 'UPS express save' | 'UPS Ground' | 'UPS next day' | 'UPS Overnight' | 'UPS standard' | 'USPS' | 'USPS Express' | 'USPS - First Class' | 'USPS - Priority Mail' | 'USPS - Priority Mail Express' | 'VIR' | 'Yamato' | 'Zeleris' | 'Other' | null; export type CreateApiWsListingsListingIdArgs = {body: {price?: (string | number) | undefined, currency?: string | undefined, comment?: (string | null) | undefined, warranty_delay?: (number | string) | undefined, quantity?: (number | string) | undefined, shipper_1?: Shipper | undefined, shipper_display_1?: (string | null) | undefined, shipping_delay_1?: (number | null) | undefined, shipping_price_1?: (string | number | null) | undefined, shipper_2?: Shipper | undefined, shipper_display_2?: (string | null) | undefined, shipping_delay_2?: (number | null) | undefined, shipping_price_2?: (string | number | null) | undefined, shipper_3?: Shipper | undefined, shipper_display_3?: (string | null) | undefined, shipping_delay_3?: (number | null) | undefined, shipping_price_3?: (string | number | null) | undefined, min_price?: (string | number | null) | undefined}}; export type CreateApiWsListingsListingIdOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const listingStateValue = z.union([z.literal(9), z.literal(0), z.literal(1), z.literal(2), z.literal(3), z.literal(4)]); export const aestheticGradeValue = z.enum(["PREMIUM", "EXCELLENT", "VERY_GOOD", "GOOD", "FAIR", "STALLONE"]); export const createApiWsListingsListingIdResponse = z.object({id: z.string(), listing_id: z.number().int(), product_id: z.string().optional(), backmarket_id: z.number().int(), title: z.string(), shippings: z.array(z.object({shipping_price: z.string(), shipping_delay: z.number().int(), shipper: z.string(), shipper_display: z.string(), country_code: z.string()})), state: listingStateValue, grade: aestheticGradeValue, quantity: z.number().int(), currency: z.string(), sku: z.string(), publication_state: z.union([z.literal(0), z.literal(1), z.literal(2), z.literal(3), z.literal(4)]), warranty_delay: z.number().int(), price: z.string(), comment: z.string().nullable(), max_price: z.string(), shippings_response: z.array(z.string()).optional(), statuscode: z.number().int(), min_price: z.string().nullable()}); 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 specific listing * * POST /ws/listings/{listingId} * * Also accepts auth: BasicAuth */ export const createApiWsListingsListingId = async (args: CreateApiWsListingsListingIdArgs, options?: CreateApiWsListingsListingIdOptions) => { const {baseUrl = "https://preprod.backmarket.co.jp", 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 (ApiKeyAuth !== undefined) headers.set("Authorization", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/ws/listings/${encodeURIComponent(String(args.listingId))}${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(createApiWsListingsListingIdResponse, await res.json()) };