export type CommunicationDirection = 'INBOUND' | 'OUTBOUND'; export type EmailParticipant = {name: string, address: string}; export type EmailParticipants = {from: EmailParticipant, to: Array, cc: Array}; export type EmailData = {direction: CommunicationDirection, attachmentCount: number, participants: EmailParticipants, subject?: string | undefined, summary?: string | undefined, classification?: string | undefined}; export type SentEmailEvent = {id: string, workflow: 'TRACK_AND_TRACE' | 'CARRIER_SUPPORT' | 'POD_COLLECTION' | 'LOAD_BUILDING' | 'CARRIER_SELECTION' | 'SCHEDULING' | 'CUSTOMER_SUPPORT' | 'null' | null, occurredAt: string, loadNumber: string | null, customerLoadInternalId: string | null, eventType: 'SENT_EMAIL', data: EmailData}; export type CreateApiSENTEMAILArgs = {body: SentEmailEvent}; export type CreateApiSENTEMAILOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; /** * Sent Email * * POST /SENT_EMAIL */ export const createApiSENTEMAIL = async (args: CreateApiSENTEMAILArgs, options: CreateApiSENTEMAILOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/SENT_EMAIL${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 };