import {z} from 'zod' export type GetApiApiXiaohongshuEcGetProductDetailV1Args = {token: string, skuId: string}; export type GetApiApiXiaohongshuEcGetProductDetailV1Options = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiApiXiaohongshuEcGetProductDetailV1Response = z.object({code: z.union([z.literal(0), z.literal(100), z.literal(101), z.literal(202), z.literal(300), z.literal(301), z.literal(302), z.literal(303), z.literal(400), z.literal(404), z.literal(500), z.literal(503), z.literal(600), z.literal(601), z.literal(602)]), message: z.string().nullable(), data: z.unknown(), recordTime: z.string().nullable(), requestId: z.string().optional(), reason: z.string().optional(), requestParams: z.object({query: z.record(z.string(), z.object({})).optional(), body: z.object({empty: z.boolean().optional(), array: z.boolean().optional(), null: z.boolean().optional(), object: z.boolean().optional(), float: z.boolean().optional(), integralNumber: z.boolean().optional(), nodeType: z.enum(["ARRAY", "BINARY", "BOOLEAN", "MISSING", "NULL", "NUMBER", "OBJECT", "POJO", "STRING"]).optional(), string: z.boolean().optional(), missingNode: z.boolean().optional(), valueNode: z.boolean().optional(), container: z.boolean().optional(), pojo: z.boolean().optional(), short: z.boolean().optional(), int: z.boolean().optional(), long: z.boolean().optional(), double: z.boolean().optional(), bigDecimal: z.boolean().optional(), bigInteger: z.boolean().optional(), textual: z.boolean().optional(), boolean: z.boolean().optional(), binary: z.boolean().optional(), floatingPointNumber: z.boolean().optional(), number: z.boolean().optional(), embeddedValue: z.boolean().optional()}).optional()}).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 }; /** * Product Detail * * GET /api/xiaohongshu-ec/get-product-detail/v1 */ export const getApiApiXiaohongshuEcGetProductDetailV1 = async (args: GetApiApiXiaohongshuEcGetProductDetailV1Args, options?: GetApiApiXiaohongshuEcGetProductDetailV1Options) => { const {baseUrl = "https://api.justoneapi.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.token != null) query.append("token", String(args.token)) if (args.skuId != null) query.append("skuId", String(args.skuId)) const url = `${baseUrl.replace(/\/+$/, '')}/api/xiaohongshu-ec/get-product-detail/v1${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(getApiApiXiaohongshuEcGetProductDetailV1Response, await res.json()) };