@c8y/client 1017.44.0 → 1017.46.0

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,2 +1,2 @@
1
- !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e(t.cumulocity={})}(this,function(t){"use strict";var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function n(t,e){return t(e={exports:{}},e.exports),e.exports}var i,r=n(function(t,e){t.exports=function(){var t={isString:function(t){return void 0!==t&&null!==t&&("string"==typeof t||t instanceof String)},isArray:function(t){return void 0!==t&&null!==t&&t instanceof Array},inArray:function(t,e){for(var n=0;n<e.length;++n)if(t===e[n])return n;return-1}},e=function(){var e,n,i;this.registered=function(t,i){e=t,n=i},this.unregistered=function(){e=null,n=null},this._debug=function(){n._debug.apply(n,arguments)},this._mixin=function(){return n._mixin.apply(n,arguments)},this.getConfiguration=function(){return n.getConfiguration()},this.getAdvice=function(){return n.getAdvice()},this.setTimeout=function(t,e){return n.setTimeout(t,e)},this.clearTimeout=function(t){n.clearTimeout(t)},this.convertToMessages=function(e){if(t.isString(e))try{return JSON.parse(e)}catch(t){throw this._debug("Could not convert to JSON the following string",'"'+e+'"'),t}if(t.isArray(e))return e;if(void 0===e||null===e)return[];if(e instanceof Object)return[e];throw"Conversion Error "+e+", typeof "+typeof e},this.accept=function(t,e,n){throw"Abstract"},this.getType=function(){return e},this.getURL=function(){return i},this.setURL=function(t){i=t},this.send=function(t,e){throw"Abstract"},this.reset=function(t){this._debug("Transport",e,"reset",t?"initial":"retry")},this.abort=function(){this._debug("Transport",e,"aborted")},this.toString=function(){return this.getType()}};e.derive=function(t){function e(){}return e.prototype=t,new e};var n=function(){var n=new e,i=e.derive(n),r=0,s=null,o=[],a=[];function c(t,e){if(this.transportSend(t,e),e.expired=!1,!t.sync){var n=this.getConfiguration().maxNetworkDelay,i=n;!0===e.metaConnect&&(i+=this.getAdvice().timeout),this._debug("Transport",this.getType(),"waiting at most",i,"ms for the response, maxNetworkDelay",n);var r=this;e.timeout=this.setTimeout(function(){e.expired=!0;var n="Request "+e.id+" of transport "+r.getType()+" exceeded "+i+" ms max network delay",s={reason:n},o=e.xhr;s.httpCode=r.xhrStatus(o),r.abortXHR(o),r._debug(n),r.complete(e,!1,e.metaConnect),t.onFailure(o,t.messages,s)},i)}}function u(t){var e=++r,n={id:e,metaConnect:!1,envelope:t};o.length<this.getConfiguration().maxConnections-1?(o.push(n),c.call(this,t,n)):(this._debug("Transport",this.getType(),"queueing request",e,"envelope",t),a.push([t,n]))}function l(e,n){var i=t.inArray(e,o);if(i>=0&&o.splice(i,1),a.length>0){var r=a.shift(),s=r[0],c=r[1];if(this._debug("Transport dequeued request",c.id),n)this.getConfiguration().autoBatch&&function(t){for(;a.length>0;){var e=a[0],n=e[0],i=e[1];if(n.url!==t.url||n.sync!==t.sync)break;a.shift(),t.messages=t.messages.concat(n.messages),this._debug("Coalesced",n.messages.length,"messages from request",i.id)}}.call(this,s),u.call(this,s),this._debug("Transport completed request",e.id,s);else{var l=this;this.setTimeout(function(){l.complete(c,!1,c.metaConnect);var t={reason:"Previous request failed"},e=c.xhr;t.httpCode=l.xhrStatus(e),s.onFailure(e,s.messages,t)},0)}}}return i.complete=function(t,e,n){n?function(t){var e=t.id;if(this._debug("Transport",this.getType(),"/meta/connect complete, request",e),null!==s&&s.id!==e)throw"/meta/connect request mismatch, completing request "+e;s=null}.call(this,t):l.call(this,t,e)},i.transportSend=function(t,e){throw"Abstract"},i.transportSuccess=function(t,e,n){e.expired||(this.clearTimeout(e.timeout),this.complete(e,!0,e.metaConnect),n&&n.length>0?t.onSuccess(n):t.onFailure(e.xhr,t.messages,{httpCode:204}))},i.transportFailure=function(t,e,n){e.expired||(this.clearTimeout(e.timeout),this.complete(e,!1,e.metaConnect),t.onFailure(e.xhr,t.messages,n))},i.send=function(t,e){e?function(t){if(null!==s)throw"Concurrent /meta/connect requests not allowed, request id="+s.id+" not yet completed";var e=++r;this._debug("Transport",this.getType(),"/meta/connect send, request",e,"envelope",t);var n={id:e,metaConnect:!0,envelope:t};c.call(this,t,n),s=n}.call(this,t):u.call(this,t)},i.abort=function(){n.abort();for(var t=0;t<o.length;++t){var e=o[t];e&&(this._debug("Aborting request",e),this.abortXHR(e.xhr)||this.transportFailure(e.envelope,e,{reason:"abort"}))}var i=s;i&&(this._debug("Aborting /meta/connect request",i),this.abortXHR(i.xhr)||this.transportFailure(i.envelope,i,{reason:"abort"})),this.reset(!0)},i.reset=function(t){n.reset(t),s=null,o=[],a=[]},i.abortXHR=function(t){if(t)try{var e=t.readyState;return t.abort(),e!==window.XMLHttpRequest.UNSENT}catch(t){this._debug(t)}return!1},i.xhrStatus=function(t){if(t)try{return t.status}catch(t){this._debug(t)}return-1},i},i=function(){var t=new n,i=e.derive(t),r=!0;return i.accept=function(t,e,n){return r||!e},i.newXMLHttpRequest=function(){return new window.XMLHttpRequest},i.xhrSend=function(t){var e=i.newXMLHttpRequest();!function(t){try{t.context=i.context}catch(t){this._debug("Could not copy transport context into XHR",t)}}(e),e.withCredentials=!0,e.open("POST",t.url,!0!==t.sync);var n=t.headers;if(n)for(var r in n)n.hasOwnProperty(r)&&e.setRequestHeader(r,n[r]);return e.setRequestHeader("Content-Type","application/json;charset=UTF-8"),e.onload=function(){200===e.status?t.onSuccess(e.responseText):t.onError(e.statusText)},e.onabort=e.onerror=function(){t.onError(e.statusText)},e.send(t.body),e},i.transportSend=function(t,e){this._debug("Transport",this.getType(),"sending request",e.id,"envelope",t);var n=this;try{var i=!0;e.xhr=this.xhrSend({transport:this,url:t.url,sync:t.sync,headers:this.getConfiguration().requestHeaders,body:JSON.stringify(t.messages),onSuccess:function(i){n._debug("Transport",n.getType(),"received response",i);var s=!1;try{var o=n.convertToMessages(i);0===o.length?(r=!1,n.transportFailure(t,e,{httpCode:204})):(s=!0,n.transportSuccess(t,e,o))}catch(i){if(n._debug(i),!s){r=!1;var a={exception:i};a.httpCode=n.xhrStatus(e.xhr),n.transportFailure(t,e,a)}}},onError:function(s,o){n._debug("Transport",n.getType(),"received error",s,o),r=!1;var a={reason:s,exception:o};a.httpCode=n.xhrStatus(e.xhr),i?n.setTimeout(function(){n.transportFailure(t,e,a)},0):n.transportFailure(t,e,a)}}),i=!1}catch(i){r=!1,this.setTimeout(function(){n.transportFailure(t,e,{exception:i})},0)}},i.reset=function(e){t.reset(e),r=!0},i},r=function(){var t=new n,i=e.derive(t),r=0;function s(t,e,n){var i=this;return function(){i.transportFailure(t,e,"error",n)}}return i.accept=function(t,e,n){return!0},i.jsonpSend=function(t){var e=document.getElementsByTagName("head")[0],n=document.createElement("script"),i="_cometd_jsonp_"+r++;window[i]=function(r){e.removeChild(n),delete window[i],t.onSuccess(r)};var s=t.url;s+=s.indexOf("?")<0?"?":"&",s+="jsonp="+i,s+="&message="+encodeURIComponent(t.body),n.src=s,n.async=!0!==t.sync,n.type="application/javascript",n.onerror=function(e){t.onError("jsonp "+e.type)},e.appendChild(n)},i.transportSend=function(t,e){for(var n=this,i=0,r=t.messages.length,o=[];r>0;){var a=JSON.stringify(t.messages.slice(i,i+r)),c=t.url.length+encodeURI(a).length,u=this.getConfiguration().maxURILength;if(c>u){if(1===r){var l="Bayeux message too big ("+c+" bytes, max is "+u+") for transport "+this.getType();return void this.setTimeout(s.call(this,t,e,l),0)}--r}else o.push(r),i+=r,r=t.messages.length-i}var d=t;if(o.length>1){var h=0,p=o[0];this._debug("Transport",this.getType(),"split",t.messages.length,"messages into",o.join(" + ")),(d=this._mixin(!1,{},t)).messages=t.messages.slice(h,p),d.onSuccess=t.onSuccess,d.onFailure=t.onFailure;for(var f=1;f<o.length;++f){var v=this._mixin(!1,{},t);h=p,p+=o[f],v.messages=t.messages.slice(h,p),v.onSuccess=t.onSuccess,v.onFailure=t.onFailure,this.send(v,e.metaConnect)}}this._debug("Transport",this.getType(),"sending request",e.id,"envelope",d);try{var g=!0;this.jsonpSend({transport:this,url:d.url,sync:d.sync,headers:this.getConfiguration().requestHeaders,body:JSON.stringify(d.messages),onSuccess:function(t){var i=!1;try{var r=n.convertToMessages(t);0===r.length?n.transportFailure(d,e,{httpCode:204}):(i=!0,n.transportSuccess(d,e,r))}catch(t){n._debug(t),i||n.transportFailure(d,e,{exception:t})}},onError:function(t,i){var r={reason:t,exception:i};g?n.setTimeout(function(){n.transportFailure(d,e,r)},0):n.transportFailure(d,e,r)}}),g=!1}catch(t){this.setTimeout(function(){n.transportFailure(d,e,{exception:t})},0)}},i},s=function(){var n,i=new e,r=e.derive(i),s=!0,o=!1,a=!0,c=null,u=null,l=!1,d=null;function h(t,e){t&&(this.webSocketClose(t,e.code,e.reason),this.onClose(t,e))}function p(t){return t===u||t===c}function f(t,e,n){for(var i=[],r=0;r<e.messages.length;++r){var s=e.messages[r];s.id&&i.push(s.id)}t.envelopes[i.join(",")]=[e,n],this._debug("Transport",this.getType(),"stored envelope, envelopes",t.envelopes)}function v(t,e,i){var r=JSON.stringify(e.messages);t.webSocket.send(r),this._debug("Transport",this.getType(),"sent",e,"/meta/connect =",i);var s=this.getConfiguration().maxNetworkDelay,o=s;i&&(o+=this.getAdvice().timeout,l=!0);for(var a=this,c=[],u=0;u<e.messages.length;++u)!function(){var i=e.messages[u];i.id&&(c.push(i.id),t.timeouts[i.id]=a.setTimeout(function(){n._debug("Transport",a.getType(),"timing out message",i.id,"after",o,"on",t),h.call(a,t,{code:1e3,reason:"Message Timeout"})},o))}();this._debug("Transport",this.getType(),"waiting at most",o,"ms for messages",c,"maxNetworkDelay",s,", timeouts:",t.timeouts)}function g(t,e,i){try{null===t?(t=u||{envelopes:{},timeouts:{}},f.call(this,t,e,i),function(t){if(!u){var e=n.getURL().replace(/^http/,"ws");this._debug("Transport",this.getType(),"connecting to URL",e);try{var i=n.getConfiguration().protocol;t.webSocket=i?new window.WebSocket(e,i):new window.WebSocket(e),u=t}catch(t){throw s=!1,this._debug("Exception while creating WebSocket object",t),t}a=!1!==n.getConfiguration().stickyReconnect;var r=this,l=n.getConfiguration().connectTimeout;l>0&&(t.connectTimer=this.setTimeout(function(){n._debug("Transport",r.getType(),"timed out while connecting to URL",e,":",l,"ms"),h.call(r,t,{code:1e3,reason:"Connect Timeout"})},l));var d=function(e){e=e||{code:1e3},n._debug("WebSocket onclose",t,e,"connecting",u,"current",c),t.connectTimer&&r.clearTimeout(t.connectTimer),r.onClose(t,e)};t.webSocket.onopen=function(){n._debug("WebSocket onopen",t),t.connectTimer&&r.clearTimeout(t.connectTimer),p(t)?(u=null,c=t,o=!0,r.onOpen(t)):(n._warn("Closing extra WebSocket connection",this,"active connection",c),h.call(r,t,{code:1e3,reason:"Extra Connection"}))},t.webSocket.onclose=d,t.webSocket.onerror=function(){d({code:1e3,reason:"Error"})},t.webSocket.onmessage=function(e){n._debug("WebSocket onmessage",e,t),r.onMessage(t,e)},this._debug("Transport",this.getType(),"configured callbacks on",t)}}.call(this,t)):(f.call(this,t,e,i),v.call(this,t,e,i))}catch(e){var r=this;this.setTimeout(function(){h.call(r,t,{code:1e3,reason:"Exception",exception:e})},0)}}return r.reset=function(t){i.reset(t),s=!0,t&&(o=!1),a=!0,c=null,u=null,l=!1},r._notifySuccess=function(t,e){t.call(this,e)},r._notifyFailure=function(t,e,n,i){t.call(this,e,n,i)},r.onOpen=function(t){var e=t.envelopes;for(var n in this._debug("Transport",this.getType(),"opened",t,"pending messages",e),e)if(e.hasOwnProperty(n)){var i=e[n],r=i[0],s=i[1];d=r.onSuccess,v.call(this,t,r,s)}},r.onMessage=function(e,n){this._debug("Transport",this.getType(),"received websocket message",n,e);for(var i=!1,r=this.convertToMessages(n.data),s=[],o=0;o<r.length;++o){var a=r[o];if((/^\/meta\//.test(a.channel)||void 0===a.data)&&a.id){s.push(a.id);var c=e.timeouts[a.id];c&&(this.clearTimeout(c),delete e.timeouts[a.id],this._debug("Transport",this.getType(),"removed timeout for message",a.id,", timeouts",e.timeouts))}"/meta/connect"===a.channel&&(l=!1),"/meta/disconnect"!==a.channel||l||(i=!0)}for(var u=!1,h=e.envelopes,p=0;p<s.length;++p){var f=s[p];for(var v in h)if(h.hasOwnProperty(v)){var g=v.split(","),y=t.inArray(f,g);if(y>=0){u=!0,g.splice(y,1);var m=h[v][0],b=h[v][1];delete h[v],g.length>0&&(h[g.join(",")]=[m,b]);break}}}u&&this._debug("Transport",this.getType(),"removed envelope, envelopes",h),this._notifySuccess(d,r),i&&this.webSocketClose(e,1e3,"Disconnect")},r.onClose=function(t,e){this._debug("Transport",this.getType(),"closed",t,e),p(t)&&(s=a&&o,u=null,c=null);var n=t.timeouts;for(var i in t.timeouts={},n)n.hasOwnProperty(i)&&this.clearTimeout(n[i]);var r=t.envelopes;for(var d in t.envelopes={},r)if(r.hasOwnProperty(d)){var h=r[d][0],f=r[d][1];f&&(l=!1);var v={websocketCode:e.code,reason:e.reason};e.exception&&(v.exception=e.exception),this._notifyFailure(h.onFailure,t,h.messages,v)}},r.registered=function(t,e){i.registered(t,e),n=e},r.accept=function(t,e,i){return this._debug("Transport",this.getType(),"accept, supported:",s),s&&!!window.WebSocket&&!1!==n.websocketEnabled},r.send=function(t,e){this._debug("Transport",this.getType(),"sending",t,"/meta/connect =",e),g.call(this,c,t,e)},r.webSocketClose=function(t,e,n){try{t.webSocket&&t.webSocket.close(e,n)}catch(t){this._debug(t)}},r.abort=function(){i.abort(),h.call(this,c,{code:1e3,reason:"Abort"}),this.reset(!0)},r},o=["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z",".","-",":","+","=","^","!","/","*","?","&","<",">","(",")","[","]","{","}","@","%","$","#"],a=[0,68,0,84,83,82,72,0,75,76,70,65,0,63,62,69,0,1,2,3,4,5,6,7,8,9,64,0,73,66,74,71,81,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,77,0,78,67,0,0,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,79,0,80,0,0];return{CometD:function(e){var n,o,a,c,u,l=new function(){var t=0,e={};this.register=function(n){var i=++t;return e[i]=n,i},this.unregister=function(t){var n=e[t];return delete e[t],n},this.setTimeout=function(t,e){return window.setTimeout(t,e)},this.clearTimeout=function(t){window.clearTimeout(t)}},d=this,h=e||"default",p=!1,f=new function(){var t=[],e={};this.getTransportTypes=function(){return t.slice(0)},this.findTransportTypes=function(n,i,r){for(var s=[],o=0;o<t.length;++o){var a=t[o];!0===e[a].accept(n,i,r)&&s.push(a)}return s},this.negotiateTransport=function(n,i,r,s){for(var o=0;o<t.length;++o)for(var a=t[o],c=0;c<n.length;++c)if(a===n[c]){var u=e[a];if(!0===u.accept(i,r,s))return u}return null},this.add=function(n,i,r){for(var s=!1,o=0;o<t.length;++o)if(t[o]===n){s=!0;break}return s||("number"!=typeof r?t.push(n):t.splice(r,0,n),e[n]=i),!s},this.find=function(n){for(var i=0;i<t.length;++i)if(t[i]===n)return e[n];return null},this.remove=function(n){for(var i=0;i<t.length;++i)if(t[i]===n){t.splice(i,1);var r=e[n];return delete e[n],r}return null},this.clear=function(){t=[],e={}},this.reset=function(n){for(var i=0;i<t.length;++i)e[t[i]].reset(n)}},v="disconnected",g=0,y=null,m=0,b=[],T=!1,O=0,w={},E=0,S=null,U=[],C={},j={},R={},_=!1,x=!1,A=0,I=0,P=null,k={useWorkerScheduler:!0,protocol:null,stickyReconnect:!0,connectTimeout:0,maxConnections:2,backoffIncrement:1e3,maxBackoff:6e4,logLevel:"info",maxNetworkDelay:1e4,requestHeaders:{},appendMessageTypeToURL:!0,autoBatch:!1,urls:{},maxURILength:2e3,advice:{timeout:6e4,interval:0,reconnect:void 0,maxInterval:0}};function N(t,e){try{return t[e]}catch(t){return}}function D(e){return t.isString(e)}function $(t){return void 0!==t&&null!==t&&"function"==typeof t}function L(t,e){for(var n="";--e>0&&!(t>=Math.pow(10,e));)n+="0";return n+=t}function F(t,e){if(window.console){var n=window.console[t];if($(n)){var i=new Date;[].splice.call(e,0,0,L(i.getHours(),2)+":"+L(i.getMinutes(),2)+":"+L(i.getSeconds(),2)+"."+L(i.getMilliseconds(),3)),n.apply(window.console,e)}}}function B(t){return new RegExp("(^https?://)?(((\\[[^\\]]+])|([^:/?#]+))(:(\\d+))?)?([^?#]*)(.*)?").exec(t)}function M(t){d._debug("Configuring cometd object with",t),D(t)&&(t={url:t}),t||(t={}),k=d._mixin(!1,k,t);var e=d.getURL();if(!e)throw"Missing required configuration parameter 'url' specifying the Bayeux server URL";var n=B(e),i=n[2],r=n[8],s=n[9];if(p=d._isCrossDomain(i),k.appendMessageTypeToURL)if(void 0!==s&&s.length>0)d._info("Appending message type to URI "+r+s+" is not supported, disabling 'appendMessageTypeToURL' configuration"),k.appendMessageTypeToURL=!1;else{var o=r.split("/"),a=o.length-1;r.match(/\/$/)&&(a-=1),o[a].indexOf(".")>=0&&(d._info("Appending message type to URI "+r+" is not supported, disabling 'appendMessageTypeToURL' configuration"),k.appendMessageTypeToURL=!1)}if(window.Worker&&window.Blob&&window.URL&&k.useWorkerScheduler){var c=function(){var t={};self.onmessage=function(e){var n=e.data,i=t[n.id];switch(n.type){case"setTimeout":t[n.id]=self.setTimeout(function(){delete t[n.id],self.postMessage({id:n.id})},n.delay);break;case"clearTimeout":delete t[n.id],i&&self.clearTimeout(i);break;default:throw"Unknown command "+n.type}}}.toString();c=c.substring(c.indexOf("{")+1,c.lastIndexOf("}"));var u=new window.Blob([c],{type:"application/json"}),h=window.URL.createObjectURL(u),f=new window.Worker(h);l.setTimeout=function(t,e){var n=l.register(t);return f.postMessage({id:n,type:"setTimeout",delay:e}),n},l.clearTimeout=function(t){l.unregister(t),f.postMessage({id:t,type:"clearTimeout"})},f.onmessage=function(t){var e=t.data.id,n=l.unregister(e);n&&n()}}}function G(t){if(t){var e=w[t.channel];e&&e[t.id]&&(delete e[t.id],d._debug("Removed",t.listener?"listener":"subscription",t))}}function H(t){t&&!t.listener&&G(t)}function V(){for(var t in w)if(w.hasOwnProperty(t)){var e=w[t];if(e)for(var n in e)e.hasOwnProperty(n)&&H(e[n])}}function q(t){v!==t&&(d._debug("Status",v,"->",t),v=t)}function J(){return"disconnecting"===v||"disconnected"===v}function X(){var t=++g;return""+t}function W(t,e,n,i,r){try{return e.call(t,i)}catch(t){var s=d.onExtensionException;if($(s)){d._debug("Invoking extension exception handler",n,t);try{s.call(d,t,n,r,i)}catch(t){d._info("Exception during execution of extension exception handler",n,t)}}else d._info("Exception during execution of extension",n,t);return i}}function Q(t){for(var e=U.length-1;e>=0&&void 0!==t&&null!==t;--e){var n=U[e],i=n.extension.outgoing;if($(i)){var r=W(n.extension,i,n.name,t,!0);t=void 0===r?t:r}}return t}function Y(t,e){var n=w[t];if(n)for(var i in n)if(n.hasOwnProperty(i)){var r=n[i];if(r)try{r.callback.call(r.scope,e)}catch(t){var s=d.onListenerException;if($(s)){d._debug("Invoking listener exception handler",r,t);try{s.call(d,t,r,r.listener,e)}catch(t){d._info("Exception during execution of listener exception handler",r,t)}}else d._info("Exception during execution of listener",r,e,t)}}}function K(t,e){Y(t,e);for(var n=t.split("/"),i=n.length-1,r=i;r>0;--r){var s=n.slice(0,r).join("/")+"/*";r===i&&Y(s,e),Y(s+="*",e)}}function z(){null!==S&&d.clearTimeout(S),S=null}function Z(t,e){z();var n=C.interval+e;d._debug("Function scheduled in",n,"ms, interval =",C.interval,"backoff =",E,t),S=d.setTimeout(t,n)}function tt(t,e,i){for(var r=0;r<t.length;++r){var s=t[r],o=s.id;y&&(s.clientId=y),void 0!==(s=Q(s))&&null!==s?(s.id=o,t[r]=s):(delete j[o],t.splice(r--,1))}if(0!==t.length){e&&(P=t[0]);var a=d.getURL();k.appendMessageTypeToURL&&(a.match(/\/$/)||(a+="/"),i&&(a+=i));var l={url:a,sync:!1,messages:t,onSuccess:function(t){try{c.call(d,t)}catch(t){d._info("Exception during handling of messages",t)}},onFailure:function(t,e,n){try{var i=d.getTransport();n.connectionType=i?i.getType():"unknown",u.call(d,t,e,n)}catch(t){d._info("Exception during handling of failure",t)}}};d._debug("Send",l),n.send(l,e)}}function et(t){m>0||!0===T?b.push(t):tt([t],!1)}function nt(){E=0}function it(){var t=b;b=[],t.length>0&&tt(t,!1)}function rt(t){q("connecting"),Z(function(){!function(){if(!J()){var t={id:X(),channel:"/meta/connect",connectionType:n.getType()};x||(t.advice={timeout:0}),q("connecting"),d._debug("Connect sent",t),tt([t],!0,"connect"),q("connected")}}()},t)}function st(t){t&&(C=d._mixin(!1,{},k.advice,t),d._debug("New advice",C))}function ot(t){if(z(),t&&n&&n.abort(),p=!1,n=null,q("disconnected"),y=null,m=0,nt(),_=!1,x=!1,A=0,P=null,b.length>0){var e=b;b=[],u.call(d,void 0,e,{reason:"Disconnected"})}}function at(t,e,n){var i=d.onTransportException;if($(i)){d._debug("Invoking transport exception handler",t,e,n);try{i.call(d,n,t,e)}catch(t){d._info("Exception during execution of transport exception handler",t)}}}function ct(t,e){$(t)&&(e=t,t=void 0),y=null,V(),J()&&f.reset(!0),st({}),m=0,T=!0,o=t,a=e;var i=d.getURL(),r=f.findTransportTypes("1.0",p,i),s={id:X(),version:"1.0",minimumVersion:"1.0",channel:"/meta/handshake",supportedConnectionTypes:r,advice:{timeout:C.timeout,interval:C.interval}},c=d._mixin(!1,{},o,s);if(d._putCallback(c.id,e),!n&&!(n=f.negotiateTransport(r,"1.0",p,i))){var u="Could not find initial transport among: "+f.getTransportTypes();throw d._warn(u),u}d._debug("Initial transport is",n.getType()),q("handshaking"),d._debug("Handshake sent",c),tt([c],!1,"handshake")}function ut(t,e){try{t.call(d,e)}catch(t){var n=d.onCallbackException;if($(n)){d._debug("Invoking callback exception handler",t);try{n.call(d,t,e)}catch(t){d._info("Exception during execution of callback exception handler",t)}}else d._info("Exception during execution of message callback",t)}}function lt(t){var e=d._getCallback([t.id]);$(e)&&(delete j[t.id],ut(e,t))}function dt(t){var e=R[t.id];if(delete R[t.id],e){d._debug("Handling remote call response for",t,"with context",e);var n=e.timeout;n&&d.clearTimeout(n);var i=e.callback;if($(i))return ut(i,t),!0}return!1}function ht(t){d._debug("Transport failure handling",t),t.transport&&(n=t.transport),t.url&&n.setURL(t.url);var e=t.action,i=t.delay||0;switch(e){case"handshake":!function(t){q("handshaking"),T=!0,Z(function(){ct(o,a)},t)}(i);break;case"retry":rt(i);break;case"none":ot(!0);break;default:throw"Unknown action "+e}}function pt(t,e){lt(t),K("/meta/handshake",t),K("/meta/unsuccessful",t),J()&&(e.action="none"),d.onTransportFailure.call(d,t,e,ht)}function ft(t){pt(t,{cause:"failure",action:"handshake",transport:null})}function vt(t){return"disconnected"===v||!(!P||P.id!==t.id)&&(P=null,!0)}function gt(t,e){K("/meta/connect",t),K("/meta/unsuccessful",t),J()&&(e.action="none"),d.onTransportFailure.call(d,t,e,ht)}function yt(t){vt(t)?(x=!1,gt(t,{cause:"failure",action:"retry",transport:null})):d._debug("Mismatched /meta/connect failure",t)}function mt(t){ot(!0),lt(t),K("/meta/disconnect",t),K("/meta/unsuccessful",t)}function bt(t){mt(t)}function Tt(t){var e=w[t.subscription];if(e)for(var n in e)if(e.hasOwnProperty(n)){var i=e[n];i&&!i.listener&&(delete e[n],d._debug("Removed failed subscription",i))}lt(t),K("/meta/subscribe",t),K("/meta/unsuccessful",t)}function Ot(t){Tt(t)}function wt(t){lt(t),K("/meta/unsubscribe",t),K("/meta/unsuccessful",t)}function Et(t){wt(t)}function St(t){dt(t)||(lt(t),K("/meta/publish",t),K("/meta/unsuccessful",t))}function Ut(t){St(t)}function Ct(t){if(A=0,void 0!==(t=function(t){for(var e=0;e<U.length&&void 0!==t&&null!==t;++e){var n=U[e],i=n.extension.incoming;if($(i)){var r=W(n.extension,i,n.name,t,!1);t=void 0===r?t:r}}return t}(t))&&null!==t){st(t.advice);var e=t.channel;switch(e){case"/meta/handshake":!function(t){var e=d.getURL();if(t.successful){var i=d._isCrossDomain(B(e)[2]),r=f.negotiateTransport(t.supportedConnectionTypes,t.version,i,e);if(null===r)return t.successful=!1,void pt(t,{cause:"negotiation",action:"none",transport:null});n!==r&&(d._debug("Transport",n.getType(),"->",r.getType()),n=r),y=t.clientId,T=!1,it(),t.reestablish=_,_=!0,lt(t),K("/meta/handshake",t),I=t["x-messages"]||0;var s=J()?"none":C.reconnect||"retry";switch(s){case"retry":nt(),0===I?rt(0):d._debug("Processing",I,"handshake-delivered messages");break;case"none":ot(!0);break;default:throw"Unrecognized advice action "+s}}else pt(t,{cause:"unsuccessful",action:C.reconnect||"handshake",transport:n})}(t);break;case"/meta/connect":!function(t){if(vt(t))if(x=t.successful){K("/meta/connect",t);var e=J()?"none":C.reconnect||"retry";switch(e){case"retry":nt(),rt(E);break;case"none":ot(!1);break;default:throw"Unrecognized advice action "+e}}else gt(t,{cause:"unsuccessful",action:C.reconnect||"retry",transport:n});else d._debug("Mismatched /meta/connect reply",t)}(t);break;case"/meta/disconnect":!function(t){t.successful?(ot(!1),lt(t),K("/meta/disconnect",t)):mt(t)}(t);break;case"/meta/subscribe":!function(t){t.successful?(lt(t),K("/meta/subscribe",t)):Tt(t)}(t);break;case"/meta/unsubscribe":!function(t){t.successful?(lt(t),K("/meta/unsubscribe",t)):wt(t)}(t);break;default:!function(t){void 0!==t.data?dt(t)||(K(t.channel,t),I>0&&0==--I&&(d._debug("Processed last handshake-delivered message"),rt(0))):void 0===t.successful?d._warn("Unknown Bayeux Message",t):t.successful?(lt(t),K("/meta/publish",t)):St(t)}(t)}}}function jt(t){var e=w[t];if(e)for(var n in e)if(e.hasOwnProperty(n)&&e[n])return!0;return!1}function Rt(t,e){var n={scope:t,method:e};if($(t))n.scope=void 0,n.method=t;else if(D(e)){if(!t)throw"Invalid scope "+t;if(n.method=t[e],!$(n.method))throw"Invalid callback "+e+" for scope "+t}else if(!$(e))throw"Invalid callback "+e;return n}function _t(t,e,n,i){var r=Rt(e,n);d._debug("Adding",i?"listener":"subscription","on",t,"with scope",r.scope,"and callback",r.method);var s=++O,o={id:s,channel:t,scope:r.scope,callback:r.method,listener:i},a=w[t];return a||(a={},w[t]=a),a[s]=o,d._debug("Added",i?"listener":"subscription",o),o}this._mixin=function(t,e,n){for(var i=e||{},r=2;r<arguments.length;++r){var s=arguments[r];if(void 0!==s&&null!==s)for(var o in s)if(s.hasOwnProperty(o)){var a=N(s,o),c=N(i,o);if(a===e)continue;if(void 0===a)continue;if(t&&"object"==typeof a&&null!==a)if(a instanceof Array)i[o]=this._mixin(t,c instanceof Array?c:[],a);else{var u="object"!=typeof c||c instanceof Array?{}:c;i[o]=this._mixin(t,u,a)}else i[o]=a}}return i},this._warn=function(){F("warn",arguments)},this._info=function(){"warn"!==k.logLevel&&F("info",arguments)},this._debug=function(){"debug"===k.logLevel&&F("debug",arguments)},this._isCrossDomain=function(t){return!!(window.location&&window.location.host&&t)&&t!==window.location.host},this.send=et,this._getCallback=function(t){return j[t]},this._putCallback=function(t,e){var n=this._getCallback(t);return $(e)&&(j[t]=e),n},this.onTransportFailure=function(t,e,i){this._debug("Transport failure",e,"for",t);var r=this.getTransportRegistry(),s=this.getURL(),o=this._isCrossDomain(B(s)[2]),a=r.findTransportTypes("1.0",o,s);if("none"===e.action){if("/meta/handshake"===t.channel&&!e.transport){var c="Could not negotiate transport, client=["+a+"], server=["+t.supportedConnectionTypes+"]";this._warn(c),at(n.getType(),null,{reason:c,connectionType:n.getType(),transport:n})}}else if(e.delay=this.getBackoffPeriod(),"/meta/handshake"===t.channel){if(!e.transport){var u=n?n.getType():null,l=r.negotiateTransport(a,"1.0",o,s);if(l){var h=l.getType();this._debug("Transport",u,"->",h),at(u,h,t.failure),e.action="handshake",e.transport=l}else this._warn("Could not negotiate transport, client=["+a+"]"),at(u,null,t.failure),e.action="none"}"none"!==e.action&&this.increaseBackoffPeriod()}else{var p=(new Date).getTime();if(0===A&&(A=p),"retry"===e.action){e.delay=this.increaseBackoffPeriod();var f=C.maxInterval;if(f>0){var v=C.timeout+C.interval+f,g=p-A;g+E>v&&(e.action="handshake")}}"handshake"===e.action&&(e.delay=0,r.reset(!1),this.resetBackoffPeriod())}i.call(d,e)},this.receive=Ct,c=function(t){d._debug("Received",t);for(var e=0;e<t.length;++e){var n=t[e];Ct(n)}},u=function(t,e,n){d._debug("handleFailure",t,e,n),n.transport=t;for(var i=0;i<e.length;++i){var r=e[i],s={id:r.id,successful:!1,channel:r.channel,failure:n};switch(n.message=r,r.channel){case"/meta/handshake":ft(s);break;case"/meta/connect":yt(s);break;case"/meta/disconnect":bt(s);break;case"/meta/subscribe":s.subscription=r.subscription,Ot(s);break;case"/meta/unsubscribe":s.subscription=r.subscription,Et(s);break;default:Ut(s)}}},this.registerTransport=function(t,e,n){var i=f.add(t,e,n);return i&&(this._debug("Registered transport",t),$(e.registered)&&e.registered(t,this)),i},this.unregisterTransport=function(t){var e=f.remove(t);return null!==e&&(this._debug("Unregistered transport",t),$(e.unregistered)&&e.unregistered()),e},this.unregisterTransports=function(){f.clear()},this.getTransportTypes=function(){return f.getTransportTypes()},this.findTransport=function(t){return f.find(t)},this.getTransportRegistry=function(){return f},this.configure=function(t){M.call(this,t)},this.init=function(t,e){this.configure(t),this.handshake(e)},this.handshake=function(t,e){if("disconnected"!==v)throw"Illegal state: handshaken";ct(t,e)},this.disconnect=function(t,e){if(!J()){$(t)&&(e=t,t=void 0);var n={id:X(),channel:"/meta/disconnect"},i=this._mixin(!1,{},t,n);d._putCallback(i.id,e),q("disconnecting"),tt([i],!1,"disconnect")}},this.startBatch=function(){++m,d._debug("Starting batch, depth",m)},this.endBatch=function(){!function(){if(--m,d._debug("Ending batch, depth",m),m<0)throw"Calls to startBatch() and endBatch() are not paired";0!==m||J()||T||it()}()},this.batch=function(t,e){var n=Rt(t,e);this.startBatch();try{n.method.call(n.scope),this.endBatch()}catch(t){throw this._info("Exception during execution of batch",t),this.endBatch(),t}},this.addListener=function(t,e,n){if(arguments.length<2)throw"Illegal arguments number: required 2, got "+arguments.length;if(!D(t))throw"Illegal argument type: channel must be a string";return _t(t,e,n,!0)},this.removeListener=function(t){if(!(t&&t.channel&&"id"in t))throw"Invalid argument: expected subscription, not "+t;G(t)},this.clearListeners=function(){w={}},this.subscribe=function(t,e,n,i,r){if(arguments.length<2)throw"Illegal arguments number: required 2, got "+arguments.length;if(!D(t))throw"Illegal argument type: channel must be a string";if(J())throw"Illegal state: disconnected";$(e)&&(r=i,i=n,n=e,e=void 0),$(i)&&(r=i,i=void 0);var s=!jt(t),o=_t(t,e,n,!1);if(s){var a={id:X(),channel:"/meta/subscribe",subscription:t},c=this._mixin(!1,{},i,a);d._putCallback(c.id,r),et(c)}return o},this.unsubscribe=function(t,e,n){if(arguments.length<1)throw"Illegal arguments number: required 1, got "+arguments.length;if(J())throw"Illegal state: disconnected";$(e)&&(n=e,e=void 0),this.removeListener(t);var i=t.channel;if(!jt(i)){var r={id:X(),channel:"/meta/unsubscribe",subscription:i},s=this._mixin(!1,{},e,r);d._putCallback(s.id,n),et(s)}},this.resubscribe=function(t,e){if(H(t),t)return this.subscribe(t.channel,t.scope,t.callback,e)},this.clearSubscriptions=function(){V()},this.publish=function(t,e,n,i){if(arguments.length<1)throw"Illegal arguments number: required 1, got "+arguments.length;if(!D(t))throw"Illegal argument type: channel must be a string";if(/^\/meta\//.test(t))throw"Illegal argument: cannot publish to meta channels";if(J())throw"Illegal state: disconnected";$(e)?(i=e,e={},n=void 0):$(n)&&(i=n,n=void 0);var r={id:X(),channel:t,data:e},s=this._mixin(!1,{},n,r);d._putCallback(s.id,i),et(s)},this.publishBinary=function(t,e,n,i,r){$(e)?(r=e,e=new ArrayBuffer(0),n=!0,i=void 0):$(n)?(r=n,n=!0,i=void 0):$(i)&&(r=i,i=void 0);var s={meta:i,data:e,last:n};this.publish(t,s,{ext:{binary:{}}},r)},this.remoteCall=function(t,e,n,i,r){if(arguments.length<1)throw"Illegal arguments number: required 1, got "+arguments.length;if(!D(t))throw"Illegal argument type: target must be a string";if(J())throw"Illegal state: disconnected";if($(e)?(r=e,e={},n=k.maxNetworkDelay,i=void 0):$(n)?(r=n,n=k.maxNetworkDelay,i=void 0):$(i)&&(r=i,i=void 0),"number"!=typeof n)throw"Illegal argument type: timeout must be a number";t.match(/^\//)||(t="/"+t);var s="/service"+t,o={id:X(),channel:s,data:e},a=this._mixin(!1,{},i,o),c={callback:r};n>0&&(c.timeout=d.setTimeout(function(){d._debug("Timing out remote call",a,"after",n,"ms"),St({id:a.id,error:"406::timeout",successful:!1,failure:{message:a,reason:"Remote Call Timeout"}})},n),d._debug("Scheduled remote call timeout",a,"in",n,"ms")),R[a.id]=c,et(a)},this.remoteCallBinary=function(t,e,n,i,r,s){$(e)?(s=e,e=new ArrayBuffer(0),n=!0,i=void 0,r=k.maxNetworkDelay):$(n)?(s=n,n=!0,i=void 0,r=k.maxNetworkDelay):$(i)?(s=i,i=void 0,r=k.maxNetworkDelay):$(r)&&(s=r,r=k.maxNetworkDelay);var o={meta:i,data:e,last:n};this.remoteCall(t,o,r,{ext:{binary:{}}},s)},this.getStatus=function(){return v},this.isDisconnected=J,this.setBackoffIncrement=function(t){k.backoffIncrement=t},this.getBackoffIncrement=function(){return k.backoffIncrement},this.getBackoffPeriod=function(){return E},this.increaseBackoffPeriod=function(){return E<k.maxBackoff&&(E+=k.backoffIncrement),E},this.resetBackoffPeriod=function(){nt()},this.setLogLevel=function(t){k.logLevel=t},this.registerExtension=function(t,e){if(arguments.length<2)throw"Illegal arguments number: required 2, got "+arguments.length;if(!D(t))throw"Illegal argument type: extension name must be a string";for(var n=!1,i=0;i<U.length;++i){var r=U[i];if(r.name===t){n=!0;break}}return n?(this._info("Could not register extension with name",t,"since another extension with the same name already exists"),!1):(U.push({name:t,extension:e}),this._debug("Registered extension",t),$(e.registered)&&e.registered(t,this),!0)},this.unregisterExtension=function(t){if(!D(t))throw"Illegal argument type: extension name must be a string";for(var e=!1,n=0;n<U.length;++n){var i=U[n];if(i.name===t){U.splice(n,1),e=!0,this._debug("Unregistered extension",t);var r=i.extension;$(r.unregistered)&&r.unregistered();break}}return e},this.getExtension=function(t){for(var e=0;e<U.length;++e){var n=U[e];if(n.name===t)return n.extension}return null},this.getName=function(){return h},this.getClientId=function(){return y},this.getURL=function(){if(n){var t=n.getURL();if(t)return t;if(t=k.urls[n.getType()])return t}return k.url},this.getTransport=function(){return n},this.getConfiguration=function(){return this._mixin(!0,{},k)},this.getAdvice=function(){return this._mixin(!0,{},C)},this.setTimeout=function(t,e){return l.setTimeout(function(){try{d._debug("Invoking timed function",t),t()}catch(e){d._debug("Exception invoking timed function",t,e)}},e)},this.clearTimeout=function(t){l.clearTimeout(t)},window.WebSocket&&this.registerTransport("websocket",new s),this.registerTransport("long-polling",new i),this.registerTransport("callback-polling",new r)},Transport:e,RequestTransport:n,LongPollingTransport:i,CallbackPollingTransport:r,WebSocketTransport:s,Utils:t,Z85:{encode:function(t){var e=null;if(t instanceof ArrayBuffer?e=t:t.buffer instanceof ArrayBuffer?e=t.buffer:Array.isArray(t)&&(e=new Uint8Array(t).buffer),null==e)throw"Cannot Z85 encode "+t;for(var n=e.byteLength,i=n%4,r=4-(0===i?4:i),s=new DataView(e),a="",c=0,u=0;u<n+r;++u){var l=u>=n;if(c=256*c+(l?0:s.getUint8(u)),(u+1)%4==0){for(var d=52200625,h=5;h>0;--h){if(!l||h>r){var p=Math.floor(c/d)%85;a+=o[p]}d/=85}c=0}}return a},decode:function(t){for(var e=t.length%5,n=5-(0===e?5:e),i=0;i<n;++i)t+=o[o.length-1];for(var r=t.length,s=new ArrayBuffer(4*r/5-n),c=new DataView(s),u=0,l=0,d=0,h=0;h<r;++h){var p=t.charCodeAt(l++)-32;if(u=85*u+a[p],l%5==0){for(var f=16777216;f>=1;)d<c.byteLength&&c.setUint8(d++,Math.floor(u/f)%256),f/=256;u=0}}return s}}}}()}),s={CometD:r.CometD,default:r}.CometD;!function(t){t.HANDSHAKE="/meta/handshake",t.CONNECT="/meta/connect",t.SUBSCRIBE="/meta/subscribe",t.UNSUBSCRIBE="/meta/unsubscribe"}(i||(i={}));class o{constructor(t,e="/notification/realtime",n){this.client=t,this.url=e,this.cometd=new s,this.metaHandshake=(t=>{if(!t.successful)throw new Error("Handshake failed")}),this.cometd.websocketEnabled=!0,this.cometd.addListener(i.HANDSHAKE,n||this.metaHandshake)}subscribe(t,e){return this.checkConnection(),this.cometd.subscribe(t,e)}unsubscribe(t){return this.cometd.unsubscribe(t)}disconnect(){this.cometd.disconnect()}checkConnection(){const{cometd:t,client:e,url:n}=this;if(t.isDisconnected()){const{headers:i}=e.getFetchOptions(),r={url:e.getUrl(n),requestHeaders:i};t.configure(r),this.handshake(e.getCometdHandshake())}}handshake(t){this.cometd.handshake(t)}}var a=function(t,e,n,i){return new(n||(n=Promise))(function(r,s){function o(t){try{c(i.next(t))}catch(t){s(t)}}function a(t){try{c(i.throw(t))}catch(t){s(t)}}function c(t){var e;t.done?r(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(o,a)}c((i=i.apply(t,e||[])).next())})};class c{constructor(t,e,n){this.filter=n,this.service=t,this.currentPage=e.currentPage,this.nextPage=e.nextPage,this.prevPage=e.prevPage,this.pageSize=e.pageSize,this.totalPages=e.totalPages}next(t={}){return a(this,void 0,void 0,function*(){return this.list(this.getFilter(t,this.nextPage))})}prev(t={}){return a(this,void 0,void 0,function*(){return this.list(this.getFilter(t,this.prevPage))})}list(t={}){return a(this,void 0,void 0,function*(){return this.service.list(t)})}goto(t,e={}){return a(this,void 0,void 0,function*(){return this.list(this.getFilter(e,t))})}getFilter(t,e){return Object.assign(t,this.filter,{currentPage:e})}}var u=function(t,e,n,i){return new(n||(n=Promise))(function(r,s){function o(t){try{c(i.next(t))}catch(t){s(t)}}function a(t){try{c(i.throw(t))}catch(t){s(t)}}function c(t){var e;t.done?r(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(o,a)}c((i=i.apply(t,e||[])).next())})};class l{constructor(t,e){this.client=t,this.realtime=e,this.cache=new Map;const n=Object.getPrototypeOf(this);["list","create","update","detail","delete"].forEach(t=>{n.hasOwnProperty(t)||Object.defineProperty(this,t,{get(){}})})}list(t={}){return u(this,void 0,void 0,function*(){const e=this.listUrl,n=yield this.fetch(e,this.changeFetchOptions({headers:{accept:"application/json"},params:t},e)),i=yield n.json();return{res:n,data:this.propertyName?i[this.propertyName]:i,paging:this.getPaging(i,t)}})}detail(t,e={}){return u(this,void 0,void 0,function*(){const n=this.getDetailUrl(t),i=yield this.fetch(n,this.changeFetchOptions({headers:{accept:"application/json"},params:Object.assign({},e)},n));return{res:i,data:yield i.json()}})}create(t){return u(this,void 0,void 0,function*(){const e=this.listUrl,n=JSON.stringify(this.onBeforeCreate(t)),i=yield this.fetch(e,this.changeFetchOptions({method:"POST",body:n,headers:{"content-type":"application/json",accept:"application/json"}},e));return{res:i,data:yield i.json()}})}update(t){return u(this,void 0,void 0,function*(){const e=this.getDetailUrl(t),n=JSON.stringify(this.onBeforeUpdate(t)),i=yield this.fetch(e,this.changeFetchOptions({method:"PUT",body:n,headers:{"content-type":"application/json",accept:"application/json"}},e));return{res:i,data:yield i.json()}})}delete(t,e){return u(this,void 0,void 0,function*(){const n=this.getDetailUrl(t);return{res:yield this.fetch(n,this.changeFetchOptions({method:"DELETE",params:e},n)),data:null}})}onBeforeCreate(t){return delete t.id,t}onBeforeUpdate(t){return t}changeFetchOptions(t,e=""){return t}getUrl(t=""){return`${this.baseUrl.replace(/\/+$/,"")}/${t.replace(/^\/+/,"")}`}getEntityId(t){return void 0===t||null===t?"":"object"==typeof t?this.getEntityId(t.id):`${t}`}getDetailUrl(t){const e=this.getEntityId(t);return`${this.listUrl}/${e}`}fetch(t,e){return u(this,void 0,void 0,function*(){const n=this.getUrl(t),i=yield this.client.fetch(n,e);return yield this.handleErrorStatusCodes(i)})}handleErrorStatusCodes(t){return u(this,void 0,void 0,function*(){if(t.status>=400){let e=null;try{e=yield t.json()}catch(n){try{e=yield t.text()}catch(t){}}throw{res:t,data:e}}return t})}mimeType(t){return`application/vnd.com.nsn.cumulocity.${t}+json`}getIdString(t){let e;return e="object"==typeof t?t.id:t,String(e)}getPaging(t,e){if(t.statistics){const n=Object.assign(Object.assign({},t.statistics),{nextPage:this.getCurrentPageFromLink(t.next),prevPage:this.getCurrentPageFromLink(t.prev)});return new c(this,n,e)}return null}getCurrentPageFromLink(t=""){const e=t.match(/currentPage=(-{0,1}\d+)/);return e&&parseInt(e[1],10)}}var d,h=n(function(t,n){var i="undefined"!=typeof self?self:e,r=function(){function t(){this.fetch=!1,this.DOMException=i.DOMException}return t.prototype=i,new t}();!function(t){!function(e){var n={searchParams:"URLSearchParams"in t,iterable:"Symbol"in t&&"iterator"in Symbol,blob:"FileReader"in t&&"Blob"in t&&function(){try{return new Blob,!0}catch(t){return!1}}(),formData:"FormData"in t,arrayBuffer:"ArrayBuffer"in t};if(n.arrayBuffer)var i=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],r=ArrayBuffer.isView||function(t){return t&&i.indexOf(Object.prototype.toString.call(t))>-1};function s(t){if("string"!=typeof t&&(t=String(t)),/[^a-z0-9\-#$%&'*+.^_`|~]/i.test(t))throw new TypeError("Invalid character in header field name");return t.toLowerCase()}function o(t){return"string"!=typeof t&&(t=String(t)),t}function a(t){var e={next:function(){var e=t.shift();return{done:void 0===e,value:e}}};return n.iterable&&(e[Symbol.iterator]=function(){return e}),e}function c(t){this.map={},t instanceof c?t.forEach(function(t,e){this.append(e,t)},this):Array.isArray(t)?t.forEach(function(t){this.append(t[0],t[1])},this):t&&Object.getOwnPropertyNames(t).forEach(function(e){this.append(e,t[e])},this)}function u(t){if(t.bodyUsed)return Promise.reject(new TypeError("Already read"));t.bodyUsed=!0}function l(t){return new Promise(function(e,n){t.onload=function(){e(t.result)},t.onerror=function(){n(t.error)}})}function d(t){var e=new FileReader,n=l(e);return e.readAsArrayBuffer(t),n}function h(t){if(t.slice)return t.slice(0);var e=new Uint8Array(t.byteLength);return e.set(new Uint8Array(t)),e.buffer}function p(){return this.bodyUsed=!1,this._initBody=function(t){var e;this._bodyInit=t,t?"string"==typeof t?this._bodyText=t:n.blob&&Blob.prototype.isPrototypeOf(t)?this._bodyBlob=t:n.formData&&FormData.prototype.isPrototypeOf(t)?this._bodyFormData=t:n.searchParams&&URLSearchParams.prototype.isPrototypeOf(t)?this._bodyText=t.toString():n.arrayBuffer&&n.blob&&((e=t)&&DataView.prototype.isPrototypeOf(e))?(this._bodyArrayBuffer=h(t.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):n.arrayBuffer&&(ArrayBuffer.prototype.isPrototypeOf(t)||r(t))?this._bodyArrayBuffer=h(t):this._bodyText=t=Object.prototype.toString.call(t):this._bodyText="",this.headers.get("content-type")||("string"==typeof t?this.headers.set("content-type","text/plain;charset=UTF-8"):this._bodyBlob&&this._bodyBlob.type?this.headers.set("content-type",this._bodyBlob.type):n.searchParams&&URLSearchParams.prototype.isPrototypeOf(t)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},n.blob&&(this.blob=function(){var t=u(this);if(t)return t;if(this._bodyBlob)return Promise.resolve(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(new Blob([this._bodyArrayBuffer]));if(this._bodyFormData)throw new Error("could not read FormData body as blob");return Promise.resolve(new Blob([this._bodyText]))},this.arrayBuffer=function(){return this._bodyArrayBuffer?u(this)||Promise.resolve(this._bodyArrayBuffer):this.blob().then(d)}),this.text=function(){var t,e,n,i=u(this);if(i)return i;if(this._bodyBlob)return t=this._bodyBlob,e=new FileReader,n=l(e),e.readAsText(t),n;if(this._bodyArrayBuffer)return Promise.resolve(function(t){for(var e=new Uint8Array(t),n=new Array(e.length),i=0;i<e.length;i++)n[i]=String.fromCharCode(e[i]);return n.join("")}(this._bodyArrayBuffer));if(this._bodyFormData)throw new Error("could not read FormData body as text");return Promise.resolve(this._bodyText)},n.formData&&(this.formData=function(){return this.text().then(g)}),this.json=function(){return this.text().then(JSON.parse)},this}c.prototype.append=function(t,e){t=s(t),e=o(e);var n=this.map[t];this.map[t]=n?n+", "+e:e},c.prototype.delete=function(t){delete this.map[s(t)]},c.prototype.get=function(t){return t=s(t),this.has(t)?this.map[t]:null},c.prototype.has=function(t){return this.map.hasOwnProperty(s(t))},c.prototype.set=function(t,e){this.map[s(t)]=o(e)},c.prototype.forEach=function(t,e){for(var n in this.map)this.map.hasOwnProperty(n)&&t.call(e,this.map[n],n,this)},c.prototype.keys=function(){var t=[];return this.forEach(function(e,n){t.push(n)}),a(t)},c.prototype.values=function(){var t=[];return this.forEach(function(e){t.push(e)}),a(t)},c.prototype.entries=function(){var t=[];return this.forEach(function(e,n){t.push([n,e])}),a(t)},n.iterable&&(c.prototype[Symbol.iterator]=c.prototype.entries);var f=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];function v(t,e){var n,i,r=(e=e||{}).body;if(t instanceof v){if(t.bodyUsed)throw new TypeError("Already read");this.url=t.url,this.credentials=t.credentials,e.headers||(this.headers=new c(t.headers)),this.method=t.method,this.mode=t.mode,this.signal=t.signal,r||null==t._bodyInit||(r=t._bodyInit,t.bodyUsed=!0)}else this.url=String(t);if(this.credentials=e.credentials||this.credentials||"same-origin",!e.headers&&this.headers||(this.headers=new c(e.headers)),this.method=(n=e.method||this.method||"GET",i=n.toUpperCase(),f.indexOf(i)>-1?i:n),this.mode=e.mode||this.mode||null,this.signal=e.signal||this.signal,this.referrer=null,("GET"===this.method||"HEAD"===this.method)&&r)throw new TypeError("Body not allowed for GET or HEAD requests");this._initBody(r)}function g(t){var e=new FormData;return t.trim().split("&").forEach(function(t){if(t){var n=t.split("="),i=n.shift().replace(/\+/g," "),r=n.join("=").replace(/\+/g," ");e.append(decodeURIComponent(i),decodeURIComponent(r))}}),e}function y(t,e){e||(e={}),this.type="default",this.status=void 0===e.status?200:e.status,this.ok=this.status>=200&&this.status<300,this.statusText="statusText"in e?e.statusText:"OK",this.headers=new c(e.headers),this.url=e.url||"",this._initBody(t)}v.prototype.clone=function(){return new v(this,{body:this._bodyInit})},p.call(v.prototype),p.call(y.prototype),y.prototype.clone=function(){return new y(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new c(this.headers),url:this.url})},y.error=function(){var t=new y(null,{status:0,statusText:""});return t.type="error",t};var m=[301,302,303,307,308];y.redirect=function(t,e){if(-1===m.indexOf(e))throw new RangeError("Invalid status code");return new y(null,{status:e,headers:{location:t}})},e.DOMException=t.DOMException;try{new e.DOMException}catch(t){e.DOMException=function(t,e){this.message=t,this.name=e;var n=Error(t);this.stack=n.stack},e.DOMException.prototype=Object.create(Error.prototype),e.DOMException.prototype.constructor=e.DOMException}function b(t,i){return new Promise(function(r,s){var o=new v(t,i);if(o.signal&&o.signal.aborted)return s(new e.DOMException("Aborted","AbortError"));var a=new XMLHttpRequest;function u(){a.abort()}a.onload=function(){var t,e,n={status:a.status,statusText:a.statusText,headers:(t=a.getAllResponseHeaders()||"",e=new c,t.replace(/\r?\n[\t ]+/g," ").split(/\r?\n/).forEach(function(t){var n=t.split(":"),i=n.shift().trim();if(i){var r=n.join(":").trim();e.append(i,r)}}),e)};n.url="responseURL"in a?a.responseURL:n.headers.get("X-Request-URL");var i="response"in a?a.response:a.responseText;r(new y(i,n))},a.onerror=function(){s(new TypeError("Network request failed"))},a.ontimeout=function(){s(new TypeError("Network request failed"))},a.onabort=function(){s(new e.DOMException("Aborted","AbortError"))},a.open(o.method,o.url,!0),"include"===o.credentials?a.withCredentials=!0:"omit"===o.credentials&&(a.withCredentials=!1),"responseType"in a&&n.blob&&(a.responseType="blob"),o.headers.forEach(function(t,e){a.setRequestHeader(e,t)}),o.signal&&(o.signal.addEventListener("abort",u),a.onreadystatechange=function(){4===a.readyState&&o.signal.removeEventListener("abort",u)}),a.send(void 0===o._bodyInit?null:o._bodyInit)})}b.polyfill=!0,t.fetch||(t.fetch=b,t.Headers=c,t.Request=v,t.Response=y),e.Headers=c,e.Request=v,e.Response=y,e.fetch=b,Object.defineProperty(e,"__esModule",{value:!0})}({})}(r),r.fetch.ponyfill=!0,delete r.fetch.polyfill;var s=r;(n=s.fetch).default=s.fetch,n.fetch=s.fetch,n.Headers=s.Headers,n.Request=s.Request,n.Response=s.Response,t.exports=n}),p=(d=h)&&d.__esModule&&Object.prototype.hasOwnProperty.call(d,"default")?d.default:d,f=(h.fetch,h.Headers,h.Request,h.Response,function(t,e,n,i){return new(n||(n=Promise))(function(r,s){function o(t){try{c(i.next(t))}catch(t){s(t)}}function a(t){try{c(i.throw(t))}catch(t){s(t)}}function c(t){var e;t.done?r(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(o,a)}c((i=i.apply(t,e||[])).next())})});let v=new WeakMap;class g{constructor(t,e){this.baseUrl=e,this.tenant="",this.defaultHeaders={},"string"==typeof t?e=t:this.setAuth(t),this.baseUrl=this.resolveServerUrl(e)}setAuth(t){v.set(this,t)}fetch(t,e){return f(this,void 0,void 0,function*(){let n=p;try{n=window.fetch||n}catch(t){}return n(this.getUrl(t,e),this.getFetchOptions(e))})}getUrl(t="",e){const n=e&&e.params;let i="";return n&&Object.keys(n).length&&(i=`?${i=Object.keys(n).map(t=>{let e=n[t];const i=encodeURIComponent(t);return Array.isArray(e)||(e=[e]),e.map(t=>`${i}=${encodeURIComponent(t)}`).join("&")}).join("&")}`),`${this.baseUrl.replace(/\/+$/,"").replace(/^\/+/,"")}/${t.replace(/\/+$/,"").replace(/^\/+/,"")}${i}`}getFetchOptions(t={}){let e=Object.assign({},t);const n=v.get(this);return e.headers=Object.assign({},this.defaultHeaders,e.headers,{UseXBasic:!0}),delete e.params,e=n?n.getFetchOptions(e):e}getCometdHandshake(t={}){const e=v.get(this);return e?e.getCometdHandshake(t):t}resolveServerUrl(t=""){if(t&&t.startsWith("http"))return t.replace(/\/+$/,"");try{const e=window.location;return`${e.protocol}//${e.host}/${t.replace(/\/+$/,"")}`}catch(t){throw Error("Your environment does not support relative URLs. Please provide a base URL.")}}}var y=function(t){function e(){this.message=t}return e.prototype=new Error,e.prototype.name="InvalidCharacterError",e.prototype.code=5,e},m=y("The string to be encoded contains characters out of range"),b="undefined"!=typeof btoa?function(t){return btoa(t)}:function(t){for(var e,n,i=String(t),r="",s=0,o="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";i.charAt(0|s)||(o="=",s%1);r+=o.charAt(63&e>>8-s%1*8)){if((n=i.charCodeAt(s+=.75))>255)throw new m;e=e<<8|n}return r},T=function(t){return b(function(t){return encodeURIComponent(t).replace(/%([0-9A-F]{2})/g,function(t,e){return String.fromCharCode("0x"+e)})}(t))},O=(y("The string to be decoded is not correctly encoded"),new WeakMap);class w{constructor(t){this.updateCredentials(t)}updateCredentials({tenant:t,user:e,password:n,token:i,tfa:r}={}){const s=O.get(this)||{};return e&&t&&(e=`${t}/${e}`),e=e||this.user,n=n||s.password,!i&&e&&n&&(i=T(`${e}:${n}`)),e&&(this.user=e),i=i||s.token,r=r||s.tfa,O.set(this,{tfa:r,token:i,password:n}),i}getFetchOptions(t){const e=O.get(this),{token:n,tfa:i}=e,r=this.getCookieValue("XSRF-TOKEN"),s=Object.assign({Authorization:`Basic ${n||""}`},r?{"X-XSRF-TOKEN":r}:void 0);return i&&(s.tfatoken=i),t.headers=Object.assign(s,t.headers),t}getCometdHandshake(t={}){const e=O.get(this),{token:n,tfa:i}=e,r="com.cumulocity.authn",s=t.ext=t.ext||{};return s[r]=Object.assign(s[r]||{},{token:n,tfa:i}),t}logout(){delete this.user,O.set(this,{})}getCookieValue(t){try{const e=document.cookie.match("(^|;)\\s*"+t+"\\s*=\\s*([^;]+)");return e?e.pop():void 0}catch(t){return}}}var E=function(t,e,n,i){return new(n||(n=Promise))(function(r,s){function o(t){try{c(i.next(t))}catch(t){s(t)}}function a(t){try{c(i.throw(t))}catch(t){s(t)}}function c(t){var e;t.done?r(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(o,a)}c((i=i.apply(t,e||[])).next())})};const S=t=>t;var U;(U=t.Severity||(t.Severity={}))[U.CRITICAL=S("CRITICAL")]="CRITICAL",U[U.MAJOR=S("MAJOR")]="MAJOR",U[U.MINOR=S("MINOR")]="MINOR",U[U.WARNING=S("WARNING")]="WARNING";class C{constructor(){this.operatorFns={__not:t=>`not(${this.buildQueryFilter(t,null)})`,__and:t=>this.buildQueryFilter(t,null,"and"),__or:t=>this.buildQueryFilter(t,null,"or"),__eq:(t,e)=>"object"==typeof t&&null!==t?this.buildQueryFilter(t,e):`${this.quoteString(e)} eq ${this.quoteString(t)}`,__gt:(t,e)=>`${this.quoteString(e)} gt ${this.quoteString(t)}`,__ge:(t,e)=>`${this.quoteString(e)} ge ${this.quoteString(t)}`,__lt:(t,e)=>`${this.quoteString(e)} lt ${this.quoteString(t)}`,__le:(t,e)=>`${this.quoteString(e)} le ${this.quoteString(t)}`,__in:(t,e)=>{const n=t.filter(t=>!!t).map(t=>`${this.quoteString(e)} eq ${this.quoteString(t)}`);return this.glue(n,"or")},__bygroupid:t=>`bygroupid(${t})`,__has:t=>`has(${t})`,__useFilterQueryString:t=>{var e;const n=null===(e=t.match(/\(.*\)/))||void 0===e?void 0:e[0];return null===n||void 0===n?void 0:n.substring(1,n.length-1)}}}buildQuery(t){const e=[],n=this.buildQueryFilter(t.__filter||t),i=this.buildQueryOrderby(t.__orderby);return n&&e.push(`$filter=(${n})`),i&&e.push(`$orderby=${i}`),e.join(" ")}buildQueryFilter(t,e,n){const i=e||null,r=n||"and",s=[];if(Array.isArray(t))t.forEach(t=>{const e=this.buildQueryFilter(t,null,r);e&&s.push(e)});else{let e;Object.keys(t).forEach(n=>{void 0!==this.operatorFns[n]?(e=this.operatorFns[n](t[n],i))&&s.push(e):(e=this.operatorFns.__eq(t[n],n))&&s.push(e)})}return this.glue(s,r)}buildQueryOrderby(t){const e=[];return t&&t.forEach(t=>{Object.keys(t).forEach(n=>{0!==t[n]&&e.push(`${n} ${t[n]>0?"asc":"desc"}`)})}),e.join(",")}addAndFilter(t,e){return this.addFilter(t,e,"and")}addOrFilter(t,e){return this.addFilter(t,e,"or")}addFilter(t,e,n){const i=t.__orderby?t.__filter||{}:t.__filter||t,r={[`__${n}`]:this.skipEmptyObjects([i,e])};return t.__filter||t.__orderby?(t.__filter=r,t):r}prependOrderbys(t,e){return this.addOrderbys(t,e,"prepend")}appendOrderbys(t,e){return this.addOrderbys(t,e,"append")}addOrderbys(t,e,n){const i=t.__orderby?t.__filter||{}:t.__filter||t,r=t.__orderby||[],s="prepend"===n?[...e,...r]:[...r,...e],o={__orderby:this.skipEmptyObjects(s)};return this.isEmptyObject(i)||(o.__filter=i),o}extractAndMergeOrderBys(t){if((null===t||void 0===t?void 0:t.length)>0){const e=t.map(t=>{var e;return null===(e=t.match(/\$orderby=(.*)$/))||void 0===e?void 0:e[1]}).filter(t=>!!t).join(",");return e?`$orderby=${e}`:""}}glue(t,e){return t.length>1?`(${t.join(`) ${e} (`)})`:t[0]}quoteString(t){return"string"==typeof t?`'${this.escapeSingleQuote(t)}'`:t}skipEmptyObjects(t){return t.filter(t=>!this.isEmptyObject(t))}isEmptyObject(t){return 0===Object.keys(t).length}escapeSingleQuote(t){return"string"!=typeof t?t:t.replace(/\'/g,"''")}}var j=function(t,e,n,i){return new(n||(n=Promise))(function(r,s){function o(t){try{c(i.next(t))}catch(t){s(t)}}function a(t){try{c(i.throw(t))}catch(t){s(t)}}function c(t){var e;t.done?r(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(o,a)}c((i=i.apply(t,e||[])).next())})};class R extends l{constructor(){super(...arguments),this.baseUrl="event",this.listUrl="events",this.propertyName="events",this.channel="/events/*"}detail(t){const e=Object.create(null,{detail:{get:()=>super.detail}});return j(this,void 0,void 0,function*(){return e.detail.call(this,t)})}create(t){const e=Object.create(null,{create:{get:()=>super.create}});return j(this,void 0,void 0,function*(){return e.create.call(this,t)})}update(t){const e=Object.create(null,{update:{get:()=>super.update}});return j(this,void 0,void 0,function*(){return e.update.call(this,t)})}list(t={}){const e=Object.create(null,{list:{get:()=>super.list}});return j(this,void 0,void 0,function*(){return e.list.call(this,t)})}delete(t){const e=Object.create(null,{delete:{get:()=>super.delete}});return j(this,void 0,void 0,function*(){return e.delete.call(this,t)})}}var _="object"==typeof self?self.FormData:window.FormData,x=function(t,e,n,i){return new(n||(n=Promise))(function(r,s){function o(t){try{c(i.next(t))}catch(t){s(t)}}function a(t){try{c(i.throw(t))}catch(t){s(t)}}function c(t){var e;t.done?r(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(o,a)}c((i=i.apply(t,e||[])).next())})};var A=function(t,e,n,i){return new(n||(n=Promise))(function(r,s){function o(t){try{c(i.next(t))}catch(t){s(t)}}function a(t){try{c(i.throw(t))}catch(t){s(t)}}function c(t){var e;t.done?r(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(o,a)}c((i=i.apply(t,e||[])).next())})};class I extends l{constructor(){super(...arguments),this.baseUrl="inventory",this.listUrl="binaries",this.propertyName="managedObjects"}create(t,e={}){return A(this,void 0,void 0,function*(){const n=this.listUrl,i=new _;let r,s,o;e.fileName&&(r=e.fileName,delete e.fileName),e.fileType&&(s=e.fileType,delete e.fileType),r||(r="bin"),"undefined"!=typeof File&&t instanceof File&&(r=t.name,s=t.type),e.name||(e.name=r),e.type||(e.type=s||"c8y_upload"),i.append("file",t,r),i.append("object",JSON.stringify(e)),"function"==typeof i.getHeaders&&(o=i.getHeaders());const a=Object.assign({accept:"application/json"},o),c=yield this.fetch(n,{method:"POST",body:i,headers:a});return{res:c,data:yield c.json()}})}list(t={}){const e=Object.create(null,{list:{get:()=>super.list}});return A(this,void 0,void 0,function*(){return e.list.call(this,t)})}delete(t){const e=Object.create(null,{delete:{get:()=>super.delete}});return A(this,void 0,void 0,function*(){return e.delete.call(this,t)})}download(t){return A(this,void 0,void 0,function*(){const e=this.getDetailUrl(t);return yield this.fetch(e)})}getIdFromUrl(t){if(t){const e=new RegExp("\\/inventory\\/binaries\\/(\\d+)|\\/inventory\\/managedObjects\\/(\\d+)"),n=t.match(e);return n&&(n[1]||n[2])}}}var P=function(t,e,n,i){return new(n||(n=Promise))(function(r,s){function o(t){try{c(i.next(t))}catch(t){s(t)}}function a(t){try{c(i.throw(t))}catch(t){s(t)}}function c(t){var e;t.done?r(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(o,a)}c((i=i.apply(t,e||[])).next())})};!function(t){t.ASSETS="childAssets",t.DEVICES="childDevices",t.ADDITIONS="childAdditions"}(t.ChildType||(t.ChildType={}));class k extends l{constructor(t,e){super(t,e),this.baseUrl="inventory",this.listUrl="managedObjects",this.propertyName="managedObjects",this.channel="/managedobjects/*",this.inventoriesQueryParamName="query",this.devicesQueryParamName="q",this.queriesUtil=new C,this.binary=new I(t)}detail(t,e={}){const n=Object.create(null,{detail:{get:()=>super.detail}});return P(this,void 0,void 0,function*(){return n.detail.call(this,t,e)})}create(t){const e=Object.create(null,{create:{get:()=>super.create}});return P(this,void 0,void 0,function*(){return e.create.call(this,t)})}update(t){const e=Object.create(null,{update:{get:()=>super.update}});return P(this,void 0,void 0,function*(){return e.update.call(this,t)})}list(t={}){const e=Object.create(null,{list:{get:()=>super.list}});return P(this,void 0,void 0,function*(){return e.list.call(this,t)})}listQuery(t,e={}){const n=Object.create(null,{list:{get:()=>super.list}});return P(this,void 0,void 0,function*(){return e[this.inventoriesQueryParamName]=this.queriesUtil.buildQuery(t),n.list.call(this,e)})}listQueryDevices(t,e={}){const n=Object.create(null,{list:{get:()=>super.list}});return P(this,void 0,void 0,function*(){return e[this.devicesQueryParamName]=this.queriesUtil.buildQuery(t),n.list.call(this,e)})}delete(t,e={}){const n=Object.create(null,{delete:{get:()=>super.delete}});return P(this,void 0,void 0,function*(){return n.delete.call(this,t,e)})}childAdditionsList(e,n={}){return P(this,void 0,void 0,function*(){return this.listChildren(t.ChildType.ADDITIONS,e,n)})}childAdditionsCreate(e,n){return P(this,void 0,void 0,function*(){return this.createChild(t.ChildType.ADDITIONS,e,n)})}childAdditionsAdd(e,n){return P(this,void 0,void 0,function*(){return this.addChild(t.ChildType.ADDITIONS,e,n)})}childAdditionsRemove(e,n){return P(this,void 0,void 0,function*(){return this.removeChild(t.ChildType.ADDITIONS,e,n)})}childAssetsList(e,n={}){return P(this,void 0,void 0,function*(){return this.listChildren(t.ChildType.ASSETS,e,n)})}childAssetsCreate(e,n){return P(this,void 0,void 0,function*(){return this.createChild(t.ChildType.ASSETS,e,n)})}childAssetsAdd(e,n){return P(this,void 0,void 0,function*(){return this.addChild(t.ChildType.ASSETS,e,n)})}childAssetsBulkAdd(e,n){return P(this,void 0,void 0,function*(){return this.addChildBulk(t.ChildType.ASSETS,e,n)})}childAssetsRemove(e,n){return P(this,void 0,void 0,function*(){return this.removeChild(t.ChildType.ASSETS,e,n)})}childDevicesList(e,n={}){return P(this,void 0,void 0,function*(){return this.listChildren(t.ChildType.DEVICES,e,n)})}childDevicesCreate(e,n){return P(this,void 0,void 0,function*(){return this.createChild(t.ChildType.DEVICES,e,n)})}childDevicesAdd(e,n){return P(this,void 0,void 0,function*(){return this.addChild(t.ChildType.DEVICES,e,n)})}childDevicesRemove(e,n){return P(this,void 0,void 0,function*(){return this.removeChild(t.ChildType.DEVICES,e,n)})}getSupportedMeasurements(t){return P(this,void 0,void 0,function*(){return this.getSupportedMeasurementDetails(t,"supportedMeasurements")})}getSupportedSeries(t){return P(this,void 0,void 0,function*(){return this.getSupportedMeasurementDetails(t,"supportedSeries")})}getMeasurementsAndSeries(t){return P(this,void 0,void 0,function*(){const[e,n]=yield Promise.all([this.getSupportedMeasurements(t),this.getSupportedSeries(t)]),i=e.sort((t,e)=>e.length-t.length);return n.map(t=>{const e=i.find(e=>0===t.indexOf(`${e}.`));return{fragment:e,series:t.replace(`${e}.`,"")}}).filter(t=>!!t.fragment)})}assetKPIsList(t,e={}){return P(this,void 0,void 0,function*(){return this.listKPIs(t,e)})}listKPIs(t,e={}){return P(this,void 0,void 0,function*(){const n=this.getChildrenUrl("kpis",t),i=yield this.fetch(n,this.changeFetchOptions({headers:{accept:"application/json"},params:e},n)),r=yield i.json();return{res:i,data:r[this.propertyName],paging:this.getPaging(r,e)}})}onBeforeUpdate(t){return delete t.lastUpdated,t}onBeforeCreate(t){return delete t.id,delete t.lastUpdated,t}getChildrenUrl(t,e){return`${this.getDetailUrl(e)}/${t}`}getChildUrl(t,e,n){const i=this.getIdString(e);return`${this.getChildrenUrl(t,n)}/${i}`}listChildren(t,e,n={}){return P(this,void 0,void 0,function*(){const i=this.getChildrenUrl(t,e),r=yield this.fetch(i,{headers:{"content-type":"application/json"},params:n}),s=yield r.json(),o=s.references.map(t=>t.managedObject),a=this.getPaging(s,n);return a.list=(n=>this.listChildren(t,e,n)),{res:r,data:o,paging:a}})}createChild(t,e,n){return P(this,void 0,void 0,function*(){const i=this.getChildrenUrl(t,n),r=JSON.stringify(this.onBeforeCreate(e)),s={"content-type":this.mimeType("managedObject"),accept:"application/json"},o=yield this.fetch(i,{method:"POST",body:r,headers:s});return{res:o,data:yield o.json()}})}addChild(t,e,n){return P(this,void 0,void 0,function*(){const i=this.getChildrenUrl(t,n),r=this.getIdString(e),s=JSON.stringify({managedObject:{id:String(r)}}),o={accept:"application/json","content-type":this.mimeType("managedObjectReference")},a=yield this.fetch(i,{method:"POST",body:s,headers:o});let c=yield a.json();return{res:a,data:c=c.managedObject}})}addChildBulk(t,e,n){return P(this,void 0,void 0,function*(){const i=this.getChildrenUrl(t,n),r=e.map(t=>({managedObject:{id:this.getIdString(t)}})),s=JSON.stringify({references:r}),o={accept:"application/json","content-type":this.mimeType("managedObjectReferenceCollection")},a=yield this.fetch(i,{method:"POST",body:s,headers:o});return{res:a,data:(yield a.json()).references.map(t=>t.managedObject)}})}removeChild(t,e,n){return P(this,void 0,void 0,function*(){const i=this.getIdString(e),r=`${this.getChildrenUrl(t,n)}/${i}`;return{res:yield this.fetch(r,{method:"DELETE",headers:{accept:"application/json"}}),data:null}})}getSupportedMeasurementDetails(t,e="supportedSeries"){return P(this,void 0,void 0,function*(){const n=`${this.getDetailUrl(t)}/${e}`;this.getIdString(t);const i=yield(yield this.fetch(n,{headers:{accept:"application/json"}})).json();return i.c8y_SupportedMeasurements||i.c8y_SupportedSeries})}}var N,D=function(t,e,n,i){return new(n||(n=Promise))(function(r,s){function o(t){try{c(i.next(t))}catch(t){s(t)}}function a(t){try{c(i.throw(t))}catch(t){s(t)}}function c(t){var e;t.done?r(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(o,a)}c((i=i.apply(t,e||[])).next())})};class $ extends l{constructor(){super(...arguments),this.baseUrl="measurement",this.listUrl="measurements",this.propertyName="measurements",this.channel="/measurements/*"}detail(t){const e=Object.create(null,{detail:{get:()=>super.detail}});return D(this,void 0,void 0,function*(){return e.detail.call(this,t)})}create(t){const e=Object.create(null,{create:{get:()=>super.create}});return D(this,void 0,void 0,function*(){return e.create.call(this,this.onBeforeCreate(t))})}list(t={}){const e=Object.create(null,{list:{get:()=>super.list}});return D(this,void 0,void 0,function*(){return e.list.call(this,t)})}delete(t){const e=Object.create(null,{delete:{get:()=>super.delete}});return D(this,void 0,void 0,function*(){return e.delete.call(this,t)})}listSeries(t){return D(this,void 0,void 0,function*(){const e=`${this.baseUrl}/${this.listUrl}/series`,n=yield this.client.fetch(e,{params:t});return{res:n,data:yield n.json()}})}onBeforeCreate(t){if(t.time||(t.time=new Date),t.type||(t.type="c8y_Measurement"),t.sourceId){const{sourceId:e}=t;delete t.sourceId,t.source||(t.source={id:String(e)})}return t}}(N=t.aggregationType||(t.aggregationType={})).MINUTELY="MINUTELY",N.HOURLY="HOURLY",N.DAILY="DAILY";var L,F=function(t,e,n,i){return new(n||(n=Promise))(function(r,s){function o(t){try{c(i.next(t))}catch(t){s(t)}}function a(t){try{c(i.throw(t))}catch(t){s(t)}}function c(t){var e;t.done?r(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(o,a)}c((i=i.apply(t,e||[])).next())})};class B extends l{constructor(){super(...arguments),this.baseUrl="alarm",this.listUrl="alarms",this.propertyName="alarms",this.channel="/alarms/*"}detail(t){const e=Object.create(null,{detail:{get:()=>super.detail}});return F(this,void 0,void 0,function*(){return e.detail.call(this,t)})}create(t){const e=Object.create(null,{create:{get:()=>super.create}});return F(this,void 0,void 0,function*(){return e.create.call(this,t)})}update(t){const e=Object.create(null,{update:{get:()=>super.update}});return F(this,void 0,void 0,function*(){return e.update.call(this,t)})}list(t={}){const e=Object.create(null,{list:{get:()=>super.list}});return F(this,void 0,void 0,function*(){return e.list.call(this,t)})}}(L=t.AlarmStatus||(t.AlarmStatus={}))[L.ACKNOWLEDGED=S("ACKNOWLEDGED")]="ACKNOWLEDGED",L[L.CLEARED=S("CLEARED")]="CLEARED",L[L.ACTIVE=S("ACTIVE")]="ACTIVE";var M=function(t,e,n,i){return new(n||(n=Promise))(function(r,s){function o(t){try{c(i.next(t))}catch(t){s(t)}}function a(t){try{c(i.throw(t))}catch(t){s(t)}}function c(t){var e;t.done?r(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(o,a)}c((i=i.apply(t,e||[])).next())})};class G extends l{constructor(){super(...arguments),this.baseUrl="devicecontrol",this.listUrl="operations",this.propertyName="operations"}detail(t){const e=Object.create(null,{detail:{get:()=>super.detail}});return M(this,void 0,void 0,function*(){return e.detail.call(this,t)})}create(t){const e=Object.create(null,{create:{get:()=>super.create}});return M(this,void 0,void 0,function*(){return e.create.call(this,t)})}update(t){const e=Object.create(null,{update:{get:()=>super.update}});return M(this,void 0,void 0,function*(){return e.update.call(this,t)})}list(t={}){const e=Object.create(null,{list:{get:()=>super.list}});return M(this,void 0,void 0,function*(){return e.list.call(this,t)})}}var H,V,q,J=function(t,e,n,i){return new(n||(n=Promise))(function(r,s){function o(t){try{c(i.next(t))}catch(t){s(t)}}function a(t){try{c(i.throw(t))}catch(t){s(t)}}function c(t){var e;t.done?r(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(o,a)}c((i=i.apply(t,e||[])).next())})};class X extends l{constructor(){super(...arguments),this.baseUrl="devicecontrol",this.listUrl="bulkoperations",this.propertyName="bulkOperations"}detail(t){const e=Object.create(null,{detail:{get:()=>super.detail}});return J(this,void 0,void 0,function*(){return e.detail.call(this,t)})}create(t){const e=Object.create(null,{create:{get:()=>super.create}});return J(this,void 0,void 0,function*(){return e.create.call(this,t)})}update(t){const e=Object.create(null,{update:{get:()=>super.update}});return J(this,void 0,void 0,function*(){return e.update.call(this,t)})}list(t={}){const e=Object.create(null,{list:{get:()=>super.list}});return J(this,void 0,void 0,function*(){return e.list.call(this,t)})}delete(t){const e=Object.create(null,{delete:{get:()=>super.delete}});return J(this,void 0,void 0,function*(){return e.delete.call(this,t)})}}(H=t.OperationBulkStatus||(t.OperationBulkStatus={}))[H.ACTIVE=S("ACTIVE")]="ACTIVE",H[H.IN_PROGRESS=S("IN_PROGRESS")]="IN_PROGRESS",H[H.COMPLETED=S("COMPLETED")]="COMPLETED",H[H.DELETED=S("DELETED")]="DELETED",(V=t.OperationBulkGeneralStatus||(t.OperationBulkGeneralStatus={}))[V.SCHEDULED=S("SCHEDULED")]="SCHEDULED",V[V.EXECUTING=S("EXECUTING")]="EXECUTING",V[V.EXECUTING_WITH_ERROR=S("EXECUTING_WITH_ERROR")]="EXECUTING_WITH_ERROR",V[V.CANCELED=S("CANCELED")]="CANCELED",V[V.FAILED=S("FAILED")]="FAILED",V[V.SUCCESSFUL=S("SUCCESSFUL")]="SUCCESSFUL",V[V.DELETED=S("DELETED")]="DELETED",V[V.INCORRECT=S("INCORRECT")]="INCORRECT",(q=t.OperationStatus||(t.OperationStatus={}))[q.PENDING=S("PENDING")]="PENDING",q[q.EXECUTING=S("EXECUTING")]="EXECUTING",q[q.SUCCESSFUL=S("SUCCESSFUL")]="SUCCESSFUL",q[q.FAILED=S("FAILED")]="FAILED";var W,Q,Y=function(t,e,n,i){return new(n||(n=Promise))(function(r,s){function o(t){try{c(i.next(t))}catch(t){s(t)}}function a(t){try{c(i.throw(t))}catch(t){s(t)}}function c(t){var e;t.done?r(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(o,a)}c((i=i.apply(t,e||[])).next())})};class K extends l{constructor(){super(...arguments),this.baseUrl="tenant",this.listUrl="tenants",this.currentTenantUrl="currentTenant",this.propertyName="tenants",this.fetchOptions={method:"PUT",body:"{}",headers:{"content-type":"application/json",accept:"application/json"}}}detail(t){const e=Object.create(null,{detail:{get:()=>super.detail}});return Y(this,void 0,void 0,function*(){return e.detail.call(this,t)})}create(t){const e=Object.create(null,{create:{get:()=>super.create}});return Y(this,void 0,void 0,function*(){return e.create.call(this,t)})}update(t){const e=Object.create(null,{update:{get:()=>super.update}});return Y(this,void 0,void 0,function*(){return e.update.call(this,t)})}list(t={}){const e=Object.create(null,{list:{get:()=>super.list}});return Y(this,void 0,void 0,function*(){return e.list.call(this,t)})}delete(t){const e=Object.create(null,{delete:{get:()=>super.delete}});return Y(this,void 0,void 0,function*(){return e.delete.call(this,t)})}current(){return Y(this,void 0,void 0,function*(){const t=yield this.fetch(this.currentTenantUrl,{headers:{"content-type":"application/json"}});return{res:t,data:yield t.json()}})}enableSupportUser(){return Y(this,void 0,void 0,function*(){return{res:yield this.fetch("support-user/enable",this.fetchOptions),data:null}})}disableSupportUser(){return Y(this,void 0,void 0,function*(){return{res:yield this.fetch("support-user/disable",this.fetchOptions),data:null}})}currentTenantType(){return Y(this,void 0,void 0,function*(){const t=yield this.current();return t.data.customProperties&&"TRIAL"===t.data.customProperties.tenantType?"TRIAL":"REGULAR"})}getTfaSettings(t){return Y(this,void 0,void 0,function*(){const e=`tenants/${this.getIdString(t)}/tfa`;return yield(yield this.fetch(e)).json()})}subscribeApplication(t,e){return Y(this,void 0,void 0,function*(){const n=this.getIdString(t),i=e.id,r=`tenants/${n}/applications`,s=JSON.stringify({application:{id:i,self:e.self}}),o={"content-type":this.mimeType("applicationReference")};return{res:yield this.fetch(r,this.changeFetchOptions({method:"POST",body:s,headers:o},r)),data:null}})}unsubscribeApplication(t,e){return Y(this,void 0,void 0,function*(){const n=`tenants/${this.getIdString(t)}/applications/${e.id}`;return{res:yield this.fetch(n,this.changeFetchOptions({method:"DELETE"},n)),data:null}})}getIdString(t){return t.id||t.name}onBeforeCreate(t){return t}}(W=t.TenantStatus||(t.TenantStatus={}))[W.ACTIVE=S("ACTIVE")]="ACTIVE",W[W.SUSPENDED=S("SUSPENDED")]="SUSPENDED",(Q=t.TfaStrategy||(t.TfaStrategy={})).TOTP="TOTP",Q.SMS="SMS";var z=function(t,e,n,i){return new(n||(n=Promise))(function(r,s){function o(t){try{c(i.next(t))}catch(t){s(t)}}function a(t){try{c(i.throw(t))}catch(t){s(t)}}function c(t){var e;t.done?r(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(o,a)}c((i=i.apply(t,e||[])).next())})};class Z extends l{constructor(t,e){super(e),this.listUrl="inventory",this.currenUserUrl="currentUser",this.propertyName="inventoryAssignments",this.baseUrl=`user/${t}/roles`}detail(t){const e=Object.create(null,{detail:{get:()=>super.detail}});return z(this,void 0,void 0,function*(){return e.detail.call(this,t)})}create(t){const e=Object.create(null,{create:{get:()=>super.create}});return z(this,void 0,void 0,function*(){return e.create.call(this,t)})}update(t){const e=Object.create(null,{update:{get:()=>super.update}});return z(this,void 0,void 0,function*(){return e.update.call(this,t)})}list(t={}){const e=Object.create(null,{list:{get:()=>super.list}});return z(this,void 0,void 0,function*(){return e.list.call(this,t)})}delete(t){const e=Object.create(null,{delete:{get:()=>super.delete}});return z(this,void 0,void 0,function*(){return e.delete.call(this,t)})}}var tt,et=function(t,e,n,i){return new(n||(n=Promise))(function(r,s){function o(t){try{c(i.next(t))}catch(t){s(t)}}function a(t){try{c(i.throw(t))}catch(t){s(t)}}function c(t){var e;t.done?r(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(o,a)}c((i=i.apply(t,e||[])).next())})};class nt extends l{constructor(){super(...arguments),this.baseUrl="user",this.currentUserUrl="currentUser",this.passwordResetUrl="passwordReset",this.currentUserPhoneUrl="currentUserPhone",this.verifyTFACodeUrl="pin",this.totpCurrentUserURL=`${this.currentUserUrl}/totpSecret`,this.verifyTOTPCodeUrl=`${this.totpCurrentUserURL}/verify`,this.activateTOTPCodeUrl=`${this.totpCurrentUserURL}/activity`,this.revokeTOTPSecretUrl="totpSecret/revoke",this.propertyName="users"}get listUrl(){return`${this.client.tenant}/users`}get newsletterEmailsUrl(){return`${this.client.tenant}/users/newsletterEmails`}get currentUserPasswordUrl(){return`${this.currentUserUrl}/password`}get revokeAllTokensUrl(){return`/logout/${this.client.tenant}/allUsers`}detail(t){const e=Object.create(null,{detail:{get:()=>super.detail}});return et(this,void 0,void 0,function*(){return e.detail.call(this,t)})}create(t){const e=Object.create(null,{create:{get:()=>super.create}});return et(this,void 0,void 0,function*(){return e.create.call(this,t)})}update(t){const e=Object.create(null,{update:{get:()=>super.update}});return et(this,void 0,void 0,function*(){return e.update.call(this,t)})}list(t={}){const e=Object.create(null,{list:{get:()=>super.list}});return et(this,void 0,void 0,function*(){return e.list.call(this,t)})}delete(t){const e=Object.create(null,{delete:{get:()=>super.delete}});return et(this,void 0,void 0,function*(){return e.delete.call(this,t)})}inventoryAssignment(t){return new Z(this.getDetailUrl(t),this.client)}current(){return et(this,void 0,void 0,function*(){const t=yield this.fetch(this.currentUserUrl,{headers:{"content-type":"application/json",Accept:"application/vnd.com.nsn.cumulocity.user+json;"}});return{res:t,data:yield t.json()}})}currentWithEffectiveRoles(){return et(this,void 0,void 0,function*(){const t=yield this.fetch(this.currentUserUrl,{headers:{"content-type":"application/json",Accept:"application/vnd.com.nsn.cumulocity.currentUser+json;"}});return{res:t,data:yield t.json()}})}updateCurrent(t){return et(this,void 0,void 0,function*(){const e="application/vnd.com.nsn.cumulocity.user+json",n={"content-type":e,Accept:e},i=JSON.stringify(this.onBeforeUpdate(t)),r=yield this.fetch(this.currentUserUrl,{headers:n,body:i,method:"PUT"});return{res:r,data:yield r.json()}})}sendPasswordResetMail(t,e){return et(this,void 0,void 0,function*(){const n=this.passwordResetUrl,i=e?{tenantId:e}:{},r=JSON.stringify({email:t});return{res:yield this.fetch(n,{headers:{"content-type":"application/json",accept:"application/json"},method:"POST",params:i,body:r}),data:null}})}resetPassword(t,e){return et(this,void 0,void 0,function*(){const n=this.passwordResetUrl,i=e?{tenantId:e}:{},r=JSON.stringify(t);return{res:yield this.fetch(n,{headers:{"content-type":"application/json",accept:"application/json"},method:"PUT",params:i,body:r}),data:null}})}verifyTFACode(t){return et(this,void 0,void 0,function*(){const e=JSON.stringify({pin:t});return{res:yield this.fetch(this.verifyTFACodeUrl,{headers:{"content-type":"application/json",accept:"application/json"},body:e,method:"POST"}),data:null}})}verifyTotpCode(t){return et(this,void 0,void 0,function*(){const e=JSON.stringify({code:t});return{res:yield this.fetch(this.verifyTOTPCodeUrl,{headers:{"content-type":"application/json"},body:e,method:"POST"}),data:null}})}activateTotp(){return et(this,void 0,void 0,function*(){const t=JSON.stringify({isActive:!0});return{res:yield this.fetch(this.activateTOTPCodeUrl,{headers:{"content-type":"application/json"},body:t,method:"POST"}),data:null}})}getActivityTotp(){return et(this,void 0,void 0,function*(){const t=yield this.fetch(this.activateTOTPCodeUrl,{headers:{"content-type":"application/json"},method:"GET"});return{res:t,data:yield t.json()}})}generateTotpSecret(){return et(this,void 0,void 0,function*(){const t=yield this.fetch(this.totpCurrentUserURL,{headers:{"content-type":"application/json",accept:"application/json"},method:"POST"});return{res:t,data:yield t.json()}})}totpRevokeSecret(t){return et(this,void 0,void 0,function*(){const e=`${this.getDetailUrl(t)}/${this.revokeTOTPSecretUrl}`;return{res:yield this.fetch(e,{headers:{accept:"application/json"},method:"DELETE"}),data:null}})}savePhoneNumber(t){return et(this,void 0,void 0,function*(){const e=this.currentUserPhoneUrl,n={method:"PUT",headers:{"content-type":"application/json",accept:"application/json"},body:JSON.stringify({phone:t})},i=yield this.fetch(e,n);return{res:i,data:yield i.json()}})}getNewsletterEmails(){return et(this,void 0,void 0,function*(){const t=this.newsletterEmailsUrl,e=yield this.fetch(t,{method:"GET",headers:{accept:"text/plain"}});return{res:e,data:yield e.text()}})}changeUserPassword(t,e,n){return et(this,void 0,void 0,function*(){const i=JSON.stringify({newPassword:e,currentUserPassword:n});return{res:yield this.fetch(this.changeUserPasswordUrl(t),{headers:{"content-type":"application/json"},body:i,method:"PUT"}),data:null}})}changeCurrentUserPassword(t,e){return et(this,void 0,void 0,function*(){const n=JSON.stringify({newPassword:t,currentUserPassword:e});return{res:yield this.fetch(this.currentUserPasswordUrl,{headers:{"content-type":"application/json"},body:n,method:"PUT"}),data:null}})}revokeTokens(){return et(this,void 0,void 0,function*(){return{res:yield this.fetch(this.revokeAllTokensUrl,{headers:{"content-type":"application/json"},method:"POST"}),data:null}})}hasRole(t,e){return this.hasRoleInUser(t,e)||this.hasRoleInGroups(t,e)}hasAllRoles(t,e){return e.every(e=>this.hasRole(t,e))}hasAnyRole(t,e){return e.some(e=>this.hasRole(t,e))}hasAnyGlobalRole(t,e){return e.some(e=>this.hasGlobalRoleInUser(t,e))}isDeviceUser(t){return t.id.match(/^device_/)}onBeforeUpdate(t){const e=Object.assign({},t);return delete e.id,delete e.userName,e}getDetailUrl(t){return`${this.listUrl}/${encodeURIComponent(this.getId(t))}`}getId(t){let e;return e="object"==typeof t&&t.id?t.id:"object"==typeof t&&t.userName?t.userName:t,String(e)}hasRoleInUser(t,e){const n=t.effectiveRoles||[];return this.hasRoleInReferences(t&&t.roles&&t.roles.references||[],e)||n.some(({id:t})=>e===t)}hasRoleInGroups(t,e){return(t&&t.groups&&t.groups.references||[]).some(t=>this.hasRoleInReferences(t.group.roles.references,e))}hasRoleInReferences(t,e){return t.some(t=>t.role.id===e)}changeUserPasswordUrl(t){return`${this.client.tenant}/users/${this.getId(t)}/password`}hasGlobalRoleInUser(t,e){var n;return((null===(n=null===t||void 0===t?void 0:t.groups)||void 0===n?void 0:n.references)||[]).map(t=>{var e;return null===(e=null===t||void 0===t?void 0:t.group)||void 0===e?void 0:e.id}).some(t=>t===e)}}(tt=t.PasswordStrength||(t.PasswordStrength={})).GREEN="GREEN",tt.RED="RED",tt.YELLOW="YELLOW";var it,rt=function(t,e,n,i){return new(n||(n=Promise))(function(r,s){function o(t){try{c(i.next(t))}catch(t){s(t)}}function a(t){try{c(i.throw(t))}catch(t){s(t)}}function c(t){var e;t.done?r(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(o,a)}c((i=i.apply(t,e||[])).next())})};class st extends l{constructor(t,e){super(t),this.listUrl="binaries",this.propertyName="attachments",this.baseUrl=`application/applications/${this.getIdString(e)}`}upload(t,e,n){return rt(this,void 0,void 0,function*(){const i=(null===n||void 0===n?void 0:n.listUrl)||this.listUrl,r=this.createBinaryRequestBody(t,e,n);let s;"function"==typeof r.getHeaders&&(s=r.getHeaders());const o=Object.assign((null===n||void 0===n?void 0:n.headers)||{Accept:"application/json"},s),a=yield this.fetch(i,{method:"POST",body:r,headers:o});return{res:a,data:yield a.json()}})}uploadWithProgressXhr(t,e,n,i){const r=`/${this.baseUrl}/${(null===i||void 0===i?void 0:i.listUrl)||this.listUrl}`,s=this.createBinaryRequestBody(t,n,i);let o;"function"==typeof s.getHeaders&&(o=s.getHeaders());const a=this.client.getFetchOptions().headers;Object.assign(a,(null===i||void 0===i?void 0:i.headers)||{Accept:"application/json"}),Object.assign(a,o);const c=new XMLHttpRequest;c.open("POST",r,!0);for(const t in a)a.hasOwnProperty(t)&&c.setRequestHeader(t,a[t]);return c.upload.addEventListener("progress",e),c.send(s),c}getXMLHttpResponse(t){return new Promise((e,n)=>{t.addEventListener("loadend",()=>{4!==t.readyState||200!==t.status&&201!==t.status?n(t.responseText?{data:JSON.parse(t.responseText)}:"Could not upload file."):e(JSON.parse(t.responseText))})})}list(t){const e=Object.create(null,{list:{get:()=>super.list}});return rt(this,void 0,void 0,function*(){return e.list.call(this,t)})}delete(t){const e=Object.create(null,{delete:{get:()=>super.delete}});return rt(this,void 0,void 0,function*(){return e.delete.call(this,t)})}listPlugins(){return rt(this,void 0,void 0,function*(){const t=`${this.listUrl}/plugins`,e=yield this.fetch(t,{headers:{accept:"application/json"}});return{res:e,data:yield e.json()}})}addPlugin(t,e){return rt(this,void 0,void 0,function*(){const n=`${this.listUrl}/plugins/${encodeURIComponent(t)}`,i=new _,r=e instanceof ArrayBuffer?Buffer.from(e):e;let s;i.append("file",r),"function"==typeof i.getHeaders&&(s=i.getHeaders());const o=Object.assign({accept:"application/json"},s),a=yield this.fetch(n,{method:"POST",body:i,headers:o});return{res:a,data:yield a.json()}})}removePlugin(t){return rt(this,void 0,void 0,function*(){const e=`${this.listUrl}/plugins/${t}`,n=yield this.fetch(e,{method:"DELETE",headers:{accept:"application/json"}});return{res:n,data:yield n.json()}})}updateFiles(t){return rt(this,void 0,void 0,function*(){const e=`${this.listUrl}/files`,n=new _;let i;t.forEach(t=>{const e=t.contents instanceof ArrayBuffer?Buffer.from(t.contents):t.contents;n.append(t.path,e)}),"function"==typeof n.getHeaders&&(i=n.getHeaders());const r=Object.assign({accept:"application/json"},i),s=yield this.fetch(e,{method:"POST",body:n,headers:r});return{res:s,data:yield s.json()}})}downloadArchive(t){return rt(this,void 0,void 0,function*(){const e=`${this.listUrl}/${t}`;return yield this.fetch(e)})}createBinaryRequestBody(t,e,n){const i=new _,r=t instanceof ArrayBuffer?Buffer.from(t):t;let s=e;if("undefined"!=typeof File&&t instanceof File&&(s=t.name),i.append((null===n||void 0===n?void 0:n.bodyFileProperty)||"file",r,s),i.append("fileName",s),null===n||void 0===n?void 0:n.requestBody)for(const t in n.requestBody)n.requestBody.hasOwnProperty(t)&&i.append(t,JSON.stringify(n.requestBody[t]));return i}}(it=t.ApplicationType||(t.ApplicationType={})).EXTERNAL="EXTERNAL",it.HOSTED="HOSTED",it.MICROSERVICE="MICROSERVICE",it.FEATURE="FEATURE",it.REPOSITORY="REPOSITORY";var ot,at,ct,ut,lt=function(t,e,n,i){return new(n||(n=Promise))(function(r,s){function o(t){try{c(i.next(t))}catch(t){s(t)}}function a(t){try{c(i.throw(t))}catch(t){s(t)}}function c(t){var e;t.done?r(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(o,a)}c((i=i.apply(t,e||[])).next())})};class dt extends l{constructor(){super(...arguments),this.baseUrl="application",this.listUrl="applications",this.propertyName="applications",this.channel="/applications/*"}create(t){const e=Object.create(null,{create:{get:()=>super.create}});return lt(this,void 0,void 0,function*(){return e.create.call(this,t)})}clone(t){return lt(this,void 0,void 0,function*(){const e=`${this.getDetailUrl(t)}/clone`,n=yield this.fetch(e,{method:"POST",body:"",headers:{"content-type":"application/json",accept:"application/json"}});return{res:n,data:yield n.json()}})}list(t={}){const e=Object.create(null,{list:{get:()=>super.list}});return lt(this,void 0,void 0,function*(){return e.list.call(this,t)})}listVersions(t,e={}){var n;return lt(this,void 0,void 0,function*(){const i=this.getEntityId(t),r=`${this.listUrl}/${i}/versions`,s={"content-type":"application/json"};try{const i=yield this.fetch(r,{headers:s,params:e});return{res:i,data:null===(n=yield i.json())||void 0===n?void 0:n.applicationVersions}}catch(e){if(404===e.res.status){const{data:e,res:n}=yield this.detail(t);return{res:n,data:e.applicationVersions}}throw e}})}detail(t){const e=Object.create(null,{detail:{get:()=>super.detail}});return lt(this,void 0,void 0,function*(){return e.detail.call(this,t)})}update(t){const e=Object.create(null,{update:{get:()=>super.update}});return lt(this,void 0,void 0,function*(){return e.update.call(this,t)})}delete(t){const e=Object.create(null,{delete:{get:()=>super.delete}});return lt(this,void 0,void 0,function*(){return e.delete.call(this,t)})}listByName(t){return lt(this,void 0,void 0,function*(){const e=`applicationsByName/${encodeURIComponent(t)}`,n=yield this.fetch(e,{headers:{"content-type":"application/json"}});return{res:n,data:(yield n.json())[this.propertyName]}})}listByTenant(t,e={}){return lt(this,void 0,void 0,function*(){const n=new K(this.client),i=this.getIdString(t||(yield n.current()).data.name),r=`applicationsByTenant/${encodeURIComponent(i)}`,s=yield this.fetch(r,{headers:{"content-type":"application/json"},params:e});return{res:s,data:(yield s.json())[this.propertyName]}})}listByOwner(t,e={}){return lt(this,void 0,void 0,function*(){const n=new K(this.client),i=this.getIdString(t||(yield n.current()).data.name),r=`applicationsByOwner/${encodeURIComponent(i)}`,s=yield this.fetch(r,{headers:{"content-type":"application/json"},params:e});return{res:s,data:(yield s.json())[this.propertyName]}})}listByUser(t,e={}){return lt(this,void 0,void 0,function*(){const n=new nt(this.client),i=this.getIdString(t||(yield n.current()).data),r=`applicationsByUser/${encodeURIComponent(i)}`,s=yield this.fetch(r,{headers:{"content-type":"application/json"},params:e});return{res:s,data:(yield s.json())[this.propertyName]}})}reactivateArchive(t){return lt(this,void 0,void 0,function*(){const e=`${this.listUrl}/${t}/refresh`;return{res:yield this.fetch(e,{method:"POST",body:"",headers:{"content-type":"application/json",accept:"application/json"}}),data:null}})}binary(t){return new st(this.client,t)}getHref(e){return e.type===t.ApplicationType.EXTERNAL?e.externalUrl:`/apps/${e.public?"public/":""}${e.contextPath}`}isAvailable(t){return lt(this,void 0,void 0,function*(){const{res:e,data:n}=yield this.listByUser(void 0,{dropOverwrittenApps:!0,noPaging:!0});return{data:(n||[]).some(e=>"string"==typeof t?e.name===t||e.contextPath===t:this.isMatch(e,t)),res:e}})}getStatusDetails(t){return lt(this,void 0,void 0,function*(){const e=this.getEntityId(t);return new k(this.client,this.realtime).list({type:`c8y_Application_${e}`})})}getInstanceNames(t){let e=new Array;return t&&t.c8y_Status&&t.c8y_Status.instances&&(e=Object.keys(t.c8y_Status.instances)),e}getInstanceLog(t,e,n){return lt(this,void 0,void 0,function*(){const i=`${this.getDetailUrl(t)}/logs/${e}`,r={accept:this.mimeType("applicationLogs")},s=yield this.fetch(i,{headers:r,params:n});return{res:s,data:yield s.json()}})}updateApplicationConfig(t,e){var n;return lt(this,void 0,void 0,function*(){const i=this.getEntityId(t),{data:r}=yield this.detail(i),s=(null===r||void 0===r?void 0:r.config)||{},o=Object.assign(Object.assign({},s),e),a=yield this.update({id:i,config:o});return null===(n=yield a)||void 0===n?void 0:n.data})}getAppManifest(t,e){return lt(this,void 0,void 0,function*(){const n=new Date;let i;if((i=e?yield this.client.fetch(`/apps/${t.contextPath}@${e}/cumulocity.json?nocache=${n.getTime()}`):yield this.client.fetch(`/apps/${t.contextPath}/cumulocity.json?nocache=${n.getTime()}`)).status>=400)throw new Error(S("No Cumulocity IoT manifest found."));return yield i.json()})}storeAppManifest(t,e){return lt(this,void 0,void 0,function*(){return yield this.binary(t).updateFiles([{path:"cumulocity.json",contents:JSON.stringify(e)}])})}setPackageVersionTag(t,e,n){return lt(this,void 0,void 0,function*(){const i=`${this.getDetailUrl(t)}/versions/${e}`,r=JSON.stringify({tags:n}),s=yield this.fetch(i,{method:"PUT",body:r,headers:{accept:"application/vnd.com.nsn.cumulocity.applicationVersion+json;charset=UTF-8;ver=0.9","content-type":"application/json"}});return{res:s,data:yield s.json()}})}getManifestOfContextPath(t){return lt(this,void 0,void 0,function*(){const e=`${this.getDetailUrl(t)}/manifest`,n=yield this.fetch(e),{application:i}=yield n.json();return{res:n,data:i}})}deleteVersionPackage(t,e){return lt(this,void 0,void 0,function*(){const n=`${this.getDetailUrl(t)}/versions/`;return{res:yield this.fetch(n,this.changeFetchOptions({method:"DELETE",params:e},n)),data:null}})}updateApplicationAvailability(t,e){return lt(this,void 0,void 0,function*(){const n=this.getEntityId(t);return yield this.update({id:n,availability:e})})}isMatch(t,e){return Object.keys(e).every(n=>Array.isArray(t[n])&&Array.isArray(e[n])?e[n].every(e=>t[n].includes(e)):"object"==typeof t[n]&&null!==t[n]&&"object"==typeof e[n]&&null!==e[n]?this.isMatch(t[n],e[n]):t[n]===e[n])}}(ot=t.InstanceStatus||(t.InstanceStatus={})).Up="Up",ot.Unhealthy="Unhealthy",ot.Down="Down",ot.Unknown="Unknown",(at=t.BillingMode||(t.BillingMode={})).SUBSCRIPTION="SUBSCRIPTION",at.RESOURCES="RESOURCES",(ct=t.Isolation||(t.Isolation={})).PER_TENANT="PER_TENANT",ct.MULTI_TENANT="MULTI_TENANT",(ut=t.ApplicationAvailability||(t.ApplicationAvailability={}))[ut.MARKET=S("MARKET")]="MARKET",ut[ut.PRIVATE=S("PRIVATE")]="PRIVATE",ut[ut.SHARED=S("SHARED")]="SHARED";var ht=function(t,e,n,i){return new(n||(n=Promise))(function(r,s){function o(t){try{c(i.next(t))}catch(t){s(t)}}function a(t){try{c(i.throw(t))}catch(t){s(t)}}function c(t){var e;t.done?r(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(o,a)}c((i=i.apply(t,e||[])).next())})};class pt extends l{constructor(){super(...arguments),this.baseUrl="tenant/system",this.listUrl="options",this.propertyName="options"}detail(t){const e=Object.create(null,{detail:{get:()=>super.detail}});return ht(this,void 0,void 0,function*(){return e.detail.call(this,t)})}list(t={}){return ht(this,void 0,void 0,function*(){const e=this.listUrl,n=yield this.fetch(e,{headers:{"content-type":"application/json"},params:t});return{res:n,data:(yield n.json())[this.propertyName]}})}getDetailUrl(t){return`${this.listUrl}/${t.category}/${t.key}`}onBeforeCreate(t){return t}}var ft=function(t,e,n,i){return new(n||(n=Promise))(function(r,s){function o(t){try{c(i.next(t))}catch(t){s(t)}}function a(t){try{c(i.throw(t))}catch(t){s(t)}}function c(t){var e;t.done?r(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(o,a)}c((i=i.apply(t,e||[])).next())})};class vt extends l{constructor(){super(...arguments),this.baseUrl="tenant",this.listUrl="options",this.propertyName="options",this.securityOptionsCategories=["password"],this.securityOptionsListUrl="security-options",this.systemOptions="system"}detail(t,e={}){const n=Object.create(null,{detail:{get:()=>super.detail}});return ft(this,void 0,void 0,function*(){return n.detail.call(this,t,e)})}create(t){const e=Object.create(null,{create:{get:()=>super.create}});return ft(this,void 0,void 0,function*(){return e.create.call(this,t)})}update(t){const e=Object.create(null,{update:{get:()=>super.update}});return ft(this,void 0,void 0,function*(){return e.update.call(this,t)})}list(t={}){const e=Object.create(null,{list:{get:()=>super.list}});return ft(this,void 0,void 0,function*(){return e.list.call(this,t)})}delete(t){const e=Object.create(null,{delete:{get:()=>super.delete}});return ft(this,void 0,void 0,function*(){return e.delete.call(this,t)})}getDetailUrl(t){const e=encodeURIComponent(t.category),n=encodeURIComponent(t.key);return this.securityOptionsCategories.indexOf(t.category)>-1?`${this.securityOptionsListUrl}/${e}/${n}`:`${this.listUrl}/${e}/${n}`}onBeforeCreate(t){return t}}var gt=function(t,e,n,i){return new(n||(n=Promise))(function(r,s){function o(t){try{c(i.next(t))}catch(t){s(t)}}function a(t){try{c(i.throw(t))}catch(t){s(t)}}function c(t){var e;t.done?r(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(o,a)}c((i=i.apply(t,e||[])).next())})};class yt extends l{constructor(){super(...arguments),this.baseUrl="tenant",this.listUrl="security-options",this.category="password",this.propertyName="options"}detail(t){const e=Object.create(null,{detail:{get:()=>super.detail}});return gt(this,void 0,void 0,function*(){return e.detail.call(this,t)})}getDetailUrl(t){return`${this.listUrl}/${this.category}/${t.key}`}onBeforeCreate(t){return t}}var mt,bt,Tt,Ot=function(t,e,n,i){return new(n||(n=Promise))(function(r,s){function o(t){try{c(i.next(t))}catch(t){s(t)}}function a(t){try{c(i.throw(t))}catch(t){s(t)}}function c(t){var e;t.done?r(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(o,a)}c((i=i.apply(t,e||[])).next())})};class wt extends l{constructor(){super(...arguments),this.baseUrl="tenant",this.listUrl="loginOptions",this.propertyName="loginOptions"}detail(t){const e=Object.create(null,{detail:{get:()=>super.detail}});return Ot(this,void 0,void 0,function*(){return e.detail.call(this,t)})}list(t={}){const e=Object.create(null,{list:{get:()=>super.list}});return Ot(this,void 0,void 0,function*(){return e.list.call(this,t)})}listForCurrentTenant(){const t=Object.create(null,{list:{get:()=>super.list}});return Ot(this,void 0,void 0,function*(){return t.list.call(this,{tenantId:this.client.tenant})})}listForManagement(){const t=Object.create(null,{list:{get:()=>super.list}});return Ot(this,void 0,void 0,function*(){return t.list.call(this,{management:!0})})}create(t){const e=Object.create(null,{create:{get:()=>super.create}});return Ot(this,void 0,void 0,function*(){return e.create.call(this,t)})}update(t){const e=Object.create(null,{update:{get:()=>super.update}});return Ot(this,void 0,void 0,function*(){return e.update.call(this,t)})}save(t){return Ot(this,void 0,void 0,function*(){return t.id?this.update(t):this.create(t)})}delete(t){const e=Object.create(null,{delete:{get:()=>super.delete}});return Ot(this,void 0,void 0,function*(){return e.delete.call(this,t)})}}(mt=t.TenantLoginOptionType||(t.TenantLoginOptionType={})).OAUTH2_INTERNAL="OAUTH2_INTERNAL",mt.OAUTH2="OAUTH2",mt.BASIC="BASIC",(bt=t.GrantType||(t.GrantType={})).AUTHORIZATION_CODE="AUTHORIZATION_CODE",bt.PASSWORD="PASSWORD",(Tt=t.UserManagementSource||(t.UserManagementSource={})).REMOTE="REMOTE",Tt.INTERNAL="INTERNAL";var Et,St,Ut=function(t,e,n,i){return new(n||(n=Promise))(function(r,s){function o(t){try{c(i.next(t))}catch(t){s(t)}}function a(t){try{c(i.throw(t))}catch(t){s(t)}}function c(t){var e;t.done?r(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(o,a)}c((i=i.apply(t,e||[])).next())})};class Ct extends l{constructor(){super(...arguments),this.baseUrl="audit",this.listUrl="auditRecords",this.propertyName="auditRecords"}detail(t){const e=Object.create(null,{detail:{get:()=>super.detail}});return Ut(this,void 0,void 0,function*(){return e.detail.call(this,t)})}create(t){const e=Object.create(null,{create:{get:()=>super.create}});return Ut(this,void 0,void 0,function*(){return e.create.call(this,t)})}list(t={}){const e=Object.create(null,{list:{get:()=>super.list}});return Ut(this,void 0,void 0,function*(){return e.list.call(this,t)})}}(Et=t.AuditRecordType||(t.AuditRecordType={})).ALARM="Alarm",Et.BULK_OPERATION="BulkOperation",Et.CEP_MODULE="CepModule",Et.EVENT="Event",Et.INVENTORY="Inventory",Et.INVENTORY_ROLE="InventoryRole",Et.OPERATION="Operation",Et.OPTION="Option",Et.GROUP="Group",Et.SMART_RULE="SmartRule",Et.SYSTEM="SYSTEM",Et.TENANT="Tenant",Et.USER="User",(St=t.ChangeType||(t.ChangeType={}))[St.ADDED=S("ADDED")]="ADDED",St[St.REPLACED=S("REPLACED")]="REPLACED",St[St.REMOVED=S("REMOVED")]="REMOVED";var jt,Rt=function(t,e,n,i){return new(n||(n=Promise))(function(r,s){function o(t){try{c(i.next(t))}catch(t){s(t)}}function a(t){try{c(i.throw(t))}catch(t){s(t)}}function c(t){var e;t.done?r(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(o,a)}c((i=i.apply(t,e||[])).next())})};class _t extends l{constructor(){super(...arguments),this.baseUrl="user",this.listUrl="inventoryroles",this.propertyName="roles"}detail(t){const e=Object.create(null,{detail:{get:()=>super.detail}});return Rt(this,void 0,void 0,function*(){return e.detail.call(this,t)})}create(t){const e=Object.create(null,{create:{get:()=>super.create}});return Rt(this,void 0,void 0,function*(){return e.create.call(this,t)})}update(t){const e=Object.create(null,{update:{get:()=>super.update}});return Rt(this,void 0,void 0,function*(){return e.update.call(this,t)})}list(t={}){const e=Object.create(null,{list:{get:()=>super.list}});return Rt(this,void 0,void 0,function*(){return e.list.call(this,t)})}delete(t){const e=Object.create(null,{delete:{get:()=>super.delete}});return Rt(this,void 0,void 0,function*(){return e.delete.call(this,t)})}}(jt=t.DeviceRegistrationStatus||(t.DeviceRegistrationStatus={}))[jt.WAITING_FOR_CONNECTION=S("WAITING_FOR_CONNECTION")]="WAITING_FOR_CONNECTION",jt[jt.PENDING_ACCEPTANCE=S("PENDING_ACCEPTANCE")]="PENDING_ACCEPTANCE",jt[jt.ACCEPTED=S("ACCEPTED")]="ACCEPTED",jt[jt.BLOCKED=S("BLOCKED")]="BLOCKED";var xt=function(t,e,n,i){return new(n||(n=Promise))(function(r,s){function o(t){try{c(i.next(t))}catch(t){s(t)}}function a(t){try{c(i.throw(t))}catch(t){s(t)}}function c(t){var e;t.done?r(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(o,a)}c((i=i.apply(t,e||[])).next())})};class At extends l{constructor(){super(...arguments),this.baseUrl="devicecontrol",this.listUrl="newDeviceRequests",this.propertyName="newDeviceRequests"}detail(t){const e=Object.create(null,{detail:{get:()=>super.detail}});return xt(this,void 0,void 0,function*(){return e.detail.call(this,t)})}create(t){const e=Object.create(null,{create:{get:()=>super.create}});return xt(this,void 0,void 0,function*(){return e.create.call(this,t)})}list(t={}){const e=Object.create(null,{list:{get:()=>super.list}});return xt(this,void 0,void 0,function*(){return e.list.call(this,t)})}delete(t){const e=Object.create(null,{delete:{get:()=>super.delete}});return xt(this,void 0,void 0,function*(){return e.delete.call(this,t)})}accept(e){const n=Object.create(null,{update:{get:()=>super.update}});return xt(this,void 0,void 0,function*(){const i=this.getSecurityToken(e);let r={id:this.getIdString(e),status:t.DeviceRegistrationStatus.ACCEPTED};return i&&(r=Object.assign(Object.assign({},r),{securityToken:i})),n.update.call(this,r)})}acceptAll(){const t=Object.create(null,{fetch:{get:()=>super.fetch}});return xt(this,void 0,void 0,function*(){const e=yield t.fetch.call(this,`${this.listUrl}/acceptAll`,{method:"POST"});return{res:e,data:yield e.json()}})}limit(){const t=Object.create(null,{fetch:{get:()=>super.fetch}});return xt(this,void 0,void 0,function*(){const e=yield t.fetch.call(this,`${this.listUrl}/limit`);return{res:e,data:yield e.json()}})}bootstrap(t,e){return xt(this,void 0,void 0,function*(){const n=this.getIdString(t),i=this.getSecurityToken(t),r=i?JSON.stringify({id:n,securityToken:i}):JSON.stringify({id:n}),s=`${this.baseUrl}/deviceCredentials`,{basicAuth:o}=e;let{basicAuthToken:a}=e;if(o){const{user:t,pass:e}=o;a=T(`${t}:${e}`)}const c={Authorization:`Basic ${a}`,accept:"application/json","content-type":"application/json"},u=yield this.client.fetch(s,{body:r,headers:c,method:"POST"}),l=yield u.json();if(u.status>400)throw{res:u,data:l};return{res:u,data:l}})}onBeforeCreate(t){return t}onBeforeUpdate(t){const e=Object.assign({},t);return delete e.id,e}getDetailUrl(t){const e=encodeURIComponent(this.getEntityId(t));return`${this.listUrl}/${e}`}getSecurityToken(t){let e;return"object"==typeof t&&(e=t.securityToken?String(t.securityToken):void 0),e}}var It,Pt=function(t,e,n,i){return new(n||(n=Promise))(function(r,s){function o(t){try{c(i.next(t))}catch(t){s(t)}}function a(t){try{c(i.throw(t))}catch(t){s(t)}}function c(t){var e;t.done?r(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(o,a)}c((i=i.apply(t,e||[])).next())})};class kt{constructor(t){this.client=t}create(t){return Pt(this,void 0,void 0,function*(){let e=t;const n=new _;let i,r="bulk-registration.csv";if("undefined"!=typeof File&&e instanceof File){r=e.name;const t=/\.csv$/;e.name.match(t)&&(e=new File([e],e.name,{type:"text/csv"}))}n.append("file",e,r),"function"==typeof n.getHeaders&&(i=n.getHeaders());const s=Object.assign({accept:"application/json"},i),o=yield this.client.fetch("/devicecontrol/bulkNewDeviceRequests",{method:"POST",body:n,headers:s});return{res:o,data:yield o.json()}})}}(It=t.DeviceRegistrationSecurityMode||(t.DeviceRegistrationSecurityMode={})).REQUIRED="REQUIRED",It.OPTIONAL="OPTIONAL",It.IGNORED="IGNORED";var Nt=function(t,e,n,i){return new(n||(n=Promise))(function(r,s){function o(t){try{c(i.next(t))}catch(t){s(t)}}function a(t){try{c(i.throw(t))}catch(t){s(t)}}function c(t){var e;t.done?r(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(o,a)}c((i=i.apply(t,e||[])).next())})};class Dt extends l{constructor(){super(...arguments),this.baseUrl="user",this.listUrl="roles",this.propertyName="roles"}detail(t){const e=Object.create(null,{detail:{get:()=>super.detail}});return Nt(this,void 0,void 0,function*(){return e.detail.call(this,t)})}list(t={}){const e=Object.create(null,{list:{get:()=>super.list}});return Nt(this,void 0,void 0,function*(){return e.list.call(this,t)})}}var $t,Lt=function(t,e,n,i){return new(n||(n=Promise))(function(r,s){function o(t){try{c(i.next(t))}catch(t){s(t)}}function a(t){try{c(i.throw(t))}catch(t){s(t)}}function c(t){var e;t.done?r(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(o,a)}c((i=i.apply(t,e||[])).next())})};!function(t){t.ROLES="roles",t.USERS="users"}($t||($t={}));class Ft extends l{constructor(){super(...arguments),this.baseUrl="user",this.propertyName="groups"}get listUrl(){return`${this.client.tenant}/groups`}detail(t){const e=Object.create(null,{detail:{get:()=>super.detail}});return Lt(this,void 0,void 0,function*(){return e.detail.call(this,t)})}create(t){const e=Object.create(null,{create:{get:()=>super.create}});return Lt(this,void 0,void 0,function*(){return e.create.call(this,t)})}update(t){const e=Object.create(null,{update:{get:()=>super.update}});return Lt(this,void 0,void 0,function*(){return e.update.call(this,t)})}list(t={}){const e=Object.create(null,{list:{get:()=>super.list}});return Lt(this,void 0,void 0,function*(){return e.list.call(this,t)})}delete(t){const e=Object.create(null,{delete:{get:()=>super.delete}});return Lt(this,void 0,void 0,function*(){return e.delete.call(this,t)})}addRoleToGroup(t,e){return Lt(this,void 0,void 0,function*(){return this.addChild($t.ROLES,t,e)})}removeRoleFromGroup(t,e){return Lt(this,void 0,void 0,function*(){return this.removeChild($t.ROLES,t,e)})}addUserToGroup(t,e){return Lt(this,void 0,void 0,function*(){return this.addChild($t.USERS,t,e)})}removeUserFromGroup(t,e){return Lt(this,void 0,void 0,function*(){return this.removeChild($t.USERS,t,e)})}getSelf(t){return"object"==typeof t&&t.self?t.self:t}getChildUrl(t,e){return`${this.getDetailUrl(e)}/${t}`}getChildReferenceAsBody(t,e){const n=this.getSelf(e);switch(t){case $t.ROLES:return JSON.stringify({role:{self:String(n)}});case $t.USERS:return JSON.stringify({user:{self:String(n)}})}throw new Error("UserGroupService -> getChild -> unsupported child type")}addChild(t,e,n){return Lt(this,void 0,void 0,function*(){const i=this.getChildUrl(t,e),r=this.getChildReferenceAsBody(t,n),s=yield this.fetch(i,{method:"POST",body:r,headers:{accept:"application/json","content-type":"application/json"}});let o=yield s.json();return{res:s,data:o=o.managedObject}})}removeChild(t,e,n){return Lt(this,void 0,void 0,function*(){const i=this.getIdString(n),r=`${this.getChildUrl(t,e)}/${encodeURIComponent(String(i))}`;return{res:yield this.fetch(r,{method:"DELETE",headers:{accept:"application/json"}}),data:null}})}}var Bt=function(t,e,n,i){return new(n||(n=Promise))(function(r,s){function o(t){try{c(i.next(t))}catch(t){s(t)}}function a(t){try{c(i.throw(t))}catch(t){s(t)}}function c(t){var e;t.done?r(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(o,a)}c((i=i.apply(t,e||[])).next())})};class Mt{constructor(t){this.baseUrl="identity",this.propertyName="externalIds",this.client=t}list(t){return Bt(this,void 0,void 0,function*(){const e=this.getExternalIdsOfGlobalIdUrl(t),n=yield this.fetch(e,{headers:{accept:"application/json"}});return{res:n,data:(yield n.json())[this.propertyName]}})}create(t){return Bt(this,void 0,void 0,function*(){const e=JSON.stringify(t),n=this.getExternalIdsOfGlobalIdUrl(t.managedObject.id),i=yield this.fetch(n,{headers:{"content-type":"application/json",accept:"application/json"},method:"POST",body:e});return{res:i,data:yield i.json()}})}detail(t){return Bt(this,void 0,void 0,function*(){const e=this.getExternalIdUrl(t),n=yield this.fetch(e,{headers:{accept:"application/json"}});return{res:n,data:yield n.json()}})}delete(t){return Bt(this,void 0,void 0,function*(){const e=this.getExternalIdUrl(t);return{res:yield this.fetch(e,{headers:{accept:"application/json"},method:"DELETE"}),data:null}})}fetch(t,e){return Bt(this,void 0,void 0,function*(){const n=yield this.client.fetch(t,e);if(n.status>=400){let t=null;try{t=yield n.json()}catch(e){try{t=yield n.text()}catch(t){}}throw{res:n,data:t}}return n})}getExternalIdsOfGlobalIdUrl(t){return`/${this.baseUrl}/globalIds/${t}/externalIds`}getExternalIdUrl(t){return`/${this.baseUrl}/externalIds/${t.type}/${t.externalId}`}}var Gt=function(t,e,n,i){return new(n||(n=Promise))(function(r,s){function o(t){try{c(i.next(t))}catch(t){s(t)}}function a(t){try{c(i.throw(t))}catch(t){s(t)}}function c(t){var e;t.done?r(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(o,a)}c((i=i.apply(t,e||[])).next())})};var Ht=function(t,e,n,i){return new(n||(n=Promise))(function(r,s){function o(t){try{c(i.next(t))}catch(t){s(t)}}function a(t){try{c(i.throw(t))}catch(t){s(t)}}function c(t){var e;t.done?r(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(o,a)}c((i=i.apply(t,e||[])).next())})},Vt=function(t,e){var n={};for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&e.indexOf(i)<0&&(n[i]=t[i]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(i=Object.getOwnPropertySymbols(t);r<i.length;r++)e.indexOf(i[r])<0&&Object.prototype.propertyIsEnumerable.call(t,i[r])&&(n[i[r]]=t[i[r]])}return n};class qt extends l{constructor(t){super(t),this.baseUrl="inventory",this.listUrl="managedObjects",this.SMART_GROUP_TYPE="c8y_DynamicGroup",this.SMART_GROUP_FRAGMENT_TYPE="c8y_IsDynamicGroup",this.DEVICE_GROUP_FRAGMENT_TYPE="c8y_IsDeviceGroup",this.DEVICE_GROUP_TYPE="c8y_DeviceGroup",this.DEVICE_SUBGROUP_TYPE="c8y_DeviceSubgroup",this.COLUMNS_CONFIG_FRAGMENT="c8y_DeviceColumnsConfig",this.FILTER_CONFIG_FRAGMENT="c8y_DeviceFilterConfig",this.QUERY_STRING_FRAGMENT="c8y_DeviceQueryString",this.SMART_GROUPS_V2_MICROSERVICE_APP_NAME="smartgroup",this.SMART_GROUPS_V2_MICROSERVICE_BASE_PATH="service/smartgroup",this.SMART_GROUPS_V2_MICROSERVICE_ENDPOINT_PATH=`${this.SMART_GROUPS_V2_MICROSERVICE_BASE_PATH}/smartgroups`,this.applicationService=new dt(t)}detail(t,e={}){const n=Object.create(null,{detail:{get:()=>super.detail}});return Ht(this,void 0,void 0,function*(){return n.detail.call(this,t,e)})}create(t){const e=Object.create(null,{create:{get:()=>super.create}});return Ht(this,void 0,void 0,function*(){const{data:n}=yield this.isSmartGroupsV2MicroserviceInstalled(),i=Object.assign(Object.assign(Object.assign({},t.smartGroup),{[this.QUERY_STRING_FRAGMENT]:t.deviceQueryString,[this.COLUMNS_CONFIG_FRAGMENT]:t.configurableColumns}),t.filterConfig&&{[this.FILTER_CONFIG_FRAGMENT]:t.filterConfig});return n?this.createSmartGroupV2(i):e.create.call(this,i)})}update(t,e={}){const n=Object.create(null,{update:{get:()=>super.update}});return Ht(this,void 0,void 0,function*(){const{id:i}=t,{data:r}=yield this.isSmartGroupsV2MicroserviceInstalled(),{data:s}=yield this.detail(i,{withChildren:!1});return r&&this.isSmartGroupV2(s)?this.updateSmartGroupV2(t,e):n.update.call(this,t)})}updateSmartGroupV2(t,e={}){return Ht(this,void 0,void 0,function*(){const{id:n}=t,i=Vt(t,["id"]),r=JSON.stringify(this.onBeforeUpdate(i)),s=`${this.SMART_GROUPS_V2_MICROSERVICE_ENDPOINT_PATH}/${n}`,o=yield this.fetch(s,{method:"PUT",body:r,headers:{"content-type":"application/json",accept:"application/json"},params:Object.assign({},e)});return{res:o,data:yield o.json()}})}delete(t,e={}){const n=Object.create(null,{delete:{get:()=>super.delete}});return Ht(this,void 0,void 0,function*(){const{data:i}=yield this.isSmartGroupsV2MicroserviceInstalled(),r=(yield this.detail(t,{withChildren:!1})).data;return i&&this.isSmartGroupV2(r)?yield this.removeSmartGroupV2(r):yield n.delete.call(this,r,e)})}isSmartGroupsV2MicroserviceInstalled(){return this.applicationService.isAvailable({name:this.SMART_GROUPS_V2_MICROSERVICE_APP_NAME})}isSmartGroup(t){const e=t.hasOwnProperty(this.SMART_GROUP_FRAGMENT_TYPE),n=t&&t.type===this.SMART_GROUP_TYPE;return e||n}isSmartGroupV2(t){const e=t.hasOwnProperty(this.SMART_GROUP_FRAGMENT_TYPE),n=t.hasOwnProperty(this.DEVICE_GROUP_FRAGMENT_TYPE),i=t&&t.type===this.DEVICE_GROUP_TYPE||t.type===this.DEVICE_SUBGROUP_TYPE;return e&&n&&i}removeSmartGroupV2(t){return Ht(this,void 0,void 0,function*(){let e;e="object"==typeof t&&t.id?t.id:t;const n=`${this.SMART_GROUPS_V2_MICROSERVICE_ENDPOINT_PATH}/${e}`;return{res:yield this.client.fetch(n,{method:"DELETE"}),data:null}})}getUrl(t=""){const e=t.replace(/^\/+/,""),n=this.baseUrl.replace(/\/+$/,"");return t.includes(this.SMART_GROUPS_V2_MICROSERVICE_ENDPOINT_PATH)?e:`${n}/${e}`}createSmartGroupV2(t){return Ht(this,void 0,void 0,function*(){const e=JSON.stringify(t),n=this.SMART_GROUPS_V2_MICROSERVICE_ENDPOINT_PATH,i=yield this.fetch(n,{method:"POST",body:e,headers:{"content-type":"application/json",accept:"application/json"}});return{res:i,data:yield i.json()}})}}var Jt=function(t,e,n,i){return new(n||(n=Promise))(function(r,s){function o(t){try{c(i.next(t))}catch(t){s(t)}}function a(t){try{c(i.throw(t))}catch(t){s(t)}}function c(t){var e;t.done?r(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(o,a)}c((i=i.apply(t,e||[])).next())})};class Xt extends l{constructor(t){super(t),this.baseUrl="service/smartrule",this.rulesUrl="smartrules",this.unupdatableFields=["type","cepModuleId","creationTime","lastUpdated"],this.applicationService=new dt(t)}isMicroserviceAvailable(){return Jt(this,void 0,void 0,function*(){return void 0===this.microserviceAvailable&&(this.microserviceAvailable=(yield this.applicationService.isAvailable(Xt.microserviceName)).data),this.microserviceAvailable})}listByContext(t){return Jt(this,void 0,void 0,function*(){const e=this.contextRulesUrl(t),n=yield this.fetch(e,{method:"GET"});return{res:n,data:(yield n.json()).rules}})}bulkDeactivateEnabledSources(t,e){if(0===e.length)return Promise.resolve({res:null,data:null});const{enabledSources:n}=t,i=this.disableEnabledSources(n,e),r=Object.assign({},t);return Object.assign(r,{enabledSources:i}),this.update(r)}update(t){return Jt(this,void 0,void 0,function*(){const e=this.getSmartRulesUrl(t),n=JSON.stringify(this.removeUnclonableFields(t,this.unupdatableFields)),i=yield this.fetch(e,{method:"PUT",body:n,headers:{"content-type":"application/json",accept:"application/json"}});return{res:i,data:yield i.json()}})}disableEnabledSources(t=[],e){return t.filter(t=>!this.getListOfStringIds(e).includes(t))}getListOfStringIds(t){return t.map(t=>"object"==typeof t&&t.id?t.id.toString():t.toString())}getSmartRulesUrl(t){const e=t&&t.c8y_Context&&t.c8y_Context.id;let n=e?this.contextRulesUrl(e):this.rulesUrl;return t.id&&(n=`${n}/${t.id}`),n}removeUnclonableFields(t,e){const n=Object.assign({},t);return e.forEach(t=>{delete n[t]}),n}contextRulesUrl(t={}){return"object"==typeof t&&t.id?`managedObjects/${t.id}/smartrules`:`managedObjects/${t}/smartrules`}}Xt.microserviceName="smartrule";var Wt=function(t,e,n,i){return new(n||(n=Promise))(function(r,s){function o(t){try{c(i.next(t))}catch(t){s(t)}}function a(t){try{c(i.throw(t))}catch(t){s(t)}}function c(t){var e;t.done?r(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(o,a)}c((i=i.apply(t,e||[])).next())})};class Qt{constructor(t,e){const n=new g(t,e);this.realtime=new o(n),this.alarm=new B(n,this.realtime),this.application=new dt(n,this.realtime),this.audit=new Ct(n),this.core=n,this.deviceRegistration=new At(n),this.deviceRegistrationBulk=new kt(n),this.event=new R(n,this.realtime),this.inventory=new k(n,this.realtime),this.inventoryBinary=new I(n),this.inventoryRole=new _t(n),this.measurement=new $(n,this.realtime),this.operation=new G(n),this.operationBulk=new X(n),this.options={security:new yt(n),system:new pt(n),login:new wt(n),tenant:new vt(n)},this.role=new _t(n),this.tenant=new K(n),this.user=new nt(n),this.userGroup=new Ft(n),this.userRole=new Dt(n),this.identity=new Mt(n),this.smartGroups=new qt(n),this.smartRules=new Xt(n)}static authenticate(t,e){return Wt(this,void 0,void 0,function*(){const n=new w(t),i=yield new g(n,e).fetch("/tenant/currentTenant",{method:"GET"});if(200!==i.status)throw{res:i};const{name:r}=yield i.json(),s=new Qt(n,e);return s.core.tenant=r,s})}static deviceBootstrap(t){return Wt(this,void 0,void 0,function*(){const{deviceId:e,timeout:n,baseUrl:i,basicAuthToken:r}=t;let{expire:s}=t;n&&!s&&(s=Date.now()+n);const o=new g(void 0,i),a=new At(o);let c;try{const{data:n}=yield a.bootstrap(e,{basicAuthToken:r}),{username:o,password:u,tenantId:l}=n,d=new w({user:o,tenant:l,password:u});(c=new Qt(d,i)).core.tenant=l}catch(e){if((!s||Date.now()<s)&&404===e.res.status)return Qt.deviceBootstrap(Object.assign({expire:s},t));throw e}return c})}static getMicroserviceSubscriptions(t,e){return Wt(this,void 0,void 0,function*(){const n=yield new g(new w(t),e).fetch("/application/currentApplication/subscriptions"),{users:i}=yield n.json();return i.map(({tenant:t,name:e,password:n})=>({tenant:t,user:e,password:n}))})}setAuth(t){this.core.setAuth(t),this.realtime.disconnect()}}t.Client=Qt,t.AlarmService=B,t.ApplicationService=dt,t.AuditService=Ct,t.Service=l,t.FetchClient=g,t.BasicAuth=w,t.CookieAuth=class{constructor(){this.logoutUrl="user/logout"}updateCredentials({user:t}={}){this.user=t}getFetchOptions(t){const e={"X-XSRF-TOKEN":this.getCookieValue("XSRF-TOKEN")};return t.headers=Object.assign(e,t.headers),t}getCometdHandshake(t={}){const e="com.cumulocity.authn",n=this.getCookieValue("XSRF-TOKEN"),i=t.ext=t.ext||{};return i[e]=Object.assign(i[e]||{},{xsrfToken:n}),t}logout(){return E(this,void 0,void 0,function*(){this.user&&delete this.user;const t=new g;t.setAuth(this);const e=JSON.stringify({});return t.fetch(this.logoutUrl,{headers:{"content-type":"application/json",accept:"application/json"},body:e,method:"POST"})})}getCookieValue(t){const e=document.cookie.match("(^|;)\\s*"+t+"\\s*=\\s*([^;]+)");return e?e.pop():""}},t.MicroserviceClientRequestAuth=class{constructor(t={}){this.xsrfToken=this.getCookieValue(t,"XSRF-TOKEN"),this.authTokenFromCookie=this.getCookieValue(t,"authorization"),this.authTokenFromHeader=t.authorization}updateCredentials(){}getFetchOptions(t){const e=Object.assign({Authorization:this.authTokenFromCookie?`Bearer ${this.authTokenFromCookie}`:this.authTokenFromHeader},this.xsrfToken?{"X-XSRF-TOKEN":this.xsrfToken}:void 0);return t.headers=Object.assign(e,t.headers),t}getCometdHandshake(t={}){const e="com.cumulocity.authn",n=this.xsrfToken;let i=this.authTokenFromCookie;!i&&this.authTokenFromHeader&&(i=this.authTokenFromHeader.replace("Basic ","").replace("Bearer ",""));const r=t.ext=t.ext||{};return r[e]=Object.assign(r[e]||{},Object.assign({token:i},n?{xsrfToken:n}:void 0)),t}logout(){this.authTokenFromCookie&&delete this.authTokenFromCookie,this.authTokenFromHeader&&delete this.authTokenFromHeader,this.xsrfToken&&delete this.xsrfToken}getCookieValue(t,e){try{const n=t&&t.cookie&&t.cookie.match("(^|;)\\s*"+e+"\\s*=\\s*([^;]+)");return n?n.pop():void 0}catch(t){return}}},t.Paging=c,t.QueriesUtil=C,t.TrustedCertificateService=class extends l{constructor(){super(...arguments),this.listUrl="trusted-certificates",this.proofOfPossessionUrl="trusted-certificates-pop",this.propertyName="certificates"}get baseUrl(){return`/tenant/tenants/${this.client.tenant}`}list(t={}){const e=Object.create(null,{list:{get:()=>super.list}});return Gt(this,void 0,void 0,function*(){return e.list.call(this,t)})}detail(t){const e=Object.create(null,{detail:{get:()=>super.detail}});return Gt(this,void 0,void 0,function*(){return e.detail.call(this,t)})}delete(t){const e=Object.create(null,{delete:{get:()=>super.delete}});return Gt(this,void 0,void 0,function*(){return e.delete.call(this,t)})}update(t){const e=Object.create(null,{update:{get:()=>super.update}});return Gt(this,void 0,void 0,function*(){return e.update.call(this,t)})}create(t){const e=Object.create(null,{create:{get:()=>super.create}});return Gt(this,void 0,void 0,function*(){return e.create.call(this,t)})}regeneratePoPVerificationCode(t){return Gt(this,void 0,void 0,function*(){const e=`${this.proofOfPossessionUrl}/${this.getEntityId(t)}/verification-code`,n=yield this.fetch(e,{headers:{"content-type":"application/json",Accept:"application/json"},method:"POST"});return{res:n,data:yield n.json()}})}verifySignedVerificationCode(t,e){return Gt(this,void 0,void 0,function*(){const n=`${this.proofOfPossessionUrl}/${this.getEntityId(t)}/pop`,i=JSON.stringify({proofOfPossessionSignedVerificationCode:e}),r=yield this.fetch(n,{method:"POST",body:i,headers:{"content-type":"application/json",Accept:"application/json"}});return{res:r,data:yield r.json()}})}getDetailUrl(t){const e=this.getEntityId(t);return`${this.listUrl}/${e}`}getEntityId(t){let e;return e="object"==typeof t&&t.fingerprint?t.fingerprint:t}},t.DeviceRegistrationService=At,t.DeviceRegistrationBulkService=kt,t.EventService=R,t.EventBinaryService=class extends l{constructor(){super(...arguments),this.baseUrl="event",this.listUrl="events"}upload(t,e){return x(this,void 0,void 0,function*(){const n=this.getDetailUrl(e),i=new _;i.append("file",t);const r=yield this.fetch(n,{method:"POST",body:i,headers:{accept:"application/json"}});return{res:r,data:yield r.json()}})}download(t){return x(this,void 0,void 0,function*(){const e=this.getDetailUrl(t);return yield this.fetch(e)})}delete(t){const e=Object.create(null,{delete:{get:()=>super.delete}});return x(this,void 0,void 0,function*(){return e.delete.call(this,t)})}getDetailUrl(t){let e;return e="object"==typeof t&&t.id?t.id:t,`${this.listUrl}/${e}/binaries`}},t.IdentityService=Mt,t.InventoryService=k,t.InventoryBinaryService=I,t.InventoryRoleService=_t,t.MeasurementService=$,t.OperationService=G,t.OperationBulkService=X,t.Realtime=o,t.SystemOptionsService=pt,t.TenantService=K,t.TenantOptionsService=vt,t.TenantSecurityOptionsService=yt,t.TenantLoginOptionsService=wt,t.UserService=nt,t.UserInventoryRoleService=Z,t.UserGroupService=Ft,t.UserRoleService=Dt,t.SmartRulesService=Xt,t.SmartGroupsService=qt,Object.defineProperty(t,"__esModule",{value:!0})});
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).cumulocity={})}(this,function(r){"use strict";var D="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function L(e,t){return e(t={exports:{}},t.exports),t.exports}var i,e=L(function(e,t){var be,Te,Oe,m,n,Se,we,Ee,h,p;e.exports=(be=function(){var n=0,i={};this.register=function(e){var t=++n;return i[t]=e,t},this.unregister=function(e){var t=i[e];return delete i[e],t},this.setTimeout=function(e,t){return window.setTimeout(e,t)},this.clearTimeout=function(e){window.clearTimeout(e)}},Te={isString:function(e){return null!=e&&("string"==typeof e||e instanceof String)},isArray:function(e){return null!=e&&e instanceof Array},inArray:function(e,t){for(var n=0;n<t.length;++n)if(e===t[n])return n;return-1}},Oe=function(){var c=[],u={};this.getTransportTypes=function(){return c.slice(0)},this.findTransportTypes=function(e,t,n){for(var i=[],r=0;r<c.length;++r){var s=c[r];!0===u[s].accept(e,t,n)&&i.push(s)}return i},this.negotiateTransport=function(e,t,n,i){for(var r=0;r<c.length;++r)for(var s=c[r],o=0;o<e.length;++o)if(s===e[o]){var a=u[s];if(!0===a.accept(t,n,i))return a}return null},this.add=function(e,t,n){for(var i=!1,r=0;r<c.length;++r)if(c[r]===e){i=!0;break}return i||("number"!=typeof n?c.push(e):c.splice(n,0,e),u[e]=t),!i},this.find=function(e){for(var t=0;t<c.length;++t)if(c[t]===e)return u[e];return null},this.remove=function(e){for(var t,n=0;n<c.length;++n)if(c[n]===e)return c.splice(n,1),t=u[e],delete u[e],t;return null},this.clear=function(){c=[],u={}},this.reset=function(e){for(var t=0;t<c.length;++t)u[c[t]].reset(e)}},(m=function(){var n,i,t;this.registered=function(e,t){n=e,i=t},this.unregistered=function(){i=n=null},this._debug=function(){i._debug.apply(i,arguments)},this._mixin=function(){return i._mixin.apply(i,arguments)},this.getConfiguration=function(){return i.getConfiguration()},this.getAdvice=function(){return i.getAdvice()},this.setTimeout=function(e,t){return i.setTimeout(e,t)},this.clearTimeout=function(e){i.clearTimeout(e)},this.convertToMessages=function(t){if(Te.isString(t))try{return JSON.parse(t)}catch(e){throw this._debug("Could not convert to JSON the following string",'"'+t+'"'),e}if(Te.isArray(t))return t;if(null==t)return[];if(t instanceof Object)return[t];throw"Conversion Error "+t+", typeof "+typeof t},this.accept=function(e,t,n){throw"Abstract"},this.getType=function(){return n},this.getURL=function(){return t},this.setURL=function(e){t=e},this.send=function(e,t){throw"Abstract"},this.reset=function(e){this._debug("Transport",n,"reset",e?"initial":"retry")},this.abort=function(){this._debug("Transport",n,"aborted")},this.toString=function(){return this.getType()}}).derive=function(e){function t(){}return t.prototype=e,new t},h=["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z",".","-",":","+","=","^","!","/","*","?","&","<",">","(",")","[","]","{","}","@","%","$","#"],p=[0,68,0,84,83,82,72,0,75,76,70,65,0,63,62,69,0,1,2,3,4,5,6,7,8,9,64,0,73,66,74,71,81,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,77,0,78,67,0,0,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,79,0,80,0,0],{CometD:function(e){var c,s,L,F,a,r=new be,u=this,B=e||"default",o=!1,l=new Oe,n="disconnected",M=0,d=null,h=0,t=[],p=!1,G=0,f={},v=0,i=null,g=[],y={},m={},H={},V=!1,b=!1,T=0,O=0,S=null,w={useWorkerScheduler:!0,protocol:null,stickyReconnect:!0,connectTimeout:0,maxConnections:2,backoffIncrement:1e3,maxBackoff:6e4,logLevel:"info",maxNetworkDelay:1e4,requestHeaders:{},appendMessageTypeToURL:!0,autoBatch:!1,urls:{},maxURILength:2e3,advice:{timeout:6e4,interval:0,reconnect:void 0,maxInterval:0}};function q(e,t){try{return e[t]}catch(e){}}function E(e){return Te.isString(e)}function U(e){return null!=e&&"function"==typeof e}function C(e,t){for(var n="";0<--t&&!(e>=Math.pow(10,t));)n+="0";return n+=e}function $(e,t){var n;window.console&&U(e=window.console[e])&&(n=new Date,[].splice.call(t,0,0,C(n.getHours(),2)+":"+C(n.getMinutes(),2)+":"+C(n.getSeconds(),2)+"."+C(n.getMilliseconds(),3)),e.apply(window.console,t))}function J(e){return new RegExp("(^https?://)?(((\\[[^\\]]+])|([^:/?#]+))(:(\\d+))?)?([^?#]*)(.*)?").exec(e)}function X(e){u._debug("Configuring cometd object with",e),E(e)&&(e={url:e}),w=u._mixin(!1,w,e=e||{});e=u.getURL();if(!e)throw"Missing required configuration parameter 'url' specifying the Bayeux server URL";var n,e=J(e),t=e[2],i=e[8],e=e[9];o=u._isCrossDomain(t),w.appendMessageTypeToURL&&(void 0!==e&&0<e.length?(u._info("Appending message type to URI "+i+e+" is not supported, disabling 'appendMessageTypeToURL' configuration"),w.appendMessageTypeToURL=!1):(e=(t=i.split("/")).length-1,i.match(/\/$/)&&--e,0<=t[e].indexOf(".")&&(u._info("Appending message type to URI "+i+" is not supported, disabling 'appendMessageTypeToURL' configuration"),w.appendMessageTypeToURL=!1))),window.Worker&&window.Blob&&window.URL&&w.useWorkerScheduler&&(t=(t=function(){var i={};self.onmessage=function(e){var t=e.data,n=i[t.id];switch(t.type){case"setTimeout":i[t.id]=self.setTimeout(function(){delete i[t.id],self.postMessage({id:t.id})},t.delay);break;case"clearTimeout":delete i[t.id],n&&self.clearTimeout(n);break;default:throw"Unknown command "+t.type}}}.toString()).substring(t.indexOf("{")+1,t.lastIndexOf("}")),e=new window.Blob([t],{type:"application/json"}),i=window.URL.createObjectURL(e),n=new window.Worker(i),r.setTimeout=function(e,t){e=r.register(e);return n.postMessage({id:e,type:"setTimeout",delay:t}),e},r.clearTimeout=function(e){r.unregister(e),n.postMessage({id:e,type:"clearTimeout"})},n.onmessage=function(e){e=e.data.id,e=r.unregister(e);e&&e()})}function W(e){var t;e&&(t=f[e.channel])&&t[e.id]&&(delete t[e.id],u._debug("Removed",e.listener?"listener":"subscription",e))}function Q(e){e&&!e.listener&&W(e)}function Y(){for(var e in f)if(f.hasOwnProperty(e)){var t=f[e];if(t)for(var n in t)t.hasOwnProperty(n)&&Q(t[n])}}function R(e){n!==e&&(u._debug("Status",n,"->",e),n=e)}function j(){return"disconnecting"===n||"disconnected"===n}function _(){return""+ ++M}function K(e,t,n,i,r){try{return t.call(e,i)}catch(e){t=u.onExtensionException;if(U(t)){u._debug("Invoking extension exception handler",n,e);try{t.call(u,e,n,r,i)}catch(e){u._info("Exception during execution of extension exception handler",n,e)}}else u._info("Exception during execution of extension",n,e);return i}}function z(e,t){var n=f[e];if(n)for(var i in n)if(n.hasOwnProperty(i)){i=n[i];if(i)try{i.callback.call(i.scope,t)}catch(e){var r=u.onListenerException;if(U(r)){u._debug("Invoking listener exception handler",i,e);try{r.call(u,e,i,i.listener,t)}catch(e){u._info("Exception during execution of listener exception handler",i,e)}}else u._info("Exception during execution of listener",i,t,e)}}}function x(e,t){z(e,t);for(var n=e.split("/"),i=n.length-1,r=i;0<r;--r){var s=n.slice(0,r).join("/")+"/*";r===i&&z(s,t),z(s+="*",t)}}function Z(){null!==i&&u.clearTimeout(i),i=null}function ee(e,t){Z();t=y.interval+t;u._debug("Function scheduled in",t,"ms, interval =",y.interval,"backoff =",v,e),i=u.setTimeout(e,t)}function A(e,t,n){for(var i,r=0;r<e.length;++r){var s=e[r],o=s.id;d&&(s.clientId=d),null!=(s=function(e){for(var t=g.length-1;0<=t&&null!=e;--t){var n=g[t],i=n.extension.outgoing;U(i)&&(e=void 0===(i=K(n.extension,i,n.name,e,!0))?e:i)}return e}(s))?(s.id=o,e[r]=s):(delete m[o],e.splice(r--,1))}0!==e.length&&(t&&(S=e[0]),i=u.getURL(),w.appendMessageTypeToURL&&(i.match(/\/$/)||(i+="/"),n)&&(i+=n),u._debug("Send",n={url:i,sync:!1,messages:e,onSuccess:function(e){try{F.call(u,e)}catch(e){u._info("Exception during handling of messages",e)}},onFailure:function(e,t,n){try{var i=u.getTransport();n.connectionType=i?i.getType():"unknown",a.call(u,e,t,n)}catch(e){u._info("Exception during handling of failure",e)}}}),c.send(n,t))}function I(e){0<h||!0===p?t.push(e):A([e],!1)}function P(){v=0}function te(){var e=t;t=[],0<e.length&&A(e,!1)}function k(e){R("connecting"),ee(function(){var e;j()||(e={id:_(),channel:"/meta/connect",connectionType:c.getType()},b||(e.advice={timeout:0}),R("connecting"),u._debug("Connect sent",e),A([e],!0,"connect"),R("connected"))},e)}function ne(e){e&&(y=u._mixin(!1,{},w.advice,e),u._debug("New advice",y))}function N(e){Z(),e&&c&&c.abort(),o=!1,c=null,R("disconnected"),P(),b=V=!1,S=d=null,(T=h=0)<t.length&&(e=t,t=[],a.call(u,void 0,e,{reason:"Disconnected"}))}function ie(e,t,n){var i=u.onTransportException;if(U(i)){u._debug("Invoking transport exception handler",e,t,n);try{i.call(u,n,e,t)}catch(e){u._info("Exception during execution of transport exception handler",e)}}}function re(e,t){U(e)&&(t=e,e=void 0),d=null,Y(),j()&&l.reset(!0),ne({}),p=!(h=0),s=e,L=t;var e="1.0",n=u.getURL(),i=l.findTransportTypes(e,o,n),r={id:_(),version:e,minimumVersion:e,channel:"/meta/handshake",supportedConnectionTypes:i,advice:{timeout:y.timeout,interval:y.interval}},r=u._mixin(!1,{},s,r);if((u._putCallback(r.id,t),!c)&&!(c=l.negotiateTransport(i,e,o,n)))throw t="Could not find initial transport among: "+l.getTransportTypes(),u._warn(t),t;u._debug("Initial transport is",c.getType()),R("handshaking"),u._debug("Handshake sent",r),A([r],!1,"handshake")}function se(t,n){try{t.call(u,n)}catch(e){t=u.onCallbackException;if(U(t)){u._debug("Invoking callback exception handler",e);try{t.call(u,e,n)}catch(e){u._info("Exception during execution of callback exception handler",e)}}else u._info("Exception during execution of message callback",e)}}function D(e){var t=u._getCallback([e.id]);U(t)&&(delete m[e.id],se(t,e))}function oe(e){var t=H[e.id];if(delete H[e.id],t){u._debug("Handling remote call response for",e,"with context",t);var n=t.timeout,n=(n&&u.clearTimeout(n),t.callback);if(U(n))return se(n,e),1}}function ae(e){u._debug("Transport failure handling",e),e.transport&&(c=e.transport),e.url&&c.setURL(e.url);var t,n=e.action,i=e.delay||0;switch(n){case"handshake":t=i,R("handshaking"),p=!0,ee(function(){re(s,L)},t);break;case"retry":k(i);break;case"none":N(!0);break;default:throw"Unknown action "+n}}function ce(e,t){D(e),x("/meta/handshake",e),x("/meta/unsuccessful",e),j()&&(t.action="none"),u.onTransportFailure.call(u,e,t,ae)}function ue(e){return"disconnected"===n||S&&S.id===e.id&&(S=null,1)}function le(e,t){x("/meta/connect",e),x("/meta/unsuccessful",e),j()&&(t.action="none"),u.onTransportFailure.call(u,e,t,ae)}function de(e){N(!0),D(e),x("/meta/disconnect",e),x("/meta/unsuccessful",e)}function he(e){var t,n=f[e.subscription];if(n)for(var i in n)n.hasOwnProperty(i)&&(t=n[i])&&!t.listener&&(delete n[i],u._debug("Removed failed subscription",t));D(e),x("/meta/subscribe",e),x("/meta/unsuccessful",e)}function pe(e){D(e),x("/meta/unsubscribe",e),x("/meta/unsuccessful",e)}function fe(e){oe(e)||(D(e),x("/meta/publish",e),x("/meta/unsuccessful",e))}function ve(e){var t;if(T=0,null!=(e=function(e){for(var t=0;t<g.length&&null!=e;++t){var n=g[t],i=n.extension.incoming;U(i)&&(e=void 0===(i=K(n.extension,i,n.name,e,!1))?e:i)}return e}(e)))switch(ne(e.advice),e.channel){case"/meta/handshake":var n=e,i=u.getURL();if(n.successful){var r=u._isCrossDomain(J(i)[2]),r=l.negotiateTransport(n.supportedConnectionTypes,n.version,r,i);if(null===r)n.successful=!1,ce(n,{cause:"negotiation",action:"none",transport:null});else{c!==r&&(u._debug("Transport",c.getType(),"->",r.getType()),c=r),d=n.clientId,p=!1,te(),n.reestablish=V,V=!0,D(n),x("/meta/handshake",n),O=n["x-messages"]||0;var s=j()?"none":y.reconnect||"retry";switch(s){case"retry":P(),0===O?k(0):u._debug("Processing",O,"handshake-delivered messages");break;case"none":N(!0);break;default:throw"Unrecognized advice action "+s}}}else ce(n,{cause:"unsuccessful",action:y.reconnect||"handshake",transport:c});break;case"/meta/connect":i=e;if(ue(i))if(b=i.successful){x("/meta/connect",i);var o=j()?"none":y.reconnect||"retry";switch(o){case"retry":P(),k(v);break;case"none":N(!1);break;default:throw"Unrecognized advice action "+o}}else le(i,{cause:"unsuccessful",action:y.reconnect||"retry",transport:c});else u._debug("Mismatched /meta/connect reply",i);break;case"/meta/disconnect":(r=e).successful?(N(!1),D(r),x("/meta/disconnect",r)):de(r);break;case"/meta/subscribe":(n=e).successful?(D(n),x("/meta/subscribe",n)):he(n);break;case"/meta/unsubscribe":(t=e).successful?(D(t),x("/meta/unsubscribe",t)):pe(t);break;default:void 0!==(t=e).data?oe(t)||(x(t.channel,t),0<O&&0===--O&&(u._debug("Processed last handshake-delivered message"),k(0))):void 0===t.successful?u._warn("Unknown Bayeux Message",t):t.successful?(D(t),x("/meta/publish",t)):fe(t)}}function ge(e){var t=f[e];if(t)for(var n in t)if(t.hasOwnProperty(n)&&t[n])return 1}function ye(e,t){var n={scope:e,method:t};if(U(e))n.scope=void 0,n.method=e;else if(E(t)){if(!e)throw"Invalid scope "+e;if(n.method=e[t],!U(n.method))throw"Invalid callback "+t+" for scope "+e}else if(!U(t))throw"Invalid callback "+t;return n}function me(e,t,n,i){var t=ye(t,n),n=(u._debug("Adding",i?"listener":"subscription","on",e,"with scope",t.scope,"and callback",t.method),++G),t={id:n,channel:e,scope:t.scope,callback:t.method,listener:i},r=f[e];return r||(f[e]=r={}),r[n]=t,u._debug("Added",i?"listener":"subscription",t),t}this._mixin=function(e,t,n){for(var i=t||{},r=2;r<arguments.length;++r){var s,o,a=arguments[r];if(null!=a)for(var c in a)a.hasOwnProperty(c)&&(s=q(a,c),o=q(i,c),s!==t)&&void 0!==s&&(e&&"object"==typeof s&&null!==s?s instanceof Array?i[c]=this._mixin(e,o instanceof Array?o:[],s):(o="object"!=typeof o||o instanceof Array?{}:o,i[c]=this._mixin(e,o,s)):i[c]=s)}return i},this._warn=function(){$("warn",arguments)},this._info=function(){"warn"!==w.logLevel&&$("info",arguments)},this._debug=function(){"debug"===w.logLevel&&$("debug",arguments)},this._isCrossDomain=function(e){return!!(window.location&&window.location.host&&e)&&e!==window.location.host},this.send=I,this._getCallback=function(e){return m[e]},this._putCallback=function(e,t){var n=this._getCallback(e);return U(t)&&(m[e]=t),n},this.onTransportFailure=function(e,t,n){this._debug("Transport failure",t,"for",e);var i,r=this.getTransportRegistry(),s=this.getURL(),o=this._isCrossDomain(J(s)[2]),a=r.findTransportTypes("1.0",o,s);"none"===t.action?"/meta/handshake"!==e.channel||t.transport||(i="Could not negotiate transport, client=["+a+"], server=["+e.supportedConnectionTypes+"]",this._warn(i),ie(c.getType(),null,{reason:i,connectionType:c.getType(),transport:c})):(t.delay=this.getBackoffPeriod(),"/meta/handshake"===e.channel?(t.transport||(i=c?c.getType():null,(o=r.negotiateTransport(a,"1.0",o,s))?(s=o.getType(),this._debug("Transport",i,"->",s),ie(i,s,e.failure),t.action="handshake",t.transport=o):(this._warn("Could not negotiate transport, client=["+a+"]"),ie(i,null,e.failure),t.action="none")),"none"!==t.action&&this.increaseBackoffPeriod()):(s=(new Date).getTime(),0===T&&(T=s),"retry"===t.action&&(t.delay=this.increaseBackoffPeriod(),0<(o=y.maxInterval))&&y.timeout+y.interval+o<s-T+v&&(t.action="handshake"),"handshake"===t.action&&(t.delay=0,r.reset(!1),this.resetBackoffPeriod()))),n.call(u,t)},this.receive=ve,F=function(e){u._debug("Received",e);for(var t=0;t<e.length;++t)ve(e[t])},a=function(e,t,n){u._debug("handleFailure",e,t,n),n.transport=e;for(var i,r=0;r<t.length;++r){var s=t[r],o={id:s.id,successful:!1,channel:s.channel,failure:n};switch((n.message=s).channel){case"/meta/handshake":ce(o,{cause:"failure",action:"handshake",transport:null});break;case"/meta/connect":ue(i=o)?(b=!1,le(i,{cause:"failure",action:"retry",transport:null})):u._debug("Mismatched /meta/connect failure",i);break;case"/meta/disconnect":de(o);break;case"/meta/subscribe":o.subscription=s.subscription,he(o);break;case"/meta/unsubscribe":o.subscription=s.subscription,pe(o);break;default:fe(o)}}},this.registerTransport=function(e,t,n){n=l.add(e,t,n);return n&&(this._debug("Registered transport",e),U(t.registered))&&t.registered(e,this),n},this.unregisterTransport=function(e){var t=l.remove(e);return null!==t&&(this._debug("Unregistered transport",e),U(t.unregistered))&&t.unregistered(),t},this.unregisterTransports=function(){l.clear()},this.getTransportTypes=function(){return l.getTransportTypes()},this.findTransport=function(e){return l.find(e)},this.getTransportRegistry=function(){return l},this.configure=function(e){X.call(this,e)},this.init=function(e,t){this.configure(e),this.handshake(t)},this.handshake=function(e,t){if("disconnected"!==n)throw"Illegal state: handshaken";re(e,t)},this.disconnect=function(e,t){var n;j()||(U(e)&&(t=e,e=void 0),n={id:_(),channel:"/meta/disconnect"},e=this._mixin(!1,{},e,n),u._putCallback(e.id,t),R("disconnecting"),A([e],!1,"disconnect"))},this.startBatch=function(){++h,u._debug("Starting batch, depth",h)},this.endBatch=function(){if(--h,u._debug("Ending batch, depth",h),h<0)throw"Calls to startBatch() and endBatch() are not paired";0!==h||j()||p||te()},this.batch=function(e,t){e=ye(e,t);this.startBatch();try{e.method.call(e.scope),this.endBatch()}catch(e){throw this._info("Exception during execution of batch",e),this.endBatch(),e}},this.addListener=function(e,t,n){if(arguments.length<2)throw"Illegal arguments number: required 2, got "+arguments.length;if(E(e))return me(e,t,n,!0);throw"Illegal argument type: channel must be a string"},this.removeListener=function(e){if(!(e&&e.channel&&"id"in e))throw"Invalid argument: expected subscription, not "+e;W(e)},this.clearListeners=function(){f={}},this.subscribe=function(e,t,n,i,r){if(arguments.length<2)throw"Illegal arguments number: required 2, got "+arguments.length;if(!E(e))throw"Illegal argument type: channel must be a string";if(j())throw"Illegal state: disconnected";U(t)&&(r=i,i=n,n=t,t=void 0),U(i)&&(r=i,i=void 0);var s=!ge(e),t=me(e,t,n,!1);return s&&(n={id:_(),channel:"/meta/subscribe",subscription:e},s=this._mixin(!1,{},i,n),u._putCallback(s.id,r),I(s)),t},this.unsubscribe=function(e,t,n){if(arguments.length<1)throw"Illegal arguments number: required 1, got "+arguments.length;if(j())throw"Illegal state: disconnected";U(t)&&(n=t,t=void 0),this.removeListener(e);var e=e.channel;ge(e)||(e={id:_(),channel:"/meta/unsubscribe",subscription:e},t=this._mixin(!1,{},t,e),u._putCallback(t.id,n),I(t))},this.resubscribe=function(e,t){if(Q(e),e)return this.subscribe(e.channel,e.scope,e.callback,t)},this.clearSubscriptions=function(){Y()},this.publish=function(e,t,n,i){if(arguments.length<1)throw"Illegal arguments number: required 1, got "+arguments.length;if(!E(e))throw"Illegal argument type: channel must be a string";if(/^\/meta\//.test(e))throw"Illegal argument: cannot publish to meta channels";if(j())throw"Illegal state: disconnected";U(t)?(i=t,t={},n=void 0):U(n)&&(i=n,n=void 0);e={id:_(),channel:e,data:t},t=this._mixin(!1,{},n,e);u._putCallback(t.id,i),I(t)},this.publishBinary=function(e,t,n,i,r){U(t)?(r=t,t=new ArrayBuffer(0),n=!0,i=void 0):U(n)?(r=n,n=!0,i=void 0):U(i)&&(r=i,i=void 0);this.publish(e,{meta:i,data:t,last:n},{ext:{binary:{}}},r)},this.remoteCall=function(e,t,n,i,r){if(arguments.length<1)throw"Illegal arguments number: required 1, got "+arguments.length;if(!E(e))throw"Illegal argument type: target must be a string";if(j())throw"Illegal state: disconnected";if(U(t)?(r=t,t={},n=w.maxNetworkDelay,i=void 0):U(n)?(r=n,n=w.maxNetworkDelay,i=void 0):U(i)&&(r=i,i=void 0),"number"!=typeof n)throw"Illegal argument type: timeout must be a number";e.match(/^\//)||(e="/"+e);var e={id:_(),channel:"/service"+e,data:t},s=this._mixin(!1,{},i,e),t={callback:r};0<n&&(t.timeout=u.setTimeout(function(){u._debug("Timing out remote call",s,"after",n,"ms"),fe({id:s.id,error:"406::timeout",successful:!1,failure:{message:s,reason:"Remote Call Timeout"}})},n),u._debug("Scheduled remote call timeout",s,"in",n,"ms")),H[s.id]=t,I(s)},this.remoteCallBinary=function(e,t,n,i,r,s){U(t)?(s=t,t=new ArrayBuffer(0),n=!0,i=void 0,r=w.maxNetworkDelay):U(n)?(s=n,n=!0,i=void 0,r=w.maxNetworkDelay):U(i)?(s=i,i=void 0,r=w.maxNetworkDelay):U(r)&&(s=r,r=w.maxNetworkDelay);this.remoteCall(e,{meta:i,data:t,last:n},r,{ext:{binary:{}}},s)},this.getStatus=function(){return n},this.isDisconnected=j,this.setBackoffIncrement=function(e){w.backoffIncrement=e},this.getBackoffIncrement=function(){return w.backoffIncrement},this.getBackoffPeriod=function(){return v},this.increaseBackoffPeriod=function(){return v<w.maxBackoff&&(v+=w.backoffIncrement),v},this.resetBackoffPeriod=function(){P()},this.setLogLevel=function(e){w.logLevel=e},this.registerExtension=function(e,t){if(arguments.length<2)throw"Illegal arguments number: required 2, got "+arguments.length;if(!E(e))throw"Illegal argument type: extension name must be a string";for(var n=!1,i=0;i<g.length;++i)if(g[i].name===e){n=!0;break}return n?(this._info("Could not register extension with name",e,"since another extension with the same name already exists"),!1):(g.push({name:e,extension:t}),this._debug("Registered extension",e),U(t.registered)&&t.registered(e,this),!0)},this.unregisterExtension=function(e){if(!E(e))throw"Illegal argument type: extension name must be a string";for(var t=!1,n=0;n<g.length;++n){var i=g[n];if(i.name===e){g.splice(n,1),t=!0,this._debug("Unregistered extension",e);i=i.extension;U(i.unregistered)&&i.unregistered();break}}return t},this.getExtension=function(e){for(var t=0;t<g.length;++t){var n=g[t];if(n.name===e)return n.extension}return null},this.getName=function(){return B},this.getClientId=function(){return d},this.getURL=function(){if(c){var e=c.getURL();if(e)return e;if(e=w.urls[c.getType()])return e}return w.url},this.getTransport=function(){return c},this.getConfiguration=function(){return this._mixin(!0,{},w)},this.getAdvice=function(){return this._mixin(!0,{},y)},this.setTimeout=function(t,e){return r.setTimeout(function(){try{u._debug("Invoking timed function",t),t()}catch(e){u._debug("Exception invoking timed function",t,e)}},e)},this.clearTimeout=function(e){r.clearTimeout(e)},window.WebSocket&&this.registerTransport("websocket",new Ee),this.registerTransport("long-polling",new Se),this.registerTransport("callback-polling",new we)},Transport:m,RequestTransport:n=function(){var i=new m,e=m.derive(i),r=0,s=null,o=[],a=[];function c(i,r){var e,s,o;this.transportSend(i,r),r.expired=!1,i.sync||(e=this.getConfiguration().maxNetworkDelay,s=e,!0===r.metaConnect&&(s+=this.getAdvice().timeout),this._debug("Transport",this.getType(),"waiting at most",s,"ms for the response, maxNetworkDelay",e),r.timeout=(o=this).setTimeout(function(){r.expired=!0;var e="Request "+r.id+" of transport "+o.getType()+" exceeded "+s+" ms max network delay",t={reason:e},n=r.xhr;t.httpCode=o.xhrStatus(n),o.abortXHR(n),o._debug(e),o.complete(r,!1,r.metaConnect),i.onFailure(n,i.messages,t)},s))}function u(e){var t=++r,n={id:t,metaConnect:!1,envelope:e};o.length<this.getConfiguration().maxConnections-1?(o.push(n),c.call(this,e,n)):(this._debug("Transport",this.getType(),"queueing request",t,"envelope",e),a.push([e,n]))}function l(e,t){var n,i,r,s=Te.inArray(e,o);0<=s&&o.splice(s,1),0<a.length&&(s=a.shift(),n=s[0],i=s[1],this._debug("Transport dequeued request",i.id),t?(this.getConfiguration().autoBatch&&function(e){for(;0<a.length;){var t=a[0],n=t[0],t=t[1];if(n.url!==e.url||n.sync!==e.sync)break;a.shift(),e.messages=e.messages.concat(n.messages),this._debug("Coalesced",n.messages.length,"messages from request",t.id)}}.call(this,n),u.call(this,n),this._debug("Transport completed request",e.id,n)):(r=this).setTimeout(function(){r.complete(i,!1,i.metaConnect);var e={reason:"Previous request failed"},t=i.xhr;e.httpCode=r.xhrStatus(t),n.onFailure(t,n.messages,e)},0))}return e.complete=function(e,t,n){n?function(e){if(e=e.id,this._debug("Transport",this.getType(),"/meta/connect complete, request",e),null!==s&&s.id!==e)throw"/meta/connect request mismatch, completing request "+e;s=null}.call(this,e):l.call(this,e,t)},e.transportSend=function(e,t){throw"Abstract"},e.transportSuccess=function(e,t,n){t.expired||(this.clearTimeout(t.timeout),this.complete(t,!0,t.metaConnect),n&&0<n.length?e.onSuccess(n):e.onFailure(t.xhr,e.messages,{httpCode:204}))},e.transportFailure=function(e,t,n){t.expired||(this.clearTimeout(t.timeout),this.complete(t,!1,t.metaConnect),e.onFailure(t.xhr,e.messages,n))},e.send=function(e,t){(t?function(e){if(null!==s)throw"Concurrent /meta/connect requests not allowed, request id="+s.id+" not yet completed";var t=++r,t=(this._debug("Transport",this.getType(),"/meta/connect send, request",t,"envelope",e),{id:t,metaConnect:!0,envelope:e});c.call(this,e,t),s=t}:u).call(this,e)},e.abort=function(){i.abort();for(var e=0;e<o.length;++e){var t=o[e];t&&(this._debug("Aborting request",t),this.abortXHR(t.xhr)||this.transportFailure(t.envelope,t,{reason:"abort"}))}var n=s;n&&(this._debug("Aborting /meta/connect request",n),this.abortXHR(n.xhr)||this.transportFailure(n.envelope,n,{reason:"abort"})),this.reset(!0)},e.reset=function(e){i.reset(e),s=null,o=[],a=[]},e.abortXHR=function(e){if(e)try{var t=e.readyState;return e.abort(),t!==window.XMLHttpRequest.UNSENT}catch(e){this._debug(e)}return!1},e.xhrStatus=function(e){if(e)try{return e.status}catch(e){this._debug(e)}return-1},e},LongPollingTransport:Se=function(){var t=new n,r=m.derive(t),a=!0;return r.accept=function(e,t,n){return a||!t},r.newXMLHttpRequest=function(){return new window.XMLHttpRequest},r.xhrSend=function(e){var t=r.newXMLHttpRequest(),n=(!function(e){try{e.context=r.context}catch(e){this._debug("Could not copy transport context into XHR",e)}}(t),t.withCredentials=!0,t.open("POST",e.url,!0!==e.sync),e.headers);if(n)for(var i in n)n.hasOwnProperty(i)&&t.setRequestHeader(i,n[i]);return t.setRequestHeader("Content-Type","application/json;charset=UTF-8"),t.onload=function(){200===t.status?e.onSuccess(t.responseText):e.onError(t.statusText)},t.onabort=t.onerror=function(){e.onError(t.statusText)},t.send(e.body),t},r.transportSend=function(i,r){this._debug("Transport",this.getType(),"sending request",r.id,"envelope",i);var s=this;try{var o=!0;r.xhr=this.xhrSend({transport:this,url:i.url,sync:i.sync,headers:this.getConfiguration().requestHeaders,body:JSON.stringify(i.messages),onSuccess:function(t){s._debug("Transport",s.getType(),"received response",t);var n=!1;try{var e=s.convertToMessages(t);0===e.length?(a=!1,s.transportFailure(i,r,{httpCode:204})):(n=!0,s.transportSuccess(i,r,e))}catch(e){s._debug(e),n||(a=!1,(t={exception:e}).httpCode=s.xhrStatus(r.xhr),s.transportFailure(i,r,t))}},onError:function(e,t){s._debug("Transport",s.getType(),"received error",e,t),a=!1;var n={reason:e,exception:t};n.httpCode=s.xhrStatus(r.xhr),o?s.setTimeout(function(){s.transportFailure(i,r,n)},0):s.transportFailure(i,r,n)}}),o=!1}catch(e){a=!1,this.setTimeout(function(){s.transportFailure(i,r,{exception:e})},0)}},r.reset=function(e){t.reset(e),a=!0},r},CallbackPollingTransport:we=function(){var e=new n,e=m.derive(e),s=0;function f(e,t,n){var i=this;return function(){i.transportFailure(e,t,"error",n)}}return e.accept=function(e,t,n){return!0},e.jsonpSend=function(t){var n=document.getElementsByTagName("head")[0],i=document.createElement("script"),r="_cometd_jsonp_"+s++,e=(window[r]=function(e){n.removeChild(i),delete window[r],t.onSuccess(e)},t.url),e=(e=(e+=e.indexOf("?")<0?"?":"&")+("jsonp="+r))+("&message="+encodeURIComponent(t.body));i.src=e,i.async=!0!==t.sync,i.type="application/javascript",i.onerror=function(e){t.onError("jsonp "+e.type)},n.appendChild(i)},e.transportSend=function(e,i){for(var r=this,t=0,n=e.messages.length,s=[];0<n;){var o=JSON.stringify(e.messages.slice(t,t+n)),o=e.url.length+encodeURI(o).length,a=this.getConfiguration().maxURILength;if(a<o){if(1===n)return o="Bayeux message too big ("+o+" bytes, max is "+a+") for transport "+this.getType(),void this.setTimeout(f.call(this,e,i,o),0);--n}else s.push(n),t+=n,n=e.messages.length-t}var c=e;if(1<s.length){var u=s[0];this._debug("Transport",this.getType(),"split",e.messages.length,"messages into",s.join(" + ")),(c=this._mixin(!1,{},e)).messages=e.messages.slice(0,u),c.onSuccess=e.onSuccess,c.onFailure=e.onFailure;for(var l=1;l<s.length;++l){var d=this._mixin(!1,{},e),h=u;u+=s[l],d.messages=e.messages.slice(h,u),d.onSuccess=e.onSuccess,d.onFailure=e.onFailure,this.send(d,i.metaConnect)}}this._debug("Transport",this.getType(),"sending request",i.id,"envelope",c);try{var p=!0;this.jsonpSend({transport:this,url:c.url,sync:c.sync,headers:this.getConfiguration().requestHeaders,body:JSON.stringify(c.messages),onSuccess:function(e){var t=!1;try{var n=r.convertToMessages(e);0===n.length?r.transportFailure(c,i,{httpCode:204}):(t=!0,r.transportSuccess(c,i,n))}catch(e){r._debug(e),t||r.transportFailure(c,i,{exception:e})}},onError:function(e,t){var n={reason:e,exception:t};p?r.setTimeout(function(){r.transportFailure(c,i,n)},0):r.transportFailure(c,i,n)}}),p=!1}catch(e){this.setTimeout(function(){r.transportFailure(c,i,{exception:e})},0)}},e},WebSocketTransport:Ee=function(){var c,n=new m,e=m.derive(n),u=!0,l=!1,d=!0,h=null,p=null,g=!1,y=null;function f(e,t){e&&(this.webSocketClose(e,t.code,t.reason),this.onClose(e,t))}function v(e){return e===p||e===h}function r(e,t,n){for(var i=[],r=0;r<t.messages.length;++r){var s=t.messages[r];s.id&&i.push(s.id)}e.envelopes[i.join(",")]=[t,n],this._debug("Transport",this.getType(),"stored envelope, envelopes",e.envelopes)}function s(t,n,e){for(var i=JSON.stringify(n.messages),i=(t.webSocket.send(i),this._debug("Transport",this.getType(),"sent",n,"/meta/connect =",e),this.getConfiguration().maxNetworkDelay),r=i,s=(e&&(r+=this.getAdvice().timeout,g=!0),this),o=[],a=0;a<n.messages.length;++a)!function(){var e=n.messages[a];e.id&&(o.push(e.id),t.timeouts[e.id]=s.setTimeout(function(){c._debug("Transport",s.getType(),"timing out message",e.id,"after",r,"on",t),f.call(s,t,{code:1e3,reason:"Message Timeout"})},r))}();this._debug("Transport",this.getType(),"waiting at most",r,"ms for messages",o,"maxNetworkDelay",i,", timeouts:",t.timeouts)}function i(t,e,n){try{null===t?(t=p||{envelopes:{},timeouts:{}},r.call(this,t,e,n),function(t){if(!p){var e=c.getURL().replace(/^http/,"ws");this._debug("Transport",this.getType(),"connecting to URL",e);try{var n=c.getConfiguration().protocol;t.webSocket=n?new window.WebSocket(e,n):new window.WebSocket(e),p=t}catch(e){throw u=!1,this._debug("Exception while creating WebSocket object",e),e}d=!1!==c.getConfiguration().stickyReconnect;var i=this,r=c.getConfiguration().connectTimeout,s=(0<r&&(t.connectTimer=this.setTimeout(function(){c._debug("Transport",i.getType(),"timed out while connecting to URL",e,":",r,"ms"),f.call(i,t,{code:1e3,reason:"Connect Timeout"})},r)),function(e){c._debug("WebSocket onclose",t,e=e||{code:1e3},"connecting",p,"current",h),t.connectTimer&&i.clearTimeout(t.connectTimer),i.onClose(t,e)});t.webSocket.onopen=function(){c._debug("WebSocket onopen",t),t.connectTimer&&i.clearTimeout(t.connectTimer),v(t)?(h=t,l=!(p=null),i.onOpen(t)):(c._warn("Closing extra WebSocket connection",this,"active connection",h),f.call(i,t,{code:1e3,reason:"Extra Connection"}))},t.webSocket.onclose=s,t.webSocket.onerror=function(){s({code:1e3,reason:"Error"})},t.webSocket.onmessage=function(e){c._debug("WebSocket onmessage",e,t),i.onMessage(t,e)},this._debug("Transport",this.getType(),"configured callbacks on",t)}}.call(this,t)):(r.call(this,t,e,n),s.call(this,t,e,n))}catch(e){var i=this;this.setTimeout(function(){f.call(i,t,{code:1e3,reason:"Exception",exception:e})},0)}}return e.reset=function(e){n.reset(e),e&&(l=!1),p=h=null,g=!(d=u=!0)},e._notifySuccess=function(e,t){e.call(this,t)},e._notifyFailure=function(e,t,n,i){e.call(this,t,n,i)},e.onOpen=function(e){var t,n,i,r=e.envelopes;for(t in this._debug("Transport",this.getType(),"opened",e,"pending messages",r),r)r.hasOwnProperty(t)&&(n=(i=r[t])[0],i=i[1],y=n.onSuccess,s.call(this,e,n,i))},e.onMessage=function(e,t){this._debug("Transport",this.getType(),"received websocket message",t,e);for(var n=!1,i=this.convertToMessages(t.data),r=[],s=0;s<i.length;++s){var o,a=i[s];(/^\/meta\//.test(a.channel)||void 0===a.data)&&a.id&&(r.push(a.id),o=e.timeouts[a.id])&&(this.clearTimeout(o),delete e.timeouts[a.id],this._debug("Transport",this.getType(),"removed timeout for message",a.id,", timeouts",e.timeouts)),"/meta/connect"===a.channel&&(g=!1),"/meta/disconnect"!==a.channel||g||(n=!0)}for(var c=!1,u=e.envelopes,l=0;l<r.length;++l){var d,h=r[l];for(d in u)if(u.hasOwnProperty(d)){var p=d.split(","),f=Te.inArray(h,p);if(0<=f){c=!0,p.splice(f,1);var f=u[d][0],v=u[d][1];delete u[d],0<p.length&&(u[p.join(",")]=[f,v]);break}}}c&&this._debug("Transport",this.getType(),"removed envelope, envelopes",u),this._notifySuccess(y,i),n&&this.webSocketClose(e,1e3,"Disconnect")},e.onClose=function(e,t){this._debug("Transport",this.getType(),"closed",e,t),v(e)&&(u=d&&l,h=p=null);var n,i=e.timeouts;for(n in e.timeouts={},i)i.hasOwnProperty(n)&&this.clearTimeout(i[n]);var r,s,o,a=e.envelopes;for(r in e.envelopes={},a)a.hasOwnProperty(r)&&(s=a[r][0],a[r][1]&&(g=!1),o={websocketCode:t.code,reason:t.reason},t.exception&&(o.exception=t.exception),this._notifyFailure(s.onFailure,e,s.messages,o))},e.registered=function(e,t){n.registered(e,t),c=t},e.accept=function(e,t,n){return this._debug("Transport",this.getType(),"accept, supported:",u),u&&!!window.WebSocket&&!1!==c.websocketEnabled},e.send=function(e,t){this._debug("Transport",this.getType(),"sending",e,"/meta/connect =",t),i.call(this,h,e,t)},e.webSocketClose=function(e,t,n){try{e.webSocket&&e.webSocket.close(t,n)}catch(e){this._debug(e)}},e.abort=function(){n.abort(),f.call(this,h,{code:1e3,reason:"Abort"}),this.reset(!0)},e},Utils:Te,Z85:{encode:function(e){var t=null;if(e instanceof ArrayBuffer?t=e:e.buffer instanceof ArrayBuffer?t=e.buffer:Array.isArray(e)&&(t=new Uint8Array(e).buffer),null==t)throw"Cannot Z85 encode "+e;for(var n=t.byteLength,e=n%4,i=4-(0==e?4:e),r=new DataView(t),s="",o=0,a=0;a<n+i;++a){var c=n<=a,o=256*o+(c?0:r.getUint8(a));if((a+1)%4==0){for(var u,l=52200625,d=5;0<d;--d)(!c||i<d)&&(u=Math.floor(o/l)%85,s+=h[u]),l/=85;o=0}}return s},decode:function(e){for(var t=e.length%5,n=5-(0==t?5:t),i=0;i<n;++i)e+=h[h.length-1];for(var r=e.length,t=new ArrayBuffer(4*r/5-n),s=new DataView(t),o=0,a=0,c=0,u=0;u<r;++u){var l=e.charCodeAt(a++)-32,o=85*o+p[l];if(a%5==0){for(var d=16777216;1<=d;)c<s.byteLength&&s.setUint8(c++,Math.floor(o/d)%256),d/=256;o=0}}return t}}})}),F={CometD:e.CometD,default:e}.CometD;(e=i=i||{}).HANDSHAKE="/meta/handshake",e.CONNECT="/meta/connect",e.SUBSCRIBE="/meta/subscribe",e.UNSUBSCRIBE="/meta/unsubscribe";class B{constructor(e,t="/notification/realtime",n){this.client=e,this.url=t,this.cometd=new F,this.metaHandshake=e=>{if(!e.successful)throw new Error("Handshake failed")},this.cometd.websocketEnabled=!0,this.cometd.addListener(i.HANDSHAKE,n||this.metaHandshake)}subscribe(e,t){return this.checkConnection(),this.cometd.subscribe(e,t)}unsubscribe(e){return this.cometd.unsubscribe(e)}disconnect(){this.cometd.disconnect()}checkConnection(){var e,{cometd:t,client:n,url:i}=this;t.isDisconnected()&&(e=n.getFetchOptions()["headers"],i={url:n.getUrl(i),requestHeaders:e},t.configure(i),this.handshake(n.getCometdHandshake()))}handshake(e){this.cometd.handshake(e)}}var n=function(e,o,a,c){return new(a=a||Promise)(function(n,t){function i(e){try{s(c.next(e))}catch(e){t(e)}}function r(e){try{s(c.throw(e))}catch(e){t(e)}}function s(e){var t;e.done?n(e.value):((t=e.value)instanceof a?t:new a(function(e){e(t)})).then(i,r)}s((c=c.apply(e,o||[])).next())})};class M{constructor(e,t,n){this.filter=n,this.service=e,this.currentPage=t.currentPage,this.nextPage=t.nextPage,this.prevPage=t.prevPage,this.pageSize=t.pageSize,this.totalPages=t.totalPages}next(e={}){return n(this,void 0,void 0,function*(){return this.list(this.getFilter(e,this.nextPage))})}prev(e={}){return n(this,void 0,void 0,function*(){return this.list(this.getFilter(e,this.prevPage))})}list(e={}){return n(this,void 0,void 0,function*(){return this.service.list(e)})}goto(e,t={}){return n(this,void 0,void 0,function*(){return this.list(this.getFilter(t,e))})}getFilter(e,t){return Object.assign(e,this.filter,{currentPage:t})}}var s=function(e,o,a,c){return new(a=a||Promise)(function(n,t){function i(e){try{s(c.next(e))}catch(e){t(e)}}function r(e){try{s(c.throw(e))}catch(e){t(e)}}function s(e){var t;e.done?n(e.value):((t=e.value)instanceof a?t:new a(function(e){e(t)})).then(i,r)}s((c=c.apply(e,o||[])).next())})};class t{constructor(e,t){this.client=e,this.realtime=t,this.cache=new Map;const n=Object.getPrototypeOf(this);["list","create","update","detail","delete"].forEach(e=>{n.hasOwnProperty(e)||Object.defineProperty(this,e,{get(){}})})}list(n={}){return s(this,void 0,void 0,function*(){var e=this.listUrl,e=yield this.fetch(e,this.changeFetchOptions({headers:{accept:"application/json"},params:n},e)),t=yield e.json();return{res:e,data:this.propertyName?t[this.propertyName]:t,paging:this.getPaging(t,n)}})}detail(n,i={}){return s(this,void 0,void 0,function*(){var e=this.getDetailUrl(n),e=yield this.fetch(e,this.changeFetchOptions({headers:{accept:"application/json"},params:Object.assign({},i)},e)),t=yield e.json();return{res:e,data:t}})}create(n){return s(this,void 0,void 0,function*(){var e=this.listUrl,t=JSON.stringify(this.onBeforeCreate(n)),t=yield this.fetch(e,this.changeFetchOptions({method:"POST",body:t,headers:{"content-type":"application/json",accept:"application/json"}},e)),e=yield t.json();return{res:t,data:e}})}update(n){return s(this,void 0,void 0,function*(){var e=this.getDetailUrl(n),t=JSON.stringify(this.onBeforeUpdate(n)),t=yield this.fetch(e,this.changeFetchOptions({method:"PUT",body:t,headers:{"content-type":"application/json",accept:"application/json"}},e)),e=yield t.json();return{res:t,data:e}})}delete(t,n){return s(this,void 0,void 0,function*(){var e=this.getDetailUrl(t);return{res:yield this.fetch(e,this.changeFetchOptions({method:"DELETE",params:n},e)),data:null}})}onBeforeCreate(e){return delete e.id,e}onBeforeUpdate(e){return e}changeFetchOptions(e,t=0){return e}getUrl(e=""){return this.baseUrl.replace(/\/+$/,"")+"/"+e.replace(/^\/+/,"")}getEntityId(e){return null==e?"":"object"==typeof e?this.getEntityId(e.id):""+e}getDetailUrl(e){e=this.getEntityId(e);return this.listUrl+"/"+e}fetch(t,n){return s(this,void 0,void 0,function*(){var e=this.getUrl(t),e=yield this.client.fetch(e,n);return yield this.handleErrorStatusCodes(e)})}handleErrorStatusCodes(n){return s(this,void 0,void 0,function*(){if(400<=n.status){let t=null;try{t=yield n.json()}catch(e){try{t=yield n.text()}catch(e){}}throw{res:n,data:t}}return n})}mimeType(e){return`application/vnd.com.nsn.cumulocity.${e}+json`}getIdString(e){let t;return t="object"==typeof e?e.id:e,String(t)}getPaging(e,t){return e.statistics?(e=Object.assign(Object.assign({},e.statistics),{nextPage:this.getCurrentPageFromLink(e.next),prevPage:this.getCurrentPageFromLink(e.prev)}),new M(this,e,t)):null}getCurrentPageFromLink(e=""){e=e.match(/currentPage=(-{0,1}\d+)/);return e&&parseInt(e[1],10)}}var e=L(function(e,t){var n="undefined"!=typeof self?self:D,i=(r.prototype=n,new r);function r(){this.fetch=!1,this.DOMException=n.DOMException}var s,o,a=i,c={},u="URLSearchParams"in a,l="Symbol"in a&&"iterator"in Symbol,d="FileReader"in a&&"Blob"in a&&function(){try{return new Blob,!0}catch(e){return!1}}(),h="FormData"in a,p="ArrayBuffer"in a;function f(e){if("string"!=typeof e&&(e=String(e)),/[^a-z0-9\-#$%&'*+.^_`|~]/i.test(e))throw new TypeError("Invalid character in header field name");return e.toLowerCase()}function v(e){return e="string"!=typeof e?String(e):e}function g(t){var e={next:function(){var e=t.shift();return{done:void 0===e,value:e}}};return l&&(e[Symbol.iterator]=function(){return e}),e}function y(t){this.map={},t instanceof y?t.forEach(function(e,t){this.append(t,e)},this):Array.isArray(t)?t.forEach(function(e){this.append(e[0],e[1])},this):t&&Object.getOwnPropertyNames(t).forEach(function(e){this.append(e,t[e])},this)}function m(e){if(e.bodyUsed)return Promise.reject(new TypeError("Already read"));e.bodyUsed=!0}function b(n){return new Promise(function(e,t){n.onload=function(){e(n.result)},n.onerror=function(){t(n.error)}})}function T(e){var t=new FileReader,n=b(t);return t.readAsArrayBuffer(e),n}function O(e){var t;return e.slice?e.slice(0):((t=new Uint8Array(e.byteLength)).set(new Uint8Array(e)),t.buffer)}function S(){return this.bodyUsed=!1,this._initBody=function(e){var t;(this._bodyInit=e)?"string"==typeof e?this._bodyText=e:d&&Blob.prototype.isPrototypeOf(e)?this._bodyBlob=e:h&&FormData.prototype.isPrototypeOf(e)?this._bodyFormData=e:u&&URLSearchParams.prototype.isPrototypeOf(e)?this._bodyText=e.toString():p&&d&&(t=e)&&DataView.prototype.isPrototypeOf(t)?(this._bodyArrayBuffer=O(e.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):p&&(ArrayBuffer.prototype.isPrototypeOf(e)||o(e))?this._bodyArrayBuffer=O(e):this._bodyText=e=Object.prototype.toString.call(e):this._bodyText="",this.headers.get("content-type")||("string"==typeof e?this.headers.set("content-type","text/plain;charset=UTF-8"):this._bodyBlob&&this._bodyBlob.type?this.headers.set("content-type",this._bodyBlob.type):u&&URLSearchParams.prototype.isPrototypeOf(e)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},d&&(this.blob=function(){var e=m(this);if(e)return e;if(this._bodyBlob)return Promise.resolve(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(new Blob([this._bodyArrayBuffer]));if(this._bodyFormData)throw new Error("could not read FormData body as blob");return Promise.resolve(new Blob([this._bodyText]))},this.arrayBuffer=function(){return this._bodyArrayBuffer?m(this)||Promise.resolve(this._bodyArrayBuffer):this.blob().then(T)}),this.text=function(){var e,t,n=m(this);if(n)return n;if(this._bodyBlob)return n=this._bodyBlob,e=new FileReader,t=b(e),e.readAsText(n),t;if(this._bodyArrayBuffer)return Promise.resolve(function(e){for(var t=new Uint8Array(e),n=new Array(t.length),i=0;i<t.length;i++)n[i]=String.fromCharCode(t[i]);return n.join("")}(this._bodyArrayBuffer));if(this._bodyFormData)throw new Error("could not read FormData body as text");return Promise.resolve(this._bodyText)},h&&(this.formData=function(){return this.text().then(U)}),this.json=function(){return this.text().then(JSON.parse)},this}p&&(s=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],o=ArrayBuffer.isView||function(e){return e&&-1<s.indexOf(Object.prototype.toString.call(e))}),y.prototype.append=function(e,t){e=f(e),t=v(t);var n=this.map[e];this.map[e]=n?n+", "+t:t},y.prototype.delete=function(e){delete this.map[f(e)]},y.prototype.get=function(e){return e=f(e),this.has(e)?this.map[e]:null},y.prototype.has=function(e){return this.map.hasOwnProperty(f(e))},y.prototype.set=function(e,t){this.map[f(e)]=v(t)},y.prototype.forEach=function(e,t){for(var n in this.map)this.map.hasOwnProperty(n)&&e.call(t,this.map[n],n,this)},y.prototype.keys=function(){var n=[];return this.forEach(function(e,t){n.push(t)}),g(n)},y.prototype.values=function(){var t=[];return this.forEach(function(e){t.push(e)}),g(t)},y.prototype.entries=function(){var n=[];return this.forEach(function(e,t){n.push([t,e])}),g(n)},l&&(y.prototype[Symbol.iterator]=y.prototype.entries);var w=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];function E(e,t){var n,i=(t=t||{}).body;if(e instanceof E){if(e.bodyUsed)throw new TypeError("Already read");this.url=e.url,this.credentials=e.credentials,t.headers||(this.headers=new y(e.headers)),this.method=e.method,this.mode=e.mode,this.signal=e.signal,i||null==e._bodyInit||(i=e._bodyInit,e.bodyUsed=!0)}else this.url=String(e);if(this.credentials=t.credentials||this.credentials||"same-origin",!t.headers&&this.headers||(this.headers=new y(t.headers)),this.method=(e=t.method||this.method||"GET",n=e.toUpperCase(),-1<w.indexOf(n)?n:e),this.mode=t.mode||this.mode||null,this.signal=t.signal||this.signal,this.referrer=null,("GET"===this.method||"HEAD"===this.method)&&i)throw new TypeError("Body not allowed for GET or HEAD requests");this._initBody(i)}function U(e){var n=new FormData;return e.trim().split("&").forEach(function(e){var t;e&&(t=(e=e.split("=")).shift().replace(/\+/g," "),e=e.join("=").replace(/\+/g," "),n.append(decodeURIComponent(t),decodeURIComponent(e)))}),n}function C(e,t){t=t||{},this.type="default",this.status=void 0===t.status?200:t.status,this.ok=200<=this.status&&this.status<300,this.statusText="statusText"in t?t.statusText:"OK",this.headers=new y(t.headers),this.url=t.url||"",this._initBody(e)}E.prototype.clone=function(){return new E(this,{body:this._bodyInit})},S.call(E.prototype),S.call(C.prototype),C.prototype.clone=function(){return new C(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new y(this.headers),url:this.url})},C.error=function(){var e=new C(null,{status:0,statusText:""});return e.type="error",e};var R=[301,302,303,307,308];C.redirect=function(e,t){if(-1===R.indexOf(t))throw new RangeError("Invalid status code");return new C(null,{status:t,headers:{location:e}})},c.DOMException=a.DOMException;try{new c.DOMException}catch(e){c.DOMException=function(e,t){this.message=e,this.name=t;t=Error(e);this.stack=t.stack},c.DOMException.prototype=Object.create(Error.prototype),c.DOMException.prototype.constructor=c.DOMException}function j(s,o){return new Promise(function(i,e){var t=new E(s,o);if(t.signal&&t.signal.aborted)return e(new c.DOMException("Aborted","AbortError"));var r=new XMLHttpRequest;function n(){r.abort()}r.onload=function(){var n,e={status:r.status,statusText:r.statusText,headers:(e=r.getAllResponseHeaders()||"",n=new y,e.replace(/\r?\n[\t ]+/g," ").split(/\r?\n/).forEach(function(e){var e=e.split(":"),t=e.shift().trim();t&&(e=e.join(":").trim(),n.append(t,e))}),n)},t=(e.url="responseURL"in r?r.responseURL:e.headers.get("X-Request-URL"),"response"in r?r.response:r.responseText);i(new C(t,e))},r.onerror=function(){e(new TypeError("Network request failed"))},r.ontimeout=function(){e(new TypeError("Network request failed"))},r.onabort=function(){e(new c.DOMException("Aborted","AbortError"))},r.open(t.method,t.url,!0),"include"===t.credentials?r.withCredentials=!0:"omit"===t.credentials&&(r.withCredentials=!1),"responseType"in r&&d&&(r.responseType="blob"),t.headers.forEach(function(e,t){r.setRequestHeader(t,e)}),t.signal&&(t.signal.addEventListener("abort",n),r.onreadystatechange=function(){4===r.readyState&&t.signal.removeEventListener("abort",n)}),r.send(void 0===t._bodyInit?null:t._bodyInit)})}j.polyfill=!0,a.fetch||(a.fetch=j,a.Headers=y,a.Request=E,a.Response=C),c.Headers=y,c.Request=E,c.Response=C,c.fetch=j,Object.defineProperty(c,"__esModule",{value:!0}),i.fetch.ponyfill=!0,delete i.fetch.polyfill;a=i;(t=a.fetch).default=a.fetch,t.fetch=a.fetch,t.Headers=a.Headers,t.Request=a.Request,t.Response=a.Response,e.exports=t}),G=(_=e)&&_.__esModule&&Object.prototype.hasOwnProperty.call(_,"default")?_.default:_,H=(e.fetch,e.Headers,e.Request,e.Response,function(e,o,a,c){return new(a=a||Promise)(function(n,t){function i(e){try{s(c.next(e))}catch(e){t(e)}}function r(e){try{s(c.throw(e))}catch(e){t(e)}}function s(e){var t;e.done?n(e.value):((t=e.value)instanceof a?t:new a(function(e){e(t)})).then(i,r)}s((c=c.apply(e,o||[])).next())})});let V=new WeakMap;class h{constructor(e,t){this.baseUrl=t,this.tenant="",this.defaultHeaders={},"string"==typeof e?t=e:this.setAuth(e),this.baseUrl=this.resolveServerUrl(t)}setAuth(e){V.set(this,e)}fetch(i,r){return H(this,void 0,void 0,function*(){let e=G;try{e=window.fetch||e}catch(e){}var t=this.getUrl(i,r),n=this.getFetchOptions(r);return e(t,n)})}getUrl(e="",t){const i=t&&t.params;let n="";return i&&Object.keys(i).length&&(n="?"+(n=Object.keys(i).map(e=>{let t=i[e];const n=encodeURIComponent(e);return(t=Array.isArray(t)?t:[t]).map(e=>n+"="+encodeURIComponent(e)).join("&")}).join("&"))),this.baseUrl.replace(/\/+$/,"").replace(/^\/+/,"")+"/"+e.replace(/\/+$/,"").replace(/^\/+/,"")+n}getFetchOptions(e={}){let t=Object.assign({},e);e=V.get(this);return t.headers=Object.assign({},this.defaultHeaders,t.headers,{UseXBasic:!0}),delete t.params,t=e?e.getFetchOptions(t):t}getCometdHandshake(e={}){var t=V.get(this);return t?t.getCometdHandshake(e):e}resolveServerUrl(e=""){if(e&&e.startsWith("http"))return e.replace(/\/+$/,"");try{var t=window.location;return`${t.protocol}//${t.host}/`+e.replace(/\/+$/,"")}catch(e){throw Error("Your environment does not support relative URLs. Please provide a base URL.")}}}function q(e){function t(){this.message=e}return(t.prototype=new Error).name="InvalidCharacterError",t.prototype.code=5,t}function $(e){return X(encodeURIComponent(e).replace(/%([0-9A-F]{2})/g,function(e,t){return String.fromCharCode("0x"+t)}))}var J=q("The string to be encoded contains characters out of range"),X="undefined"!=typeof btoa?function(e){return btoa(e)}:function(e){for(var t,n,i=String(e),r="",s=0,o="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";i.charAt(0|s)||(o="=",s%1);r+=o.charAt(63&t>>8-s%1*8)){if(255<(n=i.charCodeAt(s+=.75)))throw new J;t=t<<8|n}return r},o=(q("The string to be decoded is not correctly encoded"),new WeakMap);class p{constructor(e){this.updateCredentials(e)}updateCredentials({tenant:e,user:t,password:n,token:i,tfa:r}={}){var s=o.get(this)||{};return t=(t=t&&e?e+"/"+t:t)||this.user,n=n||s.password,!i&&t&&n&&(i=$(t+":"+n)),t&&(this.user=t),i=i||s.token,r=r||s.tfa,o.set(this,{tfa:r,token:i,password:n}),i}getFetchOptions(e){var{token:t,tfa:n}=o.get(this),i=this.getCookieValue("XSRF-TOKEN"),t=Object.assign({Authorization:"Basic "+(t||"")},i?{"X-XSRF-TOKEN":i}:void 0);return n&&(t.tfatoken=n),e.headers=Object.assign(t,e.headers),e}getCometdHandshake(e={}){var{token:t,tfa:n}=o.get(this),i="com.cumulocity.authn",r=e.ext=e.ext||{};return r[i]=Object.assign(r[i]||{},{token:t,tfa:n}),e}logout(){delete this.user,o.set(this,{})}getCookieValue(e){try{var t=document.cookie.match("(^|;)\\s*"+e+"\\s*=\\s*([^;]+)");return t?t.pop():void 0}catch(e){}}}var W=function(e,o,a,c){return new(a=a||Promise)(function(n,t){function i(e){try{s(c.next(e))}catch(e){t(e)}}function r(e){try{s(c.throw(e))}catch(e){t(e)}}function s(e){var t;e.done?n(e.value):((t=e.value)instanceof a?t:new a(function(e){e(t)})).then(i,r)}s((c=c.apply(e,o||[])).next())})};r.Severity=void 0,(_=r.Severity||(r.Severity={}))[_.CRITICAL="CRITICAL"]="CRITICAL",_[_.MAJOR="MAJOR"]="MAJOR",_[_.MINOR="MINOR"]="MINOR",_[_.WARNING="WARNING"]="WARNING";class Q{constructor(){this.operatorFns={__not:e=>`not(${this.buildQueryFilter(e,null)})`,__and:e=>this.buildQueryFilter(e,null,"and"),__or:e=>this.buildQueryFilter(e,null,"or"),__eq:(e,t)=>"object"==typeof e&&null!==e?this.buildQueryFilter(e,t):this.quoteString(t)+" eq "+this.quoteString(e),__gt:(e,t)=>this.quoteString(t)+" gt "+this.quoteString(e),__ge:(e,t)=>this.quoteString(t)+" ge "+this.quoteString(e),__lt:(e,t)=>this.quoteString(t)+" lt "+this.quoteString(e),__le:(e,t)=>this.quoteString(t)+" le "+this.quoteString(e),__in:(e,t)=>{e=e.filter(e=>!!e).map(e=>this.quoteString(t)+" eq "+this.quoteString(e));return this.glue(e,"or")},__bygroupid:e=>`bygroupid(${e})`,__has:e=>`has(${e})`,__useFilterQueryString:e=>{e=null==(e=e.match(/\(.*\)/))?void 0:e[0];return null==e?void 0:e.substring(1,e.length-1)}}}buildQuery(e){var t=[],n=this.buildQueryFilter(e.__filter||e),e=this.buildQueryOrderby(e.__orderby);return n&&t.push(`$filter=(${n})`),e&&t.push("$orderby="+e),t.join(" ")}buildQueryFilter(n,e,t){const i=e||null,r=t||"and",s=[];if(Array.isArray(n))n.forEach(e=>{e=this.buildQueryFilter(e,null,r);e&&s.push(e)});else{let t;Object.keys(n).forEach(e=>{void 0!==this.operatorFns[e]?(t=this.operatorFns[e](n[e],i))&&s.push(t):(t=this.operatorFns.__eq(n[e],e))&&s.push(t)})}return this.glue(s,r)}buildQueryOrderby(e){const n=[];return e&&e.forEach(t=>{Object.keys(t).forEach(e=>{0!==t[e]&&n.push(e+" "+(0<t[e]?"asc":"desc"))})}),n.join(",")}addAndFilter(e,t){return this.addFilter(e,t,"and")}addOrFilter(e,t){return this.addFilter(e,t,"or")}addFilter(e,t,n){var i=e.__orderby?e.__filter||{}:e.__filter||e,n={["__"+n]:this.skipEmptyObjects([i,t])};return e.__filter||e.__orderby?(e.__filter=n,e):n}prependOrderbys(e,t){return this.addOrderbys(e,t,"prepend")}appendOrderbys(e,t){return this.addOrderbys(e,t,"append")}addOrderbys(e,t,n){var i=e.__orderby?e.__filter||{}:e.__filter||e,e=e.__orderby||[],n="prepend"===n?[...t,...e]:[...e,...t],e={__orderby:this.skipEmptyObjects(n)};return this.isEmptyObject(i)||(e.__filter=i),e}extractAndMergeOrderBys(e){if(0<(null==e?void 0:e.length))return(e=e.map(e=>{return null==(e=e.match(/\$orderby=(.*)$/))?void 0:e[1]}).filter(e=>!!e).join(","))?"$orderby="+e:""}glue(e,t){return 1<e.length?`(${e.join(`) ${t} (`)})`:e[0]}quoteString(e){return"string"==typeof e?`'${this.escapeSingleQuote(e)}'`:e}skipEmptyObjects(e){return e.filter(e=>!this.isEmptyObject(e))}isEmptyObject(e){return 0===Object.keys(e).length}escapeSingleQuote(e){return"string"!=typeof e?e:e.replace(/\'/g,"''")}}var a=function(e,o,a,c){return new(a=a||Promise)(function(n,t){function i(e){try{s(c.next(e))}catch(e){t(e)}}function r(e){try{s(c.throw(e))}catch(e){t(e)}}function s(e){var t;e.done?n(e.value):((t=e.value)instanceof a?t:new a(function(e){e(t)})).then(i,r)}s((c=c.apply(e,o||[])).next())})};class Y extends t{constructor(){super(...arguments),this.baseUrl="event",this.listUrl="events",this.propertyName="events",this.channel="/events/*"}detail(e){const t=Object.create(null,{detail:{get:()=>super.detail}});return a(this,void 0,void 0,function*(){return t.detail.call(this,e)})}create(e){const t=Object.create(null,{create:{get:()=>super.create}});return a(this,void 0,void 0,function*(){return t.create.call(this,e)})}update(e){const t=Object.create(null,{update:{get:()=>super.update}});return a(this,void 0,void 0,function*(){return t.update.call(this,e)})}list(e={}){const t=Object.create(null,{list:{get:()=>super.list}});return a(this,void 0,void 0,function*(){return t.list.call(this,e)})}delete(e){const t=Object.create(null,{delete:{get:()=>super.delete}});return a(this,void 0,void 0,function*(){return t.delete.call(this,e)})}}var c=("object"==typeof self?self:window).FormData,K=function(e,o,a,c){return new(a=a||Promise)(function(n,t){function i(e){try{s(c.next(e))}catch(e){t(e)}}function r(e){try{s(c.throw(e))}catch(e){t(e)}}function s(e){var t;e.done?n(e.value):((t=e.value)instanceof a?t:new a(function(e){e(t)})).then(i,r)}s((c=c.apply(e,o||[])).next())})};class z extends t{constructor(){super(...arguments),this.baseUrl="event",this.listUrl="events"}upload(n,i){return K(this,void 0,void 0,function*(){var e=this.getDetailUrl(i),t=new c,e=(t.append("file",n),yield this.fetch(e,{method:"POST",body:t,headers:{accept:"application/json"}})),t=yield e.json();return{res:e,data:t}})}download(t){return K(this,void 0,void 0,function*(){var e=this.getDetailUrl(t);return yield this.fetch(e)})}delete(e){const t=Object.create(null,{delete:{get:()=>super.delete}});return K(this,void 0,void 0,function*(){return t.delete.call(this,e)})}getDetailUrl(e){let t;return t="object"==typeof e&&e.id?e.id:e,`${this.listUrl}/${t}/binaries`}}var u=function(e,o,a,c){return new(a=a||Promise)(function(n,t){function i(e){try{s(c.next(e))}catch(e){t(e)}}function r(e){try{s(c.throw(e))}catch(e){t(e)}}function s(e){var t;e.done?n(e.value):((t=e.value)instanceof a?t:new a(function(e){e(t)})).then(i,r)}s((c=c.apply(e,o||[])).next())})};class Z extends t{constructor(){super(...arguments),this.baseUrl="inventory",this.listUrl="binaries",this.propertyName="managedObjects"}create(o,a={}){return u(this,void 0,void 0,function*(){var e=this.listUrl,t=new c;let n,i;a.fileName&&(n=a.fileName,delete a.fileName),a.fileType&&(i=a.fileType,delete a.fileType),n=n||"bin","undefined"!=typeof File&&o instanceof File&&(n=o.name,i=o.type),a.name||(a.name=n),a.type||(a.type=i||"c8y_upload"),t.append("file",o,n),t.append("object",JSON.stringify(a));let r;"function"==typeof t.getHeaders&&(r=t.getHeaders());var s=Object.assign({accept:"application/json"},r),e=yield this.fetch(e,{method:"POST",body:t,headers:s}),t=yield e.json();return{res:e,data:t}})}list(e={}){const t=Object.create(null,{list:{get:()=>super.list}});return u(this,void 0,void 0,function*(){return t.list.call(this,e)})}delete(e){const t=Object.create(null,{delete:{get:()=>super.delete}});return u(this,void 0,void 0,function*(){return t.delete.call(this,e)})}download(t){return u(this,void 0,void 0,function*(){var e=this.getDetailUrl(t);return yield this.fetch(e)})}getIdFromUrl(e){var t;if(e)return t=new RegExp("\\/inventory\\/binaries\\/(\\d+)|\\/inventory\\/managedObjects\\/(\\d+)"),(e=e.match(t))&&(e[1]||e[2])}}var l=function(e,o,a,c){return new(a=a||Promise)(function(n,t){function i(e){try{s(c.next(e))}catch(e){t(e)}}function r(e){try{s(c.throw(e))}catch(e){t(e)}}function s(e){var t;e.done?n(e.value):((t=e.value)instanceof a?t:new a(function(e){e(t)})).then(i,r)}s((c=c.apply(e,o||[])).next())})};r.ChildType=void 0,(e=r.ChildType||(r.ChildType={})).ASSETS="childAssets",e.DEVICES="childDevices",e.ADDITIONS="childAdditions";class ee extends t{constructor(e,t){super(e,t),this.baseUrl="inventory",this.listUrl="managedObjects",this.propertyName="managedObjects",this.channel="/managedobjects/*",this.inventoriesQueryParamName="query",this.devicesQueryParamName="q",this.queriesUtil=new Q,this.binary=new Z(e)}detail(e,t={}){const n=Object.create(null,{detail:{get:()=>super.detail}});return l(this,void 0,void 0,function*(){return n.detail.call(this,e,t)})}create(e){const t=Object.create(null,{create:{get:()=>super.create}});return l(this,void 0,void 0,function*(){return t.create.call(this,e)})}update(e){const t=Object.create(null,{update:{get:()=>super.update}});return l(this,void 0,void 0,function*(){return t.update.call(this,e)})}list(e={}){const t=Object.create(null,{list:{get:()=>super.list}});return l(this,void 0,void 0,function*(){return t.list.call(this,e)})}listQuery(e,t={}){const n=Object.create(null,{list:{get:()=>super.list}});return l(this,void 0,void 0,function*(){return t[this.inventoriesQueryParamName]=this.queriesUtil.buildQuery(e),n.list.call(this,t)})}listQueryDevices(e,t={}){const n=Object.create(null,{list:{get:()=>super.list}});return l(this,void 0,void 0,function*(){return t[this.devicesQueryParamName]=this.queriesUtil.buildQuery(e),n.list.call(this,t)})}delete(e,t={}){const n=Object.create(null,{delete:{get:()=>super.delete}});return l(this,void 0,void 0,function*(){return n.delete.call(this,e,t)})}childAdditionsList(e,t={}){return l(this,void 0,void 0,function*(){return this.listChildren(r.ChildType.ADDITIONS,e,t)})}childAdditionsCreate(e,t){return l(this,void 0,void 0,function*(){return this.createChild(r.ChildType.ADDITIONS,e,t)})}childAdditionsAdd(e,t){return l(this,void 0,void 0,function*(){return this.addChild(r.ChildType.ADDITIONS,e,t)})}childAdditionsRemove(e,t){return l(this,void 0,void 0,function*(){return this.removeChild(r.ChildType.ADDITIONS,e,t)})}childAssetsList(e,t={}){return l(this,void 0,void 0,function*(){return this.listChildren(r.ChildType.ASSETS,e,t)})}childAssetsCreate(e,t){return l(this,void 0,void 0,function*(){return this.createChild(r.ChildType.ASSETS,e,t)})}childAssetsAdd(e,t){return l(this,void 0,void 0,function*(){return this.addChild(r.ChildType.ASSETS,e,t)})}childAssetsBulkAdd(e,t){return l(this,void 0,void 0,function*(){return this.addChildBulk(r.ChildType.ASSETS,e,t)})}childAssetsRemove(e,t){return l(this,void 0,void 0,function*(){return this.removeChild(r.ChildType.ASSETS,e,t)})}childDevicesList(e,t={}){return l(this,void 0,void 0,function*(){return this.listChildren(r.ChildType.DEVICES,e,t)})}childDevicesCreate(e,t){return l(this,void 0,void 0,function*(){return this.createChild(r.ChildType.DEVICES,e,t)})}childDevicesAdd(e,t){return l(this,void 0,void 0,function*(){return this.addChild(r.ChildType.DEVICES,e,t)})}childDevicesRemove(e,t){return l(this,void 0,void 0,function*(){return this.removeChild(r.ChildType.DEVICES,e,t)})}getSupportedMeasurements(e){return l(this,void 0,void 0,function*(){return this.getSupportedMeasurementDetails(e,"supportedMeasurements")})}getSupportedSeries(e){return l(this,void 0,void 0,function*(){return this.getSupportedMeasurementDetails(e,"supportedSeries")})}getMeasurementsAndSeries(i){return l(this,void 0,void 0,function*(){var[e,t]=yield Promise.all([this.getSupportedMeasurements(i),this.getSupportedSeries(i)]);const n=e.sort((e,t)=>t.length-e.length);return t.map(t=>{var e=n.find(e=>0===t.indexOf(e+"."));return{fragment:e,series:t.replace(e+".","")}}).filter(e=>!!e.fragment)})}assetKPIsList(e,t={}){return l(this,void 0,void 0,function*(){return this.listKPIs(e,t)})}listKPIs(n,i={}){return l(this,void 0,void 0,function*(){var e=this.getChildrenUrl("kpis",n),e=yield this.fetch(e,this.changeFetchOptions({headers:{accept:"application/json"},params:i},e)),t=yield e.json();return{res:e,data:t[this.propertyName],paging:this.getPaging(t,i)}})}onBeforeUpdate(e){return delete e.lastUpdated,e}onBeforeCreate(e){return delete e.id,delete e.lastUpdated,e}getChildrenUrl(e,t){return this.getDetailUrl(t)+"/"+e}getChildUrl(e,t,n){t=this.getIdString(t);return this.getChildrenUrl(e,n)+"/"+t}listChildren(i,r,s={}){return l(this,void 0,void 0,function*(){var e=this.getChildrenUrl(i,r),e=yield this.fetch(e,{headers:{"content-type":"application/json"},params:s}),t=yield e.json(),n=t.references.map(e=>e.managedObject),t=this.getPaging(t,s);return t.list=e=>this.listChildren(i,r,e),{res:e,data:n,paging:t}})}createChild(i,r,s){return l(this,void 0,void 0,function*(){var e=this.getChildrenUrl(i,s),t=JSON.stringify(this.onBeforeCreate(r)),n={"content-type":this.mimeType("managedObject"),accept:"application/json"},e=yield this.fetch(e,{method:"POST",body:t,headers:n}),t=yield e.json();return{res:e,data:t}})}addChild(i,r,s){return l(this,void 0,void 0,function*(){var e=this.getChildrenUrl(i,s),t=this.getIdString(r),t=JSON.stringify({managedObject:{id:String(t)}}),n={accept:"application/json","content-type":this.mimeType("managedObjectReference")},e=yield this.fetch(e,{method:"POST",body:t,headers:n}),t=yield e.json();return{res:e,data:t.managedObject}})}addChildBulk(i,r,s){return l(this,void 0,void 0,function*(){var e=this.getChildrenUrl(i,s),t=r.map(e=>({managedObject:{id:this.getIdString(e)}})),t=JSON.stringify({references:t}),n={accept:"application/json","content-type":this.mimeType("managedObjectReferenceCollection")},e=yield this.fetch(e,{method:"POST",body:t,headers:n}),t=(yield e.json()).references;return{res:e,data:t.map(e=>e.managedObject)}})}removeChild(t,n,i){return l(this,void 0,void 0,function*(){var e=this.getIdString(n),e=this.getChildrenUrl(t,i)+"/"+e;return{res:yield this.fetch(e,{method:"DELETE",headers:{accept:"application/json"}}),data:null}})}getSupportedMeasurementDetails(t,n="supportedSeries"){return l(this,void 0,void 0,function*(){var e=this.getDetailUrl(t)+"/"+n,e=(this.getIdString(t),yield(yield this.fetch(e,{headers:{accept:"application/json"}})).json());return e.c8y_SupportedMeasurements||e.c8y_SupportedSeries})}}var d=function(e,o,a,c){return new(a=a||Promise)(function(n,t){function i(e){try{s(c.next(e))}catch(e){t(e)}}function r(e){try{s(c.throw(e))}catch(e){t(e)}}function s(e){var t;e.done?n(e.value):((t=e.value)instanceof a?t:new a(function(e){e(t)})).then(i,r)}s((c=c.apply(e,o||[])).next())})};class te extends t{constructor(){super(...arguments),this.baseUrl="measurement",this.listUrl="measurements",this.propertyName="measurements",this.channel="/measurements/*"}detail(e){const t=Object.create(null,{detail:{get:()=>super.detail}});return d(this,void 0,void 0,function*(){return t.detail.call(this,e)})}create(e){const t=Object.create(null,{create:{get:()=>super.create}});return d(this,void 0,void 0,function*(){return t.create.call(this,this.onBeforeCreate(e))})}list(e={}){const t=Object.create(null,{list:{get:()=>super.list}});return d(this,void 0,void 0,function*(){return t.list.call(this,e)})}delete(e){const t=Object.create(null,{delete:{get:()=>super.delete}});return d(this,void 0,void 0,function*(){return t.delete.call(this,e)})}listSeries(n){return d(this,void 0,void 0,function*(){var e=`${this.baseUrl}/${this.listUrl}/series`,e=yield this.client.fetch(e,{params:n}),t=yield e.json();return{res:e,data:t}})}onBeforeCreate(e){var t;return e.time||(e.time=new Date),e.type||(e.type="c8y_Measurement"),e.sourceId&&(t=e["sourceId"],delete e.sourceId,e.source||(e.source={id:String(t)})),e}}r.aggregationType=void 0,(_=r.aggregationType||(r.aggregationType={})).MINUTELY="MINUTELY",_.HOURLY="HOURLY",_.DAILY="DAILY";var f=function(e,o,a,c){return new(a=a||Promise)(function(n,t){function i(e){try{s(c.next(e))}catch(e){t(e)}}function r(e){try{s(c.throw(e))}catch(e){t(e)}}function s(e){var t;e.done?n(e.value):((t=e.value)instanceof a?t:new a(function(e){e(t)})).then(i,r)}s((c=c.apply(e,o||[])).next())})};class ne extends t{constructor(){super(...arguments),this.baseUrl="alarm",this.listUrl="alarms",this.propertyName="alarms",this.channel="/alarms/*"}detail(e){const t=Object.create(null,{detail:{get:()=>super.detail}});return f(this,void 0,void 0,function*(){return t.detail.call(this,e)})}create(e){const t=Object.create(null,{create:{get:()=>super.create}});return f(this,void 0,void 0,function*(){return t.create.call(this,e)})}update(e){const t=Object.create(null,{update:{get:()=>super.update}});return f(this,void 0,void 0,function*(){return t.update.call(this,e)})}list(e={}){const t=Object.create(null,{list:{get:()=>super.list}});return f(this,void 0,void 0,function*(){return t.list.call(this,e)})}}r.AlarmStatus=void 0,(e=r.AlarmStatus||(r.AlarmStatus={}))[e.ACKNOWLEDGED="ACKNOWLEDGED"]="ACKNOWLEDGED",e[e.CLEARED="CLEARED"]="CLEARED",e[e.ACTIVE="ACTIVE"]="ACTIVE";var v=function(e,o,a,c){return new(a=a||Promise)(function(n,t){function i(e){try{s(c.next(e))}catch(e){t(e)}}function r(e){try{s(c.throw(e))}catch(e){t(e)}}function s(e){var t;e.done?n(e.value):((t=e.value)instanceof a?t:new a(function(e){e(t)})).then(i,r)}s((c=c.apply(e,o||[])).next())})};class ie extends t{constructor(){super(...arguments),this.baseUrl="devicecontrol",this.listUrl="operations",this.propertyName="operations"}detail(e){const t=Object.create(null,{detail:{get:()=>super.detail}});return v(this,void 0,void 0,function*(){return t.detail.call(this,e)})}create(e){const t=Object.create(null,{create:{get:()=>super.create}});return v(this,void 0,void 0,function*(){return t.create.call(this,e)})}update(e){const t=Object.create(null,{update:{get:()=>super.update}});return v(this,void 0,void 0,function*(){return t.update.call(this,e)})}list(e={}){const t=Object.create(null,{list:{get:()=>super.list}});return v(this,void 0,void 0,function*(){return t.list.call(this,e)})}}var g=function(e,o,a,c){return new(a=a||Promise)(function(n,t){function i(e){try{s(c.next(e))}catch(e){t(e)}}function r(e){try{s(c.throw(e))}catch(e){t(e)}}function s(e){var t;e.done?n(e.value):((t=e.value)instanceof a?t:new a(function(e){e(t)})).then(i,r)}s((c=c.apply(e,o||[])).next())})};class re extends t{constructor(){super(...arguments),this.baseUrl="devicecontrol",this.listUrl="bulkoperations",this.propertyName="bulkOperations"}detail(e){const t=Object.create(null,{detail:{get:()=>super.detail}});return g(this,void 0,void 0,function*(){return t.detail.call(this,e)})}create(e){const t=Object.create(null,{create:{get:()=>super.create}});return g(this,void 0,void 0,function*(){return t.create.call(this,e)})}update(e){const t=Object.create(null,{update:{get:()=>super.update}});return g(this,void 0,void 0,function*(){return t.update.call(this,e)})}list(e={}){const t=Object.create(null,{list:{get:()=>super.list}});return g(this,void 0,void 0,function*(){return t.list.call(this,e)})}delete(e){const t=Object.create(null,{delete:{get:()=>super.delete}});return g(this,void 0,void 0,function*(){return t.delete.call(this,e)})}}r.OperationBulkStatus=void 0,(_=r.OperationBulkStatus||(r.OperationBulkStatus={}))[_.ACTIVE="ACTIVE"]="ACTIVE",_[_.IN_PROGRESS="IN_PROGRESS"]="IN_PROGRESS",_[_.COMPLETED="COMPLETED"]="COMPLETED",_[_.DELETED="DELETED"]="DELETED",r.OperationBulkGeneralStatus=void 0,(e=r.OperationBulkGeneralStatus||(r.OperationBulkGeneralStatus={}))[e.SCHEDULED="SCHEDULED"]="SCHEDULED",e[e.EXECUTING="EXECUTING"]="EXECUTING",e[e.EXECUTING_WITH_ERROR="EXECUTING_WITH_ERROR"]="EXECUTING_WITH_ERROR",e[e.CANCELED="CANCELED"]="CANCELED",e[e.FAILED="FAILED"]="FAILED",e[e.SUCCESSFUL="SUCCESSFUL"]="SUCCESSFUL",e[e.DELETED="DELETED"]="DELETED",e[e.INCORRECT="INCORRECT"]="INCORRECT",r.OperationStatus=void 0,(_=r.OperationStatus||(r.OperationStatus={}))[_.PENDING="PENDING"]="PENDING",_[_.EXECUTING="EXECUTING"]="EXECUTING",_[_.SUCCESSFUL="SUCCESSFUL"]="SUCCESSFUL",_[_.FAILED="FAILED"]="FAILED";var y=function(e,o,a,c){return new(a=a||Promise)(function(n,t){function i(e){try{s(c.next(e))}catch(e){t(e)}}function r(e){try{s(c.throw(e))}catch(e){t(e)}}function s(e){var t;e.done?n(e.value):((t=e.value)instanceof a?t:new a(function(e){e(t)})).then(i,r)}s((c=c.apply(e,o||[])).next())})};class m extends t{constructor(){super(...arguments),this.baseUrl="tenant",this.listUrl="tenants",this.currentTenantUrl="currentTenant",this.propertyName="tenants",this.fetchOptions={method:"PUT",body:"{}",headers:{"content-type":"application/json",accept:"application/json"}}}detail(e){const t=Object.create(null,{detail:{get:()=>super.detail}});return y(this,void 0,void 0,function*(){return t.detail.call(this,e)})}create(e){const t=Object.create(null,{create:{get:()=>super.create}});return y(this,void 0,void 0,function*(){return t.create.call(this,e)})}update(e){const t=Object.create(null,{update:{get:()=>super.update}});return y(this,void 0,void 0,function*(){return t.update.call(this,e)})}list(e={}){const t=Object.create(null,{list:{get:()=>super.list}});return y(this,void 0,void 0,function*(){return t.list.call(this,e)})}delete(e){const t=Object.create(null,{delete:{get:()=>super.delete}});return y(this,void 0,void 0,function*(){return t.delete.call(this,e)})}current(){return y(this,void 0,void 0,function*(){var e=yield this.fetch(this.currentTenantUrl,{headers:{"content-type":"application/json"}}),t=yield e.json();return{res:e,data:t}})}enableSupportUser(){return y(this,void 0,void 0,function*(){return{res:yield this.fetch("support-user/enable",this.fetchOptions),data:null}})}disableSupportUser(){return y(this,void 0,void 0,function*(){return{res:yield this.fetch("support-user/disable",this.fetchOptions),data:null}})}currentTenantType(){return y(this,void 0,void 0,function*(){var e=yield this.current();return e.data.customProperties&&"TRIAL"===e.data.customProperties.tenantType?"TRIAL":"REGULAR"})}getTfaSettings(t){return y(this,void 0,void 0,function*(){var e=this.getIdString(t);return yield(yield this.fetch(`tenants/${e}/tfa`)).json()})}subscribeApplication(i,r){return y(this,void 0,void 0,function*(){var e=this.getIdString(i),t=r.id,e=`tenants/${e}/applications`,t=JSON.stringify({application:{id:t,self:r.self}}),n={"content-type":this.mimeType("applicationReference")};return{res:yield this.fetch(e,this.changeFetchOptions({method:"POST",body:t,headers:n},e)),data:null}})}unsubscribeApplication(t,n){return y(this,void 0,void 0,function*(){var e=`tenants/${this.getIdString(t)}/applications/`+n.id;return{res:yield this.fetch(e,this.changeFetchOptions({method:"DELETE"},e)),data:null}})}getIdString(e){return e.id||e.name}onBeforeCreate(e){return e}}r.TenantStatus=void 0,(e=r.TenantStatus||(r.TenantStatus={}))[e.ACTIVE="ACTIVE"]="ACTIVE",e[e.SUSPENDED="SUSPENDED"]="SUSPENDED",r.TfaStrategy=void 0,(_=r.TfaStrategy||(r.TfaStrategy={})).TOTP="TOTP",_.SMS="SMS";var b=function(e,o,a,c){return new(a=a||Promise)(function(n,t){function i(e){try{s(c.next(e))}catch(e){t(e)}}function r(e){try{s(c.throw(e))}catch(e){t(e)}}function s(e){var t;e.done?n(e.value):((t=e.value)instanceof a?t:new a(function(e){e(t)})).then(i,r)}s((c=c.apply(e,o||[])).next())})};class se extends t{constructor(e,t){super(t),this.listUrl="inventory",this.currenUserUrl="currentUser",this.propertyName="inventoryAssignments",this.baseUrl=`user/${e}/roles`}detail(e){const t=Object.create(null,{detail:{get:()=>super.detail}});return b(this,void 0,void 0,function*(){return t.detail.call(this,e)})}create(e){const t=Object.create(null,{create:{get:()=>super.create}});return b(this,void 0,void 0,function*(){return t.create.call(this,e)})}update(e){const t=Object.create(null,{update:{get:()=>super.update}});return b(this,void 0,void 0,function*(){return t.update.call(this,e)})}list(e={}){const t=Object.create(null,{list:{get:()=>super.list}});return b(this,void 0,void 0,function*(){return t.list.call(this,e)})}delete(e){const t=Object.create(null,{delete:{get:()=>super.delete}});return b(this,void 0,void 0,function*(){return t.delete.call(this,e)})}}var T=function(e,o,a,c){return new(a=a||Promise)(function(n,t){function i(e){try{s(c.next(e))}catch(e){t(e)}}function r(e){try{s(c.throw(e))}catch(e){t(e)}}function s(e){var t;e.done?n(e.value):((t=e.value)instanceof a?t:new a(function(e){e(t)})).then(i,r)}s((c=c.apply(e,o||[])).next())})};class oe extends t{constructor(){super(...arguments),this.baseUrl="user",this.currentUserUrl="currentUser",this.passwordResetUrl="passwordReset",this.currentUserPhoneUrl="currentUserPhone",this.verifyTFACodeUrl="pin",this.totpCurrentUserURL=this.currentUserUrl+"/totpSecret",this.verifyTOTPCodeUrl=this.totpCurrentUserURL+"/verify",this.activateTOTPCodeUrl=this.totpCurrentUserURL+"/activity",this.revokeTOTPSecretUrl="totpSecret/revoke",this.propertyName="users"}get listUrl(){return this.client.tenant+"/users"}get newsletterEmailsUrl(){return this.client.tenant+"/users/newsletterEmails"}get currentUserPasswordUrl(){return this.currentUserUrl+"/password"}get revokeAllTokensUrl(){return`/logout/${this.client.tenant}/allUsers`}detail(e){const t=Object.create(null,{detail:{get:()=>super.detail}});return T(this,void 0,void 0,function*(){return t.detail.call(this,e)})}create(e){const t=Object.create(null,{create:{get:()=>super.create}});return T(this,void 0,void 0,function*(){return t.create.call(this,e)})}update(e){const t=Object.create(null,{update:{get:()=>super.update}});return T(this,void 0,void 0,function*(){return t.update.call(this,e)})}list(e={}){const t=Object.create(null,{list:{get:()=>super.list}});return T(this,void 0,void 0,function*(){return t.list.call(this,e)})}delete(e){const t=Object.create(null,{delete:{get:()=>super.delete}});return T(this,void 0,void 0,function*(){return t.delete.call(this,e)})}inventoryAssignment(e){return new se(this.getDetailUrl(e),this.client)}current(){return T(this,void 0,void 0,function*(){var e=yield this.fetch(this.currentUserUrl,{headers:{"content-type":"application/json",Accept:"application/vnd.com.nsn.cumulocity.user+json;"}}),t=yield e.json();return{res:e,data:t}})}currentWithEffectiveRoles(){return T(this,void 0,void 0,function*(){var e=yield this.fetch(this.currentUserUrl,{headers:{"content-type":"application/json",Accept:"application/vnd.com.nsn.cumulocity.currentUser+json;"}}),t=yield e.json();return{res:e,data:t}})}updateCurrent(n){return T(this,void 0,void 0,function*(){var e="application/vnd.com.nsn.cumulocity.user+json",e={"content-type":e,Accept:e},t=JSON.stringify(this.onBeforeUpdate(n)),e=yield this.fetch(this.currentUserUrl,{headers:e,body:t,method:"PUT"}),t=yield e.json();return{res:e,data:t}})}sendPasswordResetMail(i,r){return T(this,void 0,void 0,function*(){var e=this.passwordResetUrl,t=r?{tenantId:r}:{},n=JSON.stringify({email:i});return{res:yield this.fetch(e,{headers:{"content-type":"application/json",accept:"application/json"},method:"POST",params:t,body:n}),data:null}})}resetPassword(i,r){return T(this,void 0,void 0,function*(){var e=this.passwordResetUrl,t=r?{tenantId:r}:{},n=JSON.stringify(i);return{res:yield this.fetch(e,{headers:{"content-type":"application/json",accept:"application/json"},method:"PUT",params:t,body:n}),data:null}})}verifyTFACode(t){return T(this,void 0,void 0,function*(){var e=JSON.stringify({pin:t});return{res:yield this.fetch(this.verifyTFACodeUrl,{headers:{"content-type":"application/json",accept:"application/json"},body:e,method:"POST"}),data:null}})}verifyTotpCode(t){return T(this,void 0,void 0,function*(){var e=JSON.stringify({code:t});return{res:yield this.fetch(this.verifyTOTPCodeUrl,{headers:{"content-type":"application/json"},body:e,method:"POST"}),data:null}})}activateTotp(){return T(this,void 0,void 0,function*(){var e=JSON.stringify({isActive:!0});return{res:yield this.fetch(this.activateTOTPCodeUrl,{headers:{"content-type":"application/json"},body:e,method:"POST"}),data:null}})}getActivityTotp(){return T(this,void 0,void 0,function*(){var e=yield this.fetch(this.activateTOTPCodeUrl,{headers:{"content-type":"application/json"},method:"GET"}),t=yield e.json();return{res:e,data:t}})}generateTotpSecret(){return T(this,void 0,void 0,function*(){var e=yield this.fetch(this.totpCurrentUserURL,{headers:{"content-type":"application/json",accept:"application/json"},method:"POST"}),t=yield e.json();return{res:e,data:t}})}totpRevokeSecret(t){return T(this,void 0,void 0,function*(){var e=this.getDetailUrl(t)+"/"+this.revokeTOTPSecretUrl;return{res:yield this.fetch(e,{headers:{accept:"application/json"},method:"DELETE"}),data:null}})}savePhoneNumber(n){return T(this,void 0,void 0,function*(){var e=this.currentUserPhoneUrl,t={method:"PUT",headers:{"content-type":"application/json",accept:"application/json"},body:JSON.stringify({phone:n})},e=yield this.fetch(e,t),t=yield e.json();return{res:e,data:t}})}getNewsletterEmails(){return T(this,void 0,void 0,function*(){var e=this.newsletterEmailsUrl,e=yield this.fetch(e,{method:"GET",headers:{accept:"text/plain"}}),t=yield e.text();return{res:e,data:t}})}changeUserPassword(t,n,i){return T(this,void 0,void 0,function*(){var e=JSON.stringify({newPassword:n,currentUserPassword:i});return{res:yield this.fetch(this.changeUserPasswordUrl(t),{headers:{"content-type":"application/json"},body:e,method:"PUT"}),data:null}})}changeCurrentUserPassword(t,n){return T(this,void 0,void 0,function*(){var e=JSON.stringify({newPassword:t,currentUserPassword:n});return{res:yield this.fetch(this.currentUserPasswordUrl,{headers:{"content-type":"application/json"},body:e,method:"PUT"}),data:null}})}revokeTokens(){return T(this,void 0,void 0,function*(){return{res:yield this.fetch(this.revokeAllTokensUrl,{headers:{"content-type":"application/json"},method:"POST"}),data:null}})}hasRole(e,t){return this.hasRoleInUser(e,t)||this.hasRoleInGroups(e,t)}hasAllRoles(t,e){return e.every(e=>this.hasRole(t,e))}hasAnyRole(t,e){return e.some(e=>this.hasRole(t,e))}hasAnyGlobalRole(t,e){return e.some(e=>this.hasGlobalRoleInUser(t,e))}isDeviceUser(e){return e.id.match(/^device_/)}onBeforeUpdate(e){e=Object.assign({},e);return delete e.id,delete e.userName,e}getDetailUrl(e){return this.listUrl+"/"+encodeURIComponent(this.getId(e))}getId(e){let t;return t="object"==typeof e&&e.id?e.id:"object"==typeof e&&e.userName?e.userName:e,String(t)}hasRoleInUser(e,t){var n=e.effectiveRoles||[];return this.hasRoleInReferences(e&&e.roles&&e.roles.references||[],t)||n.some(({id:e})=>t===e)}hasRoleInGroups(e,t){return(e&&e.groups&&e.groups.references||[]).some(e=>this.hasRoleInReferences(e.group.roles.references,t))}hasRoleInReferences(e,t){return e.some(e=>e.role.id===t)}changeUserPasswordUrl(e){return`${this.client.tenant}/users/${this.getId(e)}/password`}hasGlobalRoleInUser(e,t){return((null==(e=null==e?void 0:e.groups)?void 0:e.references)||[]).map(e=>{return null==(e=null==e?void 0:e.group)?void 0:e.id}).some(e=>e===t)}}r.PasswordStrength=void 0,(e=r.PasswordStrength||(r.PasswordStrength={})).GREEN="GREEN",e.RED="RED",e.YELLOW="YELLOW";var O=function(e,o,a,c){return new(a=a||Promise)(function(n,t){function i(e){try{s(c.next(e))}catch(e){t(e)}}function r(e){try{s(c.throw(e))}catch(e){t(e)}}function s(e){var t;e.done?n(e.value):((t=e.value)instanceof a?t:new a(function(e){e(t)})).then(i,r)}s((c=c.apply(e,o||[])).next())})};class ae extends t{constructor(e,t){super(e),this.listUrl="binaries",this.propertyName="attachments",this.baseUrl="application/applications/"+this.getIdString(t)}upload(r,s,o){return O(this,void 0,void 0,function*(){var e=(null==o?void 0:o.listUrl)||this.listUrl,t=this.createBinaryRequestBody(r,s,o);let n;"function"==typeof t.getHeaders&&(n=t.getHeaders());var i=Object.assign((null==o?void 0:o.headers)||{Accept:"application/json"},n),e=yield this.fetch(e,{method:"POST",body:t,headers:i}),t=yield e.json();return{res:e,data:t}})}uploadWithProgressXhr(e,t,n,i){var r=`/${this.baseUrl}/`+((null==i?void 0:i.listUrl)||this.listUrl),e=this.createBinaryRequestBody(e,n,i);let s;"function"==typeof e.getHeaders&&(s=e.getHeaders());var o=this.client.getFetchOptions().headers,a=(Object.assign(o,(null==i?void 0:i.headers)||{Accept:"application/json"}),Object.assign(o,s),new XMLHttpRequest);a.open("POST",r,!0);for(const c in o)o.hasOwnProperty(c)&&a.setRequestHeader(c,o[c]);return a.upload.addEventListener("progress",t),a.send(e),a}getXMLHttpResponse(n){return new Promise((e,t)=>{n.addEventListener("loadend",()=>{4!==n.readyState||200!==n.status&&201!==n.status?t(n.responseText?{data:JSON.parse(n.responseText)}:"Could not upload file."):e(JSON.parse(n.responseText))})})}list(e){const t=Object.create(null,{list:{get:()=>super.list}});return O(this,void 0,void 0,function*(){return t.list.call(this,e)})}delete(e){const t=Object.create(null,{delete:{get:()=>super.delete}});return O(this,void 0,void 0,function*(){return t.delete.call(this,e)})}listPlugins(){return O(this,void 0,void 0,function*(){var e=this.listUrl+"/plugins",e=yield this.fetch(e,{headers:{accept:"application/json"}}),t=yield e.json();return{res:e,data:t}})}addPlugin(r,s){return O(this,void 0,void 0,function*(){var e=this.listUrl+"/plugins/"+encodeURIComponent(r),t=new c,n=s instanceof ArrayBuffer?Buffer.from(s):s;t.append("file",n);let i;"function"==typeof t.getHeaders&&(i=t.getHeaders());n=Object.assign({accept:"application/json"},i),e=yield this.fetch(e,{method:"POST",body:t,headers:n}),t=yield e.json();return{res:e,data:t}})}removePlugin(n){return O(this,void 0,void 0,function*(){var e=this.listUrl+"/plugins/"+n,e=yield this.fetch(e,{method:"DELETE",headers:{accept:"application/json"}}),t=yield e.json();return{res:e,data:t}})}updateFiles(r){return O(this,void 0,void 0,function*(){var e=this.listUrl+"/files";const n=new c;r.forEach(e=>{var t=e.contents instanceof ArrayBuffer?Buffer.from(e.contents):e.contents;n.append(e.path,t)});let t;"function"==typeof n.getHeaders&&(t=n.getHeaders());var i=Object.assign({accept:"application/json"},t),e=yield this.fetch(e,{method:"POST",body:n,headers:i}),i=yield e.json();return{res:e,data:i}})}downloadArchive(t){return O(this,void 0,void 0,function*(){var e=this.listUrl+"/"+t;return yield this.fetch(e)})}createBinaryRequestBody(e,t,n){var i=new c,r=e instanceof ArrayBuffer?Buffer.from(e):e;let s=t;if("undefined"!=typeof File&&e instanceof File&&(s=e.name),i.append((null==n?void 0:n.bodyFileProperty)||"file",r,s),i.append("fileName",s),null!=n&&n.requestBody)for(const o in n.requestBody)n.requestBody.hasOwnProperty(o)&&i.append(o,JSON.stringify(n.requestBody[o]));return i}}r.ApplicationType=void 0,(_=r.ApplicationType||(r.ApplicationType={})).EXTERNAL="EXTERNAL",_.HOSTED="HOSTED",_.MICROSERVICE="MICROSERVICE",_.FEATURE="FEATURE",_.REPOSITORY="REPOSITORY";var S=function(e,o,a,c){return new(a=a||Promise)(function(n,t){function i(e){try{s(c.next(e))}catch(e){t(e)}}function r(e){try{s(c.throw(e))}catch(e){t(e)}}function s(e){var t;e.done?n(e.value):((t=e.value)instanceof a?t:new a(function(e){e(t)})).then(i,r)}s((c=c.apply(e,o||[])).next())})};class w extends t{constructor(){super(...arguments),this.baseUrl="application",this.listUrl="applications",this.propertyName="applications",this.channel="/applications/*"}create(e){const t=Object.create(null,{create:{get:()=>super.create}});return S(this,void 0,void 0,function*(){return t.create.call(this,e)})}clone(n){return S(this,void 0,void 0,function*(){var e=this.getDetailUrl(n)+"/clone",e=yield this.fetch(e,{method:"POST",body:"",headers:{"content-type":"application/json",accept:"application/json"}}),t=yield e.json();return{res:e,data:t}})}list(e={}){const t=Object.create(null,{list:{get:()=>super.list}});return S(this,void 0,void 0,function*(){return t.list.call(this,e)})}listVersions(i,r={}){var s;return S(this,void 0,void 0,function*(){var t=this.getEntityId(i),t=this.listUrl+`/${t}/versions`;try{var n=yield this.fetch(t,{headers:{"content-type":"application/json"},params:r}),e=null==(s=yield n.json())?void 0:s.applicationVersions;return{res:n,data:e}}catch(e){if(404===e.res.status)return{data:t,res:n}=yield this.detail(i),{res:n,data:t.applicationVersions};throw e}})}detail(e){const t=Object.create(null,{detail:{get:()=>super.detail}});return S(this,void 0,void 0,function*(){return t.detail.call(this,e)})}update(e){const t=Object.create(null,{update:{get:()=>super.update}});return S(this,void 0,void 0,function*(){return t.update.call(this,e)})}delete(e){const t=Object.create(null,{delete:{get:()=>super.delete}});return S(this,void 0,void 0,function*(){return t.delete.call(this,e)})}listByName(n){return S(this,void 0,void 0,function*(){var e="applicationsByName/"+encodeURIComponent(n),e=yield this.fetch(e,{headers:{"content-type":"application/json"}}),t=yield e.json();return{res:e,data:t[this.propertyName]}})}listByTenant(n,i={}){return S(this,void 0,void 0,function*(){var e=new m(this.client),e=this.getIdString(n||(yield e.current()).data.name),e="applicationsByTenant/"+encodeURIComponent(e),e=yield this.fetch(e,{headers:{"content-type":"application/json"},params:i}),t=yield e.json();return{res:e,data:t[this.propertyName]}})}listByOwner(n,i={}){return S(this,void 0,void 0,function*(){var e=new m(this.client),e=this.getIdString(n||(yield e.current()).data.name),e="applicationsByOwner/"+encodeURIComponent(e),e=yield this.fetch(e,{headers:{"content-type":"application/json"},params:i}),t=yield e.json();return{res:e,data:t[this.propertyName]}})}listByUser(n,i={}){return S(this,void 0,void 0,function*(){var e=new oe(this.client),e=this.getIdString(n||(yield e.current()).data),e="applicationsByUser/"+encodeURIComponent(e),e=yield this.fetch(e,{headers:{"content-type":"application/json"},params:i}),t=yield e.json();return{res:e,data:t[this.propertyName]}})}reactivateArchive(t){return S(this,void 0,void 0,function*(){var e=this.listUrl+`/${t}/refresh`;return{res:yield this.fetch(e,{method:"POST",body:"",headers:{"content-type":"application/json",accept:"application/json"}}),data:null}})}binary(e){return new ae(this.client,e)}getHref(e){return e.type===r.ApplicationType.EXTERNAL?e.externalUrl:"/apps/"+(e.public?"public/":"")+e.contextPath}isAvailable(n){return S(this,void 0,void 0,function*(){var{res:e,data:t}=yield this.listByUser(void 0,{dropOverwrittenApps:!0,noPaging:!0});return{data:(t||[]).some(e=>"string"==typeof n?e.name===n||e.contextPath===n:this.isMatch(e,n)),res:e}})}getStatusDetails(t){return S(this,void 0,void 0,function*(){var e=this.getEntityId(t);return new ee(this.client,this.realtime).list({type:"c8y_Application_"+e})})}getInstanceNames(e){let t=new Array;return t=e&&e.c8y_Status&&e.c8y_Status.instances?Object.keys(e.c8y_Status.instances):t}getInstanceLog(n,i,r){return S(this,void 0,void 0,function*(){var e=this.getDetailUrl(n)+"/logs/"+i,t={accept:this.mimeType("applicationLogs")},e=yield this.fetch(e,{headers:t,params:r}),t=yield e.json();return{res:e,data:t}})}updateApplicationConfig(n,i){var r;return S(this,void 0,void 0,function*(){var e=this.getEntityId(n),t=(yield this.detail(e))["data"],t=(null==t?void 0:t.config)||{},t=Object.assign(Object.assign({},t),i),e=yield this.update({id:e,config:t});return null==(r=yield e)?void 0:r.data})}getAppManifest(n,i){return S(this,void 0,void 0,function*(){var e=new Date;let t;if(400<=(t=i?yield this.client.fetch(`/apps/${n.contextPath}@${i}/cumulocity.json?nocache=`+e.getTime()):yield this.client.fetch(`/apps/${n.contextPath}/cumulocity.json?nocache=`+e.getTime())).status)throw new Error("No Cumulocity IoT manifest found.");return yield t.json()})}storeAppManifest(e,t){return S(this,void 0,void 0,function*(){return yield this.binary(e).updateFiles([{path:"cumulocity.json",contents:JSON.stringify(t)}])})}setPackageVersionTag(n,i,r){return S(this,void 0,void 0,function*(){var e=this.getDetailUrl(n)+"/versions/"+i,t=JSON.stringify({tags:r}),e=yield this.fetch(e,{method:"PUT",body:t,headers:{accept:"application/vnd.com.nsn.cumulocity.applicationVersion+json;charset=UTF-8;ver=0.9","content-type":"application/json"}}),t=yield e.json();return{res:e,data:t}})}getManifestOfContextPath(n){return S(this,void 0,void 0,function*(){var e=this.getDetailUrl(n)+"/manifest",e=yield this.fetch(e),t=(yield e.json())["application"];return{res:e,data:t}})}deleteVersionPackage(t,n){return S(this,void 0,void 0,function*(){var e=this.getDetailUrl(t)+"/versions/";return{res:yield this.fetch(e,this.changeFetchOptions({method:"DELETE",params:n},e)),data:null}})}updateApplicationAvailability(t,n){return S(this,void 0,void 0,function*(){var e=this.getEntityId(t);return yield this.update({id:e,availability:n})})}isMatch(n,e){return Object.keys(e).every(t=>Array.isArray(n[t])&&Array.isArray(e[t])?e[t].every(e=>n[t].includes(e)):"object"==typeof n[t]&&null!==n[t]&&"object"==typeof e[t]&&null!==e[t]?this.isMatch(n[t],e[t]):n[t]===e[t])}}r.InstanceStatus=void 0,(e=r.InstanceStatus||(r.InstanceStatus={})).Up="Up",e.Unhealthy="Unhealthy",e.Down="Down",e.Unknown="Unknown",r.BillingMode=void 0,(_=r.BillingMode||(r.BillingMode={})).SUBSCRIPTION="SUBSCRIPTION",_.RESOURCES="RESOURCES",r.Isolation=void 0,(e=r.Isolation||(r.Isolation={})).PER_TENANT="PER_TENANT",e.MULTI_TENANT="MULTI_TENANT",r.ApplicationAvailability=void 0,(_=r.ApplicationAvailability||(r.ApplicationAvailability={}))[_.MARKET="MARKET"]="MARKET",_[_.PRIVATE="PRIVATE"]="PRIVATE",_[_.SHARED="SHARED"]="SHARED";var ce=function(e,o,a,c){return new(a=a||Promise)(function(n,t){function i(e){try{s(c.next(e))}catch(e){t(e)}}function r(e){try{s(c.throw(e))}catch(e){t(e)}}function s(e){var t;e.done?n(e.value):((t=e.value)instanceof a?t:new a(function(e){e(t)})).then(i,r)}s((c=c.apply(e,o||[])).next())})};class ue extends t{constructor(){super(...arguments),this.baseUrl="tenant/system",this.listUrl="options",this.propertyName="options"}detail(e){const t=Object.create(null,{detail:{get:()=>super.detail}});return ce(this,void 0,void 0,function*(){return t.detail.call(this,e)})}list(n={}){return ce(this,void 0,void 0,function*(){var e=this.listUrl,e=yield this.fetch(e,{headers:{"content-type":"application/json"},params:n}),t=yield e.json();return{res:e,data:t[this.propertyName]}})}getDetailUrl(e){return`${this.listUrl}/${e.category}/`+e.key}onBeforeCreate(e){return e}}var E=function(e,o,a,c){return new(a=a||Promise)(function(n,t){function i(e){try{s(c.next(e))}catch(e){t(e)}}function r(e){try{s(c.throw(e))}catch(e){t(e)}}function s(e){var t;e.done?n(e.value):((t=e.value)instanceof a?t:new a(function(e){e(t)})).then(i,r)}s((c=c.apply(e,o||[])).next())})};class le extends t{constructor(){super(...arguments),this.baseUrl="tenant",this.listUrl="options",this.propertyName="options",this.securityOptionsCategories=["password"],this.securityOptionsListUrl="security-options",this.systemOptions="system"}detail(e,t={}){const n=Object.create(null,{detail:{get:()=>super.detail}});return E(this,void 0,void 0,function*(){return n.detail.call(this,e,t)})}create(e){const t=Object.create(null,{create:{get:()=>super.create}});return E(this,void 0,void 0,function*(){return t.create.call(this,e)})}update(e){const t=Object.create(null,{update:{get:()=>super.update}});return E(this,void 0,void 0,function*(){return t.update.call(this,e)})}list(e={}){const t=Object.create(null,{list:{get:()=>super.list}});return E(this,void 0,void 0,function*(){return t.list.call(this,e)})}delete(e){const t=Object.create(null,{delete:{get:()=>super.delete}});return E(this,void 0,void 0,function*(){return t.delete.call(this,e)})}getDetailUrl(e){var t=encodeURIComponent(e.category),n=encodeURIComponent(e.key);return-1<this.securityOptionsCategories.indexOf(e.category)?this.securityOptionsListUrl+`/${t}/`+n:this.listUrl+`/${t}/`+n}onBeforeCreate(e){return e}}var de=function(e,o,a,c){return new(a=a||Promise)(function(n,t){function i(e){try{s(c.next(e))}catch(e){t(e)}}function r(e){try{s(c.throw(e))}catch(e){t(e)}}function s(e){var t;e.done?n(e.value):((t=e.value)instanceof a?t:new a(function(e){e(t)})).then(i,r)}s((c=c.apply(e,o||[])).next())})};class he extends t{constructor(){super(...arguments),this.baseUrl="tenant",this.listUrl="security-options",this.category="password",this.propertyName="options"}detail(e){const t=Object.create(null,{detail:{get:()=>super.detail}});return de(this,void 0,void 0,function*(){return t.detail.call(this,e)})}getDetailUrl(e){return`${this.listUrl}/${this.category}/`+e.key}onBeforeCreate(e){return e}}var U=function(e,o,a,c){return new(a=a||Promise)(function(n,t){function i(e){try{s(c.next(e))}catch(e){t(e)}}function r(e){try{s(c.throw(e))}catch(e){t(e)}}function s(e){var t;e.done?n(e.value):((t=e.value)instanceof a?t:new a(function(e){e(t)})).then(i,r)}s((c=c.apply(e,o||[])).next())})};class pe extends t{constructor(){super(...arguments),this.baseUrl="tenant",this.listUrl="loginOptions",this.propertyName="loginOptions"}detail(e){const t=Object.create(null,{detail:{get:()=>super.detail}});return U(this,void 0,void 0,function*(){return t.detail.call(this,e)})}list(e={}){const t=Object.create(null,{list:{get:()=>super.list}});return U(this,void 0,void 0,function*(){return t.list.call(this,e)})}listForCurrentTenant(){const e=Object.create(null,{list:{get:()=>super.list}});return U(this,void 0,void 0,function*(){return e.list.call(this,{tenantId:this.client.tenant})})}listForManagement(){const e=Object.create(null,{list:{get:()=>super.list}});return U(this,void 0,void 0,function*(){return e.list.call(this,{management:!0})})}create(e){const t=Object.create(null,{create:{get:()=>super.create}});return U(this,void 0,void 0,function*(){return t.create.call(this,e)})}update(e){const t=Object.create(null,{update:{get:()=>super.update}});return U(this,void 0,void 0,function*(){return t.update.call(this,e)})}save(e){return U(this,void 0,void 0,function*(){return e.id?this.update(e):this.create(e)})}delete(e){const t=Object.create(null,{delete:{get:()=>super.delete}});return U(this,void 0,void 0,function*(){return t.delete.call(this,e)})}}r.TenantLoginOptionType=void 0,(e=r.TenantLoginOptionType||(r.TenantLoginOptionType={})).OAUTH2_INTERNAL="OAUTH2_INTERNAL",e.OAUTH2="OAUTH2",e.BASIC="BASIC",r.GrantType=void 0,(_=r.GrantType||(r.GrantType={})).AUTHORIZATION_CODE="AUTHORIZATION_CODE",_.PASSWORD="PASSWORD",r.UserManagementSource=void 0,(e=r.UserManagementSource||(r.UserManagementSource={})).REMOTE="REMOTE",e.INTERNAL="INTERNAL";var fe=function(e,o,a,c){return new(a=a||Promise)(function(n,t){function i(e){try{s(c.next(e))}catch(e){t(e)}}function r(e){try{s(c.throw(e))}catch(e){t(e)}}function s(e){var t;e.done?n(e.value):((t=e.value)instanceof a?t:new a(function(e){e(t)})).then(i,r)}s((c=c.apply(e,o||[])).next())})};class ve extends t{constructor(){super(...arguments),this.baseUrl="audit",this.listUrl="auditRecords",this.propertyName="auditRecords"}detail(e){const t=Object.create(null,{detail:{get:()=>super.detail}});return fe(this,void 0,void 0,function*(){return t.detail.call(this,e)})}create(e){const t=Object.create(null,{create:{get:()=>super.create}});return fe(this,void 0,void 0,function*(){return t.create.call(this,e)})}list(e={}){const t=Object.create(null,{list:{get:()=>super.list}});return fe(this,void 0,void 0,function*(){return t.list.call(this,e)})}}r.AuditRecordType=void 0,(_=r.AuditRecordType||(r.AuditRecordType={})).ALARM="Alarm",_.BULK_OPERATION="BulkOperation",_.CEP_MODULE="CepModule",_.EVENT="Event",_.INVENTORY="Inventory",_.INVENTORY_ROLE="InventoryRole",_.OPERATION="Operation",_.OPTION="Option",_.GROUP="Group",_.SMART_RULE="SmartRule",_.SYSTEM="SYSTEM",_.TENANT="Tenant",_.USER="User",r.ChangeType=void 0,(e=r.ChangeType||(r.ChangeType={}))[e.ADDED="ADDED"]="ADDED",e[e.REPLACED="REPLACED"]="REPLACED",e[e.REMOVED="REMOVED"]="REMOVED";var C=function(e,o,a,c){return new(a=a||Promise)(function(n,t){function i(e){try{s(c.next(e))}catch(e){t(e)}}function r(e){try{s(c.throw(e))}catch(e){t(e)}}function s(e){var t;e.done?n(e.value):((t=e.value)instanceof a?t:new a(function(e){e(t)})).then(i,r)}s((c=c.apply(e,o||[])).next())})};class ge extends t{constructor(){super(...arguments),this.baseUrl="user",this.listUrl="inventoryroles",this.propertyName="roles"}detail(e){const t=Object.create(null,{detail:{get:()=>super.detail}});return C(this,void 0,void 0,function*(){return t.detail.call(this,e)})}create(e){const t=Object.create(null,{create:{get:()=>super.create}});return C(this,void 0,void 0,function*(){return t.create.call(this,e)})}update(e){const t=Object.create(null,{update:{get:()=>super.update}});return C(this,void 0,void 0,function*(){return t.update.call(this,e)})}list(e={}){const t=Object.create(null,{list:{get:()=>super.list}});return C(this,void 0,void 0,function*(){return t.list.call(this,e)})}delete(e){const t=Object.create(null,{delete:{get:()=>super.delete}});return C(this,void 0,void 0,function*(){return t.delete.call(this,e)})}}r.DeviceRegistrationStatus=void 0,(_=r.DeviceRegistrationStatus||(r.DeviceRegistrationStatus={}))[_.WAITING_FOR_CONNECTION="WAITING_FOR_CONNECTION"]="WAITING_FOR_CONNECTION",_[_.PENDING_ACCEPTANCE="PENDING_ACCEPTANCE"]="PENDING_ACCEPTANCE",_[_.ACCEPTED="ACCEPTED"]="ACCEPTED",_[_.BLOCKED="BLOCKED"]="BLOCKED";var R=function(e,o,a,c){return new(a=a||Promise)(function(n,t){function i(e){try{s(c.next(e))}catch(e){t(e)}}function r(e){try{s(c.throw(e))}catch(e){t(e)}}function s(e){var t;e.done?n(e.value):((t=e.value)instanceof a?t:new a(function(e){e(t)})).then(i,r)}s((c=c.apply(e,o||[])).next())})};class ye extends t{constructor(){super(...arguments),this.baseUrl="devicecontrol",this.listUrl="newDeviceRequests",this.propertyName="newDeviceRequests"}detail(e){const t=Object.create(null,{detail:{get:()=>super.detail}});return R(this,void 0,void 0,function*(){return t.detail.call(this,e)})}create(e){const t=Object.create(null,{create:{get:()=>super.create}});return R(this,void 0,void 0,function*(){return t.create.call(this,e)})}list(e={}){const t=Object.create(null,{list:{get:()=>super.list}});return R(this,void 0,void 0,function*(){return t.list.call(this,e)})}delete(e){const t=Object.create(null,{delete:{get:()=>super.delete}});return R(this,void 0,void 0,function*(){return t.delete.call(this,e)})}accept(n){const i=Object.create(null,{update:{get:()=>super.update}});return R(this,void 0,void 0,function*(){var e=this.getSecurityToken(n);let t={id:this.getIdString(n),status:r.DeviceRegistrationStatus.ACCEPTED};return e&&(t=Object.assign(Object.assign({},t),{securityToken:e})),i.update.call(this,t)})}acceptAll(){const n=Object.create(null,{fetch:{get:()=>super.fetch}});return R(this,void 0,void 0,function*(){var e=yield n.fetch.call(this,this.listUrl+"/acceptAll",{method:"POST"}),t=yield e.json();return{res:e,data:t}})}limit(){const n=Object.create(null,{fetch:{get:()=>super.fetch}});return R(this,void 0,void 0,function*(){var e=yield n.fetch.call(this,this.listUrl+"/limit"),t=yield e.json();return{res:e,data:t}})}bootstrap(s,o){return R(this,void 0,void 0,function*(){var e=this.getIdString(s),t=this.getSecurityToken(s),t=t?JSON.stringify({id:e,securityToken:t}):JSON.stringify({id:e}),e=this.baseUrl+"/deviceCredentials",n=o["basicAuth"];let i=o["basicAuthToken"];n&&({user:n,pass:r}=n,i=$(n+":"+r));var n={Authorization:"Basic "+i,accept:"application/json","content-type":"application/json"},r=yield this.client.fetch(e,{body:t,headers:n,method:"POST"}),e=yield r.json();if(400<r.status)throw{res:r,data:e};return{res:r,data:e}})}onBeforeCreate(e){return e}onBeforeUpdate(e){e=Object.assign({},e);return delete e.id,e}getDetailUrl(e){e=encodeURIComponent(this.getEntityId(e));return this.listUrl+"/"+e}getSecurityToken(e){let t;return t="object"==typeof e?e.securityToken?String(e.securityToken):void 0:t}}var me=function(e,o,a,c){return new(a=a||Promise)(function(n,t){function i(e){try{s(c.next(e))}catch(e){t(e)}}function r(e){try{s(c.throw(e))}catch(e){t(e)}}function s(e){var t;e.done?n(e.value):((t=e.value)instanceof a?t:new a(function(e){e(t)})).then(i,r)}s((c=c.apply(e,o||[])).next())})};class be{constructor(e){this.client=e}create(s){return me(this,void 0,void 0,function*(){let e=s;var t=new c;let n="bulk-registration.csv";"undefined"!=typeof File&&e instanceof File&&(n=e.name,e.name.match(/\.csv$/))&&(e=new File([e],e.name,{type:"text/csv"})),t.append("file",e,n);let i;"function"==typeof t.getHeaders&&(i=t.getHeaders());var r=Object.assign({accept:"application/json"},i),t=yield this.client.fetch("/devicecontrol/bulkNewDeviceRequests",{method:"POST",body:t,headers:r}),r=yield t.json();return{res:t,data:r}})}}r.DeviceRegistrationSecurityMode=void 0,(e=r.DeviceRegistrationSecurityMode||(r.DeviceRegistrationSecurityMode={})).REQUIRED="REQUIRED",e.OPTIONAL="OPTIONAL",e.IGNORED="IGNORED";var Te=function(e,o,a,c){return new(a=a||Promise)(function(n,t){function i(e){try{s(c.next(e))}catch(e){t(e)}}function r(e){try{s(c.throw(e))}catch(e){t(e)}}function s(e){var t;e.done?n(e.value):((t=e.value)instanceof a?t:new a(function(e){e(t)})).then(i,r)}s((c=c.apply(e,o||[])).next())})};class Oe extends t{constructor(){super(...arguments),this.baseUrl="user",this.listUrl="roles",this.propertyName="roles"}detail(e){const t=Object.create(null,{detail:{get:()=>super.detail}});return Te(this,void 0,void 0,function*(){return t.detail.call(this,e)})}list(e={}){const t=Object.create(null,{list:{get:()=>super.list}});return Te(this,void 0,void 0,function*(){return t.list.call(this,e)})}}var j,_,x=function(e,o,a,c){return new(a=a||Promise)(function(n,t){function i(e){try{s(c.next(e))}catch(e){t(e)}}function r(e){try{s(c.throw(e))}catch(e){t(e)}}function s(e){var t;e.done?n(e.value):((t=e.value)instanceof a?t:new a(function(e){e(t)})).then(i,r)}s((c=c.apply(e,o||[])).next())})};(_=j=j||{}).ROLES="roles",_.USERS="users";class Se extends t{constructor(){super(...arguments),this.baseUrl="user",this.propertyName="groups"}get listUrl(){return this.client.tenant+"/groups"}detail(e){const t=Object.create(null,{detail:{get:()=>super.detail}});return x(this,void 0,void 0,function*(){return t.detail.call(this,e)})}create(e){const t=Object.create(null,{create:{get:()=>super.create}});return x(this,void 0,void 0,function*(){return t.create.call(this,e)})}update(e){const t=Object.create(null,{update:{get:()=>super.update}});return x(this,void 0,void 0,function*(){return t.update.call(this,e)})}list(e={}){const t=Object.create(null,{list:{get:()=>super.list}});return x(this,void 0,void 0,function*(){return t.list.call(this,e)})}delete(e){const t=Object.create(null,{delete:{get:()=>super.delete}});return x(this,void 0,void 0,function*(){return t.delete.call(this,e)})}addRoleToGroup(e,t){return x(this,void 0,void 0,function*(){return this.addChild(j.ROLES,e,t)})}removeRoleFromGroup(e,t){return x(this,void 0,void 0,function*(){return this.removeChild(j.ROLES,e,t)})}addUserToGroup(e,t){return x(this,void 0,void 0,function*(){return this.addChild(j.USERS,e,t)})}removeUserFromGroup(e,t){return x(this,void 0,void 0,function*(){return this.removeChild(j.USERS,e,t)})}getSelf(e){return"object"==typeof e&&e.self?e.self:e}getChildUrl(e,t){return this.getDetailUrl(t)+"/"+e}getChildReferenceAsBody(e,t){var n=this.getSelf(t);switch(e){case j.ROLES:return JSON.stringify({role:{self:String(n)}});case j.USERS:return JSON.stringify({user:{self:String(n)}})}throw new Error("UserGroupService -> getChild -> unsupported child type")}addChild(n,i,r){return x(this,void 0,void 0,function*(){var e=this.getChildUrl(n,i),t=this.getChildReferenceAsBody(n,r),e=yield this.fetch(e,{method:"POST",body:t,headers:{accept:"application/json","content-type":"application/json"}}),t=yield e.json();return{res:e,data:t.managedObject}})}removeChild(t,n,i){return x(this,void 0,void 0,function*(){var e=this.getIdString(i),e=this.getChildUrl(t,n)+"/"+encodeURIComponent(String(e));return{res:yield this.fetch(e,{method:"DELETE",headers:{accept:"application/json"}}),data:null}})}}var A=function(e,o,a,c){return new(a=a||Promise)(function(n,t){function i(e){try{s(c.next(e))}catch(e){t(e)}}function r(e){try{s(c.throw(e))}catch(e){t(e)}}function s(e){var t;e.done?n(e.value):((t=e.value)instanceof a?t:new a(function(e){e(t)})).then(i,r)}s((c=c.apply(e,o||[])).next())})};class we{constructor(e){this.baseUrl="identity",this.propertyName="externalIds",this.client=e}list(n){return A(this,void 0,void 0,function*(){var e=this.getExternalIdsOfGlobalIdUrl(n),e=yield this.fetch(e,{headers:{accept:"application/json"}}),t=yield e.json();return{res:e,data:t[this.propertyName]}})}create(n){return A(this,void 0,void 0,function*(){var e=JSON.stringify(n),t=this.getExternalIdsOfGlobalIdUrl(n.managedObject.id),t=yield this.fetch(t,{headers:{"content-type":"application/json",accept:"application/json"},method:"POST",body:e}),e=yield t.json();return{res:t,data:e}})}detail(n){return A(this,void 0,void 0,function*(){var e=this.getExternalIdUrl(n),e=yield this.fetch(e,{headers:{accept:"application/json"}}),t=yield e.json();return{res:e,data:t}})}delete(t){return A(this,void 0,void 0,function*(){var e=this.getExternalIdUrl(t);return{res:yield this.fetch(e,{headers:{accept:"application/json"},method:"DELETE"}),data:null}})}fetch(e,t){return A(this,void 0,void 0,function*(){var n=yield this.client.fetch(e,t);if(400<=n.status){let t=null;try{t=yield n.json()}catch(e){try{t=yield n.text()}catch(e){}}throw{res:n,data:t}}return n})}getExternalIdsOfGlobalIdUrl(e){return`/${this.baseUrl}/globalIds/${e}/externalIds`}getExternalIdUrl(e){return`/${this.baseUrl}/externalIds/${e.type}/`+e.externalId}}var I=function(e,o,a,c){return new(a=a||Promise)(function(n,t){function i(e){try{s(c.next(e))}catch(e){t(e)}}function r(e){try{s(c.throw(e))}catch(e){t(e)}}function s(e){var t;e.done?n(e.value):((t=e.value)instanceof a?t:new a(function(e){e(t)})).then(i,r)}s((c=c.apply(e,o||[])).next())})};class Ee extends t{constructor(){super(...arguments),this.listUrl="trusted-certificates",this.proofOfPossessionUrl="trusted-certificates-pop",this.propertyName="certificates"}get baseUrl(){return"/tenant/tenants/"+this.client.tenant}list(e={}){const t=Object.create(null,{list:{get:()=>super.list}});return I(this,void 0,void 0,function*(){return t.list.call(this,e)})}detail(e){const t=Object.create(null,{detail:{get:()=>super.detail}});return I(this,void 0,void 0,function*(){return t.detail.call(this,e)})}delete(e){const t=Object.create(null,{delete:{get:()=>super.delete}});return I(this,void 0,void 0,function*(){return t.delete.call(this,e)})}update(e){const t=Object.create(null,{update:{get:()=>super.update}});return I(this,void 0,void 0,function*(){return t.update.call(this,e)})}create(e){const t=Object.create(null,{create:{get:()=>super.create}});return I(this,void 0,void 0,function*(){return t.create.call(this,e)})}regeneratePoPVerificationCode(n){return I(this,void 0,void 0,function*(){var e=`${this.proofOfPossessionUrl}/${this.getEntityId(n)}/verification-code`,e=yield this.fetch(e,{headers:{"content-type":"application/json",Accept:"application/json"},method:"POST"}),t=yield e.json();return{res:e,data:t}})}verifySignedVerificationCode(n,i){return I(this,void 0,void 0,function*(){var e=`${this.proofOfPossessionUrl}/${this.getEntityId(n)}/pop`,t=JSON.stringify({proofOfPossessionSignedVerificationCode:i}),e=yield this.fetch(e,{method:"POST",body:t,headers:{"content-type":"application/json",Accept:"application/json"}}),t=yield e.json();return{res:e,data:t}})}getDetailUrl(e){e=this.getEntityId(e);return this.listUrl+"/"+e}getEntityId(e){let t;return t="object"==typeof e&&e.fingerprint?e.fingerprint:e}}var P=function(e,o,a,c){return new(a=a||Promise)(function(n,t){function i(e){try{s(c.next(e))}catch(e){t(e)}}function r(e){try{s(c.throw(e))}catch(e){t(e)}}function s(e){var t;e.done?n(e.value):((t=e.value)instanceof a?t:new a(function(e){e(t)})).then(i,r)}s((c=c.apply(e,o||[])).next())})},Ue=function(e,t){var n={};for(r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols)for(var i=0,r=Object.getOwnPropertySymbols(e);i<r.length;i++)t.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(e,r[i])&&(n[r[i]]=e[r[i]]);return n};class Ce extends t{constructor(e){super(e),this.baseUrl="inventory",this.listUrl="managedObjects",this.SMART_GROUP_TYPE="c8y_DynamicGroup",this.SMART_GROUP_FRAGMENT_TYPE="c8y_IsDynamicGroup",this.DEVICE_GROUP_FRAGMENT_TYPE="c8y_IsDeviceGroup",this.DEVICE_GROUP_TYPE="c8y_DeviceGroup",this.DEVICE_SUBGROUP_TYPE="c8y_DeviceSubgroup",this.COLUMNS_CONFIG_FRAGMENT="c8y_DeviceColumnsConfig",this.FILTER_CONFIG_FRAGMENT="c8y_DeviceFilterConfig",this.QUERY_STRING_FRAGMENT="c8y_DeviceQueryString",this.SMART_GROUPS_V2_MICROSERVICE_APP_NAME="smartgroup",this.SMART_GROUPS_V2_MICROSERVICE_BASE_PATH="service/smartgroup",this.SMART_GROUPS_V2_MICROSERVICE_ENDPOINT_PATH=this.SMART_GROUPS_V2_MICROSERVICE_BASE_PATH+"/smartgroups",this.applicationService=new w(e)}detail(e,t={}){const n=Object.create(null,{detail:{get:()=>super.detail}});return P(this,void 0,void 0,function*(){return n.detail.call(this,e,t)})}create(n){const i=Object.create(null,{create:{get:()=>super.create}});return P(this,void 0,void 0,function*(){var e=(yield this.isSmartGroupsV2MicroserviceInstalled())["data"],t=Object.assign(Object.assign(Object.assign({},n.smartGroup),{[this.QUERY_STRING_FRAGMENT]:n.deviceQueryString,[this.COLUMNS_CONFIG_FRAGMENT]:n.configurableColumns}),n.filterConfig&&{[this.FILTER_CONFIG_FRAGMENT]:n.filterConfig});return e?this.createSmartGroupV2(t):i.create.call(this,t)})}update(n,i={}){const r=Object.create(null,{update:{get:()=>super.update}});return P(this,void 0,void 0,function*(){var e=n["id"],t=(yield this.isSmartGroupsV2MicroserviceInstalled())["data"],e=(yield this.detail(e,{withChildren:!1}))["data"];return t&&this.isSmartGroupV2(e)?this.updateSmartGroupV2(n,i):r.update.call(this,n)})}updateSmartGroupV2(n,i={}){return P(this,void 0,void 0,function*(){var e=n["id"],t=Ue(n,["id"]),t=JSON.stringify(this.onBeforeUpdate(t)),e=this.SMART_GROUPS_V2_MICROSERVICE_ENDPOINT_PATH+"/"+e,e=yield this.fetch(e,{method:"PUT",body:t,headers:{"content-type":"application/json",accept:"application/json"},params:Object.assign({},i)}),t=yield e.json();return{res:e,data:t}})}delete(n,i={}){const r=Object.create(null,{delete:{get:()=>super.delete}});return P(this,void 0,void 0,function*(){var e=(yield this.isSmartGroupsV2MicroserviceInstalled())["data"],t=(yield this.detail(n,{withChildren:!1})).data;return e&&this.isSmartGroupV2(t)?yield this.removeSmartGroupV2(t):yield r.delete.call(this,t,i)})}isSmartGroupsV2MicroserviceInstalled(){return this.applicationService.isAvailable({name:this.SMART_GROUPS_V2_MICROSERVICE_APP_NAME})}isSmartGroup(e){var t=e.hasOwnProperty(this.SMART_GROUP_FRAGMENT_TYPE),e=e&&e.type===this.SMART_GROUP_TYPE;return t||e}isSmartGroupV2(e){var t=e.hasOwnProperty(this.SMART_GROUP_FRAGMENT_TYPE),n=e.hasOwnProperty(this.DEVICE_GROUP_FRAGMENT_TYPE),e=e&&e.type===this.DEVICE_GROUP_TYPE||e.type===this.DEVICE_SUBGROUP_TYPE;return t&&n&&e}removeSmartGroupV2(n){return P(this,void 0,void 0,function*(){let e;e="object"==typeof n&&n.id?n.id:n;var t=this.SMART_GROUPS_V2_MICROSERVICE_ENDPOINT_PATH+"/"+e;return{res:yield this.client.fetch(t,{method:"DELETE"}),data:null}})}getUrl(e=""){var t=e.replace(/^\/+/,""),n=this.baseUrl.replace(/\/+$/,"");return e.includes(this.SMART_GROUPS_V2_MICROSERVICE_ENDPOINT_PATH)?t:n+"/"+t}createSmartGroupV2(n){return P(this,void 0,void 0,function*(){var e=JSON.stringify(n),t=this.SMART_GROUPS_V2_MICROSERVICE_ENDPOINT_PATH,t=yield this.fetch(t,{method:"POST",body:e,headers:{"content-type":"application/json",accept:"application/json"}}),e=yield t.json();return{res:t,data:e}})}}var Re=function(e,o,a,c){return new(a=a||Promise)(function(n,t){function i(e){try{s(c.next(e))}catch(e){t(e)}}function r(e){try{s(c.throw(e))}catch(e){t(e)}}function s(e){var t;e.done?n(e.value):((t=e.value)instanceof a?t:new a(function(e){e(t)})).then(i,r)}s((c=c.apply(e,o||[])).next())})};class k extends t{constructor(e){super(e),this.baseUrl="service/smartrule",this.rulesUrl="smartrules",this.unupdatableFields=["type","cepModuleId","creationTime","lastUpdated"],this.applicationService=new w(e)}isMicroserviceAvailable(){return Re(this,void 0,void 0,function*(){return void 0===this.microserviceAvailable&&(this.microserviceAvailable=(yield this.applicationService.isAvailable(k.microserviceName)).data),this.microserviceAvailable})}listByContext(n){return Re(this,void 0,void 0,function*(){var e=this.contextRulesUrl(n),e=yield this.fetch(e,{method:"GET"}),t=(yield e.json()).rules;return{res:e,data:t}})}bulkDeactivateEnabledSources(e,t){var n;return 0===t.length?Promise.resolve({res:null,data:null}):(n=e["enabledSources"],n=this.disableEnabledSources(n,t),t=Object.assign({},e),Object.assign(t,{enabledSources:n}),this.update(t))}update(n){return Re(this,void 0,void 0,function*(){var e=this.getSmartRulesUrl(n),t=JSON.stringify(this.removeUnclonableFields(n,this.unupdatableFields)),e=yield this.fetch(e,{method:"PUT",body:t,headers:{"content-type":"application/json",accept:"application/json"}}),t=yield e.json();return{res:e,data:t}})}disableEnabledSources(e=[],t){return e.filter(e=>!this.getListOfStringIds(t).includes(e))}getListOfStringIds(e){return e.map(e=>("object"==typeof e&&e.id?e.id:e).toString())}getSmartRulesUrl(e){var t=e&&e.c8y_Context&&e.c8y_Context.id;let n=t?this.contextRulesUrl(t):this.rulesUrl;return n=e.id?n+"/"+e.id:n}removeUnclonableFields(e,t){const n=Object.assign({},e);return t.forEach(e=>{delete n[e]}),n}contextRulesUrl(e={}){return"object"==typeof e&&e.id?`managedObjects/${e.id}/smartrules`:`managedObjects/${e}/smartrules`}}k.microserviceName="smartrule";var je=function(e,o,a,c){return new(a=a||Promise)(function(n,t){function i(e){try{s(c.next(e))}catch(e){t(e)}}function r(e){try{s(c.throw(e))}catch(e){t(e)}}function s(e){var t;e.done?n(e.value):((t=e.value)instanceof a?t:new a(function(e){e(t)})).then(i,r)}s((c=c.apply(e,o||[])).next())})};class N{constructor(e,t){e=new h(e,t);this.realtime=new B(e),this.alarm=new ne(e,this.realtime),this.application=new w(e,this.realtime),this.audit=new ve(e),this.core=e,this.deviceRegistration=new ye(e),this.deviceRegistrationBulk=new be(e),this.event=new Y(e,this.realtime),this.inventory=new ee(e,this.realtime),this.inventoryBinary=new Z(e),this.inventoryRole=new ge(e),this.measurement=new te(e,this.realtime),this.operation=new ie(e),this.operationBulk=new re(e),this.options={security:new he(e),system:new ue(e),login:new pe(e),tenant:new le(e)},this.role=new ge(e),this.tenant=new m(e),this.user=new oe(e),this.userGroup=new Se(e),this.userRole=new Oe(e),this.identity=new we(e),this.smartGroups=new Ce(e),this.smartRules=new k(e)}static authenticate(n,i){return je(this,void 0,void 0,function*(){var e=new p(n),t=yield new h(e,i).fetch("/tenant/currentTenant",{method:"GET"});if(200!==t.status)throw{res:t};t=(yield t.json()).name,e=new N(e,i);return e.core.tenant=t,e})}static deviceBootstrap(d){return je(this,void 0,void 0,function*(){var{deviceId:e,timeout:t,baseUrl:n,basicAuthToken:i}=d;let r=d["expire"];t&&!r&&(r=Date.now()+t);t=new h(void 0,n),t=new ye(t);let s;try{var o=(yield t.bootstrap(e,{basicAuthToken:i}))["data"],{username:a,password:c,tenantId:u}=o,l=new p({user:a,tenant:u,password:c});(s=new N(l,n)).core.tenant=u}catch(e){if((!r||Date.now()<r)&&404===e.res.status)return N.deviceBootstrap(Object.assign({expire:r},d));throw e}return s})}static getMicroserviceSubscriptions(t,n){return je(this,void 0,void 0,function*(){var e=(yield(yield new h(new p(t),n).fetch("/application/currentApplication/subscriptions")).json())["users"];return e.map(({tenant:e,name:t,password:n})=>({tenant:e,user:t,password:n}))})}setAuth(e){this.core.setAuth(e),this.realtime.disconnect()}}r.AlarmService=ne,r.ApplicationBinaryService=ae,r.ApplicationService=w,r.AuditService=ve,r.BasicAuth=p,r.Client=N,r.CookieAuth=class{constructor(){this.logoutUrl="user/logout"}updateCredentials({user:e}={}){this.user=e}getFetchOptions(e){var t=this.getCookieValue("XSRF-TOKEN");return e.headers=Object.assign({"X-XSRF-TOKEN":t},e.headers),e}getCometdHandshake(e={}){var t="com.cumulocity.authn",n=this.getCookieValue("XSRF-TOKEN"),i=e.ext=e.ext||{};return i[t]=Object.assign(i[t]||{},{xsrfToken:n}),e}logout(){return W(this,void 0,void 0,function*(){this.user&&delete this.user;var e=new h,t=(e.setAuth(this),JSON.stringify({}));return e.fetch(this.logoutUrl,{headers:{"content-type":"application/json",accept:"application/json"},body:t,method:"POST"})})}getCookieValue(e){e=document.cookie.match("(^|;)\\s*"+e+"\\s*=\\s*([^;]+)");return e?e.pop():""}},r.DeviceRegistrationBulkService=be,r.DeviceRegistrationService=ye,r.EventBinaryService=z,r.EventService=Y,r.FetchClient=h,r.IdentityService=we,r.InventoryBinaryService=Z,r.InventoryRoleService=ge,r.InventoryService=ee,r.MeasurementService=te,r.MicroserviceClientRequestAuth=class{constructor(e={}){this.xsrfToken=this.getCookieValue(e,"XSRF-TOKEN"),this.authTokenFromCookie=this.getCookieValue(e,"authorization"),this.authTokenFromHeader=e.authorization}updateCredentials(){}getFetchOptions(e){var t=Object.assign({Authorization:this.authTokenFromCookie?"Bearer "+this.authTokenFromCookie:this.authTokenFromHeader},this.xsrfToken?{"X-XSRF-TOKEN":this.xsrfToken}:void 0);return e.headers=Object.assign(t,e.headers),e}getCometdHandshake(e={}){var t="com.cumulocity.authn",n=this.xsrfToken;let i=this.authTokenFromCookie;!i&&this.authTokenFromHeader&&(i=this.authTokenFromHeader.replace("Basic ","").replace("Bearer ",""));var r=e.ext=e.ext||{};return r[t]=Object.assign(r[t]||{},Object.assign({token:i},n?{xsrfToken:n}:void 0)),e}logout(){this.authTokenFromCookie&&delete this.authTokenFromCookie,this.authTokenFromHeader&&delete this.authTokenFromHeader,this.xsrfToken&&delete this.xsrfToken}getCookieValue(e,t){try{var n=e&&e.cookie&&e.cookie.match("(^|;)\\s*"+t+"\\s*=\\s*([^;]+)");return n?n.pop():void 0}catch(e){}}},r.OperationBulkService=re,r.OperationService=ie,r.Paging=M,r.QueriesUtil=Q,r.Realtime=B,r.Service=t,r.SmartGroupsService=Ce,r.SmartRulesService=k,r.SystemOptionsService=ue,r.TenantLoginOptionsService=pe,r.TenantOptionsService=le,r.TenantSecurityOptionsService=he,r.TenantService=m,r.TrustedCertificateService=Ee,r.UserGroupService=Se,r.UserInventoryRoleService=se,r.UserRoleService=Oe,r.UserService=oe});
2
2
  //# sourceMappingURL=client.umd.min.js.map