@interopio/browser-platform
Version:
IoConnect Browser main application package
1 lines • 1.52 MB
JavaScript
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).IoConnectBrowserPlatform=t()}(this,(function(){"use strict";const e=window,t={logger:"info",gateway:{webPlatform:{}},libraries:[],exposeAPI:!0},r={awaitFactory:!0,timeout:5e3},n={name:"platformUnload"},i={name:"transportSwitchRequest"},s={name:"transportSwitchResponse"},o={name:"getCurrentTransport"},a={name:"getCurrentTransportResponse"},c={name:"checkPreferredLogic"},l={name:"checkPreferredConnection"},u={name:"checkPreferredLogicResponse"},d={name:"checkPreferredConnectionResponse"},h="web-platform",p="latest_fdc3_type",g=new MessageChannel,f=e=>"string"==typeof e?e:e?.message?"string"==typeof e.message?e.message:JSON.stringify(e.message):JSON.stringify(e),m=(e,t)=>{try{return e.runWithException(t)}catch(e){return y.raiseError(e,!0)}};const y=new class{raiseError(e,t){const r=f(e);if(g.port1.postMessage(r),t)throw e;throw new Error(r)}};var w=function(e){return{ok:!0,result:e}},v=function(e){return{ok:!1,error:e}},b=function(e,t,r){return!1===t.ok?t:!1===r.ok?r:w(e(t.result,r.result))},S=function(e,t){return!0===t.ok?t:v(e(t.error))},C=function(){return C=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var i in t=arguments[r])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e},C.apply(this,arguments)};function I(e,t){if(e===t)return!0;if(null===e&&null===t)return!0;if(typeof e!=typeof t)return!1;if("object"==typeof e){if(Array.isArray(e)){if(!Array.isArray(t))return!1;if(e.length!==t.length)return!1;for(var r=0;r<e.length;r++)if(!I(e[r],t[r]))return!1;return!0}var n=Object.keys(e);if(n.length!==Object.keys(t).length)return!1;for(r=0;r<n.length;r++){if(!t.hasOwnProperty(n[r]))return!1;if(!I(e[n[r]],t[n[r]]))return!1}return!0}}var x=function(e){return Array.isArray(e)},_=function(e){return"object"==typeof e&&null!==e&&!x(e)},E=function(e,t){return"expected "+e+", got "+function(e){switch(typeof e){case"string":return"a string";case"number":return"a number";case"boolean":return"a boolean";case"undefined":return"undefined";case"object":return e instanceof Array?"an array":null===e?"null":"an object";default:return JSON.stringify(e)}}(t)},A=function(e){return e.map((function(e){return"string"==typeof e?"."+e:"["+e+"]"})).join("")},T=function(e,t){var r=t.at,n=function(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(n=Object.getOwnPropertySymbols(e);i<n.length;i++)t.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(e,n[i])&&(r[n[i]]=e[n[i]])}return r}(t,["at"]);return C({at:e+(r||"")},n)},P=function(){function e(t){var r=this;this.decode=t,this.run=function(e){return S((function(t){return{kind:"DecoderError",input:e,at:"input"+(t.at||""),message:t.message||""}}),r.decode(e))},this.runPromise=function(e){return function(e){return!0===e.ok?Promise.resolve(e.result):Promise.reject(e.error)}(r.run(e))},this.runWithException=function(e){return function(e){if(!0===e.ok)return e.result;throw e.error}(r.run(e))},this.map=function(t){return new e((function(e){return function(e,t){return!0===t.ok?w(e(t.result)):t}(t,r.decode(e))}))},this.andThen=function(t){return new e((function(e){return function(e,t){return!0===t.ok?e(t.result):t}((function(r){return t(r).decode(e)}),r.decode(e))}))},this.where=function(t,n){return r.andThen((function(r){return t(r)?e.succeed(r):e.fail(n)}))}}return e.string=function(){return new e((function(e){return"string"==typeof e?w(e):v({message:E("a string",e)})}))},e.number=function(){return new e((function(e){return"number"==typeof e?w(e):v({message:E("a number",e)})}))},e.boolean=function(){return new e((function(e){return"boolean"==typeof e?w(e):v({message:E("a boolean",e)})}))},e.constant=function(t){return new e((function(e){return I(e,t)?w(t):v({message:"expected "+JSON.stringify(t)+", got "+JSON.stringify(e)})}))},e.object=function(t){return new e((function(e){if(_(e)&&t){var r={};for(var n in t)if(t.hasOwnProperty(n)){var i=t[n].decode(e[n]);if(!0!==i.ok)return void 0===e[n]?v({message:"the key '"+n+"' is required but was not present"}):v(T("."+n,i.error));void 0!==i.result&&(r[n]=i.result)}return w(r)}return _(e)?w(e):v({message:E("an object",e)})}))},e.array=function(t){return new e((function(e){if(x(e)&&t){return e.reduce((function(e,r,n){return b((function(e,t){return e.concat([t])}),e,function(e,r){return S((function(e){return T("["+r+"]",e)}),t.decode(e))}(r,n))}),w([]))}return x(e)?w(e):v({message:E("an array",e)})}))},e.tuple=function(t){return new e((function(e){if(x(e)){if(e.length!==t.length)return v({message:"expected a tuple of length "+t.length+", got one of length "+e.length});for(var r=[],n=0;n<t.length;n++){var i=t[n].decode(e[n]);if(!i.ok)return v(T("["+n+"]",i.error));r[n]=i.result}return w(r)}return v({message:E("a tuple of length "+t.length,e)})}))},e.union=function(t,r){for(var n=[],i=2;i<arguments.length;i++)n[i-2]=arguments[i];return e.oneOf.apply(e,[t,r].concat(n))},e.intersection=function(t,r){for(var n=[],i=2;i<arguments.length;i++)n[i-2]=arguments[i];return new e((function(e){return[t,r].concat(n).reduce((function(t,r){return b(Object.assign,t,r.decode(e))}),w({}))}))},e.anyJson=function(){return new e((function(e){return w(e)}))},e.unknownJson=function(){return new e((function(e){return w(e)}))},e.dict=function(t){return new e((function(e){if(_(e)){var r={};for(var n in e)if(e.hasOwnProperty(n)){var i=t.decode(e[n]);if(!0!==i.ok)return v(T("."+n,i.error));r[n]=i.result}return w(r)}return v({message:E("an object",e)})}))},e.optional=function(t){return new e((function(e){return null==e?w(void 0):t.decode(e)}))},e.oneOf=function(){for(var t=[],r=0;r<arguments.length;r++)t[r]=arguments[r];return new e((function(e){for(var r=[],n=0;n<t.length;n++){var i=t[n].decode(e);if(!0===i.ok)return i;r[n]=i.error}var s=r.map((function(e){return"at error"+(e.at||"")+": "+e.message})).join('", "');return v({message:'expected a value matching one of the decoders, got the errors ["'+s+'"]'})}))},e.withDefault=function(t,r){return new e((function(e){return w(function(e,t){return!0===t.ok?t.result:e}(t,r.decode(e)))}))},e.valueAt=function(t,r){return new e((function(e){for(var n=e,i=0;i<t.length;i++){if(void 0===n)return v({at:A(t.slice(0,i+1)),message:"path does not exist"});if("string"==typeof t[i]&&!_(n))return v({at:A(t.slice(0,i+1)),message:E("an object",n)});if("number"==typeof t[i]&&!x(n))return v({at:A(t.slice(0,i+1)),message:E("an array",n)});n=n[t[i]]}return S((function(e){return void 0===n?{at:A(t),message:"path does not exist"}:T(A(t),e)}),r.decode(n))}))},e.succeed=function(t){return new e((function(e){return w(t)}))},e.fail=function(t){return new e((function(e){return v({message:t})}))},e.lazy=function(t){return new e((function(e){return t().decode(e)}))},e}(),k=P.string,O=P.number,R=P.boolean,N=P.anyJson;P.unknownJson;var D=P.constant,F=P.object,M=P.array;P.tuple,P.dict;var $=P.optional,j=P.oneOf;P.union,P.intersection,P.withDefault,P.valueAt,P.succeed,P.fail;var L=P.lazy;const B=["name","title","version","customProperties","icon","caption","type"],q=["appId","name","type","details","version","title","tooltip","lang","description","categories","icons","screenshots","contactEmail","moreInfo","publisher","customConfig","hostManifests","interop","localizedVersions"];var H=function(e){return{ok:!0,result:e}},W=function(e){return{ok:!1,error:e}},U=function(e,t,r){return!1===t.ok?t:!1===r.ok?r:H(e(t.result,r.result))},V=function(e,t){return!0===t.ok?t:W(e(t.error))},G=function(){return G=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var i in t=arguments[r])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e},G.apply(this,arguments)};function K(e,t){if(e===t)return!0;if(null===e&&null===t)return!0;if(typeof e!=typeof t)return!1;if("object"==typeof e){if(Array.isArray(e)){if(!Array.isArray(t))return!1;if(e.length!==t.length)return!1;for(var r=0;r<e.length;r++)if(!K(e[r],t[r]))return!1;return!0}var n=Object.keys(e);if(n.length!==Object.keys(t).length)return!1;for(r=0;r<n.length;r++){if(!t.hasOwnProperty(n[r]))return!1;if(!K(e[n[r]],t[n[r]]))return!1}return!0}}var J=function(e){return Array.isArray(e)},z=function(e){return"object"==typeof e&&null!==e&&!J(e)},X=function(e,t){return"expected "+e+", got "+function(e){switch(typeof e){case"string":return"a string";case"number":return"a number";case"boolean":return"a boolean";case"undefined":return"undefined";case"object":return e instanceof Array?"an array":null===e?"null":"an object";default:return JSON.stringify(e)}}(t)},Q=function(e){return e.map((function(e){return"string"==typeof e?"."+e:"["+e+"]"})).join("")},Y=function(e,t){var r=t.at,n=function(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(n=Object.getOwnPropertySymbols(e);i<n.length;i++)t.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(e,n[i])&&(r[n[i]]=e[n[i]])}return r}(t,["at"]);return G({at:e+(r||"")},n)},Z=function(){function e(t){var r=this;this.decode=t,this.run=function(e){return V((function(t){return{kind:"DecoderError",input:e,at:"input"+(t.at||""),message:t.message||""}}),r.decode(e))},this.runPromise=function(e){return function(e){return!0===e.ok?Promise.resolve(e.result):Promise.reject(e.error)}(r.run(e))},this.runWithException=function(e){return function(e){if(!0===e.ok)return e.result;throw e.error}(r.run(e))},this.map=function(t){return new e((function(e){return function(e,t){return!0===t.ok?H(e(t.result)):t}(t,r.decode(e))}))},this.andThen=function(t){return new e((function(e){return function(e,t){return!0===t.ok?e(t.result):t}((function(r){return t(r).decode(e)}),r.decode(e))}))},this.where=function(t,n){return r.andThen((function(r){return t(r)?e.succeed(r):e.fail(n)}))}}return e.string=function(){return new e((function(e){return"string"==typeof e?H(e):W({message:X("a string",e)})}))},e.number=function(){return new e((function(e){return"number"==typeof e?H(e):W({message:X("a number",e)})}))},e.boolean=function(){return new e((function(e){return"boolean"==typeof e?H(e):W({message:X("a boolean",e)})}))},e.constant=function(t){return new e((function(e){return K(e,t)?H(t):W({message:"expected "+JSON.stringify(t)+", got "+JSON.stringify(e)})}))},e.object=function(t){return new e((function(e){if(z(e)&&t){var r={};for(var n in t)if(t.hasOwnProperty(n)){var i=t[n].decode(e[n]);if(!0!==i.ok)return void 0===e[n]?W({message:"the key '"+n+"' is required but was not present"}):W(Y("."+n,i.error));void 0!==i.result&&(r[n]=i.result)}return H(r)}return z(e)?H(e):W({message:X("an object",e)})}))},e.array=function(t){return new e((function(e){if(J(e)&&t){return e.reduce((function(e,r,n){return U((function(e,t){return e.concat([t])}),e,function(e,r){return V((function(e){return Y("["+r+"]",e)}),t.decode(e))}(r,n))}),H([]))}return J(e)?H(e):W({message:X("an array",e)})}))},e.tuple=function(t){return new e((function(e){if(J(e)){if(e.length!==t.length)return W({message:"expected a tuple of length "+t.length+", got one of length "+e.length});for(var r=[],n=0;n<t.length;n++){var i=t[n].decode(e[n]);if(!i.ok)return W(Y("["+n+"]",i.error));r[n]=i.result}return H(r)}return W({message:X("a tuple of length "+t.length,e)})}))},e.union=function(t,r){for(var n=[],i=2;i<arguments.length;i++)n[i-2]=arguments[i];return e.oneOf.apply(e,[t,r].concat(n))},e.intersection=function(t,r){for(var n=[],i=2;i<arguments.length;i++)n[i-2]=arguments[i];return new e((function(e){return[t,r].concat(n).reduce((function(t,r){return U(Object.assign,t,r.decode(e))}),H({}))}))},e.anyJson=function(){return new e((function(e){return H(e)}))},e.unknownJson=function(){return new e((function(e){return H(e)}))},e.dict=function(t){return new e((function(e){if(z(e)){var r={};for(var n in e)if(e.hasOwnProperty(n)){var i=t.decode(e[n]);if(!0!==i.ok)return W(Y("."+n,i.error));r[n]=i.result}return H(r)}return W({message:X("an object",e)})}))},e.optional=function(t){return new e((function(e){return null==e?H(void 0):t.decode(e)}))},e.oneOf=function(){for(var t=[],r=0;r<arguments.length;r++)t[r]=arguments[r];return new e((function(e){for(var r=[],n=0;n<t.length;n++){var i=t[n].decode(e);if(!0===i.ok)return i;r[n]=i.error}var s=r.map((function(e){return"at error"+(e.at||"")+": "+e.message})).join('", "');return W({message:'expected a value matching one of the decoders, got the errors ["'+s+'"]'})}))},e.withDefault=function(t,r){return new e((function(e){return H(function(e,t){return!0===t.ok?t.result:e}(t,r.decode(e)))}))},e.valueAt=function(t,r){return new e((function(e){for(var n=e,i=0;i<t.length;i++){if(void 0===n)return W({at:Q(t.slice(0,i+1)),message:"path does not exist"});if("string"==typeof t[i]&&!z(n))return W({at:Q(t.slice(0,i+1)),message:X("an object",n)});if("number"==typeof t[i]&&!J(n))return W({at:Q(t.slice(0,i+1)),message:X("an array",n)});n=n[t[i]]}return V((function(e){return void 0===n?{at:Q(t),message:"path does not exist"}:Y(Q(t),e)}),r.decode(n))}))},e.succeed=function(t){return new e((function(e){return H(t)}))},e.fail=function(t){return new e((function(e){return W({message:t})}))},e.lazy=function(t){return new e((function(e){return t().decode(e)}))},e}(),ee=Z.string,te=Z.number,re=Z.boolean,ne=Z.anyJson;Z.unknownJson;var ie=Z.constant,se=Z.object,oe=Z.array;Z.tuple;var ae=Z.dict,ce=Z.optional,le=Z.oneOf;Z.union,Z.intersection,Z.withDefault,Z.valueAt,Z.succeed,Z.fail,Z.lazy;const ue=ee().where((e=>e.length>0),"Expected a non-empty string"),de=te().where((e=>e>=0),"Expected a non-negative number"),he=se({name:ue,displayName:ce(ee()),contexts:ce(oe(ee())),customConfig:ce(se())}),pe=le(ie("web"),ie("native"),ie("citrix"),ie("onlineNative"),ie("other")),ge=se({url:ue}),fe=se({src:ue,size:ce(ue),type:ce(ue)}),me=se({src:ue,size:ce(ue),type:ce(ue),label:ce(ue)}),ye=se({contexts:oe(ue),displayName:ce(ue),resultType:ce(ue),customConfig:ce(ne())}),we=se({listensFor:ce(ae(ye)),raises:ce(ae(oe(ue)))}),ve=se({broadcasts:ce(oe(ue)),listensFor:ce(oe(ue))}),be=se({name:ue,description:ce(ue),broadcasts:ce(oe(ue)),listensFor:ce(oe(ue))}),Se=se({intents:ce(we),userChannels:ce(ve),appChannels:ce(oe(be))}),Ce=se({url:ce(ue),top:ce(te()),left:ce(te()),width:ce(de),height:ce(de)}),Ie=se({name:ce(ue),type:ce(ue.where((e=>"window"===e),"Expected a value of window")),title:ce(ue),version:ce(ue),customProperties:ce(ne()),icon:ce(ee()),caption:ce(ee()),details:ce(Ce),intents:ce(oe(he)),hidden:ce(re())}),xe=se({name:ue,appId:ue,title:ce(ue),version:ce(ue),manifest:ue,manifestType:ue,tooltip:ce(ue),description:ce(ue),contactEmail:ce(ue),supportEmail:ce(ue),publisher:ce(ue),images:ce(oe(se({url:ce(ue)}))),icons:ce(oe(se({icon:ce(ue)}))),customConfig:ne(),intents:ce(oe(he))}),_e=se({appId:ce(ue),name:ce(ue),details:ce(ge),version:ce(ue),title:ce(ue),tooltip:ce(ue),lang:ce(ue),description:ce(ue),categories:ce(oe(ue)),icons:ce(oe(fe)),screenshots:ce(oe(me)),contactEmail:ce(ue),supportEmail:ce(ue),moreInfo:ce(ue),publisher:ce(ue),customConfig:ce(oe(ne())),hostManifests:ce(ne()),interop:ce(Se)}),Ee=se({appId:ue,name:ue,type:pe,details:ge,version:ce(ue),title:ce(ue),tooltip:ce(ue),lang:ce(ue),description:ce(ue),categories:ce(oe(ue)),icons:ce(oe(fe)),screenshots:ce(oe(me)),contactEmail:ce(ue),supportEmail:ce(ue),moreInfo:ce(ue),publisher:ce(ue),customConfig:ce(oe(ne())),hostManifests:ce(ne()),interop:ce(Se),localizedVersions:ce(ae(_e))}),Ae=le(xe,Ee),Te=e=>`${e.kind} at ${e.at}: ${JSON.stringify(e.input)}. Reason - ${e.message}`;const Pe={common:{nonEmptyStringDecoder:ue,nonNegativeNumberDecoder:de},fdc3:{allDefinitionsDecoder:Ae,v1DefinitionDecoder:xe,v2DefinitionDecoder:Ee}};var ke;!function(e){e.USER_CANCELLED="User Closed Intents Resolver UI without choosing a handler",e.CALLER_NOT_DEFINED="Caller Id is not defined",e.TIMEOUT_HIT="Timeout hit",e.INTENT_NOT_FOUND="Cannot find Intent",e.HANDLER_NOT_FOUND="Cannot find Intent Handler",e.TARGET_INSTANCE_UNAVAILABLE="Cannot start Target Instance",e.INTENT_DELIVERY_FAILED="Target Instance did not add a listener",e.RESOLVER_UNAVAILABLE="Intents Resolver UI unavailable",e.RESOLVER_TIMEOUT="User did not choose a handler",e.INVALID_RESOLVER_RESPONSE="Intents Resolver UI returned invalid response",e.INTENT_HANDLER_REJECTION="Intent Handler function processing the raised intent threw an error or rejected the promise it returned"}(ke||(ke={}));const Oe=new class{_fdc3;_decoders=Pe;_errors={intents:ke};get fdc3(){return this._fdc3||(this._fdc3=(new class{fdc3ToDesktopDefinitionType={web:"window",native:"exe",citrix:"citrix",onlineNative:"clickonce",other:"window"};toApi(){return{isFdc3Definition:this.isFdc3Definition.bind(this),parseToBrowserBaseAppData:this.parseToBrowserBaseAppData.bind(this),parseToDesktopAppConfig:this.parseToDesktopAppConfig.bind(this)}}isFdc3Definition(e){const t=Ae.run(e);return t.ok?e.appId&&e.details?{isFdc3:!0,version:"2.0"}:e.manifest?{isFdc3:!0,version:"1.2"}:{isFdc3:!1,reason:"The passed definition is not FDC3"}:{isFdc3:!1,reason:Te(t.error)}}parseToBrowserBaseAppData(e){const{isFdc3:t,version:r}=this.isFdc3Definition(e);if(!t)throw new Error("The passed definition is not FDC3");const n=Ae.run(e);if(!n.ok)throw new Error(`Invalid FDC3 ${r} definition. Error: ${Te(n.error)}`);const i=this.getUserPropertiesFromDefinition(e,r),s={url:this.getUrl(e,r)},o={name:e.appId,type:"window",createOptions:s,userProperties:{...i,intents:"1.2"===r?i.intents:this.getIntentsFromV2AppDefinition(e),details:s},title:e.title,version:e.version,icon:this.getIconFromDefinition(e,r),caption:e.description,fdc3:"2.0"===r?{...e,definitionVersion:"2.0"}:void 0},a=e.hostManifests?.ioConnect||e.hostManifests?.Glue42;if(!a)return o;const c=Ie.run(a);if(!c.ok)throw new Error(`Invalid FDC3 ${r} definition. Error: ${Te(c.error)}`);return Object.keys(c.result).length?this.mergeBaseAppDataWithGlueManifest(o,c.result):o}parseToDesktopAppConfig(e){const{isFdc3:t,version:r}=this.isFdc3Definition(e);if(!t)throw new Error("The passed definition is not FDC3");const n=Ae.run(e);if(!n.ok)throw new Error(`Invalid FDC3 ${r} definition. Error: ${Te(n.error)}`);if("1.2"===r){const t=e;return{name:t.appId,type:"window",details:{url:this.getUrl(e,r)},version:t.version,title:t.title,tooltip:t.tooltip,caption:t.description,icon:t.icons?.[0].icon,intents:t.intents,customProperties:{manifestType:t.manifestType,images:t.images,contactEmail:t.contactEmail,supportEmail:t.supportEmail,publisher:t.publisher,icons:t.icons,customConfig:t.customConfig}}}const i=e,s={name:i.appId,type:this.fdc3ToDesktopDefinitionType[i.type],details:i.details,version:i.version,title:i.title,tooltip:i.tooltip,caption:i.description,icon:this.getIconFromDefinition(i,"2.0"),intents:this.getIntentsFromV2AppDefinition(i),fdc3:{...i,definitionVersion:"2.0"}},o=e.hostManifests?.ioConnect||e.hostManifests?.Glue42;if(!o)return s;if("object"!=typeof o||Array.isArray(o))throw new Error(`Invalid '${e.hostManifests.ioConnect?"hostManifests.ioConnect":"hostManifests['Glue42']"}' key`);return this.mergeDesktopConfigWithGlueManifest(s,o)}getUserPropertiesFromDefinition(e,t){return"1.2"===t?Object.fromEntries(Object.entries(e).filter((([e])=>!B.includes(e)))):Object.fromEntries(Object.entries(e).filter((([e])=>!B.includes(e)&&!q.includes(e))))}getUrl(e,t){let r;if("1.2"===t){const t=JSON.parse(e.manifest);r=t.details?.url||t.url}else r=e.details?.url;if(!r||"string"!=typeof r)throw new Error(`Invalid FDC3 ${t} definition. Provide valid 'url' under '${"1.2"===t?"manifest":"details"}' key`);return r}getIntentsFromV2AppDefinition(e){const t=e.interop?.intents?.listensFor;if(t)return Object.entries(t).map((e=>{const[t,r]=e;return{name:t,...r}}))}getIconFromDefinition(e,t){return"1.2"===t?e.icons?.find((e=>e.icon))?.icon||void 0:e.icons?.find((e=>e.src))?.src||void 0}mergeBaseAppDataWithGlueManifest(e,t){let r=e;if(t.details){const n={...e.createOptions,...t.details};r.createOptions=n,r.userProperties.details=n}return Array.isArray(t.intents)&&(r.userProperties.intents=(r.userProperties.intents||[]).concat(t.intents)),r={...r,...t},delete r.details,delete r.intents,r}mergeDesktopConfigWithGlueManifest(e,t){const r=Object.assign({},e,t,{details:{...e.details,...t.details}});return Array.isArray(t.intents)&&(r.intents=(e.intents||[]).concat(t.intents)),r}}).toApi()),this._fdc3}get decoders(){return this._decoders}get errors(){return this._errors}};Oe.fdc3;const Re=Oe.decoders;Oe.errors;const Ne=k().where((e=>e.length>0),"Expected a non-empty string"),De=O().where((e=>e>=0),"Expected a non-negative number"),Fe=$(Ne),Me=j(D("system"),D("windows"),D("appManager"),D("layouts"),D("intents"),D("notifications"),D("channels"),D("extension"),D("themes"),D("prefs"),D("ui")),$e=j(D("openWindow"),D("windowHello"),D("windowAdded"),D("windowRemoved"),D("getBounds"),D("getFrameBounds"),D("getUrl"),D("moveResize"),D("focus"),D("close"),D("getTitle"),D("setTitle"),D("focusChange"),D("getChannel"),D("notifyChannelsChanged")),je=j(D("appHello"),D("appDirectoryStateChange"),D("instanceStarted"),D("instanceStopped"),D("applicationStart"),D("instanceStop"),D("clear")),Le=j(D("layoutAdded"),D("layoutChanged"),D("layoutRemoved"),D("layoutRenamed"),D("get"),D("getAll"),D("export"),D("import"),D("remove"),D("rename"),D("clientSaveRequest"),D("getGlobalPermissionState"),D("checkGlobalActivated"),D("requestGlobalPermission"),D("getDefaultGlobal"),D("setDefaultGlobal"),D("clearDefaultGlobal"),D("updateMetadata")),Be=j(D("raiseNotification"),D("requestPermission"),D("notificationShow"),D("notificationClick"),D("getPermission"),D("list"),D("notificationRaised"),D("notificationClosed"),D("click"),D("clear"),D("clearAll"),D("configure"),D("getConfiguration"),D("configurationChanged"),D("setState"),D("clearOld"),D("activeCountChange"),D("stateChange")),qe=j(D("getEnvironment"),D("getBase"),D("platformShutdown"),D("isFdc3DataWrappingSupported"),D("clientError"),D("systemHello")),He=j(D("top"),D("left"),D("right"),D("bottom")),We=F({top:O(),left:O(),width:De,height:De}),Ue=$(F({top:$(O()),left:$(O()),width:$(De),height:$(De),context:$(N()),relativeTo:$(Ne),relativeDirection:$(He),windowId:$(Ne),layoutComponentId:$(Ne)})),Ve=F({name:Ne,url:Ne,options:Ue}),Ge=F({windowId:$(Ne)}),Ke=F({windowId:Ne,name:Ne}),Je=F({windowId:Ne}),ze=F({windows:M(Ke),isWorkspaceFrame:R()}),Xe=F({windowId:Ne,title:k()}),Qe=F({windowId:Ne,hasFocus:R()}),Ye=F({windowId:Ne,top:$(O()),left:$(O()),width:$(De),height:$(De),relative:$(R())}),Ze=F({windowId:Ne,bounds:F({top:O(),left:O(),width:De,height:De})}),et=F({bounds:F({top:O(),left:O(),width:De,height:De})}),tt=F({windowId:Ne,url:Ne}),rt=N(),nt=F({top:$(O()),left:$(O()),width:$(De),height:$(De)}),it=F({id:Ne,applicationName:Ne}),st=F({flags:k()}),ot=F({flags:k()}),at=F({windowId:Ne,channelsNames:M(Ne)}),ct=F({enabled:R()}),lt=F({url:Ne,top:$(O()),left:$(O()),width:$(De),height:$(De),workspacesSandbox:$(ot),channelSelector:$(ct),iframePermissionsPolicy:$(st)}),ut=F({name:Ne,displayName:$(k()),contexts:$(M(k())),customConfig:$(F())});F({name:Ne,title:$(Ne),version:$(Ne),appId:$(Ne),manifest:Ne,manifestType:Ne,tooltip:$(Ne),description:$(Ne),contactEmail:$(Ne),supportEmail:$(Ne),publisher:$(Ne),images:$(M(F({url:$(Ne)}))),icons:$(M(F({icon:$(Ne)}))),customConfig:N(),intents:$(M(ut))});const dt=F({name:Ne,type:Ne.where((e=>"window"===e),"Expected a value of window"),title:$(Ne),version:$(Ne),customProperties:$(N()),icon:$(k()),caption:$(k()),details:lt,intents:$(M(ut)),hidden:$(R()),fdc3:$(Re.fdc3.v2DefinitionDecoder)}),ht=j(dt,Re.fdc3.v2DefinitionDecoder,Re.fdc3.v1DefinitionDecoder);F({definitions:M(ht),mode:j(D("replace"),D("merge"))});const pt=F({name:Ne}),gt=F({definitions:M(dt)}),ft=F({name:Ne,type:Ne.where((e=>"window"===e),"Expected a value of window"),instances:M(it),userProperties:$(N()),title:$(Ne),version:$(Ne),icon:$(Ne),caption:$(Ne)}),mt=F({name:Ne,type:Ne.where((e=>"window"===e),"Expected a value of window"),userProperties:N(),title:$(Ne),version:$(Ne),icon:$(Ne),caption:$(Ne)}),yt=F({appsAdded:M(mt),appsChanged:M(mt),appsRemoved:M(mt)}),wt=F({apps:M(ft),initialChannelId:$(Ne)}),vt=F({id:Ne}),bt=j(D("Global"),D("Activity"),D("ApplicationDefault"),D("Swimlane"),D("Workspace")),St=j(D("application"),D("activity")),Ct=F({context:$(N()),bounds:We,createArgs:F({name:$(Ne),url:$(Ne),context:$(N())}),windowState:$(Ne),restoreState:$(Ne),instanceId:Ne,isCollapsed:$(R()),isSticky:$(R()),restoreSettings:F({groupId:$(Ne),groupZOrder:$(O())})}),It=F({type:D("window"),componentType:$(St),application:Ne,state:Ct}),xt=F({type:D("window"),config:F({appName:Ne,url:$(Ne),title:$(k()),allowExtract:$(R()),allowReorder:$(R()),showCloseButton:$(R()),isMaximized:$(R())})}),_t=F({type:D("group"),config:N(),children:M(j(xt))}),Et=F({type:D("column"),config:N(),children:M(j(_t,xt,L((()=>Et)),L((()=>At))))}),At=F({type:D("row"),config:N(),children:M(j(Et,_t,xt,L((()=>At))))}),Tt=F({config:N(),context:N(),children:M(j(At,Et,_t,xt))}),Pt=F({type:D("Workspace"),application:$(Ne),state:Tt}),kt=F({bounds:We,instanceId:Ne,selectedWorkspace:De,workspaces:M(Tt),windowState:$(Ne),restoreState:$(Ne),context:$(N())}),Ot=F({type:D("workspaceFrame"),application:Ne,componentType:$(St),state:kt}),Rt=F({name:Ne,type:bt,token:$(Ne),components:M(j(It,Pt,Ot)),context:$(N()),metadata:$(N()),version:$(O())}),Nt=F({name:Ne,context:$(N()),metadata:$(N()),instances:$(M(Ne)),ignoreInstances:$(M(Ne))}),Dt=F({name:Ne,context:$(N()),closeRunningInstance:$(R()),closeMe:$(R()),timeout:$(De)}),Ft=F({name:Ne,type:bt,context:$(N()),metadata:$(N())}),Mt=F({name:Ne,type:bt}),$t=F({layout:Nt}),jt=F({layout:Rt,newName:Ne}),Lt=F({status:Ne}),Bt=F({layout:Rt}),qt=F({layout:Dt}),Ht=F({type:bt}),Wt=F({layouts:M(Rt)}),Ut=j(D("replace"),D("merge")),Vt=F({layouts:M(Rt),mode:Ut,skipManagerRequest:$(R())}),Gt=F({summaries:M(Ft)}),Kt=F({layout:Rt}),Jt=F({layout:$(Rt)}),zt=F({name:Ne}),Xt=j(D("findIntent"),D("getIntents"),D("raiseIntent"),D("raise"),D("filterHandlers")),Qt=F({applicationName:Ne,applicationTitle:$(k()),applicationDescription:$(k()),applicationIcon:$(k()),type:j(D("app"),D("instance")),displayName:$(k()),contextTypes:$(M(Ne)),instanceId:$(k()),instanceTitle:$(k()),resultType:$(k())});F({applicationName:k(),applicationIcon:$(k()),instanceId:$(k())});const Yt=F({intent:Ne,handler:Qt}),Zt=F({name:Ne,handlers:M(Qt)}),er=j(D("startNew"),D("reuse"),F({app:$(Ne),instance:$(Ne)})),tr=F({type:$(Ne),data:$(N())}),rr=M(Zt),nr=F({intents:rr}),ir=F({name:$(Ne),contextType:$(Ne),resultType:$(Ne)}),sr=j(Ne,ir),or=F({filter:$(ir)}),ar=F({intent:Ne,target:$(er),context:$(tr),options:$(Ue),handlers:$(M(Qt)),timeout:$(De),waitUserResponseIndefinitely:$(R()),clearSavedHandler:$(R())}),cr=F({interopInstance:Ne,name:$(Ne)}),lr=F({originApp:cr,intentRequest:$(ar)}),ur=F({name:Ne,waitForAGMReady:R(),id:$(Ne),context:$(N()),top:$(O()),left:$(O()),width:$(De),height:$(De),relativeTo:$(Ne),relativeDirection:$(He),forceChromeTab:$(R()),layoutComponentId:$(Ne),channelId:$(Ne),startReason:lr}),dr=j(Ne,ar),hr=F({enabled:R(),appName:Ne,waitResponseTimeout:O()}),pr=F({intentRequest:ar,resolverConfig:hr}),gr=F({request:ar,handler:Qt,result:N()}),fr=F({title:$(Ne),openResolver:$(R()),timeout:$(De),intent:$(Ne),contextTypes:$(M(Ne)),resultType:$(Ne),applicationNames:$(M(Ne))}),mr=F({handlers:M(Qt)}),yr=F({filterHandlersRequest:fr,resolverConfig:hr}),wr=F({intent:Ne,contextTypes:$(M(Ne)),displayName:$(k()),icon:$(k()),description:$(k()),resultType:$(k())}),vr=j(Ne,wr),br=F({intent:Ne,contextTypes:$(M(Ne)),description:$(Ne),displayName:$(Ne),icon:$(Ne),resultType:$(Ne)}),Sr=F({intents:M(br)}),Cr=e=>Ne.where((t=>e.includes(t)),"Expected a valid channel name"),Ir=F({contextType:$(Ne)}),xr=$(j(Ne,F({name:$(Ne),fdc3:$(R())}))),_r=F({windowId:Fe,channel:Fe}),Er=N().where((e=>"string"==typeof e.type),"Expected a valid FDC3 Context with compulsory 'type' field"),Ar=F({method:Ne,arguments:$(N()),target:$(j(D("all"),D("best")))}),Tr=F({action:k(),title:Ne,icon:$(k()),interop:$(Ar)}),Pr=j(D("Active"),D("Acknowledged"),D("Seen"),D("Closed"),D("Stale"),D("Snoozed"),D("Processing")),kr=F({count:O()}),Or=F({badge:$(k()),body:$(k()),data:$(N()),dir:$(j(D("auto"),D("ltr"),D("rtl"))),icon:$(k()),image:$(k()),lang:$(k()),renotify:$(R()),requireInteraction:$(R()),silent:$(R()),tag:$(k()),timestamp:$(De),vibrate:$(M(O()))}),Rr=F({title:Ne,clickInterop:$(Ar),actions:$(M(Tr)),focusPlatformOnDefaultClick:$(R()),badge:$(k()),body:$(k()),data:$(N()),dir:$(j(D("auto"),D("ltr"),D("rtl"))),icon:$(k()),image:$(k()),lang:$(k()),renotify:$(R()),requireInteraction:$(R()),silent:$(R()),tag:$(k()),timestamp:$(De),vibrate:$(M(O())),severity:$(j(D("Low"),D("None"),D("Medium"),D("High"),D("Critical"))),showToast:$(R()),showInPanel:$(R()),state:$(Pr)}),Nr=F({id:Ne,state:Pr});F().where((e=>!e.fdc3||"string"==typeof e.fdc3.type),"Expected a valid FDC3 Context with compulsory 'type' field");const Dr=F({color:$(Ne),icon:$(Ne),name:$(Ne),glyph:$(Ne)}),Fr=F({id:Ne,displayMetadata:$(Dr)}),Mr=F({color:Ne,fdc3:$(Fr)}),$r=F({name:Ne,meta:Mr,data:$(F())}),jr=F({name:Ne}),Lr=F({name:Ne,read:R(),write:R(),windowId:$(Ne)}),Br=F({name:Ne,read:R(),write:R(),windowId:Ne}),qr=F({config:Br}),Hr=F({channels:M(Lr)}),Wr=F({windowId:Ne}),Ur=F({read:R(),write:R(),windowId:$(Ne)}),Vr=F({restrictions:Ur}),Gr=F({settings:Rr,id:Ne}),Kr=F({settings:Rr}),Jr=F({permissionGranted:R()}),zr=F({permission:j(D("default"),D("granted"),D("denied"))}),Xr=F({definition:Or,action:$(k()),id:$(Ne)}),Qr=F({allowed:$(M(Ne)),blocked:$(M(Ne))}),Yr=F({enable:$(R()),enableToasts:$(R()),sourceFilter:$(Qr)}),Zr=F({configuration:Yr}),en=F({configuration:F({enable:R(),enableToasts:R(),sourceFilter:F({allowed:M(Ne),blocked:M(Ne)})})}),tn=F({layoutType:j(D("Global"),D("Workspace")),layoutName:Ne,context:$(N())}),rn=F({windowContext:$(N())}),nn=F({state:j(D("prompt"),D("denied"),D("granted"))}),sn=F({isAvailable:R()}),on=F({itemId:Ne}),an=F({isSupported:R()}),cn=F({operation:Ne}),ln=F({bounds:We}),un=F({displayName:Ne,name:Ne}),dn=F({theme:un}),hn=F({themes:M(un)}),pn=F({name:Ne}),gn=F({id:Ne,title:Ne,clickInterop:$(Ar),actions:$(M(Tr)),focusPlatformOnDefaultClick:$(R()),badge:$(k()),body:$(k()),data:$(N()),dir:$(j(D("auto"),D("ltr"),D("rtl"))),icon:$(k()),image:$(k()),lang:$(k()),renotify:$(R()),requireInteraction:$(R()),silent:$(R()),tag:$(k()),timestamp:$(De),vibrate:$(M(O())),severity:$(j(D("Low"),D("None"),D("Medium"),D("High"),D("Critical"))),showToast:$(R()),showInPanel:$(R()),state:$(Pr)}),fn=F({notification:gn}),mn=F({notifications:M(gn)}),yn=F({id:Ne}),wn=F({channel:Ne}),vn=F({windowIds:M(Ne)}),bn=j(D("addChannel"),D("getMyChannel"),D("getWindowIdsOnChannel"),D("getWindowIdsWithChannels"),D("joinChannel"),D("restrict"),D("getRestrictions"),D("restrictAll"),D("notifyChannelsChanged"),D("leaveChannel"),D("getMode")),Sn=F({mode:j(D("single"),D("multi"))}),Cn=F({channel:$(Ne)}),In=F({application:$(Ne),channels:$(M(Ne)),windowIds:$(M(Ne))}),xn=F({filter:$(In)}),_n=F({windowIdsWithChannels:M(F({application:Ne,channel:$(Ne),windowId:Ne}))}),En=$(N()),An=$(F({top:$(O()),left:$(O()),width:$(De),height:$(De),relativeTo:$(Ne),relativeDirection:$(He),waitForAGMReady:$(R()),channelId:$(Ne),reuseId:$(Ne),originIntentRequest:$(ar)})),Tn=F({channel:Ne,windowId:Ne}),Pn=F({windowId:Ne,channelName:$(Ne)}),kn=F({windowId:Ne,channelNames:M(Ne)}),On=F({channel:$(Ne)}),Rn=j(D("clear"),D("clearAll"),D("get"),D("getAll"),D("set"),D("update"),D("prefsChanged"),D("prefsHello")),Nn=F({app:Ne,data:F(),lastUpdate:$(Ne)}),Dn=F({app:Ne}),Fn=F({prefs:Nn}),Mn=F({all:M(Nn)}),$n=F({interopId:Ne}),jn=F({app:Ne,data:F()}),Ln=F({platform:F({app:Ne}),validNonExistentApps:$(M(Ne))}),Bn=F({message:Ne}),qn=F({isClientErrorOperationSupported:R()}),Hn={openWindow:{name:"openWindow",dataDecoder:Ve,resultDecoder:Ke},windowHello:{name:"windowHello",dataDecoder:Ge,resultDecoder:ze},windowAdded:{name:"windowAdded",dataDecoder:Ke},windowRemoved:{name:"windowRemoved",dataDecoder:Je},getBounds:{name:"getBounds",dataDecoder:Je,resultDecoder:Ze},getFrameBounds:{name:"getFrameBounds",dataDecoder:Je,resultDecoder:et},getUrl:{name:"getUrl",dataDecoder:Je,resultDecoder:tt},moveResize:{name:"moveResize",dataDecoder:Ye},focus:{name:"focus",dataDecoder:Je},close:{name:"close",dataDecoder:Je},getTitle:{name:"getTitle",dataDecoder:Je,resultDecoder:Xe},setTitle:{name:"setTitle",dataDecoder:Xe},focusChange:{name:"focusChange",dataDecoder:Qe},getChannel:{name:"getChannel",dataDecoder:Je,resultDecoder:On},notifyChannelsChanged:{name:"notifyChannelsChanged",dataDecoder:kn}};function Wn(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function Un(e){if(e&&e.errorHandling&&"function"!=typeof e.errorHandling&&"log"!==e.errorHandling&&"silent"!==e.errorHandling&&"throw"!==e.errorHandling)throw new Error('Invalid options passed to createRegistry. Prop errorHandling should be ["log" | "silent" | "throw" | (err) => void], but '+typeof e.errorHandling+" was passed");var t=e&&"function"==typeof e.errorHandling&&e.errorHandling,r={};function n(r,n){var i=r instanceof Error?r:new Error(r);if(t)t(i);else{var s='[ERROR] callback-registry: User callback for key "'+n+'" failed: '+i.stack;if(e)switch(e.errorHandling){case"log":return console.error(s);case"silent":return;case"throw":throw new Error(s)}console.error(s)}}return{add:function(e,t,i){var s=r[e];return s||(s=[],r[e]=s),s.push(t),i&&setTimeout((function(){i.forEach((function(i){var s;if(null===(s=r[e])||void 0===s?void 0:s.includes(t))try{Array.isArray(i)?t.apply(void 0,i):t.apply(void 0,[i])}catch(t){n(t,e)}}))}),0),function(){var n=r[e];n&&(n=n.reduce((function(e,r,n){return r===t&&e.length===n||e.push(r),e}),[]),0===n.length?delete r[e]:r[e]=n)}},execute:function(e){for(var t=[],i=1;i<arguments.length;i++)t[i-1]=arguments[i];var s=r[e];if(!s||0===s.length)return[];var o=[];return s.forEach((function(r){try{var i=r.apply(void 0,t);o.push(i)}catch(t){o.push(void 0),n(t,e)}})),o},clear:function(){r={}},clearKey:function(e){r[e]&&delete r[e]}}}Un.default=Un;var Vn=Wn(Un);class Gn{_id;_name;_bridge;registry=Vn();myCtxKey;ctxUnsubscribe;me;constructor(e,t,r){this._id=e,this._name=t,this._bridge=r,this.myCtxKey=`___window___${this.id}`}get id(){return this._id.slice()}get name(){return this._name.slice()}clean(){this.ctxUnsubscribe&&this.ctxUnsubscribe()}processSelfFocusEvent(e){this.me.isFocused=e,this.registry.execute("focus-change",this.me)}processChannelsChangedEvent(e){this.registry.execute("channels-changed",e)}async toApi(){return this.ctxUnsubscribe=await this._bridge.contextLib.subscribe(this.myCtxKey,(e=>this.registry.execute("context-updated",e))),this.me={id:this.id,name:this.name,isFocused:!1,getURL:this.getURL.bind(this),moveResize:this.moveResize.bind(this),resizeTo:this.resizeTo.bind(this),moveTo:this.moveTo.bind(this),focus:this.focus.bind(this),close:this.close.bind(this),getTitle:this.getTitle.bind(this),setTitle:this.setTitle.bind(this),getBounds:this.getBounds.bind(this),getContext:this.getContext.bind(this),updateContext:this.updateContext.bind(this),setContext:this.setContext.bind(this),onContextUpdated:this.onContextUpdated.bind(this),onFocusChanged:this.onFocusChanged.bind(this),getChannel:this.getChannel.bind(this),onChannelsChanged:this.onChannelsChanged.bind(this)},this.me}async getURL(){return(await this._bridge.send("windows",Hn.getUrl,{windowId:this.id})).url}onFocusChanged(e){return"function"!=typeof e?y.raiseError("Cannot subscribe to context changes, because the provided callback is not a function!"):this.registry.add("focus-change",e)}async moveResize(e){const t=m(nt,e),r=Object.assign({},t,{windowId:this.id,relative:!1});return await this._bridge.send("windows",Hn.moveResize,r),this.me}async resizeTo(e,t){if(void 0===e&&void 0===t)return this.me;void 0!==e&&m(De,e),void 0!==t&&m(De,t);const r=Object.assign({},{width:e,height:t},{windowId:this.id,relative:!0});return await this._bridge.send("windows",Hn.moveResize,r),this.me}async moveTo(e,t){if(void 0===e&&void 0===t)return this.me;void 0!==e&&m(O(),e),void 0!==t&&m(O(),t);const r=Object.assign({},{top:e,left:t},{windowId:this.id,relative:!0});return await this._bridge.send("windows",Hn.moveResize,r),this.me}async focus(){return"Platform"===this.name?window.open(void 0,this.id):await this._bridge.send("windows",Hn.focus,{windowId:this.id}),this.me}async close(){return await this._bridge.send("windows",Hn.close,{windowId:this.id}),this.me}async getTitle(){return(await this._bridge.send("windows",Hn.getTitle,{windowId:this.id})).title}async setTitle(e){const t=m(Ne,e);return await this._bridge.send("windows",Hn.setTitle,{windowId:this.id,title:t}),this.me}async getBounds(){return(await this._bridge.send("windows",Hn.getBounds,{windowId:this.id})).bounds}async getContext(){const e=await this._bridge.contextLib.get(this.myCtxKey),{___io___:t,...r}=e;return r}async updateContext(e){const t=m(rt,e);return await this._bridge.contextLib.update(this.myCtxKey,t),this.me}async setContext(e){const t=m(rt,e),r=await this._bridge.contextLib.get(this.myCtxKey),n=r.___io___?{...t,___io___:r.___io___}:t;return await this._bridge.contextLib.set(this.myCtxKey,n),this.me}onContextUpdated(e){if("function"!=typeof e)return y.raiseError("Cannot subscribe to context changes, because the provided callback is not a function!");return this.registry.add("context-updated",(t=>{const{___io___:r,...n}=t;e(n,this.me)}))}async getChannel(){return(await this._bridge.send("windows",Hn.getChannel,{windowId:this.id},void 0,{includeOperationCheck:!0})).channel}onChannelsChanged(e){return this.registry.add("channels-changed",e)}}const Kn={operationCheck:{name:"operationCheck",dataDecoder:cn,resultDecoder:an},getWorkspaceWindowFrameBounds:{name:"getWorkspaceWindowFrameBounds",resultDecoder:ln,dataDecoder:on}},Jn=(e,t,r)=>new Promise(((n,i)=>{let s=!0;const o=setTimeout((()=>{if(!s)return;s=!1;i(r||`Promise timeout hit: ${t}`)}),t);e().then((e=>{s&&(s=!1,clearTimeout(o),n(e))})).catch((e=>{s&&(s=!1,clearTimeout(o),i(e))}))})),zn=(e,t,r)=>new Promise(((n,i)=>{const s=setTimeout((()=>{i(r||`Promise timeout hit: ${t}`)}),t);new Promise(e).then((e=>{clearTimeout(s),n(e)})).catch((e=>{clearTimeout(s),i(e)}))}));const Xn="T42.Web.Platform.Control",Qn="T42.Web.Platform.Stream",Yn="T42.Web.Client.Control",Zn="T42.Core.Plus.Themes.Stream";class ei{coreGlue;communicationId;platformMethodTimeoutMs=1e4;controllers;sub;running;constructor(e,t){this.coreGlue=e,this.communicationId=t}get contextLib(){return this.coreGlue.contexts}get interopInstance(){return this.coreGlue.interop.instance.instance}async stop(){this.running=!1,this.sub.close(),await this.coreGlue.interop.unregister(Yn)}async start(e){this.running=!0,this.controllers=e,await Promise.all([this.checkWaitMethod(Xn),this.checkWaitMethod(Qn)]);const t=this.communicationId,[r]=await Promise.all([this.coreGlue.interop.subscribe(Qn,t?{target:{instance:this.communicationId}}:void 0),this.coreGlue.interop.registerAsync(Yn,((e,t,r,n)=>this.passMessageController(e,r,n)))]);this.sub=r,this.sub.onData((e=>this.passMessageController(e.data)))}getInteropInstance(e){const t=this.coreGlue.interop.servers().find((t=>t.windowId&&t.windowId===e));return{application:t?.application,applicationName:t?.applicationName,peerId:t?.peerId,instance:t?.instance,windowId:t?.windowId}}async send(e,t,r,n,i){if(t.dataDecoder)try{t.dataDecoder.runWithException(r)}catch(e){return y.raiseError(`Unexpected Web->Platform outgoing validation error: ${e.message}, for operation: ${t.name} and input: ${JSON.stringify(e.input)}`)}if(!(!i?.includeOperationCheck||(await this.checkOperationSupported(e,t)).isSupported))return y.raiseError(`Cannot complete operation: ${t.name} for domain: ${e} because this client is connected to a platform which does not support it`);try{const i=await this.transmitMessage(e,t,r,n);return t.resultDecoder&&t.resultDecoder.runWithException(i),i}catch(e){return e?.kind?y.raiseError(`Unexpected Web<-Platform incoming validation error: ${e.message}, for operation: ${t.name} and input: ${JSON.stringify(e.input)}`):y.raiseError(e)}}async createNotificationsSteam(){return this.coreGlue.interop.methods().some((e=>e.name===Zn))?this.coreGlue.interop.subscribe(Zn,this.communicationId?{target:{instance:this.communicationId}}:void 0):y.raiseError("Cannot subscribe to theme changes, because the underlying interop stream does not exist. Most likely this is the case when this client is not connected to Core Plus.")}async checkOperationSupported(e,t){try{return await this.send(e,Kn.operationCheck,{operation:t.name})}catch(e){return{isSupported:!1}}}checkWaitMethod(e){return zn((t=>{if(this.coreGlue.interop.methods().some((t=>{const r=t.name===e,n=!this.communicationId||t.getServers().some((e=>e.instance===this.communicationId));return r&&n})))return t();const r=this.coreGlue.interop.serverMethodAdded((n=>{const i=n.method,s=n.server,o=!this.communicationId||s.instance===this.communicationId;i.name===e&&o&&(r(),t())}))}),this.platformMethodTimeoutMs,`Cannot initiate Glue Web, because a system method's discovery timed out: ${e}`)}passMessageController(e,t,r){const n=Me.run(e.domain);if(!n.ok)return void(r&&r(`Cannot execute this client control, because of domain validation error: ${JSON.stringify(n.error)}`));const i=n.result;this.controllers[i].handleBridgeMessage(e).then((e=>{t&&t(e)})).catch((e=>{r&&r(e),console.warn(e)}))}async transmitMessage(e,t,r,n){const i={domain:e,data:r,operation:t.name};let s;const o=`Internal Platform Communication Error. Attempted operation: ${JSON.stringify(t.name)} with data: ${JSON.stringify(r)}. `,a=this.communicationId;try{if(!this.running)throw new Error("Cannot send a control message, because the platform shut down");if(s=await this.coreGlue.interop.invoke(Xn,i,a?{instance:this.communicationId}:void 0,n),!s)throw new Error("Received unsupported result from the platform - empty result");if(!Array.isArray(s.all_return_values)||0===s.all_return_values.length)throw new Error("Received unsupported result from the platform - empty values collection")}catch(e){if(e&&e.all_errors&&e.all_errors.length){const t=e.all_errors[0].message;throw new Error(`${o} -> Inner message: ${t}`)}throw new Error(`${o} -> Inner message: ${e.message}`)}return s.all_return_values[0].returned}}const ti={appHello:{name:"appHello",dataDecoder:Ge,resultDecoder:wt},appDirectoryStateChange:{name:"appDirectoryStateChange",dataDecoder:yt},instanceStarted:{name:"instanceStarted",dataDecoder:it},instanceStopped:{name:"instanceStopped",dataDecoder:it},applicationStart:{name:"applicationStart",dataDecoder:ur,resultDecoder:it},instanceStop:{name:"instanceStop",dataDecoder:vt},import:{name:"import"},remove:{name:"remove",dataDecoder:pt},export:{name:"export",resultDecoder:gt},clear:{name:"clear"}};class ri{me;baseApplicationsTimeoutMS=6e4;appImportTimeoutMS=20;registry=Vn();ioc;bridge;publicWindowId;applications=[];instances=[];platformRegistration;logger;channelsController;sessionController;interop;handlePlatformShutdown(){this.registry.clear(),this.applications=[],this.instances=[],delete this.me}async start(e,t){this.logger=e.logger.subLogger("appManger.controller.web"),this.logger.trace("starting the web appManager controller"),this.publicWindowId=t.publicWindowId,this.addOperationsExecutors(),this.ioc=t,this.bridge=t.bridge,this.channelsController=t.channelsController,this.sessionController=t.sessionController,this.interop=e.interop,this.platformRegistration=this.registerWithPlatform(),await this.platformRegistration,this.logger.trace("registration with the platform successful, attaching the appManager property to glue and returning");const r=this.toApi();e.appManager=r}async handleBridgeMessage(e){await this.platformRegistration;const t=m(je,e.operation),r=ti[t];if(!r.execute)return;let n=e.data;return r.dataDecoder&&(n=m(r.dataDecoder,e.data)),await r.execute(n)}onInstanceStarted(e){return"function"!=typeof e?y.raiseError("onInstanceStarted requires a single argument of type function"):this.registry.add("instance-started",e,this.instances)}onInstanceStopped(e){return"function"!=typeof e?y.raiseError("onInstanceStopped requires a single argument of type function"):this.registry.add("instance-stopped",e)}async startApplication(e,t,r){const n=await this.channelsController.all();if(r?.channelId&&!n.includes(r.channelId))return y.raiseError(`The channel with name "${r.channelId}" doesn't exist!`);const i={name:e,waitForAGMReady:r?.waitForAGMReady??!0,context:t,top:r?.top,left:r?.left,width:r?.width,height:r?.height,relativeTo:r?.relativeTo,relativeDirection:r?.relativeDirection,id:r?.reuseId,forceChromeTab:r?.forceTab,layoutComponentId:r?.layoutComponentId,channelId:r?.channelId,startReason:{originApp:{name:this.me?.application.name,interopInstance:this.interop.instance.instance}}};r?.originIntentRequest&&(i.startReason.intentRequest=r.originIntentRequest);const s=await this.bridge.send("appManager",ti.applicationStart,i),o=this.applications.find((e=>e.name===s.applicationName));return this.ioc.buildInstance(s,o)}getApplication(e){const t=m(Ne,e);return this.applications.find((e=>e.name===t))}getInstances(){return this.instances.slice()}onAppAdded(e){return"function"!=typeof e?y.raiseError("onAppAdded requires a single argument of type function"):this.registry.add("application-added",e,this.applications)}onAppRemoved(e){return"function"!=typeof e?y.raiseError("onAppRemoved requires a single argument of type function"):this.registry.add("application-removed",e)}toApi(){return{myInstance:this.me,inMemory:{import:this.importApps.bind(this),remove:this.remove.bind(this),export:this.exportApps.bind(this),clear:this.clear.bind(this)},application:this.getApplication.bind(this),applications:this.getApplications.bind(this),instances:this.getInstances.bind(this),onAppAdded:this.onAppAdded.bind(this),onAppChanged:this.onAppChanged.bind(this),onAppRemoved:this.onAppRemoved.bind(this),onInstanceStarted:this.onInstanceStarted.bind(this),onInstanceStopped:this.onInstanceStopped.bind(this)}}addOperationsExecutors(){ti.appDirectoryStateChange.execute=this.handleAppDirectoryStateChange.bind(this),ti.instanceStarted.execute=this.handleInstanceStartedMessage.bind(this),ti.instanceStopped.execute=this.handleInstanceStoppedMessage.bind(this)}async handleAppDirectoryStateChange(e){e.appsAdded.forEach(this.handleApplicationAddedMessage.bind(this)),e.appsChanged.forEach(this.handleApplicationChangedMessage.bind(this)),e.appsRemoved.forEach(this.handleApplicationRemovedMessage.bind(this))}onAppChanged(e){return"function"!=typeof e?y.raiseError("onAppChanged requires a single argument of type function"):this.registry.add("application-changed",e)}async handleApplicationAddedMessage(e){if(this.applications.some((t=>t.name===e.name)))return;const t=await this.ioc.buildApplication(e,[]),r=this.instances.filter((e=>e.application.name===t.name));t.instances.push(...r),this.applications.push(t),this.registry.execute("application-added",t)}async handleApplicationRemovedMessage(e){const t=this.applications.findIndex((t=>t.name===e.name));if(t<0)return;const r=this.applications[t];this.applications.splice(t,1),this.registry.execute("application-removed",r)}async handleApplicationChangedMessage(e){const t=this.applications.find((t=>t.name===e.name));if(!t)return this.handleApplicationAddedMessage(e);t.title=e.title,t.version=e.version,t.icon=e.icon,t.caption=e.caption,t.userProperties=e.userProperties,this.registry.execute("application-changed",t)}async handleInstanceStartedMessage(e){if(this.instances.some((t=>t.id===e.id)))return;const t=this.applications.find((t=>t.name===e.applicationName));if(!t)return y.raiseError(`Cannot add instance: ${e.id}, because there is no application definition associated with it`);const r=this.ioc.buildInstance(e,t);this.instances.push(r),t.instances.push(r),this.registry.execute("instance-started",r)}async handleInstanceStoppedMessage(e){const t=this.instances.find((t=>t.id===e.id));if(t){const t=this.instances.findIndex((t=>t.id===e.id));this.instances.splice(t,1)}const r=this.applications.find((t=>t.instances.some((t=>t.id===e.id))));if(r){const t=r.instances.findIndex((t=>t.id===e.id));r.instances.splice(t,1)}t&&this.registry.execute("instance-stopped",t)}async importApps(e,t="replace"){if(m(Ut,t),!Array.isArray(e))return y.raiseError("Import must be called with an array of definitions");if(e.length>1e4)return y.raiseError("Cannot import more than 10000 app definitions in Glue42 Core.");const r=e.reduce(((e,t)=>{const r=ht.run(t);return r.ok?e.valid.push(t):e.invalid.push({app:t?.name,error:JSON.stringify(r.error)}),e}),{valid:[],invalid:[]}),n=this.baseApplicationsTimeoutMS+this.appImportTimeoutMS*r.valid.length;return await this.bridge.send("appManager",ti.import,{definitions:r.valid,mode:t},{methodResponseTimeoutMs:n}),{imported:r.valid.map((e=>e.name)),errors:r.invalid}}async remove(e){m(Ne,e),await this.bridge.send("appManager",ti.remove,{name:e},{methodResponseTimeoutMs:this.baseApplicationsTimeoutMS})}async clear(){await this.bridge.send("appManager",ti.clear,void 0,{methodResponseTimeoutMs:this.baseApplicationsTimeoutMS})}async exportApps(){return(await this.bridge.send("appManager",ti.export,void 0,{methodResponseTimeoutMs:this.baseApplicationsTimeoutMS})).definitions}getApplications(){return this.applications.slice()}async joinInitialChannel(e){try{await this.channelsController.join(e)}catch(t){this.logger.warn(`Application instance ${this.me} was unable to join the ${e} channel. Reason: ${JSON.stringify(t)}`)}}async registerWithPlatform(){const e=await this.bridge.send("appManager",ti.appHello,{windowId:this.publicWindowId},{methodResponseTimeoutMs:this.baseApplicationsTimeoutMS});this.logger.trace("the platform responded to the hello message with a full list o