import {z} from 'zod' export type InvoiceTypeEnum1 = 'accounts_receivable' | 'accounts_payable'; export type InvoiceLineItemTypeEnum1 = '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 type FuelSurchargeConfigurationRate1 = {effective_from_date: string, surcharge_percentage: number}; export type FuelSurchargeConfigurationClientCreate1 = {schema_version: 1, name: string, invoice_type: InvoiceTypeEnum1, counterparty_org_id?: (string | null) | undefined, counterparty_off_chrt_org_data_id?: (string | null) | undefined, counterparty_driver_id?: (string | null) | undefined, shipper_account_id?: (string | null) | undefined, applies_to_line_item_types: Array, rates: Array}; export type CreateApiBillingNewFuelSurchargeConfigurationsCreateV1Args = {body: FuelSurchargeConfigurationClientCreate1}; export type CreateApiBillingNewFuelSurchargeConfigurationsCreateV1Options = {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 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 * * POST /billing_new/fuel_surcharge_configurations/create/v1 */ export const createApiBillingNewFuelSurchargeConfigurationsCreateV1 = async (args: CreateApiBillingNewFuelSurchargeConfigurationsCreateV1Args, options?: CreateApiBillingNewFuelSurchargeConfigurationsCreateV1Options) => { const {baseUrl = "http://localhost:8000", fetch: fetchFn = fetch, HTTPBearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (HTTPBearer !== undefined) headers.set('authorization', `Bearer ${HTTPBearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/billing_new/fuel_surcharge_configurations/create/v1${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(fuelSurchargeConfiguration1, await res.json()) };