import {z} from 'zod' export type Model182 = {request_id?: string | undefined, address_from_company?: string | undefined, shipping_method?: ('standard' | 'priority' | 'overnight' | 'usps_ground_advantage' | 'usps_priority' | 'usps_priority_express' | 'fedex_ground' | 'fedex_2_day' | 'fedex_smart_post' | 'fedex_standard_overnight' | 'fedex_priority_overnight' | 'ups_mail_innovations_domestic' | 'ups_next_day_air' | 'ups_next_day_air_saver' | 'ups_second_day_air' | 'ups_ground' | 'dhl_ecommerce_parcels_ground' | 'dhl_ecommerce_parcels_expedited' | 'dhl_ecommerce_parcels_expedited_max' | 'dhl_ecommerce_parcel_plus_ground' | 'dhl_ecommerce_parcel_plus_expedited' | 'dhl_ecommerce_parcel_plus_expedited_max') | undefined, signature_confirmation?: boolean | undefined, notes?: string | undefined, address_to_name: string, address_to_company?: string | undefined, address_to_street1: string, address_to_street2?: string | undefined, address_to_city: string, address_to_state: string, address_to_zip: string, address_to_country?: string | undefined, address_to_phone: string, address_to_email?: string | undefined}; export type CreateApiV1UpdateRequestArgs = {body: Model182}; export type CreateApiV1UpdateRequestOptions = {baseUrl?: string | undefined, apiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const model183 = z.object({message: z.string().optional()}); export const model184 = z.object({request_id: z.string().optional(), timestamp: z.number().int().optional(), status: z.string().optional(), details: model183.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 }; /** * Update Fill Request * * POST /v1/update_request */ export const createApiV1UpdateRequest = async (args: CreateApiV1UpdateRequestArgs, options?: CreateApiV1UpdateRequestOptions) => { 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/update_request${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(model184, await res.json()) };