export type MessageDeliveryStatus = 'accepted' | 'pending' | 'sent' | 'delivered' | 'undelivered' | 'expired' | 'rejected' | 'dlr_expired'; export type GetApiV3MessagesAllArgs = {sent_after?: string | undefined, sent_before?: string | undefined, type: string, from?: string | undefined, to?: string | undefined, status?: MessageDeliveryStatus | undefined, tag?: string | undefined, message_type?: ('sms' | 'mms') | undefined}; export type GetApiV3MessagesAllOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; /** * Export messages * * GET /v3/messages/all */ export const getApiV3MessagesAll = async (args: GetApiV3MessagesAllArgs, options?: GetApiV3MessagesAllOptions) => { const {baseUrl = "https://api.wavix.com", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/x-ndjson") if (args.sent_after != null) query.append("sent_after", String(args.sent_after)) if (args.sent_before != null) query.append("sent_before", String(args.sent_before)) if (args.type != null) query.append("type", String(args.type)) if (args.from != null) query.append("from", String(args.from)) if (args.to != null) query.append("to", String(args.to)) if (args.status != null) query.append("status", String(args.status)) if (args.tag != null) query.append("tag", String(args.tag)) if (args.message_type != null) query.append("message_type", String(args.message_type)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v3/messages/all${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 res.blob() };