import {z} from 'zod' export type OrderBillingQuoteTypeEnum1 = 'non_binding' | 'fixed'; export type BillingCurrencyCodeEnum1 = 'USD' | 'CAD' | 'EUR' | 'GBP' | 'MXN' | 'AUD' | 'JPY' | 'CNY' | 'CHF' | 'INR'; export type InvoiceLineItemUnitEnum1 = 'each' | 'shipment' | 'minute' | 'hour' | 'day' | 'mile' | 'kilometer' | 'pound' | 'kilogram'; 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 ProFormaLineItemClientCreate1 = {schema_version?: 1 | undefined, description: string, quantity: number, unit?: (InvoiceLineItemUnitEnum1 | null) | undefined, unit_price: number, currency_code: BillingCurrencyCodeEnum1, line_item_type: InvoiceLineItemTypeEnum1, awb_number?: (string | null) | undefined, tax_percentage?: (number | null) | undefined}; export type OrderBillingQuoteClientCreate1 = {schema_version: 1, order_id: string, counterparty_org_id?: (string | null) | undefined, counterparty_off_chrt_org_data_id?: (string | null) | undefined, shipper_account_id?: (string | null) | undefined, quote_type: OrderBillingQuoteTypeEnum1, currency_code: BillingCurrencyCodeEnum1, line_items?: Array | undefined}; export type CreateApiBillingNewQuotesCreateV1Args = {body: OrderBillingQuoteClientCreate1}; export type CreateApiBillingNewQuotesCreateV1Options = {baseUrl?: string | undefined, HTTPBearer?: string | undefined, fetch?: typeof fetch | undefined}; export const orderBillingQuoteTypeEnum1 = z.enum(["non_binding", "fixed"]); export const billingCurrencyCodeEnum1 = z.enum(["USD", "CAD", "EUR", "GBP", "MXN", "AUD", "JPY", "CNY", "CHF", "INR"]); export const invoiceLineItemUnitEnum1 = z.enum(["each", "shipment", "minute", "hour", "day", "mile", "kilometer", "pound", "kilogram"]); 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 proFormaLineItemProvenanceEnum1 = z.enum(["rate_sheet", "ad_hoc", "pro_forma"]); export const proFormaLineItem1 = z.object({schema_version: z.literal(1).optional(), description: z.string().min(1).max(32768), quantity: z.number().gt(0), unit: invoiceLineItemUnitEnum1.nullable().optional(), unit_price: z.number(), currency_code: billingCurrencyCodeEnum1, line_item_type: invoiceLineItemTypeEnum1, awb_number: z.string().nullable().optional(), tax_percentage: z.number().gte(0).nullable().optional(), provenance: proFormaLineItemProvenanceEnum1, rate_sheet_id: z.string().nullable().optional(), created_at_timestamp: z.string().optional()}); export const orderBillingQuoteStatusEnum1 = z.enum(["draft", "accepted", "superseded", "withdrawn"]); export const orderBillingQuote1 = z.object({schema_version: z.literal(1), order_id: z.string(), counterparty_org_id: z.string().nullable().optional(), counterparty_off_chrt_org_data_id: z.string().nullable().optional(), shipper_account_id: z.string().nullable().optional(), quote_type: orderBillingQuoteTypeEnum1, currency_code: billingCurrencyCodeEnum1, line_items: z.array(proFormaLineItem1).optional(), _id: z.string(), owned_by_org_id: z.string(), status: orderBillingQuoteStatusEnum1.optional(), created_by_user_id: z.string(), created_at_timestamp: z.string(), last_edited_by_user_id: z.string(), last_edited_at_timestamp: z.string(), accepted_by_user_id: z.string().nullable().optional(), accepted_at_timestamp: z.string().nullable().optional(), superseded_by_order_billing_quote_id: z.string().nullable().optional(), superseded_at_timestamp: z.string().nullable().optional(), withdrawn_by_user_id: z.string().nullable().optional(), withdrawn_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/quotes/create/v1 */ export const createApiBillingNewQuotesCreateV1 = async (args: CreateApiBillingNewQuotesCreateV1Args, options?: CreateApiBillingNewQuotesCreateV1Options) => { 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/quotes/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(orderBillingQuote1, await res.json()) };