import {z} from 'zod' export type GetApiV1FreightVisibilityAssetAssociationArgs = {company_id?: number | undefined, dot_id?: number | undefined, lat?: number | undefined, lon?: number | undefined}; export type GetApiV1FreightVisibilityAssetAssociationOptions = {baseUrl?: string | undefined, sec0?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiV1FreightVisibilityAssetAssociationResponse = z.object({data: z.object({asset_details: z.array(z.object({name: z.string().optional(), status: z.string().optional(), type: z.string().optional(), vin: z.unknown(), license_plate_state: z.unknown(), license_plate_number: z.unknown(), make: z.string().optional(), model: z.string().optional(), year: z.string().optional(), axle: z.unknown(), weight_metric_units: z.boolean().optional(), length_metric_units: z.boolean().optional(), leased: z.unknown(), notes: z.unknown(), length: z.unknown(), gvwr: z.unknown(), gawr: z.unknown(), asset_gateway: z.object({id: z.number().int().optional(), identifier: z.string().optional(), active: z.boolean().optional()}).optional(), asset_id: z.number().int().optional(), trailer_id: z.unknown(), located_at: z.string().optional(), lat: z.number().optional(), lon: z.number().optional(), distance_origin: z.number().optional(), description: z.string().optional()})).optional(), company_id: z.number().int().optional(), dot_ids: z.array(z.string()).optional(), integration_status: z.string().optional()}).optional(), pagination: z.object({per_page: z.number().int().optional(), page_no: z.number().int().optional(), total: z.number().int().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 location of company assets (based on proximity) * * GET /v1/freight_visibility/asset_association */ export const getApiV1FreightVisibilityAssetAssociation = async (args: GetApiV1FreightVisibilityAssetAssociationArgs, options?: GetApiV1FreightVisibilityAssetAssociationOptions) => { 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 (sec0 !== undefined) headers.set("x-api-key", sec0) const url = `${baseUrl.replace(/\/+$/, '')}/v1/freight_visibility/asset_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(getApiV1FreightVisibilityAssetAssociationResponse, await res.json()) };