@elliemae/ssf-host 2.25.3 → 2.25.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/host.js +559 -15
- package/dist/esm/host.js +559 -15
- 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.1f1cbf6c2111a68bc2c8.js +3 -0
- package/dist/public/js/emuiSsfHost.1f1cbf6c2111a68bc2c8.js.br +0 -0
- package/dist/public/js/emuiSsfHost.1f1cbf6c2111a68bc2c8.js.gz +0 -0
- package/dist/public/js/emuiSsfHost.1f1cbf6c2111a68bc2c8.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/lib/host.d.ts +98 -8
- package/dist/types/lib/ihost.d.ts +15 -0
- package/dist/types/lib/index.d.ts +1 -1
- package/dist/types/lib/types.d.ts +59 -0
- 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.110872ea16d9bc201a4f.js +0 -3
- package/dist/public/js/emuiSsfHost.110872ea16d9bc201a4f.js.br +0 -0
- package/dist/public/js/emuiSsfHost.110872ea16d9bc201a4f.js.gz +0 -0
- package/dist/public/js/emuiSsfHost.110872ea16d9bc201a4f.js.map +0 -1
package/dist/umd/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
(function(I,j){typeof exports=="object"&&typeof module=="object"?module.exports=j():typeof define=="function"&&define.amd?define([],j):typeof exports=="object"?exports.ice=j():(I.ice=I.ice||{},I.ice.host=j())})(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 I={};O.r(I),O.d(I,{Event:()=>j,Guest:()=>C,IFrameSandboxValues:()=>S,OpenMode:()=>w,SANDBOX_DEFAULT:()=>H,SSFHost:()=>he,ScriptingObject:()=>U});class j{name;objectId;id;constructor(e){const{name:t,objectId:s}=e;if(!t)throw new Error("Event name is required");if(!s)throw new Error("Scripting object id is required");this.objectId=s,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:s,eventSrc:i}=e;if(!t)throw new Error("Event name is required");if(!s)throw new Error("Scripting object id is required");if(!i)throw new Error("Event source is required");this.objectId=s,this.name=t,this.#t=i,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 J=n=>n instanceof j,ge=(n,e)=>`${n.toLowerCase()}.${e.toLowerCase()}`,Y="function",X=(n,e)=>typeof n===Y&&!!e&&!e.startsWith("_");class U{#t;#s="Object";constructor(e,t){this.#t=e,this.#s=t||this.#s}get id(){return this.#t}get objectType(){return this.#s}_toJSON=()=>{const e=[],t=[];return Object.keys(this).forEach(s=>{const i=this[s];J(i)?t.push(s):X(i,s)&&e.push(s)}),{objectId:this.#t,objectType:this.#s,functions:e,events:t}};_dispose=()=>{};dispose=()=>{}}var h=(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))(h||{}),w=(n=>(n.Popup="popup",n.Embed="embed",n))(w||{}),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 Q=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}},K=n=>n.flat(1/0).filter(e=>e!==void 0);function _(n){return typeof n=="function"}const V=[".ice.com",".elliemae.com",".ellielabs.com"],Z=["localhost","127.0.0.1"],M=n=>{try{const{hostname:e}=new URL(n,document.baseURI);return Z.includes(e)||V.some(t=>e===t.slice(1)||e.endsWith(t))}catch{return!1}};class C{id;title;url;searchParams;domElement;window;openMode;origin;initialized=!1;ready=!1;capabilities;#t;#s;constructor(e){const{guestId:t,domElement:s=null,title:i,url:r,window:o,searchParams:c={},openMode:l=w.Embed,remoting:a,perfTracker:u}=e;this.id=t,this.title=i,this.url=r,this.origin=Q(r),this.searchParams=c,this.domElement=s,this.window=o,this.openMode=l,this.capabilities={},this.#s=u,this.#t=a}dispose=()=>{if(this.openMode===w.Popup&&!this.window.closed)try{this.window.document,this.window.close()}catch{this.#t.send({targetWin:this.window,targetOrigin:this.origin,messageType:h.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 s=5;let i;const r=()=>{clearInterval(i),this.#t.unlisten({messageType:h.HandShakeAck,callback:r}),e(!0)};i=setInterval(()=>{t>=s?(clearInterval(i),this.#t.unlisten({messageType:h.HandShakeAck,callback:r}),e(!1)):(this.#t.send({targetWin:this.window,targetOrigin:this.origin,messageType:h.HandShake,messageBody:{}}),t+=1)},1e3),this.#t.listen({messageType:h.HandShakeAck,callback:r})});init=()=>{this.#t.addSender({origin:this.origin,window:this.window}),this.openMode===w.Popup&&this.handShake().catch(()=>{})};dispatchEvent=(e,t)=>{let s;if(this.#s.enabled){const i=`ScriptingObject.Event.${e.object.objectId}.${e.eventName}`;s=this.#s.start(i,{appId:this.id,appUrl:this.url})}return this.#t.invoke({targetWin:this.window,targetOrigin:this.origin,messageType:h.ObjectEvent,messageBody:e,responseTimeoutMs:t}).finally(()=>{s&&this.#s.end(s,{appId:this.id,appUrl:this.url})})};send=e=>{this.#t.send({targetWin:this.window,targetOrigin:this.origin,...e})}}const L={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};let A;const ee=new Uint8Array(16);function te(){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(ee)}var se;const p=[];for(let n=0;n<256;++n)p.push((n+256).toString(16).slice(1));function q(n,e=0){return p[n[e+0]]+p[n[e+1]]+p[n[e+2]]+p[n[e+3]]+"-"+p[n[e+4]]+p[n[e+5]]+"-"+p[n[e+6]]+p[n[e+7]]+"-"+p[n[e+8]]+p[n[e+9]]+"-"+p[n[e+10]]+p[n[e+11]]+p[n[e+12]]+p[n[e+13]]+p[n[e+14]]+p[n[e+15]]}function fe(n,e=0){const t=q(n,e);if(!se(t))throw TypeError("Stringified UUID is invalid");return t}const be=null;function ie(n,e,t){if(L.randomUUID&&!e&&!n)return L.randomUUID();n=n||{};const s=n.random||(n.rng||te)();if(s[6]=s[6]&15|64,s[8]=s[8]&63|128,e){t=t||0;for(let i=0;i<16;++i)e[t+i]=s[i];return e}return q(s)}const x=ie,D="elli:remoting",N="elli:remoting:response",F="elli:remoting:exception",k=({messageType:n,messageBody:e,requestId:t,onewayMsg:s=!1})=>({requestId:t??(s?null:x()),source:D,type:n,body:e}),we=n=>{const{targetWin:e,targetOrigin:t,messageType:s,messageBody:i}=n,r=k({messageType:s,messageBody:i});e.postMessage(r,t)};class ne{#t;#s;#e=new Map;#c=new Map;#i=null;#n=null;#r=new Map;#d;constructor(e,t,s){if(!e)throw new Error("logger is required");if(!t)throw new Error("correlationId is required");this.#t=t,this.#s=e,this.#d=s?.unsafeAllowAnyGuestOrigin??!1}#o=e=>this.#d?"*":e;#p=()=>{this.#i=null;const e=Date.now(),t=[];let s=null;if(this.#c.forEach((i,r)=>{const{requestId:o,cancelTime:c}=i;c&&c<=e?(this.#s.debug(`Detected response timeout for requestId: ${o}...`),t.push(r),i.resolve(void 0)):c&&(s=s===null?c:Math.min(s,c))}),t.forEach(i=>{this.#c.delete(i)}),s!==null){const i=Math.max(s-Date.now(),0);this.#a(i)}};#a=e=>{this.#i===null&&(this.#i=window.setTimeout(this.#p,e))};#f=()=>{this.#i!==null&&(window.clearTimeout(this.#i),this.#i=null)};#g=e=>{const t=this.#c.get(e);return this.#s.debug(`serving requestId: ${e}`),this.#c.delete(e),t};#h=e=>{const{requestId:t}=e;this.#s.debug(`Response received for invocation requestId: ${t}`);const s=this.#g(t);return s?(s.resolve(e.body),!0):(this.#s.debug(`Received response to stale/invalid request with requestId: ${t}`),!1)};#l=e=>{this.#s.debug(`Exception received for invocation (requestId = ${e.requestId})`);const t=this.#g(e.requestId);return t?(t.reject(new Error(e.body)),!0):(this.#s.warn(`Received exception for stale/invalid request (requestId = ${e.requestId})`),!1)};#b=({sourceWin:e,sourceOrigin:t,message:s})=>{this.#s.debug(`Received message of type "${s.type}"`);const i=this.#e.get(s.type);return i?(i.forEach(r=>{this.#s.debug(`Invoking message handler ${r.name}`),r({sourceWin:e,sourceOrigin:t,requestId:s.requestId,type:s.type,body:s.body})}),!0):!1};#w=e=>{if(this.#r.size===0||!e.source)return!1;const t=this.#r.get(e.source);return!t||e?.data?.source!==D?!1:(this.#s.debug(`Remoting: Received message of type "${e.data.type}"`),e.data.type===N?this.#h(e.data):e.data.type===F?this.#l(e.data):this.#b({sourceWin:e.source,sourceOrigin:t,message:e.data}),!0)};addSender=e=>{const{origin:t,window:s}=e;if(!t)throw new Error("origin is required");if(!s)throw new Error("window is required");this.#r.set(s,t)};initialize=e=>{this.#n&&this.#n.removeEventListener("message",this.#w),e.addEventListener("message",this.#w),this.#n=e,this.#s.debug(`initialized remoting id: ${this.#t}`)};close=()=>{this.#n&&(this.#n.removeEventListener("message",this.#w),this.#n=null),this.#f(),this.#s.debug(`closed remoting id: ${this.#t}`)};invoke=e=>{const{targetWin:t,targetOrigin:s,messageType:i,messageBody:r,responseTimeoutMs:o}=e;return new Promise((c,l)=>{const a=k({messageType:i,messageBody:r});this.#c.set(a.requestId,{requestId:a.requestId,resolve:c,reject:l,cancelTime:o?Date.now()+o:null}),t.postMessage(a,this.#o(s));const{requestId:u}=a;this.#s.debug(`Posted invocation message of type ${i} requestId: ${u||""}`),o&&(this.#s.debug(`scheduling timeout check for requestId: ${u||""} in ${o} ms`),this.#a(o))})};listen=e=>{const{messageType:t,callback:s}=e,i=this.#e.get(t)||[];i.push(s),this.#e.set(t,i)};unlisten=e=>{const{messageType:t,callback:s}=e,i=this.#e.get(t);if(!i)return;const r=i.indexOf(s);r!==-1&&i.splice(r,1)};send=e=>{const{targetWin:t,targetOrigin:s,messageType:i,messageBody:r}=e,o=k({messageType:i,messageBody:r,onewayMsg:!0});t.postMessage(o,this.#o(s)),this.#s.debug(`Posted one-way message of type "${i}"`)};removeSender=e=>{const{window:t}=e;t&&this.#r.delete(t)};respond=e=>{const{targetWin:t,targetOrigin:s,requestId:i,response:r}=e,o=k({messageType:N,messageBody:r,requestId:i});t.postMessage(o,this.#o(s)),this.#s.debug(`Response sent to caller for invocation requestId: ${i}`)};raiseException=e=>{const{targetWin:t,targetOrigin:s,requestId:i,ex:r}=e,o=r instanceof Error?r.message:r,c=k({messageType:F,messageBody:o,requestId:i});t.postMessage(c,this.#o(s)),this.#s.debug(`Exception sent to caller for invocation. requestId: ${i}`)}}const W="module";var re=(n=>(n.USER="USER",n.PARTNER="PARTNER",n))(re||{});class oe{#t=e=>e.trim().toLowerCase();#s=new Map;#e=new Map;#c=e=>{const{so:t,guestId:s}=e,i=this.#t(t.id),r=this.#e.get(s);if(!r)this.#e.set(s,new Map([[i,e]]));else{if(r.has(i))throw new Error(`Scripting Object ${t.id} already exists for guest ${s}`);r.set(i,e)}};#i=({so:e})=>{if(e._dispose&&typeof e._dispose=="function")try{e._dispose()}catch{}};#n=({objectId:e,guestId:t})=>{if(e===W&&!t)for(const[,i]of this.#e){const r=i.get(e);if(r)return r}const s=t?this.#e.get(t):null;return s?s.get(e)??null:null};#r=({objectId:e,guestId:t}={})=>{if(t){if(!e){const i=this.#e.get(t);i&&i.forEach(this.#i),this.#e.delete(t);return}const s=this.#e.get(t);if(s){const i=s.get(e);i&&this.#i(i),s.delete(e)}}else e&&this.#e.forEach(s=>{const i=s.get(e);i&&this.#i(i),s.delete(e)})};addScriptingObject=(e,t)=>{const{guestId:s}=t||{};if(!e?.id||!e?._toJSON)throw new Error("Object is not derived from ScriptingObject");const i=this.#t(e.id);if(i===W&&!s)throw new Error("Guest id is required to add Module scripting object");if(s){this.#c({so:e,...t,guestId:s});return}if(this.#s.has(i))throw new Error(`Scripting Object ${e.id} already exists`);this.#s.set(i,{so:e,...t})};getObject=(e,t)=>{const s=this.#t(e);let i=this.#n({objectId:s,guestId:t?.id});i=i??this.#s.get(s)??null;const{so:r}=i||{};return r||null};has=(e,t)=>this.getObject(e,t)!==null;listScriptingObjects=e=>{const t=new Set(this.#s.keys()),s=this.#e.get(e);if(s)for(const i of s.keys())t.add(i);return Array.from(t)};removeScriptingObject=(e,t)=>{const s=this.#t(e);if(t)this.#r({objectId:s,guestId:t});else{this.#r({objectId:s});const i=this.#s.get(s);i&&this.#i(i),this.#s.delete(s)}};removeAllScriptingObjects=e=>{e?this.#r({guestId:e}):(this.#s.forEach(this.#i),this.#s.clear())}}class me{__TYPE__="Proxy";id;objectType;constructor(e,t){this.id=e,this.objectType=t}}const z=n=>n?.constructor?.name==="Proxy"||n?.constructor?.name==="ScriptingObjectProxy"||n?.__TYPE__==="Proxy",ce=new Map;function Ee(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 ae(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 s=typeof n=="number"?n:Number(n);return!Number.isNaN(s)&&s>e.gt}if("lt"in e){const s=typeof n=="number"?n:Number(n);return!Number.isNaN(s)&&s<e.lt}if("regex"in e){const s=t??ce;let i=s.get(e.regex);if(i===void 0){try{i=new RegExp(e.regex)}catch{i=null}s.set(e.regex,i)}return i!==null&&typeof n=="string"&&i.test(n)}return!1}function B(n){return n!=null&&Object.keys(n).length>0}function le(n,e,t){return Object.entries(e).every(([s,i])=>ae(n[s],i,t?.regexCache))}const ve=null;function ue(n,e){return B(e)?le(n,e):!0}const de=new Set(["SSF.Guest.Load"]);class ${#t;#s;#e;#c=new Set;#i;#n=new Map;#r;static DEFAULT_SAMPLING_RATIO=.05;static DEFAULT_DEDUP_WINDOW_MS=1e4;constructor(e){this.#t=e.analyticsObj,this.#s=e.enabled??!1,this.#e=e.samplingRatio??$.DEFAULT_SAMPLING_RATIO,this.#i=e.dedupWindowMs??$.DEFAULT_DEDUP_WINDOW_MS,this.#r=e.onError}get enabled(){return this.#s}start(e,t){if(this.#s)try{const s=de.has(e);return!s&&!this.shouldTrack(e)?void 0:(!s&&!this.#c.has(e)&&(this.#t.setTimingEventSamplingRatio({[e]:this.#e}),this.#c.add(e)),this.#t.startTiming(e,t).catch(i=>{this.reportError(`startTiming failed: ${i.message}`)}),e)}catch(s){this.reportError(`startTiming failed: ${s.message}`);return}}end(e,t){if(e)try{this.#t.endTiming(e,t).catch(s=>{this.reportError(`endTiming failed: ${s.message}`)})}catch(s){this.reportError(`endTiming failed: ${s.message}`)}}reportError(e){try{this.#r?.(e)}catch{}}shouldTrack(e){if(this.#i<=0)return!0;const t=performance.now(),s=this.#n.get(e);return s!==void 0&&t-s<this.#i?!1:(this.#n.set(e,t),!0)}}const H=[S.AllowScripts,S.AllowPopups,S.AllowModals,S.AllowForms,S.AllowDownloads,S.AllowSameOrigin];class he{hostId;#t;#s;#e;#c;#i=new Map;#n=new Map;#r=new Map;#d=new Map;#o;#p=null;#a=null;#f=null;#g=null;#h=new Map;#l;#b;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.#c=t.analyticsObj;const s={analyticsObj:t.analyticsObj,enabled:t?.measurePerformance,samplingRatio:t?.performanceSamplingRatio,onError:i=>this.#e.debug(i)};if(this.#l=new $({...s,dedupWindowMs:t?.performanceDedupWindowMs}),this.#b=new $({...s,dedupWindowMs:0}),this.#s=x(),this.#t=new ne(this.#e,this.#s,{unsafeAllowAnyGuestOrigin:t?.unsafeAllowAnyGuestOrigin}),t?.readyStateCallback&&typeof t?.readyStateCallback!="function")throw new Error("readyStateCallback must be a function");this.#p=t?.readyStateCallback||null,this.#f=t?.onGuestEventSubscribe||null,this.#g=t?.onGuestEventUnsubscribe||null,this.#o=new oe,this.#t.initialize(window),this.#C(),window.addEventListener("beforeunload",this.#m),this.#e.debug(`host is initialized. hostId: ${this.hostId}, correlationId: ${this.#s}`)}#w=(e,t)=>{const s={event:e,...t};this.#c.sendBAEvent(s).catch(i=>{this.#e.debug(`Analytics sendBAEvent failed: ${i.message}`)})};#m=()=>{Array.from(this.#i.values()).filter(t=>t.openMode===w.Popup).map(t=>t.id).forEach(t=>this.unloadGuest(t))};#u=e=>this.#n.get(e);#S=e=>this.#r.get(e)??null;#I=e=>typeof e?._toJSON=="function";#v=(e,t)=>this.#I(e)?(this.#o.has(e?.id,t)||this.#o.addScriptingObject(e,t?{guestId:t?.id}:{}),{type:"object",object:e._toJSON()}):{type:"value",value:e};#z=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:h.HostConfig,messageBody:{logLevel:this.#e.getLogLevel(),...e.getInfo()}})};#k=({guest:e,obj:t,functionName:s,functionParams:i,callerChain:r})=>{const o=t[s];return _(o)?(this.#e.debug(`Invoking host implementation of ${t.id}.${String(s)}()`),new Promise(c=>{Object.defineProperty(o,"callContext",{value:{guest:e,...r?.length?{callChain:r}:{}},configurable:!0,enumerable:!0,writable:!0}),c(o(...i))})):(this.#e.warn(`Attempt to call invalid function on object type ${t.objectType}: ${String(s)}`),Promise.reject(new Error(`Method '${s}' not found in Scripting Object '${t.id}'`)))};#O=({sourceWin:e,sourceOrigin:t,requestId:s})=>{const i=this.#u(e);if(!i){this.#e.warn(`Received ready event for unknown guest. requestId: ${s}`);return}if(!i.initialized){this.#e.warn("Guest must be initialized before it is marked as ready"),this.#t.raiseException({targetWin:e,targetOrigin:t,requestId:s,ex:"Guest must be initialized before it is marked as ready"});return}if(!i.ready){i.ready=!0;const r=i.getInfo();this.#l.end("SSF.Guest.Load",{appId:r.guestId,appUrl:r.guestUrl}),this.#y(i),this.#p?.(i),this.#e.audit({message:"Guest is ready",...r})}};#$=({sourceWin:e,sourceOrigin:t,requestId:s,body:i})=>{const r=this.#u(e);if(!r){this.#e.warn(`Received ready event for unknown guest. requestid = ${s}`);return}r.initialized||(r.initialized=!0,r.capabilities=i||{},this.#e.audit({message:"Guest is initialized",...r.getInfo()})),(!i||!i.onReady)&&this.#O({sourceWin:e,sourceOrigin:t,requestId:s,type:"",body:null})};#T=async({sourceWin:e})=>{if(e?.window){const t=this.#E(e);t&&!await t.handShake()&&this.unloadGuest(e)}};#A=({sourceWin:e,sourceOrigin:t,requestId:s})=>{this.#e.debug(`Processing listObjects request. requestId = ${s}`);const i=this.#u(e);if(!i)return this.#e.warn("Rejected object request from unknown guest window"),!1;const r=this.#o.listScriptingObjects(i.id);return this.#t.respond({targetWin:e,targetOrigin:t,requestId:s,response:r}),this.#e.debug({message:"name of scripting objects returned",requestId:s,objects:r,...i.getInfo()}),!0};#G=({sourceWin:e,sourceOrigin:t,requestId:s,body:i})=>{const{objectId:r}=i;this.#e.debug(`Processing getObject request for object ${r}. requestId = ${s}`);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:s,response:this.#v(c,o)}),this.#e.debug({message:"Scripting Object returned",requestId:s,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:s,ex:`The requested object (${r}) is not available`}),!1)};#P=({sourceWin:e,requestId:t,body:s})=>{const{eventId:i,criteria:r,token:o}=s;this.#e.debug(`Processing guest event subscribe request for event ${i}. requestId = ${t}`);const c=this.#u(e);if(!c){this.#e.warn("Rejected event subscribe request from unknown guest window");return}setTimeout(()=>{try{this.#f?.({guestId:c.id,eventId:i,criteria:r,token:o})}catch(l){this.#e.warn(`Error in onGuestEventSubscribe callback for event ${i}: ${l.message}`)}},0)};#R=({sourceWin:e,requestId:t,body:s})=>{const{eventId:i,token:r}=s;this.#e.debug(`Processing guest event unsubscribe request for event ${i}. requestId = ${t}`);const o=this.#u(e);if(!o){this.#e.warn("Rejected event unsubscribe request from unknown guest window");return}setTimeout(()=>{try{this.#g?.({guestId:o.id,eventId:i,token:r})}catch(c){this.#e.warn(`Error in onGuestEventUnsubscribe callback for event ${i}: ${c.message}`)}},0)};#U=({sourceWin:e,requestId:t,body:s})=>{const i=this.#u(e);if(!i){this.#e.warn(`Received resize event from unknown guest. requestid = ${t}`);return}i.domElement&&(i.domElement.style.height=`${s.height}px`),this.#e.debug(`Guest ${i.id} resized to ${s.width}x${s.height}`)};#_=({sourceWin:e,sourceOrigin:t,requestId:s,body:i})=>{const{objectId:r,callerChain:o}=i,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(i.functionName)}() called from guest "${c.id}" (requestId = ${s})`);const l=this.getScriptingObject(r,{guest:c});if(!l)return this.#e.warn(`Invocation of unknown or unauthorized object ${r} from guest ${c.id}`),this.#t.raiseException({targetWin:e,targetOrigin:t,requestId:s,ex:`The requested object (${r}) is not available`}),!1;const a=c.getInfo();let u;if(this.#l.enabled){const d=`ScriptingObject.API.${r}.${i.functionName}`;u=this.#l.start(d,{appId:a.guestId,appUrl:a.guestUrl})}return this.#k({guest:c,obj:l,functionName:i.functionName,functionParams:i.functionParams,callerChain:o}).then(d=>{this.#t.respond({targetWin:e,targetOrigin:t,requestId:s,response:this.#v(d,c)}),this.#e.debug({message:"Value returned for Scripting Object method call",requestId:s,scriptingObject:r,scriptingMethod:i.functionName,...a})}).catch(d=>{this.#t.raiseException({targetWin:e,targetOrigin:c.origin,requestId:s,ex:d}),this.#e.error({message:"Exception thrown for Scripting Object method call",requestId:s,scriptingObject:r,scriptingMethod:i.functionName,...a})}).finally(()=>{u&&this.#l.end(u,{appId:a.guestId,appUrl:a.guestUrl})}),!0};#M=()=>{this.#t.listen({messageType:h.GuestResize,callback:this.#U})};#C=()=>{this.#t.listen({messageType:h.GuestReady,callback:this.#$}),this.#t.listen({messageType:h.GuestReadyComplete,callback:this.#O}),this.#t.listen({messageType:h.GuestClose,callback:this.#T}),this.#t.listen({messageType:h.ListObjects,callback:this.#A}),this.#t.listen({messageType:h.ObjectGet,callback:this.#G}),this.#t.listen({messageType:h.ObjectInvoke,callback:this.#_}),this.#t.listen({messageType:h.GuestEventSubscribe,callback:this.#P}),this.#t.listen({messageType:h.GuestEventUnsubscribe,callback:this.#R})};#L=e=>e instanceof R||typeof e?.subscribe=="function";#j=e=>{const t=new C({...e,remoting:this.#t,perfTracker:this.#b});return t.init(),this.#i.set(e.guestId,t),this.#n.set(t.window,t),this.#r.set(t.url,t),t};#E=e=>{if(typeof e=="string")return this.#i.get(e);const t=this.#n.get(e);return t||Array.from(this.#i.values()).find(s=>s.domElement===e)};#q=()=>{this.#a||(this.#a=setInterval(()=>{const e=[];this.#i.forEach(t=>{t.openMode===w.Popup&&t.window.closed&&e.push(t)}),e.forEach(t=>{const{id:s}=t;this.unloadGuest(s),this.#d.get(s)?.forEach(r=>{Promise.resolve(r({id:s})).catch(()=>{})})})},1e3))};#x=()=>{if(!this.#a)return;Array.from(this.#i.values()).some(t=>t.openMode===w.Popup)||(clearInterval(this.#a),this.#a=null)};#D=e=>{const{url:t,title:s,popupWindowFeatures:i={},searchParams:r,guestId:o,onLoad:c,onError:l}=e,{width:a=800,height:u=600,top:d=100,left:m=100}=i;let E=this.#S(t);if(E)E.window.closed||(M(t)?window.open("",s):E.window.focus());else{const v=Object.entries({width:a,height:u,top:d,left:m}).filter(([,f])=>f).map(([f,g])=>`${f}=${g}`).join(","),b=window.open(t,s,`popup, ${v}`);if(b)setTimeout(()=>{try{c?.(o)}catch(f){this.#e.debug(`Error occurred in onLoad for guest with id '${o}': ${f.message}`)}},0);else throw setTimeout(()=>{try{l?.(o)}catch(f){this.#e.debug(`Error occurred in onError for guest with id '${o}': ${f.message}`)}},0),new Error("Failed to open guest application in popup window");M(t)||(b.opener=null),E=this.#j({guestId:o,window:b,title:s,url:t,searchParams:r,openMode:w.Popup}),this.#q()}return E};#N=e=>{const{url:t,title:s,targetElement:i,searchParams:r,guestId:o,onLoad:c,onError:l,options:a={}}=e,u=i.ownerDocument??document,{fitToContent:d=!1,disableSandbox:m=!1,sandboxValues:E=[],customSandboxValues:v=[],style:b="",permissionPolicy:f=""}=a;if(!s)throw new Error("title is required");d&&this.#M();const g=u.createElement("iframe");g.setAttribute("id",o);const G=()=>{setTimeout(()=>{try{c?.(o)}catch(P){this.#e.debug(`Error occurred in onLoad for guest with id '${o}': ${P.message}`)}},0),this.#e.debug(`frame loaded for guest with id '${o}'`),g.removeEventListener("load",G)},y=()=>{setTimeout(()=>{try{l?.(o)}catch(P){this.#e.debug(`Error occurred in onError for guest with id '${o}': ${P.message}`)}},0),this.#e.error(`frame load failed for guest with id '${o}'`),g.removeEventListener("error",y)};g.addEventListener("load",G),g.addEventListener("error",y),g.setAttribute("style",`min-width: 100%; height: 100%; border: 0px; ${b}`),m||g.setAttribute("sandbox",v.length>0?v.join(" "):[...H,...E].join(" ")),g.setAttribute("title",s),g.setAttribute("src",t),f&&g.setAttribute("allow",f),i.appendChild(g);const T=u.getElementById(o);return this.#j({guestId:o,domElement:T,window:T.contentWindow,title:s,url:t,searchParams:r,openMode:w.Embed})};#F=(e,t)=>{let s="";return Object.keys(t).forEach(i=>{s+=`${(s.length?"&":"")+encodeURIComponent(i)}=${encodeURIComponent(t[i])}`}),e+(s?(e.indexOf("?")>=0?"&":"?")+s:"")};addScriptingObject=(e,t)=>{if(z(e)){const s=this.cloneScriptingObject(e);this.#o.addScriptingObject(s,t)}else this.#o.addScriptingObject(e,t)};cloneScriptingObject=e=>{if(!e)throw new Error("proxy is required");const t=new U(e.id,e.objectType);let s=[];return Object.keys(e).forEach(i=>{const r=e[i];if(this.#L(r)){const o=new j({name:r.name||i,objectId:t.id});if(Object.defineProperty(t,i,{value:o,enumerable:!0}),r instanceof R){const c=({eventParams:a,eventOptions:u})=>this.dispatchEvent({event:o,eventParams:a,eventOptions:u}),l=r.subscribe(c);s.push(()=>{r.unsubscribe(l)})}else{const c=r.subscribe?.((l,a,u)=>this.dispatchEvent({event:o,eventParams:a,eventOptions:u}));s.push(()=>{r.unsubscribe?.(c)})}}else if(_(r)&&(Object.defineProperty(t,i,{value:async(...o)=>{const c=t[i]?.callContext;if(c?.guest){const a=c.callChain??[],u=c.guest.id,d=this.#h.get(u),m={id:u};d&&(m.metadata=d),Object.defineProperty(r,"callContext",{value:{callChain:[...a,m]},configurable:!0,enumerable:!0,writable:!0})}const l=await r(...o);return z(l)?this.cloneScriptingObject(l):l},enumerable:!0}),i==="dispose")){const o=t.dispose;Object.defineProperty(t,i,{value:()=>(t._dispose(),o.apply(t)),enumerable:!0})}}),t._dispose=()=>{s.forEach(i=>{i?.()}),s=[]},t};close=()=>{this.#a&&(clearInterval(this.#a),this.#a=null),this.#m(),this.#h.clear(),this.#t.close(),window.removeEventListener("beforeunload",this.#m),this.#e.debug(`host is closed. hostId: ${this.hostId}, correlationId: ${this.#s}`)};#W=({targetGuest:e,guestCapabilities:t,scriptingEventId:s,dispatchToGuest:i})=>{const r=o=>{if(B(t)&&!ue(o.capabilities,t)){this.#e.debug({message:"Event skipped \u2014 guest capabilities do not match eventOptions.guestCapabilities",scriptingEventId:s,guestCapabilities:t,...o.getInfo()});return}i(o)};e?r(e):this.#i.forEach(r)};dispatchEvent=async e=>{const{event:{id:t,name:s},eventParams:i,eventOptions:r={}}=e,{eventHandler:o=null,timeout:c=null,window:l=null,guestId:a,guestCapabilities:u}=r,d=t.split(".")[0],m=a||l,E=m?this.#E(m):null,v=E?this.getScriptingObject(d,{guest:E}):this.getScriptingObject(d);if(!v)return this.#e.warn(`Attempt to dispatch event ${s} on unknown object ${d}`),Promise.resolve([]);const b={object:v._toJSON(),eventName:s,eventParams:i,eventHandler:o,eventOptions:{allowsFeedback:!1}};c&&!Number.isNaN(c)&&(b.eventOptions={allowsFeedback:!0,timeout:Number(c)});const f=[];let g;const G=y=>{const T=y.getInfo();c&&y?.capabilities?.eventFeedback?(f.push(y.dispatchEvent(b,c)),!g&&this.#l.enabled&&(g=this.#l.start(`ScriptingObject.Event.${v.id}.${s}`,{appId:this.hostId,appUrl:window.location.href})),this.#e.debug({message:"Event dispatched and awaiting feedback",scriptingEventId:t,...T})):(y.send({messageType:h.ObjectEvent,messageBody:b}),this.#e.debug({message:"Event dispatched",scriptingEventId:t,...T}))};return this.#W({targetGuest:E??null,guestCapabilities:u,scriptingEventId:t,dispatchToGuest:G}),Promise.all(f).then(y=>(this.#e.debug({message:"Event feedback received",scriptingEventId:t}),K(y))).catch(y=>{throw this.#e.error({message:"Error processing event",eventId:t,exception:y}),y}).finally(()=>{g&&this.#l.end(g,{appId:this.hostId,appUrl:window.location.href})})};getGuests=()=>Array.from(this.#i.values());getScriptingObject=(e,t)=>this.#o.getObject(e,t?.guest);loadGuest=e=>{const{id:t,url:s,targetElement:i,title:r,searchParams:o={},onLoad:c,onError:l,options:a={},metadata:u}=e;if(!t)throw new Error("id for guest application is required");let d=t;if(this.#i.has(d)){let f=1;for(;this.#i.has(`${t}-${f}`);)f+=1;d=`${t}-${f}`}const{openMode:m=w.Embed,popupWindowFeatures:E={}}=a,v=this.#F(s,o);let b=null;if(this.#l.start("SSF.Guest.Load",{appId:d,appUrl:v}),m===w.Popup)b=this.#D({guestId:d,url:v,title:r,searchParams:o,popupWindowFeatures:E,onLoad:c,onError:l});else if(m===w.Embed)b=this.#N({guestId:d,url:v,title:r,targetElement:i,searchParams:o,onLoad:c,onError:l,options:a});else throw new Error(`Invalid openMode: ${m}`);return u&&this.#h.set(d,u),this.#e.audit({message:"Guest loaded",...b.getInfo()}),b};loadGuests=e=>{const{id:t,url:s,targetElement:i,title:r,searchParamsList:o=[],options:c={}}=e;o.forEach((l,a)=>{this.loadGuest({id:`${t}-${a}`,url:s,title:r,targetElement:i,searchParams:l,options:c})},this)};removeAllScriptingObjects=e=>{this.#o.removeAllScriptingObjects(e)};removeScriptingObject=(e,t)=>{this.#o.removeScriptingObject(e,t)};setLogLevel=e=>{this.#e.setLogLevel(e),this.#i.forEach(this.#y),this.#e.debug("Dispatched config events to all guests")};unloadGuest=e=>{const t=this.#E(e);t&&(t.dispose(),this.#n.delete(t.window),this.#r.delete(t.url),this.#h.delete(t.id),this.#i.delete(t.id),this.#e.audit({message:"Guest is removed from host",...t.getInfo()}),this.#x())};onGuestClose=e=>{const{id:t,guestCloseCallback:s}=e,i=this.#d.get(t)||[];i.push(s),this.#d.set(t,i)}}return I})());
|
|
1
|
+
(function($,j){typeof exports=="object"&&typeof module=="object"?module.exports=j():typeof define=="function"&&define.amd?define([],j):typeof exports=="object"?exports.ice=j():($.ice=$.ice||{},$.ice.host=j())})(globalThis,()=>(()=>{"use strict";var S={};S.d=(r,e)=>{for(var t in e)S.o(e,t)&&!S.o(r,t)&&Object.defineProperty(r,t,{enumerable:!0,get:e[t]})},S.o=(r,e)=>Object.prototype.hasOwnProperty.call(r,e),S.r=r=>{typeof Symbol<"u"&&Symbol.toStringTag&&Object.defineProperty(r,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(r,"__esModule",{value:!0})};var $={};S.r($),S.d($,{Event:()=>j,Guest:()=>M,IFrameSandboxValues:()=>O,OpenMode:()=>b,SANDBOX_DEFAULT:()=>H,SSFHost:()=>he,ScriptingObject:()=>C});class j{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 J=r=>r instanceof j,ge=(r,e)=>`${r.toLowerCase()}.${e.toLowerCase()}`,Y="function",X=(r,e)=>typeof r===Y&&!!e&&!e.startsWith("_");class C{#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];J(s)?t.push(i):X(s,i)&&e.push(i)}),{objectId:this.#t,objectType:this.#i,functions:e,events:t}};_dispose=()=>{};dispose=()=>{}}var h=(r=>(r.GuestClose="guest:close",r.GuestEventSubscribe="guest:eventSubscribe",r.GuestEventUnsubscribe="guest:eventUnsubscribe",r.GuestFocus="guest:focus",r.GuestReady="guest:ready",r.GuestReadyComplete="guest:readyComplete",r.GuestResize="guest:resize",r.HandShake="handshake",r.HandShakeAck="handshake:ack",r.HostClose="host:close",r.HostConfig="host:config",r.ListObjects="list:objects",r.ObjectEvent="object:event",r.ObjectGet="object:get",r.ObjectInvoke="object:invoke",r))(h||{}),b=(r=>(r.Popup="popup",r.Embed="embed",r))(b||{}),O=(r=>(r.AllowDownloadsWithoutUserActivation="allow-downloads-without-user-activation",r.AllowDownloads="allow-downloads",r.AllowForms="allow-forms",r.AllowModals="allow-modals",r.AllowOrientationLock="allow-orientation-lock",r.AllowPointerLock="allow-pointer-lock",r.AllowPopups="allow-popups",r.AllowPopupsToEscapeSandbox="allow-popups-to-escape-sandbox",r.AllowPresentation="allow-presentation",r.AllowSameOrigin="allow-same-origin",r.AllowScripts="allow-scripts",r.AllowStorageAccessByUserActivation="allow-storage-access-by-user-activation",r.AllowTopNavigation="allow-top-navigation",r.AllowTopNavigationByUserActivation="allow-top-navigation-by-user-activation",r))(O||{});const Q=r=>{if(r==="about:blank")return"*";try{const{origin:e}=new URL(r);return e==="null"||!e?r:e}catch{const{origin:t}=new URL(r,document.baseURI);return t}},K=r=>r.flat(1/0).filter(e=>e!==void 0);function F(r){return typeof r=="function"}const V=[".ice.com",".elliemae.com",".ellielabs.com"],Z=["localhost","127.0.0.1"],U=r=>{try{const{hostname:e}=new URL(r,document.baseURI);return Z.includes(e)||V.some(t=>e===t.slice(1)||e.endsWith(t))}catch{return!1}};class M{id;title;url;searchParams;domElement;window;openMode;origin;initialized=!1;ready=!1;capabilities;#t;#i;constructor(e){const{guestId:t,domElement:i=null,title:s,url:n,window:o,searchParams:c={},openMode:a=b.Embed,remoting:l,perfTracker:u}=e;this.id=t,this.title=s,this.url=n,this.origin=Q(n),this.searchParams=c,this.domElement=i,this.window=o,this.openMode=a,this.capabilities={},this.#i=u,this.#t=l}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:h.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 n=()=>{clearInterval(s),this.#t.unlisten({messageType:h.HandShakeAck,callback:n}),e(!0)};s=setInterval(()=>{t>=i?(clearInterval(s),this.#t.unlisten({messageType:h.HandShakeAck,callback:n}),e(!1)):(this.#t.send({targetWin:this.window,targetOrigin:this.origin,messageType:h.HandShake,messageBody:{}}),t+=1)},1e3),this.#t.listen({messageType:h.HandShakeAck,callback:n})});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:h.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 _={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};let A;const ee=new Uint8Array(16);function te(){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(ee)}var ie;const p=[];for(let r=0;r<256;++r)p.push((r+256).toString(16).slice(1));function L(r,e=0){return p[r[e+0]]+p[r[e+1]]+p[r[e+2]]+p[r[e+3]]+"-"+p[r[e+4]]+p[r[e+5]]+"-"+p[r[e+6]]+p[r[e+7]]+"-"+p[r[e+8]]+p[r[e+9]]+"-"+p[r[e+10]]+p[r[e+11]]+p[r[e+12]]+p[r[e+13]]+p[r[e+14]]+p[r[e+15]]}function fe(r,e=0){const t=L(r,e);if(!ie(t))throw TypeError("Stringified UUID is invalid");return t}const be=null;function se(r,e,t){if(_.randomUUID&&!e&&!r)return _.randomUUID();r=r||{};const i=r.random||(r.rng||te)();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 L(i)}const q=se,x="elli:remoting",D="elli:remoting:response",N="elli:remoting:exception",I=({messageType:r,messageBody:e,requestId:t,onewayMsg:i=!1})=>({requestId:t??(i?null:q()),source:x,type:r,body:e}),we=r=>{const{targetWin:e,targetOrigin:t,messageType:i,messageBody:s}=r,n=I({messageType:i,messageBody:s});e.postMessage(n,t)};class ne{#t;#i;#e=new Map;#c=new Map;#s=null;#n=null;#r=new Map;#h;constructor(e,t,i){if(!e)throw new Error("logger is required");if(!t)throw new Error("correlationId is required");this.#t=t,this.#i=e,this.#h=i?.unsafeAllowAnyGuestOrigin??!1}#o=e=>this.#h?"*":e;#p=()=>{this.#s=null;const e=Date.now(),t=[];let i=null;if(this.#c.forEach((s,n)=>{const{requestId:o,cancelTime:c}=s;c&&c<=e?(this.#i.debug(`Detected response timeout for requestId: ${o}...`),t.push(n),s.resolve(void 0)):c&&(i=i===null?c:Math.min(i,c))}),t.forEach(s=>{this.#c.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.#p,e))};#f=()=>{this.#s!==null&&(window.clearTimeout(this.#s),this.#s=null)};#g=e=>{const t=this.#c.get(e);return this.#i.debug(`serving requestId: ${e}`),this.#c.delete(e),t};#d=e=>{const{requestId:t}=e;this.#i.debug(`Response received for invocation requestId: ${t}`);const i=this.#g(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.#g(e.requestId);return t?(t.reject(new Error(e.body)),!0):(this.#i.warn(`Received exception for stale/invalid request (requestId = ${e.requestId})`),!1)};#b=({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(n=>{this.#i.debug(`Invoking message handler ${n.name}`),n({sourceWin:e,sourceOrigin:t,requestId:i.requestId,type:i.type,body:i.body})}),!0):!1};#w=e=>{if(this.#r.size===0||!e.source)return!1;const t=this.#r.get(e.source);return!t||e?.data?.source!==x?!1:(this.#i.debug(`Remoting: Received message of type "${e.data.type}"`),e.data.type===D?this.#d(e.data):e.data.type===N?this.#l(e.data):this.#b({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.#w),e.addEventListener("message",this.#w),this.#n=e,this.#i.debug(`initialized remoting id: ${this.#t}`)};close=()=>{this.#n&&(this.#n.removeEventListener("message",this.#w),this.#n=null),this.#f(),this.#i.debug(`closed remoting id: ${this.#t}`)};invoke=e=>{const{targetWin:t,targetOrigin:i,messageType:s,messageBody:n,responseTimeoutMs:o}=e;return new Promise((c,a)=>{const l=I({messageType:s,messageBody:n});this.#c.set(l.requestId,{requestId:l.requestId,resolve:c,reject:a,cancelTime:o?Date.now()+o:null}),t.postMessage(l,this.#o(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 n=s.indexOf(i);n!==-1&&s.splice(n,1)};send=e=>{const{targetWin:t,targetOrigin:i,messageType:s,messageBody:n}=e,o=I({messageType:s,messageBody:n,onewayMsg:!0});t.postMessage(o,this.#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:n}=e,o=I({messageType:D,messageBody:n,requestId:s});t.postMessage(o,this.#o(i)),this.#i.debug(`Response sent to caller for invocation requestId: ${s}`)};raiseException=e=>{const{targetWin:t,targetOrigin:i,requestId:s,ex:n}=e,o=n instanceof Error?n.message:n,c=I({messageType:N,messageBody:o,requestId:s});t.postMessage(c,this.#o(i)),this.#i.debug(`Exception sent to caller for invocation. requestId: ${s}`)}}const W="module";var re=(r=>(r.USER="USER",r.PARTNER="PARTNER",r))(re||{});class oe{#t=e=>e.trim().toLowerCase();#i=new Map;#e=new Map;#c=e=>{const{so:t,guestId:i}=e,s=this.#t(t.id),n=this.#e.get(i);if(!n)this.#e.set(i,new Map([[s,e]]));else{if(n.has(s))throw new Error(`Scripting Object ${t.id} already exists for guest ${i}`);n.set(s,e)}};#s=({so:e})=>{if(e._dispose&&typeof e._dispose=="function")try{e._dispose()}catch{}};#n=({objectId:e,guestId:t})=>{if(e===W&&!t)for(const[,s]of this.#e){const n=s.get(e);if(n)return n}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}=t||{};if(!e?.id||!e?._toJSON)throw new Error("Object is not derived from ScriptingObject");const s=this.#t(e.id);if(s===W&&!i)throw new Error("Guest id is required to add Module scripting object");if(i){this.#c({so:e,...t,guestId:i});return}if(this.#i.has(s))throw new Error(`Scripting Object ${e.id} already exists`);this.#i.set(s,{so:e,...t})};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:n}=s||{};return n||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())}}class me{__TYPE__="Proxy";id;objectType;constructor(e,t){this.id=e,this.objectType=t}}const z=r=>r?.constructor?.name==="Proxy"||r?.constructor?.name==="ScriptingObjectProxy"||r?.__TYPE__==="Proxy",ce=new Map;function ye(r){return typeof r=="object"&&r!==null&&("eq"in r||"in"in r||"includes"in r||"gt"in r||"lt"in r||"regex"in r)}function ae(r,e,t){if("eq"in e)return r===e.eq;if("in"in e)return Array.isArray(e.in)&&e.in.includes(r);if("includes"in e)return Array.isArray(r)&&r.includes(e.includes);if("gt"in e){const i=typeof r=="number"?r:Number(r);return!Number.isNaN(i)&&i>e.gt}if("lt"in e){const i=typeof r=="number"?r:Number(r);return!Number.isNaN(i)&&i<e.lt}if("regex"in e){const i=t??ce;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 r=="string"&&s.test(r)}return!1}function B(r){return r!=null&&Object.keys(r).length>0}function le(r,e,t){return Object.entries(e).every(([i,s])=>ae(r[i],s,t?.regexCache))}const ve=null;function ue(r,e){return B(e)?le(r,e):!0}const de=new Set(["SSF.Guest.Load"]);class k{#t;#i;#e;#c=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??k.DEFAULT_SAMPLING_RATIO,this.#s=e.dedupWindowMs??k.DEFAULT_DEDUP_WINDOW_MS,this.#r=e.onError}get enabled(){return this.#i}start(e,t){if(this.#i)try{const i=de.has(e);return!i&&!this.shouldTrack(e)?void 0:(!i&&!this.#c.has(e)&&(this.#t.setTimingEventSamplingRatio({[e]:this.#e}),this.#c.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 H=[O.AllowScripts,O.AllowPopups,O.AllowModals,O.AllowForms,O.AllowDownloads,O.AllowSameOrigin];class he{hostId;#t;#i;#e;#c;#s=new Map;#n=new Map;#r=new Map;#h=new Map;#o;#p=null;#a=null;#f=null;#g=null;#d=new Map;#l;#b;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.#c=t.analyticsObj;const i={analyticsObj:t.analyticsObj,enabled:t?.measurePerformance,samplingRatio:t?.performanceSamplingRatio,onError:s=>this.#e.debug(s)};if(this.#l=new k({...i,dedupWindowMs:t?.performanceDedupWindowMs}),this.#b=new k({...i,dedupWindowMs:0}),this.#i=q(),this.#t=new ne(this.#e,this.#i,{unsafeAllowAnyGuestOrigin:t?.unsafeAllowAnyGuestOrigin}),t?.readyStateCallback&&typeof t?.readyStateCallback!="function")throw new Error("readyStateCallback must be a function");this.#p=t?.readyStateCallback||null,this.#f=t?.onGuestEventSubscribe||null,this.#g=t?.onGuestEventUnsubscribe||null,this.#o=new oe,this.#t.initialize(window),this.#L(),window.addEventListener("beforeunload",this.#y),this.#e.debug(`host is initialized. hostId: ${this.hostId}, correlationId: ${this.#i}`)}#w=(e,t)=>{const i={event:e,...t};this.#c.sendBAEvent(i).catch(s=>{this.#e.debug(`Analytics sendBAEvent failed: ${s.message}`)})};#y=()=>{Array.from(this.#s.values()).filter(t=>t.openMode===b.Popup).map(t=>t.id).forEach(t=>this.unloadGuest(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.#o.has(e?.id,t)||this.#o.addScriptingObject(e,t?{guestId:t?.id}:{}),{type:"object",object:e._toJSON()}):{type:"value",value:e};#oe=e=>typeof e=="string"?e:e instanceof Error?e.message:"An unexpected error occurred in the host application";#E=e=>{e.ready&&this.#t.send({targetWin:e.window,targetOrigin:e.origin,messageType:h.HostConfig,messageBody:{logLevel:this.#e.getLogLevel(),...e.getInfo()}})};#T=({guest:e,obj:t,functionName:i,functionParams:s,callerChain:n})=>{const o=t[i];return F(o)?(this.#e.debug(`Invoking host implementation of ${t.id}.${String(i)}()`),new Promise(c=>{Object.defineProperty(o,"callContext",{value:{guest:e,...n?.length?{callChain:n}:{}},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}'`)))};#S=({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 n=s.getInfo();this.#l.end("SSF.Guest.Load",{appId:n.guestId,appUrl:n.guestUrl}),this.#E(s),this.#p?.(s),this.#e.audit({message:"Guest is ready",...n})}};#A=({sourceWin:e,sourceOrigin:t,requestId:i,body:s})=>{const n=this.#u(e);if(!n){this.#e.warn(`Received ready event for unknown guest. requestid = ${i}`);return}n.initialized||(n.initialized=!0,n.capabilities=s||{},this.#e.audit({message:"Guest is initialized",...n.getInfo()})),(!s||!s.onReady)&&this.#S({sourceWin:e,sourceOrigin:t,requestId:i,type:"",body:null})};#G=async({sourceWin:e})=>{if(e?.window){const t=this.#m(e);t&&!await t.handShake()&&this.unloadGuest(e)}};#P=({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 n=this.#o.listScriptingObjects(s.id);return this.#t.respond({targetWin:e,targetOrigin:t,requestId:i,response:n}),this.#e.debug({message:"name of scripting objects returned",requestId:i,objects:n,...s.getInfo()}),!0};#R=({sourceWin:e,sourceOrigin:t,requestId:i,body:s})=>{const{objectId:n}=s;this.#e.debug(`Processing getObject request for object ${n}. 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(n,{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:n,...o.getInfo()}),!0):(this.#e.warn(`unknown or unauthorized object ${n} from guest ${o.id}`),this.#t.raiseException({targetWin:e,targetOrigin:t,requestId:i,ex:`The requested object (${n}) is not available`}),!1)};#C=({sourceWin:e,requestId:t,body:i})=>{const{eventId:s,criteria:n,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.#f?.({guestId:c.id,eventId:s,criteria:n,token:o})}catch(a){this.#e.warn(`Error in onGuestEventSubscribe callback for event ${s}: ${a.message}`)}},0)};#F=({sourceWin:e,requestId:t,body:i})=>{const{eventId:s,token:n}=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.#g?.({guestId:o.id,eventId:s,token:n})}catch(c){this.#e.warn(`Error in onGuestEventUnsubscribe callback for event ${s}: ${c.message}`)}},0)};#U=({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:n,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 ${n}.${String(s.functionName)}() called from guest "${c.id}" (requestId = ${i})`);const a=this.getScriptingObject(n,{guest:c});if(!a)return this.#e.warn(`Invocation of unknown or unauthorized object ${n} from guest ${c.id}`),this.#t.raiseException({targetWin:e,targetOrigin:t,requestId:i,ex:`The requested object (${n}) is not available`}),!1;const l=c.getInfo();let u;if(this.#l.enabled){const d=`ScriptingObject.API.${n}.${s.functionName}`;u=this.#l.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:n,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:n,scriptingMethod:s.functionName,...l})}).finally(()=>{u&&this.#l.end(u,{appId:l.guestId,appUrl:l.guestUrl})}),!0};#_=()=>{this.#t.listen({messageType:h.GuestResize,callback:this.#U})};#L=()=>{this.#t.listen({messageType:h.GuestReady,callback:this.#A}),this.#t.listen({messageType:h.GuestReadyComplete,callback:this.#S}),this.#t.listen({messageType:h.GuestClose,callback:this.#G}),this.#t.listen({messageType:h.ListObjects,callback:this.#P}),this.#t.listen({messageType:h.ObjectGet,callback:this.#R}),this.#t.listen({messageType:h.ObjectInvoke,callback:this.#M}),this.#t.listen({messageType:h.GuestEventSubscribe,callback:this.#C}),this.#t.listen({messageType:h.GuestEventUnsubscribe,callback:this.#F})};#q=e=>e instanceof R||typeof e?.subscribe=="function";#j=e=>{const t=new M({...e,remoting:this.#t,perfTracker:this.#b});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)};#x=()=>{this.#a||(this.#a=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.unloadGuest(i),this.#h.get(i)?.forEach(n=>{Promise.resolve(n({id:i})).catch(()=>{})})})},1e3))};#O=()=>{if(!this.#a)return;Array.from(this.#s.values()).some(t=>t.openMode===b.Popup)||(clearInterval(this.#a),this.#a=null)};#D=e=>{const{url:t,title:i,popupWindowFeatures:s={},searchParams:n,guestId:o,onLoad:c,onError:a}=e,{width:l=800,height:u=600,top:d=100,left:m=100}=s;let y=this.#I(t);if(y)y.window.closed||(U(t)?window.open("",i):y.window.focus());else{const v=Object.entries({width:l,height:u,top:d,left:m}).filter(([,f])=>f).map(([f,g])=>`${f}=${g}`).join(","),w=window.open(t,i,`popup, ${v}`);if(w)setTimeout(()=>{try{c?.(o)}catch(f){this.#e.debug(`Error occurred in onLoad for guest with id '${o}': ${f.message}`)}},0);else throw setTimeout(()=>{try{a?.(o)}catch(f){this.#e.debug(`Error occurred in onError for guest with id '${o}': ${f.message}`)}},0),new Error("Failed to open guest application in popup window");U(t)||(w.opener=null),y=this.#j({guestId:o,window:w,title:i,url:t,searchParams:n,openMode:b.Popup}),this.#x()}return y};#N=e=>{const{url:t,title:i,targetElement:s,searchParams:n,guestId:o,onLoad:c,onError:a,options:l={}}=e,u=s.ownerDocument??document,{fitToContent:d=!1,disableSandbox:m=!1,sandboxValues:y=[],customSandboxValues:v=[],style:w="",permissionPolicy:f=""}=l;if(!i)throw new Error("title is required");d&&this.#_();const g=u.createElement("iframe");g.setAttribute("id",o);const G=()=>{setTimeout(()=>{try{c?.(o)}catch(P){this.#e.debug(`Error occurred in onLoad for guest with id '${o}': ${P.message}`)}},0),this.#e.debug(`frame loaded for guest with id '${o}'`),g.removeEventListener("load",G)},E=()=>{setTimeout(()=>{try{a?.(o)}catch(P){this.#e.debug(`Error occurred in onError for guest with id '${o}': ${P.message}`)}},0),this.#e.error(`frame load failed for guest with id '${o}'`),g.removeEventListener("error",E)};g.addEventListener("load",G),g.addEventListener("error",E),g.setAttribute("style",`min-width: 100%; height: 100%; border: 0px; ${w}`),m||g.setAttribute("sandbox",v.length>0?v.join(" "):[...H,...y].join(" ")),g.setAttribute("title",i),g.setAttribute("src",t),f&&g.setAttribute("allow",f),s.appendChild(g);const T=u.getElementById(o);return this.#j({guestId:o,domElement:T,window:T.contentWindow,title:i,url:t,searchParams:n,openMode:b.Embed})};#W=(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(z(e)){const i=this.cloneScriptingObject(e);this.#o.addScriptingObject(i,t)}else this.#o.addScriptingObject(e,t)};cloneScriptingObject=e=>{if(!e)throw new Error("proxy is required");const t=new C(e.id,e.objectType);let i=[];return Object.keys(e).forEach(s=>{const n=e[s];if(this.#q(n)){const o=new j({name:n.name||s,objectId:t.id});if(Object.defineProperty(t,s,{value:o,enumerable:!0}),n instanceof R){const c=({eventParams:l,eventOptions:u})=>this.dispatchEvent({event:o,eventParams:l,eventOptions:u}),a=n.subscribe(c);i.push(()=>{n.unsubscribe(a)})}else{const c=n.subscribe?.((a,l,u)=>this.dispatchEvent({event:o,eventParams:l,eventOptions:u}));i.push(()=>{n.unsubscribe?.(c)})}}else if(F(n)&&(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(n,"callContext",{value:{callChain:[...l,m]},configurable:!0,enumerable:!0,writable:!0})}const a=await n(...o);return z(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.#a&&(clearInterval(this.#a),this.#a=null),this.#y(),this.#d.clear(),this.#t.close(),window.removeEventListener("beforeunload",this.#y),this.#e.debug(`host is closed. hostId: ${this.hostId}, correlationId: ${this.#i}`)};#z=({targetGuest:e,guestCapabilities:t,scriptingEventId:i,dispatchToGuest:s})=>{const n=o=>{if(B(t)&&!ue(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?n(e):this.#s.forEach(n)};dispatchEvent=async e=>{const{event:{id:t,name:i},eventParams:s,eventOptions:n={}}=e,{eventHandler:o=null,timeout:c=null,window:a=null,guestId:l,guestCapabilities:u}=n,d=t.split(".")[0],m=l||a,y=m?this.#m(m):null,v=y?this.getScriptingObject(d,{guest:y}):this.getScriptingObject(d);if(!v)return this.#e.warn(`Attempt to dispatch event ${i} on unknown object ${d}`),Promise.resolve([]);const w={object:v._toJSON(),eventName:i,eventParams:s,eventHandler:o,eventOptions:{allowsFeedback:!1}};c&&!Number.isNaN(c)&&(w.eventOptions={allowsFeedback:!0,timeout:Number(c)});const f=[];let g;const G=E=>{const T=E.getInfo();c&&E?.capabilities?.eventFeedback?(f.push(E.dispatchEvent(w,c)),!g&&this.#l.enabled&&(g=this.#l.start(`ScriptingObject.Event.${v.id}.${i}`,{appId:this.hostId,appUrl:window.location.href})),this.#e.debug({message:"Event dispatched and awaiting feedback",scriptingEventId:t,...T})):(E.send({messageType:h.ObjectEvent,messageBody:w}),this.#e.debug({message:"Event dispatched",scriptingEventId:t,...T}))};return this.#z({targetGuest:y??null,guestCapabilities:u,scriptingEventId:t,dispatchToGuest:G}),Promise.all(f).then(E=>(this.#e.debug({message:"Event feedback received",scriptingEventId:t}),K(E))).catch(E=>{throw this.#e.error({message:"Error processing event",eventId:t,exception:E}),E}).finally(()=>{g&&this.#l.end(g,{appId:this.hostId,appUrl:window.location.href})})};getGuests=()=>Array.from(this.#s.values());getScriptingObject=(e,t)=>this.#o.getObject(e,t?.guest);loadGuest=e=>{const{id:t,url:i,targetElement:s,title:n,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 f=1;for(;this.#s.has(`${t}-${f}`);)f+=1;d=`${t}-${f}`}const{openMode:m=b.Embed,popupWindowFeatures:y={}}=l,v=this.#W(i,o);let w=null;if(this.#l.start("SSF.Guest.Load",{appId:d,appUrl:v}),m===b.Popup)w=this.#D({guestId:d,url:v,title:n,searchParams:o,popupWindowFeatures:y,onLoad:c,onError:a});else if(m===b.Embed)w=this.#N({guestId:d,url:v,title:n,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",...w.getInfo()}),w};loadGuests=e=>{const{id:t,url:i,targetElement:s,title:n,searchParamsList:o=[],options:c={}}=e;o.forEach((a,l)=>{this.loadGuest({id:`${t}-${l}`,url:i,title:n,targetElement:s,searchParams:a,options:c})},this)};removeAllScriptingObjects=e=>{this.#o.removeAllScriptingObjects(e)};removeScriptingObject=(e,t)=>{this.#o.removeScriptingObject(e,t)};setLogLevel=e=>{this.#e.setLogLevel(e),this.#s.forEach(this.#E),this.#e.debug("Dispatched config events to all guests")};#B=e=>{const{guestEmui:t,cleanupFunctionName:i,context:s}=e,o=t[i];if(typeof o=="function")try{o(),this.#e.debug(`[SSF] Called window.emui.${String(i)}() for ${String(s)}`)}catch(c){this.#e.warn(`[SSF] emui.${String(i)}() threw error for ${String(s)}: ${c.message}`)}finally{t[i]=null}};#H=e=>{if(typeof e!="object"||e===null)return;const t=e;t.init=null,t.mount=null,t.unmount=null,t.getRef=null,t.navigate=null};#J=e=>{if(typeof e!="object"||e===null)return;const t=e;t.app&&(this.#H(t.app),t.app=null),t.registerApp=null,t.logRocket=null,t.getEnvironment=null,t.loadScript=null,t.loadStylesheet=null,t.unmount=null};#Y=(e,t)=>{try{const i=e?.document?.body;if(!i)return;const{observerReferences:s}=window;if(!s||!(s instanceof Map)||!s.has(i))return;const n=s.get(i);n&&typeof n.disconnect=="function"&&(n.disconnect(),s.delete(i),this.#e.debug(`[SSF] Disconnected FieldMutation observer for guest ${t}`))}catch(i){this.#e.debug(`[SSF] Failed to disconnect FieldMutation observer for guest ${t}: ${i.message}`)}};#X=(e,t)=>{try{if(!e||e.closed)return;e.close(),this.#e.debug(`[SSF] Called contentWindow.close() for guest ${t}`)}catch(i){this.#e.debug(`[SSF] contentWindow.close() failed for guest ${t}: ${i.message}`)}};#Q=(e,t)=>{try{if(!e.parentNode)return;e.src="about:blank",this.#e.debug(`[SSF] Navigated to about:blank for guest ${t}`)}catch(i){this.#e.debug(`[SSF] Navigation to about:blank failed for guest ${t}: ${i.message}`)}};#K=(e,t)=>{try{const i=e,{elli:s}=i;if(s?.script&&typeof s.script=="object"){const{script:n}=s;if(n&&n.guest&&typeof n.guest=="object"){const{guest:o}=n,c=o;c.create=null}n&&(n.guest=null,n.connect=null,n.getObject=null,n.setLogLevel=null,n.subscribe=null,n.unsubscribe=null,s.script=null),this.#e.debug(`[SSF] Nulled all window.elli.script properties for ${t}`)}}catch(i){this.#e.debug(`[SSF] Failed to cleanup window.elli: ${i.message}`)}};#V=(e,t)=>{try{const i=e;i.gtmDataLayer&&(i.gtmDataLayer=null,this.#e.debug(`[SSF] Cleared gtmDataLayer for ${t}`))}catch(i){this.#e.debug(`[SSF] Failed to cleanup GTM data layer: ${i.message}`)}};#Z=(e,t)=>{try{typeof e=="object"&&e!==null&&this.#J(e),this.#e.debug(`[SSF] Nulled all window.emui properties for ${t}`)}catch(i){this.#e.debug(`[SSF] Failed to cleanup window.emui: ${i.message}`)}};#$=e=>{const{guestWindow:t,guestId:i,cleanupFunctionName:s,windowType:n="iframe"}=e;if(!t){this.#e.debug(`No ${n} window available for cleanup of guest ${i}`);return}const o=`${n} ${i}`;try{const a=t.emui;if(!a){this.#e.debug(`No window.emui found for ${o}`);return}this.#B({guestEmui:a,cleanupFunctionName:s,context:o}),this.#Z(a,o),this.#K(t,o),this.#V(t,o)}catch(c){this.#e.debug(`[SSF] Could not access ${n} window for cleanup (guest ${i}): ${c.message}`)}};#ee=(e,t,i)=>{const s=[];let n=window;for(let o=0;o<e.length-1;o+=1){const c=e[o];if(n[c]===void 0||n[c]===null)return this.#e.debug(`Path "${t}" does not exist (stopped at ${c}) for guest ${i}`),null;s.push({obj:n,key:c}),n=n[c]}return{current:n,parentChain:s}};#te=(e,t,i)=>{for(let s=e.length-1;s>=0;s-=1){const{obj:n,key:o}=e[s],c=n[o];if(!c||typeof c!="object"||!this.#se(c))break;n[o]=null,this.#e.debug(`Cleaned up empty parent object at ${t.slice(0,s+1).join(".")} for guest ${i}`)}};#ie=(e,t)=>{!e||e.length===0||e.forEach(i=>{try{const s=i.split(".").filter(l=>l!=="window"&&l.trim()!=="");if(s.length===0){this.#e.debug(`Invalid path "${i}" - skipping for guest ${t}`);return}const n=this.#ee(s,i,t);if(!n)return;const{current:o,parentChain:c}=n,a=s[s.length-1];if(o[a]===void 0)return;o[a]=null,this.#e.debug(`Cleared window reference: ${i} for guest ${t}`),this.#te(c,s,t)}catch(s){this.#e.debug(`Failed to clear window reference "${i}" for guest ${t}: ${s.message}`)}})};#se=e=>{if(e==null||typeof e!="object")return!0;const t=Object.keys(e);if(t.length===0)return!0;const i=e;return t.every(s=>i[s]===null||i[s]===void 0)};unloadGuest=(e,t)=>{const i=this.#m(e);if(!i){this.#e.warn("Attempted to unload unknown guest");return}const s=i.id;if(t?.purgeOnDestroy){const n=t.cleanupFunctionName||"unmount";t.windowRefsToClear&&t.windowRefsToClear.length>0&&this.#ie(t.windowRefsToClear,s),this.unloadGuestWithFullCleanup(s,n),this.#e.audit({message:`Guest unloaded with purge mode (windowRefs: ${t.windowRefsToClear?.length||0})`,...i.getInfo()});return}i.dispose(),this.#n.delete(i.window),this.#r.delete(i.url),this.#d.delete(i.id),this.#s.delete(i.id),this.#e.audit({message:"Guest is removed from host",...i.getInfo()}),this.#O()};#ne=(e,t)=>{if(!e.domElement)return;const i=e.domElement,s=e.window,{id:n}=e;this.#$({guestWindow:s,guestId:n,cleanupFunctionName:t,windowType:"iframe"}),this.#Y(s,n),this.#X(s,n),this.#Q(i,n),setTimeout(()=>{try{i.parentNode&&(i.remove(),this.#e.debug(`[SSF] Removed iframe from DOM for guest ${n}`))}catch(o){this.#e.warn(`[SSF] Failed to remove iframe for guest ${n}: ${o.message}`)}},10)};#re=(e,t)=>{const i=e.window,{id:s}=e;this.#$({guestWindow:i,guestId:s,cleanupFunctionName:t,windowType:"popup"});try{i&&!i.closed&&(i.close(),this.#e.debug(`[SSF] Closed popup window for guest ${s}`))}catch(n){this.#e.debug(`[SSF] Failed to close popup window for guest ${s}: ${n.message}`)}e.dispose()};unloadGuestWithFullCleanup=(e,t="unmount")=>{const i=this.#m(e);if(!i){this.#e.warn("Attempted to unload unknown guest");return}const{id:s}=i;i.openMode===b.Embed&&i.domElement?this.#ne(i,t):i.openMode===b.Popup?this.#re(i,t):i.dispose();try{this.#t.removeSender({origin:i.origin,window:i.window}),this.#e.debug(`[SSF] Removed remoting sender for guest ${s}`)}catch(n){this.#e.debug(`[SSF] Failed to remove remoting sender for guest ${s}: ${n.message}`)}this.#n.delete(i.window),this.#r.delete(i.url),this.#d.delete(s),this.#s.delete(s),this.#O(),this.#e.audit({message:"Guest unloaded with full cleanup",...i.getInfo()})};onGuestClose=e=>{const{id:t,guestCloseCallback:i}=e,s=this.#h.get(t)||[];s.push(i),this.#h.set(t,s)}}return $})());
|
|
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
|