import {z} from 'zod' export type GetApiInsightsCompanyAcquisitionDivestitureArgs = {apply_end_time?: string | undefined, apply_start_time?: string | undefined, authority?: string | undefined, company_name?: string | undefined, credit_code?: string | undefined, lang: string, org_number?: string | undefined, patent_type?: string | undefined, public_end_time?: string | undefined, public_start_time?: string | undefined, simple_legal_status?: string | undefined}; export type GetApiInsightsCompanyAcquisitionDivestitureOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const a110InsightsCompanyAcquisitionDivestitureTransfer = z.object({count: z.number().int().optional(), applicant: z.string().optional()}); export const a110InsightsCompanyAcquisitionDivestitureAcquisitionTransfer = z.object({patent_total: z.number().int().optional(), transfer_list: z.array(a110InsightsCompanyAcquisitionDivestitureTransfer).optional()}); export const a110InsightsCompanyAcquisitionDivestitureAcquisitionAndDivestitureResponse = z.object({acquisition: a110InsightsCompanyAcquisitionDivestitureAcquisitionTransfer.optional(), divestiture: a110InsightsCompanyAcquisitionDivestitureAcquisitionTransfer.optional()}); export const a110InsightsCompanyAcquisitionDivestitureResponse = z.object({data: a110InsightsCompanyAcquisitionDivestitureAcquisitionAndDivestitureResponse.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 }; /** * A110 Company Patent Transfer In or Transfer Out * * GET /insights-company/acquisition-divestiture */ export const getApiInsightsCompanyAcquisitionDivestiture = async (args: GetApiInsightsCompanyAcquisitionDivestitureArgs, options?: GetApiInsightsCompanyAcquisitionDivestitureOptions) => { 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.credit_code != null) query.append("credit_code", String(args.credit_code)) if (args.lang != null) query.append("lang", String(args.lang)) if (args.org_number != null) query.append("org_number", String(args.org_number)) 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/acquisition-divestiture${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(a110InsightsCompanyAcquisitionDivestitureResponse, await res.json()) };