@c8y/ng1-modules 1023.14.68 → 1023.14.76

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- function _typeof(t){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function ownKeys(e,t){var n,r=Object.keys(e);return Object.getOwnPropertySymbols&&(n=Object.getOwnPropertySymbols(e),t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)),r}function _objectSpread(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?ownKeys(Object(n),!0).forEach(function(t){_defineProperty(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):ownKeys(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function _defineProperty(t,e,n){return(e=_toPropertyKey(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function _toPropertyKey(t){t=_toPrimitive(t,"string");return"symbol"==_typeof(t)?t:t+""}function _toPrimitive(t,e){if("object"!=_typeof(t)||!t)return t;var n=t[Symbol.toPrimitive];if(void 0===n)return("string"===e?String:Number)(t);n=n.call(t,e||"default");if("object"!=_typeof(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}(()=>{function t(i,o,r,u,a,k,I,c,B,p,t,s,l,f,e,F){var g,H=e("humanizeAppName"),d="application/",h="".concat(d,"applications"),m={headers:p.contentHeaders("application",!0)},y=this,$={HOSTED:"cloud",EXTERNAL:"external-link",SMARTAPP:"puzzle-piece",MICROSERVICE:"microchip",APAMA_CEP_RULE:"file-code-o"},z=["HOSTED","EXTERNAL"],K=["HOSTED","EXTERNAL"],q={HOSTED:f("Hosted application"),EXTERNAL:f("External application"),MICROSERVICE:f("Microservice"),APAMA_CEP_RULE:f("Apama CEP rule")},e=p.createEnum([{name:"UP",label:f("Up"),value:"Up",icon:"check-circle text-success"},{name:"DOWN",label:f("Down"),value:"Down",icon:"warning status critical"},{name:"UNHEALTHY",label:f("Unhealthy"),value:"Unhealth",icon:"exclamation-circle status major"},{name:"UNHEALTHY",label:f("Unhealthy"),value:"Unhealthy",icon:"exclamation-circle status major"}]),V=1e3,J=10;try{g=B.get("gettextCatalog")}catch(t){g={getString:_.identity}}function v(r,i){return t.current().then(function(t){var t=t.tenant,e=p.pageSizeFilter(i),n={params:e},t="".concat(p.url(r),"/").concat(t),e=p.cleanListCallback("applications",angular.bind(y,v,r),e);return o.get(t,n).then(e).then(it).then(E)})}function S(t){var e,n=t.desired,t=t.active;return e=n,{active:t=t,unhealthy:_.isNumber(t)?e-t:e,desired:n}}function b(i,a){return t.current().then(function(t){var t=i||t,e=p.pageSizeFilter(a),n={params:_.defaults(e,{noPaging:!0,dropOverwrittenApps:!0})},r=p.url("".concat(d,"applicationsByUser/").concat(encodeURIComponent(t.id))),t=p.cleanListCallback("applications",angular.bind(y,b,t),e);return o.get(r,n).then(t).then(it).then(E)})}function E(t){var e=_.sortBy(t,[function(t){return H(t)}]);return _.assign(e,_.pick(t,["statistics","paging"])),e}function n(t){return v("".concat(d,"applicationsByTenant"),t)}function A(t){var t=p.url("".concat(h,"/").concat(t.contextPath,"/manifest")),e={params:p.pageSizeNoTotalFilter()};return o.get(t,e).then(function(t){return _.map(t.data.imports,W)})}function P(t){var e=P.cache,n=t.id||t,r=p.url("".concat(h,"/").concat(n,"/binaries/plugins")),i={params:p.pageSizeNoTotalFilter()};function a(){delete e[n]}return e[n]||(e[n]=I(_.noop,2e3).then(function(){return o.get(r,i).then(p.getResData).finally(a)})),e[n]}function W(t){return{id:t.id,contextPath:t.rootContextPath,directoryName:t.directoryName,manifest:t}}function O(t){t=t.id||t;return p.url("".concat(h,"/").concat(t))}function D(t){t=O(t);return o.get(t)}function w(e,t){var n,r=O(e),t=(n=e,delete(n=_.cloneDeep(n)).type,_.defaults(t||{},m)),r=o.put(r,n,t).finally(function(){a.localStorage.setItem("refresh",e.contextPath)});return r.then(function(t){i.$emit("c8yApplication:update",{app:e,res:t})}),r}function j(e,t){var n=p.url(h),t=_.defaults(t||{},m),n=o.post(n,e,t);return n.then(function(t){return i.$emit("c8yApplication:create",{app:e,res:t})}).catch(function(){c.error("Could not emit c8yApplication:create for:",{app:e})}),n}function C(t,e){return(t.id?w:j)(t,e)}function M(n){var e,r=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},t=2<arguments.length?arguments[2]:void 0,i=J,a=(3<arguments.length?arguments[3]:void 0)||u.defer(),o=t||0,t=0===o?"":"-".concat(o);function c(t){return"".concat(t).concat(e)}return e=t,C(_objectSpread(_objectSpread({},t=n),{},{name:c(t.name),key:c(t.key),contextPath:c(t.contextPath)}),_objectSpread({silentError:!0},r)).then(function(t){a.resolve(p.getResData(t))},function(t){var e;409===t.status&&o<i?M(n,r,o+1,a):(e=(e=_.get(t,"data.message")||_.get(t,"data.details.exceptionMessage"))?g.getString(e):f("Could not create application."),t=t.data,a.reject({errorMessage:e,errorDetails:t}))}),a.promise}function R(n){var t=D(n).then(p.getResData);return u.all({appDetails:t,appPlugins:t.then(P).then(X),appManifest:t.then(L),appIndex:t.then(Y)}).then(function(t){t.appDetails;var e,n=t.appManifest,r=t.appIndex,t=(e=t.appPlugins,_(n.imports).map(function(t){return _.find(e,{pluginName:t})}).compact().concat(e).uniq().value());return u.all({newAppManifest:((t,e)=>((e=_.cloneDeep(e)).imports=_.map(t,"pluginName"),e))(t,n),newAppIndex:(t=((t,e)=>{var t=_(t).map(function(t){var e=_.get(t,"pluginPackage.css",[]);return!!(e.length?e:_.get(t,"pluginPackage.less",[])).length&&"".concat(t.pluginName,"/style.css")}).filter(_.identity).value(),n=_.flattenDeep(["\x3c!--MODULES_CSS--\x3e",_.map(t.slice(0,1),function(t){return'<link rel="stylesheet" href="'.concat(t,'"></link>')}),"\x3c!--/MODULES_CSS--\x3e"]).join("\n"),t=_.flattenDeep(["\x3c!--MODULES_CSS_DEFER--\x3e","<script>",["[",'"'.concat(t.slice(1).join('", "'),'"'),"].forEach(function(f){loadCSS(f)})"].join(""),"<\/script>","\x3c!--/MODULES_CSS_DEFER--\x3e"]).join("\n");return e=(e=e.replace(new RegExp("\x3c!--MODULES_CSS--\x3e(.|\\n|\\r)*\x3c!--\\/MODULES_CSS--\x3e","gm"),n)).replace(new RegExp("\x3c!--MODULES_CSS_DEFER--\x3e(.|\\n|\\r)*\x3c!--\\/MODULES_CSS_DEFER--\x3e","gm"),t)})(n=t,t=r),t=((t,e)=>(t=_.flattenDeep(["\x3c!--MODULES_JS--\x3e",_(t).map(function(t){return!!_.get(t,"pluginPackage.js",[]).length&&"".concat(t.pluginName,"/main.js")}).filter(_.identity).map(function(t){return'<script defer src="'.concat(t,'"><\/script>')}).value(),"\x3c!--/MODULES_JS--\x3e"]).join("\n"),e.replace(new RegExp("\x3c!--MODULES_JS--\x3e(.|\\n|\\r)*\x3c!--\\/MODULES_JS--\x3e","gm"),t)))(n,t),t=((t,e)=>(t=['C8Y_NG_MODULES=["',_.uniq(_.flattenDeep(_.map(t,function(t){return _.get(t,"pluginPackage.ngModules",[])}))).join('","'),'"];'].join(""),e.replace(new RegExp("C8Y_NG_MODULES=\\[(.|\\n|\\r)*?\\];","gm"),t)))(n,t))})}).then(function(t){var e=t.newAppManifest,t=t.newAppIndex;return Q(n,[{path:"cumulocity.json",file:new Blob([JSON.stringify(e)],{type:"application/json"})},{path:"index.html",file:new Blob([t],{type:"text/html"})}])})}function X(t){var e=[],n=_.sortBy(t,function(t){return-1*_.get(t,"pluginPackage.priority",0)});return _.forEach(n,function(t){!function n(t,r,i){var e=x(r,_.get(t,"pluginPackage.contextPath"));if(e)return;e=_.get(t,"pluginPackage.imports",[]);_.forEach(e,function(t){var e=x(i,t);e?n(e,r,i):c.error("Plugin with context path ".concat(t," is missing."))});r.push(t)}(t,e,n)}),e}function x(t,e){var n=(t=>t=(t=>/^core\//.test(t)||/^administration\//.test(t)||/^devicemanagement\//.test(t)||/^cockpit\//.test(t)||/^platformadmin\//.test(t)||/^fieldbus4\//.test(t)||/^fieldbus3\//.test(t)||/^fieldbus2\//.test(t)||/^fieldbus\//.test(t)||/^demoboard\//.test(t)||/^vendme_plugins\//.test(t))(t)?t.replace(/\//g,"_"):t)(e);return _.find(t,function(t){return t&&t.pluginPackage&&t.pluginPackage.contextPath===n})}function L(t){t="".concat(G(t),"/cumulocity.json");return o.get(t).then(p.getResData)}function Y(t){t="".concat(G(t),"/index.html");return o.get(t).then(p.getResData)}function G(t){return p.url("apps/".concat(t.contextPath))}function Q(t,e){var t="".concat(O(t),"/binaries/files"),n=new FormData;return _.forEach(e,function(t){n.append(t.path,new File([t.file],t.path))}),o.post(t,n,{transformRequest:_.identity,headers:{"Content-Type":void 0}})}function T(){var t=a.location.pathname.match(/\/apps\/(public\/){0,1}(.+?)(\/|\?|#|$)/);return t&&t[2]}function Z(){var t=a.location.pathname.match(/\/apps\/(public\/([^/]+)|([^/]+))/);return t&&-1!==t[1].indexOf("public")}function tt(){var n=T(),r=!!Z();function e(t){var e="MARKET"===t.availability;return t.contextPath===n&&(!r||e)}return b(null,{dropOverwrittenApps:!1}).then(function(t){return _.find(t,e)})}function et(e){return s.list({type:"c8y_SmartAppApplication"}).then(function(t){return _.find(t,{appId:e.id})||null})}function nt(t){var e;return(t?u.resolve(t):tt()).then(function(t){return e=t}).then(et).then(function(t){return e.config=t,e})}function rt(t){return _(t).uniq("id").filter(function(t){var e=t.manifest,n=!1;return!(n=e?e.noAppSwitcher:n)&&_.includes(["HOSTED","EXTERNAL"],t.type)}).value()}function it(t){var e=_.reject(t,function(t){return"management"===t.name&&"management"===t.owner.tenant.id});return _.assign(e,_.pick(t,_.filter(_.keys(t),function(t){return _.isNaN(_.toNumber(t))}))),e}function U(t,e){var n,e=_.isString(e)?(n=e,function(t){return t.name===n||t.contextPath===n||t.key===n}):e;return _.some(t,e)}function at(t){return"HOSTED"===t.type}function N(){return N.cache||o(e([p.url(h),(Z()?"public/":"")+T(),"manifest"].join("/"))).then(function(t){return o(e([p.url(h),t.data.application.id].join("/")))}).then(p.getResData).then(function(t){return N.cache=u.when(t),N.cache});function e(t){return{url:t,noAppKey:!0}}}return P.cache={},p.getFlag("test")&&(N.cache=u.when({name:"app",manifest:{}})),{list:n,listByUser:b,listByTenant:n,listByOwner:function(t){return v("".concat(d,"applicationsByOwner"),t)},listPlugins:function(){var t=p.url("".concat(d,"plugins"));return o.get(t,{params:{pageSize:V}}).then(function(t){return _.uniqBy(t.data.plugins,"id")})},listPluginsByTenant:function(){return n().then(function(t){var t=_.uniqBy(t,"id"),e=[];return _.forEach(t,function(t){at(t)&&e.push(A(t))}),u.all(e).then(_.flattenDeep).then(function(t){return _.uniqBy(t,"id")})})},listPluginsByApplication:A,listPluginsByPaasApp:P,listByVisibleLinks:function(){return b().then(rt).then(function(t){return u.when(t)})},listApplications:function t(e){var n=p.url("".concat(h)),r={params:p.pageSizeFilter(e)},e=p.cleanListCallback("applications",t,e);return o.get(n,r).then(e).then(E)},getApplicationMO:function(t){return t="c8y_Application_".concat(t),s.list({type:t}).then(function(t){return _.head(t)})},getApplicationMOs:function(t){var e=(t=t||{}).tenantId,t=void 0===(t=t.filters)?{}:t,n={type:"c8y_Application_*"};return e&&(n=F.addAndFilter(n,{__has:"c8y_Subscriptions.".concat(e)})),s.listQuery(n,t,!0)},getInstanceCounts:S,getSubscriptionsList:function(t){return t=_.get(t,"c8y_Subscriptions"),_.reduce(t,function(t,e,n){var r=_.get(e,"details"),e=_.get(e,"status"),r=S(r);return t.concat(_objectSpread(_objectSpread({},r),{},{tenantName:n,status:e}))},[])},getApplicationStatusForTenant:function(t,e){return _.get(t,["c8y_Subscriptions",e])},status:e,isAvailable:function(e){return b().then(function(t){return U(t,e)})},areAllAvailable:function(t){return b().then(function(e){return _.every(t,function(t){return U(e,t)})})},isAnyAvailable:function(t){return b().then(function(e){return _.some(t,function(t){return U(e,t)})})},detail:D,update:w,create:j,remove:function(e){var t=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},n=O(e),r=nt(_.isObjectLike(e)?e:{id:e}).then(function(t){return!_.get(t,"config.id")||s.remove(t.config)}),n=o.delete(n,{params:t});return(t=u.all({cfg:r,res:n})).then(function(t){t=t.res;i.$emit("c8yApplication:delete",{app:e,res:t})}),t},save:C,trySave:M,clone:function(t,e){return t="".concat(O(t),"/clone"),o.post(t).then(p.getResData).then(function(t){return _.isObjectLike(e)?(_.assign(t,e),M(t).then(p.getResData)):t})},getHref:function(t){return at(t)?(e=t,n=80===(n=r.port())||443===n?"":":".concat(n),"".concat(r.protocol(),"://").concat(r.host()).concat(n,"/apps/").concat(e.public?"public/":"").concat(e.contextPath)):t.externalUrl;var e,n},isHosted:function(t){return"HOSTED"===t.type},isApamaCepRule:function(t){return"APAMA_CEP_RULE"===_.get(t,"type")},isMicroserviceWithManifest:function(e){return s.list({type:"c8y_microservice_manifest_".concat(e.id)}).then(function(t){return"MICROSERVICE"===e.type&&0<t.length})},canOpenInBrowser:function(t){return(_.isObjectLike(t)?u.resolve(t):D(t).then(p.getResData)).then(function(t){var e=!t.name.match(/feature-/),t=_.includes(z,t.type);return e&&t})},canAddPlugin:function(t){return console.warning("This method is now deprecated. Consider using Web SDK to customize and extend applications."),(_.isObjectLike(t)?u.resolve(t):D(t).then(function(t){return t.data})).then(function(t){return!_.isEmpty(t.manifest)&&_.includes(K,_.get(t,"type"))})},icon:function(t){var e=_.isString(t)?t:t.type;return t.manifest&&"MICROSERVICE"!==e&&(e="SMARTAPP"),$[e]},typeLabel:function(t){return t=_.isString(t)?t:t.type,q[t]},getCurrent:tt,getConfig:nt,pollRefreshMessages:function(){k(function(){var t;a.localStorage.getItem("refresh")===T()&&(a.localStorage.setItem("refresh",void 0),t||a.location.reload())},1e3,0,!1)},getCurrentContextPath:T,updateManifest:function(t,e){return D(t).then(function(t){t=t.data;return t.manifest=e,t}).then(w)},listArchives:function(t,e){return t="".concat(O(t),"/binaries"),e=p.pageSizeNoTotalFilter(e),o.get(t,{params:e,silentError:!0}).then(p.getResData)},uploadArchive:function(t,e){var n=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{},t={url:"".concat(O(t),"/binaries"),method:"POST",headers:{Content:"multipart/form-data",Accept:"application/json"},file:e,fileName:e.name.replace(/\s+/g,"_")};return _.assign(t,n),l.upload(t)},deleteArchive:function(t,e){return e=e.id||e,t=[O(t),"binaries",e].join("/"),o.delete(t)},setActiveArchive:function(t,e){return C({id:t.id,activeVersionId:e.id})},addPaasAppPlugin:function(t,e){console.warning("This method is now deprecated. Consider using Web SDK to customize and extend applications.");var n=(t=>((t=t.name.split(".")).pop(),t.join(".")))(e),n="".concat(O(t),"/binaries/plugins/").concat(n),n=l.upload({url:n,method:"POST",headers:{Content:"multipart/form-data",Accept:"application/json"},file:e});return(e=n.then(_.partial(R,t))).progress=n.progress,e},removePaasAppPlugin:function(t,e){return console.warning("This method is now deprecated. Consider using Web SDK to customize and extend applications."),e=e.pluginName||e,e="".concat(O(t),"/binaries/plugins/").concat(e),o.delete(e).then(_.partial(R,t))},uploadPaasAppFiles:Q,getPaasAppManifest:L,refreshPaasApp:R,refreshHostedApp:function(t){return t="".concat(O(t),"/refresh"),o.post(t)},isPaasApp:function(t){return L(t).then(function(t){return t._webpaas},function(){return!1})},parseAppName:function(t){var e=t&&t.toLowerCase();return"devicemanagement"===e?"Device Management":"digital-twin-manager"===e?"Digital Twin Manager":t||"Cumulocity"},currentAppCached:N,sortApps:E,isAppOnTheList:U}}t.$inject=["$rootScope","$http","$location","$q","$window","$interval","$timeout","$log","$injector","c8yBase","c8yUser","c8yInventory","$upload","gettext","$filter","c8yQueriesUtil"],angular.module("c8y.core").factory("c8yApplication",t)})();
1
+ function _typeof(t){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function ownKeys(e,t){var n,r=Object.keys(e);return Object.getOwnPropertySymbols&&(n=Object.getOwnPropertySymbols(e),t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)),r}function _objectSpread(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?ownKeys(Object(n),!0).forEach(function(t){_defineProperty(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):ownKeys(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function _defineProperty(t,e,n){return(e=_toPropertyKey(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function _toPropertyKey(t){t=_toPrimitive(t,"string");return"symbol"==_typeof(t)?t:t+""}function _toPrimitive(t,e){if("object"!=_typeof(t)||!t)return t;var n=t[Symbol.toPrimitive];if(void 0===n)return("string"===e?String:Number)(t);n=n.call(t,e||"default");if("object"!=_typeof(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}(()=>{function t(i,o,r,u,a,k,I,c,B,p,t,s,l,f,e,F){var g,H=e("humanizeAppName"),d="application/",h="".concat(d,"applications"),m={headers:p.contentHeaders("application",!0)},y=this,$={HOSTED:"cloud",EXTERNAL:"external-link",SMARTAPP:"puzzle-piece",MICROSERVICE:"microchip",APAMA_CEP_RULE:"file-code-o"},z=["HOSTED","EXTERNAL"],K=["HOSTED","EXTERNAL"],q={HOSTED:f("Hosted application"),EXTERNAL:f("External application"),MICROSERVICE:f("Microservice"),APAMA_CEP_RULE:f("Apama CEP rule")},e=p.createEnum([{name:"UP",label:f("Up`service status`"),value:"Up",icon:"check-circle text-success"},{name:"DOWN",label:f("Down`service status`"),value:"Down",icon:"warning status critical"},{name:"UNHEALTHY",label:f("Unhealthy"),value:"Unhealth",icon:"exclamation-circle status major"},{name:"UNHEALTHY",label:f("Unhealthy"),value:"Unhealthy",icon:"exclamation-circle status major"}]),V=1e3,J=10;try{g=B.get("gettextCatalog")}catch(t){g={getString:_.identity}}function v(r,i){return t.current().then(function(t){var t=t.tenant,e=p.pageSizeFilter(i),n={params:e},t="".concat(p.url(r),"/").concat(t),e=p.cleanListCallback("applications",angular.bind(y,v,r),e);return o.get(t,n).then(e).then(it).then(E)})}function S(t){var e,n=t.desired,t=t.active;return e=n,{active:t=t,unhealthy:_.isNumber(t)?e-t:e,desired:n}}function b(i,a){return t.current().then(function(t){var t=i||t,e=p.pageSizeFilter(a),n={params:_.defaults(e,{noPaging:!0,dropOverwrittenApps:!0})},r=p.url("".concat(d,"applicationsByUser/").concat(encodeURIComponent(t.id))),t=p.cleanListCallback("applications",angular.bind(y,b,t),e);return o.get(r,n).then(t).then(it).then(E)})}function E(t){var e=_.sortBy(t,[function(t){return H(t)}]);return _.assign(e,_.pick(t,["statistics","paging"])),e}function n(t){return v("".concat(d,"applicationsByTenant"),t)}function A(t){var t=p.url("".concat(h,"/").concat(t.contextPath,"/manifest")),e={params:p.pageSizeNoTotalFilter()};return o.get(t,e).then(function(t){return _.map(t.data.imports,W)})}function P(t){var e=P.cache,n=t.id||t,r=p.url("".concat(h,"/").concat(n,"/binaries/plugins")),i={params:p.pageSizeNoTotalFilter()};function a(){delete e[n]}return e[n]||(e[n]=I(_.noop,2e3).then(function(){return o.get(r,i).then(p.getResData).finally(a)})),e[n]}function W(t){return{id:t.id,contextPath:t.rootContextPath,directoryName:t.directoryName,manifest:t}}function O(t){t=t.id||t;return p.url("".concat(h,"/").concat(t))}function D(t){t=O(t);return o.get(t)}function w(e,t){var n,r=O(e),t=(n=e,delete(n=_.cloneDeep(n)).type,_.defaults(t||{},m)),r=o.put(r,n,t).finally(function(){a.localStorage.setItem("refresh",e.contextPath)});return r.then(function(t){i.$emit("c8yApplication:update",{app:e,res:t})}),r}function j(e,t){var n=p.url(h),t=_.defaults(t||{},m),n=o.post(n,e,t);return n.then(function(t){return i.$emit("c8yApplication:create",{app:e,res:t})}).catch(function(){c.error("Could not emit c8yApplication:create for:",{app:e})}),n}function C(t,e){return(t.id?w:j)(t,e)}function M(n){var e,r=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},t=2<arguments.length?arguments[2]:void 0,i=J,a=(3<arguments.length?arguments[3]:void 0)||u.defer(),o=t||0,t=0===o?"":"-".concat(o);function c(t){return"".concat(t).concat(e)}return e=t,C(_objectSpread(_objectSpread({},t=n),{},{name:c(t.name),key:c(t.key),contextPath:c(t.contextPath)}),_objectSpread({silentError:!0},r)).then(function(t){a.resolve(p.getResData(t))},function(t){var e;409===t.status&&o<i?M(n,r,o+1,a):(e=(e=_.get(t,"data.message")||_.get(t,"data.details.exceptionMessage"))?g.getString(e):f("Could not create application."),t=t.data,a.reject({errorMessage:e,errorDetails:t}))}),a.promise}function R(n){var t=D(n).then(p.getResData);return u.all({appDetails:t,appPlugins:t.then(P).then(X),appManifest:t.then(L),appIndex:t.then(Y)}).then(function(t){t.appDetails;var e,n=t.appManifest,r=t.appIndex,t=(e=t.appPlugins,_(n.imports).map(function(t){return _.find(e,{pluginName:t})}).compact().concat(e).uniq().value());return u.all({newAppManifest:((t,e)=>((e=_.cloneDeep(e)).imports=_.map(t,"pluginName"),e))(t,n),newAppIndex:(t=((t,e)=>{var t=_(t).map(function(t){var e=_.get(t,"pluginPackage.css",[]);return!!(e.length?e:_.get(t,"pluginPackage.less",[])).length&&"".concat(t.pluginName,"/style.css")}).filter(_.identity).value(),n=_.flattenDeep(["\x3c!--MODULES_CSS--\x3e",_.map(t.slice(0,1),function(t){return'<link rel="stylesheet" href="'.concat(t,'"></link>')}),"\x3c!--/MODULES_CSS--\x3e"]).join("\n"),t=_.flattenDeep(["\x3c!--MODULES_CSS_DEFER--\x3e","<script>",["[",'"'.concat(t.slice(1).join('", "'),'"'),"].forEach(function(f){loadCSS(f)})"].join(""),"<\/script>","\x3c!--/MODULES_CSS_DEFER--\x3e"]).join("\n");return e=(e=e.replace(new RegExp("\x3c!--MODULES_CSS--\x3e(.|\\n|\\r)*\x3c!--\\/MODULES_CSS--\x3e","gm"),n)).replace(new RegExp("\x3c!--MODULES_CSS_DEFER--\x3e(.|\\n|\\r)*\x3c!--\\/MODULES_CSS_DEFER--\x3e","gm"),t)})(n=t,t=r),t=((t,e)=>(t=_.flattenDeep(["\x3c!--MODULES_JS--\x3e",_(t).map(function(t){return!!_.get(t,"pluginPackage.js",[]).length&&"".concat(t.pluginName,"/main.js")}).filter(_.identity).map(function(t){return'<script defer src="'.concat(t,'"><\/script>')}).value(),"\x3c!--/MODULES_JS--\x3e"]).join("\n"),e.replace(new RegExp("\x3c!--MODULES_JS--\x3e(.|\\n|\\r)*\x3c!--\\/MODULES_JS--\x3e","gm"),t)))(n,t),t=((t,e)=>(t=['C8Y_NG_MODULES=["',_.uniq(_.flattenDeep(_.map(t,function(t){return _.get(t,"pluginPackage.ngModules",[])}))).join('","'),'"];'].join(""),e.replace(new RegExp("C8Y_NG_MODULES=\\[(.|\\n|\\r)*?\\];","gm"),t)))(n,t))})}).then(function(t){var e=t.newAppManifest,t=t.newAppIndex;return Q(n,[{path:"cumulocity.json",file:new Blob([JSON.stringify(e)],{type:"application/json"})},{path:"index.html",file:new Blob([t],{type:"text/html"})}])})}function X(t){var e=[],n=_.sortBy(t,function(t){return-1*_.get(t,"pluginPackage.priority",0)});return _.forEach(n,function(t){!function n(t,r,i){var e=x(r,_.get(t,"pluginPackage.contextPath"));if(e)return;e=_.get(t,"pluginPackage.imports",[]);_.forEach(e,function(t){var e=x(i,t);e?n(e,r,i):c.error("Plugin with context path ".concat(t," is missing."))});r.push(t)}(t,e,n)}),e}function x(t,e){var n=(t=>t=(t=>/^core\//.test(t)||/^administration\//.test(t)||/^devicemanagement\//.test(t)||/^cockpit\//.test(t)||/^platformadmin\//.test(t)||/^fieldbus4\//.test(t)||/^fieldbus3\//.test(t)||/^fieldbus2\//.test(t)||/^fieldbus\//.test(t)||/^demoboard\//.test(t)||/^vendme_plugins\//.test(t))(t)?t.replace(/\//g,"_"):t)(e);return _.find(t,function(t){return t&&t.pluginPackage&&t.pluginPackage.contextPath===n})}function L(t){t="".concat(G(t),"/cumulocity.json");return o.get(t).then(p.getResData)}function Y(t){t="".concat(G(t),"/index.html");return o.get(t).then(p.getResData)}function G(t){return p.url("apps/".concat(t.contextPath))}function Q(t,e){var t="".concat(O(t),"/binaries/files"),n=new FormData;return _.forEach(e,function(t){n.append(t.path,new File([t.file],t.path))}),o.post(t,n,{transformRequest:_.identity,headers:{"Content-Type":void 0}})}function T(){var t=a.location.pathname.match(/\/apps\/(public\/){0,1}(.+?)(\/|\?|#|$)/);return t&&t[2]}function Z(){var t=a.location.pathname.match(/\/apps\/(public\/([^/]+)|([^/]+))/);return t&&-1!==t[1].indexOf("public")}function tt(){var n=T(),r=!!Z();function e(t){var e="MARKET"===t.availability;return t.contextPath===n&&(!r||e)}return b(null,{dropOverwrittenApps:!1}).then(function(t){return _.find(t,e)})}function et(e){return s.list({type:"c8y_SmartAppApplication"}).then(function(t){return _.find(t,{appId:e.id})||null})}function nt(t){var e;return(t?u.resolve(t):tt()).then(function(t){return e=t}).then(et).then(function(t){return e.config=t,e})}function rt(t){return _(t).uniq("id").filter(function(t){var e=t.manifest,n=!1;return!(n=e?e.noAppSwitcher:n)&&_.includes(["HOSTED","EXTERNAL"],t.type)}).value()}function it(t){var e=_.reject(t,function(t){return"management"===t.name&&"management"===t.owner.tenant.id});return _.assign(e,_.pick(t,_.filter(_.keys(t),function(t){return _.isNaN(_.toNumber(t))}))),e}function U(t,e){var n,e=_.isString(e)?(n=e,function(t){return t.name===n||t.contextPath===n||t.key===n}):e;return _.some(t,e)}function at(t){return"HOSTED"===t.type}function N(){return N.cache||o(e([p.url(h),(Z()?"public/":"")+T(),"manifest"].join("/"))).then(function(t){return o(e([p.url(h),t.data.application.id].join("/")))}).then(p.getResData).then(function(t){return N.cache=u.when(t),N.cache});function e(t){return{url:t,noAppKey:!0}}}return P.cache={},p.getFlag("test")&&(N.cache=u.when({name:"app",manifest:{}})),{list:n,listByUser:b,listByTenant:n,listByOwner:function(t){return v("".concat(d,"applicationsByOwner"),t)},listPlugins:function(){var t=p.url("".concat(d,"plugins"));return o.get(t,{params:{pageSize:V}}).then(function(t){return _.uniqBy(t.data.plugins,"id")})},listPluginsByTenant:function(){return n().then(function(t){var t=_.uniqBy(t,"id"),e=[];return _.forEach(t,function(t){at(t)&&e.push(A(t))}),u.all(e).then(_.flattenDeep).then(function(t){return _.uniqBy(t,"id")})})},listPluginsByApplication:A,listPluginsByPaasApp:P,listByVisibleLinks:function(){return b().then(rt).then(function(t){return u.when(t)})},listApplications:function t(e){var n=p.url("".concat(h)),r={params:p.pageSizeFilter(e)},e=p.cleanListCallback("applications",t,e);return o.get(n,r).then(e).then(E)},getApplicationMO:function(t){return t="c8y_Application_".concat(t),s.list({type:t}).then(function(t){return _.head(t)})},getApplicationMOs:function(t){var e=(t=t||{}).tenantId,t=void 0===(t=t.filters)?{}:t,n={type:"c8y_Application_*"};return e&&(n=F.addAndFilter(n,{__has:"c8y_Subscriptions.".concat(e)})),s.listQuery(n,t,!0)},getInstanceCounts:S,getSubscriptionsList:function(t){return t=_.get(t,"c8y_Subscriptions"),_.reduce(t,function(t,e,n){var r=_.get(e,"details"),e=_.get(e,"status"),r=S(r);return t.concat(_objectSpread(_objectSpread({},r),{},{tenantName:n,status:e}))},[])},getApplicationStatusForTenant:function(t,e){return _.get(t,["c8y_Subscriptions",e])},status:e,isAvailable:function(e){return b().then(function(t){return U(t,e)})},areAllAvailable:function(t){return b().then(function(e){return _.every(t,function(t){return U(e,t)})})},isAnyAvailable:function(t){return b().then(function(e){return _.some(t,function(t){return U(e,t)})})},detail:D,update:w,create:j,remove:function(e){var t=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},n=O(e),r=nt(_.isObjectLike(e)?e:{id:e}).then(function(t){return!_.get(t,"config.id")||s.remove(t.config)}),n=o.delete(n,{params:t});return(t=u.all({cfg:r,res:n})).then(function(t){t=t.res;i.$emit("c8yApplication:delete",{app:e,res:t})}),t},save:C,trySave:M,clone:function(t,e){return t="".concat(O(t),"/clone"),o.post(t).then(p.getResData).then(function(t){return _.isObjectLike(e)?(_.assign(t,e),M(t).then(p.getResData)):t})},getHref:function(t){return at(t)?(e=t,n=80===(n=r.port())||443===n?"":":".concat(n),"".concat(r.protocol(),"://").concat(r.host()).concat(n,"/apps/").concat(e.public?"public/":"").concat(e.contextPath)):t.externalUrl;var e,n},isHosted:function(t){return"HOSTED"===t.type},isApamaCepRule:function(t){return"APAMA_CEP_RULE"===_.get(t,"type")},isMicroserviceWithManifest:function(e){return s.list({type:"c8y_microservice_manifest_".concat(e.id)}).then(function(t){return"MICROSERVICE"===e.type&&0<t.length})},canOpenInBrowser:function(t){return(_.isObjectLike(t)?u.resolve(t):D(t).then(p.getResData)).then(function(t){var e=!t.name.match(/feature-/),t=_.includes(z,t.type);return e&&t})},canAddPlugin:function(t){return console.warning("This method is now deprecated. Consider using Web SDK to customize and extend applications."),(_.isObjectLike(t)?u.resolve(t):D(t).then(function(t){return t.data})).then(function(t){return!_.isEmpty(t.manifest)&&_.includes(K,_.get(t,"type"))})},icon:function(t){var e=_.isString(t)?t:t.type;return t.manifest&&"MICROSERVICE"!==e&&(e="SMARTAPP"),$[e]},typeLabel:function(t){return t=_.isString(t)?t:t.type,q[t]},getCurrent:tt,getConfig:nt,pollRefreshMessages:function(){k(function(){var t;a.localStorage.getItem("refresh")===T()&&(a.localStorage.setItem("refresh",void 0),t||a.location.reload())},1e3,0,!1)},getCurrentContextPath:T,updateManifest:function(t,e){return D(t).then(function(t){t=t.data;return t.manifest=e,t}).then(w)},listArchives:function(t,e){return t="".concat(O(t),"/binaries"),e=p.pageSizeNoTotalFilter(e),o.get(t,{params:e,silentError:!0}).then(p.getResData)},uploadArchive:function(t,e){var n=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{},t={url:"".concat(O(t),"/binaries"),method:"POST",headers:{Content:"multipart/form-data",Accept:"application/json"},file:e,fileName:e.name.replace(/\s+/g,"_")};return _.assign(t,n),l.upload(t)},deleteArchive:function(t,e){return e=e.id||e,t=[O(t),"binaries",e].join("/"),o.delete(t)},setActiveArchive:function(t,e){return C({id:t.id,activeVersionId:e.id})},addPaasAppPlugin:function(t,e){console.warning("This method is now deprecated. Consider using Web SDK to customize and extend applications.");var n=(t=>((t=t.name.split(".")).pop(),t.join(".")))(e),n="".concat(O(t),"/binaries/plugins/").concat(n),n=l.upload({url:n,method:"POST",headers:{Content:"multipart/form-data",Accept:"application/json"},file:e});return(e=n.then(_.partial(R,t))).progress=n.progress,e},removePaasAppPlugin:function(t,e){return console.warning("This method is now deprecated. Consider using Web SDK to customize and extend applications."),e=e.pluginName||e,e="".concat(O(t),"/binaries/plugins/").concat(e),o.delete(e).then(_.partial(R,t))},uploadPaasAppFiles:Q,getPaasAppManifest:L,refreshPaasApp:R,refreshHostedApp:function(t){return t="".concat(O(t),"/refresh"),o.post(t)},isPaasApp:function(t){return L(t).then(function(t){return t._webpaas},function(){return!1})},parseAppName:function(t){var e=t&&t.toLowerCase();return"devicemanagement"===e?"Device Management":"digital-twin-manager"===e?"Digital Twin Manager":t||"Cumulocity"},currentAppCached:N,sortApps:E,isAppOnTheList:U}}t.$inject=["$rootScope","$http","$location","$q","$window","$interval","$timeout","$log","$injector","c8yBase","c8yUser","c8yInventory","$upload","gettext","$filter","c8yQueriesUtil"],angular.module("c8y.core").factory("c8yApplication",t)})();