import {z} from 'zod' export type CreateApiV1DispatchLocationsArgs = {'X-Metric-Units'?: boolean | undefined, body: {name?: string | undefined, vendor_id?: string | undefined, address1?: string | undefined, address2?: string | undefined, city?: string | undefined, state?: string | undefined, zip?: string | undefined, country?: string | undefined, lat?: number | undefined, lon?: number | undefined, arrive_radius?: number | undefined, depart_radius?: number | undefined, phone?: string | undefined}}; export type CreateApiV1DispatchLocationsOptions = {baseUrl?: string | undefined, sec0?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiV1DispatchLocationsResponse = z.object({dispatch_location: z.object({id: z.number().int().optional(), vendor_id: z.string().optional(), lat: z.number().int().optional(), lon: z.number().int().optional(), name: z.string().optional(), address1: z.string().optional(), address2: z.string().optional(), city: z.string().optional(), state: z.string().optional(), zip: z.string().optional(), country: z.string().optional(), arrive_radius: z.number().int().optional(), depart_radius: z.number().int().optional(), phone: z.string().optional()}).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 a dispatch location * * POST /v1/dispatch_locations */ export const createApiV1DispatchLocations = async (args: CreateApiV1DispatchLocationsArgs, options?: CreateApiV1DispatchLocationsOptions) => { const {baseUrl = "https://api.gomotive.com", fetch: fetchFn = fetch, sec0} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args['X-Metric-Units'] != null) headers.set("X-Metric-Units", String(args['X-Metric-Units'])) if (sec0 !== undefined) headers.set("x-api-key", sec0) const url = `${baseUrl.replace(/\/+$/, '')}/v1/dispatch_locations${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(createApiV1DispatchLocationsResponse, await res.json()) };