@elliemae/ssf-host 2.35.0 → 2.35.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/host.js +63 -25
- package/dist/esm/host.js +63 -25
- package/dist/public/callchain-host.html +1 -1
- package/dist/public/callchain-intermediate.html +1 -1
- package/dist/public/e2e-host.html +1 -1
- package/dist/public/e2e-index.html +1 -1
- package/dist/public/index.html +1 -1
- package/dist/public/js/emuiSsfHost.cc299d33bc6c79fa47d8.js +3 -0
- package/dist/public/js/emuiSsfHost.cc299d33bc6c79fa47d8.js.br +0 -0
- package/dist/public/js/emuiSsfHost.cc299d33bc6c79fa47d8.js.gz +0 -0
- package/dist/public/js/emuiSsfHost.cc299d33bc6c79fa47d8.js.map +1 -0
- package/dist/public/popup-focus-host.html +1 -1
- package/dist/public/v1-guest-v2-host.html +1 -1
- package/dist/public/v2-host-v1-guest.html +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/dist/umd/index.js +1 -1
- package/dist/umd/index.js.br +0 -0
- package/dist/umd/index.js.gz +0 -0
- package/dist/umd/index.js.map +1 -1
- package/package.json +3 -3
- package/dist/public/js/emuiSsfHost.a710a0562fe60b877957.js +0 -3
- package/dist/public/js/emuiSsfHost.a710a0562fe60b877957.js.br +0 -0
- package/dist/public/js/emuiSsfHost.a710a0562fe60b877957.js.gz +0 -0
- package/dist/public/js/emuiSsfHost.a710a0562fe60b877957.js.map +0 -1
package/dist/umd/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
(function(k,S){typeof exports=="object"&&typeof module=="object"?module.exports=S():typeof define=="function"&&define.amd?define([],S):typeof exports=="object"?exports.ice=S():(k.ice=k.ice||{},k.ice.host=S())})(globalThis,()=>(()=>{"use strict";const O={};O.d=(n,e)=>{for(var t in e)O.o(e,t)&&!O.o(n,t)&&Object.defineProperty(n,t,{enumerable:!0,get:e[t]})},O.o=(n,e)=>Object.hasOwn(n,e),O.r=n=>{Object.defineProperty(n,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(n,"__esModule",{value:!0})};let k={};O.r(k),O.d(k,{Event:()=>S,Guest:()=>x,IFrameSandboxValues:()=>j,OnDuplicate:()=>M,OpenMode:()=>p,SANDBOX_DEFAULT:()=>J,SSFHost:()=>Ie,ScriptingObject:()=>P});class S{name;objectId;id;constructor(e){const{name:t,objectId:i}=e;if(!t)throw new Error("Event name is required");if(!i)throw new Error("Scripting object id is required");this.objectId=i,this.name=t,this.id=`${this.objectId}.${this.name}`.toLowerCase()}}class R{static[Symbol.hasInstance](e){return typeof e=="object"&&e!==null&&"getType"in e&&typeof e.getType=="function"&&e.getType()==="ProxyEvent"}#t;objectId;name;id;getType(){return"ProxyEvent"}constructor(e){const{name:t,objectId:i,eventSrc:s}=e;if(!t)throw new Error("Event name is required");if(!i)throw new Error("Scripting object id is required");if(!s)throw new Error("Event source is required");this.objectId=i,this.name=t,this.#t=s,this.id=`${this.objectId}.${this.name}`.toLowerCase()}subscribe=e=>this.#t.subscribe({eventId:this.id,callback:e});unsubscribe=e=>{this.#t.unsubscribe({eventId:this.id,token:e})}}const Y=n=>n instanceof S,Te=(n,e)=>`${n.toLowerCase()}.${e.toLowerCase()}`,K="function",Q=(n,e)=>typeof n===K&&!!e&&!e.startsWith("_");class P{#t;#i="Object";constructor(e,t){this.#t=e,this.#i=t||this.#i}get id(){return this.#t}get objectType(){return this.#i}_toJSON=()=>{const e=[],t=[];return Object.keys(this).forEach(i=>{const s=this[i];Y(s)?t.push(i):Q(s,i)&&e.push(i)}),{objectId:this.#t,objectType:this.#i,functions:e,events:t}};_dispose=()=>{};dispose=()=>{}}const _="module";var $e=null,M=(n=>(n.THROW="throw",n.IGNORE="ignore",n))(M||{});class Z{#t=e=>e.trim().toLowerCase();#i=new Map;#e=new Map;#o=e=>{const{so:t,guestId:i,onDuplicate:s="throw",securityContext:r}=e,o=this.#t(t.id),c={so:t,guestId:i,securityContext:r},d=this.#e.get(i);if(!d){this.#e.set(i,new Map([[o,c]]));return}if(d.has(o)){if(s==="ignore")return;throw new Error(`Scripting Object ${t.id} already exists for guest ${i}`)}d.set(o,c)};#s=({so:e})=>{if(e._dispose&&typeof e._dispose=="function")try{e._dispose()}catch{}};#r=({objectId:e,guestId:t})=>{if(e===_&&!t)for(const[,s]of this.#e){const r=s.get(e);if(r)return r}const i=t?this.#e.get(t):null;return i?i.get(e)??null:null};#n=({objectId:e,guestId:t}={})=>{if(t){if(!e){const s=this.#e.get(t);s&&s.forEach(this.#s),this.#e.delete(t);return}const i=this.#e.get(t);if(i){const s=i.get(e);s&&this.#s(s),i.delete(e)}}else e&&this.#e.forEach(i=>{const s=i.get(e);s&&this.#s(s),i.delete(e)})};addScriptingObject=(e,t)=>{const{guestId:i,onDuplicate:s="throw",securityContext:r}=t||{};if(!e?.id||!e?._toJSON)throw new Error("Object is not derived from ScriptingObject");const o=this.#t(e.id);if(o===_&&!i)throw new Error("Guest id is required to add Module scripting object");if(i){this.#o({so:e,...t,guestId:i,onDuplicate:s});return}if(this.#i.has(o)){if(s==="ignore")return;throw new Error(`Scripting Object ${e.id} already exists`)}this.#i.set(o,{so:e,guestId:i,securityContext:r})};getObject=(e,t)=>{const i=this.#t(e);let s=this.#r({objectId:i,guestId:t?.id});s=s??this.#i.get(i)??null;const{so:r}=s||{};return r||null};has=(e,t)=>this.getObject(e,t)!==null;listScriptingObjects=e=>{const t=new Set(this.#i.keys()),i=this.#e.get(e);if(i)for(const s of i.keys())t.add(s);return Array.from(t)};removeScriptingObject=(e,t)=>{const i=this.#t(e);if(t)this.#n({objectId:i,guestId:t});else{this.#n({objectId:i});const s=this.#i.get(i);s&&this.#s(s),this.#i.delete(i)}};removeAllScriptingObjects=e=>{e?this.#n({guestId:e}):(this.#i.forEach(this.#s),this.#i.clear())}}var g=(n=>(n.GuestClose="guest:close",n.GuestEventSubscribe="guest:eventSubscribe",n.GuestEventUnsubscribe="guest:eventUnsubscribe",n.GuestFocus="guest:focus",n.GuestReady="guest:ready",n.GuestReadyComplete="guest:readyComplete",n.GuestResize="guest:resize",n.HandShake="handshake",n.HandShakeAck="handshake:ack",n.HostClose="host:close",n.HostConfig="host:config",n.ListObjects="list:objects",n.ObjectEvent="object:event",n.ObjectGet="object:get",n.ObjectInvoke="object:invoke",n))(g||{}),p=(n=>(n.Popup="popup",n.Embed="embed",n))(p||{}),j=(n=>(n.AllowDownloadsWithoutUserActivation="allow-downloads-without-user-activation",n.AllowDownloads="allow-downloads",n.AllowForms="allow-forms",n.AllowModals="allow-modals",n.AllowOrientationLock="allow-orientation-lock",n.AllowPointerLock="allow-pointer-lock",n.AllowPopups="allow-popups",n.AllowPopupsToEscapeSandbox="allow-popups-to-escape-sandbox",n.AllowPresentation="allow-presentation",n.AllowSameOrigin="allow-same-origin",n.AllowScripts="allow-scripts",n.AllowStorageAccessByUserActivation="allow-storage-access-by-user-activation",n.AllowTopNavigation="allow-top-navigation",n.AllowTopNavigationByUserActivation="allow-top-navigation-by-user-activation",n))(j||{});const ee=n=>{if(n==="about:blank")return"*";try{const{origin:e}=new URL(n);return e==="null"||!e?n:e}catch{const{origin:t}=new URL(n,document.baseURI);return t}},te=n=>n.flat(1/0).filter(e=>e!==void 0);function C(n){return typeof n=="function"}const ie=[".ice.com",".elliemae.com",".ellielabs.com",".elliemae.io",".ellieservices.com"],se=["localhost","127.0.0.1"],L=n=>n.split(".").slice(-2).join("."),ne=n=>se.includes(n)||ie.some(e=>n===e.slice(1)||n.endsWith(e)),re=n=>{const e=L(window.location.hostname),t=L(n);return e===t},D=n=>{if(!n)return!1;try{const{hostname:e}=new URL(n,document.baseURI);return ne(e)||re(e)}catch{return!1}},oe=1e3,ce=10,ae=30,de=n=>typeof n!="number"||!Number.isFinite(n)?n===void 0?ce:1:Math.min(ae,Math.max(1,Math.floor(n)));class x{id;title;url;searchParams;domElement;window;openMode;origin;initialized=!1;ready=!1;capabilities;#t;#i;#e;#o;#s=null;#r=null;#n=null;constructor(e){const{guestId:t,domElement:i=null,title:s,url:r,window:o,searchParams:c={},openMode:d=p.Embed,remoting:a,perfTracker:l,handshakeToken:h,handshakeRetries:E}=e;this.id=t,this.title=s,this.url=r,this.origin=ee(r),this.searchParams=c,this.domElement=i,this.window=o,this.openMode=d,this.capabilities={},this.#i=l,this.#t=a,this.#e=h,this.#o=de(E)}dispose=()=>{this.#a(!1);let e=!1;if(this.openMode===p.Popup)try{e=!this.window.closed}catch{e=!1}if(e)try{this.window.document,this.window.close()}catch{this.#t.send({targetWin:this.window,targetOrigin:this.origin,messageType:g.HostClose,messageBody:{}})}else this.domElement?.remove?.();this.#t.removeSender({origin:this.origin,window:this.window})};getInfo=()=>({guestId:this.id,guestTitle:this.title,guestUrl:this.url});#a=e=>{this.#s&&(clearInterval(this.#s),this.#s=null),this.#r&&(this.#t.unlisten({messageType:g.HandShakeAck,callback:this.#r}),this.#r=null);const t=this.#n;this.#n=null,t&&e!==void 0&&t(e)};#c=()=>{this.#n&&this.#t.send({targetWin:this.window,targetOrigin:this.origin,messageType:g.HandShake,messageBody:this.#e?{handshakeToken:this.#e}:{}})};handShake=()=>(this.#a(!1),this.openMode!==p.Popup?Promise.resolve(!1):new Promise(e=>{let t=0;this.#n=e;const i=()=>{this.#n&&this.#a(!0)};this.#r=i,this.#c(),t=1,this.#s=setInterval(()=>{if(this.#n){if(t>=this.#o){this.#a(!1);return}this.#c(),t+=1}},oe),this.#t.listen({messageType:g.HandShakeAck,callback:i})}));init=()=>{this.#t.addSender({origin:this.origin,window:this.window}),this.openMode===p.Popup&&this.handShake().catch(()=>{})};dispatchEvent=(e,t)=>{let i;if(this.#i.enabled){const s=`ScriptingObject.Event.${e.object.objectId}.${e.eventName}`;i=this.#i.start(s,{appId:this.id,appUrl:this.url})}return this.#t.invoke({targetWin:this.window,targetOrigin:this.origin,messageType:g.ObjectEvent,messageBody:e,responseTimeoutMs:t}).finally(()=>{i&&this.#i.end(i,{appId:this.id,appUrl:this.url})})};send=e=>{this.#t.send({targetWin:this.window,targetOrigin:this.origin,...e})}}const q={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};let G;const le=new Uint8Array(16);function he(){if(!G&&(G=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!G))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return G(le)}var ue;const f=[];for(let n=0;n<256;++n)f.push((n+256).toString(16).slice(1));function N(n,e=0){return f[n[e+0]]+f[n[e+1]]+f[n[e+2]]+f[n[e+3]]+"-"+f[n[e+4]]+f[n[e+5]]+"-"+f[n[e+6]]+f[n[e+7]]+"-"+f[n[e+8]]+f[n[e+9]]+"-"+f[n[e+10]]+f[n[e+11]]+f[n[e+12]]+f[n[e+13]]+f[n[e+14]]+f[n[e+15]]}function Ge(n,e=0){const t=N(n,e);if(!ue(t))throw TypeError("Stringified UUID is invalid");return t}const Pe=null;function ge(n,e,t){if(q.randomUUID&&!e&&!n)return q.randomUUID();n=n||{};const i=n.random||(n.rng||he)();if(i[6]=i[6]&15|64,i[8]=i[8]&63|128,e){t=t||0;for(let s=0;s<16;++s)e[t+s]=i[s];return e}return N(i)}const U=ge,F="elli:remoting",W="elli:remoting:response",z="elli:remoting:exception",$=({messageType:n,messageBody:e,requestId:t,onewayMsg:i=!1})=>({requestId:t??(i?null:U()),source:F,type:n,body:e}),Ue=n=>{const{targetWin:e,targetOrigin:t,messageType:i,messageBody:s}=n,r=$({messageType:i,messageBody:s});e.postMessage(r,t)};class pe{#t;#i;#e=new Map;#o=new Map;#s=null;#r=null;#n=new Map;constructor(e,t){if(!e)throw new Error("logger is required");if(!t)throw new Error("correlationId is required");this.#t=t,this.#i=e}#a=()=>{this.#s=null;const e=Date.now(),t=[];let i=null;if(this.#o.forEach((s,r)=>{const{requestId:o,cancelTime:c}=s;c&&c<=e?(this.#i.debug(`Detected response timeout for requestId: ${o}...`),t.push(r),s.resolve(void 0)):c&&(i=i===null?c:Math.min(i,c))}),t.forEach(s=>{this.#o.delete(s)}),i!==null){const s=Math.max(i-Date.now(),0);this.#c(s)}};#c=e=>{this.#s===null&&(this.#s=window.setTimeout(this.#a,e))};#m=()=>{this.#s!==null&&(window.clearTimeout(this.#s),this.#s=null)};#d=e=>{const t=this.#o.get(e);return this.#i.debug(`serving requestId: ${e}`),this.#o.delete(e),t};#p=e=>{const{requestId:t}=e;this.#i.debug(`Response received for invocation requestId: ${t}`);const i=this.#d(t);return i?(i.resolve(e.body),!0):(this.#i.debug(`Received response to stale/invalid request with requestId: ${t}`),!1)};#l=e=>{this.#i.debug(`Exception received for invocation (requestId = ${e.requestId})`);const t=this.#d(e.requestId);return t?(t.reject(new Error(e.body)),!0):(this.#i.warn(`Received exception for stale/invalid request (requestId = ${e.requestId})`),!1)};#f=({sourceWin:e,sourceOrigin:t,message:i})=>{this.#i.debug(`Received message of type "${i.type}"`);const s=this.#e.get(i.type);return s?(s.forEach(r=>{this.#i.debug(`Invoking message handler ${r.name}`),r({sourceWin:e,sourceOrigin:t,requestId:i.requestId,type:i.type,body:i.body})}),!0):!1};#h=e=>{if(this.#n.size===0||!e.source)return!1;const t=this.#n.get(e.source);return!t||e?.data?.source!==F?!1:(this.#i.debug(`Remoting: Received message of type "${e.data.type}"`),e.data.type===W?this.#p(e.data):e.data.type===z?this.#l(e.data):this.#f({sourceWin:e.source,sourceOrigin:t,message:e.data}),!0)};addSender=e=>{const{origin:t,window:i}=e;if(!t)throw new Error("origin is required");if(!i)throw new Error("window is required");this.#n.set(i,t)};initialize=e=>{this.#r&&this.#r.removeEventListener("message",this.#h),e.addEventListener("message",this.#h),this.#r=e,this.#i.debug(`initialized remoting id: ${this.#t}`)};close=()=>{this.#r&&(this.#r.removeEventListener("message",this.#h),this.#r=null),this.#m(),this.#o.forEach(({reject:e})=>{e(new Error("Remoting closed"))}),this.#o.clear(),this.#e.clear(),this.#n.clear(),this.#i.debug(`closed remoting id: ${this.#t}`)};invoke=e=>{const{targetWin:t,targetOrigin:i,messageType:s,messageBody:r,responseTimeoutMs:o}=e;return new Promise((c,d)=>{const a=$({messageType:s,messageBody:r});this.#o.set(a.requestId,{requestId:a.requestId,resolve:c,reject:d,cancelTime:o?Date.now()+o:null}),t.postMessage(a,i);const{requestId:l}=a;this.#i.debug(`Posted invocation message of type ${s} requestId: ${l||""}`),o&&(this.#i.debug(`scheduling timeout check for requestId: ${l||""} in ${o} ms`),this.#c(o))})};listen=e=>{const{messageType:t,callback:i}=e,s=this.#e.get(t)||[];s.push(i),this.#e.set(t,s)};unlisten=e=>{const{messageType:t,callback:i}=e,s=this.#e.get(t);if(!s)return;const r=s.indexOf(i);r!==-1&&s.splice(r,1)};send=e=>{const{targetWin:t,targetOrigin:i,messageType:s,messageBody:r}=e,o=$({messageType:s,messageBody:r,onewayMsg:!0});t.postMessage(o,i),this.#i.debug(`Posted one-way message of type "${s}"`)};removeSender=e=>{const{window:t}=e;t&&this.#n.delete(t)};respond=e=>{const{targetWin:t,targetOrigin:i,requestId:s,response:r}=e,o=$({messageType:W,messageBody:r,requestId:s});t.postMessage(o,i),this.#i.debug(`Response sent to caller for invocation requestId: ${s}`)};raiseException=e=>{const{targetWin:t,targetOrigin:i,requestId:s,ex:r}=e,o=r instanceof Error?r.message:r,c=$({messageType:z,messageBody:o,requestId:s});t.postMessage(c,i),this.#i.debug(`Exception sent to caller for invocation. requestId: ${s}`)}}class Re{__TYPE__="Proxy";id;objectType;constructor(e,t){this.id=e,this.objectType=t}}const B=n=>n?.constructor?.name==="Proxy"||n?.constructor?.name==="ScriptingObjectProxy"||n?.__TYPE__==="Proxy",fe=new Map;function _e(n){return typeof n=="object"&&n!==null&&("eq"in n||"in"in n||"includes"in n||"gt"in n||"lt"in n||"regex"in n)}function be(n,e,t){if("eq"in e)return n===e.eq;if("in"in e)return Array.isArray(e.in)&&e.in.includes(n);if("includes"in e)return Array.isArray(n)&&n.includes(e.includes);if("gt"in e){const i=typeof n=="number"?n:Number(n);return!Number.isNaN(i)&&i>e.gt}if("lt"in e){const i=typeof n=="number"?n:Number(n);return!Number.isNaN(i)&&i<e.lt}if("regex"in e){const i=t??fe;let s=i.get(e.regex);if(s===void 0){try{s=new RegExp(e.regex)}catch{s=null}i.set(e.regex,s)}return s!==null&&typeof n=="string"&&s.test(n)}return!1}function H(n){return n!=null&&Object.keys(n).length>0}function me(n,e,t){return Object.entries(e).every(([i,s])=>be(n[i],s,t?.regexCache))}const Me=null;function we(n,e){return H(e)?me(n,e):!0}const Ee=new Set(["SSF.Guest.Load"]);class A{#t;#i;#e;#o=new Set;#s;#r=new Map;#n;static DEFAULT_SAMPLING_RATIO=.05;static DEFAULT_DEDUP_WINDOW_MS=1e4;constructor(e){this.#t=e.analyticsObj,this.#i=e.enabled??!1,this.#e=e.samplingRatio??A.DEFAULT_SAMPLING_RATIO,this.#s=e.dedupWindowMs??A.DEFAULT_DEDUP_WINDOW_MS,this.#n=e.onError}get enabled(){return this.#i}start(e,t){if(this.#i)try{const i=Ee.has(e);return!i&&!this.shouldTrack(e)?void 0:(!i&&!this.#o.has(e)&&(this.#t.setTimingEventSamplingRatio({[e]:this.#e}),this.#o.add(e)),this.#t.startTiming(e,t).catch(s=>{this.reportError(`startTiming failed: ${s.message}`)}),e)}catch(i){this.reportError(`startTiming failed: ${i.message}`);return}}end(e,t){if(e)try{this.#t.endTiming(e,t).catch(i=>{this.reportError(`endTiming failed: ${i.message}`)})}catch(i){this.reportError(`endTiming failed: ${i.message}`)}}reportError(e){try{this.#n?.(e)}catch{}}shouldTrack(e){if(this.#s<=0)return!0;const t=performance.now(),i=this.#r.get(e);return i!==void 0&&t-i<this.#s?!1:(this.#r.set(e,t),!0)}}const J=[j.AllowScripts,j.AllowPopups,j.AllowModals,j.AllowForms,j.AllowDownloads,j.AllowSameOrigin],V="module",ve="module.unloading",ye="module.unmount",Oe=1e3,Se=new P(V),je=n=>Array.isArray(n)&&n.some(e=>e===!1),X=()=>{};class Ie{hostId;#t;#i;#e;#o;#s=new Map;#r=new Map;#n=new Map;#a=new Map;#c;#m=null;#d=null;#p=new Map;#l=new Set;#f=new Set;#h=new Set;#S=null;#j=null;#w=new Map;#u;#I;constructor(e,t){if(this.hostId=e,!t?.logger)throw new Error("Logger is required");if(!t?.analyticsObj)throw new Error("Analytics object is required");this.#e=t.logger,this.#o=t.analyticsObj;const i={analyticsObj:t.analyticsObj,enabled:t?.measurePerformance,samplingRatio:t?.performanceSamplingRatio,onError:s=>this.#e.debug(s)};if(this.#u=new A({...i,dedupWindowMs:t?.performanceDedupWindowMs}),this.#I=new A({...i,dedupWindowMs:0}),this.#i=U(),this.#t=new pe(this.#e,this.#i),t?.readyStateCallback&&typeof t?.readyStateCallback!="function")throw new Error("readyStateCallback must be a function");this.#m=t?.readyStateCallback||null,this.#S=t?.onGuestEventSubscribe||null,this.#j=t?.onGuestEventUnsubscribe||null,this.#c=new Z,this.#t.initialize(window),this.#K(),window.addEventListener("beforeunload",this.#b),window.addEventListener("pagehide",this.#b),this.#e.debug(`host is initialized. hostId: ${this.hostId}, correlationId: ${this.#i}`)}#fe=(e,t)=>{const i={event:e,...t};this.#o.sendBAEvent(i).catch(s=>{this.#e.debug(`Analytics sendBAEvent failed: ${s.message}`)})};#D=()=>{this.#s.forEach(e=>{e.openMode!==p.Popup||this.#v(e.window)||e.dispose()})};#b=()=>{this.#D(),Array.from(this.#s.keys()).forEach(e=>this.#L(e))};#g=e=>this.#r.get(e);#y=e=>this.#n.get(e)??null;#x=e=>typeof e?._toJSON=="function";#k=(e,t)=>this.#x(e)?(this.#c.has(e?.id,t)||this.#c.addScriptingObject(e,t?{guestId:t?.id}:{}),{type:"object",object:e._toJSON()}):{type:"value",value:e};#be=e=>typeof e=="string"?e:e instanceof Error?e.message:"An unexpected error occurred in the host application";#T=e=>{e.ready&&this.#t.send({targetWin:e.window,targetOrigin:e.origin,messageType:g.HostConfig,messageBody:{logLevel:this.#e.getLogLevel(),...e.getInfo()}})};#q=({guest:e,obj:t,functionName:i,functionParams:s,callerChain:r})=>{const o=t[i];return C(o)?(this.#e.debug(`Invoking host implementation of ${t.id}.${String(i)}()`),new Promise(c=>{Object.defineProperty(o,"callContext",{value:{guest:e,...r?.length?{callChain:r}:{}},configurable:!0,enumerable:!0,writable:!0}),c(o(...s))})):(this.#e.warn(`Attempt to call invalid function on object type ${t.objectType}: ${String(i)}`),Promise.reject(new Error(`Method '${i}' not found in Scripting Object '${t.id}'`)))};#$=({sourceWin:e,sourceOrigin:t,requestId:i})=>{const s=this.#g(e);if(!s){this.#e.warn(`Received ready event for unknown guest. requestId: ${i}`);return}if(!s.initialized){this.#e.warn("Guest must be initialized before it is marked as ready"),this.#t.raiseException({targetWin:e,targetOrigin:t,requestId:i,ex:"Guest must be initialized before it is marked as ready"});return}if(!s.ready){s.ready=!0;const r=s.getInfo();this.#u.end("SSF.Guest.Load",{appId:r.guestId,appUrl:r.guestUrl}),this.#T(s),this.#m?.(s),this.#e.audit({message:"Guest is ready",...r})}};#N=({sourceWin:e,sourceOrigin:t,requestId:i,body:s})=>{const r=this.#g(e);if(!r){this.#e.warn(`Received ready event for unknown guest. requestid = ${i}`);return}r.initialized?s&&(r.capabilities={...r.capabilities,...s}):(r.initialized=!0,r.capabilities=s||{},this.#e.audit({message:"Guest is initialized",...r.getInfo()})),(!s||!s.onReady)&&this.#$({sourceWin:e,sourceOrigin:t,requestId:i,type:"",body:null})};#F=({sourceWin:e})=>{if(!e)return;const t=this.#O(e);t&&this.#E(t.id)};#W=({sourceWin:e,sourceOrigin:t,requestId:i})=>{this.#e.debug(`Processing listObjects request. requestId = ${i}`);const s=this.#g(e);if(!s)return this.#e.warn("Rejected object request from unknown guest window"),!1;const r=this.#c.listScriptingObjects(s.id);return this.#t.respond({targetWin:e,targetOrigin:t,requestId:i,response:r}),this.#e.debug({message:"name of scripting objects returned",requestId:i,objects:r,...s.getInfo()}),!0};#z=({sourceWin:e,sourceOrigin:t,requestId:i,body:s})=>{const{objectId:r}=s;this.#e.debug(`Processing getObject request for object ${r}. requestId = ${i}`);const o=this.#g(e);if(!o)return this.#e.warn("Rejected object request from unknown guest window"),!1;const c=this.getScriptingObject(r,{guest:o});return c?(this.#t.respond({targetWin:e,targetOrigin:t,requestId:i,response:this.#k(c,o)}),this.#e.debug({message:"Scripting Object returned",requestId:i,scriptingObject:r,...o.getInfo()}),!0):(this.#e.warn(`unknown or unauthorized object ${r} from guest ${o.id}`),this.#t.raiseException({targetWin:e,targetOrigin:t,requestId:i,ex:`The requested object (${r}) is not available`}),!1)};#B=({sourceWin:e,requestId:t,body:i})=>{const{eventId:s,criteria:r,filterOnGuest:o,token:c}=i;this.#e.debug(`Processing guest event subscribe request for event ${s}. requestId = ${t}`);const d=this.#g(e);if(!d){this.#e.warn("Rejected event subscribe request from unknown guest window");return}setTimeout(()=>{try{this.#S?.({guestId:d.id,eventId:s,criteria:r,token:c,...o===!1?{filterOnGuest:!1}:{}})}catch(a){this.#e.warn(`Error in onGuestEventSubscribe callback for event ${s}: ${a.message}`)}},0)};#H=({sourceWin:e,requestId:t,body:i})=>{const{eventId:s,token:r}=i;this.#e.debug(`Processing guest event unsubscribe request for event ${s}. requestId = ${t}`);const o=this.#g(e);if(!o){this.#e.warn("Rejected event unsubscribe request from unknown guest window");return}setTimeout(()=>{try{this.#j?.({guestId:o.id,eventId:s,token:r})}catch(c){this.#e.warn(`Error in onGuestEventUnsubscribe callback for event ${s}: ${c.message}`)}},0)};#A=({sourceWin:e,requestId:t,body:i})=>{const s=this.#g(e);if(!s||!this.#l.has(s.id)||this.#f.has(s.id)){s?this.#e.debug(`Ignored resize event from guest ${s.id}. requestId = ${t}`):this.#e.warn(`Received resize event from unknown guest. requestid = ${t}`);return}s.domElement&&(s.domElement.style.height=`${i.height}px`),this.#e.debug(`Guest ${s.id} resized to ${i.width}x${i.height}`)};#J=({sourceWin:e,sourceOrigin:t,requestId:i,body:s})=>{const{objectId:r,callerChain:o}=s,c=this.#g(e);if(!c)return this.#e.warn("Rejected method invocation request from unknown guest window"),!1;this.#e.debug(`Function ${r}.${String(s.functionName)}() called from guest "${c.id}" (requestId = ${i})`);const d=this.getScriptingObject(r,{guest:c});if(!d)return this.#e.warn(`Invocation of unknown or unauthorized object ${r} from guest ${c.id}`),this.#t.raiseException({targetWin:e,targetOrigin:t,requestId:i,ex:`The requested object (${r}) is not available`}),!1;const a=c.getInfo();let l;if(this.#u.enabled){const h=`ScriptingObject.API.${r}.${s.functionName}`;l=this.#u.start(h,{appId:a.guestId,appUrl:a.guestUrl})}return this.#q({guest:c,obj:d,functionName:s.functionName,functionParams:s.functionParams,callerChain:o}).then(h=>{this.#t.respond({targetWin:e,targetOrigin:t,requestId:i,response:this.#k(h,c)}),this.#e.debug({message:"Value returned for Scripting Object method call",requestId:i,scriptingObject:r,scriptingMethod:s.functionName,...a})}).catch(h=>{this.#t.raiseException({targetWin:e,targetOrigin:c.origin,requestId:i,ex:h}),this.#e.error({message:"Exception thrown for Scripting Object method call",requestId:i,scriptingObject:r,scriptingMethod:s.functionName,...a})}).finally(()=>{l&&this.#u.end(l,{appId:a.guestId,appUrl:a.guestUrl})}),!0};#V=()=>{this.#t.listen({messageType:g.GuestResize,callback:this.#A})};#G=()=>{this.#t.unlisten({messageType:g.GuestResize,callback:this.#A})};#X=e=>{if(this.#l.has(e))return;const t=this.#l.size===0;this.#l.add(e),t&&this.#V()};#Y=e=>{this.#l.delete(e)&&this.#l.size===0&&this.#G()};#K=()=>{this.#t.listen({messageType:g.GuestReady,callback:this.#N}),this.#t.listen({messageType:g.GuestReadyComplete,callback:this.#$}),this.#t.listen({messageType:g.GuestClose,callback:this.#F}),this.#t.listen({messageType:g.ListObjects,callback:this.#W}),this.#t.listen({messageType:g.ObjectGet,callback:this.#z}),this.#t.listen({messageType:g.ObjectInvoke,callback:this.#J}),this.#t.listen({messageType:g.GuestEventSubscribe,callback:this.#B}),this.#t.listen({messageType:g.GuestEventUnsubscribe,callback:this.#H})};#Q=e=>e instanceof R||typeof e?.subscribe=="function";#P=e=>{const t=new x({...e,remoting:this.#t,perfTracker:this.#I});return t.init(),this.#s.set(e.guestId,t),this.#r.set(t.window,t),this.#n.set(t.url,t),t};#O=e=>{if(typeof e=="string")return this.#s.get(e);const t=this.#r.get(e);return t||Array.from(this.#s.values()).find(i=>i.domElement===e)};#U=e=>e.openMode===p.Embed&&(!e.domElement||!e.domElement.isConnected);#Z=e=>{this.#a.get(e)?.forEach(i=>{Promise.resolve(i({id:e})).catch(X)})};#E=e=>{this.#s.has(e)&&(this.#h.has(e)||(this.#h.add(e),this.#Z(e)),this.#f.has(e)||this.#L(e))};#ee=e=>{const t=e.domElement,i=t?.parentNode;if(!t||!i)return;const s=new MutationObserver(()=>{this.#U(e)&&(this.#R(e.id),this.#E(e.id))});s.observe(i,{childList:!0}),this.#p.set(e.id,s)};#R=e=>{this.#p.get(e)?.disconnect(),this.#p.delete(e)};#te=()=>{this.#p.forEach(e=>e.disconnect()),this.#p.clear()};#v=e=>{try{return!!e?.closed}catch{return!0}};#ie=()=>{this.#d||(this.#d=setInterval(()=>{const e=[];this.#s.forEach(t=>{t.openMode===p.Popup&&this.#v(t.window)&&e.push(t)}),e.forEach(t=>{this.#E(t.id)})},1e3))};#se=()=>{if(!this.#d)return;Array.from(this.#s.values()).some(t=>t.openMode===p.Popup)||(clearInterval(this.#d),this.#d=null)};#ne=e=>{const t=D(e),i=t?void 0:U();return{popupUrl:i?`${e}#hs=${i}`:e,handshakeToken:i,trusted:t}};#_=e=>!e||!this.#v(e.window)?e:(this.#E(e.id),this.#y(e.url));#re=(e,t)=>{e===p.Popup&&this.#_(this.#y(t))};#oe=e=>{const{url:t,title:i,popupWindowFeatures:s={},searchParams:r,guestId:o,handshakeRetries:c,onLoad:d,onError:a}=e,{width:l=800,height:h=600,top:E=100,left:I=100}=s;let m=this.#_(this.#y(t));if(m)D(t)?window.open("",i):m.window.focus();else{const w=Object.entries({width:l,height:h,top:E,left:I}).filter(([,y])=>y).map(([y,ke])=>`${y}=${ke}`).join(","),{popupUrl:v,handshakeToken:u,trusted:T}=this.#ne(t),b=window.open(v,i,`popup, ${w}`);if(b)setTimeout(()=>{try{d?.(o)}catch(y){this.#e.debug(`Error occurred in onLoad for guest with id '${o}': ${y.message}`)}},0);else throw setTimeout(()=>{try{a?.(o)}catch(y){this.#e.debug(`Error occurred in onError for guest with id '${o}': ${y.message}`)}},0),new Error("Failed to open guest application in popup window");T||(b.opener=null),m=this.#P({guestId:o,window:b,title:i,url:t,searchParams:r,openMode:p.Popup,handshakeToken:u,handshakeRetries:c}),this.#ie()}return m};#M=(e,t,i)=>{setTimeout(()=>{try{t?.(e)}catch(s){this.#e.debug(`Error occurred in ${i} for guest with id '${e}': ${s.message}`)}},0)};#ce=(e,t,i={})=>{const{onLoad:s,onError:r}=i,o=()=>{this.#M(t,s,"onLoad"),this.#e.debug(`frame loaded for guest with id '${t}'`),e.removeEventListener("load",o)},c=()=>{this.#M(t,r,"onError"),this.#e.error(`frame load failed for guest with id '${t}'`),e.removeEventListener("error",c)};e.addEventListener("load",o),e.addEventListener("error",c)};#ae=e=>{const{url:t,title:i,targetElement:s,searchParams:r,guestId:o,onLoad:c,onError:d,options:a={}}=e,l=s.ownerDocument??document,{fitToContent:h=!1,disableSandbox:E=!1,sandboxValues:I=[],customSandboxValues:m=[],style:w="",permissionPolicy:v=""}=a;if(!i)throw new Error("title is required");const u=l.createElement("iframe");u.setAttribute("id",o),this.#ce(u,o,{onLoad:c,onError:d}),u.setAttribute("style",`min-width: 100%; height: 100%; border: 0px; ${w}`),E||u.setAttribute("sandbox",m.length>0?m.join(" "):[...J,...I].join(" ")),u.setAttribute("title",i),u.setAttribute("src",t),v&&u.setAttribute("allow",v),s.appendChild(u);const T=l.getElementById(o),b=this.#P({guestId:o,domElement:T,window:T.contentWindow,title:i,url:t,searchParams:r,openMode:p.Embed});return h&&this.#X(b.id),this.#ee(b),b};#de=(e,t)=>{let i="";return Object.keys(t).forEach(s=>{i+=`${(i.length?"&":"")+encodeURIComponent(s)}=${encodeURIComponent(t[s])}`}),e+(i?(e.indexOf("?")>=0?"&":"?")+i:"")};addScriptingObject=(e,t)=>{if(B(e)){const i=this.cloneScriptingObject(e);this.#c.addScriptingObject(i,t)}else this.#c.addScriptingObject(e,t)};cloneScriptingObject=e=>{if(!e)throw new Error("proxy is required");const t=new P(e.id,e.objectType);let i=[];return Object.keys(e).forEach(s=>{const r=e[s];if(this.#Q(r)){const o=new S({name:r.name||s,objectId:t.id});if(Object.defineProperty(t,s,{value:o,enumerable:!0}),r instanceof R){const c=({eventParams:a,eventOptions:l})=>this.dispatchEvent({event:o,eventParams:a,eventOptions:l}),d=r.subscribe(c);i.push(()=>{r.unsubscribe(d)})}else{const c=r.subscribe?.((d,a,l)=>this.dispatchEvent({event:o,eventParams:a,eventOptions:l}));i.push(()=>{r.unsubscribe?.(c)})}}else if(C(r)&&(Object.defineProperty(t,s,{value:async(...o)=>{const c=t[s]?.callContext;if(c?.guest){const a=c.callChain??[],l=c.guest.id,h=this.#w.get(l),E={id:l};h&&(E.metadata=h),Object.defineProperty(r,"callContext",{value:{callChain:[...a,E]},configurable:!0,enumerable:!0,writable:!0})}const d=await r(...o);return B(d)?this.cloneScriptingObject(d):d},enumerable:!0}),s==="dispose")){const o=t.dispose;Object.defineProperty(t,s,{value:()=>(t._dispose(),o.apply(t)),enumerable:!0})}}),t._dispose=()=>{i.forEach(s=>{s?.()}),i=[]},t};close=()=>{this.#d&&(clearInterval(this.#d),this.#d=null),this.#te(),this.#b(),this.#l.clear(),this.#h.clear(),this.#G(),this.#a.clear(),this.removeAllScriptingObjects(),this.#w.clear(),this.#t.close(),window.removeEventListener("beforeunload",this.#b),window.removeEventListener("pagehide",this.#b),this.#e.debug(`host is closed. hostId: ${this.hostId}, correlationId: ${this.#i}`)};#le=({targetGuest:e,guestCapabilities:t,scriptingEventId:i,dispatchToGuest:s})=>{const r=o=>{if(H(t)&&!we(o.capabilities,t)){this.#e.debug({message:"Event skipped \u2014 guest capabilities do not match eventOptions.guestCapabilities",scriptingEventId:i,guestCapabilities:t,...o.getInfo()});return}s(o)};e?r(e):this.#s.forEach(r)};#he=(e,t)=>(t?this.getScriptingObject(e,{guest:t}):this.getScriptingObject(e))??(e===V&&t?Se:null);dispatchEvent=async e=>{const{event:{id:t,name:i},eventParams:s,eventOptions:r={}}=e,{eventHandler:o=null,timeout:c=null,window:d=null,guestId:a,guestCapabilities:l}=r,h=t.split(".")[0],E=a||d,I=E?this.#O(E):null,m=this.#he(h,I??null);if(!m)return this.#e.warn(`Attempt to dispatch event ${i} on unknown object ${h}`),Promise.resolve([]);const w={object:m._toJSON(),eventName:i,eventParams:s,eventHandler:o,eventOptions:{allowsFeedback:!1}};c&&!Number.isNaN(c)&&(w.eventOptions={allowsFeedback:!0,timeout:Number(c)});const v=[];let u;const T=b=>{const y=b.getInfo();c&&b?.capabilities?.eventFeedback?(v.push(b.dispatchEvent(w,c)),!u&&this.#u.enabled&&(u=this.#u.start(`ScriptingObject.Event.${m.id}.${i}`,{appId:this.hostId,appUrl:window.location.href})),this.#e.debug({message:"Event dispatched and awaiting feedback",scriptingEventId:t,...y})):(b.send({messageType:g.ObjectEvent,messageBody:w}),this.#e.debug({message:"Event dispatched",scriptingEventId:t,...y}))};return this.#le({targetGuest:I??null,guestCapabilities:l,scriptingEventId:t,dispatchToGuest:T}),Promise.all(v).then(b=>(this.#e.debug({message:"Event feedback received",scriptingEventId:t}),te(b))).catch(b=>{throw this.#e.error({message:"Error processing event",eventId:t,exception:b}),b}).finally(()=>{u&&this.#u.end(u,{appId:this.hostId,appUrl:window.location.href})})};getGuests=()=>Array.from(this.#s.values());getScriptingObject=(e,t)=>this.#c.getObject(e,t?.guest);loadGuest=e=>{const{id:t,url:i,targetElement:s,title:r,searchParams:o={},onLoad:c,onError:d,options:a={},metadata:l}=e;if(!t)throw new Error("id for guest application is required");const{openMode:h=p.Embed,popupWindowFeatures:E={},handshakeRetries:I}=a,m=this.#de(i,o);this.#re(h,m);let w=t;if(this.#s.has(w)){let u=1;for(;this.#s.has(`${t}-${u}`);)u+=1;w=`${t}-${u}`}let v=null;if(this.#u.start("SSF.Guest.Load",{appId:w,appUrl:m}),h===p.Popup)v=this.#oe({guestId:w,url:m,title:r,searchParams:o,popupWindowFeatures:E,handshakeRetries:I,onLoad:c,onError:d});else if(h===p.Embed)v=this.#ae({guestId:w,url:m,title:r,targetElement:s,searchParams:o,onLoad:c,onError:d,options:a});else throw new Error(`Invalid openMode: ${h}`);return l&&this.#w.set(w,l),this.#e.audit({message:"Guest loaded",...v.getInfo()}),v};loadGuests=e=>{const{id:t,url:i,targetElement:s,title:r,searchParamsList:o=[],options:c={}}=e;o.forEach((d,a)=>{this.loadGuest({id:`${t}-${a}`,url:i,title:r,targetElement:s,searchParams:d,options:c})},this)};removeAllScriptingObjects=e=>{this.#c.removeAllScriptingObjects(e)};removeScriptingObject=(e,t)=>{this.#c.removeScriptingObject(e,t)};setLogLevel=e=>{this.#e.setLogLevel(e),this.#s.forEach(this.#T),this.#e.debug("Dispatched config events to all guests")};#C=async(e,t,i)=>this.dispatchEvent({event:{id:t,name:i},eventParams:{moduleId:e.id},eventOptions:{timeout:Oe,guestId:e.id}});#ue=async e=>{try{const t=await this.#C(e,ve,"unloading");if(je(t))return this.#e.info(`Unload denied by guest ${e.id} via module.unloading event`),!1}catch(t){this.#e.warn({message:`Error dispatching module.unloading event for ${e.id}; proceeding with unload`,exception:t})}return!0};#ge=async e=>{try{await this.#C(e,ye,"unmount")}catch(t){this.#e.warn({message:`Error dispatching module.unmount event for ${e.id}`,exception:t})}};#L=e=>{this.unloadGuest(e).catch(X)};#pe=e=>{e.dispose(),this.#r.get(e.window)===e&&this.#r.delete(e.window),this.#n.get(e.url)===e&&this.#n.delete(e.url),this.#s.get(e.id)===e&&(this.#R(e.id),this.#Y(e.id),this.removeAllScriptingObjects(e.id),this.#w.delete(e.id),this.#s.delete(e.id),this.#a.delete(e.id),this.#h.delete(e.id)),this.#e.audit({message:"Guest is removed from host",...e.getInfo()}),this.#se()};unloadGuest=async e=>{const t=this.#O(e);if(t&&!this.#f.has(t.id)){this.#f.add(t.id);try{if(!((t.openMode===p.Popup?this.#v(t.window):!!t.window?.closed)||this.#U(t))){if(!await this.#ue(t)){this.#h.delete(t.id);return}await this.#ge(t)}this.#pe(t)}finally{this.#f.delete(t.id)}}};onGuestClose=e=>{const{id:t,guestCloseCallback:i}=e,s=this.#a.get(t)||[];s.push(i),this.#a.set(t,s)}}return k})());
|
|
1
|
+
(function(I,O){typeof exports=="object"&&typeof module=="object"?module.exports=O():typeof define=="function"&&define.amd?define([],O):typeof exports=="object"?exports.ice=O():(I.ice=I.ice||{},I.ice.host=O())})(globalThis,()=>(()=>{"use strict";const y={};y.d=(n,e)=>{for(var t in e)y.o(e,t)&&!y.o(n,t)&&Object.defineProperty(n,t,{enumerable:!0,get:e[t]})},y.o=(n,e)=>Object.hasOwn(n,e),y.r=n=>{Object.defineProperty(n,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(n,"__esModule",{value:!0})};let I={};y.r(I),y.d(I,{Event:()=>O,Guest:()=>x,IFrameSandboxValues:()=>S,OnDuplicate:()=>M,OpenMode:()=>g,SANDBOX_DEFAULT:()=>J,SSFHost:()=>Ie,ScriptingObject:()=>P});class O{name;objectId;id;constructor(e){const{name:t,objectId:i}=e;if(!t)throw new Error("Event name is required");if(!i)throw new Error("Scripting object id is required");this.objectId=i,this.name=t,this.id=`${this.objectId}.${this.name}`.toLowerCase()}}class R{static[Symbol.hasInstance](e){return typeof e=="object"&&e!==null&&"getType"in e&&typeof e.getType=="function"&&e.getType()==="ProxyEvent"}#t;objectId;name;id;getType(){return"ProxyEvent"}constructor(e){const{name:t,objectId:i,eventSrc:s}=e;if(!t)throw new Error("Event name is required");if(!i)throw new Error("Scripting object id is required");if(!s)throw new Error("Event source is required");this.objectId=i,this.name=t,this.#t=s,this.id=`${this.objectId}.${this.name}`.toLowerCase()}subscribe=e=>this.#t.subscribe({eventId:this.id,callback:e});unsubscribe=e=>{this.#t.unsubscribe({eventId:this.id,token:e})}}const Y=n=>n instanceof O,Te=(n,e)=>`${n.toLowerCase()}.${e.toLowerCase()}`,K="function",Q=(n,e)=>typeof n===K&&!!e&&!e.startsWith("_");class P{#t;#i="Object";constructor(e,t){this.#t=e,this.#i=t||this.#i}get id(){return this.#t}get objectType(){return this.#i}_toJSON=()=>{const e=[],t=[];return Object.keys(this).forEach(i=>{const s=this[i];Y(s)?t.push(i):Q(s,i)&&e.push(i)}),{objectId:this.#t,objectType:this.#i,functions:e,events:t}};_dispose=()=>{};dispose=()=>{}}const C="module";var $e=null,M=(n=>(n.THROW="throw",n.IGNORE="ignore",n))(M||{});class Z{#t=e=>e.trim().toLowerCase();#i=new Map;#e=new Map;#o=e=>{const{so:t,guestId:i,onDuplicate:s="throw",securityContext:r}=e,o=this.#t(t.id),a={so:t,guestId:i,securityContext:r},c=this.#e.get(i);if(!c){this.#e.set(i,new Map([[o,a]]));return}if(c.has(o)){if(s==="ignore")return;throw new Error(`Scripting Object ${t.id} already exists for guest ${i}`)}c.set(o,a)};#s=({so:e})=>{if(e._dispose&&typeof e._dispose=="function")try{e._dispose()}catch{}};#r=({objectId:e,guestId:t})=>{if(e===C&&!t)for(const[,s]of this.#e){const r=s.get(e);if(r)return r}const i=t?this.#e.get(t):null;return i?i.get(e)??null:null};#n=({objectId:e,guestId:t}={})=>{if(t){if(!e){const s=this.#e.get(t);s&&s.forEach(this.#s),this.#e.delete(t);return}const i=this.#e.get(t);if(i){const s=i.get(e);s&&this.#s(s),i.delete(e)}}else e&&this.#e.forEach(i=>{const s=i.get(e);s&&this.#s(s),i.delete(e)})};addScriptingObject=(e,t)=>{const{guestId:i,onDuplicate:s="throw",securityContext:r}=t||{};if(!e?.id||!e?._toJSON)throw new Error("Object is not derived from ScriptingObject");const o=this.#t(e.id);if(o===C&&!i)throw new Error("Guest id is required to add Module scripting object");if(i){this.#o({so:e,...t,guestId:i,onDuplicate:s});return}if(this.#i.has(o)){if(s==="ignore")return;throw new Error(`Scripting Object ${e.id} already exists`)}this.#i.set(o,{so:e,guestId:i,securityContext:r})};getObject=(e,t)=>{const i=this.#t(e);let s=this.#r({objectId:i,guestId:t?.id});s=s??this.#i.get(i)??null;const{so:r}=s||{};return r||null};has=(e,t)=>this.getObject(e,t)!==null;listScriptingObjects=e=>{const t=new Set(this.#i.keys()),i=this.#e.get(e);if(i)for(const s of i.keys())t.add(s);return Array.from(t)};removeScriptingObject=(e,t)=>{const i=this.#t(e);if(t)this.#n({objectId:i,guestId:t});else{this.#n({objectId:i});const s=this.#i.get(i);s&&this.#s(s),this.#i.delete(i)}};removeAllScriptingObjects=e=>{e?this.#n({guestId:e}):(this.#i.forEach(this.#s),this.#i.clear())}}var p=(n=>(n.GuestClose="guest:close",n.GuestEventSubscribe="guest:eventSubscribe",n.GuestEventUnsubscribe="guest:eventUnsubscribe",n.GuestFocus="guest:focus",n.GuestReady="guest:ready",n.GuestReadyComplete="guest:readyComplete",n.GuestResize="guest:resize",n.HandShake="handshake",n.HandShakeAck="handshake:ack",n.HostClose="host:close",n.HostConfig="host:config",n.ListObjects="list:objects",n.ObjectEvent="object:event",n.ObjectGet="object:get",n.ObjectInvoke="object:invoke",n))(p||{}),g=(n=>(n.Popup="popup",n.Embed="embed",n))(g||{}),S=(n=>(n.AllowDownloadsWithoutUserActivation="allow-downloads-without-user-activation",n.AllowDownloads="allow-downloads",n.AllowForms="allow-forms",n.AllowModals="allow-modals",n.AllowOrientationLock="allow-orientation-lock",n.AllowPointerLock="allow-pointer-lock",n.AllowPopups="allow-popups",n.AllowPopupsToEscapeSandbox="allow-popups-to-escape-sandbox",n.AllowPresentation="allow-presentation",n.AllowSameOrigin="allow-same-origin",n.AllowScripts="allow-scripts",n.AllowStorageAccessByUserActivation="allow-storage-access-by-user-activation",n.AllowTopNavigation="allow-top-navigation",n.AllowTopNavigationByUserActivation="allow-top-navigation-by-user-activation",n))(S||{});const ee=n=>{if(n==="about:blank")return"*";try{const{origin:e}=new URL(n);return e==="null"||!e?n:e}catch{const{origin:t}=new URL(n,document.baseURI);return t}},te=n=>n.flat(1/0).filter(e=>e!==void 0);function _(n){return typeof n=="function"}const ie=[".ice.com",".elliemae.com",".ellielabs.com",".elliemae.io",".ellieservices.com"],se=["localhost","127.0.0.1"],L=n=>n.split(".").slice(-2).join("."),ne=n=>se.includes(n)||ie.some(e=>n===e.slice(1)||n.endsWith(e)),re=n=>{const e=L(window.location.hostname),t=L(n);return e===t},D=n=>{if(!n)return!1;try{const{hostname:e}=new URL(n,document.baseURI);return ne(e)||re(e)}catch{return!1}},oe=1e3,ae=10,ce=30,de=n=>typeof n!="number"||!Number.isFinite(n)?n===void 0?ae:1:Math.min(ce,Math.max(1,Math.floor(n)));class x{id;title;url;searchParams;domElement;window;openMode;origin;initialized=!1;ready=!1;capabilities;#t;#i;#e;#o;#s=null;#r=null;#n=null;constructor(e){const{guestId:t,domElement:i=null,title:s,url:r,window:o,searchParams:a={},openMode:c=g.Embed,remoting:d,perfTracker:l,handshakeToken:h,handshakeRetries:E}=e;this.id=t,this.title=s,this.url=r,this.origin=ee(r),this.searchParams=a,this.domElement=i,this.window=o,this.openMode=c,this.capabilities={},this.#i=l,this.#t=d,this.#e=h,this.#o=de(E)}dispose=()=>{this.#c(!1);let e=!1;if(this.openMode===g.Popup)try{e=!this.window.closed}catch{e=!1}if(e)try{this.window.document,this.window.close()}catch{this.#t.send({targetWin:this.window,targetOrigin:this.origin,messageType:p.HostClose,messageBody:{}})}else this.domElement?.remove?.();this.#t.removeSender({origin:this.origin,window:this.window})};getInfo=()=>({guestId:this.id,guestTitle:this.title,guestUrl:this.url});#c=e=>{this.#s&&(clearInterval(this.#s),this.#s=null),this.#r&&(this.#t.unlisten({messageType:p.HandShakeAck,callback:this.#r}),this.#r=null);const t=this.#n;this.#n=null,t&&e!==void 0&&t(e)};#a=()=>{this.#n&&this.#t.send({targetWin:this.window,targetOrigin:this.origin,messageType:p.HandShake,messageBody:this.#e?{handshakeToken:this.#e}:{}})};handShake=()=>(this.#c(!1),this.openMode!==g.Popup?Promise.resolve(!1):new Promise(e=>{let t=0;this.#n=e;const i=()=>{this.#n&&this.#c(!0)};this.#r=i,this.#a(),t=1,this.#s=setInterval(()=>{if(this.#n){if(t>=this.#o){this.#c(!1);return}this.#a(),t+=1}},oe),this.#t.listen({messageType:p.HandShakeAck,callback:i})}));init=()=>{this.#t.addSender({origin:this.origin,window:this.window}),this.openMode===g.Popup&&this.handShake().catch(()=>{})};dispatchEvent=(e,t)=>{let i;if(this.#i.enabled){const s=`ScriptingObject.Event.${e.object.objectId}.${e.eventName}`;i=this.#i.start(s,{appId:this.id,appUrl:this.url})}return this.#t.invoke({targetWin:this.window,targetOrigin:this.origin,messageType:p.ObjectEvent,messageBody:e,responseTimeoutMs:t}).finally(()=>{i&&this.#i.end(i,{appId:this.id,appUrl:this.url})})};send=e=>{this.#t.send({targetWin:this.window,targetOrigin:this.origin,...e})}}const N={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};let G;const le=new Uint8Array(16);function he(){if(!G&&(G=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!G))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return G(le)}var ue;const f=[];for(let n=0;n<256;++n)f.push((n+256).toString(16).slice(1));function q(n,e=0){return f[n[e+0]]+f[n[e+1]]+f[n[e+2]]+f[n[e+3]]+"-"+f[n[e+4]]+f[n[e+5]]+"-"+f[n[e+6]]+f[n[e+7]]+"-"+f[n[e+8]]+f[n[e+9]]+"-"+f[n[e+10]]+f[n[e+11]]+f[n[e+12]]+f[n[e+13]]+f[n[e+14]]+f[n[e+15]]}function Ge(n,e=0){const t=q(n,e);if(!ue(t))throw TypeError("Stringified UUID is invalid");return t}const Pe=null;function pe(n,e,t){if(N.randomUUID&&!e&&!n)return N.randomUUID();n=n||{};const i=n.random||(n.rng||he)();if(i[6]=i[6]&15|64,i[8]=i[8]&63|128,e){t=t||0;for(let s=0;s<16;++s)e[t+s]=i[s];return e}return q(i)}const U=pe,F="elli:remoting",W="elli:remoting:response",z="elli:remoting:exception",$=({messageType:n,messageBody:e,requestId:t,onewayMsg:i=!1})=>({requestId:t??(i?null:U()),source:F,type:n,body:e}),Ue=n=>{const{targetWin:e,targetOrigin:t,messageType:i,messageBody:s}=n,r=$({messageType:i,messageBody:s});e.postMessage(r,t)};class ge{#t;#i;#e=new Map;#o=new Map;#s=null;#r=null;#n=new Map;constructor(e,t){if(!e)throw new Error("logger is required");if(!t)throw new Error("correlationId is required");this.#t=t,this.#i=e}#c=()=>{this.#s=null;const e=Date.now(),t=[];let i=null;if(this.#o.forEach((s,r)=>{const{requestId:o,cancelTime:a}=s;a&&a<=e?(this.#i.debug(`Detected response timeout for requestId: ${o}...`),t.push(r),s.resolve(void 0)):a&&(i=i===null?a:Math.min(i,a))}),t.forEach(s=>{this.#o.delete(s)}),i!==null){const s=Math.max(i-Date.now(),0);this.#a(s)}};#a=e=>{this.#s===null&&(this.#s=window.setTimeout(this.#c,e))};#E=()=>{this.#s!==null&&(window.clearTimeout(this.#s),this.#s=null)};#d=e=>{const t=this.#o.get(e);return this.#i.debug(`serving requestId: ${e}`),this.#o.delete(e),t};#g=e=>{const{requestId:t}=e;this.#i.debug(`Response received for invocation requestId: ${t}`);const i=this.#d(t);return i?(i.resolve(e.body),!0):(this.#i.debug(`Received response to stale/invalid request with requestId: ${t}`),!1)};#l=e=>{this.#i.debug(`Exception received for invocation (requestId = ${e.requestId})`);const t=this.#d(e.requestId);return t?(t.reject(new Error(e.body)),!0):(this.#i.warn(`Received exception for stale/invalid request (requestId = ${e.requestId})`),!1)};#u=({sourceWin:e,sourceOrigin:t,message:i})=>{this.#i.debug(`Received message of type "${i.type}"`);const s=this.#e.get(i.type);return s?(s.forEach(r=>{this.#i.debug(`Invoking message handler ${r.name}`),r({sourceWin:e,sourceOrigin:t,requestId:i.requestId,type:i.type,body:i.body})}),!0):!1};#f=e=>{if(this.#n.size===0||!e.source)return!1;const t=this.#n.get(e.source);return!t||e?.data?.source!==F?!1:(this.#i.debug(`Remoting: Received message of type "${e.data.type}"`),e.data.type===W?this.#g(e.data):e.data.type===z?this.#l(e.data):this.#u({sourceWin:e.source,sourceOrigin:t,message:e.data}),!0)};addSender=e=>{const{origin:t,window:i}=e;if(!t)throw new Error("origin is required");if(!i)throw new Error("window is required");this.#n.set(i,t)};initialize=e=>{this.#r&&this.#r.removeEventListener("message",this.#f),e.addEventListener("message",this.#f),this.#r=e,this.#i.debug(`initialized remoting id: ${this.#t}`)};close=()=>{this.#r&&(this.#r.removeEventListener("message",this.#f),this.#r=null),this.#E(),this.#o.forEach(({reject:e})=>{e(new Error("Remoting closed"))}),this.#o.clear(),this.#e.clear(),this.#n.clear(),this.#i.debug(`closed remoting id: ${this.#t}`)};invoke=e=>{const{targetWin:t,targetOrigin:i,messageType:s,messageBody:r,responseTimeoutMs:o}=e;return new Promise((a,c)=>{const d=$({messageType:s,messageBody:r});this.#o.set(d.requestId,{requestId:d.requestId,resolve:a,reject:c,cancelTime:o?Date.now()+o:null}),t.postMessage(d,i);const{requestId:l}=d;this.#i.debug(`Posted invocation message of type ${s} requestId: ${l||""}`),o&&(this.#i.debug(`scheduling timeout check for requestId: ${l||""} in ${o} ms`),this.#a(o))})};listen=e=>{const{messageType:t,callback:i}=e,s=this.#e.get(t)||[];s.push(i),this.#e.set(t,s)};unlisten=e=>{const{messageType:t,callback:i}=e,s=this.#e.get(t);if(!s)return;const r=s.indexOf(i);r!==-1&&s.splice(r,1)};send=e=>{const{targetWin:t,targetOrigin:i,messageType:s,messageBody:r}=e,o=$({messageType:s,messageBody:r,onewayMsg:!0});t.postMessage(o,i),this.#i.debug(`Posted one-way message of type "${s}"`)};removeSender=e=>{const{window:t}=e;t&&this.#n.delete(t)};respond=e=>{const{targetWin:t,targetOrigin:i,requestId:s,response:r}=e,o=$({messageType:W,messageBody:r,requestId:s});t.postMessage(o,i),this.#i.debug(`Response sent to caller for invocation requestId: ${s}`)};raiseException=e=>{const{targetWin:t,targetOrigin:i,requestId:s,ex:r}=e,o=r instanceof Error?r.message:r,a=$({messageType:z,messageBody:o,requestId:s});t.postMessage(a,i),this.#i.debug(`Exception sent to caller for invocation. requestId: ${s}`)}}class Re{__TYPE__="Proxy";id;objectType;constructor(e,t){this.id=e,this.objectType=t}}const B=n=>n?.constructor?.name==="Proxy"||n?.constructor?.name==="ScriptingObjectProxy"||n?.__TYPE__==="Proxy",fe=new Map;function Ce(n){return typeof n=="object"&&n!==null&&("eq"in n||"in"in n||"includes"in n||"gt"in n||"lt"in n||"regex"in n)}function be(n,e,t){if("eq"in e)return n===e.eq;if("in"in e)return Array.isArray(e.in)&&e.in.includes(n);if("includes"in e)return Array.isArray(n)&&n.includes(e.includes);if("gt"in e){const i=typeof n=="number"?n:Number(n);return!Number.isNaN(i)&&i>e.gt}if("lt"in e){const i=typeof n=="number"?n:Number(n);return!Number.isNaN(i)&&i<e.lt}if("regex"in e){const i=t??fe;let s=i.get(e.regex);if(s===void 0){try{s=new RegExp(e.regex)}catch{s=null}i.set(e.regex,s)}return s!==null&&typeof n=="string"&&s.test(n)}return!1}function H(n){return n!=null&&Object.keys(n).length>0}function me(n,e,t){return Object.entries(e).every(([i,s])=>be(n[i],s,t?.regexCache))}const Me=null;function we(n,e){return H(e)?me(n,e):!0}const Ee=new Set(["SSF.Guest.Load"]);class A{#t;#i;#e;#o=new Set;#s;#r=new Map;#n;static DEFAULT_SAMPLING_RATIO=.05;static DEFAULT_DEDUP_WINDOW_MS=1e4;constructor(e){this.#t=e.analyticsObj,this.#i=e.enabled??!1,this.#e=e.samplingRatio??A.DEFAULT_SAMPLING_RATIO,this.#s=e.dedupWindowMs??A.DEFAULT_DEDUP_WINDOW_MS,this.#n=e.onError}get enabled(){return this.#i}start(e,t){if(this.#i)try{const i=Ee.has(e);return!i&&!this.shouldTrack(e)?void 0:(!i&&!this.#o.has(e)&&(this.#t.setTimingEventSamplingRatio({[e]:this.#e}),this.#o.add(e)),this.#t.startTiming(e,t).catch(s=>{this.reportError(`startTiming failed: ${s.message}`)}),e)}catch(i){this.reportError(`startTiming failed: ${i.message}`);return}}end(e,t){if(e)try{this.#t.endTiming(e,t).catch(i=>{this.reportError(`endTiming failed: ${i.message}`)})}catch(i){this.reportError(`endTiming failed: ${i.message}`)}}reportError(e){try{this.#n?.(e)}catch{}}shouldTrack(e){if(this.#s<=0)return!0;const t=performance.now(),i=this.#r.get(e);return i!==void 0&&t-i<this.#s?!1:(this.#r.set(e,t),!0)}}const J=[S.AllowScripts,S.AllowPopups,S.AllowModals,S.AllowForms,S.AllowDownloads,S.AllowSameOrigin],V="module",ve="module.unloading",ye="module.unmount",Oe=1e3,Se=new P(V),je=n=>Array.isArray(n)&&n.some(e=>e===!1),X=()=>{};class Ie{hostId;#t;#i;#e;#o;#s=new Map;#r=new Map;#n=new Map;#c=new Map;#a;#E=null;#d=null;#g=new Map;#l=new Set;#u=new Set;#f=new Set;#b=new Set;#I=null;#k=null;#v=new Map;#h;#T;constructor(e,t){if(this.hostId=e,!t?.logger)throw new Error("Logger is required");if(!t?.analyticsObj)throw new Error("Analytics object is required");this.#e=t.logger,this.#o=t.analyticsObj;const i={analyticsObj:t.analyticsObj,enabled:t?.measurePerformance,samplingRatio:t?.performanceSamplingRatio,onError:s=>this.#e.debug(s)};if(this.#h=new A({...i,dedupWindowMs:t?.performanceDedupWindowMs}),this.#T=new A({...i,dedupWindowMs:0}),this.#i=U(),this.#t=new ge(this.#e,this.#i),t?.readyStateCallback&&typeof t?.readyStateCallback!="function")throw new Error("readyStateCallback must be a function");this.#E=t?.readyStateCallback||null,this.#I=t?.onGuestEventSubscribe||null,this.#k=t?.onGuestEventUnsubscribe||null,this.#a=new Z,this.#t.initialize(window),this.#ee(),window.addEventListener("beforeunload",this.#w),window.addEventListener("pagehide",this.#w),this.#e.debug(`host is initialized. hostId: ${this.hostId}, correlationId: ${this.#i}`)}#we=(e,t)=>{const i={event:e,...t};this.#o.sendBAEvent(i).catch(s=>{this.#e.debug(`Analytics sendBAEvent failed: ${s.message}`)})};#q=()=>{this.#s.forEach(e=>{e.openMode!==g.Popup||this.#m(e.window)||e.dispose()})};#w=()=>{this.#q(),Array.from(this.#s.keys()).forEach(e=>this.#x(e))};#p=e=>this.#r.get(e);#y=e=>this.#n.get(e)??null;#F=e=>typeof e?._toJSON=="function";#$=(e,t)=>this.#F(e)?(this.#a.has(e?.id,t)||this.#a.addScriptingObject(e,t?{guestId:t?.id}:{}),{type:"object",object:e._toJSON()}):{type:"value",value:e};#Ee=e=>typeof e=="string"?e:e instanceof Error?e.message:"An unexpected error occurred in the host application";#A=e=>{e.ready&&this.#t.send({targetWin:e.window,targetOrigin:e.origin,messageType:p.HostConfig,messageBody:{logLevel:this.#e.getLogLevel(),...e.getInfo()}})};#W=({guest:e,obj:t,functionName:i,functionParams:s,callerChain:r})=>{const o=t[i];return _(o)?(this.#e.debug(`Invoking host implementation of ${t.id}.${String(i)}()`),new Promise(a=>{Object.defineProperty(o,"callContext",{value:{guest:e,...r?.length?{callChain:r}:{}},configurable:!0,enumerable:!0,writable:!0}),a(o(...s))})):(this.#e.warn(`Attempt to call invalid function on object type ${t.objectType}: ${String(i)}`),Promise.reject(new Error(`Method '${i}' not found in Scripting Object '${t.id}'`)))};#G=({sourceWin:e,sourceOrigin:t,requestId:i})=>{const s=this.#p(e);if(!s){this.#e.warn(`Received ready event for unknown guest. requestId: ${i}`);return}if(!s.initialized){this.#e.warn("Guest must be initialized before it is marked as ready"),this.#t.raiseException({targetWin:e,targetOrigin:t,requestId:i,ex:"Guest must be initialized before it is marked as ready"});return}if(!s.ready){s.ready=!0;const r=s.getInfo();this.#h.end("SSF.Guest.Load",{appId:r.guestId,appUrl:r.guestUrl}),this.#A(s),this.#E?.(s),this.#e.audit({message:"Guest is ready",...r})}};#z=({sourceWin:e,sourceOrigin:t,requestId:i,body:s})=>{const r=this.#p(e);if(!r){this.#e.warn(`Received ready event for unknown guest. requestid = ${i}`);return}r.initialized?s&&(r.capabilities={...r.capabilities,...s}):(r.initialized=!0,r.capabilities=s||{},this.#e.audit({message:"Guest is initialized",...r.getInfo()})),(!s||!s.onReady)&&this.#G({sourceWin:e,sourceOrigin:t,requestId:i,type:"",body:null})};#B=({sourceWin:e})=>{if(!e)return;const t=this.#j(e);t&&(t.openMode===g.Popup&&this.#f.add(t.id),this.#O(t.id))};#H=({sourceWin:e,sourceOrigin:t,requestId:i})=>{this.#e.debug(`Processing listObjects request. requestId = ${i}`);const s=this.#p(e);if(!s)return this.#e.warn("Rejected object request from unknown guest window"),!1;const r=this.#a.listScriptingObjects(s.id);return this.#t.respond({targetWin:e,targetOrigin:t,requestId:i,response:r}),this.#e.debug({message:"name of scripting objects returned",requestId:i,objects:r,...s.getInfo()}),!0};#J=({sourceWin:e,sourceOrigin:t,requestId:i,body:s})=>{const{objectId:r}=s;this.#e.debug(`Processing getObject request for object ${r}. requestId = ${i}`);const o=this.#p(e);if(!o)return this.#e.warn("Rejected object request from unknown guest window"),!1;const a=this.getScriptingObject(r,{guest:o});return a?(this.#t.respond({targetWin:e,targetOrigin:t,requestId:i,response:this.#$(a,o)}),this.#e.debug({message:"Scripting Object returned",requestId:i,scriptingObject:r,...o.getInfo()}),!0):(this.#e.warn(`unknown or unauthorized object ${r} from guest ${o.id}`),this.#t.raiseException({targetWin:e,targetOrigin:t,requestId:i,ex:`The requested object (${r}) is not available`}),!1)};#V=({sourceWin:e,requestId:t,body:i})=>{const{eventId:s,criteria:r,filterOnGuest:o,token:a}=i;this.#e.debug(`Processing guest event subscribe request for event ${s}. requestId = ${t}`);const c=this.#p(e);if(!c){this.#e.warn("Rejected event subscribe request from unknown guest window");return}setTimeout(()=>{try{this.#I?.({guestId:c.id,eventId:s,criteria:r,token:a,...o===!1?{filterOnGuest:!1}:{}})}catch(d){this.#e.warn(`Error in onGuestEventSubscribe callback for event ${s}: ${d.message}`)}},0)};#X=({sourceWin:e,requestId:t,body:i})=>{const{eventId:s,token:r}=i;this.#e.debug(`Processing guest event unsubscribe request for event ${s}. requestId = ${t}`);const o=this.#p(e);if(!o){this.#e.warn("Rejected event unsubscribe request from unknown guest window");return}setTimeout(()=>{try{this.#k?.({guestId:o.id,eventId:s,token:r})}catch(a){this.#e.warn(`Error in onGuestEventUnsubscribe callback for event ${s}: ${a.message}`)}},0)};#P=({sourceWin:e,requestId:t,body:i})=>{const s=this.#p(e);if(!s||!this.#l.has(s.id)||this.#u.has(s.id)){s?this.#e.debug(`Ignored resize event from guest ${s.id}. requestId = ${t}`):this.#e.warn(`Received resize event from unknown guest. requestid = ${t}`);return}s.domElement&&(s.domElement.style.height=`${i.height}px`),this.#e.debug(`Guest ${s.id} resized to ${i.width}x${i.height}`)};#Y=({sourceWin:e,sourceOrigin:t,requestId:i,body:s})=>{const{objectId:r,callerChain:o}=s,a=this.#p(e);if(!a)return this.#e.warn("Rejected method invocation request from unknown guest window"),!1;this.#e.debug(`Function ${r}.${String(s.functionName)}() called from guest "${a.id}" (requestId = ${i})`);const c=this.getScriptingObject(r,{guest:a});if(!c)return this.#e.warn(`Invocation of unknown or unauthorized object ${r} from guest ${a.id}`),this.#t.raiseException({targetWin:e,targetOrigin:t,requestId:i,ex:`The requested object (${r}) is not available`}),!1;const d=a.getInfo();let l;if(this.#h.enabled){const h=`ScriptingObject.API.${r}.${s.functionName}`;l=this.#h.start(h,{appId:d.guestId,appUrl:d.guestUrl})}return this.#W({guest:a,obj:c,functionName:s.functionName,functionParams:s.functionParams,callerChain:o}).then(h=>{this.#t.respond({targetWin:e,targetOrigin:t,requestId:i,response:this.#$(h,a)}),this.#e.debug({message:"Value returned for Scripting Object method call",requestId:i,scriptingObject:r,scriptingMethod:s.functionName,...d})}).catch(h=>{this.#t.raiseException({targetWin:e,targetOrigin:a.origin,requestId:i,ex:h}),this.#e.error({message:"Exception thrown for Scripting Object method call",requestId:i,scriptingObject:r,scriptingMethod:s.functionName,...d})}).finally(()=>{l&&this.#h.end(l,{appId:d.guestId,appUrl:d.guestUrl})}),!0};#K=()=>{this.#t.listen({messageType:p.GuestResize,callback:this.#P})};#U=()=>{this.#t.unlisten({messageType:p.GuestResize,callback:this.#P})};#Q=e=>{if(this.#l.has(e))return;const t=this.#l.size===0;this.#l.add(e),t&&this.#K()};#Z=e=>{this.#l.delete(e)&&this.#l.size===0&&this.#U()};#ee=()=>{this.#t.listen({messageType:p.GuestReady,callback:this.#z}),this.#t.listen({messageType:p.GuestReadyComplete,callback:this.#G}),this.#t.listen({messageType:p.GuestClose,callback:this.#B}),this.#t.listen({messageType:p.ListObjects,callback:this.#H}),this.#t.listen({messageType:p.ObjectGet,callback:this.#J}),this.#t.listen({messageType:p.ObjectInvoke,callback:this.#Y}),this.#t.listen({messageType:p.GuestEventSubscribe,callback:this.#V}),this.#t.listen({messageType:p.GuestEventUnsubscribe,callback:this.#X})};#te=e=>e instanceof R||typeof e?.subscribe=="function";#R=e=>{const t=new x({...e,remoting:this.#t,perfTracker:this.#T});return t.init(),this.#s.set(e.guestId,t),this.#r.set(t.window,t),this.#n.set(t.url,t),t};#j=e=>{if(typeof e=="string")return this.#s.get(e);const t=this.#r.get(e);return t||Array.from(this.#s.values()).find(i=>i.domElement===e)};#C=e=>e.openMode===g.Embed&&(!e.domElement||!e.domElement.isConnected);#M=e=>{this.#c.get(e)?.forEach(i=>{Promise.resolve(i({id:e})).catch(X)})};#O=e=>{this.#s.has(e)&&(this.#b.has(e)||(this.#b.add(e),this.#M(e)),this.#u.has(e)||this.#x(e))};#ie=e=>{const t=e.domElement,i=t?.parentNode;if(!t||!i)return;const s=new MutationObserver(()=>{this.#C(e)&&(this.#_(e.id),this.#O(e.id))});s.observe(i,{childList:!0}),this.#g.set(e.id,s)};#_=e=>{this.#g.get(e)?.disconnect(),this.#g.delete(e)};#se=()=>{this.#g.forEach(e=>e.disconnect()),this.#g.clear()};#m=e=>{try{return!!e?.closed}catch{return!0}};#ne=()=>{this.#d||(this.#d=setInterval(()=>{const e=[];this.#s.forEach(t=>{t.openMode===g.Popup&&this.#m(t.window)&&e.push(t)}),e.forEach(t=>{this.#O(t.id)})},1e3))};#re=()=>{if(!this.#d)return;Array.from(this.#s.values()).some(t=>t.openMode===g.Popup)||(clearInterval(this.#d),this.#d=null)};#oe=e=>{const t=D(e),i=t?void 0:U();return{popupUrl:i?`${e}#hs=${i}`:e,handshakeToken:i,trusted:t}};#L=e=>!e||!this.#m(e.window)?e:(this.#u.has(e.id)||this.#O(e.id),this.#y(e.url)===e&&this.#ae(e),this.#y(e.url)===e?e:null);#ae=e=>{this.#b.has(e.id)||(this.#b.add(e.id),this.#M(e.id)),this.#N(e)};#ce=(e,t)=>{e===g.Popup&&this.#L(this.#y(t))};#de=e=>{const{url:t,title:i,popupWindowFeatures:s={},searchParams:r,guestId:o,handshakeRetries:a,onLoad:c,onError:d}=e,{width:l=800,height:h=600,top:E=100,left:j=100}=s;let m=this.#L(this.#y(t));if(m)D(t)?window.open("",i):m.window.focus();else{const w=Object.entries({width:l,height:h,top:E,left:j}).filter(([,T])=>T).map(([T,ke])=>`${T}=${ke}`).join(","),{popupUrl:v,handshakeToken:u,trusted:k}=this.#oe(t),b=this.#le({popupUrl:v,title:i,guestId:o,features:`popup, ${w}`,retryClosedWindow:!k});if(!b)throw this.#S(o,d,"onError"),new Error("Failed to open guest application in popup window");this.#S(o,c,"onLoad"),k||(b.opener=null),m=this.#R({guestId:o,window:b,title:i,url:t,searchParams:r,openMode:g.Popup,handshakeToken:u,handshakeRetries:a}),this.#ne()}return m};#le=e=>{const{popupUrl:t,title:i,guestId:s,features:r,retryClosedWindow:o}=e;let a=i,c=window.open(t,a,r);return o&&c&&this.#m(c)&&(a=`${i}-${s}`,c=window.open(t,a,r)),!c||o&&this.#m(c)?null:c};#S=(e,t,i)=>{setTimeout(()=>{try{t?.(e)}catch(s){this.#e.debug(`Error occurred in ${i} for guest with id '${e}': ${s.message}`)}},0)};#he=(e,t,i={})=>{const{onLoad:s,onError:r}=i,o=()=>{this.#S(t,s,"onLoad"),this.#e.debug(`frame loaded for guest with id '${t}'`),e.removeEventListener("load",o)},a=()=>{this.#S(t,r,"onError"),this.#e.error(`frame load failed for guest with id '${t}'`),e.removeEventListener("error",a)};e.addEventListener("load",o),e.addEventListener("error",a)};#ue=e=>{const{url:t,title:i,targetElement:s,searchParams:r,guestId:o,onLoad:a,onError:c,options:d={}}=e,l=s.ownerDocument??document,{fitToContent:h=!1,disableSandbox:E=!1,sandboxValues:j=[],customSandboxValues:m=[],style:w="",permissionPolicy:v=""}=d;if(!i)throw new Error("title is required");const u=l.createElement("iframe");u.setAttribute("id",o),this.#he(u,o,{onLoad:a,onError:c}),u.setAttribute("style",`min-width: 100%; height: 100%; border: 0px; ${w}`),E||u.setAttribute("sandbox",m.length>0?m.join(" "):[...J,...j].join(" ")),u.setAttribute("title",i),u.setAttribute("src",t),v&&u.setAttribute("allow",v),s.appendChild(u);const k=l.getElementById(o),b=this.#R({guestId:o,domElement:k,window:k.contentWindow,title:i,url:t,searchParams:r,openMode:g.Embed});return h&&this.#Q(b.id),this.#ie(b),b};#pe=(e,t)=>{let i="";return Object.keys(t).forEach(s=>{i+=`${(i.length?"&":"")+encodeURIComponent(s)}=${encodeURIComponent(t[s])}`}),e+(i?(e.indexOf("?")>=0?"&":"?")+i:"")};addScriptingObject=(e,t)=>{if(B(e)){const i=this.cloneScriptingObject(e);this.#a.addScriptingObject(i,t)}else this.#a.addScriptingObject(e,t)};cloneScriptingObject=e=>{if(!e)throw new Error("proxy is required");const t=new P(e.id,e.objectType);let i=[];return Object.keys(e).forEach(s=>{const r=e[s];if(this.#te(r)){const o=new O({name:r.name||s,objectId:t.id});if(Object.defineProperty(t,s,{value:o,enumerable:!0}),r instanceof R){const a=({eventParams:d,eventOptions:l})=>this.dispatchEvent({event:o,eventParams:d,eventOptions:l}),c=r.subscribe(a);i.push(()=>{r.unsubscribe(c)})}else{const a=r.subscribe?.((c,d,l)=>this.dispatchEvent({event:o,eventParams:d,eventOptions:l}));i.push(()=>{r.unsubscribe?.(a)})}}else if(_(r)&&(Object.defineProperty(t,s,{value:async(...o)=>{const a=t[s]?.callContext;if(a?.guest){const d=a.callChain??[],l=a.guest.id,h=this.#v.get(l),E={id:l};h&&(E.metadata=h),Object.defineProperty(r,"callContext",{value:{callChain:[...d,E]},configurable:!0,enumerable:!0,writable:!0})}const c=await r(...o);return B(c)?this.cloneScriptingObject(c):c},enumerable:!0}),s==="dispose")){const o=t.dispose;Object.defineProperty(t,s,{value:()=>(t._dispose(),o.apply(t)),enumerable:!0})}}),t._dispose=()=>{i.forEach(s=>{s?.()}),i=[]},t};close=()=>{this.#d&&(clearInterval(this.#d),this.#d=null),this.#se(),this.#w(),this.#l.clear(),this.#b.clear(),this.#U(),this.#c.clear(),this.removeAllScriptingObjects(),this.#v.clear(),this.#t.close(),window.removeEventListener("beforeunload",this.#w),window.removeEventListener("pagehide",this.#w),this.#e.debug(`host is closed. hostId: ${this.hostId}, correlationId: ${this.#i}`)};#ge=({targetGuest:e,guestCapabilities:t,scriptingEventId:i,dispatchToGuest:s})=>{const r=o=>{if(H(t)&&!we(o.capabilities,t)){this.#e.debug({message:"Event skipped \u2014 guest capabilities do not match eventOptions.guestCapabilities",scriptingEventId:i,guestCapabilities:t,...o.getInfo()});return}s(o)};e?r(e):this.#s.forEach(r)};#fe=(e,t)=>(t?this.getScriptingObject(e,{guest:t}):this.getScriptingObject(e))??(e===V&&t?Se:null);dispatchEvent=async e=>{const{event:{id:t,name:i},eventParams:s,eventOptions:r={}}=e,{eventHandler:o=null,timeout:a=null,window:c=null,guestId:d,guestCapabilities:l}=r,h=t.split(".")[0],E=d||c,j=E?this.#j(E):null,m=this.#fe(h,j??null);if(!m)return this.#e.warn(`Attempt to dispatch event ${i} on unknown object ${h}`),Promise.resolve([]);const w={object:m._toJSON(),eventName:i,eventParams:s,eventHandler:o,eventOptions:{allowsFeedback:!1}};a&&!Number.isNaN(a)&&(w.eventOptions={allowsFeedback:!0,timeout:Number(a)});const v=[];let u;const k=b=>{const T=b.getInfo();a&&b?.capabilities?.eventFeedback?(v.push(b.dispatchEvent(w,a)),!u&&this.#h.enabled&&(u=this.#h.start(`ScriptingObject.Event.${m.id}.${i}`,{appId:this.hostId,appUrl:window.location.href})),this.#e.debug({message:"Event dispatched and awaiting feedback",scriptingEventId:t,...T})):(b.send({messageType:p.ObjectEvent,messageBody:w}),this.#e.debug({message:"Event dispatched",scriptingEventId:t,...T}))};return this.#ge({targetGuest:j??null,guestCapabilities:l,scriptingEventId:t,dispatchToGuest:k}),Promise.all(v).then(b=>(this.#e.debug({message:"Event feedback received",scriptingEventId:t}),te(b))).catch(b=>{throw this.#e.error({message:"Error processing event",eventId:t,exception:b}),b}).finally(()=>{u&&this.#h.end(u,{appId:this.hostId,appUrl:window.location.href})})};getGuests=()=>Array.from(this.#s.values());getScriptingObject=(e,t)=>this.#a.getObject(e,t?.guest);loadGuest=e=>{const{id:t,url:i,targetElement:s,title:r,searchParams:o={},onLoad:a,onError:c,options:d={},metadata:l}=e;if(!t)throw new Error("id for guest application is required");const{openMode:h=g.Embed,popupWindowFeatures:E={},handshakeRetries:j}=d,m=this.#pe(i,o);this.#ce(h,m);let w=t;if(this.#s.has(w)){let u=1;for(;this.#s.has(`${t}-${u}`);)u+=1;w=`${t}-${u}`}let v=null;if(this.#h.start("SSF.Guest.Load",{appId:w,appUrl:m}),h===g.Popup)v=this.#de({guestId:w,url:m,title:r,searchParams:o,popupWindowFeatures:E,handshakeRetries:j,onLoad:a,onError:c});else if(h===g.Embed)v=this.#ue({guestId:w,url:m,title:r,targetElement:s,searchParams:o,onLoad:a,onError:c,options:d});else throw new Error(`Invalid openMode: ${h}`);return l&&this.#v.set(w,l),this.#e.audit({message:"Guest loaded",...v.getInfo()}),v};loadGuests=e=>{const{id:t,url:i,targetElement:s,title:r,searchParamsList:o=[],options:a={}}=e;o.forEach((c,d)=>{this.loadGuest({id:`${t}-${d}`,url:i,title:r,targetElement:s,searchParams:c,options:a})},this)};removeAllScriptingObjects=e=>{this.#a.removeAllScriptingObjects(e)};removeScriptingObject=(e,t)=>{this.#a.removeScriptingObject(e,t)};setLogLevel=e=>{this.#e.setLogLevel(e),this.#s.forEach(this.#A),this.#e.debug("Dispatched config events to all guests")};#D=async(e,t,i)=>this.dispatchEvent({event:{id:t,name:i},eventParams:{moduleId:e.id},eventOptions:{timeout:Oe,guestId:e.id}});#be=async e=>{try{const t=await this.#D(e,ve,"unloading");if(je(t))return this.#e.info(`Unload denied by guest ${e.id} via module.unloading event`),!1}catch(t){this.#e.warn({message:`Error dispatching module.unloading event for ${e.id}; proceeding with unload`,exception:t})}return!0};#me=async e=>{try{await this.#D(e,ye,"unmount")}catch(t){this.#e.warn({message:`Error dispatching module.unmount event for ${e.id}`,exception:t})}};#x=e=>{this.unloadGuest(e).catch(X)};#N=e=>{e.dispose(),this.#r.get(e.window)===e&&this.#r.delete(e.window),this.#n.get(e.url)===e&&this.#n.delete(e.url),this.#s.get(e.id)===e&&(this.#_(e.id),this.#Z(e.id),this.removeAllScriptingObjects(e.id),this.#v.delete(e.id),this.#s.delete(e.id),this.#c.delete(e.id),this.#b.delete(e.id)),this.#e.audit({message:"Guest is removed from host",...e.getInfo()}),this.#re()};unloadGuest=async e=>{const t=this.#j(e);if(t&&!this.#u.has(t.id)){this.#u.add(t.id);try{const i=t.openMode===g.Popup?this.#m(t.window):!!t.window?.closed,s=this.#f.has(t.id);if(!(i||this.#C(t)||s)){if(!await this.#be(t)){this.#b.delete(t.id);return}await this.#me(t)}this.#N(t)}finally{this.#u.delete(t.id),this.#f.delete(t.id)}}};onGuestClose=e=>{const{id:t,guestCloseCallback:i}=e,s=this.#c.get(t)||[];s.push(i),this.#c.set(t,s)}}return I})());
|
|
2
2
|
|
|
3
3
|
//# sourceMappingURL=index.js.map
|
package/dist/umd/index.js.br
CHANGED
|
Binary file
|
package/dist/umd/index.js.gz
CHANGED
|
Binary file
|