@c8y/client 1019.22.0 → 1019.23.4
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.
- package/lib/bundles/client.umd.js +28 -0
- package/lib/bundles/client.umd.js.map +1 -1
- package/lib/bundles/client.umd.min.js +1 -1
- package/lib/bundles/client.umd.min.js.map +1 -1
- package/lib/cjs/src/tenant/TenantService.d.ts +19 -0
- package/lib/cjs/src/tenant/TenantService.d.ts.map +1 -1
- package/lib/cjs/src/tenant/TenantService.js +26 -0
- package/lib/cjs/src/tenant/TenantService.js.map +1 -1
- package/lib/esm2015/src/tenant/TenantService.d.ts +19 -0
- package/lib/esm2015/src/tenant/TenantService.d.ts.map +1 -1
- package/lib/esm2015/src/tenant/TenantService.js +28 -0
- package/lib/esm2015/src/tenant/TenantService.js.map +1 -1
- package/lib/src/tenant/TenantService.d.ts +19 -0
- package/lib/src/tenant/TenantService.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).cumulocity={})}(this,function(r){"use strict";function a(e,o,a,c){return new(a=a||Promise)(function(n,t){function i(e){try{s(c.next(e))}catch(e){t(e)}}function r(e){try{s(c.throw(e))}catch(e){t(e)}}function s(e){var t;e.done?n(e.value):((t=e.value)instanceof a?t:new a(function(e){e(t)})).then(i,r)}s((c=c.apply(e,o||[])).next())})}class n{constructor(e,t,n){this.filter=n,this.service=e,this.currentPage=t.currentPage,this.nextPage=t.nextPage,this.prevPage=t.prevPage,this.pageSize=t.pageSize,this.totalPages=t.totalPages}next(e={}){return a(this,void 0,void 0,function*(){return this.list(this.getFilter(e,this.nextPage))})}prev(e={}){return a(this,void 0,void 0,function*(){return this.list(this.getFilter(e,this.prevPage))})}list(e={}){return a(this,void 0,void 0,function*(){return this.service.list(e)})}goto(e,t={}){return a(this,void 0,void 0,function*(){return this.list(this.getFilter(t,e))})}getFilter(e,t){return Object.assign(e,this.filter,{currentPage:t})}}class e{constructor(e,t){this.client=e,this.realtime=t,this.cache=new Map;const n=Object.getPrototypeOf(this);["list","create","update","detail","delete"].forEach(e=>{n.hasOwnProperty(e)||Object.defineProperty(this,e,{get(){}})})}list(n={}){return a(this,void 0,void 0,function*(){var e=this.listUrl,e=yield this.fetch(e,this.changeFetchOptions({headers:{accept:"application/json"},params:n},e)),t=yield e.json();return{res:e,data:this.propertyName?t[this.propertyName]:t,paging:this.getPaging(t,n)}})}detail(n,i={}){return a(this,void 0,void 0,function*(){var e=this.getDetailUrl(n),e=yield this.fetch(e,this.changeFetchOptions({headers:{accept:"application/json"},params:Object.assign({},i)},e)),t=yield e.json();return{res:e,data:t}})}create(n){return a(this,void 0,void 0,function*(){var e=this.listUrl,t=JSON.stringify(this.onBeforeCreate(n)),t=yield this.fetch(e,this.changeFetchOptions({method:"POST",body:t,headers:{"content-type":"application/json",accept:"application/json"}},e)),e=yield t.json();return{res:t,data:e}})}update(n){return a(this,void 0,void 0,function*(){var e=this.getDetailUrl(n),t=JSON.stringify(this.onBeforeUpdate(n)),t=yield this.fetch(e,this.changeFetchOptions({method:"PUT",body:t,headers:{"content-type":"application/json",accept:"application/json"}},e)),e=yield t.json();return{res:t,data:e}})}delete(t,n){return a(this,void 0,void 0,function*(){var e=this.getDetailUrl(t);return{res:yield this.fetch(e,this.changeFetchOptions({method:"DELETE",params:n},e)),data:null}})}onBeforeCreate(e){return delete e.id,e}onBeforeUpdate(e){return e}changeFetchOptions(e,t=0){return e}getUrl(e=""){return this.baseUrl.replace(/\/+$/,"")+"/"+e.replace(/^\/+/,"")}getEntityId(e){return null==e?"":"object"==typeof e?this.getEntityId(e.id):""+e}getDetailUrl(e){e=this.getEntityId(e);return this.listUrl+"/"+e}fetch(t,n){return a(this,void 0,void 0,function*(){var e=this.getUrl(t),e=yield this.client.fetch(e,n);return yield this.handleErrorStatusCodes(e)})}handleErrorStatusCodes(n){return a(this,void 0,void 0,function*(){if(400<=n.status){let t=null;try{t=yield n.json()}catch(e){try{t=yield n.text()}catch(e){}}throw{res:n,data:t}}return n})}mimeType(e){return`application/vnd.com.nsn.cumulocity.${e}+json`}getIdString(e){let t;return t="object"==typeof e?e.id:e,String(t)}getPaging(e,t){return e.statistics?(e=Object.assign(Object.assign({},e.statistics),{nextPage:this.getCurrentPageFromLink(e.next),prevPage:this.getCurrentPageFromLink(e.prev)}),new n(this,e,t)):null}getCurrentPageFromLink(e=""){e=e.match(/currentPage=(-{0,1}\d+)/);return e&&parseInt(e[1],10)}}var P="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function t(e,t){return e(t={exports:{}},t.exports),t.exports}var i=t(function(e,t){var n="undefined"!=typeof self?self:P,i=(r.prototype=n,new r);function r(){this.fetch=!1,this.DOMException=n.DOMException}var s,o,a=i,c={},l="URLSearchParams"in a,u="Symbol"in a&&"iterator"in Symbol,d="FileReader"in a&&"Blob"in a&&function(){try{return new Blob,!0}catch(e){return!1}}(),h="FormData"in a,p="ArrayBuffer"in a;function f(e){if("string"!=typeof e&&(e=String(e)),/[^a-z0-9\-#$%&'*+.^_`|~]/i.test(e))throw new TypeError("Invalid character in header field name");return e.toLowerCase()}function g(e){return e="string"!=typeof e?String(e):e}function v(t){var e={next:function(){var e=t.shift();return{done:void 0===e,value:e}}};return u&&(e[Symbol.iterator]=function(){return e}),e}function y(t){this.map={},t instanceof y?t.forEach(function(e,t){this.append(t,e)},this):Array.isArray(t)?t.forEach(function(e){this.append(e[0],e[1])},this):t&&Object.getOwnPropertyNames(t).forEach(function(e){this.append(e,t[e])},this)}function m(e){if(e.bodyUsed)return Promise.reject(new TypeError("Already read"));e.bodyUsed=!0}function b(n){return new Promise(function(e,t){n.onload=function(){e(n.result)},n.onerror=function(){t(n.error)}})}function T(e){var t=new FileReader,n=b(t);return t.readAsArrayBuffer(e),n}function O(e){var t;return e.slice?e.slice(0):((t=new Uint8Array(e.byteLength)).set(new Uint8Array(e)),t.buffer)}function S(){return this.bodyUsed=!1,this._initBody=function(e){var t;(this._bodyInit=e)?"string"==typeof e?this._bodyText=e:d&&Blob.prototype.isPrototypeOf(e)?this._bodyBlob=e:h&&FormData.prototype.isPrototypeOf(e)?this._bodyFormData=e:l&&URLSearchParams.prototype.isPrototypeOf(e)?this._bodyText=e.toString():p&&d&&(t=e)&&DataView.prototype.isPrototypeOf(t)?(this._bodyArrayBuffer=O(e.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):p&&(ArrayBuffer.prototype.isPrototypeOf(e)||o(e))?this._bodyArrayBuffer=O(e):this._bodyText=e=Object.prototype.toString.call(e):this._bodyText="",this.headers.get("content-type")||("string"==typeof e?this.headers.set("content-type","text/plain;charset=UTF-8"):this._bodyBlob&&this._bodyBlob.type?this.headers.set("content-type",this._bodyBlob.type):l&&URLSearchParams.prototype.isPrototypeOf(e)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},d&&(this.blob=function(){var e=m(this);if(e)return e;if(this._bodyBlob)return Promise.resolve(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(new Blob([this._bodyArrayBuffer]));if(this._bodyFormData)throw new Error("could not read FormData body as blob");return Promise.resolve(new Blob([this._bodyText]))},this.arrayBuffer=function(){return this._bodyArrayBuffer?m(this)||Promise.resolve(this._bodyArrayBuffer):this.blob().then(T)}),this.text=function(){var e,t,n=m(this);if(n)return n;if(this._bodyBlob)return n=this._bodyBlob,e=new FileReader,t=b(e),e.readAsText(n),t;if(this._bodyArrayBuffer)return Promise.resolve(function(e){for(var t=new Uint8Array(e),n=new Array(t.length),i=0;i<t.length;i++)n[i]=String.fromCharCode(t[i]);return n.join("")}(this._bodyArrayBuffer));if(this._bodyFormData)throw new Error("could not read FormData body as text");return Promise.resolve(this._bodyText)},h&&(this.formData=function(){return this.text().then(w)}),this.json=function(){return this.text().then(JSON.parse)},this}p&&(s=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],o=ArrayBuffer.isView||function(e){return e&&-1<s.indexOf(Object.prototype.toString.call(e))}),y.prototype.append=function(e,t){e=f(e),t=g(t);var n=this.map[e];this.map[e]=n?n+", "+t:t},y.prototype.delete=function(e){delete this.map[f(e)]},y.prototype.get=function(e){return e=f(e),this.has(e)?this.map[e]:null},y.prototype.has=function(e){return this.map.hasOwnProperty(f(e))},y.prototype.set=function(e,t){this.map[f(e)]=g(t)},y.prototype.forEach=function(e,t){for(var n in this.map)this.map.hasOwnProperty(n)&&e.call(t,this.map[n],n,this)},y.prototype.keys=function(){var n=[];return this.forEach(function(e,t){n.push(t)}),v(n)},y.prototype.values=function(){var t=[];return this.forEach(function(e){t.push(e)}),v(t)},y.prototype.entries=function(){var n=[];return this.forEach(function(e,t){n.push([t,e])}),v(n)},u&&(y.prototype[Symbol.iterator]=y.prototype.entries);var E=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];function U(e,t){var n,i=(t=t||{}).body;if(e instanceof U){if(e.bodyUsed)throw new TypeError("Already read");this.url=e.url,this.credentials=e.credentials,t.headers||(this.headers=new y(e.headers)),this.method=e.method,this.mode=e.mode,this.signal=e.signal,i||null==e._bodyInit||(i=e._bodyInit,e.bodyUsed=!0)}else this.url=String(e);if(this.credentials=t.credentials||this.credentials||"same-origin",!t.headers&&this.headers||(this.headers=new y(t.headers)),this.method=(e=t.method||this.method||"GET",n=e.toUpperCase(),-1<E.indexOf(n)?n:e),this.mode=t.mode||this.mode||null,this.signal=t.signal||this.signal,this.referrer=null,("GET"===this.method||"HEAD"===this.method)&&i)throw new TypeError("Body not allowed for GET or HEAD requests");this._initBody(i)}function w(e){var n=new FormData;return e.trim().split("&").forEach(function(e){var t;e&&(t=(e=e.split("=")).shift().replace(/\+/g," "),e=e.join("=").replace(/\+/g," "),n.append(decodeURIComponent(t),decodeURIComponent(e)))}),n}function C(e,t){t=t||{},this.type="default",this.status=void 0===t.status?200:t.status,this.ok=200<=this.status&&this.status<300,this.statusText="statusText"in t?t.statusText:"OK",this.headers=new y(t.headers),this.url=t.url||"",this._initBody(e)}U.prototype.clone=function(){return new U(this,{body:this._bodyInit})},S.call(U.prototype),S.call(C.prototype),C.prototype.clone=function(){return new C(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new y(this.headers),url:this.url})},C.error=function(){var e=new C(null,{status:0,statusText:""});return e.type="error",e};var j=[301,302,303,307,308];C.redirect=function(e,t){if(-1===j.indexOf(t))throw new RangeError("Invalid status code");return new C(null,{status:t,headers:{location:e}})},c.DOMException=a.DOMException;try{new c.DOMException}catch(e){c.DOMException=function(e,t){this.message=e,this.name=t;t=Error(e);this.stack=t.stack},c.DOMException.prototype=Object.create(Error.prototype),c.DOMException.prototype.constructor=c.DOMException}function R(s,o){return new Promise(function(i,e){var t=new U(s,o);if(t.signal&&t.signal.aborted)return e(new c.DOMException("Aborted","AbortError"));var r=new XMLHttpRequest;function n(){r.abort()}r.onload=function(){var n,e={status:r.status,statusText:r.statusText,headers:(e=r.getAllResponseHeaders()||"",n=new y,e.replace(/\r?\n[\t ]+/g," ").split(/\r?\n/).forEach(function(e){var e=e.split(":"),t=e.shift().trim();t&&(e=e.join(":").trim(),n.append(t,e))}),n)},t=(e.url="responseURL"in r?r.responseURL:e.headers.get("X-Request-URL"),"response"in r?r.response:r.responseText);i(new C(t,e))},r.onerror=function(){e(new TypeError("Network request failed"))},r.ontimeout=function(){e(new TypeError("Network request failed"))},r.onabort=function(){e(new c.DOMException("Aborted","AbortError"))},r.open(t.method,t.url,!0),"include"===t.credentials?r.withCredentials=!0:"omit"===t.credentials&&(r.withCredentials=!1),"responseType"in r&&d&&(r.responseType="blob"),t.headers.forEach(function(e,t){r.setRequestHeader(t,e)}),t.signal&&(t.signal.addEventListener("abort",n),r.onreadystatechange=function(){4===r.readyState&&t.signal.removeEventListener("abort",n)}),r.send(void 0===t._bodyInit?null:t._bodyInit)})}R.polyfill=!0,a.fetch||(a.fetch=R,a.Headers=y,a.Request=U,a.Response=C),c.Headers=y,c.Request=U,c.Response=C,c.fetch=R,Object.defineProperty(c,"__esModule",{value:!0}),i.fetch.ponyfill=!0,delete i.fetch.polyfill;a=i;(t=a.fetch).default=a.fetch,t.fetch=a.fetch,t.Headers=a.Headers,t.Request=a.Request,t.Response=a.Response,e.exports=t}),L=(S=i)&&S.__esModule&&Object.prototype.hasOwnProperty.call(S,"default")?S.default:S;i.fetch,i.Headers,i.Request,i.Response;let s=new WeakMap;class h{constructor(e,t){this.baseUrl=t,this.tenant="",this.defaultHeaders={},"string"==typeof e?t=e:this.setAuth(e),this.baseUrl=this.resolveServerUrl(t)}setAuth(e){s.set(this,e)}fetch(i,r){return a(this,void 0,void 0,function*(){let e=L;try{e=window.fetch||e}catch(e){}var t=this.getUrl(i,r),n=this.getFetchOptions(r),n=this.adjustOptionsForFormData(n);return e(t,n)})}getUrl(e="",t){const i=t&&t.params;let n="";return i&&Object.keys(i).length&&(n="?"+(n=Object.keys(i).map(e=>{let t=i[e];const n=encodeURIComponent(e);return(t=Array.isArray(t)?t:[t]).map(e=>n+"="+encodeURIComponent(e)).join("&")}).join("&"))),this.baseUrl.replace(/\/+$/,"").replace(/^\/+/,"")+"/"+e.replace(/\/+$/,"").replace(/^\/+/,"")+n}getFetchOptions(e={}){let t=Object.assign({},e);e=s.get(this);return t.headers=Object.assign({},this.defaultHeaders,t.headers,{UseXBasic:!0}),delete t.params,t=e?e.getFetchOptions(t):t}getCometdHandshake(e={}){var t=s.get(this);return t?t.getCometdHandshake(e):e}resolveServerUrl(e=""){if(e&&e.startsWith("http"))return e.replace(/\/+$/,"");try{var t=window.location;return`${t.protocol}//${t.host}/`+e.replace(/\/+$/,"")}catch(e){throw Error("Your environment does not support relative URLs. Please provide a base URL.")}}adjustOptionsForFormData(e){return Object.assign(e,{body:e.body})}}function o(e){function t(){this.message=e}return(t.prototype=new Error).name="InvalidCharacterError",t.prototype.code=5,t}function c(e){return B(encodeURIComponent(e).replace(/%([0-9A-F]{2})/g,function(e,t){return String.fromCharCode("0x"+t)}))}var F=o("The string to be encoded contains characters out of range"),B="undefined"!=typeof btoa?function(e){return btoa(e)}:function(e){for(var t,n,i=String(e),r="",s=0,o="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";i.charAt(0|s)||(o="=",s%1);r+=o.charAt(63&t>>8-s%1*8)){if(255<(n=i.charCodeAt(s+=.75)))throw new F;t=t<<8|n}return r},l=(o("The string to be decoded is not correctly encoded"),new WeakMap);class p{constructor(e){this.updateCredentials(e)}updateCredentials({tenant:e,user:t,password:n,token:i,tfa:r}={}){var s=l.get(this)||{};return t=(t=t&&e?e+"/"+t:t)||this.user,n=n||s.password,!i&&t&&n&&(i=c(t+":"+n)),t&&(this.user=t),i=i||s.token,r=r||s.tfa,l.set(this,{tfa:r,token:i,password:n}),i}getFetchOptions(e){var{token:t,tfa:n}=l.get(this),i=this.getCookieValue("XSRF-TOKEN"),t=Object.assign({Authorization:"Basic "+(t||"")},i?{"X-XSRF-TOKEN":i}:void 0);return n&&(t.tfatoken=n),e.headers=Object.assign(t,e.headers),e}getCometdHandshake(e={}){var{token:t,tfa:n}=l.get(this),i="com.cumulocity.authn",r=e.ext=e.ext||{};return r[i]=Object.assign(r[i]||{},{token:t,tfa:n}),e}logout(){delete this.user,l.set(this,{})}getCookieValue(e){try{var t=document.cookie.match("(^|;)\\s*"+e+"\\s*=\\s*([^;]+)");return t?t.pop():void 0}catch(e){}}}const u=new WeakMap;class d{constructor(e){u.set(this,{token:e})}getFetchOptions(e){var t=u.get(this)["token"];return e.headers=Object.assign({Authorization:"Bearer "+t},e.headers),e}updateCredentials({token:e}){u.set(this,{token:e})}getCometdHandshake(e={}){var{token:t,tfa:n}=u.get(this),i="com.cumulocity.authn",r=e.ext=e.ext||{};return r[i]=Object.assign(r[i]||{},{token:t,tfa:n}),e}logout(){u.set(this,{})}}class f{constructor(){this.logoutUrl="user/logout"}updateCredentials({user:e}={}){this.user=e}getFetchOptions(e){var t=this.getCookieValue("XSRF-TOKEN");return e.headers=Object.assign({"X-XSRF-TOKEN":t},e.headers),e}getCometdHandshake(e={}){var t="com.cumulocity.authn",n=this.getCookieValue("XSRF-TOKEN"),i=e.ext=e.ext||{};return i[t]=Object.assign(i[t]||{},{xsrfToken:n}),e}logout(){return a(this,void 0,void 0,function*(){this.user&&delete this.user;var e=new h,t=(e.setAuth(this),JSON.stringify({}));return e.fetch(this.logoutUrl,{headers:{"content-type":"application/json",accept:"application/json"},body:t,method:"POST"})})}getCookieValue(e){e=document.cookie.match("(^|;)\\s*"+e+"\\s*=\\s*([^;]+)");return e?e.pop():""}}class g{constructor(e={}){this.xsrfToken=this.getCookieValue(e,"XSRF-TOKEN"),this.authTokenFromCookie=this.getCookieValue(e,"authorization"),this.authTokenFromHeader=e.authorization}updateCredentials(){}getFetchOptions(e){var t=Object.assign({Authorization:this.authTokenFromCookie?"Bearer "+this.authTokenFromCookie:this.authTokenFromHeader},this.xsrfToken?{"X-XSRF-TOKEN":this.xsrfToken}:void 0);return e.headers=Object.assign(t,e.headers),e}getCometdHandshake(e={}){var t="com.cumulocity.authn",n=this.xsrfToken;let i=this.authTokenFromCookie;!i&&this.authTokenFromHeader&&(i=this.authTokenFromHeader.replace("Basic ","").replace("Bearer ",""));var r=e.ext=e.ext||{};return r[t]=Object.assign(r[t]||{},Object.assign({token:i},n?{xsrfToken:n}:void 0)),e}logout(){this.authTokenFromCookie&&delete this.authTokenFromCookie,this.authTokenFromHeader&&delete this.authTokenFromHeader,this.xsrfToken&&delete this.xsrfToken}getCookieValue(e,t){try{var n=e&&e.cookie&&e.cookie.match("(^|;)\\s*"+t+"\\s*=\\s*([^;]+)");return n?n.pop():void 0}catch(e){}}}class v extends g{constructor(e){super();e=e.headers.get("set-cookie");if(!e)throw Error("No Cookie set");this.authTokenFromCookie=this.getCookieValue({cookie:e},"authorization")}}r.Severity=void 0,(S=r.Severity||(r.Severity={}))[S.CRITICAL="CRITICAL"]="CRITICAL",S[S.MAJOR="MAJOR"]="MAJOR",S[S.MINOR="MINOR"]="MINOR",S[S.WARNING="WARNING"]="WARNING";class y{constructor(){this.operatorFns={__not:e=>`not(${this.buildQueryFilter(e,null)})`,__and:e=>this.buildQueryFilter(e,null,"and"),__or:e=>this.buildQueryFilter(e,null,"or"),__eq:(e,t)=>"object"==typeof e&&null!==e?this.buildQueryFilter(e,t):t+" eq "+this.quoteString(e),__gt:(e,t)=>t+" gt "+this.quoteString(e),__ge:(e,t)=>t+" ge "+this.quoteString(e),__lt:(e,t)=>t+" lt "+this.quoteString(e),__le:(e,t)=>t+" le "+this.quoteString(e),__in:(e,t)=>{e=e.filter(e=>!!e).map(e=>t+" eq "+this.quoteString(e));return this.glue(e,"or")},__bygroupid:e=>`bygroupid(${e})`,__has:e=>`has(${e})`,__useFilterQueryString:e=>{e=null==(e=e.match(/\(.*\)/))?void 0:e[0];return null==e?void 0:e.substring(1,e.length-1)}}}buildQuery(e){var t=[],n=this.buildQueryFilter(e.__filter||e),e=this.buildQueryOrderby(e.__orderby);return n&&t.push(`$filter=(${n})`),e&&t.push("$orderby="+e),t.join(" ")}buildQueryFilter(n,e,t){const i=e||null,r=t||"and",s=[];if(Array.isArray(n))n.forEach(e=>{e=this.buildQueryFilter(e,null,r);e&&s.push(e)});else{let t;Object.keys(n).forEach(e=>{void 0!==this.operatorFns[e]?(t=this.operatorFns[e](n[e],i))&&s.push(t):(t=this.operatorFns.__eq(n[e],e))&&s.push(t)})}return this.glue(s,r)}buildQueryOrderby(e){const n=[];return e&&e.forEach(t=>{Object.keys(t).forEach(e=>{0!==t[e]&&n.push(e+" "+(0<t[e]?"asc":"desc"))})}),n.join(",")}addAndFilter(e,t){return this.addFilter(e,t,"and")}addOrFilter(e,t){return this.addFilter(e,t,"or")}addFilter(e,t,n){var i=e.__orderby?e.__filter||{}:e.__filter||e,n={["__"+n]:this.skipEmptyObjects([i,t])};return e.__filter||e.__orderby?(e.__filter=n,e):n}prependOrderbys(e,t){return this.addOrderbys(e,t,"prepend")}appendOrderbys(e,t){return this.addOrderbys(e,t,"append")}addOrderbys(e,t,n){var i=e.__orderby?e.__filter||{}:e.__filter||e,e=e.__orderby||[],n="prepend"===n?[...t,...e]:[...e,...t],e={__orderby:this.skipEmptyObjects(n)};return this.isEmptyObject(i)||(e.__filter=i),e}extractAndMergeOrderBys(e){if(0<(null==e?void 0:e.length))return(e=e.map(e=>{return null==(e=e.match(/\$orderby=(.*)$/))?void 0:e[1]}).filter(e=>!!e).join(","))?"$orderby="+e:""}glue(e,t){return 1<e.length?`(${e.join(`) ${t} (`)})`:e[0]}quoteString(e){return"string"==typeof e?`'${this.escapeSingleQuote(e)}'`:e}skipEmptyObjects(e){return e.filter(e=>!this.isEmptyObject(e))}isEmptyObject(e){return 0===Object.keys(e).length}escapeSingleQuote(e){return"string"!=typeof e?e:e.replace(/\'/g,"''")}}var m,i=t(function(e,t){var be,Te,Oe,m,n,Se,Ee,Ue,h,p;e.exports=(be=function(){var n=0,i={};this.register=function(e){var t=++n;return i[t]=e,t},this.unregister=function(e){var t=i[e];return delete i[e],t},this.setTimeout=function(e,t){return window.setTimeout(e,t)},this.clearTimeout=function(e){window.clearTimeout(e)}},Te={isString:function(e){return null!=e&&("string"==typeof e||e instanceof String)},isArray:function(e){return null!=e&&e instanceof Array},inArray:function(e,t){for(var n=0;n<t.length;++n)if(e===t[n])return n;return-1}},Oe=function(){var c=[],l={};this.getTransportTypes=function(){return c.slice(0)},this.findTransportTypes=function(e,t,n){for(var i=[],r=0;r<c.length;++r){var s=c[r];!0===l[s].accept(e,t,n)&&i.push(s)}return i},this.negotiateTransport=function(e,t,n,i){for(var r=0;r<c.length;++r)for(var s=c[r],o=0;o<e.length;++o)if(s===e[o]){var a=l[s];if(!0===a.accept(t,n,i))return a}return null},this.add=function(e,t,n){for(var i=!1,r=0;r<c.length;++r)if(c[r]===e){i=!0;break}return i||("number"!=typeof n?c.push(e):c.splice(n,0,e),l[e]=t),!i},this.find=function(e){for(var t=0;t<c.length;++t)if(c[t]===e)return l[e];return null},this.remove=function(e){for(var t,n=0;n<c.length;++n)if(c[n]===e)return c.splice(n,1),t=l[e],delete l[e],t;return null},this.clear=function(){c=[],l={}},this.reset=function(e){for(var t=0;t<c.length;++t)l[c[t]].reset(e)}},(m=function(){var n,i,t;this.registered=function(e,t){n=e,i=t},this.unregistered=function(){i=n=null},this._debug=function(){i._debug.apply(i,arguments)},this._mixin=function(){return i._mixin.apply(i,arguments)},this.getConfiguration=function(){return i.getConfiguration()},this.getAdvice=function(){return i.getAdvice()},this.setTimeout=function(e,t){return i.setTimeout(e,t)},this.clearTimeout=function(e){i.clearTimeout(e)},this.convertToMessages=function(t){if(Te.isString(t))try{return JSON.parse(t)}catch(e){throw this._debug("Could not convert to JSON the following string",'"'+t+'"'),e}if(Te.isArray(t))return t;if(null==t)return[];if(t instanceof Object)return[t];throw"Conversion Error "+t+", typeof "+typeof t},this.accept=function(e,t,n){throw"Abstract"},this.getType=function(){return n},this.getURL=function(){return t},this.setURL=function(e){t=e},this.send=function(e,t){throw"Abstract"},this.reset=function(e){this._debug("Transport",n,"reset",e?"initial":"retry")},this.abort=function(){this._debug("Transport",n,"aborted")},this.toString=function(){return this.getType()}}).derive=function(e){function t(){}return t.prototype=e,new t},h=["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z",".","-",":","+","=","^","!","/","*","?","&","<",">","(",")","[","]","{","}","@","%","$","#"],p=[0,68,0,84,83,82,72,0,75,76,70,65,0,63,62,69,0,1,2,3,4,5,6,7,8,9,64,0,73,66,74,71,81,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,77,0,78,67,0,0,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,79,0,80,0,0],{CometD:function(e){var c,s,L,F,a,r=new be,l=this,B=e||"default",o=!1,u=new Oe,n="disconnected",M=0,d=null,h=0,t=[],p=!1,G=0,f={},g=0,i=null,v=[],y={},m={},H={},q=!1,b=!1,T=0,O=0,S=null,E={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 $(e,t){try{return e[t]}catch(e){}}function U(e){return Te.isString(e)}function w(e){return null!=e&&"function"==typeof e}function C(e,t){for(var n="";0<--t&&!(e>=Math.pow(10,t));)n+="0";return n+=e}function V(e,t){var n;window.console&&w(e=window.console[e])&&(n=new Date,[].splice.call(t,0,0,C(n.getHours(),2)+":"+C(n.getMinutes(),2)+":"+C(n.getSeconds(),2)+"."+C(n.getMilliseconds(),3)),e.apply(window.console,t))}function J(e){return new RegExp("(^https?://)?(((\\[[^\\]]+])|([^:/?#]+))(:(\\d+))?)?([^?#]*)(.*)?").exec(e)}function X(e){l._debug("Configuring cometd object with",e),U(e)&&(e={url:e}),E=l._mixin(!1,E,e=e||{});e=l.getURL();if(!e)throw"Missing required configuration parameter 'url' specifying the Bayeux server URL";var n,e=J(e),t=e[2],i=e[8],e=e[9];o=l._isCrossDomain(t),E.appendMessageTypeToURL&&(void 0!==e&&0<e.length?(l._info("Appending message type to URI "+i+e+" is not supported, disabling 'appendMessageTypeToURL' configuration"),E.appendMessageTypeToURL=!1):(e=(t=i.split("/")).length-1,i.match(/\/$/)&&--e,0<=t[e].indexOf(".")&&(l._info("Appending message type to URI "+i+" is not supported, disabling 'appendMessageTypeToURL' configuration"),E.appendMessageTypeToURL=!1))),window.Worker&&window.Blob&&window.URL&&E.useWorkerScheduler&&(t=(t=function(){var i={};self.onmessage=function(e){var t=e.data,n=i[t.id];switch(t.type){case"setTimeout":i[t.id]=self.setTimeout(function(){delete i[t.id],self.postMessage({id:t.id})},t.delay);break;case"clearTimeout":delete i[t.id],n&&self.clearTimeout(n);break;default:throw"Unknown command "+t.type}}}.toString()).substring(t.indexOf("{")+1,t.lastIndexOf("}")),e=new window.Blob([t],{type:"application/json"}),i=window.URL.createObjectURL(e),n=new window.Worker(i),r.setTimeout=function(e,t){e=r.register(e);return n.postMessage({id:e,type:"setTimeout",delay:t}),e},r.clearTimeout=function(e){r.unregister(e),n.postMessage({id:e,type:"clearTimeout"})},n.onmessage=function(e){e=e.data.id,e=r.unregister(e);e&&e()})}function W(e){var t;e&&(t=f[e.channel])&&t[e.id]&&(delete t[e.id],l._debug("Removed",e.listener?"listener":"subscription",e))}function Q(e){e&&!e.listener&&W(e)}function K(){for(var e in f)if(f.hasOwnProperty(e)){var t=f[e];if(t)for(var n in t)t.hasOwnProperty(n)&&Q(t[n])}}function j(e){n!==e&&(l._debug("Status",n,"->",e),n=e)}function R(){return"disconnecting"===n||"disconnected"===n}function A(){return""+ ++M}function Y(e,t,n,i,r){try{return t.call(e,i)}catch(e){t=l.onExtensionException;if(w(t)){l._debug("Invoking extension exception handler",n,e);try{t.call(l,e,n,r,i)}catch(e){l._info("Exception during execution of extension exception handler",n,e)}}else l._info("Exception during execution of extension",n,e);return i}}function z(e,t){var n=f[e];if(n)for(var i in n)if(n.hasOwnProperty(i)){i=n[i];if(i)try{i.callback.call(i.scope,t)}catch(e){var r=l.onListenerException;if(w(r)){l._debug("Invoking listener exception handler",i,e);try{r.call(l,e,i,i.listener,t)}catch(e){l._info("Exception during execution of listener exception handler",i,e)}}else l._info("Exception during execution of listener",i,t,e)}}}function _(e,t){z(e,t);for(var n=e.split("/"),i=n.length-1,r=i;0<r;--r){var s=n.slice(0,r).join("/")+"/*";r===i&&z(s,t),z(s+="*",t)}}function Z(){null!==i&&l.clearTimeout(i),i=null}function ee(e,t){Z();t=y.interval+t;l._debug("Function scheduled in",t,"ms, interval =",y.interval,"backoff =",g,e),i=l.setTimeout(e,t)}function I(e,t,n){for(var i,r=0;r<e.length;++r){var s=e[r],o=s.id;d&&(s.clientId=d),null!=(s=function(e){for(var t=v.length-1;0<=t&&null!=e;--t){var n=v[t],i=n.extension.outgoing;w(i)&&(e=void 0===(i=Y(n.extension,i,n.name,e,!0))?e:i)}return e}(s))?(s.id=o,e[r]=s):(delete m[o],e.splice(r--,1))}0!==e.length&&(t&&(S=e[0]),i=l.getURL(),E.appendMessageTypeToURL&&(i.match(/\/$/)||(i+="/"),n)&&(i+=n),l._debug("Send",n={url:i,sync:!1,messages:e,onSuccess:function(e){try{F.call(l,e)}catch(e){l._info("Exception during handling of messages",e)}},onFailure:function(e,t,n){try{var i=l.getTransport();n.connectionType=i?i.getType():"unknown",a.call(l,e,t,n)}catch(e){l._info("Exception during handling of failure",e)}}}),c.send(n,t))}function k(e){0<h||!0===p?t.push(e):I([e],!1)}function x(){g=0}function te(){var e=t;t=[],0<e.length&&I(e,!1)}function N(e){j("connecting"),ee(function(){var e;R()||(e={id:A(),channel:"/meta/connect",connectionType:c.getType()},b||(e.advice={timeout:0}),j("connecting"),l._debug("Connect sent",e),I([e],!0,"connect"),j("connected"))},e)}function ne(e){e&&(y=l._mixin(!1,{},E.advice,e),l._debug("New advice",y))}function D(e){Z(),e&&c&&c.abort(),o=!1,c=null,j("disconnected"),x(),b=q=!1,S=d=null,(T=h=0)<t.length&&(e=t,t=[],a.call(l,void 0,e,{reason:"Disconnected"}))}function ie(e,t,n){var i=l.onTransportException;if(w(i)){l._debug("Invoking transport exception handler",e,t,n);try{i.call(l,n,e,t)}catch(e){l._info("Exception during execution of transport exception handler",e)}}}function re(e,t){w(e)&&(t=e,e=void 0),d=null,K(),R()&&u.reset(!0),ne({}),p=!(h=0),s=e,L=t;var e="1.0",n=l.getURL(),i=u.findTransportTypes(e,o,n),r={id:A(),version:e,minimumVersion:e,channel:"/meta/handshake",supportedConnectionTypes:i,advice:{timeout:y.timeout,interval:y.interval}},r=l._mixin(!1,{},s,r);if((l._putCallback(r.id,t),!c)&&!(c=u.negotiateTransport(i,e,o,n)))throw t="Could not find initial transport among: "+u.getTransportTypes(),l._warn(t),t;l._debug("Initial transport is",c.getType()),j("handshaking"),l._debug("Handshake sent",r),I([r],!1,"handshake")}function se(t,n){try{t.call(l,n)}catch(e){t=l.onCallbackException;if(w(t)){l._debug("Invoking callback exception handler",e);try{t.call(l,e,n)}catch(e){l._info("Exception during execution of callback exception handler",e)}}else l._info("Exception during execution of message callback",e)}}function P(e){var t=l._getCallback([e.id]);w(t)&&(delete m[e.id],se(t,e))}function oe(e){var t=H[e.id];if(delete H[e.id],t){l._debug("Handling remote call response for",e,"with context",t);var n=t.timeout,n=(n&&l.clearTimeout(n),t.callback);if(w(n))return se(n,e),1}}function ae(e){l._debug("Transport failure handling",e),e.transport&&(c=e.transport),e.url&&c.setURL(e.url);var t,n=e.action,i=e.delay||0;switch(n){case"handshake":t=i,j("handshaking"),p=!0,ee(function(){re(s,L)},t);break;case"retry":N(i);break;case"none":D(!0);break;default:throw"Unknown action "+n}}function ce(e,t){P(e),_("/meta/handshake",e),_("/meta/unsuccessful",e),R()&&(t.action="none"),l.onTransportFailure.call(l,e,t,ae)}function le(e){return"disconnected"===n||S&&S.id===e.id&&(S=null,1)}function ue(e,t){_("/meta/connect",e),_("/meta/unsuccessful",e),R()&&(t.action="none"),l.onTransportFailure.call(l,e,t,ae)}function de(e){D(!0),P(e),_("/meta/disconnect",e),_("/meta/unsuccessful",e)}function he(e){var t,n=f[e.subscription];if(n)for(var i in n)n.hasOwnProperty(i)&&(t=n[i])&&!t.listener&&(delete n[i],l._debug("Removed failed subscription",t));P(e),_("/meta/subscribe",e),_("/meta/unsuccessful",e)}function pe(e){P(e),_("/meta/unsubscribe",e),_("/meta/unsuccessful",e)}function fe(e){oe(e)||(P(e),_("/meta/publish",e),_("/meta/unsuccessful",e))}function ge(e){var t;if(T=0,null!=(e=function(e){for(var t=0;t<v.length&&null!=e;++t){var n=v[t],i=n.extension.incoming;w(i)&&(e=void 0===(i=Y(n.extension,i,n.name,e,!1))?e:i)}return e}(e)))switch(ne(e.advice),e.channel){case"/meta/handshake":var n=e,i=l.getURL();if(n.successful){var r=l._isCrossDomain(J(i)[2]),r=u.negotiateTransport(n.supportedConnectionTypes,n.version,r,i);if(null===r)n.successful=!1,ce(n,{cause:"negotiation",action:"none",transport:null});else{c!==r&&(l._debug("Transport",c.getType(),"->",r.getType()),c=r),d=n.clientId,p=!1,te(),n.reestablish=q,q=!0,P(n),_("/meta/handshake",n),O=n["x-messages"]||0;var s=R()?"none":y.reconnect||"retry";switch(s){case"retry":x(),0===O?N(0):l._debug("Processing",O,"handshake-delivered messages");break;case"none":D(!0);break;default:throw"Unrecognized advice action "+s}}}else ce(n,{cause:"unsuccessful",action:y.reconnect||"handshake",transport:c});break;case"/meta/connect":i=e;if(le(i))if(b=i.successful){_("/meta/connect",i);var o=R()?"none":y.reconnect||"retry";switch(o){case"retry":x(),N(g);break;case"none":D(!1);break;default:throw"Unrecognized advice action "+o}}else ue(i,{cause:"unsuccessful",action:y.reconnect||"retry",transport:c});else l._debug("Mismatched /meta/connect reply",i);break;case"/meta/disconnect":(r=e).successful?(D(!1),P(r),_("/meta/disconnect",r)):de(r);break;case"/meta/subscribe":(n=e).successful?(P(n),_("/meta/subscribe",n)):he(n);break;case"/meta/unsubscribe":(t=e).successful?(P(t),_("/meta/unsubscribe",t)):pe(t);break;default:void 0!==(t=e).data?oe(t)||(_(t.channel,t),0<O&&0===--O&&(l._debug("Processed last handshake-delivered message"),N(0))):void 0===t.successful?l._warn("Unknown Bayeux Message",t):t.successful?(P(t),_("/meta/publish",t)):fe(t)}}function ve(e){var t=f[e];if(t)for(var n in t)if(t.hasOwnProperty(n)&&t[n])return 1}function ye(e,t){var n={scope:e,method:t};if(w(e))n.scope=void 0,n.method=e;else if(U(t)){if(!e)throw"Invalid scope "+e;if(n.method=e[t],!w(n.method))throw"Invalid callback "+t+" for scope "+e}else if(!w(t))throw"Invalid callback "+t;return n}function me(e,t,n,i){var t=ye(t,n),n=(l._debug("Adding",i?"listener":"subscription","on",e,"with scope",t.scope,"and callback",t.method),++G),t={id:n,channel:e,scope:t.scope,callback:t.method,listener:i},r=f[e];return r||(f[e]=r={}),r[n]=t,l._debug("Added",i?"listener":"subscription",t),t}this._mixin=function(e,t,n){for(var i=t||{},r=2;r<arguments.length;++r){var s,o,a=arguments[r];if(null!=a)for(var c in a)a.hasOwnProperty(c)&&(s=$(a,c),o=$(i,c),s!==t)&&void 0!==s&&(e&&"object"==typeof s&&null!==s?s instanceof Array?i[c]=this._mixin(e,o instanceof Array?o:[],s):(o="object"!=typeof o||o instanceof Array?{}:o,i[c]=this._mixin(e,o,s)):i[c]=s)}return i},this._warn=function(){V("warn",arguments)},this._info=function(){"warn"!==E.logLevel&&V("info",arguments)},this._debug=function(){"debug"===E.logLevel&&V("debug",arguments)},this._isCrossDomain=function(e){return!!(window.location&&window.location.host&&e)&&e!==window.location.host},this.send=k,this._getCallback=function(e){return m[e]},this._putCallback=function(e,t){var n=this._getCallback(e);return w(t)&&(m[e]=t),n},this.onTransportFailure=function(e,t,n){this._debug("Transport failure",t,"for",e);var i,r=this.getTransportRegistry(),s=this.getURL(),o=this._isCrossDomain(J(s)[2]),a=r.findTransportTypes("1.0",o,s);"none"===t.action?"/meta/handshake"!==e.channel||t.transport||(i="Could not negotiate transport, client=["+a+"], server=["+e.supportedConnectionTypes+"]",this._warn(i),ie(c.getType(),null,{reason:i,connectionType:c.getType(),transport:c})):(t.delay=this.getBackoffPeriod(),"/meta/handshake"===e.channel?(t.transport||(i=c?c.getType():null,(o=r.negotiateTransport(a,"1.0",o,s))?(s=o.getType(),this._debug("Transport",i,"->",s),ie(i,s,e.failure),t.action="handshake",t.transport=o):(this._warn("Could not negotiate transport, client=["+a+"]"),ie(i,null,e.failure),t.action="none")),"none"!==t.action&&this.increaseBackoffPeriod()):(s=(new Date).getTime(),0===T&&(T=s),"retry"===t.action&&(t.delay=this.increaseBackoffPeriod(),0<(o=y.maxInterval))&&y.timeout+y.interval+o<s-T+g&&(t.action="handshake"),"handshake"===t.action&&(t.delay=0,r.reset(!1),this.resetBackoffPeriod()))),n.call(l,t)},this.receive=ge,F=function(e){l._debug("Received",e);for(var t=0;t<e.length;++t)ge(e[t])},a=function(e,t,n){l._debug("handleFailure",e,t,n),n.transport=e;for(var i,r=0;r<t.length;++r){var s=t[r],o={id:s.id,successful:!1,channel:s.channel,failure:n};switch((n.message=s).channel){case"/meta/handshake":ce(o,{cause:"failure",action:"handshake",transport:null});break;case"/meta/connect":le(i=o)?(b=!1,ue(i,{cause:"failure",action:"retry",transport:null})):l._debug("Mismatched /meta/connect failure",i);break;case"/meta/disconnect":de(o);break;case"/meta/subscribe":o.subscription=s.subscription,he(o);break;case"/meta/unsubscribe":o.subscription=s.subscription,pe(o);break;default:fe(o)}}},this.registerTransport=function(e,t,n){n=u.add(e,t,n);return n&&(this._debug("Registered transport",e),w(t.registered))&&t.registered(e,this),n},this.unregisterTransport=function(e){var t=u.remove(e);return null!==t&&(this._debug("Unregistered transport",e),w(t.unregistered))&&t.unregistered(),t},this.unregisterTransports=function(){u.clear()},this.getTransportTypes=function(){return u.getTransportTypes()},this.findTransport=function(e){return u.find(e)},this.getTransportRegistry=function(){return u},this.configure=function(e){X.call(this,e)},this.init=function(e,t){this.configure(e),this.handshake(t)},this.handshake=function(e,t){if("disconnected"!==n)throw"Illegal state: handshaken";re(e,t)},this.disconnect=function(e,t){var n;R()||(w(e)&&(t=e,e=void 0),n={id:A(),channel:"/meta/disconnect"},e=this._mixin(!1,{},e,n),l._putCallback(e.id,t),j("disconnecting"),I([e],!1,"disconnect"))},this.startBatch=function(){++h,l._debug("Starting batch, depth",h)},this.endBatch=function(){if(--h,l._debug("Ending batch, depth",h),h<0)throw"Calls to startBatch() and endBatch() are not paired";0!==h||R()||p||te()},this.batch=function(e,t){e=ye(e,t);this.startBatch();try{e.method.call(e.scope),this.endBatch()}catch(e){throw this._info("Exception during execution of batch",e),this.endBatch(),e}},this.addListener=function(e,t,n){if(arguments.length<2)throw"Illegal arguments number: required 2, got "+arguments.length;if(U(e))return me(e,t,n,!0);throw"Illegal argument type: channel must be a string"},this.removeListener=function(e){if(!(e&&e.channel&&"id"in e))throw"Invalid argument: expected subscription, not "+e;W(e)},this.clearListeners=function(){f={}},this.subscribe=function(e,t,n,i,r){if(arguments.length<2)throw"Illegal arguments number: required 2, got "+arguments.length;if(!U(e))throw"Illegal argument type: channel must be a string";if(R())throw"Illegal state: disconnected";w(t)&&(r=i,i=n,n=t,t=void 0),w(i)&&(r=i,i=void 0);var s=!ve(e),t=me(e,t,n,!1);return s&&(n={id:A(),channel:"/meta/subscribe",subscription:e},s=this._mixin(!1,{},i,n),l._putCallback(s.id,r),k(s)),t},this.unsubscribe=function(e,t,n){if(arguments.length<1)throw"Illegal arguments number: required 1, got "+arguments.length;if(R())throw"Illegal state: disconnected";w(t)&&(n=t,t=void 0),this.removeListener(e);var e=e.channel;ve(e)||(e={id:A(),channel:"/meta/unsubscribe",subscription:e},t=this._mixin(!1,{},t,e),l._putCallback(t.id,n),k(t))},this.resubscribe=function(e,t){if(Q(e),e)return this.subscribe(e.channel,e.scope,e.callback,t)},this.clearSubscriptions=function(){K()},this.publish=function(e,t,n,i){if(arguments.length<1)throw"Illegal arguments number: required 1, got "+arguments.length;if(!U(e))throw"Illegal argument type: channel must be a string";if(/^\/meta\//.test(e))throw"Illegal argument: cannot publish to meta channels";if(R())throw"Illegal state: disconnected";w(t)?(i=t,t={},n=void 0):w(n)&&(i=n,n=void 0);e={id:A(),channel:e,data:t},t=this._mixin(!1,{},n,e);l._putCallback(t.id,i),k(t)},this.publishBinary=function(e,t,n,i,r){w(t)?(r=t,t=new ArrayBuffer(0),n=!0,i=void 0):w(n)?(r=n,n=!0,i=void 0):w(i)&&(r=i,i=void 0);this.publish(e,{meta:i,data:t,last:n},{ext:{binary:{}}},r)},this.remoteCall=function(e,t,n,i,r){if(arguments.length<1)throw"Illegal arguments number: required 1, got "+arguments.length;if(!U(e))throw"Illegal argument type: target must be a string";if(R())throw"Illegal state: disconnected";if(w(t)?(r=t,t={},n=E.maxNetworkDelay,i=void 0):w(n)?(r=n,n=E.maxNetworkDelay,i=void 0):w(i)&&(r=i,i=void 0),"number"!=typeof n)throw"Illegal argument type: timeout must be a number";e.match(/^\//)||(e="/"+e);var e={id:A(),channel:"/service"+e,data:t},s=this._mixin(!1,{},i,e),t={callback:r};0<n&&(t.timeout=l.setTimeout(function(){l._debug("Timing out remote call",s,"after",n,"ms"),fe({id:s.id,error:"406::timeout",successful:!1,failure:{message:s,reason:"Remote Call Timeout"}})},n),l._debug("Scheduled remote call timeout",s,"in",n,"ms")),H[s.id]=t,k(s)},this.remoteCallBinary=function(e,t,n,i,r,s){w(t)?(s=t,t=new ArrayBuffer(0),n=!0,i=void 0,r=E.maxNetworkDelay):w(n)?(s=n,n=!0,i=void 0,r=E.maxNetworkDelay):w(i)?(s=i,i=void 0,r=E.maxNetworkDelay):w(r)&&(s=r,r=E.maxNetworkDelay);this.remoteCall(e,{meta:i,data:t,last:n},r,{ext:{binary:{}}},s)},this.getStatus=function(){return n},this.isDisconnected=R,this.setBackoffIncrement=function(e){E.backoffIncrement=e},this.getBackoffIncrement=function(){return E.backoffIncrement},this.getBackoffPeriod=function(){return g},this.increaseBackoffPeriod=function(){return g<E.maxBackoff&&(g+=E.backoffIncrement),g},this.resetBackoffPeriod=function(){x()},this.setLogLevel=function(e){E.logLevel=e},this.registerExtension=function(e,t){if(arguments.length<2)throw"Illegal arguments number: required 2, got "+arguments.length;if(!U(e))throw"Illegal argument type: extension name must be a string";for(var n=!1,i=0;i<v.length;++i)if(v[i].name===e){n=!0;break}return n?(this._info("Could not register extension with name",e,"since another extension with the same name already exists"),!1):(v.push({name:e,extension:t}),this._debug("Registered extension",e),w(t.registered)&&t.registered(e,this),!0)},this.unregisterExtension=function(e){if(!U(e))throw"Illegal argument type: extension name must be a string";for(var t=!1,n=0;n<v.length;++n){var i=v[n];if(i.name===e){v.splice(n,1),t=!0,this._debug("Unregistered extension",e);i=i.extension;w(i.unregistered)&&i.unregistered();break}}return t},this.getExtension=function(e){for(var t=0;t<v.length;++t){var n=v[t];if(n.name===e)return n.extension}return null},this.getName=function(){return B},this.getClientId=function(){return d},this.getURL=function(){if(c){var e=c.getURL();if(e)return e;if(e=E.urls[c.getType()])return e}return E.url},this.getTransport=function(){return c},this.getConfiguration=function(){return this._mixin(!0,{},E)},this.getAdvice=function(){return this._mixin(!0,{},y)},this.setTimeout=function(t,e){return r.setTimeout(function(){try{l._debug("Invoking timed function",t),t()}catch(e){l._debug("Exception invoking timed function",t,e)}},e)},this.clearTimeout=function(e){r.clearTimeout(e)},window.WebSocket&&this.registerTransport("websocket",new Ue),this.registerTransport("long-polling",new Se),this.registerTransport("callback-polling",new Ee)},Transport:m,RequestTransport:n=function(){var i=new m,e=m.derive(i),r=0,s=null,o=[],a=[];function c(i,r){var e,s,o;this.transportSend(i,r),r.expired=!1,i.sync||(e=this.getConfiguration().maxNetworkDelay,s=e,!0===r.metaConnect&&(s+=this.getAdvice().timeout),this._debug("Transport",this.getType(),"waiting at most",s,"ms for the response, maxNetworkDelay",e),r.timeout=(o=this).setTimeout(function(){r.expired=!0;var e="Request "+r.id+" of transport "+o.getType()+" exceeded "+s+" ms max network delay",t={reason:e},n=r.xhr;t.httpCode=o.xhrStatus(n),o.abortXHR(n),o._debug(e),o.complete(r,!1,r.metaConnect),i.onFailure(n,i.messages,t)},s))}function l(e){var t=++r,n={id:t,metaConnect:!1,envelope:e};o.length<this.getConfiguration().maxConnections-1?(o.push(n),c.call(this,e,n)):(this._debug("Transport",this.getType(),"queueing request",t,"envelope",e),a.push([e,n]))}function u(e,t){var n,i,r,s=Te.inArray(e,o);0<=s&&o.splice(s,1),0<a.length&&(s=a.shift(),n=s[0],i=s[1],this._debug("Transport dequeued request",i.id),t?(this.getConfiguration().autoBatch&&function(e){for(;0<a.length;){var t=a[0],n=t[0],t=t[1];if(n.url!==e.url||n.sync!==e.sync)break;a.shift(),e.messages=e.messages.concat(n.messages),this._debug("Coalesced",n.messages.length,"messages from request",t.id)}}.call(this,n),l.call(this,n),this._debug("Transport completed request",e.id,n)):(r=this).setTimeout(function(){r.complete(i,!1,i.metaConnect);var e={reason:"Previous request failed"},t=i.xhr;e.httpCode=r.xhrStatus(t),n.onFailure(t,n.messages,e)},0))}return e.complete=function(e,t,n){n?function(e){if(e=e.id,this._debug("Transport",this.getType(),"/meta/connect complete, request",e),null!==s&&s.id!==e)throw"/meta/connect request mismatch, completing request "+e;s=null}.call(this,e):u.call(this,e,t)},e.transportSend=function(e,t){throw"Abstract"},e.transportSuccess=function(e,t,n){t.expired||(this.clearTimeout(t.timeout),this.complete(t,!0,t.metaConnect),n&&0<n.length?e.onSuccess(n):e.onFailure(t.xhr,e.messages,{httpCode:204}))},e.transportFailure=function(e,t,n){t.expired||(this.clearTimeout(t.timeout),this.complete(t,!1,t.metaConnect),e.onFailure(t.xhr,e.messages,n))},e.send=function(e,t){(t?function(e){if(null!==s)throw"Concurrent /meta/connect requests not allowed, request id="+s.id+" not yet completed";var t=++r,t=(this._debug("Transport",this.getType(),"/meta/connect send, request",t,"envelope",e),{id:t,metaConnect:!0,envelope:e});c.call(this,e,t),s=t}:l).call(this,e)},e.abort=function(){i.abort();for(var e=0;e<o.length;++e){var t=o[e];t&&(this._debug("Aborting request",t),this.abortXHR(t.xhr)||this.transportFailure(t.envelope,t,{reason:"abort"}))}var n=s;n&&(this._debug("Aborting /meta/connect request",n),this.abortXHR(n.xhr)||this.transportFailure(n.envelope,n,{reason:"abort"})),this.reset(!0)},e.reset=function(e){i.reset(e),s=null,o=[],a=[]},e.abortXHR=function(e){if(e)try{var t=e.readyState;return e.abort(),t!==window.XMLHttpRequest.UNSENT}catch(e){this._debug(e)}return!1},e.xhrStatus=function(e){if(e)try{return e.status}catch(e){this._debug(e)}return-1},e},LongPollingTransport:Se=function(){var t=new n,r=m.derive(t),a=!0;return r.accept=function(e,t,n){return a||!t},r.newXMLHttpRequest=function(){return new window.XMLHttpRequest},r.xhrSend=function(e){var t=r.newXMLHttpRequest(),n=(!function(e){try{e.context=r.context}catch(e){this._debug("Could not copy transport context into XHR",e)}}(t),t.withCredentials=!0,t.open("POST",e.url,!0!==e.sync),e.headers);if(n)for(var i in n)n.hasOwnProperty(i)&&t.setRequestHeader(i,n[i]);return t.setRequestHeader("Content-Type","application/json;charset=UTF-8"),t.onload=function(){200===t.status?e.onSuccess(t.responseText):e.onError(t.statusText)},t.onabort=t.onerror=function(){e.onError(t.statusText)},t.send(e.body),t},r.transportSend=function(i,r){this._debug("Transport",this.getType(),"sending request",r.id,"envelope",i);var s=this;try{var o=!0;r.xhr=this.xhrSend({transport:this,url:i.url,sync:i.sync,headers:this.getConfiguration().requestHeaders,body:JSON.stringify(i.messages),onSuccess:function(t){s._debug("Transport",s.getType(),"received response",t);var n=!1;try{var e=s.convertToMessages(t);0===e.length?(a=!1,s.transportFailure(i,r,{httpCode:204})):(n=!0,s.transportSuccess(i,r,e))}catch(e){s._debug(e),n||(a=!1,(t={exception:e}).httpCode=s.xhrStatus(r.xhr),s.transportFailure(i,r,t))}},onError:function(e,t){s._debug("Transport",s.getType(),"received error",e,t),a=!1;var n={reason:e,exception:t};n.httpCode=s.xhrStatus(r.xhr),o?s.setTimeout(function(){s.transportFailure(i,r,n)},0):s.transportFailure(i,r,n)}}),o=!1}catch(e){a=!1,this.setTimeout(function(){s.transportFailure(i,r,{exception:e})},0)}},r.reset=function(e){t.reset(e),a=!0},r},CallbackPollingTransport:Ee=function(){var e=new n,e=m.derive(e),s=0;function f(e,t,n){var i=this;return function(){i.transportFailure(e,t,"error",n)}}return e.accept=function(e,t,n){return!0},e.jsonpSend=function(t){var n=document.getElementsByTagName("head")[0],i=document.createElement("script"),r="_cometd_jsonp_"+s++,e=(window[r]=function(e){n.removeChild(i),delete window[r],t.onSuccess(e)},t.url),e=(e=(e+=e.indexOf("?")<0?"?":"&")+("jsonp="+r))+("&message="+encodeURIComponent(t.body));i.src=e,i.async=!0!==t.sync,i.type="application/javascript",i.onerror=function(e){t.onError("jsonp "+e.type)},n.appendChild(i)},e.transportSend=function(e,i){for(var r=this,t=0,n=e.messages.length,s=[];0<n;){var o=JSON.stringify(e.messages.slice(t,t+n)),o=e.url.length+encodeURI(o).length,a=this.getConfiguration().maxURILength;if(a<o){if(1===n)return o="Bayeux message too big ("+o+" bytes, max is "+a+") for transport "+this.getType(),void this.setTimeout(f.call(this,e,i,o),0);--n}else s.push(n),t+=n,n=e.messages.length-t}var c=e;if(1<s.length){var l=s[0];this._debug("Transport",this.getType(),"split",e.messages.length,"messages into",s.join(" + ")),(c=this._mixin(!1,{},e)).messages=e.messages.slice(0,l),c.onSuccess=e.onSuccess,c.onFailure=e.onFailure;for(var u=1;u<s.length;++u){var d=this._mixin(!1,{},e),h=l;l+=s[u],d.messages=e.messages.slice(h,l),d.onSuccess=e.onSuccess,d.onFailure=e.onFailure,this.send(d,i.metaConnect)}}this._debug("Transport",this.getType(),"sending request",i.id,"envelope",c);try{var p=!0;this.jsonpSend({transport:this,url:c.url,sync:c.sync,headers:this.getConfiguration().requestHeaders,body:JSON.stringify(c.messages),onSuccess:function(e){var t=!1;try{var n=r.convertToMessages(e);0===n.length?r.transportFailure(c,i,{httpCode:204}):(t=!0,r.transportSuccess(c,i,n))}catch(e){r._debug(e),t||r.transportFailure(c,i,{exception:e})}},onError:function(e,t){var n={reason:e,exception:t};p?r.setTimeout(function(){r.transportFailure(c,i,n)},0):r.transportFailure(c,i,n)}}),p=!1}catch(e){this.setTimeout(function(){r.transportFailure(c,i,{exception:e})},0)}},e},WebSocketTransport:Ue=function(){var c,n=new m,e=m.derive(n),l=!0,u=!1,d=!0,h=null,p=null,v=!1,y=null;function f(e,t){e&&(this.webSocketClose(e,t.code,t.reason),this.onClose(e,t))}function g(e){return e===p||e===h}function r(e,t,n){for(var i=[],r=0;r<t.messages.length;++r){var s=t.messages[r];s.id&&i.push(s.id)}e.envelopes[i.join(",")]=[t,n],this._debug("Transport",this.getType(),"stored envelope, envelopes",e.envelopes)}function s(t,n,e){for(var i=JSON.stringify(n.messages),i=(t.webSocket.send(i),this._debug("Transport",this.getType(),"sent",n,"/meta/connect =",e),this.getConfiguration().maxNetworkDelay),r=i,s=(e&&(r+=this.getAdvice().timeout,v=!0),this),o=[],a=0;a<n.messages.length;++a)!function(){var e=n.messages[a];e.id&&(o.push(e.id),t.timeouts[e.id]=s.setTimeout(function(){c._debug("Transport",s.getType(),"timing out message",e.id,"after",r,"on",t),f.call(s,t,{code:1e3,reason:"Message Timeout"})},r))}();this._debug("Transport",this.getType(),"waiting at most",r,"ms for messages",o,"maxNetworkDelay",i,", timeouts:",t.timeouts)}function i(t,e,n){try{null===t?(t=p||{envelopes:{},timeouts:{}},r.call(this,t,e,n),function(t){if(!p){var e=c.getURL().replace(/^http/,"ws");this._debug("Transport",this.getType(),"connecting to URL",e);try{var n=c.getConfiguration().protocol;t.webSocket=n?new window.WebSocket(e,n):new window.WebSocket(e),p=t}catch(e){throw l=!1,this._debug("Exception while creating WebSocket object",e),e}d=!1!==c.getConfiguration().stickyReconnect;var i=this,r=c.getConfiguration().connectTimeout,s=(0<r&&(t.connectTimer=this.setTimeout(function(){c._debug("Transport",i.getType(),"timed out while connecting to URL",e,":",r,"ms"),f.call(i,t,{code:1e3,reason:"Connect Timeout"})},r)),function(e){c._debug("WebSocket onclose",t,e=e||{code:1e3},"connecting",p,"current",h),t.connectTimer&&i.clearTimeout(t.connectTimer),i.onClose(t,e)});t.webSocket.onopen=function(){c._debug("WebSocket onopen",t),t.connectTimer&&i.clearTimeout(t.connectTimer),g(t)?(h=t,u=!(p=null),i.onOpen(t)):(c._warn("Closing extra WebSocket connection",this,"active connection",h),f.call(i,t,{code:1e3,reason:"Extra Connection"}))},t.webSocket.onclose=s,t.webSocket.onerror=function(){s({code:1e3,reason:"Error"})},t.webSocket.onmessage=function(e){c._debug("WebSocket onmessage",e,t),i.onMessage(t,e)},this._debug("Transport",this.getType(),"configured callbacks on",t)}}.call(this,t)):(r.call(this,t,e,n),s.call(this,t,e,n))}catch(e){var i=this;this.setTimeout(function(){f.call(i,t,{code:1e3,reason:"Exception",exception:e})},0)}}return e.reset=function(e){n.reset(e),e&&(u=!1),p=h=null,v=!(d=l=!0)},e._notifySuccess=function(e,t){e.call(this,t)},e._notifyFailure=function(e,t,n,i){e.call(this,t,n,i)},e.onOpen=function(e){var t,n,i,r=e.envelopes;for(t in this._debug("Transport",this.getType(),"opened",e,"pending messages",r),r)r.hasOwnProperty(t)&&(n=(i=r[t])[0],i=i[1],y=n.onSuccess,s.call(this,e,n,i))},e.onMessage=function(e,t){this._debug("Transport",this.getType(),"received websocket message",t,e);for(var n=!1,i=this.convertToMessages(t.data),r=[],s=0;s<i.length;++s){var o,a=i[s];(/^\/meta\//.test(a.channel)||void 0===a.data)&&a.id&&(r.push(a.id),o=e.timeouts[a.id])&&(this.clearTimeout(o),delete e.timeouts[a.id],this._debug("Transport",this.getType(),"removed timeout for message",a.id,", timeouts",e.timeouts)),"/meta/connect"===a.channel&&(v=!1),"/meta/disconnect"!==a.channel||v||(n=!0)}for(var c=!1,l=e.envelopes,u=0;u<r.length;++u){var d,h=r[u];for(d in l)if(l.hasOwnProperty(d)){var p=d.split(","),f=Te.inArray(h,p);if(0<=f){c=!0,p.splice(f,1);var f=l[d][0],g=l[d][1];delete l[d],0<p.length&&(l[p.join(",")]=[f,g]);break}}}c&&this._debug("Transport",this.getType(),"removed envelope, envelopes",l),this._notifySuccess(y,i),n&&this.webSocketClose(e,1e3,"Disconnect")},e.onClose=function(e,t){this._debug("Transport",this.getType(),"closed",e,t),g(e)&&(l=d&&u,h=p=null);var n,i=e.timeouts;for(n in e.timeouts={},i)i.hasOwnProperty(n)&&this.clearTimeout(i[n]);var r,s,o,a=e.envelopes;for(r in e.envelopes={},a)a.hasOwnProperty(r)&&(s=a[r][0],a[r][1]&&(v=!1),o={websocketCode:t.code,reason:t.reason},t.exception&&(o.exception=t.exception),this._notifyFailure(s.onFailure,e,s.messages,o))},e.registered=function(e,t){n.registered(e,t),c=t},e.accept=function(e,t,n){return this._debug("Transport",this.getType(),"accept, supported:",l),l&&!!window.WebSocket&&!1!==c.websocketEnabled},e.send=function(e,t){this._debug("Transport",this.getType(),"sending",e,"/meta/connect =",t),i.call(this,h,e,t)},e.webSocketClose=function(e,t,n){try{e.webSocket&&e.webSocket.close(t,n)}catch(e){this._debug(e)}},e.abort=function(){n.abort(),f.call(this,h,{code:1e3,reason:"Abort"}),this.reset(!0)},e},Utils:Te,Z85:{encode:function(e){var t=null;if(e instanceof ArrayBuffer?t=e:e.buffer instanceof ArrayBuffer?t=e.buffer:Array.isArray(e)&&(t=new Uint8Array(e).buffer),null==t)throw"Cannot Z85 encode "+e;for(var n=t.byteLength,e=n%4,i=4-(0==e?4:e),r=new DataView(t),s="",o=0,a=0;a<n+i;++a){var c=n<=a,o=256*o+(c?0:r.getUint8(a));if((a+1)%4==0){for(var l,u=52200625,d=5;0<d;--d)(!c||i<d)&&(l=Math.floor(o/u)%85,s+=h[l]),u/=85;o=0}}return s},decode:function(e){for(var t=e.length%5,n=5-(0==t?5:t),i=0;i<n;++i)e+=h[h.length-1];for(var r=e.length,t=new ArrayBuffer(4*r/5-n),s=new DataView(t),o=0,a=0,c=0,l=0;l<r;++l){var u=e.charCodeAt(a++)-32,o=85*o+p[u];if(a%5==0){for(var d=16777216;1<=d;)c<s.byteLength&&s.setUint8(c++,Math.floor(o/d)%256),d/=256;o=0}}return t}}})}),M={CometD:i.CometD,default:i}.CometD;(S=m=m||{}).HANDSHAKE="/meta/handshake",S.CONNECT="/meta/connect",S.SUBSCRIBE="/meta/subscribe",S.UNSUBSCRIBE="/meta/unsubscribe";class b{constructor(e,t="/notification/realtime",n){this.client=e,this.url=t,this.metaHandshake=e=>{if(!e.successful)throw new Error("Handshake failed")},this.cometd=new M({}),this.cometd.websocketEnabled=!0,this.cometd.addListener(m.HANDSHAKE,n||this.metaHandshake)}subscribe(e,t){return this.checkConnection(),this.cometd.subscribe(e,t)}unsubscribe(e){return this.cometd.unsubscribe(e)}addHandshakeListener(e){return this.cometd.addListener(m.HANDSHAKE,e)}addConnectListener(e){return this.cometd.addListener(m.CONNECT,e)}removeListener(e){return this.cometd.removeListener(e)}resubscribe(e){return this.cometd.resubscribe(e)}disconnect(e=void 0){this.cometd.disconnect(e)}isDisconnected(){return this.cometd.isDisconnected()}checkConnection(){var e,{cometd:t,client:n,url:i}=this;t.isDisconnected()&&(e=n.getFetchOptions()["headers"],i={url:n.getUrl(i),requestHeaders:e},t.configure(i),this.handshake(n.getCometdHandshake()))}handshake(e){this.cometd.handshake(e,void 0)}}class T extends e{constructor(){super(...arguments),this.baseUrl="event",this.listUrl="events",this.propertyName="events",this.channel="/events/*"}detail(e){const t=Object.create(null,{detail:{get:()=>super.detail}});return a(this,void 0,void 0,function*(){return t.detail.call(this,e)})}create(e){const t=Object.create(null,{create:{get:()=>super.create}});return a(this,void 0,void 0,function*(){return t.create.call(this,e)})}update(e){const t=Object.create(null,{update:{get:()=>super.update}});return a(this,void 0,void 0,function*(){return t.update.call(this,e)})}list(e={}){const t=Object.create(null,{list:{get:()=>super.list}});return a(this,void 0,void 0,function*(){return t.list.call(this,e)})}delete(e){const t=Object.create(null,{delete:{get:()=>super.delete}});return a(this,void 0,void 0,function*(){return t.delete.call(this,e)})}}var O,S,E=("object"==typeof self?self:window).FormData;class G extends e{constructor(){super(...arguments),this.baseUrl="event",this.listUrl="events"}upload(n,i){return a(this,void 0,void 0,function*(){var e=this.getDetailUrl(i),t=new E,e=(t.append("file",n),yield this.fetch(e,{method:"POST",body:t,headers:{accept:"application/json"}})),t=yield e.json();return{res:e,data:t}})}download(t){return a(this,void 0,void 0,function*(){var e=this.getDetailUrl(t);return yield this.fetch(e)})}delete(e){const t=Object.create(null,{delete:{get:()=>super.delete}});return a(this,void 0,void 0,function*(){return t.delete.call(this,e)})}getDetailUrl(e){let t;return t="object"==typeof e&&e.id?e.id:e,`${this.listUrl}/${t}/binaries`}}class U extends e{constructor(){super(...arguments),this.baseUrl="inventory",this.listUrl="binaries",this.propertyName="managedObjects"}create(r,s={}){return a(this,void 0,void 0,function*(){var e=this.listUrl,t=new E;let n,i;s.fileName&&(n=s.fileName,delete s.fileName),s.fileType&&(i=s.fileType,delete s.fileType),n=n||"bin","undefined"!=typeof File&&r instanceof File&&(n=r.name,i=r.type),s.name||(s.name=n),s.type||(s.type=i||"c8y_upload"),t.append("file",r,n),t.append("object",JSON.stringify(s));e=yield this.fetch(e,{method:"POST",body:t,headers:{accept:"application/json"}}),t=yield e.json();return{res:e,data:t}})}list(e={}){const t=Object.create(null,{list:{get:()=>super.list}});return a(this,void 0,void 0,function*(){return t.list.call(this,e)})}delete(e){const t=Object.create(null,{delete:{get:()=>super.delete}});return a(this,void 0,void 0,function*(){return t.delete.call(this,e)})}download(t,n){return a(this,void 0,void 0,function*(){var e=this.getDetailUrl(t);return yield this.fetch(e,n)})}createWithProgress(e,t,n={}){var i=`/${this.baseUrl}/`+this.listUrl,r=new E;let s,o;n.fileName&&(s=n.fileName,delete n.fileName),n.fileType&&(o=n.fileType,delete n.fileType),s=s||"bin","undefined"!=typeof File&&e instanceof File&&(s=e.name,o=e.type),n.name||(n.name=s),n.type||(n.type=o||"c8y_upload"),r.append("file",e,s),r.append("object",JSON.stringify(n));let a;"function"==typeof r.getHeaders&&(a=r.getHeaders());var c=this.client.getFetchOptions().headers,l=(Object.assign(c,{accept:"application/json"},a),new XMLHttpRequest);l.open("POST",i,!0);for(const d in c)c.hasOwnProperty(d)&&l.setRequestHeader(d,c[d]);l.upload.addEventListener("progress",t);let u;return u="function"==typeof r.getBuffer?r.getBuffer():r,l.send(u),l}getXMLHttpResponse(n){return new Promise((e,t)=>{n.addEventListener("loadend",()=>{4!==n.readyState||200!==n.status&&201!==n.status?t(n.responseText?{data:JSON.parse(n.responseText)}:"Could not upload file."):e(JSON.parse(n.responseText))})})}getIdFromUrl(e){var t;if(e)return t=new RegExp("\\/inventory\\/binaries\\/(\\d+)|\\/inventory\\/managedObjects\\/(\\d+)"),(e=e.match(t))&&(e[1]||e[2])}}r.ChildType=void 0,(i=r.ChildType||(r.ChildType={})).ASSETS="childAssets",i.DEVICES="childDevices",i.ADDITIONS="childAdditions";class w extends e{constructor(e,t){super(e,t),this.baseUrl="inventory",this.listUrl="managedObjects",this.propertyName="managedObjects",this.channel="/managedobjects/*",this.inventoriesQueryParamName="query",this.devicesQueryParamName="q",this.queriesUtil=new y,this.binary=new U(e)}detail(e,t={}){const n=Object.create(null,{detail:{get:()=>super.detail}});return a(this,void 0,void 0,function*(){return n.detail.call(this,e,t)})}create(e){const t=Object.create(null,{create:{get:()=>super.create}});return a(this,void 0,void 0,function*(){return t.create.call(this,e)})}update(e){const t=Object.create(null,{update:{get:()=>super.update}});return a(this,void 0,void 0,function*(){return t.update.call(this,e)})}list(e={}){const t=Object.create(null,{list:{get:()=>super.list}});return a(this,void 0,void 0,function*(){return t.list.call(this,e)})}listQuery(e,t={}){const n=Object.create(null,{list:{get:()=>super.list}});return a(this,void 0,void 0,function*(){return t[this.inventoriesQueryParamName]=this.queriesUtil.buildQuery(e),n.list.call(this,t)})}listQueryDevices(e,t={}){const n=Object.create(null,{list:{get:()=>super.list}});return a(this,void 0,void 0,function*(){return t[this.devicesQueryParamName]=this.queriesUtil.buildQuery(e),n.list.call(this,t)})}delete(e,t={}){const n=Object.create(null,{delete:{get:()=>super.delete}});return a(this,void 0,void 0,function*(){return n.delete.call(this,e,t)})}childAdditionsList(e,t={}){return a(this,void 0,void 0,function*(){return this.listChildren(r.ChildType.ADDITIONS,e,t)})}childAdditionsCreate(e,t){return a(this,void 0,void 0,function*(){return this.createChild(r.ChildType.ADDITIONS,e,t)})}childAdditionsAdd(e,t){return a(this,void 0,void 0,function*(){return this.addChild(r.ChildType.ADDITIONS,e,t)})}childAdditionsRemove(e,t){return a(this,void 0,void 0,function*(){return this.removeChild(r.ChildType.ADDITIONS,e,t)})}childAssetsList(e,t={}){return a(this,void 0,void 0,function*(){return this.listChildren(r.ChildType.ASSETS,e,t)})}childAssetsCreate(e,t){return a(this,void 0,void 0,function*(){return this.createChild(r.ChildType.ASSETS,e,t)})}childAssetsAdd(e,t){return a(this,void 0,void 0,function*(){return this.addChild(r.ChildType.ASSETS,e,t)})}childAssetsBulkAdd(e,t){return a(this,void 0,void 0,function*(){return this.addChildBulk(r.ChildType.ASSETS,e,t)})}childAssetsRemove(e,t){return a(this,void 0,void 0,function*(){return this.removeChild(r.ChildType.ASSETS,e,t)})}childDevicesList(e,t={}){return a(this,void 0,void 0,function*(){return this.listChildren(r.ChildType.DEVICES,e,t)})}childDevicesCreate(e,t){return a(this,void 0,void 0,function*(){return this.createChild(r.ChildType.DEVICES,e,t)})}childDevicesAdd(e,t){return a(this,void 0,void 0,function*(){return this.addChild(r.ChildType.DEVICES,e,t)})}childDevicesRemove(e,t){return a(this,void 0,void 0,function*(){return this.removeChild(r.ChildType.DEVICES,e,t)})}getSupportedMeasurements(e){return a(this,void 0,void 0,function*(){return this.getSupportedMeasurementDetails(e,"supportedMeasurements")})}getSupportedSeries(e){return a(this,void 0,void 0,function*(){return this.getSupportedMeasurementDetails(e,"supportedSeries")})}getMeasurementsAndSeries(i){return a(this,void 0,void 0,function*(){var[e,t]=yield Promise.all([this.getSupportedMeasurements(i),this.getSupportedSeries(i)]);const n=e.sort((e,t)=>t.length-e.length);return t.map(t=>{var e=n.find(e=>0===t.indexOf(e+"."));return{fragment:e,series:t.replace(e+".","")}}).filter(e=>!!e.fragment)})}assetKPIsList(e,t={}){return a(this,void 0,void 0,function*(){return this.listKPIs(e,t)})}listKPIs(n,i={}){return a(this,void 0,void 0,function*(){var e=this.getChildrenUrl("kpis",n),e=yield this.fetch(e,this.changeFetchOptions({headers:{accept:"application/json"},params:i},e)),t=yield e.json();return{res:e,data:t[this.propertyName],paging:this.getPaging(t,i)}})}onBeforeUpdate(e){return delete e.lastUpdated,e}onBeforeCreate(e){return delete e.id,delete e.lastUpdated,e}getChildrenUrl(e,t){return this.getDetailUrl(t)+"/"+e}getChildUrl(e,t,n){t=this.getIdString(t);return this.getChildrenUrl(e,n)+"/"+t}listChildren(i,r,s={}){return a(this,void 0,void 0,function*(){var e=this.getChildrenUrl(i,r),e=yield this.fetch(e,{headers:{"content-type":"application/json"},params:s}),t=yield e.json(),n=t.references.map(e=>e.managedObject),t=this.getPaging(t,s);return t.list=e=>this.listChildren(i,r,e),{res:e,data:n,paging:t}})}createChild(i,r,s){return a(this,void 0,void 0,function*(){var e=this.getChildrenUrl(i,s),t=JSON.stringify(this.onBeforeCreate(r)),n={"content-type":this.mimeType("managedObject"),accept:"application/json"},e=yield this.fetch(e,{method:"POST",body:t,headers:n}),t=yield e.json();return{res:e,data:t}})}addChild(i,r,s){return a(this,void 0,void 0,function*(){var e=this.getChildrenUrl(i,s),t=this.getIdString(r),t=JSON.stringify({managedObject:{id:String(t)}}),n={accept:"application/json","content-type":this.mimeType("managedObjectReference")},e=yield this.fetch(e,{method:"POST",body:t,headers:n}),t=yield e.json();return{res:e,data:t.managedObject}})}addChildBulk(i,r,s){return a(this,void 0,void 0,function*(){var e=this.getChildrenUrl(i,s),t=r.map(e=>({managedObject:{id:this.getIdString(e)}})),t=JSON.stringify({references:t}),n={accept:"application/json","content-type":this.mimeType("managedObjectReferenceCollection")},e=yield this.fetch(e,{method:"POST",body:t,headers:n}),t=(yield e.json()).references;return{res:e,data:t.map(e=>e.managedObject)}})}removeChild(t,n,i){return a(this,void 0,void 0,function*(){var e=this.getIdString(n),e=this.getChildrenUrl(t,i)+"/"+e;return{res:yield this.fetch(e,{method:"DELETE",headers:{accept:"application/json"}}),data:null}})}getSupportedMeasurementDetails(t,n="supportedSeries"){return a(this,void 0,void 0,function*(){var e=this.getDetailUrl(t)+"/"+n,e=(this.getIdString(t),yield(yield this.fetch(e,{headers:{accept:"application/json"}})).json());return e.c8y_SupportedMeasurements||e.c8y_SupportedSeries})}}class C extends e{constructor(){super(...arguments),this.baseUrl="measurement",this.listUrl="measurements",this.propertyName="measurements",this.channel="/measurements/*"}detail(e){const t=Object.create(null,{detail:{get:()=>super.detail}});return a(this,void 0,void 0,function*(){return t.detail.call(this,e)})}create(e){const t=Object.create(null,{create:{get:()=>super.create}});return a(this,void 0,void 0,function*(){return t.create.call(this,this.onBeforeCreate(e))})}list(e={}){const t=Object.create(null,{list:{get:()=>super.list}});return a(this,void 0,void 0,function*(){return t.list.call(this,e)})}delete(e){const t=Object.create(null,{delete:{get:()=>super.delete}});return a(this,void 0,void 0,function*(){return t.delete.call(this,e)})}listSeries(n){return a(this,void 0,void 0,function*(){var e=`${this.baseUrl}/${this.listUrl}/series`,e=yield this.client.fetch(e,{params:n}),t=yield e.json();return{res:e,data:t}})}onBeforeCreate(e){var t;return e.time||(e.time=(new Date).toISOString()),e.type||(e.type="c8y_Measurement"),e.sourceId&&(t=e["sourceId"],delete e.sourceId,e.source||(e.source={id:String(t)})),e}}r.aggregationType=void 0,(S=r.aggregationType||(r.aggregationType={})).MINUTELY="MINUTELY",S.HOURLY="HOURLY",S.DAILY="DAILY";class j extends e{constructor(){super(...arguments),this.baseUrl="alarm",this.listUrl="alarms",this.propertyName="alarms",this.channel="/alarms/*"}detail(e){const t=Object.create(null,{detail:{get:()=>super.detail}});return a(this,void 0,void 0,function*(){return t.detail.call(this,e)})}create(e){const t=Object.create(null,{create:{get:()=>super.create}});return a(this,void 0,void 0,function*(){return t.create.call(this,e)})}update(e){const t=Object.create(null,{update:{get:()=>super.update}});return a(this,void 0,void 0,function*(){return t.update.call(this,e)})}list(e={}){const t=Object.create(null,{list:{get:()=>super.list}});return a(this,void 0,void 0,function*(){return t.list.call(this,e)})}}r.AlarmStatus=void 0,(i=r.AlarmStatus||(r.AlarmStatus={}))[i.ACKNOWLEDGED="ACKNOWLEDGED"]="ACKNOWLEDGED",i[i.CLEARED="CLEARED"]="CLEARED",i[i.ACTIVE="ACTIVE"]="ACTIVE";class R extends e{constructor(){super(...arguments),this.baseUrl="devicecontrol",this.listUrl="operations",this.propertyName="operations"}detail(e){const t=Object.create(null,{detail:{get:()=>super.detail}});return a(this,void 0,void 0,function*(){return t.detail.call(this,e)})}create(e){const t=Object.create(null,{create:{get:()=>super.create}});return a(this,void 0,void 0,function*(){return t.create.call(this,e)})}update(e){const t=Object.create(null,{update:{get:()=>super.update}});return a(this,void 0,void 0,function*(){return t.update.call(this,e)})}list(e={}){const t=Object.create(null,{list:{get:()=>super.list}});return a(this,void 0,void 0,function*(){return t.list.call(this,e)})}}class H extends e{constructor(){super(...arguments),this.baseUrl="devicecontrol",this.listUrl="bulkoperations",this.propertyName="bulkOperations"}detail(e){const t=Object.create(null,{detail:{get:()=>super.detail}});return a(this,void 0,void 0,function*(){return t.detail.call(this,e)})}create(e){const t=Object.create(null,{create:{get:()=>super.create}});return a(this,void 0,void 0,function*(){return t.create.call(this,e)})}update(e){const t=Object.create(null,{update:{get:()=>super.update}});return a(this,void 0,void 0,function*(){return t.update.call(this,e)})}list(e={}){const t=Object.create(null,{list:{get:()=>super.list}});return a(this,void 0,void 0,function*(){return t.list.call(this,e)})}delete(e){const t=Object.create(null,{delete:{get:()=>super.delete}});return a(this,void 0,void 0,function*(){return t.delete.call(this,e)})}}r.OperationBulkStatus=void 0,(S=r.OperationBulkStatus||(r.OperationBulkStatus={}))[S.ACTIVE="ACTIVE"]="ACTIVE",S[S.IN_PROGRESS="IN_PROGRESS"]="IN_PROGRESS",S[S.COMPLETED="COMPLETED"]="COMPLETED",S[S.DELETED="DELETED"]="DELETED",r.OperationBulkGeneralStatus=void 0,(i=r.OperationBulkGeneralStatus||(r.OperationBulkGeneralStatus={}))[i.SCHEDULED="SCHEDULED"]="SCHEDULED",i[i.EXECUTING="EXECUTING"]="EXECUTING",i[i.EXECUTING_WITH_ERROR="EXECUTING_WITH_ERROR"]="EXECUTING_WITH_ERROR",i[i.CANCELED="CANCELED"]="CANCELED",i[i.FAILED="FAILED"]="FAILED",i[i.SUCCESSFUL="SUCCESSFUL"]="SUCCESSFUL",i[i.DELETED="DELETED"]="DELETED",i[i.INCORRECT="INCORRECT"]="INCORRECT",r.OperationStatus=void 0,(S=r.OperationStatus||(r.OperationStatus={}))[S.PENDING="PENDING"]="PENDING",S[S.EXECUTING="EXECUTING"]="EXECUTING",S[S.SUCCESSFUL="SUCCESSFUL"]="SUCCESSFUL",S[S.FAILED="FAILED"]="FAILED";class A extends e{constructor(){super(...arguments),this.baseUrl="tenant",this.listUrl="tenants",this.currentTenantUrl="currentTenant",this.propertyName="tenants",this.fetchOptions={method:"PUT",body:"{}",headers:{"content-type":"application/json",accept:"application/json"}}}detail(e){const t=Object.create(null,{detail:{get:()=>super.detail}});return a(this,void 0,void 0,function*(){return t.detail.call(this,e)})}create(e){const t=Object.create(null,{create:{get:()=>super.create}});return a(this,void 0,void 0,function*(){return t.create.call(this,e)})}update(e){const t=Object.create(null,{update:{get:()=>super.update}});return a(this,void 0,void 0,function*(){return t.update.call(this,e)})}list(e={}){const t=Object.create(null,{list:{get:()=>super.list}});return a(this,void 0,void 0,function*(){return t.list.call(this,e)})}delete(e){const t=Object.create(null,{delete:{get:()=>super.delete}});return a(this,void 0,void 0,function*(){return t.delete.call(this,e)})}current(){return a(this,void 0,void 0,function*(){var e=yield this.fetch(this.currentTenantUrl,{headers:{"content-type":"application/json"}}),t=yield e.json();return{res:e,data:t}})}enableSupportUser(){return a(this,void 0,void 0,function*(){return{res:yield this.fetch("support-user/enable",this.fetchOptions),data:null}})}disableSupportUser(){return a(this,void 0,void 0,function*(){return{res:yield this.fetch("support-user/disable",this.fetchOptions),data:null}})}currentTenantType(){return a(this,void 0,void 0,function*(){var e=yield this.current();return e.data.customProperties&&"TRIAL"===e.data.customProperties.tenantType?"TRIAL":"REGULAR"})}getTfaSettings(t){return a(this,void 0,void 0,function*(){var e=this.getIdString(t);return yield(yield this.fetch(`tenants/${e}/tfa`)).json()})}subscribeApplication(i,r){return a(this,void 0,void 0,function*(){var e=this.getIdString(i),t=r.id,e=`tenants/${e}/applications`,t=JSON.stringify({application:{id:t,self:r.self}}),n={"content-type":this.mimeType("applicationReference")};return{res:yield this.fetch(e,this.changeFetchOptions({method:"POST",body:t,headers:n},e)),data:null}})}unsubscribeApplication(t,n){return a(this,void 0,void 0,function*(){var e=`tenants/${this.getIdString(t)}/applications/`+n.id;return{res:yield this.fetch(e,this.changeFetchOptions({method:"DELETE"},e)),data:null}})}getIdString(e){return e.id||e.name}onBeforeCreate(e){return e}}r.TenantStatus=void 0,(i=r.TenantStatus||(r.TenantStatus={}))[i.ACTIVE="ACTIVE"]="ACTIVE",i[i.SUSPENDED="SUSPENDED"]="SUSPENDED",r.TfaStrategy=void 0,(S=r.TfaStrategy||(r.TfaStrategy={})).TOTP="TOTP",S.SMS="SMS";class q extends e{constructor(e,t){super(t),this.listUrl="inventory",this.currenUserUrl="currentUser",this.propertyName="inventoryAssignments",this.baseUrl=`user/${e}/roles`}detail(e){const t=Object.create(null,{detail:{get:()=>super.detail}});return a(this,void 0,void 0,function*(){return t.detail.call(this,e)})}create(e){const t=Object.create(null,{create:{get:()=>super.create}});return a(this,void 0,void 0,function*(){return t.create.call(this,e)})}update(e){const t=Object.create(null,{update:{get:()=>super.update}});return a(this,void 0,void 0,function*(){return t.update.call(this,e)})}list(e={}){const t=Object.create(null,{list:{get:()=>super.list}});return a(this,void 0,void 0,function*(){return t.list.call(this,e)})}delete(e){const t=Object.create(null,{delete:{get:()=>super.delete}});return a(this,void 0,void 0,function*(){return t.delete.call(this,e)})}}class _ extends e{constructor(){super(...arguments),this.baseUrl="user",this.currentUserUrl="currentUser",this.passwordResetUrl="passwordReset",this.currentUserPhoneUrl="currentUserPhone",this.verifyTFACodeUrl="pin",this.totpCurrentUserURL=this.currentUserUrl+"/totpSecret",this.verifyTOTPCodeUrl=this.totpCurrentUserURL+"/verify",this.activateTOTPCodeUrl=this.totpCurrentUserURL+"/activity",this.revokeTOTPSecretUrl="totpSecret/revoke",this.propertyName="users"}get listUrl(){return this.client.tenant+"/users"}get newsletterEmailsUrl(){return this.client.tenant+"/users/newsletterEmails"}get currentUserPasswordUrl(){return this.currentUserUrl+"/password"}get revokeAllTokensUrl(){return`/logout/${this.client.tenant}/allUsers`}detail(e){const t=Object.create(null,{detail:{get:()=>super.detail}});return a(this,void 0,void 0,function*(){return t.detail.call(this,e)})}create(e){const t=Object.create(null,{create:{get:()=>super.create}});return a(this,void 0,void 0,function*(){return t.create.call(this,e)})}update(e){const t=Object.create(null,{update:{get:()=>super.update}});return a(this,void 0,void 0,function*(){return t.update.call(this,e)})}list(e={}){const t=Object.create(null,{list:{get:()=>super.list}});return a(this,void 0,void 0,function*(){return t.list.call(this,e)})}delete(e){const t=Object.create(null,{delete:{get:()=>super.delete}});return a(this,void 0,void 0,function*(){return t.delete.call(this,e)})}inventoryAssignment(e){return new q(this.getDetailUrl(e),this.client)}current(){return a(this,void 0,void 0,function*(){var e=yield this.fetch(this.currentUserUrl,{headers:{"content-type":"application/json",Accept:"application/vnd.com.nsn.cumulocity.user+json;"}}),t=yield e.json();return{res:e,data:t}})}currentWithEffectiveRoles(){return a(this,void 0,void 0,function*(){var e=yield this.fetch(this.currentUserUrl,{headers:{"content-type":"application/json",Accept:"application/vnd.com.nsn.cumulocity.currentUser+json;"}}),t=yield e.json();return{res:e,data:t}})}updateCurrent(n){return a(this,void 0,void 0,function*(){var e="application/vnd.com.nsn.cumulocity.user+json",e={"content-type":e,Accept:e},t=JSON.stringify(this.onBeforeUpdate(n)),e=yield this.fetch(this.currentUserUrl,{headers:e,body:t,method:"PUT"}),t=yield e.json();return{res:e,data:t}})}sendPasswordResetMail(i,r){return a(this,void 0,void 0,function*(){var e=this.passwordResetUrl,t=r?{tenantId:r}:{},n=JSON.stringify({email:i});return{res:yield this.fetch(e,{headers:{"content-type":"application/json",accept:"application/json"},method:"POST",params:t,body:n}),data:null}})}resetPassword(i,r){return a(this,void 0,void 0,function*(){var e=this.passwordResetUrl,t=r?{tenantId:r}:{},n=JSON.stringify(i);return{res:yield this.fetch(e,{headers:{"content-type":"application/json",accept:"application/json"},method:"PUT",params:t,body:n}),data:null}})}verifyTFACode(t){return a(this,void 0,void 0,function*(){var e=JSON.stringify({pin:t});return{res:yield this.fetch(this.verifyTFACodeUrl,{headers:{"content-type":"application/json",accept:"application/json"},body:e,method:"POST"}),data:null}})}verifyTotpCode(t){return a(this,void 0,void 0,function*(){var e=JSON.stringify({code:t});return{res:yield this.fetch(this.verifyTOTPCodeUrl,{headers:{"content-type":"application/json"},body:e,method:"POST"}),data:null}})}activateTotp(){return a(this,void 0,void 0,function*(){var e=JSON.stringify({isActive:!0});return{res:yield this.fetch(this.activateTOTPCodeUrl,{headers:{"content-type":"application/json"},body:e,method:"POST"}),data:null}})}getActivityTotp(){return a(this,void 0,void 0,function*(){var e=yield this.fetch(this.activateTOTPCodeUrl,{headers:{"content-type":"application/json"},method:"GET"}),t=yield e.json();return{res:e,data:t}})}generateTotpSecret(){return a(this,void 0,void 0,function*(){var e=yield this.fetch(this.totpCurrentUserURL,{headers:{"content-type":"application/json",accept:"application/json"},method:"POST"}),t=yield e.json();return{res:e,data:t}})}totpRevokeSecret(t){return a(this,void 0,void 0,function*(){var e=this.getDetailUrl(t)+"/"+this.revokeTOTPSecretUrl;return{res:yield this.fetch(e,{headers:{accept:"application/json"},method:"DELETE"}),data:null}})}savePhoneNumber(n){return a(this,void 0,void 0,function*(){var e=this.currentUserPhoneUrl,t={method:"PUT",headers:{"content-type":"application/json",accept:"application/json"},body:JSON.stringify({phone:n})},e=yield this.fetch(e,t),t=yield e.json();return{res:e,data:t}})}getNewsletterEmails(){return a(this,void 0,void 0,function*(){var e=this.newsletterEmailsUrl,e=yield this.fetch(e,{method:"GET",headers:{accept:"text/plain"}}),t=yield e.text();return{res:e,data:t}})}changeUserPassword(t,n,i){return a(this,void 0,void 0,function*(){var e=JSON.stringify({newPassword:n,currentUserPassword:i});return{res:yield this.fetch(this.changeUserPasswordUrl(t),{headers:{"content-type":"application/json"},body:e,method:"PUT"}),data:null}})}changeCurrentUserPassword(t,n){return a(this,void 0,void 0,function*(){var e=JSON.stringify({newPassword:t,currentUserPassword:n});return{res:yield this.fetch(this.currentUserPasswordUrl,{headers:{"content-type":"application/json"},body:e,method:"PUT"}),data:null}})}revokeTokens(){return a(this,void 0,void 0,function*(){return{res:yield this.fetch(this.revokeAllTokensUrl,{headers:{"content-type":"application/json"},method:"POST"}),data:null}})}hasRole(e,t){return this.hasRoleInUser(e,t)||this.hasRoleInGroups(e,t)}hasAllRoles(t,e){return e.every(e=>this.hasRole(t,e))}hasAnyRole(t,e){return e.some(e=>this.hasRole(t,e))}hasAnyGlobalRole(t,e){return e.some(e=>this.hasGlobalRoleInUser(t,e))}isDeviceUser(e){return e.id.match(/^device_/)}onBeforeUpdate(e){e=Object.assign({},e);return delete e.id,delete e.userName,e}getDetailUrl(e){return this.listUrl+"/"+encodeURIComponent(this.getId(e))}getId(e){let t;return t="object"==typeof e&&e.id?e.id:"object"==typeof e&&e.userName?e.userName:e,String(t)}hasRoleInUser(e,t){var n=e.effectiveRoles||[];return this.hasRoleInReferences(e&&e.roles&&e.roles.references||[],t)||n.some(({id:e})=>t===e)}hasRoleInGroups(e,t){return(e&&e.groups&&e.groups.references||[]).some(e=>this.hasRoleInReferences(e.group.roles.references,t))}hasRoleInReferences(e,t){return e.some(e=>e.role.id===t)}changeUserPasswordUrl(e){return`${this.client.tenant}/users/${this.getId(e)}/password`}hasGlobalRoleInUser(e,t){return((null==(e=null==e?void 0:e.groups)?void 0:e.references)||[]).map(e=>{return null==(e=null==e?void 0:e.group)?void 0:e.id}).some(e=>e===t)}}r.PasswordStrength=void 0,(i=r.PasswordStrength||(r.PasswordStrength={})).GREEN="GREEN",i.RED="RED",i.YELLOW="YELLOW";class $ extends e{constructor(e,t){super(e),this.listUrl="binaries",this.propertyName="attachments",this.baseUrl="application/applications/"+this.getIdString(t)}upload(r,s,o){return a(this,void 0,void 0,function*(){var e=(null==o?void 0:o.listUrl)||this.listUrl,t=this.createBinaryRequestBody(r,s,o);let n;"function"==typeof t.getHeaders&&(n=t.getHeaders());var i=Object.assign((null==o?void 0:o.headers)||{Accept:"application/json"},n),e=yield this.fetch(e,{method:"POST",body:t,headers:i}),t=yield e.json();return{res:e,data:t}})}uploadWithProgressXhr(e,t,n,i){var r=`/${this.baseUrl}/`+((null==i?void 0:i.listUrl)||this.listUrl),e=this.createBinaryRequestBody(e,n,i);let s;"function"==typeof e.getHeaders&&(s=e.getHeaders());var o=this.client.getFetchOptions().headers,a=(Object.assign(o,(null==i?void 0:i.headers)||{Accept:"application/json"}),Object.assign(o,s),new XMLHttpRequest);a.open("POST",r,!0);for(const l in o)o.hasOwnProperty(l)&&a.setRequestHeader(l,o[l]);a.upload.addEventListener("progress",t);let c;return c="function"==typeof e.getBuffer?e.getBuffer():e,a.send(c),a}getXMLHttpResponse(n){return new Promise((e,t)=>{n.addEventListener("loadend",()=>{4!==n.readyState||200!==n.status&&201!==n.status?t(n.responseText?{data:JSON.parse(n.responseText)}:"Could not upload file."):e(JSON.parse(n.responseText))})})}list(e){const t=Object.create(null,{list:{get:()=>super.list}});return a(this,void 0,void 0,function*(){return t.list.call(this,e)})}delete(e){const t=Object.create(null,{delete:{get:()=>super.delete}});return a(this,void 0,void 0,function*(){return t.delete.call(this,e)})}listPlugins(){return a(this,void 0,void 0,function*(){var e=this.listUrl+"/plugins",e=yield this.fetch(e,{headers:{accept:"application/json"}}),t=yield e.json();return{res:e,data:t}})}addPlugin(i,r){return a(this,void 0,void 0,function*(){var e=this.listUrl+"/plugins/"+encodeURIComponent(i),t=new E,n=r instanceof ArrayBuffer?Buffer.from(r):r,n=(t.append("file",n),yield this.fetch(e,{method:"POST",body:t,headers:{accept:"application/json"}})),e=yield n.json();return{res:n,data:e}})}removePlugin(n){return a(this,void 0,void 0,function*(){var e=this.listUrl+"/plugins/"+n,e=yield this.fetch(e,{method:"DELETE",headers:{accept:"application/json"}}),t=yield e.json();return{res:e,data:t}})}updateFiles(i){return a(this,void 0,void 0,function*(){var e=this.listUrl+"/files";const n=new E;i.forEach(e=>{var t=e.contents instanceof ArrayBuffer?Buffer.from(e.contents):e.contents;n.append(e.path,t)});var e=yield this.fetch(e,{method:"POST",body:n,headers:{accept:"application/json"}}),t=yield e.json();return{res:e,data:t}})}downloadArchive(t){return a(this,void 0,void 0,function*(){var e=this.listUrl+"/"+t;return yield this.fetch(e)})}createBinaryRequestBody(e,t,n){var i=new E,r=e instanceof ArrayBuffer?Buffer.from(e):e;let s=t;if("undefined"!=typeof File&&e instanceof File&&(s=e.name),i.append((null==n?void 0:n.bodyFileProperty)||"file",r,s),i.append("fileName",s),null!=n&&n.requestBody)for(const o in n.requestBody)n.requestBody.hasOwnProperty(o)&&i.append(o,JSON.stringify(n.requestBody[o]));return i}}r.ApplicationType=void 0,(S=r.ApplicationType||(r.ApplicationType={})).EXTERNAL="EXTERNAL",S.HOSTED="HOSTED",S.MICROSERVICE="MICROSERVICE",S.FEATURE="FEATURE";class I extends e{constructor(){super(...arguments),this.baseUrl="application",this.listUrl="applications",this.propertyName="applications",this.channel="/applications/*"}create(e){const t=Object.create(null,{create:{get:()=>super.create}});return a(this,void 0,void 0,function*(){return t.create.call(this,e)})}clone(i,r){return a(this,void 0,void 0,function*(){var e=this.getDetailUrl(i)+"/clone";let t=void 0;r&&(t={version:r});var e=yield this.fetch(e,{method:"POST",body:"",headers:{"content-type":"application/json",accept:"application/json"},params:t}),n=yield e.json();return{res:e,data:n}})}list(e={}){const t=Object.create(null,{list:{get:()=>super.list}});return a(this,void 0,void 0,function*(){return t.list.call(this,e)})}listVersions(i,r={}){var s;return a(this,void 0,void 0,function*(){var t=this.getEntityId(i),t=this.listUrl+`/${t}/versions`;try{var n=yield this.fetch(t,{headers:{"content-type":"application/json"},params:r}),e=null==(s=yield n.json())?void 0:s.applicationVersions;return{res:n,data:e}}catch(e){if(404===e.res.status)return{data:t,res:n}=yield this.detail(i),{res:n,data:t.applicationVersions};throw e}})}detail(e){const t=Object.create(null,{detail:{get:()=>super.detail}});return a(this,void 0,void 0,function*(){return t.detail.call(this,e)})}update(e){const t=Object.create(null,{update:{get:()=>super.update}});return a(this,void 0,void 0,function*(){return t.update.call(this,e)})}delete(e){const t=Object.create(null,{delete:{get:()=>super.delete}});return a(this,void 0,void 0,function*(){return t.delete.call(this,e)})}listByName(n){return a(this,void 0,void 0,function*(){var e="applicationsByName/"+encodeURIComponent(n),e=yield this.fetch(e,{headers:{"content-type":"application/json"}}),t=yield e.json();return{res:e,data:t[this.propertyName]}})}listByTenant(n,i={}){return a(this,void 0,void 0,function*(){var e=new A(this.client),e=this.getIdString(n||(yield e.current()).data.name),e="applicationsByTenant/"+encodeURIComponent(e),e=yield this.fetch(e,{headers:{"content-type":"application/json"},params:i}),t=yield e.json();return{res:e,data:t[this.propertyName]}})}listByOwner(n,i={}){return a(this,void 0,void 0,function*(){var e=new A(this.client),e=this.getIdString(n||(yield e.current()).data.name),e="applicationsByOwner/"+encodeURIComponent(e),e=yield this.fetch(e,{headers:{"content-type":"application/json"},params:i}),t=yield e.json();return{res:e,data:t[this.propertyName]}})}listByUser(n,i={}){return a(this,void 0,void 0,function*(){var e=new _(this.client),e=this.getIdString(n||(yield e.current()).data),e="applicationsByUser/"+encodeURIComponent(e),e=yield this.fetch(e,{headers:{"content-type":"application/json"},params:i}),t=yield e.json();return{res:e,data:t[this.propertyName]}})}reactivateArchive(t){return a(this,void 0,void 0,function*(){var e=this.listUrl+`/${t}/refresh`;return{res:yield this.fetch(e,{method:"POST",body:"",headers:{"content-type":"application/json",accept:"application/json"}}),data:null}})}binary(e){return new $(this.client,e)}getHref(e){return e.type===r.ApplicationType.EXTERNAL?e.externalUrl:"/apps/"+(e.public?"public/":"")+e.contextPath}isAvailable(n){return a(this,void 0,void 0,function*(){var{res:e,data:t}=yield this.listByUser(void 0,{dropOverwrittenApps:!0,noPaging:!0});return{data:(t||[]).some(e=>"string"==typeof n?e.name===n||e.contextPath===n:this.isMatch(e,n)),res:e}})}getStatusDetails(t){return a(this,void 0,void 0,function*(){var e=this.getEntityId(t);return new w(this.client,this.realtime).list({type:"c8y_Application_"+e})})}getInstanceNames(e){let t=new Array;return t=e&&e.c8y_Status&&e.c8y_Status.instances?Object.keys(e.c8y_Status.instances):t}getInstanceLog(n,i,r){return a(this,void 0,void 0,function*(){var e=this.getDetailUrl(n)+"/logs/"+i,t={accept:this.mimeType("applicationLogs")},e=yield this.fetch(e,{headers:t,params:r}),t=yield e.json();return{res:e,data:t}})}updateApplicationConfig(n,i){var r;return a(this,void 0,void 0,function*(){var e=this.getEntityId(n),t=(yield this.detail(e))["data"],t=(null==t?void 0:t.config)||{},t=Object.assign(Object.assign({},t),i),e=yield this.update({id:e,config:t});return null==(r=yield e)?void 0:r.data})}getAppManifest(n,i){return a(this,void 0,void 0,function*(){var e=new Date;let t;if(400<=(t=i?yield this.client.fetch(`/apps/${n.contextPath}@${i}/cumulocity.json?nocache=`+e.getTime()):yield this.client.fetch(`/apps/${n.contextPath}/cumulocity.json?nocache=`+e.getTime())).status)throw new Error("No Cumulocity IoT manifest found.");return yield t.json()})}storeAppManifest(e,t){return a(this,void 0,void 0,function*(){return yield this.binary(e).updateFiles([{path:"cumulocity.json",contents:JSON.stringify(t)}])})}setPackageVersionTag(n,i,r){return a(this,void 0,void 0,function*(){var e=this.getDetailUrl(n)+"/versions/"+i,t=JSON.stringify({tags:r}),e=yield this.fetch(e,{method:"PUT",body:t,headers:{accept:"application/vnd.com.nsn.cumulocity.applicationVersion+json;charset=UTF-8;ver=0.9","content-type":"application/json"}}),t=yield e.json();return{res:e,data:t}})}getManifestOfContextPath(n){return a(this,void 0,void 0,function*(){var e=this.getDetailUrl(n)+"/manifest",e=yield this.fetch(e),t=(yield e.json())["application"];return{res:e,data:t}})}deleteVersionPackage(t,n){return a(this,void 0,void 0,function*(){var e=this.getDetailUrl(t)+"/versions/";return{res:yield this.fetch(e,this.changeFetchOptions({method:"DELETE",params:n},e)),data:null}})}updateApplicationAvailability(t,n){return a(this,void 0,void 0,function*(){var e=this.getEntityId(t);return yield this.update({id:e,availability:n})})}isMatch(n,e){return Object.keys(e).every(t=>Array.isArray(n[t])&&Array.isArray(e[t])?e[t].every(e=>n[t].includes(e)):"object"==typeof n[t]&&null!==n[t]&&"object"==typeof e[t]&&null!==e[t]?this.isMatch(n[t],e[t]):n[t]===e[t])}}r.InstanceStatus=void 0,(i=r.InstanceStatus||(r.InstanceStatus={})).Up="Up",i.Unhealthy="Unhealthy",i.Down="Down",i.Unknown="Unknown",r.BillingMode=void 0,(S=r.BillingMode||(r.BillingMode={})).SUBSCRIPTION="SUBSCRIPTION",S.RESOURCES="RESOURCES",r.Isolation=void 0,(i=r.Isolation||(r.Isolation={})).PER_TENANT="PER_TENANT",i.MULTI_TENANT="MULTI_TENANT",r.ApplicationAvailability=void 0,(S=r.ApplicationAvailability||(r.ApplicationAvailability={}))[S.MARKET="MARKET"]="MARKET",S[S.PRIVATE="PRIVATE"]="PRIVATE",S[S.SHARED="SHARED"]="SHARED";class V extends e{constructor(){super(...arguments),this.baseUrl="tenant/system",this.listUrl="options",this.propertyName="options"}detail(e){const t=Object.create(null,{detail:{get:()=>super.detail}});return a(this,void 0,void 0,function*(){return t.detail.call(this,e)})}list(n={}){return a(this,void 0,void 0,function*(){var e=this.listUrl,e=yield this.fetch(e,{headers:{"content-type":"application/json"},params:n}),t=yield e.json();return{res:e,data:t[this.propertyName]}})}getDetailUrl(e){return`${this.listUrl}/${e.category}/`+e.key}onBeforeCreate(e){return e}}class J extends e{constructor(){super(...arguments),this.baseUrl="tenant",this.listUrl="options",this.propertyName="options",this.securityOptionsCategories=["password"],this.securityOptionsListUrl="security-options",this.systemOptions="system"}detail(e,t={}){const n=Object.create(null,{detail:{get:()=>super.detail}});return a(this,void 0,void 0,function*(){return n.detail.call(this,e,t)})}create(e){const t=Object.create(null,{create:{get:()=>super.create}});return a(this,void 0,void 0,function*(){return t.create.call(this,e)})}update(e){const t=Object.create(null,{update:{get:()=>super.update}});return a(this,void 0,void 0,function*(){return t.update.call(this,e)})}list(e={}){const t=Object.create(null,{list:{get:()=>super.list}});return a(this,void 0,void 0,function*(){return t.list.call(this,e)})}delete(e){const t=Object.create(null,{delete:{get:()=>super.delete}});return a(this,void 0,void 0,function*(){return t.delete.call(this,e)})}getDetailUrl(e){var t=encodeURIComponent(e.category),n=encodeURIComponent(e.key);return-1<this.securityOptionsCategories.indexOf(e.category)?this.securityOptionsListUrl+`/${t}/`+n:this.listUrl+`/${t}/`+n}onBeforeCreate(e){return e}}class X extends e{constructor(){super(...arguments),this.baseUrl="tenant",this.listUrl="security-options",this.category="password",this.propertyName="options"}detail(e){const t=Object.create(null,{detail:{get:()=>super.detail}});return a(this,void 0,void 0,function*(){return t.detail.call(this,e)})}getDetailUrl(e){return`${this.listUrl}/${this.category}/`+e.key}onBeforeCreate(e){return e}}class W extends e{constructor(){super(...arguments),this.baseUrl="tenant",this.listUrl="loginOptions",this.propertyName="loginOptions"}detail(e){const t=Object.create(null,{detail:{get:()=>super.detail}});return a(this,void 0,void 0,function*(){return t.detail.call(this,e)})}list(e={}){const t=Object.create(null,{list:{get:()=>super.list}});return a(this,void 0,void 0,function*(){return t.list.call(this,e)})}listForCurrentTenant(){const e=Object.create(null,{list:{get:()=>super.list}});return a(this,void 0,void 0,function*(){return e.list.call(this,{tenantId:this.client.tenant})})}listForManagement(){const e=Object.create(null,{list:{get:()=>super.list}});return a(this,void 0,void 0,function*(){return e.list.call(this,{management:!0})})}create(e){const t=Object.create(null,{create:{get:()=>super.create}});return a(this,void 0,void 0,function*(){return t.create.call(this,e)})}update(e){const t=Object.create(null,{update:{get:()=>super.update}});return a(this,void 0,void 0,function*(){return t.update.call(this,e)})}save(e){return a(this,void 0,void 0,function*(){return e.id?this.update(e):this.create(e)})}delete(e){const t=Object.create(null,{delete:{get:()=>super.delete}});return a(this,void 0,void 0,function*(){return t.delete.call(this,e)})}}r.TenantLoginOptionType=void 0,(i=r.TenantLoginOptionType||(r.TenantLoginOptionType={})).OAUTH2_INTERNAL="OAUTH2_INTERNAL",i.OAUTH2="OAUTH2",i.BASIC="BASIC",r.GrantType=void 0,(S=r.GrantType||(r.GrantType={})).AUTHORIZATION_CODE="AUTHORIZATION_CODE",S.PASSWORD="PASSWORD",r.UserManagementSource=void 0,(i=r.UserManagementSource||(r.UserManagementSource={})).REMOTE="REMOTE",i.INTERNAL="INTERNAL";class Q extends e{constructor(){super(...arguments),this.baseUrl="audit",this.listUrl="auditRecords",this.propertyName="auditRecords"}detail(e){const t=Object.create(null,{detail:{get:()=>super.detail}});return a(this,void 0,void 0,function*(){return t.detail.call(this,e)})}create(e){const t=Object.create(null,{create:{get:()=>super.create}});return a(this,void 0,void 0,function*(){return t.create.call(this,e)})}list(e={}){const t=Object.create(null,{list:{get:()=>super.list}});return a(this,void 0,void 0,function*(){return t.list.call(this,e)})}}r.AuditRecordType=void 0,(S=r.AuditRecordType||(r.AuditRecordType={})).ALARM="Alarm",S.BULK_OPERATION="BulkOperation",S.CEP_MODULE="CepModule",S.EVENT="Event",S.INVENTORY="Inventory",S.INVENTORY_ROLE="InventoryRole",S.OPERATION="Operation",S.OPTION="Option",S.GROUP="Group",S.SMART_RULE="SmartRule",S.SYSTEM="SYSTEM",S.TENANT="Tenant",S.USER="User",r.ChangeType=void 0,(i=r.ChangeType||(r.ChangeType={}))[i.ADDED="ADDED"]="ADDED",i[i.REPLACED="REPLACED"]="REPLACED",i[i.REMOVED="REMOVED"]="REMOVED";class k extends e{constructor(){super(...arguments),this.baseUrl="user",this.listUrl="inventoryroles",this.propertyName="roles"}detail(e){const t=Object.create(null,{detail:{get:()=>super.detail}});return a(this,void 0,void 0,function*(){return t.detail.call(this,e)})}create(e){const t=Object.create(null,{create:{get:()=>super.create}});return a(this,void 0,void 0,function*(){return t.create.call(this,e)})}update(e){const t=Object.create(null,{update:{get:()=>super.update}});return a(this,void 0,void 0,function*(){return t.update.call(this,e)})}list(e={}){const t=Object.create(null,{list:{get:()=>super.list}});return a(this,void 0,void 0,function*(){return t.list.call(this,e)})}delete(e){const t=Object.create(null,{delete:{get:()=>super.delete}});return a(this,void 0,void 0,function*(){return t.delete.call(this,e)})}}r.DeviceRegistrationStatus=void 0,(S=r.DeviceRegistrationStatus||(r.DeviceRegistrationStatus={}))[S.WAITING_FOR_CONNECTION="WAITING_FOR_CONNECTION"]="WAITING_FOR_CONNECTION",S[S.PENDING_ACCEPTANCE="PENDING_ACCEPTANCE"]="PENDING_ACCEPTANCE",S[S.ACCEPTED="ACCEPTED"]="ACCEPTED",S[S.BLOCKED="BLOCKED"]="BLOCKED";class x extends e{constructor(){super(...arguments),this.baseUrl="devicecontrol",this.listUrl="newDeviceRequests",this.propertyName="newDeviceRequests"}detail(e){const t=Object.create(null,{detail:{get:()=>super.detail}});return a(this,void 0,void 0,function*(){return t.detail.call(this,e)})}create(e){const t=Object.create(null,{create:{get:()=>super.create}});return a(this,void 0,void 0,function*(){return t.create.call(this,e)})}list(e={}){const t=Object.create(null,{list:{get:()=>super.list}});return a(this,void 0,void 0,function*(){return t.list.call(this,e)})}delete(e){const t=Object.create(null,{delete:{get:()=>super.delete}});return a(this,void 0,void 0,function*(){return t.delete.call(this,e)})}accept(n){const i=Object.create(null,{update:{get:()=>super.update}});return a(this,void 0,void 0,function*(){var e=this.getSecurityToken(n);let t={id:this.getIdString(n),status:r.DeviceRegistrationStatus.ACCEPTED};return e&&(t=Object.assign(Object.assign({},t),{securityToken:e})),i.update.call(this,t)})}acceptAll(){const n=Object.create(null,{fetch:{get:()=>super.fetch}});return a(this,void 0,void 0,function*(){var e=yield n.fetch.call(this,this.listUrl+"/acceptAll",{method:"POST"}),t=yield e.json();return{res:e,data:t}})}limit(){const n=Object.create(null,{fetch:{get:()=>super.fetch}});return a(this,void 0,void 0,function*(){var e=yield n.fetch.call(this,this.listUrl+"/limit"),t=yield e.json();return{res:e,data:t}})}bootstrap(s,o){return a(this,void 0,void 0,function*(){var e=this.getIdString(s),t=this.getSecurityToken(s),t=t?JSON.stringify({id:e,securityToken:t}):JSON.stringify({id:e}),e=this.baseUrl+"/deviceCredentials",n=o["basicAuth"];let i=o["basicAuthToken"];n&&({user:n,pass:r}=n,i=c(n+":"+r));var n={Authorization:"Basic "+i,accept:"application/json","content-type":"application/json"},r=yield this.client.fetch(e,{body:t,headers:n,method:"POST"}),e=yield r.json();if(400<r.status)throw{res:r,data:e};return{res:r,data:e}})}onBeforeCreate(e){return e}onBeforeUpdate(e){e=Object.assign({},e);return delete e.id,e}getDetailUrl(e){e=encodeURIComponent(this.getEntityId(e));return this.listUrl+"/"+e}getSecurityToken(e){let t;return t="object"==typeof e?e.securityToken?String(e.securityToken):void 0:t}}class K{constructor(e){this.client=e}create(r){return a(this,void 0,void 0,function*(){let e=r;var t=new E;let n="bulk-registration.csv";"undefined"!=typeof File&&e instanceof File&&(n=e.name,e.name.match(/\.csv$/))&&(e=new File([e],e.name,{type:"text/csv"})),t.append("file",e,n);var t=yield this.client.fetch("/devicecontrol/bulkNewDeviceRequests",{method:"POST",body:t,headers:{accept:"application/json"}}),i=yield t.json();return{res:t,data:i}})}}r.DeviceRegistrationSecurityMode=void 0,(i=r.DeviceRegistrationSecurityMode||(r.DeviceRegistrationSecurityMode={})).REQUIRED="REQUIRED",i.OPTIONAL="OPTIONAL",i.IGNORED="IGNORED";class Y extends e{constructor(){super(...arguments),this.baseUrl="user",this.listUrl="roles",this.propertyName="roles"}detail(e){const t=Object.create(null,{detail:{get:()=>super.detail}});return a(this,void 0,void 0,function*(){return t.detail.call(this,e)})}list(e={}){const t=Object.create(null,{list:{get:()=>super.list}});return a(this,void 0,void 0,function*(){return t.list.call(this,e)})}}(S=O=O||{}).ROLES="roles",S.USERS="users";class z extends e{constructor(){super(...arguments),this.baseUrl="user",this.propertyName="groups"}get listUrl(){return this.client.tenant+"/groups"}detail(e){const t=Object.create(null,{detail:{get:()=>super.detail}});return a(this,void 0,void 0,function*(){return t.detail.call(this,e)})}create(e){const t=Object.create(null,{create:{get:()=>super.create}});return a(this,void 0,void 0,function*(){return t.create.call(this,e)})}update(e){const t=Object.create(null,{update:{get:()=>super.update}});return a(this,void 0,void 0,function*(){return t.update.call(this,e)})}list(e={}){const t=Object.create(null,{list:{get:()=>super.list}});return a(this,void 0,void 0,function*(){return t.list.call(this,e)})}delete(e){const t=Object.create(null,{delete:{get:()=>super.delete}});return a(this,void 0,void 0,function*(){return t.delete.call(this,e)})}addRoleToGroup(e,t){return a(this,void 0,void 0,function*(){return this.addChild(O.ROLES,e,t)})}removeRoleFromGroup(e,t){return a(this,void 0,void 0,function*(){return this.removeChild(O.ROLES,e,t)})}addUserToGroup(e,t){return a(this,void 0,void 0,function*(){return this.addChild(O.USERS,e,t)})}removeUserFromGroup(e,t){return a(this,void 0,void 0,function*(){return this.removeChild(O.USERS,e,t)})}getSelf(e){return"object"==typeof e&&e.self?e.self:e}getChildUrl(e,t){return this.getDetailUrl(t)+"/"+e}getChildReferenceAsBody(e,t){var n=this.getSelf(t);switch(e){case O.ROLES:return JSON.stringify({role:{self:String(n)}});case O.USERS:return JSON.stringify({user:{self:String(n)}})}throw new Error("UserGroupService -> getChild -> unsupported child type")}addChild(n,i,r){return a(this,void 0,void 0,function*(){var e=this.getChildUrl(n,i),t=this.getChildReferenceAsBody(n,r),e=yield this.fetch(e,{method:"POST",body:t,headers:{accept:"application/json","content-type":"application/json"}}),t=yield e.json();return{res:e,data:t.managedObject}})}removeChild(t,n,i){return a(this,void 0,void 0,function*(){var e=this.getIdString(i),e=this.getChildUrl(t,n)+"/"+encodeURIComponent(String(e));return{res:yield this.fetch(e,{method:"DELETE",headers:{accept:"application/json"}}),data:null}})}}class Z{constructor(e){this.baseUrl="identity",this.propertyName="externalIds",this.client=e}list(n){return a(this,void 0,void 0,function*(){var e=this.getExternalIdsOfGlobalIdUrl(n),e=yield this.fetch(e,{headers:{accept:"application/json"}}),t=yield e.json();return{res:e,data:t[this.propertyName]}})}create(n){return a(this,void 0,void 0,function*(){var e=JSON.stringify(n),t=this.getExternalIdsOfGlobalIdUrl(n.managedObject.id),t=yield this.fetch(t,{headers:{"content-type":"application/json",accept:"application/json"},method:"POST",body:e}),e=yield t.json();return{res:t,data:e}})}detail(n){return a(this,void 0,void 0,function*(){var e=this.getExternalIdUrl(n),e=yield this.fetch(e,{headers:{accept:"application/json"}}),t=yield e.json();return{res:e,data:t}})}delete(t){return a(this,void 0,void 0,function*(){var e=this.getExternalIdUrl(t);return{res:yield this.fetch(e,{headers:{accept:"application/json"},method:"DELETE"}),data:null}})}fetch(e,t){return a(this,void 0,void 0,function*(){var n=yield this.client.fetch(e,t);if(400<=n.status){let t=null;try{t=yield n.json()}catch(e){try{t=yield n.text()}catch(e){}}throw{res:n,data:t}}return n})}getExternalIdsOfGlobalIdUrl(e){return`/${this.baseUrl}/globalIds/${e}/externalIds`}getExternalIdUrl(e){return`/${this.baseUrl}/externalIds/${e.type}/`+e.externalId}}class ee extends e{constructor(){super(...arguments),this.listUrl="trusted-certificates",this.proofOfPossessionUrl="trusted-certificates-pop",this.propertyName="certificates"}get baseUrl(){return"/tenant/tenants/"+this.client.tenant}list(e={}){const t=Object.create(null,{list:{get:()=>super.list}});return a(this,void 0,void 0,function*(){return t.list.call(this,e)})}detail(e){const t=Object.create(null,{detail:{get:()=>super.detail}});return a(this,void 0,void 0,function*(){return t.detail.call(this,e)})}delete(e){const t=Object.create(null,{delete:{get:()=>super.delete}});return a(this,void 0,void 0,function*(){return t.delete.call(this,e)})}update(e){const t=Object.create(null,{update:{get:()=>super.update}});return a(this,void 0,void 0,function*(){return t.update.call(this,e)})}create(e){const t=Object.create(null,{create:{get:()=>super.create}});return a(this,void 0,void 0,function*(){return t.create.call(this,e)})}regeneratePoPVerificationCode(n){return a(this,void 0,void 0,function*(){var e=`${this.proofOfPossessionUrl}/${this.getEntityId(n)}/verification-code`,e=yield this.fetch(e,{headers:{"content-type":"application/json",Accept:"application/json"},method:"POST"}),t=yield e.json();return{res:e,data:t}})}verifySignedVerificationCode(n,i){return a(this,void 0,void 0,function*(){var e=`${this.proofOfPossessionUrl}/${this.getEntityId(n)}/pop`,t=JSON.stringify({proofOfPossessionSignedVerificationCode:i}),e=yield this.fetch(e,{method:"POST",body:t,headers:{"content-type":"application/json",Accept:"application/json"}}),t=yield e.json();return{res:e,data:t}})}getDetailUrl(e){e=this.getEntityId(e);return this.listUrl+"/"+e}getEntityId(e){let t;return t="object"==typeof e&&e.fingerprint?e.fingerprint:e}}class te extends e{get baseUrl(){return"/tenant/trusted-certificates/settings/crl"}uploadCrls(t){return a(this,void 0,void 0,function*(){var e=JSON.stringify({crls:t});return{res:yield this.fetch("",{method:"PUT",body:e,headers:{"content-type":"application/json",Accept:"application/json"}}),data:null}})}uploadCrlFile(t){return a(this,void 0,void 0,function*(){var e=new E;e.append("file",t);return{res:yield this.fetch("",{method:"PUT",body:e,headers:{accept:"application/json"}}),data:null}})}downloadCrlFile(e){return a(this,void 0,void 0,function*(){return yield this.fetch("",e)})}}class ne extends e{constructor(e){super(e),this.baseUrl="inventory",this.listUrl="managedObjects",this.SMART_GROUP_TYPE="c8y_DynamicGroup",this.SMART_GROUP_FRAGMENT_TYPE="c8y_IsDynamicGroup",this.COLUMNS_CONFIG_FRAGMENT="c8y_DeviceColumnsConfig",this.FILTER_CONFIG_FRAGMENT="c8y_DeviceFilterConfig",this.QUERY_STRING_FRAGMENT="c8y_DeviceQueryString"}detail(e,t={}){const n=Object.create(null,{detail:{get:()=>super.detail}});return a(this,void 0,void 0,function*(){return n.detail.call(this,e,t)})}create(t){const n=Object.create(null,{create:{get:()=>super.create}});return a(this,void 0,void 0,function*(){var e=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.create.call(this,e)})}update(e){const t=Object.create(null,{update:{get:()=>super.update}});return a(this,void 0,void 0,function*(){return t.update.call(this,e)})}delete(t,n={}){const i=Object.create(null,{delete:{get:()=>super.delete}});return a(this,void 0,void 0,function*(){var e=(yield this.detail(t,{withChildren:!1})).data;return yield i.delete.call(this,e,n)})}isSmartGroup(e){var t=e.hasOwnProperty(this.SMART_GROUP_FRAGMENT_TYPE),e=e&&e.type===this.SMART_GROUP_TYPE;return t||e}getUrl(e=""){e=e.replace(/^\/+/,"");return this.baseUrl.replace(/\/+$/,"")+"/"+e}}class N extends e{constructor(e){super(e),this.baseUrl="service/smartrule",this.rulesUrl="smartrules",this.unupdatableFields=["type","cepModuleId","creationTime","lastUpdated"],this.applicationService=new I(e)}isMicroserviceAvailable(){return a(this,void 0,void 0,function*(){return void 0===this.microserviceAvailable&&(this.microserviceAvailable=(yield this.applicationService.isAvailable(N.microserviceName)).data),this.microserviceAvailable})}listByContext(n){return a(this,void 0,void 0,function*(){var e=this.contextRulesUrl(n),e=yield this.fetch(e,{method:"GET"}),t=(yield e.json()).rules;return{res:e,data:t}})}bulkDeactivateEnabledSources(e,t){var n;return 0===t.length?Promise.resolve({res:null,data:null}):(n=e["enabledSources"],n=this.disableEnabledSources(n,t),t=Object.assign({},e),Object.assign(t,{enabledSources:n}),this.update(t))}update(n){return a(this,void 0,void 0,function*(){var e=this.getSmartRulesUrl(n),t=JSON.stringify(this.removeUnclonableFields(n,this.unupdatableFields)),e=yield this.fetch(e,{method:"PUT",body:t,headers:{"content-type":"application/json",accept:"application/json"}}),t=yield e.json();return{res:e,data:t}})}disableEnabledSources(e=[],t){return e.filter(e=>!this.getListOfStringIds(t).includes(e))}getListOfStringIds(e){return e.map(e=>("object"==typeof e&&e.id?e.id:e).toString())}getSmartRulesUrl(e){var t=e&&e.c8y_Context&&e.c8y_Context.id;let n=t?this.contextRulesUrl(t):this.rulesUrl;return n=e.id?n+"/"+e.id:n}removeUnclonableFields(e,t){const n=Object.assign({},e);return t.forEach(e=>{delete n[e]}),n}contextRulesUrl(e={}){return"object"==typeof e&&e.id?`managedObjects/${e.id}/smartrules`:`managedObjects/${e}/smartrules`}}N.microserviceName="smartrule";class D{static authenticate(n,i){return a(this,void 0,void 0,function*(){var e=new p(n),t=new h(e,i),t=yield this.getCurrentTenant(t),e=new D(e,i);return e.core.tenant=t,e})}static authenticateViaOAuthInternal(n,i){return a(this,void 0,void 0,function*(){var e=yield this.loginViaOAuthInternal(n,!0,i),e=new d(e),t=new h(e,i),t=n.tenant||(yield this.getCurrentTenant(t)),e=new D(e,i);return e.core.tenant=t,e})}static authenticateViaOAuthInternalCookie(i,r){return a(this,void 0,void 0,function*(){var e=yield this.loginViaOAuthInternal(i,!1,r);let t;t="undefined"==typeof document?new v(e):new f;var e=new h(t,r),e=i.tenant||(yield this.getCurrentTenant(e)),n=new D(t,r);return n.core.tenant=e,n})}static deviceBootstrap(d){return a(this,void 0,void 0,function*(){var{deviceId:e,timeout:t,baseUrl:n,basicAuthToken:i}=d;let r=d["expire"];t&&!r&&(r=Date.now()+t);t=new h(void 0,n),t=new x(t);let s;try{var o=(yield t.bootstrap(e,{basicAuthToken:i}))["data"],{username:a,password:c,tenantId:l}=o,u=new p({user:a,tenant:l,password:c});(s=new D(u,n)).core.tenant=l}catch(e){if((!r||Date.now()<r)&&404===e.res.status)return D.deviceBootstrap(Object.assign({expire:r},d));throw e}return s})}static getMicroserviceSubscriptions(t,n){return a(this,void 0,void 0,function*(){var e=(yield(yield new h(new p(t),n).fetch("/application/currentApplication/subscriptions")).json())["users"];return e.map(({tenant:e,name:t,password:n})=>({tenant:e,user:t,password:n}))})}static loginViaOAuthInternal(i,r=!0,s){return a(this,void 0,void 0,function*(){var e=new p(i),e=new h(e,s);let t="/tenant/oauth";r&&(t+="/token"),i.tenant&&(t+="?tenant_id="+i.tenant);var n=new URLSearchParams({grant_type:"PASSWORD",username:i.user,password:i.password,tfa_code:i.tfa}),e=yield e.fetch(t,{method:"POST",body:n.toString(),headers:{"content-type":"application/x-www-form-urlencoded;charset=UTF-8"}});if(200!==e.status)throw{res:e};return r?(yield e.json()).access_token:e})}static getCurrentTenant(t){return a(this,void 0,void 0,function*(){var e=(yield new A(t).current())["data"];return e.name})}constructor(e,t){e=new h(e,t);this.realtime=new b(e),this.alarm=new j(e,this.realtime),this.application=new I(e,this.realtime),this.audit=new Q(e),this.core=e,this.deviceRegistration=new x(e),this.deviceRegistrationBulk=new K(e),this.event=new T(e,this.realtime),this.inventory=new w(e,this.realtime),this.inventoryBinary=new U(e),this.inventoryRole=new k(e),this.measurement=new C(e,this.realtime),this.operation=new R(e),this.operationBulk=new H(e),this.options={security:new X(e),system:new V(e),login:new W(e),tenant:new J(e)},this.role=new k(e),this.tenant=new A(e),this.user=new _(e),this.userGroup=new z(e),this.userRole=new Y(e),this.identity=new Z(e),this.smartGroups=new ne(e),this.smartRules=new N(e)}setAuth(e){this.core.setAuth(e),this.realtime.disconnect()}}r.AlarmService=j,r.ApplicationBinaryService=$,r.ApplicationService=I,r.AuditService=Q,r.BasicAuth=p,r.BearerAuth=d,r.Client=D,r.CookieAuth=f,r.CrlService=te,r.DeviceRegistrationBulkService=K,r.DeviceRegistrationService=x,r.EventBinaryService=G,r.EventService=T,r.FetchClient=h,r.IdentityService=Z,r.InventoryBinaryService=U,r.InventoryRoleService=k,r.InventoryService=w,r.MeasurementService=C,r.MicroserviceClientRequestAuth=g,r.NodeJSCookieAuth=v,r.OperationBulkService=H,r.OperationService=R,r.Paging=n,r.QueriesUtil=y,r.Realtime=b,r.Service=e,r.SmartGroupsService=ne,r.SmartRulesService=N,r.SystemOptionsService=V,r.TenantLoginOptionsService=W,r.TenantOptionsService=J,r.TenantSecurityOptionsService=X,r.TenantService=A,r.TrustedCertificateService=ee,r.UserGroupService=z,r.UserInventoryRoleService=q,r.UserRoleService=Y,r.UserService=_});
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).cumulocity={})}(this,function(r){"use strict";function a(e,o,a,c){return new(a=a||Promise)(function(n,t){function i(e){try{s(c.next(e))}catch(e){t(e)}}function r(e){try{s(c.throw(e))}catch(e){t(e)}}function s(e){var t;e.done?n(e.value):((t=e.value)instanceof a?t:new a(function(e){e(t)})).then(i,r)}s((c=c.apply(e,o||[])).next())})}class n{constructor(e,t,n){this.filter=n,this.service=e,this.currentPage=t.currentPage,this.nextPage=t.nextPage,this.prevPage=t.prevPage,this.pageSize=t.pageSize,this.totalPages=t.totalPages}next(e={}){return a(this,void 0,void 0,function*(){return this.list(this.getFilter(e,this.nextPage))})}prev(e={}){return a(this,void 0,void 0,function*(){return this.list(this.getFilter(e,this.prevPage))})}list(e={}){return a(this,void 0,void 0,function*(){return this.service.list(e)})}goto(e,t={}){return a(this,void 0,void 0,function*(){return this.list(this.getFilter(t,e))})}getFilter(e,t){return Object.assign(e,this.filter,{currentPage:t})}}class e{constructor(e,t){this.client=e,this.realtime=t,this.cache=new Map;const n=Object.getPrototypeOf(this);["list","create","update","detail","delete"].forEach(e=>{n.hasOwnProperty(e)||Object.defineProperty(this,e,{get(){}})})}list(n={}){return a(this,void 0,void 0,function*(){var e=this.listUrl,e=yield this.fetch(e,this.changeFetchOptions({headers:{accept:"application/json"},params:n},e)),t=yield e.json();return{res:e,data:this.propertyName?t[this.propertyName]:t,paging:this.getPaging(t,n)}})}detail(n,i={}){return a(this,void 0,void 0,function*(){var e=this.getDetailUrl(n),e=yield this.fetch(e,this.changeFetchOptions({headers:{accept:"application/json"},params:Object.assign({},i)},e)),t=yield e.json();return{res:e,data:t}})}create(n){return a(this,void 0,void 0,function*(){var e=this.listUrl,t=JSON.stringify(this.onBeforeCreate(n)),t=yield this.fetch(e,this.changeFetchOptions({method:"POST",body:t,headers:{"content-type":"application/json",accept:"application/json"}},e)),e=yield t.json();return{res:t,data:e}})}update(n){return a(this,void 0,void 0,function*(){var e=this.getDetailUrl(n),t=JSON.stringify(this.onBeforeUpdate(n)),t=yield this.fetch(e,this.changeFetchOptions({method:"PUT",body:t,headers:{"content-type":"application/json",accept:"application/json"}},e)),e=yield t.json();return{res:t,data:e}})}delete(t,n){return a(this,void 0,void 0,function*(){var e=this.getDetailUrl(t);return{res:yield this.fetch(e,this.changeFetchOptions({method:"DELETE",params:n},e)),data:null}})}onBeforeCreate(e){return delete e.id,e}onBeforeUpdate(e){return e}changeFetchOptions(e,t=0){return e}getUrl(e=""){return this.baseUrl.replace(/\/+$/,"")+"/"+e.replace(/^\/+/,"")}getEntityId(e){return null==e?"":"object"==typeof e?this.getEntityId(e.id):""+e}getDetailUrl(e){e=this.getEntityId(e);return this.listUrl+"/"+e}fetch(t,n){return a(this,void 0,void 0,function*(){var e=this.getUrl(t),e=yield this.client.fetch(e,n);return yield this.handleErrorStatusCodes(e)})}handleErrorStatusCodes(n){return a(this,void 0,void 0,function*(){if(400<=n.status){let t=null;try{t=yield n.json()}catch(e){try{t=yield n.text()}catch(e){}}throw{res:n,data:t}}return n})}mimeType(e){return`application/vnd.com.nsn.cumulocity.${e}+json`}getIdString(e){let t;return t="object"==typeof e?e.id:e,String(t)}getPaging(e,t){return e.statistics?(e=Object.assign(Object.assign({},e.statistics),{nextPage:this.getCurrentPageFromLink(e.next),prevPage:this.getCurrentPageFromLink(e.prev)}),new n(this,e,t)):null}getCurrentPageFromLink(e=""){e=e.match(/currentPage=(-{0,1}\d+)/);return e&&parseInt(e[1],10)}}var P="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function t(e,t){return e(t={exports:{}},t.exports),t.exports}var i=t(function(e,t){var n="undefined"!=typeof self?self:P,i=(r.prototype=n,new r);function r(){this.fetch=!1,this.DOMException=n.DOMException}var s,o,a=i,c={},l="URLSearchParams"in a,u="Symbol"in a&&"iterator"in Symbol,d="FileReader"in a&&"Blob"in a&&function(){try{return new Blob,!0}catch(e){return!1}}(),h="FormData"in a,p="ArrayBuffer"in a;function f(e){if("string"!=typeof e&&(e=String(e)),/[^a-z0-9\-#$%&'*+.^_`|~]/i.test(e))throw new TypeError("Invalid character in header field name");return e.toLowerCase()}function g(e){return e="string"!=typeof e?String(e):e}function v(t){var e={next:function(){var e=t.shift();return{done:void 0===e,value:e}}};return u&&(e[Symbol.iterator]=function(){return e}),e}function y(t){this.map={},t instanceof y?t.forEach(function(e,t){this.append(t,e)},this):Array.isArray(t)?t.forEach(function(e){this.append(e[0],e[1])},this):t&&Object.getOwnPropertyNames(t).forEach(function(e){this.append(e,t[e])},this)}function m(e){if(e.bodyUsed)return Promise.reject(new TypeError("Already read"));e.bodyUsed=!0}function b(n){return new Promise(function(e,t){n.onload=function(){e(n.result)},n.onerror=function(){t(n.error)}})}function T(e){var t=new FileReader,n=b(t);return t.readAsArrayBuffer(e),n}function O(e){var t;return e.slice?e.slice(0):((t=new Uint8Array(e.byteLength)).set(new Uint8Array(e)),t.buffer)}function S(){return this.bodyUsed=!1,this._initBody=function(e){var t;(this._bodyInit=e)?"string"==typeof e?this._bodyText=e:d&&Blob.prototype.isPrototypeOf(e)?this._bodyBlob=e:h&&FormData.prototype.isPrototypeOf(e)?this._bodyFormData=e:l&&URLSearchParams.prototype.isPrototypeOf(e)?this._bodyText=e.toString():p&&d&&(t=e)&&DataView.prototype.isPrototypeOf(t)?(this._bodyArrayBuffer=O(e.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):p&&(ArrayBuffer.prototype.isPrototypeOf(e)||o(e))?this._bodyArrayBuffer=O(e):this._bodyText=e=Object.prototype.toString.call(e):this._bodyText="",this.headers.get("content-type")||("string"==typeof e?this.headers.set("content-type","text/plain;charset=UTF-8"):this._bodyBlob&&this._bodyBlob.type?this.headers.set("content-type",this._bodyBlob.type):l&&URLSearchParams.prototype.isPrototypeOf(e)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},d&&(this.blob=function(){var e=m(this);if(e)return e;if(this._bodyBlob)return Promise.resolve(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(new Blob([this._bodyArrayBuffer]));if(this._bodyFormData)throw new Error("could not read FormData body as blob");return Promise.resolve(new Blob([this._bodyText]))},this.arrayBuffer=function(){return this._bodyArrayBuffer?m(this)||Promise.resolve(this._bodyArrayBuffer):this.blob().then(T)}),this.text=function(){var e,t,n=m(this);if(n)return n;if(this._bodyBlob)return n=this._bodyBlob,e=new FileReader,t=b(e),e.readAsText(n),t;if(this._bodyArrayBuffer)return Promise.resolve(function(e){for(var t=new Uint8Array(e),n=new Array(t.length),i=0;i<t.length;i++)n[i]=String.fromCharCode(t[i]);return n.join("")}(this._bodyArrayBuffer));if(this._bodyFormData)throw new Error("could not read FormData body as text");return Promise.resolve(this._bodyText)},h&&(this.formData=function(){return this.text().then(w)}),this.json=function(){return this.text().then(JSON.parse)},this}p&&(s=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],o=ArrayBuffer.isView||function(e){return e&&-1<s.indexOf(Object.prototype.toString.call(e))}),y.prototype.append=function(e,t){e=f(e),t=g(t);var n=this.map[e];this.map[e]=n?n+", "+t:t},y.prototype.delete=function(e){delete this.map[f(e)]},y.prototype.get=function(e){return e=f(e),this.has(e)?this.map[e]:null},y.prototype.has=function(e){return this.map.hasOwnProperty(f(e))},y.prototype.set=function(e,t){this.map[f(e)]=g(t)},y.prototype.forEach=function(e,t){for(var n in this.map)this.map.hasOwnProperty(n)&&e.call(t,this.map[n],n,this)},y.prototype.keys=function(){var n=[];return this.forEach(function(e,t){n.push(t)}),v(n)},y.prototype.values=function(){var t=[];return this.forEach(function(e){t.push(e)}),v(t)},y.prototype.entries=function(){var n=[];return this.forEach(function(e,t){n.push([t,e])}),v(n)},u&&(y.prototype[Symbol.iterator]=y.prototype.entries);var E=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];function U(e,t){var n,i=(t=t||{}).body;if(e instanceof U){if(e.bodyUsed)throw new TypeError("Already read");this.url=e.url,this.credentials=e.credentials,t.headers||(this.headers=new y(e.headers)),this.method=e.method,this.mode=e.mode,this.signal=e.signal,i||null==e._bodyInit||(i=e._bodyInit,e.bodyUsed=!0)}else this.url=String(e);if(this.credentials=t.credentials||this.credentials||"same-origin",!t.headers&&this.headers||(this.headers=new y(t.headers)),this.method=(e=t.method||this.method||"GET",n=e.toUpperCase(),-1<E.indexOf(n)?n:e),this.mode=t.mode||this.mode||null,this.signal=t.signal||this.signal,this.referrer=null,("GET"===this.method||"HEAD"===this.method)&&i)throw new TypeError("Body not allowed for GET or HEAD requests");this._initBody(i)}function w(e){var n=new FormData;return e.trim().split("&").forEach(function(e){var t;e&&(t=(e=e.split("=")).shift().replace(/\+/g," "),e=e.join("=").replace(/\+/g," "),n.append(decodeURIComponent(t),decodeURIComponent(e)))}),n}function C(e,t){t=t||{},this.type="default",this.status=void 0===t.status?200:t.status,this.ok=200<=this.status&&this.status<300,this.statusText="statusText"in t?t.statusText:"OK",this.headers=new y(t.headers),this.url=t.url||"",this._initBody(e)}U.prototype.clone=function(){return new U(this,{body:this._bodyInit})},S.call(U.prototype),S.call(C.prototype),C.prototype.clone=function(){return new C(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new y(this.headers),url:this.url})},C.error=function(){var e=new C(null,{status:0,statusText:""});return e.type="error",e};var j=[301,302,303,307,308];C.redirect=function(e,t){if(-1===j.indexOf(t))throw new RangeError("Invalid status code");return new C(null,{status:t,headers:{location:e}})},c.DOMException=a.DOMException;try{new c.DOMException}catch(e){c.DOMException=function(e,t){this.message=e,this.name=t;t=Error(e);this.stack=t.stack},c.DOMException.prototype=Object.create(Error.prototype),c.DOMException.prototype.constructor=c.DOMException}function R(s,o){return new Promise(function(i,e){var t=new U(s,o);if(t.signal&&t.signal.aborted)return e(new c.DOMException("Aborted","AbortError"));var r=new XMLHttpRequest;function n(){r.abort()}r.onload=function(){var n,e={status:r.status,statusText:r.statusText,headers:(e=r.getAllResponseHeaders()||"",n=new y,e.replace(/\r?\n[\t ]+/g," ").split(/\r?\n/).forEach(function(e){var e=e.split(":"),t=e.shift().trim();t&&(e=e.join(":").trim(),n.append(t,e))}),n)},t=(e.url="responseURL"in r?r.responseURL:e.headers.get("X-Request-URL"),"response"in r?r.response:r.responseText);i(new C(t,e))},r.onerror=function(){e(new TypeError("Network request failed"))},r.ontimeout=function(){e(new TypeError("Network request failed"))},r.onabort=function(){e(new c.DOMException("Aborted","AbortError"))},r.open(t.method,t.url,!0),"include"===t.credentials?r.withCredentials=!0:"omit"===t.credentials&&(r.withCredentials=!1),"responseType"in r&&d&&(r.responseType="blob"),t.headers.forEach(function(e,t){r.setRequestHeader(t,e)}),t.signal&&(t.signal.addEventListener("abort",n),r.onreadystatechange=function(){4===r.readyState&&t.signal.removeEventListener("abort",n)}),r.send(void 0===t._bodyInit?null:t._bodyInit)})}R.polyfill=!0,a.fetch||(a.fetch=R,a.Headers=y,a.Request=U,a.Response=C),c.Headers=y,c.Request=U,c.Response=C,c.fetch=R,Object.defineProperty(c,"__esModule",{value:!0}),i.fetch.ponyfill=!0,delete i.fetch.polyfill;a=i;(t=a.fetch).default=a.fetch,t.fetch=a.fetch,t.Headers=a.Headers,t.Request=a.Request,t.Response=a.Response,e.exports=t}),L=(S=i)&&S.__esModule&&Object.prototype.hasOwnProperty.call(S,"default")?S.default:S;i.fetch,i.Headers,i.Request,i.Response;let s=new WeakMap;class h{constructor(e,t){this.baseUrl=t,this.tenant="",this.defaultHeaders={},"string"==typeof e?t=e:this.setAuth(e),this.baseUrl=this.resolveServerUrl(t)}setAuth(e){s.set(this,e)}fetch(i,r){return a(this,void 0,void 0,function*(){let e=L;try{e=window.fetch||e}catch(e){}var t=this.getUrl(i,r),n=this.getFetchOptions(r),n=this.adjustOptionsForFormData(n);return e(t,n)})}getUrl(e="",t){const i=t&&t.params;let n="";return i&&Object.keys(i).length&&(n="?"+(n=Object.keys(i).map(e=>{let t=i[e];const n=encodeURIComponent(e);return(t=Array.isArray(t)?t:[t]).map(e=>n+"="+encodeURIComponent(e)).join("&")}).join("&"))),this.baseUrl.replace(/\/+$/,"").replace(/^\/+/,"")+"/"+e.replace(/\/+$/,"").replace(/^\/+/,"")+n}getFetchOptions(e={}){let t=Object.assign({},e);e=s.get(this);return t.headers=Object.assign({},this.defaultHeaders,t.headers,{UseXBasic:!0}),delete t.params,t=e?e.getFetchOptions(t):t}getCometdHandshake(e={}){var t=s.get(this);return t?t.getCometdHandshake(e):e}resolveServerUrl(e=""){if(e&&e.startsWith("http"))return e.replace(/\/+$/,"");try{var t=window.location;return`${t.protocol}//${t.host}/`+e.replace(/\/+$/,"")}catch(e){throw Error("Your environment does not support relative URLs. Please provide a base URL.")}}adjustOptionsForFormData(e){return Object.assign(e,{body:e.body})}}function o(e){function t(){this.message=e}return(t.prototype=new Error).name="InvalidCharacterError",t.prototype.code=5,t}function c(e){return B(encodeURIComponent(e).replace(/%([0-9A-F]{2})/g,function(e,t){return String.fromCharCode("0x"+t)}))}var F=o("The string to be encoded contains characters out of range"),B="undefined"!=typeof btoa?function(e){return btoa(e)}:function(e){for(var t,n,i=String(e),r="",s=0,o="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";i.charAt(0|s)||(o="=",s%1);r+=o.charAt(63&t>>8-s%1*8)){if(255<(n=i.charCodeAt(s+=.75)))throw new F;t=t<<8|n}return r},l=(o("The string to be decoded is not correctly encoded"),new WeakMap);class p{constructor(e){this.updateCredentials(e)}updateCredentials({tenant:e,user:t,password:n,token:i,tfa:r}={}){var s=l.get(this)||{};return t=(t=t&&e?e+"/"+t:t)||this.user,n=n||s.password,!i&&t&&n&&(i=c(t+":"+n)),t&&(this.user=t),i=i||s.token,r=r||s.tfa,l.set(this,{tfa:r,token:i,password:n}),i}getFetchOptions(e){var{token:t,tfa:n}=l.get(this),i=this.getCookieValue("XSRF-TOKEN"),t=Object.assign({Authorization:"Basic "+(t||"")},i?{"X-XSRF-TOKEN":i}:void 0);return n&&(t.tfatoken=n),e.headers=Object.assign(t,e.headers),e}getCometdHandshake(e={}){var{token:t,tfa:n}=l.get(this),i="com.cumulocity.authn",r=e.ext=e.ext||{};return r[i]=Object.assign(r[i]||{},{token:t,tfa:n}),e}logout(){delete this.user,l.set(this,{})}getCookieValue(e){try{var t=document.cookie.match("(^|;)\\s*"+e+"\\s*=\\s*([^;]+)");return t?t.pop():void 0}catch(e){}}}const u=new WeakMap;class d{constructor(e){u.set(this,{token:e})}getFetchOptions(e){var t=u.get(this)["token"];return e.headers=Object.assign({Authorization:"Bearer "+t},e.headers),e}updateCredentials({token:e}){u.set(this,{token:e})}getCometdHandshake(e={}){var{token:t,tfa:n}=u.get(this),i="com.cumulocity.authn",r=e.ext=e.ext||{};return r[i]=Object.assign(r[i]||{},{token:t,tfa:n}),e}logout(){u.set(this,{})}}class f{constructor(){this.logoutUrl="user/logout"}updateCredentials({user:e}={}){this.user=e}getFetchOptions(e){var t=this.getCookieValue("XSRF-TOKEN");return e.headers=Object.assign({"X-XSRF-TOKEN":t},e.headers),e}getCometdHandshake(e={}){var t="com.cumulocity.authn",n=this.getCookieValue("XSRF-TOKEN"),i=e.ext=e.ext||{};return i[t]=Object.assign(i[t]||{},{xsrfToken:n}),e}logout(){return a(this,void 0,void 0,function*(){this.user&&delete this.user;var e=new h,t=(e.setAuth(this),JSON.stringify({}));return e.fetch(this.logoutUrl,{headers:{"content-type":"application/json",accept:"application/json"},body:t,method:"POST"})})}getCookieValue(e){e=document.cookie.match("(^|;)\\s*"+e+"\\s*=\\s*([^;]+)");return e?e.pop():""}}class g{constructor(e={}){this.xsrfToken=this.getCookieValue(e,"XSRF-TOKEN"),this.authTokenFromCookie=this.getCookieValue(e,"authorization"),this.authTokenFromHeader=e.authorization}updateCredentials(){}getFetchOptions(e){var t=Object.assign({Authorization:this.authTokenFromCookie?"Bearer "+this.authTokenFromCookie:this.authTokenFromHeader},this.xsrfToken?{"X-XSRF-TOKEN":this.xsrfToken}:void 0);return e.headers=Object.assign(t,e.headers),e}getCometdHandshake(e={}){var t="com.cumulocity.authn",n=this.xsrfToken;let i=this.authTokenFromCookie;!i&&this.authTokenFromHeader&&(i=this.authTokenFromHeader.replace("Basic ","").replace("Bearer ",""));var r=e.ext=e.ext||{};return r[t]=Object.assign(r[t]||{},Object.assign({token:i},n?{xsrfToken:n}:void 0)),e}logout(){this.authTokenFromCookie&&delete this.authTokenFromCookie,this.authTokenFromHeader&&delete this.authTokenFromHeader,this.xsrfToken&&delete this.xsrfToken}getCookieValue(e,t){try{var n=e&&e.cookie&&e.cookie.match("(^|;)\\s*"+t+"\\s*=\\s*([^;]+)");return n?n.pop():void 0}catch(e){}}}class v extends g{constructor(e){super();e=e.headers.get("set-cookie");if(!e)throw Error("No Cookie set");this.authTokenFromCookie=this.getCookieValue({cookie:e},"authorization")}}r.Severity=void 0,(S=r.Severity||(r.Severity={}))[S.CRITICAL="CRITICAL"]="CRITICAL",S[S.MAJOR="MAJOR"]="MAJOR",S[S.MINOR="MINOR"]="MINOR",S[S.WARNING="WARNING"]="WARNING";class y{constructor(){this.operatorFns={__not:e=>`not(${this.buildQueryFilter(e,null)})`,__and:e=>this.buildQueryFilter(e,null,"and"),__or:e=>this.buildQueryFilter(e,null,"or"),__eq:(e,t)=>"object"==typeof e&&null!==e?this.buildQueryFilter(e,t):t+" eq "+this.quoteString(e),__gt:(e,t)=>t+" gt "+this.quoteString(e),__ge:(e,t)=>t+" ge "+this.quoteString(e),__lt:(e,t)=>t+" lt "+this.quoteString(e),__le:(e,t)=>t+" le "+this.quoteString(e),__in:(e,t)=>{e=e.filter(e=>!!e).map(e=>t+" eq "+this.quoteString(e));return this.glue(e,"or")},__bygroupid:e=>`bygroupid(${e})`,__has:e=>`has(${e})`,__useFilterQueryString:e=>{e=null==(e=e.match(/\(.*\)/))?void 0:e[0];return null==e?void 0:e.substring(1,e.length-1)}}}buildQuery(e){var t=[],n=this.buildQueryFilter(e.__filter||e),e=this.buildQueryOrderby(e.__orderby);return n&&t.push(`$filter=(${n})`),e&&t.push("$orderby="+e),t.join(" ")}buildQueryFilter(n,e,t){const i=e||null,r=t||"and",s=[];if(Array.isArray(n))n.forEach(e=>{e=this.buildQueryFilter(e,null,r);e&&s.push(e)});else{let t;Object.keys(n).forEach(e=>{void 0!==this.operatorFns[e]?(t=this.operatorFns[e](n[e],i))&&s.push(t):(t=this.operatorFns.__eq(n[e],e))&&s.push(t)})}return this.glue(s,r)}buildQueryOrderby(e){const n=[];return e&&e.forEach(t=>{Object.keys(t).forEach(e=>{0!==t[e]&&n.push(e+" "+(0<t[e]?"asc":"desc"))})}),n.join(",")}addAndFilter(e,t){return this.addFilter(e,t,"and")}addOrFilter(e,t){return this.addFilter(e,t,"or")}addFilter(e,t,n){var i=e.__orderby?e.__filter||{}:e.__filter||e,n={["__"+n]:this.skipEmptyObjects([i,t])};return e.__filter||e.__orderby?(e.__filter=n,e):n}prependOrderbys(e,t){return this.addOrderbys(e,t,"prepend")}appendOrderbys(e,t){return this.addOrderbys(e,t,"append")}addOrderbys(e,t,n){var i=e.__orderby?e.__filter||{}:e.__filter||e,e=e.__orderby||[],n="prepend"===n?[...t,...e]:[...e,...t],e={__orderby:this.skipEmptyObjects(n)};return this.isEmptyObject(i)||(e.__filter=i),e}extractAndMergeOrderBys(e){if(0<(null==e?void 0:e.length))return(e=e.map(e=>{return null==(e=e.match(/\$orderby=(.*)$/))?void 0:e[1]}).filter(e=>!!e).join(","))?"$orderby="+e:""}glue(e,t){return 1<e.length?`(${e.join(`) ${t} (`)})`:e[0]}quoteString(e){return"string"==typeof e?`'${this.escapeSingleQuote(e)}'`:e}skipEmptyObjects(e){return e.filter(e=>!this.isEmptyObject(e))}isEmptyObject(e){return 0===Object.keys(e).length}escapeSingleQuote(e){return"string"!=typeof e?e:e.replace(/\'/g,"''")}}var m,i=t(function(e,t){var be,Te,Oe,m,n,Se,Ee,Ue,h,p;e.exports=(be=function(){var n=0,i={};this.register=function(e){var t=++n;return i[t]=e,t},this.unregister=function(e){var t=i[e];return delete i[e],t},this.setTimeout=function(e,t){return window.setTimeout(e,t)},this.clearTimeout=function(e){window.clearTimeout(e)}},Te={isString:function(e){return null!=e&&("string"==typeof e||e instanceof String)},isArray:function(e){return null!=e&&e instanceof Array},inArray:function(e,t){for(var n=0;n<t.length;++n)if(e===t[n])return n;return-1}},Oe=function(){var c=[],l={};this.getTransportTypes=function(){return c.slice(0)},this.findTransportTypes=function(e,t,n){for(var i=[],r=0;r<c.length;++r){var s=c[r];!0===l[s].accept(e,t,n)&&i.push(s)}return i},this.negotiateTransport=function(e,t,n,i){for(var r=0;r<c.length;++r)for(var s=c[r],o=0;o<e.length;++o)if(s===e[o]){var a=l[s];if(!0===a.accept(t,n,i))return a}return null},this.add=function(e,t,n){for(var i=!1,r=0;r<c.length;++r)if(c[r]===e){i=!0;break}return i||("number"!=typeof n?c.push(e):c.splice(n,0,e),l[e]=t),!i},this.find=function(e){for(var t=0;t<c.length;++t)if(c[t]===e)return l[e];return null},this.remove=function(e){for(var t,n=0;n<c.length;++n)if(c[n]===e)return c.splice(n,1),t=l[e],delete l[e],t;return null},this.clear=function(){c=[],l={}},this.reset=function(e){for(var t=0;t<c.length;++t)l[c[t]].reset(e)}},(m=function(){var n,i,t;this.registered=function(e,t){n=e,i=t},this.unregistered=function(){i=n=null},this._debug=function(){i._debug.apply(i,arguments)},this._mixin=function(){return i._mixin.apply(i,arguments)},this.getConfiguration=function(){return i.getConfiguration()},this.getAdvice=function(){return i.getAdvice()},this.setTimeout=function(e,t){return i.setTimeout(e,t)},this.clearTimeout=function(e){i.clearTimeout(e)},this.convertToMessages=function(t){if(Te.isString(t))try{return JSON.parse(t)}catch(e){throw this._debug("Could not convert to JSON the following string",'"'+t+'"'),e}if(Te.isArray(t))return t;if(null==t)return[];if(t instanceof Object)return[t];throw"Conversion Error "+t+", typeof "+typeof t},this.accept=function(e,t,n){throw"Abstract"},this.getType=function(){return n},this.getURL=function(){return t},this.setURL=function(e){t=e},this.send=function(e,t){throw"Abstract"},this.reset=function(e){this._debug("Transport",n,"reset",e?"initial":"retry")},this.abort=function(){this._debug("Transport",n,"aborted")},this.toString=function(){return this.getType()}}).derive=function(e){function t(){}return t.prototype=e,new t},h=["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z",".","-",":","+","=","^","!","/","*","?","&","<",">","(",")","[","]","{","}","@","%","$","#"],p=[0,68,0,84,83,82,72,0,75,76,70,65,0,63,62,69,0,1,2,3,4,5,6,7,8,9,64,0,73,66,74,71,81,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,77,0,78,67,0,0,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,79,0,80,0,0],{CometD:function(e){var c,s,L,F,a,r=new be,l=this,B=e||"default",o=!1,u=new Oe,n="disconnected",M=0,d=null,h=0,t=[],p=!1,G=0,f={},g=0,i=null,v=[],y={},m={},H={},q=!1,b=!1,T=0,O=0,S=null,E={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 $(e,t){try{return e[t]}catch(e){}}function U(e){return Te.isString(e)}function w(e){return null!=e&&"function"==typeof e}function C(e,t){for(var n="";0<--t&&!(e>=Math.pow(10,t));)n+="0";return n+=e}function V(e,t){var n;window.console&&w(e=window.console[e])&&(n=new Date,[].splice.call(t,0,0,C(n.getHours(),2)+":"+C(n.getMinutes(),2)+":"+C(n.getSeconds(),2)+"."+C(n.getMilliseconds(),3)),e.apply(window.console,t))}function J(e){return new RegExp("(^https?://)?(((\\[[^\\]]+])|([^:/?#]+))(:(\\d+))?)?([^?#]*)(.*)?").exec(e)}function X(e){l._debug("Configuring cometd object with",e),U(e)&&(e={url:e}),E=l._mixin(!1,E,e=e||{});e=l.getURL();if(!e)throw"Missing required configuration parameter 'url' specifying the Bayeux server URL";var n,e=J(e),t=e[2],i=e[8],e=e[9];o=l._isCrossDomain(t),E.appendMessageTypeToURL&&(void 0!==e&&0<e.length?(l._info("Appending message type to URI "+i+e+" is not supported, disabling 'appendMessageTypeToURL' configuration"),E.appendMessageTypeToURL=!1):(e=(t=i.split("/")).length-1,i.match(/\/$/)&&--e,0<=t[e].indexOf(".")&&(l._info("Appending message type to URI "+i+" is not supported, disabling 'appendMessageTypeToURL' configuration"),E.appendMessageTypeToURL=!1))),window.Worker&&window.Blob&&window.URL&&E.useWorkerScheduler&&(t=(t=function(){var i={};self.onmessage=function(e){var t=e.data,n=i[t.id];switch(t.type){case"setTimeout":i[t.id]=self.setTimeout(function(){delete i[t.id],self.postMessage({id:t.id})},t.delay);break;case"clearTimeout":delete i[t.id],n&&self.clearTimeout(n);break;default:throw"Unknown command "+t.type}}}.toString()).substring(t.indexOf("{")+1,t.lastIndexOf("}")),e=new window.Blob([t],{type:"application/json"}),i=window.URL.createObjectURL(e),n=new window.Worker(i),r.setTimeout=function(e,t){e=r.register(e);return n.postMessage({id:e,type:"setTimeout",delay:t}),e},r.clearTimeout=function(e){r.unregister(e),n.postMessage({id:e,type:"clearTimeout"})},n.onmessage=function(e){e=e.data.id,e=r.unregister(e);e&&e()})}function W(e){var t;e&&(t=f[e.channel])&&t[e.id]&&(delete t[e.id],l._debug("Removed",e.listener?"listener":"subscription",e))}function Q(e){e&&!e.listener&&W(e)}function K(){for(var e in f)if(f.hasOwnProperty(e)){var t=f[e];if(t)for(var n in t)t.hasOwnProperty(n)&&Q(t[n])}}function j(e){n!==e&&(l._debug("Status",n,"->",e),n=e)}function R(){return"disconnecting"===n||"disconnected"===n}function A(){return""+ ++M}function Y(e,t,n,i,r){try{return t.call(e,i)}catch(e){t=l.onExtensionException;if(w(t)){l._debug("Invoking extension exception handler",n,e);try{t.call(l,e,n,r,i)}catch(e){l._info("Exception during execution of extension exception handler",n,e)}}else l._info("Exception during execution of extension",n,e);return i}}function z(e,t){var n=f[e];if(n)for(var i in n)if(n.hasOwnProperty(i)){i=n[i];if(i)try{i.callback.call(i.scope,t)}catch(e){var r=l.onListenerException;if(w(r)){l._debug("Invoking listener exception handler",i,e);try{r.call(l,e,i,i.listener,t)}catch(e){l._info("Exception during execution of listener exception handler",i,e)}}else l._info("Exception during execution of listener",i,t,e)}}}function _(e,t){z(e,t);for(var n=e.split("/"),i=n.length-1,r=i;0<r;--r){var s=n.slice(0,r).join("/")+"/*";r===i&&z(s,t),z(s+="*",t)}}function Z(){null!==i&&l.clearTimeout(i),i=null}function ee(e,t){Z();t=y.interval+t;l._debug("Function scheduled in",t,"ms, interval =",y.interval,"backoff =",g,e),i=l.setTimeout(e,t)}function I(e,t,n){for(var i,r=0;r<e.length;++r){var s=e[r],o=s.id;d&&(s.clientId=d),null!=(s=function(e){for(var t=v.length-1;0<=t&&null!=e;--t){var n=v[t],i=n.extension.outgoing;w(i)&&(e=void 0===(i=Y(n.extension,i,n.name,e,!0))?e:i)}return e}(s))?(s.id=o,e[r]=s):(delete m[o],e.splice(r--,1))}0!==e.length&&(t&&(S=e[0]),i=l.getURL(),E.appendMessageTypeToURL&&(i.match(/\/$/)||(i+="/"),n)&&(i+=n),l._debug("Send",n={url:i,sync:!1,messages:e,onSuccess:function(e){try{F.call(l,e)}catch(e){l._info("Exception during handling of messages",e)}},onFailure:function(e,t,n){try{var i=l.getTransport();n.connectionType=i?i.getType():"unknown",a.call(l,e,t,n)}catch(e){l._info("Exception during handling of failure",e)}}}),c.send(n,t))}function k(e){0<h||!0===p?t.push(e):I([e],!1)}function x(){g=0}function te(){var e=t;t=[],0<e.length&&I(e,!1)}function N(e){j("connecting"),ee(function(){var e;R()||(e={id:A(),channel:"/meta/connect",connectionType:c.getType()},b||(e.advice={timeout:0}),j("connecting"),l._debug("Connect sent",e),I([e],!0,"connect"),j("connected"))},e)}function ne(e){e&&(y=l._mixin(!1,{},E.advice,e),l._debug("New advice",y))}function D(e){Z(),e&&c&&c.abort(),o=!1,c=null,j("disconnected"),x(),b=q=!1,S=d=null,(T=h=0)<t.length&&(e=t,t=[],a.call(l,void 0,e,{reason:"Disconnected"}))}function ie(e,t,n){var i=l.onTransportException;if(w(i)){l._debug("Invoking transport exception handler",e,t,n);try{i.call(l,n,e,t)}catch(e){l._info("Exception during execution of transport exception handler",e)}}}function re(e,t){w(e)&&(t=e,e=void 0),d=null,K(),R()&&u.reset(!0),ne({}),p=!(h=0),s=e,L=t;var e="1.0",n=l.getURL(),i=u.findTransportTypes(e,o,n),r={id:A(),version:e,minimumVersion:e,channel:"/meta/handshake",supportedConnectionTypes:i,advice:{timeout:y.timeout,interval:y.interval}},r=l._mixin(!1,{},s,r);if((l._putCallback(r.id,t),!c)&&!(c=u.negotiateTransport(i,e,o,n)))throw t="Could not find initial transport among: "+u.getTransportTypes(),l._warn(t),t;l._debug("Initial transport is",c.getType()),j("handshaking"),l._debug("Handshake sent",r),I([r],!1,"handshake")}function se(t,n){try{t.call(l,n)}catch(e){t=l.onCallbackException;if(w(t)){l._debug("Invoking callback exception handler",e);try{t.call(l,e,n)}catch(e){l._info("Exception during execution of callback exception handler",e)}}else l._info("Exception during execution of message callback",e)}}function P(e){var t=l._getCallback([e.id]);w(t)&&(delete m[e.id],se(t,e))}function oe(e){var t=H[e.id];if(delete H[e.id],t){l._debug("Handling remote call response for",e,"with context",t);var n=t.timeout,n=(n&&l.clearTimeout(n),t.callback);if(w(n))return se(n,e),1}}function ae(e){l._debug("Transport failure handling",e),e.transport&&(c=e.transport),e.url&&c.setURL(e.url);var t,n=e.action,i=e.delay||0;switch(n){case"handshake":t=i,j("handshaking"),p=!0,ee(function(){re(s,L)},t);break;case"retry":N(i);break;case"none":D(!0);break;default:throw"Unknown action "+n}}function ce(e,t){P(e),_("/meta/handshake",e),_("/meta/unsuccessful",e),R()&&(t.action="none"),l.onTransportFailure.call(l,e,t,ae)}function le(e){return"disconnected"===n||S&&S.id===e.id&&(S=null,1)}function ue(e,t){_("/meta/connect",e),_("/meta/unsuccessful",e),R()&&(t.action="none"),l.onTransportFailure.call(l,e,t,ae)}function de(e){D(!0),P(e),_("/meta/disconnect",e),_("/meta/unsuccessful",e)}function he(e){var t,n=f[e.subscription];if(n)for(var i in n)n.hasOwnProperty(i)&&(t=n[i])&&!t.listener&&(delete n[i],l._debug("Removed failed subscription",t));P(e),_("/meta/subscribe",e),_("/meta/unsuccessful",e)}function pe(e){P(e),_("/meta/unsubscribe",e),_("/meta/unsuccessful",e)}function fe(e){oe(e)||(P(e),_("/meta/publish",e),_("/meta/unsuccessful",e))}function ge(e){var t;if(T=0,null!=(e=function(e){for(var t=0;t<v.length&&null!=e;++t){var n=v[t],i=n.extension.incoming;w(i)&&(e=void 0===(i=Y(n.extension,i,n.name,e,!1))?e:i)}return e}(e)))switch(ne(e.advice),e.channel){case"/meta/handshake":var n=e,i=l.getURL();if(n.successful){var r=l._isCrossDomain(J(i)[2]),r=u.negotiateTransport(n.supportedConnectionTypes,n.version,r,i);if(null===r)n.successful=!1,ce(n,{cause:"negotiation",action:"none",transport:null});else{c!==r&&(l._debug("Transport",c.getType(),"->",r.getType()),c=r),d=n.clientId,p=!1,te(),n.reestablish=q,q=!0,P(n),_("/meta/handshake",n),O=n["x-messages"]||0;var s=R()?"none":y.reconnect||"retry";switch(s){case"retry":x(),0===O?N(0):l._debug("Processing",O,"handshake-delivered messages");break;case"none":D(!0);break;default:throw"Unrecognized advice action "+s}}}else ce(n,{cause:"unsuccessful",action:y.reconnect||"handshake",transport:c});break;case"/meta/connect":i=e;if(le(i))if(b=i.successful){_("/meta/connect",i);var o=R()?"none":y.reconnect||"retry";switch(o){case"retry":x(),N(g);break;case"none":D(!1);break;default:throw"Unrecognized advice action "+o}}else ue(i,{cause:"unsuccessful",action:y.reconnect||"retry",transport:c});else l._debug("Mismatched /meta/connect reply",i);break;case"/meta/disconnect":(r=e).successful?(D(!1),P(r),_("/meta/disconnect",r)):de(r);break;case"/meta/subscribe":(n=e).successful?(P(n),_("/meta/subscribe",n)):he(n);break;case"/meta/unsubscribe":(t=e).successful?(P(t),_("/meta/unsubscribe",t)):pe(t);break;default:void 0!==(t=e).data?oe(t)||(_(t.channel,t),0<O&&0===--O&&(l._debug("Processed last handshake-delivered message"),N(0))):void 0===t.successful?l._warn("Unknown Bayeux Message",t):t.successful?(P(t),_("/meta/publish",t)):fe(t)}}function ve(e){var t=f[e];if(t)for(var n in t)if(t.hasOwnProperty(n)&&t[n])return 1}function ye(e,t){var n={scope:e,method:t};if(w(e))n.scope=void 0,n.method=e;else if(U(t)){if(!e)throw"Invalid scope "+e;if(n.method=e[t],!w(n.method))throw"Invalid callback "+t+" for scope "+e}else if(!w(t))throw"Invalid callback "+t;return n}function me(e,t,n,i){var t=ye(t,n),n=(l._debug("Adding",i?"listener":"subscription","on",e,"with scope",t.scope,"and callback",t.method),++G),t={id:n,channel:e,scope:t.scope,callback:t.method,listener:i},r=f[e];return r||(f[e]=r={}),r[n]=t,l._debug("Added",i?"listener":"subscription",t),t}this._mixin=function(e,t,n){for(var i=t||{},r=2;r<arguments.length;++r){var s,o,a=arguments[r];if(null!=a)for(var c in a)a.hasOwnProperty(c)&&(s=$(a,c),o=$(i,c),s!==t)&&void 0!==s&&(e&&"object"==typeof s&&null!==s?s instanceof Array?i[c]=this._mixin(e,o instanceof Array?o:[],s):(o="object"!=typeof o||o instanceof Array?{}:o,i[c]=this._mixin(e,o,s)):i[c]=s)}return i},this._warn=function(){V("warn",arguments)},this._info=function(){"warn"!==E.logLevel&&V("info",arguments)},this._debug=function(){"debug"===E.logLevel&&V("debug",arguments)},this._isCrossDomain=function(e){return!!(window.location&&window.location.host&&e)&&e!==window.location.host},this.send=k,this._getCallback=function(e){return m[e]},this._putCallback=function(e,t){var n=this._getCallback(e);return w(t)&&(m[e]=t),n},this.onTransportFailure=function(e,t,n){this._debug("Transport failure",t,"for",e);var i,r=this.getTransportRegistry(),s=this.getURL(),o=this._isCrossDomain(J(s)[2]),a=r.findTransportTypes("1.0",o,s);"none"===t.action?"/meta/handshake"!==e.channel||t.transport||(i="Could not negotiate transport, client=["+a+"], server=["+e.supportedConnectionTypes+"]",this._warn(i),ie(c.getType(),null,{reason:i,connectionType:c.getType(),transport:c})):(t.delay=this.getBackoffPeriod(),"/meta/handshake"===e.channel?(t.transport||(i=c?c.getType():null,(o=r.negotiateTransport(a,"1.0",o,s))?(s=o.getType(),this._debug("Transport",i,"->",s),ie(i,s,e.failure),t.action="handshake",t.transport=o):(this._warn("Could not negotiate transport, client=["+a+"]"),ie(i,null,e.failure),t.action="none")),"none"!==t.action&&this.increaseBackoffPeriod()):(s=(new Date).getTime(),0===T&&(T=s),"retry"===t.action&&(t.delay=this.increaseBackoffPeriod(),0<(o=y.maxInterval))&&y.timeout+y.interval+o<s-T+g&&(t.action="handshake"),"handshake"===t.action&&(t.delay=0,r.reset(!1),this.resetBackoffPeriod()))),n.call(l,t)},this.receive=ge,F=function(e){l._debug("Received",e);for(var t=0;t<e.length;++t)ge(e[t])},a=function(e,t,n){l._debug("handleFailure",e,t,n),n.transport=e;for(var i,r=0;r<t.length;++r){var s=t[r],o={id:s.id,successful:!1,channel:s.channel,failure:n};switch((n.message=s).channel){case"/meta/handshake":ce(o,{cause:"failure",action:"handshake",transport:null});break;case"/meta/connect":le(i=o)?(b=!1,ue(i,{cause:"failure",action:"retry",transport:null})):l._debug("Mismatched /meta/connect failure",i);break;case"/meta/disconnect":de(o);break;case"/meta/subscribe":o.subscription=s.subscription,he(o);break;case"/meta/unsubscribe":o.subscription=s.subscription,pe(o);break;default:fe(o)}}},this.registerTransport=function(e,t,n){n=u.add(e,t,n);return n&&(this._debug("Registered transport",e),w(t.registered))&&t.registered(e,this),n},this.unregisterTransport=function(e){var t=u.remove(e);return null!==t&&(this._debug("Unregistered transport",e),w(t.unregistered))&&t.unregistered(),t},this.unregisterTransports=function(){u.clear()},this.getTransportTypes=function(){return u.getTransportTypes()},this.findTransport=function(e){return u.find(e)},this.getTransportRegistry=function(){return u},this.configure=function(e){X.call(this,e)},this.init=function(e,t){this.configure(e),this.handshake(t)},this.handshake=function(e,t){if("disconnected"!==n)throw"Illegal state: handshaken";re(e,t)},this.disconnect=function(e,t){var n;R()||(w(e)&&(t=e,e=void 0),n={id:A(),channel:"/meta/disconnect"},e=this._mixin(!1,{},e,n),l._putCallback(e.id,t),j("disconnecting"),I([e],!1,"disconnect"))},this.startBatch=function(){++h,l._debug("Starting batch, depth",h)},this.endBatch=function(){if(--h,l._debug("Ending batch, depth",h),h<0)throw"Calls to startBatch() and endBatch() are not paired";0!==h||R()||p||te()},this.batch=function(e,t){e=ye(e,t);this.startBatch();try{e.method.call(e.scope),this.endBatch()}catch(e){throw this._info("Exception during execution of batch",e),this.endBatch(),e}},this.addListener=function(e,t,n){if(arguments.length<2)throw"Illegal arguments number: required 2, got "+arguments.length;if(U(e))return me(e,t,n,!0);throw"Illegal argument type: channel must be a string"},this.removeListener=function(e){if(!(e&&e.channel&&"id"in e))throw"Invalid argument: expected subscription, not "+e;W(e)},this.clearListeners=function(){f={}},this.subscribe=function(e,t,n,i,r){if(arguments.length<2)throw"Illegal arguments number: required 2, got "+arguments.length;if(!U(e))throw"Illegal argument type: channel must be a string";if(R())throw"Illegal state: disconnected";w(t)&&(r=i,i=n,n=t,t=void 0),w(i)&&(r=i,i=void 0);var s=!ve(e),t=me(e,t,n,!1);return s&&(n={id:A(),channel:"/meta/subscribe",subscription:e},s=this._mixin(!1,{},i,n),l._putCallback(s.id,r),k(s)),t},this.unsubscribe=function(e,t,n){if(arguments.length<1)throw"Illegal arguments number: required 1, got "+arguments.length;if(R())throw"Illegal state: disconnected";w(t)&&(n=t,t=void 0),this.removeListener(e);var e=e.channel;ve(e)||(e={id:A(),channel:"/meta/unsubscribe",subscription:e},t=this._mixin(!1,{},t,e),l._putCallback(t.id,n),k(t))},this.resubscribe=function(e,t){if(Q(e),e)return this.subscribe(e.channel,e.scope,e.callback,t)},this.clearSubscriptions=function(){K()},this.publish=function(e,t,n,i){if(arguments.length<1)throw"Illegal arguments number: required 1, got "+arguments.length;if(!U(e))throw"Illegal argument type: channel must be a string";if(/^\/meta\//.test(e))throw"Illegal argument: cannot publish to meta channels";if(R())throw"Illegal state: disconnected";w(t)?(i=t,t={},n=void 0):w(n)&&(i=n,n=void 0);e={id:A(),channel:e,data:t},t=this._mixin(!1,{},n,e);l._putCallback(t.id,i),k(t)},this.publishBinary=function(e,t,n,i,r){w(t)?(r=t,t=new ArrayBuffer(0),n=!0,i=void 0):w(n)?(r=n,n=!0,i=void 0):w(i)&&(r=i,i=void 0);this.publish(e,{meta:i,data:t,last:n},{ext:{binary:{}}},r)},this.remoteCall=function(e,t,n,i,r){if(arguments.length<1)throw"Illegal arguments number: required 1, got "+arguments.length;if(!U(e))throw"Illegal argument type: target must be a string";if(R())throw"Illegal state: disconnected";if(w(t)?(r=t,t={},n=E.maxNetworkDelay,i=void 0):w(n)?(r=n,n=E.maxNetworkDelay,i=void 0):w(i)&&(r=i,i=void 0),"number"!=typeof n)throw"Illegal argument type: timeout must be a number";e.match(/^\//)||(e="/"+e);var e={id:A(),channel:"/service"+e,data:t},s=this._mixin(!1,{},i,e),t={callback:r};0<n&&(t.timeout=l.setTimeout(function(){l._debug("Timing out remote call",s,"after",n,"ms"),fe({id:s.id,error:"406::timeout",successful:!1,failure:{message:s,reason:"Remote Call Timeout"}})},n),l._debug("Scheduled remote call timeout",s,"in",n,"ms")),H[s.id]=t,k(s)},this.remoteCallBinary=function(e,t,n,i,r,s){w(t)?(s=t,t=new ArrayBuffer(0),n=!0,i=void 0,r=E.maxNetworkDelay):w(n)?(s=n,n=!0,i=void 0,r=E.maxNetworkDelay):w(i)?(s=i,i=void 0,r=E.maxNetworkDelay):w(r)&&(s=r,r=E.maxNetworkDelay);this.remoteCall(e,{meta:i,data:t,last:n},r,{ext:{binary:{}}},s)},this.getStatus=function(){return n},this.isDisconnected=R,this.setBackoffIncrement=function(e){E.backoffIncrement=e},this.getBackoffIncrement=function(){return E.backoffIncrement},this.getBackoffPeriod=function(){return g},this.increaseBackoffPeriod=function(){return g<E.maxBackoff&&(g+=E.backoffIncrement),g},this.resetBackoffPeriod=function(){x()},this.setLogLevel=function(e){E.logLevel=e},this.registerExtension=function(e,t){if(arguments.length<2)throw"Illegal arguments number: required 2, got "+arguments.length;if(!U(e))throw"Illegal argument type: extension name must be a string";for(var n=!1,i=0;i<v.length;++i)if(v[i].name===e){n=!0;break}return n?(this._info("Could not register extension with name",e,"since another extension with the same name already exists"),!1):(v.push({name:e,extension:t}),this._debug("Registered extension",e),w(t.registered)&&t.registered(e,this),!0)},this.unregisterExtension=function(e){if(!U(e))throw"Illegal argument type: extension name must be a string";for(var t=!1,n=0;n<v.length;++n){var i=v[n];if(i.name===e){v.splice(n,1),t=!0,this._debug("Unregistered extension",e);i=i.extension;w(i.unregistered)&&i.unregistered();break}}return t},this.getExtension=function(e){for(var t=0;t<v.length;++t){var n=v[t];if(n.name===e)return n.extension}return null},this.getName=function(){return B},this.getClientId=function(){return d},this.getURL=function(){if(c){var e=c.getURL();if(e)return e;if(e=E.urls[c.getType()])return e}return E.url},this.getTransport=function(){return c},this.getConfiguration=function(){return this._mixin(!0,{},E)},this.getAdvice=function(){return this._mixin(!0,{},y)},this.setTimeout=function(t,e){return r.setTimeout(function(){try{l._debug("Invoking timed function",t),t()}catch(e){l._debug("Exception invoking timed function",t,e)}},e)},this.clearTimeout=function(e){r.clearTimeout(e)},window.WebSocket&&this.registerTransport("websocket",new Ue),this.registerTransport("long-polling",new Se),this.registerTransport("callback-polling",new Ee)},Transport:m,RequestTransport:n=function(){var i=new m,e=m.derive(i),r=0,s=null,o=[],a=[];function c(i,r){var e,s,o;this.transportSend(i,r),r.expired=!1,i.sync||(e=this.getConfiguration().maxNetworkDelay,s=e,!0===r.metaConnect&&(s+=this.getAdvice().timeout),this._debug("Transport",this.getType(),"waiting at most",s,"ms for the response, maxNetworkDelay",e),r.timeout=(o=this).setTimeout(function(){r.expired=!0;var e="Request "+r.id+" of transport "+o.getType()+" exceeded "+s+" ms max network delay",t={reason:e},n=r.xhr;t.httpCode=o.xhrStatus(n),o.abortXHR(n),o._debug(e),o.complete(r,!1,r.metaConnect),i.onFailure(n,i.messages,t)},s))}function l(e){var t=++r,n={id:t,metaConnect:!1,envelope:e};o.length<this.getConfiguration().maxConnections-1?(o.push(n),c.call(this,e,n)):(this._debug("Transport",this.getType(),"queueing request",t,"envelope",e),a.push([e,n]))}function u(e,t){var n,i,r,s=Te.inArray(e,o);0<=s&&o.splice(s,1),0<a.length&&(s=a.shift(),n=s[0],i=s[1],this._debug("Transport dequeued request",i.id),t?(this.getConfiguration().autoBatch&&function(e){for(;0<a.length;){var t=a[0],n=t[0],t=t[1];if(n.url!==e.url||n.sync!==e.sync)break;a.shift(),e.messages=e.messages.concat(n.messages),this._debug("Coalesced",n.messages.length,"messages from request",t.id)}}.call(this,n),l.call(this,n),this._debug("Transport completed request",e.id,n)):(r=this).setTimeout(function(){r.complete(i,!1,i.metaConnect);var e={reason:"Previous request failed"},t=i.xhr;e.httpCode=r.xhrStatus(t),n.onFailure(t,n.messages,e)},0))}return e.complete=function(e,t,n){n?function(e){if(e=e.id,this._debug("Transport",this.getType(),"/meta/connect complete, request",e),null!==s&&s.id!==e)throw"/meta/connect request mismatch, completing request "+e;s=null}.call(this,e):u.call(this,e,t)},e.transportSend=function(e,t){throw"Abstract"},e.transportSuccess=function(e,t,n){t.expired||(this.clearTimeout(t.timeout),this.complete(t,!0,t.metaConnect),n&&0<n.length?e.onSuccess(n):e.onFailure(t.xhr,e.messages,{httpCode:204}))},e.transportFailure=function(e,t,n){t.expired||(this.clearTimeout(t.timeout),this.complete(t,!1,t.metaConnect),e.onFailure(t.xhr,e.messages,n))},e.send=function(e,t){(t?function(e){if(null!==s)throw"Concurrent /meta/connect requests not allowed, request id="+s.id+" not yet completed";var t=++r,t=(this._debug("Transport",this.getType(),"/meta/connect send, request",t,"envelope",e),{id:t,metaConnect:!0,envelope:e});c.call(this,e,t),s=t}:l).call(this,e)},e.abort=function(){i.abort();for(var e=0;e<o.length;++e){var t=o[e];t&&(this._debug("Aborting request",t),this.abortXHR(t.xhr)||this.transportFailure(t.envelope,t,{reason:"abort"}))}var n=s;n&&(this._debug("Aborting /meta/connect request",n),this.abortXHR(n.xhr)||this.transportFailure(n.envelope,n,{reason:"abort"})),this.reset(!0)},e.reset=function(e){i.reset(e),s=null,o=[],a=[]},e.abortXHR=function(e){if(e)try{var t=e.readyState;return e.abort(),t!==window.XMLHttpRequest.UNSENT}catch(e){this._debug(e)}return!1},e.xhrStatus=function(e){if(e)try{return e.status}catch(e){this._debug(e)}return-1},e},LongPollingTransport:Se=function(){var t=new n,r=m.derive(t),a=!0;return r.accept=function(e,t,n){return a||!t},r.newXMLHttpRequest=function(){return new window.XMLHttpRequest},r.xhrSend=function(e){var t=r.newXMLHttpRequest(),n=(!function(e){try{e.context=r.context}catch(e){this._debug("Could not copy transport context into XHR",e)}}(t),t.withCredentials=!0,t.open("POST",e.url,!0!==e.sync),e.headers);if(n)for(var i in n)n.hasOwnProperty(i)&&t.setRequestHeader(i,n[i]);return t.setRequestHeader("Content-Type","application/json;charset=UTF-8"),t.onload=function(){200===t.status?e.onSuccess(t.responseText):e.onError(t.statusText)},t.onabort=t.onerror=function(){e.onError(t.statusText)},t.send(e.body),t},r.transportSend=function(i,r){this._debug("Transport",this.getType(),"sending request",r.id,"envelope",i);var s=this;try{var o=!0;r.xhr=this.xhrSend({transport:this,url:i.url,sync:i.sync,headers:this.getConfiguration().requestHeaders,body:JSON.stringify(i.messages),onSuccess:function(t){s._debug("Transport",s.getType(),"received response",t);var n=!1;try{var e=s.convertToMessages(t);0===e.length?(a=!1,s.transportFailure(i,r,{httpCode:204})):(n=!0,s.transportSuccess(i,r,e))}catch(e){s._debug(e),n||(a=!1,(t={exception:e}).httpCode=s.xhrStatus(r.xhr),s.transportFailure(i,r,t))}},onError:function(e,t){s._debug("Transport",s.getType(),"received error",e,t),a=!1;var n={reason:e,exception:t};n.httpCode=s.xhrStatus(r.xhr),o?s.setTimeout(function(){s.transportFailure(i,r,n)},0):s.transportFailure(i,r,n)}}),o=!1}catch(e){a=!1,this.setTimeout(function(){s.transportFailure(i,r,{exception:e})},0)}},r.reset=function(e){t.reset(e),a=!0},r},CallbackPollingTransport:Ee=function(){var e=new n,e=m.derive(e),s=0;function f(e,t,n){var i=this;return function(){i.transportFailure(e,t,"error",n)}}return e.accept=function(e,t,n){return!0},e.jsonpSend=function(t){var n=document.getElementsByTagName("head")[0],i=document.createElement("script"),r="_cometd_jsonp_"+s++,e=(window[r]=function(e){n.removeChild(i),delete window[r],t.onSuccess(e)},t.url),e=(e=(e+=e.indexOf("?")<0?"?":"&")+("jsonp="+r))+("&message="+encodeURIComponent(t.body));i.src=e,i.async=!0!==t.sync,i.type="application/javascript",i.onerror=function(e){t.onError("jsonp "+e.type)},n.appendChild(i)},e.transportSend=function(e,i){for(var r=this,t=0,n=e.messages.length,s=[];0<n;){var o=JSON.stringify(e.messages.slice(t,t+n)),o=e.url.length+encodeURI(o).length,a=this.getConfiguration().maxURILength;if(a<o){if(1===n)return o="Bayeux message too big ("+o+" bytes, max is "+a+") for transport "+this.getType(),void this.setTimeout(f.call(this,e,i,o),0);--n}else s.push(n),t+=n,n=e.messages.length-t}var c=e;if(1<s.length){var l=s[0];this._debug("Transport",this.getType(),"split",e.messages.length,"messages into",s.join(" + ")),(c=this._mixin(!1,{},e)).messages=e.messages.slice(0,l),c.onSuccess=e.onSuccess,c.onFailure=e.onFailure;for(var u=1;u<s.length;++u){var d=this._mixin(!1,{},e),h=l;l+=s[u],d.messages=e.messages.slice(h,l),d.onSuccess=e.onSuccess,d.onFailure=e.onFailure,this.send(d,i.metaConnect)}}this._debug("Transport",this.getType(),"sending request",i.id,"envelope",c);try{var p=!0;this.jsonpSend({transport:this,url:c.url,sync:c.sync,headers:this.getConfiguration().requestHeaders,body:JSON.stringify(c.messages),onSuccess:function(e){var t=!1;try{var n=r.convertToMessages(e);0===n.length?r.transportFailure(c,i,{httpCode:204}):(t=!0,r.transportSuccess(c,i,n))}catch(e){r._debug(e),t||r.transportFailure(c,i,{exception:e})}},onError:function(e,t){var n={reason:e,exception:t};p?r.setTimeout(function(){r.transportFailure(c,i,n)},0):r.transportFailure(c,i,n)}}),p=!1}catch(e){this.setTimeout(function(){r.transportFailure(c,i,{exception:e})},0)}},e},WebSocketTransport:Ue=function(){var c,n=new m,e=m.derive(n),l=!0,u=!1,d=!0,h=null,p=null,v=!1,y=null;function f(e,t){e&&(this.webSocketClose(e,t.code,t.reason),this.onClose(e,t))}function g(e){return e===p||e===h}function r(e,t,n){for(var i=[],r=0;r<t.messages.length;++r){var s=t.messages[r];s.id&&i.push(s.id)}e.envelopes[i.join(",")]=[t,n],this._debug("Transport",this.getType(),"stored envelope, envelopes",e.envelopes)}function s(t,n,e){for(var i=JSON.stringify(n.messages),i=(t.webSocket.send(i),this._debug("Transport",this.getType(),"sent",n,"/meta/connect =",e),this.getConfiguration().maxNetworkDelay),r=i,s=(e&&(r+=this.getAdvice().timeout,v=!0),this),o=[],a=0;a<n.messages.length;++a)!function(){var e=n.messages[a];e.id&&(o.push(e.id),t.timeouts[e.id]=s.setTimeout(function(){c._debug("Transport",s.getType(),"timing out message",e.id,"after",r,"on",t),f.call(s,t,{code:1e3,reason:"Message Timeout"})},r))}();this._debug("Transport",this.getType(),"waiting at most",r,"ms for messages",o,"maxNetworkDelay",i,", timeouts:",t.timeouts)}function i(t,e,n){try{null===t?(t=p||{envelopes:{},timeouts:{}},r.call(this,t,e,n),function(t){if(!p){var e=c.getURL().replace(/^http/,"ws");this._debug("Transport",this.getType(),"connecting to URL",e);try{var n=c.getConfiguration().protocol;t.webSocket=n?new window.WebSocket(e,n):new window.WebSocket(e),p=t}catch(e){throw l=!1,this._debug("Exception while creating WebSocket object",e),e}d=!1!==c.getConfiguration().stickyReconnect;var i=this,r=c.getConfiguration().connectTimeout,s=(0<r&&(t.connectTimer=this.setTimeout(function(){c._debug("Transport",i.getType(),"timed out while connecting to URL",e,":",r,"ms"),f.call(i,t,{code:1e3,reason:"Connect Timeout"})},r)),function(e){c._debug("WebSocket onclose",t,e=e||{code:1e3},"connecting",p,"current",h),t.connectTimer&&i.clearTimeout(t.connectTimer),i.onClose(t,e)});t.webSocket.onopen=function(){c._debug("WebSocket onopen",t),t.connectTimer&&i.clearTimeout(t.connectTimer),g(t)?(h=t,u=!(p=null),i.onOpen(t)):(c._warn("Closing extra WebSocket connection",this,"active connection",h),f.call(i,t,{code:1e3,reason:"Extra Connection"}))},t.webSocket.onclose=s,t.webSocket.onerror=function(){s({code:1e3,reason:"Error"})},t.webSocket.onmessage=function(e){c._debug("WebSocket onmessage",e,t),i.onMessage(t,e)},this._debug("Transport",this.getType(),"configured callbacks on",t)}}.call(this,t)):(r.call(this,t,e,n),s.call(this,t,e,n))}catch(e){var i=this;this.setTimeout(function(){f.call(i,t,{code:1e3,reason:"Exception",exception:e})},0)}}return e.reset=function(e){n.reset(e),e&&(u=!1),p=h=null,v=!(d=l=!0)},e._notifySuccess=function(e,t){e.call(this,t)},e._notifyFailure=function(e,t,n,i){e.call(this,t,n,i)},e.onOpen=function(e){var t,n,i,r=e.envelopes;for(t in this._debug("Transport",this.getType(),"opened",e,"pending messages",r),r)r.hasOwnProperty(t)&&(n=(i=r[t])[0],i=i[1],y=n.onSuccess,s.call(this,e,n,i))},e.onMessage=function(e,t){this._debug("Transport",this.getType(),"received websocket message",t,e);for(var n=!1,i=this.convertToMessages(t.data),r=[],s=0;s<i.length;++s){var o,a=i[s];(/^\/meta\//.test(a.channel)||void 0===a.data)&&a.id&&(r.push(a.id),o=e.timeouts[a.id])&&(this.clearTimeout(o),delete e.timeouts[a.id],this._debug("Transport",this.getType(),"removed timeout for message",a.id,", timeouts",e.timeouts)),"/meta/connect"===a.channel&&(v=!1),"/meta/disconnect"!==a.channel||v||(n=!0)}for(var c=!1,l=e.envelopes,u=0;u<r.length;++u){var d,h=r[u];for(d in l)if(l.hasOwnProperty(d)){var p=d.split(","),f=Te.inArray(h,p);if(0<=f){c=!0,p.splice(f,1);var f=l[d][0],g=l[d][1];delete l[d],0<p.length&&(l[p.join(",")]=[f,g]);break}}}c&&this._debug("Transport",this.getType(),"removed envelope, envelopes",l),this._notifySuccess(y,i),n&&this.webSocketClose(e,1e3,"Disconnect")},e.onClose=function(e,t){this._debug("Transport",this.getType(),"closed",e,t),g(e)&&(l=d&&u,h=p=null);var n,i=e.timeouts;for(n in e.timeouts={},i)i.hasOwnProperty(n)&&this.clearTimeout(i[n]);var r,s,o,a=e.envelopes;for(r in e.envelopes={},a)a.hasOwnProperty(r)&&(s=a[r][0],a[r][1]&&(v=!1),o={websocketCode:t.code,reason:t.reason},t.exception&&(o.exception=t.exception),this._notifyFailure(s.onFailure,e,s.messages,o))},e.registered=function(e,t){n.registered(e,t),c=t},e.accept=function(e,t,n){return this._debug("Transport",this.getType(),"accept, supported:",l),l&&!!window.WebSocket&&!1!==c.websocketEnabled},e.send=function(e,t){this._debug("Transport",this.getType(),"sending",e,"/meta/connect =",t),i.call(this,h,e,t)},e.webSocketClose=function(e,t,n){try{e.webSocket&&e.webSocket.close(t,n)}catch(e){this._debug(e)}},e.abort=function(){n.abort(),f.call(this,h,{code:1e3,reason:"Abort"}),this.reset(!0)},e},Utils:Te,Z85:{encode:function(e){var t=null;if(e instanceof ArrayBuffer?t=e:e.buffer instanceof ArrayBuffer?t=e.buffer:Array.isArray(e)&&(t=new Uint8Array(e).buffer),null==t)throw"Cannot Z85 encode "+e;for(var n=t.byteLength,e=n%4,i=4-(0==e?4:e),r=new DataView(t),s="",o=0,a=0;a<n+i;++a){var c=n<=a,o=256*o+(c?0:r.getUint8(a));if((a+1)%4==0){for(var l,u=52200625,d=5;0<d;--d)(!c||i<d)&&(l=Math.floor(o/u)%85,s+=h[l]),u/=85;o=0}}return s},decode:function(e){for(var t=e.length%5,n=5-(0==t?5:t),i=0;i<n;++i)e+=h[h.length-1];for(var r=e.length,t=new ArrayBuffer(4*r/5-n),s=new DataView(t),o=0,a=0,c=0,l=0;l<r;++l){var u=e.charCodeAt(a++)-32,o=85*o+p[u];if(a%5==0){for(var d=16777216;1<=d;)c<s.byteLength&&s.setUint8(c++,Math.floor(o/d)%256),d/=256;o=0}}return t}}})}),M={CometD:i.CometD,default:i}.CometD;(S=m=m||{}).HANDSHAKE="/meta/handshake",S.CONNECT="/meta/connect",S.SUBSCRIBE="/meta/subscribe",S.UNSUBSCRIBE="/meta/unsubscribe";class b{constructor(e,t="/notification/realtime",n){this.client=e,this.url=t,this.metaHandshake=e=>{if(!e.successful)throw new Error("Handshake failed")},this.cometd=new M({}),this.cometd.websocketEnabled=!0,this.cometd.addListener(m.HANDSHAKE,n||this.metaHandshake)}subscribe(e,t){return this.checkConnection(),this.cometd.subscribe(e,t)}unsubscribe(e){return this.cometd.unsubscribe(e)}addHandshakeListener(e){return this.cometd.addListener(m.HANDSHAKE,e)}addConnectListener(e){return this.cometd.addListener(m.CONNECT,e)}removeListener(e){return this.cometd.removeListener(e)}resubscribe(e){return this.cometd.resubscribe(e)}disconnect(e=void 0){this.cometd.disconnect(e)}isDisconnected(){return this.cometd.isDisconnected()}checkConnection(){var e,{cometd:t,client:n,url:i}=this;t.isDisconnected()&&(e=n.getFetchOptions()["headers"],i={url:n.getUrl(i),requestHeaders:e},t.configure(i),this.handshake(n.getCometdHandshake()))}handshake(e){this.cometd.handshake(e,void 0)}}class T extends e{constructor(){super(...arguments),this.baseUrl="event",this.listUrl="events",this.propertyName="events",this.channel="/events/*"}detail(e){const t=Object.create(null,{detail:{get:()=>super.detail}});return a(this,void 0,void 0,function*(){return t.detail.call(this,e)})}create(e){const t=Object.create(null,{create:{get:()=>super.create}});return a(this,void 0,void 0,function*(){return t.create.call(this,e)})}update(e){const t=Object.create(null,{update:{get:()=>super.update}});return a(this,void 0,void 0,function*(){return t.update.call(this,e)})}list(e={}){const t=Object.create(null,{list:{get:()=>super.list}});return a(this,void 0,void 0,function*(){return t.list.call(this,e)})}delete(e){const t=Object.create(null,{delete:{get:()=>super.delete}});return a(this,void 0,void 0,function*(){return t.delete.call(this,e)})}}var O,S,E=("object"==typeof self?self:window).FormData;class G extends e{constructor(){super(...arguments),this.baseUrl="event",this.listUrl="events"}upload(n,i){return a(this,void 0,void 0,function*(){var e=this.getDetailUrl(i),t=new E,e=(t.append("file",n),yield this.fetch(e,{method:"POST",body:t,headers:{accept:"application/json"}})),t=yield e.json();return{res:e,data:t}})}download(t){return a(this,void 0,void 0,function*(){var e=this.getDetailUrl(t);return yield this.fetch(e)})}delete(e){const t=Object.create(null,{delete:{get:()=>super.delete}});return a(this,void 0,void 0,function*(){return t.delete.call(this,e)})}getDetailUrl(e){let t;return t="object"==typeof e&&e.id?e.id:e,`${this.listUrl}/${t}/binaries`}}class U extends e{constructor(){super(...arguments),this.baseUrl="inventory",this.listUrl="binaries",this.propertyName="managedObjects"}create(r,s={}){return a(this,void 0,void 0,function*(){var e=this.listUrl,t=new E;let n,i;s.fileName&&(n=s.fileName,delete s.fileName),s.fileType&&(i=s.fileType,delete s.fileType),n=n||"bin","undefined"!=typeof File&&r instanceof File&&(n=r.name,i=r.type),s.name||(s.name=n),s.type||(s.type=i||"c8y_upload"),t.append("file",r,n),t.append("object",JSON.stringify(s));e=yield this.fetch(e,{method:"POST",body:t,headers:{accept:"application/json"}}),t=yield e.json();return{res:e,data:t}})}list(e={}){const t=Object.create(null,{list:{get:()=>super.list}});return a(this,void 0,void 0,function*(){return t.list.call(this,e)})}delete(e){const t=Object.create(null,{delete:{get:()=>super.delete}});return a(this,void 0,void 0,function*(){return t.delete.call(this,e)})}download(t,n){return a(this,void 0,void 0,function*(){var e=this.getDetailUrl(t);return yield this.fetch(e,n)})}createWithProgress(e,t,n={}){var i=`/${this.baseUrl}/`+this.listUrl,r=new E;let s,o;n.fileName&&(s=n.fileName,delete n.fileName),n.fileType&&(o=n.fileType,delete n.fileType),s=s||"bin","undefined"!=typeof File&&e instanceof File&&(s=e.name,o=e.type),n.name||(n.name=s),n.type||(n.type=o||"c8y_upload"),r.append("file",e,s),r.append("object",JSON.stringify(n));let a;"function"==typeof r.getHeaders&&(a=r.getHeaders());var c=this.client.getFetchOptions().headers,l=(Object.assign(c,{accept:"application/json"},a),new XMLHttpRequest);l.open("POST",i,!0);for(const d in c)c.hasOwnProperty(d)&&l.setRequestHeader(d,c[d]);l.upload.addEventListener("progress",t);let u;return u="function"==typeof r.getBuffer?r.getBuffer():r,l.send(u),l}getXMLHttpResponse(n){return new Promise((e,t)=>{n.addEventListener("loadend",()=>{4!==n.readyState||200!==n.status&&201!==n.status?t(n.responseText?{data:JSON.parse(n.responseText)}:"Could not upload file."):e(JSON.parse(n.responseText))})})}getIdFromUrl(e){var t;if(e)return t=new RegExp("\\/inventory\\/binaries\\/(\\d+)|\\/inventory\\/managedObjects\\/(\\d+)"),(e=e.match(t))&&(e[1]||e[2])}}r.ChildType=void 0,(i=r.ChildType||(r.ChildType={})).ASSETS="childAssets",i.DEVICES="childDevices",i.ADDITIONS="childAdditions";class w extends e{constructor(e,t){super(e,t),this.baseUrl="inventory",this.listUrl="managedObjects",this.propertyName="managedObjects",this.channel="/managedobjects/*",this.inventoriesQueryParamName="query",this.devicesQueryParamName="q",this.queriesUtil=new y,this.binary=new U(e)}detail(e,t={}){const n=Object.create(null,{detail:{get:()=>super.detail}});return a(this,void 0,void 0,function*(){return n.detail.call(this,e,t)})}create(e){const t=Object.create(null,{create:{get:()=>super.create}});return a(this,void 0,void 0,function*(){return t.create.call(this,e)})}update(e){const t=Object.create(null,{update:{get:()=>super.update}});return a(this,void 0,void 0,function*(){return t.update.call(this,e)})}list(e={}){const t=Object.create(null,{list:{get:()=>super.list}});return a(this,void 0,void 0,function*(){return t.list.call(this,e)})}listQuery(e,t={}){const n=Object.create(null,{list:{get:()=>super.list}});return a(this,void 0,void 0,function*(){return t[this.inventoriesQueryParamName]=this.queriesUtil.buildQuery(e),n.list.call(this,t)})}listQueryDevices(e,t={}){const n=Object.create(null,{list:{get:()=>super.list}});return a(this,void 0,void 0,function*(){return t[this.devicesQueryParamName]=this.queriesUtil.buildQuery(e),n.list.call(this,t)})}delete(e,t={}){const n=Object.create(null,{delete:{get:()=>super.delete}});return a(this,void 0,void 0,function*(){return n.delete.call(this,e,t)})}childAdditionsList(e,t={}){return a(this,void 0,void 0,function*(){return this.listChildren(r.ChildType.ADDITIONS,e,t)})}childAdditionsCreate(e,t){return a(this,void 0,void 0,function*(){return this.createChild(r.ChildType.ADDITIONS,e,t)})}childAdditionsAdd(e,t){return a(this,void 0,void 0,function*(){return this.addChild(r.ChildType.ADDITIONS,e,t)})}childAdditionsRemove(e,t){return a(this,void 0,void 0,function*(){return this.removeChild(r.ChildType.ADDITIONS,e,t)})}childAssetsList(e,t={}){return a(this,void 0,void 0,function*(){return this.listChildren(r.ChildType.ASSETS,e,t)})}childAssetsCreate(e,t){return a(this,void 0,void 0,function*(){return this.createChild(r.ChildType.ASSETS,e,t)})}childAssetsAdd(e,t){return a(this,void 0,void 0,function*(){return this.addChild(r.ChildType.ASSETS,e,t)})}childAssetsBulkAdd(e,t){return a(this,void 0,void 0,function*(){return this.addChildBulk(r.ChildType.ASSETS,e,t)})}childAssetsRemove(e,t){return a(this,void 0,void 0,function*(){return this.removeChild(r.ChildType.ASSETS,e,t)})}childDevicesList(e,t={}){return a(this,void 0,void 0,function*(){return this.listChildren(r.ChildType.DEVICES,e,t)})}childDevicesCreate(e,t){return a(this,void 0,void 0,function*(){return this.createChild(r.ChildType.DEVICES,e,t)})}childDevicesAdd(e,t){return a(this,void 0,void 0,function*(){return this.addChild(r.ChildType.DEVICES,e,t)})}childDevicesRemove(e,t){return a(this,void 0,void 0,function*(){return this.removeChild(r.ChildType.DEVICES,e,t)})}getSupportedMeasurements(e){return a(this,void 0,void 0,function*(){return this.getSupportedMeasurementDetails(e,"supportedMeasurements")})}getSupportedSeries(e){return a(this,void 0,void 0,function*(){return this.getSupportedMeasurementDetails(e,"supportedSeries")})}getMeasurementsAndSeries(i){return a(this,void 0,void 0,function*(){var[e,t]=yield Promise.all([this.getSupportedMeasurements(i),this.getSupportedSeries(i)]);const n=e.sort((e,t)=>t.length-e.length);return t.map(t=>{var e=n.find(e=>0===t.indexOf(e+"."));return{fragment:e,series:t.replace(e+".","")}}).filter(e=>!!e.fragment)})}assetKPIsList(e,t={}){return a(this,void 0,void 0,function*(){return this.listKPIs(e,t)})}listKPIs(n,i={}){return a(this,void 0,void 0,function*(){var e=this.getChildrenUrl("kpis",n),e=yield this.fetch(e,this.changeFetchOptions({headers:{accept:"application/json"},params:i},e)),t=yield e.json();return{res:e,data:t[this.propertyName],paging:this.getPaging(t,i)}})}onBeforeUpdate(e){return delete e.lastUpdated,e}onBeforeCreate(e){return delete e.id,delete e.lastUpdated,e}getChildrenUrl(e,t){return this.getDetailUrl(t)+"/"+e}getChildUrl(e,t,n){t=this.getIdString(t);return this.getChildrenUrl(e,n)+"/"+t}listChildren(i,r,s={}){return a(this,void 0,void 0,function*(){var e=this.getChildrenUrl(i,r),e=yield this.fetch(e,{headers:{"content-type":"application/json"},params:s}),t=yield e.json(),n=t.references.map(e=>e.managedObject),t=this.getPaging(t,s);return t.list=e=>this.listChildren(i,r,e),{res:e,data:n,paging:t}})}createChild(i,r,s){return a(this,void 0,void 0,function*(){var e=this.getChildrenUrl(i,s),t=JSON.stringify(this.onBeforeCreate(r)),n={"content-type":this.mimeType("managedObject"),accept:"application/json"},e=yield this.fetch(e,{method:"POST",body:t,headers:n}),t=yield e.json();return{res:e,data:t}})}addChild(i,r,s){return a(this,void 0,void 0,function*(){var e=this.getChildrenUrl(i,s),t=this.getIdString(r),t=JSON.stringify({managedObject:{id:String(t)}}),n={accept:"application/json","content-type":this.mimeType("managedObjectReference")},e=yield this.fetch(e,{method:"POST",body:t,headers:n}),t=yield e.json();return{res:e,data:t.managedObject}})}addChildBulk(i,r,s){return a(this,void 0,void 0,function*(){var e=this.getChildrenUrl(i,s),t=r.map(e=>({managedObject:{id:this.getIdString(e)}})),t=JSON.stringify({references:t}),n={accept:"application/json","content-type":this.mimeType("managedObjectReferenceCollection")},e=yield this.fetch(e,{method:"POST",body:t,headers:n}),t=(yield e.json()).references;return{res:e,data:t.map(e=>e.managedObject)}})}removeChild(t,n,i){return a(this,void 0,void 0,function*(){var e=this.getIdString(n),e=this.getChildrenUrl(t,i)+"/"+e;return{res:yield this.fetch(e,{method:"DELETE",headers:{accept:"application/json"}}),data:null}})}getSupportedMeasurementDetails(t,n="supportedSeries"){return a(this,void 0,void 0,function*(){var e=this.getDetailUrl(t)+"/"+n,e=(this.getIdString(t),yield(yield this.fetch(e,{headers:{accept:"application/json"}})).json());return e.c8y_SupportedMeasurements||e.c8y_SupportedSeries})}}class C extends e{constructor(){super(...arguments),this.baseUrl="measurement",this.listUrl="measurements",this.propertyName="measurements",this.channel="/measurements/*"}detail(e){const t=Object.create(null,{detail:{get:()=>super.detail}});return a(this,void 0,void 0,function*(){return t.detail.call(this,e)})}create(e){const t=Object.create(null,{create:{get:()=>super.create}});return a(this,void 0,void 0,function*(){return t.create.call(this,this.onBeforeCreate(e))})}list(e={}){const t=Object.create(null,{list:{get:()=>super.list}});return a(this,void 0,void 0,function*(){return t.list.call(this,e)})}delete(e){const t=Object.create(null,{delete:{get:()=>super.delete}});return a(this,void 0,void 0,function*(){return t.delete.call(this,e)})}listSeries(n){return a(this,void 0,void 0,function*(){var e=`${this.baseUrl}/${this.listUrl}/series`,e=yield this.client.fetch(e,{params:n}),t=yield e.json();return{res:e,data:t}})}onBeforeCreate(e){var t;return e.time||(e.time=(new Date).toISOString()),e.type||(e.type="c8y_Measurement"),e.sourceId&&(t=e["sourceId"],delete e.sourceId,e.source||(e.source={id:String(t)})),e}}r.aggregationType=void 0,(S=r.aggregationType||(r.aggregationType={})).MINUTELY="MINUTELY",S.HOURLY="HOURLY",S.DAILY="DAILY";class j extends e{constructor(){super(...arguments),this.baseUrl="alarm",this.listUrl="alarms",this.propertyName="alarms",this.channel="/alarms/*"}detail(e){const t=Object.create(null,{detail:{get:()=>super.detail}});return a(this,void 0,void 0,function*(){return t.detail.call(this,e)})}create(e){const t=Object.create(null,{create:{get:()=>super.create}});return a(this,void 0,void 0,function*(){return t.create.call(this,e)})}update(e){const t=Object.create(null,{update:{get:()=>super.update}});return a(this,void 0,void 0,function*(){return t.update.call(this,e)})}list(e={}){const t=Object.create(null,{list:{get:()=>super.list}});return a(this,void 0,void 0,function*(){return t.list.call(this,e)})}}r.AlarmStatus=void 0,(i=r.AlarmStatus||(r.AlarmStatus={}))[i.ACKNOWLEDGED="ACKNOWLEDGED"]="ACKNOWLEDGED",i[i.CLEARED="CLEARED"]="CLEARED",i[i.ACTIVE="ACTIVE"]="ACTIVE";class R extends e{constructor(){super(...arguments),this.baseUrl="devicecontrol",this.listUrl="operations",this.propertyName="operations"}detail(e){const t=Object.create(null,{detail:{get:()=>super.detail}});return a(this,void 0,void 0,function*(){return t.detail.call(this,e)})}create(e){const t=Object.create(null,{create:{get:()=>super.create}});return a(this,void 0,void 0,function*(){return t.create.call(this,e)})}update(e){const t=Object.create(null,{update:{get:()=>super.update}});return a(this,void 0,void 0,function*(){return t.update.call(this,e)})}list(e={}){const t=Object.create(null,{list:{get:()=>super.list}});return a(this,void 0,void 0,function*(){return t.list.call(this,e)})}}class H extends e{constructor(){super(...arguments),this.baseUrl="devicecontrol",this.listUrl="bulkoperations",this.propertyName="bulkOperations"}detail(e){const t=Object.create(null,{detail:{get:()=>super.detail}});return a(this,void 0,void 0,function*(){return t.detail.call(this,e)})}create(e){const t=Object.create(null,{create:{get:()=>super.create}});return a(this,void 0,void 0,function*(){return t.create.call(this,e)})}update(e){const t=Object.create(null,{update:{get:()=>super.update}});return a(this,void 0,void 0,function*(){return t.update.call(this,e)})}list(e={}){const t=Object.create(null,{list:{get:()=>super.list}});return a(this,void 0,void 0,function*(){return t.list.call(this,e)})}delete(e){const t=Object.create(null,{delete:{get:()=>super.delete}});return a(this,void 0,void 0,function*(){return t.delete.call(this,e)})}}r.OperationBulkStatus=void 0,(S=r.OperationBulkStatus||(r.OperationBulkStatus={}))[S.ACTIVE="ACTIVE"]="ACTIVE",S[S.IN_PROGRESS="IN_PROGRESS"]="IN_PROGRESS",S[S.COMPLETED="COMPLETED"]="COMPLETED",S[S.DELETED="DELETED"]="DELETED",r.OperationBulkGeneralStatus=void 0,(i=r.OperationBulkGeneralStatus||(r.OperationBulkGeneralStatus={}))[i.SCHEDULED="SCHEDULED"]="SCHEDULED",i[i.EXECUTING="EXECUTING"]="EXECUTING",i[i.EXECUTING_WITH_ERROR="EXECUTING_WITH_ERROR"]="EXECUTING_WITH_ERROR",i[i.CANCELED="CANCELED"]="CANCELED",i[i.FAILED="FAILED"]="FAILED",i[i.SUCCESSFUL="SUCCESSFUL"]="SUCCESSFUL",i[i.DELETED="DELETED"]="DELETED",i[i.INCORRECT="INCORRECT"]="INCORRECT",r.OperationStatus=void 0,(S=r.OperationStatus||(r.OperationStatus={}))[S.PENDING="PENDING"]="PENDING",S[S.EXECUTING="EXECUTING"]="EXECUTING",S[S.SUCCESSFUL="SUCCESSFUL"]="SUCCESSFUL",S[S.FAILED="FAILED"]="FAILED";class A extends e{constructor(){super(...arguments),this.baseUrl="tenant",this.listUrl="tenants",this.currentTenantUrl="currentTenant",this.propertyName="tenants",this.fetchOptions={method:"PUT",body:"{}",headers:{"content-type":"application/json",accept:"application/json"}}}detail(e){const t=Object.create(null,{detail:{get:()=>super.detail}});return a(this,void 0,void 0,function*(){return t.detail.call(this,e)})}create(e){const t=Object.create(null,{create:{get:()=>super.create}});return a(this,void 0,void 0,function*(){return t.create.call(this,e)})}update(e){const t=Object.create(null,{update:{get:()=>super.update}});return a(this,void 0,void 0,function*(){return t.update.call(this,e)})}list(e={}){const t=Object.create(null,{list:{get:()=>super.list}});return a(this,void 0,void 0,function*(){return t.list.call(this,e)})}delete(e){const t=Object.create(null,{delete:{get:()=>super.delete}});return a(this,void 0,void 0,function*(){return t.delete.call(this,e)})}current(){return a(this,void 0,void 0,function*(){var e=yield this.fetch(this.currentTenantUrl,{headers:{"content-type":"application/json"}}),t=yield e.json();return{res:e,data:t}})}enableSupportUser(){return a(this,void 0,void 0,function*(){return{res:yield this.fetch("support-user/enable",this.fetchOptions),data:null}})}disableSupportUser(){return a(this,void 0,void 0,function*(){return{res:yield this.fetch("support-user/disable",this.fetchOptions),data:null}})}currentTenantType(){return a(this,void 0,void 0,function*(){var e=yield this.current();return e.data.customProperties&&"TRIAL"===e.data.customProperties.tenantType?"TRIAL":"REGULAR"})}getTfaSettings(t){return a(this,void 0,void 0,function*(){var e=this.getIdString(t);return yield(yield this.fetch(`tenants/${e}/tfa`)).json()})}updateTfaStrategy(n,i){return a(this,void 0,void 0,function*(){var e=`tenants/${this.getIdString(n)}/tfa`,t=JSON.stringify({strategy:i});return{res:yield this.fetch(e,{method:"PUT",body:t,headers:{"content-type":"application/json",accept:"application/json"}}),data:null}})}subscribeApplication(i,r){return a(this,void 0,void 0,function*(){var e=this.getIdString(i),t=r.id,e=`tenants/${e}/applications`,t=JSON.stringify({application:{id:t,self:r.self}}),n={"content-type":this.mimeType("applicationReference")};return{res:yield this.fetch(e,this.changeFetchOptions({method:"POST",body:t,headers:n},e)),data:null}})}unsubscribeApplication(t,n){return a(this,void 0,void 0,function*(){var e=`tenants/${this.getIdString(t)}/applications/`+n.id;return{res:yield this.fetch(e,this.changeFetchOptions({method:"DELETE"},e)),data:null}})}getIdString(e){return e.id||e.name}onBeforeCreate(e){return e}}r.TenantStatus=void 0,(i=r.TenantStatus||(r.TenantStatus={}))[i.ACTIVE="ACTIVE"]="ACTIVE",i[i.SUSPENDED="SUSPENDED"]="SUSPENDED",r.TfaStrategy=void 0,(S=r.TfaStrategy||(r.TfaStrategy={})).TOTP="TOTP",S.SMS="SMS";class q extends e{constructor(e,t){super(t),this.listUrl="inventory",this.currenUserUrl="currentUser",this.propertyName="inventoryAssignments",this.baseUrl=`user/${e}/roles`}detail(e){const t=Object.create(null,{detail:{get:()=>super.detail}});return a(this,void 0,void 0,function*(){return t.detail.call(this,e)})}create(e){const t=Object.create(null,{create:{get:()=>super.create}});return a(this,void 0,void 0,function*(){return t.create.call(this,e)})}update(e){const t=Object.create(null,{update:{get:()=>super.update}});return a(this,void 0,void 0,function*(){return t.update.call(this,e)})}list(e={}){const t=Object.create(null,{list:{get:()=>super.list}});return a(this,void 0,void 0,function*(){return t.list.call(this,e)})}delete(e){const t=Object.create(null,{delete:{get:()=>super.delete}});return a(this,void 0,void 0,function*(){return t.delete.call(this,e)})}}class _ extends e{constructor(){super(...arguments),this.baseUrl="user",this.currentUserUrl="currentUser",this.passwordResetUrl="passwordReset",this.currentUserPhoneUrl="currentUserPhone",this.verifyTFACodeUrl="pin",this.totpCurrentUserURL=this.currentUserUrl+"/totpSecret",this.verifyTOTPCodeUrl=this.totpCurrentUserURL+"/verify",this.activateTOTPCodeUrl=this.totpCurrentUserURL+"/activity",this.revokeTOTPSecretUrl="totpSecret/revoke",this.propertyName="users"}get listUrl(){return this.client.tenant+"/users"}get newsletterEmailsUrl(){return this.client.tenant+"/users/newsletterEmails"}get currentUserPasswordUrl(){return this.currentUserUrl+"/password"}get revokeAllTokensUrl(){return`/logout/${this.client.tenant}/allUsers`}detail(e){const t=Object.create(null,{detail:{get:()=>super.detail}});return a(this,void 0,void 0,function*(){return t.detail.call(this,e)})}create(e){const t=Object.create(null,{create:{get:()=>super.create}});return a(this,void 0,void 0,function*(){return t.create.call(this,e)})}update(e){const t=Object.create(null,{update:{get:()=>super.update}});return a(this,void 0,void 0,function*(){return t.update.call(this,e)})}list(e={}){const t=Object.create(null,{list:{get:()=>super.list}});return a(this,void 0,void 0,function*(){return t.list.call(this,e)})}delete(e){const t=Object.create(null,{delete:{get:()=>super.delete}});return a(this,void 0,void 0,function*(){return t.delete.call(this,e)})}inventoryAssignment(e){return new q(this.getDetailUrl(e),this.client)}current(){return a(this,void 0,void 0,function*(){var e=yield this.fetch(this.currentUserUrl,{headers:{"content-type":"application/json",Accept:"application/vnd.com.nsn.cumulocity.user+json;"}}),t=yield e.json();return{res:e,data:t}})}currentWithEffectiveRoles(){return a(this,void 0,void 0,function*(){var e=yield this.fetch(this.currentUserUrl,{headers:{"content-type":"application/json",Accept:"application/vnd.com.nsn.cumulocity.currentUser+json;"}}),t=yield e.json();return{res:e,data:t}})}updateCurrent(n){return a(this,void 0,void 0,function*(){var e="application/vnd.com.nsn.cumulocity.user+json",e={"content-type":e,Accept:e},t=JSON.stringify(this.onBeforeUpdate(n)),e=yield this.fetch(this.currentUserUrl,{headers:e,body:t,method:"PUT"}),t=yield e.json();return{res:e,data:t}})}sendPasswordResetMail(i,r){return a(this,void 0,void 0,function*(){var e=this.passwordResetUrl,t=r?{tenantId:r}:{},n=JSON.stringify({email:i});return{res:yield this.fetch(e,{headers:{"content-type":"application/json",accept:"application/json"},method:"POST",params:t,body:n}),data:null}})}resetPassword(i,r){return a(this,void 0,void 0,function*(){var e=this.passwordResetUrl,t=r?{tenantId:r}:{},n=JSON.stringify(i);return{res:yield this.fetch(e,{headers:{"content-type":"application/json",accept:"application/json"},method:"PUT",params:t,body:n}),data:null}})}verifyTFACode(t){return a(this,void 0,void 0,function*(){var e=JSON.stringify({pin:t});return{res:yield this.fetch(this.verifyTFACodeUrl,{headers:{"content-type":"application/json",accept:"application/json"},body:e,method:"POST"}),data:null}})}verifyTotpCode(t){return a(this,void 0,void 0,function*(){var e=JSON.stringify({code:t});return{res:yield this.fetch(this.verifyTOTPCodeUrl,{headers:{"content-type":"application/json"},body:e,method:"POST"}),data:null}})}activateTotp(){return a(this,void 0,void 0,function*(){var e=JSON.stringify({isActive:!0});return{res:yield this.fetch(this.activateTOTPCodeUrl,{headers:{"content-type":"application/json"},body:e,method:"POST"}),data:null}})}getActivityTotp(){return a(this,void 0,void 0,function*(){var e=yield this.fetch(this.activateTOTPCodeUrl,{headers:{"content-type":"application/json"},method:"GET"}),t=yield e.json();return{res:e,data:t}})}generateTotpSecret(){return a(this,void 0,void 0,function*(){var e=yield this.fetch(this.totpCurrentUserURL,{headers:{"content-type":"application/json",accept:"application/json"},method:"POST"}),t=yield e.json();return{res:e,data:t}})}totpRevokeSecret(t){return a(this,void 0,void 0,function*(){var e=this.getDetailUrl(t)+"/"+this.revokeTOTPSecretUrl;return{res:yield this.fetch(e,{headers:{accept:"application/json"},method:"DELETE"}),data:null}})}savePhoneNumber(n){return a(this,void 0,void 0,function*(){var e=this.currentUserPhoneUrl,t={method:"PUT",headers:{"content-type":"application/json",accept:"application/json"},body:JSON.stringify({phone:n})},e=yield this.fetch(e,t),t=yield e.json();return{res:e,data:t}})}getNewsletterEmails(){return a(this,void 0,void 0,function*(){var e=this.newsletterEmailsUrl,e=yield this.fetch(e,{method:"GET",headers:{accept:"text/plain"}}),t=yield e.text();return{res:e,data:t}})}changeUserPassword(t,n,i){return a(this,void 0,void 0,function*(){var e=JSON.stringify({newPassword:n,currentUserPassword:i});return{res:yield this.fetch(this.changeUserPasswordUrl(t),{headers:{"content-type":"application/json"},body:e,method:"PUT"}),data:null}})}changeCurrentUserPassword(t,n){return a(this,void 0,void 0,function*(){var e=JSON.stringify({newPassword:t,currentUserPassword:n});return{res:yield this.fetch(this.currentUserPasswordUrl,{headers:{"content-type":"application/json"},body:e,method:"PUT"}),data:null}})}revokeTokens(){return a(this,void 0,void 0,function*(){return{res:yield this.fetch(this.revokeAllTokensUrl,{headers:{"content-type":"application/json"},method:"POST"}),data:null}})}hasRole(e,t){return this.hasRoleInUser(e,t)||this.hasRoleInGroups(e,t)}hasAllRoles(t,e){return e.every(e=>this.hasRole(t,e))}hasAnyRole(t,e){return e.some(e=>this.hasRole(t,e))}hasAnyGlobalRole(t,e){return e.some(e=>this.hasGlobalRoleInUser(t,e))}isDeviceUser(e){return e.id.match(/^device_/)}onBeforeUpdate(e){e=Object.assign({},e);return delete e.id,delete e.userName,e}getDetailUrl(e){return this.listUrl+"/"+encodeURIComponent(this.getId(e))}getId(e){let t;return t="object"==typeof e&&e.id?e.id:"object"==typeof e&&e.userName?e.userName:e,String(t)}hasRoleInUser(e,t){var n=e.effectiveRoles||[];return this.hasRoleInReferences(e&&e.roles&&e.roles.references||[],t)||n.some(({id:e})=>t===e)}hasRoleInGroups(e,t){return(e&&e.groups&&e.groups.references||[]).some(e=>this.hasRoleInReferences(e.group.roles.references,t))}hasRoleInReferences(e,t){return e.some(e=>e.role.id===t)}changeUserPasswordUrl(e){return`${this.client.tenant}/users/${this.getId(e)}/password`}hasGlobalRoleInUser(e,t){return((null==(e=null==e?void 0:e.groups)?void 0:e.references)||[]).map(e=>{return null==(e=null==e?void 0:e.group)?void 0:e.id}).some(e=>e===t)}}r.PasswordStrength=void 0,(i=r.PasswordStrength||(r.PasswordStrength={})).GREEN="GREEN",i.RED="RED",i.YELLOW="YELLOW";class $ extends e{constructor(e,t){super(e),this.listUrl="binaries",this.propertyName="attachments",this.baseUrl="application/applications/"+this.getIdString(t)}upload(r,s,o){return a(this,void 0,void 0,function*(){var e=(null==o?void 0:o.listUrl)||this.listUrl,t=this.createBinaryRequestBody(r,s,o);let n;"function"==typeof t.getHeaders&&(n=t.getHeaders());var i=Object.assign((null==o?void 0:o.headers)||{Accept:"application/json"},n),e=yield this.fetch(e,{method:"POST",body:t,headers:i}),t=yield e.json();return{res:e,data:t}})}uploadWithProgressXhr(e,t,n,i){var r=`/${this.baseUrl}/`+((null==i?void 0:i.listUrl)||this.listUrl),e=this.createBinaryRequestBody(e,n,i);let s;"function"==typeof e.getHeaders&&(s=e.getHeaders());var o=this.client.getFetchOptions().headers,a=(Object.assign(o,(null==i?void 0:i.headers)||{Accept:"application/json"}),Object.assign(o,s),new XMLHttpRequest);a.open("POST",r,!0);for(const l in o)o.hasOwnProperty(l)&&a.setRequestHeader(l,o[l]);a.upload.addEventListener("progress",t);let c;return c="function"==typeof e.getBuffer?e.getBuffer():e,a.send(c),a}getXMLHttpResponse(n){return new Promise((e,t)=>{n.addEventListener("loadend",()=>{4!==n.readyState||200!==n.status&&201!==n.status?t(n.responseText?{data:JSON.parse(n.responseText)}:"Could not upload file."):e(JSON.parse(n.responseText))})})}list(e){const t=Object.create(null,{list:{get:()=>super.list}});return a(this,void 0,void 0,function*(){return t.list.call(this,e)})}delete(e){const t=Object.create(null,{delete:{get:()=>super.delete}});return a(this,void 0,void 0,function*(){return t.delete.call(this,e)})}listPlugins(){return a(this,void 0,void 0,function*(){var e=this.listUrl+"/plugins",e=yield this.fetch(e,{headers:{accept:"application/json"}}),t=yield e.json();return{res:e,data:t}})}addPlugin(i,r){return a(this,void 0,void 0,function*(){var e=this.listUrl+"/plugins/"+encodeURIComponent(i),t=new E,n=r instanceof ArrayBuffer?Buffer.from(r):r,n=(t.append("file",n),yield this.fetch(e,{method:"POST",body:t,headers:{accept:"application/json"}})),e=yield n.json();return{res:n,data:e}})}removePlugin(n){return a(this,void 0,void 0,function*(){var e=this.listUrl+"/plugins/"+n,e=yield this.fetch(e,{method:"DELETE",headers:{accept:"application/json"}}),t=yield e.json();return{res:e,data:t}})}updateFiles(i){return a(this,void 0,void 0,function*(){var e=this.listUrl+"/files";const n=new E;i.forEach(e=>{var t=e.contents instanceof ArrayBuffer?Buffer.from(e.contents):e.contents;n.append(e.path,t)});var e=yield this.fetch(e,{method:"POST",body:n,headers:{accept:"application/json"}}),t=yield e.json();return{res:e,data:t}})}downloadArchive(t){return a(this,void 0,void 0,function*(){var e=this.listUrl+"/"+t;return yield this.fetch(e)})}createBinaryRequestBody(e,t,n){var i=new E,r=e instanceof ArrayBuffer?Buffer.from(e):e;let s=t;if("undefined"!=typeof File&&e instanceof File&&(s=e.name),i.append((null==n?void 0:n.bodyFileProperty)||"file",r,s),i.append("fileName",s),null!=n&&n.requestBody)for(const o in n.requestBody)n.requestBody.hasOwnProperty(o)&&i.append(o,JSON.stringify(n.requestBody[o]));return i}}r.ApplicationType=void 0,(S=r.ApplicationType||(r.ApplicationType={})).EXTERNAL="EXTERNAL",S.HOSTED="HOSTED",S.MICROSERVICE="MICROSERVICE",S.FEATURE="FEATURE";class I extends e{constructor(){super(...arguments),this.baseUrl="application",this.listUrl="applications",this.propertyName="applications",this.channel="/applications/*"}create(e){const t=Object.create(null,{create:{get:()=>super.create}});return a(this,void 0,void 0,function*(){return t.create.call(this,e)})}clone(i,r){return a(this,void 0,void 0,function*(){var e=this.getDetailUrl(i)+"/clone";let t=void 0;r&&(t={version:r});var e=yield this.fetch(e,{method:"POST",body:"",headers:{"content-type":"application/json",accept:"application/json"},params:t}),n=yield e.json();return{res:e,data:n}})}list(e={}){const t=Object.create(null,{list:{get:()=>super.list}});return a(this,void 0,void 0,function*(){return t.list.call(this,e)})}listVersions(i,r={}){var s;return a(this,void 0,void 0,function*(){var t=this.getEntityId(i),t=this.listUrl+`/${t}/versions`;try{var n=yield this.fetch(t,{headers:{"content-type":"application/json"},params:r}),e=null==(s=yield n.json())?void 0:s.applicationVersions;return{res:n,data:e}}catch(e){if(404===e.res.status)return{data:t,res:n}=yield this.detail(i),{res:n,data:t.applicationVersions};throw e}})}detail(e){const t=Object.create(null,{detail:{get:()=>super.detail}});return a(this,void 0,void 0,function*(){return t.detail.call(this,e)})}update(e){const t=Object.create(null,{update:{get:()=>super.update}});return a(this,void 0,void 0,function*(){return t.update.call(this,e)})}delete(e){const t=Object.create(null,{delete:{get:()=>super.delete}});return a(this,void 0,void 0,function*(){return t.delete.call(this,e)})}listByName(n){return a(this,void 0,void 0,function*(){var e="applicationsByName/"+encodeURIComponent(n),e=yield this.fetch(e,{headers:{"content-type":"application/json"}}),t=yield e.json();return{res:e,data:t[this.propertyName]}})}listByTenant(n,i={}){return a(this,void 0,void 0,function*(){var e=new A(this.client),e=this.getIdString(n||(yield e.current()).data.name),e="applicationsByTenant/"+encodeURIComponent(e),e=yield this.fetch(e,{headers:{"content-type":"application/json"},params:i}),t=yield e.json();return{res:e,data:t[this.propertyName]}})}listByOwner(n,i={}){return a(this,void 0,void 0,function*(){var e=new A(this.client),e=this.getIdString(n||(yield e.current()).data.name),e="applicationsByOwner/"+encodeURIComponent(e),e=yield this.fetch(e,{headers:{"content-type":"application/json"},params:i}),t=yield e.json();return{res:e,data:t[this.propertyName]}})}listByUser(n,i={}){return a(this,void 0,void 0,function*(){var e=new _(this.client),e=this.getIdString(n||(yield e.current()).data),e="applicationsByUser/"+encodeURIComponent(e),e=yield this.fetch(e,{headers:{"content-type":"application/json"},params:i}),t=yield e.json();return{res:e,data:t[this.propertyName]}})}reactivateArchive(t){return a(this,void 0,void 0,function*(){var e=this.listUrl+`/${t}/refresh`;return{res:yield this.fetch(e,{method:"POST",body:"",headers:{"content-type":"application/json",accept:"application/json"}}),data:null}})}binary(e){return new $(this.client,e)}getHref(e){return e.type===r.ApplicationType.EXTERNAL?e.externalUrl:"/apps/"+(e.public?"public/":"")+e.contextPath}isAvailable(n){return a(this,void 0,void 0,function*(){var{res:e,data:t}=yield this.listByUser(void 0,{dropOverwrittenApps:!0,noPaging:!0});return{data:(t||[]).some(e=>"string"==typeof n?e.name===n||e.contextPath===n:this.isMatch(e,n)),res:e}})}getStatusDetails(t){return a(this,void 0,void 0,function*(){var e=this.getEntityId(t);return new w(this.client,this.realtime).list({type:"c8y_Application_"+e})})}getInstanceNames(e){let t=new Array;return t=e&&e.c8y_Status&&e.c8y_Status.instances?Object.keys(e.c8y_Status.instances):t}getInstanceLog(n,i,r){return a(this,void 0,void 0,function*(){var e=this.getDetailUrl(n)+"/logs/"+i,t={accept:this.mimeType("applicationLogs")},e=yield this.fetch(e,{headers:t,params:r}),t=yield e.json();return{res:e,data:t}})}updateApplicationConfig(n,i){var r;return a(this,void 0,void 0,function*(){var e=this.getEntityId(n),t=(yield this.detail(e))["data"],t=(null==t?void 0:t.config)||{},t=Object.assign(Object.assign({},t),i),e=yield this.update({id:e,config:t});return null==(r=yield e)?void 0:r.data})}getAppManifest(n,i){return a(this,void 0,void 0,function*(){var e=new Date;let t;if(400<=(t=i?yield this.client.fetch(`/apps/${n.contextPath}@${i}/cumulocity.json?nocache=`+e.getTime()):yield this.client.fetch(`/apps/${n.contextPath}/cumulocity.json?nocache=`+e.getTime())).status)throw new Error("No Cumulocity IoT manifest found.");return yield t.json()})}storeAppManifest(e,t){return a(this,void 0,void 0,function*(){return yield this.binary(e).updateFiles([{path:"cumulocity.json",contents:JSON.stringify(t)}])})}setPackageVersionTag(n,i,r){return a(this,void 0,void 0,function*(){var e=this.getDetailUrl(n)+"/versions/"+i,t=JSON.stringify({tags:r}),e=yield this.fetch(e,{method:"PUT",body:t,headers:{accept:"application/vnd.com.nsn.cumulocity.applicationVersion+json;charset=UTF-8;ver=0.9","content-type":"application/json"}}),t=yield e.json();return{res:e,data:t}})}getManifestOfContextPath(n){return a(this,void 0,void 0,function*(){var e=this.getDetailUrl(n)+"/manifest",e=yield this.fetch(e),t=(yield e.json())["application"];return{res:e,data:t}})}deleteVersionPackage(t,n){return a(this,void 0,void 0,function*(){var e=this.getDetailUrl(t)+"/versions/";return{res:yield this.fetch(e,this.changeFetchOptions({method:"DELETE",params:n},e)),data:null}})}updateApplicationAvailability(t,n){return a(this,void 0,void 0,function*(){var e=this.getEntityId(t);return yield this.update({id:e,availability:n})})}isMatch(n,e){return Object.keys(e).every(t=>Array.isArray(n[t])&&Array.isArray(e[t])?e[t].every(e=>n[t].includes(e)):"object"==typeof n[t]&&null!==n[t]&&"object"==typeof e[t]&&null!==e[t]?this.isMatch(n[t],e[t]):n[t]===e[t])}}r.InstanceStatus=void 0,(i=r.InstanceStatus||(r.InstanceStatus={})).Up="Up",i.Unhealthy="Unhealthy",i.Down="Down",i.Unknown="Unknown",r.BillingMode=void 0,(S=r.BillingMode||(r.BillingMode={})).SUBSCRIPTION="SUBSCRIPTION",S.RESOURCES="RESOURCES",r.Isolation=void 0,(i=r.Isolation||(r.Isolation={})).PER_TENANT="PER_TENANT",i.MULTI_TENANT="MULTI_TENANT",r.ApplicationAvailability=void 0,(S=r.ApplicationAvailability||(r.ApplicationAvailability={}))[S.MARKET="MARKET"]="MARKET",S[S.PRIVATE="PRIVATE"]="PRIVATE",S[S.SHARED="SHARED"]="SHARED";class V extends e{constructor(){super(...arguments),this.baseUrl="tenant/system",this.listUrl="options",this.propertyName="options"}detail(e){const t=Object.create(null,{detail:{get:()=>super.detail}});return a(this,void 0,void 0,function*(){return t.detail.call(this,e)})}list(n={}){return a(this,void 0,void 0,function*(){var e=this.listUrl,e=yield this.fetch(e,{headers:{"content-type":"application/json"},params:n}),t=yield e.json();return{res:e,data:t[this.propertyName]}})}getDetailUrl(e){return`${this.listUrl}/${e.category}/`+e.key}onBeforeCreate(e){return e}}class J extends e{constructor(){super(...arguments),this.baseUrl="tenant",this.listUrl="options",this.propertyName="options",this.securityOptionsCategories=["password"],this.securityOptionsListUrl="security-options",this.systemOptions="system"}detail(e,t={}){const n=Object.create(null,{detail:{get:()=>super.detail}});return a(this,void 0,void 0,function*(){return n.detail.call(this,e,t)})}create(e){const t=Object.create(null,{create:{get:()=>super.create}});return a(this,void 0,void 0,function*(){return t.create.call(this,e)})}update(e){const t=Object.create(null,{update:{get:()=>super.update}});return a(this,void 0,void 0,function*(){return t.update.call(this,e)})}list(e={}){const t=Object.create(null,{list:{get:()=>super.list}});return a(this,void 0,void 0,function*(){return t.list.call(this,e)})}delete(e){const t=Object.create(null,{delete:{get:()=>super.delete}});return a(this,void 0,void 0,function*(){return t.delete.call(this,e)})}getDetailUrl(e){var t=encodeURIComponent(e.category),n=encodeURIComponent(e.key);return-1<this.securityOptionsCategories.indexOf(e.category)?this.securityOptionsListUrl+`/${t}/`+n:this.listUrl+`/${t}/`+n}onBeforeCreate(e){return e}}class X extends e{constructor(){super(...arguments),this.baseUrl="tenant",this.listUrl="security-options",this.category="password",this.propertyName="options"}detail(e){const t=Object.create(null,{detail:{get:()=>super.detail}});return a(this,void 0,void 0,function*(){return t.detail.call(this,e)})}getDetailUrl(e){return`${this.listUrl}/${this.category}/`+e.key}onBeforeCreate(e){return e}}class W extends e{constructor(){super(...arguments),this.baseUrl="tenant",this.listUrl="loginOptions",this.propertyName="loginOptions"}detail(e){const t=Object.create(null,{detail:{get:()=>super.detail}});return a(this,void 0,void 0,function*(){return t.detail.call(this,e)})}list(e={}){const t=Object.create(null,{list:{get:()=>super.list}});return a(this,void 0,void 0,function*(){return t.list.call(this,e)})}listForCurrentTenant(){const e=Object.create(null,{list:{get:()=>super.list}});return a(this,void 0,void 0,function*(){return e.list.call(this,{tenantId:this.client.tenant})})}listForManagement(){const e=Object.create(null,{list:{get:()=>super.list}});return a(this,void 0,void 0,function*(){return e.list.call(this,{management:!0})})}create(e){const t=Object.create(null,{create:{get:()=>super.create}});return a(this,void 0,void 0,function*(){return t.create.call(this,e)})}update(e){const t=Object.create(null,{update:{get:()=>super.update}});return a(this,void 0,void 0,function*(){return t.update.call(this,e)})}save(e){return a(this,void 0,void 0,function*(){return e.id?this.update(e):this.create(e)})}delete(e){const t=Object.create(null,{delete:{get:()=>super.delete}});return a(this,void 0,void 0,function*(){return t.delete.call(this,e)})}}r.TenantLoginOptionType=void 0,(i=r.TenantLoginOptionType||(r.TenantLoginOptionType={})).OAUTH2_INTERNAL="OAUTH2_INTERNAL",i.OAUTH2="OAUTH2",i.BASIC="BASIC",r.GrantType=void 0,(S=r.GrantType||(r.GrantType={})).AUTHORIZATION_CODE="AUTHORIZATION_CODE",S.PASSWORD="PASSWORD",r.UserManagementSource=void 0,(i=r.UserManagementSource||(r.UserManagementSource={})).REMOTE="REMOTE",i.INTERNAL="INTERNAL";class Q extends e{constructor(){super(...arguments),this.baseUrl="audit",this.listUrl="auditRecords",this.propertyName="auditRecords"}detail(e){const t=Object.create(null,{detail:{get:()=>super.detail}});return a(this,void 0,void 0,function*(){return t.detail.call(this,e)})}create(e){const t=Object.create(null,{create:{get:()=>super.create}});return a(this,void 0,void 0,function*(){return t.create.call(this,e)})}list(e={}){const t=Object.create(null,{list:{get:()=>super.list}});return a(this,void 0,void 0,function*(){return t.list.call(this,e)})}}r.AuditRecordType=void 0,(S=r.AuditRecordType||(r.AuditRecordType={})).ALARM="Alarm",S.BULK_OPERATION="BulkOperation",S.CEP_MODULE="CepModule",S.EVENT="Event",S.INVENTORY="Inventory",S.INVENTORY_ROLE="InventoryRole",S.OPERATION="Operation",S.OPTION="Option",S.GROUP="Group",S.SMART_RULE="SmartRule",S.SYSTEM="SYSTEM",S.TENANT="Tenant",S.USER="User",r.ChangeType=void 0,(i=r.ChangeType||(r.ChangeType={}))[i.ADDED="ADDED"]="ADDED",i[i.REPLACED="REPLACED"]="REPLACED",i[i.REMOVED="REMOVED"]="REMOVED";class k extends e{constructor(){super(...arguments),this.baseUrl="user",this.listUrl="inventoryroles",this.propertyName="roles"}detail(e){const t=Object.create(null,{detail:{get:()=>super.detail}});return a(this,void 0,void 0,function*(){return t.detail.call(this,e)})}create(e){const t=Object.create(null,{create:{get:()=>super.create}});return a(this,void 0,void 0,function*(){return t.create.call(this,e)})}update(e){const t=Object.create(null,{update:{get:()=>super.update}});return a(this,void 0,void 0,function*(){return t.update.call(this,e)})}list(e={}){const t=Object.create(null,{list:{get:()=>super.list}});return a(this,void 0,void 0,function*(){return t.list.call(this,e)})}delete(e){const t=Object.create(null,{delete:{get:()=>super.delete}});return a(this,void 0,void 0,function*(){return t.delete.call(this,e)})}}r.DeviceRegistrationStatus=void 0,(S=r.DeviceRegistrationStatus||(r.DeviceRegistrationStatus={}))[S.WAITING_FOR_CONNECTION="WAITING_FOR_CONNECTION"]="WAITING_FOR_CONNECTION",S[S.PENDING_ACCEPTANCE="PENDING_ACCEPTANCE"]="PENDING_ACCEPTANCE",S[S.ACCEPTED="ACCEPTED"]="ACCEPTED",S[S.BLOCKED="BLOCKED"]="BLOCKED";class x extends e{constructor(){super(...arguments),this.baseUrl="devicecontrol",this.listUrl="newDeviceRequests",this.propertyName="newDeviceRequests"}detail(e){const t=Object.create(null,{detail:{get:()=>super.detail}});return a(this,void 0,void 0,function*(){return t.detail.call(this,e)})}create(e){const t=Object.create(null,{create:{get:()=>super.create}});return a(this,void 0,void 0,function*(){return t.create.call(this,e)})}list(e={}){const t=Object.create(null,{list:{get:()=>super.list}});return a(this,void 0,void 0,function*(){return t.list.call(this,e)})}delete(e){const t=Object.create(null,{delete:{get:()=>super.delete}});return a(this,void 0,void 0,function*(){return t.delete.call(this,e)})}accept(n){const i=Object.create(null,{update:{get:()=>super.update}});return a(this,void 0,void 0,function*(){var e=this.getSecurityToken(n);let t={id:this.getIdString(n),status:r.DeviceRegistrationStatus.ACCEPTED};return e&&(t=Object.assign(Object.assign({},t),{securityToken:e})),i.update.call(this,t)})}acceptAll(){const n=Object.create(null,{fetch:{get:()=>super.fetch}});return a(this,void 0,void 0,function*(){var e=yield n.fetch.call(this,this.listUrl+"/acceptAll",{method:"POST"}),t=yield e.json();return{res:e,data:t}})}limit(){const n=Object.create(null,{fetch:{get:()=>super.fetch}});return a(this,void 0,void 0,function*(){var e=yield n.fetch.call(this,this.listUrl+"/limit"),t=yield e.json();return{res:e,data:t}})}bootstrap(s,o){return a(this,void 0,void 0,function*(){var e=this.getIdString(s),t=this.getSecurityToken(s),t=t?JSON.stringify({id:e,securityToken:t}):JSON.stringify({id:e}),e=this.baseUrl+"/deviceCredentials",n=o["basicAuth"];let i=o["basicAuthToken"];n&&({user:n,pass:r}=n,i=c(n+":"+r));var n={Authorization:"Basic "+i,accept:"application/json","content-type":"application/json"},r=yield this.client.fetch(e,{body:t,headers:n,method:"POST"}),e=yield r.json();if(400<r.status)throw{res:r,data:e};return{res:r,data:e}})}onBeforeCreate(e){return e}onBeforeUpdate(e){e=Object.assign({},e);return delete e.id,e}getDetailUrl(e){e=encodeURIComponent(this.getEntityId(e));return this.listUrl+"/"+e}getSecurityToken(e){let t;return t="object"==typeof e?e.securityToken?String(e.securityToken):void 0:t}}class K{constructor(e){this.client=e}create(r){return a(this,void 0,void 0,function*(){let e=r;var t=new E;let n="bulk-registration.csv";"undefined"!=typeof File&&e instanceof File&&(n=e.name,e.name.match(/\.csv$/))&&(e=new File([e],e.name,{type:"text/csv"})),t.append("file",e,n);var t=yield this.client.fetch("/devicecontrol/bulkNewDeviceRequests",{method:"POST",body:t,headers:{accept:"application/json"}}),i=yield t.json();return{res:t,data:i}})}}r.DeviceRegistrationSecurityMode=void 0,(i=r.DeviceRegistrationSecurityMode||(r.DeviceRegistrationSecurityMode={})).REQUIRED="REQUIRED",i.OPTIONAL="OPTIONAL",i.IGNORED="IGNORED";class Y extends e{constructor(){super(...arguments),this.baseUrl="user",this.listUrl="roles",this.propertyName="roles"}detail(e){const t=Object.create(null,{detail:{get:()=>super.detail}});return a(this,void 0,void 0,function*(){return t.detail.call(this,e)})}list(e={}){const t=Object.create(null,{list:{get:()=>super.list}});return a(this,void 0,void 0,function*(){return t.list.call(this,e)})}}(S=O=O||{}).ROLES="roles",S.USERS="users";class z extends e{constructor(){super(...arguments),this.baseUrl="user",this.propertyName="groups"}get listUrl(){return this.client.tenant+"/groups"}detail(e){const t=Object.create(null,{detail:{get:()=>super.detail}});return a(this,void 0,void 0,function*(){return t.detail.call(this,e)})}create(e){const t=Object.create(null,{create:{get:()=>super.create}});return a(this,void 0,void 0,function*(){return t.create.call(this,e)})}update(e){const t=Object.create(null,{update:{get:()=>super.update}});return a(this,void 0,void 0,function*(){return t.update.call(this,e)})}list(e={}){const t=Object.create(null,{list:{get:()=>super.list}});return a(this,void 0,void 0,function*(){return t.list.call(this,e)})}delete(e){const t=Object.create(null,{delete:{get:()=>super.delete}});return a(this,void 0,void 0,function*(){return t.delete.call(this,e)})}addRoleToGroup(e,t){return a(this,void 0,void 0,function*(){return this.addChild(O.ROLES,e,t)})}removeRoleFromGroup(e,t){return a(this,void 0,void 0,function*(){return this.removeChild(O.ROLES,e,t)})}addUserToGroup(e,t){return a(this,void 0,void 0,function*(){return this.addChild(O.USERS,e,t)})}removeUserFromGroup(e,t){return a(this,void 0,void 0,function*(){return this.removeChild(O.USERS,e,t)})}getSelf(e){return"object"==typeof e&&e.self?e.self:e}getChildUrl(e,t){return this.getDetailUrl(t)+"/"+e}getChildReferenceAsBody(e,t){var n=this.getSelf(t);switch(e){case O.ROLES:return JSON.stringify({role:{self:String(n)}});case O.USERS:return JSON.stringify({user:{self:String(n)}})}throw new Error("UserGroupService -> getChild -> unsupported child type")}addChild(n,i,r){return a(this,void 0,void 0,function*(){var e=this.getChildUrl(n,i),t=this.getChildReferenceAsBody(n,r),e=yield this.fetch(e,{method:"POST",body:t,headers:{accept:"application/json","content-type":"application/json"}}),t=yield e.json();return{res:e,data:t.managedObject}})}removeChild(t,n,i){return a(this,void 0,void 0,function*(){var e=this.getIdString(i),e=this.getChildUrl(t,n)+"/"+encodeURIComponent(String(e));return{res:yield this.fetch(e,{method:"DELETE",headers:{accept:"application/json"}}),data:null}})}}class Z{constructor(e){this.baseUrl="identity",this.propertyName="externalIds",this.client=e}list(n){return a(this,void 0,void 0,function*(){var e=this.getExternalIdsOfGlobalIdUrl(n),e=yield this.fetch(e,{headers:{accept:"application/json"}}),t=yield e.json();return{res:e,data:t[this.propertyName]}})}create(n){return a(this,void 0,void 0,function*(){var e=JSON.stringify(n),t=this.getExternalIdsOfGlobalIdUrl(n.managedObject.id),t=yield this.fetch(t,{headers:{"content-type":"application/json",accept:"application/json"},method:"POST",body:e}),e=yield t.json();return{res:t,data:e}})}detail(n){return a(this,void 0,void 0,function*(){var e=this.getExternalIdUrl(n),e=yield this.fetch(e,{headers:{accept:"application/json"}}),t=yield e.json();return{res:e,data:t}})}delete(t){return a(this,void 0,void 0,function*(){var e=this.getExternalIdUrl(t);return{res:yield this.fetch(e,{headers:{accept:"application/json"},method:"DELETE"}),data:null}})}fetch(e,t){return a(this,void 0,void 0,function*(){var n=yield this.client.fetch(e,t);if(400<=n.status){let t=null;try{t=yield n.json()}catch(e){try{t=yield n.text()}catch(e){}}throw{res:n,data:t}}return n})}getExternalIdsOfGlobalIdUrl(e){return`/${this.baseUrl}/globalIds/${e}/externalIds`}getExternalIdUrl(e){return`/${this.baseUrl}/externalIds/${e.type}/`+e.externalId}}class ee extends e{constructor(){super(...arguments),this.listUrl="trusted-certificates",this.proofOfPossessionUrl="trusted-certificates-pop",this.propertyName="certificates"}get baseUrl(){return"/tenant/tenants/"+this.client.tenant}list(e={}){const t=Object.create(null,{list:{get:()=>super.list}});return a(this,void 0,void 0,function*(){return t.list.call(this,e)})}detail(e){const t=Object.create(null,{detail:{get:()=>super.detail}});return a(this,void 0,void 0,function*(){return t.detail.call(this,e)})}delete(e){const t=Object.create(null,{delete:{get:()=>super.delete}});return a(this,void 0,void 0,function*(){return t.delete.call(this,e)})}update(e){const t=Object.create(null,{update:{get:()=>super.update}});return a(this,void 0,void 0,function*(){return t.update.call(this,e)})}create(e){const t=Object.create(null,{create:{get:()=>super.create}});return a(this,void 0,void 0,function*(){return t.create.call(this,e)})}regeneratePoPVerificationCode(n){return a(this,void 0,void 0,function*(){var e=`${this.proofOfPossessionUrl}/${this.getEntityId(n)}/verification-code`,e=yield this.fetch(e,{headers:{"content-type":"application/json",Accept:"application/json"},method:"POST"}),t=yield e.json();return{res:e,data:t}})}verifySignedVerificationCode(n,i){return a(this,void 0,void 0,function*(){var e=`${this.proofOfPossessionUrl}/${this.getEntityId(n)}/pop`,t=JSON.stringify({proofOfPossessionSignedVerificationCode:i}),e=yield this.fetch(e,{method:"POST",body:t,headers:{"content-type":"application/json",Accept:"application/json"}}),t=yield e.json();return{res:e,data:t}})}getDetailUrl(e){e=this.getEntityId(e);return this.listUrl+"/"+e}getEntityId(e){let t;return t="object"==typeof e&&e.fingerprint?e.fingerprint:e}}class te extends e{get baseUrl(){return"/tenant/trusted-certificates/settings/crl"}uploadCrls(t){return a(this,void 0,void 0,function*(){var e=JSON.stringify({crls:t});return{res:yield this.fetch("",{method:"PUT",body:e,headers:{"content-type":"application/json",Accept:"application/json"}}),data:null}})}uploadCrlFile(t){return a(this,void 0,void 0,function*(){var e=new E;e.append("file",t);return{res:yield this.fetch("",{method:"PUT",body:e,headers:{accept:"application/json"}}),data:null}})}downloadCrlFile(e){return a(this,void 0,void 0,function*(){return yield this.fetch("",e)})}}class ne extends e{constructor(e){super(e),this.baseUrl="inventory",this.listUrl="managedObjects",this.SMART_GROUP_TYPE="c8y_DynamicGroup",this.SMART_GROUP_FRAGMENT_TYPE="c8y_IsDynamicGroup",this.COLUMNS_CONFIG_FRAGMENT="c8y_DeviceColumnsConfig",this.FILTER_CONFIG_FRAGMENT="c8y_DeviceFilterConfig",this.QUERY_STRING_FRAGMENT="c8y_DeviceQueryString"}detail(e,t={}){const n=Object.create(null,{detail:{get:()=>super.detail}});return a(this,void 0,void 0,function*(){return n.detail.call(this,e,t)})}create(t){const n=Object.create(null,{create:{get:()=>super.create}});return a(this,void 0,void 0,function*(){var e=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.create.call(this,e)})}update(e){const t=Object.create(null,{update:{get:()=>super.update}});return a(this,void 0,void 0,function*(){return t.update.call(this,e)})}delete(t,n={}){const i=Object.create(null,{delete:{get:()=>super.delete}});return a(this,void 0,void 0,function*(){var e=(yield this.detail(t,{withChildren:!1})).data;return yield i.delete.call(this,e,n)})}isSmartGroup(e){var t=e.hasOwnProperty(this.SMART_GROUP_FRAGMENT_TYPE),e=e&&e.type===this.SMART_GROUP_TYPE;return t||e}getUrl(e=""){e=e.replace(/^\/+/,"");return this.baseUrl.replace(/\/+$/,"")+"/"+e}}class N extends e{constructor(e){super(e),this.baseUrl="service/smartrule",this.rulesUrl="smartrules",this.unupdatableFields=["type","cepModuleId","creationTime","lastUpdated"],this.applicationService=new I(e)}isMicroserviceAvailable(){return a(this,void 0,void 0,function*(){return void 0===this.microserviceAvailable&&(this.microserviceAvailable=(yield this.applicationService.isAvailable(N.microserviceName)).data),this.microserviceAvailable})}listByContext(n){return a(this,void 0,void 0,function*(){var e=this.contextRulesUrl(n),e=yield this.fetch(e,{method:"GET"}),t=(yield e.json()).rules;return{res:e,data:t}})}bulkDeactivateEnabledSources(e,t){var n;return 0===t.length?Promise.resolve({res:null,data:null}):(n=e["enabledSources"],n=this.disableEnabledSources(n,t),t=Object.assign({},e),Object.assign(t,{enabledSources:n}),this.update(t))}update(n){return a(this,void 0,void 0,function*(){var e=this.getSmartRulesUrl(n),t=JSON.stringify(this.removeUnclonableFields(n,this.unupdatableFields)),e=yield this.fetch(e,{method:"PUT",body:t,headers:{"content-type":"application/json",accept:"application/json"}}),t=yield e.json();return{res:e,data:t}})}disableEnabledSources(e=[],t){return e.filter(e=>!this.getListOfStringIds(t).includes(e))}getListOfStringIds(e){return e.map(e=>("object"==typeof e&&e.id?e.id:e).toString())}getSmartRulesUrl(e){var t=e&&e.c8y_Context&&e.c8y_Context.id;let n=t?this.contextRulesUrl(t):this.rulesUrl;return n=e.id?n+"/"+e.id:n}removeUnclonableFields(e,t){const n=Object.assign({},e);return t.forEach(e=>{delete n[e]}),n}contextRulesUrl(e={}){return"object"==typeof e&&e.id?`managedObjects/${e.id}/smartrules`:`managedObjects/${e}/smartrules`}}N.microserviceName="smartrule";class D{static authenticate(n,i){return a(this,void 0,void 0,function*(){var e=new p(n),t=new h(e,i),t=yield this.getCurrentTenant(t),e=new D(e,i);return e.core.tenant=t,e})}static authenticateViaOAuthInternal(n,i){return a(this,void 0,void 0,function*(){var e=yield this.loginViaOAuthInternal(n,!0,i),e=new d(e),t=new h(e,i),t=n.tenant||(yield this.getCurrentTenant(t)),e=new D(e,i);return e.core.tenant=t,e})}static authenticateViaOAuthInternalCookie(i,r){return a(this,void 0,void 0,function*(){var e=yield this.loginViaOAuthInternal(i,!1,r);let t;t="undefined"==typeof document?new v(e):new f;var e=new h(t,r),e=i.tenant||(yield this.getCurrentTenant(e)),n=new D(t,r);return n.core.tenant=e,n})}static deviceBootstrap(d){return a(this,void 0,void 0,function*(){var{deviceId:e,timeout:t,baseUrl:n,basicAuthToken:i}=d;let r=d["expire"];t&&!r&&(r=Date.now()+t);t=new h(void 0,n),t=new x(t);let s;try{var o=(yield t.bootstrap(e,{basicAuthToken:i}))["data"],{username:a,password:c,tenantId:l}=o,u=new p({user:a,tenant:l,password:c});(s=new D(u,n)).core.tenant=l}catch(e){if((!r||Date.now()<r)&&404===e.res.status)return D.deviceBootstrap(Object.assign({expire:r},d));throw e}return s})}static getMicroserviceSubscriptions(t,n){return a(this,void 0,void 0,function*(){var e=(yield(yield new h(new p(t),n).fetch("/application/currentApplication/subscriptions")).json())["users"];return e.map(({tenant:e,name:t,password:n})=>({tenant:e,user:t,password:n}))})}static loginViaOAuthInternal(i,r=!0,s){return a(this,void 0,void 0,function*(){var e=new p(i),e=new h(e,s);let t="/tenant/oauth";r&&(t+="/token"),i.tenant&&(t+="?tenant_id="+i.tenant);var n=new URLSearchParams({grant_type:"PASSWORD",username:i.user,password:i.password,tfa_code:i.tfa}),e=yield e.fetch(t,{method:"POST",body:n.toString(),headers:{"content-type":"application/x-www-form-urlencoded;charset=UTF-8"}});if(200!==e.status)throw{res:e};return r?(yield e.json()).access_token:e})}static getCurrentTenant(t){return a(this,void 0,void 0,function*(){var e=(yield new A(t).current())["data"];return e.name})}constructor(e,t){e=new h(e,t);this.realtime=new b(e),this.alarm=new j(e,this.realtime),this.application=new I(e,this.realtime),this.audit=new Q(e),this.core=e,this.deviceRegistration=new x(e),this.deviceRegistrationBulk=new K(e),this.event=new T(e,this.realtime),this.inventory=new w(e,this.realtime),this.inventoryBinary=new U(e),this.inventoryRole=new k(e),this.measurement=new C(e,this.realtime),this.operation=new R(e),this.operationBulk=new H(e),this.options={security:new X(e),system:new V(e),login:new W(e),tenant:new J(e)},this.role=new k(e),this.tenant=new A(e),this.user=new _(e),this.userGroup=new z(e),this.userRole=new Y(e),this.identity=new Z(e),this.smartGroups=new ne(e),this.smartRules=new N(e)}setAuth(e){this.core.setAuth(e),this.realtime.disconnect()}}r.AlarmService=j,r.ApplicationBinaryService=$,r.ApplicationService=I,r.AuditService=Q,r.BasicAuth=p,r.BearerAuth=d,r.Client=D,r.CookieAuth=f,r.CrlService=te,r.DeviceRegistrationBulkService=K,r.DeviceRegistrationService=x,r.EventBinaryService=G,r.EventService=T,r.FetchClient=h,r.IdentityService=Z,r.InventoryBinaryService=U,r.InventoryRoleService=k,r.InventoryService=w,r.MeasurementService=C,r.MicroserviceClientRequestAuth=g,r.NodeJSCookieAuth=v,r.OperationBulkService=H,r.OperationService=R,r.Paging=n,r.QueriesUtil=y,r.Realtime=b,r.Service=e,r.SmartGroupsService=ne,r.SmartRulesService=N,r.SystemOptionsService=V,r.TenantLoginOptionsService=W,r.TenantOptionsService=J,r.TenantSecurityOptionsService=X,r.TenantService=A,r.TrustedCertificateService=ee,r.UserGroupService=z,r.UserInventoryRoleService=q,r.UserRoleService=Y,r.UserService=_});
|
|
2
2
|
//# sourceMappingURL=client.umd.min.js.map
|