import {z} from 'zod' export type DeliveryAppointmentDetails = {end?: string | undefined, start?: string | undefined}; export type PickupAppointmentDetails = {end?: string | undefined, start?: string | undefined}; export type AppointmentDetails = {delivery?: DeliveryAppointmentDetails | undefined, pickup?: PickupAppointmentDetails | undefined}; export type AccessorialCode = 'APTD' | 'APTP' | 'COD' | 'EXPD' | 'FVC' | 'GTD_AM' | 'GTD_NOON' | 'GTD_PM' | 'HAZ' | 'IDL' | 'INBD' | 'IPU' | 'LFTD' | 'LFTP' | 'LTDAD' | 'LTDAP' | 'MARK' | 'MNC' | 'OVR' | 'PPD' | 'PSC' | 'PSH' | 'PSN' | 'REP' | 'RES' | 'SRT' | 'SS' | 'TCS'; export type Currency = 'USD' | 'CAD' | 'MXN' | 'EUR'; export type CountryCode = 'US' | 'CA' | 'MX' | 'AG' | 'BB' | 'BS' | 'BZ' | 'CR' | 'CU' | 'DM' | 'DO' | 'GD' | 'GT' | 'HN' | 'HT' | 'JM' | 'KN' | 'LC' | 'NI' | 'PA' | 'SV' | 'TT' | 'VC' | 'AI' | 'AW' | 'BL' | 'BM' | 'BQ' | 'CW' | 'GL' | 'GP' | 'KY' | 'MF' | 'MQ' | 'MS' | 'PM' | 'PR' | 'SX' | 'TC' | 'UM' | 'VG' | 'VI' | 'AT' | 'BE' | 'BG' | 'CY' | 'CZ' | 'DK' | 'DE' | 'EE' | 'ES' | 'FI' | 'FR' | 'GB' | 'GR' | 'HR' | 'HU' | 'IE' | 'IT' | 'LT' | 'LU' | 'LV' | 'MT' | 'NL' | 'PL' | 'PT' | 'RO' | 'SE' | 'SK' | 'SI' | 'CH' | 'IS' | 'LI' | 'NO' | 'AL' | 'ME' | 'MK' | 'RS' | 'TR' | 'AD' | 'AX' | 'BA' | 'BV' | 'BY' | 'FO' | 'GG' | 'GI' | 'IM' | 'IO' | 'JE' | 'MC' | 'MD' | 'SJ' | 'SM' | 'TF' | 'UA' | 'VA' | 'AE' | 'AF' | 'AM' | 'AZ' | 'BD' | 'BH' | 'BN' | 'BT' | 'CN' | 'GE' | 'HK' | 'ID' | 'IL' | 'IN' | 'IQ' | 'IR' | 'JO' | 'JP' | 'KG' | 'KH' | 'KP' | 'KR' | 'KW' | 'KZ' | 'LA' | 'LB' | 'LK' | 'MM' | 'MN' | 'MO' | 'MV' | 'MY' | 'NP' | 'OM' | 'PH' | 'PK' | 'PS' | 'QA' | 'RU' | 'SA' | 'SG' | 'SY' | 'TH' | 'TJ' | 'TL' | 'TM' | 'TW' | 'UZ' | 'VN' | 'YE' | 'AO' | 'BF' | 'BI' | 'BJ' | 'BW' | 'CD' | 'CF' | 'CG' | 'CI' | 'CM' | 'CV' | 'DJ' | 'DZ' | 'EG' | 'EH' | 'ER' | 'ET' | 'GA' | 'GH' | 'GM' | 'GN' | 'GQ' | 'GW' | 'HM' | 'KE' | 'KM' | 'LR' | 'LS' | 'LY' | 'MA' | 'MG' | 'ML' | 'MR' | 'MU' | 'MW' | 'MZ' | 'NA' | 'NE' | 'NG' | 'RE' | 'RW' | 'SC' | 'SD' | 'SH' | 'SL' | 'SN' | 'SO' | 'SS' | 'ST' | 'SZ' | 'TD' | 'TG' | 'TN' | 'TZ' | 'UG' | 'YT' | 'ZA' | 'ZM' | 'ZW' | 'AR' | 'BO' | 'BR' | 'CL' | 'CO' | 'EC' | 'FK' | 'GF' | 'GS' | 'GY' | 'PE' | 'PY' | 'SR' | 'UY' | 'VE' | 'AS' | 'AU' | 'CC' | 'CK' | 'CX' | 'FJ' | 'FM' | 'GU' | 'KI' | 'MH' | 'MP' | 'NC' | 'NF' | 'NR' | 'NU' | 'NZ' | 'PF' | 'PG' | 'PN' | 'PW' | 'SB' | 'TK' | 'TO' | 'TV' | 'VU' | 'WF' | 'WS' | 'AQ' | 'EL' | 'UK' | 'XK' | 'XS' | 'XI'; export type StateProvinceCode = 'AL' | 'AK' | 'AZ' | 'AR' | 'CA' | 'CO' | 'CT' | 'DC' | 'DE' | 'FL' | 'GA' | 'HI' | 'ID' | 'IL' | 'IN' | 'IA' | 'KS' | 'KY' | 'LA' | 'ME' | 'MD' | 'MA' | 'MI' | 'MN' | 'MS' | 'MO' | 'MT' | 'NE' | 'NV' | 'NH' | 'NJ' | 'NM' | 'NY' | 'NC' | 'ND' | 'OH' | 'OK' | 'OR' | 'PA' | 'PR' | 'RI' | 'SC' | 'SD' | 'TN' | 'TX' | 'UT' | 'VT' | 'VA' | 'WA' | 'WV' | 'WI' | 'WY' | 'AB' | 'BC' | 'MB' | 'NB' | 'NL' | 'NS' | 'NT' | 'NU' | 'ON' | 'PE' | 'QC' | 'SK' | 'YT' | 'CMX' | 'AGU' | 'BCN' | 'BCS' | 'CAM' | 'COA' | 'COL' | 'CHP' | 'CHH' | 'DUR' | 'GUA' | 'GRO' | 'HID' | 'JAL' | 'MEX' | 'MIC' | 'MOR' | 'NAY' | 'NLE' | 'OAX' | 'PUE' | 'QUE' | 'ROO' | 'SLP' | 'SIN' | 'SON' | 'TAB' | 'TAM' | 'TLA' | 'VER' | 'YUC' | 'ZAC'; export type RemitTo = {address1?: string | undefined, address2?: string | undefined, city?: string | undefined, country?: CountryCode | undefined, name?: string | undefined, postalCode?: string | undefined, stateProvince?: StateProvinceCode | undefined}; export type CodTermCode = 'Collect' | 'Prepaid'; export type Cod = {amount?: string | undefined, currency?: Currency | undefined, customerCheckAcceptable?: boolean | undefined, remitTo?: RemitTo | undefined, terms?: CodTermCode | undefined}; export type FullValueCoverageDetails = {currency?: Currency | undefined, monetaryValue?: string | undefined}; export type EmergencyContact = {name?: string | undefined, phone?: string | undefined}; export type HazardousDetailsContact = {emergencyContact?: EmergencyContact | undefined}; export type LimitedAccessCode = 'Airport' | 'Church' | 'Club' | 'Construction' | 'Fair' | 'Farm' | 'Hotel' | 'Mine' | 'Other' | 'Park' | 'Port' | 'School' | 'Secure' | 'Storage' | 'Tradeshow'; export type LimitedAccessType = {destination?: LimitedAccessCode | undefined, origin?: LimitedAccessCode | undefined}; export type MarkDetails = {pieces?: number | undefined}; export type SortAndSegregateDetails = {pieces?: number | undefined}; export type DateWindow = {end?: string | undefined, start?: string | undefined}; export type TimeCriticalDetailsType = 'Deliver On Date' | 'Deliver On or After Date' | 'Deliver By Date' | 'Delivery Window'; export type TimeCriticalDetails = {date?: DateWindow | undefined, type?: TimeCriticalDetailsType | undefined}; export type Accessorial = {appointmentDetails?: AppointmentDetails | undefined, codes?: Array | undefined, cod?: Cod | undefined, fullValueCoverageDetails?: FullValueCoverageDetails | undefined, hazardousDetails?: HazardousDetailsContact | undefined, limitedAccessType?: LimitedAccessType | undefined, markDetails?: MarkDetails | undefined, sortAndSegregateDetails?: SortAndSegregateDetails | undefined, timeCriticalDetails?: TimeCriticalDetails | undefined}; export type RequestorRoleCode = 'Shipper' | 'Consignee' | 'Third Party'; export type Bol = {function?: string | undefined, isTest?: boolean | undefined, requestedPickupDate?: string | undefined, requestorRole?: RequestorRoleCode | undefined, specialInstructions?: string | undefined}; export type BookingEBOLContact = {email?: string | undefined, name?: string | undefined, phone?: string | undefined, phoneExt?: string | undefined}; export type BookingEBOLLocation = {account?: string | undefined, address1?: string | undefined, address2?: string | undefined, city?: string | undefined, country?: CountryCode | undefined, contact?: BookingEBOLContact | undefined, locationId?: string | undefined, name?: string | undefined, postalCode?: string | undefined, stateProvince?: StateProvinceCode | undefined}; export type DimensionsUnit = 'Inches' | 'Centimeters'; export type ClassificationCode = '50' | '55' | '60' | '65' | '70' | '77.5' | '85' | '92.5' | '100' | '110' | '125' | '150' | '175' | '200' | '250' | '300' | '400' | '500'; export type HazardousDetails = {class?: string | undefined, contractNumber?: string | undefined, propername?: string | undefined, packingGroup?: string | undefined, technicalName?: string | undefined, unnaNumber?: string | undefined, weight?: number | undefined}; export type PackagingTypeCode = 'BAG' | 'BAL' | 'BBL' | 'BSK' | 'BIN' | 'BOX' | 'BXT' | 'BCH' | 'BDL' | 'CAB' | 'CAG' | 'CAN' | 'CBY' | 'CAR' | 'CTN' | 'CAS' | 'CSK' | 'CHS' | 'COL' | 'CNT' | 'COR' | 'CRT' | 'CYL' | 'DRM' | 'DBK' | 'ENV' | 'FIR' | 'GLD' | 'HPR' | 'HGH' | 'HRB' | 'INT' | 'JAR' | 'JCN' | 'KEG' | 'KIT' | 'LIF' | 'LBK' | 'LSE' | 'MXD' | 'OTH' | 'PKG' | 'PCK' | 'PAL' | 'PAT' | 'PCS' | 'PLN' | 'RCK' | 'REL' | 'ROL' | 'SKD' | 'SLP' | 'SPL' | 'TNK' | 'TBN' | 'TRY' | 'TRU' | 'TRK' | 'TUB' | 'TBE' | 'UNT' | 'VPK' | 'WRP'; export type BookingEBOLWeightUnit = 'Pounds' | 'Kilograms'; export type BookingLineItem = {classification?: ClassificationCode | undefined, description?: string | undefined, hazardous?: boolean | undefined, hazardousDescription?: string | undefined, hazardousDetails?: HazardousDetails | undefined, nmfc?: string | undefined, nmfcSub?: string | undefined, pieces?: number | undefined, packagingType?: PackagingTypeCode | undefined, weight?: number | undefined, weightUnit?: BookingEBOLWeightUnit | undefined}; export type HandlingUnitTypeCode = 'BAG' | 'BAL' | 'BBL' | 'BSK' | 'BIN' | 'BOX' | 'BXT' | 'BCH' | 'BDL' | 'CAB' | 'CAG' | 'CAN' | 'CBY' | 'CAR' | 'CTN' | 'CAS' | 'CSK' | 'CHS' | 'COL' | 'CNT' | 'COR' | 'CRT' | 'CYL' | 'DRM' | 'DBK' | 'ENV' | 'FIR' | 'GLD' | 'HPR' | 'HGH' | 'HRB' | 'INT' | 'JAR' | 'JCN' | 'KEG' | 'KIT' | 'LIF' | 'LBK' | 'LSE' | 'MXD' | 'OTH' | 'PKG' | 'PCK' | 'PAL' | 'PAT' | 'PCS' | 'PLN' | 'RCK' | 'REL' | 'ROL' | 'SKD' | 'SLP' | 'SPL' | 'TNK' | 'TBN' | 'TRY' | 'TRU' | 'TRK' | 'TUB' | 'TBE' | 'UNT' | 'VPK' | 'WRP'; export type BookingEBOLHandlingUnit = {count?: number | undefined, dimensionsUnit?: DimensionsUnit | undefined, height?: number | undefined, length?: number | undefined, lineItems?: Array | undefined, stackable?: boolean | undefined, type?: HandlingUnitTypeCode | undefined, tareWeight?: number | undefined, weight?: number | undefined, weightUnit?: BookingEBOLWeightUnit | undefined, width?: number | undefined}; export type LineItemLayoutType = 'Nested' | 'Stacked'; export type Commodities = {handlingUnits?: Array | undefined, lineItemLayout?: LineItemLayoutType | undefined}; export type CustomsBrokerType = 'Import' | 'Export'; export type CustomsBroker = {address1?: string | undefined, address2?: string | undefined, city?: string | undefined, country?: CountryCode | undefined, contact?: BookingEBOLContact | undefined, name?: string | undefined, postalCode?: string | undefined, stateProvince?: StateProvinceCode | undefined, type?: CustomsBrokerType | undefined}; export type Email = {addresses?: Array | undefined, includeBol?: boolean | undefined, includeLabels?: boolean | undefined}; export type ShippingLabelsFormat = 'Avery' | 'Letter' | 'Zebra'; export type ShippingLabels = {format?: ShippingLabelsFormat | undefined, position?: number | undefined, quantity?: number | undefined}; export type Images = {email?: Email | undefined, includeBol?: boolean | undefined, includeShippingLabels?: boolean | undefined, shippingLabels?: ShippingLabels | undefined}; export type Notification = {email?: string | undefined, phoneNumber?: string | undefined}; export type PaymentTerms = 'Prepaid' | 'Collect' | 'Third Party'; export type Payment = {terms?: PaymentTerms | undefined}; export type AdditionalReference = {name?: string | undefined, value?: string | undefined}; export type Po = {additionalShipperInfo?: string | undefined, number?: string | undefined, pieces?: number | undefined, palletized?: boolean | undefined, weight?: number | undefined}; export type ReferenceNumbers = {additionalReferences?: Array | undefined, bol?: Array | undefined, masterBol?: string | undefined, pro?: string | undefined, po?: Array | undefined, quoteId?: string | undefined, shipmentId?: string | undefined}; export type ShipmentTotalsDimensionsUnitCode = 'Feet' | 'Meters'; export type ShipmentTotals = {cube?: number | undefined, cubeDimensionsUnit?: ShipmentTotalsDimensionsUnitCode | undefined, currency?: string | undefined, dimensionsUnit?: DimensionsUnit | undefined, declaredValue?: number | undefined, grossWeight?: number | undefined, handlingUnits?: number | undefined, linearLength?: number | undefined, netWeight?: number | undefined, weightUnit?: BookingEBOLWeightUnit | undefined}; export type RequestEbol = {accessorials?: Accessorial | undefined, bol?: Bol | undefined, billTo?: BookingEBOLLocation | undefined, commodities?: Commodities | undefined, customsBroker?: CustomsBroker | undefined, destination?: BookingEBOLLocation | undefined, images?: Images | undefined, notifications?: Array | undefined, origin?: BookingEBOLLocation | undefined, payment?: Payment | undefined, referenceNumbers?: ReferenceNumbers | undefined, shipmentTotals?: ShipmentTotals | undefined, version?: string | undefined}; export type CreateApiServicesBookingV1LtlElectronicBolsArgs = {body: RequestEbol}; export type CreateApiServicesBookingV1LtlElectronicBolsOptions = {baseUrl?: string | undefined, oAuth2?: string | undefined, fetch?: typeof fetch | undefined}; export const ebolImages = z.object({bol: z.string().optional(), shippingLabels: z.string().optional()}); export const messageStatusInformation = z.object({code: z.string().optional(), message: z.string().optional(), type: z.string().optional()}); export const messageStatus = z.enum(["PASS", "FAIL", "WARNING"]); export const ebolMessageStatus = z.object({code: z.string().optional(), information: z.array(messageStatusInformation).optional(), message: z.string().optional(), resolution: z.string().optional(), status: messageStatus.optional()}); export const ebolReferenceNumbers = z.object({pro: z.string().optional(), shipmentConfirmationNumber: z.string().optional()}); export const ebol = z.object({images: ebolImages.optional(), messageStatus: ebolMessageStatus.optional(), referenceNumbers: ebolReferenceNumbers.optional(), transactionDate: z.string().optional(), version: 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 }; /** * Create Electronic Bol * * POST /services/booking/v1/ltl/electronic-bols */ export const createApiServicesBookingV1LtlElectronicBols = async (args: CreateApiServicesBookingV1LtlElectronicBolsArgs, options?: CreateApiServicesBookingV1LtlElectronicBolsOptions) => { 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(/\/+$/, '')}/services/booking/v1/ltl/electronic-bols${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(ebol, await res.json()) };