import {z} from 'zod' export type B074DrugMilestoneRequest = {offset?: number | undefined, limit?: number | undefined, drug_id: string, sort_order?: string | undefined, milestone?: Array | undefined, event_id?: Array | undefined, disease_id?: Array | undefined, country_id?: Array | undefined, organization_id?: Array | undefined, event_start_time?: number | undefined, event_end_time?: number | undefined}; export type CreateApiSynapseDrugMilestoneArgs = {body: B074DrugMilestoneRequest}; export type CreateApiSynapseDrugMilestoneOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const b074DrugMilestoneCommonName = z.object({lang: z.string().optional(), name: z.string().optional()}); export const b074DrugMilestoneCommonEntity = z.object({id: z.string().optional(), display_name: z.array(b074DrugMilestoneCommonName).optional()}); export const b074DrugMilestoneCommonCountry = z.object({country_id: z.string().optional(), alpha2_code: z.string().optional(), display_name: z.array(b074DrugMilestoneCommonName).optional()}); export const b074DrugMilestoneCommonDisease = z.object({disease_id: z.string().optional(), display_name: z.array(b074DrugMilestoneCommonName).optional()}); export const b074DrugMilestoneCommonOrganization = z.object({display_name: z.array(b074DrugMilestoneCommonName).optional(), organization_id: z.string().optional()}); export const b074DrugMilestoneDrugMilestoneResponseDetail = z.object({date: z.string().optional(), event: z.array(b074DrugMilestoneCommonEntity).optional(), country: z.array(b074DrugMilestoneCommonCountry).optional(), disease: z.array(b074DrugMilestoneCommonDisease).optional(), description: z.array(b074DrugMilestoneCommonName).optional(), event_status: b074DrugMilestoneCommonEntity.optional(), organization: z.array(b074DrugMilestoneCommonOrganization).optional(), milestone_tag: z.array(b074DrugMilestoneCommonName).optional()}); export const b074DrugMilestoneDrugMilestoneResponseDto = z.object({items: z.array(b074DrugMilestoneDrugMilestoneResponseDetail).optional(), limit: z.number().int().optional(), total: z.number().int().optional(), offset: z.number().int().optional()}); export const b074DrugMilestoneResponse = z.object({data: b074DrugMilestoneDrugMilestoneResponseDto.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 }; /** * B074 Drug milestone * * POST /synapse/drug/milestone */ export const createApiSynapseDrugMilestone = async (args: CreateApiSynapseDrugMilestoneArgs, options?: CreateApiSynapseDrugMilestoneOptions) => { 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(/\/+$/, '')}/synapse/drug/milestone${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(b074DrugMilestoneResponse, await res.json()) };