import {z} from 'zod' export type Model162 = {clinic_name?: string | undefined, street1: string, street2?: string | undefined, city: string, state: string, country?: string | undefined, zip: string, phone: string, email?: string | undefined, fax?: string | undefined}; export type Model163 = {prescriber_type?: ('OD' | 'PMHNP' | 'MBBS' | 'DNP' | 'D.O.' | 'DPT' | 'D.D.S.' | 'F.N.P.' | 'CPP' | 'N.D.' | 'P.A.' | 'APNP' | 'V.M.D.' | 'RPh' | 'APRN' | 'DC APC' | 'PsyD' | 'CRNA' | 'PharmD' | 'B.V.M.S.' | 'WHNP' | 'PhD' | 'ARNP' | 'PT' | 'CRNP' | 'DPM' | 'CNP' | 'N.P.' | 'CDH' | 'D.M.D.' | 'D.V.M.' | 'M.D.' | 'CNM') | undefined, first_name: string, last_name: string, dea?: string | undefined, npi: string, active: boolean, address: Model162}; export type CreateApiV1PrescriberArgs = {body: Model163}; export type CreateApiV1PrescriberOptions = {baseUrl?: string | undefined, apiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const model164 = z.object({prescriber_token: z.string().optional()}); 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 }; /** * Create Prescriber * * POST /v1/prescriber */ export const createApiV1Prescriber = async (args: CreateApiV1PrescriberArgs, options?: CreateApiV1PrescriberOptions) => { const {baseUrl = "https://api.truepill.com", fetch: fetchFn = fetch, apiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (apiKey !== undefined) headers.set("Authorization", apiKey) const url = `${baseUrl.replace(/\/+$/, '')}/v1/prescriber${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(model164, await res.json()) };