import {z} from 'zod' export type InvoiceTypeEnum1 = 'accounts_receivable' | 'accounts_payable'; export type BillingCurrencyCodeEnum1 = 'USD' | 'CAD' | 'EUR' | 'GBP' | 'MXN' | 'AUD' | 'JPY' | 'CNY' | 'CHF' | 'INR'; export type TaskGroupTypeEnum1 = 'chrt_ground_provider' | 'cargo_on_flight' | 'cargo_on_vessel' | 'onboard_courier'; export type ServiceLineEnum = 'on_demand' | 'routed'; export type RateSheetRuleChargedPerEnum1 = 'order' | 'task_group' | 'task'; export type BaseRateChargeRule1 = {rule_type: 'base_rate', rule_key?: unknown | undefined, charged_per?: RateSheetRuleChargedPerEnum1 | undefined, line_item_description: string, export_ref__sage__item_id?: (string | null) | undefined, flat_rate: number}; export type RateSheetLocationRate1 = {shipper_account_id?: (string | null) | undefined, pricing_zone_id?: (string | null) | undefined, flat_rate: number}; export type LocationRateChargeRule1 = {rule_type: 'location_rate', rule_key?: unknown | undefined, charged_per?: 'task' | undefined, line_item_description: string, export_ref__sage__item_id?: (string | null) | undefined, location_rates: Array}; export type RateSheetZonePairRate1 = {origin_pricing_zone_id: string, destination_pricing_zone_id: string, flat_rate: number}; export type ZoneToZoneChargeRule1 = {rule_type: 'zone_to_zone', rule_key?: unknown | undefined, charged_per?: RateSheetRuleChargedPerEnum1 | undefined, line_item_description: string, export_ref__sage__item_id?: (string | null) | undefined, zone_pair_rates: Array, rates_apply_both_directions?: boolean | undefined}; export type MileageChargeRule1 = {rule_type: 'mileage', rule_key?: unknown | undefined, charged_per?: ('task_group' | 'task') | undefined, line_item_description: string, export_ref__sage__item_id?: (string | null) | undefined, included_distance_miles?: number | undefined, rate_per_mile: number, ends_at_total_distance_miles?: (number | null) | undefined, minimum_charge?: (number | null) | undefined}; export type LongDistanceMileageChargeRule1 = {rule_type: 'long_distance_mileage', rule_key?: unknown | undefined, charged_per?: ('task_group' | 'task') | undefined, line_item_description: string, export_ref__sage__item_id?: (string | null) | undefined, included_distance_miles?: number | undefined, rate_per_mile: number, ends_at_total_distance_miles?: (number | null) | undefined, minimum_charge?: (number | null) | undefined}; export type WaitTimeChargeRule1 = {rule_type: 'wait_time', rule_key?: unknown | undefined, charged_per?: 'task' | undefined, line_item_description: string, export_ref__sage__item_id?: (string | null) | undefined, included_wait_minutes: number, rate_per_wait_minute: number}; export type ExtraStopChargeRule1 = {rule_type: 'extra_stop', rule_key?: unknown | undefined, charged_per?: 'task_group' | undefined, line_item_description: string, export_ref__sage__item_id?: (string | null) | undefined, included_stops?: number | undefined, rate_per_extra_stop: number, attempted_stops_count_as_stops?: boolean | undefined}; export type ChrtGroundProviderTaskActionEnum1 = 'chrt_ground_provider__pickup' | 'chrt_ground_provider__deliver' | 'chrt_ground_provider__recover_from_airline' | 'chrt_ground_provider__tender_to_airline' | 'chrt_ground_provider__recover_from_ocean_terminal' | 'chrt_ground_provider__tender_to_ocean_terminal' | 'chrt_ground_provider__consolidate' | 'chrt_ground_provider__hold' | 'chrt_ground_provider__other'; export type CargoOnFlightTaskActionEnum1 = 'cargo_on_flight__cargo_received_by_airline' | 'cargo_on_flight__cargo_manifested' | 'cargo_on_flight__cargo_loaded_onto_flight' | 'cargo_on_flight__flight_departed' | 'cargo_on_flight__flight_arrived' | 'cargo_on_flight__cargo_offloaded_from_flight' | 'cargo_on_flight__cargo_cleared_customs' | 'cargo_on_flight__cargo_ready_for_recovery' | 'cargo_on_flight__cargo_recovered'; export type CargoOnVesselTaskActionEnum1 = 'cargo_on_vessel__gated_in_full' | 'cargo_on_vessel__loaded_onto_vessel' | 'cargo_on_vessel__vessel_departed' | 'cargo_on_vessel__vessel_arrived' | 'cargo_on_vessel__discharged_from_vessel' | 'cargo_on_vessel__available_for_pickup' | 'cargo_on_vessel__gated_out_full'; export type OnboardCourierTaskActionEnum1 = 'obc__cargo_picked_up' | 'obc__courier_thru_security' | 'obc__courier_boarded_flight' | 'obc__courier_deboarded_flight' | 'obc__courier_cleared_customs' | 'obc__cargo_delivered'; export type StopFeeChargeRule1 = {rule_type: 'stop_fee', rule_key?: unknown | undefined, charged_per?: 'task' | undefined, line_item_description: string, export_ref__sage__item_id?: (string | null) | undefined, flat_rate: number, applies_to_task_actions: Array}; export type RateSheetRuleQuantityBasisEnum1 = 'order_unique_cargo' | 'task_group_unique_cargo' | 'task_handled_cargo'; export type PieceCountChargeRule1 = {rule_type: 'piece_count', rule_key?: unknown | undefined, charged_per?: ('order' | 'task_group') | undefined, line_item_description: string, export_ref__sage__item_id?: (string | null) | undefined, included_pieces: number, rate_per_piece: number, quantity_basis: RateSheetRuleQuantityBasisEnum1}; export type RateSheetRuleWeightUnitEnum1 = 'lb' | 'kg'; export type RateSheetRuleWeightTypeEnum1 = 'gross' | 'chargeable' | 'volumetric'; export type RateSheetWeightBreak1 = {starts_at_weight: number, rate_per_weight_unit: number}; export type WeightChargeRule1 = {rule_type: 'weight', rule_key?: unknown | undefined, charged_per?: ('order' | 'task_group') | undefined, line_item_description: string, export_ref__sage__item_id?: (string | null) | undefined, included_weight: number, rate_per_weight_unit: number, weight_unit: RateSheetRuleWeightUnitEnum1, weight_type: RateSheetRuleWeightTypeEnum1, quantity_basis: RateSheetRuleQuantityBasisEnum1, weight_breaks?: Array | undefined, minimum_charge?: (number | null) | undefined, dim_factor_cubic_inches_per_pound?: (number | null) | undefined}; export type FuelSurchargeChargeRule1 = {rule_type: 'fuel_surcharge', rule_key?: unknown | undefined, charged_per?: 'task_group' | undefined, line_item_description: string, export_ref__sage__item_id?: (string | null) | undefined}; export type VehicleTypeEnum = 'sedan' | 'suv' | 'cargo_van' | 'box_truck' | 'flatbed' | 'semi_truck' | 'airplane'; 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 VehicleSurchargeChargeRule1 = {rule_type: 'vehicle_surcharge', rule_key?: unknown | undefined, charged_per?: ('task_group' | 'task') | undefined, line_item_description: string, export_ref__sage__item_id?: (string | null) | undefined, vehicle_types: Array, flat_rate?: (number | null) | undefined, surcharge_percentage?: (number | null) | undefined, applies_to_line_item_types?: Array | undefined}; export type RateSheetRulePricingMethodEnum1 = 'markup' | 'margin'; export type AirWaybillResaleChargeRule1 = {rule_type: 'air_waybill_resale', rule_key?: unknown | undefined, charged_per?: 'task_group' | undefined, line_item_description: string, export_ref__sage__item_id?: (string | null) | undefined, pricing_method: RateSheetRulePricingMethodEnum1, pricing_percentage: number, applies_to_line_item_types: Array, combine_sources_into_one_charge?: boolean | undefined, applies_to_relationship_types?: (Array<'executor_payable' | 'driver_payable'>) | undefined}; export type FlightTicketResaleChargeRule1 = {rule_type: 'flight_ticket_resale', rule_key?: unknown | undefined, charged_per?: 'task_group' | undefined, line_item_description: string, export_ref__sage__item_id?: (string | null) | undefined, pricing_method: RateSheetRulePricingMethodEnum1, pricing_percentage: number, applies_to_line_item_types: Array, combine_sources_into_one_charge?: boolean | undefined, applies_to_relationship_types?: (Array<'executor_payable' | 'driver_payable'>) | undefined}; export type SupplierMarkupChargeRule1 = {rule_type: 'supplier_markup', rule_key?: unknown | undefined, charged_per?: 'task_group' | undefined, line_item_description: string, export_ref__sage__item_id?: (string | null) | undefined, pricing_method: RateSheetRulePricingMethodEnum1, pricing_percentage: number, applies_to_line_item_types: Array, combine_sources_into_one_charge?: boolean | undefined, applies_to_relationship_types?: (Array<'executor_payable' | 'driver_payable'>) | undefined}; export type RevenueShareChargeRule1 = {rule_type: 'revenue_share', rule_key?: unknown | undefined, charged_per?: 'order' | undefined, line_item_description: string, export_ref__sage__item_id?: (string | null) | undefined, revenue_share_percentage: number, applies_to_line_item_types: Array}; export type OnboardCourierMissionBaseChargeRule1 = {rule_type: 'onboard_courier_mission_base', rule_key?: unknown | undefined, charged_per?: ('task_group' | 'task') | undefined, line_item_description: string, export_ref__sage__item_id?: (string | null) | undefined, flat_rate: number}; export type AttemptChargeRule1 = {rule_type: 'attempt', rule_key?: unknown | undefined, charged_per?: 'task' | undefined, line_item_description: string, export_ref__sage__item_id?: (string | null) | undefined, rate_per_occurrence: number}; export type PickAndHoldChargeRule1 = {rule_type: 'pick_and_hold', rule_key?: unknown | undefined, charged_per?: 'task_group' | undefined, line_item_description: string, export_ref__sage__item_id?: (string | null) | undefined, rate_per_occurrence: number}; export type EquipmentChargeRule1 = {rule_type: 'equipment', rule_key?: unknown | undefined, charged_per?: RateSheetRuleChargedPerEnum1 | undefined, line_item_description: string, export_ref__sage__item_id?: (string | null) | undefined, flat_rate: number}; export type DangerousGoodsChargeRule1 = {rule_type: 'dangerous_goods', rule_key?: unknown | undefined, charged_per?: RateSheetRuleChargedPerEnum1 | undefined, line_item_description: string, export_ref__sage__item_id?: (string | null) | undefined, flat_rate: number}; export type AfterHoursChargeRule1 = {rule_type: 'after_hours', rule_key?: unknown | undefined, charged_per?: RateSheetRuleChargedPerEnum1 | undefined, line_item_description: string, export_ref__sage__item_id?: (string | null) | undefined, flat_rate: number}; export type WeekendChargeRule1 = {rule_type: 'weekend', rule_key?: unknown | undefined, charged_per?: RateSheetRuleChargedPerEnum1 | undefined, line_item_description: string, export_ref__sage__item_id?: (string | null) | undefined, flat_rate: number}; export type HolidayChargeRule1 = {rule_type: 'holiday', rule_key?: unknown | undefined, charged_per?: RateSheetRuleChargedPerEnum1 | undefined, line_item_description: string, export_ref__sage__item_id?: (string | null) | undefined, flat_rate: number}; export type OrderMinimumChargeRule1 = {rule_type: 'order_minimum', rule_key?: unknown | undefined, charged_per?: 'order' | undefined, line_item_description: string, export_ref__sage__item_id?: (string | null) | undefined, minimum_charge: number}; export type RateSheetClientCreate1 = {schema_version: 1, name: string, invoice_type: InvoiceTypeEnum1, currency_code: BillingCurrencyCodeEnum1, counterparty_org_id?: (string | null) | undefined, counterparty_off_chrt_org_data_id?: (string | null) | undefined, counterparty_driver_id?: (string | null) | undefined, task_group_type: TaskGroupTypeEnum1, applies_to_service_lines?: Array | undefined, effective_time_zone_name?: string | undefined, effective_starts_at_timestamp?: (string | null) | undefined, effective_ends_at_timestamp?: (string | null) | undefined, rules: Array}; export type RateSheetPreviewReq = {rate_sheet: RateSheetClientCreate1, order_id: string}; export type CreateApiBillingNewRateSheetsPreviewV1Args = {body: RateSheetPreviewReq}; export type CreateApiBillingNewRateSheetsPreviewV1Options = {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 invoiceLineItemUnitEnum1 = z.enum(["each", "shipment", "minute", "hour", "day", "mile", "kilometer", "pound", "kilogram"]); export const billingCurrencyCodeEnum1 = z.enum(["USD", "CAD", "EUR", "GBP", "MXN", "AUD", "JPY", "CNY", "CHF", "INR"]); export const orderBillingEstimateLineItem1 = z.object({billing_line_key: z.string().min(1).max(1024), 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(), task_group_id: z.string().nullable().optional(), rate_sheet_id: z.string().nullable().optional(), line_item_type: invoiceLineItemTypeEnum1, description: z.string().min(1).max(32768), quantity: z.number().gt(0), unit: invoiceLineItemUnitEnum1.nullable().optional(), unit_price: z.number(), currency_code: billingCurrencyCodeEnum1}); export const unpricedReasonCodeEnum1 = z.enum(["no_rate_sheet", "rate_sheet_not_found", "rate_sheet_not_in_effect", "rule_not_priced_yet", "missing_stops", "no_lane_rate", "no_location_rate", "missing_miles", "no_cargo_to_measure", "missing_measurements", "charged_on_gross_weight", "currency_left_out", "no_payable_lines", "no_receivable_lines_to_share", "order_wide_charges_left_out", "no_fuel_surcharge_configuration"]); export const billingRelationshipTypeEnum1 = z.enum(["receivable", "executor_payable", "driver_payable"]); export const unpricedReason1 = z.object({code: unpricedReasonCodeEnum1, relationship_type: billingRelationshipTypeEnum1.nullable().optional(), task_group_id: z.string().nullable().optional(), task_id: z.string().nullable().optional(), rate_sheet_id: z.string().nullable().optional(), rule_key: z.string().nullable().optional()}); export const rateSheetPreviewRes = z.object({order_id: z.string(), task_group_ids: z.array(z.string()).optional(), line_items: z.array(orderBillingEstimateLineItem1).optional(), unpriced_reasons: z.array(unpricedReason1).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 }; /** * Preview * * POST /billing_new/rate_sheets/preview/v1 */ export const createApiBillingNewRateSheetsPreviewV1 = async (args: CreateApiBillingNewRateSheetsPreviewV1Args, options?: CreateApiBillingNewRateSheetsPreviewV1Options) => { 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/rate_sheets/preview/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(rateSheetPreviewRes, await res.json()) };