@elliemae/ssf-host 2.29.1 → 2.30.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/host.js +5 -2
- package/dist/cjs/utils.js +8 -1
- package/dist/esm/host.js +5 -2
- package/dist/esm/utils.js +8 -1
- 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.14d0a39ec7aadb5abeef.js +3 -0
- package/dist/public/js/emuiSsfHost.14d0a39ec7aadb5abeef.js.br +0 -0
- package/dist/public/js/emuiSsfHost.14d0a39ec7aadb5abeef.js.gz +0 -0
- package/dist/public/js/emuiSsfHost.14d0a39ec7aadb5abeef.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.e05998eeb058c9f027f1.js +0 -3
- package/dist/public/js/emuiSsfHost.e05998eeb058c9f027f1.js.br +0 -0
- package/dist/public/js/emuiSsfHost.e05998eeb058c9f027f1.js.gz +0 -0
- package/dist/public/js/emuiSsfHost.e05998eeb058c9f027f1.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";var 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.prototype.hasOwnProperty.call(n,e),O.r=n=>{typeof Symbol<"u"&&Symbol.toStringTag&&Object.defineProperty(n,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(n,"__esModule",{value:!0})};var k={};O.r(k),O.d(k,{Event:()=>S,Guest:()=>q,IFrameSandboxValues:()=>j,OnDuplicate:()=>C,OpenMode:()=>b,SANDBOX_DEFAULT:()=>V,SSFHost:()=>Oe,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 _{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 X=n=>n instanceof S,Se=(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];X(s)?t.push(i):Q(s,i)&&e.push(i)}),{objectId:this.#t,objectType:this.#i,functions:e,events:t}};_dispose=()=>{};dispose=()=>{}}const M="module";var je=null,C=(n=>(n.THROW="throw",n.IGNORE="ignore",n))(C||{});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},a=this.#e.get(i);if(!a){this.#e.set(i,new Map([[o,c]]));return}if(a.has(o)){if(s==="ignore")return;throw new Error(`Scripting Object ${t.id} already exists for guest ${i}`)}a.set(o,c)};#s=({so:e})=>{if(e._dispose&&typeof e._dispose=="function")try{e._dispose()}catch{}};#n=({objectId:e,guestId:t})=>{if(e===M&&!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};#r=({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===M&&!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.#n({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.#r({objectId:i,guestId:t});else{this.#r({objectId:i});const s=this.#i.get(i);s&&this.#s(s),this.#i.delete(i)}};removeAllScriptingObjects=e=>{e?this.#r({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||{}),b=(n=>(n.Popup="popup",n.Embed="embed",n))(b||{}),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 L(n){return typeof n=="function"}const ie=[".ice.com",".elliemae.com",".ellielabs.com"],se=["localhost","127.0.0.1"],x=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=x(window.location.hostname),t=x(n);return e===t},D=n=>{try{const{hostname:e}=new URL(n,document.baseURI);return ne(e)||re(e)}catch{return!1}};class q{id;title;url;searchParams;domElement;window;openMode;origin;initialized=!1;ready=!1;capabilities;#t;#i;#e;constructor(e){const{guestId:t,domElement:i=null,title:s,url:r,window:o,searchParams:c={},openMode:a=b.Embed,remoting:u,perfTracker:l,handshakeToken:d}=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=a,this.capabilities={},this.#i=l,this.#t=u,this.#e=d}dispose=()=>{if(this.openMode===b.Popup&&!this.window.closed)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});handShake=()=>new Promise(e=>{let t=0;const i=5;let s;const r=()=>{clearInterval(s),this.#t.unlisten({messageType:g.HandShakeAck,callback:r}),e(!0)};s=setInterval(()=>{t>=i?(clearInterval(s),this.#t.unlisten({messageType:g.HandShakeAck,callback:r}),e(!1)):(this.#t.send({targetWin:this.window,targetOrigin:this.origin,messageType:g.HandShake,messageBody:this.#e?{handshakeToken:this.#e}:{}}),t+=1)},1e3),this.#t.listen({messageType:g.HandShakeAck,callback:r})});init=()=>{this.#t.addSender({origin:this.origin,window:this.window}),this.openMode===b.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 N={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};let A;const oe=new Uint8Array(16);function ce(){if(!A&&(A=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!A))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return A(oe)}var ae;const f=[];for(let n=0;n<256;++n)f.push((n+256).toString(16).slice(1));function F(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 ke(n,e=0){const t=F(n,e);if(!ae(t))throw TypeError("Stringified UUID is invalid");return t}const Te=null;function ue(n,e,t){if(N.randomUUID&&!e&&!n)return N.randomUUID();n=n||{};const i=n.random||(n.rng||ce)();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 F(i)}const G=ue,W="elli:remoting",B="elli:remoting:response",z="elli:remoting:exception",$=({messageType:n,messageBody:e,requestId:t,onewayMsg:i=!1})=>({requestId:t??(i?null:G()),source:W,type:n,body:e}),$e=n=>{const{targetWin:e,targetOrigin:t,messageType:i,messageBody:s}=n,r=$({messageType:i,messageBody:s});e.postMessage(r,t)};class le{#t;#i;#e=new Map;#o=new Map;#s=null;#n=null;#r=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}#h=()=>{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.#a(s)}};#a=e=>{this.#s===null&&(this.#s=window.setTimeout(this.#h,e))};#g=()=>{this.#s!==null&&(window.clearTimeout(this.#s),this.#s=null)};#u=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.#u(t);return i?(i.resolve(e.body),!0):(this.#i.debug(`Received response to stale/invalid request with requestId: ${t}`),!1)};#f=e=>{this.#i.debug(`Exception received for invocation (requestId = ${e.requestId})`);const t=this.#u(e.requestId);return t?(t.reject(new Error(e.body)),!0):(this.#i.warn(`Received exception for stale/invalid request (requestId = ${e.requestId})`),!1)};#d=({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};#c=e=>{if(this.#r.size===0||!e.source)return!1;const t=this.#r.get(e.source);return!t||e?.data?.source!==W?!1:(this.#i.debug(`Remoting: Received message of type "${e.data.type}"`),e.data.type===B?this.#p(e.data):e.data.type===z?this.#f(e.data):this.#d({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.#r.set(i,t)};initialize=e=>{this.#n&&this.#n.removeEventListener("message",this.#c),e.addEventListener("message",this.#c),this.#n=e,this.#i.debug(`initialized remoting id: ${this.#t}`)};close=()=>{this.#n&&(this.#n.removeEventListener("message",this.#c),this.#n=null),this.#g(),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,a)=>{const u=$({messageType:s,messageBody:r});this.#o.set(u.requestId,{requestId:u.requestId,resolve:c,reject:a,cancelTime:o?Date.now()+o:null}),t.postMessage(u,i);const{requestId:l}=u;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.#r.delete(t)};respond=e=>{const{targetWin:t,targetOrigin:i,requestId:s,response:r}=e,o=$({messageType:B,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 Ue{__TYPE__="Proxy";id;objectType;constructor(e,t){this.id=e,this.objectType=t}}const H=n=>n?.constructor?.name==="Proxy"||n?.constructor?.name==="ScriptingObjectProxy"||n?.__TYPE__==="Proxy",de=new Map;function Ae(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 he(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??de;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 J(n){return n!=null&&Object.keys(n).length>0}function ge(n,e,t){return Object.entries(e).every(([i,s])=>he(n[i],s,t?.regexCache))}const Pe=null;function pe(n,e){return J(e)?ge(n,e):!0}const fe=new Set(["SSF.Guest.Load"]);class U{#t;#i;#e;#o=new Set;#s;#n=new Map;#r;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??U.DEFAULT_SAMPLING_RATIO,this.#s=e.dedupWindowMs??U.DEFAULT_DEDUP_WINDOW_MS,this.#r=e.onError}get enabled(){return this.#i}start(e,t){if(this.#i)try{const i=fe.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.#r?.(e)}catch{}}shouldTrack(e){if(this.#s<=0)return!0;const t=performance.now(),i=this.#n.get(e);return i!==void 0&&t-i<this.#s?!1:(this.#n.set(e,t),!0)}}const V=[j.AllowScripts,j.AllowPopups,j.AllowModals,j.AllowForms,j.AllowDownloads,j.AllowSameOrigin],Y="module",be="module.unloading",me="module.unmount",we=1e3,Ee=new P(Y),ve=n=>Array.isArray(n)&&n.some(e=>e===!1),ye=()=>{};class Oe{hostId;#t;#i;#e;#o;#s=new Map;#n=new Map;#r=new Map;#h=new Map;#a;#g=null;#u=null;#p=null;#f=null;#d=new Map;#c;#E;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.#c=new U({...i,dedupWindowMs:t?.performanceDedupWindowMs}),this.#E=new U({...i,dedupWindowMs:0}),this.#i=G(),this.#t=new le(this.#e,this.#i),t?.readyStateCallback&&typeof t?.readyStateCallback!="function")throw new Error("readyStateCallback must be a function");this.#g=t?.readyStateCallback||null,this.#p=t?.onGuestEventSubscribe||null,this.#f=t?.onGuestEventUnsubscribe||null,this.#a=new Z,this.#t.initialize(window),this.#L(),window.addEventListener("beforeunload",this.#b),this.#e.debug(`host is initialized. hostId: ${this.hostId}, correlationId: ${this.#i}`)}#Y=(e,t)=>{const i={event:e,...t};this.#o.sendBAEvent(i).catch(s=>{this.#e.debug(`Analytics sendBAEvent failed: ${s.message}`)})};#b=()=>{Array.from(this.#s.values()).filter(t=>t.openMode===b.Popup).map(t=>t.id).forEach(t=>this.#w(t))};#l=e=>this.#n.get(e);#I=e=>this.#r.get(e)??null;#k=e=>typeof e?._toJSON=="function";#v=(e,t)=>this.#k(e)?(this.#a.has(e?.id,t)||this.#a.addScriptingObject(e,t?{guestId:t?.id}:{}),{type:"object",object:e._toJSON()}):{type:"value",value:e};#X=e=>typeof e=="string"?e:e instanceof Error?e.message:"An unexpected error occurred in the host application";#y=e=>{e.ready&&this.#t.send({targetWin:e.window,targetOrigin:e.origin,messageType:g.HostConfig,messageBody:{logLevel:this.#e.getLogLevel(),...e.getInfo()}})};#T=({guest:e,obj:t,functionName:i,functionParams:s,callerChain:r})=>{const o=t[i];return L(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}'`)))};#O=({sourceWin:e,sourceOrigin:t,requestId:i})=>{const s=this.#l(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.#c.end("SSF.Guest.Load",{appId:r.guestId,appUrl:r.guestUrl}),this.#y(s),this.#g?.(s),this.#e.audit({message:"Guest is ready",...r})}};#$=({sourceWin:e,sourceOrigin:t,requestId:i,body:s})=>{const r=this.#l(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.#O({sourceWin:e,sourceOrigin:t,requestId:i,type:"",body:null})};#U=async({sourceWin:e})=>{if(e?.window){const t=this.#m(e);t&&!await t.handShake()&&this.#w(e)}};#A=({sourceWin:e,sourceOrigin:t,requestId:i})=>{this.#e.debug(`Processing listObjects request. requestId = ${i}`);const s=this.#l(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};#P=({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.#l(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.#v(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)};#G=({sourceWin:e,requestId:t,body:i})=>{const{eventId:s,criteria:r,token:o}=i;this.#e.debug(`Processing guest event subscribe request for event ${s}. requestId = ${t}`);const c=this.#l(e);if(!c){this.#e.warn("Rejected event subscribe request from unknown guest window");return}setTimeout(()=>{try{this.#p?.({guestId:c.id,eventId:s,criteria:r,token:o})}catch(a){this.#e.warn(`Error in onGuestEventSubscribe callback for event ${s}: ${a.message}`)}},0)};#R=({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.#l(e);if(!o){this.#e.warn("Rejected event unsubscribe request from unknown guest window");return}setTimeout(()=>{try{this.#f?.({guestId:o.id,eventId:s,token:r})}catch(c){this.#e.warn(`Error in onGuestEventUnsubscribe callback for event ${s}: ${c.message}`)}},0)};#_=({sourceWin:e,requestId:t,body:i})=>{const s=this.#l(e);if(!s){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}`)};#M=({sourceWin:e,sourceOrigin:t,requestId:i,body:s})=>{const{objectId:r,callerChain:o}=s,c=this.#l(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 a=this.getScriptingObject(r,{guest:c});if(!a)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 u=c.getInfo();let l;if(this.#c.enabled){const d=`ScriptingObject.API.${r}.${s.functionName}`;l=this.#c.start(d,{appId:u.guestId,appUrl:u.guestUrl})}return this.#T({guest:c,obj:a,functionName:s.functionName,functionParams:s.functionParams,callerChain:o}).then(d=>{this.#t.respond({targetWin:e,targetOrigin:t,requestId:i,response:this.#v(d,c)}),this.#e.debug({message:"Value returned for Scripting Object method call",requestId:i,scriptingObject:r,scriptingMethod:s.functionName,...u})}).catch(d=>{this.#t.raiseException({targetWin:e,targetOrigin:c.origin,requestId:i,ex:d}),this.#e.error({message:"Exception thrown for Scripting Object method call",requestId:i,scriptingObject:r,scriptingMethod:s.functionName,...u})}).finally(()=>{l&&this.#c.end(l,{appId:u.guestId,appUrl:u.guestUrl})}),!0};#C=()=>{this.#t.listen({messageType:g.GuestResize,callback:this.#_})};#L=()=>{this.#t.listen({messageType:g.GuestReady,callback:this.#$}),this.#t.listen({messageType:g.GuestReadyComplete,callback:this.#O}),this.#t.listen({messageType:g.GuestClose,callback:this.#U}),this.#t.listen({messageType:g.ListObjects,callback:this.#A}),this.#t.listen({messageType:g.ObjectGet,callback:this.#P}),this.#t.listen({messageType:g.ObjectInvoke,callback:this.#M}),this.#t.listen({messageType:g.GuestEventSubscribe,callback:this.#G}),this.#t.listen({messageType:g.GuestEventUnsubscribe,callback:this.#R})};#x=e=>e instanceof _||typeof e?.subscribe=="function";#S=e=>{const t=new q({...e,remoting:this.#t,perfTracker:this.#E});return t.init(),this.#s.set(e.guestId,t),this.#n.set(t.window,t),this.#r.set(t.url,t),t};#m=e=>{if(typeof e=="string")return this.#s.get(e);const t=this.#n.get(e);return t||Array.from(this.#s.values()).find(i=>i.domElement===e)};#D=()=>{this.#u||(this.#u=setInterval(()=>{const e=[];this.#s.forEach(t=>{t.openMode===b.Popup&&t.window.closed&&e.push(t)}),e.forEach(t=>{const{id:i}=t;this.#w(i),this.#h.get(i)?.forEach(r=>{Promise.resolve(r({id:i})).catch(()=>{})})})},1e3))};#q=()=>{if(!this.#u)return;Array.from(this.#s.values()).some(t=>t.openMode===b.Popup)||(clearInterval(this.#u),this.#u=null)};#N=e=>{const t=D(e),i=t?void 0:G();return{popupUrl:i?`${e}#hs=${i}`:e,handshakeToken:i,trusted:t}};#F=e=>{const{url:t,title:i,popupWindowFeatures:s={},searchParams:r,guestId:o,onLoad:c,onError:a}=e,{width:u=800,height:l=600,top:d=100,left:m=100}=s;let w=this.#I(t);if(w)w.window.closed||(D(t)?window.open("",i):w.window.focus());else{const E=Object.entries({width:u,height:l,top:d,left:m}).filter(([,h])=>h).map(([h,T])=>`${h}=${T}`).join(","),{popupUrl:v,handshakeToken:y,trusted:p}=this.#N(t),I=window.open(v,i,`popup, ${E}`);if(I)setTimeout(()=>{try{c?.(o)}catch(h){this.#e.debug(`Error occurred in onLoad for guest with id '${o}': ${h.message}`)}},0);else throw setTimeout(()=>{try{a?.(o)}catch(h){this.#e.debug(`Error occurred in onError for guest with id '${o}': ${h.message}`)}},0),new Error("Failed to open guest application in popup window");p||(I.opener=null),w=this.#S({guestId:o,window:I,title:i,url:t,searchParams:r,openMode:b.Popup,handshakeToken:y}),this.#D()}return w};#W=e=>{const{url:t,title:i,targetElement:s,searchParams:r,guestId:o,onLoad:c,onError:a,options:u={}}=e,l=s.ownerDocument??document,{fitToContent:d=!1,disableSandbox:m=!1,sandboxValues:w=[],customSandboxValues:E=[],style:v="",permissionPolicy:y=""}=u;if(!i)throw new Error("title is required");d&&this.#C();const p=l.createElement("iframe");p.setAttribute("id",o);const I=()=>{setTimeout(()=>{try{c?.(o)}catch(R){this.#e.debug(`Error occurred in onLoad for guest with id '${o}': ${R.message}`)}},0),this.#e.debug(`frame loaded for guest with id '${o}'`),p.removeEventListener("load",I)},h=()=>{setTimeout(()=>{try{a?.(o)}catch(R){this.#e.debug(`Error occurred in onError for guest with id '${o}': ${R.message}`)}},0),this.#e.error(`frame load failed for guest with id '${o}'`),p.removeEventListener("error",h)};p.addEventListener("load",I),p.addEventListener("error",h),p.setAttribute("style",`min-width: 100%; height: 100%; border: 0px; ${v}`),m||p.setAttribute("sandbox",E.length>0?E.join(" "):[...V,...w].join(" ")),p.setAttribute("title",i),p.setAttribute("src",t),y&&p.setAttribute("allow",y),s.appendChild(p);const T=l.getElementById(o);return this.#S({guestId:o,domElement:T,window:T.contentWindow,title:i,url:t,searchParams:r,openMode:b.Embed})};#B=(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(H(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.#x(r)){const o=new S({name:r.name||s,objectId:t.id});if(Object.defineProperty(t,s,{value:o,enumerable:!0}),r instanceof _){const c=({eventParams:u,eventOptions:l})=>this.dispatchEvent({event:o,eventParams:u,eventOptions:l}),a=r.subscribe(c);i.push(()=>{r.unsubscribe(a)})}else{const c=r.subscribe?.((a,u,l)=>this.dispatchEvent({event:o,eventParams:u,eventOptions:l}));i.push(()=>{r.unsubscribe?.(c)})}}else if(L(r)&&(Object.defineProperty(t,s,{value:async(...o)=>{const c=t[s]?.callContext;if(c?.guest){const u=c.callChain??[],l=c.guest.id,d=this.#d.get(l),m={id:l};d&&(m.metadata=d),Object.defineProperty(r,"callContext",{value:{callChain:[...u,m]},configurable:!0,enumerable:!0,writable:!0})}const a=await r(...o);return H(a)?this.cloneScriptingObject(a):a},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.#u&&(clearInterval(this.#u),this.#u=null),this.#b(),this.#d.clear(),this.#t.close(),window.removeEventListener("beforeunload",this.#b),this.#e.debug(`host is closed. hostId: ${this.hostId}, correlationId: ${this.#i}`)};#z=({targetGuest:e,guestCapabilities:t,scriptingEventId:i,dispatchToGuest:s})=>{const r=o=>{if(J(t)&&!pe(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)};#H=(e,t)=>(t?this.getScriptingObject(e,{guest:t}):this.getScriptingObject(e))??(e===Y&&t?Ee:null);dispatchEvent=async e=>{const{event:{id:t,name:i},eventParams:s,eventOptions:r={}}=e,{eventHandler:o=null,timeout:c=null,window:a=null,guestId:u,guestCapabilities:l}=r,d=t.split(".")[0],m=u||a,w=m?this.#m(m):null,E=this.#H(d,w??null);if(!E)return this.#e.warn(`Attempt to dispatch event ${i} on unknown object ${d}`),Promise.resolve([]);const v={object:E._toJSON(),eventName:i,eventParams:s,eventHandler:o,eventOptions:{allowsFeedback:!1}};c&&!Number.isNaN(c)&&(v.eventOptions={allowsFeedback:!0,timeout:Number(c)});const y=[];let p;const I=h=>{const T=h.getInfo();c&&h?.capabilities?.eventFeedback?(y.push(h.dispatchEvent(v,c)),!p&&this.#c.enabled&&(p=this.#c.start(`ScriptingObject.Event.${E.id}.${i}`,{appId:this.hostId,appUrl:window.location.href})),this.#e.debug({message:"Event dispatched and awaiting feedback",scriptingEventId:t,...T})):(h.send({messageType:g.ObjectEvent,messageBody:v}),this.#e.debug({message:"Event dispatched",scriptingEventId:t,...T}))};return this.#z({targetGuest:w??null,guestCapabilities:l,scriptingEventId:t,dispatchToGuest:I}),Promise.all(y).then(h=>(this.#e.debug({message:"Event feedback received",scriptingEventId:t}),te(h))).catch(h=>{throw this.#e.error({message:"Error processing event",eventId:t,exception:h}),h}).finally(()=>{p&&this.#c.end(p,{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:c,onError:a,options:u={},metadata:l}=e;if(!t)throw new Error("id for guest application is required");let d=t;if(this.#s.has(d)){let y=1;for(;this.#s.has(`${t}-${y}`);)y+=1;d=`${t}-${y}`}const{openMode:m=b.Embed,popupWindowFeatures:w={}}=u,E=this.#B(i,o);let v=null;if(this.#c.start("SSF.Guest.Load",{appId:d,appUrl:E}),m===b.Popup)v=this.#F({guestId:d,url:E,title:r,searchParams:o,popupWindowFeatures:w,onLoad:c,onError:a});else if(m===b.Embed)v=this.#W({guestId:d,url:E,title:r,targetElement:s,searchParams:o,onLoad:c,onError:a,options:u});else throw new Error(`Invalid openMode: ${m}`);return l&&this.#d.set(d,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((a,u)=>{this.loadGuest({id:`${t}-${u}`,url:i,title:r,targetElement:s,searchParams:a,options:c})},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.#y),this.#e.debug("Dispatched config events to all guests")};#j=async(e,t,i)=>this.dispatchEvent({event:{id:t,name:i},eventParams:{moduleId:e.id},eventOptions:{timeout:we,guestId:e.id}});#J=async e=>{try{const t=await this.#j(e,be,"unloading");if(ve(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};#V=async e=>{try{await this.#j(e,me,"unmount")}catch(t){this.#e.warn({message:`Error dispatching module.unmount event for ${e.id}`,exception:t})}};#w=e=>{this.unloadGuest(e).catch(ye)};unloadGuest=async e=>{const t=this.#m(e);t&&await this.#J(t)&&(await this.#V(t),t.dispose(),this.#n.delete(t.window),this.#r.delete(t.url),this.#d.delete(t.id),this.#s.delete(t.id),this.#e.audit({message:"Guest is removed from host",...t.getInfo()}),this.#q())};onGuestClose=e=>{const{id:t,guestCloseCallback:i}=e,s=this.#h.get(t)||[];s.push(i),this.#h.set(t,s)}}return k})());
|
|
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";var 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.prototype.hasOwnProperty.call(n,e),O.r=n=>{typeof Symbol<"u"&&Symbol.toStringTag&&Object.defineProperty(n,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(n,"__esModule",{value:!0})};var k={};O.r(k),O.d(k,{Event:()=>S,Guest:()=>q,IFrameSandboxValues:()=>j,OnDuplicate:()=>C,OpenMode:()=>b,SANDBOX_DEFAULT:()=>V,SSFHost:()=>Oe,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 _{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 X=n=>n instanceof S,Se=(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];X(s)?t.push(i):Q(s,i)&&e.push(i)}),{objectId:this.#t,objectType:this.#i,functions:e,events:t}};_dispose=()=>{};dispose=()=>{}}const M="module";var je=null,C=(n=>(n.THROW="throw",n.IGNORE="ignore",n))(C||{});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},a=this.#e.get(i);if(!a){this.#e.set(i,new Map([[o,c]]));return}if(a.has(o)){if(s==="ignore")return;throw new Error(`Scripting Object ${t.id} already exists for guest ${i}`)}a.set(o,c)};#s=({so:e})=>{if(e._dispose&&typeof e._dispose=="function")try{e._dispose()}catch{}};#n=({objectId:e,guestId:t})=>{if(e===M&&!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};#r=({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===M&&!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.#n({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.#r({objectId:i,guestId:t});else{this.#r({objectId:i});const s=this.#i.get(i);s&&this.#s(s),this.#i.delete(i)}};removeAllScriptingObjects=e=>{e?this.#r({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||{}),b=(n=>(n.Popup="popup",n.Embed="embed",n))(b||{}),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 L(n){return typeof n=="function"}const ie=[".ice.com",".elliemae.com",".ellielabs.com",".elliemae.io",".ellieservices.com"],se=["localhost","127.0.0.1"],x=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=x(window.location.hostname),t=x(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}};class q{id;title;url;searchParams;domElement;window;openMode;origin;initialized=!1;ready=!1;capabilities;#t;#i;#e;constructor(e){const{guestId:t,domElement:i=null,title:s,url:r,window:o,searchParams:c={},openMode:a=b.Embed,remoting:l,perfTracker:u,handshakeToken:d}=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=a,this.capabilities={},this.#i=u,this.#t=l,this.#e=d}dispose=()=>{if(this.openMode===b.Popup&&!this.window.closed)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});handShake=()=>new Promise(e=>{let t=0;const i=5;let s;const r=()=>{clearInterval(s),this.#t.unlisten({messageType:g.HandShakeAck,callback:r}),e(!0)};s=setInterval(()=>{t>=i?(clearInterval(s),this.#t.unlisten({messageType:g.HandShakeAck,callback:r}),e(!1)):(this.#t.send({targetWin:this.window,targetOrigin:this.origin,messageType:g.HandShake,messageBody:this.#e?{handshakeToken:this.#e}:{}}),t+=1)},1e3),this.#t.listen({messageType:g.HandShakeAck,callback:r})});init=()=>{this.#t.addSender({origin:this.origin,window:this.window}),this.openMode===b.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 N={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};let U;const oe=new Uint8Array(16);function ce(){if(!U&&(U=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!U))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return U(oe)}var ae;const f=[];for(let n=0;n<256;++n)f.push((n+256).toString(16).slice(1));function F(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 ke(n,e=0){const t=F(n,e);if(!ae(t))throw TypeError("Stringified UUID is invalid");return t}const Te=null;function le(n,e,t){if(N.randomUUID&&!e&&!n)return N.randomUUID();n=n||{};const i=n.random||(n.rng||ce)();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 F(i)}const G=le,W="elli:remoting",B="elli:remoting:response",z="elli:remoting:exception",$=({messageType:n,messageBody:e,requestId:t,onewayMsg:i=!1})=>({requestId:t??(i?null:G()),source:W,type:n,body:e}),$e=n=>{const{targetWin:e,targetOrigin:t,messageType:i,messageBody:s}=n,r=$({messageType:i,messageBody:s});e.postMessage(r,t)};class ue{#t;#i;#e=new Map;#o=new Map;#s=null;#n=null;#r=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}#h=()=>{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.#a(s)}};#a=e=>{this.#s===null&&(this.#s=window.setTimeout(this.#h,e))};#g=()=>{this.#s!==null&&(window.clearTimeout(this.#s),this.#s=null)};#l=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.#l(t);return i?(i.resolve(e.body),!0):(this.#i.debug(`Received response to stale/invalid request with requestId: ${t}`),!1)};#f=e=>{this.#i.debug(`Exception received for invocation (requestId = ${e.requestId})`);const t=this.#l(e.requestId);return t?(t.reject(new Error(e.body)),!0):(this.#i.warn(`Received exception for stale/invalid request (requestId = ${e.requestId})`),!1)};#d=({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};#c=e=>{if(this.#r.size===0||!e.source)return!1;const t=this.#r.get(e.source);return!t||e?.data?.source!==W?!1:(this.#i.debug(`Remoting: Received message of type "${e.data.type}"`),e.data.type===B?this.#p(e.data):e.data.type===z?this.#f(e.data):this.#d({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.#r.set(i,t)};initialize=e=>{this.#n&&this.#n.removeEventListener("message",this.#c),e.addEventListener("message",this.#c),this.#n=e,this.#i.debug(`initialized remoting id: ${this.#t}`)};close=()=>{this.#n&&(this.#n.removeEventListener("message",this.#c),this.#n=null),this.#g(),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,a)=>{const l=$({messageType:s,messageBody:r});this.#o.set(l.requestId,{requestId:l.requestId,resolve:c,reject:a,cancelTime:o?Date.now()+o:null}),t.postMessage(l,i);const{requestId:u}=l;this.#i.debug(`Posted invocation message of type ${s} requestId: ${u||""}`),o&&(this.#i.debug(`scheduling timeout check for requestId: ${u||""} 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.#r.delete(t)};respond=e=>{const{targetWin:t,targetOrigin:i,requestId:s,response:r}=e,o=$({messageType:B,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 Ae{__TYPE__="Proxy";id;objectType;constructor(e,t){this.id=e,this.objectType=t}}const H=n=>n?.constructor?.name==="Proxy"||n?.constructor?.name==="ScriptingObjectProxy"||n?.__TYPE__==="Proxy",de=new Map;function Ue(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 he(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??de;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 J(n){return n!=null&&Object.keys(n).length>0}function ge(n,e,t){return Object.entries(e).every(([i,s])=>he(n[i],s,t?.regexCache))}const Pe=null;function pe(n,e){return J(e)?ge(n,e):!0}const fe=new Set(["SSF.Guest.Load"]);class A{#t;#i;#e;#o=new Set;#s;#n=new Map;#r;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.#r=e.onError}get enabled(){return this.#i}start(e,t){if(this.#i)try{const i=fe.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.#r?.(e)}catch{}}shouldTrack(e){if(this.#s<=0)return!0;const t=performance.now(),i=this.#n.get(e);return i!==void 0&&t-i<this.#s?!1:(this.#n.set(e,t),!0)}}const V=[j.AllowScripts,j.AllowPopups,j.AllowModals,j.AllowForms,j.AllowDownloads,j.AllowSameOrigin],Y="module",be="module.unloading",me="module.unmount",we=1e3,Ee=new P(Y),ve=n=>Array.isArray(n)&&n.some(e=>e===!1),ye=()=>{};class Oe{hostId;#t;#i;#e;#o;#s=new Map;#n=new Map;#r=new Map;#h=new Map;#a;#g=null;#l=null;#p=null;#f=null;#d=new Map;#c;#E;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.#c=new A({...i,dedupWindowMs:t?.performanceDedupWindowMs}),this.#E=new A({...i,dedupWindowMs:0}),this.#i=G(),this.#t=new ue(this.#e,this.#i),t?.readyStateCallback&&typeof t?.readyStateCallback!="function")throw new Error("readyStateCallback must be a function");this.#g=t?.readyStateCallback||null,this.#p=t?.onGuestEventSubscribe||null,this.#f=t?.onGuestEventUnsubscribe||null,this.#a=new Z,this.#t.initialize(window),this.#L(),window.addEventListener("beforeunload",this.#b),this.#e.debug(`host is initialized. hostId: ${this.hostId}, correlationId: ${this.#i}`)}#Y=(e,t)=>{const i={event:e,...t};this.#o.sendBAEvent(i).catch(s=>{this.#e.debug(`Analytics sendBAEvent failed: ${s.message}`)})};#b=()=>{Array.from(this.#s.values()).filter(t=>t.openMode===b.Popup).map(t=>t.id).forEach(t=>this.#w(t))};#u=e=>this.#n.get(e);#I=e=>this.#r.get(e)??null;#k=e=>typeof e?._toJSON=="function";#v=(e,t)=>this.#k(e)?(this.#a.has(e?.id,t)||this.#a.addScriptingObject(e,t?{guestId:t?.id}:{}),{type:"object",object:e._toJSON()}):{type:"value",value:e};#X=e=>typeof e=="string"?e:e instanceof Error?e.message:"An unexpected error occurred in the host application";#y=e=>{e.ready&&this.#t.send({targetWin:e.window,targetOrigin:e.origin,messageType:g.HostConfig,messageBody:{logLevel:this.#e.getLogLevel(),...e.getInfo()}})};#T=({guest:e,obj:t,functionName:i,functionParams:s,callerChain:r})=>{const o=t[i];return L(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}'`)))};#O=({sourceWin:e,sourceOrigin:t,requestId:i})=>{const s=this.#u(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.#c.end("SSF.Guest.Load",{appId:r.guestId,appUrl:r.guestUrl}),this.#y(s),this.#g?.(s),this.#e.audit({message:"Guest is ready",...r})}};#$=({sourceWin:e,sourceOrigin:t,requestId:i,body:s})=>{const r=this.#u(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.#O({sourceWin:e,sourceOrigin:t,requestId:i,type:"",body:null})};#A=async({sourceWin:e})=>{if(e?.window){const t=this.#m(e);t&&!await t.handShake()&&this.#w(e)}};#U=({sourceWin:e,sourceOrigin:t,requestId:i})=>{this.#e.debug(`Processing listObjects request. requestId = ${i}`);const s=this.#u(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};#P=({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.#u(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.#v(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)};#G=({sourceWin:e,requestId:t,body:i})=>{const{eventId:s,criteria:r,token:o}=i;this.#e.debug(`Processing guest event subscribe request for event ${s}. requestId = ${t}`);const c=this.#u(e);if(!c){this.#e.warn("Rejected event subscribe request from unknown guest window");return}setTimeout(()=>{try{this.#p?.({guestId:c.id,eventId:s,criteria:r,token:o})}catch(a){this.#e.warn(`Error in onGuestEventSubscribe callback for event ${s}: ${a.message}`)}},0)};#R=({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.#u(e);if(!o){this.#e.warn("Rejected event unsubscribe request from unknown guest window");return}setTimeout(()=>{try{this.#f?.({guestId:o.id,eventId:s,token:r})}catch(c){this.#e.warn(`Error in onGuestEventUnsubscribe callback for event ${s}: ${c.message}`)}},0)};#_=({sourceWin:e,requestId:t,body:i})=>{const s=this.#u(e);if(!s){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}`)};#M=({sourceWin:e,sourceOrigin:t,requestId:i,body:s})=>{const{objectId:r,callerChain:o}=s,c=this.#u(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 a=this.getScriptingObject(r,{guest:c});if(!a)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 l=c.getInfo();let u;if(this.#c.enabled){const d=`ScriptingObject.API.${r}.${s.functionName}`;u=this.#c.start(d,{appId:l.guestId,appUrl:l.guestUrl})}return this.#T({guest:c,obj:a,functionName:s.functionName,functionParams:s.functionParams,callerChain:o}).then(d=>{this.#t.respond({targetWin:e,targetOrigin:t,requestId:i,response:this.#v(d,c)}),this.#e.debug({message:"Value returned for Scripting Object method call",requestId:i,scriptingObject:r,scriptingMethod:s.functionName,...l})}).catch(d=>{this.#t.raiseException({targetWin:e,targetOrigin:c.origin,requestId:i,ex:d}),this.#e.error({message:"Exception thrown for Scripting Object method call",requestId:i,scriptingObject:r,scriptingMethod:s.functionName,...l})}).finally(()=>{u&&this.#c.end(u,{appId:l.guestId,appUrl:l.guestUrl})}),!0};#C=()=>{this.#t.listen({messageType:g.GuestResize,callback:this.#_})};#L=()=>{this.#t.listen({messageType:g.GuestReady,callback:this.#$}),this.#t.listen({messageType:g.GuestReadyComplete,callback:this.#O}),this.#t.listen({messageType:g.GuestClose,callback:this.#A}),this.#t.listen({messageType:g.ListObjects,callback:this.#U}),this.#t.listen({messageType:g.ObjectGet,callback:this.#P}),this.#t.listen({messageType:g.ObjectInvoke,callback:this.#M}),this.#t.listen({messageType:g.GuestEventSubscribe,callback:this.#G}),this.#t.listen({messageType:g.GuestEventUnsubscribe,callback:this.#R})};#x=e=>e instanceof _||typeof e?.subscribe=="function";#S=e=>{const t=new q({...e,remoting:this.#t,perfTracker:this.#E});return t.init(),this.#s.set(e.guestId,t),this.#n.set(t.window,t),this.#r.set(t.url,t),t};#m=e=>{if(typeof e=="string")return this.#s.get(e);const t=this.#n.get(e);return t||Array.from(this.#s.values()).find(i=>i.domElement===e)};#D=()=>{this.#l||(this.#l=setInterval(()=>{const e=[];this.#s.forEach(t=>{t.openMode===b.Popup&&t.window.closed&&e.push(t)}),e.forEach(t=>{const{id:i}=t;this.#w(i),this.#h.get(i)?.forEach(r=>{Promise.resolve(r({id:i})).catch(()=>{})})})},1e3))};#q=()=>{if(!this.#l)return;Array.from(this.#s.values()).some(t=>t.openMode===b.Popup)||(clearInterval(this.#l),this.#l=null)};#N=e=>{const t=D(e),i=t?void 0:G();return{popupUrl:i?`${e}#hs=${i}`:e,handshakeToken:i,trusted:t}};#F=e=>{const{url:t,title:i,popupWindowFeatures:s={},searchParams:r,guestId:o,onLoad:c,onError:a}=e,{width:l=800,height:u=600,top:d=100,left:m=100}=s;let w=this.#I(t);if(w)w.window.closed||(D(t)?window.open("",i):w.window.focus());else{const E=Object.entries({width:l,height:u,top:d,left:m}).filter(([,h])=>h).map(([h,T])=>`${h}=${T}`).join(","),{popupUrl:v,handshakeToken:y,trusted:p}=this.#N(t),I=window.open(v,i,`popup, ${E}`);if(I)setTimeout(()=>{try{c?.(o)}catch(h){this.#e.debug(`Error occurred in onLoad for guest with id '${o}': ${h.message}`)}},0);else throw setTimeout(()=>{try{a?.(o)}catch(h){this.#e.debug(`Error occurred in onError for guest with id '${o}': ${h.message}`)}},0),new Error("Failed to open guest application in popup window");p||(I.opener=null),w=this.#S({guestId:o,window:I,title:i,url:t,searchParams:r,openMode:b.Popup,handshakeToken:y}),this.#D()}return w};#W=e=>{const{url:t,title:i,targetElement:s,searchParams:r,guestId:o,onLoad:c,onError:a,options:l={}}=e,u=s.ownerDocument??document,{fitToContent:d=!1,disableSandbox:m=!1,sandboxValues:w=[],customSandboxValues:E=[],style:v="",permissionPolicy:y=""}=l;if(!i)throw new Error("title is required");d&&this.#C();const p=u.createElement("iframe");p.setAttribute("id",o);const I=()=>{setTimeout(()=>{try{c?.(o)}catch(R){this.#e.debug(`Error occurred in onLoad for guest with id '${o}': ${R.message}`)}},0),this.#e.debug(`frame loaded for guest with id '${o}'`),p.removeEventListener("load",I)},h=()=>{setTimeout(()=>{try{a?.(o)}catch(R){this.#e.debug(`Error occurred in onError for guest with id '${o}': ${R.message}`)}},0),this.#e.error(`frame load failed for guest with id '${o}'`),p.removeEventListener("error",h)};p.addEventListener("load",I),p.addEventListener("error",h),p.setAttribute("style",`min-width: 100%; height: 100%; border: 0px; ${v}`),m||p.setAttribute("sandbox",E.length>0?E.join(" "):[...V,...w].join(" ")),p.setAttribute("title",i),p.setAttribute("src",t),y&&p.setAttribute("allow",y),s.appendChild(p);const T=u.getElementById(o);return this.#S({guestId:o,domElement:T,window:T.contentWindow,title:i,url:t,searchParams:r,openMode:b.Embed})};#B=(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(H(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.#x(r)){const o=new S({name:r.name||s,objectId:t.id});if(Object.defineProperty(t,s,{value:o,enumerable:!0}),r instanceof _){const c=({eventParams:l,eventOptions:u})=>this.dispatchEvent({event:o,eventParams:l,eventOptions:u}),a=r.subscribe(c);i.push(()=>{r.unsubscribe(a)})}else{const c=r.subscribe?.((a,l,u)=>this.dispatchEvent({event:o,eventParams:l,eventOptions:u}));i.push(()=>{r.unsubscribe?.(c)})}}else if(L(r)&&(Object.defineProperty(t,s,{value:async(...o)=>{const c=t[s]?.callContext;if(c?.guest){const l=c.callChain??[],u=c.guest.id,d=this.#d.get(u),m={id:u};d&&(m.metadata=d),Object.defineProperty(r,"callContext",{value:{callChain:[...l,m]},configurable:!0,enumerable:!0,writable:!0})}const a=await r(...o);return H(a)?this.cloneScriptingObject(a):a},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.#l&&(clearInterval(this.#l),this.#l=null),this.#b(),this.#d.clear(),this.#t.close(),window.removeEventListener("beforeunload",this.#b),this.#e.debug(`host is closed. hostId: ${this.hostId}, correlationId: ${this.#i}`)};#z=({targetGuest:e,guestCapabilities:t,scriptingEventId:i,dispatchToGuest:s})=>{const r=o=>{if(J(t)&&!pe(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)};#H=(e,t)=>(t?this.getScriptingObject(e,{guest:t}):this.getScriptingObject(e))??(e===Y&&t?Ee:null);dispatchEvent=async e=>{const{event:{id:t,name:i},eventParams:s,eventOptions:r={}}=e,{eventHandler:o=null,timeout:c=null,window:a=null,guestId:l,guestCapabilities:u}=r,d=t.split(".")[0],m=l||a,w=m?this.#m(m):null,E=this.#H(d,w??null);if(!E)return this.#e.warn(`Attempt to dispatch event ${i} on unknown object ${d}`),Promise.resolve([]);const v={object:E._toJSON(),eventName:i,eventParams:s,eventHandler:o,eventOptions:{allowsFeedback:!1}};c&&!Number.isNaN(c)&&(v.eventOptions={allowsFeedback:!0,timeout:Number(c)});const y=[];let p;const I=h=>{const T=h.getInfo();c&&h?.capabilities?.eventFeedback?(y.push(h.dispatchEvent(v,c)),!p&&this.#c.enabled&&(p=this.#c.start(`ScriptingObject.Event.${E.id}.${i}`,{appId:this.hostId,appUrl:window.location.href})),this.#e.debug({message:"Event dispatched and awaiting feedback",scriptingEventId:t,...T})):(h.send({messageType:g.ObjectEvent,messageBody:v}),this.#e.debug({message:"Event dispatched",scriptingEventId:t,...T}))};return this.#z({targetGuest:w??null,guestCapabilities:u,scriptingEventId:t,dispatchToGuest:I}),Promise.all(y).then(h=>(this.#e.debug({message:"Event feedback received",scriptingEventId:t}),te(h))).catch(h=>{throw this.#e.error({message:"Error processing event",eventId:t,exception:h}),h}).finally(()=>{p&&this.#c.end(p,{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:c,onError:a,options:l={},metadata:u}=e;if(!t)throw new Error("id for guest application is required");let d=t;if(this.#s.has(d)){let y=1;for(;this.#s.has(`${t}-${y}`);)y+=1;d=`${t}-${y}`}const{openMode:m=b.Embed,popupWindowFeatures:w={}}=l,E=this.#B(i,o);let v=null;if(this.#c.start("SSF.Guest.Load",{appId:d,appUrl:E}),m===b.Popup)v=this.#F({guestId:d,url:E,title:r,searchParams:o,popupWindowFeatures:w,onLoad:c,onError:a});else if(m===b.Embed)v=this.#W({guestId:d,url:E,title:r,targetElement:s,searchParams:o,onLoad:c,onError:a,options:l});else throw new Error(`Invalid openMode: ${m}`);return u&&this.#d.set(d,u),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((a,l)=>{this.loadGuest({id:`${t}-${l}`,url:i,title:r,targetElement:s,searchParams:a,options:c})},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.#y),this.#e.debug("Dispatched config events to all guests")};#j=async(e,t,i)=>this.dispatchEvent({event:{id:t,name:i},eventParams:{moduleId:e.id},eventOptions:{timeout:we,guestId:e.id}});#J=async e=>{try{const t=await this.#j(e,be,"unloading");if(ve(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};#V=async e=>{try{await this.#j(e,me,"unmount")}catch(t){this.#e.warn({message:`Error dispatching module.unmount event for ${e.id}`,exception:t})}};#w=e=>{this.unloadGuest(e).catch(ye)};unloadGuest=async e=>{const t=this.#m(e);if(!t)return;if(!!!t.window?.closed){if(!await this.#J(t))return;await this.#V(t)}t.dispose(),this.#n.delete(t.window),this.#r.delete(t.url),this.#d.delete(t.id),this.#s.delete(t.id),this.#e.audit({message:"Guest is removed from host",...t.getInfo()}),this.#q()};onGuestClose=e=>{const{id:t,guestCloseCallback:i}=e,s=this.#h.get(t)||[];s.push(i),this.#h.set(t,s)}}return k})());
|
|
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
|