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 TruckloadShipmentIdentifier = {type?: ('BILL_OF_LADING' | 'ORDER') | undefined, value?: string | undefined}; export type ZonedDateTimeWindow = {endDateTime?: string | undefined, localTimeZoneIdentifier?: string | undefined, startDateTime?: string | undefined}; export type GeoCoordinates = {latitude?: number | undefined, longitude?: number | undefined}; 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 Address = {addressLines?: Array | undefined, city?: string | undefined, country?: CountryCode | undefined, postalCode?: string | undefined, state?: string | undefined}; export type Contact = {companyName?: string | undefined, contactName?: string | undefined, email?: string | undefined, faxNumber?: string | undefined, faxNumberCountryCode?: string | undefined, phoneNumber?: string | undefined, phoneNumber2?: string | undefined, phoneNumber2CountryCode?: string | undefined, phoneNumberCountryCode?: string | undefined}; export type Location = {address?: Address | undefined, contact?: Contact | undefined}; export type TruckloadShipmentIntermediateStop = {appointmentWindow?: ZonedDateTimeWindow | undefined, geoCoordinates?: GeoCoordinates | undefined, location?: Location | undefined, stopName?: string | undefined}; export type TruckloadIntermediateStopsUpdate = {carrierIdentifier?: CapacityProviderIdentifier | undefined, customerAccountNumber?: string | undefined, shipmentIdentifiers?: Array | undefined, shipmentStops?: Array | undefined}; export type CreateApiApiV4CapacityprovidersTlShipmentsIntermediateStopsArgs = {body: TruckloadIntermediateStopsUpdate}; export type CreateApiApiV4CapacityprovidersTlShipmentsIntermediateStopsOptions = {baseUrl?: string | undefined, oAuth2?: string | undefined, fetch?: typeof fetch | undefined}; 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 truckloadShipmentIdentifier = z.object({type: z.enum(["BILL_OF_LADING", "ORDER"]).optional(), value: z.string().optional()}); export const zonedDateTimeWindow = z.object({endDateTime: z.string().optional(), localTimeZoneIdentifier: z.string().optional(), startDateTime: z.string().optional()}); export const geoCoordinates = z.object({latitude: z.number().optional(), longitude: z.number().optional()}); export const countryCode = z.enum(["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 const address = z.object({addressLines: z.array(z.string()).optional(), city: z.string().optional(), country: countryCode.optional(), postalCode: z.string().optional(), state: z.string().optional()}); export const contact = z.object({companyName: z.string().optional(), contactName: z.string().optional(), email: z.string().optional(), faxNumber: z.string().optional(), faxNumberCountryCode: z.string().optional(), phoneNumber: z.string().optional(), phoneNumber2: z.string().optional(), phoneNumber2CountryCode: z.string().optional(), phoneNumberCountryCode: z.string().optional()}); export const location = z.object({address: address.optional(), contact: contact.optional()}); export const truckloadShipmentIntermediateStop = z.object({appointmentWindow: zonedDateTimeWindow.optional(), geoCoordinates: geoCoordinates.optional(), location: location.optional(), stopName: z.string().optional()}); export const truckloadIntermediateStopsUpdate = z.object({carrierIdentifier: capacityProviderIdentifier.optional(), customerAccountNumber: z.string().optional(), shipmentIdentifiers: z.array(truckloadShipmentIdentifier).optional(), shipmentStops: z.array(truckloadShipmentIntermediateStop).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 }; /** * postIntermediateStops * * POST /api/v4/capacityproviders/tl/shipments/intermediateStops */ export const createApiApiV4CapacityprovidersTlShipmentsIntermediateStops = async (args: CreateApiApiV4CapacityprovidersTlShipmentsIntermediateStopsArgs, options?: CreateApiApiV4CapacityprovidersTlShipmentsIntermediateStopsOptions) => { 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/shipments/intermediateStops${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(truckloadIntermediateStopsUpdate, await res.json()) };