import {z} from 'zod' export type CreateApiV1AssetsArgs = {'X-Time-Zone'?: string | undefined, 'X-User-Id'?: number | undefined, body: {name: string, type: string, custom_type?: string | undefined, make: string, model: string, year: string, subtype?: string | undefined, vin?: string | undefined, length?: number | undefined, axle?: number | undefined, gvwr?: number | undefined, gawr?: number | undefined, length_metric_units?: boolean | undefined, weight_metric_units?: boolean | undefined, license_plate_state?: string | undefined, license_plate_number?: string | undefined, leased?: boolean | undefined, notes?: string | undefined, asset_gateway_id?: string | undefined, external_ids_attributes?: {external_id: string, integration_name: string, external_id_holder_id: number, external_id_holder_type: string} | undefined, group_ids?: Array | undefined, availability_details?: ({availability_status?: string | undefined, additional_note?: string | undefined, custom_driver_app_warning_prompt?: string | undefined}) | undefined}}; export type CreateApiV1AssetsOptions = {baseUrl?: string | undefined, sec0?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiV1AssetsResponse = z.object({assets: z.array(z.object({asset: z.object({id: z.number().int().optional(), name: z.string().optional(), status: z.string().optional(), type: z.string().optional(), custom_type: z.unknown(), 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(), external_ids: z.array(z.object({})).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()}).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 }; /** * Create a new asset * * POST /v1/assets */ export const createApiV1Assets = async (args: CreateApiV1AssetsArgs, options?: CreateApiV1AssetsOptions) => { 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-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/assets${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(createApiV1AssetsResponse, await res.json()) };