import {z} from 'zod' export type GetApiInsightsCompanyKeyTechnologyOverviewArgs = {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 GetApiInsightsCompanyKeyTechnologyOverviewOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const a103InsightsCompanyKeyTechnologyOverviewKeyTechnologyOverviewResponse = z.object({count: z.number().int().optional(), percentage: z.number().optional(), description: z.string().optional(), classification: z.string().optional()}); export const a103InsightsCompanyKeyTechnologyOverviewResponse = z.object({data: z.array(a103InsightsCompanyKeyTechnologyOverviewKeyTechnologyOverviewResponse).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 }; /** * A103 Company Key Technologies * * GET /insights-company/key-technology-overview */ export const getApiInsightsCompanyKeyTechnologyOverview = async (args: GetApiInsightsCompanyKeyTechnologyOverviewArgs, options?: GetApiInsightsCompanyKeyTechnologyOverviewOptions) => { 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/key-technology-overview${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(a103InsightsCompanyKeyTechnologyOverviewResponse, await res.json()) };