UNPKG

@objectiv/transport-xhr

Version:

A TrackerTransport based on XMLHttpRequest API

34 lines (30 loc) 1.19 kB
import { TrackerEvent, TrackerTransportInterface, TrackerInterface, NonEmptyArray, TransportableEvent } from '@objectiv/tracker-core'; /** * The default XMLHttpRequest function implementation. */ declare const defaultXHRFunction: ({ endpoint, events, }: { endpoint: string; events: [TrackerEvent, ...TrackerEvent[]]; }) => Promise<unknown>; /** * The configuration of the XHRTransport class */ declare type XHRTransportConfig = { /** * Optional. Override the default XMLHttpRequestFunction implementation with a custom one. */ xmlHttpRequestFunction?: typeof defaultXHRFunction; }; /** * A TrackerTransport based on XMLHttpRequest. Sends event to the specified Collector endpoint. * Optionally supports specifying a custom `xmlHttpRequestFunction`. */ declare class XHRTransport implements TrackerTransportInterface { readonly transportName = "XHRTransport"; xmlHttpRequestFunction: typeof defaultXHRFunction; endpoint?: string; initialize(tracker: TrackerInterface): void; handle(...args: NonEmptyArray<TransportableEvent>): Promise<any>; isUsable(): boolean; } export { XHRTransport, XHRTransportConfig, defaultXHRFunction };