import {z} from 'zod' export type GetApiInsightsCompanyWordCloudArgs = {apply_end_time?: string | undefined, apply_start_time?: string | undefined, authority?: string | undefined, company_name?: string | undefined, lang: string, patent_type?: string | undefined, public_end_time?: string | undefined, public_start_time?: string | undefined, simple_legal_status?: string | undefined}; export type GetApiInsightsCompanyWordCloudOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const a101InsightsCompanyWordCloudWordCloudResponse = z.object({name: z.string().optional(), count: z.number().int().optional()}); export const a101InsightsCompanyWordCloudResponse = z.object({data: z.array(a101InsightsCompanyWordCloudWordCloudResponse).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 }; /** * A101 Company Innovation Word Cloud * * GET /insights-company/word-cloud */ export const getApiInsightsCompanyWordCloud = async (args: GetApiInsightsCompanyWordCloudArgs, options?: GetApiInsightsCompanyWordCloudOptions) => { const {baseUrl = "https://connect.patsnap.com", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.apply_end_time != null) query.append("apply_end_time", String(args.apply_end_time)) if (args.apply_start_time != null) query.append("apply_start_time", String(args.apply_start_time)) if (args.authority != null) query.append("authority", String(args.authority)) if (args.company_name != null) query.append("company_name", String(args.company_name)) if (args.lang != null) query.append("lang", String(args.lang)) if (args.patent_type != null) query.append("patent_type", String(args.patent_type)) if (args.public_end_time != null) query.append("public_end_time", String(args.public_end_time)) if (args.public_start_time != null) query.append("public_start_time", String(args.public_start_time)) if (args.simple_legal_status != null) query.append("simple_legal_status", String(args.simple_legal_status)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/insights-company/word-cloud${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(a101InsightsCompanyWordCloudResponse, await res.json()) };