@mindconnect/mindconnect-nodejs
Version:
MindConnect Library for NodeJS (community based)
139 lines (138 loc) • 7.08 kB
TypeScript
/// <reference types="node" />
import * as ajv from "ajv";
import "url-search-params-polyfill";
import { DataSourceConfiguration, Mapping } from "..";
import { AgentAuth } from "./agent-auth";
import { BaseEvent, DataPointValue, IMindConnectConfiguration, TimeStampedDataPoint } from "./mindconnect-models";
import { fileUploadOptionalParameters } from "./sdk/common/multipart-uploader";
/**
* MindConnect Agent implements the V3 of the Mindsphere API.
*
* @export
* @class MindConnectAgent
*/
export declare class MindConnectAgent extends AgentAuth {
ClientId(): string;
/**
*Checkis if the agent is onboarded.
*
* @returns {boolean}
* @memberof MindConnectAgent
*/
IsOnBoarded(): boolean;
/**
* Checks if the agent has a data source configuration
*
* @returns {boolean}
* @memberof MindConnectAgent
*/
HasDataSourceConfiguration(): boolean;
/**
* Checks if the agent has mappings
*
* @returns {boolean}
* @memberof MindConnectAgent
*/
HasDataMappings(): boolean;
/**
* Stores the configuration in the mindsphere.
*
* By default the eTag parameter in the provided configuration is ignored, and the agent just updates the configuration every time the put method is stored
* and automatically increases the eTag.
* This is why its a good idea to check if the configuration was stored before the data was posted. If the ignoreEtag is set to false then the agent just uses
* the eTag which was specified in the configuration. This might throw an "already stored" exception in the mindsphere.
*
* @param {DataSourceConfiguration} dataSourceConfiguration
* @param {boolean} [ignoreEtag=true]
* @returns {Promise<DataSourceConfiguration>}
* @memberof MindConnectAgent
*/
PutDataSourceConfiguration(dataSourceConfiguration: DataSourceConfiguration, ignoreEtag?: boolean): Promise<DataSourceConfiguration>;
GetDataSourceConfiguration(): Promise<DataSourceConfiguration>;
GetDataMappings(): Promise<Array<Mapping>>;
PutDataMappings(mappings: Mapping[]): Promise<boolean>;
/**
* Posts the Events to the Exchange Endpoint
*
* @see: https://developer.mindsphere.io/apis/api-advanced-eventmanagement/index.html
*
* @param {*} events
* @param {Date} [timeStamp=new Date()]
* @param {boolean} [validateModel=true]
* @returns {Promise<boolean>}
* @memberof MindConnectAgent
*/
PostEvent(event: BaseEvent, timeStamp?: Date, validateModel?: boolean): Promise<boolean>;
/**
* Post Data Point Values to the Exchange Endpoint
*
*
* @see: https://developer.mindsphere.io/howto/howto-upload-agent-data/index.html
*
* @param {DataPointValue[]} dataPoints
* @param {Date} [timeStamp=new Date()]
* @param {boolean} [validateModel=true] you can set this to false to speed up the things if your agent is working.
* @returns {Promise<boolean>}
* @memberof MindConnectAgent
*/
PostData(dataPoints: DataPointValue[], timeStamp?: Date, validateModel?: boolean): Promise<boolean>;
BulkPostData(timeStampedDataPoints: TimeStampedDataPoint[], validateModel?: boolean): Promise<boolean>;
/**
* Upload file to MindSphere IOTFileService
*
* * This method is used to upload the files to the MindSphere.
* * It supports standard and multipart upload which can be configured with the [optional.chunk] parameter.
*
* * The method will try to abort the multipart upload if an exception occurs.
* * Multipart Upload is done in following steps:
* * start multipart upload
* * upload in parallel [optional.parallelUploadChunks] the file parts (retrying [optional.retry] times if configured)
* * uploading last chunk.
*
* @param {string} entityId - asset id or agent.ClientId() for agent
* @param {string} filepath - mindsphere file path
* @param {(string | Buffer)} file - local path or Buffer
* @param {fileUploadOptionalParameters} [optional] - optional parameters: enable chunking, define retries etc.
* @param {(number | undefined)}[optional.part] multipart/upload part
* @param {(Date | undefined)} [optional.timestamp] File timestamp in mindsphere.
* @param {(string | undefined)} [optional.description] Description in mindsphere.
* @param {(string | undefined)} [optional.type] Mime type in mindsphere.
* @param {(number | undefined)} [optional.chunkSize] chunkSize. It must be bigger than 5 MB. Default 8 MB.
* @param {(number | undefined)} [optional.retry] Number of retries
* @param {(Function | undefined)} [optional.logFunction] log functgion is called every time a retry happens.
* @param {(Function | undefined)} [optional.verboseFunction] verboseLog function.
* @param {(boolean | undefined)} [optional.chunk] Set to true to enable multipart uploads
* @param {(number | undefined)} [optional.parallelUploads] max paralell uploads for parts (default: 3)
* @param {(number | undefined)} [optional.ifMatch] The etag for the upload.
* @returns {Promise<string>} - md5 hash of the file
*
* @memberOf MindConnectAgent
*
* @example await agent.UploadFile (agent.GetClientId(), "some/mindsphere/path/file.txt", "file.txt");
* @example await agent.UploadFile (agent.GetClientId(), "some/other/path/10MB.bin", "bigFile.bin",{ chunked:true, retry:5 });
*/
UploadFile(entityId: string, filepath: string, file: string | Buffer, optional?: fileUploadOptionalParameters): Promise<string>;
/**
* Uploads the file to mindsphere
*
* @deprecated please use UploadFile method instead this method will probably be removed in version 4.0.0
*
* @param {string} file filename or buffer for upload
* @param {string} fileType mime type (e.g. image/png)
* @param {string} description description of the file
* @param {boolean} [chunk=true] if this is set to false the system will only upload smaller files
* @param {string} [entityId] entityid can be used to define the asset for upload, otherwise the agent is used.
* @param {number} [chunkSize=8 * 1024 * 1024] - at the moment 8MB as per restriction of mindgate
* @param {number} [maxSockets=3] - maxSockets for http Upload - number of parallel multipart uploads
* @returns {Promise<string>} md5 hash of the uploaded file
*
* @memberOf MindConnectAgent
*/
Upload(file: string | Buffer, fileType: string, description: string, chunk?: boolean, entityId?: string, chunkSize?: number, maxSockets?: number, filePath?: string): Promise<string>;
private SendMessage;
GetValidator(): ajv.ValidateFunction;
private _eventValidator?;
GetEventValidator(): ajv.ValidateFunction;
GetMindConnectConfiguration(): IMindConnectConfiguration;
private uploader;
}