UNPKG

@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)

302 lines 10.1 kB
"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.AgentManagementClient = void 0; const test_utils_1 = require("../../../../test/test-utils"); const utils_1 = require("../../utils"); const sdk_client_1 = require("../common/sdk-client"); /** * API defining resources and operations for managing agents. * * Generating a Boarding Configuration action is an asynchronous operation therefore it may take a while. * In case Boarding Configuration is not generated, try to read the configuration again after a couple of seconds. * * @export * @class AgentManagementClient * @extends {SdkClient} */ class AgentManagementClient extends sdk_client_1.SdkClient { constructor() { super(...arguments); this._baseUrl = "/api/agentmanagement/v3"; } /** * * Agents * * Creates a new agent. * * @param {AgentManagementModels.Agent} agent * @returns * * @memberOf AgentManagementClient */ PostAgent(agent) { 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}/agents`, body: agent, }); return result; }); } /** * * Agents * * Gets the agents for given filter. * * @param {{ * page?: number; * size?: number; * sort?: string; * filter?: string; * }} [params] * @returns {Promise<AgentManagementModels.PagedAgent>} * * @memberOf AgentManagementClient */ GetAgents(params) { return __awaiter(this, void 0, void 0, function* () { const parameters = params || {}; const { page, size, sort, filter } = parameters; const result = yield this.HttpAction({ verb: "GET", gateway: this.GetGateway(), authorization: yield this.GetToken(), baseUrl: `${this._baseUrl}/agents?${(0, utils_1.toQueryString)({ page, size, sort, filter })}`, }); return result; }); } /** * * Agents * * Gets the agent for the given agent id. * * @param {string} id * @returns {Promise<AgentManagementModels.Agent>} * * @memberOf AgentManagementClient */ GetAgent(id) { 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}/agents/${id}`, }); return result; }); } /** * * Agents * * Updates the agent for the given agent id with given parameters. * * @param {string} id * @param {AgentManagementModels.AgentUpdate} agent * @param {{ ifMatch: string }} params * @returns {Promise<AgentManagementModels.Agent>} * * @memberOf AgentManagementClient */ PutAgent(id, agent, params) { return __awaiter(this, void 0, void 0, function* () { const parameters = params || {}; const { ifMatch } = parameters; const result = yield this.HttpAction({ verb: "PUT", gateway: this.GetGateway(), authorization: yield this.GetToken(), baseUrl: `${this._baseUrl}/agents/${id}`, body: agent, additionalHeaders: { "If-Match": ifMatch }, }); return result; }); } /** * * Agents * * Deletes the agent for the given agent id. * * @param {string} id * @param {{ ifMatch: string }} params * @returns {Promise<AgentManagementModels.Agent>} * * @memberOf AgentManagementClient */ DeleteAgent(id, params) { return __awaiter(this, void 0, void 0, function* () { const parameters = params || {}; const { ifMatch } = parameters; const result = yield this.HttpAction({ verb: "DELETE", gateway: this.GetGateway(), authorization: yield this.GetToken(), baseUrl: `${this._baseUrl}/agents/${id}`, additionalHeaders: { "If-Match": ifMatch }, noResponse: true, }); return result; }); } /** * * Agents * * Get online status for the agent with specified agent id. * * @param {string} id * @returns {Promise<AgentManagementModels.OnlineStatus>} * * @memberOf AgentManagementClient */ GetAgentOnlineStatus(id) { 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}/agents/${id}/status`, }); return result; }); } /** * * DataSourceConfiguration * * Fetches data source configuration object. * * @param {string} id * @returns {Promise<AgentManagementModels.DataSourceConfiguration>} * * @memberOf AgentManagementClient */ GetDataSourceConfiguration(id) { 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}/agents/${id}/dataSourceConfiguration`, }); return result; }); } /** * * DataSourceConfiguration * * Creates or updates data source conifguration object. * * @param {string} id * @param {AgentManagementModels.DataSourceConfiguration} dataSourceConfiguration * @param {{ ifMatch: string }} params * @returns {Promise<AgentManagementModels.DataSourceConfiguration>} * * @memberOf AgentManagementClient */ PutDataSourceConfiguration(id, dataSourceConfiguration, params) { return __awaiter(this, void 0, void 0, function* () { const parameters = params || {}; const { ifMatch } = parameters; const result = yield this.HttpAction({ verb: "PUT", gateway: this.GetGateway(), authorization: yield this.GetToken(), baseUrl: `${this._baseUrl}/agents/${id}/dataSourceConfiguration`, body: dataSourceConfiguration, additionalHeaders: { "If-Match": ifMatch }, }); return result; }); } /** * * Boarding * * Gets boarding configuration * * @param {string} id * @returns {Promise<AgentManagementModels.Configuration>} * * @memberOf AgentManagementClient */ GetBoardingConfiguration(id, params) { return __awaiter(this, void 0, void 0, function* () { const parameters = params || {}; let { retry } = parameters; retry = retry || 1; let result; for (let index = 0; index < retry; index++) { result = (yield this.HttpAction({ verb: "GET", gateway: this.GetGateway(), authorization: yield this.GetToken(), baseUrl: `${this._baseUrl}/agents/${id}/boarding/configuration`, })); if (!result.content) { yield (0, test_utils_1.sleep)(500 * index); continue; } else { break; } } return result; }); } /** * * Boarding * * Offboards the agent * * @param {string} id * @returns {Promise<AgentManagementModels.OnboardingStatus>} * * @memberOf AgentManagementClient */ OffboardAgent(id) { 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}/agents/${id}/boarding/offboard`, }); return result; }); } /** * * Boarding * * Gets onboarding status. * * @param {string} id * @returns {Promise<AgentManagementModels.OnboardingStatus>} * * @memberOf AgentManagementClient */ GetOnboardingStatus(id) { 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}/agents/${id}/boarding/status`, }); return result; }); } } exports.AgentManagementClient = AgentManagementClient; //# sourceMappingURL=agent-management.js.map