UNPKG

@mindconnect/mindconnect-nodejs

Version:

MindConnect Library for NodeJS (community based)

1,017 lines (1,013 loc) 45.6 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 }); 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; * }} [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 * * @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 } = parameters; const result = yield this.HttpAction({ verb: "GET", gateway: this.GetGateway(), authorization: yield this.GetToken(), baseUrl: `${this._baseUrl}/aspecttypes?${utils_1.toQueryString({ page, size, sort, filter })}`, 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’s 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 {AssetManagementModels.AspectType} aspectType aspect type * @param {{ ifMatch?: string; ifNoneMatch?: string }} [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 * @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 } = parameters; const result = yield this.HttpAction({ verb: "PUT", gateway: this.GetGateway(), authorization: yield this.GetToken(), baseUrl: `${this._baseUrl}/aspecttypes/${id}`, 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’s 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 {AssetManagementModels.AspectType} aspectType aspect type * @param {{ ifMatch: string}} params * @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 } = parameters; const result = yield this.HttpAction({ verb: "PATCH", gateway: this.GetGateway(), authorization: yield this.GetToken(), baseUrl: `${this._baseUrl}/aspecttypes/${id}`, 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’s 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 }} params * @param {{ ifMatch: string }} params.ifMatch Last known version to facilitate optimistic locking, required for deleting * @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* () { yield this.HttpAction({ verb: "DELETE", gateway: this.GetGateway(), authorization: yield this.GetToken(), baseUrl: `${this._baseUrl}/aspecttypes/${id}`, additionalHeaders: { "If-Match": params.ifMatch }, noResponse: true }); }); } /** * * AspectTypes * * Read an aspect type. * * @param {string} id he type’s 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 {{ ifNoneMatch?: number }} [params] ETag hash of previous request to allow caching * @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 } = parameters; const result = yield this.HttpAction({ verb: "GET", gateway: this.GetGateway(), authorization: yield this.GetToken(), baseUrl: `${this._baseUrl}/aspecttypes/${id}`, 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; * }} [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. * * @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 } = parameters; const result = yield this.HttpAction({ verb: "GET", gateway: this.GetGateway(), authorization: yield this.GetToken(), baseUrl: `${this._baseUrl}/assettypes?${utils_1.toQueryString({ page, size, sort, filter, exploded })}`, 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 it’s inherited variables and aspects. Default is false. * @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 } = parameters; const result = yield this.HttpAction({ verb: "PUT", gateway: this.GetGateway(), authorization: yield this.GetToken(), baseUrl: `${this._baseUrl}/assettypes/${id}?${utils_1.toQueryString({ exploded: exploded })}`, 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 }} 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 it’s inherited variables and aspects. Default is false. * @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 } = parameters; const result = yield this.HttpAction({ verb: "PATCH", gateway: this.GetGateway(), authorization: yield this.GetToken(), baseUrl: `${this._baseUrl}/assettypes/${id}?${utils_1.toQueryString({ exploded: exploded })}`, 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’s 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 }} params * @param {{number}} params.ifMatch Last known version to facilitate optimistic locking, required for deleting * * @example await am.DeleteAssetType("mdsp.SimulationEnigine", {ifMatch:0}) * @memberOf AssetManagementClient * */ DeleteAssetType(id, params) { return __awaiter(this, void 0, void 0, function* () { yield this.HttpAction({ verb: "DELETE", gateway: this.GetGateway(), authorization: yield this.GetToken(), baseUrl: `${this._baseUrl}/assettypes/${id}`, additionalHeaders: { "If-Match": params.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 }} [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 } = 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}?exploded=${ex}`, 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’s 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 {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 }} params * @param {{number}} params.ifMatch Last known version to facilitate optimistic locking * @returns {Promise<AssetManagementModels.AssetTypeResource>} * * @memberOf AssetManagementClient */ PutAssetTypeFileAssignment(id, key, assignment, 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}/assettypes/${id}/fileAssignments/${key}`, body: assignment, additionalHeaders: { "If-Match": ifMatch } }); return result; }); } /** * *AssetTypes * * Deletes a file assignment from an asset type. * If the type’s parent has defined a file with the same key, the key will be displayed with the inherited value. * * @param {string} id The type’s 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 {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 }} params * @param {{number}} params.ifMatch Last known version to facilitate optimistic locking * * @memberOf AssetManagementClient */ DeleteAssetTypeFileAssignment(id, key, params) { return __awaiter(this, void 0, void 0, function* () { const parameters = params || {}; const { ifMatch } = parameters; yield this.HttpAction({ verb: "DELETE", gateway: this.GetGateway(), authorization: yield this.GetToken(), baseUrl: `${this._baseUrl}/assettypes/${id}/fileAssignments/${key}`, additionalHeaders: { "If-Match": ifMatch }, noResponse: true }); }); } /** * * Asset * * List all assets available for the authenticated user. * * @param {{ * page?: number; * size?: number; * sort?: string; * filter?: string; * ifNoneMatch?: string; * }} [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.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 } = parameters; const result = yield this.HttpAction({ verb: "GET", gateway: this.GetGateway(), authorization: yield this.GetToken(), baseUrl: `${this._baseUrl}/assets?${utils_1.toQueryString({ page, size, sort, filter })}`, additionalHeaders: { "If-None-Match": ifNoneMatch } }); return result; }); } /** * * Asset * * Creates a new asset with the provided content. Only instantiable types could be used. * * @param {AssetManagementModels.Asset} asset * @returns {Promise<AssetManagementModels.AssetResourceWithHierarchyPath>} * * @example await assetManagement.PostAsset(myasset); * @memberOf AssetManagementClient */ PostAsset(asset) { 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}/assets`, body: asset }); return result; }); } /** * * Asset * * Read a single asset. All static properties of asset are returned. * * @param {string} assetId Unique identifier * @param {{ ifNoneMatch?: string }} [params] * @param {{string}} [params.ifNoneMatch] * @returns {Promise<AssetManagementModels.AssetResourceWithHierarchyPath>} * * @memberOf AssetManagementClient */ GetAsset(assetId, 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}/assets/${assetId}`, additionalHeaders: { "If-None-Match": ifNoneMatch } }); return result; }); } /** * * Asset * * Updates an asset with the provided content. * Only values can be modified, asset’s structure have to be modified in asset’s type * * @param {string} assetId * @param {AssetManagementModels.AssetUpdate} asset * @param {{ ifMatch: string }} params * @param {{number}} [params.ifMatch] Last known version to facilitate optimistic locking. Required for modification. * @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 } = parameters; const result = yield this.HttpAction({ verb: "PUT", gateway: this.GetGateway(), authorization: yield this.GetToken(), baseUrl: `${this._baseUrl}/assets/${assetId}`, body: asset, additionalHeaders: { "If-Match": ifMatch } }); return result; }); } /** * * Asset * * Patch an asset with the provided content. * Only values can be modified, asset’s structure have to be modified in asset’s type. * Conforms to RFC 7396 - JSON merge Patch. * * @param {string} assetId * @param {AssetManagementModels.AssetUpdate} asset * @param {{ ifMatch: string }} params * @param {{number}} [params.ifMatch] Last known version to facilitate optimistic locking. Required for modification. * @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 } = parameters; const result = yield this.HttpAction({ verb: "PATCH", gateway: this.GetGateway(), authorization: yield this.GetToken(), baseUrl: `${this._baseUrl}/assets/${assetId}`, 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’s not possible to delete an asset if it has children. * * @param {string} id The type’s 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 }} params * @param {{number}} params.ifMatch Last known version to facilitate optimistic locking, required for deleting * * @example await assetManagement.DeleteAsset(id, {ifMatch:0}) * * @memberOf AssetManagementClient */ DeleteAsset(id, params) { return __awaiter(this, void 0, void 0, function* () { yield this.HttpAction({ verb: "DELETE", gateway: this.GetGateway(), authorization: yield this.GetToken(), baseUrl: `${this._baseUrl}/assets/${id}`, additionalHeaders: { "If-Match": params.ifMatch }, noResponse: true }); }); } /** * * Asset * * Save a file assignment to a given asset * * @param {string} id The type’s 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 {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 }} params * @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 } = parameters; const result = yield this.HttpAction({ verb: "PUT", gateway: this.GetGateway(), authorization: yield this.GetToken(), baseUrl: `${this._baseUrl}/assets/${id}/fileAssignments/${key}`, body: assignment, additionalHeaders: { "If-Match": ifMatch } }); return result; }); } /** * * Asset * * Deletes a file assignment from an asset. * If the asset’s parent type has defined a file with the same key, the key will be displayed with the inherited value. * * @param {string} id The type’s 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 {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 }} 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 } = parameters; yield this.HttpAction({ verb: "DELETE", gateway: this.GetGateway(), authorization: yield this.GetToken(), baseUrl: `${this._baseUrl}/assets/${id}/fileAssignments/${key}`, 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`, message: "PostAsset" }); 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; * }} [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.AspectListResource>} * * @memberOf AssetManagementClient */ GetAspects(assetId, 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}/assets/${assetId}/aspects?${utils_1.toQueryString({ page, size, sort, filter })}`, 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; * }} [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.AspectListResource>} * * @memberOf AssetManagementClient */ GetVariables(assetId, 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}/assets/${assetId}/variables?${utils_1.toQueryString({ page, size, sort, filter })}`, 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’s 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 {AssetManagementModels.Location} location Data for location * @param {{ ifMatch: string }} params * @param {{number}} params.ifMatch Last known version to facilitate optimistic locking * @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 } = parameters; const result = yield this.HttpAction({ verb: "PUT", gateway: this.GetGateway(), authorization: yield this.GetToken(), baseUrl: `${this._baseUrl}/assets/${id}/location`, 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’s 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 {AssetManagementModels.Location} location Data for location * @param {{ ifMatch: string }} params * @param {{number}} params.ifMatch Last known version to facilitate optimistic locking * @returns {Promise<AssetManagementModels.AssetResourceWithHierarchyPath>} * * @memberOf AssetManagementClient */ DeleteAssetLocation(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}/assets/${id}/location`, 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?${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; * }} [params] * @returns {Promise<Response>} Response Context Type is base64 * * @memberOf AssetManagementClient */ DownloadFile(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}/file`, additionalHeaders: { "If-None-Match": ifNoneMatch }, rawResponse: true }); return result; }); } /** * * Asset Files * * Update a previously uploaded file. * Max file size is 5 MB. * * @param {string} fileid * @param {Buffer} file * @param {string} name * @param {{ * scope: AssetManagementModels.FileMetadataResource.ScopeEnum; * description?: string; * mimeType?: string; * ifMatch: string; * }} params * @returns {Promise<AssetManagementModels.FileMetadataResource>} * * @memberOf AssetManagementClient */ PutFile(fileid, file, name, params) { return __awaiter(this, void 0, void 0, function* () { const parameters = params || {}; const { scope, description, mimeType, ifMatch } = 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}\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: "PUT", gateway: this.GetGateway(), authorization: yield this.GetToken(), baseUrl: `${this._baseUrl}/files/${fileid}`, body: template, multiPartFormData: true, additionalHeaders: { "If-Match": ifMatch } }); return result; }); } /** * * Asset Files * * Delete a file * Deletion is blocked if there are any file assignment with the given fileId. * * @param {string} fileId * @param {{ ifMatch: string }} params * * @memberOf AssetManagementClient */ DeleteFile(fileId, params) { return __awaiter(this, void 0, void 0, function* () { const parameters = params || {}; const { ifMatch } = parameters; yield this.HttpAction({ verb: "DELETE", gateway: this.GetGateway(), authorization: yield this.GetToken(), baseUrl: `${this._baseUrl}/files/${fileId}`, additionalHeaders: { "If-Match": ifMatch }, noResponse: true }); }); } /** * List all links for available resources * * @returns {Promise<AssetManagementModels.BillboardResource>} * * @memberOf AssetManagementClient */ GetBillboard() { 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}/` }); return result; }); } } exports.AssetManagementClient = AssetManagementClient; //# sourceMappingURL=asset-management.js.map