import {z} from 'zod' export type GetApiCalldataLogCallDataArgs = {CampaignId: number, MediaId: number, EventDate: string, ActionTrackerId: number, CallProvider: string, CallSessionId: string, CallerId: string, CalledPhoneNumber: string, CallDuration: number, TalkDuration: number, AdId?: number | undefined, CallStatus?: ('UNKNOWN_CALLERID' | 'CONGESTION' | 'INCOMPLETE' | 'CANCEL' | 'IVR_DROPOFF' | 'NO_TRANSFER_ATTEMPT' | 'ANSWER' | 'FAILURE') | undefined, CallerPhoneNumberCountry?: string | undefined, CalledPhoneNumberCountry?: string | undefined, SubId1?: string | undefined, SubId2?: string | undefined, SubId3?: string | undefined, ClickId?: string | undefined, City?: string | undefined, Region?: string | undefined, Zip?: number | undefined, RepeatCaller?: string | undefined, PhoneType?: string | undefined, CallRecording?: string | undefined, IvrDuration?: number | undefined, Keypresses?: string | undefined, Key1?: string | undefined, Key2?: string | undefined, Key3?: string | undefined, Key4?: string | undefined, TrafficSource?: string | undefined, OptInSms?: string | undefined, UserAgent?: string | undefined, DispositionName?: string | undefined, SaleAmount?: number | undefined, ReferenceId?: number | undefined, CustomConversionEvent1Name?: string | undefined, CustomConversionEvent1Value?: string | undefined, VendorEventId?: string | undefined, PromoNumberDescription?: string | undefined, CustomCallEvent1Name?: string | undefined, CustomCallEvent1Value?: string | undefined}; export type GetApiCalldataLogCallDataOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const statusResponse = z.object({Status: 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 }; /** * Log Call Data via GET * * GET /calldata/logCallData */ export const getApiCalldataLogCallData = async (args: GetApiCalldataLogCallDataArgs, options?: GetApiCalldataLogCallDataOptions) => { const {baseUrl = "https://api.impact.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.CampaignId != null) query.append("CampaignId", String(args.CampaignId)) if (args.MediaId != null) query.append("MediaId", String(args.MediaId)) if (args.EventDate != null) query.append("EventDate", String(args.EventDate)) if (args.ActionTrackerId != null) query.append("ActionTrackerId", String(args.ActionTrackerId)) if (args.CallProvider != null) query.append("CallProvider", String(args.CallProvider)) if (args.CallSessionId != null) query.append("CallSessionId", String(args.CallSessionId)) if (args.CallerId != null) query.append("CallerId", String(args.CallerId)) if (args.CalledPhoneNumber != null) query.append("CalledPhoneNumber", String(args.CalledPhoneNumber)) if (args.CallDuration != null) query.append("CallDuration", String(args.CallDuration)) if (args.TalkDuration != null) query.append("TalkDuration", String(args.TalkDuration)) if (args.AdId != null) query.append("AdId", String(args.AdId)) if (args.CallStatus != null) query.append("CallStatus", String(args.CallStatus)) if (args.CallerPhoneNumberCountry != null) query.append("CallerPhoneNumberCountry", String(args.CallerPhoneNumberCountry)) if (args.CalledPhoneNumberCountry != null) query.append("CalledPhoneNumberCountry", String(args.CalledPhoneNumberCountry)) if (args.SubId1 != null) query.append("SubId1", String(args.SubId1)) if (args.SubId2 != null) query.append("SubId2", String(args.SubId2)) if (args.SubId3 != null) query.append("SubId3", String(args.SubId3)) if (args.ClickId != null) query.append("ClickId", String(args.ClickId)) if (args.City != null) query.append("City", String(args.City)) if (args.Region != null) query.append("Region", String(args.Region)) if (args.Zip != null) query.append("Zip", String(args.Zip)) if (args.RepeatCaller != null) query.append("RepeatCaller", String(args.RepeatCaller)) if (args.PhoneType != null) query.append("PhoneType", String(args.PhoneType)) if (args.CallRecording != null) query.append("CallRecording", String(args.CallRecording)) if (args.IvrDuration != null) query.append("IvrDuration", String(args.IvrDuration)) if (args.Keypresses != null) query.append("Keypresses", String(args.Keypresses)) if (args.Key1 != null) query.append("Key1", String(args.Key1)) if (args.Key2 != null) query.append("Key2", String(args.Key2)) if (args.Key3 != null) query.append("Key3", String(args.Key3)) if (args.Key4 != null) query.append("Key4", String(args.Key4)) if (args.TrafficSource != null) query.append("TrafficSource", String(args.TrafficSource)) if (args.OptInSms != null) query.append("OptInSms", String(args.OptInSms)) if (args.UserAgent != null) query.append("UserAgent", String(args.UserAgent)) if (args.DispositionName != null) query.append("DispositionName", String(args.DispositionName)) if (args.SaleAmount != null) query.append("SaleAmount", String(args.SaleAmount)) if (args.ReferenceId != null) query.append("ReferenceId", String(args.ReferenceId)) if (args.CustomConversionEvent1Name != null) query.append("CustomConversionEvent1Name", String(args.CustomConversionEvent1Name)) if (args.CustomConversionEvent1Value != null) query.append("CustomConversionEvent1Value", String(args.CustomConversionEvent1Value)) if (args.VendorEventId != null) query.append("VendorEventId", String(args.VendorEventId)) if (args.PromoNumberDescription != null) query.append("PromoNumberDescription", String(args.PromoNumberDescription)) if (args.CustomCallEvent1Name != null) query.append("CustomCallEvent1Name", String(args.CustomCallEvent1Name)) if (args.CustomCallEvent1Value != null) query.append("CustomCallEvent1Value", String(args.CustomCallEvent1Value)) const url = `${baseUrl.replace(/\/+$/, '')}/calldata/logCallData${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(statusResponse, await res.json()) };