import {z} from 'zod' export type GetApiBillingNewQuotesListV1Args = {order_id: string}; export type GetApiBillingNewQuotesListV1Options = {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 getApiBillingNewQuotesListV1Response = z.array(orderBillingQuote1); 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/quotes/list/v1 */ export const getApiBillingNewQuotesListV1 = async (args: GetApiBillingNewQuotesListV1Args, options?: GetApiBillingNewQuotesListV1Options) => { 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.order_id != null) query.append("order_id", String(args.order_id)) if (HTTPBearer !== undefined) headers.set('authorization', `Bearer ${HTTPBearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/billing_new/quotes/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(getApiBillingNewQuotesListV1Response, await res.json()) };