UNPKG

@glue42/desktop

Version:

Glue42 desktop library

1 lines 348 kB
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):((t="undefined"!=typeof globalThis?globalThis:t||self).desktop=t.desktop||{},t.desktop.browser=t.desktop.browser||{},t.desktop.browser.min=e())}(this,(function(){"use strict";var t=function(e,n){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},t(e,n)};function e(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function i(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(i.prototype=n.prototype,new i)}var n=function(){return n=Object.assign||function(t){for(var e,n=1,i=arguments.length;n<i;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},n.apply(this,arguments)};function i(t,e,n,i){return new(n||(n=Promise))((function(o,r){function s(t){try{c(i.next(t))}catch(t){r(t)}}function a(t){try{c(i.throw(t))}catch(t){r(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,a)}c((i=i.apply(t,e||[])).next())}))}function o(t,e){var n,i,o,r,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return r={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(r[Symbol.iterator]=function(){return this}),r;function a(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;r&&(r=0,a[0]&&(s=0)),s;)try{if(n=1,i&&(o=2&a[0]?i.return:a[0]?i.throw||((o=i.return)&&o.call(i),0):i.next)&&!(o=o.call(i,a[1])).done)return o;switch(i=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,i=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!(o=s.trys,(o=o.length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],i=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}}function r(t,e,n){if(n||2===arguments.length)for(var i,o=0,r=e.length;o<r;o++)!i&&o in e||(i||(i=Array.prototype.slice.call(e,0,o)),i[o]=e[o]);return t.concat(i||Array.prototype.slice.call(e))}var s=1,a=2,c=3,d=4;function u(t){return t.type===c?"timestamp":t.type===a?"number":t.type===s?"string":t.type===d?"object":"unknown"}function h(t){return t.constructor===Date?"timestamp":"number"==typeof t?"number":"string"==typeof t?"string":"object"==typeof t?"object":"string"}function l(t){var e={},n=u(t);if("object"===n){var i=Object.keys(t.value).reduce((function(e,n){var i=h(t.value[n]);if("object"===i){var o=p(t.value[n]);e[n]={type:"object",description:"",context:{},composite:o}}else e[n]={type:i,description:"",context:{}};return e}),{});e.composite=i}return e.name=g(t.path.join("/")+"/"+t.name),e.type=n,e.description=t.description,e.context={},e}function p(t){return Object.keys(t).reduce((function(e,n){var i=h(t[n]);return e[n]="object"===i?{type:"object",description:"",context:{},composite:p(t[n])}:{type:i,description:"",context:{}},e}),{})}function g(t){return void 0!==t&&t.length>0&&"/"!==t[0]?"/"+t:t}function f(t){return"timestamp"===u(t)?Date.now():y(t.value)}function y(t){return"object"!=typeof t?t:Object.keys(t).reduce((function(e,n){var i=t[n];return"object"==typeof i&&i.constructor!==Date?e[n]=y(i):i.constructor===Date?e[n]=new Date(i).getTime():i.constructor===Boolean?e[n]=i.toString():e[n]=i,e}),{})}function m(t){return t.reduce((function(t,e){return t.concat(Array.isArray(e)?m(e):e)}),[])}function v(t){var e=m(t.root.getAggregateState()),n=e.sort((function(t,e){return t.state?e.state?e.state-t.state:-1:1}))[0],i=function(t){var e="";return t.forEach((function(t,n,i){var o=t.path.join(".");n===i.length-1?e+=o+"."+t.name+": "+t.description:e+=o+"."+t.name+": "+t.description+","})),e.length>100?e.slice(0,100)+"...":e}(e);return{description:i,value:n.state}}var w=function(t,e,n){if(null===t||"object"!=typeof t)throw new Error("Missing definition");if(null===e||"object"!=typeof e)throw new Error("Missing parent");if(null===n||"object"!=typeof n)throw new Error("Missing transport")},b=function(){function t(t,e,n,i,o){this.definition=t,this.system=e,this.transport=n,this.value=i,this.type=o,this.path=[],w(t,e,n),this.path=e.path.slice(0),this.path.push(e.name),this.name=t.name,this.description=t.description,n.createMetric(this)}return Object.defineProperty(t.prototype,"repo",{get:function(){var t;return null===(t=this.system)||void 0===t?void 0:t.repo},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"id",{get:function(){return"".concat(this.system.path,"/").concat(name)},enumerable:!1,configurable:!0}),t.prototype.update=function(t){return this.value=t,this.transport.updateMetric(this)},t}(),_=function(t){function n(e,n,i,o){return t.call(this,e,n,i,o,a)||this}return e(n,t),n.prototype.incrementBy=function(t){this.update(this.value+t)},n.prototype.increment=function(){this.incrementBy(1)},n.prototype.decrement=function(){this.incrementBy(-1)},n.prototype.decrementBy=function(t){this.incrementBy(-1*t)},n}(b),I=function(t){function n(e,n,i,o){return t.call(this,e,n,i,o,d)||this}return e(n,t),n.prototype.update=function(t){return this.mergeValues(t),this.transport.updateMetric(this)},n.prototype.mergeValues=function(t){var e=this;return Object.keys(this.value).forEach((function(n){void 0!==t[n]&&(e.value[n]=t[n])}))},n}(b),C=function(t){function n(e,n,i,o){return t.call(this,e,n,i,o,s)||this}return e(n,t),n}(b),A=function(t){function n(e,n,i,o){return t.call(this,e,n,i,o,c)||this}return e(n,t),n.prototype.now=function(){this.update(new Date)},n}(b);function S(t,e,n,i,o){if(!e)throw new Error("Repository is required");if(!n)throw new Error("Transport is required");var r,u,h=n,l=t,p=o||"",g=e,f=i,y=function t(e){if(!e||!e.parent)return[];var n=t(e.parent);return n.push(e.name),n}(i),m={},v=(u="/",((r=y)&&r.length>0?r.join(u):"")+t),w=e.root,b=[],x=[];function k(t,e,n,i){var o={name:""};o="string"==typeof t?{name:t}:t;var r=x.filter((function(t){return t.name===o.name}));if(r.length>0){var s=r[0];if(s.type!==e)throw new Error("A metric named ".concat(o.name," is already defined with different type."));return void 0!==n&&s.update(n).catch((function(){})),s}var a=i(o);return x.push(a),a}var T={get name(){return l},get description(){return p},get repo(){return g},get parent(){return f},path:y,id:v,root:w,get subSystems(){return b},get metrics(){return x},subSystem:function(t,e){if(!t||0===t.length)throw new Error("name is required");var n=b.filter((function(e){return e.name===t}));if(n.length>0)return n[0];var i=S(t,g,h,T,e);return b.push(i),i},getState:function(){return m},setState:function(t,e){m={state:t,description:e},h.updateSystem(T,m)},stringMetric:function(t,e){return k(t,s,e,(function(t){return new C(t,T,h,e)}))},timestampMetric:function(t,e){return k(t,c,e,(function(t){return new A(t,T,h,e)}))},objectMetric:function(t,e){return k(t,d,e,(function(t){return new I(t,T,h,e)}))},numberMetric:function(t,e){return k(t,a,e,(function(t){return new _(t,T,h,e)}))},getAggregateState:function(){var t=[];return Object.keys(m).length>0&&t.push({name:l,path:y,state:m.state,description:m.description}),b.forEach((function(e){var n=e.getAggregateState();n.length>0&&t.push.apply(t,n)})),t}};return h.createSystem(T),T}var x=function(){function t(t,e){e.init(this),this.root=S("",this,e),this.addSystemMetrics(this.root,t.clickStream||void 0===t.clickStream)}return t.prototype.addSystemMetrics=function(t,e){if("undefined"!=typeof navigator&&t.stringMetric("UserAgent",navigator.userAgent),e&&"undefined"!=typeof document){var n=t.subSystem("ClickStream"),i=function(t){var e;if(t.target){var i=t.target,o=i&&null!==(e=i.getAttribute("class"))&&void 0!==e?e:"";n.objectMetric("LastBrowserEvent",{type:"click",timestamp:new Date,target:{className:o,id:i.id,type:"<"+i.tagName.toLowerCase()+">",href:i.href||""}})}};n.objectMetric("Page",{title:document.title,page:window.location.href}),document.addEventListener?document.addEventListener("click",i):document.attachEvent("onclick",i)}t.stringMetric("StartTime",(new Date).toString());var o=t.stringMetric("StartURL",""),r=t.stringMetric("AppName","");if("undefined"!=typeof window){if(void 0!==window.location){var s=window.location.href;o.update(s)}void 0!==window.glue42gd&&r.update(window.glue42gd.appName)}},t}(),k=function(){function t(){}return t.prototype.init=function(t){},t.prototype.createSystem=function(t){return Promise.resolve()},t.prototype.updateSystem=function(t,e){return Promise.resolve()},t.prototype.createMetric=function(t){return Promise.resolve()},t.prototype.updateMetric=function(t){return Promise.resolve()},t}(),T=function(){function t(t,e,n){this.api=t,this.lastCount=0,this.initialPublishTimeout=1e4,this.publishInterval=6e4,this.initialPublishTimeout=null!=e?e:this.initialPublishTimeout,this.publishInterval=null!=n?n:this.publishInterval,this.scheduleCollection(),this.system=this.api.subSystem("performance","Performance data published by the web application")}return t.prototype.scheduleCollection=function(){var t=this;setTimeout((function(){t.collect(),setInterval((function(){t.collect()}),t.publishInterval)}),this.initialPublishTimeout)},t.prototype.collect=function(){try{this.collectMemory(),this.collectEntries()}catch(t){}},t.prototype.collectMemory=function(){var t=window.performance.memory;this.system.stringMetric("memory",JSON.stringify({totalJSHeapSize:t.totalJSHeapSize,usedJSHeapSize:t.usedJSHeapSize}))},t.prototype.collectEntries=function(){var t=window.performance.getEntries();if(!(t.length<=this.lastCount)){this.lastCount=t.length;var e=t.map((function(t){return t.toJSON()}));this.system.stringMetric("entries",JSON.stringify(e))}},t}(),E=function(t){var e;e=t.connection&&"object"==typeof t.connection?function(t,e){var r,s,a=this;if(!t||"object"!=typeof t)throw new Error("Connection is required parameter");var c=function(t){d(t.root)},d=function(t){u(t),t.metrics.forEach((function(t){h(t)})),t.subSystems.forEach((function(t){d(t)}))},u=function(t){return i(a,void 0,void 0,(function(){var e,n;return o(this,(function(i){switch(i.label){case 0:return void 0===t.parent?[2]:[4,r];case 1:return i.sent(),e={name:g(t.path.join("/")+"/"+t.name+"/State"),type:"object",composite:{Description:{type:"string",description:""},Value:{type:"number",description:""}},description:"System state",context:{}},n={type:"define",metrics:[e]},s.send(n),[2]}}))}))},h=function(t){return i(a,void 0,void 0,(function(){var e,n,i;return o(this,(function(o){switch(o.label){case 0:return e=y(t),[4,r];case 1:return o.sent(),n=l(e),i={type:"define",metrics:[n]},s.send(i),void 0!==e.value&&p(e),[2]}}))}))},p=function(t){if(m()){var e=f(t),n={type:"publish",values:[{name:g(t.path.join("/")+"/"+t.name),value:e,timestamp:Date.now()}]};return s.sendFireAndForget(n)}return Promise.resolve()},y=function(t){var e=n({},t);return"object"==typeof t.value&&null!==t.value&&(e.value=n({},t.value)),e},m=function(){var t;try{return(null!==(t=e.canUpdateMetric)&&void 0!==t?t:function(){return!0})()}catch(t){return!0}};return{init:function(n){var i;r=new Promise((function(t){i=t})),(s=t.domain("metrics")).onJoined((function(t){!t&&i&&(i(),i=void 0);var e={type:"define",metrics:[{name:"/State",type:"object",composite:{Description:{type:"string",description:""},Value:{type:"number",description:""}},description:"System state",context:{}}]};s.send(e),t&&c(n)})),s.join({system:e.system,service:e.service,instance:e.instance})},createSystem:u,updateSystem:function(e,n){return i(a,void 0,void 0,(function(){var i,a,c;return o(this,(function(o){switch(o.label){case 0:return[4,r];case 1:return o.sent(),i={type:"publish",values:[{name:g(e.path.join("/")+"/"+e.name+"/State"),value:{Description:n.description,Value:n.state},timestamp:Date.now()}]},s.send(i),a=v(e),c={type:"publish",peer_id:t.peerId,values:[{name:"/State",value:{Description:a.description,Value:a.value},timestamp:Date.now()}]},s.send(c),[2]}}))}))},createMetric:h,updateMetric:function(t){return i(a,void 0,void 0,(function(){var e;return o(this,(function(n){switch(n.label){case 0:return e=y(t),[4,r];case 1:return n.sent(),p(e),[2]}}))}))}}}(t.connection,t):new k;var r=new x(t,e).root;t.disableAutoAppSystem||(r=r.subSystem("App"));var s=function(t){var e,n=t.subSystem("reporting"),i={name:"features"},o=function(t,o,r){if(void 0===t||""===t)throw new Error("name is mandatory");if(void 0===o||""===o)throw new Error("action is mandatory");if(void 0===r||""===r)throw new Error("payload is mandatory");e?e.update({name:t,action:o,payload:r}):e=n.objectMetric(i,{name:t,action:o,payload:r})};return t.featureMetric=o,t}(r);return function(t,e){var n,i;if("undefined"==typeof window)return;var o=null===(i=null===(n=null===window||void 0===window?void 0:window.glue42gd)||void 0===n?void 0:n.metrics)||void 0===i?void 0:i.pagePerformanceMetrics;o&&(e=o);(null==e?void 0:e.enabled)&&new T(t,e.initialPublishTimeout,e.publishInterval)}(s,t.pagePerformanceMetrics),s};var P="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function M(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}function R(t){if(t&&t.errorHandling&&"function"!=typeof t.errorHandling&&"log"!==t.errorHandling&&"silent"!==t.errorHandling&&"throw"!==t.errorHandling)throw new Error('Invalid options passed to createRegistry. Prop errorHandling should be ["log" | "silent" | "throw" | (err) => void], but '+typeof t.errorHandling+" was passed");var e=t&&"function"==typeof t.errorHandling&&t.errorHandling,n={};function i(n,i){var o=n instanceof Error?n:new Error(n);if(e)e(o);else{var r='[ERROR] callback-registry: User callback for key "'+i+'" failed: '+o.stack;if(t)switch(t.errorHandling){case"log":return console.error(r);case"silent":return;case"throw":throw new Error(r)}console.error(r)}}return{add:function(t,e,o){var r=n[t];return r||(r=[],n[t]=r),r.push(e),o&&setTimeout((function(){o.forEach((function(o){var r;if(null===(r=n[t])||void 0===r?void 0:r.includes(e))try{Array.isArray(o)?e.apply(void 0,o):e.apply(void 0,[o])}catch(e){i(e,t)}}))}),0),function(){var i=n[t];i&&(0===(i=i.reduce((function(t,n,i){return n===e&&t.length===i||t.push(n),t}),[])).length?delete n[t]:n[t]=i)}},execute:function(t){for(var e=[],o=1;o<arguments.length;o++)e[o-1]=arguments[o];var r=n[t];if(!r||0===r.length)return[];var s=[];return r.forEach((function(n){try{var o=n.apply(void 0,e);s.push(o)}catch(e){s.push(void 0),i(e,t)}})),s},clear:function(){n={}},clearKey:function(t){n[t]&&delete n[t]}}}R.default=R;var N=R,j=function(){function t(t,e){var n=this;this.registry=N(),this.gw=t.facade,this.gw.connect((function(t,e){n.messageHandler(e)})).then((function(t){n.client=t}))}return Object.defineProperty(t.prototype,"isObjectBasedTransport",{get:function(){return!0},enumerable:!1,configurable:!0}),t.prototype.sendObject=function(t){return this.client?(this.client.send(t),Promise.resolve(void 0)):Promise.reject("not connected")},t.prototype.send=function(t){return Promise.reject("not supported")},t.prototype.onMessage=function(t){return this.registry.add("onMessage",t)},t.prototype.onConnectedChanged=function(t){return t(!0),function(){}},t.prototype.close=function(){return Promise.resolve()},t.prototype.open=function(){return Promise.resolve()},t.prototype.name=function(){return"in-memory"},t.prototype.reconnect=function(){return Promise.resolve()},t.prototype.messageHandler=function(t){this.registry.execute("onMessage",t)},t}(),O=function(){function t(t,e){var n=this;this.logger=e,this.registry=N(),this.worker=new SharedWorker(t),this.worker.port.onmessage=function(t){n.messageHandler(t.data)}}return Object.defineProperty(t.prototype,"isObjectBasedTransport",{get:function(){return!0},enumerable:!1,configurable:!0}),t.prototype.sendObject=function(t){return this.worker.port.postMessage(t),Promise.resolve()},t.prototype.send=function(t){return Promise.reject("not supported")},t.prototype.onMessage=function(t){return this.registry.add("onMessage",t)},t.prototype.onConnectedChanged=function(t){return t(!0),function(){}},t.prototype.close=function(){return Promise.resolve()},t.prototype.open=function(){return Promise.resolve()},t.prototype.name=function(){return"shared-worker"},t.prototype.reconnect=function(){return Promise.resolve()},t.prototype.messageHandler=function(t){this.registry.execute("onMessage",t)},t}(),W=function(){function t(){}return t.isNode=function(){if(void 0!==t._isNode)return t._isNode;if("undefined"!=typeof window)return t._isNode=!1,!1;try{t._isNode="[object process]"===Object.prototype.toString.call(global.process)}catch(e){t._isNode=!1}return t._isNode},t}(),F=function(){function t(){var t=this;this.rejected=!1,this.resolved=!1,this.promise=new Promise((function(e,n){t.resolve=function(n){t.resolved=!0,e(n)},t.reject=function(e){t.rejected=!0,n(e)}}))}return t.delay=function(t){return new Promise((function(e){return setTimeout(e,t)}))},Object.defineProperty(t.prototype,"ended",{get:function(){return this.rejected||this.resolved},enumerable:!1,configurable:!0}),t}(),L={};function D(t){var e=L[t];if(e)return e;var n=[];function i(){return(new Date).getTime()}var o,r,s=i();function a(t,e){var o=null!=e?e:i(),r=0;n.length>0&&(r=o-n[n.length-1].time),n.push({name:t,time:o,diff:r})}a("start",s);var c={get startTime(){return s},get endTime(){return o},get period(){return r},stop:function(){return a("end",o=i()),r=o-s},mark:a,marks:n};return L[t]=c,c}var G=W.isNode()?null:window.WebSocket,B=function(){function t(t,e){if(this.startupTimer=D("connection"),this._running=!0,this._registry=N(),this.wsRequests=[],this.settings=t,this.logger=e,!this.settings.ws)throw new Error("ws is missing")}return t.prototype.onMessage=function(t){return this._registry.add("onMessage",t)},t.prototype.send=function(t,e){var n=this;return new Promise((function(e,i){n.waitForSocketConnection((function(){var o;try{null===(o=n.ws)||void 0===o||o.send(t),e()}catch(t){i(t)}}),i)}))},t.prototype.open=function(){var t=this;return this.logger.info("opening ws..."),this._running=!0,new Promise((function(e,n){t.waitForSocketConnection(e,n)}))},t.prototype.close=function(){return this._running=!1,this.ws&&this.ws.close(),Promise.resolve()},t.prototype.onConnectedChanged=function(t){return this._registry.add("onConnectedChanged",t)},t.prototype.name=function(){return this.settings.ws},t.prototype.reconnect=function(){var t;null===(t=this.ws)||void 0===t||t.close();var e=new F;return this.waitForSocketConnection((function(){e.resolve()})),e.promise},t.prototype.waitForSocketConnection=function(t,e){var n;e=null!=e?e:function(){},this._running?1!==(null===(n=this.ws)||void 0===n?void 0:n.readyState)?(this.wsRequests.push({callback:t,failed:e}),this.wsRequests.length>1||this.openSocket()):t():e("wait for socket on ".concat(this.settings.ws," failed - socket closed by user"))},t.prototype.openSocket=function(t,e){return i(this,void 0,void 0,(function(){var n=this;return o(this,(function(i){switch(i.label){case 0:if(this.startupTimer.mark("opening-socket"),void 0===t&&(t=this.settings.reconnectInterval),void 0===e&&(e=this.settings.reconnectAttempts),void 0!==e){if(0===e)return this.notifyForSocketState("wait for socket on ".concat(this.settings.ws," failed - no more retries left")),[2];this.logger.debug("will retry ".concat(e," more times (every ").concat(t," ms)"))}i.label=1;case 1:return i.trys.push([1,3,,4]),[4,this.initiateSocket()];case 2:return i.sent(),this.startupTimer.mark("socket-initiated"),this.notifyForSocketState(),[3,4];case 3:return i.sent(),setTimeout((function(){var i=void 0===e?void 0:e-1;n.openSocket(t,i)}),t),[3,4];case 4:return[2]}}))}))},t.prototype.initiateSocket=function(){var t=this,e=new F;return this.logger.debug("initiating ws to ".concat(this.settings.ws,"...")),this.ws=new G(this.settings.ws||""),this.ws.onerror=function(n){var i="";try{i=JSON.stringify(n)}catch(t){var o=new WeakSet;i=JSON.stringify(n,(function(t,e){if("object"==typeof e&&null!==e){if(o.has(e))return;o.add(e)}return e}))}e.reject("error"),t.notifyStatusChanged(!1,i)},this.ws.onclose=function(n){t.logger.info("ws closed ".concat(n)),e.reject("closed"),t.notifyStatusChanged(!1)},this.ws.onopen=function(){var n;t.startupTimer.mark("ws-opened"),t.logger.info("ws opened ".concat(null===(n=t.settings.identity)||void 0===n?void 0:n.application)),e.resolve(),t.notifyStatusChanged(!0)},this.ws.onmessage=function(e){t._registry.execute("onMessage",e.data)},e.promise},t.prototype.notifyForSocketState=function(t){this.wsRequests.forEach((function(e){t?e.failed&&e.failed(t):e.callback()})),this.wsRequests=[]},t.prototype.notifyStatusChanged=function(t,e){this._registry.execute("onConnectedChanged",t,e)},t}(),H={},q={get exports(){return H},set exports(t){H=t}},U={},V={get exports(){return U},set exports(t){U=t}},$=1;var J,z,K,Q={nextValue:function(){return($=(9301*$+49297)%233280)/233280},seed:function(t){$=t}},Z="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-";function X(){K=!1}function Y(t){if(t){if(t!==J){if(t.length!==Z.length)throw new Error("Custom alphabet for shortid must be "+Z.length+" unique characters. You submitted "+t.length+" characters: "+t);var e=t.split("").filter((function(t,e,n){return e!==n.lastIndexOf(t)}));if(e.length)throw new Error("Custom alphabet for shortid must be "+Z.length+" unique characters. These characters were not unique: "+e.join(", "));J=t,X()}}else J!==Z&&(J=Z,X())}function tt(){return K||(K=function(){J||Y(Z);for(var t,e=J.split(""),n=[],i=Q.nextValue();e.length>0;)i=Q.nextValue(),t=Math.floor(i*e.length),n.push(e.splice(t,1)[0]);return n.join("")}())}var et,nt={get:function(){return J||Z},characters:function(t){return Y(t),J},seed:function(t){Q.seed(t),z!==t&&(X(),z=t)},lookup:function(t){return tt()[t]},shuffled:tt},it="object"==typeof window&&(window.crypto||window.msCrypto);et=it&&it.getRandomValues?function(t){return it.getRandomValues(new Uint8Array(t))}:function(t){for(var e=[],n=0;n<t;n++)e.push(Math.floor(256*Math.random()));return e};var ot=nt,rt=et,st=function(t,e,n){for(var i=(2<<Math.log(e.length-1)/Math.LN2)-1,o=-~(1.6*i*n/e.length),r="";;)for(var s=t(o),a=o;a--;)if((r+=e[s[a]&i]||"").length===+n)return r};var at,ct,dt=function(t){for(var e,n=0,i="";!e;)i+=st(rt,ot.get(),1),e=t<Math.pow(16,n+1),n++;return i};var ut=function(t){var e="",n=Math.floor(.001*(Date.now()-1567752802062));return n===ct?at++:(at=0,ct=n),e+=dt(7),e+=dt(t),at>0&&(e+=dt(at)),e+=dt(n)},ht=nt;var lt=function(t){return!(!t||"string"!=typeof t||t.length<6)&&!new RegExp("[^"+ht.get().replace(/[|\\{}()[\]^$+*?.-]/g,"\\$&")+"]").test(t)};!function(t){var e=nt,n=ut,i=lt,o=0;function r(){return n(o)}t.exports=r,t.exports.generate=r,t.exports.seed=function(n){return e.seed(n),t.exports},t.exports.worker=function(e){return o=e,t.exports},t.exports.characters=function(t){return void 0!==t&&e.characters(t),e.shuffled()},t.exports.isValid=i}(V),function(t){t.exports=U}(q);var pt=M(H);function gt(t,e,n,i,o){null==t&&(t="global"),i=i||["success"],o=o||["error"];var r,s=!1,a=!1,c=!1,d=N();e.disconnected((function(){c=!1,n.debug("connection is down"),s=!1,a=!0,d.execute("onLeft",{disconnected:!0})})),e.loggedIn((function(){c=!0,a&&(n.debug("connection is now up - trying to reconnect..."),h(r))})),e.on("success",(function(t){return p(t)})),e.on("error",(function(t){return l(t)})),e.on("result",(function(t){return p(t)})),i&&i.forEach((function(t){e.on(t,(function(t){return p(t)}))})),o&&o.forEach((function(t){e.on(t,(function(t){return l(t)}))}));var u={};function h(e){return r=e,new Promise((function(i,o){if(s)i({});else{var r;if("global"===t)r=c?Promise.resolve({}):Promise.reject("not connected to gateway");else n.debug("joining domain ".concat(t)),r=f({type:"join",destination:t,domain:"global",options:e});r.then((function(){!function(){n.debug("did join "+t),s=!0;var e=a;a=!1,d.execute("onJoined",e)}(),i({})})).catch((function(e){n.debug("error joining "+t+" domain: "+JSON.stringify(e)),o(e)}))}}))}function l(e){if(t===e.domain){var n=e.request_id;if(n){var i=u[n];i&&i.error(e)}}}function p(e){if(e.domain===t){var n=e.request_id;if(n){var i=u[n];i&&i.success(e)}}}function g(){return pt()}function f(i,o,r){r=r||{},i.request_id=i.request_id||g(),i.domain=i.domain||t,r.skipPeerId||(i.peer_id=e.peerId);var s=i.request_id;return new Promise((function(t,a){u[s]={success:function(e){delete u[s],e._tag=o,t(e)},error:function(t){n.warn("Gateway error - ".concat(JSON.stringify(t))),delete u[s],t._tag=o,a(t)}},e.send(i,r).catch((function(t){u[s].error({err:t})}))}))}return{join:h,leave:function(){return"global"===t?Promise.resolve():(n.debug("stopping session "+t+"..."),a=!1,f({type:"leave",destination:t,domain:"global"}).then((function(){s=!1,d.execute("onLeft")})).catch((function(){s=!1,d.execute("onLeft")})))},onJoined:function(t){return s&&t(!1),d.add("onJoined",t)},onLeft:function(t){return s||t(),d.add("onLeft",t)},send:f,sendFireAndForget:function(n){return n.request_id=n.request_id?n.request_id:g(),n.domain=n.domain||t,n.peer_id=e.peerId,e.send(n)},on:function(i,o){e.on(i,(function(e){if(e.domain===t)try{o(e)}catch(t){n.error("Callback failed: ".concat(t," \n ").concat(t.stack," \n msg was: ").concat(JSON.stringify(e)),t)}}))},loggedIn:function(t){return e.loggedIn(t)},connected:function(t){return e.connected(t)},disconnected:function(t){return e.disconnected(t)},get peerId(){return e.peerId},get domain(){return t}}}var ft=function(){function t(t,e,n){var i=this;this.connection=t,this.settings=e,this.logger=n,this.protocolVersion=3,this.datePrefix="#T42_DATE#",this.datePrefixLen=this.datePrefix.length,this.dateMinLen=this.datePrefixLen+1,this.datePrefixFirstChar=this.datePrefix[0],this.registry=N(),this._isLoggedIn=!1,this.shouldTryLogin=!0,this.initialLogin=!0,this.initialLoginAttempts=3,this.sessions=[],t.disconnected((function(){i.handleDisconnected()})),this.ping()}return Object.defineProperty(t.prototype,"isLoggedIn",{get:function(){return this._isLoggedIn},enumerable:!1,configurable:!0}),t.prototype.processStringMessage=function(t){var e=this,n=JSON.parse(t,(function(t,n){if("string"!=typeof n)return n;if(n.length<e.dateMinLen)return n;if(n[0]!==e.datePrefixFirstChar)return n;if(n.substring(0,e.datePrefixLen)!==e.datePrefix)return n;try{var i=parseInt(n.substring(e.datePrefixLen,n.length),10);return isNaN(i)?n:new Date(i)}catch(t){return n}}));return{msg:n,msgType:n.type}},t.prototype.createStringMessage=function(t){var e=Date.prototype.toJSON;try{var n=this.datePrefix;return Date.prototype.toJSON=function(){return n+this.getTime()},JSON.stringify(t)}finally{Date.prototype.toJSON=e}},t.prototype.processObjectMessage=function(t){if(!t.type)throw new Error("Object should have type property");return{msg:t,msgType:t.type}},t.prototype.createObjectMessage=function(t){return t},t.prototype.login=function(t,e){return i(this,void 0,void 0,(function(){var n,i,r,s,a,c,d,u,h,l;return o(this,(function(o){switch(o.label){case 0:if(this.logger.debug("logging in..."),this.loginConfig=t,this.loginConfig||(this.loginConfig={username:"",password:""}),this.shouldTryLogin=!0,n={},this.connection.gatewayToken=t.gatewayToken,!t.gatewayToken)return[3,5];if(!e)return[3,4];o.label=1;case 1:return o.trys.push([1,3,,4]),[4,this.getNewGWToken()];case 2:return u=o.sent(),t.gatewayToken=u,[3,4];case 3:return i=o.sent(),this.logger.warn("failed to get GW token when reconnecting ".concat((null==i?void 0:i.message)||i)),[3,4];case 4:return n.method="gateway-token",n.token=t.gatewayToken,this.connection.gatewayToken=t.gatewayToken,[3,10];case 5:return"sspi"!==t.flowName?[3,9]:(n.provider="win",n.method="access-token",t.flowCallback&&t.sessionId?(r=n,[4,t.flowCallback(t.sessionId,null)]):[3,7]);case 6:return r.token=o.sent().data.toString("base64"),[3,8];case 7:throw new Error("Invalid SSPI config");case 8:return[3,10];case 9:if(t.token)n.method="access-token",n.token=t.token;else if(t.username)n.method="secret",n.login=t.username,n.secret=t.password;else{if(!t.provider)throw new Error("invalid auth message"+JSON.stringify(t));n.provider=t.provider,n.providerContext=t.providerContext}o.label=10;case 10:s={type:"hello",identity:this.settings.identity,authentication:n},t.sessionId&&(s.request_id=t.sessionId),this.globalDomain=gt("global",this.connection,this.logger.subLogger("global-domain"),["welcome","token","authentication-request"]),a={skipPeerId:!0},this.initialLogin&&(a.retryInterval=this.settings.reconnectInterval,a.maxRetries=this.settings.reconnectAttempts),o.label=11;case 11:o.trys.push([11,19,20,21]),c=void 0,o.label=12;case 12:return[4,this.globalDomain.send(s,void 0,a)];case 13:return"authentication-request"!==(d=o.sent()).type?[3,16]:(u=Buffer.from(d.authentication.token,"base64"),t.flowCallback&&t.sessionId?(h=s.authentication,[4,t.flowCallback(t.sessionId,u)]):[3,15]);case 14:h.token=o.sent().data.toString("base64"),o.label=15;case 15:return s.request_id=t.sessionId,[3,12];case 16:if("welcome"===d.type)return c=d,[3,18];throw"error"===d.type?new Error("Authentication failed: "+d.reason):new Error("Unexpected message type during authentication: "+d.type);case 17:return[3,12];case 18:return this.initialLogin=!1,this.logger.debug("login successful with peerId "+c.peer_id),this.connection.peerId=c.peer_id,this.connection.resolvedIdentity=c.resolved_identity,this.connection.availableDomains=c.available_domains,c.options&&(this.connection.token=c.options.access_token,this.connection.info=c.options.info),this.setLoggedIn(!0),[2,c.resolved_identity];case 19:throw l=o.sent(),this.logger.error("error sending hello message - "+(l.message||l.msg||l.reason||l),l),l;case 20:return t&&t.flowCallback&&t.sessionId&&t.flowCallback(t.sessionId,null),[7];case 21:return[2]}}))}))},t.prototype.logout=function(){return i(this,void 0,void 0,(function(){var t;return o(this,(function(e){switch(e.label){case 0:return this.logger.debug("logging out..."),this.shouldTryLogin=!1,this.pingTimer&&clearTimeout(this.pingTimer),t=this.sessions.map((function(t){t.leave()})),[4,Promise.all(t)];case 1:return e.sent(),[2]}}))}))},t.prototype.loggedIn=function(t){return this._isLoggedIn&&t(),this.registry.add("onLoggedIn",t)},t.prototype.domain=function(t,e,n,i){var o=this.sessions.filter((function(e){return e.domain===t}))[0];return o||(o=gt(t,this.connection,e,n,i),this.sessions.push(o)),o},t.prototype.handleDisconnected=function(){var t=this;if(this.setLoggedIn(!1),this.shouldTryLogin&&this.initialLogin){if(this.initialLoginAttempts<=0)return;this.initialLoginAttempts--}if(this.logger.debug("disconnected - will try new login?"+this.shouldTryLogin),this.shouldTryLogin){if(!this.loginConfig)throw new Error("no login info");this.connection.login(this.loginConfig,!0).catch((function(){setTimeout(t.handleDisconnected.bind(t),t.settings.reconnectInterval||1e3)}))}},t.prototype.setLoggedIn=function(t){this._isLoggedIn=t,this._isLoggedIn&&this.registry.execute("onLoggedIn")},t.prototype.ping=function(){var t=this;this.shouldTryLogin&&(this._isLoggedIn&&this.connection.send({type:"ping"}),this.pingTimer=setTimeout((function(){t.ping()}),3e4))},t.prototype.authToken=function(){return this.globalDomain?this.globalDomain.send({type:"create-token"}).then((function(t){return t.token})):Promise.reject(new Error("no global domain session"))},t.prototype.getNewGWToken=function(){if(void 0!==typeof window){var t=window.glue42gd;if(t)return t.getGWToken()}return Promise.reject(new Error("not running in GD"))},t}(),yt=function(){function t(t){this.specsNames=[],this.messages={},this.subs={},this.subsRefCount={},this.specs={};for(var e=0,n=t;e<n.length;e++){var i=n[e];this.specs[i.name]=i,this.specsNames.push(i.name)}}return t.prototype.init=function(t){var e=this;this.connection=t;for(var n=0,i=this.specsNames;n<i.length;n++)for(var o=i[n],r=function(n){var i=s.subsRefCount[n];if(i||(i=0),i+=1,s.subsRefCount[n]=i,i>1)return"continue";var o=t.on(n,(function(t){return e.processMessage(n,t)}));s.subs[n]=o},s=this,a=0,c=this.specs[o].types;a<c.length;a++){r(c[a])}},t.prototype.processMessage=function(t,e){if(!this.isDone&&e)for(var n=0,i=this.specsNames;n<i.length;n++){var o=i[n];if(-1!==this.specs[o].types.indexOf(t)){var r=this.messages[o]||[];this.messages[o]=r,r.push(e)}}},t.prototype.drain=function(t,e){var n;e&&(this.messages[t]||[]).forEach(e),delete this.messages[t];for(var i=0,o=this.specs[t].types;i<o.length;i++){var r=o[i];this.subsRefCount[r]-=1,this.subsRefCount[r]<=0&&(null===(n=this.connection)||void 0===n||n.off(this.subs[r]),delete this.subs[r],delete this.subsRefCount[r])}delete this.specs[t],this.specs.length||(this.isDone=!0)},t}(),mt=function(t,e,n){return new Promise((function(i,o){var r=setTimeout((function(){var t=n||"Promise timeout hit: ".concat(e);o(t)}),e);new Promise(t).then((function(t){clearTimeout(r),i(t)})).catch((function(t){clearTimeout(r),o(t)}))}))},vt=function(){function t(t,e,n){this.settings=t,this.logger=e,this.identity=n,this.iAmConnected=!1,this.parentReady=!1,this.rejected=!1,this.children=[],this.extContentAvailable=!1,this.extContentConnecting=!1,this.extContentConnected=!1,this.parentInExtMode=!1,this.webNamespace="g42_core_web",this.parentPingTimeout=5e3,this.connectionRequestTimeout=7e3,this.defaultTargetString="*",this.registry=N(),this.messages={connectionAccepted:{name:"connectionAccepted",handle:this.handleConnectionAccepted.bind(this)},connectionRejected:{name:"connectionRejected",handle:this.handleConnectionRejected.bind(this)},connectionRequest:{name:"connectionRequest",handle:this.handleConnectionRequest.bind(this)},parentReady:{name:"parentReady",handle:function(){}},parentPing:{name:"parentPing",handle:this.handleParentPing.bind(this)},platformPing:{name:"platformPing",handle:this.handlePlatformPing.bind(this)},platformReady:{name:"platformReady",handle:this.handlePlatformReady.bind(this)},clientUnload:{name:"clientUnload",handle:this.handleClientUnload.bind(this)},manualUnload:{name:"manualUnload",handle:this.handleManualUnload.bind(this)},extConnectionResponse:{name:"extConnectionResponse",handle:this.handleExtConnectionResponse.bind(this)},extSetupRequest:{name:"extSetupRequest",handle:this.handleExtSetupRequest.bind(this)},gatewayDisconnect:{name:"gatewayDisconnect",handle:this.handleGatewayDisconnect.bind(this)},gatewayInternalConnect:{name:"gatewayInternalConnect",handle:this.handleGatewayInternalConnect.bind(this)}},this.extContentAvailable=!!window.glue42ext,this.setUpMessageListener(),this.setUpUnload(),this.setupPlatformUnloadListener(),this.parentType=window.name.includes("#wsp")?"workspace":void 0}return t.prototype.manualSetReadyState=function(){this.iAmConnected=!0,this.parentReady=!0},Object.defineProperty(t.prototype,"transportWindowId",{get:function(){return this.publicWindowId},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"communicationId",{get:function(){return this._communicationId},enumerable:!1,configurable:!0}),t.prototype.sendObject=function(t){return i(this,void 0,void 0,(function(){return o(this,(function(e){if(this.extContentConnected)return[2,window.postMessage({glue42ExtOut:t},this.defaultTargetString)];if(!this.port)throw new Error("Cannot send message, because the port was not opened yet");return this.port.postMessage(t),[2]}))}))},Object.defineProperty(t.prototype,"isObjectBasedTransport",{get:function(){return!0},enumerable:!1,configurable:!0}),t.prototype.onMessage=function(t){return this.registry.add("onMessage",t)},t.prototype.send=function(){return Promise.reject("not supported")},t.prototype.onConnectedChanged=function(t){return this.registry.add("onConnectedChanged",t)},t.prototype.open=function(){return i(this,void 0,void 0,(function(){return o(this,(function(t){switch(t.label){case 0:return this.logger.debug("opening a connection to the web platform gateway."),[4,this.connect()];case 1:return t.sent(),this.notifyStatusChanged(!0),[2]}}))}))},t.prototype.close=function(){var t,e,n={glue42core:{type:this.messages.gatewayDisconnect.name,data:{clientId:this.myClientId,ownWindowId:null===(t=this.identity)||void 0===t?void 0:t.windowId}}};return null===(e=this.port)||void 0===e||e.postMessage(n),this.parentReady=!1,this.notifyStatusChanged(!1,"manual reconnection"),Promise.resolve()},t.prototype.name=function(){return"web-platform"},t.prototype.reconnect=function(){return i(this,void 0,void 0,(function(){return o(this,(function(t){switch(t.label){case 0:return[4,this.close()];case 1:return t.sent(),[2,Promise.resolve()]}}))}))},t.prototype.initiateInternalConnection=function(){var t=this;return new Promise((function(e,n){t.logger.debug("opening an internal web platform connection"),t.port=t.settings.port,t.iAmConnected?t.logger.warn("cannot open a new connection, because this client is currently connected"):(t.port.onmessage=function(i){var o,r;if(!t.iAmConnected||(null===(o=i.data)||void 0===o?void 0:o.glue42core)){var s=null===(r=i.data)||void 0===r?void 0:r.glue42core;s&&(s.type===t.messages.gatewayInternalConnect.name&&s.success&&(t.publicWindowId=t.settings.windowId,t.identity&&t.publicWindowId&&(t.identity.windowId=t.publicWindowId,t.identity.instance=t.publicWindowId),e()),s.type===t.messages.gatewayInternalConnect.name&&s.error&&n(s.error))}else t.registry.execute("onMessage",i.data)},t.port.postMessage({glue42core:{type:t.messages.gatewayInternalConnect.name}}))}))},t.prototype.initiateRemoteConnection=function(t){var e=this;return mt((function(n,i){var o;e.connectionResolve=n,e.connectionReject=i,e.myClientId=null!==(o=e.myClientId)&&void 0!==o?o:pt();var r=e.getMyWindowId()||pt(),s={glue42core:{type:e.messages.connectionRequest.name,clientId:e.myClientId,clientType:"child",bridgeInstanceId:r,selfAssignedWindowId:e.selfAssignedWindowId}};if(e.logger.debug("sending connection request"),e.extContentConnecting)return s.glue42core.clientType="child",s.glue42core.bridgeInstanceId=e.myClientId,s.glue42core.parentWindowId=e.parentWindowId,window.postMessage(s,e.defaultTargetString);if(!t)throw new Error("Cannot send a connection request, because no glue target was specified!");t.postMessage(s,e.defaultTargetString)}),this.connectionRequestTimeout,"The connection to the target glue window timed out")},t.prototype.isParentCheckSuccess=function(t){return i(this,void 0,void 0,(function(){return o(this,(function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),[4,t];case 1:return e.sent(),[2,{success:!0}];case 2:return e.sent(),[2,{success:!1}];case 3:return[2]}}))}))},t.prototype.setUpMessageListener=function(){var t=this;this.settings.port?this.logger.debug("skipping generic message listener, because this is an internal client"):window.addEventListener("message",(function(e){var n,i=null===(n=e.data)||void 0===n?void 0:n.glue42core;if(i&&!t.rejected)if(t.checkMessageTypeValid(i.type)){var o=i.type;t.logger.debug("received valid glue42core message of type: ".concat(o)),t.messages[o].handle(e)}else t.logger.error("cannot handle the incoming glue42 core message, because the type is invalid: ".concat(i.type))}))},t.prototype.setUpUnload=function(){var t=this;this.settings.port?this.logger.debug("skipping unload event listener, because this is an internal client"):window.addEventListener("beforeunload",(function(){var e,n;if(!t.extContentConnected){var i={glue42core:{type:t.messages.clientUnload.name,data:{clientId:t.myClientId,ownWindowId:null===(e=t.identity)||void 0===e?void 0:e.windowId}}};t.parent&&t.parent.postMessage(i,t.defaultTargetString),null===(n=t.port)||void 0===n||n.postMessage(i)}}))},t.prototype.handlePlatformReady=function(t){this.logger.debug("the web platform gave the ready signal"),this.parentReady=!0,this.parentPingResolve&&(this.parentPingResolve(),delete this.parentPingResolve),this.parentPingInterval&&(clearInterval(this.parentPingInterval),delete this.parentPingInterval),this.parent=t.source,this.parentType=window.name.includes("#wsp")?"workspace":"window"},t.prototype.handleConnectionAccepted=function(t){var e,n=null===(e=t.data)||void 0===e?void 0:e.glue42core;return this.myClientId===n.clientId?this.handleAcceptanceOfMyRequest(n):this.handleAcceptanceOfGrandChildRequest(n,t)},t.prototype.handleAcceptanceOfMyRequest=function(t){var e=this;if(this.logger.debug("handling a connection accepted signal targeted at me."),this.isPreferredActivated=t.isPreferredActivated,this.extContentConnecting)return this.processExtContentConnection(t);if(t.port){if(this.publicWindowId=this.getMyWindowId(),this.identity&&(this.identity.windowId=this.publicWindowId,this.identity.instance=this.identity.instance?this.identity.instance:this.publicWindowId||pt()),this.identity&&t.appName&&(this.identity.application=t.appName,this.identity.applicationName=t.appName),this._communicationId=t.communicationId,this.port=t.port,this.port.onmessage=function(t){return e.registry.execute("onMessage",t.data)},this.connectionResolve)return this.logger.debug("my connection is set up, calling the connection resolve."),this.connectionResolve(),void delete this.connectionResolve;this.logger.error("unable to call the connection resolve, because no connection promise was found")}else this.logger.error("cannot set up my connection, because I was not provided with a port")},t.prototype.processExtContentConnection=function(t){var e=this;if(this.logger.debug("handling a connection accepted signal targeted at me for extension content connection."),this.extContentConnecting=!1,this.extContentConnected=!0,this.publicWindowId=this.parentWindowId||this.myClientId,this.extContentConnecting&&this.identity&&(this.identity.windowId=this.publicWindowId),this.identity&&t.appName&&(this.identity.application=t.appName,this.identity.applicationName=t.appName),window.addEventListener("message",(function(t){var n,i=null===(n=t.data)||void 0===n?void 0:n.glue42ExtInc;i&&e.registry.execute("onMessage",i)})),this.connectionResolve)return this.logger.debug("my connection is set up, calling the connection resolve."),this.connectionResolve(),void delete this.connectionResolve},t.prototype.handleAcceptanceOfGrandChildRequest=function(t,e){if(this.extContentConnecting||this.extContentConnected)this.logger.debug("cannot process acceptance of a grandchild, because I am connected to a content script");else{this.logger.debug("handling a connection accepted signal targeted at a grandchild: ".concat(t.clientId));var n=this.children.find((function(e){return e.grandChildId===t.clientId}));n?(n.connected=!0,this.logger.debug("the grandchild connection for ".concat(t.clientId," is set up, forwarding the success message and the gateway port")),t.parentWindowId=this.publicWindowId,n.source.postMessage(e.data,n.origin,[t.port])):this.logger.error("cannot handle connection accepted for grandchild: ".concat(t.clientId,", because there is no grandchild with this id"))}},t.prototype.handleConnectionRejected=function(){this.logger.debug("handling a connection rejection. Most likely the reason is that this window was not created by a glue API call"),this.connectionReject&&(this.connectionReject("The platform connection was rejected. Most likely because this window was not created by a glue API call"),delete this.connectionReject)},t.prototype.handleConnectionRequest=function(t){if(this.extContentConnecting)this.logger.debug("This connection request event is targeted at the extension content");else{var e=t.source,n=t.data.glue42core;if(!n.clientType||"grandChild"!==n.clientType)return this.rejectConnectionRequest(e,t.origin,"rejecting a connection request, because the source was not opened by a glue API call");if(!n.clientId)return this.rejectConnectionRequest(e,t.origin,"rejecting a connection request, because the source did not provide a valid id");if(!this.parent)return this.rejectConnectionRequest(e,t.origin,"Cannot forward the connection request, because no direct connection to the platform was found");this.logger.debug("handling a connection request for a grandchild: ".concat(n.clientId)),this.children.push({grandChildId:n.clientId,source:e,connected:!1,origin:t.origin}),this.logger.debug("grandchild: ".concat(n.clientId," is prepared, forwarding connection request to the platform")),this.parent.postMessage(t.data,this.defaultTargetString)}},t.prototype.handleParentPing=function(t){if(this.parentReady)if(this.iAmConnected){var e={glue42core:{type:this.messages.parentReady.name}};this.extContentConnected&&(e.glue42core.extMode={windowId:this.myClientId});var n=t.source;this.logger.debug("responding to a parent ping with a ready message"),n.postMessage(e,t.origin)}else this.logger.debug("i am not fully connected yet, I am ignoring the parent ping");else this.logger.debug("my parent is not ready, I am ignoring the parent ping")},t.prototype.setupPlatformUnloadListener=function(){var t=this;this.onMessage((function(e){"platformUnload"===e.type&&(t.logger.debug("detected a web platform unload"),t.parentReady=!1,t.notifyStatusChanged(!1,"Gateway unloaded"))}))},t.prototype.handleManualUnload=function(){var t,e,n={glue42core:{type:this.messages.clientUnload.name,data:{clientId:this.myClientId,ownWindowId:null===(t=this.identity)||void 0===t?void 0:t.windowId}}};if(this.extContentConnected)return window.postMessage({glue42ExtOut:n},this.defaultTargetString);null===(e=this.port)||void 0===e||e.postMessage(n)},t.prototype.handleClientUnload=function(t){var e=t.data.glue42core,n=null==e?void 0:e.data.clientId;n?this.children.find((function(t){return t.grandChildId===n}))?(this.logger.debug("handling grandchild unload for id: ".concat(n)),this.children=this.children.filter((function(t){return t.grandChildId!==n}))):this.logger.warn("cannot process grand child unload, because this client is unaware of this grandchild"):this.logger.warn("cannot process grand child unload, because the provided id was not valid")},t.prototype.handlePlatformPing=function(){},t.prototype.notifyStatusChanged=function(t,e){this.iAmConnected=t,this.registry.execute("onConnectedChanged",t,e)},t.prototype.checkMessageTypeValid=function(t){return"string"==typeof t&&!!this.messages[t]},t.prototype.rejectConnectionRequest=function(t,e,n){this.rejected=!0,this.logger.error(n);var i={glue42core:{type:this.messages.connectionRejected.name}};t.postMessage(i,e)},t.prototype.requestConnectionPermissionFromExt=function(){var t=this;return this.waitForContentScript().then((function(){return mt((function(e,n){t.extConnectionResolve=e,t.extConnectionReject=n;t.logger.debug("permission request to the extension content script was sent"),window.postMessage({glue42core:{type:"extSetupRequest"}},t.defaultTargetString)}),t.parentPingTimeout,"Cannot initialize glue, because this app was not opened or created by a Glue Client and the request for extension connection timed out")}))},t.prototype.handleExtConnectionResponse=function(t){var e;if(!(null===(e=t.data)||void 0===e?void 0:e.glue42core).approved)return this.extConnectionReject?this.extConnectionReject("Cannot initialize glue, because this app was not opened or created by a Glue Client and the request for extension connection was rejected"):void 0;this.extConnectionResolve&&(this.extConnectionResolve(),delete this.extConnectionResolve),this.extContentConnecting=!0,this.parentType="extension",this.logger.debug("The extension connection was approved, proceeding.")},t.prototype.handleExtSetupRequest=function(){},t.prototype.handleGatewayDisconnect=function(){},t.prototype.handleGatewayInternalConnect=function(){},t.prototype.waitForContentScript=function(){var t;return!!(null===(t=window.glue42ext)||void 0===t?void 0:t.content)?Promise.resolve():mt((function(t){window.addEventListener("Glue42EXTReady",(function(){t()}))}),this.connectionRequestTimeout,"The content script was available, but was never heard to be ready")},t.prototype.connect=function(){return i(this,void 0,void 0,(function(){return o(this,(function(t){switch(t.label){case 0:return this.settings.port?[4,this.initiateInternalConnection()]:[3,2];case 1:return t.sent(),this.logger.debug("internal web platform connection completed"),[2];case 2:return this.logger.debug("opening a client web platform connection"),[4,this.findParent()];case 3:return t.sent(),[4,this.initiateRemoteConnection(this.parent)];case 4:return t.sent(),this.logger.debug("the client is connected"),[2]}}))}))},t.prototype.findParent=function(){var t;return i(this,void 0,void 0,(function(){var e,n,i,s;return o(this,(function(o){switch(o.label){case 0:if(e="Cannot initiate glue, because this window was not opened or created by a glue client",n=this.getPossibleParentsInWindow(window),i=this.getPossibleParentsOutsideWindow(null===(t=window.top)||void 0===t?void 0:t.opener,window.top),!(s=new Set(r(r([],n,!0),i,!0))).size&&!this.extContentAvailable)throw new Error(e);return s.size||!this.extContentAvailable?[3,2]:[4,this.requestConnectionPermissionFromExt()];case 1:case 4:return o.sent(),[2];case 2:return[4,this.isParentCheckSuccess(this.confirmParent(Array.from(s)))];case 3:if(o.sent().success)return this.logger.debug("The default parent was found!"),[2];if(!this.extContentAvailable)throw new Error(e);return[4,this.requestConnectionPermissionFromExt()]}}))}))},t.prototype.getPossibleParentsInWindow=function(t){return t&&t!==t.top?r([t.parent],this.getPossibleParentsInWindow(t.parent),!0):[]},t.prototype.getPossibleParentsOutsideWindow=function(t,e){return t&&e&&t!==e?r(r([t],this.getPossibleParentsInWindow(t),!0),this.getPossibleParentsOutsideWindow(t.opener,t),!0):[]},t.prototype.confirmParent=function(t){var e=this,n=mt((function(n)