@mindconnect/mindconnect-nodejs
Version:
NodeJS Library for Siemens Insights Hub Connectivity - TypeScript SDK for Insights Hub and Industrial IoT - Command Line Interface - Insights Hub Development Proxy (Siemens Insights Hub was formerly known as MindSphere)
218 lines • 8.13 kB
JavaScript
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.CommandingClient = void 0;
const utils_1 = require("../../utils");
const sdk_client_1 = require("../common/sdk-client");
/**
* Commanding is a service that provides the APIs to manage delivery jobs to send commands to MQTT clients for execution.
*
* Limitations
* The maximum number of clients to which a command can be published is 20.
* Command data size is restricted to 4kB.
*
* @export
* @class CommandingClient
* @extends {SdkClient}
*/
class CommandingClient extends sdk_client_1.SdkClient {
constructor() {
super(...arguments);
this._baseUrl = "/api/commanding/v3";
}
/**
* Creates a delivery job.
*
* A delivery job is used to send an MQTT command to a list of clients for execution.
* The following validations are performed when a delivery job is created.
* The provided clients must be valid.
* * Maximum number of clients can be 20 in a delivery job.
* * Data size is restricted to 4kB.
*
* @param {CommandingModels.JobRequest} jobRequest Object describing the Job request
* @returns {Promise<CommandingModels.Job>}
*
* @memberOf CommandingClient
*/
PostDeliveryJob(jobRequest) {
return __awaiter(this, void 0, void 0, function* () {
const result = yield this.HttpAction({
verb: "POST",
gateway: this.GetGateway(),
authorization: yield this.GetToken(),
baseUrl: `${this._baseUrl}/deliveryJobs`,
body: jobRequest,
});
return result;
});
}
/**
*
* Get all delivery jobs
*
* @param {{
* filter?: string;
* page?: number;
* size?: number;
* }} [params]
* @returns {Promise<CommandingModels.DeliveryJobsResponse>}
*
* @param params.filter
* JSON string describing filter operations performed on delivery jobs to be returned. The following fields and operations are supported
* Filter
* name: eq, in, endsWith,startsWith, contains
* createdAt: before, after, between
*
* @example
* // Unencoded example filter value to fetch all delivery jobs for name "test"
* { "name": "test" }
* { "name": { "startsWith" : "test" }}
*
* @example
* // Unencoded example filter value to fetch all delivery jobs based on createdAt:
* {"createdAt": {"between": "[2021-11-06T13:46:00Z, 2021-11-11T13:46:00Z]"}}
* {"createdAt": {"after": "2021-11-06T13:46:00Z"}}
* {"createdAt": {"before": "2021-11-06T13:46:00Z"}}
*
*
* @param params.size
* The maximum number of elements returned in one page.
* Default value is 20.
* Maximum allowed value is 100.
*
*
* @param params.page
* The zero-based index of the page to be returned.
* Default value - 0.
*
* @memberOf CommandingClient
*/
GetDeliveryJobs(params) {
return __awaiter(this, void 0, void 0, function* () {
const result = yield this.HttpAction({
verb: "GET",
gateway: this.GetGateway(),
authorization: yield this.GetToken(),
baseUrl: `${this._baseUrl}/deliveryJobs?${(0, utils_1.toQueryString)(params)}`,
});
return result;
});
}
/**
* Get the delivery job by Id
*
* @param {string} jobid
* @returns {Promise<CommandingModels.Job>}
*
* @memberOf CommandingClient
*/
GetDeliveryJob(jobid) {
return __awaiter(this, void 0, void 0, function* () {
const result = yield this.HttpAction({
verb: "GET",
gateway: this.GetGateway(),
authorization: yield this.GetToken(),
baseUrl: `${this._baseUrl}/deliveryJobs/${jobid}`,
});
return result;
});
}
/**
* Delete the job and its related commands.
*
* @param {string} jobid
*
* @memberOf CommandingClient
*/
DeleteDeliveryJob(jobid) {
return __awaiter(this, void 0, void 0, function* () {
yield this.HttpAction({
verb: "DELETE",
gateway: this.GetGateway(),
authorization: yield this.GetToken(),
baseUrl: `${this._baseUrl}/deliveryJobs/${jobid}`,
noResponse: true,
});
});
}
/**
*
* Get all the commands for the given delivery job Id.
*
* @param {string} id
* @param {{filter?: string; page?: number; size?: number}} [params]
* @returns {Promise<CommandingModels.CommandsResponse>}
*
* @param params.filter
* JSON string describing filter operations performed on commands associated with a delivery job to be returned.
* The following fields and operations are supported
*
* clientId: eq, in, endsWith,startsWith, contains
* status: eq, in, endsWith,startsWith, contains
* updatedAt: before, after, between
*
* @example
* // Unencoded example filter value to fetch all commands associated with delivery job for clientId "punint05_testDevice":
* { "clientId": "punint05_testDevice" }
* { "clientId": { "startsWith" : "punint05" }}
* // Unencoded example filter value to fetch all commands associated with delivery job for status "EXECUTED":
* { "status": "EXECUTED" }
* { "status": { "startsWith" : "EXE" }}
* // Unencoded example filter value to fetch all commands associated with delivery job based on updatedAt:
* {"updatedAt": {"between": "[2021-08-06T13:46:00Z, 2021-11-11T13:46:00Z]"}}
* {"updatedAt": {"after": "2021-11-06T13:46:00Z"}}
* {"updatedAt": {"before": "2021-11-06T13:46:00Z"}}
*
* @param params.size
* The maximum number of elements returned in one page.
* Default value is 20.
* Maximum allowed value is 100.
* *
* @param params.page
* The zero-based index of the page to be returned.
* Default value - 0.
* @memberOf CommandingClient
*/
GetDeliveryJobCommands(id, params) {
return __awaiter(this, void 0, void 0, function* () {
const result = yield this.HttpAction({
verb: "GET",
gateway: this.GetGateway(),
authorization: yield this.GetToken(),
baseUrl: `${this._baseUrl}/deliveryJobs/${id}/commands?${(0, utils_1.toQueryString)(params)}`,
});
return result;
});
}
/**
*
* Get the command associated with a delivery job by command Id
*
* @param {string} id
* @param {string} commandId
* @returns {Promise<CommandingModels.Command>}
*
* @memberOf CommandingClient
*/
GetDeliveryJobCommand(id, commandId) {
return __awaiter(this, void 0, void 0, function* () {
const result = yield this.HttpAction({
verb: "GET",
gateway: this.GetGateway(),
authorization: yield this.GetToken(),
baseUrl: `${this._baseUrl}/deliveryJobs/${id}/commands/${commandId}`,
});
return result;
});
}
}
exports.CommandingClient = CommandingClient;
//# sourceMappingURL=commanding.js.map