import {z} from 'zod' export type GetApiV2FreightVisibilityVehicleAssociationArgs = {company_id?: number | undefined, dot_id?: number | undefined, lat?: number | undefined, lon?: number | undefined, expected_time?: string | undefined}; export type GetApiV2FreightVisibilityVehicleAssociationOptions = {baseUrl?: string | undefined, sec0?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiV2FreightVisibilityVehicleAssociationResponse = z.object({pagination: z.object({per_page: z.number().int().optional(), page_no: z.number().int().optional(), total: z.number().int().optional()}).optional(), data: z.object({company_id: z.string().optional(), dot_ids: z.array(z.string()).optional(), integration_status: z.string().optional(), vehicle_details: z.array(z.object({vehicle_id: z.string().optional(), vehicle_name: z.string().optional(), eld_device_id: z.unknown(), eld_identifier: z.unknown(), trailer_id: z.string().optional(), driver: z.object({id: z.number().int().optional(), first_name: z.string().optional(), last_name: z.string().optional()}).optional(), located_at: z.string().optional(), description: z.string().optional(), distance_origin: z.object({value: z.number().optional(), unit: z.string().optional()}).optional(), matching_score: z.number().optional()})).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 }; /** * List all the nearby vehicles (v2) * * GET /v2/freight_visibility/vehicle_association */ export const getApiV2FreightVisibilityVehicleAssociation = async (args: GetApiV2FreightVisibilityVehicleAssociationArgs, options?: GetApiV2FreightVisibilityVehicleAssociationOptions) => { const {baseUrl = "https://api.gomotive.com", fetch: fetchFn = fetch, sec0} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.company_id != null) query.append("company_id", String(args.company_id)) if (args.dot_id != null) query.append("dot_id", String(args.dot_id)) if (args.lat != null) query.append("lat", String(args.lat)) if (args.lon != null) query.append("lon", String(args.lon)) if (args.expected_time != null) query.append("expected_time", String(args.expected_time)) if (sec0 !== undefined) headers.set("x-api-key", sec0) const url = `${baseUrl.replace(/\/+$/, '')}/v2/freight_visibility/vehicle_association${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(getApiV2FreightVisibilityVehicleAssociationResponse, await res.json()) };