export type TrackingEventContact = {id?: string | undefined, name?: string | undefined, phone?: string | undefined, phoneExtension?: string | undefined, email?: string | undefined}; export type TrackingEvent = {nextSequence?: number | undefined, nextEtaUtc?: string | undefined, eventType: 'DELAYED' | 'INFO' | 'PICKED_UP' | 'PING' | 'COVERED' | 'DISPATCHED', eventSource: '4KITES' | 'CARRIER_API' | 'HIGHWAY' | 'MACROPOINT' | 'P44' | 'PHONE_EMAIL' | 'SMC3' | 'TEXT' | 'TMS' | 'TRUCKER_TOOLS' | 'OTHER', eventUtc: string, isLocalTime?: boolean | undefined, city?: string | undefined, country?: string | undefined, stateOrProvince?: string | undefined, postalCode?: string | undefined, latitude?: number | undefined, longitude?: number | undefined, temperatureF?: number | undefined, notes?: string | undefined, dispatcher?: TrackingEventContact | undefined, driver?: TrackingEventContact | undefined}; export type TrackingEventRequest = {loadNumber: string, trackingEvent: TrackingEvent}; export type CreateApiV2LoadsTrackingArgs = {body: TrackingEventRequest}; export type CreateApiV2LoadsTrackingOptions = {baseUrl?: string | undefined, httpBasic?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; /** * Add a tracking event * * POST /v2/loads/tracking */ export const createApiV2LoadsTracking = async (args: CreateApiV2LoadsTrackingArgs, options?: CreateApiV2LoadsTrackingOptions) => { const {baseUrl = "https://api.prod.goaugment.com", fetch: fetchFn = fetch, httpBasic} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (httpBasic !== undefined) headers.set('authorization', `Basic ${btoa(`${httpBasic.username}:${httpBasic.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/v2/loads/tracking${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 undefined };