@c8y/client 1016.247.0 → 1016.248.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 L(t){return void 0!==t&&null!==t&&"function"==typeof t}function $(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(L(n)){var i=new Date;[].splice.call(e,0,0,$(i.getHours(),2)+":"+$(i.getMinutes(),2)+":"+$(i.getSeconds(),2)+"."+$(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(L(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(L(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(L(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(),R=!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(L(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){L(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(L(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]);L(e)&&(delete j[t.id],ut(e,t))}function dt(t){var e=_[t.id];if(delete _[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(L(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(L(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=R,R=!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 _t(t,e){var n={scope:t,method:e};if(L(t))n.scope=void 0,n.method=t;else if(D(e)){if(!t)throw"Invalid scope "+t;if(n.method=t[e],!L(n.method))throw"Invalid callback "+e+" for scope "+t}else if(!L(e))throw"Invalid callback "+e;return n}function Rt(t,e,n,i){var r=_t(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 L(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),L(e.registered)&&e.registered(t,this)),i},this.unregisterTransport=function(t){var e=f.remove(t);return null!==e&&(this._debug("Unregistered transport",t),L(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()){L(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=_t(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 Rt(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";L(e)&&(r=i,i=n,n=e,e=void 0),L(i)&&(r=i,i=void 0);var s=!jt(t),o=Rt(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";L(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";L(e)?(i=e,e={},n=void 0):L(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){L(e)?(r=e,e=new ArrayBuffer(0),n=!0,i=void 0):L(n)?(r=n,n=!0,i=void 0):L(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(L(e)?(r=e,e={},n=k.maxNetworkDelay,i=void 0):L(n)?(r=n,n=k.maxNetworkDelay,i=void 0):L(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")),_[a.id]=c,et(a)},this.remoteCallBinary=function(t,e,n,i,r,s){L(e)?(s=e,e=new ArrayBuffer(0),n=!0,i=void 0,r=k.maxNetworkDelay):L(n)?(s=n,n=!0,i=void 0,r=k.maxNetworkDelay):L(i)?(s=i,i=void 0,r=k.maxNetworkDelay):L(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),L(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;L(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 _ 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 R="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 R;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 L 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 $,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)})}}($=t.AlarmStatus||(t.AlarmStatus={}))[$.ACKNOWLEDGED=S("ACKNOWLEDGED")]="ACKNOWLEDGED",$[$.CLEARED=S("CLEARED")]="CLEARED",$[$.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`}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}})}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))}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`}}(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,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 R;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,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()}})}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,_t=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 Rt 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 _t(this,void 0,void 0,function*(){return e.detail.call(this,t)})}create(t){const e=Object.create(null,{create:{get:()=>super.create}});return _t(this,void 0,void 0,function*(){return e.create.call(this,t)})}update(t){const e=Object.create(null,{update:{get:()=>super.update}});return _t(this,void 0,void 0,function*(){return e.update.call(this,t)})}list(t={}){const e=Object.create(null,{list:{get:()=>super.list}});return _t(this,void 0,void 0,function*(){return e.list.call(this,t)})}delete(t){const e=Object.create(null,{delete:{get:()=>super.delete}});return _t(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 R;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 Lt,$t=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"}(Lt||(Lt={}));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 $t(this,void 0,void 0,function*(){return e.detail.call(this,t)})}create(t){const e=Object.create(null,{create:{get:()=>super.create}});return $t(this,void 0,void 0,function*(){return e.create.call(this,t)})}update(t){const e=Object.create(null,{update:{get:()=>super.update}});return $t(this,void 0,void 0,function*(){return e.update.call(this,t)})}list(t={}){const e=Object.create(null,{list:{get:()=>super.list}});return $t(this,void 0,void 0,function*(){return e.list.call(this,t)})}delete(t){const e=Object.create(null,{delete:{get:()=>super.delete}});return $t(this,void 0,void 0,function*(){return e.delete.call(this,t)})}addRoleToGroup(t,e){return $t(this,void 0,void 0,function*(){return this.addChild(Lt.ROLES,t,e)})}removeRoleFromGroup(t,e){return $t(this,void 0,void 0,function*(){return this.removeChild(Lt.ROLES,t,e)})}addUserToGroup(t,e){return $t(this,void 0,void 0,function*(){return this.addChild(Lt.USERS,t,e)})}removeUserFromGroup(t,e){return $t(this,void 0,void 0,function*(){return this.removeChild(Lt.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 Lt.ROLES:return JSON.stringify({role:{self:String(n)}});case Lt.USERS:return JSON.stringify({user:{self:String(n)}})}throw new Error("UserGroupService -> getChild -> unsupported child type")}addChild(t,e,n){return $t(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 $t(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 _(n,this.realtime),this.inventory=new k(n,this.realtime),this.inventoryBinary=new I(n),this.inventoryRole=new Rt(n),this.measurement=new L(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 Rt(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=_,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 R;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=Rt,t.MeasurementService=L,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(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`}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}})}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})});
2
2
  //# sourceMappingURL=client.umd.min.js.map