import {z} from 'zod' export type Id = number; export type CustomFields = Record | null; export type PatchApiFuelEntriesIdArgs = {id: string, body: {vehicle_id?: Id | undefined, vendor_id?: number | undefined, fuel_type_id?: number | undefined, date?: string | undefined, us_gallons?: number | undefined, uk_gallons?: number | undefined, liters?: number | undefined, price_per_volume_unit?: number | undefined, meter_entry_attributes?: ({value?: number | undefined, void?: boolean | undefined}) | undefined, reference?: string | undefined, partial?: boolean | undefined, personal?: boolean | undefined, custom_fields?: CustomFields | undefined, documents_attributes?: (Array<{name?: string | undefined, file_url?: string | undefined, file_mime_type?: string | undefined, file_name?: string | undefined, file_size?: number | undefined}>) | undefined, images_attributes?: (Array<{name?: string | undefined, file_url?: string | undefined, file_mime_type?: string | undefined, file_name?: string | undefined, file_size?: number | undefined}>) | undefined}}; export type PatchApiFuelEntriesIdOptions = {baseUrl?: string | undefined, apiKey?: string | undefined, accountToken?: string | undefined, fetch?: typeof fetch | undefined}; export const id = z.number().int().gte(1); export const createdAt = z.string(); export const updatedAt = z.string(); export const customFields = z.object({}).nullable(); export const nullableId = z.number().int().gte(1).nullable(); export const vehicleMeterEntry = z.object({id: z.number().int().optional(), created_at: z.string().optional(), updated_at: z.string().optional(), auto_voided_at: z.string().nullable().optional(), category: z.enum(["starting", "ending", "nightly", "manual"]).nullable().optional(), meter_type: z.literal("secondary").nullable().optional(), meterable_id: nullableId.optional(), meterable_type: z.enum(["FuelEntry", "Issue", "PurchaseDetail", "ServiceEntry", "SubmittedInspectionItem", "VehicleAssignment", "WorkOrder"]).nullable().optional(), value: z.string().optional(), vehicle_id: nullableId.optional(), void: z.boolean().optional(), type: z.literal("GpsMeterEntry").nullable().optional(), date: z.string().optional()}).nullable(); export const geolocation = z.object({gps_device: z.string().nullable().optional(), original_vendor: z.string().nullable().optional(), exception_distance_in_mi: z.number().nullable().optional(), exception_distance_in_km: z.number().nullable().optional()}).nullable(); export const mapPreviews = z.object({small: z.string().nullable().optional(), large: z.string().nullable().optional(), small_short: z.string().nullable().optional(), large_short: z.string().nullable().optional()}); export const attachmentPermissions = z.object({read_photos: z.boolean().optional(), manage_photos: z.boolean().optional(), read_documents: z.boolean().optional(), manage_documents: z.boolean().optional()}).nullable(); export const commentableType = z.enum(["Contact", "FleetcorCard", "FuelEntry", "InventoryJournalEntry", "Issue", "Part", "PurchaseOrder", "ServiceEntry", "ServiceReminder", "SubmittedInspectionItem", "Vehicle", "VehicleAssignment", "Vendor", "WexCard", "WorkOrder"]); export const comment = z.object({id: id, created_at: createdAt.optional(), updated_at: updatedAt.optional(), commentable_type: commentableType, commentable_id: id, user_id: id, title: z.string().optional(), comment: z.string(), user_full_name: z.string(), user_image_url: z.string().nullable(), rich_content: z.object({}).nullable(), html_content: z.string().nullable(), with_mentions: z.boolean()}).nullable(); export const imageableType = z.enum(["ExpenseEntry", "WorkOrder", "Equipment", "IssueResolution", "ServiceEntry", "Vendor", "ServiceProgram", "Issue", "Contact", "Part", "Vehicle", "FuelEntry", "SubmittedInspectionItem"]); export const imageMimeType = z.enum(["image/jpeg", "image/gif", "image/jif", "image/jfif", "image/jfi", "image/tiff", "image/png", "image/jpg", "image/jpe", "image/pdf", "image/webp", "image/tif", "image/psd", "image/raw", "image/arw", "image/cr2", "image/nrw", "image/k25", "image/bmp", "image/dip", "image/ai", "image/eps", "image/heif", "image/heic", "image/ind", "image/indd", "image/indt", "image/jp2", "image/j2k", "image/jpf", "image/jpx", "image/jpm", "image/mj2", "image/x-png"]); export const image2 = z.object({id: id, created_at: createdAt.optional(), updated_at: updatedAt.optional(), imageable_id: id.optional(), imageable_type: imageableType.optional(), file_name: z.string().optional(), file_mime_type: imageMimeType.optional(), file_size: z.number().optional(), file_url: z.string().optional(), full_url: z.string().optional()}).nullable(); export const documentableType = z.enum(["ServiceEntry", "FuelEntry", "Issue", "WorkOrder", "ExpenseEntry", "Vehicle"]); export const document = z.object({id: id, created_at: createdAt.optional(), updated_at: updatedAt.optional(), name: z.string(), description: z.string(), documentable_id: id, documentable_type: documentableType, file_name: z.string(), file_mime_type: z.string(), file_size: z.number(), file_url: z.string(), full_file_url: z.string()}).nullable(); export const fuelEntry = z.object({id: id, created_at: createdAt.optional(), updated_at: updatedAt.optional(), cost_per_hr: z.number().nullable(), cost_per_km: z.number().nullable(), cost_per_mi: z.number().nullable(), date: z.string(), external_id: z.string().nullable(), fuel_type_id: z.number().int().gte(1).nullable(), fuel_type_name: z.string().nullable(), kpl: z.number().nullable(), liters: z.string().nullable(), liters_per_hr: z.number().nullable(), lp100k: z.number().nullable(), mpg_uk: z.number().nullable(), mpg_us: z.number().nullable(), partial: z.boolean(), personal: z.boolean(), price_per_volume_unit: z.number().nullable(), raw_transaction_data: z.object({}).nullable(), reference: z.string().nullable(), region: z.string().nullable(), reset: z.boolean(), uk_gallons: z.string(), uk_gallons_per_hr: z.number().nullable(), us_gallons: z.string(), us_gallons_per_hr: z.number().nullable(), usage_in_hr: z.string().nullable(), usage_in_km: z.string().nullable(), usage_in_mi: z.string().nullable(), vehicle_id: z.number().int().gte(1).nullable(), vehicle_name: z.string(), vendor_id: z.number().int().gte(1).nullable(), vendor_name: z.string().nullable(), is_sample: z.boolean(), custom_fields: customFields.optional(), fuel_economy_for_current_user: z.string().nullable().optional(), fuel_economy_units_for_current_user: z.string().optional(), meter_entry: vehicleMeterEntry, geolocation: geolocation, map_previews: mapPreviews, attachment_permissions: attachmentPermissions.optional(), total_amount: z.number(), comments: z.array(comment), comments_count: z.number().int().gte(0), images: z.array(image2).optional(), images_count: z.number().int().gte(0), documents: z.array(document).optional(), documents_count: z.number().int().gte(0)}).nullable(); 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 Fuel Entry * * PATCH /fuel_entries/{id} */ export const patchApiFuelEntriesId = async (args: PatchApiFuelEntriesIdArgs, options?: PatchApiFuelEntriesIdOptions) => { 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(/\/+$/, '')}/fuel_entries/${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(fuelEntry, await res.json()) };