import {z} from 'zod' export type CapacityProviderIdentifier = {type?: ('SCAC' | 'DOT_NUMBER' | 'MC_NUMBER' | 'P44_EU' | 'SYSTEM' | 'P44_GLOBAL' | 'VAT') | undefined, value?: string | undefined}; export type TruckloadEquipmentIdentifier = {shouldDelete?: boolean | undefined, type?: ('MOBILE_PHONE_NUMBER' | 'VEHICLE_ID' | 'LICENSE_PLATE' | 'SENSITECH_DEVICE_ID' | 'TIVE_DEVICE_ID') | undefined, value?: string | undefined}; export type TruckloadVendorCharge = {amount?: number | undefined, description?: string | undefined, vendorCode?: ('LH' | 'FSC') | undefined}; export type TruckloadRateQuoteDetail = {charges?: Array | undefined, subtotal?: number | undefined, total?: number | undefined}; export type TruckloadTenderTrackingShipmentIdentifier = {type?: ('BILL_OF_LADING' | 'ORDER' | 'TRACKING_IDENTIFIER') | undefined, value?: string | undefined}; export type TruckloadCapacityProviderTenderRateQuote = {capacityProviderOfferIdentifier?: string | undefined, carrierIdentifier?: CapacityProviderIdentifier | undefined, currency?: ('USD' | 'CAD' | 'MXN' | 'EUR') | undefined, equipmentIdentifiers?: Array | undefined, offerExpirationDateTime?: string | undefined, rateQuoteDetail?: TruckloadRateQuoteDetail | undefined, trackingShipmentIdentifiers?: Array | undefined}; export type CreateApiApiV4CapacityprovidersTlTendersTenderIdentifierQuotesArgs = {tenderIdentifier: string, body: TruckloadCapacityProviderTenderRateQuote}; export type CreateApiApiV4CapacityprovidersTlTendersTenderIdentifierQuotesOptions = {baseUrl?: string | undefined, oAuth2?: string | undefined, fetch?: typeof fetch | undefined}; export const message = z.object({diagnostic: z.string().optional(), message: z.string().optional(), severity: z.enum(["ERROR", "WARNING", "INFO"]).optional(), source: z.enum(["SYSTEM", "CAPACITY_PROVIDER"]).optional()}); export const capacityProviderIdentifier = z.object({type: z.enum(["SCAC", "DOT_NUMBER", "MC_NUMBER", "P44_EU", "SYSTEM", "P44_GLOBAL", "VAT"]).optional(), value: z.string().optional()}); export const truckloadEquipmentIdentifier = z.object({shouldDelete: z.boolean().optional(), type: z.enum(["MOBILE_PHONE_NUMBER", "VEHICLE_ID", "LICENSE_PLATE", "SENSITECH_DEVICE_ID", "TIVE_DEVICE_ID"]).optional(), value: z.string().optional()}); export const truckloadVendorCharge = z.object({amount: z.number().optional(), description: z.string().optional(), vendorCode: z.enum(["LH", "FSC"]).optional()}); export const truckloadRateQuoteDetail = z.object({charges: z.array(truckloadVendorCharge).optional(), subtotal: z.number().optional(), total: z.number().optional()}); export const truckloadTenderTrackingShipmentIdentifier = z.object({type: z.enum(["BILL_OF_LADING", "ORDER", "TRACKING_IDENTIFIER"]).optional(), value: z.string().optional()}); export const truckloadCapacityProviderTenderRateQuote = z.object({capacityProviderOfferIdentifier: z.string().optional(), carrierIdentifier: capacityProviderIdentifier.optional(), currency: z.enum(["USD", "CAD", "MXN", "EUR"]).optional(), equipmentIdentifiers: z.array(truckloadEquipmentIdentifier).optional(), offerExpirationDateTime: z.string().optional(), rateQuoteDetail: truckloadRateQuoteDetail.optional(), trackingShipmentIdentifiers: z.array(truckloadTenderTrackingShipmentIdentifier).optional()}); export const truckloadCapacityProviderTenderRateQuoteConfirmation = z.object({infoMessages: z.array(message).optional(), rateQuote: truckloadCapacityProviderTenderRateQuote.optional(), tenderIdentifier: z.string().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 }; /** * Provide a rate quote in response to a shipment tender. * * POST /api/v4/capacityproviders/tl/tenders/{tenderIdentifier}/quotes */ export const createApiApiV4CapacityprovidersTlTendersTenderIdentifierQuotes = async (args: CreateApiApiV4CapacityprovidersTlTendersTenderIdentifierQuotesArgs, options?: CreateApiApiV4CapacityprovidersTlTendersTenderIdentifierQuotesOptions) => { const {baseUrl = "https://na12.api.project44.com", fetch: fetchFn = fetch, oAuth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (oAuth2 !== undefined) headers.set('authorization', `Bearer ${oAuth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v4/capacityproviders/tl/tenders/${encodeURIComponent(String(args.tenderIdentifier))}/quotes${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(truckloadCapacityProviderTenderRateQuoteConfirmation, await res.json()) };