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)

1,034 lines (1,031 loc) 55.3 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.AssetManagementClient = void 0; const utils_1 = require("../../utils"); const sdk_client_1 = require("../common/sdk-client"); /** * Service for configuring, reading and managing assets, asset ~ and aspect types. * * @export * @class AssetManagementClient * @extends {SdkClient} */ class AssetManagementClient extends sdk_client_1.SdkClient { constructor() { super(...arguments); this._baseUrl = "/api/assetmanagement/v3"; } /** * * AspectTypes * * Managing static and dynamic aspect types. * * List all aspect types * * @param {{ * page?: number; * size?: number; * sort?: string; * filter?: string; * ifNoneMatch?: number; * includeShared?: boolean; * }} [params] * @param [params.page] Specifies the requested page index * @param [params.size] Specifies the number of elements in a page * @param [params.sort] Specifies the ordering of returned elements * @param [params.filter] Specifies the additional filtering criteria * @param [params.ifnonematch] ETag hash of previous request to allow caching * @param [params.includeShared] Specifies if the operation should take into account shared (received) assets, aspects and asset types. * @example await assetManagement.GetAspectTypes(); * @example await assetManagement.GetAspectTypes({filter: "id eq mdsp.wing"}); * @returns {Promise<AssetManagementModels.AspectTypeListResource>} * * @memberOf AssetManagementClient */ GetAspectTypes(params) { return __awaiter(this, void 0, void 0, function* () { const parameters = params || {}; const { page, size, sort, filter, ifNoneMatch, includeShared } = parameters; const result = yield this.HttpAction({ verb: "GET", gateway: this.GetGateway(), authorization: yield this.GetToken(), baseUrl: `${this._baseUrl}/aspecttypes?${(0, utils_1.toQueryString)({ page, size, sort, filter, includeShared })}`, additionalHeaders: { "If-None-Match": ifNoneMatch }, }); return result; }); } /** * * AspectTypes * * Create or Update an aspect type. * Only adding variables supported. * User can increase the length of a static STRING variable. * The length cannot be decreased. * The length of a dynamic STRING variable cannot be changed. * * @param {string} id The type id is a unique identifier. The id length must be between 1 and 128 characters and matches the following symbols "A-Z", "a-z", "0-9","_" and "." beginning with the tenant prefix what has a maximum of 8 characters. (e.g . ten_pref.type_id) * @param {AssetManagementModels.AspectType} aspectType aspect type * @param {{ ifMatch?: string; ifNoneMatch?: string, includeShared?:boolean }} [params] * @param {{number}} [params.ifMatch] Last known version to facilitate optimistic locking. Required for modification. * @param {{number}} [params.ifNoneMatch] Set ifNoneMatch header to"*" for ensuring create request * @param [params.includeShared] Specifies if the operation should take into account shared (received) assets, aspects and asset types. * * @returns {Promise<AssetManagementModels.AspectTypeResource>} * * @example await am.PutAspectType ("mdsp.EnvironmentAspects", myAspectType, {ifNoneMatch:"*"}) * @memberOf AssetManagementClient */ PutAspectType(id, aspectType, params) { return __awaiter(this, void 0, void 0, function* () { const parameters = params || {}; const { ifMatch, ifNoneMatch, includeShared } = parameters; const result = yield this.HttpAction({ verb: "PUT", gateway: this.GetGateway(), authorization: yield this.GetToken(), baseUrl: `${this._baseUrl}/aspecttypes/${id}?${(0, utils_1.toQueryString)({ includeShared })}`, body: aspectType, additionalHeaders: { "If-Match": ifMatch, "If-None-Match": ifNoneMatch }, }); return result; }); } /** * * AspectTypes * * Patch an aspect type. Only adding variables supported. * Patching requires the inclusion of already existing variables. * Other fields may be omitted. Conforms to RFC 7396 - JSON merge Patch. * * @param {string} id The type id is a unique identifier. The id length must be between 1 and 128 characters and matches the following symbols "A-Z", "a-z", "0-9","_" and "." beginning with the tenant prefix what has a maximum of 8 characters. (e.g . ten_pref.type_id) * @param {AssetManagementModels.AspectType} aspectType aspect type * @param {{ ifMatch: string, includeShared?: boolean}} params * @param [params.includeShared] Specifies if the operation should take into account shared (received) assets, aspects and asset types. * @param {{number}} params.ifMatch Last known version to facilitate optimistic locking. Required for modification. * @returns {Promise<AssetManagementModels.AspectTypeResource>} * * @example await am.PatchAspectType ("mdsp.EnvironmentAspect", myAspectType, {ifMatch:"0"}) * @memberOf AssetManagementClient */ PatchAspectType(id, aspectType, params) { return __awaiter(this, void 0, void 0, function* () { const parameters = params || {}; const { ifMatch, includeShared } = parameters; const result = yield this.HttpAction({ verb: "PATCH", gateway: this.GetGateway(), authorization: yield this.GetToken(), baseUrl: `${this._baseUrl}/aspecttypes/${id}?${(0, utils_1.toQueryString)({ includeShared })}`, body: aspectType, additionalHeaders: { "If-Match": ifMatch, "Content-Type": "application/merge-patch+json" }, }); return result; }); } /** * * AspectTypes * * Delete an aspect type. Aspect type can only be deleted if there is no asset type using it. * * @param {string} id The type id is a unique identifier. The id length must be between 1 and 128 characters and matches the following symbols "A-Z", "a-z", "0-9","_" and "." beginning with the tenant prefix what has a maximum of 8 characters. (e.g . ten_pref.type_id) * @param {{ ifMatch: string, includeShared?: boolean }} params * @param {{ ifMatch: string }} params.ifMatch Last known version to facilitate optimistic locking, required for deleting * @param [params.includeShared] Specifies if the operation should take into account shared (received) assets, aspects and asset types. * @returns {Promise<Object>} - return empty object * * @example await am.DeleteAspectType("mdsp.EnvironmentAspect", {ifMatch:0}) * @memberOf AssetManagementClient * */ DeleteAspectType(id, params) { return __awaiter(this, void 0, void 0, function* () { const parameters = params || {}; const { ifMatch, includeShared } = parameters; yield this.HttpAction({ verb: "DELETE", gateway: this.GetGateway(), authorization: yield this.GetToken(), baseUrl: `${this._baseUrl}/aspecttypes/${id}?${(0, utils_1.toQueryString)({ includeShared })}`, additionalHeaders: { "If-Match": ifMatch }, noResponse: true, }); }); } /** * * AspectTypes * * Read an aspect type. * * @param {string} id he type id is a unique identifier. The id length must be between 1 and 128 characters and matches the following symbols "A-Z", "a-z", "0-9","_" and "." beginning with the tenant prefix what has a maximum of 8 characters. (e.g . ten_pref.type_id) * @param {{ ifNoneMatch?: number, includeShared?: boolean }} [params] ETag hash of previous request to allow caching * @param [params.includeShared] Specifies if the operation should take into account shared (received) assets, aspects and asset types. * @returns {Promise<AssetManagementModels.AspectTypeResource>} * * @example await am.GetAspectType("mdsp.EnvironmentAspect") * @memberOf AssetManagementClient */ GetAspectType(id, params) { return __awaiter(this, void 0, void 0, function* () { const parameters = params || {}; const { ifNoneMatch, includeShared } = parameters; const result = yield this.HttpAction({ verb: "GET", gateway: this.GetGateway(), authorization: yield this.GetToken(), baseUrl: `${this._baseUrl}/aspecttypes/${id}?${(0, utils_1.toQueryString)({ includeShared })}`, additionalHeaders: { "If-None-Match": ifNoneMatch }, }); return result; }); } /** * * AssetTypes * ! important: the default setting for inherited properties is false * ! important: @see [params.exploded] * * List all asset types * * @param {{ * page?: number; * size?: number; * sort?: string; * filter?: string; * ifNoneMatch?: number; * exploded?: boolean; * includeShared? boolean; * }} [params] * @param [params.page] Specifies the requested page index * @param [params.size] Specifies the number of elements in a page * @param [params.sort] Specifies the ordering of returned elements * @param [params.filter] Specifies the additional filtering criteria * @param [params.ifnonematch] ETag hash of previous request to allow caching * @param [params.exploded] Specifies if the asset type should include all of it’s inherited variables and aspects. Default is false. * @param [params.includeShared] Specifies if the operation should take into account shared (received) assets, aspects and asset types. * * @example await assetManagement.GetAssetTypes(); * @example await assetManagement.GetAssetTypes({filter: "id eq mdsp.spaceship"}); * @returns {Promise<AssetManagementModels.AssetTypeListResource>} * * @memberOf AssetManagementClient * */ GetAssetTypes(params) { return __awaiter(this, void 0, void 0, function* () { const parameters = params || {}; const { page, size, sort, filter, ifNoneMatch, exploded, includeShared } = parameters; const result = yield this.HttpAction({ verb: "GET", gateway: this.GetGateway(), authorization: yield this.GetToken(), baseUrl: `${this._baseUrl}/assettypes?${(0, utils_1.toQueryString)({ page, size, sort, filter, exploded, includeShared, })}`, additionalHeaders: { "If-None-Match": ifNoneMatch }, }); return result; }); } /** * * AssetTypes * * Create or Update an asset type * User can increase the length of a STRING variable. * The length cannot be decreased. * * @param {string} id * @param {AssetManagementModels.AssetType} assetType * @param {{ ifMatch?: string; ifNoneMatch?: string; exploded?: boolean }} [params] * @param {{number}} [params.ifMatch] Last known version to facilitate optimistic locking. Required for modification. * @param {{string}} [params.ifNoneMatch] Set ifNoneMatch header to "*"" for ensuring create request * @param {{boolean}} [params.exploded] Specifies if the asset type should include all of inherited variables and aspects. Default is false. * @param {{boolean}} [params.includeShared] Specifies if the operation should take into account shared (received) assets, aspects and asset types. * @returns {Promise<AssetManagementModels.AssetTypeResource>} * * @example await am.PutAssetType("mdsp.SimulationEngine", myAssetType) * @memberOf AssetManagementClient */ PutAssetType(id, assetType, params) { return __awaiter(this, void 0, void 0, function* () { const parameters = params || {}; const { ifMatch, ifNoneMatch, exploded, includeShared } = parameters; const result = yield this.HttpAction({ verb: "PUT", gateway: this.GetGateway(), authorization: yield this.GetToken(), baseUrl: `${this._baseUrl}/assettypes/${id}?${(0, utils_1.toQueryString)({ exploded, includeShared })}`, body: assetType, additionalHeaders: { "If-Match": ifMatch, "If-None-Match": ifNoneMatch }, }); return result; }); } /** * * AssetTypes * * Patch an asset type. * Patching requires the inclusion of all existing variables and aspects. * Missing file assignments will be deleted. * Other fields may be omitted. Conforms to RFC 7396 - JSON merge Patch. * * @param {string} id * @param {AssetManagementModels.AssetType} assetType * @param {{ ifMatch: string; exploded?: boolean; includeShared?:boolean }} params * @param {{number}} [params.ifMatch] Last known version to facilitate optimistic locking. Required for modification. * @param {{boolean}} [params.exploded] Specifies if the asset type should include all of inherited variables and aspects. Default is false. * @param {{boolean}} [params.includeShared] Specifies if the operation should take into account shared (received) assets, aspects and asset types. * @returns {Promise<AssetManagementModels.AssetTypeResource>} * * @example await am.PatchAssetType("mdsp.SimulationEngine", myAssetType) * @memberOf AssetManagementClient */ PatchAssetType(id, assetType, params) { return __awaiter(this, void 0, void 0, function* () { const parameters = params || {}; const { ifMatch, exploded, includeShared } = parameters; const result = yield this.HttpAction({ verb: "PATCH", gateway: this.GetGateway(), authorization: yield this.GetToken(), baseUrl: `${this._baseUrl}/assettypes/${id}?${(0, utils_1.toQueryString)({ exploded, includeShared })}`, body: assetType, additionalHeaders: { "If-Match": ifMatch, "Content-Type": "application/merge-patch+json" }, }); return result; }); } /** * * AssetTypes * * Deletes an asset type. * Deletion only possible when the type has no child-type and there is no asset that instantiate it. * * @param {string} id The type id is a unique identifier. The id length must be between 1 and 128 characters and matches the following symbols "A-Z", "a-z", "0-9", "_' and "." beginning with the tenant prefix what has a maximum of 8 characters. (e.g . ten_pref.type_id) * @param {{ ifMatch: string; includeShared?:boolean; }} params * @param {{number}} params.ifMatch Last known version to facilitate optimistic locking, required for deleting * @param {{boolean}} [params.includeShared] Specifies if the operation should take into account shared (received) assets, aspects and asset types. * * @example await am.DeleteAssetType("mdsp.SimulationEnigine", {ifMatch:0}) * @memberOf AssetManagementClient * */ DeleteAssetType(id, params) { return __awaiter(this, void 0, void 0, function* () { const parameters = params || {}; const { ifMatch, includeShared } = parameters; yield this.HttpAction({ verb: "DELETE", gateway: this.GetGateway(), authorization: yield this.GetToken(), baseUrl: `${this._baseUrl}/assettypes/${id}?${(0, utils_1.toQueryString)({ includeShared })}`, additionalHeaders: { "If-Match": ifMatch }, noResponse: true, }); }); } /** * * AssetTypes * * Read an asset type * ! important: the default setting for inherited properties is false * ! important: @see [params.exploded] * * @param {string} id * @param {{ ifNoneMatch?: string; exploded?: boolean; includeShared?: boolean }} [params] * @returns {Promise<AssetManagementModels.AssetTypeResource>} * * @example await am.GetAssetType("mdsp.SimulationEngine") * @memberOf AssetManagementClient */ GetAssetType(id, params) { return __awaiter(this, void 0, void 0, function* () { const parameters = params || {}; const { ifNoneMatch, exploded, includeShared } = parameters; const ex = exploded === undefined ? false : exploded; const result = yield this.HttpAction({ verb: "GET", gateway: this.GetGateway(), authorization: yield this.GetToken(), baseUrl: `${this._baseUrl}/assettypes/${id}?${(0, utils_1.toQueryString)({ exploded: ex, includeShared })}`, additionalHeaders: { "If-None-Match": ifNoneMatch }, }); return result; }); } /** * * AssetTypes * * Add a new file assignment to a given asset type. All asset which extends these types will have its file by default. * * @param {string} id The type id is a unique identifier. The id length must be between 1 and 128 characters and matches the following symbols "A-Z", "a-z", "0-9", "_" and "." beginning with the tenant prefix what has a maximum of 8 characters. (e.g . ten_pref.type_id) * @param {string} key Keyword for the file to be assigned to an asset or asset type. * @param {AssetManagementModels.KeyedFileAssignment} assignment Data for file assignment * @param {{ ifMatch: string ; includeShared?: boolean}} params * @param {{number}} params.ifMatch Last known version to facilitate optimistic locking * @param {{boolean}} [params.includeShared] Specifies if the operation should take into account shared (received) assets, aspects and asset types. * @returns {Promise<AssetManagementModels.AssetTypeResource>} * * @memberOf AssetManagementClient */ PutAssetTypeFileAssignment(id, key, assignment, params) { return __awaiter(this, void 0, void 0, function* () { const parameters = params || {}; const { ifMatch, includeShared } = parameters; const result = yield this.HttpAction({ verb: "PUT", gateway: this.GetGateway(), authorization: yield this.GetToken(), baseUrl: `${this._baseUrl}/assettypes/${id}/fileAssignments/${key}?${(0, utils_1.toQueryString)({ includeShared })}`, body: assignment, additionalHeaders: { "If-Match": ifMatch }, }); return result; }); } /** * *AssetTypes * * Deletes a file assignment from an asset type. * If the type parent has defined a file with the same key, the key will be displayed with the inherited value. * * @param {string} id The type id is a unique identifier. The id length must be between 1 and 128 characters and matches the following symbols "A-Z", "a-z", "0-9","_" and "." beginning with the tenant prefix what has a maximum of 8 characters. (e.g . ten_pref.type_id) * @param {string} key Keyword for the file to be assigned to an asset or asset type. * @param {AssetManagementModels.KeyedFileAssignment} assignment Data for file assignment * @param {{ ifMatch: string; includeShared?: boolean }} params * @param {{number}} params.ifMatch Last known version to facilitate optimistic locking * @param {{boolean}} [params.includeShared] Specifies if the operation should take into account shared (received) assets, aspects and asset types. * * @memberOf AssetManagementClient */ DeleteAssetTypeFileAssignment(id, key, params) { return __awaiter(this, void 0, void 0, function* () { const parameters = params || {}; const { ifMatch, includeShared } = parameters; yield this.HttpAction({ verb: "DELETE", gateway: this.GetGateway(), authorization: yield this.GetToken(), baseUrl: `${this._baseUrl}/assettypes/${id}/fileAssignments/${key}?${(0, utils_1.toQueryString)({ includeShared })}`, additionalHeaders: { "If-Match": ifMatch }, noResponse: true, }); }); } /** * * AssetTypes * * Updates an existing variable defined on an asset type. Variables cannot be added or deleted using this operation, * for adding or deleting variables use patch/put assettype api. Any variable which is not part of the request will remain unchanged * Variable's Name, Length, Default Value and Unit can be changed. The unit changes from the api does not compute any value changes * derived after the unit changes, the values will remain as it is and only the unit will be updated. * The length can only be increased of a string variable and it cannot be decreased. * This operation will increment the asset type etag value. * * @param {string} id The type id is a unique identifier. The id length must be between 1 and 128 characters and matches the following symbols "A-Z", "a-z", "0-9","_" and "." beginning with the tenant prefix what has a maximum of 8 characters. (e.g . ten_pref.type_id) * @param {{ ifMatch: string; includeShared?: boolean }} params * @param {{number}} params.ifMatch Last known version to facilitate optimistic locking * @param {{boolean}} [params.includeShared] Specifies if the operation should take into account shared (received) assets, aspects and asset types. * @param {AssetManagementModels.VariableUpdateMap} variableMap * @returns {Promise<Headers>} * * @memberOf AssetManagementClient */ PatchAssetTypeVariable(id, variableMap, params) { return __awaiter(this, void 0, void 0, function* () { const parameters = params || {}; const { ifMatch, includeShared } = parameters; const result = yield this.HttpAction({ verb: "PATCH", gateway: this.GetGateway(), authorization: yield this.GetToken(), baseUrl: `${this._baseUrl}/assettypes/${id}/variables?${(0, utils_1.toQueryString)({ includeShared })}`, body: variableMap, returnHeaders: true, additionalHeaders: { "If-Match": ifMatch, "Content-Type": "application/merge-patch+json" }, }); return result; }); } /** * * Asset * * List all assets available for the authenticated user. * * @param {{ * page?: number; * size?: number; * sort?: string; * filter?: string; * ifNoneMatch?: string; * includeShared? boolean; * }} [params] * @param [params.page] Specifies the requested page index * @param [params.size] Specifies the number of elements in a page * @param [params.sort] Specifies the ordering of returned elements * @param [params.filter] Specifies the additional filtering criteria * @param [params.ifnonematch] ETag hash of previous request to allow caching * @param [params.includeShared] Specifies if the operation should take into account shared (received) assets, aspects and asset types. * * @returns {Promise<AssetManagementModels.AssetListResource>} * * @example await assetManagement.GetAssets(); * @example await assetManagement.GetAssetTypes({filter: "typeid eq mdsp.spaceship"}); * * @memberOf AssetManagementClient */ GetAssets(params) { return __awaiter(this, void 0, void 0, function* () { const parameters = params || {}; const { page, size, sort, filter, ifNoneMatch, includeShared } = parameters; const result = yield this.HttpAction({ verb: "GET", gateway: this.GetGateway(), authorization: yield this.GetToken(), baseUrl: `${this._baseUrl}/assets?${(0, utils_1.toQueryString)({ page, size, sort, filter, includeShared })}`, additionalHeaders: { "If-None-Match": ifNoneMatch }, }); return result; }); } /** * * Asset * * Creates a new asset with the provided content. Only instantiable types could be used. * @param {{ * includeShared? boolean; * }} [params] * @param [params.includeShared] Specifies if the operation should take into account shared (received) assets, aspects and asset types. * * @param {AssetManagementModels.Asset} asset * @returns {Promise<AssetManagementModels.AssetResourceWithHierarchyPath>} * * @example await assetManagement.PostAsset(myasset); * @memberOf AssetManagementClient */ PostAsset(asset, params) { return __awaiter(this, void 0, void 0, function* () { const parameters = params || {}; const { includeShared } = parameters; const result = yield this.HttpAction({ verb: "POST", gateway: this.GetGateway(), authorization: yield this.GetToken(), baseUrl: `${this._baseUrl}/assets?${(0, utils_1.toQueryString)({ includeShared })} `, body: asset, }); return result; }); } /** * * Asset * * Read a single asset. All static properties of asset are returned. * * @param {string} assetId Unique identifier * @param {{ ifNoneMatch?: string; includeShared?: boolean}} [params] * @param {{string}} [params.ifNoneMatch] * @param [params.includeShared] Specifies if the operation should take into account shared (received) assets, aspects and asset types. * @returns {Promise<AssetManagementModels.AssetResourceWithHierarchyPath>} * * @memberOf AssetManagementClient */ GetAsset(assetId, params) { return __awaiter(this, void 0, void 0, function* () { const parameters = params || {}; const { ifNoneMatch, includeShared } = parameters; const result = yield this.HttpAction({ verb: "GET", gateway: this.GetGateway(), authorization: yield this.GetToken(), baseUrl: `${this._baseUrl}/assets/${assetId}?${(0, utils_1.toQueryString)({ includeShared })}`, additionalHeaders: { "If-None-Match": ifNoneMatch }, }); return result; }); } /** * * Asset * * Updates an asset with the provided content. * Only values can be modified, asset structure have to be modified in asset type * * @param {string} assetId * @param {AssetManagementModels.AssetUpdate} asset * @param {{ ifMatch: string; includeShared?: boolean }} params * @param {{number}} [params.ifMatch] Last known version to facilitate optimistic locking. Required for modification. * @param {{boolean}} [params.includeShared] Specifies if the operation should take into account shared (received) assets, aspects and asset types. * @returns {Promise<AssetManagementModels.AssetResourceWithHierarchyPath>} * * @example await assetManagement.PutAsset (myAsset, {ifMatch: `${myAsset.etag}`}) * * @memberOf AssetManagementClient */ PutAsset(assetId, asset, params) { return __awaiter(this, void 0, void 0, function* () { const parameters = params || {}; const { ifMatch, includeShared } = parameters; const result = yield this.HttpAction({ verb: "PUT", gateway: this.GetGateway(), authorization: yield this.GetToken(), baseUrl: `${this._baseUrl}/assets/${assetId}?${(0, utils_1.toQueryString)({ includeShared })}`, body: asset, additionalHeaders: { "If-Match": ifMatch }, }); return result; }); } /** * * Asset * * Patch an asset with the provided content. * Only values can be modified, asset structure have to be modified in asset type. * Conforms to RFC 7396 - JSON merge Patch. * * @param {string} assetId * @param {AssetManagementModels.AssetUpdate} asset * @param {{ ifMatch: string; includeShared?: boolean; }} params * @param {{number}} [params.ifMatch] Last known version to facilitate optimistic locking. Required for modification. * @param {{boolean}} [params.includeShared] Specifies if the operation should take into account shared (received) assets, aspects and asset types. * @returns {Promise<AssetManagementModels.AssetResourceWithHierarchyPath>} * * @example await assetManagement.Patch (myAsset, {ifMatch: `${myAsset.etag}`}) * * @memberOf AssetManagementClient */ PatchAsset(assetId, asset, params) { return __awaiter(this, void 0, void 0, function* () { const parameters = params || {}; const { ifMatch, includeShared } = parameters; const result = yield this.HttpAction({ verb: "PATCH", gateway: this.GetGateway(), authorization: yield this.GetToken(), baseUrl: `${this._baseUrl}/assets/${assetId}?${(0, utils_1.toQueryString)({ includeShared })}`, body: asset, additionalHeaders: { "If-Match": ifMatch, "Content-Type": "application/merge-patch+json" }, }); return result; }); } /** * * Asset * * Deletes the given asset. * After deletion only users with admin role can read it, * but modification is not possible anymore. * It is not possible to delete an asset if it has children. * * @param {string} id The type id is a unique identifier. The id s length must be between 1 and 128 characters and matches the following symbols "A-Z", "a-z", "0-9", "_" and "." beginning with the tenant prefix what has a maximum of 8 characters. (e.g . ten_pref.type_id) * @param {{ ifMatch: string; includeShared?: booleanl }} params * @param {{number}} params.ifMatch Last known version to facilitate optimistic locking, required for deleting * @param {{boolean}} [params.includeShared] Specifies if the operation should take into account shared (received) assets, aspects and asset types. * @example await assetManagement.DeleteAsset(id, {ifMatch:0}) * * @memberOf AssetManagementClient */ DeleteAsset(id, params) { return __awaiter(this, void 0, void 0, function* () { const parameters = params || {}; const { ifMatch, includeShared } = parameters; yield this.HttpAction({ verb: "DELETE", gateway: this.GetGateway(), authorization: yield this.GetToken(), baseUrl: `${this._baseUrl}/assets/${id}?${(0, utils_1.toQueryString)({ includeShared })}`, additionalHeaders: { "If-Match": ifMatch }, noResponse: true, }); }); } /** * * Asset * * Moves an asset (and all asset children) in the instance hierarchy * * @param {string} assetId * @param {AssetManagementModels.AssetMove} moveParameters * @param {{ ifMatch: string; includeShared?: boolean }} params * @param {{number}} [params.ifMatch] Last known version to facilitate optimistic locking. Required for modification. * @param {{boolean}} [params.includeShared] Specifies if the operation should take into account shared (received) assets, aspects and asset types. * @returns {Promise<AssetManagementModels.AssetResourceWithHierarchyPath>} * * @example await assetManagement.PutAsset (myAsset, {ifMatch: `${myAsset.etag}`}) * * @memberOf AssetManagementClient */ MoveAsset(assetId, moveParameters, params) { return __awaiter(this, void 0, void 0, function* () { const parameters = params || {}; const { ifMatch, includeShared } = parameters; const result = yield this.HttpAction({ verb: "POST", gateway: this.GetGateway(), authorization: yield this.GetToken(), baseUrl: `${this._baseUrl}/assets/${assetId}?${(0, utils_1.toQueryString)({ includeShared })}`, body: moveParameters, additionalHeaders: { "If-Match": ifMatch }, }); return result; }); } /** * * Asset * * Save a file assignment to a given asset * * @param {string} id The type id is a unique identifier. The id length must be between 1 and 128 characters and matches the following symbols "A-Z", "a-z", "0-9", "_" and ". * beginning with the tenant prefix what has a maximum of 8 characters. (e.g. ten_pref.type_id) * @param {string} key Keyword for the file to be assigned to an asset or asset type. * @param {AssetManagementModels.KeyedFileAssignment} assignment Data for file assignment * @param {{ ifMatch: string; includeShared ?: boolean; }} params * @param {{boolean}} [params.includeShared] Specifies if the operation should take into account shared (received) assets, aspects and asset types. * @param {{number}} [params.ifMatch] Last known version to facilitate optimistic locking * @returns {Promise<AssetManagementModels.AssetTypeResource>} * * @memberOf AssetManagementClient */ PutAssetFileAssignment(id, key, assignment, params) { return __awaiter(this, void 0, void 0, function* () { const parameters = params || {}; const { ifMatch, includeShared } = parameters; const result = yield this.HttpAction({ verb: "PUT", gateway: this.GetGateway(), authorization: yield this.GetToken(), baseUrl: `${this._baseUrl}/assets/${id}/fileAssignments/${key}?${(0, utils_1.toQueryString)({ includeShared })}`, body: assignment, additionalHeaders: { "If-Match": ifMatch }, }); return result; }); } /** * * Asset * * Deletes a file assignment from an asset. * If the asset parent type has defined a file with the same key, the key will be displayed with the inherited value. * * @param {string} id The type id is a unique identifier. The id length must be between 1 and 128 characters and matches the following symbols "A-Z", "a-z", "0-9","_" and "." beginning with the tenant prefix what has a maximum of 8 characters. (e.g . ten_pref.type_id) * @param {string} key Keyword for the file to be assigned to an asset or asset type. * @param {AssetManagementModels.KeyedFileAssignment} assignment Data for file assignment * @param {{ ifMatch: string; includeShared?: boolean }} params * @param {{number}} params.ifMatch Last known version to facilitate optimistic locking * * @memberOf AssetManagementClient */ DeleteAssetFileAssignment(id, key, params) { return __awaiter(this, void 0, void 0, function* () { const parameters = params || {}; const { ifMatch, includeShared } = parameters; yield this.HttpAction({ verb: "DELETE", gateway: this.GetGateway(), authorization: yield this.GetToken(), baseUrl: `${this._baseUrl}/assets/${id}/fileAssignments/${key}?${(0, utils_1.toQueryString)({ includeShared })}`, additionalHeaders: { "If-Match": ifMatch }, noResponse: true, }); }); } /** * * Asset * Returns the root asset of the user. * Read the root asset of the user, from which the whole asset hierarchy can be rebuilt. * * @returns {Promise<AssetManagementModels.RootAssetResource>} * * @memberOf AssetManagementClient */ GetRootAsset() { 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}/assets/root`, }); return result; }); } /** * * Asset Structure * Get all static and dynamic aspects of a given asset * * @param {string} assetId * @param {{ * page?: number; * size?: number; * sort?: string; * filter?: string; * ifNoneMatch?: number; * includeShared?: number; * }} [params] * @param [params.page] Specifies the requested page index * @param [params.size] Specifies the number of elements in a page * @param [params.sort] Specifies the ordering of returned elements * @param [params.filter] Specifies the additional filtering criteria * @param [params.ifnonematch] ETag hash of previous request to allow caching * @param [params.includeShared] Specifies if the operation should take into account shared (received) assets, aspects and asset types. * * @returns {Promise<AssetManagementModels.AspectListResource>} * * @memberOf AssetManagementClient */ GetAspects(assetId, params) { return __awaiter(this, void 0, void 0, function* () { const parameters = params || {}; const { page, size, sort, filter, ifNoneMatch, includeShared } = parameters; const result = yield this.HttpAction({ verb: "GET", gateway: this.GetGateway(), authorization: yield this.GetToken(), baseUrl: `${this._baseUrl}/assets/${assetId}/aspects?${(0, utils_1.toQueryString)({ page, size, sort, filter, includeShared, })}`, additionalHeaders: { "If-None-Match": ifNoneMatch }, }); return result; }); } /** * * Asset Structure * Get all variables of a given asset including inherited ones * * @param {string} assetId * @param {{ * page?: number; * size?: number; * sort?: string; * filter?: string; * ifNoneMatch?: number; * includeShared?: boolean; * }} [params] * @param [params.page] Specifies the requested page index * @param [params.size] Specifies the number of elements in a page * @param [params.sort] Specifies the ordering of returned elements * @param [params.filter] Specifies the additional filtering criteria * @param [params.ifnonematch] ETag hash of previous request to allow caching * @param [params.includeShared] Specifies if the operation should take into account shared (received) assets, aspects and asset types. * * @returns {Promise<AssetManagementModels.AspectListResource>} * * @memberOf AssetManagementClient */ GetVariables(assetId, params) { return __awaiter(this, void 0, void 0, function* () { const parameters = params || {}; const { page, size, sort, filter, ifNoneMatch, includeShared } = parameters; const result = yield this.HttpAction({ verb: "GET", gateway: this.GetGateway(), authorization: yield this.GetToken(), baseUrl: `${this._baseUrl}/assets/${assetId}/variables?${(0, utils_1.toQueryString)({ page, size, sort, filter, includeShared, })}`, additionalHeaders: { "If-None-Match": ifNoneMatch }, }); return result; }); } /** * * Asset Location * * Create or Update location assigned to given asset * * * If the given asset has own location, this endpoint will update that location. * * If the given asset has no location, this endpoint will create a new location and update the given asset. * * If the given asset has inherited location, this endpoint will create a new location and update the given asset. * * If you wanted to update the inherited location you have to use the location url in AssetResource object (with PUT method). * * @param {string} id The type id is a unique identifier. The id length must be between 1 and 128 characters and matches the following symbols "A-Z", "a-z", "0-9","_" and "." beginning with the tenant prefix what has a maximum of 8 characters. (e.g . ten_pref.type_id) * @param {AssetManagementModels.Location} location Data for location * @param {{ ifMatch: string; includeShared ?: boolean }} params * @param {{number}} params.ifMatch Last known version to facilitate optimistic locking * @param {{boolean}} [params.includeShared] Specifies if the operation should take into account shared (received) assets, aspects and asset types. * @returns {Promise<AssetManagementModels.Location>} * * ! fix: 3.11. : the swagger documentation says that the method is returning Location but it returns AssetResourceWithHierarchyPath * * @memberOf AssetManagementClient */ PutAssetLocation(id, location, params) { return __awaiter(this, void 0, void 0, function* () { const parameters = params || {}; const { ifMatch, includeShared } = parameters; const result = yield this.HttpAction({ verb: "PUT", gateway: this.GetGateway(), authorization: yield this.GetToken(), baseUrl: `${this._baseUrl}/assets/${id}/location?${(0, utils_1.toQueryString)({ includeShared })}`, body: location, additionalHeaders: { "If-Match": ifMatch }, }); return result; }); } /** * * Asset Location * * Delete location assigned to given asset. * * * Only those locations can be deleted here which assigned to the given asset. * * If the location inherited from an ancestor asset, you have to delete the location with the assigned assetId (using location url in AssetResource object with DELETE method). * * The response contains the updated AssetResource with the inherited Location details. * * @param {string} id The type id is a unique identifier. The id length must be between 1 and 128 characters and matches the following symbols "A-Z", "a-z", "0-9","_" and "." beginning with the tenant prefix what has a maximum of 8 characters. (e.g . ten_pref.type_id) * @param {AssetManagementModels.Location} location Data for location * @param {{ ifMatch: string; includeShared?: boolean }} params * @param {{number}} params.ifMatch Last known version to facilitate optimistic locking * @param {{boolean}} [params.includeShared] Specifies if the operation should take into account shared (received) assets, aspects and asset types. * @returns {Promise<AssetManagementModels.AssetResourceWithHierarchyPath>} * * @memberOf AssetManagementClient */ DeleteAssetLocation(id, params) { return __awaiter(this, void 0, void 0, function* () { const parameters = params || {}; const { ifMatch, includeShared } = parameters; const result = yield this.HttpAction({ verb: "DELETE", gateway: this.GetGateway(), authorization: yield this.GetToken(), baseUrl: `${this._baseUrl}/assets/${id}/location?${(0, utils_1.toQueryString)({ includeShared })}`, additionalHeaders: { "If-Match": ifMatch }, }); return result; }); } /** * * Asset Files * * Upload files to be used in Asset Management. * * @param {Buffer} file * @param {string} name * @param {{ * scope?: AssetManagementModels.FileMetadataResource.ScopeEnum; * description?: string; * mimeType?: string; * }} [params] * @returns {Promise<AssetManagementModels.FileMetadataResource>} * * @memberOf AssetManagementClient */ PostFile(file, name, params) { return __awaiter(this, void 0, void 0, function* () { const parameters = params || {}; const { scope, description, mimeType } = parameters; const template = `----mindsphere\r\nContent-Disposition: form-data; name="file"; filename="${name}"\r\nContent-Type: ${mimeType || "application/octet-stream"}\r\n\r\n${file.toString("ascii")}\r\n----mindsphere\r\nContent-Disposition: form-data; name="name"\r\n\r\n${name}\r\n----mindsphere\r\nContent-Disposition: form-data; name="description"\r\n\r\n${description || "uploaded file"}\r\n\----mindsphere\r\nContent-Disposition: form-data; name="scope"\r\n\r\n${scope || "PRIVATE"}\r\n----mindsphere--`; const result = yield this.HttpAction({ verb: "POST", gateway: this.GetGateway(), authorization: yield this.GetToken(), baseUrl: `${this._baseUrl}/files`, body: template, multiPartFormData: true, }); return result; }); } /** * * Asset files * * Get metadata of uploaded files. * Returns all visible file metadata for the tenant. Will NOT return the files. * * @param {{ * page?: number; * size?: number; * sort?: string; * filter?: string; * ifNoneMatch?: number; * }} [params] * * @param {{ * page?: number; * size?: number; * sort?: string; * filter?: string; * ifNoneMatch?: number; * }} [params] * @param [params.page] Specifies the requested page index * @param [params.size] Specifies the number of elements in a page * @param [params.sort] Specifies the ordering of returned elements * @param [params.filter] Specifies the additional filtering criteria * @param [params.ifnonematch] ETag hash of previous request to allow caching * @returns {Promise<AssetManagementModels.FileMetadataListResource>} * * @memberOf AssetManagementClient */ GetFiles(params) { return __awaiter(this, void 0, void 0, function* () { const parameters = params || {}; const { page, size, sort, filter, ifNoneMatch } = parameters; const result = yield this.HttpAction({ verb: "GET", gateway: this.GetGateway(), authorization: yield this.GetToken(), baseUrl: `${this._baseUrl}/files?${(0, utils_1.toQueryString)({ page, size, sort, filter })}`, additionalHeaders: { "If-None-Match": ifNoneMatch }, }); return result; }); } /** * * Asset Files * * Get metadata of uploaded files. * * @param {string} fileId * @param {{ * ifNoneMatch?: number; * }} [params] * @returns {Promise<AssetManagementModels.FileMetadataResource>} * * @memberOf AssetManagementClient */ GetFile(fileId, params) { return __awaiter(this, void 0, void 0, function* () { const parameters = params || {}; const { ifNoneMatch } = parameters; const result = yield this.HttpAction({ verb: "GET", gateway: this.GetGateway(), authorization: yield this.GetToken(), baseUrl: `${this._baseUrl}/files/${fileId}`, additionalHeaders: { "If-None-Match": ifNoneMatch }, }); return result; }); } /** * Returns a file by its id * * @param {string} fileId * @param {{ * ifNoneMatch?: number; * }