import {z} from 'zod' export type NullableId = number | null; export type PatchApiVehiclesVehicleIdWarrantiesIdArgs = {vehicle_id: string, id: string, body: {name?: string | undefined, description?: (string | null) | undefined, contract_number?: (string | null) | undefined, coverage_type?: ('standard' | 'extended' | null) | undefined, manufacturer_name?: (string | null) | undefined, start_date?: string | undefined, end_date?: (string | null) | undefined, start_primary_meter?: (number | null) | undefined, end_primary_meter?: (number | null) | undefined, start_secondary_meter?: (number | null) | undefined, end_secondary_meter?: (number | null) | undefined, primary_meter_distance?: (number | null) | undefined, primary_meter_unlimited?: boolean | undefined, secondary_meter_distance?: (number | null) | undefined, secondary_meter_unlimited?: boolean | undefined, term_duration_unit?: ('months' | 'years') | undefined, term_duration_value?: number | undefined, vendor_id?: NullableId | undefined, vendor_warranties_url?: (string | null) | undefined}}; export type PatchApiVehiclesVehicleIdWarrantiesIdOptions = {baseUrl?: string | undefined, apiKey?: string | undefined, accountToken?: string | undefined, fetch?: typeof fetch | undefined}; export const id = z.number().int().gte(1); export const nullableId = z.number().int().gte(1).nullable(); export const createdAt = z.string(); export const updatedAt = z.string(); export const warranty = z.object({id: id, vehicle_id: id, name: z.string(), description: z.string().nullable().optional(), contract_number: z.string().nullable().optional(), coverage_type: z.enum(["standard", "extended"]).nullable().optional(), manufacturer_name: z.string().nullable().optional(), start_date: z.string(), end_date: z.string().nullable().optional(), start_primary_meter: z.string().nullable().optional(), end_primary_meter: z.string().nullable().optional(), start_secondary_meter: z.string().nullable().optional(), end_secondary_meter: z.string().nullable().optional(), primary_meter_distance: z.number().int().nullable().optional(), secondary_meter_distance: z.number().int().nullable().optional(), primary_meter_unlimited: z.boolean(), secondary_meter_unlimited: z.boolean(), term_duration_unit: z.enum(["months", "years"]), term_duration_value: z.number().int(), vendor_id: nullableId.optional(), vendor_name: z.string().nullable().optional(), vendor_warranties_url: z.string().nullable().optional(), status: z.enum(["active", "expiring_soon", "expired"]).nullable().optional(), created_at: createdAt, updated_at: updatedAt}); 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 }; /** * Update Warranty * * PATCH /vehicles/{vehicle_id}/warranties/{id} */ export const patchApiVehiclesVehicleIdWarrantiesId = async (args: PatchApiVehiclesVehicleIdWarrantiesIdArgs, options?: PatchApiVehiclesVehicleIdWarrantiesIdOptions) => { const {baseUrl = "https://secure.fleetio.com/api", fetch: fetchFn = fetch, apiKey, accountToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (apiKey !== undefined) headers.set("Authorization", apiKey) if (accountToken !== undefined) headers.set("Account-Token", accountToken) const url = `${baseUrl.replace(/\/+$/, '')}/vehicles/${encodeURIComponent(String(args.vehicle_id))}/warranties/${encodeURIComponent(String(args.id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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(warranty, await res.json()) };