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)

123 lines 8.09 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()); }); }; var __asyncValues = (this && this.__asyncValues) || function (o) { if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); var m = o[Symbol.asyncIterator], i; return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i); function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; } function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); } }; Object.defineProperty(exports, "__esModule", { value: true }); const console_1 = require("console"); const utils_1 = require("../../api/utils"); const command_utils_1 = require("./command-utils"); let color = (0, command_utils_1.getColor)("magenta"); exports.default = (program) => { program .command("asset-info") .alias("ai") .option("-i, --assetid <assetid>", "mindsphere asset id ") .option("-k, --passkey <passkey>", "passkey") .option("-y, --retry <number>", "retry attempts before giving up", "3") .option("-v, --verbose", "verbose output") .description(color(`get infos about asset *`)) .action((options) => { (() => __awaiter(void 0, void 0, void 0, function* () { var _a, e_1, _b, _c; var _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t; try { checkRequiredParameters(options); const sdk = (0, command_utils_1.getSdk)(options); color = (0, command_utils_1.adjustColor)(color, options); (0, command_utils_1.homeDirLog)(options.verbose, color); (0, command_utils_1.proxyLog)(options.verbose, color); const assetMgmt = sdk.GetAssetManagementClient(); const asset = (yield (0, utils_1.retry)(options.retry, () => assetMgmt.GetAsset(options.assetid))); const assetType = (yield (0, utils_1.retry)(options.retry, () => assetMgmt.GetAssetType(`${asset.typeId}`))); let path = ""; (_d = asset.hierarchyPath) === null || _d === void 0 ? void 0 : _d.forEach((entry) => { path = `${path} ${color(">")} ${entry.name}`; }); console.log(`\nAsset Information for Asset with Asset Id: ${color(asset.assetId)}\n`); console.log(`Path: ${path}`); console.log(`Type: ${asset.typeId} ${color(":")} ${assetType.parentTypeId}`); console.log(`Name: ${color(asset.name)}`); console.log(`TimeZone: ${asset.timezone}`); console.log(`TwinType: ${asset.twinType}`); console.log(`Description: ${asset.description}`); console.log(`Location: ${(_e = asset.location) === null || _e === void 0 ? void 0 : _e.streetAddress} ${(_f = asset.location) === null || _f === void 0 ? void 0 : _f.postalCode} ${(_g = asset.location) === null || _g === void 0 ? void 0 : _g.locality} ${(_h = asset.location) === null || _h === void 0 ? void 0 : _h.region} ${(_j = asset.location) === null || _j === void 0 ? void 0 : _j.country} ${(_k = asset.location) === null || _k === void 0 ? void 0 : _k.region}`); const map = `https://www.google.com/maps/search/?api=1&query=${(_l = asset.location) === null || _l === void 0 ? void 0 : _l.latitude},${(_m = asset.location) === null || _m === void 0 ? void 0 : _m.longitude}`; console.log(`Google Maps: ${color(map)}`); console.log("Variables:"); (_o = assetType.variables) === null || _o === void 0 ? void 0 : _o.forEach((variable) => { console.log(`- ${color(variable.name)} ${variable.unit} ${variable.dataType}`); }); console.log("Aspects:"); try { for (var _u = true, _v = __asyncValues(assetType.aspects || []), _w; _w = yield _v.next(), _a = _w.done, !_a; _u = true) { _c = _w.value; _u = false; const entry = _c; console.log(`- ${color(entry.name)}: ${(_p = entry.aspectType) === null || _p === void 0 ? void 0 : _p.id}`); (_r = (_q = entry.aspectType) === null || _q === void 0 ? void 0 : _q.variables) === null || _r === void 0 ? void 0 : _r.forEach((variable) => { console.log(`\t - ${color(variable.name)} ${variable.unit} ${variable.dataType}`); }); const ts = yield (0, utils_1.retry)(options.retry, () => sdk.GetTimeSeriesClient().GetTimeSeries(asset.assetId, entry.name)); console.log("\nLast Timeseries Entry:"); console.table(ts); } } catch (e_1_1) { e_1 = { error: e_1_1 }; } finally { try { if (!_u && !_a && (_b = _v.return)) yield _b.call(_v); } finally { if (e_1) throw e_1.error; } } console.log("\nLast Event Entries:"); const events = yield (0, utils_1.retry)(options.retry, () => sdk .GetEventManagementClient() .GetEvents({ sort: "timestamp,desc", filter: JSON.stringify({ entityId: asset.assetId }) })); console.table(((_t = (_s = events._embedded) === null || _s === void 0 ? void 0 : _s.events) === null || _t === void 0 ? void 0 : _t.slice(0, 10)) || [], [ "timestamp", "source", "severity", "description", ]); console.log("\n Last uploaded Files:"); const files = yield (0, utils_1.retry)(options.retry, () => sdk.GetIoTFileClient().GetFiles(asset.assetId, { order: "updated desc" })); console.table(files.slice(0, 10), ["name", "path", "type", "timestamp"]); console.log("\nAsset Manager:"); console.log("\t" + color(`${sdk .GetGateway() .replace("gateway", sdk.GetTenant() + "-assetmanager")}/entity/${asset.assetId}`)); console.log("\nOperations Insight:"); console.log("\t" + color(`${sdk .GetGateway() .replace("gateway", sdk.GetTenant() + "-operationsinsight")}/explore-assets/info?asset=${asset.assetId}`)); } catch (err) { (0, command_utils_1.errorLog)(err, options.verbose); } }))(); }) .on("--help", () => { (0, console_1.log)("\n Examples:\n"); (0, console_1.log)(` mdsp asset-info --assetid 123456...ef \t print out infos about asset with id 132456...ef`); (0, command_utils_1.serviceCredentialLog)(); }); }; function checkRequiredParameters(options) { !options.assetid && (0, command_utils_1.errorLog)("you have to provide an assetid", true); } //# sourceMappingURL=asset-info.js.map