import {z} from 'zod' export type P066HighValueDataPatentClassificationDescriptionRequest = {code: string, replace_by_merge?: number | undefined, type: string}; export type CreateApiHighValueDataPatentClassificationDescriptionArgs = {body: P066HighValueDataPatentClassificationDescriptionRequest}; export type CreateApiHighValueDataPatentClassificationDescriptionOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const p066HighValueDataPatentClassificationDescriptionClassificationDesc = z.object({lang: z.string().optional(), text: z.string().optional()}); export const p066HighValueDataPatentClassificationDescriptionClassificationParent = z.object({desc: z.array(p066HighValueDataPatentClassificationDescriptionClassificationDesc).optional(), parent_code: z.string().optional()}); export const p066HighValueDataPatentClassificationDescriptionPatentClassDescResponse = z.object({code: z.string().optional(), desc: z.array(p066HighValueDataPatentClassificationDescriptionClassificationDesc).optional(), type: z.string().optional(), parent: z.array(p066HighValueDataPatentClassificationDescriptionClassificationParent).optional(), version: z.string().optional()}); export const p066HighValueDataPatentClassificationDescriptionResponse = z.object({data: z.array(p066HighValueDataPatentClassificationDescriptionPatentClassDescResponse).optional(), status: z.boolean(), error_msg: z.string().optional(), error_code: z.number().int()}); 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 }; /** * P066 Patent Classification Description * * POST /high-value-data/patent-classification-description */ export const createApiHighValueDataPatentClassificationDescription = async (args: CreateApiHighValueDataPatentClassificationDescriptionArgs, options?: CreateApiHighValueDataPatentClassificationDescriptionOptions) => { const {baseUrl = "https://connect.patsnap.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(/\/+$/, '')}/high-value-data/patent-classification-description${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(p066HighValueDataPatentClassificationDescriptionResponse, await res.json()) };