import * as request from "superagent"; import { SuperAgentStatic, SuperAgentRequest, Response } from "superagent"; export declare type RequestHeaders = { [header: string]: string; }; export declare type RequestHeadersHandler = (headers: RequestHeaders) => RequestHeaders; export declare type ConfigureAgentHandler = (agent: SuperAgentStatic) => SuperAgentStatic; export declare type ConfigureRequestHandler = (agent: SuperAgentRequest) => SuperAgentRequest; export declare type CallbackHandler = (err: any, res?: request.Response) => void; export declare type Location = { 'latitude'?: number; 'longitude'?: number; }; export declare type OrderTemplate = { 'description'?: string; 'id'?: string; 'isTemplate'?: boolean; 'location'?: Location; }; export declare type Order = { 'description'?: string; 'id'?: string; }; export declare type Tracking = { 'id'?: number; 'startedAt'?: string; 'deviceId'?: string; 'orderIds'?: Array; 'stoppedAt'?: string; 'status'?: TrackingStatus; 'target'?: Location; }; export declare type TrackingStatus = "ONGOING" | "STOPPED" | "ARRIVED"; export declare type Logger = { log: (line: string) => any; }; export interface ResponseWithBody extends Response { status: S; body: T; } export declare type QueryParameters = { [param: string]: any; }; export interface CommonRequestOptions { $queryParameters?: QueryParameters; $domain?: string; $path?: string | ((path: string) => string); $retries?: number; $timeout?: number; $deadline?: number; } /** * API for the communication between DTV app and server. * @class DTVApi * @param {(string)} [domainOrOptions] - The project domain. */ export declare class DTVApi { private logger?; private domain; private errorHandlers; private requestHeadersHandler?; private configureAgentHandler?; private configureRequestHandler?; constructor(domain?: string, logger?: Logger | undefined); getDomain(): string; addErrorHandler(handler: CallbackHandler): void; setRequestHeadersHandler(handler: RequestHeadersHandler): void; setConfigureAgentHandler(handler: ConfigureAgentHandler): void; setConfigureRequestHandler(handler: ConfigureRequestHandler): void; private request; private convertParameterCollectionFormat; getOrderURL(parameters: { 'orderId': string; } & CommonRequestOptions): string; /** * Returns the order with the given ID. Under some circumstances (if the given order id is an template id) it creates a new order based off this ID and returns the created order. * @method * @name DTVApi#getOrder * @param {string} orderId - ID of the order to be returned */ getOrder(parameters: { 'orderId': string; } & CommonRequestOptions): Promise | ResponseWithBody<404, void>>; addOrderURL(parameters: { 'orderData': { 'orderTemplate': OrderTemplate; } & { [key: string]: any; }; } & CommonRequestOptions): string; /** * Creates a new order and persists it to the database * @method * @name DTVApi#addOrder * @param {} orderData - API for the communication between DTV app and server. */ addOrder(parameters: { 'orderData': { 'orderTemplate': OrderTemplate; } & { [key: string]: any; }; } & CommonRequestOptions): Promise | ResponseWithBody<409, void>>; sendLocationURL(parameters: { 'locationData': Array<{ 'trackingId': number; 'location': Location; } & { [key: string]: any; }>; } & CommonRequestOptions): string; /** * Sends the current position for the truck with the given order(s) to the system. * @method * @name DTVApi#sendLocation * @param {} locationData - API for the communication between DTV app and server. */ sendLocation(parameters: { 'locationData': Array<{ 'trackingId': number; 'location': Location; } & { [key: string]: any; }>; } & CommonRequestOptions): Promise | ResponseWithBody<400, void> | ResponseWithBody<409, void>>; startTrackingURL(parameters: { 'trackingData': Tracking; } & CommonRequestOptions): string; /** * Starts new tracking and creates corresponding truck-trip. * @method * @name DTVApi#startTracking * @param {} trackingData - API for the communication between DTV app and server. */ startTracking(parameters: { 'trackingData': Tracking; } & CommonRequestOptions): Promise>; stopTrackingURL(parameters: { 'trackingId': number; 'stopData': { 'status'?: TrackingStatus; }; } & CommonRequestOptions): string; /** * Stops the tracking and saves the stopped date * @method * @name DTVApi#stopTracking * @param {integer} trackingId - API for the communication between DTV app and server. * @param {} stopData - API for the communication between DTV app and server. */ stopTracking(parameters: { 'trackingId': number; 'stopData': { 'status'?: TrackingStatus; }; } & CommonRequestOptions): Promise>; } export default DTVApi;