import {z} from 'zod' export type InvoiceTypeEnum1 = 'accounts_receivable' | 'accounts_payable'; export type FuelSurchargeConfigurationSortByEnum = 'name' | 'created_at_timestamp'; export type SortOrderEnum = 'asc' | 'desc'; export type GetApiBillingNewFuelSurchargeConfigurationsListV1Args = {filter_invoice_type?: (InvoiceTypeEnum1 | null) | undefined, filter_counterparty_org_id?: (string | null) | undefined, filter_counterparty_off_chrt_org_data_id?: (string | null) | undefined, filter_counterparty_driver_id?: (string | null) | undefined, filter_shipper_account_id?: (string | null) | undefined, filter_archived?: (boolean | null) | undefined, sort_by?: FuelSurchargeConfigurationSortByEnum | undefined, sort_order?: SortOrderEnum | undefined, page?: number | undefined, page_size?: number | undefined}; export type GetApiBillingNewFuelSurchargeConfigurationsListV1Options = {baseUrl?: string | undefined, HTTPBearer?: string | undefined, fetch?: typeof fetch | undefined}; export const invoiceTypeEnum1 = z.enum(["accounts_receivable", "accounts_payable"]); export const invoiceLineItemTypeEnum1 = z.enum(["base_rate", "additional_mileage", "long_distance_mileage", "fuel", "extra_stop", "wait_time", "attempt", "pick_and_hold", "stop_fee", "parking", "tolls", "additional_fee", "dispute", "equipment", "dangerous_goods", "special_vehicle", "after_hours", "weekend", "holiday", "air_waybill", "insurance", "off_network_carrier", "obc_day_rate", "flight_ticket", "piece_count", "weight", "revenue_share", "minimum_charge", "tracking_device_label", "tracking_device_tag", "tracking_device_other", "tax", "adjustment", "other"]); export const fuelSurchargeConfigurationRate1 = z.object({effective_from_date: z.string(), surcharge_percentage: z.number().gte(0)}); export const fuelSurchargeConfiguration1 = z.object({schema_version: z.literal(1), name: z.string().min(1).max(255), invoice_type: invoiceTypeEnum1, counterparty_org_id: z.string().nullable().optional(), counterparty_off_chrt_org_data_id: z.string().nullable().optional(), counterparty_driver_id: z.string().nullable().optional(), shipper_account_id: z.string().nullable().optional(), applies_to_line_item_types: z.array(invoiceLineItemTypeEnum1), rates: z.array(fuelSurchargeConfigurationRate1), _id: z.string(), owned_by_org_id: z.string(), created_by_user_id: z.string(), created_at_timestamp: z.string(), last_edited_by_user_id: z.string(), last_edited_at_timestamp: z.string(), archived_by_user_id: z.string().nullable().optional(), archived_at_timestamp: z.string().nullable().optional()}); export const fuelSurchargeConfigurationListRes = z.object({items: z.array(fuelSurchargeConfiguration1).optional(), total_count: z.number().int()}); 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 * * GET /billing_new/fuel_surcharge_configurations/list/v1 */ export const getApiBillingNewFuelSurchargeConfigurationsListV1 = async (args: GetApiBillingNewFuelSurchargeConfigurationsListV1Args, options?: GetApiBillingNewFuelSurchargeConfigurationsListV1Options) => { const {baseUrl = "http://localhost:8000", fetch: fetchFn = fetch, HTTPBearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.filter_invoice_type != null) query.append("filter_invoice_type", String(args.filter_invoice_type)) if (args.filter_counterparty_org_id != null) query.append("filter_counterparty_org_id", String(args.filter_counterparty_org_id)) if (args.filter_counterparty_off_chrt_org_data_id != null) query.append("filter_counterparty_off_chrt_org_data_id", String(args.filter_counterparty_off_chrt_org_data_id)) if (args.filter_counterparty_driver_id != null) query.append("filter_counterparty_driver_id", String(args.filter_counterparty_driver_id)) if (args.filter_shipper_account_id != null) query.append("filter_shipper_account_id", String(args.filter_shipper_account_id)) if (args.filter_archived != null) query.append("filter_archived", String(args.filter_archived)) if (args.sort_by != null) query.append("sort_by", String(args.sort_by)) if (args.sort_order != null) query.append("sort_order", String(args.sort_order)) if (args.page != null) query.append("page", String(args.page)) if (args.page_size != null) query.append("page_size", String(args.page_size)) if (HTTPBearer !== undefined) headers.set('authorization', `Bearer ${HTTPBearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/billing_new/fuel_surcharge_configurations/list/v1${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(fuelSurchargeConfigurationListRes, await res.json()) };