import {z} from 'zod' export type CreateApiV1VehiclesArgs = {'X-Time-Zone'?: string | undefined, 'X-Metric-Units'?: boolean | undefined, 'X-User-Id'?: number | undefined, body: {number: number, eld_device_id?: number | undefined, status?: string | undefined, ifta?: boolean | undefined, metric_units?: boolean | undefined, fuel_type?: string | undefined, vin?: string | undefined, license_plate_state?: string | undefined, license_plate_number?: string | undefined, make?: string | undefined, model?: string | undefined, year?: string | undefined, prevent_auto_odometer_entry?: boolean | undefined, external_ids_attributes?: Array<{external_id: string, integration_name: string, external_id_holder_id: number, external_id_holder_type: string}> | undefined, permanent_driver_id?: number | undefined, notes?: string | undefined, group_ids?: ({''?: Array | undefined}) | undefined, driver_facing_camera?: number | undefined, incab_audio_recording?: number | undefined, availability_details?: ({availability_status?: string | undefined, additional_note?: string | undefined, custom_driver_app_warning_prompt?: string | undefined}) | undefined}}; export type CreateApiV1VehiclesOptions = {baseUrl?: string | undefined, sec0?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiV1VehiclesResponse = z.object({vehicle: z.object({id: z.unknown(), company_id: z.number().int().optional(), number: z.string().optional(), status: z.string().optional(), ifta: z.boolean().optional(), vin: z.unknown(), make: z.unknown(), model: z.unknown(), year: z.unknown(), license_plate_state: z.unknown(), license_plate_number: z.unknown(), metric_units: z.boolean().optional(), fuel_type: z.string().optional(), prevent_auto_odometer_entry: z.boolean().optional(), notes: z.unknown(), group_ids: z.array(z.object({})).optional(), created_at: z.unknown(), updated_at: z.unknown(), mcleod_id: z.unknown(), permanent_driver: z.unknown(), eld_device: z.unknown(), current_driver: z.unknown(), external_ids: z.array(z.object({})).optional()}).optional(), availability_details: z.object({availability_status: z.string().optional(), out_of_service_reason: z.string().optional(), updated_at: z.string().optional(), additional_note: z.string().optional(), custom_driver_app_warning_prompt: z.string().optional(), updated_by_user: z.object({id: z.number().int().optional(), first_name: z.string().optional(), last_name: z.string().optional(), user_name: z.string().optional(), email: z.string().optional(), company_reference_id: z.number().int().optional(), status: z.string().optional(), role: z.string().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 }; /** * Create a new vehicle * * POST /v1/vehicles */ export const createApiV1Vehicles = async (args: CreateApiV1VehiclesArgs, options?: CreateApiV1VehiclesOptions) => { 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-Time-Zone'] != null) headers.set("X-Time-Zone", String(args['X-Time-Zone'])) if (args['X-Metric-Units'] != null) headers.set("X-Metric-Units", String(args['X-Metric-Units'])) if (args['X-User-Id'] != null) headers.set("X-User-Id", String(args['X-User-Id'])) if (sec0 !== undefined) headers.set("x-api-key", sec0) const url = `${baseUrl.replace(/\/+$/, '')}/v1/vehicles${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(createApiV1VehiclesResponse, await res.json()) };