import {z} from 'zod' export type B0641DrugSearchCreateEvent = {name: string, sub_event: Array}; export type B0641DrugSearchCreateFrequency = {date?: number | undefined, type: string}; export type B0641DrugSearchCreateDrugSearchDrugConditionValue = {condition?: string | undefined, value?: Array | undefined}; export type B0641DrugSearchCreateDrugSearchTargetConditionValue = {condition?: string | undefined, value?: Array | undefined}; export type B0641DrugSearchCreateDrugSearchDiseaseConditionValue = {condition?: string | undefined, value?: Array | undefined}; export type B0641DrugSearchCreateDrugSearchOrganizationConditionValue = {condition?: string | undefined, value?: Array | undefined}; export type B0641DrugSearchCreateDrugSearchMechanismActionConditionValue = {condition?: string | undefined, value?: Array | undefined}; export type B0641DrugSearchCreateDrugSearchDrugTypeConditionValue = {condition?: string | undefined, value?: Array | undefined}; export type B0641DrugSearchCreateDrugSearchSortDto = {sort_field?: string | undefined, sort_order?: string | undefined}; export type B0641DrugSearchCreateDrugSearchRequestDto = {offset?: number | undefined, limit?: number | undefined, drug?: B0641DrugSearchCreateDrugSearchDrugConditionValue | undefined, target?: B0641DrugSearchCreateDrugSearchTargetConditionValue | undefined, disease?: B0641DrugSearchCreateDrugSearchDiseaseConditionValue | undefined, organization?: B0641DrugSearchCreateDrugSearchOrganizationConditionValue | undefined, mechanism_action?: B0641DrugSearchCreateDrugSearchMechanismActionConditionValue | undefined, drug_type?: B0641DrugSearchCreateDrugSearchDrugTypeConditionValue | undefined, global_highest_dev_status?: Array | undefined, exist_deal?: boolean | undefined, dev_status?: Array | undefined, country?: Array | undefined, organization_type?: Array | undefined, employee_number?: Array | undefined, start_up?: boolean | undefined, sort?: Array | undefined}; export type B0641DrugSearchCreateRequest = {events: Array, frequency: B0641DrugSearchCreateFrequency, lang: string, query: B0641DrugSearchCreateDrugSearchRequestDto, title: string}; export type CreateApiSynapseAlertDrugSearchCreateArgs = {body: B0641DrugSearchCreateRequest}; export type CreateApiSynapseAlertDrugSearchCreateOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const b0641DrugSearchCreateAlertResponse = z.object({alert_id: z.string().optional()}); export const b0641DrugSearchCreateResponse = z.object({data: b0641DrugSearchCreateAlertResponse.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 }; /** * B064-1 Create drug monitoring * * POST /synapse/alert/drug_search/create */ export const createApiSynapseAlertDrugSearchCreate = async (args: CreateApiSynapseAlertDrugSearchCreateArgs, options?: CreateApiSynapseAlertDrugSearchCreateOptions) => { 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/alert/drug_search/create${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(b0641DrugSearchCreateResponse, await res.json()) };